Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
sqlite3.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stddef.h>
#include <time.h>
#include <pthread.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/mman.h>
#include <dlfcn.h>

Go to the source code of this file.

Data Structures

struct  sqlite3_file
 
struct  sqlite3_io_methods
 
struct  sqlite3_vfs
 
struct  sqlite3_mem_methods
 
struct  sqlite3_module
 
struct  sqlite3_index_info
 
struct  sqlite3_index_info::sqlite3_index_constraint
 
struct  sqlite3_index_info::sqlite3_index_orderby
 
struct  sqlite3_index_info::sqlite3_index_constraint_usage
 
struct  sqlite3_vtab
 
struct  sqlite3_vtab_cursor
 
struct  sqlite3_mutex_methods
 
struct  sqlite3_pcache_page
 
struct  sqlite3_pcache_methods2
 
struct  sqlite3_pcache_methods
 
struct  sqlite3_snapshot
 
struct  sqlite3_rtree_geometry
 
struct  sqlite3_rtree_query_info
 
struct  Fts5PhraseIter
 
struct  Fts5ExtensionApi
 
struct  fts5_tokenizer
 
struct  fts5_api
 
struct  Hash
 
struct  Hash::_ht
 
struct  HashElem
 
struct  BusyHandler
 
struct  BtreePayload
 
struct  VdbeOp
 
union  VdbeOp::p4union
 
struct  SubProgram
 
struct  VdbeOpList
 
struct  PgHdr
 
struct  Db
 
struct  Schema
 
struct  Lookaside
 
struct  LookasideSlot
 
struct  FuncDefHash
 
struct  sqlite3
 
struct  sqlite3::sqlite3InitInfo
 
struct  FuncDef
 
struct  FuncDestructor
 
struct  Savepoint
 
struct  Module
 
struct  Column
 
struct  CollSeq
 
struct  VTable
 
struct  Table
 
struct  FKey
 
struct  FKey::sColMap
 
struct  KeyInfo
 
struct  UnpackedRecord
 
struct  Index
 
struct  IndexSample
 
struct  Token
 
struct  AggInfo
 
struct  AggInfo::AggInfo_col
 
struct  AggInfo::AggInfo_func
 
struct  Expr
 
struct  ExprList
 
struct  ExprList::ExprList_item
 
struct  IdList
 
struct  IdList::IdList_item
 
struct  SrcList
 
struct  SrcList::SrcList_item
 
struct  NameContext
 
struct  Upsert
 
struct  Select
 
struct  SelectDest
 
struct  AutoincInfo
 
struct  TriggerPrg
 
struct  Parse
 
struct  AuthContext
 
struct  Trigger
 
struct  TriggerStep
 
struct  DbFixer
 
struct  sqlite3_str
 
struct  InitData
 
struct  Sqlite3Config
 
struct  Walker
 
struct  With
 
struct  With::Cte
 
struct  Window
 
struct  PrintfArguments
 
struct  VdbeCursor
 
struct  VdbeFrame
 
struct  sqlite3_value
 
union  sqlite3_value::MemValue
 
struct  AuxData
 
struct  sqlite3_context
 
struct  ScanStatus
 
struct  DblquoteStr
 
struct  Vdbe
 
struct  PreUpdate
 
struct  sqlite3StatType
 
struct  DateTime
 
struct  BenignMallocHooks
 
struct  sqlite3_mutex
 
struct  Mem0Global
 
struct  et_info
 
struct  sqlite3PrngType
 
struct  SQLiteThread
 
struct  UnixUnusedFd
 
struct  unixFile
 
struct  unix_syscall
 
struct  vxworksFileId
 
struct  unixFileId
 
struct  unixInodeInfo
 
struct  unixShmNode
 
struct  unixShm
 
struct  Bitvec
 
struct  PCache
 
struct  PgHdr1
 
struct  PGroup
 
struct  PCache1
 
struct  PgFreeslot
 
struct  PCacheGlobal
 
struct  RowSetEntry
 
struct  RowSetChunk
 
struct  RowSet
 
struct  PagerSavepoint
 
struct  Pager
 
struct  WalIndexHdr
 
struct  WalCkptInfo
 
struct  Wal
 
struct  WalIterator
 
struct  WalIterator::WalSegment
 
struct  WalHashLoc
 
struct  WalWriter
 
struct  MemPage
 
struct  BtLock
 
struct  Btree
 
struct  BtShared
 
struct  CellInfo
 
struct  BtCursor
 
struct  IntegrityCk
 
struct  CellArray
 
struct  sqlite3_backup
 
struct  ValueNewStat4Ctx
 
struct  ReusableSpace
 
struct  Incrblob
 
struct  SorterFile
 
struct  SorterList
 
struct  MergeEngine
 
struct  SortSubtask
 
struct  VdbeSorter
 
struct  PmaReader
 
struct  IncrMerger
 
struct  PmaWriter
 
struct  SorterRecord
 
struct  FileChunk
 
struct  FilePoint
 
struct  MemJournal
 
struct  IdxCover
 
struct  SrcCount
 
struct  RenameToken
 
struct  RenameCtx
 
struct  StatSample
 
struct  StatAccum
 
struct  analysisInfo
 
struct  TableLock
 
struct  compareInfo
 
struct  SumCtx
 
struct  CountCtx
 
struct  sqlite3_api_routines
 
struct  sqlite3AutoExtList
 
struct  PragmaName
 
struct  PragmaVtab
 
struct  PragmaVtabCursor
 
struct  DistinctCtx
 
struct  SortCtx
 
struct  RowLoadInfo
 
struct  SubstContext
 
struct  WhereConst
 
struct  TabResult
 
struct  VtabCtx
 
struct  WhereLevel
 
struct  WhereLoop
 
struct  WhereOrCost
 
struct  WhereOrSet
 
struct  WherePath
 
struct  WhereTerm
 
struct  WhereScan
 
struct  WhereClause
 
struct  WhereOrInfo
 
struct  WhereAndInfo
 
struct  WhereMaskSet
 
struct  WhereLoopBuilder
 
struct  WhereExprMod
 
struct  WhereInfo
 
struct  IdxExprTrans
 
struct  HiddenIndexInfo
 
struct  CallCount
 
struct  NthValueCtx
 
struct  NtileCtx
 
struct  LastValueCtx
 
struct  WindowRewrite
 
struct  WindowCsrAndReg
 
struct  WindowCodeArg
 
struct  TrigEvent
 
struct  FrameBound
 
union  YYMINORTYPE
 
struct  yyStackEntry
 
struct  yyParser
 

Macros

#define SQLITE_CORE   1
 
#define SQLITE_AMALGAMATION   1
 
#define SQLITE_PRIVATE   static
 
#define CTIMEOPT_VAL_(opt)   #opt
 
#define CTIMEOPT_VAL(opt)   CTIMEOPT_VAL_(opt)
 
#define CTIMEOPT_VAL2_(opt1, opt2)   #opt1 "," #opt2
 
#define CTIMEOPT_VAL2(opt)   CTIMEOPT_VAL2_(opt)
 
#define SQLITEINT_H
 
#define SQLITE_TCLAPI
 
#define SQLITE_MSVC_H
 
#define OS_VXWORKS   0
 
#define HAVE_FCHOWN   1
 
#define HAVE_READLINK   1
 
#define HAVE_LSTAT   1
 
#define _LARGE_FILE   1
 
#define _FILE_OFFSET_BITS   64
 
#define _LARGEFILE_SOURCE   1
 
#define GCC_VERSION   0
 
#define MSVC_VERSION   0
 
#define deliberate_fall_through
 
#define SQLITE3_H
 
#define SQLITE_EXTERN   extern
 
#define SQLITE_API
 
#define SQLITE_CDECL
 
#define SQLITE_APICALL
 
#define SQLITE_STDCALL   SQLITE_APICALL
 
#define SQLITE_CALLBACK
 
#define SQLITE_SYSAPI
 
#define SQLITE_DEPRECATED
 
#define SQLITE_EXPERIMENTAL
 
#define SQLITE_VERSION   "3.33.0"
 
#define SQLITE_VERSION_NUMBER   3033000
 
#define SQLITE_SOURCE_ID   "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f"
 
#define SQLITE_OK   0 /* Successful result */
 
#define SQLITE_ERROR   1 /* Generic error */
 
#define SQLITE_INTERNAL   2 /* Internal logic error in SQLite */
 
#define SQLITE_PERM   3 /* Access permission denied */
 
#define SQLITE_ABORT   4 /* Callback routine requested an abort */
 
#define SQLITE_BUSY   5 /* The database file is locked */
 
#define SQLITE_LOCKED   6 /* A table in the database is locked */
 
#define SQLITE_NOMEM   7 /* A malloc() failed */
 
#define SQLITE_READONLY   8 /* Attempt to write a readonly database */
 
#define SQLITE_INTERRUPT   9 /* Operation terminated by sqlite3_interrupt()*/
 
#define SQLITE_IOERR   10 /* Some kind of disk I/O error occurred */
 
#define SQLITE_CORRUPT   11 /* The database disk image is malformed */
 
#define SQLITE_NOTFOUND   12 /* Unknown opcode in sqlite3_file_control() */
 
#define SQLITE_FULL   13 /* Insertion failed because database is full */
 
#define SQLITE_CANTOPEN   14 /* Unable to open the database file */
 
#define SQLITE_PROTOCOL   15 /* Database lock protocol error */
 
#define SQLITE_EMPTY   16 /* Internal use only */
 
#define SQLITE_SCHEMA   17 /* The database schema changed */
 
#define SQLITE_TOOBIG   18 /* String or BLOB exceeds size limit */
 
#define SQLITE_CONSTRAINT   19 /* Abort due to constraint violation */
 
#define SQLITE_MISMATCH   20 /* Data type mismatch */
 
#define SQLITE_MISUSE   21 /* Library used incorrectly */
 
#define SQLITE_NOLFS   22 /* Uses OS features not supported on host */
 
#define SQLITE_AUTH   23 /* Authorization denied */
 
#define SQLITE_FORMAT   24 /* Not used */
 
#define SQLITE_RANGE   25 /* 2nd parameter to sqlite3_bind out of range */
 
#define SQLITE_NOTADB   26 /* File opened that is not a database file */
 
#define SQLITE_NOTICE   27 /* Notifications from sqlite3_log() */
 
#define SQLITE_WARNING   28 /* Warnings from sqlite3_log() */
 
#define SQLITE_ROW   100 /* sqlite3_step() has another row ready */
 
#define SQLITE_DONE   101 /* sqlite3_step() has finished executing */
 
#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
 
#define SQLITE_ERROR_RETRY   (SQLITE_ERROR | (2<<8))
 
#define SQLITE_ERROR_SNAPSHOT   (SQLITE_ERROR | (3<<8))
 
#define SQLITE_IOERR_READ   (SQLITE_IOERR | (1<<8))
 
#define SQLITE_IOERR_SHORT_READ   (SQLITE_IOERR | (2<<8))
 
#define SQLITE_IOERR_WRITE   (SQLITE_IOERR | (3<<8))
 
#define SQLITE_IOERR_FSYNC   (SQLITE_IOERR | (4<<8))
 
#define SQLITE_IOERR_DIR_FSYNC   (SQLITE_IOERR | (5<<8))
 
#define SQLITE_IOERR_TRUNCATE   (SQLITE_IOERR | (6<<8))
 
#define SQLITE_IOERR_FSTAT   (SQLITE_IOERR | (7<<8))
 
#define SQLITE_IOERR_UNLOCK   (SQLITE_IOERR | (8<<8))
 
#define SQLITE_IOERR_RDLOCK   (SQLITE_IOERR | (9<<8))
 
#define SQLITE_IOERR_DELETE   (SQLITE_IOERR | (10<<8))
 
#define SQLITE_IOERR_BLOCKED   (SQLITE_IOERR | (11<<8))
 
#define SQLITE_IOERR_NOMEM   (SQLITE_IOERR | (12<<8))
 
#define SQLITE_IOERR_ACCESS   (SQLITE_IOERR | (13<<8))
 
#define SQLITE_IOERR_CHECKRESERVEDLOCK   (SQLITE_IOERR | (14<<8))
 
#define SQLITE_IOERR_LOCK   (SQLITE_IOERR | (15<<8))
 
#define SQLITE_IOERR_CLOSE   (SQLITE_IOERR | (16<<8))
 
#define SQLITE_IOERR_DIR_CLOSE   (SQLITE_IOERR | (17<<8))
 
#define SQLITE_IOERR_SHMOPEN   (SQLITE_IOERR | (18<<8))
 
#define SQLITE_IOERR_SHMSIZE   (SQLITE_IOERR | (19<<8))
 
#define SQLITE_IOERR_SHMLOCK   (SQLITE_IOERR | (20<<8))
 
#define SQLITE_IOERR_SHMMAP   (SQLITE_IOERR | (21<<8))
 
#define SQLITE_IOERR_SEEK   (SQLITE_IOERR | (22<<8))
 
#define SQLITE_IOERR_DELETE_NOENT   (SQLITE_IOERR | (23<<8))
 
#define SQLITE_IOERR_MMAP   (SQLITE_IOERR | (24<<8))
 
#define SQLITE_IOERR_GETTEMPPATH   (SQLITE_IOERR | (25<<8))
 
#define SQLITE_IOERR_CONVPATH   (SQLITE_IOERR | (26<<8))
 
#define SQLITE_IOERR_VNODE   (SQLITE_IOERR | (27<<8))
 
#define SQLITE_IOERR_AUTH   (SQLITE_IOERR | (28<<8))
 
#define SQLITE_IOERR_BEGIN_ATOMIC   (SQLITE_IOERR | (29<<8))
 
#define SQLITE_IOERR_COMMIT_ATOMIC   (SQLITE_IOERR | (30<<8))
 
#define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
 
#define SQLITE_IOERR_DATA   (SQLITE_IOERR | (32<<8))
 
#define SQLITE_LOCKED_SHAREDCACHE   (SQLITE_LOCKED | (1<<8))
 
#define SQLITE_LOCKED_VTAB   (SQLITE_LOCKED | (2<<8))
 
#define SQLITE_BUSY_RECOVERY   (SQLITE_BUSY | (1<<8))
 
#define SQLITE_BUSY_SNAPSHOT   (SQLITE_BUSY | (2<<8))
 
#define SQLITE_BUSY_TIMEOUT   (SQLITE_BUSY | (3<<8))
 
#define SQLITE_CANTOPEN_NOTEMPDIR   (SQLITE_CANTOPEN | (1<<8))
 
#define SQLITE_CANTOPEN_ISDIR   (SQLITE_CANTOPEN | (2<<8))
 
#define SQLITE_CANTOPEN_FULLPATH   (SQLITE_CANTOPEN | (3<<8))
 
#define SQLITE_CANTOPEN_CONVPATH   (SQLITE_CANTOPEN | (4<<8))
 
#define SQLITE_CANTOPEN_DIRTYWAL   (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
 
#define SQLITE_CANTOPEN_SYMLINK   (SQLITE_CANTOPEN | (6<<8))
 
#define SQLITE_CORRUPT_VTAB   (SQLITE_CORRUPT | (1<<8))
 
#define SQLITE_CORRUPT_SEQUENCE   (SQLITE_CORRUPT | (2<<8))
 
#define SQLITE_CORRUPT_INDEX   (SQLITE_CORRUPT | (3<<8))
 
#define SQLITE_READONLY_RECOVERY   (SQLITE_READONLY | (1<<8))
 
#define SQLITE_READONLY_CANTLOCK   (SQLITE_READONLY | (2<<8))
 
#define SQLITE_READONLY_ROLLBACK   (SQLITE_READONLY | (3<<8))
 
#define SQLITE_READONLY_DBMOVED   (SQLITE_READONLY | (4<<8))
 
#define SQLITE_READONLY_CANTINIT   (SQLITE_READONLY | (5<<8))
 
#define SQLITE_READONLY_DIRECTORY   (SQLITE_READONLY | (6<<8))
 
#define SQLITE_ABORT_ROLLBACK   (SQLITE_ABORT | (2<<8))
 
#define SQLITE_CONSTRAINT_CHECK   (SQLITE_CONSTRAINT | (1<<8))
 
#define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
 
#define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
 
#define SQLITE_CONSTRAINT_FUNCTION   (SQLITE_CONSTRAINT | (4<<8))
 
#define SQLITE_CONSTRAINT_NOTNULL   (SQLITE_CONSTRAINT | (5<<8))
 
#define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
 
#define SQLITE_CONSTRAINT_TRIGGER   (SQLITE_CONSTRAINT | (7<<8))
 
#define SQLITE_CONSTRAINT_UNIQUE   (SQLITE_CONSTRAINT | (8<<8))
 
#define SQLITE_CONSTRAINT_VTAB   (SQLITE_CONSTRAINT | (9<<8))
 
#define SQLITE_CONSTRAINT_ROWID   (SQLITE_CONSTRAINT |(10<<8))
 
#define SQLITE_CONSTRAINT_PINNED   (SQLITE_CONSTRAINT |(11<<8))
 
#define SQLITE_NOTICE_RECOVER_WAL   (SQLITE_NOTICE | (1<<8))
 
#define SQLITE_NOTICE_RECOVER_ROLLBACK   (SQLITE_NOTICE | (2<<8))
 
#define SQLITE_WARNING_AUTOINDEX   (SQLITE_WARNING | (1<<8))
 
#define SQLITE_AUTH_USER   (SQLITE_AUTH | (1<<8))
 
#define SQLITE_OK_LOAD_PERMANENTLY   (SQLITE_OK | (1<<8))
 
#define SQLITE_OK_SYMLINK   (SQLITE_OK | (2<<8))
 
#define SQLITE_OPEN_READONLY   0x00000001 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_READWRITE   0x00000002 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_CREATE   0x00000004 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_DELETEONCLOSE   0x00000008 /* VFS only */
 
#define SQLITE_OPEN_EXCLUSIVE   0x00000010 /* VFS only */
 
#define SQLITE_OPEN_AUTOPROXY   0x00000020 /* VFS only */
 
#define SQLITE_OPEN_URI   0x00000040 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_MEMORY   0x00000080 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_MAIN_DB   0x00000100 /* VFS only */
 
#define SQLITE_OPEN_TEMP_DB   0x00000200 /* VFS only */
 
#define SQLITE_OPEN_TRANSIENT_DB   0x00000400 /* VFS only */
 
#define SQLITE_OPEN_MAIN_JOURNAL   0x00000800 /* VFS only */
 
#define SQLITE_OPEN_TEMP_JOURNAL   0x00001000 /* VFS only */
 
#define SQLITE_OPEN_SUBJOURNAL   0x00002000 /* VFS only */
 
#define SQLITE_OPEN_SUPER_JOURNAL   0x00004000 /* VFS only */
 
#define SQLITE_OPEN_NOMUTEX   0x00008000 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_FULLMUTEX   0x00010000 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_SHAREDCACHE   0x00020000 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_PRIVATECACHE   0x00040000 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_WAL   0x00080000 /* VFS only */
 
#define SQLITE_OPEN_NOFOLLOW   0x01000000 /* Ok for sqlite3_open_v2() */
 
#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000 /* VFS only */
 
#define SQLITE_IOCAP_ATOMIC   0x00000001
 
#define SQLITE_IOCAP_ATOMIC512   0x00000002
 
#define SQLITE_IOCAP_ATOMIC1K   0x00000004
 
#define SQLITE_IOCAP_ATOMIC2K   0x00000008
 
#define SQLITE_IOCAP_ATOMIC4K   0x00000010
 
#define SQLITE_IOCAP_ATOMIC8K   0x00000020
 
#define SQLITE_IOCAP_ATOMIC16K   0x00000040
 
#define SQLITE_IOCAP_ATOMIC32K   0x00000080
 
#define SQLITE_IOCAP_ATOMIC64K   0x00000100
 
#define SQLITE_IOCAP_SAFE_APPEND   0x00000200
 
#define SQLITE_IOCAP_SEQUENTIAL   0x00000400
 
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN   0x00000800
 
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE   0x00001000
 
#define SQLITE_IOCAP_IMMUTABLE   0x00002000
 
#define SQLITE_IOCAP_BATCH_ATOMIC   0x00004000
 
#define SQLITE_LOCK_NONE   0
 
#define SQLITE_LOCK_SHARED   1
 
#define SQLITE_LOCK_RESERVED   2
 
#define SQLITE_LOCK_PENDING   3
 
#define SQLITE_LOCK_EXCLUSIVE   4
 
#define SQLITE_SYNC_NORMAL   0x00002
 
#define SQLITE_SYNC_FULL   0x00003
 
#define SQLITE_SYNC_DATAONLY   0x00010
 
#define SQLITE_FCNTL_LOCKSTATE   1
 
#define SQLITE_FCNTL_GET_LOCKPROXYFILE   2
 
#define SQLITE_FCNTL_SET_LOCKPROXYFILE   3
 
#define SQLITE_FCNTL_LAST_ERRNO   4
 
#define SQLITE_FCNTL_SIZE_HINT   5
 
#define SQLITE_FCNTL_CHUNK_SIZE   6
 
#define SQLITE_FCNTL_FILE_POINTER   7
 
#define SQLITE_FCNTL_SYNC_OMITTED   8
 
#define SQLITE_FCNTL_WIN32_AV_RETRY   9
 
#define SQLITE_FCNTL_PERSIST_WAL   10
 
#define SQLITE_FCNTL_OVERWRITE   11
 
#define SQLITE_FCNTL_VFSNAME   12
 
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE   13
 
#define SQLITE_FCNTL_PRAGMA   14
 
#define SQLITE_FCNTL_BUSYHANDLER   15
 
#define SQLITE_FCNTL_TEMPFILENAME   16
 
#define SQLITE_FCNTL_MMAP_SIZE   18
 
#define SQLITE_FCNTL_TRACE   19
 
#define SQLITE_FCNTL_HAS_MOVED   20
 
#define SQLITE_FCNTL_SYNC   21
 
#define SQLITE_FCNTL_COMMIT_PHASETWO   22
 
#define SQLITE_FCNTL_WIN32_SET_HANDLE   23
 
#define SQLITE_FCNTL_WAL_BLOCK   24
 
#define SQLITE_FCNTL_ZIPVFS   25
 
#define SQLITE_FCNTL_RBU   26
 
#define SQLITE_FCNTL_VFS_POINTER   27
 
#define SQLITE_FCNTL_JOURNAL_POINTER   28
 
#define SQLITE_FCNTL_WIN32_GET_HANDLE   29
 
#define SQLITE_FCNTL_PDB   30
 
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE   31
 
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE   32
 
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE   33
 
#define SQLITE_FCNTL_LOCK_TIMEOUT   34
 
#define SQLITE_FCNTL_DATA_VERSION   35
 
#define SQLITE_FCNTL_SIZE_LIMIT   36
 
#define SQLITE_FCNTL_CKPT_DONE   37
 
#define SQLITE_FCNTL_RESERVE_BYTES   38
 
#define SQLITE_FCNTL_CKPT_START   39
 
#define SQLITE_GET_LOCKPROXYFILE   SQLITE_FCNTL_GET_LOCKPROXYFILE
 
#define SQLITE_SET_LOCKPROXYFILE   SQLITE_FCNTL_SET_LOCKPROXYFILE
 
#define SQLITE_LAST_ERRNO   SQLITE_FCNTL_LAST_ERRNO
 
#define SQLITE_ACCESS_EXISTS   0
 
#define SQLITE_ACCESS_READWRITE   1 /* Used by PRAGMA temp_store_directory */
 
#define SQLITE_ACCESS_READ   2 /* Unused */
 
#define SQLITE_SHM_UNLOCK   1
 
#define SQLITE_SHM_LOCK   2
 
#define SQLITE_SHM_SHARED   4
 
#define SQLITE_SHM_EXCLUSIVE   8
 
#define SQLITE_SHM_NLOCK   8
 
#define SQLITE_CONFIG_SINGLETHREAD   1 /* nil */
 
#define SQLITE_CONFIG_MULTITHREAD   2 /* nil */
 
#define SQLITE_CONFIG_SERIALIZED   3 /* nil */
 
#define SQLITE_CONFIG_MALLOC   4 /* sqlite3_mem_methods* */
 
#define SQLITE_CONFIG_GETMALLOC   5 /* sqlite3_mem_methods* */
 
#define SQLITE_CONFIG_SCRATCH   6 /* No longer used */
 
#define SQLITE_CONFIG_PAGECACHE   7 /* void*, int sz, int N */
 
#define SQLITE_CONFIG_HEAP   8 /* void*, int nByte, int min */
 
#define SQLITE_CONFIG_MEMSTATUS   9 /* boolean */
 
#define SQLITE_CONFIG_MUTEX   10 /* sqlite3_mutex_methods* */
 
#define SQLITE_CONFIG_GETMUTEX   11 /* sqlite3_mutex_methods* */
 
#define SQLITE_CONFIG_LOOKASIDE   13 /* int int */
 
#define SQLITE_CONFIG_PCACHE   14 /* no-op */
 
#define SQLITE_CONFIG_GETPCACHE   15 /* no-op */
 
#define SQLITE_CONFIG_LOG   16 /* xFunc, void* */
 
#define SQLITE_CONFIG_URI   17 /* int */
 
#define SQLITE_CONFIG_PCACHE2   18 /* sqlite3_pcache_methods2* */
 
#define SQLITE_CONFIG_GETPCACHE2   19 /* sqlite3_pcache_methods2* */
 
#define SQLITE_CONFIG_COVERING_INDEX_SCAN   20 /* int */
 
#define SQLITE_CONFIG_SQLLOG   21 /* xSqllog, void* */
 
#define SQLITE_CONFIG_MMAP_SIZE   22 /* sqlite3_int64, sqlite3_int64 */
 
#define SQLITE_CONFIG_WIN32_HEAPSIZE   23 /* int nByte */
 
#define SQLITE_CONFIG_PCACHE_HDRSZ   24 /* int *psz */
 
#define SQLITE_CONFIG_PMASZ   25 /* unsigned int szPma */
 
#define SQLITE_CONFIG_STMTJRNL_SPILL   26 /* int nByte */
 
#define SQLITE_CONFIG_SMALL_MALLOC   27 /* boolean */
 
#define SQLITE_CONFIG_SORTERREF_SIZE   28 /* int nByte */
 
#define SQLITE_CONFIG_MEMDB_MAXSIZE   29 /* sqlite3_int64 */
 
#define SQLITE_DBCONFIG_MAINDBNAME   1000 /* const char* */
 
#define SQLITE_DBCONFIG_LOOKASIDE   1001 /* void* int int */
 
#define SQLITE_DBCONFIG_ENABLE_FKEY   1002 /* int int* */
 
#define SQLITE_DBCONFIG_ENABLE_TRIGGER   1003 /* int int* */
 
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER   1004 /* int int* */
 
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION   1005 /* int int* */
 
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE   1006 /* int int* */
 
#define SQLITE_DBCONFIG_ENABLE_QPSG   1007 /* int int* */
 
#define SQLITE_DBCONFIG_TRIGGER_EQP   1008 /* int int* */
 
#define SQLITE_DBCONFIG_RESET_DATABASE   1009 /* int int* */
 
#define SQLITE_DBCONFIG_DEFENSIVE   1010 /* int int* */
 
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA   1011 /* int int* */
 
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE   1012 /* int int* */
 
#define SQLITE_DBCONFIG_DQS_DML   1013 /* int int* */
 
#define SQLITE_DBCONFIG_DQS_DDL   1014 /* int int* */
 
#define SQLITE_DBCONFIG_ENABLE_VIEW   1015 /* int int* */
 
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT   1016 /* int int* */
 
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA   1017 /* int int* */
 
#define SQLITE_DBCONFIG_MAX   1017 /* Largest DBCONFIG */
 
#define SQLITE_DENY   1 /* Abort the SQL statement with an error */
 
#define SQLITE_IGNORE   2 /* Don't allow access, but don't generate an error */
 
#define SQLITE_CREATE_INDEX   1 /* Index Name Table Name */
 
#define SQLITE_CREATE_TABLE   2 /* Table Name NULL */
 
#define SQLITE_CREATE_TEMP_INDEX   3 /* Index Name Table Name */
 
#define SQLITE_CREATE_TEMP_TABLE   4 /* Table Name NULL */
 
#define SQLITE_CREATE_TEMP_TRIGGER   5 /* Trigger Name Table Name */
 
#define SQLITE_CREATE_TEMP_VIEW   6 /* View Name NULL */
 
#define SQLITE_CREATE_TRIGGER   7 /* Trigger Name Table Name */
 
#define SQLITE_CREATE_VIEW   8 /* View Name NULL */
 
#define SQLITE_DELETE   9 /* Table Name NULL */
 
#define SQLITE_DROP_INDEX   10 /* Index Name Table Name */
 
#define SQLITE_DROP_TABLE   11 /* Table Name NULL */
 
#define SQLITE_DROP_TEMP_INDEX   12 /* Index Name Table Name */
 
#define SQLITE_DROP_TEMP_TABLE   13 /* Table Name NULL */
 
#define SQLITE_DROP_TEMP_TRIGGER   14 /* Trigger Name Table Name */
 
#define SQLITE_DROP_TEMP_VIEW   15 /* View Name NULL */
 
#define SQLITE_DROP_TRIGGER   16 /* Trigger Name Table Name */
 
#define SQLITE_DROP_VIEW   17 /* View Name NULL */
 
#define SQLITE_INSERT   18 /* Table Name NULL */
 
#define SQLITE_PRAGMA   19 /* Pragma Name 1st arg or NULL */
 
#define SQLITE_READ   20 /* Table Name Column Name */
 
#define SQLITE_SELECT   21 /* NULL NULL */
 
#define SQLITE_TRANSACTION   22 /* Operation NULL */
 
#define SQLITE_UPDATE   23 /* Table Name Column Name */
 
#define SQLITE_ATTACH   24 /* Filename NULL */
 
#define SQLITE_DETACH   25 /* Database Name NULL */
 
#define SQLITE_ALTER_TABLE   26 /* Database Name Table Name */
 
#define SQLITE_REINDEX   27 /* Index Name NULL */
 
#define SQLITE_ANALYZE   28 /* Table Name NULL */
 
#define SQLITE_CREATE_VTABLE   29 /* Table Name Module Name */
 
#define SQLITE_DROP_VTABLE   30 /* Table Name Module Name */
 
#define SQLITE_FUNCTION   31 /* NULL Function Name */
 
#define SQLITE_SAVEPOINT   32 /* Operation Savepoint Name */
 
#define SQLITE_COPY   0 /* No longer used */
 
#define SQLITE_RECURSIVE   33 /* NULL NULL */
 
#define SQLITE_TRACE_STMT   0x01
 
#define SQLITE_TRACE_PROFILE   0x02
 
#define SQLITE_TRACE_ROW   0x04
 
#define SQLITE_TRACE_CLOSE   0x08
 
#define SQLITE_LIMIT_LENGTH   0
 
#define SQLITE_LIMIT_SQL_LENGTH   1
 
#define SQLITE_LIMIT_COLUMN   2
 
#define SQLITE_LIMIT_EXPR_DEPTH   3
 
#define SQLITE_LIMIT_COMPOUND_SELECT   4
 
#define SQLITE_LIMIT_VDBE_OP   5
 
#define SQLITE_LIMIT_FUNCTION_ARG   6
 
#define SQLITE_LIMIT_ATTACHED   7
 
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH   8
 
#define SQLITE_LIMIT_VARIABLE_NUMBER   9
 
#define SQLITE_LIMIT_TRIGGER_DEPTH   10
 
#define SQLITE_LIMIT_WORKER_THREADS   11
 
#define SQLITE_PREPARE_PERSISTENT   0x01
 
#define SQLITE_PREPARE_NORMALIZE   0x02
 
#define SQLITE_PREPARE_NO_VTAB   0x04
 
#define SQLITE_INTEGER   1
 
#define SQLITE_FLOAT   2
 
#define SQLITE_BLOB   4
 
#define SQLITE_NULL   5
 
#define SQLITE_TEXT   3
 
#define SQLITE3_TEXT   3
 
#define SQLITE_UTF8   1 /* IMP: R-37514-35566 */
 
#define SQLITE_UTF16LE   2 /* IMP: R-03371-37637 */
 
#define SQLITE_UTF16BE   3 /* IMP: R-51971-34154 */
 
#define SQLITE_UTF16   4 /* Use native byte order */
 
#define SQLITE_ANY   5 /* Deprecated */
 
#define SQLITE_UTF16_ALIGNED   8 /* sqlite3_create_collation only */
 
#define SQLITE_DETERMINISTIC   0x000000800
 
#define SQLITE_DIRECTONLY   0x000080000
 
#define SQLITE_SUBTYPE   0x000100000
 
#define SQLITE_INNOCUOUS   0x000200000
 
#define SQLITE_STATIC   ((sqlite3_destructor_type)0)
 
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
 
#define SQLITE_WIN32_DATA_DIRECTORY_TYPE   1
 
#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE   2
 
#define SQLITE_INDEX_SCAN_UNIQUE   1 /* Scan visits at most 1 row */
 
#define SQLITE_INDEX_CONSTRAINT_EQ   2
 
#define SQLITE_INDEX_CONSTRAINT_GT   4
 
#define SQLITE_INDEX_CONSTRAINT_LE   8
 
#define SQLITE_INDEX_CONSTRAINT_LT   16
 
#define SQLITE_INDEX_CONSTRAINT_GE   32
 
#define SQLITE_INDEX_CONSTRAINT_MATCH   64
 
#define SQLITE_INDEX_CONSTRAINT_LIKE   65
 
#define SQLITE_INDEX_CONSTRAINT_GLOB   66
 
#define SQLITE_INDEX_CONSTRAINT_REGEXP   67
 
#define SQLITE_INDEX_CONSTRAINT_NE   68
 
#define SQLITE_INDEX_CONSTRAINT_ISNOT   69
 
#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL   70
 
#define SQLITE_INDEX_CONSTRAINT_ISNULL   71
 
#define SQLITE_INDEX_CONSTRAINT_IS   72
 
#define SQLITE_INDEX_CONSTRAINT_FUNCTION   150
 
#define SQLITE_MUTEX_FAST   0
 
#define SQLITE_MUTEX_RECURSIVE   1
 
#define SQLITE_MUTEX_STATIC_MAIN   2
 
#define SQLITE_MUTEX_STATIC_MEM   3 /* sqlite3_malloc() */
 
#define SQLITE_MUTEX_STATIC_MEM2   4 /* NOT USED */
 
#define SQLITE_MUTEX_STATIC_OPEN   4 /* sqlite3BtreeOpen() */
 
#define SQLITE_MUTEX_STATIC_PRNG   5 /* sqlite3_randomness() */
 
#define SQLITE_MUTEX_STATIC_LRU   6 /* lru page list */
 
#define SQLITE_MUTEX_STATIC_LRU2   7 /* NOT USED */
 
#define SQLITE_MUTEX_STATIC_PMEM   7 /* sqlite3PageMalloc() */
 
#define SQLITE_MUTEX_STATIC_APP1   8 /* For use by application */
 
#define SQLITE_MUTEX_STATIC_APP2   9 /* For use by application */
 
#define SQLITE_MUTEX_STATIC_APP3   10 /* For use by application */
 
#define SQLITE_MUTEX_STATIC_VFS1   11 /* For use by built-in VFS */
 
#define SQLITE_MUTEX_STATIC_VFS2   12 /* For use by extension VFS */
 
#define SQLITE_MUTEX_STATIC_VFS3   13 /* For use by application VFS */
 
#define SQLITE_MUTEX_STATIC_MASTER   2
 
#define SQLITE_TESTCTRL_FIRST   5
 
#define SQLITE_TESTCTRL_PRNG_SAVE   5
 
#define SQLITE_TESTCTRL_PRNG_RESTORE   6
 
#define SQLITE_TESTCTRL_PRNG_RESET   7 /* NOT USED */
 
#define SQLITE_TESTCTRL_BITVEC_TEST   8
 
#define SQLITE_TESTCTRL_FAULT_INSTALL   9
 
#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS   10
 
#define SQLITE_TESTCTRL_PENDING_BYTE   11
 
#define SQLITE_TESTCTRL_ASSERT   12
 
#define SQLITE_TESTCTRL_ALWAYS   13
 
#define SQLITE_TESTCTRL_RESERVE   14 /* NOT USED */
 
#define SQLITE_TESTCTRL_OPTIMIZATIONS   15
 
#define SQLITE_TESTCTRL_ISKEYWORD   16 /* NOT USED */
 
#define SQLITE_TESTCTRL_SCRATCHMALLOC   17 /* NOT USED */
 
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS   17
 
#define SQLITE_TESTCTRL_LOCALTIME_FAULT   18
 
#define SQLITE_TESTCTRL_EXPLAIN_STMT   19 /* NOT USED */
 
#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD   19
 
#define SQLITE_TESTCTRL_NEVER_CORRUPT   20
 
#define SQLITE_TESTCTRL_VDBE_COVERAGE   21
 
#define SQLITE_TESTCTRL_BYTEORDER   22
 
#define SQLITE_TESTCTRL_ISINIT   23
 
#define SQLITE_TESTCTRL_SORTER_MMAP   24
 
#define SQLITE_TESTCTRL_IMPOSTER   25
 
#define SQLITE_TESTCTRL_PARSER_COVERAGE   26
 
#define SQLITE_TESTCTRL_RESULT_INTREAL   27
 
#define SQLITE_TESTCTRL_PRNG_SEED   28
 
#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS   29
 
#define SQLITE_TESTCTRL_LAST   29 /* Largest TESTCTRL */
 
#define SQLITE_STATUS_MEMORY_USED   0
 
#define SQLITE_STATUS_PAGECACHE_USED   1
 
#define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
 
#define SQLITE_STATUS_SCRATCH_USED   3 /* NOT USED */
 
#define SQLITE_STATUS_SCRATCH_OVERFLOW   4 /* NOT USED */
 
#define SQLITE_STATUS_MALLOC_SIZE   5
 
#define SQLITE_STATUS_PARSER_STACK   6
 
#define SQLITE_STATUS_PAGECACHE_SIZE   7
 
#define SQLITE_STATUS_SCRATCH_SIZE   8 /* NOT USED */
 
#define SQLITE_STATUS_MALLOC_COUNT   9
 
#define SQLITE_DBSTATUS_LOOKASIDE_USED   0
 
#define SQLITE_DBSTATUS_CACHE_USED   1
 
#define SQLITE_DBSTATUS_SCHEMA_USED   2
 
#define SQLITE_DBSTATUS_STMT_USED   3
 
#define SQLITE_DBSTATUS_LOOKASIDE_HIT   4
 
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE   5
 
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL   6
 
#define SQLITE_DBSTATUS_CACHE_HIT   7
 
#define SQLITE_DBSTATUS_CACHE_MISS   8
 
#define SQLITE_DBSTATUS_CACHE_WRITE   9
 
#define SQLITE_DBSTATUS_DEFERRED_FKS   10
 
#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
 
#define SQLITE_DBSTATUS_CACHE_SPILL   12
 
#define SQLITE_DBSTATUS_MAX   12 /* Largest defined DBSTATUS */
 
#define SQLITE_STMTSTATUS_FULLSCAN_STEP   1
 
#define SQLITE_STMTSTATUS_SORT   2
 
#define SQLITE_STMTSTATUS_AUTOINDEX   3
 
#define SQLITE_STMTSTATUS_VM_STEP   4
 
#define SQLITE_STMTSTATUS_REPREPARE   5
 
#define SQLITE_STMTSTATUS_RUN   6
 
#define SQLITE_STMTSTATUS_MEMUSED   99
 
#define SQLITE_CHECKPOINT_PASSIVE   0 /* Do as much as possible w/o blocking */
 
#define SQLITE_CHECKPOINT_FULL   1 /* Wait for writers, then checkpoint */
 
#define SQLITE_CHECKPOINT_RESTART   2 /* Like FULL but wait for for readers */
 
#define SQLITE_CHECKPOINT_TRUNCATE   3 /* Like RESTART but also truncate WAL */
 
#define SQLITE_VTAB_CONSTRAINT_SUPPORT   1
 
#define SQLITE_VTAB_INNOCUOUS   2
 
#define SQLITE_VTAB_DIRECTONLY   3
 
#define SQLITE_ROLLBACK   1
 
#define SQLITE_FAIL   3
 
#define SQLITE_REPLACE   5
 
#define SQLITE_SCANSTAT_NLOOP   0
 
#define SQLITE_SCANSTAT_NVISIT   1
 
#define SQLITE_SCANSTAT_EST   2
 
#define SQLITE_SCANSTAT_NAME   3
 
#define SQLITE_SCANSTAT_EXPLAIN   4
 
#define SQLITE_SCANSTAT_SELECTID   5
 
#define SQLITE_SERIALIZE_NOCOPY   0x001 /* Do no memory allocations */
 
#define SQLITE_DESERIALIZE_FREEONCLOSE   1 /* Call sqlite3_free() on close */
 
#define SQLITE_DESERIALIZE_RESIZEABLE   2 /* Resize using sqlite3_realloc64() */
 
#define SQLITE_DESERIALIZE_READONLY   4 /* Database is read-only */
 
#define _SQLITE3RTREE_H_
 
#define NOT_WITHIN   0 /* Object completely outside of query region */
 
#define PARTLY_WITHIN   1 /* Object partially overlaps query region */
 
#define FULLY_WITHIN   2 /* Object fully contained within query region */
 
#define _FTS5_H
 
#define FTS5_TOKENIZE_QUERY   0x0001
 
#define FTS5_TOKENIZE_PREFIX   0x0002
 
#define FTS5_TOKENIZE_DOCUMENT   0x0004
 
#define FTS5_TOKENIZE_AUX   0x0008
 
#define FTS5_TOKEN_COLOCATED   0x0001 /* Same position as prev. token */
 
#define SQLITE_MAX_LENGTH   1000000000
 
#define SQLITE_MAX_COLUMN   2000
 
#define SQLITE_MAX_SQL_LENGTH   1000000000
 
#define SQLITE_MAX_EXPR_DEPTH   1000
 
#define SQLITE_MAX_COMPOUND_SELECT   500
 
#define SQLITE_MAX_VDBE_OP   250000000
 
#define SQLITE_MAX_FUNCTION_ARG   127
 
#define SQLITE_DEFAULT_CACHE_SIZE   -2000
 
#define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT   1000
 
#define SQLITE_MAX_ATTACHED   10
 
#define SQLITE_MAX_VARIABLE_NUMBER   32766
 
#define SQLITE_MAX_PAGE_SIZE   65536
 
#define SQLITE_DEFAULT_PAGE_SIZE   4096
 
#define SQLITE_MAX_DEFAULT_PAGE_SIZE   8192
 
#define SQLITE_MAX_PAGE_COUNT   1073741823
 
#define SQLITE_MAX_LIKE_PATTERN_LENGTH   50000
 
#define SQLITE_MAX_TRIGGER_DEPTH   1000
 
#define __has_extension(x)   0 /* compatibility with non-clang compilers */
 
#define AtomicLoad(PTR)   (*(PTR))
 
#define AtomicStore(PTR, VAL)   (*(PTR) = (VAL))
 
#define SQLITE_INT_TO_PTR(X)   ((void*)&((char*)0)[X])
 
#define SQLITE_PTR_TO_INT(X)   ((int)(((char*)X)-(char*)0))
 
#define SQLITE_NOINLINE
 
#define SQLITE_THREADSAFE   1 /* IMP: R-07272-22309 */
 
#define SQLITE_POWERSAFE_OVERWRITE   1
 
#define SQLITE_DEFAULT_MEMSTATUS   1
 
#define SQLITE_SYSTEM_MALLOC   1
 
#define SQLITE_MALLOC_SOFT_LIMIT   1024
 
#define _XOPEN_SOURCE   600
 
#define NDEBUG   1
 
#define testcase(X)
 
#define TESTONLY(X)
 
#define VVA_ONLY(X)
 
#define ALWAYS(X)   (X)
 
#define NEVER(X)   (X)
 
#define harmless(X)
 
#define OK_IF_ALWAYS_TRUE(X)   (X)
 
#define OK_IF_ALWAYS_FALSE(X)   (X)
 
#define ONLY_IF_REALLOC_STRESS(X)   (0)
 
#define OSTRACE(X)
 
#define IS_BIG_INT(X)   (((X)&~(i64)0xffffffff)!=0)
 
#define likely(X)   (X)
 
#define unlikely(X)   (X)
 
#define SQLITE_HASH_H
 
#define sqliteHashFirst(H)   ((H)->first)
 
#define sqliteHashNext(E)   ((E)->next)
 
#define sqliteHashData(E)   ((E)->data)
 
#define TK_SEMI   1
 
#define TK_EXPLAIN   2
 
#define TK_QUERY   3
 
#define TK_PLAN   4
 
#define TK_BEGIN   5
 
#define TK_TRANSACTION   6
 
#define TK_DEFERRED   7
 
#define TK_IMMEDIATE   8
 
#define TK_EXCLUSIVE   9
 
#define TK_COMMIT   10
 
#define TK_END   11
 
#define TK_ROLLBACK   12
 
#define TK_SAVEPOINT   13
 
#define TK_RELEASE   14
 
#define TK_TO   15
 
#define TK_TABLE   16
 
#define TK_CREATE   17
 
#define TK_IF   18
 
#define TK_NOT   19
 
#define TK_EXISTS   20
 
#define TK_TEMP   21
 
#define TK_LP   22
 
#define TK_RP   23
 
#define TK_AS   24
 
#define TK_WITHOUT   25
 
#define TK_COMMA   26
 
#define TK_ABORT   27
 
#define TK_ACTION   28
 
#define TK_AFTER   29
 
#define TK_ANALYZE   30
 
#define TK_ASC   31
 
#define TK_ATTACH   32
 
#define TK_BEFORE   33
 
#define TK_BY   34
 
#define TK_CASCADE   35
 
#define TK_CAST   36
 
#define TK_CONFLICT   37
 
#define TK_DATABASE   38
 
#define TK_DESC   39
 
#define TK_DETACH   40
 
#define TK_EACH   41
 
#define TK_FAIL   42
 
#define TK_OR   43
 
#define TK_AND   44
 
#define TK_IS   45
 
#define TK_MATCH   46
 
#define TK_LIKE_KW   47
 
#define TK_BETWEEN   48
 
#define TK_IN   49
 
#define TK_ISNULL   50
 
#define TK_NOTNULL   51
 
#define TK_NE   52
 
#define TK_EQ   53
 
#define TK_GT   54
 
#define TK_LE   55
 
#define TK_LT   56
 
#define TK_GE   57
 
#define TK_ESCAPE   58
 
#define TK_ID   59
 
#define TK_COLUMNKW   60
 
#define TK_DO   61
 
#define TK_FOR   62
 
#define TK_IGNORE   63
 
#define TK_INITIALLY   64
 
#define TK_INSTEAD   65
 
#define TK_NO   66
 
#define TK_KEY   67
 
#define TK_OF   68
 
#define TK_OFFSET   69
 
#define TK_PRAGMA   70
 
#define TK_RAISE   71
 
#define TK_RECURSIVE   72
 
#define TK_REPLACE   73
 
#define TK_RESTRICT   74
 
#define TK_ROW   75
 
#define TK_ROWS   76
 
#define TK_TRIGGER   77
 
#define TK_VACUUM   78
 
#define TK_VIEW   79
 
#define TK_VIRTUAL   80
 
#define TK_WITH   81
 
#define TK_NULLS   82
 
#define TK_FIRST   83
 
#define TK_LAST   84
 
#define TK_CURRENT   85
 
#define TK_FOLLOWING   86
 
#define TK_PARTITION   87
 
#define TK_PRECEDING   88
 
#define TK_RANGE   89
 
#define TK_UNBOUNDED   90
 
#define TK_EXCLUDE   91
 
#define TK_GROUPS   92
 
#define TK_OTHERS   93
 
#define TK_TIES   94
 
#define TK_GENERATED   95
 
#define TK_ALWAYS   96
 
#define TK_REINDEX   97
 
#define TK_RENAME   98
 
#define TK_CTIME_KW   99
 
#define TK_ANY   100
 
#define TK_BITAND   101
 
#define TK_BITOR   102
 
#define TK_LSHIFT   103
 
#define TK_RSHIFT   104
 
#define TK_PLUS   105
 
#define TK_MINUS   106
 
#define TK_STAR   107
 
#define TK_SLASH   108
 
#define TK_REM   109
 
#define TK_CONCAT   110
 
#define TK_COLLATE   111
 
#define TK_BITNOT   112
 
#define TK_ON   113
 
#define TK_INDEXED   114
 
#define TK_STRING   115
 
#define TK_JOIN_KW   116
 
#define TK_CONSTRAINT   117
 
#define TK_DEFAULT   118
 
#define TK_NULL   119
 
#define TK_PRIMARY   120
 
#define TK_UNIQUE   121
 
#define TK_CHECK   122
 
#define TK_REFERENCES   123
 
#define TK_AUTOINCR   124
 
#define TK_INSERT   125
 
#define TK_DELETE   126
 
#define TK_UPDATE   127
 
#define TK_SET   128
 
#define TK_DEFERRABLE   129
 
#define TK_FOREIGN   130
 
#define TK_DROP   131
 
#define TK_UNION   132
 
#define TK_ALL   133
 
#define TK_EXCEPT   134
 
#define TK_INTERSECT   135
 
#define TK_SELECT   136
 
#define TK_VALUES   137
 
#define TK_DISTINCT   138
 
#define TK_DOT   139
 
#define TK_FROM   140
 
#define TK_JOIN   141
 
#define TK_USING   142
 
#define TK_ORDER   143
 
#define TK_GROUP   144
 
#define TK_HAVING   145
 
#define TK_LIMIT   146
 
#define TK_WHERE   147
 
#define TK_INTO   148
 
#define TK_NOTHING   149
 
#define TK_FLOAT   150
 
#define TK_BLOB   151
 
#define TK_INTEGER   152
 
#define TK_VARIABLE   153
 
#define TK_CASE   154
 
#define TK_WHEN   155
 
#define TK_THEN   156
 
#define TK_ELSE   157
 
#define TK_INDEX   158
 
#define TK_ALTER   159
 
#define TK_ADD   160
 
#define TK_WINDOW   161
 
#define TK_OVER   162
 
#define TK_FILTER   163
 
#define TK_COLUMN   164
 
#define TK_AGG_FUNCTION   165
 
#define TK_AGG_COLUMN   166
 
#define TK_TRUEFALSE   167
 
#define TK_ISNOT   168
 
#define TK_FUNCTION   169
 
#define TK_UMINUS   170
 
#define TK_UPLUS   171
 
#define TK_TRUTH   172
 
#define TK_REGISTER   173
 
#define TK_VECTOR   174
 
#define TK_SELECT_COLUMN   175
 
#define TK_IF_NULL_ROW   176
 
#define TK_ASTERISK   177
 
#define TK_SPAN   178
 
#define TK_SPACE   179
 
#define TK_ILLEGAL   180
 
#define SQLITE_BIG_DBL   (1e99)
 
#define OMIT_TEMPDB   0
 
#define SQLITE_MAX_FILE_FORMAT   4
 
#define SQLITE_DEFAULT_FILE_FORMAT   4
 
#define SQLITE_DEFAULT_RECURSIVE_TRIGGERS   0
 
#define SQLITE_TEMP_STORE   1
 
#define SQLITE_MAX_WORKER_THREADS   8
 
#define SQLITE_DEFAULT_WORKER_THREADS   0
 
#define SQLITE_DEFAULT_PCACHE_INITSZ   20
 
#define SQLITE_DEFAULT_SORTERREF_SIZE   0x7fffffff
 
#define offsetof(STRUCTURE, FIELD)   ((int)((char*)&((STRUCTURE*)0)->FIELD))
 
#define MIN(A, B)   ((A)<(B)?(A):(B))
 
#define MAX(A, B)   ((A)>(B)?(A):(B))
 
#define SWAP(TYPE, A, B)   {TYPE t=A; A=B; B=t;}
 
#define SQLITE_ASCII   1
 
#define UINT32_TYPE   unsigned int
 
#define UINT16_TYPE   unsigned short int
 
#define INT16_TYPE   short int
 
#define UINT8_TYPE   unsigned char
 
#define INT8_TYPE   signed char
 
#define LONGDOUBLE_TYPE   long double
 
#define SQLITE_MAX_U32   ((((u64)1)<<32)-1)
 
#define SQLITE_PTRSIZE   8
 
#define SQLITE_WITHIN(P, S, E)   (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E)))
 
#define SQLITE_BYTEORDER   0
 
#define SQLITE_BIGENDIAN   (*(char *)(&sqlite3one)==0)
 
#define SQLITE_LITTLEENDIAN   (*(char *)(&sqlite3one)==1)
 
#define SQLITE_UTF16NATIVE   (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
 
#define LARGEST_INT64   (0xffffffff|(((i64)0x7fffffff)<<32))
 
#define LARGEST_UINT64   (0xffffffff|(((u64)0xffffffff)<<32))
 
#define SMALLEST_INT64   (((i64)-1) - LARGEST_INT64)
 
#define ROUND8(x)   (((x)+7)&~7)
 
#define ROUNDDOWN8(x)   ((x)&~7)
 
#define EIGHT_BYTE_ALIGNMENT(X)   ((((char*)(X) - (char*)0)&7)==0)
 
#define SQLITE_MAX_MMAP_SIZE   0
 
#define SQLITE_DEFAULT_MMAP_SIZE   0
 
#define SELECTTRACE_ENABLED   0
 
#define SELECTTRACE(K, P, S, X)
 
#define SELECTTRACE_ENABLED   0
 
#define DFLT_SCHEMA_TABLE   "sqlite_master"
 
#define DFLT_TEMP_SCHEMA_TABLE   "sqlite_temp_master"
 
#define ALT_SCHEMA_TABLE   "sqlite_schema"
 
#define ALT_TEMP_SCHEMA_TABLE   "sqlite_temp_schema"
 
#define SCHEMA_ROOT   1
 
#define SCHEMA_TABLE(x)    ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE)
 
#define ArraySize(X)   ((int)(sizeof(X)/sizeof(X[0])))
 
#define IsPowerOfTwo(X)   (((X)&((X)-1))==0)
 
#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)sqlite3OomFault)
 
#define SQLITE_WSD
 
#define GLOBAL(t, v)   v
 
#define sqlite3GlobalConfig   sqlite3Config
 
#define UNUSED_PARAMETER(x)   (void)(x)
 
#define UNUSED_PARAMETER2(x, y)   UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
 
#define BMS   ((int)(sizeof(Bitmask)*8))
 
#define MASKBIT(n)   (((Bitmask)1)<<(n))
 
#define MASKBIT64(n)   (((u64)1)<<(n))
 
#define MASKBIT32(n)   (((unsigned int)1)<<(n))
 
#define ALLBITS   ((Bitmask)-1)
 
#define SQLITE_PAGER_H
 
#define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT   -1
 
#define PAGER_MJ_PGNO(x)   ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
 
#define PAGER_OMIT_JOURNAL   0x0001 /* Do not use a rollback journal */
 
#define PAGER_MEMORY   0x0002 /* In-memory database */
 
#define PAGER_LOCKINGMODE_QUERY   -1
 
#define PAGER_LOCKINGMODE_NORMAL   0
 
#define PAGER_LOCKINGMODE_EXCLUSIVE   1
 
#define PAGER_JOURNALMODE_QUERY   (-1) /* Query the value of journalmode */
 
#define PAGER_JOURNALMODE_DELETE   0 /* Commit by deleting journal file */
 
#define PAGER_JOURNALMODE_PERSIST   1 /* Commit by zeroing journal header */
 
#define PAGER_JOURNALMODE_OFF   2 /* Journal omitted. */
 
#define PAGER_JOURNALMODE_TRUNCATE   3 /* Commit by truncating journal */
 
#define PAGER_JOURNALMODE_MEMORY   4 /* In-memory journal file */
 
#define PAGER_JOURNALMODE_WAL   5 /* Use write-ahead logging */
 
#define PAGER_GET_NOCONTENT   0x01 /* Do not load data from disk */
 
#define PAGER_GET_READONLY   0x02 /* Read-only page is acceptable */
 
#define PAGER_SYNCHRONOUS_OFF   0x01 /* PRAGMA synchronous=OFF */
 
#define PAGER_SYNCHRONOUS_NORMAL   0x02 /* PRAGMA synchronous=NORMAL */
 
#define PAGER_SYNCHRONOUS_FULL   0x03 /* PRAGMA synchronous=FULL */
 
#define PAGER_SYNCHRONOUS_EXTRA   0x04 /* PRAGMA synchronous=EXTRA */
 
#define PAGER_SYNCHRONOUS_MASK   0x07 /* Mask for four values above */
 
#define PAGER_FULLFSYNC   0x08 /* PRAGMA fullfsync=ON */
 
#define PAGER_CKPT_FULLFSYNC   0x10 /* PRAGMA checkpoint_fullfsync=ON */
 
#define PAGER_CACHESPILL   0x20 /* PRAGMA cache_spill=ON */
 
#define PAGER_FLAGS_MASK   0x38 /* All above except SYNCHRONOUS */
 
#define sqlite3PagerWalWriteLock(y, z)   SQLITE_OK
 
#define sqlite3PagerWalDb(x, y)
 
#define disable_simulated_io_errors()
 
#define enable_simulated_io_errors()
 
#define SQLITE_BTREE_H
 
#define SQLITE_N_BTREE_META   16
 
#define SQLITE_DEFAULT_AUTOVACUUM   0
 
#define BTREE_AUTOVACUUM_NONE   0 /* Do not do auto-vacuum */
 
#define BTREE_AUTOVACUUM_FULL   1 /* Do full auto-vacuum */
 
#define BTREE_AUTOVACUUM_INCR   2 /* Incremental vacuum */
 
#define BTREE_OMIT_JOURNAL   1 /* Do not create or use a rollback journal */
 
#define BTREE_MEMORY   2 /* This is an in-memory DB */
 
#define BTREE_SINGLE   4 /* The file contains at most 1 b-tree */
 
#define BTREE_UNORDERED   8 /* Use of a hash implementation is OK */
 
#define BTREE_INTKEY   1 /* Table has only 64-bit signed integer keys */
 
#define BTREE_BLOBKEY   2 /* Table has keys only - no data */
 
#define BTREE_FREE_PAGE_COUNT   0
 
#define BTREE_SCHEMA_VERSION   1
 
#define BTREE_FILE_FORMAT   2
 
#define BTREE_DEFAULT_CACHE_SIZE   3
 
#define BTREE_LARGEST_ROOT_PAGE   4
 
#define BTREE_TEXT_ENCODING   5
 
#define BTREE_USER_VERSION   6
 
#define BTREE_INCR_VACUUM   7
 
#define BTREE_APPLICATION_ID   8
 
#define BTREE_DATA_VERSION   15 /* A virtual meta-value */
 
#define BTREE_HINT_RANGE   0 /* Range constraints on queries */
 
#define BTREE_BULKLOAD   0x00000001 /* Used to full index in sorted order */
 
#define BTREE_SEEK_EQ   0x00000002 /* EQ seeks only - no range seeks */
 
#define BTREE_WRCSR   0x00000004 /* read-write cursor */
 
#define BTREE_FORDELETE   0x00000008 /* Cursor is for seek/delete only */
 
#define BTREE_SAVEPOSITION   0x02 /* Leave cursor pointing at NEXT or PREV */
 
#define BTREE_AUXDELETE   0x04 /* not the primary delete operation */
 
#define BTREE_APPEND   0x08 /* Insert is likely an append */
 
#define SQLITE_VDBE_H
 
#define P4_NOTUSED   0 /* The P4 parameter is not used */
 
#define P4_TRANSIENT   0 /* P4 is a pointer to a transient string */
 
#define P4_STATIC   (-1) /* Pointer to a static string */
 
#define P4_COLLSEQ   (-2) /* P4 is a pointer to a CollSeq structure */
 
#define P4_INT32   (-3) /* P4 is a 32-bit signed integer */
 
#define P4_SUBPROGRAM   (-4) /* P4 is a pointer to a SubProgram structure */
 
#define P4_ADVANCE   (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */
 
#define P4_TABLE   (-6) /* P4 is a pointer to a Table structure */
 
#define P4_FREE_IF_LE   (-7)
 
#define P4_DYNAMIC   (-7) /* Pointer to memory from sqliteMalloc() */
 
#define P4_FUNCDEF   (-8) /* P4 is a pointer to a FuncDef structure */
 
#define P4_KEYINFO   (-9) /* P4 is a pointer to a KeyInfo structure */
 
#define P4_EXPR   (-10) /* P4 is a pointer to an Expr tree */
 
#define P4_MEM   (-11) /* P4 is a pointer to a Mem* structure */
 
#define P4_VTAB   (-12) /* P4 is a pointer to an sqlite3_vtab structure */
 
#define P4_REAL   (-13) /* P4 is a 64-bit floating point value */
 
#define P4_INT64   (-14) /* P4 is a 64-bit signed integer */
 
#define P4_INTARRAY   (-15) /* P4 is a vector of 32-bit integers */
 
#define P4_FUNCCTX   (-16) /* P4 is a pointer to an sqlite3_context object */
 
#define P4_DYNBLOB   (-17) /* Pointer to memory from sqliteMalloc() */
 
#define P5_ConstraintNotNull   1
 
#define P5_ConstraintUnique   2
 
#define P5_ConstraintCheck   3
 
#define P5_ConstraintFK   4
 
#define COLNAME_NAME   0
 
#define COLNAME_DECLTYPE   1
 
#define COLNAME_DATABASE   2
 
#define COLNAME_TABLE   3
 
#define COLNAME_COLUMN   4
 
#define COLNAME_N   2 /* Store the name and decltype */
 
#define ADDR(X)   (~(X))
 
#define OP_Savepoint   0
 
#define OP_AutoCommit   1
 
#define OP_Transaction   2
 
#define OP_SorterNext   3 /* jump */
 
#define OP_Prev   4 /* jump */
 
#define OP_Next   5 /* jump */
 
#define OP_Checkpoint   6
 
#define OP_JournalMode   7
 
#define OP_Vacuum   8
 
#define OP_VFilter   9 /* jump, synopsis: iplan=r[P3] zplan='P4' */
 
#define OP_VUpdate   10 /* synopsis: data=r[P3@P2] */
 
#define OP_Goto   11 /* jump */
 
#define OP_Gosub   12 /* jump */
 
#define OP_InitCoroutine   13 /* jump */
 
#define OP_Yield   14 /* jump */
 
#define OP_MustBeInt   15 /* jump */
 
#define OP_Jump   16 /* jump */
 
#define OP_Once   17 /* jump */
 
#define OP_If   18 /* jump */
 
#define OP_Not   19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
 
#define OP_IfNot   20 /* jump */
 
#define OP_IfNullRow   21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
 
#define OP_SeekLT   22 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_SeekLE   23 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_SeekGE   24 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_SeekGT   25 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_IfNotOpen   26 /* jump, synopsis: if( !csr[P1] ) goto P2 */
 
#define OP_IfNoHope   27 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_NoConflict   28 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_NotFound   29 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_Found   30 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_SeekRowid   31 /* jump, synopsis: intkey=r[P3] */
 
#define OP_NotExists   32 /* jump, synopsis: intkey=r[P3] */
 
#define OP_Last   33 /* jump */
 
#define OP_IfSmaller   34 /* jump */
 
#define OP_SorterSort   35 /* jump */
 
#define OP_Sort   36 /* jump */
 
#define OP_Rewind   37 /* jump */
 
#define OP_IdxLE   38 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_IdxGT   39 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_IdxLT   40 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_IdxGE   41 /* jump, synopsis: key=r[P3@P4] */
 
#define OP_RowSetRead   42 /* jump, synopsis: r[P3]=rowset(P1) */
 
#define OP_Or   43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 
#define OP_And   44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 
#define OP_RowSetTest   45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
 
#define OP_Program   46 /* jump */
 
#define OP_FkIfZero   47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
 
#define OP_IfPos   48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 
#define OP_IfNotZero   49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
 
#define OP_IsNull   50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 
#define OP_NotNull   51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 
#define OP_Ne   52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
 
#define OP_Eq   53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
 
#define OP_Gt   54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
 
#define OP_Le   55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
 
#define OP_Lt   56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
 
#define OP_Ge   57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
 
#define OP_ElseNotEq   58 /* jump, same as TK_ESCAPE */
 
#define OP_DecrJumpZero   59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
 
#define OP_IncrVacuum   60 /* jump */
 
#define OP_VNext   61 /* jump */
 
#define OP_Init   62 /* jump, synopsis: Start at P2 */
 
#define OP_PureFunc   63 /* synopsis: r[P3]=func(r[P2@NP]) */
 
#define OP_Function   64 /* synopsis: r[P3]=func(r[P2@NP]) */
 
#define OP_Return   65
 
#define OP_EndCoroutine   66
 
#define OP_HaltIfNull   67 /* synopsis: if r[P3]=null halt */
 
#define OP_Halt   68
 
#define OP_Integer   69 /* synopsis: r[P2]=P1 */
 
#define OP_Int64   70 /* synopsis: r[P2]=P4 */
 
#define OP_String   71 /* synopsis: r[P2]='P4' (len=P1) */
 
#define OP_Null   72 /* synopsis: r[P2..P3]=NULL */
 
#define OP_SoftNull   73 /* synopsis: r[P1]=NULL */
 
#define OP_Blob   74 /* synopsis: r[P2]=P4 (len=P1) */
 
#define OP_Variable   75 /* synopsis: r[P2]=parameter(P1,P4) */
 
#define OP_Move   76 /* synopsis: r[P2@P3]=r[P1@P3] */
 
#define OP_Copy   77 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
 
#define OP_SCopy   78 /* synopsis: r[P2]=r[P1] */
 
#define OP_IntCopy   79 /* synopsis: r[P2]=r[P1] */
 
#define OP_ResultRow   80 /* synopsis: output=r[P1@P2] */
 
#define OP_CollSeq   81
 
#define OP_AddImm   82 /* synopsis: r[P1]=r[P1]+P2 */
 
#define OP_RealAffinity   83
 
#define OP_Cast   84 /* synopsis: affinity(r[P1]) */
 
#define OP_Permutation   85
 
#define OP_Compare   86 /* synopsis: r[P1@P3] <-> r[P2@P3] */
 
#define OP_IsTrue   87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
 
#define OP_Offset   88 /* synopsis: r[P3] = sqlite_offset(P1) */
 
#define OP_Column   89 /* synopsis: r[P3]=PX */
 
#define OP_Affinity   90 /* synopsis: affinity(r[P1@P2]) */
 
#define OP_MakeRecord   91 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
 
#define OP_Count   92 /* synopsis: r[P2]=count() */
 
#define OP_ReadCookie   93
 
#define OP_SetCookie   94
 
#define OP_ReopenIdx   95 /* synopsis: root=P2 iDb=P3 */
 
#define OP_OpenRead   96 /* synopsis: root=P2 iDb=P3 */
 
#define OP_OpenWrite   97 /* synopsis: root=P2 iDb=P3 */
 
#define OP_OpenDup   98
 
#define OP_OpenAutoindex   99 /* synopsis: nColumn=P2 */
 
#define OP_OpenEphemeral   100 /* synopsis: nColumn=P2 */
 
#define OP_BitAnd   101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 
#define OP_BitOr   102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 
#define OP_ShiftLeft   103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 
#define OP_ShiftRight   104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 
#define OP_Add   105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 
#define OP_Subtract   106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 
#define OP_Multiply   107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 
#define OP_Divide   108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 
#define OP_Remainder   109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 
#define OP_Concat   110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 
#define OP_SorterOpen   111
 
#define OP_BitNot   112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
 
#define OP_SequenceTest   113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
 
#define OP_OpenPseudo   114 /* synopsis: P3 columns in r[P2] */
 
#define OP_String8   115 /* same as TK_STRING, synopsis: r[P2]='P4' */
 
#define OP_Close   116
 
#define OP_ColumnsUsed   117
 
#define OP_SeekHit   118 /* synopsis: seekHit=P2 */
 
#define OP_Sequence   119 /* synopsis: r[P2]=cursor[P1].ctr++ */
 
#define OP_NewRowid   120 /* synopsis: r[P2]=rowid */
 
#define OP_Insert   121 /* synopsis: intkey=r[P3] data=r[P2] */
 
#define OP_Delete   122
 
#define OP_ResetCount   123
 
#define OP_SorterCompare   124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 
#define OP_SorterData   125 /* synopsis: r[P2]=data */
 
#define OP_RowData   126 /* synopsis: r[P2]=data */
 
#define OP_Rowid   127 /* synopsis: r[P2]=rowid */
 
#define OP_NullRow   128
 
#define OP_SeekEnd   129
 
#define OP_IdxInsert   130 /* synopsis: key=r[P2] */
 
#define OP_SorterInsert   131 /* synopsis: key=r[P2] */
 
#define OP_IdxDelete   132 /* synopsis: key=r[P2@P3] */
 
#define OP_DeferredSeek   133 /* synopsis: Move P3 to P1.rowid if needed */
 
#define OP_IdxRowid   134 /* synopsis: r[P2]=rowid */
 
#define OP_FinishSeek   135
 
#define OP_Destroy   136
 
#define OP_Clear   137
 
#define OP_ResetSorter   138
 
#define OP_CreateBtree   139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
 
#define OP_SqlExec   140
 
#define OP_ParseSchema   141
 
#define OP_LoadAnalysis   142
 
#define OP_DropTable   143
 
#define OP_DropIndex   144
 
#define OP_DropTrigger   145
 
#define OP_IntegrityCk   146
 
#define OP_RowSetAdd   147 /* synopsis: rowset(P1)=r[P2] */
 
#define OP_Param   148
 
#define OP_FkCounter   149 /* synopsis: fkctr[P1]+=P2 */
 
#define OP_Real   150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
 
#define OP_MemMax   151 /* synopsis: r[P1]=max(r[P1],r[P2]) */
 
#define OP_OffsetLimit   152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 
#define OP_AggInverse   153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
 
#define OP_AggStep   154 /* synopsis: accum=r[P3] step(r[P2@P5]) */
 
#define OP_AggStep1   155 /* synopsis: accum=r[P3] step(r[P2@P5]) */
 
#define OP_AggValue   156 /* synopsis: r[P3]=value N=P2 */
 
#define OP_AggFinal   157 /* synopsis: accum=r[P1] N=P2 */
 
#define OP_Expire   158
 
#define OP_CursorLock   159
 
#define OP_CursorUnlock   160
 
#define OP_TableLock   161 /* synopsis: iDb=P1 root=P2 write=P3 */
 
#define OP_VBegin   162
 
#define OP_VCreate   163
 
#define OP_VDestroy   164
 
#define OP_VOpen   165
 
#define OP_VColumn   166 /* synopsis: r[P3]=vcolumn(P2) */
 
#define OP_VRename   167
 
#define OP_Pagecount   168
 
#define OP_MaxPgcnt   169
 
#define OP_Trace   170
 
#define OP_CursorHint   171
 
#define OP_ReleaseReg   172 /* synopsis: release r[P1@P2] mask P3 */
 
#define OP_Noop   173
 
#define OP_Explain   174
 
#define OP_Abortable   175
 
#define OPFLG_JUMP   0x01 /* jump: P2 holds jmp target */
 
#define OPFLG_IN1   0x02 /* in1: P1 is an input */
 
#define OPFLG_IN2   0x04 /* in2: P2 is an input */
 
#define OPFLG_IN3   0x08 /* in3: P3 is an input */
 
#define OPFLG_OUT2   0x10 /* out2: P2 is an output */
 
#define OPFLG_OUT3   0x20 /* out3: P3 is an output */
 
#define OPFLG_INITIALIZER
 
#define SQLITE_MX_JUMP_OPCODE   62 /* Maximum JUMP opcode */
 
#define SQLITE_PREPARE_SAVESQL   0x80 /* Preserve SQL text */
 
#define SQLITE_PREPARE_MASK   0x0f /* Mask of public flags */
 
#define sqlite3VdbeVerifyNoMallocRequired(A, B)
 
#define sqlite3VdbeVerifyNoResultRow(A)
 
#define sqlite3VdbeVerifyAbortable(A, B)
 
#define ExplainQueryPlan(P)   sqlite3VdbeExplain P
 
#define ExplainQueryPlanPop(P)   sqlite3VdbeExplainPop(P)
 
#define ExplainQueryPlanParent(P)   sqlite3VdbeExplainParent(P)
 
#define sqlite3ExplainBreakpoint(A, B)   /*no-op*/
 
#define sqlite3VdbeReleaseRegisters(P, A, N, M, F)
 
#define VdbeComment(X)
 
#define VdbeNoopComment(X)
 
#define VdbeModuleComment(X)
 
#define VdbeCoverage(v)
 
#define VdbeCoverageIf(v, x)
 
#define VdbeCoverageAlwaysTaken(v)
 
#define VdbeCoverageNeverTaken(v)
 
#define VdbeCoverageNeverNull(v)
 
#define VdbeCoverageNeverNullIf(v, x)
 
#define VdbeCoverageEqNe(v)
 
#define VDBE_OFFSET_LINENO(x)   0
 
#define sqlite3VdbeScanStatus(a, b, c, d, e)
 
#define PGHDR_CLEAN   0x001 /* Page not on the PCache.pDirty list */
 
#define PGHDR_DIRTY   0x002 /* Page is on the PCache.pDirty list */
 
#define PGHDR_WRITEABLE   0x004 /* Journaled and ready to modify */
 
#define PGHDR_NEED_SYNC
 
#define PGHDR_DONT_WRITE   0x010 /* Do not write content to disk */
 
#define PGHDR_MMAP   0x020 /* This is an mmap page object */
 
#define PGHDR_WAL_APPEND   0x040 /* Appended to wal file */
 
#define _SQLITE_OS_H_
 
#define SQLITE_OS_SETUP_H
 
#define SQLITE_OS_OTHER   0
 
#define SQLITE_OS_WIN   0
 
#define SQLITE_OS_UNIX   1
 
#define SET_FULLSYNC(x, y)
 
#define SQLITE_DEFAULT_SECTOR_SIZE   4096
 
#define SQLITE_TEMP_FILE_PREFIX   "etilqs_"
 
#define NO_LOCK   0
 
#define SHARED_LOCK   1
 
#define RESERVED_LOCK   2
 
#define PENDING_LOCK   3
 
#define EXCLUSIVE_LOCK   4
 
#define PENDING_BYTE   sqlite3PendingByte
 
#define RESERVED_BYTE   (PENDING_BYTE+1)
 
#define SHARED_FIRST   (PENDING_BYTE+2)
 
#define SHARED_SIZE   510
 
#define SQLITE_FCNTL_DB_UNCHANGED   0xca093fa0
 
#define SQLITE_MUTEX_PTHREADS
 
#define MUTEX_LOGIC(X)   X
 
#define SQLITE_DEFAULT_SYNCHRONOUS   2
 
#define SQLITE_DEFAULT_WAL_SYNCHRONOUS   SQLITE_DEFAULT_SYNCHRONOUS
 
#define DbHasProperty(D, I, P)   (((D)->aDb[I].pSchema->schemaFlags&(P))==(P))
 
#define DbHasAnyProperty(D, I, P)   (((D)->aDb[I].pSchema->schemaFlags&(P))!=0)
 
#define DbSetProperty(D, I, P)   (D)->aDb[I].pSchema->schemaFlags|=(P)
 
#define DbClearProperty(D, I, P)   (D)->aDb[I].pSchema->schemaFlags&=~(P)
 
#define DB_SchemaLoaded   0x0001 /* The schema has been loaded */
 
#define DB_UnresetViews   0x0002 /* Some views have defined column names */
 
#define DB_ResetWanted   0x0008 /* Reset the schema when nSchemaLock==0 */
 
#define SQLITE_N_LIMIT   (SQLITE_LIMIT_WORKER_THREADS+1)
 
#define DisableLookaside   db->lookaside.bDisable++;db->lookaside.sz=0
 
#define EnableLookaside
 
#define LOOKASIDE_SMALL   128
 
#define SQLITE_FUNC_HASH_SZ   23
 
#define SQLITE_FUNC_HASH(C, L)   (((C)+(L))%SQLITE_FUNC_HASH_SZ)
 
#define SQLITE_TRACE_LEGACY   0x40 /* Use the legacy xTrace */
 
#define SQLITE_TRACE_XPROFILE   0x80 /* Use the legacy xProfile */
 
#define SQLITE_TRACE_NONLEGACY_MASK   0x0f /* Normal flags */
 
#define SCHEMA_ENC(db)   ((db)->aDb[0].pSchema->enc)
 
#define ENC(db)   ((db)->enc)
 
#define HI(X)   ((u64)(X)<<32)
 
#define SQLITE_WriteSchema   0x00000001 /* OK to update SQLITE_SCHEMA */
 
#define SQLITE_LegacyFileFmt   0x00000002 /* Create new databases in format 1 */
 
#define SQLITE_FullColNames   0x00000004 /* Show full column names on SELECT */
 
#define SQLITE_FullFSync   0x00000008 /* Use full fsync on the backend */
 
#define SQLITE_CkptFullFSync   0x00000010 /* Use full fsync for checkpoint */
 
#define SQLITE_CacheSpill   0x00000020 /* OK to spill pager cache */
 
#define SQLITE_ShortColNames   0x00000040 /* Show short columns names */
 
#define SQLITE_TrustedSchema
 
#define SQLITE_NullCallback   0x00000100 /* Invoke the callback once if the */
 
#define SQLITE_IgnoreChecks   0x00000200 /* Do not enforce check constraints */
 
#define SQLITE_ReadUncommit   0x00000400 /* READ UNCOMMITTED in shared-cache */
 
#define SQLITE_NoCkptOnClose   0x00000800 /* No checkpoint on close()/DETACH */
 
#define SQLITE_ReverseOrder   0x00001000 /* Reverse unordered SELECTs */
 
#define SQLITE_RecTriggers   0x00002000 /* Enable recursive triggers */
 
#define SQLITE_ForeignKeys   0x00004000 /* Enforce foreign key constraints */
 
#define SQLITE_AutoIndex   0x00008000 /* Enable automatic indexes */
 
#define SQLITE_LoadExtension   0x00010000 /* Enable load_extension */
 
#define SQLITE_LoadExtFunc   0x00020000 /* Enable load_extension() SQL func */
 
#define SQLITE_EnableTrigger   0x00040000 /* True to enable triggers */
 
#define SQLITE_DeferFKs   0x00080000 /* Defer all FK constraints */
 
#define SQLITE_QueryOnly   0x00100000 /* Disable database changes */
 
#define SQLITE_CellSizeCk   0x00200000 /* Check btree cell sizes on load */
 
#define SQLITE_Fts3Tokenizer   0x00400000 /* Enable fts3_tokenizer(2) */
 
#define SQLITE_EnableQPSG   0x00800000 /* Query Planner Stability Guarantee*/
 
#define SQLITE_TriggerEQP   0x01000000 /* Show trigger EXPLAIN QUERY PLAN */
 
#define SQLITE_ResetDatabase   0x02000000 /* Reset the database */
 
#define SQLITE_LegacyAlter   0x04000000 /* Legacy ALTER TABLE behaviour */
 
#define SQLITE_NoSchemaError   0x08000000 /* Do not report schema parse errors*/
 
#define SQLITE_Defensive   0x10000000 /* Input SQL is likely hostile */
 
#define SQLITE_DqsDDL   0x20000000 /* dbl-quoted strings allowed in DDL*/
 
#define SQLITE_DqsDML   0x40000000 /* dbl-quoted strings allowed in DML*/
 
#define SQLITE_EnableView   0x80000000 /* Enable the use of views */
 
#define SQLITE_CountRows   HI(0x00001) /* Count rows changed by INSERT, */
 
#define DBFLAG_SchemaChange   0x0001 /* Uncommitted Hash table changes */
 
#define DBFLAG_PreferBuiltin   0x0002 /* Preference to built-in funcs */
 
#define DBFLAG_Vacuum   0x0004 /* Currently in a VACUUM */
 
#define DBFLAG_VacuumInto   0x0008 /* Currently running VACUUM INTO */
 
#define DBFLAG_SchemaKnownOk   0x0010 /* Schema is known to be valid */
 
#define DBFLAG_InternalFunc   0x0020 /* Allow use of internal functions */
 
#define DBFLAG_EncodingFixed   0x0040 /* No longer possible to change enc. */
 
#define SQLITE_QueryFlattener   0x0001 /* Query flattening */
 
#define SQLITE_WindowFunc   0x0002 /* Use xInverse for window functions */
 
#define SQLITE_GroupByOrder   0x0004 /* GROUPBY cover of ORDERBY */
 
#define SQLITE_FactorOutConst   0x0008 /* Constant factoring */
 
#define SQLITE_DistinctOpt   0x0010 /* DISTINCT using indexes */
 
#define SQLITE_CoverIdxScan   0x0020 /* Covering index scans */
 
#define SQLITE_OrderByIdxJoin   0x0040 /* ORDER BY of joins via index */
 
#define SQLITE_Transitive   0x0080 /* Transitive constraints */
 
#define SQLITE_OmitNoopJoin   0x0100 /* Omit unused tables in joins */
 
#define SQLITE_CountOfView   0x0200 /* The count-of-view optimization */
 
#define SQLITE_CursorHints   0x0400 /* Add OP_CursorHint opcodes */
 
#define SQLITE_Stat4   0x0800 /* Use STAT4 data */
 
#define SQLITE_PushDown   0x1000 /* The push-down optimization */
 
#define SQLITE_SimplifyJoin   0x2000 /* Convert LEFT JOIN to JOIN */
 
#define SQLITE_SkipScan   0x4000 /* Skip-scans */
 
#define SQLITE_PropagateConst   0x8000 /* The constant propagation opt */
 
#define SQLITE_AllOpts   0xffff /* All optimizations */
 
#define OptimizationDisabled(db, mask)   (((db)->dbOptFlags&(mask))!=0)
 
#define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
 
#define ConstFactorOk(P)   ((P)->okConstFactor)
 
#define SQLITE_MAGIC_OPEN   0xa029a697 /* Database is open */
 
#define SQLITE_MAGIC_CLOSED   0x9f3c2d33 /* Database is closed */
 
#define SQLITE_MAGIC_SICK   0x4b771290 /* Error and awaiting close */
 
#define SQLITE_MAGIC_BUSY   0xf03b7906 /* Database currently in use */
 
#define SQLITE_MAGIC_ERROR   0xb5357930 /* An SQLITE_MISUSE error occurred */
 
#define SQLITE_MAGIC_ZOMBIE   0x64cffc7f /* Close with last statement close */
 
#define SQLITE_FUNC_ENCMASK   0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
 
#define SQLITE_FUNC_LIKE   0x0004 /* Candidate for the LIKE optimization */
 
#define SQLITE_FUNC_CASE   0x0008 /* Case-sensitive LIKE-type function */
 
#define SQLITE_FUNC_EPHEM   0x0010 /* Ephemeral. Delete with VDBE */
 
#define SQLITE_FUNC_NEEDCOLL   0x0020 /* sqlite3GetFuncCollSeq() might be called*/
 
#define SQLITE_FUNC_LENGTH   0x0040 /* Built-in length() function */
 
#define SQLITE_FUNC_TYPEOF   0x0080 /* Built-in typeof() function */
 
#define SQLITE_FUNC_COUNT   0x0100 /* Built-in count(*) aggregate */
 
#define SQLITE_FUNC_UNLIKELY   0x0400 /* Built-in unlikely() function */
 
#define SQLITE_FUNC_CONSTANT   0x0800 /* Constant inputs give a constant output */
 
#define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
 
#define SQLITE_FUNC_SLOCHNG
 
#define SQLITE_FUNC_TEST   0x4000 /* Built-in testing functions */
 
#define SQLITE_FUNC_OFFSET   0x8000 /* Built-in sqlite_offset() function */
 
#define SQLITE_FUNC_WINDOW   0x00010000 /* Built-in window-only function */
 
#define SQLITE_FUNC_INTERNAL   0x00040000 /* For use by NestedParse() only */
 
#define SQLITE_FUNC_DIRECT   0x00080000 /* Not for use in TRIGGERs or VIEWs */
 
#define SQLITE_FUNC_SUBTYPE   0x00100000 /* Result likely to have sub-type */
 
#define SQLITE_FUNC_UNSAFE   0x00200000 /* Function has side effects */
 
#define SQLITE_FUNC_INLINE   0x00400000 /* Functions implemented in-line */
 
#define INLINEFUNC_coalesce   0
 
#define INLINEFUNC_implies_nonnull_row   1
 
#define INLINEFUNC_expr_implies_expr   2
 
#define INLINEFUNC_expr_compare   3
 
#define INLINEFUNC_affinity   4
 
#define INLINEFUNC_iif   5
 
#define INLINEFUNC_unlikely   99 /* Default case */
 
#define FUNCTION(zName, nArg, iArg, bNC, xFunc)
 
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc)
 
#define SFUNCTION(zName, nArg, iArg, bNC, xFunc)
 
#define INLINE_FUNC(zName, nArg, iArg, mFlags)
 
#define TEST_FUNC(zName, nArg, iArg, mFlags)
 
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc)
 
#define PURE_DATE(zName, nArg, iArg, bNC, xFunc)
 
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags)
 
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc)
 
#define LIKEFUNC(zName, nArg, arg, flags)
 
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f)
 
#define INTERNAL_FUNCTION(zName, nArg, xFunc)
 
#define SAVEPOINT_BEGIN   0
 
#define SAVEPOINT_RELEASE   1
 
#define SAVEPOINT_ROLLBACK   2
 
#define COLFLAG_PRIMKEY   0x0001 /* Column is part of the primary key */
 
#define COLFLAG_HIDDEN   0x0002 /* A hidden column in a virtual table */
 
#define COLFLAG_HASTYPE   0x0004 /* Type name follows column name */
 
#define COLFLAG_UNIQUE   0x0008 /* Column def contains "UNIQUE" or "PK" */
 
#define COLFLAG_SORTERREF   0x0010 /* Use sorter-refs with this column */
 
#define COLFLAG_VIRTUAL   0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
 
#define COLFLAG_STORED   0x0040 /* GENERATED ALWAYS AS ... STORED */
 
#define COLFLAG_NOTAVAIL   0x0080 /* STORED column not yet calculated */
 
#define COLFLAG_BUSY   0x0100 /* Blocks recursion on GENERATED columns */
 
#define COLFLAG_GENERATED   0x0060 /* Combo: _STORED, _VIRTUAL */
 
#define COLFLAG_NOINSERT   0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
 
#define SQLITE_SO_ASC   0 /* Sort in ascending order */
 
#define SQLITE_SO_DESC   1 /* Sort in ascending order */
 
#define SQLITE_SO_UNDEFINED   -1 /* No sort order specified */
 
#define SQLITE_AFF_NONE   0x40 /* '@' */
 
#define SQLITE_AFF_BLOB   0x41 /* 'A' */
 
#define SQLITE_AFF_TEXT   0x42 /* 'B' */
 
#define SQLITE_AFF_NUMERIC   0x43 /* 'C' */
 
#define SQLITE_AFF_INTEGER   0x44 /* 'D' */
 
#define SQLITE_AFF_REAL   0x45 /* 'E' */
 
#define sqlite3IsNumericAffinity(X)   ((X)>=SQLITE_AFF_NUMERIC)
 
#define SQLITE_AFF_MASK   0x47
 
#define SQLITE_KEEPNULL   0x08 /* Used by vector == or <> */
 
#define SQLITE_JUMPIFNULL   0x10 /* jumps if either operand is NULL */
 
#define SQLITE_STOREP2   0x20 /* Store result in reg[P2] rather than jump */
 
#define SQLITE_NULLEQ   0x80 /* NULL=NULL */
 
#define SQLITE_NOTNULL   0x90 /* Assert that operands are never NULL */
 
#define SQLITE_VTABRISK_Low   0
 
#define SQLITE_VTABRISK_Normal   1
 
#define SQLITE_VTABRISK_High   2
 
#define TF_Readonly   0x0001 /* Read-only system table */
 
#define TF_Ephemeral   0x0002 /* An ephemeral table */
 
#define TF_HasPrimaryKey   0x0004 /* Table has a primary key */
 
#define TF_Autoincrement   0x0008 /* Integer primary key is autoincrement */
 
#define TF_HasStat1   0x0010 /* nRowLogEst set from sqlite_stat1 */
 
#define TF_HasVirtual   0x0020 /* Has one or more VIRTUAL columns */
 
#define TF_HasStored   0x0040 /* Has one or more STORED columns */
 
#define TF_HasGenerated   0x0060 /* Combo: HasVirtual + HasStored */
 
#define TF_WithoutRowid   0x0080 /* No rowid. PRIMARY KEY is the key */
 
#define TF_StatsUsed
 
#define TF_NoVisibleRowid   0x0200 /* No user-visible "rowid" column */
 
#define TF_OOOHidden   0x0400 /* Out-of-Order hidden columns */
 
#define TF_HasNotNull   0x0800 /* Contains NOT NULL constraints */
 
#define TF_Shadow   0x1000 /* True for a shadow table */
 
#define IsVirtual(X)   ((X)->nModuleArg)
 
#define ExprIsVtab(X)    ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)
 
#define IsHiddenColumn(X)   (((X)->colFlags & COLFLAG_HIDDEN)!=0)
 
#define IsOrdinaryHiddenColumn(X)   0
 
#define HasRowid(X)   (((X)->tabFlags & TF_WithoutRowid)==0)
 
#define VisibleRowid(X)   (((X)->tabFlags & TF_NoVisibleRowid)==0)
 
#define OE_None   0 /* There is no constraint to check */
 
#define OE_Rollback   1 /* Fail the operation and rollback the transaction */
 
#define OE_Abort   2 /* Back out changes but do no rollback transaction */
 
#define OE_Fail   3 /* Stop the operation but leave all prior changes */
 
#define OE_Ignore   4 /* Ignore the error. Do not do the INSERT or UPDATE */
 
#define OE_Replace   5 /* Delete existing record, then do INSERT or UPDATE */
 
#define OE_Update   6 /* Process as a DO UPDATE in an upsert */
 
#define OE_Restrict   7 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
 
#define OE_SetNull   8 /* Set the foreign key value to NULL */
 
#define OE_SetDflt   9 /* Set the foreign key value to its default */
 
#define OE_Cascade   10 /* Cascade the changes */
 
#define OE_Default   11 /* Do whatever the default action is */
 
#define KEYINFO_ORDER_DESC   0x01 /* DESC sort order */
 
#define KEYINFO_ORDER_BIGNULL   0x02 /* NULL is larger than any other value */
 
#define SQLITE_IDXTYPE_APPDEF   0 /* Created using CREATE INDEX */
 
#define SQLITE_IDXTYPE_UNIQUE   1 /* Implements a UNIQUE constraint */
 
#define SQLITE_IDXTYPE_PRIMARYKEY   2 /* Is the PRIMARY KEY for the table */
 
#define SQLITE_IDXTYPE_IPK   3 /* INTEGER PRIMARY KEY index */
 
#define IsPrimaryKeyIndex(X)   ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY)
 
#define IsUniqueIndex(X)   ((X)->onError!=OE_None)
 
#define XN_ROWID   (-1) /* Indexed column is the rowid */
 
#define XN_EXPR   (-2) /* Indexed column is an expression */
 
#define SQLITE_TOKEN_QUOTED   0x1 /* Token is a quoted identifier. */
 
#define SQLITE_TOKEN_KEYWORD   0x2 /* Token is a keyword. */
 
#define EP_FromJoin   0x000001 /* Originates in ON/USING clause of outer join */
 
#define EP_Distinct   0x000002 /* Aggregate function with DISTINCT keyword */
 
#define EP_HasFunc   0x000004 /* Contains one or more functions of any kind */
 
#define EP_FixedCol   0x000008 /* TK_Column with a known fixed value */
 
#define EP_Agg   0x000010 /* Contains one or more aggregate functions */
 
#define EP_VarSelect   0x000020 /* pSelect is correlated, not constant */
 
#define EP_DblQuoted   0x000040 /* token.z was originally in "..." */
 
#define EP_InfixFunc   0x000080 /* True for an infix function: LIKE, GLOB, etc */
 
#define EP_Collate   0x000100 /* Tree contains a TK_COLLATE operator */
 
#define EP_Commuted   0x000200 /* Comparison operator has been commuted */
 
#define EP_IntValue   0x000400 /* Integer value contained in u.iValue */
 
#define EP_xIsSelect   0x000800 /* x.pSelect is valid (otherwise x.pList is) */
 
#define EP_Skip   0x001000 /* Operator does not contribute to affinity */
 
#define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
 
#define EP_TokenOnly   0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
 
#define EP_Win   0x008000 /* Contains window functions */
 
#define EP_MemToken   0x010000 /* Need to sqlite3DbFree() Expr.zToken */
 
#define EP_Unlikely   0x040000 /* unlikely() or likelihood() function */
 
#define EP_ConstFunc   0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
 
#define EP_CanBeNull   0x100000 /* Can be null despite NOT NULL constraint */
 
#define EP_Subquery   0x200000 /* Tree contains a TK_SELECT operator */
 
#define EP_Alias   0x400000 /* Is an alias for a result set column */
 
#define EP_Leaf   0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
 
#define EP_WinFunc   0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
 
#define EP_Subrtn   0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
 
#define EP_Quoted   0x4000000 /* TK_ID was originally quoted */
 
#define EP_Static   0x8000000 /* Held in memory not obtained from malloc() */
 
#define EP_IsTrue   0x10000000 /* Always has boolean value of TRUE */
 
#define EP_IsFalse   0x20000000 /* Always has boolean value of FALSE */
 
#define EP_FromDDL   0x40000000 /* Originates from sqlite_schema */
 
#define EP_Propagate   (EP_Collate|EP_Subquery|EP_HasFunc)
 
#define ExprHasProperty(E, P)   (((E)->flags&(P))!=0)
 
#define ExprHasAllProperty(E, P)   (((E)->flags&(P))==(P))
 
#define ExprSetProperty(E, P)   (E)->flags|=(P)
 
#define ExprClearProperty(E, P)   (E)->flags&=~(P)
 
#define ExprAlwaysTrue(E)   (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
 
#define ExprAlwaysFalse(E)   (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
 
#define EP_NoReduce   0x01 /* Cannot EXPRDUP_REDUCE this Expr */
 
#define EP_Immutable   0x02 /* Do not change this Expr node */
 
#define ExprSetVVAProperty(E, P)
 
#define ExprHasVVAProperty(E, P)   0
 
#define ExprClearVVAProperties(E)
 
#define EXPR_FULLSIZE   sizeof(Expr) /* Full size */
 
#define EXPR_REDUCEDSIZE   offsetof(Expr,iTable) /* Common features */
 
#define EXPR_TOKENONLYSIZE   offsetof(Expr,pLeft) /* Fewer features */
 
#define EXPRDUP_REDUCE   0x0001 /* Used reduced-size Expr nodes */
 
#define IsWindowFunc(p)
 
#define ENAME_NAME   0 /* The AS clause of a result set */
 
#define ENAME_SPAN   1 /* Complete text of the result set expression */
 
#define ENAME_TAB   2 /* "DB.TABLE.NAME" for the result set */
 
#define JT_INNER   0x0001 /* Any kind of inner or cross join */
 
#define JT_CROSS   0x0002 /* Explicit use of the CROSS keyword */
 
#define JT_NATURAL   0x0004 /* True for a "natural" join */
 
#define JT_LEFT   0x0008 /* Left outer join */
 
#define JT_RIGHT   0x0010 /* Right outer join */
 
#define JT_OUTER   0x0020 /* The "OUTER" keyword is present */
 
#define JT_ERROR   0x0040 /* unknown or unsupported join type */
 
#define WHERE_ORDERBY_NORMAL   0x0000 /* No-op */
 
#define WHERE_ORDERBY_MIN   0x0001 /* ORDER BY processing for min() func */
 
#define WHERE_ORDERBY_MAX   0x0002 /* ORDER BY processing for max() func */
 
#define WHERE_ONEPASS_DESIRED   0x0004 /* Want to do one-pass UPDATE/DELETE */
 
#define WHERE_ONEPASS_MULTIROW   0x0008 /* ONEPASS is ok with multiple rows */
 
#define WHERE_DUPLICATES_OK   0x0010 /* Ok to return a row more than once */
 
#define WHERE_OR_SUBCLAUSE
 
#define WHERE_GROUPBY   0x0040 /* pOrderBy is really a GROUP BY */
 
#define WHERE_DISTINCTBY   0x0080 /* pOrderby is really a DISTINCT clause */
 
#define WHERE_WANT_DISTINCT   0x0100 /* All output needs to be distinct */
 
#define WHERE_SORTBYGROUP   0x0200 /* Support sqlite3WhereIsSorted() */
 
#define WHERE_SEEK_TABLE   0x0400 /* Do not defer seeks on main table */
 
#define WHERE_ORDERBY_LIMIT   0x0800 /* ORDERBY+LIMIT on the inner loop */
 
#define WHERE_SEEK_UNIQ_TABLE   0x1000 /* Do not defer seeks if unique */
 
#define WHERE_USE_LIMIT   0x4000 /* Use the LIMIT in cost estimates */
 
#define WHERE_DISTINCT_NOOP   0 /* DISTINCT keyword not used */
 
#define WHERE_DISTINCT_UNIQUE   1 /* No duplicates */
 
#define WHERE_DISTINCT_ORDERED   2 /* All duplicates are adjacent */
 
#define WHERE_DISTINCT_UNORDERED   3 /* Duplicates are scattered */
 
#define NC_AllowAgg   0x00001 /* Aggregate functions are allowed here */
 
#define NC_PartIdx   0x00002 /* True if resolving a partial index WHERE */
 
#define NC_IsCheck   0x00004 /* True if resolving a CHECK constraint */
 
#define NC_GenCol   0x00008 /* True for a GENERATED ALWAYS AS clause */
 
#define NC_HasAgg   0x00010 /* One or more aggregate functions seen */
 
#define NC_IdxExpr   0x00020 /* True if resolving columns of CREATE INDEX */
 
#define NC_SelfRef   0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
 
#define NC_VarSelect   0x00040 /* A correlated subquery has been seen */
 
#define NC_UEList   0x00080 /* True if uNC.pEList is used */
 
#define NC_UAggInfo   0x00100 /* True if uNC.pAggInfo is used */
 
#define NC_UUpsert   0x00200 /* True if uNC.pUpsert is used */
 
#define NC_MinMaxAgg   0x01000 /* min/max aggregates seen. See note above */
 
#define NC_Complex   0x02000 /* True if a function or subquery seen */
 
#define NC_AllowWin   0x04000 /* Window functions are allowed here */
 
#define NC_HasWin   0x08000 /* One or more window functions seen */
 
#define NC_IsDDL   0x10000 /* Resolving names in a CREATE statement */
 
#define NC_InAggFunc   0x20000 /* True if analyzing arguments to an agg func */
 
#define NC_FromDDL   0x40000 /* SQL text comes from sqlite_schema */
 
#define SF_Distinct   0x0000001 /* Output should be DISTINCT */
 
#define SF_All   0x0000002 /* Includes the ALL keyword */
 
#define SF_Resolved   0x0000004 /* Identifiers have been resolved */
 
#define SF_Aggregate   0x0000008 /* Contains agg functions or a GROUP BY */
 
#define SF_HasAgg   0x0000010 /* Contains aggregate functions */
 
#define SF_UsesEphemeral   0x0000020 /* Uses the OpenEphemeral opcode */
 
#define SF_Expanded   0x0000040 /* sqlite3SelectExpand() called on this */
 
#define SF_HasTypeInfo   0x0000080 /* FROM subqueries have Table metadata */
 
#define SF_Compound   0x0000100 /* Part of a compound query */
 
#define SF_Values   0x0000200 /* Synthesized from VALUES clause */
 
#define SF_MultiValue   0x0000400 /* Single VALUES term with multiple rows */
 
#define SF_NestedFrom   0x0000800 /* Part of a parenthesized FROM clause */
 
#define SF_MinMaxAgg   0x0001000 /* Aggregate containing min() or max() */
 
#define SF_Recursive   0x0002000 /* The recursive part of a recursive CTE */
 
#define SF_FixedLimit   0x0004000 /* nSelectRow set by a constant LIMIT */
 
#define SF_MaybeConvert   0x0008000 /* Need convertCompoundSelectToSubquery() */
 
#define SF_Converted   0x0010000 /* By convertCompoundSelectToSubquery() */
 
#define SF_IncludeHidden   0x0020000 /* Include hidden columns in output */
 
#define SF_ComplexResult   0x0040000 /* Result contains subquery or function */
 
#define SF_WhereBegin   0x0080000 /* Really a WhereBegin() call. Debug Only */
 
#define SF_WinRewrite   0x0100000 /* Window function rewrite accomplished */
 
#define SF_View   0x0200000 /* SELECT statement is a view */
 
#define SF_NoopOrderBy   0x0400000 /* ORDER BY is ignored for this query */
 
#define SF_UpdateFrom   0x0800000 /* Statement is an UPDATE...FROM */
 
#define SRT_Union   1 /* Store result as keys in an index */
 
#define SRT_Except   2 /* Remove result from a UNION index */
 
#define SRT_Exists   3 /* Store 1 if the result is not empty */
 
#define SRT_Discard   4 /* Do not save the results anywhere */
 
#define SRT_Fifo   5 /* Store result as data with an automatic rowid */
 
#define SRT_DistFifo   6 /* Like SRT_Fifo, but unique results only */
 
#define SRT_Queue   7 /* Store result in an queue */
 
#define SRT_DistQueue   8 /* Like SRT_Queue, but unique results only */
 
#define IgnorableOrderby(X)   ((X->eDest)<=SRT_DistQueue)
 
#define SRT_Output   9 /* Output each row of result */
 
#define SRT_Mem   10 /* Store result in a memory cell */
 
#define SRT_Set   11 /* Store results as keys in an index */
 
#define SRT_EphemTab   12 /* Create transient tab and store like SRT_Table */
 
#define SRT_Coroutine   13 /* Generate a single row of result */
 
#define SRT_Table   14 /* Store result as data with an automatic rowid */
 
#define SRT_Upfrom   15 /* Store result as data with rowid */
 
#define DbMaskTest(M, I)   (((M)&(((yDbMask)1)<<(I)))!=0)
 
#define DbMaskZero(M)   (M)=0
 
#define DbMaskSet(M, I)   (M)|=(((yDbMask)1)<<(I))
 
#define DbMaskAllZero(M)   (M)==0
 
#define DbMaskNonZero(M)   (M)!=0
 
#define PARSE_MODE_NORMAL   0
 
#define PARSE_MODE_DECLARE_VTAB   1
 
#define PARSE_MODE_RENAME   2
 
#define PARSE_MODE_UNMAP   3
 
#define PARSE_HDR_SZ   offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
 
#define PARSE_RECURSE_SZ   offsetof(Parse,sLastToken) /* Recursive part */
 
#define PARSE_TAIL_SZ   (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
 
#define PARSE_TAIL(X)   (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
 
#define IN_DECLARE_VTAB   (pParse->eParseMode==PARSE_MODE_DECLARE_VTAB)
 
#define IN_RENAME_OBJECT   (pParse->eParseMode>=PARSE_MODE_RENAME)
 
#define IN_SPECIAL_PARSE   (pParse->eParseMode!=PARSE_MODE_NORMAL)
 
#define OPFLAG_NCHANGE   0x01 /* OP_Insert: Set to update db->nChange */
 
#define OPFLAG_NOCHNG   0x01 /* OP_VColumn nochange for UPDATE */
 
#define OPFLAG_EPHEM   0x01 /* OP_Column: Ephemeral output is ok */
 
#define OPFLAG_LASTROWID   0x20 /* Set to update db->lastRowid */
 
#define OPFLAG_ISUPDATE   0x04 /* This OP_Insert is an sql UPDATE */
 
#define OPFLAG_APPEND   0x08 /* This is likely to be an append */
 
#define OPFLAG_USESEEKRESULT   0x10 /* Try to avoid a seek in BtreeInsert() */
 
#define OPFLAG_ISNOOP   0x40 /* OP_Delete does pre-update-hook only */
 
#define OPFLAG_LENGTHARG   0x40 /* OP_Column only used for length() */
 
#define OPFLAG_TYPEOFARG   0x80 /* OP_Column only used for typeof() */
 
#define OPFLAG_BULKCSR   0x01 /* OP_Open** used to open bulk cursor */
 
#define OPFLAG_SEEKEQ   0x02 /* OP_Open** cursor uses EQ seek only */
 
#define OPFLAG_FORDELETE   0x08 /* OP_Open should use BTREE_FORDELETE */
 
#define OPFLAG_P2ISREG   0x10 /* P2 to OP_Open** is a register number */
 
#define OPFLAG_PERMUTE   0x01 /* OP_Compare: use the permutation */
 
#define OPFLAG_SAVEPOSITION   0x02 /* OP_Delete/Insert: save cursor pos */
 
#define OPFLAG_AUXDELETE   0x04 /* OP_Delete: index in a DELETE op */
 
#define OPFLAG_NOCHNG_MAGIC   0x6d /* OP_MakeRecord: serialtype 10 is ok */
 
#define TRIGGER_BEFORE   1
 
#define TRIGGER_AFTER   2
 
#define SQLITE_PRINTF_INTERNAL   0x01 /* Internal-use-only converters allowed */
 
#define SQLITE_PRINTF_SQLFUNC   0x02 /* SQL function arguments to VXPrintf */
 
#define SQLITE_PRINTF_MALLOCED   0x04 /* True if xText is allocated space */
 
#define isMalloced(X)   (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
 
#define INITFLAG_AlterTable   0x0001 /* This is a reparse after ALTER TABLE */
 
#define CORRUPT_DB   (sqlite3Config.neverCorrupt==0)
 
#define WRC_Continue   0 /* Continue down into children */
 
#define WRC_Prune   1 /* Omit children but continue walking siblings */
 
#define WRC_Abort   2 /* Abandon the tree walk */
 
#define SQLITE_SKIP_UTF8(zIn)
 
#define SQLITE_CORRUPT_BKPT   sqlite3CorruptError(__LINE__)
 
#define SQLITE_MISUSE_BKPT   sqlite3MisuseError(__LINE__)
 
#define SQLITE_CANTOPEN_BKPT   sqlite3CantopenError(__LINE__)
 
#define SQLITE_NOMEM_BKPT   SQLITE_NOMEM
 
#define SQLITE_IOERR_NOMEM_BKPT   SQLITE_IOERR_NOMEM
 
#define SQLITE_CORRUPT_PGNO(P)   sqlite3CorruptError(__LINE__)
 
#define sqlite3Toupper(x)   ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))
 
#define sqlite3Isspace(x)   (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
 
#define sqlite3Isalnum(x)   (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
 
#define sqlite3Isalpha(x)   (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
 
#define sqlite3Isdigit(x)   (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
 
#define sqlite3Isxdigit(x)   (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
 
#define sqlite3Tolower(x)   (sqlite3UpperToLower[(unsigned char)(x)])
 
#define sqlite3Isquote(x)   (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
 
#define sqlite3Strlen30NN(C)   (strlen(C)&0x3fffffff)
 
#define sqlite3StrNICmp   sqlite3_strnicmp
 
#define sqlite3StackAllocRaw(D, N)   sqlite3DbMallocRaw(D,N)
 
#define sqlite3StackAllocZero(D, N)   sqlite3DbMallocZero(D,N)
 
#define sqlite3StackFree(D, P)   sqlite3DbFree(D,P)
 
#define sqlite3MutexWarnOnContention(x)
 
#define EXP754   (((u64)0x7ff)<<52)
 
#define MAN754   ((((u64)1)<<52)-1)
 
#define IsNaN(X)   (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)
 
#define sqlite3ColumnPropertiesFromName(T, C)   /* no-op */
 
#define sqlite3CodecQueryParameters(A, B, C)   0
 
#define ONEPASS_OFF   0 /* Use of ONEPASS not allowed */
 
#define ONEPASS_SINGLE   1 /* ONEPASS valid for a single row update */
 
#define ONEPASS_MULTI   2 /* ONEPASS is valid for multiple rows */
 
#define SQLITE_ECEL_DUP   0x01 /* Deep, not shallow copies */
 
#define SQLITE_ECEL_FACTOR   0x02 /* Factor out constant terms */
 
#define SQLITE_ECEL_REF   0x04 /* Use ExprList.u.x.iOrderByCol */
 
#define SQLITE_ECEL_OMITREF   0x08 /* Omit if ExprList.u.x.iOrderByCol */
 
#define LOCATE_VIEW   0x01
 
#define LOCATE_NOERR   0x02
 
#define sqlite3SetMakeRecordP5(A, B)
 
#define sqlite3ParseToplevel(p)   ((p)->pToplevel ? (p)->pToplevel : (p))
 
#define sqlite3IsToplevel(p)   ((p)->pToplevel==0)
 
#define getVarint32(A, B)    (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))
 
#define getVarint32NR(A, B)    B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
 
#define putVarint32(A, B)
 
#define getVarint   sqlite3GetVarint
 
#define putVarint   sqlite3PutVarint
 
#define sqlite3FileSuffix3(X, Y)
 
#define sqlite3VtabInSync(db)   ((db)->nVTrans>0 && (db)->aVTrans==0)
 
#define SQLITE_FAULTINJECTOR_MALLOC   0
 
#define SQLITE_FAULTINJECTOR_COUNT   1
 
#define IN_INDEX_ROWID   1 /* Search the rowid of the table */
 
#define IN_INDEX_EPH   2 /* Search an ephemeral b-tree */
 
#define IN_INDEX_INDEX_ASC   3 /* Existing index ASCENDING */
 
#define IN_INDEX_INDEX_DESC   4 /* Existing index DESCENDING */
 
#define IN_INDEX_NOOP   5 /* No table available. Use comparisons */
 
#define IN_INDEX_NOOP_OK   0x0001 /* OK to return IN_INDEX_NOOP */
 
#define IN_INDEX_MEMBERSHIP   0x0002 /* IN operator used for membership test */
 
#define IN_INDEX_LOOP   0x0004 /* IN operator used as a loop */
 
#define sqlite3ConnectionBlocked(x, y)
 
#define sqlite3ConnectionUnlocked(x)
 
#define sqlite3ConnectionClosed(x)
 
#define IOTRACE(A)
 
#define sqlite3VdbeIOTraceSql(X)
 
#define sqlite3MemdebugSetType(X, Y)   /* no-op */
 
#define sqlite3MemdebugHasType(X, Y)   1
 
#define sqlite3MemdebugNoType(X, Y)   1
 
#define MEMTYPE_HEAP   0x01 /* General heap allocations */
 
#define MEMTYPE_LOOKASIDE   0x02 /* Heap that might have been lookaside */
 
#define MEMTYPE_PCACHE   0x04 /* Page cache allocations */
 
#define SQLITE_USE_URI   0
 
#define SQLITE_ALLOW_COVERING_INDEX_SCAN   1
 
#define SQLITE_SORTER_PMASZ   250
 
#define SQLITE_STMTJRNL_SPILL   (64*1024)
 
#define SQLITE_DEFAULT_LOOKASIDE   1200,40 /* 48KB of memory */
 
#define SQLITE_MEMDB_DEFAULT_MAXSIZE   1073741824
 
#define SQLITE_VDBEINT_H
 
#define SQLITE_MAX_SCHEMA_RETRY   50
 
#define VDBE_DISPLAY_P4   1
 
#define CURTYPE_BTREE   0
 
#define CURTYPE_SORTER   1
 
#define CURTYPE_VTAB   2
 
#define CURTYPE_PSEUDO   3
 
#define CACHE_STALE   0
 
#define SQLITE_FRAME_MAGIC   0x879fb71e
 
#define VdbeFrameMem(p)   ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
 
#define MEMCELLSIZE   offsetof(Mem,zMalloc)
 
#define MEM_Null   0x0001 /* Value is NULL (or a pointer) */
 
#define MEM_Str   0x0002 /* Value is a string */
 
#define MEM_Int   0x0004 /* Value is an integer */
 
#define MEM_Real   0x0008 /* Value is a real number */
 
#define MEM_Blob   0x0010 /* Value is a BLOB */
 
#define MEM_IntReal   0x0020 /* MEM_Int that stringifies like MEM_Real */
 
#define MEM_AffMask   0x003f /* Mask of affinity bits */
 
#define MEM_FromBind   0x0040 /* Value originates from sqlite3_bind() */
 
#define MEM_Undefined   0x0080 /* Value is undefined */
 
#define MEM_Cleared   0x0100 /* NULL set by OP_Null, not from data */
 
#define MEM_TypeMask   0xc1bf /* Mask of type bits */
 
#define MEM_Term   0x0200 /* String in Mem.z is zero terminated */
 
#define MEM_Dyn   0x0400 /* Need to call Mem.xDel() on Mem.z */
 
#define MEM_Static   0x0800 /* Mem.z points to a static string */
 
#define MEM_Ephem   0x1000 /* Mem.z points to an ephemeral string */
 
#define MEM_Agg   0x2000 /* Mem.z points to an agg function context */
 
#define MEM_Zero   0x4000 /* Mem.i contains count of 0s appended to blob */
 
#define MEM_Subtype   0x8000 /* Mem.eSubtype is valid */
 
#define VdbeMemDynamic(X)    (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
 
#define MemSetTypeFlag(p, f)    ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
 
#define MemNullNochng(X)
 
#define VDBE_MAGIC_INIT   0x16bceaa5 /* Building a VDBE program */
 
#define VDBE_MAGIC_RUN   0x2df20da3 /* VDBE is ready to execute */
 
#define VDBE_MAGIC_HALT   0x319c2973 /* VDBE has completed execution */
 
#define VDBE_MAGIC_RESET   0x48fa9f76 /* Reset and ready to run again */
 
#define VDBE_MAGIC_DEAD   0x5606c3c8 /* The VDBE has been deallocated */
 
#define sqlite3VdbeIncrWriteCounter(V, C)
 
#define sqlite3VdbeAssertAbortable(V)
 
#define ExpandBlob(P)   (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
 
#define wsdStatInit
 
#define wsdStat   sqlite3Stat
 
#define INT_464269060799999   ((((i64)0x1a640)<<32)|0x1072fdff)
 
#define DO_OS_MALLOC_TEST(x)
 
#define vfsList   GLOBAL(sqlite3_vfs *, vfsList)
 
#define wsdHooksInit
 
#define wsdHooks   sqlite3Hooks
 
#define SQLITE_MALLOC(x)   malloc(x)
 
#define SQLITE_FREE(x)   free(x)
 
#define SQLITE_REALLOC(x, y)   realloc((x),(y))
 
#define SQLITE_MUTEX_NREF   0
 
#define SQLITE3_MUTEX_INITIALIZER(id)   { PTHREAD_MUTEX_INITIALIZER }
 
#define SQLITE_MAX_MEMORY   0
 
#define mem0   GLOBAL(struct Mem0Global, mem0)
 
#define etRADIX   0 /* non-decimal integer types. %x %o */
 
#define etFLOAT   1 /* Floating point. %f */
 
#define etEXP   2 /* Exponentional notation. %e and %E */
 
#define etGENERIC   3 /* Floating or exponential, depending on exponent. %g */
 
#define etSIZE   4 /* Return number of characters processed so far. %n */
 
#define etSTRING   5 /* Strings. %s */
 
#define etDYNSTRING   6 /* Dynamically allocated strings. %z */
 
#define etPERCENT   7 /* Percent symbol. %% */
 
#define etCHARX   8 /* Characters. %c */
 
#define etSQLESCAPE   9 /* Strings with '\'' doubled. %q */
 
#define etSQLESCAPE2
 
#define etTOKEN   11 /* a pointer to a Token structure */
 
#define etSRCLIST   12 /* a pointer to a SrcList */
 
#define etPOINTER   13 /* The %p conversion */
 
#define etSQLESCAPE3   14 /* %w -> Strings with '\"' doubled */
 
#define etORDINAL   15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
 
#define etDECIMAL   16 /* %d or %u, but not %x, %o */
 
#define etINVALID   17 /* Any unrecognized conversion type */
 
#define FLAG_SIGNED   1 /* True if the value to convert is signed */
 
#define FLAG_STRING   4 /* Allow infinite precision */
 
#define SQLITE_PRINT_BUF_SIZE   70
 
#define etBUFSIZE   SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
 
#define SQLITE_FP_PRECISION_LIMIT   100000000
 
#define wsdPrng   sqlite3Prng
 
#define SQLITE_THREADS_IMPLEMENTED   1 /* Prevent the single-thread code below */
 
#define WRITE_UTF8(zOut, c)
 
#define WRITE_UTF16LE(zOut, c)
 
#define WRITE_UTF16BE(zOut, c)
 
#define READ_UTF8(zIn, zTerm, c)
 
#define UpperToLower   sqlite3UpperToLower
 
#define SLOT_2_0   0x001fc07f
 
#define SLOT_4_2_0   0xf01fc07f
 
#define OpHelp(X)
 
#define SQLITE_ENABLE_LOCKING_STYLE   0
 
#define HAVE_GETHOSTUUID   0
 
#define SQLITE_FSFLAGS_IS_MSDOS   0x1
 
#define SQLITE_DEFAULT_FILE_PERMISSIONS   0644
 
#define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS   0755
 
#define MAX_PATHNAME   512
 
#define SQLITE_MAX_SYMLINKS   100
 
#define osGetpid(X)   (pid_t)getpid()
 
#define IS_LOCK_ERROR(x)   ((x != SQLITE_OK) && (x != SQLITE_BUSY))
 
#define UNIXFILE_EXCL   0x01 /* Connections from one process only */
 
#define UNIXFILE_RDONLY   0x02 /* Connection is read only */
 
#define UNIXFILE_PERSIST_WAL   0x04 /* Persistent WAL mode */
 
#define UNIXFILE_DIRSYNC   0x08 /* Directory sync needed */
 
#define UNIXFILE_PSOW   0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
 
#define UNIXFILE_DELETE   0x20 /* Delete on close */
 
#define UNIXFILE_URI   0x40 /* Filename might have query parameters */
 
#define UNIXFILE_NOLOCK   0x80 /* Do no file locking */
 
#define _OS_COMMON_H_
 
#define TIMER_START
 
#define TIMER_END
 
#define TIMER_ELAPSED   ((sqlite_uint64)0)
 
#define SimulateIOErrorBenign(X)
 
#define SimulateIOError(A)
 
#define SimulateDiskfullError(A)
 
#define OpenCounter(X)
 
#define O_LARGEFILE   0
 
#define O_NOFOLLOW   0
 
#define O_BINARY   0
 
#define threadid   pthread_self()
 
#define HAVE_MREMAP   0
 
#define osOpen   ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
 
#define osClose   ((int(*)(int))aSyscall[1].pCurrent)
 
#define osAccess   ((int(*)(const char*,int))aSyscall[2].pCurrent)
 
#define osGetcwd   ((char*(*)(char*,size_t))aSyscall[3].pCurrent)
 
#define osStat   ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)
 
#define osFstat   ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
 
#define osFtruncate   ((int(*)(int,off_t))aSyscall[6].pCurrent)
 
#define osFcntl   ((int(*)(int,int,...))aSyscall[7].pCurrent)
 
#define osRead   ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
 
#define osPread   ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
 
#define osPread64   ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
 
#define osWrite   ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
 
#define osPwrite
 
#define osPwrite64
 
#define osFchmod   ((int(*)(int,mode_t))aSyscall[14].pCurrent)
 
#define osFallocate   ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent)
 
#define osUnlink   ((int(*)(const char*))aSyscall[16].pCurrent)
 
#define osOpenDirectory   ((int(*)(const char*,int*))aSyscall[17].pCurrent)
 
#define osMkdir   ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
 
#define osRmdir   ((int(*)(const char*))aSyscall[19].pCurrent)
 
#define osFchown   ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
 
#define osGeteuid   ((uid_t(*)(void))aSyscall[21].pCurrent)
 
#define osMmap   ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent)
 
#define osMunmap   ((int(*)(void*,size_t))aSyscall[23].pCurrent)
 
#define osMremap   ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent)
 
#define osGetpagesize   ((int(*)(void))aSyscall[25].pCurrent)
 
#define osReadlink   ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent)
 
#define osLstat   ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)
 
#define SQLITE_MINIMUM_FILE_DESCRIPTOR   3
 
#define unixLogError(a, b, c)   unixLogErrorAtLine(a,b,c,__LINE__)
 
#define osSetPosixAdvisoryLock(h, x, t)   osFcntl(h,F_SETLK,x)
 
#define DOTLOCK_SUFFIX   ".lock"
 
#define fdatasync   fsync
 
#define HAVE_FULLFSYNC   0
 
#define UNIX_SHM_BASE   ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
 
#define UNIX_SHM_DMS   (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
 
#define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK, SHMMAP)
 
#define UNIXVFS(VFSNAME, FINDER)
 
#define BITVEC_SZ   512
 
#define BITVEC_USIZE    (((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*))
 
#define BITVEC_TELEM   u8
 
#define BITVEC_SZELEM   8
 
#define BITVEC_NELEM   (BITVEC_USIZE/sizeof(BITVEC_TELEM))
 
#define BITVEC_NBIT   (BITVEC_NELEM*BITVEC_SZELEM)
 
#define BITVEC_NINT   (BITVEC_USIZE/sizeof(u32))
 
#define BITVEC_MXHASH   (BITVEC_NINT/2)
 
#define BITVEC_HASH(X)   (((X)*1)%BITVEC_NINT)
 
#define BITVEC_NPTR   (BITVEC_USIZE/sizeof(Bitvec *))
 
#define SETBIT(V, I)   V[I>>3] |= (1<<(I&7))
 
#define CLEARBIT(V, I)   V[I>>3] &= ~(1<<(I&7))
 
#define TESTBIT(V, I)   (V[I>>3]&(1<<(I&7)))!=0
 
#define pcacheTrace(X)
 
#define pcacheDump(X)
 
#define PCACHE_DIRTYLIST_REMOVE   1 /* Remove pPage from dirty list */
 
#define PCACHE_DIRTYLIST_ADD   2 /* Add pPage to the dirty list */
 
#define PCACHE_DIRTYLIST_FRONT   3 /* Move pPage to the front of the list */
 
#define N_SORT_BUCKET   32
 
#define PAGE_IS_PINNED(p)   ((p)->pLruNext==0)
 
#define PAGE_IS_UNPINNED(p)   ((p)->pLruNext!=0)
 
#define pcache1   (GLOBAL(struct PCacheGlobal, pcache1_g))
 
#define pcache1EnterMutex(X)   assert((X)->mutex==0)
 
#define pcache1LeaveMutex(X)   assert((X)->mutex==0)
 
#define PCACHE1_MIGHT_USE_GROUP_MUTEX   0
 
#define ROWSET_ALLOCATION_SIZE   1024
 
#define ROWSET_ENTRY_PER_CHUNK    ((ROWSET_ALLOCATION_SIZE-8)/sizeof(struct RowSetEntry))
 
#define ROWSET_SORTED   0x01 /* True if RowSet.pEntry is sorted */
 
#define ROWSET_NEXT   0x02 /* True if sqlite3RowSetNext() has been called */
 
#define SQLITE_WAL_H
 
#define WAL_SYNC_FLAGS(X)   ((X)&0x03)
 
#define CKPT_SYNC_FLAGS(X)   (((X)>>2)&0x03)
 
#define WAL_SAVEPOINT_NDATA   4
 
#define PAGERTRACE(X)
 
#define PAGERID(p)   (SQLITE_PTR_TO_INT(p->fd))
 
#define FILEHANDLEID(fd)   (SQLITE_PTR_TO_INT(fd))
 
#define PAGER_OPEN   0
 
#define PAGER_READER   1
 
#define PAGER_WRITER_LOCKED   2
 
#define PAGER_WRITER_CACHEMOD   3
 
#define PAGER_WRITER_DBMOD   4
 
#define PAGER_WRITER_FINISHED   5
 
#define PAGER_ERROR   6
 
#define UNKNOWN_LOCK   (EXCLUSIVE_LOCK+1)
 
#define MAX_SECTOR_SIZE   0x10000
 
#define SPILLFLAG_OFF   0x01 /* Never spill cache. Set via pragma */
 
#define SPILLFLAG_ROLLBACK   0x02 /* Current rolling back, so do not spill */
 
#define SPILLFLAG_NOSYNC   0x04 /* Spill is ok, but do not sync */
 
#define PAGER_STAT_HIT   0
 
#define PAGER_STAT_MISS   1
 
#define PAGER_STAT_WRITE   2
 
#define PAGER_STAT_SPILL   3
 
#define PAGER_INCR(v)
 
#define JOURNAL_PG_SZ(pPager)   ((pPager->pageSize) + 8)
 
#define JOURNAL_HDR_SZ(pPager)   (pPager->sectorSize)
 
#define MEMDB   pPager->memDb
 
#define USEFETCH(x)   0
 
#define isOpen(pFd)   ((pFd)->pMethods!=0)
 
#define pagerUseWal(x)   ((x)->pWal!=0)
 
#define put32bits(A, B)   sqlite3Put4byte((u8*)A,B)
 
#define pager_datahash(X, Y)   0
 
#define pager_pagehash(X)   0
 
#define pager_set_pagehash(X)
 
#define CHECK_PAGE(x)
 
#define disable_simulated_io_errors()
 
#define enable_simulated_io_errors()
 
#define assertTruncateConstraint(pPager)
 
#define memJM   0
 
#define DIRECT_MODE   0
 
#define bBatch   0
 
#define WALTRACE(X)
 
#define WAL_MAX_VERSION   3007000
 
#define WALINDEX_MAX_VERSION   3007000
 
#define WAL_WRITE_LOCK   0
 
#define WAL_ALL_BUT_WRITE   1
 
#define WAL_CKPT_LOCK   1
 
#define WAL_RECOVER_LOCK   2
 
#define WAL_READ_LOCK(I)   (3+(I))
 
#define WAL_NREADER   (SQLITE_SHM_NLOCK-3)
 
#define READMARK_NOT_USED   0xffffffff
 
#define WALINDEX_LOCK_OFFSET   (sizeof(WalIndexHdr)*2+offsetof(WalCkptInfo,aLock))
 
#define WALINDEX_HDR_SIZE   (sizeof(WalIndexHdr)*2+sizeof(WalCkptInfo))
 
#define WAL_FRAME_HDRSIZE   24
 
#define WAL_HDRSIZE   32
 
#define WAL_MAGIC   0x377f0682
 
#define walFrameOffset(iFrame, szPage)
 
#define WAL_NORMAL_MODE   0
 
#define WAL_EXCLUSIVE_MODE   1
 
#define WAL_HEAPMEMORY_MODE   2
 
#define WAL_RDWR   0 /* Normal read/write connection */
 
#define WAL_RDONLY   1 /* The WAL file is readonly */
 
#define WAL_SHM_RDONLY   2 /* The SHM file is readonly */
 
#define HASHTABLE_NPAGE   4096 /* Must be power of 2 */
 
#define HASHTABLE_HASH_1   383 /* Should be prime */
 
#define HASHTABLE_NSLOT   (HASHTABLE_NPAGE*2) /* Must be a power of 2 */
 
#define HASHTABLE_NPAGE_ONE   (HASHTABLE_NPAGE - (WALINDEX_HDR_SIZE/sizeof(u32)))
 
#define WALINDEX_PGSZ
 
#define BYTESWAP32(x)
 
#define SQLITE_NO_TSAN
 
#define walEnableBlocking(x)   0
 
#define walDisableBlocking(x)
 
#define walLockWriter(pWal)   walLockExclusive((pWal), WAL_WRITE_LOCK, 1)
 
#define sqlite3WalDb(pWal, db)
 
#define WAL_RETRY   (-1)
 
#define MX_CELL_SIZE(pBt)   ((int)(pBt->pageSize-8))
 
#define MX_CELL(pBt)   ((pBt->pageSize-8)/6)
 
#define SQLITE_FILE_HEADER   "SQLite format 3"
 
#define PTF_INTKEY   0x01
 
#define PTF_ZERODATA   0x02
 
#define PTF_LEAFDATA   0x04
 
#define PTF_LEAF   0x08
 
#define READ_LOCK   1
 
#define WRITE_LOCK   2
 
#define TRANS_NONE   0
 
#define TRANS_READ   1
 
#define TRANS_WRITE   2
 
#define BTS_READ_ONLY   0x0001 /* Underlying file is readonly */
 
#define BTS_PAGESIZE_FIXED   0x0002 /* Page size can no longer be changed */
 
#define BTS_SECURE_DELETE   0x0004 /* PRAGMA secure_delete is enabled */
 
#define BTS_OVERWRITE   0x0008 /* Overwrite deleted content with zeros */
 
#define BTS_FAST_SECURE   0x000c /* Combination of the previous two */
 
#define BTS_INITIALLY_EMPTY   0x0010 /* Database was empty at trans start */
 
#define BTS_NO_WAL   0x0020 /* Do not open write-ahead-log files */
 
#define BTS_EXCLUSIVE   0x0040 /* pWriter has an exclusive lock */
 
#define BTS_PENDING   0x0080 /* Waiting for read-locks to clear */
 
#define BTCURSOR_MAX_DEPTH   20
 
#define BTCURSOR_FIRST_UNINIT   pBt /* Name of first uninitialized field */
 
#define BTCF_WriteFlag   0x01 /* True if a write cursor */
 
#define BTCF_ValidNKey   0x02 /* True if info.nKey is valid */
 
#define BTCF_ValidOvfl   0x04 /* True if aOverflow is valid */
 
#define BTCF_AtLast   0x08 /* Cursor is pointing ot the last entry */
 
#define BTCF_Incrblob   0x10 /* True if an incremental I/O handle */
 
#define BTCF_Multiple   0x20 /* Maybe another cursor on the same btree */
 
#define BTCF_Pinned   0x40 /* Cursor is busy and cannot be moved */
 
#define CURSOR_VALID   0
 
#define CURSOR_INVALID   1
 
#define CURSOR_SKIPNEXT   2
 
#define CURSOR_REQUIRESEEK   3
 
#define CURSOR_FAULT   4
 
#define PENDING_BYTE_PAGE(pBt)   PAGER_MJ_PGNO(pBt)
 
#define PTRMAP_PAGENO(pBt, pgno)   ptrmapPageno(pBt, pgno)
 
#define PTRMAP_PTROFFSET(pgptrmap, pgno)   (5*(pgno-pgptrmap-1))
 
#define PTRMAP_ISPAGE(pBt, pgno)   (PTRMAP_PAGENO((pBt),(pgno))==(pgno))
 
#define PTRMAP_ROOTPAGE   1
 
#define PTRMAP_FREEPAGE   2
 
#define PTRMAP_OVERFLOW1   3
 
#define PTRMAP_OVERFLOW2   4
 
#define PTRMAP_BTREE   5
 
#define btreeIntegrity(p)
 
#define ISAUTOVACUUM   (pBt->autoVacuum)
 
#define get2byte(x)   ((x)[0]<<8 | (x)[1])
 
#define put2byte(p, v)   ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
 
#define get4byte   sqlite3Get4byte
 
#define put4byte   sqlite3Put4byte
 
#define get2byteAligned(x)   ((x)[0]<<8 | (x)[1])
 
#define TRACE(X)
 
#define get2byteNotZero(X)   (((((int)get2byte(X))-1)&0xffff)+1)
 
#define BTALLOC_ANY   0 /* Allocate any page */
 
#define BTALLOC_EXACT   1 /* Allocate exact page if possible */
 
#define BTALLOC_LE   2 /* Allocate any page <= the parameter */
 
#define IfNotOmitAV(expr)   (expr)
 
#define SQLITE_CORRUPT_PAGE(pMemPage)   SQLITE_CORRUPT_PGNO(pMemPage->pgno)
 
#define invalidateOverflowCache(pCur)   (pCur->curFlags &= ~BTCF_ValidOvfl)
 
#define restoreCursorPosition(p)
 
#define findCell(P, I)    ((P)->aData + ((P)->maskPage & get2byteAligned(&(P)->aCellIdx[2*(I)])))
 
#define findCellPastPtr(P, I)    ((P)->aDataOfst + ((P)->maskPage & get2byteAligned(&(P)->aCellIdx[2*(I)])))
 
#define setDefaultSyncFlag(pBt, safety_level)
 
#define assertCellInfo(x)
 
#define assertParentIndex(x, y, z)
 
#define NN   1 /* Number of neighbors on either side of pPage */
 
#define NB   3 /* (NN*2+1): Total pages involved in the balance */
 
#define ISPOWEROF2(X)   (((X)&((X)-1))==0)
 
#define valueFromFunction(a, b, c, d, e, f)   SQLITE_OK
 
#define checkActiveVdbeCnt(x)
 
#define vdbeInvokeSqllog(x)
 
#define swapMixedEndianFloat(X)
 
#define ONE_BYTE_INT(x)   ((i8)(x)[0])
 
#define TWO_BYTE_INT(x)   (256*(i8)((x)[0])|(x)[1])
 
#define THREE_BYTE_INT(x)   (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
 
#define FOUR_BYTE_UINT(x)   (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
 
#define FOUR_BYTE_INT(x)   (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
 
#define vdbeAssertFieldCountWithinLimits(A, B, C)
 
#define checkProfileCallback(DB, P)    if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
 
#define memAboutToChange(P, M)
 
#define HAS_UPDATE_HOOK(DB)   ((DB)->xUpdateCallback)
 
#define UPDATE_MAX_BLOBSIZE(P)
 
#define VdbeBranchTaken(I, M)
 
#define Deephemeralize(P)
 
#define isSorter(x)   ((x)->eCurType==CURTYPE_SORTER)
 
#define REGISTER_TRACE(R, M)
 
#define MAX_ROWID   (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
 
#define SQLITE_MAX_PMASZ   (1<<29)
 
#define SORTER_TYPE_INTEGER   0x01
 
#define SORTER_TYPE_TEXT   0x02
 
#define SRVAL(p)   ((void*)((SorterRecord*)(p) + 1))
 
#define SORTER_MAX_MERGE_COUNT   16
 
#define vdbeSorterWorkDebug(x, y)
 
#define vdbeSorterRewindDebug(y)
 
#define vdbeSorterPopulateDebug(x, y)
 
#define vdbeSorterBlockDebug(x, y, z)
 
#define vdbeSorterExtendFile(x, y, z)
 
#define INCRINIT_NORMAL   0
 
#define INCRINIT_TASK   1
 
#define INCRINIT_ROOT   2
 
#define MEMJOURNAL_DFLT_FILECHUNKSIZE   1024
 
#define fileChunkSize(nChunkSize)   (sizeof(FileChunk) + ((nChunkSize)-8))
 
#define EXCLUDED_TABLE_NUMBER   2
 
#define sqlite3ResolveNotValid(P, N, M, X, E)
 
#define renameTokenCheckAll(x, y)
 
#define IsStat4   0
 
#define SQLITE_STAT4_SAMPLES   1
 
#define STAT_GET_STAT1   0 /* "stat" column of stat1 table */
 
#define STAT_GET_ROWID   1 /* "rowid" column of stat[34] entry */
 
#define STAT_GET_NEQ   2 /* "neq" column of stat[34] entry */
 
#define STAT_GET_NLT   3 /* "nlt" column of stat[34] entry */
 
#define STAT_GET_NDLT   4 /* "ndlt" column of stat[34] entry */
 
#define analyzeVdbeCommentIndexWithColumnName(a, b, c)
 
#define REOPEN_AS_MEMDB(db)   (0)
 
#define markExprListImmutable(X)   /* no-op */
 
#define SQLITE_MAX_SRCLIST   200
 
#define FUNC_PERFECT_MATCH   6 /* The score for a perfect match */
 
#define noopFunc   versionFunc /* Substitute function - never called */
 
#define Utf8Read(A)   (A[0]<0x80?*(A++):sqlite3Utf8Read(&A))
 
#define SQLITE_MATCH   0
 
#define SQLITE_NOMATCH   1
 
#define SQLITE_NOWILDCARDMATCH   2
 
#define COLUMN_MASK(x)   (((x)>31) ? 0xffffffff : ((u32)1<<(x)))
 
#define CKCNSTRNT_COLUMN   0x01 /* CHECK constraint uses a changing column */
 
#define CKCNSTRNT_ROWID   0x02 /* CHECK constraint references the ROWID */
 
#define SQLITE3EXT_H
 
#define SQLITE_EXTENSION_INIT1   /*no-op*/
 
#define SQLITE_EXTENSION_INIT2(v)   (void)v; /* unused parameter */
 
#define SQLITE_EXTENSION_INIT3   /*no-op*/
 
#define sqlite3_column_database_name   0
 
#define sqlite3_column_database_name16   0
 
#define sqlite3_column_table_name   0
 
#define sqlite3_column_table_name16   0
 
#define sqlite3_column_origin_name   0
 
#define sqlite3_column_origin_name16   0
 
#define DirSep(X)   ((X)=='/')
 
#define wsdAutoextInit
 
#define wsdAutoext   sqlite3Autoext
 
#define PragTyp_ACTIVATE_EXTENSIONS   0
 
#define PragTyp_ANALYSIS_LIMIT   1
 
#define PragTyp_HEADER_VALUE   2
 
#define PragTyp_AUTO_VACUUM   3
 
#define PragTyp_FLAG   4
 
#define PragTyp_BUSY_TIMEOUT   5
 
#define PragTyp_CACHE_SIZE   6
 
#define PragTyp_CACHE_SPILL   7
 
#define PragTyp_CASE_SENSITIVE_LIKE   8
 
#define PragTyp_COLLATION_LIST   9
 
#define PragTyp_COMPILE_OPTIONS   10
 
#define PragTyp_DATA_STORE_DIRECTORY   11
 
#define PragTyp_DATABASE_LIST   12
 
#define PragTyp_DEFAULT_CACHE_SIZE   13
 
#define PragTyp_ENCODING   14
 
#define PragTyp_FOREIGN_KEY_CHECK   15
 
#define PragTyp_FOREIGN_KEY_LIST   16
 
#define PragTyp_FUNCTION_LIST   17
 
#define PragTyp_HARD_HEAP_LIMIT   18
 
#define PragTyp_INCREMENTAL_VACUUM   19
 
#define PragTyp_INDEX_INFO   20
 
#define PragTyp_INDEX_LIST   21
 
#define PragTyp_INTEGRITY_CHECK   22
 
#define PragTyp_JOURNAL_MODE   23
 
#define PragTyp_JOURNAL_SIZE_LIMIT   24
 
#define PragTyp_LOCK_PROXY_FILE   25
 
#define PragTyp_LOCKING_MODE   26
 
#define PragTyp_PAGE_COUNT   27
 
#define PragTyp_MMAP_SIZE   28
 
#define PragTyp_MODULE_LIST   29
 
#define PragTyp_OPTIMIZE   30
 
#define PragTyp_PAGE_SIZE   31
 
#define PragTyp_PRAGMA_LIST   32
 
#define PragTyp_SECURE_DELETE   33
 
#define PragTyp_SHRINK_MEMORY   34
 
#define PragTyp_SOFT_HEAP_LIMIT   35
 
#define PragTyp_SYNCHRONOUS   36
 
#define PragTyp_TABLE_INFO   37
 
#define PragTyp_TEMP_STORE   38
 
#define PragTyp_TEMP_STORE_DIRECTORY   39
 
#define PragTyp_THREADS   40
 
#define PragTyp_WAL_AUTOCHECKPOINT   41
 
#define PragTyp_WAL_CHECKPOINT   42
 
#define PragTyp_LOCK_STATUS   43
 
#define PragTyp_STATS   44
 
#define PragFlg_NeedSchema   0x01 /* Force schema load before running */
 
#define PragFlg_NoColumns   0x02 /* OP_ResultRow called with zero columns */
 
#define PragFlg_NoColumns1   0x04 /* zero columns if RHS argument is present */
 
#define PragFlg_ReadOnly   0x08 /* Read-only HEADER_VALUE */
 
#define PragFlg_Result0   0x10 /* Acts as query when no argument */
 
#define PragFlg_Result1   0x20 /* Acts as query when has one argument */
 
#define PragFlg_SchemaOpt   0x40 /* Schema restricts name search if present */
 
#define PragFlg_SchemaReq   0x80 /* Schema required - "main" is default */
 
#define SQLITE_INTEGRITY_CHECK_ERROR_MAX   100
 
#define SORTFLAG_UseSorter   0x01 /* Use SorterOpen instead of OpenEphemeral */
 
#define explainSetInteger(a, b)   a = b
 
#define columnType(A, B, C, D, E)   columnTypeImpl(A,B)
 
#define SQLITE_WHEREINT_H
 
#define WHERETRACE(K, X)
 
#define WHERE_LOOP_XFER_SZ   offsetof(WhereLoop,nLSlot)
 
#define N_OR_COST   3
 
#define TERM_DYNAMIC   0x0001 /* Need to call sqlite3ExprDelete(db, pExpr) */
 
#define TERM_VIRTUAL   0x0002 /* Added by the optimizer. Do not code */
 
#define TERM_CODED   0x0004 /* This term is already coded */
 
#define TERM_COPIED   0x0008 /* Has a child */
 
#define TERM_ORINFO   0x0010 /* Need to free the WhereTerm.u.pOrInfo object */
 
#define TERM_ANDINFO   0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */
 
#define TERM_OR_OK   0x0040 /* Used during OR-clause processing */
 
#define TERM_VNULL   0x0000 /* Disabled if not using stat4 */
 
#define TERM_LIKEOPT   0x0100 /* Virtual terms from the LIKE optimization */
 
#define TERM_LIKECOND   0x0200 /* Conditionally this LIKE operator term */
 
#define TERM_LIKE   0x0400 /* The original LIKE operator */
 
#define TERM_IS   0x0800 /* Term.pExpr is an IS operator */
 
#define TERM_VARSELECT   0x1000 /* Term.pExpr contains a correlated sub-query */
 
#define TERM_HEURTRUTH   0x2000 /* Heuristic truthProb used */
 
#define TERM_HIGHTRUTH   0 /* Only used with STAT4 */
 
#define initMaskSet(P)   (P)->n=0
 
#define SQLITE_BLDF1_INDEXED   0x0001 /* An index is used */
 
#define SQLITE_BLDF1_UNIQUE   0x0002 /* All keys of a UNIQUE index used */
 
#define SQLITE_BLDF2_2NDPASS   0x0004 /* Second builder pass needed */
 
#define SQLITE_QUERY_PLANNER_LIMIT   20000
 
#define SQLITE_QUERY_PLANNER_LIMIT_INCR   1000
 
#define sqlite3WhereAddScanStatus(a, b, c, d)   ((void)d)
 
#define WO_IN   0x0001
 
#define WO_EQ   0x0002
 
#define WO_LT   (WO_EQ<<(TK_LT-TK_EQ))
 
#define WO_LE   (WO_EQ<<(TK_LE-TK_EQ))
 
#define WO_GT   (WO_EQ<<(TK_GT-TK_EQ))
 
#define WO_GE   (WO_EQ<<(TK_GE-TK_EQ))
 
#define WO_AUX   0x0040 /* Op useful to virtual tables only */
 
#define WO_IS   0x0080
 
#define WO_ISNULL   0x0100
 
#define WO_OR   0x0200 /* Two or more OR-connected terms */
 
#define WO_AND   0x0400 /* Two or more AND-connected terms */
 
#define WO_EQUIV   0x0800 /* Of the form A==B, both columns */
 
#define WO_NOOP   0x1000 /* This term does not restrict search space */
 
#define WO_ALL   0x1fff /* Mask of all possible WO_* values */
 
#define WO_SINGLE   0x01ff /* Mask of all non-compound WO_* values */
 
#define WHERE_COLUMN_EQ   0x00000001 /* x=EXPR */
 
#define WHERE_COLUMN_RANGE   0x00000002 /* x<EXPR and/or x>EXPR */
 
#define WHERE_COLUMN_IN   0x00000004 /* x IN (...) */
 
#define WHERE_COLUMN_NULL   0x00000008 /* x IS NULL */
 
#define WHERE_CONSTRAINT   0x0000000f /* Any of the WHERE_COLUMN_xxx values */
 
#define WHERE_TOP_LIMIT   0x00000010 /* x<EXPR or x<=EXPR constraint */
 
#define WHERE_BTM_LIMIT   0x00000020 /* x>EXPR or x>=EXPR constraint */
 
#define WHERE_BOTH_LIMIT   0x00000030 /* Both x>EXPR and x<EXPR */
 
#define WHERE_IDX_ONLY   0x00000040 /* Use index only - omit table */
 
#define WHERE_IPK   0x00000100 /* x is the INTEGER PRIMARY KEY */
 
#define WHERE_INDEXED   0x00000200 /* WhereLoop.u.btree.pIndex is valid */
 
#define WHERE_VIRTUALTABLE   0x00000400 /* WhereLoop.u.vtab is valid */
 
#define WHERE_IN_ABLE   0x00000800 /* Able to support an IN operator */
 
#define WHERE_ONEROW   0x00001000 /* Selects no more than one row */
 
#define WHERE_MULTI_OR   0x00002000 /* OR using multiple indices */
 
#define WHERE_AUTO_INDEX   0x00004000 /* Uses an ephemeral index */
 
#define WHERE_SKIPSCAN   0x00008000 /* Uses the skip-scan algorithm */
 
#define WHERE_UNQ_WANTED   0x00010000 /* WHERE_ONEROW would have been helpful*/
 
#define WHERE_PARTIALIDX   0x00020000 /* The automatic index is partial */
 
#define WHERE_IN_EARLYOUT   0x00040000 /* Perhaps quit IN loops early */
 
#define WHERE_BIGNULL_SORT   0x00080000 /* Column nEq of index is BIGNULL */
 
#define codeCursorHint(A, B, C, D)   /* No-op */
 
#define whereTraceIndexInfoInputs(A)
 
#define whereTraceIndexInfoOutputs(A)
 
#define ApplyCostMultiplier(C, T)
 
#define WHERETRACE_ALL_LOOPS(W, C)
 
#define OpcodeRewriteTrace(D, K, P)   /* no-op */
 
#define nth_valueInvFunc   noopStepFunc
 
#define nth_valueValueFunc   noopValueFunc
 
#define first_valueInvFunc   noopStepFunc
 
#define first_valueValueFunc   noopValueFunc
 
#define percent_rankFinalizeFunc   percent_rankValueFunc
 
#define cume_distFinalizeFunc   cume_distValueFunc
 
#define ntileFinalizeFunc   ntileValueFunc
 
#define WINDOWFUNCALL(name, nArg, extra)
 
#define WINDOWFUNCNOOP(name, nArg, extra)
 
#define WINDOWFUNCX(name, nArg, extra)
 
#define WINDOW_STARTING_INT   0
 
#define WINDOW_ENDING_INT   1
 
#define WINDOW_NTH_VALUE_INT   2
 
#define WINDOW_STARTING_NUM   3
 
#define WINDOW_ENDING_NUM   4
 
#define WINDOW_RETURN_ROW   1
 
#define WINDOW_AGGINVERSE   2
 
#define WINDOW_AGGSTEP   3
 
#define YYNOERRORRECOVERY   1
 
#define yytestcase(X)   testcase(X)
 
#define YYPARSEFREENEVERNULL   1
 
#define sqlite3Parser_ENGINEALWAYSONSTACK   1
 
#define YYMALLOCARGTYPE   u64
 
#define INTERFACE   1
 
#define YYCODETYPE   unsigned short int
 
#define YYNOCODE   310
 
#define YYACTIONTYPE   unsigned short int
 
#define YYWILDCARD   100
 
#define sqlite3ParserTOKENTYPE   Token
 
#define YYSTACKDEPTH   100
 
#define sqlite3ParserARG_SDECL
 
#define sqlite3ParserARG_PDECL
 
#define sqlite3ParserARG_PARAM
 
#define sqlite3ParserARG_FETCH
 
#define sqlite3ParserARG_STORE
 
#define sqlite3ParserCTX_SDECL   Parse *pParse;
 
#define sqlite3ParserCTX_PDECL   ,Parse *pParse
 
#define sqlite3ParserCTX_PARAM   ,pParse
 
#define sqlite3ParserCTX_FETCH   Parse *pParse=yypParser->pParse;
 
#define sqlite3ParserCTX_STORE   yypParser->pParse=pParse;
 
#define YYFALLBACK   1
 
#define YYNSTATE   553
 
#define YYNRULE   385
 
#define YYNRULE_WITH_ACTION   325
 
#define YYNTOKEN   181
 
#define YY_MAX_SHIFT   552
 
#define YY_MIN_SHIFTREDUCE   803
 
#define YY_MAX_SHIFTREDUCE   1187
 
#define YY_ERROR_ACTION   1188
 
#define YY_ACCEPT_ACTION   1189
 
#define YY_NO_ACTION   1190
 
#define YY_MIN_REDUCE   1191
 
#define YY_MAX_REDUCE   1575
 
#define YY_NLOOKAHEAD   ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
 
#define YY_ACTTAB_COUNT   (1962)
 
#define YY_SHIFT_COUNT   (552)
 
#define YY_SHIFT_MIN   (0)
 
#define YY_SHIFT_MAX   (1951)
 
#define YY_REDUCE_COUNT   (391)
 
#define YY_REDUCE_MIN   (-262)
 
#define YY_REDUCE_MAX   (1625)
 
#define yyTraceShift(X, Y, Z)
 
#define TOKEN   yyminor
 
#define CC_X   0 /* The letter 'x', or start of BLOB literal */
 
#define CC_KYWD   1 /* Alphabetics or '_'. Usable in a keyword */
 
#define CC_ID   2 /* unicode characters usable in IDs */
 
#define CC_DIGIT   3 /* Digits */
 
#define CC_DOLLAR   4 /* '$' */
 
#define CC_VARALPHA   5 /* '@', '#', ':'. Alphabetic SQL variables */
 
#define CC_VARNUM   6 /* '?'. Numeric SQL variables */
 
#define CC_SPACE   7 /* Space characters */
 
#define CC_QUOTE   8 /* '"', '\'', or '`'. String literals, quoted ids */
 
#define CC_QUOTE2   9 /* '['. [...] style quoted ids */
 
#define CC_PIPE   10 /* '|'. Bitwise OR or concatenate */
 
#define CC_MINUS   11 /* '-'. Minus or SQL-style comment */
 
#define CC_LT   12 /* '<'. Part of < or <= or <> */
 
#define CC_GT   13 /* '>'. Part of > or >= */
 
#define CC_EQ   14 /* '='. Part of = or == */
 
#define CC_BANG   15 /* '!'. Part of != */
 
#define CC_SLASH   16 /* '/'. / or c-style comment */
 
#define CC_LP   17 /* '(' */
 
#define CC_RP   18 /* ')' */
 
#define CC_SEMI   19 /* ';' */
 
#define CC_PLUS   20 /* '+' */
 
#define CC_STAR   21 /* '*' */
 
#define CC_PERCENT   22 /* '%' */
 
#define CC_COMMA   23 /* ',' */
 
#define CC_AND   24 /* '&' */
 
#define CC_TILDA   25 /* '~' */
 
#define CC_DOT   26 /* '.' */
 
#define CC_ILLEGAL   27 /* Illegal character */
 
#define CC_NUL   28 /* 0x00 */
 
#define charMap(X)   sqlite3UpperToLower[(unsigned char)X]
 
#define SQLITE_N_KEYWORD   145
 
#define IdChar(C)   ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
 
#define tkSEMI   0
 
#define tkWS   1
 
#define tkOTHER   2
 
#define tkEXPLAIN   3
 
#define tkCREATE   4
 
#define tkTEMP   5
 
#define tkTRIGGER   6
 
#define tkEND   7
 
#define SQLITE_DQS   3
 
#define _FTSINT_H
 
#define SQLITE_SOURCE_ID   "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2"
 

Typedefs

typedef struct sqlite3 sqlite3
 
typedef long long int sqlite_int64
 
typedef unsigned long long int sqlite_uint64
 
typedef sqlite_int64 sqlite3_int64
 
typedef sqlite_uint64 sqlite3_uint64
 
typedef int(* sqlite3_callback) (void *, int, char **, char **)
 
typedef struct sqlite3_file sqlite3_file
 
typedef struct sqlite3_io_methods sqlite3_io_methods
 
typedef struct sqlite3_mutex sqlite3_mutex
 
typedef struct sqlite3_api_routines sqlite3_api_routines
 
typedef struct sqlite3_vfs sqlite3_vfs
 
typedef void(* sqlite3_syscall_ptr) (void)
 
typedef struct sqlite3_mem_methods sqlite3_mem_methods
 
typedef struct sqlite3_stmt sqlite3_stmt
 
typedef struct sqlite3_value sqlite3_value
 
typedef struct sqlite3_context sqlite3_context
 
typedef void(* sqlite3_destructor_type) (void *)
 
typedef struct sqlite3_vtab sqlite3_vtab
 
typedef struct sqlite3_index_info sqlite3_index_info
 
typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor
 
typedef struct sqlite3_module sqlite3_module
 
typedef struct sqlite3_blob sqlite3_blob
 
typedef struct sqlite3_mutex_methods sqlite3_mutex_methods
 
typedef struct sqlite3_str sqlite3_str
 
typedef struct sqlite3_pcache sqlite3_pcache
 
typedef struct sqlite3_pcache_page sqlite3_pcache_page
 
typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2
 
typedef struct sqlite3_pcache_methods sqlite3_pcache_methods
 
typedef struct sqlite3_backup sqlite3_backup
 
typedef struct sqlite3_snapshot sqlite3_snapshot
 
typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry
 
typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info
 
typedef double sqlite3_rtree_dbl
 
typedef struct Fts5ExtensionApi Fts5ExtensionApi
 
typedef struct Fts5Context Fts5Context
 
typedef struct Fts5PhraseIter Fts5PhraseIter
 
typedef void(* fts5_extension_function) (const Fts5ExtensionApi *pApi, Fts5Context *pFts, sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
 
typedef struct Fts5Tokenizer Fts5Tokenizer
 
typedef struct fts5_tokenizer fts5_tokenizer
 
typedef struct fts5_api fts5_api
 
typedef struct Hash Hash
 
typedef struct HashElem HashElem
 
typedef sqlite_int64 i64
 
typedef sqlite_uint64 u64
 
typedef UINT32_TYPE u32
 
typedef UINT16_TYPE u16
 
typedef INT16_TYPE i16
 
typedef UINT8_TYPE u8
 
typedef INT8_TYPE i8
 
typedef u32 tRowcnt
 
typedef INT16_TYPE LogEst
 
typedef u64 uptr
 
typedef struct BusyHandler BusyHandler
 
typedef struct AggInfo AggInfo
 
typedef struct AuthContext AuthContext
 
typedef struct AutoincInfo AutoincInfo
 
typedef struct Bitvec Bitvec
 
typedef struct CollSeq CollSeq
 
typedef struct Column Column
 
typedef struct Db Db
 
typedef struct Schema Schema
 
typedef struct Expr Expr
 
typedef struct ExprList ExprList
 
typedef struct FKey FKey
 
typedef struct FuncDestructor FuncDestructor
 
typedef struct FuncDef FuncDef
 
typedef struct FuncDefHash FuncDefHash
 
typedef struct IdList IdList
 
typedef struct Index Index
 
typedef struct IndexSample IndexSample
 
typedef struct KeyClass KeyClass
 
typedef struct KeyInfo KeyInfo
 
typedef struct Lookaside Lookaside
 
typedef struct LookasideSlot LookasideSlot
 
typedef struct Module Module
 
typedef struct NameContext NameContext
 
typedef struct Parse Parse
 
typedef struct PreUpdate PreUpdate
 
typedef struct PrintfArguments PrintfArguments
 
typedef struct RenameToken RenameToken
 
typedef struct RowSet RowSet
 
typedef struct Savepoint Savepoint
 
typedef struct Select Select
 
typedef struct SQLiteThread SQLiteThread
 
typedef struct SelectDest SelectDest
 
typedef struct SrcList SrcList
 
typedef struct sqlite3_str StrAccum
 
typedef struct Table Table
 
typedef struct TableLock TableLock
 
typedef struct Token Token
 
typedef struct TreeView TreeView
 
typedef struct Trigger Trigger
 
typedef struct TriggerPrg TriggerPrg
 
typedef struct TriggerStep TriggerStep
 
typedef struct UnpackedRecord UnpackedRecord
 
typedef struct Upsert Upsert
 
typedef struct VTable VTable
 
typedef struct VtabCtx VtabCtx
 
typedef struct Walker Walker
 
typedef struct WhereInfo WhereInfo
 
typedef struct Window Window
 
typedef struct With With
 
typedef u64 Bitmask
 
typedef int VList
 
typedef u32 Pgno
 
typedef struct Pager Pager
 
typedef struct PgHdr DbPage
 
typedef struct Btree Btree
 
typedef struct BtCursor BtCursor
 
typedef struct BtShared BtShared
 
typedef struct BtreePayload BtreePayload
 
typedef struct Vdbe Vdbe
 
typedef struct sqlite3_value Mem
 
typedef struct SubProgram SubProgram
 
typedef struct VdbeOp VdbeOp
 
typedef struct VdbeOpList VdbeOpList
 
typedef int(* RecordCompare) (int, const void *, UnpackedRecord *)
 
typedef struct PgHdr PgHdr
 
typedef struct PCache PCache
 
typedef int(* sqlite3_xauth) (void *, int, const char *, const char *, const char *, const char *)
 
typedef i16 ynVar
 
typedef unsigned int yDbMask
 
typedef struct DbFixer DbFixer
 
typedef struct VdbeOp Op
 
typedef unsigned Bool
 
typedef struct VdbeSorter VdbeSorter
 
typedef struct AuxData AuxData
 
typedef struct VdbeCursor VdbeCursor
 
typedef struct VdbeFrame VdbeFrame
 
typedef unsigned bft
 
typedef struct ScanStatus ScanStatus
 
typedef struct DblquoteStr DblquoteStr
 
typedef sqlite3_int64 sqlite3StatValueType
 
typedef struct sqlite3StatType sqlite3StatType
 
typedef struct DateTime DateTime
 
typedef struct BenignMallocHooks BenignMallocHooks
 
typedef unsigned char etByte
 
typedef struct et_info et_info
 
typedef struct unixShm unixShm
 
typedef struct unixShmNode unixShmNode
 
typedef struct unixInodeInfo unixInodeInfo
 
typedef struct UnixUnusedFd UnixUnusedFd
 
typedef struct unixFile unixFile
 
typedef struct PCache1 PCache1
 
typedef struct PgHdr1 PgHdr1
 
typedef struct PgFreeslot PgFreeslot
 
typedef struct PGroup PGroup
 
typedef struct Wal Wal
 
typedef struct PagerSavepoint PagerSavepoint
 
typedef struct WalIndexHdr WalIndexHdr
 
typedef struct WalIterator WalIterator
 
typedef struct WalCkptInfo WalCkptInfo
 
typedef u16 ht_slot
 
typedef struct WalHashLoc WalHashLoc
 
typedef struct WalWriter WalWriter
 
typedef struct MemPage MemPage
 
typedef struct BtLock BtLock
 
typedef struct CellInfo CellInfo
 
typedef struct IntegrityCk IntegrityCk
 
typedef struct CellArray CellArray
 
typedef struct Incrblob Incrblob
 
typedef struct MergeEngine MergeEngine
 
typedef struct PmaReader PmaReader
 
typedef struct PmaWriter PmaWriter
 
typedef struct SorterRecord SorterRecord
 
typedef struct SortSubtask SortSubtask
 
typedef struct SorterFile SorterFile
 
typedef struct SorterList SorterList
 
typedef struct IncrMerger IncrMerger
 
typedef int(* SorterCompare) (SortSubtask *, int *, const void *, int, const void *, int)
 
typedef struct MemJournal MemJournal
 
typedef struct FilePoint FilePoint
 
typedef struct FileChunk FileChunk
 
typedef struct RenameCtx RenameCtx
 
typedef struct StatAccum StatAccum
 
typedef struct StatSample StatSample
 
typedef struct analysisInfo analysisInfo
 
typedef struct SumCtx SumCtx
 
typedef struct CountCtx CountCtx
 
typedef int(* sqlite3_loadext_entry) (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pThunk)
 
typedef struct sqlite3AutoExtList sqlite3AutoExtList
 
typedef struct PragmaName PragmaName
 
typedef struct PragmaVtab PragmaVtab
 
typedef struct PragmaVtabCursor PragmaVtabCursor
 
typedef struct DistinctCtx DistinctCtx
 
typedef struct SortCtx SortCtx
 
typedef struct RowLoadInfo RowLoadInfo
 
typedef struct SubstContext SubstContext
 
typedef struct WhereConst WhereConst
 
typedef struct TabResult TabResult
 
typedef struct WhereClause WhereClause
 
typedef struct WhereMaskSet WhereMaskSet
 
typedef struct WhereOrInfo WhereOrInfo
 
typedef struct WhereAndInfo WhereAndInfo
 
typedef struct WhereLevel WhereLevel
 
typedef struct WhereLoop WhereLoop
 
typedef struct WherePath WherePath
 
typedef struct WhereTerm WhereTerm
 
typedef struct WhereLoopBuilder WhereLoopBuilder
 
typedef struct WhereScan WhereScan
 
typedef struct WhereOrCost WhereOrCost
 
typedef struct WhereOrSet WhereOrSet
 
typedef struct WhereExprMod WhereExprMod
 
typedef struct IdxExprTrans IdxExprTrans
 
typedef struct HiddenIndexInfo HiddenIndexInfo
 
typedef struct WindowRewrite WindowRewrite
 
typedef struct WindowCodeArg WindowCodeArg
 
typedef struct WindowCsrAndReg WindowCsrAndReg
 
typedef struct yyStackEntry yyStackEntry
 
typedef struct yyParser yyParser
 

Functions

SQLITE_PRIVATE const char ** sqlite3CompileOptions (int *pnOpt)
 
SQLITE_API const char * sqlite3_libversion (void)
 
SQLITE_API const char * sqlite3_sourceid (void)
 
SQLITE_API int sqlite3_libversion_number (void)
 
SQLITE_API int sqlite3_compileoption_used (const char *zOptName)
 
SQLITE_API const char * sqlite3_compileoption_get (int N)
 
SQLITE_API int sqlite3_threadsafe (void)
 
SQLITE_API int sqlite3_close (sqlite3 *)
 
SQLITE_API int sqlite3_close_v2 (sqlite3 *)
 
SQLITE_API int sqlite3_exec (sqlite3 *, const char *sql, int(*callback)(void *, int, char **, char **), void *, char **errmsg)
 
SQLITE_API int sqlite3_initialize (void)
 
SQLITE_API int sqlite3_shutdown (void)
 
SQLITE_API int sqlite3_os_init (void)
 
SQLITE_API int sqlite3_os_end (void)
 
SQLITE_API int sqlite3_config (int,...)
 
SQLITE_API int sqlite3_db_config (sqlite3 *, int op,...)
 
SQLITE_API int sqlite3_extended_result_codes (sqlite3 *, int onoff)
 
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid (sqlite3 *)
 
SQLITE_API void sqlite3_set_last_insert_rowid (sqlite3 *, sqlite3_int64)
 
SQLITE_API int sqlite3_changes (sqlite3 *)
 
SQLITE_API int sqlite3_total_changes (sqlite3 *)
 
SQLITE_API void sqlite3_interrupt (sqlite3 *)
 
SQLITE_API int sqlite3_complete (const char *sql)
 
SQLITE_API int sqlite3_complete16 (const void *sql)
 
SQLITE_API int sqlite3_busy_handler (sqlite3 *, int(*)(void *, int), void *)
 
SQLITE_API int sqlite3_busy_timeout (sqlite3 *, int ms)
 
SQLITE_API int sqlite3_get_table (sqlite3 *db, const char *zSql, char ***pazResult, int *pnRow, int *pnColumn, char **pzErrmsg)
 
SQLITE_API void sqlite3_free_table (char **result)
 
SQLITE_API char * sqlite3_mprintf (const char *,...)
 
SQLITE_API char * sqlite3_vmprintf (const char *, va_list)
 
SQLITE_API char * sqlite3_snprintf (int, char *, const char *,...)
 
SQLITE_API char * sqlite3_vsnprintf (int, char *, const char *, va_list)
 
SQLITE_API void * sqlite3_malloc (int)
 
SQLITE_API void * sqlite3_malloc64 (sqlite3_uint64)
 
SQLITE_API void * sqlite3_realloc (void *, int)
 
SQLITE_API void * sqlite3_realloc64 (void *, sqlite3_uint64)
 
SQLITE_API void sqlite3_free (void *)
 
SQLITE_API sqlite3_uint64 sqlite3_msize (void *)
 
SQLITE_API sqlite3_int64 sqlite3_memory_used (void)
 
SQLITE_API sqlite3_int64 sqlite3_memory_highwater (int resetFlag)
 
SQLITE_API void sqlite3_randomness (int N, void *P)
 
SQLITE_API int sqlite3_set_authorizer (sqlite3 *, int(*xAuth)(void *, int, const char *, const char *, const char *, const char *), void *pUserData)
 
SQLITE_API SQLITE_DEPRECATED void * sqlite3_trace (sqlite3 *, void(*xTrace)(void *, const char *), void *)
 
SQLITE_API SQLITE_DEPRECATED void * sqlite3_profile (sqlite3 *, void(*xProfile)(void *, const char *, sqlite3_uint64), void *)
 
SQLITE_API int sqlite3_trace_v2 (sqlite3 *, unsigned uMask, int(*xCallback)(unsigned, void *, void *, void *), void *pCtx)
 
SQLITE_API void sqlite3_progress_handler (sqlite3 *, int, int(*)(void *), void *)
 
SQLITE_API int sqlite3_open (const char *filename, sqlite3 **ppDb)
 
SQLITE_API int sqlite3_open16 (const void *filename, sqlite3 **ppDb)
 
SQLITE_API int sqlite3_open_v2 (const char *filename, sqlite3 **ppDb, int flags, const char *zVfs)
 
SQLITE_API const char * sqlite3_uri_parameter (const char *zFilename, const char *zParam)
 
SQLITE_API int sqlite3_uri_boolean (const char *zFile, const char *zParam, int bDefault)
 
SQLITE_API sqlite3_int64 sqlite3_uri_int64 (const char *, const char *, sqlite3_int64)
 
SQLITE_API const char * sqlite3_uri_key (const char *zFilename, int N)
 
SQLITE_API const char * sqlite3_filename_database (const char *)
 
SQLITE_API const char * sqlite3_filename_journal (const char *)
 
SQLITE_API const char * sqlite3_filename_wal (const char *)
 
SQLITE_API sqlite3_filesqlite3_database_file_object (const char *)
 
SQLITE_API char * sqlite3_create_filename (const char *zDatabase, const char *zJournal, const char *zWal, int nParam, const char **azParam)
 
SQLITE_API void sqlite3_free_filename (char *)
 
SQLITE_API int sqlite3_errcode (sqlite3 *db)
 
SQLITE_API int sqlite3_extended_errcode (sqlite3 *db)
 
SQLITE_API const char * sqlite3_errmsg (sqlite3 *)
 
SQLITE_API const void * sqlite3_errmsg16 (sqlite3 *)
 
SQLITE_API const char * sqlite3_errstr (int)
 
SQLITE_API int sqlite3_limit (sqlite3 *, int id, int newVal)
 
SQLITE_API int sqlite3_prepare (sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail)
 
SQLITE_API int sqlite3_prepare_v2 (sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail)
 
SQLITE_API int sqlite3_prepare_v3 (sqlite3 *db, const char *zSql, int nByte, unsigned int prepFlags, sqlite3_stmt **ppStmt, const char **pzTail)
 
SQLITE_API int sqlite3_prepare16 (sqlite3 *db, const void *zSql, int nByte, sqlite3_stmt **ppStmt, const void **pzTail)
 
SQLITE_API int sqlite3_prepare16_v2 (sqlite3 *db, const void *zSql, int nByte, sqlite3_stmt **ppStmt, const void **pzTail)
 
SQLITE_API int sqlite3_prepare16_v3 (sqlite3 *db, const void *zSql, int nByte, unsigned int prepFlags, sqlite3_stmt **ppStmt, const void **pzTail)
 
SQLITE_API const char * sqlite3_sql (sqlite3_stmt *pStmt)
 
SQLITE_API char * sqlite3_expanded_sql (sqlite3_stmt *pStmt)
 
SQLITE_API const char * sqlite3_normalized_sql (sqlite3_stmt *pStmt)
 
SQLITE_API int sqlite3_stmt_readonly (sqlite3_stmt *pStmt)
 
SQLITE_API int sqlite3_stmt_isexplain (sqlite3_stmt *pStmt)
 
SQLITE_API int sqlite3_stmt_busy (sqlite3_stmt *)
 
SQLITE_API int sqlite3_bind_blob (sqlite3_stmt *, int, const void *, int n, void(*)(void *))
 
SQLITE_API int sqlite3_bind_blob64 (sqlite3_stmt *, int, const void *, sqlite3_uint64, void(*)(void *))
 
SQLITE_API int sqlite3_bind_double (sqlite3_stmt *, int, double)
 
SQLITE_API int sqlite3_bind_int (sqlite3_stmt *, int, int)
 
SQLITE_API int sqlite3_bind_int64 (sqlite3_stmt *, int, sqlite3_int64)
 
SQLITE_API int sqlite3_bind_null (sqlite3_stmt *, int)
 
SQLITE_API int sqlite3_bind_text (sqlite3_stmt *, int, const char *, int, void(*)(void *))
 
SQLITE_API int sqlite3_bind_text16 (sqlite3_stmt *, int, const void *, int, void(*)(void *))
 
SQLITE_API int sqlite3_bind_text64 (sqlite3_stmt *, int, const char *, sqlite3_uint64, void(*)(void *), unsigned char encoding)
 
SQLITE_API int sqlite3_bind_value (sqlite3_stmt *, int, const sqlite3_value *)
 
SQLITE_API int sqlite3_bind_pointer (sqlite3_stmt *, int, void *, const char *, void(*)(void *))
 
SQLITE_API int sqlite3_bind_zeroblob (sqlite3_stmt *, int, int n)
 
SQLITE_API int sqlite3_bind_zeroblob64 (sqlite3_stmt *, int, sqlite3_uint64)
 
SQLITE_API int sqlite3_bind_parameter_count (sqlite3_stmt *)
 
SQLITE_API const char * sqlite3_bind_parameter_name (sqlite3_stmt *, int)
 
SQLITE_API int sqlite3_bind_parameter_index (sqlite3_stmt *, const char *zName)
 
SQLITE_API int sqlite3_clear_bindings (sqlite3_stmt *)
 
SQLITE_API int sqlite3_column_count (sqlite3_stmt *pStmt)
 
SQLITE_API const char * sqlite3_column_name (sqlite3_stmt *, int N)
 
SQLITE_API const void * sqlite3_column_name16 (sqlite3_stmt *, int N)
 
SQLITE_API const char * sqlite3_column_database_name (sqlite3_stmt *, int)
 
SQLITE_API const void * sqlite3_column_database_name16 (sqlite3_stmt *, int)
 
SQLITE_API const char * sqlite3_column_table_name (sqlite3_stmt *, int)
 
SQLITE_API const void * sqlite3_column_table_name16 (sqlite3_stmt *, int)
 
SQLITE_API const char * sqlite3_column_origin_name (sqlite3_stmt *, int)
 
SQLITE_API const void * sqlite3_column_origin_name16 (sqlite3_stmt *, int)
 
SQLITE_API const char * sqlite3_column_decltype (sqlite3_stmt *, int)
 
SQLITE_API const void * sqlite3_column_decltype16 (sqlite3_stmt *, int)
 
SQLITE_API int sqlite3_step (sqlite3_stmt *)
 
SQLITE_API int sqlite3_data_count (sqlite3_stmt *pStmt)
 
SQLITE_API const void * sqlite3_column_blob (sqlite3_stmt *, int iCol)
 
SQLITE_API double sqlite3_column_double (sqlite3_stmt *, int iCol)
 
SQLITE_API int sqlite3_column_int (sqlite3_stmt *, int iCol)
 
SQLITE_API sqlite3_int64 sqlite3_column_int64 (sqlite3_stmt *, int iCol)
 
SQLITE_API const unsigned char * sqlite3_column_text (sqlite3_stmt *, int iCol)
 
SQLITE_API const void * sqlite3_column_text16 (sqlite3_stmt *, int iCol)
 
SQLITE_API sqlite3_valuesqlite3_column_value (sqlite3_stmt *, int iCol)
 
SQLITE_API int sqlite3_column_bytes (sqlite3_stmt *, int iCol)
 
SQLITE_API int sqlite3_column_bytes16 (sqlite3_stmt *, int iCol)
 
SQLITE_API int sqlite3_column_type (sqlite3_stmt *, int iCol)
 
SQLITE_API int sqlite3_finalize (sqlite3_stmt *pStmt)
 
SQLITE_API int sqlite3_reset (sqlite3_stmt *pStmt)
 
SQLITE_API int sqlite3_create_function (sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *))
 
SQLITE_API int sqlite3_create_function16 (sqlite3 *db, const void *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *))
 
SQLITE_API int sqlite3_create_function_v2 (sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *), void(*xDestroy)(void *))
 
SQLITE_API int sqlite3_create_window_function (sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *), void(*xValue)(sqlite3_context *), void(*xInverse)(sqlite3_context *, int, sqlite3_value **), void(*xDestroy)(void *))
 
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count (sqlite3_context *)
 
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired (sqlite3_stmt *)
 
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings (sqlite3_stmt *, sqlite3_stmt *)
 
SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover (void)
 
SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup (void)
 
SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm (void(*)(void *, sqlite3_int64, int), void *, sqlite3_int64)
 
SQLITE_API const void * sqlite3_value_blob (sqlite3_value *)
 
SQLITE_API double sqlite3_value_double (sqlite3_value *)
 
SQLITE_API int sqlite3_value_int (sqlite3_value *)
 
SQLITE_API sqlite3_int64 sqlite3_value_int64 (sqlite3_value *)
 
SQLITE_API void * sqlite3_value_pointer (sqlite3_value *, const char *)
 
SQLITE_API const unsigned char * sqlite3_value_text (sqlite3_value *)
 
SQLITE_API const void * sqlite3_value_text16 (sqlite3_value *)
 
SQLITE_API const void * sqlite3_value_text16le (sqlite3_value *)
 
SQLITE_API const void * sqlite3_value_text16be (sqlite3_value *)
 
SQLITE_API int sqlite3_value_bytes (sqlite3_value *)
 
SQLITE_API int sqlite3_value_bytes16 (sqlite3_value *)
 
SQLITE_API int sqlite3_value_type (sqlite3_value *)
 
SQLITE_API int sqlite3_value_numeric_type (sqlite3_value *)
 
SQLITE_API int sqlite3_value_nochange (sqlite3_value *)
 
SQLITE_API int sqlite3_value_frombind (sqlite3_value *)
 
SQLITE_API unsigned int sqlite3_value_subtype (sqlite3_value *)
 
SQLITE_API sqlite3_valuesqlite3_value_dup (const sqlite3_value *)
 
SQLITE_API void sqlite3_value_free (sqlite3_value *)
 
SQLITE_API void * sqlite3_aggregate_context (sqlite3_context *, int nBytes)
 
SQLITE_API void * sqlite3_user_data (sqlite3_context *)
 
SQLITE_API sqlite3sqlite3_context_db_handle (sqlite3_context *)
 
SQLITE_API void * sqlite3_get_auxdata (sqlite3_context *, int N)
 
SQLITE_API void sqlite3_set_auxdata (sqlite3_context *, int N, void *, void(*)(void *))
 
SQLITE_API void sqlite3_result_blob (sqlite3_context *, const void *, int, void(*)(void *))
 
SQLITE_API void sqlite3_result_blob64 (sqlite3_context *, const void *, sqlite3_uint64, void(*)(void *))
 
SQLITE_API void sqlite3_result_double (sqlite3_context *, double)
 
SQLITE_API void sqlite3_result_error (sqlite3_context *, const char *, int)
 
SQLITE_API void sqlite3_result_error16 (sqlite3_context *, const void *, int)
 
SQLITE_API void sqlite3_result_error_toobig (sqlite3_context *)
 
SQLITE_API void sqlite3_result_error_nomem (sqlite3_context *)
 
SQLITE_API void sqlite3_result_error_code (sqlite3_context *, int)
 
SQLITE_API void sqlite3_result_int (sqlite3_context *, int)
 
SQLITE_API void sqlite3_result_int64 (sqlite3_context *, sqlite3_int64)
 
SQLITE_API void sqlite3_result_null (sqlite3_context *)
 
SQLITE_API void sqlite3_result_text (sqlite3_context *, const char *, int, void(*)(void *))
 
SQLITE_API void sqlite3_result_text64 (sqlite3_context *, const char *, sqlite3_uint64, void(*)(void *), unsigned char encoding)
 
SQLITE_API void sqlite3_result_text16 (sqlite3_context *, const void *, int, void(*)(void *))
 
SQLITE_API void sqlite3_result_text16le (sqlite3_context *, const void *, int, void(*)(void *))
 
SQLITE_API void sqlite3_result_text16be (sqlite3_context *, const void *, int, void(*)(void *))
 
SQLITE_API void sqlite3_result_value (sqlite3_context *, sqlite3_value *)
 
SQLITE_API void sqlite3_result_pointer (sqlite3_context *, void *, const char *, void(*)(void *))
 
SQLITE_API void sqlite3_result_zeroblob (sqlite3_context *, int n)
 
SQLITE_API int sqlite3_result_zeroblob64 (sqlite3_context *, sqlite3_uint64 n)
 
SQLITE_API void sqlite3_result_subtype (sqlite3_context *, unsigned int)
 
SQLITE_API int sqlite3_create_collation (sqlite3 *, const char *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *))
 
SQLITE_API int sqlite3_create_collation_v2 (sqlite3 *, const char *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *), void(*xDestroy)(void *))
 
SQLITE_API int sqlite3_create_collation16 (sqlite3 *, const void *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *))
 
SQLITE_API int sqlite3_collation_needed (sqlite3 *, void *, void(*)(void *, sqlite3 *, int eTextRep, const char *))
 
SQLITE_API int sqlite3_collation_needed16 (sqlite3 *, void *, void(*)(void *, sqlite3 *, int eTextRep, const void *))
 
SQLITE_API int sqlite3_sleep (int)
 
SQLITE_API int sqlite3_win32_set_directory (unsigned long type, void *zValue)
 
SQLITE_API int sqlite3_win32_set_directory8 (unsigned long type, const char *zValue)
 
SQLITE_API int sqlite3_win32_set_directory16 (unsigned long type, const void *zValue)
 
SQLITE_API int sqlite3_get_autocommit (sqlite3 *)
 
SQLITE_API sqlite3sqlite3_db_handle (sqlite3_stmt *)
 
SQLITE_API const char * sqlite3_db_filename (sqlite3 *db, const char *zDbName)
 
SQLITE_API int sqlite3_db_readonly (sqlite3 *db, const char *zDbName)
 
SQLITE_API sqlite3_stmtsqlite3_next_stmt (sqlite3 *pDb, sqlite3_stmt *pStmt)
 
SQLITE_API void * sqlite3_commit_hook (sqlite3 *, int(*)(void *), void *)
 
SQLITE_API void * sqlite3_rollback_hook (sqlite3 *, void(*)(void *), void *)
 
SQLITE_API void * sqlite3_update_hook (sqlite3 *, void(*)(void *, int, char const *, char const *, sqlite3_int64), void *)
 
SQLITE_API int sqlite3_enable_shared_cache (int)
 
SQLITE_API int sqlite3_release_memory (int)
 
SQLITE_API int sqlite3_db_release_memory (sqlite3 *)
 
SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64 (sqlite3_int64 N)
 
SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64 (sqlite3_int64 N)
 
SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit (int N)
 
SQLITE_API int sqlite3_table_column_metadata (sqlite3 *db, const char *zDbName, const char *zTableName, const char *zColumnName, char const **pzDataType, char const **pzCollSeq, int *pNotNull, int *pPrimaryKey, int *pAutoinc)
 
SQLITE_API int sqlite3_load_extension (sqlite3 *db, const char *zFile, const char *zProc, char **pzErrMsg)
 
SQLITE_API int sqlite3_enable_load_extension (sqlite3 *db, int onoff)
 
SQLITE_API int sqlite3_auto_extension (void(*xEntryPoint)(void))
 
SQLITE_API int sqlite3_cancel_auto_extension (void(*xEntryPoint)(void))
 
SQLITE_API void sqlite3_reset_auto_extension (void)
 
SQLITE_API int sqlite3_create_module (sqlite3 *db, const char *zName, const sqlite3_module *p, void *pClientData)
 
SQLITE_API int sqlite3_create_module_v2 (sqlite3 *db, const char *zName, const sqlite3_module *p, void *pClientData, void(*xDestroy)(void *))
 
SQLITE_API int sqlite3_drop_modules (sqlite3 *db, const char **azKeep)
 
SQLITE_API int sqlite3_declare_vtab (sqlite3 *, const char *zSQL)
 
SQLITE_API int sqlite3_overload_function (sqlite3 *, const char *zFuncName, int nArg)
 
SQLITE_API int sqlite3_blob_open (sqlite3 *, const char *zDb, const char *zTable, const char *zColumn, sqlite3_int64 iRow, int flags, sqlite3_blob **ppBlob)
 
SQLITE_API int sqlite3_blob_reopen (sqlite3_blob *, sqlite3_int64)
 
SQLITE_API int sqlite3_blob_close (sqlite3_blob *)
 
SQLITE_API int sqlite3_blob_bytes (sqlite3_blob *)
 
SQLITE_API int sqlite3_blob_read (sqlite3_blob *, void *Z, int N, int iOffset)
 
SQLITE_API int sqlite3_blob_write (sqlite3_blob *, const void *z, int n, int iOffset)
 
SQLITE_API sqlite3_vfssqlite3_vfs_find (const char *zVfsName)
 
SQLITE_API int sqlite3_vfs_register (sqlite3_vfs *, int makeDflt)
 
SQLITE_API int sqlite3_vfs_unregister (sqlite3_vfs *)
 
SQLITE_API sqlite3_mutexsqlite3_mutex_alloc (int)
 
SQLITE_API void sqlite3_mutex_free (sqlite3_mutex *)
 
SQLITE_API void sqlite3_mutex_enter (sqlite3_mutex *)
 
SQLITE_API int sqlite3_mutex_try (sqlite3_mutex *)
 
SQLITE_API void sqlite3_mutex_leave (sqlite3_mutex *)
 
SQLITE_API int sqlite3_mutex_held (sqlite3_mutex *)
 
SQLITE_API int sqlite3_mutex_notheld (sqlite3_mutex *)
 
SQLITE_API sqlite3_mutexsqlite3_db_mutex (sqlite3 *)
 
SQLITE_API int sqlite3_file_control (sqlite3 *, const char *zDbName, int op, void *)
 
SQLITE_API int sqlite3_test_control (int op,...)
 
SQLITE_API int sqlite3_keyword_count (void)
 
SQLITE_API int sqlite3_keyword_name (int, const char **, int *)
 
SQLITE_API int sqlite3_keyword_check (const char *, int)
 
SQLITE_API sqlite3_strsqlite3_str_new (sqlite3 *)
 
SQLITE_API char * sqlite3_str_finish (sqlite3_str *)
 
SQLITE_API void sqlite3_str_appendf (sqlite3_str *, const char *zFormat,...)
 
SQLITE_API void sqlite3_str_vappendf (sqlite3_str *, const char *zFormat, va_list)
 
SQLITE_API void sqlite3_str_append (sqlite3_str *, const char *zIn, int N)
 
SQLITE_API void sqlite3_str_appendall (sqlite3_str *, const char *zIn)
 
SQLITE_API void sqlite3_str_appendchar (sqlite3_str *, int N, char C)
 
SQLITE_API void sqlite3_str_reset (sqlite3_str *)
 
SQLITE_API int sqlite3_str_errcode (sqlite3_str *)
 
SQLITE_API int sqlite3_str_length (sqlite3_str *)
 
SQLITE_API char * sqlite3_str_value (sqlite3_str *)
 
SQLITE_API int sqlite3_status (int op, int *pCurrent, int *pHighwater, int resetFlag)
 
SQLITE_API int sqlite3_status64 (int op, sqlite3_int64 *pCurrent, sqlite3_int64 *pHighwater, int resetFlag)
 
SQLITE_API int sqlite3_db_status (sqlite3 *, int op, int *pCur, int *pHiwtr, int resetFlg)
 
SQLITE_API int sqlite3_stmt_status (sqlite3_stmt *, int op, int resetFlg)
 
SQLITE_API sqlite3_backupsqlite3_backup_init (sqlite3 *pDest, const char *zDestName, sqlite3 *pSource, const char *zSourceName)
 
SQLITE_API int sqlite3_backup_step (sqlite3_backup *p, int nPage)
 
SQLITE_API int sqlite3_backup_finish (sqlite3_backup *p)
 
SQLITE_API int sqlite3_backup_remaining (sqlite3_backup *p)
 
SQLITE_API int sqlite3_backup_pagecount (sqlite3_backup *p)
 
SQLITE_API int sqlite3_unlock_notify (sqlite3 *pBlocked, void(*xNotify)(void **apArg, int nArg), void *pNotifyArg)
 
SQLITE_API int sqlite3_stricmp (const char *, const char *)
 
SQLITE_API int sqlite3_strnicmp (const char *, const char *, int)
 
SQLITE_API int sqlite3_strglob (const char *zGlob, const char *zStr)
 
SQLITE_API int sqlite3_strlike (const char *zGlob, const char *zStr, unsigned int cEsc)
 
SQLITE_API void sqlite3_log (int iErrCode, const char *zFormat,...)
 
SQLITE_API void * sqlite3_wal_hook (sqlite3 *, int(*)(void *, sqlite3 *, const char *, int), void *)
 
SQLITE_API int sqlite3_wal_autocheckpoint (sqlite3 *db, int N)
 
SQLITE_API int sqlite3_wal_checkpoint (sqlite3 *db, const char *zDb)
 
SQLITE_API int sqlite3_wal_checkpoint_v2 (sqlite3 *db, const char *zDb, int eMode, int *pnLog, int *pnCkpt)
 
SQLITE_API int sqlite3_vtab_config (sqlite3 *, int op,...)
 
SQLITE_API int sqlite3_vtab_on_conflict (sqlite3 *)
 
SQLITE_API int sqlite3_vtab_nochange (sqlite3_context *)
 
SQLITE_API SQLITE_EXPERIMENTAL const char * sqlite3_vtab_collation (sqlite3_index_info *, int)
 
SQLITE_API int sqlite3_stmt_scanstatus (sqlite3_stmt *pStmt, int idx, int iScanStatusOp, void *pOut)
 
SQLITE_API void sqlite3_stmt_scanstatus_reset (sqlite3_stmt *)
 
SQLITE_API int sqlite3_db_cacheflush (sqlite3 *)
 
SQLITE_API int sqlite3_system_errno (sqlite3 *)
 
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get (sqlite3 *db, const char *zSchema, sqlite3_snapshot **ppSnapshot)
 
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open (sqlite3 *db, const char *zSchema, sqlite3_snapshot *pSnapshot)
 
SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free (sqlite3_snapshot *)
 
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp (sqlite3_snapshot *p1, sqlite3_snapshot *p2)
 
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover (sqlite3 *db, const char *zDb)
 
SQLITE_API unsigned char * sqlite3_serialize (sqlite3 *db, const char *zSchema, sqlite3_int64 *piSize, unsigned int mFlags)
 
SQLITE_API int sqlite3_deserialize (sqlite3 *db, const char *zSchema, unsigned char *pData, sqlite3_int64 szDb, sqlite3_int64 szBuf, unsigned mFlags)
 
SQLITE_API int sqlite3_rtree_geometry_callback (sqlite3 *db, const char *zGeom, int(*xGeom)(sqlite3_rtree_geometry *, int, sqlite3_rtree_dbl *, int *), void *pContext)
 
SQLITE_API int sqlite3_rtree_query_callback (sqlite3 *db, const char *zQueryFunc, int(*xQueryFunc)(sqlite3_rtree_query_info *), void *pContext, void(*xDestructor)(void *))
 
SQLITE_PRIVATE void sqlite3HashInit (Hash *)
 
SQLITE_PRIVATE void * sqlite3HashInsert (Hash *, const char *pKey, void *pData)
 
SQLITE_PRIVATE void * sqlite3HashFind (const Hash *, const char *pKey)
 
SQLITE_PRIVATE void sqlite3HashClear (Hash *)
 
SQLITE_PRIVATE int sqlite3PagerOpen (sqlite3_vfs *, Pager **ppPager, const char *, int, int, int, void(*)(DbPage *))
 
SQLITE_PRIVATE int sqlite3PagerClose (Pager *pPager, sqlite3 *)
 
SQLITE_PRIVATE int sqlite3PagerReadFileheader (Pager *, int, unsigned char *)
 
SQLITE_PRIVATE void sqlite3PagerSetBusyHandler (Pager *, int(*)(void *), void *)
 
SQLITE_PRIVATE int sqlite3PagerSetPagesize (Pager *, u32 *, int)
 
SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount (Pager *, Pgno)
 
SQLITE_PRIVATE void sqlite3PagerSetCachesize (Pager *, int)
 
SQLITE_PRIVATE int sqlite3PagerSetSpillsize (Pager *, int)
 
SQLITE_PRIVATE void sqlite3PagerSetMmapLimit (Pager *, sqlite3_int64)
 
SQLITE_PRIVATE void sqlite3PagerShrink (Pager *)
 
SQLITE_PRIVATE void sqlite3PagerSetFlags (Pager *, unsigned)
 
SQLITE_PRIVATE int sqlite3PagerLockingMode (Pager *, int)
 
SQLITE_PRIVATE int sqlite3PagerSetJournalMode (Pager *, int)
 
SQLITE_PRIVATE int sqlite3PagerGetJournalMode (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode (Pager *)
 
SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit (Pager *, i64)
 
SQLITE_PRIVATE sqlite3_backup ** sqlite3PagerBackupPtr (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerFlush (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerGet (Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag)
 
SQLITE_PRIVATE DbPagesqlite3PagerLookup (Pager *pPager, Pgno pgno)
 
SQLITE_PRIVATE void sqlite3PagerRef (DbPage *)
 
SQLITE_PRIVATE void sqlite3PagerUnref (DbPage *)
 
SQLITE_PRIVATE void sqlite3PagerUnrefNotNull (DbPage *)
 
SQLITE_PRIVATE void sqlite3PagerUnrefPageOne (DbPage *)
 
SQLITE_PRIVATE int sqlite3PagerWrite (DbPage *)
 
SQLITE_PRIVATE void sqlite3PagerDontWrite (DbPage *)
 
SQLITE_PRIVATE int sqlite3PagerMovepage (Pager *, DbPage *, Pgno, int)
 
SQLITE_PRIVATE int sqlite3PagerPageRefcount (DbPage *)
 
SQLITE_PRIVATE void * sqlite3PagerGetData (DbPage *)
 
SQLITE_PRIVATE void * sqlite3PagerGetExtra (DbPage *)
 
SQLITE_PRIVATE void sqlite3PagerPagecount (Pager *, int *)
 
SQLITE_PRIVATE int sqlite3PagerBegin (Pager *, int exFlag, int)
 
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne (Pager *, const char *zSuper, int)
 
SQLITE_PRIVATE int sqlite3PagerExclusiveLock (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerSync (Pager *pPager, const char *zSuper)
 
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerRollback (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint (Pager *pPager, int n)
 
SQLITE_PRIVATE int sqlite3PagerSavepoint (Pager *pPager, int op, int iSavepoint)
 
SQLITE_PRIVATE int sqlite3PagerSharedLock (Pager *pPager)
 
SQLITE_PRIVATE int sqlite3PagerCheckpoint (Pager *pPager, sqlite3 *, int, int *, int *)
 
SQLITE_PRIVATE int sqlite3PagerWalSupported (Pager *pPager)
 
SQLITE_PRIVATE int sqlite3PagerWalCallback (Pager *pPager)
 
SQLITE_PRIVATE int sqlite3PagerOpenWal (Pager *pPager, int *pisOpen)
 
SQLITE_PRIVATE int sqlite3PagerCloseWal (Pager *pPager, sqlite3 *)
 
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly (Pager *)
 
SQLITE_PRIVATE u32 sqlite3PagerDataVersion (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerMemUsed (Pager *)
 
SQLITE_PRIVATE const char * sqlite3PagerFilename (const Pager *, int)
 
SQLITE_PRIVATE sqlite3_vfssqlite3PagerVfs (Pager *)
 
SQLITE_PRIVATE sqlite3_filesqlite3PagerFile (Pager *)
 
SQLITE_PRIVATE sqlite3_filesqlite3PagerJrnlFile (Pager *)
 
SQLITE_PRIVATE const char * sqlite3PagerJournalname (Pager *)
 
SQLITE_PRIVATE void * sqlite3PagerTempSpace (Pager *)
 
SQLITE_PRIVATE int sqlite3PagerIsMemdb (Pager *)
 
SQLITE_PRIVATE void sqlite3PagerCacheStat (Pager *, int, int, int *)
 
SQLITE_PRIVATE void sqlite3PagerClearCache (Pager *)
 
SQLITE_PRIVATE int sqlite3SectorSize (sqlite3_file *)
 
SQLITE_PRIVATE void sqlite3PagerTruncateImage (Pager *, Pgno)
 
SQLITE_PRIVATE void sqlite3PagerRekey (DbPage *, Pgno, u16)
 
SQLITE_PRIVATE int sqlite3BtreeOpen (sqlite3_vfs *pVfs, const char *zFilename, sqlite3 *db, Btree **ppBtree, int flags, int vfsFlags)
 
SQLITE_PRIVATE int sqlite3BtreeClose (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeSetCacheSize (Btree *, int)
 
SQLITE_PRIVATE int sqlite3BtreeSetSpillSize (Btree *, int)
 
SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags (Btree *, unsigned)
 
SQLITE_PRIVATE int sqlite3BtreeSetPageSize (Btree *p, int nPagesize, int nReserve, int eFix)
 
SQLITE_PRIVATE int sqlite3BtreeGetPageSize (Btree *)
 
SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount (Btree *, Pgno)
 
SQLITE_PRIVATE Pgno sqlite3BtreeLastPage (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeSecureDelete (Btree *, int)
 
SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex (Btree *p)
 
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum (Btree *, int)
 
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeBeginTrans (Btree *, int, int *)
 
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne (Btree *, const char *)
 
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo (Btree *, int)
 
SQLITE_PRIVATE int sqlite3BtreeCommit (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeRollback (Btree *, int, int)
 
SQLITE_PRIVATE int sqlite3BtreeBeginStmt (Btree *, int)
 
SQLITE_PRIVATE int sqlite3BtreeCreateTable (Btree *, Pgno *, int flags)
 
SQLITE_PRIVATE int sqlite3BtreeIsInTrans (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeIsInBackup (Btree *)
 
SQLITE_PRIVATE void * sqlite3BtreeSchema (Btree *, int, void(*)(void *))
 
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked (Btree *pBtree)
 
SQLITE_PRIVATE int sqlite3BtreeLockTable (Btree *pBtree, int iTab, u8 isWriteLock)
 
SQLITE_PRIVATE int sqlite3BtreeSavepoint (Btree *, int, int)
 
SQLITE_PRIVATE const char * sqlite3BtreeGetFilename (Btree *)
 
SQLITE_PRIVATE const char * sqlite3BtreeGetJournalname (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeCopyFile (Btree *, Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeIncrVacuum (Btree *)
 
SQLITE_PRIVATE int sqlite3BtreeDropTable (Btree *, int, int *)
 
SQLITE_PRIVATE int sqlite3BtreeClearTable (Btree *, int, int *)
 
SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreeTripAllCursors (Btree *, int, int)
 
SQLITE_PRIVATE void sqlite3BtreeGetMeta (Btree *pBtree, int idx, u32 *pValue)
 
SQLITE_PRIVATE int sqlite3BtreeUpdateMeta (Btree *, int idx, u32 value)
 
SQLITE_PRIVATE int sqlite3BtreeNewDb (Btree *p)
 
SQLITE_PRIVATE int sqlite3BtreeCursor (Btree *, Pgno iTable, int wrFlag, struct KeyInfo *, BtCursor *pCursor)
 
SQLITE_PRIVATE BtCursorsqlite3BtreeFakeValidCursor (void)
 
SQLITE_PRIVATE int sqlite3BtreeCursorSize (void)
 
SQLITE_PRIVATE void sqlite3BtreeCursorZero (BtCursor *)
 
SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags (BtCursor *, unsigned)
 
SQLITE_PRIVATE int sqlite3BtreeCloseCursor (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked (BtCursor *, UnpackedRecord *pUnKey, i64 intKey, int bias, int *pRes)
 
SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreeCursorRestore (BtCursor *, int *)
 
SQLITE_PRIVATE int sqlite3BtreeDelete (BtCursor *, u8 flags)
 
SQLITE_PRIVATE int sqlite3BtreeInsert (BtCursor *, const BtreePayload *pPayload, int flags, int seekResult)
 
SQLITE_PRIVATE int sqlite3BtreeFirst (BtCursor *, int *pRes)
 
SQLITE_PRIVATE int sqlite3BtreeLast (BtCursor *, int *pRes)
 
SQLITE_PRIVATE int sqlite3BtreeNext (BtCursor *, int flags)
 
SQLITE_PRIVATE int sqlite3BtreeEof (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreePrevious (BtCursor *, int flags)
 
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey (BtCursor *)
 
SQLITE_PRIVATE void sqlite3BtreeCursorPin (BtCursor *)
 
SQLITE_PRIVATE void sqlite3BtreeCursorUnpin (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreePayload (BtCursor *, u32 offset, u32 amt, void *)
 
SQLITE_PRIVATE const void * sqlite3BtreePayloadFetch (BtCursor *, u32 *pAmt)
 
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize (BtCursor *)
 
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize (BtCursor *)
 
SQLITE_PRIVATE char * sqlite3BtreeIntegrityCheck (sqlite3 *, Btree *, Pgno *aRoot, int nRoot, int, int *)
 
SQLITE_PRIVATE struct Pagersqlite3BtreePager (Btree *)
 
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreePayloadChecked (BtCursor *, u32 offset, u32 amt, void *)
 
SQLITE_PRIVATE int sqlite3BtreePutData (BtCursor *, u32 offset, u32 amt, void *)
 
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor (BtCursor *)
 
SQLITE_PRIVATE void sqlite3BtreeClearCursor (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreeSetVersion (Btree *pBt, int iVersion)
 
SQLITE_PRIVATE int sqlite3BtreeCursorHasHint (BtCursor *, unsigned int mask)
 
SQLITE_PRIVATE int sqlite3BtreeIsReadonly (Btree *pBt)
 
SQLITE_PRIVATE int sqlite3HeaderSizeBtree (void)
 
SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreeCount (sqlite3 *, BtCursor *, i64 *)
 
SQLITE_PRIVATE int sqlite3BtreeCheckpoint (Btree *, int, int *, int *)
 
SQLITE_PRIVATE void sqlite3BtreeEnter (Btree *)
 
SQLITE_PRIVATE void sqlite3BtreeEnterAll (sqlite3 *)
 
SQLITE_PRIVATE int sqlite3BtreeSharable (Btree *)
 
SQLITE_PRIVATE void sqlite3BtreeEnterCursor (BtCursor *)
 
SQLITE_PRIVATE int sqlite3BtreeConnectionCount (Btree *)
 
SQLITE_PRIVATE void sqlite3BtreeLeave (Btree *)
 
SQLITE_PRIVATE void sqlite3BtreeLeaveCursor (BtCursor *)
 
SQLITE_PRIVATE void sqlite3BtreeLeaveAll (sqlite3 *)
 
SQLITE_PRIVATE Vdbesqlite3VdbeCreate (Parse *)
 
SQLITE_PRIVATE Parsesqlite3VdbeParser (Vdbe *)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp0 (Vdbe *, int)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp1 (Vdbe *, int, int)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp2 (Vdbe *, int, int, int)
 
SQLITE_PRIVATE int sqlite3VdbeGoto (Vdbe *, int)
 
SQLITE_PRIVATE int sqlite3VdbeLoadString (Vdbe *, int, const char *)
 
SQLITE_PRIVATE void sqlite3VdbeMultiLoad (Vdbe *, int, const char *,...)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp3 (Vdbe *, int, int, int, int)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp4 (Vdbe *, int, int, int, int, const char *zP4, int)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8 (Vdbe *, int, int, int, int, const u8 *, int)
 
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int (Vdbe *, int, int, int, int, int)
 
SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall (Parse *, int, int, int, int, const FuncDef *, int)
 
SQLITE_PRIVATE void sqlite3VdbeEndCoroutine (Vdbe *, int)
 
SQLITE_PRIVATE VdbeOpsqlite3VdbeAddOpList (Vdbe *, int nOp, VdbeOpList const *aOp, int iLineno)
 
SQLITE_PRIVATE void sqlite3VdbeExplain (Parse *, u8, const char *,...)
 
SQLITE_PRIVATE void sqlite3VdbeExplainPop (Parse *)
 
SQLITE_PRIVATE int sqlite3VdbeExplainParent (Parse *)
 
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp (Vdbe *, int, char *)
 
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode (Vdbe *, int addr, u8)
 
SQLITE_PRIVATE void sqlite3VdbeChangeP1 (Vdbe *, int addr, int P1)
 
SQLITE_PRIVATE void sqlite3VdbeChangeP2 (Vdbe *, int addr, int P2)
 
SQLITE_PRIVATE void sqlite3VdbeChangeP3 (Vdbe *, int addr, int P3)
 
SQLITE_PRIVATE void sqlite3VdbeChangeP5 (Vdbe *, u16 P5)
 
SQLITE_PRIVATE void sqlite3VdbeJumpHere (Vdbe *, int addr)
 
SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst (Vdbe *, int addr)
 
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop (Vdbe *, int addr)
 
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode (Vdbe *, u8 op)
 
SQLITE_PRIVATE void sqlite3VdbeChangeP4 (Vdbe *, int addr, const char *zP4, int N)
 
SQLITE_PRIVATE void sqlite3VdbeAppendP4 (Vdbe *, void *pP4, int p4type)
 
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo (Parse *, Index *)
 
SQLITE_PRIVATE void sqlite3VdbeUsesBtree (Vdbe *, int)
 
SQLITE_PRIVATE VdbeOpsqlite3VdbeGetOp (Vdbe *, int)
 
SQLITE_PRIVATE int sqlite3VdbeMakeLabel (Parse *)
 
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeReusable (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeDelete (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeClearObject (sqlite3 *, Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeMakeReady (Vdbe *, Parse *)
 
SQLITE_PRIVATE int sqlite3VdbeFinalize (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeResolveLabel (Vdbe *, int)
 
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeResetStepResult (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeRewind (Vdbe *)
 
SQLITE_PRIVATE int sqlite3VdbeReset (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeSetNumCols (Vdbe *, int)
 
SQLITE_PRIVATE int sqlite3VdbeSetColName (Vdbe *, int, int, const char *, void(*)(void *))
 
SQLITE_PRIVATE void sqlite3VdbeCountChanges (Vdbe *)
 
SQLITE_PRIVATE sqlite3sqlite3VdbeDb (Vdbe *)
 
SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeSetSql (Vdbe *, const char *z, int n, u8)
 
SQLITE_PRIVATE void sqlite3VdbeSwap (Vdbe *, Vdbe *)
 
SQLITE_PRIVATE VdbeOpsqlite3VdbeTakeOpArray (Vdbe *, int *, int *)
 
SQLITE_PRIVATE sqlite3_valuesqlite3VdbeGetBoundValue (Vdbe *, int, u8)
 
SQLITE_PRIVATE void sqlite3VdbeSetVarmask (Vdbe *, int)
 
SQLITE_PRIVATE char * sqlite3VdbeExpandSql (Vdbe *, const char *)
 
SQLITE_PRIVATE int sqlite3MemCompare (const Mem *, const Mem *, const CollSeq *)
 
SQLITE_PRIVATE int sqlite3BlobCompare (const Mem *, const Mem *)
 
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack (KeyInfo *, int, const void *, UnpackedRecord *)
 
SQLITE_PRIVATE int sqlite3VdbeRecordCompare (int, const void *, UnpackedRecord *)
 
SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip (int, const void *, UnpackedRecord *, int)
 
SQLITE_PRIVATE UnpackedRecordsqlite3VdbeAllocUnpackedRecord (KeyInfo *)
 
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare (UnpackedRecord *)
 
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram (Vdbe *, SubProgram *)
 
SQLITE_PRIVATE int sqlite3VdbeHasSubProgram (Vdbe *)
 
SQLITE_PRIVATE int sqlite3NotPureFunc (sqlite3_context *)
 
SQLITE_PRIVATE int sqlite3PcacheInitialize (void)
 
SQLITE_PRIVATE void sqlite3PcacheShutdown (void)
 
SQLITE_PRIVATE void sqlite3PCacheBufferSetup (void *, int sz, int n)
 
SQLITE_PRIVATE int sqlite3PcacheOpen (int szPage, int szExtra, int bPurgeable, int(*xStress)(void *, PgHdr *), void *pStress, PCache *pToInit)
 
SQLITE_PRIVATE int sqlite3PcacheSetPageSize (PCache *, int)
 
SQLITE_PRIVATE int sqlite3PcacheSize (void)
 
SQLITE_PRIVATE sqlite3_pcache_pagesqlite3PcacheFetch (PCache *, Pgno, int createFlag)
 
SQLITE_PRIVATE int sqlite3PcacheFetchStress (PCache *, Pgno, sqlite3_pcache_page **)
 
SQLITE_PRIVATE PgHdrsqlite3PcacheFetchFinish (PCache *, Pgno, sqlite3_pcache_page *pPage)
 
SQLITE_PRIVATE void sqlite3PcacheRelease (PgHdr *)
 
SQLITE_PRIVATE void sqlite3PcacheDrop (PgHdr *)
 
SQLITE_PRIVATE void sqlite3PcacheMakeDirty (PgHdr *)
 
SQLITE_PRIVATE void sqlite3PcacheMakeClean (PgHdr *)
 
SQLITE_PRIVATE void sqlite3PcacheCleanAll (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheClearWritable (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheMove (PgHdr *, Pgno)
 
SQLITE_PRIVATE void sqlite3PcacheTruncate (PCache *, Pgno x)
 
SQLITE_PRIVATE PgHdrsqlite3PcacheDirtyList (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheClose (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheClear (PCache *)
 
SQLITE_PRIVATE int sqlite3PcacheRefCount (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheRef (PgHdr *)
 
SQLITE_PRIVATE int sqlite3PcachePageRefcount (PgHdr *)
 
SQLITE_PRIVATE int sqlite3PcachePagecount (PCache *)
 
SQLITE_PRIVATE void sqlite3PcacheSetCachesize (PCache *, int)
 
SQLITE_PRIVATE int sqlite3PcacheSetSpillsize (PCache *, int)
 
SQLITE_PRIVATE void sqlite3PcacheShrink (PCache *)
 
SQLITE_PRIVATE void sqlite3PCacheSetDefault (void)
 
SQLITE_PRIVATE int sqlite3HeaderSizePcache (void)
 
SQLITE_PRIVATE int sqlite3HeaderSizePcache1 (void)
 
SQLITE_PRIVATE int sqlite3PCachePercentDirty (PCache *)
 
SQLITE_PRIVATE int sqlite3OsInit (void)
 
SQLITE_PRIVATE void sqlite3OsClose (sqlite3_file *)
 
SQLITE_PRIVATE int sqlite3OsRead (sqlite3_file *, void *, int amt, i64 offset)
 
SQLITE_PRIVATE int sqlite3OsWrite (sqlite3_file *, const void *, int amt, i64 offset)
 
SQLITE_PRIVATE int sqlite3OsTruncate (sqlite3_file *, i64 size)
 
SQLITE_PRIVATE int sqlite3OsSync (sqlite3_file *, int)
 
SQLITE_PRIVATE int sqlite3OsFileSize (sqlite3_file *, i64 *pSize)
 
SQLITE_PRIVATE int sqlite3OsLock (sqlite3_file *, int)
 
SQLITE_PRIVATE int sqlite3OsUnlock (sqlite3_file *, int)
 
SQLITE_PRIVATE int sqlite3OsCheckReservedLock (sqlite3_file *id, int *pResOut)
 
SQLITE_PRIVATE int sqlite3OsFileControl (sqlite3_file *, int, void *)
 
SQLITE_PRIVATE void sqlite3OsFileControlHint (sqlite3_file *, int, void *)
 
SQLITE_PRIVATE int sqlite3OsSectorSize (sqlite3_file *id)
 
SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics (sqlite3_file *id)
 
SQLITE_PRIVATE int sqlite3OsShmMap (sqlite3_file *, int, int, int, void volatile **)
 
SQLITE_PRIVATE int sqlite3OsShmLock (sqlite3_file *id, int, int, int)
 
SQLITE_PRIVATE void sqlite3OsShmBarrier (sqlite3_file *id)
 
SQLITE_PRIVATE int sqlite3OsShmUnmap (sqlite3_file *id, int)
 
SQLITE_PRIVATE int sqlite3OsFetch (sqlite3_file *id, i64, int, void **)
 
SQLITE_PRIVATE int sqlite3OsUnfetch (sqlite3_file *, i64, void *)
 
SQLITE_PRIVATE int sqlite3OsOpen (sqlite3_vfs *, const char *, sqlite3_file *, int, int *)
 
SQLITE_PRIVATE int sqlite3OsDelete (sqlite3_vfs *, const char *, int)
 
SQLITE_PRIVATE int sqlite3OsAccess (sqlite3_vfs *, const char *, int, int *pResOut)
 
SQLITE_PRIVATE int sqlite3OsFullPathname (sqlite3_vfs *, const char *, int, char *)
 
SQLITE_PRIVATE void * sqlite3OsDlOpen (sqlite3_vfs *, const char *)
 
SQLITE_PRIVATE void sqlite3OsDlError (sqlite3_vfs *, int, char *)
 
SQLITE_PRIVATE void sqlite3OsDlClose (sqlite3_vfs *, void *)
 
SQLITE_PRIVATE int sqlite3OsRandomness (sqlite3_vfs *, int, char *)
 
SQLITE_PRIVATE int sqlite3OsSleep (sqlite3_vfs *, int)
 
SQLITE_PRIVATE int sqlite3OsGetLastError (sqlite3_vfs *)
 
SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64 (sqlite3_vfs *, sqlite3_int64 *)
 
SQLITE_PRIVATE int sqlite3OsOpenMalloc (sqlite3_vfs *, const char *, sqlite3_file **, int, int *)
 
SQLITE_PRIVATE void sqlite3OsCloseFree (sqlite3_file *)
 
SQLITE_PRIVATE int sqlite3WalkExpr (Walker *, Expr *)
 
SQLITE_PRIVATE int sqlite3WalkExprList (Walker *, ExprList *)
 
SQLITE_PRIVATE int sqlite3WalkSelect (Walker *, Select *)
 
SQLITE_PRIVATE int sqlite3WalkSelectExpr (Walker *, Select *)
 
SQLITE_PRIVATE int sqlite3WalkSelectFrom (Walker *, Select *)
 
SQLITE_PRIVATE int sqlite3ExprWalkNoop (Walker *, Expr *)
 
SQLITE_PRIVATE int sqlite3SelectWalkNoop (Walker *, Select *)
 
SQLITE_PRIVATE int sqlite3SelectWalkFail (Walker *, Select *)
 
SQLITE_PRIVATE int sqlite3WalkerDepthIncrease (Walker *, Select *)
 
SQLITE_PRIVATE void sqlite3WalkerDepthDecrease (Walker *, Select *)
 
SQLITE_PRIVATE void sqlite3WindowDelete (sqlite3 *, Window *)
 
SQLITE_PRIVATE void sqlite3WindowUnlinkFromSelect (Window *)
 
SQLITE_PRIVATE void sqlite3WindowListDelete (sqlite3 *db, Window *p)
 
SQLITE_PRIVATE Windowsqlite3WindowAlloc (Parse *, int, int, Expr *, int, Expr *, u8)
 
SQLITE_PRIVATE void sqlite3WindowAttach (Parse *, Expr *, Window *)
 
SQLITE_PRIVATE void sqlite3WindowLink (Select *pSel, Window *pWin)
 
SQLITE_PRIVATE int sqlite3WindowCompare (Parse *, Window *, Window *, int)
 
SQLITE_PRIVATE void sqlite3WindowCodeInit (Parse *, Select *)
 
SQLITE_PRIVATE void sqlite3WindowCodeStep (Parse *, Select *, WhereInfo *, int, int)
 
SQLITE_PRIVATE int sqlite3WindowRewrite (Parse *, Select *)
 
SQLITE_PRIVATE int sqlite3ExpandSubquery (Parse *, struct SrcList_item *)
 
SQLITE_PRIVATE void sqlite3WindowUpdate (Parse *, Window *, Window *, FuncDef *)
 
SQLITE_PRIVATE Windowsqlite3WindowDup (sqlite3 *db, Expr *pOwner, Window *p)
 
SQLITE_PRIVATE Windowsqlite3WindowListDup (sqlite3 *db, Window *p)
 
SQLITE_PRIVATE void sqlite3WindowFunctions (void)
 
SQLITE_PRIVATE void sqlite3WindowChain (Parse *, Window *, Window *)
 
SQLITE_PRIVATE Windowsqlite3WindowAssemble (Parse *, Window *, ExprList *, ExprList *, Token *)
 
SQLITE_PRIVATE int sqlite3ReportError (int iErr, int lineno, const char *zType)
 
SQLITE_PRIVATE int sqlite3CorruptError (int)
 
SQLITE_PRIVATE int sqlite3MisuseError (int)
 
SQLITE_PRIVATE int sqlite3CantopenError (int)
 
SQLITE_PRIVATE int sqlite3IsIdChar (u8)
 
SQLITE_PRIVATE int sqlite3StrICmp (const char *, const char *)
 
SQLITE_PRIVATE int sqlite3Strlen30 (const char *)
 
SQLITE_PRIVATE char * sqlite3ColumnType (Column *, char *)
 
SQLITE_PRIVATE int sqlite3MallocInit (void)
 
SQLITE_PRIVATE void sqlite3MallocEnd (void)
 
SQLITE_PRIVATE void * sqlite3Malloc (u64)
 
SQLITE_PRIVATE void * sqlite3MallocZero (u64)
 
SQLITE_PRIVATE void * sqlite3DbMallocZero (sqlite3 *, u64)
 
SQLITE_PRIVATE void * sqlite3DbMallocRaw (sqlite3 *, u64)
 
SQLITE_PRIVATE void * sqlite3DbMallocRawNN (sqlite3 *, u64)
 
SQLITE_PRIVATE char * sqlite3DbStrDup (sqlite3 *, const char *)
 
SQLITE_PRIVATE char * sqlite3DbStrNDup (sqlite3 *, const char *, u64)
 
SQLITE_PRIVATE char * sqlite3DbSpanDup (sqlite3 *, const char *, const char *)
 
SQLITE_PRIVATE void * sqlite3Realloc (void *, u64)
 
SQLITE_PRIVATE void * sqlite3DbReallocOrFree (sqlite3 *, void *, u64)
 
SQLITE_PRIVATE void * sqlite3DbRealloc (sqlite3 *, void *, u64)
 
SQLITE_PRIVATE void sqlite3DbFree (sqlite3 *, void *)
 
SQLITE_PRIVATE void sqlite3DbFreeNN (sqlite3 *, void *)
 
SQLITE_PRIVATE int sqlite3MallocSize (void *)
 
SQLITE_PRIVATE int sqlite3DbMallocSize (sqlite3 *, void *)
 
SQLITE_PRIVATE void * sqlite3PageMalloc (int)
 
SQLITE_PRIVATE void sqlite3PageFree (void *)
 
SQLITE_PRIVATE void sqlite3MemSetDefault (void)
 
SQLITE_PRIVATE void sqlite3BenignMallocHooks (void(*)(void), void(*)(void))
 
SQLITE_PRIVATE int sqlite3HeapNearlyFull (void)
 
SQLITE_PRIVATE sqlite3_mutex_methods const * sqlite3DefaultMutex (void)
 
SQLITE_PRIVATE sqlite3_mutex_methods const * sqlite3NoopMutex (void)
 
SQLITE_PRIVATE sqlite3_mutexsqlite3MutexAlloc (int)
 
SQLITE_PRIVATE int sqlite3MutexInit (void)
 
SQLITE_PRIVATE int sqlite3MutexEnd (void)
 
SQLITE_PRIVATE void sqlite3MemoryBarrier (void)
 
SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue (int)
 
SQLITE_PRIVATE void sqlite3StatusUp (int, int)
 
SQLITE_PRIVATE void sqlite3StatusDown (int, int)
 
SQLITE_PRIVATE void sqlite3StatusHighwater (int, int)
 
SQLITE_PRIVATE int sqlite3LookasideUsed (sqlite3 *, int *)
 
SQLITE_PRIVATE sqlite3_mutexsqlite3Pcache1Mutex (void)
 
SQLITE_PRIVATE sqlite3_mutexsqlite3MallocMutex (void)
 
SQLITE_PRIVATE int sqlite3IsNaN (double)
 
SQLITE_PRIVATE char * sqlite3MPrintf (sqlite3 *, const char *,...)
 
SQLITE_PRIVATE char * sqlite3VMPrintf (sqlite3 *, const char *, va_list)
 
SQLITE_PRIVATE void sqlite3SetString (char **, sqlite3 *, const char *)
 
SQLITE_PRIVATE void sqlite3ErrorMsg (Parse *, const char *,...)
 
SQLITE_PRIVATE int sqlite3ErrorToParser (sqlite3 *, int)
 
SQLITE_PRIVATE void sqlite3Dequote (char *)
 
SQLITE_PRIVATE void sqlite3DequoteExpr (Expr *)
 
SQLITE_PRIVATE void sqlite3TokenInit (Token *, char *)
 
SQLITE_PRIVATE int sqlite3KeywordCode (const unsigned char *, int)
 
SQLITE_PRIVATE int sqlite3RunParser (Parse *, const char *, char **)
 
SQLITE_PRIVATE void sqlite3FinishCoding (Parse *)
 
SQLITE_PRIVATE int sqlite3GetTempReg (Parse *)
 
SQLITE_PRIVATE void sqlite3ReleaseTempReg (Parse *, int)
 
SQLITE_PRIVATE int sqlite3GetTempRange (Parse *, int)
 
SQLITE_PRIVATE void sqlite3ReleaseTempRange (Parse *, int, int)
 
SQLITE_PRIVATE void sqlite3ClearTempRegCache (Parse *)
 
SQLITE_PRIVATE Exprsqlite3ExprAlloc (sqlite3 *, int, const Token *, int)
 
SQLITE_PRIVATE Exprsqlite3Expr (sqlite3 *, int, const char *)
 
SQLITE_PRIVATE void sqlite3ExprAttachSubtrees (sqlite3 *, Expr *, Expr *, Expr *)
 
SQLITE_PRIVATE Exprsqlite3PExpr (Parse *, int, Expr *, Expr *)
 
SQLITE_PRIVATE void sqlite3PExprAddSelect (Parse *, Expr *, Select *)
 
SQLITE_PRIVATE Exprsqlite3ExprAnd (Parse *, Expr *, Expr *)
 
SQLITE_PRIVATE Exprsqlite3ExprSimplifiedAndOr (Expr *)
 
SQLITE_PRIVATE Exprsqlite3ExprFunction (Parse *, ExprList *, Token *, int)
 
SQLITE_PRIVATE void sqlite3ExprFunctionUsable (Parse *, Expr *, FuncDef *)
 
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber (Parse *, Expr *, u32)
 
SQLITE_PRIVATE void sqlite3ExprDelete (sqlite3 *, Expr *)
 
SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete (Parse *, Expr *)
 
SQLITE_PRIVATE ExprListsqlite3ExprListAppend (Parse *, ExprList *, Expr *)
 
SQLITE_PRIVATE ExprListsqlite3ExprListAppendVector (Parse *, ExprList *, IdList *, Expr *)
 
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder (ExprList *, int, int)
 
SQLITE_PRIVATE void sqlite3ExprListSetName (Parse *, ExprList *, Token *, int)
 
SQLITE_PRIVATE void sqlite3ExprListSetSpan (Parse *, ExprList *, const char *, const char *)
 
SQLITE_PRIVATE void sqlite3ExprListDelete (sqlite3 *, ExprList *)
 
SQLITE_PRIVATE u32 sqlite3ExprListFlags (const ExprList *)
 
SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage (Index *)
 
SQLITE_PRIVATE int sqlite3Init (sqlite3 *, char **)
 
SQLITE_PRIVATE int sqlite3InitCallback (void *, int, char **, char **)
 
SQLITE_PRIVATE int sqlite3InitOne (sqlite3 *, int, char **, u32)
 
SQLITE_PRIVATE void sqlite3Pragma (Parse *, Token *, Token *, Token *, int)
 
SQLITE_PRIVATE Modulesqlite3PragmaVtabRegister (sqlite3 *, const char *zName)
 
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3ResetOneSchema (sqlite3 *, int)
 
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3CommitInternalChanges (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3DeleteColumnNames (sqlite3 *, Table *)
 
SQLITE_PRIVATE int sqlite3ColumnsFromExprList (Parse *, ExprList *, i16 *, Column **)
 
SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation (Parse *, Table *, Select *, char)
 
SQLITE_PRIVATE Tablesqlite3ResultSetOfSelect (Parse *, Select *, char)
 
SQLITE_PRIVATE void sqlite3OpenSchemaTable (Parse *, int)
 
SQLITE_PRIVATE Indexsqlite3PrimaryKeyIndex (Table *)
 
SQLITE_PRIVATE i16 sqlite3TableColumnToIndex (Index *, i16)
 
SQLITE_PRIVATE i16 sqlite3TableColumnToStorage (Table *, i16)
 
SQLITE_PRIVATE i16 sqlite3StorageColumnToTable (Table *, i16)
 
SQLITE_PRIVATE void sqlite3StartTable (Parse *, Token *, Token *, int, int, int, int)
 
SQLITE_PRIVATE void sqlite3AddColumn (Parse *, Token *, Token *)
 
SQLITE_PRIVATE void sqlite3AddNotNull (Parse *, int)
 
SQLITE_PRIVATE void sqlite3AddPrimaryKey (Parse *, ExprList *, int, int, int)
 
SQLITE_PRIVATE void sqlite3AddCheckConstraint (Parse *, Expr *)
 
SQLITE_PRIVATE void sqlite3AddDefaultValue (Parse *, Expr *, const char *, const char *)
 
SQLITE_PRIVATE void sqlite3AddCollateType (Parse *, Token *)
 
SQLITE_PRIVATE void sqlite3AddGenerated (Parse *, Expr *, Token *)
 
SQLITE_PRIVATE void sqlite3EndTable (Parse *, Token *, Token *, u8, Select *)
 
SQLITE_PRIVATE int sqlite3ParseUri (const char *, const char *, unsigned int *, sqlite3_vfs **, char **, char **)
 
SQLITE_PRIVATE Btreesqlite3DbNameToBtree (sqlite3 *, const char *)
 
SQLITE_PRIVATE int sqlite3FaultSim (int)
 
SQLITE_PRIVATE Bitvecsqlite3BitvecCreate (u32)
 
SQLITE_PRIVATE int sqlite3BitvecTest (Bitvec *, u32)
 
SQLITE_PRIVATE int sqlite3BitvecTestNotNull (Bitvec *, u32)
 
SQLITE_PRIVATE int sqlite3BitvecSet (Bitvec *, u32)
 
SQLITE_PRIVATE void sqlite3BitvecClear (Bitvec *, u32, void *)
 
SQLITE_PRIVATE void sqlite3BitvecDestroy (Bitvec *)
 
SQLITE_PRIVATE u32 sqlite3BitvecSize (Bitvec *)
 
SQLITE_PRIVATE int sqlite3BitvecBuiltinTest (int, int *)
 
SQLITE_PRIVATE RowSetsqlite3RowSetInit (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3RowSetDelete (void *)
 
SQLITE_PRIVATE void sqlite3RowSetClear (void *)
 
SQLITE_PRIVATE void sqlite3RowSetInsert (RowSet *, i64)
 
SQLITE_PRIVATE int sqlite3RowSetTest (RowSet *, int iBatch, i64)
 
SQLITE_PRIVATE int sqlite3RowSetNext (RowSet *, i64 *)
 
SQLITE_PRIVATE void sqlite3CreateView (Parse *, Token *, Token *, Token *, ExprList *, Select *, int, int)
 
SQLITE_PRIVATE int sqlite3ViewGetColumnNames (Parse *, Table *)
 
SQLITE_PRIVATE void sqlite3DropTable (Parse *, SrcList *, int, int)
 
SQLITE_PRIVATE void sqlite3CodeDropTable (Parse *, Table *, int, int)
 
SQLITE_PRIVATE void sqlite3DeleteTable (sqlite3 *, Table *)
 
SQLITE_PRIVATE void sqlite3FreeIndex (sqlite3 *, Index *)
 
SQLITE_PRIVATE void sqlite3AutoincrementBegin (Parse *pParse)
 
SQLITE_PRIVATE void sqlite3AutoincrementEnd (Parse *pParse)
 
SQLITE_PRIVATE void sqlite3Insert (Parse *, SrcList *, Select *, IdList *, int, Upsert *)
 
SQLITE_PRIVATE void sqlite3ComputeGeneratedColumns (Parse *, int, Table *)
 
SQLITE_PRIVATE void * sqlite3ArrayAllocate (sqlite3 *, void *, int, int *, int *)
 
SQLITE_PRIVATE IdListsqlite3IdListAppend (Parse *, IdList *, Token *)
 
SQLITE_PRIVATE int sqlite3IdListIndex (IdList *, const char *)
 
SQLITE_PRIVATE SrcListsqlite3SrcListEnlarge (Parse *, SrcList *, int, int)
 
SQLITE_PRIVATE SrcListsqlite3SrcListAppendList (Parse *pParse, SrcList *p1, SrcList *p2)
 
SQLITE_PRIVATE SrcListsqlite3SrcListAppend (Parse *, SrcList *, Token *, Token *)
 
SQLITE_PRIVATE SrcListsqlite3SrcListAppendFromTerm (Parse *, SrcList *, Token *, Token *, Token *, Select *, Expr *, IdList *)
 
SQLITE_PRIVATE void sqlite3SrcListIndexedBy (Parse *, SrcList *, Token *)
 
SQLITE_PRIVATE void sqlite3SrcListFuncArgs (Parse *, SrcList *, ExprList *)
 
SQLITE_PRIVATE int sqlite3IndexedByLookup (Parse *, struct SrcList_item *)
 
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType (SrcList *)
 
SQLITE_PRIVATE void sqlite3SrcListAssignCursors (Parse *, SrcList *)
 
SQLITE_PRIVATE void sqlite3IdListDelete (sqlite3 *, IdList *)
 
SQLITE_PRIVATE void sqlite3SrcListDelete (sqlite3 *, SrcList *)
 
SQLITE_PRIVATE Indexsqlite3AllocateIndexObject (sqlite3 *, i16, int, char **)
 
SQLITE_PRIVATE void sqlite3CreateIndex (Parse *, Token *, Token *, SrcList *, ExprList *, int, Token *, Expr *, int, int, u8)
 
SQLITE_PRIVATE void sqlite3DropIndex (Parse *, SrcList *, int)
 
SQLITE_PRIVATE int sqlite3Select (Parse *, Select *, SelectDest *)
 
SQLITE_PRIVATE Selectsqlite3SelectNew (Parse *, ExprList *, SrcList *, Expr *, ExprList *, Expr *, ExprList *, u32, Expr *)
 
SQLITE_PRIVATE void sqlite3SelectDelete (sqlite3 *, Select *)
 
SQLITE_PRIVATE Tablesqlite3SrcListLookup (Parse *, SrcList *)
 
SQLITE_PRIVATE int sqlite3IsReadOnly (Parse *, Table *, int)
 
SQLITE_PRIVATE void sqlite3OpenTable (Parse *, int iCur, int iDb, Table *, int)
 
SQLITE_PRIVATE void sqlite3DeleteFrom (Parse *, SrcList *, Expr *, ExprList *, Expr *)
 
SQLITE_PRIVATE void sqlite3Update (Parse *, SrcList *, ExprList *, Expr *, int, ExprList *, Expr *, Upsert *)
 
SQLITE_PRIVATE WhereInfosqlite3WhereBegin (Parse *, SrcList *, Expr *, ExprList *, ExprList *, u16, int)
 
SQLITE_PRIVATE void sqlite3WhereEnd (WhereInfo *)
 
SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereIsDistinct (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereIsOrdered (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereIsSorted (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereContinueLabel (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereBreakLabel (WhereInfo *)
 
SQLITE_PRIVATE int sqlite3WhereOkOnePass (WhereInfo *, int *)
 
SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek (WhereInfo *)
 
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn (Parse *, Index *, int, int, int)
 
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn (Parse *, Table *, int, int, int, u8)
 
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable (Vdbe *, Table *, int, int, int)
 
SQLITE_PRIVATE void sqlite3ExprCodeMove (Parse *, int, int, int)
 
SQLITE_PRIVATE void sqlite3ExprCode (Parse *, Expr *, int)
 
SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn (Parse *, Column *, int)
 
SQLITE_PRIVATE void sqlite3ExprCodeCopy (Parse *, Expr *, int)
 
SQLITE_PRIVATE void sqlite3ExprCodeFactorable (Parse *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce (Parse *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprCodeTemp (Parse *, Expr *, int *)
 
SQLITE_PRIVATE int sqlite3ExprCodeTarget (Parse *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprCodeExprList (Parse *, ExprList *, int, int, u8)
 
SQLITE_PRIVATE void sqlite3ExprIfTrue (Parse *, Expr *, int, int)
 
SQLITE_PRIVATE void sqlite3ExprIfFalse (Parse *, Expr *, int, int)
 
SQLITE_PRIVATE void sqlite3ExprIfFalseDup (Parse *, Expr *, int, int)
 
SQLITE_PRIVATE Tablesqlite3FindTable (sqlite3 *, const char *, const char *)
 
SQLITE_PRIVATE Tablesqlite3LocateTable (Parse *, u32 flags, const char *, const char *)
 
SQLITE_PRIVATE Tablesqlite3LocateTableItem (Parse *, u32 flags, struct SrcList_item *)
 
SQLITE_PRIVATE Indexsqlite3FindIndex (sqlite3 *, const char *, const char *)
 
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable (sqlite3 *, int, const char *)
 
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex (sqlite3 *, int, const char *)
 
SQLITE_PRIVATE void sqlite3Vacuum (Parse *, Token *, Expr *)
 
SQLITE_PRIVATE int sqlite3RunVacuum (char **, sqlite3 *, int, sqlite3_value *)
 
SQLITE_PRIVATE char * sqlite3NameFromToken (sqlite3 *, Token *)
 
SQLITE_PRIVATE int sqlite3ExprCompare (Parse *, Expr *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprCompareSkip (Expr *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprListCompare (ExprList *, ExprList *, int)
 
SQLITE_PRIVATE int sqlite3ExprImpliesExpr (Parse *, Expr *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow (Expr *, int)
 
SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit (Walker *, Parse *)
 
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates (NameContext *, Expr *)
 
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList (NameContext *, ExprList *)
 
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex (Expr *, int iCur, Index *pIdx)
 
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc (Expr *, SrcList *)
 
SQLITE_PRIVATE Vdbesqlite3GetVdbe (Parse *)
 
SQLITE_PRIVATE void sqlite3PrngSaveState (void)
 
SQLITE_PRIVATE void sqlite3PrngRestoreState (void)
 
SQLITE_PRIVATE void sqlite3RollbackAll (sqlite3 *, int)
 
SQLITE_PRIVATE void sqlite3CodeVerifySchema (Parse *, int)
 
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema (Parse *, const char *zDb)
 
SQLITE_PRIVATE void sqlite3BeginTransaction (Parse *, int)
 
SQLITE_PRIVATE void sqlite3EndTransaction (Parse *, int)
 
SQLITE_PRIVATE void sqlite3Savepoint (Parse *, int, Token *)
 
SQLITE_PRIVATE void sqlite3CloseSavepoints (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie (sqlite3 *)
 
SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse (const char *)
 
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse (Expr *)
 
SQLITE_PRIVATE int sqlite3ExprTruthValue (const Expr *)
 
SQLITE_PRIVATE int sqlite3ExprIsConstant (Expr *)
 
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin (Expr *)
 
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction (Expr *, u8)
 
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy (Parse *, Expr *, ExprList *)
 
SQLITE_PRIVATE int sqlite3ExprIsTableConstant (Expr *, int)
 
SQLITE_PRIVATE int sqlite3ExprIsInteger (Expr *, int *)
 
SQLITE_PRIVATE int sqlite3ExprCanBeNull (const Expr *)
 
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange (const Expr *, char)
 
SQLITE_PRIVATE int sqlite3IsRowid (const char *)
 
SQLITE_PRIVATE void sqlite3GenerateRowDelete (Parse *, Table *, Trigger *, int, int, int, i16, u8, u8, u8, int)
 
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete (Parse *, Table *, int, int, int *, int)
 
SQLITE_PRIVATE int sqlite3GenerateIndexKey (Parse *, Index *, int, int, int, int *, Index *, int)
 
SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel (Parse *, int)
 
SQLITE_PRIVATE int sqlite3ExprReferencesUpdatedColumn (Expr *, int *, int)
 
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks (Parse *, Table *, int *, int, int, int, int, u8, u8, int, int *, int *, Upsert *)
 
SQLITE_PRIVATE void sqlite3CompleteInsertion (Parse *, Table *, int, int, int, int *, int, int, int)
 
SQLITE_PRIVATE int sqlite3OpenTableAndIndices (Parse *, Table *, int, u8, int, u8 *, int *, int *)
 
SQLITE_PRIVATE void sqlite3BeginWriteOperation (Parse *, int, int)
 
SQLITE_PRIVATE void sqlite3MultiWrite (Parse *)
 
SQLITE_PRIVATE void sqlite3MayAbort (Parse *)
 
SQLITE_PRIVATE void sqlite3HaltConstraint (Parse *, int, int, char *, i8, u8)
 
SQLITE_PRIVATE void sqlite3UniqueConstraint (Parse *, int, Index *)
 
SQLITE_PRIVATE void sqlite3RowidConstraint (Parse *, int, Table *)
 
SQLITE_PRIVATE Exprsqlite3ExprDup (sqlite3 *, Expr *, int)
 
SQLITE_PRIVATE ExprListsqlite3ExprListDup (sqlite3 *, ExprList *, int)
 
SQLITE_PRIVATE SrcListsqlite3SrcListDup (sqlite3 *, SrcList *, int)
 
SQLITE_PRIVATE IdListsqlite3IdListDup (sqlite3 *, IdList *)
 
SQLITE_PRIVATE Selectsqlite3SelectDup (sqlite3 *, Select *, int)
 
SQLITE_PRIVATE FuncDefsqlite3FunctionSearch (int, const char *)
 
SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs (FuncDef *, int)
 
SQLITE_PRIVATE FuncDefsqlite3FindFunction (sqlite3 *, const char *, int, u8, u8)
 
SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions (void)
 
SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions (void)
 
SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions (sqlite3 *)
 
SQLITE_PRIVATE int sqlite3SafetyCheckOk (sqlite3 *)
 
SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3ChangeCookie (Parse *, int)
 
SQLITE_PRIVATE void sqlite3MaterializeView (Parse *, Table *, Expr *, ExprList *, Expr *, int)
 
SQLITE_PRIVATE void sqlite3BeginTrigger (Parse *, Token *, Token *, int, int, IdList *, SrcList *, Expr *, int, int)
 
SQLITE_PRIVATE void sqlite3FinishTrigger (Parse *, TriggerStep *, Token *)
 
SQLITE_PRIVATE void sqlite3DropTrigger (Parse *, SrcList *, int)
 
SQLITE_PRIVATE void sqlite3DropTriggerPtr (Parse *, Trigger *)
 
SQLITE_PRIVATE Triggersqlite3TriggersExist (Parse *, Table *, int, ExprList *, int *pMask)
 
SQLITE_PRIVATE Triggersqlite3TriggerList (Parse *, Table *)
 
SQLITE_PRIVATE void sqlite3CodeRowTrigger (Parse *, Trigger *, int, ExprList *, int, Table *, int, int, int)
 
SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect (Parse *, Trigger *, Table *, int, int, int)
 
void sqliteViewTriggers (Parse *, Table *, Expr *, int, ExprList *)
 
SQLITE_PRIVATE void sqlite3DeleteTriggerStep (sqlite3 *, TriggerStep *)
 
SQLITE_PRIVATE TriggerStepsqlite3TriggerSelectStep (sqlite3 *, Select *, const char *, const char *)
 
SQLITE_PRIVATE TriggerStepsqlite3TriggerInsertStep (Parse *, Token *, IdList *, Select *, u8, Upsert *, const char *, const char *)
 
SQLITE_PRIVATE TriggerStepsqlite3TriggerUpdateStep (Parse *, Token *, SrcList *, ExprList *, Expr *, u8, const char *, const char *)
 
SQLITE_PRIVATE TriggerStepsqlite3TriggerDeleteStep (Parse *, Token *, Expr *, const char *, const char *)
 
SQLITE_PRIVATE void sqlite3DeleteTrigger (sqlite3 *, Trigger *)
 
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger (sqlite3 *, int, const char *)
 
SQLITE_PRIVATE u32 sqlite3TriggerColmask (Parse *, Trigger *, ExprList *, int, int, Table *, int)
 
SQLITE_PRIVATE SrcListsqlite3TriggerStepSrc (Parse *, TriggerStep *)
 
SQLITE_PRIVATE int sqlite3JoinType (Parse *, Token *, Token *, Token *)
 
SQLITE_PRIVATE void sqlite3SetJoinExpr (Expr *, int)
 
SQLITE_PRIVATE void sqlite3CreateForeignKey (Parse *, ExprList *, Token *, ExprList *, int)
 
SQLITE_PRIVATE void sqlite3DeferForeignKey (Parse *, int)
 
SQLITE_PRIVATE void sqlite3AuthRead (Parse *, Expr *, Schema *, SrcList *)
 
SQLITE_PRIVATE int sqlite3AuthCheck (Parse *, int, const char *, const char *, const char *)
 
SQLITE_PRIVATE void sqlite3AuthContextPush (Parse *, AuthContext *, const char *)
 
SQLITE_PRIVATE void sqlite3AuthContextPop (AuthContext *)
 
SQLITE_PRIVATE int sqlite3AuthReadCol (Parse *, const char *, const char *, int)
 
SQLITE_PRIVATE int sqlite3DbIsNamed (sqlite3 *db, int iDb, const char *zName)
 
SQLITE_PRIVATE void sqlite3Attach (Parse *, Expr *, Expr *, Expr *)
 
SQLITE_PRIVATE void sqlite3Detach (Parse *, Expr *)
 
SQLITE_PRIVATE void sqlite3FixInit (DbFixer *, Parse *, int, const char *, const Token *)
 
SQLITE_PRIVATE int sqlite3FixSrcList (DbFixer *, SrcList *)
 
SQLITE_PRIVATE int sqlite3FixSelect (DbFixer *, Select *)
 
SQLITE_PRIVATE int sqlite3FixExpr (DbFixer *, Expr *)
 
SQLITE_PRIVATE int sqlite3FixExprList (DbFixer *, ExprList *)
 
SQLITE_PRIVATE int sqlite3FixTriggerStep (DbFixer *, TriggerStep *)
 
SQLITE_PRIVATE int sqlite3RealSameAsInt (double, sqlite3_int64)
 
SQLITE_PRIVATE void sqlite3Int64ToText (i64, char *)
 
SQLITE_PRIVATE int sqlite3AtoF (const char *z, double *, int, u8)
 
SQLITE_PRIVATE int sqlite3GetInt32 (const char *, int *)
 
SQLITE_PRIVATE int sqlite3GetUInt32 (const char *, u32 *)
 
SQLITE_PRIVATE int sqlite3Atoi (const char *)
 
SQLITE_PRIVATE int sqlite3Utf16ByteLen (const void *pData, int nChar)
 
SQLITE_PRIVATE int sqlite3Utf8CharLen (const char *pData, int nByte)
 
SQLITE_PRIVATE u32 sqlite3Utf8Read (const u8 **)
 
SQLITE_PRIVATE LogEst sqlite3LogEst (u64)
 
SQLITE_PRIVATE LogEst sqlite3LogEstAdd (LogEst, LogEst)
 
SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble (double)
 
SQLITE_PRIVATE VListsqlite3VListAdd (sqlite3 *, VList *, const char *, int, int)
 
SQLITE_PRIVATE const char * sqlite3VListNumToName (VList *, int)
 
SQLITE_PRIVATE int sqlite3VListNameToNum (VList *, const char *, int)
 
SQLITE_PRIVATE int sqlite3PutVarint (unsigned char *, u64)
 
SQLITE_PRIVATE u8 sqlite3GetVarint (const unsigned char *, u64 *)
 
SQLITE_PRIVATE u8 sqlite3GetVarint32 (const unsigned char *, u32 *)
 
SQLITE_PRIVATE int sqlite3VarintLen (u64 v)
 
SQLITE_PRIVATE const char * sqlite3IndexAffinityStr (sqlite3 *, Index *)
 
SQLITE_PRIVATE void sqlite3TableAffinity (Vdbe *, Table *, int)
 
SQLITE_PRIVATE char sqlite3CompareAffinity (const Expr *pExpr, char aff2)
 
SQLITE_PRIVATE int sqlite3IndexAffinityOk (const Expr *pExpr, char idx_affinity)
 
SQLITE_PRIVATE char sqlite3TableColumnAffinity (Table *, int)
 
SQLITE_PRIVATE char sqlite3ExprAffinity (const Expr *pExpr)
 
SQLITE_PRIVATE int sqlite3Atoi64 (const char *, i64 *, int, u8)
 
SQLITE_PRIVATE int sqlite3DecOrHexToI64 (const char *, i64 *)
 
SQLITE_PRIVATE void sqlite3ErrorWithMsg (sqlite3 *, int, const char *,...)
 
SQLITE_PRIVATE void sqlite3Error (sqlite3 *, int)
 
SQLITE_PRIVATE void sqlite3SystemError (sqlite3 *, int)
 
SQLITE_PRIVATE void * sqlite3HexToBlob (sqlite3 *, const char *z, int n)
 
SQLITE_PRIVATE u8 sqlite3HexToInt (int h)
 
SQLITE_PRIVATE int sqlite3TwoPartName (Parse *, Token *, Token *, Token **)
 
SQLITE_PRIVATE const char * sqlite3ErrStr (int)
 
SQLITE_PRIVATE int sqlite3ReadSchema (Parse *pParse)
 
SQLITE_PRIVATE CollSeqsqlite3FindCollSeq (sqlite3 *, u8 enc, const char *, int)
 
SQLITE_PRIVATE int sqlite3IsBinary (const CollSeq *)
 
SQLITE_PRIVATE CollSeqsqlite3LocateCollSeq (Parse *pParse, const char *zName)
 
SQLITE_PRIVATE void sqlite3SetTextEncoding (sqlite3 *db, u8)
 
SQLITE_PRIVATE CollSeqsqlite3ExprCollSeq (Parse *pParse, const Expr *pExpr)
 
SQLITE_PRIVATE CollSeqsqlite3ExprNNCollSeq (Parse *pParse, const Expr *pExpr)
 
SQLITE_PRIVATE int sqlite3ExprCollSeqMatch (Parse *, const Expr *, const Expr *)
 
SQLITE_PRIVATE Exprsqlite3ExprAddCollateToken (Parse *pParse, Expr *, const Token *, int)
 
SQLITE_PRIVATE Exprsqlite3ExprAddCollateString (Parse *, Expr *, const char *)
 
SQLITE_PRIVATE Exprsqlite3ExprSkipCollate (Expr *)
 
SQLITE_PRIVATE Exprsqlite3ExprSkipCollateAndLikely (Expr *)
 
SQLITE_PRIVATE int sqlite3CheckCollSeq (Parse *, CollSeq *)
 
SQLITE_PRIVATE int sqlite3WritableSchema (sqlite3 *)
 
SQLITE_PRIVATE int sqlite3CheckObjectName (Parse *, const char *, const char *, const char *)
 
SQLITE_PRIVATE void sqlite3VdbeSetChanges (sqlite3 *, int)
 
SQLITE_PRIVATE int sqlite3AddInt64 (i64 *, i64)
 
SQLITE_PRIVATE int sqlite3SubInt64 (i64 *, i64)
 
SQLITE_PRIVATE int sqlite3MulInt64 (i64 *, i64)
 
SQLITE_PRIVATE int sqlite3AbsInt32 (int)
 
SQLITE_PRIVATE u8 sqlite3GetBoolean (const char *z, u8)
 
SQLITE_PRIVATE const void * sqlite3ValueText (sqlite3_value *, u8)
 
SQLITE_PRIVATE int sqlite3ValueBytes (sqlite3_value *, u8)
 
SQLITE_PRIVATE void sqlite3ValueSetStr (sqlite3_value *, int, const void *, u8, void(*)(void *))
 
SQLITE_PRIVATE void sqlite3ValueSetNull (sqlite3_value *)
 
SQLITE_PRIVATE void sqlite3ValueFree (sqlite3_value *)
 
SQLITE_PRIVATE void sqlite3ResultIntReal (sqlite3_context *)
 
SQLITE_PRIVATE sqlite3_valuesqlite3ValueNew (sqlite3 *)
 
SQLITE_PRIVATE char * sqlite3Utf16to8 (sqlite3 *, const void *, int, u8)
 
SQLITE_PRIVATE int sqlite3ValueFromExpr (sqlite3 *, Expr *, u8, u8, sqlite3_value **)
 
SQLITE_PRIVATE void sqlite3ValueApplyAffinity (sqlite3_value *, u8, u8)
 
SQLITE_PRIVATE void sqlite3RootPageMoved (sqlite3 *, int, Pgno, Pgno)
 
SQLITE_PRIVATE void sqlite3Reindex (Parse *, Token *, Token *)
 
SQLITE_PRIVATE void sqlite3AlterFunctions (void)
 
SQLITE_PRIVATE void sqlite3AlterRenameTable (Parse *, SrcList *, Token *)
 
SQLITE_PRIVATE void sqlite3AlterRenameColumn (Parse *, SrcList *, Token *, Token *)
 
SQLITE_PRIVATE int sqlite3GetToken (const unsigned char *, int *)
 
SQLITE_PRIVATE void sqlite3NestedParse (Parse *, const char *,...)
 
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements (sqlite3 *, int)
 
SQLITE_PRIVATE void sqlite3CodeRhsOfIN (Parse *, Expr *, int)
 
SQLITE_PRIVATE int sqlite3CodeSubselect (Parse *, Expr *)
 
SQLITE_PRIVATE void sqlite3SelectPrep (Parse *, Select *, NameContext *)
 
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError (Parse *pParse, Select *p)
 
SQLITE_PRIVATE int sqlite3MatchEName (const struct ExprList_item *, const char *, const char *, const char *)
 
SQLITE_PRIVATE Bitmask sqlite3ExprColUsed (Expr *)
 
SQLITE_PRIVATE u8 sqlite3StrIHash (const char *)
 
SQLITE_PRIVATE int sqlite3ResolveExprNames (NameContext *, Expr *)
 
SQLITE_PRIVATE int sqlite3ResolveExprListNames (NameContext *, ExprList *)
 
SQLITE_PRIVATE void sqlite3ResolveSelectNames (Parse *, Select *, NameContext *)
 
SQLITE_PRIVATE int sqlite3ResolveSelfReference (Parse *, Table *, int, Expr *, ExprList *)
 
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy (Parse *, Select *, ExprList *, const char *)
 
SQLITE_PRIVATE void sqlite3ColumnDefault (Vdbe *, Table *, int, int)
 
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn (Parse *, Token *)
 
SQLITE_PRIVATE void sqlite3AlterBeginAddColumn (Parse *, SrcList *)
 
SQLITE_PRIVATE void * sqlite3RenameTokenMap (Parse *, void *, Token *)
 
SQLITE_PRIVATE void sqlite3RenameTokenRemap (Parse *, void *pTo, void *pFrom)
 
SQLITE_PRIVATE void sqlite3RenameExprUnmap (Parse *, Expr *)
 
SQLITE_PRIVATE void sqlite3RenameExprlistUnmap (Parse *, ExprList *)
 
SQLITE_PRIVATE CollSeqsqlite3GetCollSeq (Parse *, u8, CollSeq *, const char *)
 
SQLITE_PRIVATE char sqlite3AffinityType (const char *, Column *)
 
SQLITE_PRIVATE void sqlite3Analyze (Parse *, Token *, Token *)
 
SQLITE_PRIVATE int sqlite3InvokeBusyHandler (BusyHandler *)
 
SQLITE_PRIVATE int sqlite3FindDb (sqlite3 *, Token *)
 
SQLITE_PRIVATE int sqlite3FindDbName (sqlite3 *, const char *)
 
SQLITE_PRIVATE int sqlite3AnalysisLoad (sqlite3 *, int iDB)
 
SQLITE_PRIVATE void sqlite3DeleteIndexSamples (sqlite3 *, Index *)
 
SQLITE_PRIVATE void sqlite3DefaultRowEst (Index *)
 
SQLITE_PRIVATE void sqlite3RegisterLikeFunctions (sqlite3 *, int)
 
SQLITE_PRIVATE int sqlite3IsLikeFunction (sqlite3 *, Expr *, int *, char *)
 
SQLITE_PRIVATE void sqlite3SchemaClear (void *)
 
SQLITE_PRIVATE Schemasqlite3SchemaGet (sqlite3 *, Btree *)
 
SQLITE_PRIVATE int sqlite3SchemaToIndex (sqlite3 *db, Schema *)
 
SQLITE_PRIVATE KeyInfosqlite3KeyInfoAlloc (sqlite3 *, int, int)
 
SQLITE_PRIVATE void sqlite3KeyInfoUnref (KeyInfo *)
 
SQLITE_PRIVATE KeyInfosqlite3KeyInfoRef (KeyInfo *)
 
SQLITE_PRIVATE KeyInfosqlite3KeyInfoOfIndex (Parse *, Index *)
 
SQLITE_PRIVATE KeyInfosqlite3KeyInfoFromExprList (Parse *, ExprList *, int, int)
 
SQLITE_PRIVATE int sqlite3HasExplicitNulls (Parse *, ExprList *)
 
SQLITE_PRIVATE int sqlite3CreateFunc (sqlite3 *, const char *, int, int, void *, void(*)(sqlite3_context *, int, sqlite3_value **), void(*)(sqlite3_context *, int, sqlite3_value **), void(*)(sqlite3_context *), void(*)(sqlite3_context *), void(*)(sqlite3_context *, int, sqlite3_value **), FuncDestructor *pDestructor)
 
SQLITE_PRIVATE void sqlite3NoopDestructor (void *)
 
SQLITE_PRIVATE void sqlite3OomFault (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3OomClear (sqlite3 *)
 
SQLITE_PRIVATE int sqlite3ApiExit (sqlite3 *db, int)
 
SQLITE_PRIVATE int sqlite3OpenTempDatabase (Parse *)
 
SQLITE_PRIVATE void sqlite3StrAccumInit (StrAccum *, sqlite3 *, char *, int, int)
 
SQLITE_PRIVATE char * sqlite3StrAccumFinish (StrAccum *)
 
SQLITE_PRIVATE void sqlite3SelectDestInit (SelectDest *, int, int)
 
SQLITE_PRIVATE Exprsqlite3CreateColumnExpr (sqlite3 *, SrcList *, int, int)
 
SQLITE_PRIVATE void sqlite3BackupRestart (sqlite3_backup *)
 
SQLITE_PRIVATE void sqlite3BackupUpdate (sqlite3_backup *, Pgno, const u8 *)
 
SQLITE_PRIVATE int sqlite3ExprCheckIN (Parse *, Expr *)
 
SQLITE_PRIVATE void sqlite3Parser (void *, int, Token)
 
SQLITE_PRIVATE int sqlite3ParserFallback (int)
 
SQLITE_PRIVATE void sqlite3AutoLoadExtensions (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3CloseExtensions (sqlite3 *)
 
SQLITE_PRIVATE void sqlite3TableLock (Parse *, int, Pgno, u8, const char *)
 
SQLITE_PRIVATE void sqlite3VtabClear (sqlite3 *db, Table *)
 
SQLITE_PRIVATE void sqlite3VtabDisconnect (sqlite3 *db, Table *p)
 
SQLITE_PRIVATE int sqlite3VtabSync (sqlite3 *db, Vdbe *)
 
SQLITE_PRIVATE int sqlite3VtabRollback (sqlite3 *db)
 
SQLITE_PRIVATE int sqlite3VtabCommit (sqlite3 *db)
 
SQLITE_PRIVATE void sqlite3VtabLock (VTable *)
 
SQLITE_PRIVATE void sqlite3VtabUnlock (VTable *)
 
SQLITE_PRIVATE void sqlite3VtabModuleUnref (sqlite3 *, Module *)
 
SQLITE_PRIVATE void sqlite3VtabUnlockList (sqlite3 *)
 
SQLITE_PRIVATE int sqlite3VtabSavepoint (sqlite3 *, int, int)
 
SQLITE_PRIVATE void sqlite3VtabImportErrmsg (Vdbe *, sqlite3_vtab *)
 
SQLITE_PRIVATE VTablesqlite3GetVTable (sqlite3 *, Table *)
 
SQLITE_PRIVATE Modulesqlite3VtabCreateModule (sqlite3 *, const char *, const sqlite3_module *, void *, void(*)(void *))
 
SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables (sqlite3 *db)
 
SQLITE_PRIVATE int sqlite3ShadowTableName (sqlite3 *db, const char *zName)
 
SQLITE_PRIVATE int sqlite3IsShadowTableOf (sqlite3 *, Table *, const char *)
 
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit (Parse *, Module *)
 
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear (sqlite3 *, Module *)
 
SQLITE_PRIVATE void sqlite3VtabMakeWritable (Parse *, Table *)
 
SQLITE_PRIVATE void sqlite3VtabBeginParse (Parse *, Token *, Token *, Token *, int)
 
SQLITE_PRIVATE void sqlite3VtabFinishParse (Parse *, Token *)
 
SQLITE_PRIVATE void sqlite3VtabArgInit (Parse *)
 
SQLITE_PRIVATE void sqlite3VtabArgExtend (Parse *, Token *)
 
SQLITE_PRIVATE int sqlite3VtabCallCreate (sqlite3 *, int, const char *, char **)
 
SQLITE_PRIVATE int sqlite3VtabCallConnect (Parse *, Table *)
 
SQLITE_PRIVATE int sqlite3VtabCallDestroy (sqlite3 *, int, const char *)
 
SQLITE_PRIVATE int sqlite3VtabBegin (sqlite3 *, VTable *)
 
SQLITE_PRIVATE FuncDefsqlite3VtabOverloadFunction (sqlite3 *, FuncDef *, int nArg, Expr *)
 
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime (sqlite3_context *)
 
SQLITE_PRIVATE int sqlite3VdbeParameterIndex (Vdbe *, const char *, int)
 
SQLITE_PRIVATE int sqlite3TransferBindings (sqlite3_stmt *, sqlite3_stmt *)
 
SQLITE_PRIVATE void sqlite3ParserReset (Parse *)
 
SQLITE_PRIVATE int sqlite3Reprepare (Vdbe *)
 
SQLITE_PRIVATE void sqlite3ExprListCheckLength (Parse *, ExprList *, const char *)
 
SQLITE_PRIVATE CollSeqsqlite3ExprCompareCollSeq (Parse *, const Expr *)
 
SQLITE_PRIVATE CollSeqsqlite3BinaryCompareCollSeq (Parse *, const Expr *, const Expr *)
 
SQLITE_PRIVATE int sqlite3TempInMemory (const sqlite3 *)
 
SQLITE_PRIVATE const char * sqlite3JournalModename (int)
 
SQLITE_PRIVATE int sqlite3Checkpoint (sqlite3 *, int, int, int *, int *)
 
SQLITE_PRIVATE int sqlite3WalDefaultHook (void *, sqlite3 *, const char *, int)
 
SQLITE_PRIVATE Withsqlite3WithAdd (Parse *, With *, Token *, ExprList *, Select *)
 
SQLITE_PRIVATE void sqlite3WithDelete (sqlite3 *, With *)
 
SQLITE_PRIVATE void sqlite3WithPush (Parse *, With *, u8)
 
SQLITE_PRIVATE Upsertsqlite3UpsertNew (sqlite3 *, ExprList *, Expr *, ExprList *, Expr *)
 
SQLITE_PRIVATE void sqlite3UpsertDelete (sqlite3 *, Upsert *)
 
SQLITE_PRIVATE Upsertsqlite3UpsertDup (sqlite3 *, Upsert *)
 
SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget (Parse *, SrcList *, Upsert *)
 
SQLITE_PRIVATE void sqlite3UpsertDoUpdate (Parse *, Upsert *, Table *, Index *, int)
 
SQLITE_PRIVATE void sqlite3FkCheck (Parse *, Table *, int, int, int *, int)
 
SQLITE_PRIVATE void sqlite3FkDropTable (Parse *, SrcList *, Table *)
 
SQLITE_PRIVATE void sqlite3FkActions (Parse *, Table *, ExprList *, int, int *, int)
 
SQLITE_PRIVATE int sqlite3FkRequired (Parse *, Table *, int *, int)
 
SQLITE_PRIVATE u32 sqlite3FkOldmask (Parse *, Table *)
 
SQLITE_PRIVATE FKeysqlite3FkReferences (Table *)
 
SQLITE_PRIVATE void sqlite3FkDelete (sqlite3 *, Table *)
 
SQLITE_PRIVATE int sqlite3FkLocateIndex (Parse *, Table *, FKey *, Index **, int **)
 
SQLITE_PRIVATE void sqlite3BeginBenignMalloc (void)
 
SQLITE_PRIVATE void sqlite3EndBenignMalloc (void)
 
SQLITE_PRIVATE int sqlite3FindInIndex (Parse *, Expr *, u32, int *, int *, int *)
 
SQLITE_PRIVATE int sqlite3JournalOpen (sqlite3_vfs *, const char *, sqlite3_file *, int, int)
 
SQLITE_PRIVATE int sqlite3JournalSize (sqlite3_vfs *)
 
SQLITE_PRIVATE int sqlite3JournalIsInMemory (sqlite3_file *p)
 
SQLITE_PRIVATE void sqlite3MemJournalOpen (sqlite3_file *)
 
SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags (Parse *pParse, Expr *p)
 
SQLITE_PRIVATE int sqlite3SelectExprHeight (Select *)
 
SQLITE_PRIVATE int sqlite3ExprCheckHeight (Parse *, int)
 
SQLITE_PRIVATE u32 sqlite3Get4byte (const u8 *)
 
SQLITE_PRIVATE void sqlite3Put4byte (u8 *, u32)
 
SQLITE_PRIVATE int sqlite3ThreadCreate (SQLiteThread **, void *(*)(void *), void *)
 
SQLITE_PRIVATE int sqlite3ThreadJoin (SQLiteThread *, void **)
 
SQLITE_PRIVATE int sqlite3ExprVectorSize (Expr *pExpr)
 
SQLITE_PRIVATE int sqlite3ExprIsVector (Expr *pExpr)
 
SQLITE_PRIVATE Exprsqlite3VectorFieldSubexpr (Expr *, int)
 
SQLITE_PRIVATE Exprsqlite3ExprForVectorField (Parse *, Expr *, int)
 
SQLITE_PRIVATE void sqlite3VectorErrorMsg (Parse *, Expr *)
 
SQLITE_PRIVATE void sqlite3VdbeError (Vdbe *, const char *,...)
 
SQLITE_PRIVATE void sqlite3VdbeFreeCursor (Vdbe *, VdbeCursor *)
 
void sqliteVdbePopStack (Vdbe *, int)
 
SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto (VdbeCursor *)
 
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto (VdbeCursor **, u32 *)
 
SQLITE_PRIVATE int sqlite3VdbeCursorRestore (VdbeCursor *)
 
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen (u32)
 
SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen (u8)
 
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut (unsigned char *, Mem *, u32)
 
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet (const unsigned char *, u32, Mem *)
 
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData (sqlite3 *, AuxData **, int, int)
 
int sqlite2BtreeKeyCompare (BtCursor *, const void *, int, int, int *)
 
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare (sqlite3 *, VdbeCursor *, UnpackedRecord *, int *)
 
SQLITE_PRIVATE int sqlite3VdbeIdxRowid (sqlite3 *, BtCursor *, i64 *)
 
SQLITE_PRIVATE int sqlite3VdbeExec (Vdbe *)
 
SQLITE_PRIVATE int sqlite3VdbeNextOpcode (Vdbe *, Mem *, int, int *, int *, Op **)
 
SQLITE_PRIVATE char * sqlite3VdbeDisplayP4 (sqlite3 *, Op *)
 
SQLITE_PRIVATE int sqlite3VdbeList (Vdbe *)
 
SQLITE_PRIVATE int sqlite3VdbeHalt (Vdbe *)
 
SQLITE_PRIVATE int sqlite3VdbeChangeEncoding (Mem *, int)
 
SQLITE_PRIVATE int sqlite3VdbeMemTooBig (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemCopy (Mem *, const Mem *)
 
SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy (Mem *, const Mem *, int)
 
SQLITE_PRIVATE void sqlite3VdbeMemMove (Mem *, Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemSetStr (Mem *, const char *, int, u8, void(*)(void *))
 
SQLITE_PRIVATE void sqlite3VdbeMemSetInt64 (Mem *, i64)
 
SQLITE_PRIVATE void sqlite3VdbeMemSetDouble (Mem *, double)
 
SQLITE_PRIVATE void sqlite3VdbeMemSetPointer (Mem *, void *, const char *, void(*)(void *))
 
SQLITE_PRIVATE void sqlite3VdbeMemInit (Mem *, sqlite3 *, u16)
 
SQLITE_PRIVATE void sqlite3VdbeMemSetNull (Mem *)
 
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob (Mem *, int)
 
SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemStringify (Mem *, u8, u8)
 
SQLITE_PRIVATE i64 sqlite3VdbeIntValue (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify (Mem *)
 
SQLITE_PRIVATE double sqlite3VdbeRealValue (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeBooleanValue (Mem *, int ifNull)
 
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemRealify (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemNumerify (Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemCast (Mem *, u8, u8)
 
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree (BtCursor *, u32, u32, Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset (BtCursor *, u32, Mem *)
 
SQLITE_PRIVATE void sqlite3VdbeMemRelease (Mem *p)
 
SQLITE_PRIVATE int sqlite3VdbeMemFinalize (Mem *, FuncDef *)
 
SQLITE_PRIVATE int sqlite3VdbeMemAggValue (Mem *, Mem *, FuncDef *)
 
SQLITE_PRIVATE const char * sqlite3OpcodeName (int)
 
SQLITE_PRIVATE int sqlite3VdbeMemGrow (Mem *pMem, int n, int preserve)
 
SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize (Mem *pMem, int n)
 
SQLITE_PRIVATE int sqlite3VdbeCloseStatement (Vdbe *, int)
 
SQLITE_PRIVATE void sqlite3VdbeFrameMemDel (void *)
 
SQLITE_PRIVATE void sqlite3VdbeFrameDelete (VdbeFrame *)
 
SQLITE_PRIVATE int sqlite3VdbeFrameRestore (VdbeFrame *)
 
SQLITE_PRIVATE int sqlite3VdbeTransferError (Vdbe *p)
 
SQLITE_PRIVATE int sqlite3VdbeSorterInit (sqlite3 *, int, VdbeCursor *)
 
SQLITE_PRIVATE void sqlite3VdbeSorterReset (sqlite3 *, VdbeSorter *)
 
SQLITE_PRIVATE void sqlite3VdbeSorterClose (sqlite3 *, VdbeCursor *)
 
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey (const VdbeCursor *, Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeSorterNext (sqlite3 *, const VdbeCursor *)
 
SQLITE_PRIVATE int sqlite3VdbeSorterRewind (const VdbeCursor *, int *)
 
SQLITE_PRIVATE int sqlite3VdbeSorterWrite (const VdbeCursor *, Mem *)
 
SQLITE_PRIVATE int sqlite3VdbeSorterCompare (const VdbeCursor *, Mem *, int, int *)
 
SQLITE_PRIVATE void sqlite3VdbeEnter (Vdbe *)
 
SQLITE_PRIVATE void sqlite3VdbeLeave (Vdbe *)
 
SQLITE_PRIVATE int sqlite3VdbeCheckFk (Vdbe *, int)
 
SQLITE_PRIVATE int sqlite3VdbeMemTranslate (Mem *, u8)
 
SQLITE_PRIVATE int sqlite3VdbeMemHandleBom (Mem *pMem)
 
SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob (Mem *)
 
static u32 countLookasideSlots (LookasideSlot *p)
 
static int getDigits (const char *zDate, const char *zFormat,...)
 
static int parseTimezone (const char *zDate, DateTime *p)
 
static int parseHhMmSs (const char *zDate, DateTime *p)
 
static void datetimeError (DateTime *p)
 
static void computeJD (DateTime *p)
 
static int parseYyyyMmDd (const char *zDate, DateTime *p)
 
static int setDateTimeToCurrent (sqlite3_context *context, DateTime *p)
 
static void setRawDateNumber (DateTime *p, double r)
 
static int parseDateOrTime (sqlite3_context *context, const char *zDate, DateTime *p)
 
static int validJulianDay (sqlite3_int64 iJD)
 
static void computeYMD (DateTime *p)
 
static void computeHMS (DateTime *p)
 
static void computeYMD_HMS (DateTime *p)
 
static void clearYMD_HMS_TZ (DateTime *p)
 
static int osLocaltime (time_t *t, struct tm *pTm)
 
static sqlite3_int64 localtimeOffset (DateTime *p, sqlite3_context *pCtx, int *pRc)
 
static int parseModifier (sqlite3_context *pCtx, const char *z, int n, DateTime *p)
 
static int isDate (sqlite3_context *context, int argc, sqlite3_value **argv, DateTime *p)
 
static void juliandayFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void datetimeFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void timeFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void dateFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void strftimeFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void ctimeFunc (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void cdateFunc (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void ctimestampFunc (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void vfsUnlink (sqlite3_vfs *pVfs)
 
static void * sqlite3MemMalloc (int nByte)
 
static void sqlite3MemFree (void *pPrior)
 
static int sqlite3MemSize (void *pPrior)
 
static void * sqlite3MemRealloc (void *pPrior, int nByte)
 
static int sqlite3MemRoundup (int n)
 
static int sqlite3MemInit (void *NotUsed)
 
static void sqlite3MemShutdown (void *NotUsed)
 
static int noopMutexInit (void)
 
static int noopMutexEnd (void)
 
static sqlite3_mutexnoopMutexAlloc (int id)
 
static void noopMutexFree (sqlite3_mutex *p)
 
static void noopMutexEnter (sqlite3_mutex *p)
 
static int noopMutexTry (sqlite3_mutex *p)
 
static void noopMutexLeave (sqlite3_mutex *p)
 
static int pthreadMutexInit (void)
 
static int pthreadMutexEnd (void)
 
static sqlite3_mutexpthreadMutexAlloc (int iType)
 
static void pthreadMutexFree (sqlite3_mutex *p)
 
static void pthreadMutexEnter (sqlite3_mutex *p)
 
static int pthreadMutexTry (sqlite3_mutex *p)
 
static void pthreadMutexLeave (sqlite3_mutex *p)
 
SQLITE_API int sqlite3_memory_alarm (void(*xCallback)(void *pArg, sqlite3_int64 used, int N), void *pArg, sqlite3_int64 iThreshold)
 
static void sqlite3MallocAlarm (int nByte)
 
static void mallocWithAlarm (int n, void **pp)
 
static int isLookaside (sqlite3 *db, void *p)
 
static int lookasideMallocSize (sqlite3 *db, void *p)
 
static SQLITE_NOINLINE void measureAllocationSize (sqlite3 *db, void *p)
 
static SQLITE_NOINLINE void * dbMallocRawFinish (sqlite3 *db, u64 n)
 
static SQLITE_NOINLINE void * dbReallocFinish (sqlite3 *db, void *p, u64 n)
 
static SQLITE_NOINLINE int apiOomError (sqlite3 *db)
 
static char et_getdigit (LONGDOUBLE_TYPE *val, int *cnt)
 
static void setStrAccumError (StrAccum *p, u8 eError)
 
static sqlite3_int64 getIntArg (PrintfArguments *p)
 
static double getDoubleArg (PrintfArguments *p)
 
static char * getTextArg (PrintfArguments *p)
 
static char * printfTempBuf (sqlite3_str *pAccum, sqlite3_int64 n)
 
static int sqlite3StrAccumEnlarge (StrAccum *p, int N)
 
static void SQLITE_NOINLINE enlargeAndAppend (StrAccum *p, const char *z, int N)
 
static SQLITE_NOINLINE char * strAccumFinishRealloc (StrAccum *p)
 
static void renderLogMsg (int iErrCode, const char *zFormat, va_list ap)
 
SQLITE_PRIVATE int sqlite3ThreadCreate (SQLiteThread **ppThread, void *(*xTask)(void *), void *pIn)
 
SQLITE_PRIVATE u32 sqlite3Utf8Read (const unsigned char **pz)
 
static SQLITE_NOINLINE void sqlite3ErrorFinish (sqlite3 *db, int err_code)
 
static LONGDOUBLE_TYPE sqlite3Pow10 (int E)
 
static int compare2pow63 (const char *zNum, int incr)
 
static int SQLITE_NOINLINE putVarint64 (unsigned char *p, u64 v)
 
SQLITE_PRIVATE void sqlite3Put4byte (unsigned char *p, u32 v)
 
static void logBadConnection (const char *zType)
 
static unsigned int strHash (const char *z)
 
static void insertElement (Hash *pH, struct _ht *pEntry, HashElem *pNew)
 
static int rehash (Hash *pH, unsigned int new_size)
 
static HashElemfindElementWithHash (const Hash *pH, const char *pKey, unsigned int *pHash)
 
static void removeElementGivenHash (Hash *pH, HashElem *elem, unsigned int h)
 
static int posixOpen (const char *zFile, int flags, int mode)
 
static int openDirectory (const char *, int *)
 
static int unixGetpagesize (void)
 
static int robustFchown (int fd, uid_t uid, gid_t gid)
 
static int unixSetSystemCall (sqlite3_vfs *pNotUsed, const char *zName, sqlite3_syscall_ptr pNewFunc)
 
static sqlite3_syscall_ptr unixGetSystemCall (sqlite3_vfs *pNotUsed, const char *zName)
 
static const char * unixNextSystemCall (sqlite3_vfs *p, const char *zName)
 
static int robust_open (const char *z, int f, mode_t m)
 
static void unixEnterMutex (void)
 
static void unixLeaveMutex (void)
 
static int robust_ftruncate (int h, sqlite3_int64 sz)
 
static int sqliteErrorFromPosixError (int posixError, int sqliteIOErr)
 
static int unixLogErrorAtLine (int errcode, const char *zFunc, const char *zPath, int iLine)
 
static void robust_close (unixFile *pFile, int h, int lineno)
 
static void storeLastErrno (unixFile *pFile, int error)
 
static void closePendingFds (unixFile *pFile)
 
static void releaseInodeInfo (unixFile *pFile)
 
static int findInodeInfo (unixFile *pFile, unixInodeInfo **ppInode)
 
static int fileHasMoved (unixFile *pFile)
 
static void verifyDbFile (unixFile *pFile)
 
static int unixCheckReservedLock (sqlite3_file *id, int *pResOut)
 
static int unixFileLock (unixFile *pFile, struct flock *pLock)
 
static int unixLock (sqlite3_file *id, int eFileLock)
 
static void setPendingFd (unixFile *pFile)
 
static int posixUnlock (sqlite3_file *id, int eFileLock, int handleNFSUnlock)
 
static int unixUnlock (sqlite3_file *id, int eFileLock)
 
static int closeUnixFile (sqlite3_file *id)
 
static int unixClose (sqlite3_file *id)
 
static int nolockCheckReservedLock (sqlite3_file *NotUsed, int *pResOut)
 
static int nolockLock (sqlite3_file *NotUsed, int NotUsed2)
 
static int nolockUnlock (sqlite3_file *NotUsed, int NotUsed2)
 
static int nolockClose (sqlite3_file *id)
 
static int dotlockCheckReservedLock (sqlite3_file *id, int *pResOut)
 
static int dotlockLock (sqlite3_file *id, int eFileLock)
 
static int dotlockUnlock (sqlite3_file *id, int eFileLock)
 
static int dotlockClose (sqlite3_file *id)
 
static int seekAndRead (unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt)
 
static int unixRead (sqlite3_file *id, void *pBuf, int amt, sqlite3_int64 offset)
 
static int seekAndWriteFd (int fd, i64 iOff, const void *pBuf, int nBuf, int *piErrno)
 
static int seekAndWrite (unixFile *id, i64 offset, const void *pBuf, int cnt)
 
static int unixWrite (sqlite3_file *id, const void *pBuf, int amt, sqlite3_int64 offset)
 
static int full_fsync (int fd, int fullSync, int dataOnly)
 
static int unixSync (sqlite3_file *id, int flags)
 
static int unixTruncate (sqlite3_file *id, i64 nByte)
 
static int unixFileSize (sqlite3_file *id, i64 *pSize)
 
static int fcntlSizeHint (unixFile *pFile, i64 nByte)
 
static void unixModeBit (unixFile *pFile, unsigned char mask, int *pArg)
 
static int unixGetTempname (int nBuf, char *zBuf)
 
static int unixFileControl (sqlite3_file *id, int op, void *pArg)
 
static void setDeviceCharacteristics (unixFile *pFd)
 
static int unixSectorSize (sqlite3_file *id)
 
static int unixDeviceCharacteristics (sqlite3_file *id)
 
static int unixShmSystemLock (unixFile *pFile, int lockType, int ofst, int n)
 
static int unixShmRegionPerMap (void)
 
static void unixShmPurge (unixFile *pFd)
 
static int unixLockSharedMemory (unixFile *pDbFd, unixShmNode *pShmNode)
 
static int unixOpenSharedMemory (unixFile *pDbFd)
 
static int unixShmMap (sqlite3_file *fd, int iRegion, int szRegion, int bExtend, void volatile **pp)
 
static int unixShmLock (sqlite3_file *fd, int ofst, int n, int flags)
 
static void unixShmBarrier (sqlite3_file *fd)
 
static int unixShmUnmap (sqlite3_file *fd, int deleteFlag)
 
static int unixFetch (sqlite3_file *fd, i64 iOff, int nAmt, void **pp)
 
static int unixUnfetch (sqlite3_file *fd, i64 iOff, void *p)
 
 IOMETHODS (posixIoFinder, posixIoMethods, IOMETHODS(3, unixClose, unixLock, unixUnlock, unixCheckReservedLock, unixShmMap)
 
static const char * unixTempFileDir (void)
 
static UnixUnusedFdfindReusableFd (const char *zPath, int flags)
 
static int getFileMode (const char *zFile, mode_t *pMode, uid_t *pUid, gid_t *pGid)
 
static int findCreateFileMode (const char *zPath, int flags, mode_t *pMode, uid_t *pUid, gid_t *pGid)
 
static int unixOpen (sqlite3_vfs *pVfs, const char *zPath, sqlite3_file *pFile, int flags, int *pOutFlags)
 
static int unixDelete (sqlite3_vfs *NotUsed, const char *zPath, int dirSync)
 
static int unixAccess (sqlite3_vfs *NotUsed, const char *zPath, int flags, int *pResOut)
 
static int mkFullPathname (const char *zPath, char *zOut, int nOut)
 
static int unixFullPathname (sqlite3_vfs *pVfs, const char *zPath, int nOut, char *zOut)
 
static void * unixDlOpen (sqlite3_vfs *NotUsed, const char *zFilename)
 
static void unixDlError (sqlite3_vfs *NotUsed, int nBuf, char *zBufOut)
 
static void unixDlClose (sqlite3_vfs *NotUsed, void *pHandle)
 
static int unixRandomness (sqlite3_vfs *NotUsed, int nBuf, char *zBuf)
 
static int unixSleep (sqlite3_vfs *NotUsed, int microseconds)
 
static int unixCurrentTimeInt64 (sqlite3_vfs *NotUsed, sqlite3_int64 *piNow)
 
static int unixCurrentTime (sqlite3_vfs *NotUsed, double *prNow)
 
static int unixGetLastError (sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3)
 
static void pcacheManageDirtyList (PgHdr *pPage, u8 addRemove)
 
static void pcacheUnpin (PgHdr *p)
 
static int numberOfCachePages (PCache *p)
 
static SQLITE_NOINLINE PgHdrpcacheFetchFinishWithInit (PCache *pCache, Pgno pgno, sqlite3_pcache_page *pPage)
 
static PgHdrpcacheMergeDirtyList (PgHdr *pA, PgHdr *pB)
 
static PgHdrpcacheSortDirtyList (PgHdr *pIn)
 
static int pcache1InitBulk (PCache1 *pCache)
 
static void * pcache1Alloc (int nByte)
 
static void pcache1Free (void *p)
 
static PgHdr1pcache1AllocPage (PCache1 *pCache, int benignMalloc)
 
static void pcache1FreePage (PgHdr1 *p)
 
static int pcache1UnderMemoryPressure (PCache1 *pCache)
 
static void pcache1ResizeHash (PCache1 *p)
 
static PgHdr1pcache1PinPage (PgHdr1 *pPage)
 
static void pcache1RemoveFromHash (PgHdr1 *pPage, int freeFlag)
 
static void pcache1EnforceMaxPage (PCache1 *pCache)
 
static void pcache1TruncateUnsafe (PCache1 *pCache, unsigned int iLimit)
 
static int pcache1Init (void *NotUsed)
 
static void pcache1Shutdown (void *NotUsed)
 
static void pcache1Destroy (sqlite3_pcache *p)
 
static sqlite3_pcachepcache1Create (int szPage, int szExtra, int bPurgeable)
 
static void pcache1Cachesize (sqlite3_pcache *p, int nMax)
 
static void pcache1Shrink (sqlite3_pcache *p)
 
static int pcache1Pagecount (sqlite3_pcache *p)
 
static SQLITE_NOINLINE PgHdr1pcache1FetchStage2 (PCache1 *pCache, unsigned int iKey, int createFlag)
 
static PgHdr1pcache1FetchNoMutex (sqlite3_pcache *p, unsigned int iKey, int createFlag)
 
static sqlite3_pcache_pagepcache1Fetch (sqlite3_pcache *p, unsigned int iKey, int createFlag)
 
static void pcache1Unpin (sqlite3_pcache *p, sqlite3_pcache_page *pPg, int reuseUnlikely)
 
static void pcache1Rekey (sqlite3_pcache *p, sqlite3_pcache_page *pPg, unsigned int iOld, unsigned int iNew)
 
static void pcache1Truncate (sqlite3_pcache *p, unsigned int iLimit)
 
static struct RowSetEntryrowSetEntryAlloc (RowSet *p)
 
static struct RowSetEntryrowSetEntryMerge (struct RowSetEntry *pA, struct RowSetEntry *pB)
 
static struct RowSetEntryrowSetEntrySort (struct RowSetEntry *pIn)
 
static void rowSetTreeToList (struct RowSetEntry *pIn, struct RowSetEntry **ppFirst, struct RowSetEntry **ppLast)
 
static struct RowSetEntryrowSetNDeepTree (struct RowSetEntry **ppList, int iDepth)
 
static struct RowSetEntryrowSetListToTree (struct RowSetEntry *pList)
 
SQLITE_PRIVATE int sqlite3WalOpen (sqlite3_vfs *, sqlite3_file *, const char *, int, i64, Wal **)
 
SQLITE_PRIVATE int sqlite3WalClose (Wal *pWal, sqlite3 *, int sync_flags, int, u8 *)
 
SQLITE_PRIVATE void sqlite3WalLimit (Wal *, i64)
 
SQLITE_PRIVATE int sqlite3WalBeginReadTransaction (Wal *pWal, int *)
 
SQLITE_PRIVATE void sqlite3WalEndReadTransaction (Wal *pWal)
 
SQLITE_PRIVATE int sqlite3WalFindFrame (Wal *, Pgno, u32 *)
 
SQLITE_PRIVATE int sqlite3WalReadFrame (Wal *, u32, int, u8 *)
 
SQLITE_PRIVATE Pgno sqlite3WalDbsize (Wal *pWal)
 
SQLITE_PRIVATE int sqlite3WalBeginWriteTransaction (Wal *pWal)
 
SQLITE_PRIVATE int sqlite3WalEndWriteTransaction (Wal *pWal)
 
SQLITE_PRIVATE int sqlite3WalUndo (Wal *pWal, int(*xUndo)(void *, Pgno), void *pUndoCtx)
 
SQLITE_PRIVATE void sqlite3WalSavepoint (Wal *pWal, u32 *aWalData)
 
SQLITE_PRIVATE int sqlite3WalSavepointUndo (Wal *pWal, u32 *aWalData)
 
SQLITE_PRIVATE int sqlite3WalFrames (Wal *pWal, int, PgHdr *, Pgno, int, int)
 
SQLITE_PRIVATE int sqlite3WalCheckpoint (Wal *pWal, sqlite3 *db, int eMode, int(*xBusy)(void *), void *pBusyArg, int sync_flags, int nBuf, u8 *zBuf, int *pnLog, int *pnCkpt)
 
SQLITE_PRIVATE int sqlite3WalCallback (Wal *pWal)
 
SQLITE_PRIVATE int sqlite3WalExclusiveMode (Wal *pWal, int op)
 
SQLITE_PRIVATE int sqlite3WalHeapMemory (Wal *pWal)
 
SQLITE_PRIVATE sqlite3_filesqlite3WalFile (Wal *pWal)
 
static int getPageNormal (Pager *, Pgno, DbPage **, int)
 
static int getPageError (Pager *, Pgno, DbPage **, int)
 
static void setGetterMethod (Pager *pPager)
 
static int subjRequiresPage (PgHdr *pPg)
 
static int read32bits (sqlite3_file *fd, i64 offset, u32 *pRes)
 
static int write32bits (sqlite3_file *fd, i64 offset, u32 val)
 
static int pagerUnlockDb (Pager *pPager, int eLock)
 
static int pagerLockDb (Pager *pPager, int eLock)
 
static int jrnlBufferSize (Pager *pPager)
 
static int readSuperJournal (sqlite3_file *pJrnl, char *zSuper, u32 nSuper)
 
static i64 journalHdrOffset (Pager *pPager)
 
static int zeroJournalHdr (Pager *pPager, int doTruncate)
 
static int writeJournalHdr (Pager *pPager)
 
static int readJournalHdr (Pager *pPager, int isHot, i64 journalSize, u32 *pNRec, u32 *pDbSize)
 
static int writeSuperJournal (Pager *pPager, const char *zSuper)
 
static void pager_reset (Pager *pPager)
 
static void releaseAllSavepoints (Pager *pPager)
 
static int addToSavepointBitvecs (Pager *pPager, Pgno pgno)
 
static void pager_unlock (Pager *pPager)
 
static int pager_error (Pager *pPager, int rc)
 
static int pager_truncate (Pager *pPager, Pgno nPage)
 
static int pagerFlushOnCommit (Pager *pPager, int bCommit)
 
static int pager_end_transaction (Pager *pPager, int hasSuper, int bCommit)
 
static void pagerUnlockAndRollback (Pager *pPager)
 
static u32 pager_cksum (Pager *pPager, const u8 *aData)
 
static int pager_playback_one_page (Pager *pPager, i64 *pOffset, Bitvec *pDone, int isMainJrnl, int isSavepnt)
 
static int pager_delsuper (Pager *pPager, const char *zSuper)
 
static void setSectorSize (Pager *pPager)
 
static int pager_playback (Pager *pPager, int isHot)
 
static int readDbPage (PgHdr *pPg)
 
static void pager_write_changecounter (PgHdr *pPg)
 
static int pagerUndoCallback (void *pCtx, Pgno iPg)
 
static int pagerRollbackWal (Pager *pPager)
 
static int pagerWalFrames (Pager *pPager, PgHdr *pList, Pgno nTruncate, int isCommit)
 
static int pagerBeginReadTransaction (Pager *pPager)
 
static int pagerPagecount (Pager *pPager, Pgno *pnPage)
 
static int pagerOpenWalIfPresent (Pager *pPager)
 
static int pagerPlaybackSavepoint (Pager *pPager, PagerSavepoint *pSavepoint)
 
static void pagerFixMaplimit (Pager *pPager)
 
static int pagerOpentemp (Pager *pPager, sqlite3_file *pFile, int vfsFlags)
 
static int pager_wait_on_lock (Pager *pPager, int locktype)
 
static int pagerSyncHotJournal (Pager *pPager)
 
static void pagerReleaseMapPage (PgHdr *pPg)
 
static void pagerFreeMapHdrs (Pager *pPager)
 
static int databaseIsUnmoved (Pager *pPager)
 
static int syncJournal (Pager *pPager, int newHdr)
 
static int pager_write_pagelist (Pager *pPager, PgHdr *pList)
 
static int openSubJournal (Pager *pPager)
 
static int subjournalPage (PgHdr *pPg)
 
static int subjournalPageIfRequired (PgHdr *pPg)
 
static int pagerStress (void *p, PgHdr *pPg)
 
static int hasHotJournal (Pager *pPager, int *pExists)
 
static void pagerUnlockIfUnused (Pager *pPager)
 
static int pager_open_journal (Pager *pPager)
 
static SQLITE_NOINLINE int pagerAddPageToRollbackJournal (PgHdr *pPg)
 
static int pager_write (PgHdr *pPg)
 
static SQLITE_NOINLINE int pagerWriteLargeSector (PgHdr *pPg)
 
static int pager_incr_changecounter (Pager *pPager, int isDirectMode)
 
static SQLITE_NOINLINE int pagerOpenSavepoint (Pager *pPager, int nSavepoint)
 
static int pagerExclusiveLock (Pager *pPager)
 
static int pagerOpenWal (Pager *pPager)
 
static SQLITE_NOINLINE int walIndexPageRealloc (Wal *pWal, int iPage, volatile u32 **ppPage)
 
static int walIndexPage (Wal *pWal, int iPage, volatile u32 **ppPage)
 
static volatile WalCkptInfowalCkptInfo (Wal *pWal)
 
static volatile WalIndexHdrwalIndexHdr (Wal *pWal)
 
static void walChecksumBytes (int nativeCksum, u8 *a, int nByte, const u32 *aIn, u32 *aOut)
 
static void walShmBarrier (Wal *pWal)
 
static SQLITE_NO_TSAN void walIndexWriteHdr (Wal *pWal)
 
static void walEncodeFrame (Wal *pWal, u32 iPage, u32 nTruncate, u8 *aData, u8 *aFrame)
 
static int walDecodeFrame (Wal *pWal, u32 *piPage, u32 *pnTruncate, u8 *aData, u8 *aFrame)
 
static int walLockShared (Wal *pWal, int lockIdx)
 
static void walUnlockShared (Wal *pWal, int lockIdx)
 
static int walLockExclusive (Wal *pWal, int lockIdx, int n)
 
static void walUnlockExclusive (Wal *pWal, int lockIdx, int n)
 
static int walHash (u32 iPage)
 
static int walNextHash (int iPriorHash)
 
static int walHashGet (Wal *pWal, int iHash, WalHashLoc *pLoc)
 
static int walFramePage (u32 iFrame)
 
static u32 walFramePgno (Wal *pWal, u32 iFrame)
 
static void walCleanupHash (Wal *pWal)
 
static int walIndexAppend (Wal *pWal, u32 iFrame, u32 iPage)
 
static int walIndexRecover (Wal *pWal)
 
static void walIndexClose (Wal *pWal, int isDelete)
 
static int walIteratorNext (WalIterator *p, u32 *piPage, u32 *piFrame)
 
static void walMerge (const u32 *aContent, ht_slot *aLeft, int nLeft, ht_slot **paRight, int *pnRight, ht_slot *aTmp)
 
static void walMergesort (const u32 *aContent, ht_slot *aBuffer, ht_slot *aList, int *pnList)
 
static void walIteratorFree (WalIterator *p)
 
static int walIteratorInit (Wal *pWal, u32 nBackfill, WalIterator **pp)
 
static int walBusyLock (Wal *pWal, int(*xBusy)(void *), void *pBusyArg, int lockIdx, int n)
 
static int walPagesize (Wal *pWal)
 
static void walRestartHdr (Wal *pWal, u32 salt1)
 
static int walCheckpoint (Wal *pWal, sqlite3 *db, int eMode, int(*xBusy)(void *), void *pBusyArg, int sync_flags, u8 *zBuf)
 
static void walLimitSize (Wal *pWal, i64 nMax)
 
static SQLITE_NO_TSAN int walIndexTryHdr (Wal *pWal, int *pChanged)
 
static int walIndexReadHdr (Wal *pWal, int *pChanged)
 
static int walBeginShmUnreliable (Wal *pWal, int *pChanged)
 
static int walTryBeginRead (Wal *pWal, int *pChanged, int useWal, int cnt)
 
static int walRestartLog (Wal *pWal)
 
static int walWriteToLog (WalWriter *p, void *pContent, int iAmt, sqlite3_int64 iOffset)
 
static int walWriteOneFrame (WalWriter *p, PgHdr *pPage, int nTruncate, sqlite3_int64 iOffset)
 
static int walRewriteChecksums (Wal *pWal, u32 iLast)
 
static void lockBtreeMutex (Btree *p)
 
static void SQLITE_NOINLINE unlockBtreeMutex (Btree *p)
 
static void SQLITE_NOINLINE btreeLockCarefully (Btree *p)
 
static void SQLITE_NOINLINE btreeEnterAll (sqlite3 *db)
 
static void SQLITE_NOINLINE btreeLeaveAll (sqlite3 *db)
 
static int querySharedCacheTableLock (Btree *p, Pgno iTab, u8 eLock)
 
static int setSharedCacheTableLock (Btree *p, Pgno iTable, u8 eLock)
 
static void clearAllSharedCacheTableLocks (Btree *p)
 
static void downgradeAllSharedCacheTableLocks (Btree *p)
 
static void releasePage (MemPage *pPage)
 
static void releasePageOne (MemPage *pPage)
 
static void releasePageNotNull (MemPage *pPage)
 
static void invalidateAllOverflowCache (BtShared *pBt)
 
static void invalidateIncrblobCursors (Btree *pBtree, Pgno pgnoRoot, i64 iRow, int isClearTable)
 
static int btreeSetHasContent (BtShared *pBt, Pgno pgno)
 
static int btreeGetHasContent (BtShared *pBt, Pgno pgno)
 
static void btreeClearHasContent (BtShared *pBt)
 
static void btreeReleaseAllCursorPages (BtCursor *pCur)
 
static int saveCursorKey (BtCursor *pCur)
 
static int saveCursorPosition (BtCursor *pCur)
 
static int SQLITE_NOINLINE saveCursorsOnList (BtCursor *, Pgno, BtCursor *)
 
static int saveAllCursors (BtShared *pBt, Pgno iRoot, BtCursor *pExcept)
 
static int btreeMoveto (BtCursor *pCur, const void *pKey, i64 nKey, int bias, int *pRes)
 
static int btreeRestoreCursorPosition (BtCursor *pCur)
 
static Pgno ptrmapPageno (BtShared *pBt, Pgno pgno)
 
static void ptrmapPut (BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC)
 
static int ptrmapGet (BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno)
 
static SQLITE_NOINLINE void btreeParseCellAdjustSizeForOverflow (MemPage *pPage, u8 *pCell, CellInfo *pInfo)
 
static void btreeParseCellPtrNoPayload (MemPage *pPage, u8 *pCell, CellInfo *pInfo)
 
static void btreeParseCellPtr (MemPage *pPage, u8 *pCell, CellInfo *pInfo)
 
static void btreeParseCellPtrIndex (MemPage *pPage, u8 *pCell, CellInfo *pInfo)
 
static void btreeParseCell (MemPage *pPage, int iCell, CellInfo *pInfo)
 
static u16 cellSizePtr (MemPage *pPage, u8 *pCell)
 
static u16 cellSizePtrNoPayload (MemPage *pPage, u8 *pCell)
 
static void ptrmapPutOvflPtr (MemPage *pPage, MemPage *pSrc, u8 *pCell, int *pRC)
 
static int defragmentPage (MemPage *pPage, int nMaxFrag)
 
static u8pageFindSlot (MemPage *pPg, int nByte, int *pRc)
 
static int allocateSpace (MemPage *pPage, int nByte, int *pIdx)
 
static int freeSpace (MemPage *pPage, u16 iStart, u16 iSize)
 
static int decodeFlags (MemPage *pPage, int flagByte)
 
static int btreeComputeFreeSpace (MemPage *pPage)
 
static SQLITE_NOINLINE int btreeCellSizeCheck (MemPage *pPage)
 
static int btreeInitPage (MemPage *pPage)
 
static void zeroPage (MemPage *pPage, int flags)
 
static MemPagebtreePageFromDbPage (DbPage *pDbPage, Pgno pgno, BtShared *pBt)
 
static int btreeGetPage (BtShared *pBt, Pgno pgno, MemPage **ppPage, int flags)
 
static MemPagebtreePageLookup (BtShared *pBt, Pgno pgno)
 
static Pgno btreePagecount (BtShared *pBt)
 
static int getAndInitPage (BtShared *pBt, Pgno pgno, MemPage **ppPage, BtCursor *pCur, int bReadOnly)
 
static int btreeGetUnusedPage (BtShared *pBt, Pgno pgno, MemPage **ppPage, int flags)
 
static void pageReinit (DbPage *pData)
 
static int btreeInvokeBusyHandler (void *pArg)
 
static int removeFromSharingList (BtShared *pBt)
 
static void allocateTempSpace (BtShared *pBt)
 
static void freeTempSpace (BtShared *pBt)
 
static int newDatabase (BtShared *)
 
static int lockBtree (BtShared *pBt)
 
static void unlockBtreeIfUnused (BtShared *pBt)
 
static int setChildPtrmaps (MemPage *pPage)
 
static int modifyPagePointer (MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType)
 
static int relocatePage (BtShared *pBt, MemPage *pDbPage, u8 eType, Pgno iPtrPage, Pgno iFreePage, int isCommit)
 
static int allocateBtreePage (BtShared *, MemPage **, Pgno *, Pgno, u8)
 
static int incrVacuumStep (BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit)
 
static Pgno finalDbSize (BtShared *pBt, Pgno nOrig, Pgno nFree)
 
static int autoVacuumCommit (BtShared *pBt)
 
static void btreeEndTransaction (Btree *p)
 
static void btreeSetNPage (BtShared *pBt, MemPage *pPage1)
 
static int btreeCursor (Btree *p, Pgno iTable, int wrFlag, struct KeyInfo *pKeyInfo, BtCursor *pCur)
 
static int btreeCursorWithLock (Btree *p, Pgno iTable, int wrFlag, struct KeyInfo *pKeyInfo, BtCursor *pCur)
 
static SQLITE_NOINLINE void getCellInfo (BtCursor *pCur)
 
static int getOverflowPage (BtShared *pBt, Pgno ovfl, MemPage **ppPage, Pgno *pPgnoNext)
 
static int copyPayload (void *pPayload, void *pBuf, int nByte, int eOp, DbPage *pDbPage)
 
static int accessPayload (BtCursor *pCur, u32 offset, u32 amt, unsigned char *pBuf, int eOp)
 
static SQLITE_NOINLINE int accessPayloadChecked (BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 
static const void * fetchPayload (BtCursor *pCur, u32 *pAmt)
 
static int moveToChild (BtCursor *pCur, u32 newPgno)
 
static void moveToParent (BtCursor *pCur)
 
static int moveToRoot (BtCursor *pCur)
 
static int moveToLeftmost (BtCursor *pCur)
 
static int moveToRightmost (BtCursor *pCur)
 
static SQLITE_NOINLINE int btreeNext (BtCursor *pCur)
 
static SQLITE_NOINLINE int btreePrevious (BtCursor *pCur)
 
static int freePage2 (BtShared *pBt, MemPage *pMemPage, Pgno iPage)
 
static void freePage (MemPage *pPage, int *pRC)
 
static int clearCell (MemPage *pPage, unsigned char *pCell, CellInfo *pInfo)
 
static int fillInCell (MemPage *pPage, unsigned char *pCell, const BtreePayload *pX, int *pnSize)
 
static void dropCell (MemPage *pPage, int idx, int sz, int *pRC)
 
static void insertCell (MemPage *pPage, int i, u8 *pCell, int sz, u8 *pTemp, Pgno iChild, int *pRC)
 
static void populateCellCache (CellArray *p, int idx, int N)
 
static SQLITE_NOINLINE u16 computeCellSize (CellArray *p, int N)
 
static u16 cachedCellSize (CellArray *p, int N)
 
static int rebuildPage (CellArray *pCArray, int iFirst, int nCell, MemPage *pPg)
 
static int pageInsertArray (MemPage *pPg, u8 *pBegin, u8 **ppData, u8 *pCellptr, int iFirst, int nCell, CellArray *pCArray)
 
static int pageFreeArray (MemPage *pPg, int iFirst, int nCell, CellArray *pCArray)
 
static int editPage (MemPage *pPg, int iOld, int iNew, int nNew, CellArray *pCArray)
 
static int balance_quick (MemPage *pParent, MemPage *pPage, u8 *pSpace)
 
static void copyNodeContent (MemPage *pFrom, MemPage *pTo, int *pRC)
 
static int balance_nonroot (MemPage *pParent, int iParentIdx, u8 *aOvflSpace, int isRoot, int bBulk)
 
static int balance_deeper (MemPage *pRoot, MemPage **ppChild)
 
static int anotherValidCursor (BtCursor *pCur)
 
static int balance (BtCursor *pCur)
 
static int btreeOverwriteContent (MemPage *pPage, u8 *pDest, const BtreePayload *pX, int iOffset, int iAmt)
 
static int btreeOverwriteCell (BtCursor *pCur, const BtreePayload *pX)
 
static int btreeCreateTable (Btree *p, Pgno *piTable, int createTabFlags)
 
static int clearDatabasePage (BtShared *pBt, Pgno pgno, int freePageFlag, int *pnChange)
 
static int btreeDropTable (Btree *p, Pgno iTable, int *piMoved)
 
static void checkAppendMsg (IntegrityCk *pCheck, const char *zFormat,...)
 
static int getPageReferenced (IntegrityCk *pCheck, Pgno iPg)
 
static void setPageReferenced (IntegrityCk *pCheck, Pgno iPg)
 
static int checkRef (IntegrityCk *pCheck, Pgno iPage)
 
static void checkPtrmap (IntegrityCk *pCheck, Pgno iChild, u8 eType, Pgno iParent)
 
static void checkList (IntegrityCk *pCheck, int isFreeList, Pgno iPage, u32 N)
 
static void btreeHeapInsert (u32 *aHeap, u32 x)
 
static int btreeHeapPull (u32 *aHeap, u32 *pOut)
 
static int checkTreePage (IntegrityCk *pCheck, Pgno iPage, i64 *piMinKey, i64 maxKey)
 
static BtreefindBtree (sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb)
 
static int setDestPgsz (sqlite3_backup *p)
 
static int checkReadTransaction (sqlite3 *db, Btree *p)
 
static int isFatalError (int rc)
 
static int backupOnePage (sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData, int bUpdate)
 
static int backupTruncateFile (sqlite3_file *pFile, i64 iSize)
 
static void attachBackupObject (sqlite3_backup *p)
 
static SQLITE_NOINLINE void backupUpdate (sqlite3_backup *p, Pgno iPage, const u8 *aData)
 
static void vdbeMemRenderNum (int sz, char *zBuf, Mem *p)
 
static SQLITE_NOINLINE int vdbeMemAddTerminator (Mem *pMem)
 
static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull (Mem *p)
 
static SQLITE_NOINLINE void vdbeMemClear (Mem *p)
 
static SQLITE_NOINLINE i64 doubleToInt64 (double r)
 
static SQLITE_NOINLINE i64 memIntValue (Mem *pMem)
 
static SQLITE_NOINLINE double memRealValue (Mem *pMem)
 
static SQLITE_NOINLINE void vdbeReleaseAndSetInt64 (Mem *pMem, i64 val)
 
static SQLITE_NOINLINE void vdbeClrCopy (Mem *pTo, const Mem *pFrom, int eType)
 
static SQLITE_NOINLINE const void * valueToText (sqlite3_value *pVal, u8 enc)
 
static sqlite3_valuevalueNew (sqlite3 *db, struct ValueNewStat4Ctx *p)
 
static int valueFromExpr (sqlite3 *db, Expr *pExpr, u8 enc, u8 affinity, sqlite3_value **ppVal, struct ValueNewStat4Ctx *pCtx)
 
static SQLITE_NOINLINE int valueBytes (sqlite3_value *pVal, u8 enc)
 
static void freeEphemeralFunction (sqlite3 *db, FuncDef *pDef)
 
static void vdbeFreeOpArray (sqlite3 *, Op *, int)
 
static int growOpArray (Vdbe *v, int nOp)
 
static SQLITE_NOINLINE int growOp3 (Vdbe *p, int op, int p1, int p2, int p3)
 
static SQLITE_NOINLINE void resizeResolveLabel (Parse *p, Vdbe *v, int j)
 
static void resolveP2Values (Vdbe *p, int *pMaxFuncArgs)
 
static SQLITE_NOINLINE void freeP4Mem (sqlite3 *db, Mem *p)
 
static SQLITE_NOINLINE void freeP4FuncCtx (sqlite3 *db, sqlite3_context *p)
 
static void freeP4 (sqlite3 *db, int p4type, void *p4)
 
static void SQLITE_NOINLINE vdbeChangeP4Full (Vdbe *p, Op *pOp, const char *zP4, int n)
 
static SQLITE_NOINLINE void vdbeLeave (Vdbe *p)
 
static void initMemArray (Mem *p, int N, sqlite3 *db, u16 flags)
 
static void releaseMemArray (Mem *p, int N)
 
static void * allocSpace (struct ReusableSpace *p, void *pBuf, sqlite3_int64 nByte)
 
static void closeCursorsInFrame (Vdbe *p)
 
static void closeAllCursors (Vdbe *p)
 
static int vdbeCommit (sqlite3 *db, Vdbe *p)
 
static SQLITE_NOINLINE int vdbeCloseStatement (Vdbe *p, int eOp)
 
static int SQLITE_NOINLINE handleMovedCursor (VdbeCursor *p)
 
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut (u8 *buf, Mem *pMem, u32 serial_type)
 
static u32 serialGet (const unsigned char *buf, u32 serial_type, Mem *pMem)
 
static int vdbeCompareMemString (const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl, u8 *prcErr)
 
static int isAllZero (const char *z, int n)
 
static int sqlite3IntFloatCompare (i64 i, double r)
 
static i64 vdbeRecordDecodeInt (u32 serial_type, const u8 *aKey)
 
static int vdbeRecordCompareInt (int nKey1, const void *pKey1, UnpackedRecord *pPKey2)
 
static int vdbeRecordCompareString (int nKey1, const void *pKey1, UnpackedRecord *pPKey2)
 
static int vdbeSafety (Vdbe *p)
 
static int vdbeSafetyNotNull (Vdbe *p)
 
static SQLITE_NOINLINE void invokeProfileCallback (sqlite3 *db, Vdbe *p)
 
static void setResultStrOrError (sqlite3_context *pCtx, const char *z, int n, u8 enc, void(*xDel)(void *))
 
static int invokeValueDestructor (const void *p, void(*xDel)(void *), sqlite3_context *pCtx)
 
static int doWalCallbacks (sqlite3 *db)
 
static int sqlite3Step (Vdbe *p)
 
static SQLITE_NOINLINE void * createAggContext (sqlite3_context *p, int nByte)
 
static const MemcolumnNullValue (void)
 
static MemcolumnMem (sqlite3_stmt *pStmt, int i)
 
static void columnMallocFailure (sqlite3_stmt *pStmt)
 
static const void * columnName (sqlite3_stmt *pStmt, int N, int useUtf16, int useType)
 
static int vdbeUnbind (Vdbe *p, int i)
 
static int bindText (sqlite3_stmt *pStmt, int i, const void *zData, int nData, void(*xDel)(void *), u8 encoding)
 
static int findNextHostParameter (const char *zSql, int *pnToken)
 
static VdbeCursorallocateCursor (Vdbe *p, int iCur, int nField, int iDb, u8 eCurType)
 
static int alsoAnInt (Mem *pRec, double rValue, i64 *piValue)
 
static void applyNumericAffinity (Mem *pRec, int bTryForInt)
 
static void applyAffinity (Mem *pRec, char affinity, u8 enc)
 
static u16 SQLITE_NOINLINE computeNumericType (Mem *pMem)
 
static u16 numericType (Mem *pMem)
 
static SQLITE_NOINLINE Memout2PrereleaseWithClear (Mem *pOut)
 
static Memout2Prerelease (Vdbe *p, VdbeOp *pOp)
 
static int blobSeekToRow (Incrblob *p, sqlite3_int64 iRow, char **pzErr)
 
static int blobReadWrite (sqlite3_blob *pBlob, void *z, int n, int iOffset, int(*xCall)(BtCursor *, u32, u32, void *))
 
static int vdbeIncrSwap (IncrMerger *)
 
static void vdbeIncrFree (IncrMerger *)
 
static void vdbePmaReaderClear (PmaReader *pReadr)
 
static int vdbePmaReadBlob (PmaReader *p, int nByte, u8 **ppOut)
 
static int vdbePmaReadVarint (PmaReader *p, u64 *pnOut)
 
static int vdbeSorterMapFile (SortSubtask *pTask, SorterFile *pFile, u8 **pp)
 
static int vdbePmaReaderSeek (SortSubtask *pTask, PmaReader *pReadr, SorterFile *pFile, i64 iOff)
 
static int vdbePmaReaderNext (PmaReader *pReadr)
 
static int vdbePmaReaderInit (SortSubtask *pTask, SorterFile *pFile, i64 iStart, PmaReader *pReadr, i64 *pnByte)
 
static int vdbeSorterCompareTail (SortSubtask *pTask, int *pbKey2Cached, const void *pKey1, int nKey1, const void *pKey2, int nKey2)
 
static int vdbeSorterCompare (SortSubtask *pTask, int *pbKey2Cached, const void *pKey1, int nKey1, const void *pKey2, int nKey2)
 
static int vdbeSorterCompareText (SortSubtask *pTask, int *pbKey2Cached, const void *pKey1, int nKey1, const void *pKey2, int nKey2)
 
static int vdbeSorterCompareInt (SortSubtask *pTask, int *pbKey2Cached, const void *pKey1, int nKey1, const void *pKey2, int nKey2)
 
static void vdbeSorterRecordFree (sqlite3 *db, SorterRecord *pRecord)
 
static void vdbeSortSubtaskCleanup (sqlite3 *db, SortSubtask *pTask)
 
static int vdbeSorterJoinThread (SortSubtask *pTask)
 
static int vdbeSorterCreateThread (SortSubtask *pTask, void *(*xTask)(void *), void *pIn)
 
static int vdbeSorterJoinAll (VdbeSorter *pSorter, int rcin)
 
static MergeEnginevdbeMergeEngineNew (int nReader)
 
static void vdbeMergeEngineFree (MergeEngine *pMerger)
 
static int vdbeSorterOpenTempFile (sqlite3 *db, i64 nExtend, sqlite3_file **ppFd)
 
static int vdbeSortAllocUnpacked (SortSubtask *pTask)
 
static SorterRecordvdbeSorterMerge (SortSubtask *pTask, SorterRecord *p1, SorterRecord *p2)
 
static SorterCompare vdbeSorterGetCompare (VdbeSorter *p)
 
static int vdbeSorterSort (SortSubtask *pTask, SorterList *pList)
 
static void vdbePmaWriterInit (sqlite3_file *pFd, PmaWriter *p, int nBuf, i64 iStart)
 
static void vdbePmaWriteBlob (PmaWriter *p, u8 *pData, int nData)
 
static int vdbePmaWriterFinish (PmaWriter *p, i64 *piEof)
 
static void vdbePmaWriteVarint (PmaWriter *p, u64 iVal)
 
static int vdbeSorterListToPMA (SortSubtask *pTask, SorterList *pList)
 
static int vdbeMergeEngineStep (MergeEngine *pMerger, int *pbEof)
 
static void * vdbeSorterFlushThread (void *pCtx)
 
static int vdbeSorterFlushPMA (VdbeSorter *pSorter)
 
static int vdbeIncrPopulate (IncrMerger *pIncr)
 
static void * vdbeIncrPopulateThread (void *pCtx)
 
static int vdbeIncrBgPopulate (IncrMerger *pIncr)
 
static int vdbeIncrMergerNew (SortSubtask *pTask, MergeEngine *pMerger, IncrMerger **ppOut)
 
static void vdbeIncrMergerSetThreads (IncrMerger *pIncr)
 
static void vdbeMergeEngineCompare (MergeEngine *pMerger, int iOut)
 
static int vdbePmaReaderIncrInit (PmaReader *pReadr, int eMode)
 
static int vdbeMergeEngineInit (SortSubtask *pTask, MergeEngine *pMerger, int eMode)
 
static int vdbePmaReaderIncrMergeInit (PmaReader *pReadr, int eMode)
 
static void * vdbePmaReaderBgIncrInit (void *pCtx)
 
static int vdbeMergeEngineLevel0 (SortSubtask *pTask, int nPMA, i64 *piOffset, MergeEngine **ppOut)
 
static int vdbeSorterTreeDepth (int nPMA)
 
static int vdbeSorterAddToTree (SortSubtask *pTask, int nDepth, int iSeq, MergeEngine *pRoot, MergeEngine *pLeaf)
 
static int vdbeSorterMergeTreeBuild (VdbeSorter *pSorter, MergeEngine **ppOut)
 
static int vdbeSorterSetupMerge (VdbeSorter *pSorter)
 
static void * vdbeSorterRowkey (const VdbeSorter *pSorter, int *pnKey)
 
static int memjrnlRead (sqlite3_file *pJfd, void *zBuf, int iAmt, sqlite_int64 iOfst)
 
static void memjrnlFreeChunks (MemJournal *p)
 
static int memjrnlCreateFile (MemJournal *p)
 
static int memjrnlWrite (sqlite3_file *pJfd, const void *zBuf, int iAmt, sqlite_int64 iOfst)
 
static int memjrnlTruncate (sqlite3_file *pJfd, sqlite_int64 size)
 
static int memjrnlClose (sqlite3_file *pJfd)
 
static int memjrnlSync (sqlite3_file *pJfd, int flags)
 
static int memjrnlFileSize (sqlite3_file *pJfd, sqlite_int64 *pSize)
 
static int walkWindowList (Walker *pWalker, Window *pList)
 
static SQLITE_NOINLINE int walkExpr (Walker *pWalker, Expr *pExpr)
 
static int incrAggDepth (Walker *pWalker, Expr *pExpr)
 
static void incrAggFunctionDepth (Expr *pExpr, int N)
 
static void resolveAlias (Parse *pParse, ExprList *pEList, int iCol, Expr *pExpr, const char *zType, int nSubquery)
 
static int nameInUsingClause (IdList *pUsing, const char *zCol)
 
static int areDoubleQuotedStringsEnabled (sqlite3 *db, NameContext *pTopNC)
 
static int lookupName (Parse *pParse, const char *zDb, const char *zTab, const char *zCol, NameContext *pNC, Expr *pExpr)
 
static void notValidImpl (Parse *pParse, NameContext *pNC, const char *zMsg, Expr *pExpr)
 
static int exprProbability (Expr *p)
 
static int resolveExprStep (Walker *pWalker, Expr *pExpr)
 
static int resolveAsName (Parse *pParse, ExprList *pEList, Expr *pE)
 
static int resolveOrderByTermToExprList (Parse *pParse, Select *pSelect, Expr *pE)
 
static void resolveOutOfRangeError (Parse *pParse, const char *zType, int i, int mx)
 
static int resolveCompoundOrderBy (Parse *pParse, Select *pSelect)
 
static int resolveRemoveWindowsCb (Walker *pWalker, Expr *pExpr)
 
static void windowRemoveExprFromSelect (Select *pSelect, Expr *pExpr)
 
static int resolveOrderGroupBy (NameContext *pNC, Select *pSelect, ExprList *pOrderBy, const char *zType)
 
static int resolveSelectStep (Walker *pWalker, Select *p)
 
static void exprCodeBetween (Parse *, Expr *, int, void(*)(Parse *, Expr *, int, int), int)
 
static int exprCodeVector (Parse *pParse, Expr *p, int *piToFree)
 
static char comparisonAffinity (const Expr *pExpr)
 
static u8 binaryCompareP5 (const Expr *pExpr1, const Expr *pExpr2, int jumpIfNull)
 
static int codeCompare (Parse *pParse, Expr *pLeft, Expr *pRight, int opcode, int in1, int in2, int dest, int jumpIfNull, int isCommuted)
 
static int exprCodeSubselect (Parse *pParse, Expr *pExpr)
 
static int exprVectorRegister (Parse *pParse, Expr *pVector, int iField, int regSelect, Expr **ppExpr, int *pRegFree)
 
static void codeVectorCompare (Parse *pParse, Expr *pExpr, int dest, u8 op, u8 p5)
 
static void heightOfExpr (Expr *p, int *pnHeight)
 
static void heightOfExprList (ExprList *p, int *pnHeight)
 
static void heightOfSelect (Select *pSelect, int *pnHeight)
 
static void exprSetHeight (Expr *p)
 
static SQLITE_NOINLINE void sqlite3ExprDeleteNN (sqlite3 *db, Expr *p)
 
static int exprStructSize (Expr *p)
 
static int dupedExprStructSize (Expr *p, int flags)
 
static int dupedExprNodeSize (Expr *p, int flags)
 
static int dupedExprSize (Expr *p, int flags)
 
static ExprexprDup (sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer)
 
static WithwithDup (sqlite3 *db, With *p)
 
static int gatherSelectWindowsCallback (Walker *pWalker, Expr *pExpr)
 
static int gatherSelectWindowsSelectCallback (Walker *pWalker, Select *p)
 
static void gatherSelectWindows (Select *p)
 
static SQLITE_NOINLINE void exprListDeleteNN (sqlite3 *db, ExprList *pList)
 
static int exprNodeIsConstant (Walker *pWalker, Expr *pExpr)
 
static int exprIsConst (Expr *p, int initFlag, int iCur)
 
static int exprNodeIsConstantOrGroupBy (Walker *pWalker, Expr *pExpr)
 
static SelectisCandidateForInOpt (Expr *pX)
 
static void sqlite3SetHasNullFlag (Vdbe *v, int iCur, int regHasNull)
 
static int sqlite3InRhsIsConstant (Expr *pIn)
 
static char * exprINAffinity (Parse *pParse, Expr *pExpr)
 
SQLITE_PRIVATE void sqlite3SubselectError (Parse *pParse, int nActual, int nExpect)
 
static void sqlite3ExprCodeIN (Parse *pParse, Expr *pExpr, int destIfFalse, int destIfNull)
 
static void codeReal (Vdbe *v, const char *z, int negateFlag, int iMem)
 
static void codeInteger (Parse *pParse, Expr *pExpr, int negFlag, int iMem)
 
static void exprToRegister (Expr *pExpr, int iReg)
 
static void setDoNotMergeFlagOnCopy (Vdbe *v)
 
static int exprCodeInlineFunction (Parse *pParse, ExprList *pFarg, int iFuncId, int target)
 
static int exprCompareVariable (Parse *pParse, Expr *pVar, Expr *pExpr)
 
static int exprImpliesNotNull (Parse *pParse, Expr *p, Expr *pNN, int iTab, int seenNot)
 
static int impliesNotNullRow (Walker *pWalker, Expr *pExpr)
 
static int exprIdxCover (Walker *pWalker, Expr *pExpr)
 
static int selectSrcCount (Walker *pWalker, Select *pSel)
 
static int exprSrcCount (Walker *pWalker, Expr *pExpr)
 
static int agginfoPersistExprCb (Walker *pWalker, Expr *pExpr)
 
static int addAggInfoColumn (sqlite3 *db, AggInfo *pInfo)
 
static int addAggInfoFunc (sqlite3 *db, AggInfo *pInfo)
 
static int analyzeAggregate (Walker *pWalker, Expr *pExpr)
 
static int isAlterableTable (Parse *pParse, Table *pTab)
 
static void renameTestSchema (Parse *pParse, const char *zDb, int bTemp)
 
static void renameReloadSchema (Parse *pParse, int iDb)
 
static void sqlite3ErrorIfNotEmpty (Parse *pParse, const char *zDb, const char *zTab, const char *zErr)
 
static int isRealTable (Parse *pParse, Table *pTab)
 
static int renameUnmapExprCb (Walker *pWalker, Expr *pExpr)
 
static void renameWalkWith (Walker *pWalker, Select *pSelect)
 
static void unmapColumnIdlistNames (Parse *pParse, IdList *pIdList)
 
static int renameUnmapSelectCb (Walker *pWalker, Select *p)
 
static void renameTokenFree (sqlite3 *db, RenameToken *pToken)
 
static void renameTokenFind (Parse *pParse, struct RenameCtx *pCtx, void *pPtr)
 
static int renameColumnSelectCb (Walker *pWalker, Select *p)
 
static int renameColumnExprCb (Walker *pWalker, Expr *pExpr)
 
static RenameTokenrenameColumnTokenNext (RenameCtx *pCtx)
 
static void renameColumnParseError (sqlite3_context *pCtx, int bPost, sqlite3_value *pType, sqlite3_value *pObject, Parse *pParse)
 
static void renameColumnElistNames (Parse *pParse, RenameCtx *pCtx, ExprList *pEList, const char *zOld)
 
static void renameColumnIdlistNames (Parse *pParse, RenameCtx *pCtx, IdList *pIdList, const char *zOld)
 
static int renameParseSql (Parse *p, const char *zDb, sqlite3 *db, const char *zSql, int bTemp)
 
static int renameEditSql (sqlite3_context *pCtx, RenameCtx *pRename, const char *zSql, const char *zNew, int bQuote)
 
static int renameResolveTrigger (Parse *pParse)
 
static void renameWalkTrigger (Walker *pWalker, Trigger *pTrigger)
 
static void renameParseCleanup (Parse *pParse)
 
static void renameColumnFunc (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static int renameTableExprCb (Walker *pWalker, Expr *pExpr)
 
static int renameTableSelectCb (Walker *pWalker, Select *pSelect)
 
static void renameTableFunc (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void renameTableTest (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void openStatTable (Parse *pParse, int iDb, int iStatCur, const char *zWhere, const char *zWhereType)
 
static void statAccumDestructor (void *pOld)
 
static void statInit (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void statPush (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void statGet (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void callStatGet (Parse *pParse, int regStat, int iParam, int regOut)
 
static void analyzeOneTable (Parse *pParse, Table *pTab, Index *pOnlyIdx, int iStatCur, int iMem, int iTab)
 
static void loadAnalysis (Parse *pParse, int iDb)
 
static void analyzeDatabase (Parse *pParse, int iDb)
 
static void analyzeTable (Parse *pParse, Table *pTab, Index *pOnlyIdx)
 
static void decodeIntArray (char *zIntArray, int nOut, tRowcnt *aOut, LogEst *aLog, Index *pIndex)
 
static int analysisLoader (void *pData, int argc, char **argv, char **NotUsed)
 
static int resolveAttachExpr (NameContext *pName, Expr *pExpr)
 
static void attachFunc (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void detachFunc (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void codeAttach (Parse *pParse, int type, FuncDef const *pFunc, Expr *pAuthArg, Expr *pFilename, Expr *pDbname, Expr *pKey)
 
static void sqliteAuthBadReturnCode (Parse *pParse)
 
static void codeTableLocks (Parse *pParse)
 
static void SQLITE_NOINLINE deleteTable (sqlite3 *db, Table *pTable)
 
static void sqlite3StringToId (Expr *p)
 
static void makeColumnPartOfPrimaryKey (Parse *pParse, Column *pCol)
 
static int identLength (const char *z)
 
static void identPut (char *z, int *pIdx, char *zSignedIdent)
 
static char * createTableStmt (sqlite3 *db, Table *p)
 
static int resizeIndexObject (sqlite3 *db, Index *pIdx, int N)
 
static void estimateTableWidth (Table *pTab)
 
static void estimateIndexWidth (Index *pIdx)
 
static int hasColumn (const i16 *aiCol, int nCol, int x)
 
static int isDupColumn (Index *pIdx, int nKey, Index *pPk, int iCol)
 
static void recomputeColumnsNotIndexed (Index *pIdx)
 
static void convertToWithoutRowidTable (Parse *pParse, Table *pTab)
 
static void sqliteViewResetAll (sqlite3 *db, int idx)
 
static void destroyRootPage (Parse *pParse, int iTable, int iDb)
 
static void destroyTable (Parse *pParse, Table *pTab)
 
static void sqlite3ClearStatTables (Parse *pParse, int iDb, const char *zType, const char *zName)
 
static int tableMayNotBeDropped (sqlite3 *db, Table *pTab)
 
static void sqlite3RefillIndex (Parse *pParse, Index *pIndex, int memRootPage)
 
static int collationMatch (const char *zColl, Index *pIndex)
 
static void reindexTable (Parse *pParse, Table *pTab, char const *zColl)
 
static void reindexDatabases (Parse *pParse, char const *zColl)
 
static void callCollNeeded (sqlite3 *db, int enc, const char *zName)
 
static int synthCollSeq (sqlite3 *db, CollSeq *pColl)
 
static CollSeqfindCollSeqEntry (sqlite3 *db, const char *zName, int create)
 
static int matchQuality (FuncDef *p, int nArg, u8 enc)
 
static int tabIsReadOnly (Parse *pParse, Table *pTab)
 
static CollSeqsqlite3GetFuncCollSeq (sqlite3_context *context)
 
static void sqlite3SkipAccumulatorLoad (sqlite3_context *context)
 
static void minmaxFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void typeofFunc (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void lengthFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void absFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void instrFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void printfFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void substrFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void roundFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void * contextMalloc (sqlite3_context *context, i64 nByte)
 
static void upperFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void lowerFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void randomFunc (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void randomBlob (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void last_insert_rowid (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void changes (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void total_changes (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static int patternCompare (const u8 *zPattern, const u8 *zString, const struct compareInfo *pInfo, u32 matchOther)
 
static void likeFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void nullifFunc (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void versionFunc (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void sourceidFunc (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static void errlogFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void compileoptionusedFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void compileoptiongetFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void quoteFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void unicodeFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void charFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void hexFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void zeroblobFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void replaceFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void trimFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void loadExt (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void sumStep (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void sumInverse (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void sumFinalize (sqlite3_context *context)
 
static void avgFinalize (sqlite3_context *context)
 
static void totalFinalize (sqlite3_context *context)
 
static void countStep (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void countFinalize (sqlite3_context *context)
 
static void countInverse (sqlite3_context *ctx, int argc, sqlite3_value **argv)
 
static void minmaxStep (sqlite3_context *context, int NotUsed, sqlite3_value **argv)
 
static void minMaxValueFinalize (sqlite3_context *context, int bValue)
 
static void minMaxValue (sqlite3_context *context)
 
static void minMaxFinalize (sqlite3_context *context)
 
static void groupConcatStep (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void groupConcatInverse (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void groupConcatFinalize (sqlite3_context *context)
 
static void groupConcatValue (sqlite3_context *context)
 
static void fkLookupParent (Parse *pParse, int iDb, Table *pTab, Index *pIdx, FKey *pFKey, int *aiCol, int regData, int nIncr, int isIgnore)
 
static ExprexprTableRegister (Parse *pParse, Table *pTab, int regBase, i16 iCol)
 
static ExprexprTableColumn (sqlite3 *db, Table *pTab, int iCursor, i16 iCol)
 
static void fkScanChildren (Parse *pParse, SrcList *pSrc, Table *pTab, Index *pIdx, FKey *pFKey, int *aiCol, int regData, int nIncr)
 
static void fkTriggerDelete (sqlite3 *dbMem, Trigger *p)
 
static int fkChildIsModified (Table *pTab, FKey *p, int *aChange, int bChngRowid)
 
static int fkParentIsModified (Table *pTab, FKey *p, int *aChange, int bChngRowid)
 
static int isSetNullAction (Parse *pParse, FKey *pFKey)
 
static TriggerfkActionTrigger (Parse *pParse, Table *pTab, FKey *pFKey, ExprList *pChanges)
 
static int readsTable (Parse *p, int iDb, Table *pTab)
 
static int exprColumnFlagUnion (Walker *pWalker, Expr *pExpr)
 
static int autoIncBegin (Parse *pParse, int iDb, Table *pTab)
 
static void autoIncStep (Parse *pParse, int memId, int regRowid)
 
static SQLITE_NOINLINE void autoIncrementEnd (Parse *pParse)
 
static int xferOptimization (Parse *pParse, Table *pDest, Select *pSelect, int onError, int iDbDest)
 
static int checkConstraintExprNode (Walker *pWalker, Expr *pExpr)
 
static int xferCompatibleIndex (Index *pDest, Index *pSrc)
 
static int sqlite3LoadExtension (sqlite3 *db, const char *zFile, const char *zProc, char **pzErrMsg)
 
static u8 getSafetyLevel (const char *z, int omitFull, u8 dflt)
 
static int getLockingMode (const char *z)
 
static int getAutoVacuum (const char *z)
 
static int getTempStore (const char *z)
 
static int invalidateTempStorage (Parse *pParse)
 
static int changeTempStorage (Parse *pParse, const char *zStorageType)
 
static void setPragmaResultColumnNames (Vdbe *v, const PragmaName *pPragma)
 
static void returnSingleInt (Vdbe *v, i64 value)
 
static void returnSingleText (Vdbe *v, const char *zValue)
 
static void setAllPagerFlags (sqlite3 *db)
 
static const char * actionName (u8 action)
 
static const PragmaNamepragmaLocate (const char *zName)
 
static void pragmaFunclistLine (Vdbe *v, FuncDef *p, int isBuiltin, int showInternFuncs)
 
static int integrityCheckResultRow (Vdbe *v)
 
static int pragmaVtabConnect (sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
 
static int pragmaVtabDisconnect (sqlite3_vtab *pVtab)
 
static int pragmaVtabBestIndex (sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
 
static int pragmaVtabOpen (sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor)
 
static void pragmaVtabCursorClear (PragmaVtabCursor *pCsr)
 
static int pragmaVtabClose (sqlite3_vtab_cursor *cur)
 
static int pragmaVtabNext (sqlite3_vtab_cursor *pVtabCursor)
 
static int pragmaVtabFilter (sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
 
static int pragmaVtabEof (sqlite3_vtab_cursor *pVtabCursor)
 
static int pragmaVtabColumn (sqlite3_vtab_cursor *pVtabCursor, sqlite3_context *ctx, int i)
 
static int pragmaVtabRowid (sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *p)
 
static void corruptSchema (InitData *pData, const char *zObj, const char *zExtra)
 
static int sqlite3Prepare (sqlite3 *db, const char *zSql, int nBytes, u32 prepFlags, Vdbe *pReprepare, sqlite3_stmt **ppStmt, const char **pzTail)
 
static void schemaIsValid (Parse *pParse)
 
static void agginfoFree (sqlite3 *db, AggInfo *p)
 
static int sqlite3LockAndPrepare (sqlite3 *db, const char *zSql, int nBytes, u32 prepFlags, Vdbe *pOld, sqlite3_stmt **ppStmt, const char **pzTail)
 
static int sqlite3Prepare16 (sqlite3 *db, const void *zSql, int nBytes, u32 prepFlags, sqlite3_stmt **ppStmt, const void **pzTail)
 
static void clearSelect (sqlite3 *db, Select *p, int bFree)
 
static SelectfindRightmost (Select *p)
 
static int columnIndex (Table *pTab, const char *zCol)
 
static int tableAndColumnIndex (SrcList *pSrc, int N, const char *zCol, int *piTab, int *piCol, int bIgnoreHidden)
 
static void addWhereTerm (Parse *pParse, SrcList *pSrc, int iLeft, int iColLeft, int iRight, int iColRight, int isOuterJoin, Expr **ppWhere)
 
static void unsetJoinExpr (Expr *p, int iTable)
 
static int sqliteProcessJoin (Parse *pParse, Select *p)
 
static void innerLoopLoadRow (Parse *pParse, Select *pSelect, RowLoadInfo *pInfo)
 
static int makeSorterRecord (Parse *pParse, SortCtx *pSort, Select *pSelect, int regBase, int nBase)
 
static void pushOntoSorter (Parse *pParse, SortCtx *pSort, Select *pSelect, int regData, int regOrigData, int nData, int nPrefixReg)
 
static void codeOffset (Vdbe *v, int iOffset, int iContinue)
 
static void codeDistinct (Parse *pParse, int iTab, int addrRepeat, int N, int iMem)
 
static void selectInnerLoop (Parse *pParse, Select *p, int srcTab, SortCtx *pSort, DistinctCtx *pDistinct, SelectDest *pDest, int iContinue, int iBreak)
 
static const char * selectOpName (int id)
 
static void explainTempTable (Parse *pParse, const char *zUsage)
 
static void generateSortTail (Parse *pParse, Select *p, SortCtx *pSort, int nColumn, SelectDest *pDest)
 
static const char * columnTypeImpl (NameContext *pNC, Expr *pExpr)
 
static void generateColumnTypes (Parse *pParse, SrcList *pTabList, ExprList *pEList)
 
static void generateColumnNames (Parse *pParse, Select *pSelect)
 
static void computeLimitRegisters (Parse *pParse, Select *p, int iBreak)
 
static CollSeqmultiSelectCollSeq (Parse *pParse, Select *p, int iCol)
 
static KeyInfomultiSelectOrderByKeyInfo (Parse *pParse, Select *p, int nExtra)
 
static void generateWithRecursiveQuery (Parse *pParse, Select *p, SelectDest *pDest)
 
static int multiSelectOrderBy (Parse *pParse, Select *p, SelectDest *pDest)
 
static int multiSelectValues (Parse *pParse, Select *p, SelectDest *pDest)
 
static int multiSelect (Parse *pParse, Select *p, SelectDest *pDest)
 
static int generateOutputSubroutine (Parse *pParse, Select *p, SelectDest *pIn, SelectDest *pDest, int regReturn, int regPrev, KeyInfo *pKeyInfo, int iBreak)
 
static void substExprList (SubstContext *, ExprList *)
 
static void substSelect (SubstContext *, Select *, int)
 
static ExprsubstExpr (SubstContext *pSubst, Expr *pExpr)
 
static int recomputeColumnsUsedExpr (Walker *pWalker, Expr *pExpr)
 
static void recomputeColumnsUsed (Select *pSelect, struct SrcList_item *pSrcItem)
 
static int flattenSubquery (Parse *pParse, Select *p, int iFrom, int isAgg)
 
static void constInsert (WhereConst *pConst, Expr *pColumn, Expr *pValue, Expr *pExpr)
 
static void findConstInWhere (WhereConst *pConst, Expr *pExpr)
 
static int propagateConstantExprRewrite (Walker *pWalker, Expr *pExpr)
 
static int propagateConstants (Parse *pParse, Select *p)
 
static int pushDownWhereTerms (Parse *pParse, Select *pSubq, Expr *pWhere, int iCursor, int isLeftJoin)
 
static u8 minMaxQuery (sqlite3 *db, Expr *pFunc, ExprList **ppMinMax)
 
static TableisSimpleCount (Select *p, AggInfo *pAggInfo)
 
static int convertCompoundSelectToSubquery (Walker *pWalker, Select *p)
 
static int cannotBeFunction (Parse *pParse, struct SrcList_item *pFrom)
 
static struct Cte * searchWith (With *pWith, struct SrcList_item *pItem, With **ppContext)
 
static int withExpand (Walker *pWalker, struct SrcList_item *pFrom)
 
static void selectPopWith (Walker *pWalker, Select *p)
 
static int selectExpander (Walker *pWalker, Select *p)
 
static void sqlite3SelectExpand (Parse *pParse, Select *pSelect)
 
static void selectAddSubqueryTypeInfo (Walker *pWalker, Select *p)
 
static void sqlite3SelectAddTypeInfo (Parse *pParse, Select *pSelect)
 
static void resetAccumulator (Parse *pParse, AggInfo *pAggInfo)
 
static void finalizeAggFunctions (Parse *pParse, AggInfo *pAggInfo)
 
static void updateAccumulator (Parse *pParse, int regAcc, AggInfo *pAggInfo)
 
static void explainSimpleCount (Parse *pParse, Table *pTab, Index *pIdx)
 
static int havingToWhereExprCb (Walker *pWalker, Expr *pExpr)
 
static void havingToWhere (Parse *pParse, Select *p)
 
static struct SrcList_item * isSelfJoinView (SrcList *pTabList, struct SrcList_item *pThis)
 
static int sqlite3_get_table_cb (void *pArg, int nCol, char **argv, char **colv)
 
static char * triggerSpanDup (sqlite3 *db, const char *zStart, const char *zEnd)
 
static TriggerSteptriggerStepAllocate (Parse *pParse, u8 op, Token *pName, const char *zStart, const char *zEnd)
 
static TabletableOfTrigger (Trigger *pTrigger)
 
static int checkColumnOverlap (IdList *pIdList, ExprList *pEList)
 
static int codeTriggerProgram (Parse *pParse, TriggerStep *pStepList, int orconf)
 
static void transferParseError (Parse *pTo, Parse *pFrom)
 
static TriggerPrgcodeRowTrigger (Parse *pParse, Trigger *pTrigger, Table *pTab, int orconf)
 
static TriggerPrggetRowTrigger (Parse *pParse, Trigger *pTrigger, Table *pTab, int orconf)
 
static void updateVirtualTable (Parse *pParse, SrcList *pSrc, Table *pTab, ExprList *pChanges, Expr *pRowidExpr, int *aXRef, Expr *pWhere, int onError)
 
static int indexColumnIsBeingUpdated (Index *pIdx, int iCol, int *aXRef, int chngRowid)
 
static int indexWhereClauseMightChange (Index *pIdx, int *aXRef, int chngRowid)
 
static ExprexprRowColumn (Parse *pParse, int iCol)
 
static void updateFromSelect (Parse *pParse, int iEph, Index *pPk, ExprList *pChanges, SrcList *pTabList, Expr *pWhere, ExprList *pOrderBy, Expr *pLimit)
 
static int execSql (sqlite3 *db, char **pzErrMsg, const char *zSql)
 
static int execSqlF (sqlite3 *db, char **pzErrMsg, const char *zSql,...)
 
static int createModule (sqlite3 *db, const char *zName, const sqlite3_module *pModule, void *pAux, void(*xDestroy)(void *))
 
static VTablevtabDisconnectAll (sqlite3 *db, Table *p)
 
static void addModuleArgument (Parse *pParse, Table *pTable, char *zArg)
 
static void addArgumentToVtab (Parse *pParse)
 
static int vtabCallConstructor (sqlite3 *db, Table *pTab, Module *pMod, int(*xConstruct)(sqlite3 *, void *, int, const char *const *, sqlite3_vtab **, char **), char **pzErr)
 
static int growVTrans (sqlite3 *db)
 
static void addToVTrans (sqlite3 *db, VTable *pVTab)
 
static void callFinaliser (sqlite3 *db, int offset)
 
SQLITE_PRIVATE Bitmask sqlite3WhereGetMask (WhereMaskSet *, int)
 
SQLITE_PRIVATE WhereTermsqlite3WhereFindTerm (WhereClause *pWC, int iCur, int iColumn, Bitmask notReady, u32 op, Index *pIdx)
 
SQLITE_PRIVATE int sqlite3WhereExplainOneScan (Parse *pParse, SrcList *pTabList, WhereLevel *pLevel, u16 wctrlFlags)
 
SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart (Parse *pParse, Vdbe *v, WhereInfo *pWInfo, int iLevel, WhereLevel *pLevel, Bitmask notReady)
 
SQLITE_PRIVATE void sqlite3WhereClauseInit (WhereClause *, WhereInfo *)
 
SQLITE_PRIVATE void sqlite3WhereClauseClear (WhereClause *)
 
SQLITE_PRIVATE void sqlite3WhereSplit (WhereClause *, Expr *, u8)
 
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage (WhereMaskSet *, Expr *)
 
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN (WhereMaskSet *, Expr *)
 
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage (WhereMaskSet *, ExprList *)
 
SQLITE_PRIVATE void sqlite3WhereExprAnalyze (SrcList *, WhereClause *)
 
SQLITE_PRIVATE void sqlite3WhereTabFuncArgs (Parse *, struct SrcList_item *, WhereClause *)
 
static const char * explainIndexColumnName (Index *pIdx, int i)
 
static void explainAppendTerm (StrAccum *pStr, Index *pIdx, int nTerm, int iTerm, int bAnd, const char *zOp)
 
static void explainIndexRange (StrAccum *pStr, WhereLoop *pLoop)
 
static void disableTerm (WhereLevel *pLevel, WhereTerm *pTerm)
 
static void codeApplyAffinity (Parse *pParse, int base, int n, char *zAff)
 
static void updateRangeAffinityStr (Expr *pRight, int n, char *zAff)
 
static ExprremoveUnindexableInClauseTerms (Parse *pParse, int iEq, WhereLoop *pLoop, Expr *pX)
 
static int codeEqualityTerm (Parse *pParse, WhereTerm *pTerm, WhereLevel *pLevel, int iEq, int bRev, int iTarget)
 
static int codeAllEqualityTerms (Parse *pParse, WhereLevel *pLevel, int bRev, int nExtraReg, char **pzAff)
 
static void whereLikeOptimizationStringFixup (Vdbe *v, WhereLevel *pLevel, WhereTerm *pTerm)
 
static void codeDeferredSeek (WhereInfo *pWInfo, Index *pIdx, int iCur, int iIdxCur)
 
static void codeExprOrVector (Parse *pParse, Expr *p, int iReg, int nReg)
 
static void preserveExpr (IdxExprTrans *pTrans, Expr *pExpr)
 
static int whereIndexExprTransNode (Walker *p, Expr *pExpr)
 
static int whereIndexExprTransColumn (Walker *p, Expr *pExpr)
 
static void whereIndexExprTrans (Index *pIdx, int iTabCur, int iIdxCur, WhereInfo *pWInfo)
 
static void whereApplyPartialIndexConstraints (Expr *pTruth, int iTabCur, WhereClause *pWC)
 
static void exprAnalyze (SrcList *, WhereClause *, int)
 
static void whereOrInfoDelete (sqlite3 *db, WhereOrInfo *p)
 
static void whereAndInfoDelete (sqlite3 *db, WhereAndInfo *p)
 
static int whereClauseInsert (WhereClause *pWC, Expr *p, u16 wtFlags)
 
static int allowedOp (int op)
 
static u16 exprCommute (Parse *pParse, Expr *pExpr)
 
static u16 operatorMask (int op)
 
static int isLikeOrGlob (Parse *pParse, Expr *pExpr, Expr **ppPrefix, int *pisComplete, int *pnoCase)
 
static int isAuxiliaryVtabOperator (sqlite3 *db, Expr *pExpr, unsigned char *peOp2, Expr **ppLeft, Expr **ppRight)
 
static void transferJoinMarkings (Expr *pDerived, Expr *pBase)
 
static void markTermAsChild (WhereClause *pWC, int iChild, int iParent)
 
static WhereTermwhereNthSubterm (WhereTerm *pTerm, int N)
 
static void whereCombineDisjuncts (SrcList *pSrc, WhereClause *pWC, WhereTerm *pOne, WhereTerm *pTwo)
 
static void exprAnalyzeOrTerm (SrcList *pSrc, WhereClause *pWC, int idxTerm)
 
static int termIsEquivalence (Parse *pParse, Expr *pExpr)
 
static Bitmask exprSelectUsage (WhereMaskSet *pMaskSet, Select *pS)
 
static SQLITE_NOINLINE int exprMightBeIndexed2 (SrcList *pFrom, Bitmask mPrereq, int *aiCurCol, Expr *pExpr)
 
static int exprMightBeIndexed (SrcList *pFrom, Bitmask mPrereq, int *aiCurCol, Expr *pExpr, int op)
 
static int whereLoopResize (sqlite3 *, WhereLoop *, int)
 
static void whereOrMove (WhereOrSet *pDest, WhereOrSet *pSrc)
 
static int whereOrInsert (WhereOrSet *pSet, Bitmask prereq, LogEst rRun, LogEst nOut)
 
static void createMask (WhereMaskSet *pMaskSet, int iCursor)
 
static WhereTermwhereScanNext (WhereScan *pScan)
 
static SQLITE_NOINLINE WhereTermwhereScanInitIndexExpr (WhereScan *pScan)
 
static WhereTermwhereScanInit (WhereScan *pScan, WhereClause *pWC, int iCur, int iColumn, u32 opMask, Index *pIdx)
 
static int findIndexCol (Parse *pParse, ExprList *pList, int iBase, Index *pIdx, int iCol)
 
static int indexColumnNotNull (Index *pIdx, int iCol)
 
static int isDistinctRedundant (Parse *pParse, SrcList *pTabList, WhereClause *pWC, ExprList *pDistinct)
 
static LogEst estLog (LogEst N)
 
static void translateColumnToCopy (Parse *pParse, int iStart, int iTabCur, int iRegister, int iAutoidxCur)
 
static int termCanDriveIndex (WhereTerm *pTerm, struct SrcList_item *pSrc, Bitmask notReady)
 
static void constructAutomaticIndex (Parse *pParse, WhereClause *pWC, struct SrcList_item *pSrc, Bitmask notReady, WhereLevel *pLevel)
 
static sqlite3_index_infoallocateIndexInfo (Parse *pParse, WhereClause *pWC, Bitmask mUnusable, struct SrcList_item *pSrc, ExprList *pOrderBy, u16 *pmNoOmit)
 
static int vtabBestIndex (Parse *pParse, Table *pTab, sqlite3_index_info *p)
 
static LogEst whereRangeAdjust (WhereTerm *pTerm, LogEst nNew)
 
static int whereRangeScanEst (Parse *pParse, WhereLoopBuilder *pBuilder, WhereTerm *pLower, WhereTerm *pUpper, WhereLoop *pLoop)
 
static void whereLoopInit (WhereLoop *p)
 
static void whereLoopClearUnion (sqlite3 *db, WhereLoop *p)
 
static void whereLoopClear (sqlite3 *db, WhereLoop *p)
 
static int whereLoopXfer (sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom)
 
static void whereLoopDelete (sqlite3 *db, WhereLoop *p)
 
static void whereInfoFree (sqlite3 *db, WhereInfo *pWInfo)
 
static int whereLoopCheaperProperSubset (const WhereLoop *pX, const WhereLoop *pY)
 
static void whereLoopAdjustCost (const WhereLoop *p, WhereLoop *pTemplate)
 
static WhereLoop ** whereLoopFindLesser (WhereLoop **ppPrev, const WhereLoop *pTemplate)
 
static int whereLoopInsert (WhereLoopBuilder *pBuilder, WhereLoop *pTemplate)
 
static void whereLoopOutputAdjust (WhereClause *pWC, WhereLoop *pLoop, LogEst nRow)
 
static int whereRangeVectorLen (Parse *pParse, int iCur, Index *pIdx, int nEq, WhereTerm *pTerm)
 
static int whereLoopAddBtreeIndex (WhereLoopBuilder *pBuilder, struct SrcList_item *pSrc, Index *pProbe, LogEst nInMul)
 
static int indexMightHelpWithOrderBy (WhereLoopBuilder *pBuilder, Index *pIndex, int iCursor)
 
static int whereUsablePartialIndex (int iTab, int isLeft, WhereClause *pWC, Expr *pWhere)
 
static int whereLoopAddBtree (WhereLoopBuilder *pBuilder, Bitmask mPrereq)
 
static int whereLoopAddVirtualOne (WhereLoopBuilder *pBuilder, Bitmask mPrereq, Bitmask mUsable, u16 mExclude, sqlite3_index_info *pIdxInfo, u16 mNoOmit, int *pbIn)
 
static int whereLoopAddVirtual (WhereLoopBuilder *pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 
static int whereLoopAddOr (WhereLoopBuilder *pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 
static int whereLoopAddAll (WhereLoopBuilder *pBuilder)
 
static i8 wherePathSatisfiesOrderBy (WhereInfo *pWInfo, ExprList *pOrderBy, WherePath *pPath, u16 wctrlFlags, u16 nLoop, WhereLoop *pLast, Bitmask *pRevMask)
 
static LogEst whereSortingCost (WhereInfo *pWInfo, LogEst nRow, int nOrderBy, int nSorted)
 
static int wherePathSolver (WhereInfo *pWInfo, LogEst nRowEst)
 
static int whereShortCut (WhereLoopBuilder *pBuilder)
 
static int exprNodeIsDeterministic (Walker *pWalker, Expr *pExpr)
 
static int exprIsDeterministic (Expr *p)
 
static void row_numberStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void row_numberValueFunc (sqlite3_context *pCtx)
 
static void dense_rankStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void dense_rankValueFunc (sqlite3_context *pCtx)
 
static void nth_valueStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void nth_valueFinalizeFunc (sqlite3_context *pCtx)
 
static void first_valueStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void first_valueFinalizeFunc (sqlite3_context *pCtx)
 
static void rankStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void rankValueFunc (sqlite3_context *pCtx)
 
static void percent_rankStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void percent_rankInvFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void percent_rankValueFunc (sqlite3_context *pCtx)
 
static void cume_distStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void cume_distInvFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void cume_distValueFunc (sqlite3_context *pCtx)
 
static void ntileStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void ntileInvFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void ntileValueFunc (sqlite3_context *pCtx)
 
static void last_valueStepFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void last_valueInvFunc (sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
 
static void last_valueValueFunc (sqlite3_context *pCtx)
 
static void last_valueFinalizeFunc (sqlite3_context *pCtx)
 
static void noopStepFunc (sqlite3_context *p, int n, sqlite3_value **a)
 
static void noopValueFunc (sqlite3_context *p)
 
static WindowwindowFind (Parse *pParse, Window *pList, const char *zName)
 
static int selectWindowRewriteExprCb (Walker *pWalker, Expr *pExpr)
 
static int selectWindowRewriteSelectCb (Walker *pWalker, Select *pSelect)
 
static void selectWindowRewriteEList (Parse *pParse, Window *pWin, SrcList *pSrc, ExprList *pEList, Table *pTab, ExprList **ppSub)
 
static ExprListexprListAppendList (Parse *pParse, ExprList *pList, ExprList *pAppend, int bIntToNull)
 
static int sqlite3WindowExtraAggFuncDepth (Walker *pWalker, Expr *pExpr)
 
static Exprsqlite3WindowOffsetExpr (Parse *pParse, Expr *pExpr)
 
static void windowCheckValue (Parse *pParse, int reg, int eCond)
 
static int windowArgCount (Window *pWin)
 
static void windowReadPeerValues (WindowCodeArg *p, int csr, int reg)
 
static void windowAggStep (WindowCodeArg *p, Window *pMWin, int csr, int bInverse, int reg)
 
static void windowAggFinal (WindowCodeArg *p, int bFin)
 
static void windowFullScan (WindowCodeArg *p)
 
static void windowReturnOneRow (WindowCodeArg *p)
 
static int windowInitAccum (Parse *pParse, Window *pMWin)
 
static int windowCacheFrame (Window *pMWin)
 
static void windowIfNewPeer (Parse *pParse, ExprList *pOrderBy, int regNew, int regOld, int addr)
 
static void windowCodeRangeTest (WindowCodeArg *p, int op, int csr1, int regVal, int csr2, int lbl)
 
static int windowCodeOp (WindowCodeArg *p, int op, int regCountdown, int jumpOnEof)
 
static int windowExprGtZero (Parse *pParse, Expr *pExpr)
 
static void disableLookaside (Parse *pParse)
 
static void parserDoubleLinkSelect (Parse *pParse, Select *p)
 
static ExprtokenExpr (Parse *pParse, int op, Token t)
 
static void binaryToUnaryIfNull (Parse *pParse, Expr *pY, Expr *pA, int op)
 
static ExprListparserAddExprIdListTerm (Parse *pParse, ExprList *pPrior, Token *pIdToken, int hasCollate, int sortOrder)
 
SQLITE_PRIVATE void sqlite3ParserInit (void *yypRawParser sqlite3ParserCTX_PDECL)
 
static void yy_destructor (yyParser *yypParser, YYCODETYPE yymajor, YYMINORTYPE *yypminor)
 
static void yy_pop_parser_stack (yyParser *pParser)
 
SQLITE_PRIVATE void sqlite3ParserFinalize (void *p)
 
static YYACTIONTYPE yy_find_shift_action (YYCODETYPE iLookAhead, YYACTIONTYPE stateno)
 
static YYACTIONTYPE yy_find_reduce_action (YYACTIONTYPE stateno, YYCODETYPE iLookAhead)
 
static void yyStackOverflow (yyParser *yypParser)
 
static void yy_shift (yyParser *yypParser, YYACTIONTYPE yyNewState, YYCODETYPE yyMajor, sqlite3ParserTOKENTYPE yyMinor)
 
static void yy_accept (yyParser *)
 
static YYACTIONTYPE yy_reduce (yyParser *yypParser, unsigned int yyruleno, int yyLookahead, sqlite3ParserTOKENTYPE yyLookaheadToken sqlite3ParserCTX_PDECL)
 
static void yy_syntax_error (yyParser *yypParser, int yymajor, sqlite3ParserTOKENTYPE yyminor)
 
SQLITE_PRIVATE void sqlite3Parser (void *yyp, int yymajor, sqlite3ParserTOKENTYPE yyminor sqlite3ParserARG_PDECL)
 
static int keywordCode (const char *z, int n, int *pType)
 
static int getToken (const unsigned char **pz)
 
static int analyzeWindowKeyword (const unsigned char *z)
 
static int analyzeOverKeyword (const unsigned char *z, int lastToken)
 
static int analyzeFilterKeyword (const unsigned char *z, int lastToken)
 
static int sqlite3TestExtInit (sqlite3 *db)
 
static int setupLookaside (sqlite3 *db, void *pBuf, int sz, int cnt)
 
static int binCollFunc (void *NotUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
 
static int rtrimCollFunc (void *pUser, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
 
static int nocaseCollatingFunc (void *NotUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
 
static void functionDestroy (sqlite3 *db, FuncDef *p)
 
static void disconnectAllVtab (sqlite3 *db)
 
static int connectionIsBusy (sqlite3 *db)
 
static int sqlite3Close (sqlite3 *db, int forceZombie)
 
static int sqliteDefaultBusyCallback (void *ptr, int count)
 
static int createFunctionApi (sqlite3 *db, const char *zFunc, int nArg, int enc, void *p, void(*xSFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *), void(*xValue)(sqlite3_context *), void(*xInverse)(sqlite3_context *, int, sqlite3_value **), void(*xDestroy)(void *))
 
static void sqlite3InvalidFunction (sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
 
static int createCollation (sqlite3 *db, const char *zName, u8 enc, void *pCtx, int(*xCompare)(void *, int, const void *, int, const void *), void(*xDel)(void *))
 
static const char * uriParameter (const char *zFilename, const char *zParam)
 
static int openDatabase (const char *zFilename, sqlite3 **ppDb, unsigned int flags, const char *zVfs)
 
static const char * databaseName (const char *zName)
 
static char * appendText (char *p, const char *z)
 

Variables

static const char *const sqlite3azCompileOpt []
 
SQLITE_API const char sqlite3_version [] = SQLITE_VERSION
 
SQLITE_API char * sqlite3_temp_directory = 0
 
SQLITE_API char * sqlite3_data_directory = 0
 
const int sqlite3one = 1
 
SQLITE_PRIVATE void(*)(void) sqlite3OsDlSym (sqlite3_vfs *, void *, const char *)
 
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower []
 
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap [256]
 
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config
 
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions
 
SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000
 
SQLITE_API u32 sqlite3_unsupported_selecttrace = 0
 
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty [] = OPFLG_INITIALIZER
 
SQLITE_PRIVATE const char sqlite3StrBINARY [] = "BINARY"
 
static SQLITE_WSD struct sqlite3StatType sqlite3Stat = { {0,}, {0,} }
 
static const char statMutex []
 
struct { 
 
   u8   eType 
 
   u8   nName 
 
   char *   zName 
 
   double   rLimit 
 
   double   rXform 
 
aXformType [] 
 
static sqlite3_vfs *SQLITE_WSD vfsList = 0
 
static SQLITE_WSD struct BenignMallocHooks sqlite3Hooks = { 0, 0 }
 
static SQLITE_WSD struct Mem0Global mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 }
 
static const char aDigits [] = "0123456789ABCDEF0123456789abcdef"
 
static const char aPrefix [] = "-x0\000X0"
 
static const et_info fmtinfo []
 
static const double arRound []
 
static sqlite3_str sqlite3OomStr
 
static SQLITE_WSD struct sqlite3PrngType sqlite3Prng
 
static SQLITE_WSD struct sqlite3PrngType sqlite3SavedPrng
 
static const unsigned char sqlite3Utf8Trans1 []
 
static pid_t randomnessPid = 0
 
static struct unix_syscall aSyscall []
 
static sqlite3_mutexunixBigLock = 0
 
static unixInodeInfoinodeList = 0
 
static void(*)(void) unixDlSym (sqlite3_vfs *NotUsed, void *p, const char *zSym)
 
static SQLITE_WSD struct PCacheGlobal pcache1_g
 
static const unsigned char aJournalMagic []
 
static const char zMagicHeader [] = SQLITE_FILE_HEADER
 
static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0
 
static const u8 sqlite3SmallTypeSizes []
 
static const struct sqlite3_io_methods MemJournalMethods
 
static const FuncDef statInitFuncdef
 
static const FuncDef statPushFuncdef
 
static const FuncDef statGetFuncdef
 
static const struct compareInfo globInfo = { '*', '?', '[', 0 }
 
static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 }
 
static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }
 
static const char hexdigits []
 
static const sqlite3_api_routines sqlite3Apis
 
static SQLITE_WSD struct sqlite3AutoExtList sqlite3Autoext = { 0, 0 }
 
static const char *const pragCName []
 
static const PragmaName aPragmaName []
 
static const sqlite3_module pragmaVtabModule
 
static const char row_numberName [] = "row_number"
 
static const char dense_rankName [] = "dense_rank"
 
static const char rankName [] = "rank"
 
static const char percent_rankName [] = "percent_rank"
 
static const char cume_distName [] = "cume_dist"
 
static const char ntileName [] = "ntile"
 
static const char last_valueName [] = "last_value"
 
static const char nth_valueName [] = "nth_value"
 
static const char first_valueName [] = "first_value"
 
static const char leadName [] = "lead"
 
static const char lagName [] = "lag"
 
static const YYACTIONTYPE yy_action []
 
static const YYCODETYPE yy_lookahead []
 
static const unsigned short int yy_shift_ofst []
 
static const short yy_reduce_ofst []
 
static const YYACTIONTYPE yy_default []
 
static const YYCODETYPE yyFallback []
 
static const YYCODETYPE yyRuleInfoLhs []
 
static const signed char yyRuleInfoNRhs []
 
static const unsigned char aiClass []
 
static const char zKWText [647]
 
static const unsigned char aKWHash [127]
 
static const unsigned char aKWNext [145]
 
static const unsigned char aKWLen [145]
 
static const unsigned short int aKWOffset [145]
 
static const unsigned char aKWCode [145]
 
static int(*const sqlite3BuiltinExtensions [])(sqlite3 *)
 
static const int aHardLimit []
 

Macro Definition Documentation

◆ __has_extension

#define __has_extension ( x)    0 /* compatibility with non-clang compilers */

Definition at line 13470 of file sqlite3.c.

◆ _FILE_OFFSET_BITS

#define _FILE_OFFSET_BITS   64

Definition at line 964 of file sqlite3.c.

◆ _FTS5_H

#define _FTS5_H

Definition at line 12668 of file sqlite3.c.

◆ _FTSINT_H

#define _FTSINT_H

Definition at line 166240 of file sqlite3.c.

◆ _LARGE_FILE

#define _LARGE_FILE   1

Definition at line 962 of file sqlite3.c.

◆ _LARGEFILE_SOURCE

#define _LARGEFILE_SOURCE   1

Definition at line 966 of file sqlite3.c.

◆ _OS_COMMON_H_

#define _OS_COMMON_H_

Definition at line 33665 of file sqlite3.c.

◆ _SQLITE3RTREE_H_

#define _SQLITE3RTREE_H_

Definition at line 10880 of file sqlite3.c.

◆ _SQLITE_OS_H_

#define _SQLITE_OS_H_

Definition at line 16234 of file sqlite3.c.

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   600

Definition at line 13640 of file sqlite3.c.

◆ ADDR

#define ADDR ( X)    (~(X))

Definition at line 15556 of file sqlite3.c.

Referenced by resolveP2Values().

◆ ALLBITS

#define ALLBITS   ((Bitmask)-1)

Definition at line 14734 of file sqlite3.c.

Referenced by sqlite3Update(), sqlite3WhereBegin(), and whereLoopAddVirtual().

◆ ALT_SCHEMA_TABLE

#define ALT_SCHEMA_TABLE   "sqlite_schema"

Definition at line 14575 of file sqlite3.c.

Referenced by sqlite3FindTable().

◆ ALT_TEMP_SCHEMA_TABLE

#define ALT_TEMP_SCHEMA_TABLE   "sqlite_temp_schema"

Definition at line 14576 of file sqlite3.c.

Referenced by sqlite3FindTable().

◆ ALWAYS

◆ analyzeVdbeCommentIndexWithColumnName

#define analyzeVdbeCommentIndexWithColumnName ( a,
b,
c )

Definition at line 108518 of file sqlite3.c.

Referenced by analyzeOneTable().

◆ ApplyCostMultiplier

#define ApplyCostMultiplier ( C,
T )

Definition at line 148005 of file sqlite3.c.

Referenced by whereLoopAddBtree(), and whereLoopAddBtreeIndex().

◆ ArraySize

◆ assertCellInfo

#define assertCellInfo ( x)

Definition at line 69021 of file sqlite3.c.

◆ assertParentIndex

#define assertParentIndex ( x,
y,
z )

Definition at line 69609 of file sqlite3.c.

Referenced by moveToParent().

◆ assertTruncateConstraint

#define assertTruncateConstraint ( pPager)

Definition at line 55613 of file sqlite3.c.

◆ AtomicLoad

◆ AtomicStore

#define AtomicStore ( PTR,
VAL )   (*(PTR) = (VAL))

◆ bBatch

#define bBatch   0

◆ BITVEC_HASH

#define BITVEC_HASH ( X)    (((X)*1)%BITVEC_NINT)

Definition at line 48527 of file sqlite3.c.

Referenced by sqlite3BitvecClear(), sqlite3BitvecSet(), and sqlite3BitvecTestNotNull().

◆ BITVEC_MXHASH

#define BITVEC_MXHASH   (BITVEC_NINT/2)

Definition at line 48522 of file sqlite3.c.

Referenced by sqlite3BitvecSet().

◆ BITVEC_NBIT

#define BITVEC_NBIT   (BITVEC_NELEM*BITVEC_SZELEM)

Definition at line 48516 of file sqlite3.c.

Referenced by sqlite3BitvecClear(), sqlite3BitvecSet(), and sqlite3BitvecTestNotNull().

◆ BITVEC_NELEM

#define BITVEC_NELEM   (BITVEC_USIZE/sizeof(BITVEC_TELEM))

Definition at line 48514 of file sqlite3.c.

◆ BITVEC_NINT

#define BITVEC_NINT   (BITVEC_USIZE/sizeof(u32))

Definition at line 48519 of file sqlite3.c.

Referenced by sqlite3BitvecClear(), and sqlite3BitvecSet().

◆ BITVEC_NPTR

#define BITVEC_NPTR   (BITVEC_USIZE/sizeof(Bitvec *))

Definition at line 48529 of file sqlite3.c.

Referenced by sqlite3BitvecSet().

◆ BITVEC_SZ

#define BITVEC_SZ   512

Definition at line 48499 of file sqlite3.c.

Referenced by sqlite3BitvecBuiltinTest(), and sqlite3BitvecCreate().

◆ BITVEC_SZELEM

#define BITVEC_SZELEM   8

Definition at line 48512 of file sqlite3.c.

Referenced by sqlite3BitvecClear(), sqlite3BitvecSet(), and sqlite3BitvecTestNotNull().

◆ BITVEC_TELEM

#define BITVEC_TELEM   u8

Definition at line 48510 of file sqlite3.c.

◆ BITVEC_USIZE

#define BITVEC_USIZE    (((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*))

Definition at line 48503 of file sqlite3.c.

48503
48504/* Size of the Bitvec structure in bytes. */

◆ BMS

#define BMS   ((int)(sizeof(Bitmask)*8))

◆ BTALLOC_ANY

#define BTALLOC_ANY   0 /* Allocate any page */

Definition at line 64526 of file sqlite3.c.

Referenced by allocateBtreePage(), and incrVacuumStep().

◆ BTALLOC_EXACT

#define BTALLOC_EXACT   1 /* Allocate exact page if possible */

Definition at line 64527 of file sqlite3.c.

Referenced by allocateBtreePage(), btreeCreateTable(), and incrVacuumStep().

◆ BTALLOC_LE

#define BTALLOC_LE   2 /* Allocate any page <= the parameter */

Definition at line 64528 of file sqlite3.c.

Referenced by allocateBtreePage(), and incrVacuumStep().

◆ BTCF_AtLast

#define BTCF_AtLast   0x08 /* Cursor is pointing ot the last entry */

◆ BTCF_Incrblob

#define BTCF_Incrblob   0x10 /* True if an incremental I/O handle */

Definition at line 64010 of file sqlite3.c.

Referenced by invalidateIncrblobCursors(), and sqlite3BtreePutData().

◆ BTCF_Multiple

#define BTCF_Multiple   0x20 /* Maybe another cursor on the same btree */

Definition at line 64011 of file sqlite3.c.

Referenced by btreeCursor(), sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ BTCF_Pinned

#define BTCF_Pinned   0x40 /* Cursor is busy and cannot be moved */

Definition at line 64012 of file sqlite3.c.

Referenced by saveCursorPosition(), and sqlite3BtreeCursorUnpin().

◆ BTCF_ValidNKey

#define BTCF_ValidNKey   0x02 /* True if info.nKey is valid */

◆ BTCF_ValidOvfl

#define BTCF_ValidOvfl   0x04 /* True if aOverflow is valid */

◆ BTCF_WriteFlag

#define BTCF_WriteFlag   0x01 /* True if a write cursor */

◆ BTCURSOR_FIRST_UNINIT

#define BTCURSOR_FIRST_UNINIT   pBt /* Name of first uninitialized field */

Definition at line 63988 of file sqlite3.c.

Referenced by sqlite3BtreeCursorZero().

◆ BTCURSOR_MAX_DEPTH

#define BTCURSOR_MAX_DEPTH   20

Definition at line 63947 of file sqlite3.c.

Referenced by moveToChild().

◆ BTREE_APPEND

#define BTREE_APPEND   0x08 /* Insert is likely an append */

Definition at line 15253 of file sqlite3.c.

Referenced by sqlite3BtreeInsert().

◆ BTREE_APPLICATION_ID

#define BTREE_APPLICATION_ID   8

Definition at line 15149 of file sqlite3.c.

◆ BTREE_AUTOVACUUM_FULL

#define BTREE_AUTOVACUUM_FULL   1 /* Do full auto-vacuum */

Definition at line 15030 of file sqlite3.c.

Referenced by getAutoVacuum().

◆ BTREE_AUTOVACUUM_INCR

#define BTREE_AUTOVACUUM_INCR   2 /* Incremental vacuum */

Definition at line 15031 of file sqlite3.c.

Referenced by getAutoVacuum().

◆ BTREE_AUTOVACUUM_NONE

#define BTREE_AUTOVACUUM_NONE   0 /* Do not do auto-vacuum */

Definition at line 15029 of file sqlite3.c.

Referenced by getAutoVacuum().

◆ BTREE_AUXDELETE

#define BTREE_AUXDELETE   0x04 /* not the primary delete operation */

Definition at line 15252 of file sqlite3.c.

Referenced by sqlite3BtreeDelete(), and sqlite3VdbeExec().

◆ BTREE_BLOBKEY

#define BTREE_BLOBKEY   2 /* Table has keys only - no data */

Definition at line 15112 of file sqlite3.c.

Referenced by convertToWithoutRowidTable(), sqlite3CreateIndex(), and sqlite3VdbeExec().

◆ BTREE_BULKLOAD

#define BTREE_BULKLOAD   0x00000001 /* Used to full index in sorted order */

Definition at line 15194 of file sqlite3.c.

Referenced by balance(), and sqlite3VdbeExec().

◆ BTREE_DATA_VERSION

#define BTREE_DATA_VERSION   15 /* A virtual meta-value */

Definition at line 15150 of file sqlite3.c.

Referenced by sqlite3BtreeGetMeta().

◆ BTREE_DEFAULT_CACHE_SIZE

#define BTREE_DEFAULT_CACHE_SIZE   3

Definition at line 15144 of file sqlite3.c.

Referenced by sqlite3InitOne(), and sqlite3Pragma().

◆ BTREE_FILE_FORMAT

#define BTREE_FILE_FORMAT   2

◆ BTREE_FORDELETE

#define BTREE_FORDELETE   0x00000008 /* Cursor is for seek/delete only */

Definition at line 15221 of file sqlite3.c.

Referenced by btreeCursor(), and sqlite3VdbeExec().

◆ BTREE_FREE_PAGE_COUNT

#define BTREE_FREE_PAGE_COUNT   0

Definition at line 15141 of file sqlite3.c.

◆ BTREE_HINT_RANGE

#define BTREE_HINT_RANGE   0 /* Range constraints on queries */

Definition at line 15179 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ BTREE_INCR_VACUUM

#define BTREE_INCR_VACUUM   7

Definition at line 15148 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ BTREE_INTKEY

#define BTREE_INTKEY   1 /* Table has only 64-bit signed integer keys */

Definition at line 15111 of file sqlite3.c.

Referenced by btreeCreateTable(), sqlite3StartTable(), and sqlite3VdbeExec().

◆ BTREE_LARGEST_ROOT_PAGE

#define BTREE_LARGEST_ROOT_PAGE   4

Definition at line 15145 of file sqlite3.c.

Referenced by btreeCreateTable(), btreeDropTable(), sqlite3BtreeGetMeta(), and sqlite3Pragma().

◆ BTREE_MEMORY

#define BTREE_MEMORY   2 /* This is an in-memory DB */

Definition at line 15058 of file sqlite3.c.

Referenced by sqlite3BtreeOpen().

◆ BTREE_OMIT_JOURNAL

#define BTREE_OMIT_JOURNAL   1 /* Do not create or use a rollback journal */

Definition at line 15057 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ BTREE_SAVEPOSITION

#define BTREE_SAVEPOSITION   0x02 /* Leave cursor pointing at NEXT or PREV */

Definition at line 15251 of file sqlite3.c.

Referenced by sqlite3BtreeDelete(), sqlite3BtreeInsert(), and sqlite3VdbeExec().

◆ BTREE_SCHEMA_VERSION

#define BTREE_SCHEMA_VERSION   1

Definition at line 15142 of file sqlite3.c.

Referenced by schemaIsValid(), sqlite3ChangeCookie(), sqlite3InitOne(), and sqlite3VdbeExec().

◆ BTREE_SEEK_EQ

#define BTREE_SEEK_EQ   0x00000002 /* EQ seeks only - no range seeks */

Definition at line 15195 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ BTREE_SINGLE

#define BTREE_SINGLE   4 /* The file contains at most 1 b-tree */

Definition at line 15059 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), and sqlite3VdbeExec().

◆ BTREE_TEXT_ENCODING

#define BTREE_TEXT_ENCODING   5

Definition at line 15146 of file sqlite3.c.

Referenced by sqlite3InitOne(), and sqlite3StartTable().

◆ BTREE_UNORDERED

#define BTREE_UNORDERED   8 /* Use of a hash implementation is OK */

Definition at line 15060 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), sqlite3Select(), and sqlite3VdbeExec().

◆ BTREE_USER_VERSION

#define BTREE_USER_VERSION   6

Definition at line 15147 of file sqlite3.c.

◆ BTREE_WRCSR

#define BTREE_WRCSR   0x00000004 /* read-write cursor */

Definition at line 15220 of file sqlite3.c.

Referenced by btreeCursor(), and sqlite3VdbeExec().

◆ btreeIntegrity

#define btreeIntegrity ( p)
Value:
assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
assert( p->pBt->inTransaction>=p->inTrans );
#define TRANS_NONE
Definition sqlite3.c:63837

Definition at line 64114 of file sqlite3.c.

64114#define PTRMAP_OVERFLOW2 4
64115#define PTRMAP_BTREE 5
64116

Referenced by sqlite3BtreeBeginTrans(), sqlite3BtreeCommitPhaseTwo(), and sqlite3BtreeRollback().

◆ BTS_EXCLUSIVE

#define BTS_EXCLUSIVE   0x0040 /* pWriter has an exclusive lock */

◆ BTS_FAST_SECURE

#define BTS_FAST_SECURE   0x000c /* Combination of the previous two */

Definition at line 63919 of file sqlite3.c.

Referenced by balance_nonroot(), freeSpace(), and sqlite3BtreeSecureDelete().

◆ BTS_INITIALLY_EMPTY

#define BTS_INITIALLY_EMPTY   0x0010 /* Database was empty at trans start */

Definition at line 63920 of file sqlite3.c.

Referenced by sqlite3BtreeBeginTrans(), and sqlite3BtreeSavepoint().

◆ BTS_NO_WAL

#define BTS_NO_WAL   0x0020 /* Do not open write-ahead-log files */

Definition at line 63921 of file sqlite3.c.

Referenced by lockBtree(), and sqlite3BtreeSetVersion().

◆ BTS_OVERWRITE

#define BTS_OVERWRITE   0x0008 /* Overwrite deleted content with zeros */

Definition at line 63918 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), and sqlite3BtreeSecureDelete().

◆ BTS_PAGESIZE_FIXED

#define BTS_PAGESIZE_FIXED   0x0002 /* Page size can no longer be changed */

◆ BTS_PENDING

#define BTS_PENDING   0x0080 /* Waiting for read-locks to clear */

◆ BTS_READ_ONLY

◆ BTS_SECURE_DELETE

#define BTS_SECURE_DELETE   0x0004 /* PRAGMA secure_delete is enabled */

Definition at line 63917 of file sqlite3.c.

Referenced by freePage2(), sqlite3BtreeOpen(), and sqlite3BtreeSecureDelete().

◆ BYTESWAP32

#define BYTESWAP32 ( x)
Value:
( \
(((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
+ (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
)

Definition at line 60038 of file sqlite3.c.

60038** The argument to this macro must be of type u32. On a little-endian
60039** architecture, it returns the u32 value that results from interpreting
60040** the 4 bytes as a big-endian value. On a big-endian architecture, it
60041** returns the value that would be produced by interpreting the 4 bytes
int value
Definition lsqlite3.c:2155
char endian
Definition lua_struct.c:81
UINT32_TYPE u32
Definition sqlite3.c:14331

Referenced by walChecksumBytes().

◆ CACHE_STALE

#define CACHE_STALE   0

Definition at line 20842 of file sqlite3.c.

Referenced by handleMovedCursor(), sqlite3VdbeExec(), and sqlite3VdbeFinishMoveto().

◆ CC_AND

#define CC_AND   24 /* '&' */

Definition at line 159309 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_BANG

#define CC_BANG   15 /* '!'. Part of != */

Definition at line 159300 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_COMMA

#define CC_COMMA   23 /* ',' */

Definition at line 159308 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_DIGIT

#define CC_DIGIT   3 /* Digits */

Definition at line 159288 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_DOLLAR

#define CC_DOLLAR   4 /* '$' */

Definition at line 159289 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_DOT

#define CC_DOT   26 /* '.' */

Definition at line 159311 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_EQ

#define CC_EQ   14 /* '='. Part of = or == */

Definition at line 159299 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_GT

#define CC_GT   13 /* '>'. Part of > or >= */

Definition at line 159298 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_ID

#define CC_ID   2 /* unicode characters usable in IDs */

Definition at line 159287 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_ILLEGAL

#define CC_ILLEGAL   27 /* Illegal character */

Definition at line 159312 of file sqlite3.c.

◆ CC_KYWD

#define CC_KYWD   1 /* Alphabetics or '_'. Usable in a keyword */

Definition at line 159286 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_LP

#define CC_LP   17 /* '(' */

Definition at line 159302 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_LT

#define CC_LT   12 /* '<'. Part of < or <= or <> */

Definition at line 159297 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_MINUS

#define CC_MINUS   11 /* '-'. Minus or SQL-style comment */

Definition at line 159296 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_NUL

#define CC_NUL   28 /* 0x00 */

Definition at line 159313 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_PERCENT

#define CC_PERCENT   22 /* '%' */

Definition at line 159307 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_PIPE

#define CC_PIPE   10 /* '|'. Bitwise OR or concatenate */

Definition at line 159295 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_PLUS

#define CC_PLUS   20 /* '+' */

Definition at line 159305 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_QUOTE

#define CC_QUOTE   8 /* '"', '\'', or '`'. String literals, quoted ids */

Definition at line 159293 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_QUOTE2

#define CC_QUOTE2   9 /* '['. [...] style quoted ids */

Definition at line 159294 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_RP

#define CC_RP   18 /* ')' */

Definition at line 159303 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_SEMI

#define CC_SEMI   19 /* ';' */

Definition at line 159304 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_SLASH

#define CC_SLASH   16 /* '/'. / or c-style comment */

Definition at line 159301 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_SPACE

#define CC_SPACE   7 /* Space characters */

Definition at line 159292 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_STAR

#define CC_STAR   21 /* '*' */

Definition at line 159306 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_TILDA

#define CC_TILDA   25 /* '~' */

Definition at line 159310 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_VARALPHA

#define CC_VARALPHA   5 /* '@', '#', ':'. Alphabetic SQL variables */

Definition at line 159290 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_VARNUM

#define CC_VARNUM   6 /* '?'. Numeric SQL variables */

Definition at line 159291 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ CC_X

#define CC_X   0 /* The letter 'x', or start of BLOB literal */

Definition at line 159285 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ charMap

#define charMap ( X)    sqlite3UpperToLower[(unsigned char)X]

Definition at line 159366 of file sqlite3.c.

Referenced by keywordCode().

◆ CHECK_PAGE

#define CHECK_PAGE ( x)

Definition at line 52969 of file sqlite3.c.

Referenced by pager_write().

◆ checkActiveVdbeCnt

#define checkActiveVdbeCnt ( x)

Definition at line 80650 of file sqlite3.c.

Referenced by sqlite3VdbeHalt().

◆ checkProfileCallback

#define checkProfileCallback ( DB,
P )    if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }

Definition at line 83065 of file sqlite3.c.

83065 p->startTime = 0;
83066}

Referenced by sqlite3_finalize(), sqlite3_reset(), and sqlite3Step().

◆ CKCNSTRNT_COLUMN

#define CKCNSTRNT_COLUMN   0x01 /* CHECK constraint uses a changing column */

Definition at line 121889 of file sqlite3.c.

Referenced by checkConstraintExprNode(), and sqlite3ExprReferencesUpdatedColumn().

◆ CKCNSTRNT_ROWID

#define CKCNSTRNT_ROWID   0x02 /* CHECK constraint references the ROWID */

Definition at line 121890 of file sqlite3.c.

Referenced by checkConstraintExprNode(), and sqlite3ExprReferencesUpdatedColumn().

◆ CKPT_SYNC_FLAGS

#define CKPT_SYNC_FLAGS ( X)    (((X)>>2)&0x03)

Definition at line 51593 of file sqlite3.c.

Referenced by walCheckpoint().

◆ CLEARBIT

#define CLEARBIT ( V,
I )   V[I>>3] &= ~(1<<(I&7))

Definition at line 48763 of file sqlite3.c.

Referenced by sqlite3BitvecBuiltinTest().

◆ codeCursorHint

#define codeCursorHint ( A,
B,
C,
D )   /* No-op */

Definition at line 142531 of file sqlite3.c.

◆ COLFLAG_BUSY

#define COLFLAG_BUSY   0x0100 /* Blocks recursion on GENERATED columns */

Definition at line 17352 of file sqlite3.c.

Referenced by sqlite3ComputeGeneratedColumns(), and sqlite3ExprCodeTarget().

◆ COLFLAG_GENERATED

◆ COLFLAG_HASTYPE

#define COLFLAG_HASTYPE   0x0004 /* Type name follows column name */

◆ COLFLAG_HIDDEN

#define COLFLAG_HIDDEN   0x0002 /* A hidden column in a virtual table */

◆ COLFLAG_NOINSERT

#define COLFLAG_NOINSERT   0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */

Definition at line 17354 of file sqlite3.c.

Referenced by sqlite3Insert(), and sqlite3Pragma().

◆ COLFLAG_NOTAVAIL

#define COLFLAG_NOTAVAIL   0x0080 /* STORED column not yet calculated */

Definition at line 17351 of file sqlite3.c.

Referenced by sqlite3ComputeGeneratedColumns(), and sqlite3ExprCodeTarget().

◆ COLFLAG_PRIMKEY

#define COLFLAG_PRIMKEY   0x0001 /* Column is part of the primary key */

◆ COLFLAG_SORTERREF

#define COLFLAG_SORTERREF   0x0010 /* Use sorter-refs with this column */

Definition at line 17348 of file sqlite3.c.

Referenced by sqlite3AddColumn(), and sqlite3AffinityType().

◆ COLFLAG_STORED

◆ COLFLAG_UNIQUE

#define COLFLAG_UNIQUE   0x0008 /* Column def contains "UNIQUE" or "PK" */

Definition at line 17347 of file sqlite3.c.

Referenced by sqlite3AddNotNull(), and sqlite3CreateIndex().

◆ COLFLAG_VIRTUAL

◆ COLNAME_COLUMN

#define COLNAME_COLUMN   4

Definition at line 15540 of file sqlite3.c.

◆ COLNAME_DATABASE

#define COLNAME_DATABASE   2

Definition at line 15538 of file sqlite3.c.

◆ COLNAME_DECLTYPE

#define COLNAME_DECLTYPE   1

Definition at line 15537 of file sqlite3.c.

Referenced by sqlite3_column_decltype16().

◆ COLNAME_N

#define COLNAME_N   2 /* Store the name and decltype */

◆ COLNAME_NAME

◆ COLNAME_TABLE

#define COLNAME_TABLE   3

Definition at line 15539 of file sqlite3.c.

◆ COLUMN_MASK

#define COLUMN_MASK ( x)    (((x)>31) ? 0xffffffff : ((u32)1<<(x)))

Definition at line 120162 of file sqlite3.c.

Referenced by sqlite3FkOldmask().

◆ columnType

#define columnType ( A,
B,
C,
D,
E )   columnTypeImpl(A,B)

Definition at line 130950 of file sqlite3.c.

Referenced by columnTypeImpl(), and sqlite3SelectAddColumnTypeAndCollation().

◆ ConstFactorOk

#define ConstFactorOk ( P)    ((P)->okConstFactor)

◆ CORRUPT_DB

◆ CTIMEOPT_VAL

#define CTIMEOPT_VAL ( opt)    CTIMEOPT_VAL_(opt)

Definition at line 56 of file sqlite3.c.

◆ CTIMEOPT_VAL2

#define CTIMEOPT_VAL2 ( opt)    CTIMEOPT_VAL2_(opt)

Definition at line 62 of file sqlite3.c.

◆ CTIMEOPT_VAL2_

#define CTIMEOPT_VAL2_ ( opt1,
opt2 )   #opt1 "," #opt2

Definition at line 61 of file sqlite3.c.

◆ CTIMEOPT_VAL_

#define CTIMEOPT_VAL_ ( opt)    #opt

Definition at line 55 of file sqlite3.c.

◆ cume_distFinalizeFunc

#define cume_distFinalizeFunc   cume_distValueFunc

Definition at line 151564 of file sqlite3.c.

◆ CURSOR_FAULT

#define CURSOR_FAULT   4

◆ CURSOR_INVALID

◆ CURSOR_REQUIRESEEK

#define CURSOR_REQUIRESEEK   3

◆ CURSOR_SKIPNEXT

#define CURSOR_SKIPNEXT   2

◆ CURSOR_VALID

◆ CURTYPE_BTREE

◆ CURTYPE_PSEUDO

#define CURTYPE_PSEUDO   3

Definition at line 20767 of file sqlite3.c.

Referenced by sqlite3VdbeCursorMoveto(), and sqlite3VdbeExec().

◆ CURTYPE_SORTER

#define CURTYPE_SORTER   1

◆ CURTYPE_VTAB

#define CURTYPE_VTAB   2

Definition at line 20766 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ DB_ResetWanted

#define DB_ResetWanted   0x0008 /* Reset the schema when nSchemaLock==0 */

Definition at line 16665 of file sqlite3.c.

Referenced by sqlite3ResetOneSchema(), and sqlite3SchemaClear().

◆ DB_SchemaLoaded

#define DB_SchemaLoaded   0x0001 /* The schema has been loaded */

Definition at line 16663 of file sqlite3.c.

Referenced by sqlite3Init(), sqlite3InitOne(), sqlite3SchemaClear(), and sqlite3VdbeExec().

◆ DB_UnresetViews

#define DB_UnresetViews   0x0002 /* Some views have defined column names */

Definition at line 16664 of file sqlite3.c.

Referenced by sqlite3ViewGetColumnNames(), and sqliteViewResetAll().

◆ DbClearProperty

#define DbClearProperty ( D,
I,
P )   (D)->aDb[I].pSchema->schemaFlags&=~(P)

Definition at line 16651 of file sqlite3.c.

Referenced by sqliteViewResetAll().

◆ DBFLAG_EncodingFixed

#define DBFLAG_EncodingFixed   0x0040 /* No longer possible to change enc. */

Definition at line 17034 of file sqlite3.c.

Referenced by sqlite3InitCallback(), sqlite3InitOne(), and sqlite3Pragma().

◆ DBFLAG_InternalFunc

#define DBFLAG_InternalFunc   0x0020 /* Allow use of internal functions */

Definition at line 17033 of file sqlite3.c.

Referenced by openDatabase(), resolveExprStep(), and sqlite3Pragma().

◆ DBFLAG_PreferBuiltin

#define DBFLAG_PreferBuiltin   0x0002 /* Preference to built-in funcs */

Definition at line 17029 of file sqlite3.c.

Referenced by sqlite3AlterFinishAddColumn(), and sqlite3FindFunction().

◆ DBFLAG_SchemaChange

#define DBFLAG_SchemaChange   0x0001 /* Uncommitted Hash table changes */

◆ DBFLAG_SchemaKnownOk

#define DBFLAG_SchemaKnownOk   0x0010 /* Schema is known to be valid */

Definition at line 17032 of file sqlite3.c.

Referenced by attachFunc(), sqlite3InitOne(), and sqlite3LocateTable().

◆ DBFLAG_Vacuum

#define DBFLAG_Vacuum   0x0004 /* Currently in a VACUUM */

Definition at line 17030 of file sqlite3.c.

Referenced by autoIncBegin(), sqlite3TwoPartName(), and xferOptimization().

◆ DBFLAG_VacuumInto

#define DBFLAG_VacuumInto   0x0008 /* Currently running VACUUM INTO */

Definition at line 17031 of file sqlite3.c.

Referenced by xferOptimization().

◆ DbHasAnyProperty

#define DbHasAnyProperty ( D,
I,
P )   (((D)->aDb[I].pSchema->schemaFlags&(P))!=0)

Definition at line 16649 of file sqlite3.c.

◆ DbHasProperty

#define DbHasProperty ( D,
I,
P )   (((D)->aDb[I].pSchema->schemaFlags&(P))==(P))

◆ DbMaskAllZero

#define DbMaskAllZero ( M)    (M)==0

Definition at line 18659 of file sqlite3.c.

Referenced by codeDeferredSeek(), sqlite3VdbeEnter(), and sqlite3VdbeTakeOpArray().

◆ DbMaskNonZero

#define DbMaskNonZero ( M)    (M)!=0

Definition at line 18660 of file sqlite3.c.

Referenced by sqlite3FinishCoding().

◆ DbMaskSet

#define DbMaskSet ( M,
I )   (M)|=(((yDbMask)1)<<(I))

◆ DbMaskTest

#define DbMaskTest ( M,
I )   (((M)&(((yDbMask)1)<<(I)))!=0)

◆ DbMaskZero

#define DbMaskZero ( M)    (M)=0

Definition at line 18657 of file sqlite3.c.

◆ DbSetProperty

#define DbSetProperty ( D,
I,
P )   (D)->aDb[I].pSchema->schemaFlags|=(P)

Definition at line 16650 of file sqlite3.c.

Referenced by sqlite3InitOne(), and sqlite3ResetOneSchema().

◆ Deephemeralize

#define Deephemeralize ( P)
Value:
if( ((P)->flags&MEM_Ephem)!=0 \
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
#define MEM_Ephem
Definition sqlite3.c:20969
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *)
Definition sqlite3.c:76154

Definition at line 85461 of file sqlite3.c.

85461** knowing it.
85462**
85463** This routine converts an ephemeral string into a dynamically allocated

Referenced by sqlite3VdbeExec().

◆ deliberate_fall_through

◆ DFLT_SCHEMA_TABLE

◆ DFLT_TEMP_SCHEMA_TABLE

#define DFLT_TEMP_SCHEMA_TABLE   "sqlite_temp_master"

Definition at line 14574 of file sqlite3.c.

Referenced by sqlite3FindTable().

◆ DFUNCTION

#define DFUNCTION ( zName,
nArg,
iArg,
bNC,
xFunc )
Value:
0, 0, xFunc, 0, 0, 0, #zName, {0} }
#define SQLITE_FUNC_SLOCHNG
Definition sqlite3.c:17157
char * zName
Definition sqlite3.c:22329
#define SQLITE_UTF8
Definition sqlite3.c:6252

Definition at line 17255 of file sqlite3.c.

17257 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
#define SQLITE_FUNC_TEST
Definition sqlite3.c:17158
#define SQLITE_FUNC_CONSTANT
Definition sqlite3.c:17155
#define SQLITE_FUNC_INTERNAL
Definition sqlite3.c:17161
#define SQLITE_INT_TO_PTR(X)
Definition sqlite3.c:13513
#define SQLITE_FUNC_INLINE
Definition sqlite3.c:17165
#define noopFunc
Definition sqlite3.c:117547

Referenced by sqlite3RegisterBuiltinFunctions(), and sqlite3RegisterDateTimeFunctions().

◆ DIRECT_MODE

#define DIRECT_MODE   0

◆ DirSep

#define DirSep ( X)    ((X)=='/')

Definition at line 124720 of file sqlite3.c.

Referenced by sqlite3LoadExtension().

◆ disable_simulated_io_errors [1/2]

#define disable_simulated_io_errors ( )

Definition at line 14988 of file sqlite3.c.

Referenced by sqlite3PagerClose(), and vdbeCommit().

◆ disable_simulated_io_errors [2/2]

#define disable_simulated_io_errors ( )

Definition at line 14988 of file sqlite3.c.

◆ DisableLookaside

#define DisableLookaside   db->lookaside.bDisable++;db->lookaside.sz=0

◆ DO_OS_MALLOC_TEST

#define DO_OS_MALLOC_TEST ( x)

Definition at line 23034 of file sqlite3.c.

Referenced by sqlite3OsAccess(), sqlite3OsFullPathname(), and sqlite3OsOpen().

◆ DOTLOCK_SUFFIX

#define DOTLOCK_SUFFIX   ".lock"

Definition at line 35764 of file sqlite3.c.

◆ EIGHT_BYTE_ALIGNMENT

◆ enable_simulated_io_errors [1/2]

#define enable_simulated_io_errors ( )

Definition at line 14989 of file sqlite3.c.

Referenced by sqlite3PagerClose(), and vdbeCommit().

◆ enable_simulated_io_errors [2/2]

#define enable_simulated_io_errors ( )

Definition at line 14989 of file sqlite3.c.

◆ EnableLookaside

#define EnableLookaside
Value:
db->lookaside.bDisable--;\
db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue

Definition at line 16741 of file sqlite3.c.

16741#define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
16742#define EnableLookaside db->lookaside.bDisable--;\

Referenced by fkActionTrigger(), sqlite3AnalysisLoad(), sqlite3OomClear(), and sqlite3ViewGetColumnNames().

◆ ENAME_NAME

#define ENAME_NAME   0 /* The AS clause of a result set */

◆ ENAME_SPAN

#define ENAME_SPAN   1 /* Complete text of the result set expression */

Definition at line 18204 of file sqlite3.c.

Referenced by sqlite3ExprListSetSpan().

◆ ENAME_TAB

#define ENAME_TAB   2 /* "DB.TABLE.NAME" for the result set */

Definition at line 18205 of file sqlite3.c.

Referenced by selectExpander(), and sqlite3MatchEName().

◆ ENC

◆ EP_Agg

#define EP_Agg   0x000010 /* Contains one or more aggregate functions */

Definition at line 18064 of file sqlite3.c.

Referenced by lookupName(), sqlite3ResolveExprListNames(), and sqlite3ResolveExprNames().

◆ EP_Alias

#define EP_Alias   0x400000 /* Is an alias for a result set column */

Definition at line 18082 of file sqlite3.c.

Referenced by lookupName(), and resolveAlias().

◆ EP_CanBeNull

#define EP_CanBeNull   0x100000 /* Can be null despite NOT NULL constraint */

Definition at line 18080 of file sqlite3.c.

Referenced by lookupName(), sqlite3ExprCanBeNull(), and substExpr().

◆ EP_Collate

#define EP_Collate   0x000100 /* Tree contains a TK_COLLATE operator */

◆ EP_Commuted

#define EP_Commuted   0x000200 /* Comparison operator has been commuted */

◆ EP_ConstFunc

#define EP_ConstFunc   0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */

Definition at line 18079 of file sqlite3.c.

Referenced by exprNodeIsConstant(), and resolveExprStep().

◆ EP_DblQuoted

#define EP_DblQuoted   0x000040 /* token.z was originally in "..." */

Definition at line 18066 of file sqlite3.c.

Referenced by lookupName().

◆ EP_Distinct

#define EP_Distinct   0x000002 /* Aggregate function with DISTINCT keyword */

Definition at line 18061 of file sqlite3.c.

Referenced by analyzeAggregate(), isSimpleCount(), and sqlite3ExprCompare().

◆ EP_FixedCol

#define EP_FixedCol   0x000008 /* TK_Column with a known fixed value */

◆ EP_FromDDL

#define EP_FromDDL   0x40000000 /* Originates from sqlite_schema */

Definition at line 18090 of file sqlite3.c.

Referenced by exprNodeIsConstant(), resolveExprStep(), and sqlite3ExprFunctionUsable().

◆ EP_FromJoin

◆ EP_HasFunc

#define EP_HasFunc   0x000004 /* Contains one or more functions of any kind */

Definition at line 18062 of file sqlite3.c.

Referenced by selectExpander(), and sqlite3ExprCodeRunJustOnce().

◆ EP_Immutable

#define EP_Immutable   0x02 /* Do not change this Expr node */

◆ EP_InfixFunc

#define EP_InfixFunc   0x000080 /* True for an infix function: LIKE, GLOB, etc */

Definition at line 18067 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and yy_reduce().

◆ EP_IntValue

◆ EP_IsFalse

#define EP_IsFalse   0x20000000 /* Always has boolean value of FALSE */

Definition at line 18089 of file sqlite3.c.

Referenced by sqlite3ExprAlloc(), and sqlite3IsTrueOrFalse().

◆ EP_IsTrue

#define EP_IsTrue   0x10000000 /* Always has boolean value of TRUE */

Definition at line 18088 of file sqlite3.c.

Referenced by sqlite3ExprAlloc(), and sqlite3IsTrueOrFalse().

◆ EP_Leaf

#define EP_Leaf   0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */

◆ EP_MemToken

#define EP_MemToken   0x010000 /* Need to sqlite3DbFree() Expr.zToken */

Definition at line 18076 of file sqlite3.c.

Referenced by dupedExprStructSize(), exprDup(), and resolveAlias().

◆ EP_NoReduce

#define EP_NoReduce   0x01 /* Cannot EXPRDUP_REDUCE this Expr */

◆ EP_Propagate

#define EP_Propagate   (EP_Collate|EP_Subquery|EP_HasFunc)

Definition at line 18097 of file sqlite3.c.

Referenced by exprSetHeight(), sqlite3ExprAttachSubtrees(), and yy_reduce().

◆ EP_Quoted

#define EP_Quoted   0x4000000 /* TK_ID was originally quoted */

Definition at line 18086 of file sqlite3.c.

Referenced by sqlite3ExprIdToTrueFalse().

◆ EP_Reduced

◆ EP_Skip

#define EP_Skip   0x001000 /* Operator does not contribute to affinity */

◆ EP_Static

#define EP_Static   0x8000000 /* Held in memory not obtained from malloc() */

Definition at line 18087 of file sqlite3.c.

Referenced by exprDup(), resolveAlias(), and selectWindowRewriteExprCb().

◆ EP_Subquery

#define EP_Subquery   0x200000 /* Tree contains a TK_SELECT operator */

Definition at line 18081 of file sqlite3.c.

Referenced by selectExpander(), sqlite3ExprCode(), and substExpr().

◆ EP_Subrtn

#define EP_Subrtn   0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */

Definition at line 18085 of file sqlite3.c.

Referenced by sqlite3CodeRhsOfIN(), and sqlite3CodeSubselect().

◆ EP_TokenOnly

◆ EP_Unlikely

#define EP_Unlikely   0x040000 /* unlikely() or likelihood() function */

◆ EP_VarSelect

#define EP_VarSelect   0x000020 /* pSelect is correlated, not constant */

◆ EP_Win

#define EP_Win   0x008000 /* Contains window functions */

Definition at line 18075 of file sqlite3.c.

Referenced by lookupName(), sqlite3ResolveExprListNames(), and sqlite3ResolveExprNames().

◆ EP_WinFunc

◆ EP_xIsSelect

◆ etBUFSIZE

#define etBUFSIZE   SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */

Definition at line 28329 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etCHARX

#define etCHARX   8 /* Characters. %c */

Definition at line 28161 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etDECIMAL

#define etDECIMAL   16 /* %d or %u, but not %x, %o */

Definition at line 28170 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etDYNSTRING

#define etDYNSTRING   6 /* Dynamically allocated strings. %z */

Definition at line 28159 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etEXP

#define etEXP   2 /* Exponentional notation. %e and %E */

Definition at line 28155 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etFLOAT

#define etFLOAT   1 /* Floating point. %f */

Definition at line 28154 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etGENERIC

#define etGENERIC   3 /* Floating or exponential, depending on exponent. %g */

Definition at line 28156 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etINVALID

#define etINVALID   17 /* Any unrecognized conversion type */

Definition at line 28172 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etORDINAL

#define etORDINAL   15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */

Definition at line 28169 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etPERCENT

#define etPERCENT   7 /* Percent symbol. %% */

Definition at line 28160 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etPOINTER

#define etPOINTER   13 /* The %p conversion */

Definition at line 28167 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etRADIX

#define etRADIX   0 /* non-decimal integer types. %x %o */

Definition at line 28153 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etSIZE

#define etSIZE   4 /* Return number of characters processed so far. %n */

Definition at line 28157 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etSQLESCAPE

#define etSQLESCAPE   9 /* Strings with '\'' doubled. %q */

Definition at line 28163 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etSQLESCAPE2

#define etSQLESCAPE2
Value:
10 /* Strings with '\'' doubled and enclosed in '',
NULL pointers replaced by SQL NULL. %Q */

Definition at line 28164 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etSQLESCAPE3

#define etSQLESCAPE3   14 /* %w -> Strings with '\"' doubled */

Definition at line 28168 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etSRCLIST

#define etSRCLIST   12 /* a pointer to a SrcList */

Definition at line 28166 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etSTRING

#define etSTRING   5 /* Strings. %s */

Definition at line 28158 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ etTOKEN

#define etTOKEN   11 /* a pointer to a Token structure */

Definition at line 28165 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ EXCLUDED_TABLE_NUMBER

#define EXCLUDED_TABLE_NUMBER   2

Definition at line 97771 of file sqlite3.c.

Referenced by lookupName().

◆ EXCLUSIVE_LOCK

◆ EXP754

#define EXP754   (((u64)0x7ff)<<52)

Definition at line 19432 of file sqlite3.c.

◆ ExpandBlob

#define ExpandBlob ( P)    (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)

◆ ExplainQueryPlan

◆ ExplainQueryPlanParent

#define ExplainQueryPlanParent ( P)    sqlite3VdbeExplainParent(P)

Definition at line 15832 of file sqlite3.c.

Referenced by sqlite3Select().

◆ ExplainQueryPlanPop

#define ExplainQueryPlanPop ( P)    sqlite3VdbeExplainPop(P)

Definition at line 15831 of file sqlite3.c.

Referenced by multiSelect(), multiSelectOrderBy(), and sqlite3Select().

◆ explainSetInteger

#define explainSetInteger ( a,
b )   a = b

Definition at line 130712 of file sqlite3.c.

◆ EXPR_FULLSIZE

#define EXPR_FULLSIZE   sizeof(Expr) /* Full size */

Definition at line 18135 of file sqlite3.c.

Referenced by dupedExprStructSize(), exprDup(), and exprStructSize().

◆ EXPR_REDUCEDSIZE

#define EXPR_REDUCEDSIZE   offsetof(Expr,iTable) /* Common features */

Definition at line 18136 of file sqlite3.c.

Referenced by dupedExprStructSize(), and exprStructSize().

◆ EXPR_TOKENONLYSIZE

#define EXPR_TOKENONLYSIZE   offsetof(Expr,pLeft) /* Fewer features */

Definition at line 18137 of file sqlite3.c.

Referenced by dupedExprStructSize(), and exprStructSize().

◆ ExprAlwaysFalse

#define ExprAlwaysFalse ( E)    (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)

◆ ExprAlwaysTrue

#define ExprAlwaysTrue ( E)    (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)

Definition at line 18107 of file sqlite3.c.

Referenced by sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), and sqlite3ExprSimplifiedAndOr().

◆ ExprClearProperty

#define ExprClearProperty ( E,
P )   (E)->flags&=~(P)

◆ ExprClearVVAProperties

#define ExprClearVVAProperties ( E)

Definition at line 18127 of file sqlite3.c.

Referenced by exprDup(), sqlite3ExprCodeTarget(), and tokenExpr().

◆ EXPRDUP_REDUCE

◆ ExprHasAllProperty

#define ExprHasAllProperty ( E,
P )   (((E)->flags&(P))==(P))

Definition at line 18104 of file sqlite3.c.

◆ ExprHasProperty

#define ExprHasProperty ( E,
P )   (((E)->flags&(P))!=0)

Definition at line 18103 of file sqlite3.c.

Referenced by addWhereTerm(), agginfoPersistExprCb(), allocateIndexInfo(), analyzeAggregate(), codeVectorCompare(), columnTypeImpl(), constInsert(), constructAutomaticIndex(), disableTerm(), dupedExprNodeSize(), dupedExprStructSize(), exprAnalyze(), exprAnalyzeOrTerm(), exprCodeBetween(), exprDup(), exprImpliesNotNull(), exprNodeIsConstant(), exprSetHeight(), exprStructSize(), findConstInWhere(), gatherSelectWindowsCallback(), impliesNotNullRow(), isCandidateForInOpt(), isSimpleCount(), lookupName(), minMaxQuery(), propagateConstantExprRewrite(), pushDownWhereTerms(), resetAccumulator(), resolveAlias(), resolveExprStep(), selectExpander(), selectWindowRewriteExprCb(), sqlite3CodeRhsOfIN(), sqlite3CodeSubselect(), sqlite3ColumnsFromExprList(), sqlite3ExprAffinity(), sqlite3ExprAssignVarNumber(), sqlite3ExprCanBeNull(), sqlite3ExprCode(), sqlite3ExprCodeIN(), sqlite3ExprCodeRunJustOnce(), sqlite3ExprCodeTarget(), sqlite3ExprCollSeq(), sqlite3ExprCompare(), sqlite3ExprCompareCollSeq(), sqlite3ExprFunctionUsable(), sqlite3ExprIdToTrueFalse(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3ExprSkipCollateAndLikely(), sqlite3FindInIndex(), sqlite3FunctionUsesThisSrc(), sqlite3InRhsIsConstant(), sqlite3IsLikeFunction(), sqlite3Select(), sqlite3SetJoinExpr(), sqlite3WhereBegin(), sqlite3WhereExprUsageNN(), substExpr(), termCanDriveIndex(), termIsEquivalence(), unsetJoinExpr(), updateAccumulator(), valueFromExpr(), walkExpr(), whereClauseInsert(), whereIndexExprTransNode(), whereLoopAddBtreeIndex(), and whereScanNext().

◆ ExprHasVVAProperty

#define ExprHasVVAProperty ( E,
P )   0

◆ ExprIsVtab

#define ExprIsVtab ( X)     ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)

Definition at line 17557 of file sqlite3.c.

17557** table support is omitted from the build.
17558*/

Referenced by isAuxiliaryVtabOperator().

◆ ExprSetProperty

◆ ExprSetVVAProperty

#define ExprSetVVAProperty ( E,
P )

◆ fdatasync

#define fdatasync   fsync

Definition at line 37083 of file sqlite3.c.

Referenced by full_fsync().

◆ fileChunkSize

#define fileChunkSize ( nChunkSize)    (sizeof(FileChunk) + ((nChunkSize)-8))

Definition at line 97121 of file sqlite3.c.

Referenced by sqlite3JournalOpen().

◆ FILEHANDLEID

#define FILEHANDLEID ( fd)    (SQLITE_PTR_TO_INT(fd))

Definition at line 51834 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ findCell

#define findCell ( P,
I )    ((P)->aData + ((P)->maskPage & get2byteAligned(&(P)->aCellIdx[2*(I)])))

Definition at line 65569 of file sqlite3.c.

65569**
65570** findCellPastPtr() does the same except it skips past the initial
#define findCellPastPtr(P, I)
Definition sqlite3.c:65571

Referenced by balance_nonroot(), balance_quick(), btreePrevious(), modifyPagePointer(), moveToLeftmost(), setChildPtrmaps(), sqlite3BtreeCount(), sqlite3BtreeDelete(), sqlite3BtreeInsert(), and sqlite3BtreeMovetoUnpacked().

◆ findCellPastPtr

#define findCellPastPtr ( P,
I )    ((P)->aDataOfst + ((P)->maskPage & get2byteAligned(&(P)->aCellIdx[2*(I)])))

Definition at line 65571 of file sqlite3.c.

65571** 4-byte child pointer found on interior pages, if there is one.
65572**

Referenced by sqlite3BtreeMovetoUnpacked().

◆ first_valueInvFunc

#define first_valueInvFunc   noopStepFunc

Definition at line 151447 of file sqlite3.c.

◆ first_valueValueFunc

#define first_valueValueFunc   noopValueFunc

Definition at line 151448 of file sqlite3.c.

◆ FLAG_SIGNED

#define FLAG_SIGNED   1 /* True if the value to convert is signed */

Definition at line 28196 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ FLAG_STRING

#define FLAG_STRING   4 /* Allow infinite precision */

Definition at line 28197 of file sqlite3.c.

◆ FOUR_BYTE_INT

#define FOUR_BYTE_INT ( x)    (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3])

Definition at line 81576 of file sqlite3.c.

◆ FOUR_BYTE_UINT

#define FOUR_BYTE_UINT ( x)    (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])

Definition at line 81575 of file sqlite3.c.

Referenced by serialGet(), vdbeRecordCompareInt(), and vdbeRecordDecodeInt().

◆ FTS5_TOKEN_COLOCATED

#define FTS5_TOKEN_COLOCATED   0x0001 /* Same position as prev. token */

Definition at line 13172 of file sqlite3.c.

◆ FTS5_TOKENIZE_AUX

#define FTS5_TOKENIZE_AUX   0x0008

Definition at line 13168 of file sqlite3.c.

◆ FTS5_TOKENIZE_DOCUMENT

#define FTS5_TOKENIZE_DOCUMENT   0x0004

Definition at line 13167 of file sqlite3.c.

◆ FTS5_TOKENIZE_PREFIX

#define FTS5_TOKENIZE_PREFIX   0x0002

Definition at line 13166 of file sqlite3.c.

◆ FTS5_TOKENIZE_QUERY

#define FTS5_TOKENIZE_QUERY   0x0001

Definition at line 13165 of file sqlite3.c.

◆ FULLY_WITHIN

#define FULLY_WITHIN   2 /* Object fully contained within query region */

Definition at line 10974 of file sqlite3.c.

◆ FUNC_PERFECT_MATCH

#define FUNC_PERFECT_MATCH   6 /* The score for a perfect match */

Definition at line 115833 of file sqlite3.c.

Referenced by matchQuality(), and sqlite3FindFunction().

◆ FUNCTION

#define FUNCTION ( zName,
nArg,
iArg,
bNC,
xFunc )
Value:
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
#define SQLITE_FUNC_NEEDCOLL
Definition sqlite3.c:17149

Definition at line 17239 of file sqlite3.c.

17239** FuncDef.flags variable is set to the value passed as the flags
17240** parameter.
17241*/

Referenced by sqlite3RegisterBuiltinFunctions().

◆ FUNCTION2

#define FUNCTION2 ( zName,
nArg,
iArg,
bNC,
xFunc,
extraFlags )
Value:
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }

Definition at line 17261 of file sqlite3.c.

17261#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
17262 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
17263 (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ GCC_VERSION

#define GCC_VERSION   0

Definition at line 985 of file sqlite3.c.

◆ get2byte

#define get2byte ( x)    ((x)[0]<<8 | (x)[1])

◆ get2byteAligned

#define get2byteAligned ( x)    ((x)[0]<<8 | (x)[1])

Definition at line 64180 of file sqlite3.c.

Referenced by balance_nonroot(), checkTreePage(), and editPage().

◆ get2byteNotZero

#define get2byteNotZero ( X)    (((((int)get2byte(X))-1)&0xffff)+1)

Definition at line 64521 of file sqlite3.c.

Referenced by allocateSpace(), balance_nonroot(), btreeInitPage(), checkTreePage(), and editPage().

◆ get4byte

◆ getVarint

#define getVarint   sqlite3GetVarint

Definition at line 19875 of file sqlite3.c.

Referenced by sqlite3BtreeMovetoUnpacked().

◆ getVarint32

#define getVarint32 ( A,
B )    (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))

Definition at line 19868 of file sqlite3.c.

19868/*
19869** The common case is for a varint to be a single byte. They following

Referenced by sqlite3VdbeExec(), sqlite3VdbeRecordCompareWithSkip(), and sqlite3VdbeRecordUnpack().

◆ getVarint32NR

#define getVarint32NR ( A,
B )    B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))

Definition at line 19870 of file sqlite3.c.

19870** macros handle the common case without a procedure call, but then call
19871** the procedure for larger varints.

Referenced by sqlite3VdbeIdxRowid(), sqlite3VdbeRecordCompareWithSkip(), and vdbeSorterCompareText().

◆ GLOBAL

#define GLOBAL ( t,
v )   v

◆ harmless

#define harmless ( X)

Definition at line 13757 of file sqlite3.c.

Referenced by btreeNext().

◆ HAS_UPDATE_HOOK

#define HAS_UPDATE_HOOK ( DB)    ((DB)->xUpdateCallback)

Definition at line 85328 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ HASHTABLE_HASH_1

#define HASHTABLE_HASH_1   383 /* Should be prime */

Definition at line 59928 of file sqlite3.c.

Referenced by walNextHash().

◆ HASHTABLE_NPAGE

#define HASHTABLE_NPAGE   4096 /* Must be power of 2 */

Definition at line 59927 of file sqlite3.c.

Referenced by walFramePage(), walHashGet(), walIndexRecover(), walIteratorInit(), and walMergesort().

◆ HASHTABLE_NPAGE_ONE

#define HASHTABLE_NPAGE_ONE   (HASHTABLE_NPAGE - (WALINDEX_HDR_SIZE/sizeof(u32)))

Definition at line 59936 of file sqlite3.c.

Referenced by walCleanupHash(), walFramePage(), walHashGet(), and walIndexRecover().

◆ HASHTABLE_NSLOT

#define HASHTABLE_NSLOT   (HASHTABLE_NPAGE*2) /* Must be a power of 2 */

Definition at line 59929 of file sqlite3.c.

Referenced by sqlite3WalFindFrame(), walCleanupHash(), walIndexAppend(), and walNextHash().

◆ HasRowid

◆ HAVE_FCHOWN

#define HAVE_FCHOWN   1

Definition at line 929 of file sqlite3.c.

◆ HAVE_FULLFSYNC

#define HAVE_FULLFSYNC   0

Definition at line 37094 of file sqlite3.c.

Referenced by unixSync().

◆ HAVE_GETHOSTUUID

#define HAVE_GETHOSTUUID   0

Definition at line 33465 of file sqlite3.c.

◆ HAVE_LSTAT

#define HAVE_LSTAT   1

Definition at line 931 of file sqlite3.c.

◆ HAVE_MREMAP

#define HAVE_MREMAP   0

Definition at line 33877 of file sqlite3.c.

◆ HAVE_READLINK

#define HAVE_READLINK   1

Definition at line 930 of file sqlite3.c.

◆ HI

#define HI ( X)    ((u64)(X)<<32)

Definition at line 16968 of file sqlite3.c.

◆ IdChar

#define IdChar ( C)    ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)

Definition at line 159903 of file sqlite3.c.

Referenced by sqlite3_complete(), and sqlite3GetToken().

◆ IfNotOmitAV

#define IfNotOmitAV ( expr)    (expr)

Definition at line 64537 of file sqlite3.c.

Referenced by allocateBtreePage(), and sqlite3BtreeBeginTrans().

◆ IgnorableOrderby

#define IgnorableOrderby ( X)    ((X->eDest)<=SRT_DistQueue)

Definition at line 18578 of file sqlite3.c.

Referenced by sqlite3Select().

◆ IN_DECLARE_VTAB

#define IN_DECLARE_VTAB   (pParse->eParseMode==PARSE_MODE_DECLARE_VTAB)

Definition at line 18800 of file sqlite3.c.

Referenced by sqlite3CreateForeignKey(), and sqlite3CreateIndex().

◆ IN_INDEX_EPH

#define IN_INDEX_EPH   2 /* Search an ephemeral b-tree */

Definition at line 20229 of file sqlite3.c.

Referenced by sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ IN_INDEX_INDEX_ASC

#define IN_INDEX_INDEX_ASC   3 /* Existing index ASCENDING */

Definition at line 20230 of file sqlite3.c.

Referenced by sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ IN_INDEX_INDEX_DESC

#define IN_INDEX_INDEX_DESC   4 /* Existing index DESCENDING */

Definition at line 20231 of file sqlite3.c.

Referenced by codeEqualityTerm(), sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ IN_INDEX_LOOP

#define IN_INDEX_LOOP   0x0004 /* IN operator used as a loop */

Definition at line 20238 of file sqlite3.c.

Referenced by codeEqualityTerm(), and sqlite3FindInIndex().

◆ IN_INDEX_MEMBERSHIP

#define IN_INDEX_MEMBERSHIP   0x0002 /* IN operator used for membership test */

Definition at line 20237 of file sqlite3.c.

Referenced by sqlite3ExprCodeIN().

◆ IN_INDEX_NOOP

#define IN_INDEX_NOOP   5 /* No table available. Use comparisons */

Definition at line 20232 of file sqlite3.c.

Referenced by codeEqualityTerm(), sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ IN_INDEX_NOOP_OK

#define IN_INDEX_NOOP_OK   0x0001 /* OK to return IN_INDEX_NOOP */

Definition at line 20236 of file sqlite3.c.

Referenced by sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ IN_INDEX_ROWID

#define IN_INDEX_ROWID   1 /* Search the rowid of the table */

Definition at line 20228 of file sqlite3.c.

Referenced by codeEqualityTerm(), sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ IN_RENAME_OBJECT

◆ IN_SPECIAL_PARSE

#define IN_SPECIAL_PARSE   (pParse->eParseMode!=PARSE_MODE_NORMAL)

◆ INCRINIT_NORMAL

#define INCRINIT_NORMAL   0

◆ INCRINIT_ROOT

#define INCRINIT_ROOT   2

◆ INCRINIT_TASK

#define INCRINIT_TASK   1

◆ INITFLAG_AlterTable

#define INITFLAG_AlterTable   0x0001 /* This is a reparse after ALTER TABLE */

Definition at line 19001 of file sqlite3.c.

Referenced by corruptSchema(), and sqlite3VdbeExec().

◆ initMaskSet

#define initMaskSet ( P)    (P)->n=0

Definition at line 141312 of file sqlite3.c.

Referenced by sqlite3WhereBegin().

◆ INLINE_FUNC

#define INLINE_FUNC ( zName,
nArg,
iArg,
mFlags )
Value:
SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }

Definition at line 17248 of file sqlite3.c.

17248#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
17249 {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
17250 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_affinity

#define INLINEFUNC_affinity   4

Definition at line 17172 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_coalesce

#define INLINEFUNC_coalesce   0

Definition at line 17168 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_expr_compare

#define INLINEFUNC_expr_compare   3

Definition at line 17171 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_expr_implies_expr

#define INLINEFUNC_expr_implies_expr   2

Definition at line 17170 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_iif

#define INLINEFUNC_iif   5

Definition at line 17173 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_implies_nonnull_row

#define INLINEFUNC_implies_nonnull_row   1

Definition at line 17169 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INLINEFUNC_unlikely

#define INLINEFUNC_unlikely   99 /* Default case */

Definition at line 17174 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ INT16_TYPE

#define INT16_TYPE   short int

Definition at line 14309 of file sqlite3.c.

◆ INT8_TYPE

#define INT8_TYPE   signed char

Definition at line 14323 of file sqlite3.c.

◆ INT_464269060799999

#define INT_464269060799999   ((((i64)0x1a640)<<32)|0x1072fdff)

Definition at line 22114 of file sqlite3.c.

Referenced by validJulianDay().

◆ INTERFACE

#define INTERFACE   1

Definition at line 154473 of file sqlite3.c.

◆ INTERNAL_FUNCTION

#define INTERNAL_FUNCTION ( zName,
nArg,
xFunc )
Value:
0, 0, xFunc, 0, 0, 0, #zName, {0} }

Definition at line 17273 of file sqlite3.c.

17273#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
17274 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
17275 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}

◆ invalidateOverflowCache

#define invalidateOverflowCache ( pCur)    (pCur->curFlags &= ~BTCF_ValidOvfl)

Definition at line 64981 of file sqlite3.c.

Referenced by invalidateAllOverflowCache(), and sqlite3BtreeInsert().

◆ IOMETHODS

#define IOMETHODS ( FINDER,
METHOD,
VERSION,
CLOSE,
LOCK,
UNLOCK,
CKLOCK,
SHMMAP )
Value:
static const sqlite3_io_methods METHOD = { \
VERSION, /* iVersion */ \
CLOSE, /* xClose */ \
unixRead, /* xRead */ \
unixWrite, /* xWrite */ \
unixTruncate, /* xTruncate */ \
unixSync, /* xSync */ \
unixFileSize, /* xFileSize */ \
LOCK, /* xLock */ \
UNLOCK, /* xUnlock */ \
CKLOCK, /* xCheckReservedLock */ \
unixFileControl, /* xFileControl */ \
unixSectorSize, /* xSectorSize */ \
unixDeviceCharacteristics, /* xDeviceCapabilities */ \
SHMMAP, /* xShmMap */ \
unixShmLock, /* xShmLock */ \
unixShmBarrier, /* xShmBarrier */ \
unixShmUnmap, /* xShmUnmap */ \
unixFetch, /* xFetch */ \
unixUnfetch, /* xUnfetch */ \
}; \
static const sqlite3_io_methods *FINDER##Impl(const char *z, unixFile *p){ \
UNUSED_PARAMETER(z); UNUSED_PARAMETER(p); \
return &METHOD; \
} \
static const sqlite3_io_methods *(*const FINDER)(const char*,unixFile *p) \
= FINDER##Impl;
#define VERSION
static int unixTruncate(sqlite3_file *id, i64 nByte)
Definition sqlite3.c:37305
static int unixRead(sqlite3_file *id, void *pBuf, int amt, sqlite3_int64 offset)
Definition sqlite3.c:36873
static int unixUnfetch(sqlite3_file *fd, i64 iOff, void *p)
Definition sqlite3.c:38742
static int unixFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp)
Definition sqlite3.c:38711
#define UNUSED_PARAMETER(x)
Definition sqlite3.c:14653
static int unixWrite(sqlite3_file *id, const void *pBuf, int amt, sqlite3_int64 offset)
Definition sqlite3.c:36987
static int unixDeviceCharacteristics(sqlite3_file *id)
Definition sqlite3.c:37730
static void unixShmBarrier(sqlite3_file *fd)
Definition sqlite3.c:38481
static int unixSectorSize(sqlite3_file *id)
Definition sqlite3.c:37711
static int unixShmLock(sqlite3_file *fd, int ofst, int n, int flags)
Definition sqlite3.c:38347
static int unixFileSize(sqlite3_file *id, i64 *pSize)
Definition sqlite3.c:37355
static int unixSync(sqlite3_file *id, int flags)
Definition sqlite3.c:37255
static int unixShmUnmap(sqlite3_file *fd, int deleteFlag)
Definition sqlite3.c:38500
static int unixFileControl(sqlite3_file *id, int op, void *pArg)
Definition sqlite3.c:37478

Definition at line 38810 of file sqlite3.c.

38810** * A constant sqlite3_io_methods object call METHOD that has locking
38811** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
38812**
38813** * An I/O method finder function called FINDER that returns a pointer
38814** to the METHOD object in the previous bullet.
38815*/
38816#define IOMETHODS(FINDER,METHOD,VERSION,CLOSE,LOCK,UNLOCK,CKLOCK,SHMMAP) \
38817static const sqlite3_io_methods METHOD = { \
38818 VERSION, /* iVersion */ \
38819 CLOSE, /* xClose */ \
38820 unixRead, /* xRead */ \
38821 unixWrite, /* xWrite */ \
38822 unixTruncate, /* xTruncate */ \
38823 unixSync, /* xSync */ \
38824 unixFileSize, /* xFileSize */ \
38825 LOCK, /* xLock */ \
38826 UNLOCK, /* xUnlock */ \
38827 CKLOCK, /* xCheckReservedLock */ \
38828 unixFileControl, /* xFileControl */ \
38829 unixSectorSize, /* xSectorSize */ \
38830 unixDeviceCharacteristics, /* xDeviceCapabilities */ \
38831 SHMMAP, /* xShmMap */ \
38832 unixShmLock, /* xShmLock */ \
38833 unixShmBarrier, /* xShmBarrier */ \
38834 unixShmUnmap, /* xShmUnmap */ \
38835 unixFetch, /* xFetch */ \
38836 unixUnfetch, /* xUnfetch */ \
38837}; \

◆ IOTRACE

◆ IS_BIG_INT

#define IS_BIG_INT ( X)    (((X)&~(i64)0xffffffff)!=0)

Definition at line 13828 of file sqlite3.c.

Referenced by walCheckpoint().

◆ IS_LOCK_ERROR

#define IS_LOCK_ERROR ( x)    ((x != SQLITE_OK) && (x != SQLITE_BUSY))

Definition at line 33537 of file sqlite3.c.

Referenced by posixUnlock().

◆ ISAUTOVACUUM

#define ISAUTOVACUUM   (pBt->autoVacuum)

◆ IsHiddenColumn

#define IsHiddenColumn ( X)    (((X)->colFlags & COLFLAG_HIDDEN)!=0)

Definition at line 17574 of file sqlite3.c.

Referenced by selectExpander(), sqliteProcessJoin(), and tableAndColumnIndex().

◆ isMalloced

#define isMalloced ( X)    (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)

Definition at line 18981 of file sqlite3.c.

Referenced by sqlite3StrAccumEnlarge(), and strAccumFinishRealloc().

◆ IsNaN

#define IsNaN ( X)    (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)

Definition at line 19434 of file sqlite3.c.

Referenced by sqlite3IsNaN().

◆ isOpen

◆ IsOrdinaryHiddenColumn

#define IsOrdinaryHiddenColumn ( X)    0

Definition at line 17575 of file sqlite3.c.

◆ ISPOWEROF2

#define ISPOWEROF2 ( X)    (((X)&((X)-1))==0)

Definition at line 75848 of file sqlite3.c.

◆ IsPowerOfTwo

#define IsPowerOfTwo ( X)    (((X)&((X)-1))==0)

Definition at line 14599 of file sqlite3.c.

Referenced by allocateIndexInfo(), and exprAnalyzeOrTerm().

◆ IsPrimaryKeyIndex

◆ isSorter

#define isSorter ( x)    ((x)->eCurType==CURTYPE_SORTER)

Definition at line 85466 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ IsStat4

#define IsStat4   0

Definition at line 107691 of file sqlite3.c.

Referenced by analyzeOneTable().

◆ IsUniqueIndex

◆ IsVirtual

◆ IsWindowFunc

#define IsWindowFunc ( p)
Value:
( \
ExprHasProperty((p), EP_WinFunc) && p->y.pWin->eFrmType!=TK_FILTER \
)
#define TK_FILTER
Definition sqlite3.c:14105
#define EP_WinFunc
Definition sqlite3.c:18084

Definition at line 18152 of file sqlite3.c.

18152*/
18153#ifdef SQLITE_OMIT_WINDOWFUNC
18154# define IsWindowFunc(p) 0

Referenced by minMaxQuery(), resolveExprStep(), sqlite3Select(), and updateAccumulator().

◆ JOURNAL_HDR_SZ

#define JOURNAL_HDR_SZ ( pPager)    (pPager->sectorSize)

◆ JOURNAL_PG_SZ

#define JOURNAL_PG_SZ ( pPager)    ((pPager->pageSize) + 8)

Definition at line 52461 of file sqlite3.c.

Referenced by jrnlBufferSize(), pager_playback(), and pagerPlaybackSavepoint().

◆ JT_CROSS

#define JT_CROSS   0x0002 /* Explicit use of the CROSS keyword */

Definition at line 18288 of file sqlite3.c.

Referenced by sqlite3JoinType(), and sqlite3Select().

◆ JT_ERROR

#define JT_ERROR   0x0040 /* unknown or unsupported join type */

Definition at line 18293 of file sqlite3.c.

Referenced by sqlite3JoinType().

◆ JT_INNER

#define JT_INNER   0x0001 /* Any kind of inner or cross join */

Definition at line 18287 of file sqlite3.c.

Referenced by sqlite3JoinType(), and yy_reduce().

◆ JT_LEFT

#define JT_LEFT   0x0008 /* Left outer join */

◆ JT_NATURAL

#define JT_NATURAL   0x0004 /* True for a "natural" join */

Definition at line 18289 of file sqlite3.c.

Referenced by lookupName(), selectExpander(), sqlite3JoinType(), and sqliteProcessJoin().

◆ JT_OUTER

#define JT_OUTER   0x0020 /* The "OUTER" keyword is present */

◆ JT_RIGHT

#define JT_RIGHT   0x0010 /* Right outer join */

Definition at line 18291 of file sqlite3.c.

Referenced by lookupName(), and sqlite3JoinType().

◆ KEYINFO_ORDER_BIGNULL

◆ KEYINFO_ORDER_DESC

◆ LARGEST_INT64

#define LARGEST_INT64   (0xffffffff|(((i64)0x7fffffff)<<32))

◆ LARGEST_UINT64

#define LARGEST_UINT64   (0xffffffff|(((u64)0xffffffff)<<32))

Definition at line 14465 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ LIKEFUNC

#define LIKEFUNC ( zName,
nArg,
arg,
flags )
Value:
(void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
CURL_EXTERN int void * arg
Definition curl.h:2622
static void likeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117890

Definition at line 17267 of file sqlite3.c.

17267#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
17268 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
17269 pArg, 0, xFunc, 0, 0, 0, #zName, }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ likely

#define likely ( X)    (X)

Definition at line 13837 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ LOCATE_NOERR

#define LOCATE_NOERR   0x02

Definition at line 19674 of file sqlite3.c.

Referenced by sqlite3LocateTable(), and sqlite3Pragma().

◆ LOCATE_VIEW

#define LOCATE_VIEW   0x01

Definition at line 19673 of file sqlite3.c.

Referenced by sqlite3LocateTable().

◆ LONGDOUBLE_TYPE

#define LONGDOUBLE_TYPE   long double

◆ LOOKASIDE_SMALL

#define LOOKASIDE_SMALL   128

Definition at line 16748 of file sqlite3.c.

Referenced by setupLookaside(), sqlite3DbFreeNN(), and sqlite3DbRealloc().

◆ MAN754

#define MAN754   ((((u64)1)<<52)-1)

Definition at line 19433 of file sqlite3.c.

◆ markExprListImmutable

#define markExprListImmutable ( X)    /* no-op */

Definition at line 112636 of file sqlite3.c.

Referenced by sqlite3EndTable().

◆ MASKBIT

#define MASKBIT ( n)    (((Bitmask)1)<<(n))

◆ MASKBIT32

#define MASKBIT32 ( n)    (((unsigned int)1)<<(n))

◆ MASKBIT64

#define MASKBIT64 ( n)    (((u64)1)<<(n))

Definition at line 14732 of file sqlite3.c.

◆ MAX

◆ MAX_PATHNAME

#define MAX_PATHNAME   512

Definition at line 33522 of file sqlite3.c.

Referenced by findCreateFileMode(), openDirectory(), unixFullPathname(), and unixOpen().

◆ MAX_ROWID

#define MAX_ROWID   (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )

◆ MAX_SECTOR_SIZE

#define MAX_SECTOR_SIZE   0x10000

Definition at line 52117 of file sqlite3.c.

Referenced by readJournalHdr().

◆ mem0

◆ MEM_AffMask

#define MEM_AffMask   0x003f /* Mask of affinity bits */

Definition at line 20954 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3VdbeMemTranslate().

◆ MEM_Agg

#define MEM_Agg   0x2000 /* Mem.z points to an agg function context */

◆ MEM_Blob

◆ MEM_Cleared

#define MEM_Cleared   0x0100 /* NULL set by OP_Null, not from data */

Definition at line 20957 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ MEM_Dyn

#define MEM_Dyn   0x0400 /* Need to call Mem.xDel() on Mem.z */

◆ MEM_Ephem

#define MEM_Ephem   0x1000 /* Mem.z points to an ephemeral string */

◆ MEM_FromBind

#define MEM_FromBind   0x0040 /* Value originates from sqlite3_bind() */

Definition at line 20955 of file sqlite3.c.

Referenced by sqlite3_value_dup(), and sqlite3VdbeExec().

◆ MEM_Int

◆ MEM_IntReal

◆ MEM_Null

◆ MEM_Real

◆ MEM_Static

#define MEM_Static   0x0800 /* Mem.z points to a static string */

◆ MEM_Str

◆ MEM_Subtype

#define MEM_Subtype   0x8000 /* Mem.eSubtype is valid */

Definition at line 20972 of file sqlite3.c.

Referenced by sqlite3_result_text(), and sqlite3VdbeMemTranslate().

◆ MEM_Term

◆ MEM_TypeMask

#define MEM_TypeMask   0xc1bf /* Mask of type bits */

Definition at line 20958 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), sqlite3VdbeMemCast(), and sqlite3VdbeMemInit().

◆ MEM_Undefined

#define MEM_Undefined   0x0080 /* Value is undefined */

Definition at line 20956 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), sqlite3VdbeMakeReady(), and sqlite3VdbeReset().

◆ MEM_Zero

◆ memAboutToChange

#define memAboutToChange ( P,
M )

Definition at line 85268 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ MEMCELLSIZE

#define MEMCELLSIZE   offsetof(Mem,zMalloc)

Definition at line 20933 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ MEMDB

◆ memJM

#define memJM   0

◆ MEMJOURNAL_DFLT_FILECHUNKSIZE

#define MEMJOURNAL_DFLT_FILECHUNKSIZE   1024

Definition at line 97115 of file sqlite3.c.

Referenced by sqlite3JournalOpen().

◆ MemNullNochng

#define MemNullNochng ( X)
Value:
(((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \
&& (X)->n==0 && (X)->u.nZero==0)
#define MEM_Zero
Definition sqlite3.c:20971
#define MEM_TypeMask
Definition sqlite3.c:20958
#define MEM_Null
Definition sqlite3.c:20948

Definition at line 20993 of file sqlite3.c.

20993 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
20994
20995/*

Referenced by sqlite3VdbeMemExpandBlob().

◆ MemSetTypeFlag

#define MemSetTypeFlag ( p,
f )    ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)

Definition at line 20987 of file sqlite3.c.

20987 (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
20988
#define MEM_Agg
Definition sqlite3.c:20970
#define MEM_Dyn
Definition sqlite3.c:20967

Referenced by sqlite3VdbeExec(), sqlite3VdbeMemCast(), sqlite3VdbeMemNumerify(), sqlite3VdbeNextOpcode(), and valueFromExpr().

◆ MEMTYPE_HEAP

#define MEMTYPE_HEAP   0x01 /* General heap allocations */

Definition at line 20331 of file sqlite3.c.

Referenced by dbMallocRawFinish(), lookasideMallocSize(), and sqlite3DbFreeNN().

◆ MEMTYPE_LOOKASIDE

#define MEMTYPE_LOOKASIDE   0x02 /* Heap that might have been lookaside */

Definition at line 20332 of file sqlite3.c.

Referenced by dbMallocRawFinish(), and sqlite3DbFreeNN().

◆ MEMTYPE_PCACHE

#define MEMTYPE_PCACHE   0x04 /* Page cache allocations */

Definition at line 20333 of file sqlite3.c.

Referenced by pcache1Alloc().

◆ MIN

◆ MSVC_VERSION

#define MSVC_VERSION   0

Definition at line 990 of file sqlite3.c.

◆ MUTEX_LOGIC

#define MUTEX_LOGIC ( X)    X

◆ MX_CELL

#define MX_CELL ( pBt)    ((pBt->pageSize-8)/6)

Definition at line 63698 of file sqlite3.c.

Referenced by balance_nonroot(), btreeInitPage(), and insertCell().

◆ MX_CELL_SIZE

#define MX_CELL_SIZE ( pBt)    ((int)(pBt->pageSize-8))

Definition at line 63691 of file sqlite3.c.

Referenced by lockBtree(), sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ N_OR_COST

#define N_OR_COST   3

Definition at line 141083 of file sqlite3.c.

Referenced by whereOrInsert().

◆ N_SORT_BUCKET

#define N_SORT_BUCKET   32

Definition at line 49601 of file sqlite3.c.

Referenced by pcacheSortDirtyList().

◆ NB

#define NB   3 /* (NN*2+1): Total pages involved in the balance */

Definition at line 71294 of file sqlite3.c.

Referenced by balance_nonroot(), pageInsertArray(), and rebuildPage().

◆ NC_AllowAgg

#define NC_AllowAgg   0x00001 /* Aggregate functions are allowed here */

Definition at line 18373 of file sqlite3.c.

Referenced by lookupName(), resolveExprStep(), and resolveOrderByTermToExprList().

◆ NC_AllowWin

#define NC_AllowWin   0x04000 /* Window functions are allowed here */

Definition at line 18386 of file sqlite3.c.

Referenced by lookupName(), and resolveExprStep().

◆ NC_Complex

#define NC_Complex   0x02000 /* True if a function or subquery seen */

Definition at line 18385 of file sqlite3.c.

◆ NC_FromDDL

#define NC_FromDDL   0x40000 /* SQL text comes from sqlite_schema */

Definition at line 18390 of file sqlite3.c.

Referenced by resolveExprStep(), and sqlite3ResolveSelfReference().

◆ NC_GenCol

#define NC_GenCol   0x00008 /* True for a GENERATED ALWAYS AS clause */

◆ NC_HasAgg

#define NC_HasAgg   0x00010 /* One or more aggregate functions seen */

◆ NC_HasWin

#define NC_HasWin   0x08000 /* One or more window functions seen */

◆ NC_IdxExpr

#define NC_IdxExpr   0x00020 /* True if resolving columns of CREATE INDEX */

◆ NC_InAggFunc

#define NC_InAggFunc   0x20000 /* True if analyzing arguments to an agg func */

Definition at line 18389 of file sqlite3.c.

Referenced by analyzeAggregate(), and sqlite3Select().

◆ NC_IsCheck

#define NC_IsCheck   0x00004 /* True if resolving a CHECK constraint */

◆ NC_IsDDL

#define NC_IsDDL   0x10000 /* Resolving names in a CREATE statement */

Definition at line 18388 of file sqlite3.c.

Referenced by sqlite3ResolveSelfReference().

◆ NC_MinMaxAgg

#define NC_MinMaxAgg   0x01000 /* min/max aggregates seen. See note above */

◆ NC_PartIdx

#define NC_PartIdx   0x00002 /* True if resolving a partial index WHERE */

◆ NC_SelfRef

#define NC_SelfRef   0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */

Definition at line 18379 of file sqlite3.c.

Referenced by resolveExprStep(), and sqlite3VdbeAddFunctionCall().

◆ NC_UAggInfo

#define NC_UAggInfo   0x00100 /* True if uNC.pAggInfo is used */

Definition at line 18382 of file sqlite3.c.

Referenced by analyzeAggregate(), and sqlite3Select().

◆ NC_UEList

#define NC_UEList   0x00080 /* True if uNC.pEList is used */

Definition at line 18381 of file sqlite3.c.

Referenced by lookupName(), and resolveOrderByTermToExprList().

◆ NC_UUpsert

#define NC_UUpsert   0x00200 /* True if uNC.pUpsert is used */

Definition at line 18383 of file sqlite3.c.

Referenced by lookupName(), renameResolveTrigger(), and sqlite3Update().

◆ NC_VarSelect

#define NC_VarSelect   0x00040 /* A correlated subquery has been seen */

Definition at line 18380 of file sqlite3.c.

Referenced by resolveExprStep(), and sqlite3DeleteFrom().

◆ NDEBUG

#define NDEBUG   1

Definition at line 13655 of file sqlite3.c.

◆ NEVER

◆ NN

#define NN   1 /* Number of neighbors on either side of pPage */

Definition at line 71293 of file sqlite3.c.

◆ NO_LOCK

◆ noopFunc

#define noopFunc   versionFunc /* Substitute function - never called */

Definition at line 117547 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ NOT_WITHIN

#define NOT_WITHIN   0 /* Object completely outside of query region */

Definition at line 10972 of file sqlite3.c.

◆ nth_valueInvFunc

#define nth_valueInvFunc   noopStepFunc

Definition at line 151419 of file sqlite3.c.

◆ nth_valueValueFunc

#define nth_valueValueFunc   noopValueFunc

Definition at line 151420 of file sqlite3.c.

◆ ntileFinalizeFunc

#define ntileFinalizeFunc   ntileValueFunc

Definition at line 151634 of file sqlite3.c.

◆ O_BINARY

#define O_BINARY   0

Definition at line 33857 of file sqlite3.c.

Referenced by openDirectory(), and unixOpen().

◆ O_LARGEFILE

#define O_LARGEFILE   0

Definition at line 33847 of file sqlite3.c.

Referenced by unixOpen().

◆ O_NOFOLLOW

#define O_NOFOLLOW   0

Definition at line 33854 of file sqlite3.c.

Referenced by unixOpen(), and unixOpenSharedMemory().

◆ OE_Abort

◆ OE_Cascade

#define OE_Cascade   10 /* Cascade the changes */

Definition at line 17666 of file sqlite3.c.

Referenced by actionName(), fkActionTrigger(), sqlite3FkCheck(), and yy_reduce().

◆ OE_Default

◆ OE_Fail

#define OE_Fail   3 /* Stop the operation but leave all prior changes */

◆ OE_Ignore

#define OE_Ignore   4 /* Ignore the error. Do not do the INSERT or UPDATE */

◆ OE_None

#define OE_None   0 /* There is no constraint to check */

◆ OE_Replace

#define OE_Replace   5 /* Delete existing record, then do INSERT or UPDATE */

◆ OE_Restrict

#define OE_Restrict   7 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */

Definition at line 17663 of file sqlite3.c.

Referenced by actionName(), fkActionTrigger(), and yy_reduce().

◆ OE_Rollback

#define OE_Rollback   1 /* Fail the operation and rollback the transaction */

◆ OE_SetDflt

#define OE_SetDflt   9 /* Set the foreign key value to its default */

Definition at line 17665 of file sqlite3.c.

Referenced by actionName(), fkActionTrigger(), and yy_reduce().

◆ OE_SetNull

#define OE_SetNull   8 /* Set the foreign key value to NULL */

Definition at line 17664 of file sqlite3.c.

Referenced by actionName(), isSetNullAction(), sqlite3FkCheck(), and yy_reduce().

◆ OE_Update

#define OE_Update   6 /* Process as a DO UPDATE in an upsert */

Definition at line 17662 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks().

◆ offsetof

◆ OK_IF_ALWAYS_FALSE

#define OK_IF_ALWAYS_FALSE ( X)    (X)

Definition at line 13772 of file sqlite3.c.

◆ OK_IF_ALWAYS_TRUE

#define OK_IF_ALWAYS_TRUE ( X)    (X)

Definition at line 13771 of file sqlite3.c.

Referenced by clearSelect(), selectPopWith(), and sqlite3SelectExpand().

◆ OMIT_TEMPDB

#define OMIT_TEMPDB   0

◆ ONE_BYTE_INT

#define ONE_BYTE_INT ( x)    ((i8)(x)[0])

Definition at line 81572 of file sqlite3.c.

Referenced by vdbeRecordCompareInt(), and vdbeRecordDecodeInt().

◆ ONEPASS_MULTI

#define ONEPASS_MULTI   2 /* ONEPASS is valid for multiple rows */

◆ ONEPASS_OFF

#define ONEPASS_OFF   0 /* Use of ONEPASS not allowed */

◆ ONEPASS_SINGLE

#define ONEPASS_SINGLE   1 /* ONEPASS valid for a single row update */

◆ ONLY_IF_REALLOC_STRESS

#define ONLY_IF_REALLOC_STRESS ( X)    (0)

Definition at line 13787 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ OP_Abortable

#define OP_Abortable   175

Definition at line 15741 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_Add

#define OP_Add   105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */

◆ OP_AddImm

◆ OP_Affinity

#define OP_Affinity   90 /* synopsis: affinity(r[P1@P2]) */

◆ OP_AggFinal

#define OP_AggFinal   157 /* synopsis: accum=r[P1] N=P2 */

Definition at line 15723 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and windowAggFinal().

◆ OP_AggInverse

#define OP_AggInverse   153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */

Definition at line 15719 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and windowAggStep().

◆ OP_AggStep

#define OP_AggStep   154 /* synopsis: accum=r[P3] step(r[P2@P5]) */

Definition at line 15720 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), updateAccumulator(), and windowAggStep().

◆ OP_AggStep1

#define OP_AggStep1   155 /* synopsis: accum=r[P3] step(r[P2@P5]) */

Definition at line 15721 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_AggValue

#define OP_AggValue   156 /* synopsis: r[P3]=value N=P2 */

Definition at line 15722 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and windowAggFinal().

◆ OP_And

#define OP_And   44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */

Definition at line 15610 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_AutoCommit

#define OP_AutoCommit   1

Definition at line 15567 of file sqlite3.c.

Referenced by resolveP2Values(), sqlite3EndTransaction(), and sqlite3VdbeExec().

◆ OP_BitAnd

#define OP_BitAnd   101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */

Definition at line 15667 of file sqlite3.c.

Referenced by sqlite3ExprCodeIN(), sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_BitNot

#define OP_BitNot   112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */

Definition at line 15678 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_BitOr

#define OP_BitOr   102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */

Definition at line 15668 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_Blob

#define OP_Blob   74 /* synopsis: r[P2]=P4 (len=P1) */

Definition at line 15640 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), sqlite3StartTable(), and sqlite3VdbeExec().

◆ OP_Cast

#define OP_Cast   84 /* synopsis: affinity(r[P1]) */

Definition at line 15650 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_Checkpoint

#define OP_Checkpoint   6

Definition at line 15572 of file sqlite3.c.

Referenced by resolveP2Values(), sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Clear

#define OP_Clear   137

Definition at line 15703 of file sqlite3.c.

Referenced by openStatTable(), sqlite3DeleteFrom(), sqlite3RefillIndex(), and sqlite3VdbeExec().

◆ OP_Close

◆ OP_CollSeq

#define OP_CollSeq   81

◆ OP_Column

◆ OP_ColumnsUsed

#define OP_ColumnsUsed   117

Definition at line 15683 of file sqlite3.c.

Referenced by sqlite3FindInIndex(), sqlite3VdbeExec(), and sqlite3WhereBegin().

◆ OP_Compare

#define OP_Compare   86 /* synopsis: r[P1@P3] <-> r[P2@P3] */

◆ OP_Concat

#define OP_Concat   110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */

Definition at line 15676 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Copy

◆ OP_Count

#define OP_Count   92 /* synopsis: r[P2]=count() */

Definition at line 15658 of file sqlite3.c.

Referenced by analyzeOneTable(), sqlite3Pragma(), sqlite3Select(), and sqlite3VdbeExec().

◆ OP_CreateBtree

#define OP_CreateBtree   139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */

Definition at line 15705 of file sqlite3.c.

Referenced by sqlite3CreateIndex(), sqlite3StartTable(), and sqlite3VdbeExec().

◆ OP_CursorHint

#define OP_CursorHint   171

Definition at line 15737 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_CursorLock

#define OP_CursorLock   159

Definition at line 15725 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3VdbeExec().

◆ OP_CursorUnlock

#define OP_CursorUnlock   160

Definition at line 15726 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3VdbeExec().

◆ OP_DecrJumpZero

#define OP_DecrJumpZero   59 /* jump, synopsis: if (--r[P1])==0 goto P2 */

◆ OP_DeferredSeek

#define OP_DeferredSeek   133 /* synopsis: Move P3 to P1.rowid if needed */

Definition at line 15699 of file sqlite3.c.

Referenced by codeDeferredSeek(), and sqlite3VdbeExec().

◆ OP_Delete

◆ OP_Destroy

#define OP_Destroy   136

Definition at line 15702 of file sqlite3.c.

Referenced by destroyRootPage(), and sqlite3VdbeExec().

◆ OP_Divide

#define OP_Divide   108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */

Definition at line 15674 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_DropIndex

#define OP_DropIndex   144

Definition at line 15710 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_DropTable

#define OP_DropTable   143

Definition at line 15709 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_DropTrigger

#define OP_DropTrigger   145

Definition at line 15711 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_ElseNotEq

#define OP_ElseNotEq   58 /* jump, same as TK_ESCAPE */

Definition at line 15624 of file sqlite3.c.

Referenced by codeVectorCompare(), and sqlite3VdbeExec().

◆ OP_EndCoroutine

#define OP_EndCoroutine   66

Definition at line 15632 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_Eq

◆ OP_Expire

#define OP_Expire   158

Definition at line 15724 of file sqlite3.c.

Referenced by sqlite3Analyze(), sqlite3CreateIndex(), sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Explain

#define OP_Explain   174

◆ OP_FinishSeek

#define OP_FinishSeek   135

Definition at line 15701 of file sqlite3.c.

Referenced by sqlite3Update(), and sqlite3VdbeExec().

◆ OP_FkCounter

#define OP_FkCounter   149 /* synopsis: fkctr[P1]+=P2 */

Definition at line 15715 of file sqlite3.c.

Referenced by fkLookupParent(), fkScanChildren(), sqlite3FkCheck(), and sqlite3VdbeExec().

◆ OP_FkIfZero

#define OP_FkIfZero   47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */

◆ OP_Found

#define OP_Found   30 /* jump, synopsis: key=r[P3@P4] */

◆ OP_Function

#define OP_Function   64 /* synopsis: r[P3]=func(r[P2@NP]) */

Definition at line 15630 of file sqlite3.c.

Referenced by sqlite3VdbeAddFunctionCall(), and sqlite3VdbeExec().

◆ OP_Ge

#define OP_Ge   57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */

◆ OP_Gosub

◆ OP_Goto

◆ OP_Gt

◆ OP_Halt

◆ OP_HaltIfNull

#define OP_HaltIfNull   67 /* synopsis: if r[P3]=null halt */

Definition at line 15633 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3VdbeExec().

◆ OP_IdxDelete

#define OP_IdxDelete   132 /* synopsis: key=r[P2@P3] */

Definition at line 15698 of file sqlite3.c.

Referenced by selectInnerLoop(), sqlite3GenerateRowIndexDelete(), and sqlite3VdbeExec().

◆ OP_IdxGE

#define OP_IdxGE   41 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15607 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_IdxGT

#define OP_IdxGT   39 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15605 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_IdxInsert

◆ OP_IdxLE

#define OP_IdxLE   38 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15604 of file sqlite3.c.

Referenced by generateSortTail(), and sqlite3VdbeExec().

◆ OP_IdxLT

#define OP_IdxLT   40 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15606 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_IdxRowid

#define OP_IdxRowid   134 /* synopsis: r[P2]=rowid */

◆ OP_If

◆ OP_IfNoHope

#define OP_IfNoHope   27 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15593 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3WhereEnd().

◆ OP_IfNot

◆ OP_IfNotOpen

#define OP_IfNotOpen   26 /* jump, synopsis: if( !csr[P1] ) goto P2 */

Definition at line 15592 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3WhereEnd().

◆ OP_IfNotZero

#define OP_IfNotZero   49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */

Definition at line 15615 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_IfNullRow

#define OP_IfNullRow   21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */

◆ OP_IfPos

#define OP_IfPos   48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */

◆ OP_IfSmaller

#define OP_IfSmaller   34 /* jump */

Definition at line 15600 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_IncrVacuum

#define OP_IncrVacuum   60 /* jump */

Definition at line 15626 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Init

#define OP_Init   62 /* jump, synopsis: Start at P2 */

Definition at line 15628 of file sqlite3.c.

Referenced by sqlite3FinishCoding(), sqlite3VdbeExec(), and sqlite3VdbeNextOpcode().

◆ OP_InitCoroutine

#define OP_InitCoroutine   13 /* jump */

◆ OP_Insert

◆ OP_Int64

#define OP_Int64   70 /* synopsis: r[P2]=P4 */

Definition at line 15636 of file sqlite3.c.

Referenced by codeInteger(), and sqlite3VdbeExec().

◆ OP_IntCopy

#define OP_IntCopy   79 /* synopsis: r[P2]=r[P1] */

Definition at line 15645 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3VdbeExec().

◆ OP_Integer

◆ OP_IntegrityCk

#define OP_IntegrityCk   146

Definition at line 15712 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_IsNull

◆ OP_IsTrue

#define OP_IsTrue   87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */

Definition at line 15653 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_JournalMode

#define OP_JournalMode   7

Definition at line 15573 of file sqlite3.c.

Referenced by resolveP2Values(), sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Jump

◆ OP_Last

#define OP_Last   33 /* jump */

◆ OP_Le

#define OP_Le   55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */

◆ OP_LoadAnalysis

#define OP_LoadAnalysis   142

Definition at line 15708 of file sqlite3.c.

Referenced by loadAnalysis(), and sqlite3VdbeExec().

◆ OP_Lt

#define OP_Lt   56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */

◆ OP_MakeRecord

◆ OP_MaxPgcnt

#define OP_MaxPgcnt   169

Definition at line 15735 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_MemMax

#define OP_MemMax   151 /* synopsis: r[P1]=max(r[P1],r[P2]) */

Definition at line 15717 of file sqlite3.c.

Referenced by autoIncStep(), and sqlite3VdbeExec().

◆ OP_Move

#define OP_Move   76 /* synopsis: r[P2@P3]=r[P1@P3] */

Definition at line 15642 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_Multiply

#define OP_Multiply   107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */

Definition at line 15673 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_MustBeInt

#define OP_MustBeInt   15 /* jump */

◆ OP_Ne

◆ OP_NewRowid

◆ OP_Next

◆ OP_NoConflict

#define OP_NoConflict   28 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15594 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3VdbeExec().

◆ OP_Noop

#define OP_Noop   173

◆ OP_Not

#define OP_Not   19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */

Definition at line 15585 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_NotExists

#define OP_NotExists   32 /* jump, synopsis: intkey=r[P3] */

◆ OP_NotFound

#define OP_NotFound   29 /* jump, synopsis: key=r[P3@P4] */

◆ OP_NotNull

◆ OP_Null

◆ OP_NullRow

#define OP_NullRow   128

◆ OP_Offset

#define OP_Offset   88 /* synopsis: r[P3] = sqlite_offset(P1) */

Definition at line 15654 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), sqlite3VdbeExec(), and sqlite3WhereEnd().

◆ OP_OffsetLimit

#define OP_OffsetLimit   152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */

Definition at line 15718 of file sqlite3.c.

Referenced by computeLimitRegisters(), multiSelect(), and sqlite3VdbeExec().

◆ OP_Once

◆ OP_OpenAutoindex

#define OP_OpenAutoindex   99 /* synopsis: nColumn=P2 */

Definition at line 15665 of file sqlite3.c.

Referenced by constructAutomaticIndex(), and sqlite3VdbeExec().

◆ OP_OpenDup

#define OP_OpenDup   98

◆ OP_OpenEphemeral

◆ OP_OpenPseudo

#define OP_OpenPseudo   114 /* synopsis: P3 columns in r[P2] */

◆ OP_OpenRead

◆ OP_OpenWrite

◆ OP_Or

#define OP_Or   43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */

Definition at line 15609 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_Pagecount

#define OP_Pagecount   168

Definition at line 15734 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Param

#define OP_Param   148

Definition at line 15714 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_ParseSchema

#define OP_ParseSchema   141

Definition at line 15707 of file sqlite3.c.

Referenced by sqlite3VdbeAddParseSchemaOp(), and sqlite3VdbeExec().

◆ OP_Permutation

#define OP_Permutation   85

Definition at line 15651 of file sqlite3.c.

Referenced by multiSelectOrderBy(), and sqlite3VdbeExec().

◆ OP_Prev

#define OP_Prev   4 /* jump */

Definition at line 15570 of file sqlite3.c.

Referenced by codeEqualityTerm(), resolveP2Values(), sqlite3VdbeExec(), and sqlite3WhereEnd().

◆ OP_Program

#define OP_Program   46 /* jump */

Definition at line 15612 of file sqlite3.c.

Referenced by sqlite3CodeRowTriggerDirect(), and sqlite3VdbeExec().

◆ OP_PureFunc

#define OP_PureFunc   63 /* synopsis: r[P3]=func(r[P2@NP]) */

Definition at line 15629 of file sqlite3.c.

Referenced by sqlite3NotPureFunc(), sqlite3VdbeAddFunctionCall(), and sqlite3VdbeExec().

◆ OP_ReadCookie

#define OP_ReadCookie   93

◆ OP_Real

#define OP_Real   150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */

Definition at line 15716 of file sqlite3.c.

Referenced by codeReal(), and sqlite3VdbeExec().

◆ OP_RealAffinity

#define OP_RealAffinity   83

◆ OP_ReleaseReg

#define OP_ReleaseReg   172 /* synopsis: release r[P1@P2] mask P3 */

Definition at line 15738 of file sqlite3.c.

Referenced by sqlite3Insert(), and sqlite3VdbeExec().

◆ OP_Remainder

#define OP_Remainder   109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */

Definition at line 15675 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_ReopenIdx

#define OP_ReopenIdx   95 /* synopsis: root=P2 iDb=P3 */

Definition at line 15661 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), sqlite3VdbeNextOpcode(), and sqlite3WhereBegin().

◆ OP_ResetCount

#define OP_ResetCount   123

Definition at line 15689 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_ResetSorter

#define OP_ResetSorter   138

Definition at line 15704 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), sqlite3WindowCodeStep(), and windowInitAccum().

◆ OP_ResultRow

◆ OP_Return

◆ OP_Rewind

◆ OP_RowData

#define OP_RowData   126 /* synopsis: r[P2]=data */

◆ OP_Rowid

◆ OP_RowSetAdd

#define OP_RowSetAdd   147 /* synopsis: rowset(P1)=r[P2] */

Definition at line 15713 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), sqlite3Update(), and sqlite3VdbeExec().

◆ OP_RowSetRead

#define OP_RowSetRead   42 /* jump, synopsis: r[P3]=rowset(P1) */

Definition at line 15608 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), sqlite3Update(), and sqlite3VdbeExec().

◆ OP_RowSetTest

#define OP_RowSetTest   45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */

Definition at line 15611 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_Savepoint

#define OP_Savepoint   0

Definition at line 15566 of file sqlite3.c.

Referenced by resolveP2Values(), and sqlite3VdbeExec().

◆ OP_SCopy

◆ OP_SeekEnd

#define OP_SeekEnd   129

Definition at line 15695 of file sqlite3.c.

Referenced by sqlite3RefillIndex(), sqlite3VdbeExec(), and xferOptimization().

◆ OP_SeekGE

#define OP_SeekGE   24 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15590 of file sqlite3.c.

Referenced by generateSortTail(), sqlite3VdbeExec(), windowAggStep(), and windowFullScan().

◆ OP_SeekGT

#define OP_SeekGT   25 /* jump, synopsis: key=r[P3@P4] */

◆ OP_SeekHit

#define OP_SeekHit   118 /* synopsis: seekHit=P2 */

Definition at line 15684 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_SeekLE

#define OP_SeekLE   23 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15589 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_SeekLT

#define OP_SeekLT   22 /* jump, synopsis: key=r[P3@P4] */

Definition at line 15588 of file sqlite3.c.

Referenced by codeAllEqualityTerms(), sqlite3VdbeExec(), and sqlite3WhereEnd().

◆ OP_SeekRowid

#define OP_SeekRowid   31 /* jump, synopsis: intkey=r[P3] */

◆ OP_Sequence

#define OP_Sequence   119 /* synopsis: r[P2]=cursor[P1].ctr++ */

Definition at line 15685 of file sqlite3.c.

Referenced by selectInnerLoop(), sqlite3VdbeExec(), and translateColumnToCopy().

◆ OP_SequenceTest

#define OP_SequenceTest   113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */

Definition at line 15679 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_SetCookie

#define OP_SetCookie   94

◆ OP_ShiftLeft

#define OP_ShiftLeft   103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */

Definition at line 15669 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_ShiftRight

#define OP_ShiftRight   104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */

Definition at line 15670 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_SoftNull

#define OP_SoftNull   73 /* synopsis: r[P1]=NULL */

Definition at line 15639 of file sqlite3.c.

Referenced by sqlite3Insert(), and sqlite3VdbeExec().

◆ OP_Sort

#define OP_Sort   36 /* jump */

Definition at line 15602 of file sqlite3.c.

Referenced by generateSortTail(), and sqlite3VdbeExec().

◆ OP_SorterCompare

#define OP_SorterCompare   124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */

Definition at line 15690 of file sqlite3.c.

Referenced by sqlite3RefillIndex(), and sqlite3VdbeExec().

◆ OP_SorterData

#define OP_SorterData   125 /* synopsis: r[P2]=data */

Definition at line 15691 of file sqlite3.c.

Referenced by generateSortTail(), sqlite3RefillIndex(), sqlite3Select(), and sqlite3VdbeExec().

◆ OP_SorterInsert

#define OP_SorterInsert   131 /* synopsis: key=r[P2] */

Definition at line 15697 of file sqlite3.c.

Referenced by sqlite3RefillIndex(), sqlite3Select(), and sqlite3VdbeExec().

◆ OP_SorterNext

#define OP_SorterNext   3 /* jump */

◆ OP_SorterOpen

#define OP_SorterOpen   111

Definition at line 15677 of file sqlite3.c.

Referenced by sqlite3RefillIndex(), sqlite3Select(), and sqlite3VdbeExec().

◆ OP_SorterSort

#define OP_SorterSort   35 /* jump */

Definition at line 15601 of file sqlite3.c.

Referenced by generateSortTail(), sqlite3RefillIndex(), sqlite3Select(), and sqlite3VdbeExec().

◆ OP_SqlExec

#define OP_SqlExec   140

Definition at line 15706 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_String

#define OP_String   71 /* synopsis: r[P2]='P4' (len=P1) */

Definition at line 15637 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_String8

#define OP_String8   115 /* same as TK_STRING, synopsis: r[P2]='P4' */

◆ OP_Subtract

#define OP_Subtract   106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */

◆ OP_TableLock

#define OP_TableLock   161 /* synopsis: iDb=P1 root=P2 write=P3 */

Definition at line 15727 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_Trace

#define OP_Trace   170

Definition at line 15736 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_Transaction

#define OP_Transaction   2

Definition at line 15568 of file sqlite3.c.

Referenced by resolveP2Values(), sqlite3FinishCoding(), sqlite3Pragma(), and sqlite3VdbeExec().

◆ OP_Vacuum

#define OP_Vacuum   8

Definition at line 15574 of file sqlite3.c.

Referenced by resolveP2Values(), sqlite3Vacuum(), and sqlite3VdbeExec().

◆ OP_Variable

#define OP_Variable   75 /* synopsis: r[P2]=parameter(P1,P4) */

Definition at line 15641 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OP_VBegin

#define OP_VBegin   162

Definition at line 15728 of file sqlite3.c.

Referenced by sqlite3FinishCoding(), sqlite3StartTable(), and sqlite3VdbeExec().

◆ OP_VColumn

#define OP_VColumn   166 /* synopsis: r[P3]=vcolumn(P2) */

Definition at line 15732 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and updateVirtualTable().

◆ OP_VCreate

#define OP_VCreate   163

Definition at line 15729 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_VDestroy

#define OP_VDestroy   164

Definition at line 15730 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_VFilter

#define OP_VFilter   9 /* jump, synopsis: iplan=r[P3] zplan='P4' */

Definition at line 15575 of file sqlite3.c.

Referenced by resolveP2Values(), and sqlite3VdbeExec().

◆ OP_VNext

#define OP_VNext   61 /* jump */

Definition at line 15627 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3WhereEnd().

◆ OP_VOpen

#define OP_VOpen   165

Definition at line 15731 of file sqlite3.c.

Referenced by readsTable(), sqlite3VdbeExec(), and sqlite3WhereBegin().

◆ OP_VRename

#define OP_VRename   167

Definition at line 15733 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OP_VUpdate

#define OP_VUpdate   10 /* synopsis: data=r[P3@P2] */

◆ OP_Yield

◆ OpcodeRewriteTrace

#define OpcodeRewriteTrace ( D,
K,
P )   /* no-op */

Definition at line 150872 of file sqlite3.c.

Referenced by sqlite3WhereEnd().

◆ OpenCounter

#define OpenCounter ( X)

Definition at line 33835 of file sqlite3.c.

Referenced by closeUnixFile().

◆ OPFLAG_APPEND

◆ OPFLAG_AUXDELETE

#define OPFLAG_AUXDELETE   0x04 /* OP_Delete: index in a DELETE op */

Definition at line 18853 of file sqlite3.c.

Referenced by sqlite3GenerateRowDelete(), and sqlite3VdbeExec().

◆ OPFLAG_BULKCSR

#define OPFLAG_BULKCSR   0x01 /* OP_Open** used to open bulk cursor */

Definition at line 18847 of file sqlite3.c.

Referenced by sqlite3RefillIndex(), sqlite3VdbeExec(), and xferOptimization().

◆ OPFLAG_EPHEM

#define OPFLAG_EPHEM   0x01 /* OP_Column: Ephemeral output is ok */

Definition at line 18839 of file sqlite3.c.

◆ OPFLAG_FORDELETE

#define OPFLAG_FORDELETE   0x08 /* OP_Open should use BTREE_FORDELETE */

Definition at line 18849 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), sqlite3VdbeExec(), and sqlite3WhereBegin().

◆ OPFLAG_ISNOOP

#define OPFLAG_ISNOOP   0x40 /* OP_Delete does pre-update-hook only */

◆ OPFLAG_ISUPDATE

#define OPFLAG_ISUPDATE   0x04 /* This OP_Insert is an sql UPDATE */

Definition at line 18841 of file sqlite3.c.

Referenced by sqlite3CompleteInsertion(), sqlite3Update(), and sqlite3VdbeExec().

◆ OPFLAG_LASTROWID

#define OPFLAG_LASTROWID   0x20 /* Set to update db->lastRowid */

Definition at line 18840 of file sqlite3.c.

Referenced by sqlite3CompleteInsertion(), sqlite3VdbeExec(), and xferOptimization().

◆ OPFLAG_LENGTHARG

#define OPFLAG_LENGTHARG   0x40 /* OP_Column only used for length() */

Definition at line 18845 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ OPFLAG_NCHANGE

#define OPFLAG_NCHANGE   0x01 /* OP_Insert: Set to update db->nChange */

◆ OPFLAG_NOCHNG

#define OPFLAG_NOCHNG   0x01 /* OP_VColumn nochange for UPDATE */

Definition at line 18838 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and updateVirtualTable().

◆ OPFLAG_NOCHNG_MAGIC

#define OPFLAG_NOCHNG_MAGIC   0x6d /* OP_MakeRecord: serialtype 10 is ok */

Definition at line 18854 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and updateVirtualTable().

◆ OPFLAG_P2ISREG

#define OPFLAG_P2ISREG   0x10 /* P2 to OP_Open** is a register number */

◆ OPFLAG_PERMUTE

#define OPFLAG_PERMUTE   0x01 /* OP_Compare: use the permutation */

Definition at line 18851 of file sqlite3.c.

Referenced by multiSelectOrderBy(), and sqlite3VdbeExec().

◆ OPFLAG_SAVEPOSITION

#define OPFLAG_SAVEPOSITION   0x02 /* OP_Delete/Insert: save cursor pos */

◆ OPFLAG_SEEKEQ

#define OPFLAG_SEEKEQ   0x02 /* OP_Open** cursor uses EQ seek only */

Definition at line 18848 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3WhereBegin().

◆ OPFLAG_TYPEOFARG

#define OPFLAG_TYPEOFARG   0x80 /* OP_Column only used for typeof() */

◆ OPFLAG_USESEEKRESULT

#define OPFLAG_USESEEKRESULT   0x10 /* Try to avoid a seek in BtreeInsert() */

◆ OPFLG_IN1

#define OPFLG_IN1   0x02 /* in1: P1 is an input */

Definition at line 15748 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OPFLG_IN2

#define OPFLG_IN2   0x04 /* in2: P2 is an input */

Definition at line 15749 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OPFLG_IN3

#define OPFLG_IN3   0x08 /* in3: P3 is an input */

Definition at line 15750 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OPFLG_INITIALIZER

#define OPFLG_INITIALIZER
Value:
{\
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
/* 24 */ 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09,\
/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
/* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\
/* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\
/* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
/* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\
/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
}

Definition at line 15753 of file sqlite3.c.

15753#define OPFLG_INITIALIZER {\
15754/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
15755/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
15756/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
15757/* 24 */ 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09,\
15758/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15759/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
15760/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15761/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
15762/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
15763/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15764/* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\
15765/* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15766/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
15767/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
15768/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\
15769/* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15770/* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15771/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15772/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\
15773/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15774/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15775/* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15776}

◆ OPFLG_JUMP

#define OPFLG_JUMP   0x01 /* jump: P2 holds jmp target */

◆ OPFLG_OUT2

#define OPFLG_OUT2   0x10 /* out2: P2 is an output */

Definition at line 15751 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OPFLG_OUT3

#define OPFLG_OUT3   0x20 /* out3: P3 is an output */

Definition at line 15752 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ OpHelp

#define OpHelp ( X)

Definition at line 33158 of file sqlite3.c.

Referenced by sqlite3OpcodeName().

◆ OptimizationDisabled

#define OptimizationDisabled ( db,
mask )   (((db)->dbOptFlags&(mask))!=0)

Definition at line 17063 of file sqlite3.c.

Referenced by flattenSubquery(), sqlite3WhereBegin(), and wherePathSatisfiesOrderBy().

◆ OptimizationEnabled

#define OptimizationEnabled ( db,
mask )   (((db)->dbOptFlags&(mask))==0)

◆ OS_VXWORKS

#define OS_VXWORKS   0

Definition at line 928 of file sqlite3.c.

Referenced by full_fsync(), and unixDelete().

◆ osAccess

#define osAccess   ((int(*)(const char*,int))aSyscall[2].pCurrent)

◆ osClose

#define osClose   ((int(*)(int))aSyscall[1].pCurrent)

◆ osFallocate

#define osFallocate   ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent)

◆ osFchmod

#define osFchmod   ((int(*)(int,mode_t))aSyscall[14].pCurrent)

◆ osFchown

#define osFchown   ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)

◆ osFcntl

#define osFcntl   ((int(*)(int,int,...))aSyscall[7].pCurrent)

◆ osFstat

#define osFstat   ((int(*)(int,struct stat*))aSyscall[5].pCurrent)

◆ osFtruncate

#define osFtruncate   ((int(*)(int,off_t))aSyscall[6].pCurrent)

◆ osGetcwd

#define osGetcwd   ((char*(*)(char*,size_t))aSyscall[3].pCurrent)

◆ osGeteuid

#define osGeteuid   ((uid_t(*)(void))aSyscall[21].pCurrent)

◆ osGetpagesize

#define osGetpagesize   ((int(*)(void))aSyscall[25].pCurrent)

◆ osGetpid

#define osGetpid ( X)    (pid_t)getpid()

Definition at line 33531 of file sqlite3.c.

Referenced by dotlockUnlock(), posixUnlock(), unixLock(), unixOpen(), unixRandomness(), and unixShmLock().

◆ osLstat

#define osLstat   ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)

◆ osMkdir

#define osMkdir   ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)

◆ osMmap

#define osMmap   ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent)

◆ osMremap

#define osMremap   ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent)

◆ osMunmap

#define osMunmap   ((int(*)(void*,size_t))aSyscall[23].pCurrent)

◆ osOpen

#define osOpen   ((int(*)(const char*,int,int))aSyscall[0].pCurrent)

◆ osOpenDirectory

#define osOpenDirectory   ((int(*)(const char*,int*))aSyscall[17].pCurrent)

◆ osPread

#define osPread   ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)

◆ osPread64

#define osPread64   ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)

◆ osPwrite

#define osPwrite
Value:
((ssize_t(*)(int,const void*,size_t,off_t))\
static struct unix_syscall aSyscall[]
sqlite3_syscall_ptr pCurrent
Definition sqlite3.c:33927

◆ osPwrite64

#define osPwrite64
Value:
((ssize_t(*)(int,const void*,size_t,off64_t))\

◆ osRead

#define osRead   ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)

◆ osReadlink

#define osReadlink   ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent)

◆ osRmdir

#define osRmdir   ((int(*)(const char*))aSyscall[19].pCurrent)

◆ osSetPosixAdvisoryLock

#define osSetPosixAdvisoryLock ( h,
x,
t )   osFcntl(h,F_SETLK,x)

Definition at line 35103 of file sqlite3.c.

Referenced by unixFileLock(), and unixShmSystemLock().

◆ osStat

#define osStat   ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)

◆ OSTRACE

◆ osUnlink

#define osUnlink   ((int(*)(const char*))aSyscall[16].pCurrent)

◆ osWrite

#define osWrite   ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)

◆ P4_ADVANCE

#define P4_ADVANCE   (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */

Definition at line 15510 of file sqlite3.c.

Referenced by resolveP2Values(), and sqlite3VdbeDisplayP4().

◆ P4_COLLSEQ

◆ P4_DYNAMIC

◆ P4_DYNBLOB

#define P4_DYNBLOB   (-17) /* Pointer to memory from sqliteMalloc() */

Definition at line 15524 of file sqlite3.c.

Referenced by analyzeOneTable(), and sqlite3VdbeDisplayP4().

◆ P4_EXPR

#define P4_EXPR   (-10) /* P4 is a pointer to an Expr tree */

Definition at line 15517 of file sqlite3.c.

Referenced by sqlite3VdbeDisplayP4(), and sqlite3VdbeExec().

◆ P4_FREE_IF_LE

#define P4_FREE_IF_LE   (-7)

Definition at line 15513 of file sqlite3.c.

Referenced by vdbeFreeOpArray().

◆ P4_FUNCCTX

#define P4_FUNCCTX   (-16) /* P4 is a pointer to an sqlite3_context object */

Definition at line 15523 of file sqlite3.c.

Referenced by sqlite3VdbeAddFunctionCall(), sqlite3VdbeDisplayP4(), and sqlite3VdbeExec().

◆ P4_FUNCDEF

#define P4_FUNCDEF   (-8) /* P4 is a pointer to a FuncDef structure */

◆ P4_INT32

#define P4_INT32   (-3) /* P4 is a 32-bit signed integer */

◆ P4_INT64

#define P4_INT64   (-14) /* P4 is a 64-bit signed integer */

◆ P4_INTARRAY

#define P4_INTARRAY   (-15) /* P4 is a vector of 32-bit integers */

◆ P4_KEYINFO

◆ P4_MEM

#define P4_MEM   (-11) /* P4 is a pointer to a Mem* structure */

Definition at line 15518 of file sqlite3.c.

Referenced by sqlite3ColumnDefault(), sqlite3VdbeDisplayP4(), and sqlite3VdbeExec().

◆ P4_NOTUSED

#define P4_NOTUSED   0 /* The P4 parameter is not used */

Definition at line 15504 of file sqlite3.c.

Referenced by sqlite3VdbeAddOpList(), and sqlite3VdbeAppendP4().

◆ P4_REAL

#define P4_REAL   (-13) /* P4 is a 64-bit floating point value */

Definition at line 15520 of file sqlite3.c.

Referenced by codeReal(), and sqlite3VdbeDisplayP4().

◆ P4_STATIC

◆ P4_SUBPROGRAM

#define P4_SUBPROGRAM   (-4) /* P4 is a pointer to a SubProgram structure */

◆ P4_TABLE

◆ P4_TRANSIENT

#define P4_TRANSIENT   0 /* P4 is a pointer to a transient string */

Definition at line 15505 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3GenerateIndexKey().

◆ P4_VTAB

#define P4_VTAB   (-12) /* P4 is a pointer to an sqlite3_vtab structure */

◆ P5_ConstraintCheck

#define P5_ConstraintCheck   3

Definition at line 15529 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks().

◆ P5_ConstraintFK

#define P5_ConstraintFK   4

Definition at line 15530 of file sqlite3.c.

Referenced by fkLookupParent(), and sqlite3FkDropTable().

◆ P5_ConstraintNotNull

#define P5_ConstraintNotNull   1

Definition at line 15527 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks().

◆ P5_ConstraintUnique

#define P5_ConstraintUnique   2

Definition at line 15528 of file sqlite3.c.

◆ PAGE_IS_PINNED

#define PAGE_IS_PINNED ( p)    ((p)->pLruNext==0)

Definition at line 49880 of file sqlite3.c.

Referenced by pcache1Unpin().

◆ PAGE_IS_UNPINNED

#define PAGE_IS_UNPINNED ( p)    ((p)->pLruNext!=0)

◆ PAGER_CACHESPILL

#define PAGER_CACHESPILL   0x20 /* PRAGMA cache_spill=ON */

Definition at line 14856 of file sqlite3.c.

Referenced by setAllPagerFlags(), and sqlite3PagerSetFlags().

◆ PAGER_CKPT_FULLFSYNC

#define PAGER_CKPT_FULLFSYNC   0x10 /* PRAGMA checkpoint_fullfsync=ON */

Definition at line 14855 of file sqlite3.c.

Referenced by setAllPagerFlags(), and sqlite3PagerSetFlags().

◆ pager_datahash

#define pager_datahash ( X,
Y )   0

Definition at line 52966 of file sqlite3.c.

Referenced by pager_playback_one_page().

◆ PAGER_ERROR

◆ PAGER_FLAGS_MASK

#define PAGER_FLAGS_MASK   0x38 /* All above except SYNCHRONOUS */

Definition at line 14857 of file sqlite3.c.

Referenced by attachFunc(), and setAllPagerFlags().

◆ PAGER_FULLFSYNC

#define PAGER_FULLFSYNC   0x08 /* PRAGMA fullfsync=ON */

Definition at line 14854 of file sqlite3.c.

Referenced by setAllPagerFlags(), and sqlite3PagerSetFlags().

◆ PAGER_GET_NOCONTENT

#define PAGER_GET_NOCONTENT   0x01 /* Do not load data from disk */

Definition at line 14838 of file sqlite3.c.

Referenced by allocateBtreePage(), btreeGetPage(), and getPageNormal().

◆ PAGER_GET_READONLY

#define PAGER_GET_READONLY   0x02 /* Read-only page is acceptable */

Definition at line 14839 of file sqlite3.c.

Referenced by accessPayload(), btreeCursor(), btreeGetPage(), and getOverflowPage().

◆ PAGER_INCR

#define PAGER_INCR ( v)

Definition at line 52425 of file sqlite3.c.

Referenced by pager_write_pagelist(), and readDbPage().

◆ PAGER_JOURNALMODE_DELETE

#define PAGER_JOURNALMODE_DELETE   0 /* Commit by deleting journal file */

◆ PAGER_JOURNALMODE_MEMORY

◆ PAGER_JOURNALMODE_OFF

◆ PAGER_JOURNALMODE_PERSIST

#define PAGER_JOURNALMODE_PERSIST   1 /* Commit by zeroing journal header */

◆ PAGER_JOURNALMODE_QUERY

#define PAGER_JOURNALMODE_QUERY   (-1) /* Query the value of journalmode */

Definition at line 14827 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ PAGER_JOURNALMODE_TRUNCATE

#define PAGER_JOURNALMODE_TRUNCATE   3 /* Commit by truncating journal */

◆ PAGER_JOURNALMODE_WAL

◆ PAGER_LOCKINGMODE_EXCLUSIVE

#define PAGER_LOCKINGMODE_EXCLUSIVE   1

◆ PAGER_LOCKINGMODE_NORMAL

#define PAGER_LOCKINGMODE_NORMAL   0

◆ PAGER_LOCKINGMODE_QUERY

#define PAGER_LOCKINGMODE_QUERY   -1

Definition at line 14816 of file sqlite3.c.

Referenced by getLockingMode(), sqlite3PagerLockingMode(), and sqlite3Pragma().

◆ PAGER_MEMORY

#define PAGER_MEMORY   0x0002 /* In-memory database */

Definition at line 14811 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ PAGER_MJ_PGNO

#define PAGER_MJ_PGNO ( x)    ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))

◆ PAGER_OMIT_JOURNAL

#define PAGER_OMIT_JOURNAL   0x0001 /* Do not use a rollback journal */

Definition at line 14810 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ PAGER_OPEN

◆ pager_pagehash

#define pager_pagehash ( X)    0

Definition at line 52967 of file sqlite3.c.

Referenced by pager_write_pagelist(), and readDbPage().

◆ PAGER_READER

◆ pager_set_pagehash

#define pager_set_pagehash ( X)

◆ PAGER_STAT_HIT

#define PAGER_STAT_HIT   0

Definition at line 52409 of file sqlite3.c.

Referenced by getPageNormal(), and sqlite3PagerCacheStat().

◆ PAGER_STAT_MISS

#define PAGER_STAT_MISS   1

Definition at line 52410 of file sqlite3.c.

Referenced by getPageNormal(), and sqlite3PagerCacheStat().

◆ PAGER_STAT_SPILL

#define PAGER_STAT_SPILL   3

Definition at line 52412 of file sqlite3.c.

Referenced by pagerStress(), and sqlite3PagerCacheStat().

◆ PAGER_STAT_WRITE

#define PAGER_STAT_WRITE   2

◆ PAGER_SYNCHRONOUS_EXTRA

#define PAGER_SYNCHRONOUS_EXTRA   0x04 /* PRAGMA synchronous=EXTRA */

Definition at line 14852 of file sqlite3.c.

Referenced by sqlite3PagerSetFlags().

◆ PAGER_SYNCHRONOUS_FULL

#define PAGER_SYNCHRONOUS_FULL   0x03 /* PRAGMA synchronous=FULL */

Definition at line 14851 of file sqlite3.c.

Referenced by attachFunc(), and sqlite3PagerSetFlags().

◆ PAGER_SYNCHRONOUS_MASK

#define PAGER_SYNCHRONOUS_MASK   0x07 /* Mask for four values above */

Definition at line 14853 of file sqlite3.c.

Referenced by setAllPagerFlags(), sqlite3PagerSetFlags(), and sqlite3Pragma().

◆ PAGER_SYNCHRONOUS_NORMAL

#define PAGER_SYNCHRONOUS_NORMAL   0x02 /* PRAGMA synchronous=NORMAL */

Definition at line 14850 of file sqlite3.c.

◆ PAGER_SYNCHRONOUS_OFF

#define PAGER_SYNCHRONOUS_OFF   0x01 /* PRAGMA synchronous=OFF */

Definition at line 14849 of file sqlite3.c.

Referenced by openDatabase(), sqlite3PagerSetFlags(), and vdbeCommit().

◆ PAGER_WRITER_CACHEMOD

◆ PAGER_WRITER_DBMOD

◆ PAGER_WRITER_FINISHED

#define PAGER_WRITER_FINISHED   5

◆ PAGER_WRITER_LOCKED

◆ PAGERID

◆ PAGERTRACE

◆ pagerUseWal

◆ PARSE_HDR_SZ

#define PARSE_HDR_SZ   offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/

Definition at line 18789 of file sqlite3.c.

◆ PARSE_MODE_DECLARE_VTAB

#define PARSE_MODE_DECLARE_VTAB   1

Definition at line 18782 of file sqlite3.c.

Referenced by sqlite3_declare_vtab().

◆ PARSE_MODE_NORMAL

#define PARSE_MODE_NORMAL   0

Definition at line 18781 of file sqlite3.c.

Referenced by sqlite3_declare_vtab(), and sqlite3ViewGetColumnNames().

◆ PARSE_MODE_RENAME

#define PARSE_MODE_RENAME   2

Definition at line 18783 of file sqlite3.c.

Referenced by renameParseSql().

◆ PARSE_MODE_UNMAP

#define PARSE_MODE_UNMAP   3

Definition at line 18784 of file sqlite3.c.

Referenced by sqlite3ExprListSetName(), and sqlite3RenameTokenMap().

◆ PARSE_RECURSE_SZ

#define PARSE_RECURSE_SZ   offsetof(Parse,sLastToken) /* Recursive part */

Definition at line 18790 of file sqlite3.c.

◆ PARSE_TAIL

#define PARSE_TAIL ( X)    (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */

Definition at line 18792 of file sqlite3.c.

Referenced by sqlite3NestedParse().

◆ PARSE_TAIL_SZ

#define PARSE_TAIL_SZ   (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */

Definition at line 18791 of file sqlite3.c.

Referenced by sqlite3NestedParse().

◆ PARTLY_WITHIN

#define PARTLY_WITHIN   1 /* Object partially overlaps query region */

Definition at line 10973 of file sqlite3.c.

◆ pcache1

◆ PCACHE1_MIGHT_USE_GROUP_MUTEX

#define PCACHE1_MIGHT_USE_GROUP_MUTEX   0

Definition at line 50002 of file sqlite3.c.

◆ pcache1EnterMutex

#define pcache1EnterMutex ( X)    assert((X)->mutex==0)

◆ pcache1LeaveMutex

#define pcache1LeaveMutex ( X)    assert((X)->mutex==0)

◆ PCACHE_DIRTYLIST_ADD

#define PCACHE_DIRTYLIST_ADD   2 /* Add pPage to the dirty list */

Definition at line 49022 of file sqlite3.c.

Referenced by pcacheManageDirtyList().

◆ PCACHE_DIRTYLIST_FRONT

#define PCACHE_DIRTYLIST_FRONT   3 /* Move pPage to the front of the list */

Definition at line 49023 of file sqlite3.c.

◆ PCACHE_DIRTYLIST_REMOVE

#define PCACHE_DIRTYLIST_REMOVE   1 /* Remove pPage from dirty list */

Definition at line 49021 of file sqlite3.c.

Referenced by pcacheManageDirtyList(), and sqlite3PcacheDrop().

◆ pcacheDump

#define pcacheDump ( X)

Definition at line 48968 of file sqlite3.c.

Referenced by pcacheManageDirtyList(), and sqlite3PcacheFetchStress().

◆ pcacheTrace

#define pcacheTrace ( X)

◆ PENDING_BYTE

#define PENDING_BYTE   sqlite3PendingByte

Definition at line 16423 of file sqlite3.c.

Referenced by posixUnlock(), unixLock(), unixRead(), and unixWrite().

◆ PENDING_BYTE_PAGE

◆ PENDING_LOCK

#define PENDING_LOCK   3

Definition at line 16362 of file sqlite3.c.

Referenced by unixLock().

◆ percent_rankFinalizeFunc

#define percent_rankFinalizeFunc   percent_rankValueFunc

Definition at line 151524 of file sqlite3.c.

◆ PGHDR_CLEAN

#define PGHDR_CLEAN   0x001 /* Page not on the PCache.pDirty list */

Definition at line 16070 of file sqlite3.c.

Referenced by pcacheFetchFinishWithInit().

◆ PGHDR_DIRTY

#define PGHDR_DIRTY   0x002 /* Page is on the PCache.pDirty list */

◆ PGHDR_DONT_WRITE

#define PGHDR_DONT_WRITE   0x010 /* Do not write content to disk */

Definition at line 16074 of file sqlite3.c.

Referenced by pager_write_pagelist(), and sqlite3PagerDontWrite().

◆ PGHDR_MMAP

#define PGHDR_MMAP   0x020 /* This is an mmap page object */

Definition at line 16075 of file sqlite3.c.

Referenced by sqlite3PagerUnrefNotNull(), and sqlite3PagerWrite().

◆ PGHDR_NEED_SYNC

#define PGHDR_NEED_SYNC
Value:
0x008 /* Fsync the rollback journal before
** writing this page to the database */

Definition at line 16073 of file sqlite3.c.

Referenced by pager_playback_one_page(), pager_write(), pager_write_pagelist(), pagerStress(), pagerWriteLargeSector(), pcacheManageDirtyList(), sqlite3PagerDontWrite(), sqlite3PagerMovepage(), and sqlite3PcacheFetchStress().

◆ PGHDR_WAL_APPEND

#define PGHDR_WAL_APPEND   0x040 /* Appended to wal file */

Definition at line 16077 of file sqlite3.c.

◆ PGHDR_WRITEABLE

#define PGHDR_WRITEABLE   0x004 /* Journaled and ready to modify */

Definition at line 16072 of file sqlite3.c.

Referenced by pager_write(), and sqlite3PagerWrite().

◆ PragFlg_NeedSchema

#define PragFlg_NeedSchema   0x01 /* Force schema load before running */

Definition at line 125174 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragFlg_NoColumns

#define PragFlg_NoColumns   0x02 /* OP_ResultRow called with zero columns */

Definition at line 125175 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragFlg_NoColumns1

#define PragFlg_NoColumns1   0x04 /* zero columns if RHS argument is present */

Definition at line 125176 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragFlg_ReadOnly

#define PragFlg_ReadOnly   0x08 /* Read-only HEADER_VALUE */

Definition at line 125177 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragFlg_Result0

#define PragFlg_Result0   0x10 /* Acts as query when no argument */

Definition at line 125178 of file sqlite3.c.

Referenced by sqlite3PragmaVtabRegister().

◆ PragFlg_Result1

#define PragFlg_Result1   0x20 /* Acts as query when has one argument */

Definition at line 125179 of file sqlite3.c.

Referenced by sqlite3PragmaVtabRegister().

◆ PragFlg_SchemaOpt

#define PragFlg_SchemaOpt   0x40 /* Schema restricts name search if present */

Definition at line 125180 of file sqlite3.c.

◆ PragFlg_SchemaReq

#define PragFlg_SchemaReq   0x80 /* Schema required - "main" is default */

Definition at line 125181 of file sqlite3.c.

◆ PragTyp_ACTIVATE_EXTENSIONS

#define PragTyp_ACTIVATE_EXTENSIONS   0

Definition at line 125127 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_ANALYSIS_LIMIT

#define PragTyp_ANALYSIS_LIMIT   1

Definition at line 125128 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_AUTO_VACUUM

#define PragTyp_AUTO_VACUUM   3

Definition at line 125130 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_BUSY_TIMEOUT

#define PragTyp_BUSY_TIMEOUT   5

Definition at line 125132 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_CACHE_SIZE

#define PragTyp_CACHE_SIZE   6

Definition at line 125133 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_CACHE_SPILL

#define PragTyp_CACHE_SPILL   7

Definition at line 125134 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_CASE_SENSITIVE_LIKE

#define PragTyp_CASE_SENSITIVE_LIKE   8

Definition at line 125135 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_COLLATION_LIST

#define PragTyp_COLLATION_LIST   9

Definition at line 125136 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_COMPILE_OPTIONS

#define PragTyp_COMPILE_OPTIONS   10

Definition at line 125137 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_DATA_STORE_DIRECTORY

#define PragTyp_DATA_STORE_DIRECTORY   11

Definition at line 125138 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_DATABASE_LIST

#define PragTyp_DATABASE_LIST   12

Definition at line 125139 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_DEFAULT_CACHE_SIZE

#define PragTyp_DEFAULT_CACHE_SIZE   13

Definition at line 125140 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_ENCODING

#define PragTyp_ENCODING   14

Definition at line 125141 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_FLAG

#define PragTyp_FLAG   4

Definition at line 125131 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_FOREIGN_KEY_CHECK

#define PragTyp_FOREIGN_KEY_CHECK   15

Definition at line 125142 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_FOREIGN_KEY_LIST

#define PragTyp_FOREIGN_KEY_LIST   16

Definition at line 125143 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_FUNCTION_LIST

#define PragTyp_FUNCTION_LIST   17

Definition at line 125144 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_HARD_HEAP_LIMIT

#define PragTyp_HARD_HEAP_LIMIT   18

Definition at line 125145 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_HEADER_VALUE

#define PragTyp_HEADER_VALUE   2

Definition at line 125129 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_INCREMENTAL_VACUUM

#define PragTyp_INCREMENTAL_VACUUM   19

Definition at line 125146 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_INDEX_INFO

#define PragTyp_INDEX_INFO   20

Definition at line 125147 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_INDEX_LIST

#define PragTyp_INDEX_LIST   21

Definition at line 125148 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_INTEGRITY_CHECK

#define PragTyp_INTEGRITY_CHECK   22

Definition at line 125149 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_JOURNAL_MODE

#define PragTyp_JOURNAL_MODE   23

Definition at line 125150 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_JOURNAL_SIZE_LIMIT

#define PragTyp_JOURNAL_SIZE_LIMIT   24

Definition at line 125151 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_LOCK_PROXY_FILE

#define PragTyp_LOCK_PROXY_FILE   25

Definition at line 125152 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_LOCK_STATUS

#define PragTyp_LOCK_STATUS   43

Definition at line 125170 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_LOCKING_MODE

#define PragTyp_LOCKING_MODE   26

Definition at line 125153 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_MMAP_SIZE

#define PragTyp_MMAP_SIZE   28

Definition at line 125155 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_MODULE_LIST

#define PragTyp_MODULE_LIST   29

Definition at line 125156 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_OPTIMIZE

#define PragTyp_OPTIMIZE   30

Definition at line 125157 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_PAGE_COUNT

#define PragTyp_PAGE_COUNT   27

Definition at line 125154 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_PAGE_SIZE

#define PragTyp_PAGE_SIZE   31

Definition at line 125158 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_PRAGMA_LIST

#define PragTyp_PRAGMA_LIST   32

Definition at line 125159 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_SECURE_DELETE

#define PragTyp_SECURE_DELETE   33

Definition at line 125160 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_SHRINK_MEMORY

#define PragTyp_SHRINK_MEMORY   34

Definition at line 125161 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_SOFT_HEAP_LIMIT

#define PragTyp_SOFT_HEAP_LIMIT   35

Definition at line 125162 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_STATS

#define PragTyp_STATS   44

Definition at line 125171 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_SYNCHRONOUS

#define PragTyp_SYNCHRONOUS   36

Definition at line 125163 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_TABLE_INFO

#define PragTyp_TABLE_INFO   37

Definition at line 125164 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_TEMP_STORE

#define PragTyp_TEMP_STORE   38

Definition at line 125165 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_TEMP_STORE_DIRECTORY

#define PragTyp_TEMP_STORE_DIRECTORY   39

Definition at line 125166 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_THREADS

#define PragTyp_THREADS   40

Definition at line 125167 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_WAL_AUTOCHECKPOINT

#define PragTyp_WAL_AUTOCHECKPOINT   41

Definition at line 125168 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PragTyp_WAL_CHECKPOINT

#define PragTyp_WAL_CHECKPOINT   42

Definition at line 125169 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ PTF_INTKEY

#define PTF_INTKEY   0x01

Definition at line 63725 of file sqlite3.c.

Referenced by balance_quick(), btreeCreateTable(), decodeFlags(), and newDatabase().

◆ PTF_LEAF

#define PTF_LEAF   0x08

◆ PTF_LEAFDATA

#define PTF_LEAFDATA   0x04

Definition at line 63727 of file sqlite3.c.

Referenced by balance_quick(), btreeCreateTable(), decodeFlags(), and newDatabase().

◆ PTF_ZERODATA

#define PTF_ZERODATA   0x02

Definition at line 63726 of file sqlite3.c.

Referenced by btreeCreateTable(), and decodeFlags().

◆ PTRMAP_BTREE

#define PTRMAP_BTREE   5

◆ PTRMAP_FREEPAGE

#define PTRMAP_FREEPAGE   2

◆ PTRMAP_ISPAGE

#define PTRMAP_ISPAGE ( pBt,
pgno )   (PTRMAP_PAGENO((pBt),(pgno))==(pgno))

◆ PTRMAP_OVERFLOW1

#define PTRMAP_OVERFLOW1   3

◆ PTRMAP_OVERFLOW2

#define PTRMAP_OVERFLOW2   4

Definition at line 64108 of file sqlite3.c.

Referenced by checkList(), fillInCell(), getOverflowPage(), modifyPagePointer(), and relocatePage().

◆ PTRMAP_PAGENO

#define PTRMAP_PAGENO ( pBt,
pgno )   ptrmapPageno(pBt, pgno)

◆ PTRMAP_PTROFFSET

#define PTRMAP_PTROFFSET ( pgptrmap,
pgno )   (5*(pgno-pgptrmap-1))

Definition at line 64071 of file sqlite3.c.

Referenced by ptrmapGet(), and ptrmapPut().

◆ PTRMAP_ROOTPAGE

#define PTRMAP_ROOTPAGE   1

◆ PURE_DATE

#define PURE_DATE ( zName,
nArg,
iArg,
bNC,
xFunc )
Value:
(void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config
Definition sqlite3.c:20573

Definition at line 17258 of file sqlite3.c.

17258#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
17259 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
17260 0, 0, xFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterDateTimeFunctions().

◆ put2byte

#define put2byte ( p,
v )   ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))

◆ put32bits

#define put32bits ( A,
B )   sqlite3Put4byte((u8*)A,B)

Definition at line 52809 of file sqlite3.c.

Referenced by pager_write_changecounter(), syncJournal(), write32bits(), and writeJournalHdr().

◆ put4byte

◆ putVarint

#define putVarint   sqlite3PutVarint

Definition at line 19876 of file sqlite3.c.

Referenced by balance_nonroot(), and fillInCell().

◆ putVarint32

#define putVarint32 ( A,
B )
Value:
(u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
sqlite3PutVarint((A),(B)))
UINT8_TYPE u8
Definition sqlite3.c:14334

Definition at line 19872 of file sqlite3.c.

19872*/
19873#define getVarint32(A,B) \
19874 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))

Referenced by fillInCell(), and sqlite3VdbeExec().

◆ READ_LOCK

◆ READ_UTF8

#define READ_UTF8 ( zIn,
zTerm,
c )
Value:
c = *(zIn++); \
if( c>=0xc0 ){ \
c = sqlite3Utf8Trans1[c-0xc0]; \
while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
c = (c<<6) + (0x3f & *(zIn++)); \
} \
if( c<0x80 \
|| (c&0xFFFFF800)==0xD800 \
|| (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
}
static const unsigned char sqlite3Utf8Trans1[]
Definition sqlite3.c:30694

Definition at line 30777 of file sqlite3.c.

30777** invalid characters.
30778**
30779** * This routine accepts over-length UTF8 encodings
30780** for unicode values 0x80 and greater. It does not change over-length
30781** encodings to 0xfffd as some systems recommend.
30782*/
30783#define READ_UTF8(zIn, zTerm, c) \
30784 c = *(zIn++); \
30785 if( c>=0xc0 ){ \
30786 c = sqlite3Utf8Trans1[c-0xc0]; \
30787 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \

Referenced by sqlite3VdbeMemTranslate().

◆ READMARK_NOT_USED

#define READMARK_NOT_USED   0xffffffff

Definition at line 59795 of file sqlite3.c.

Referenced by walCheckpoint(), walIndexRecover(), walRestartHdr(), and walTryBeginRead().

◆ REGISTER_TRACE

#define REGISTER_TRACE ( R,
M )

Definition at line 85828 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ renameTokenCheckAll

#define renameTokenCheckAll ( x,
y )

Definition at line 106492 of file sqlite3.c.

Referenced by sqlite3RenameTokenMap(), and sqlite3RenameTokenRemap().

◆ REOPEN_AS_MEMDB

#define REOPEN_AS_MEMDB ( db)    (0)

◆ RESERVED_BYTE

#define RESERVED_BYTE   (PENDING_BYTE+1)

Definition at line 16425 of file sqlite3.c.

Referenced by posixUnlock(), unixCheckReservedLock(), and unixLock().

◆ RESERVED_LOCK

◆ restoreCursorPosition

#define restoreCursorPosition ( p)
Value:
(p->eState>=CURSOR_REQUIRESEEK ? \
btreeRestoreCursorPosition(p) : \
#define SQLITE_OK
Definition sqlite3.c:1469
#define CURSOR_REQUIRESEEK
Definition sqlite3.c:64047

Definition at line 65342 of file sqlite3.c.

65342 pCur->eState = CURSOR_SKIPNEXT;
65343 }
65344 }
65345 return rc;
#define CURSOR_SKIPNEXT
Definition sqlite3.c:64046

Referenced by btreeNext(), btreePrevious(), sqlite3BtreeCursorRestore(), and sqlite3BtreePutData().

◆ ROUND8

◆ ROUNDDOWN8

#define ROUNDDOWN8 ( x)    ((x)&~7)

Definition at line 14477 of file sqlite3.c.

Referenced by setupLookaside(), sqlite3PCacheBufferSetup(), and sqlite3VdbeMakeReady().

◆ ROWSET_ALLOCATION_SIZE

#define ROWSET_ALLOCATION_SIZE   1024

Definition at line 51108 of file sqlite3.c.

◆ ROWSET_ENTRY_PER_CHUNK

#define ROWSET_ENTRY_PER_CHUNK    ((ROWSET_ALLOCATION_SIZE-8)/sizeof(struct RowSetEntry))

Definition at line 51113 of file sqlite3.c.

51113*/
51114#define ROWSET_ALLOCATION_SIZE 1024

Referenced by rowSetEntryAlloc().

◆ ROWSET_NEXT

#define ROWSET_NEXT   0x02 /* True if sqlite3RowSetNext() has been called */

Definition at line 51162 of file sqlite3.c.

Referenced by sqlite3RowSetInsert(), sqlite3RowSetNext(), and sqlite3RowSetTest().

◆ ROWSET_SORTED

#define ROWSET_SORTED   0x01 /* True if RowSet.pEntry is sorted */

◆ SAVEPOINT_BEGIN

#define SAVEPOINT_BEGIN   0

Definition at line 17295 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), sqlite3VtabSavepoint(), and yy_reduce().

◆ SAVEPOINT_RELEASE

◆ SAVEPOINT_ROLLBACK

◆ SCHEMA_ENC

#define SCHEMA_ENC ( db)    ((db)->aDb[0].pSchema->enc)

Definition at line 16960 of file sqlite3.c.

Referenced by openDatabase(), sqlite3Init(), and sqlite3Pragma().

◆ SCHEMA_ROOT

#define SCHEMA_ROOT   1

◆ SCHEMA_TABLE

#define SCHEMA_TABLE ( x)     ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE)

Definition at line 14587 of file sqlite3.c.

14587#define SCHEMA_TABLE(x) \
14588 ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE)

Referenced by sqlite3BeginTrigger(), sqlite3CreateIndex(), sqlite3InitOne(), and sqlite3StartTable().

◆ SELECTTRACE

#define SELECTTRACE ( K,
P,
S,
X )

◆ SELECTTRACE_ENABLED [1/2]

#define SELECTTRACE_ENABLED   0

Definition at line 14541 of file sqlite3.c.

◆ SELECTTRACE_ENABLED [2/2]

#define SELECTTRACE_ENABLED   0

Definition at line 14541 of file sqlite3.c.

◆ SET_FULLSYNC

#define SET_FULLSYNC ( x,
y )

Definition at line 16307 of file sqlite3.c.

◆ SETBIT

#define SETBIT ( V,
I )   V[I>>3] |= (1<<(I&7))

Definition at line 48762 of file sqlite3.c.

Referenced by sqlite3BitvecBuiltinTest().

◆ setDefaultSyncFlag

#define setDefaultSyncFlag ( pBt,
safety_level )

Definition at line 67522 of file sqlite3.c.

Referenced by lockBtree().

◆ SF_Aggregate

#define SF_Aggregate   0x0000008 /* Contains agg functions or a GROUP BY */

◆ SF_All

#define SF_All   0x0000002 /* Includes the ALL keyword */

Definition at line 18472 of file sqlite3.c.

Referenced by yy_reduce().

◆ SF_ComplexResult

#define SF_ComplexResult   0x0040000 /* Result contains subquery or function */

Definition at line 18489 of file sqlite3.c.

Referenced by selectExpander(), and sqlite3Select().

◆ SF_Compound

#define SF_Compound   0x0000100 /* Part of a compound query */

Definition at line 18479 of file sqlite3.c.

Referenced by flattenSubquery(), multiSelect(), and parserDoubleLinkSelect().

◆ SF_Converted

#define SF_Converted   0x0010000 /* By convertCompoundSelectToSubquery() */

Definition at line 18487 of file sqlite3.c.

Referenced by convertCompoundSelectToSubquery().

◆ SF_Distinct

#define SF_Distinct   0x0000001 /* Output should be DISTINCT */

◆ SF_Expanded

#define SF_Expanded   0x0000040 /* sqlite3SelectExpand() called on this */

Definition at line 18477 of file sqlite3.c.

Referenced by selectExpander(), and sqlite3WindowRewrite().

◆ SF_FixedLimit

#define SF_FixedLimit   0x0004000 /* nSelectRow set by a constant LIMIT */

Definition at line 18485 of file sqlite3.c.

Referenced by computeLimitRegisters(), and sqlite3Select().

◆ SF_HasAgg

#define SF_HasAgg   0x0000010 /* Contains aggregate functions */

Definition at line 18475 of file sqlite3.c.

◆ SF_HasTypeInfo

#define SF_HasTypeInfo   0x0000080 /* FROM subqueries have Table metadata */

Definition at line 18478 of file sqlite3.c.

Referenced by selectAddSubqueryTypeInfo(), and sqlite3SelectPrep().

◆ SF_IncludeHidden

#define SF_IncludeHidden   0x0020000 /* Include hidden columns in output */

Definition at line 18488 of file sqlite3.c.

Referenced by selectExpander(), sqlite3MaterializeView(), and updateFromSelect().

◆ SF_MaybeConvert

#define SF_MaybeConvert   0x0008000 /* Need convertCompoundSelectToSubquery() */

Definition at line 18486 of file sqlite3.c.

◆ SF_MinMaxAgg

#define SF_MinMaxAgg   0x0001000 /* Aggregate containing min() or max() */

Definition at line 18483 of file sqlite3.c.

◆ SF_MultiValue

#define SF_MultiValue   0x0000400 /* Single VALUES term with multiple rows */

Definition at line 18481 of file sqlite3.c.

Referenced by multiSelect(), multiSelectValues(), parserDoubleLinkSelect(), and yy_reduce().

◆ SF_NestedFrom

#define SF_NestedFrom   0x0000800 /* Part of a parenthesized FROM clause */

Definition at line 18482 of file sqlite3.c.

Referenced by lookupName(), selectExpander(), and yy_reduce().

◆ SF_NoopOrderBy

#define SF_NoopOrderBy   0x0400000 /* ORDER BY is ignored for this query */

Definition at line 18493 of file sqlite3.c.

Referenced by flattenSubquery(), and sqlite3Select().

◆ SF_Recursive

#define SF_Recursive   0x0002000 /* The recursive part of a recursive CTE */

Definition at line 18484 of file sqlite3.c.

Referenced by flattenSubquery(), multiSelect(), pushDownWhereTerms(), and withExpand().

◆ SF_Resolved

#define SF_Resolved   0x0000004 /* Identifiers have been resolved */

◆ SF_UpdateFrom

#define SF_UpdateFrom   0x0800000 /* Statement is an UPDATE...FROM */

Definition at line 18494 of file sqlite3.c.

Referenced by sqlite3Select(), and updateFromSelect().

◆ SF_UsesEphemeral

#define SF_UsesEphemeral   0x0000020 /* Uses the OpenEphemeral opcode */

Definition at line 18476 of file sqlite3.c.

Referenced by generateWithRecursiveQuery(), and multiSelect().

◆ SF_Values

#define SF_Values   0x0000200 /* Synthesized from VALUES clause */

◆ SF_View

#define SF_View   0x0200000 /* SELECT statement is a view */

Definition at line 18492 of file sqlite3.c.

Referenced by renameColumnSelectCb(), and renameTableFunc().

◆ SF_WhereBegin

#define SF_WhereBegin   0x0080000 /* Really a WhereBegin() call. Debug Only */

Definition at line 18490 of file sqlite3.c.

Referenced by sqlite3WhereBegin().

◆ SF_WinRewrite

#define SF_WinRewrite   0x0100000 /* Window function rewrite accomplished */

Definition at line 18491 of file sqlite3.c.

Referenced by sqlite3WindowRewrite().

◆ SFUNCTION

#define SFUNCTION ( zName,
nArg,
iArg,
bNC,
xFunc )
Value:
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
#define SQLITE_DIRECTONLY
Definition sqlite3.c:6325
#define SQLITE_FUNC_UNSAFE
Definition sqlite3.c:17164

Definition at line 17245 of file sqlite3.c.

17245#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
17246 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
17247 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ SHARED_FIRST

#define SHARED_FIRST   (PENDING_BYTE+2)

Definition at line 16426 of file sqlite3.c.

Referenced by posixUnlock(), unixFileLock(), and unixLock().

◆ SHARED_LOCK

◆ SHARED_SIZE

#define SHARED_SIZE   510

Definition at line 16427 of file sqlite3.c.

Referenced by posixUnlock(), unixFileLock(), and unixLock().

◆ SimulateDiskfullError

#define SimulateDiskfullError ( A)

Definition at line 33825 of file sqlite3.c.

Referenced by unixSync(), and unixWrite().

◆ SimulateIOError

◆ SimulateIOErrorBenign

#define SimulateIOErrorBenign ( X)

Definition at line 33823 of file sqlite3.c.

Referenced by unixWrite().

◆ SLOT_2_0

#define SLOT_2_0   0x001fc07f

Definition at line 32139 of file sqlite3.c.

Referenced by sqlite3GetVarint().

◆ SLOT_4_2_0

#define SLOT_4_2_0   0xf01fc07f

Definition at line 32140 of file sqlite3.c.

Referenced by sqlite3GetVarint(), and sqlite3GetVarint32().

◆ SMALLEST_INT64

#define SMALLEST_INT64   (((i64)-1) - LARGEST_INT64)

◆ SORTER_MAX_MERGE_COUNT

#define SORTER_MAX_MERGE_COUNT   16

◆ SORTER_TYPE_INTEGER

#define SORTER_TYPE_INTEGER   0x01

Definition at line 94216 of file sqlite3.c.

Referenced by sqlite3VdbeSorterInit().

◆ SORTER_TYPE_TEXT

#define SORTER_TYPE_TEXT   0x02

Definition at line 94217 of file sqlite3.c.

Referenced by sqlite3VdbeSorterInit().

◆ SORTFLAG_UseSorter

#define SORTFLAG_UseSorter   0x01 /* Use SorterOpen instead of OpenEphemeral */

Definition at line 129362 of file sqlite3.c.

Referenced by generateSortTail(), selectInnerLoop(), and sqlite3Select().

◆ SPILLFLAG_NOSYNC

#define SPILLFLAG_NOSYNC   0x04 /* Spill is ok, but do not sync */

Definition at line 52150 of file sqlite3.c.

Referenced by pagerStress(), and pagerWriteLargeSector().

◆ SPILLFLAG_OFF

#define SPILLFLAG_OFF   0x01 /* Never spill cache. Set via pragma */

Definition at line 52148 of file sqlite3.c.

Referenced by pagerStress(), and sqlite3PagerSetFlags().

◆ SPILLFLAG_ROLLBACK

#define SPILLFLAG_ROLLBACK   0x02 /* Current rolling back, so do not spill */

Definition at line 52149 of file sqlite3.c.

Referenced by pager_playback_one_page(), and pagerStress().

◆ sqlite3_column_database_name

#define sqlite3_column_database_name   0

Definition at line 124261 of file sqlite3.c.

◆ sqlite3_column_database_name16

#define sqlite3_column_database_name16   0

Definition at line 124262 of file sqlite3.c.

◆ sqlite3_column_origin_name

#define sqlite3_column_origin_name   0

Definition at line 124265 of file sqlite3.c.

◆ sqlite3_column_origin_name16

#define sqlite3_column_origin_name16   0

Definition at line 124266 of file sqlite3.c.

◆ sqlite3_column_table_name

#define sqlite3_column_table_name   0

Definition at line 124263 of file sqlite3.c.

◆ sqlite3_column_table_name16

#define sqlite3_column_table_name16   0

Definition at line 124264 of file sqlite3.c.

◆ SQLITE3_H

#define SQLITE3_H

Definition at line 1082 of file sqlite3.c.

◆ SQLITE3_MUTEX_INITIALIZER

#define SQLITE3_MUTEX_INITIALIZER ( id)    { PTHREAD_MUTEX_INITIALIZER }

Definition at line 26281 of file sqlite3.c.

Referenced by pthreadMutexAlloc().

◆ SQLITE3_TEXT

#define SQLITE3_TEXT   3

Definition at line 5800 of file sqlite3.c.

◆ sqlite3CodecQueryParameters

#define sqlite3CodecQueryParameters ( A,
B,
C )   0

Definition at line 19552 of file sqlite3.c.

◆ sqlite3ColumnPropertiesFromName

#define sqlite3ColumnPropertiesFromName ( T,
C )   /* no-op */

Definition at line 19540 of file sqlite3.c.

Referenced by sqlite3AddColumn(), and sqlite3ColumnsFromExprList().

◆ sqlite3ConnectionBlocked

#define sqlite3ConnectionBlocked ( x,
y )

Definition at line 20268 of file sqlite3.c.

Referenced by querySharedCacheTableLock(), and sqlite3BtreeBeginTrans().

◆ sqlite3ConnectionClosed

#define sqlite3ConnectionClosed ( x)

Definition at line 20270 of file sqlite3.c.

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ sqlite3ConnectionUnlocked

#define sqlite3ConnectionUnlocked ( x)

Definition at line 20269 of file sqlite3.c.

Referenced by sqlite3VdbeHalt().

◆ sqlite3ExplainBreakpoint

#define sqlite3ExplainBreakpoint ( A,
B )   /*no-op*/

Definition at line 15842 of file sqlite3.c.

Referenced by sqlite3VdbeExplain(), and sqlite3WhereExplainOneScan().

◆ SQLITE3EXT_H

#define SQLITE3EXT_H

Definition at line 123608 of file sqlite3.c.

◆ sqlite3FileSuffix3

#define sqlite3FileSuffix3 ( X,
Y )

Definition at line 19926 of file sqlite3.c.

Referenced by sqlite3PagerOpen(), unixOpenSharedMemory(), and vdbeCommit().

◆ sqlite3GlobalConfig

◆ sqlite3Isalnum

#define sqlite3Isalnum ( x)    (sqlite3CtypeMap[(unsigned char)(x)]&0x06)

Definition at line 19320 of file sqlite3.c.

Referenced by identPut().

◆ sqlite3Isalpha

#define sqlite3Isalpha ( x)    (sqlite3CtypeMap[(unsigned char)(x)]&0x02)

Definition at line 19321 of file sqlite3.c.

Referenced by sqlite3LoadExtension().

◆ sqlite3Isdigit

◆ sqlite3IsNumericAffinity

#define sqlite3IsNumericAffinity ( X)    ((X)>=SQLITE_AFF_NUMERIC)

◆ sqlite3Isquote

#define sqlite3Isquote ( x)    (sqlite3CtypeMap[(unsigned char)(x)]&0x80)

◆ sqlite3Isspace

#define sqlite3Isspace ( x)    (sqlite3CtypeMap[(unsigned char)(x)]&0x01)

◆ sqlite3IsToplevel

#define sqlite3IsToplevel ( p)    ((p)->pToplevel==0)

Definition at line 19788 of file sqlite3.c.

Referenced by sqlite3DeleteFrom().

◆ sqlite3Isxdigit

#define sqlite3Isxdigit ( x)    (sqlite3CtypeMap[(unsigned char)(x)]&0x08)

◆ sqlite3MemdebugHasType

#define sqlite3MemdebugHasType ( X,
Y )   1

Definition at line 20328 of file sqlite3.c.

Referenced by lookasideMallocSize(), and sqlite3DbFreeNN().

◆ sqlite3MemdebugNoType

#define sqlite3MemdebugNoType ( X,
Y )   1

Definition at line 20329 of file sqlite3.c.

◆ sqlite3MemdebugSetType

#define sqlite3MemdebugSetType ( X,
Y )   /* no-op */

Definition at line 20327 of file sqlite3.c.

Referenced by dbMallocRawFinish(), and pcache1Alloc().

◆ sqlite3MutexWarnOnContention

#define sqlite3MutexWarnOnContention ( x)

Definition at line 19428 of file sqlite3.c.

Referenced by openDatabase().

◆ sqlite3PagerWalDb

#define sqlite3PagerWalDb ( x,
y )

Definition at line 14943 of file sqlite3.c.

Referenced by sqlite3BtreeBeginTrans().

◆ sqlite3PagerWalWriteLock

#define sqlite3PagerWalWriteLock ( y,
z )   SQLITE_OK

Definition at line 14942 of file sqlite3.c.

Referenced by sqlite3BtreeBeginTrans().

◆ sqlite3Parser_ENGINEALWAYSONSTACK

#define sqlite3Parser_ENGINEALWAYSONSTACK   1

Definition at line 154262 of file sqlite3.c.

◆ sqlite3ParserARG_FETCH

#define sqlite3ParserARG_FETCH

Definition at line 154506 of file sqlite3.c.

Referenced by yy_destructor(), and yy_reduce().

◆ sqlite3ParserARG_PARAM

#define sqlite3ParserARG_PARAM

Definition at line 154505 of file sqlite3.c.

◆ sqlite3ParserARG_PDECL

#define sqlite3ParserARG_PDECL

Definition at line 154504 of file sqlite3.c.

◆ sqlite3ParserARG_SDECL

#define sqlite3ParserARG_SDECL

Definition at line 154503 of file sqlite3.c.

◆ sqlite3ParserARG_STORE

#define sqlite3ParserARG_STORE

Definition at line 154507 of file sqlite3.c.

Referenced by sqlite3Parser().

◆ sqlite3ParserCTX_FETCH

#define sqlite3ParserCTX_FETCH   Parse *pParse=yypParser->pParse;

Definition at line 154511 of file sqlite3.c.

Referenced by sqlite3Parser(), and yy_destructor().

◆ sqlite3ParserCTX_PARAM

#define sqlite3ParserCTX_PARAM   ,pParse

Definition at line 154510 of file sqlite3.c.

Referenced by sqlite3Parser().

◆ sqlite3ParserCTX_PDECL

#define sqlite3ParserCTX_PDECL   ,Parse *pParse

Definition at line 154509 of file sqlite3.c.

◆ sqlite3ParserCTX_SDECL

#define sqlite3ParserCTX_SDECL   Parse *pParse;

Definition at line 154508 of file sqlite3.c.

◆ sqlite3ParserCTX_STORE

#define sqlite3ParserCTX_STORE   yypParser->pParse=pParse;

Definition at line 154512 of file sqlite3.c.

Referenced by sqlite3ParserInit().

◆ sqlite3ParserTOKENTYPE

#define sqlite3ParserTOKENTYPE   Token

Definition at line 154480 of file sqlite3.c.

◆ sqlite3ParseToplevel

◆ sqlite3ResolveNotValid

#define sqlite3ResolveNotValid ( P,
N,
M,
X,
E )
Value:
assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E);
#define NC_IsCheck
Definition sqlite3.c:18375
static void notValidImpl(Parse *pParse, NameContext *pNC, const char *zMsg, Expr *pExpr)
Definition sqlite3.c:98442
#define NC_PartIdx
Definition sqlite3.c:18374
#define NC_IdxExpr
Definition sqlite3.c:18378
#define NC_GenCol
Definition sqlite3.c:18376

Definition at line 98459 of file sqlite3.c.

98459#ifndef SQLITE_OMIT_GENERATED_COLUMNS
98460 else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
98461#endif

Referenced by resolveExprStep().

◆ sqlite3SetMakeRecordP5

#define sqlite3SetMakeRecordP5 ( A,
B )

Definition at line 19732 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks().

◆ sqlite3StackAllocRaw

#define sqlite3StackAllocRaw ( D,
N )   sqlite3DbMallocRaw(D,N)

Definition at line 19385 of file sqlite3.c.

Referenced by balance_nonroot(), and sqlite3BitvecSet().

◆ sqlite3StackAllocZero

#define sqlite3StackAllocZero ( D,
N )   sqlite3DbMallocZero(D,N)

Definition at line 19386 of file sqlite3.c.

◆ sqlite3StackFree

#define sqlite3StackFree ( D,
P )   sqlite3DbFree(D,P)

Definition at line 19387 of file sqlite3.c.

Referenced by balance_nonroot(), and sqlite3BitvecSet().

◆ sqlite3Strlen30NN

#define sqlite3Strlen30NN ( C)    (strlen(C)&0x3fffffff)

Definition at line 19343 of file sqlite3.c.

Referenced by dupedExprNodeSize(), sqlite3TableAffinity(), and sqlite3VdbeMemStringify().

◆ sqlite3StrNICmp

◆ sqlite3Tolower

#define sqlite3Tolower ( x)    (sqlite3UpperToLower[(unsigned char)(x)])

Definition at line 19324 of file sqlite3.c.

Referenced by exprAnalyze(), patternCompare(), sqlite3Pragma(), and sqlite3RunParser().

◆ sqlite3Toupper

#define sqlite3Toupper ( x)    ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))

Definition at line 19318 of file sqlite3.c.

Referenced by exprAnalyze(), patternCompare(), and sqlite3RunParser().

◆ sqlite3VdbeAssertAbortable

#define sqlite3VdbeAssertAbortable ( V)

Definition at line 21284 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeIncrWriteCounter

#define sqlite3VdbeIncrWriteCounter ( V,
C )

Definition at line 21283 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeIOTraceSql

#define sqlite3VdbeIOTraceSql ( X)

Definition at line 20291 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeReleaseRegisters

#define sqlite3VdbeReleaseRegisters ( P,
A,
N,
M,
F )

◆ sqlite3VdbeScanStatus

#define sqlite3VdbeScanStatus ( a,
b,
c,
d,
e )

Definition at line 16007 of file sqlite3.c.

◆ sqlite3VdbeVerifyAbortable

#define sqlite3VdbeVerifyAbortable ( A,
B )

◆ sqlite3VdbeVerifyNoMallocRequired

#define sqlite3VdbeVerifyNoMallocRequired ( A,
B )

Definition at line 15817 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ sqlite3VdbeVerifyNoResultRow

#define sqlite3VdbeVerifyNoResultRow ( A)

Definition at line 15818 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ sqlite3VtabInSync

#define sqlite3VtabInSync ( db)    ((db)->nVTrans>0 && (db)->aVTrans==0)

Definition at line 20115 of file sqlite3.c.

Referenced by sqlite3VdbeHalt(), and sqlite3VtabBegin().

◆ sqlite3WalDb

#define sqlite3WalDb ( pWal,
db )

Definition at line 61228 of file sqlite3.c.

Referenced by sqlite3WalCheckpoint().

◆ sqlite3WhereAddScanStatus

#define sqlite3WhereAddScanStatus ( a,
b,
c,
d )   ((void)d)

Definition at line 141452 of file sqlite3.c.

Referenced by sqlite3WhereBegin().

◆ SQLITE_ABORT

#define SQLITE_ABORT   4 /* Callback routine requested an abort */

◆ SQLITE_ABORT_ROLLBACK

#define SQLITE_ABORT_ROLLBACK   (SQLITE_ABORT | (2<<8))

Definition at line 1575 of file sqlite3.c.

Referenced by sqlite3BtreeRollback(), sqlite3ErrStr(), sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ SQLITE_ACCESS_EXISTS

◆ SQLITE_ACCESS_READ

#define SQLITE_ACCESS_READ   2 /* Unused */

Definition at line 2478 of file sqlite3.c.

◆ SQLITE_ACCESS_READWRITE

#define SQLITE_ACCESS_READWRITE   1 /* Used by PRAGMA temp_store_directory */

Definition at line 2477 of file sqlite3.c.

Referenced by sqlite3Pragma(), and unixAccess().

◆ SQLITE_AFF_BLOB

◆ SQLITE_AFF_INTEGER

◆ SQLITE_AFF_MASK

#define SQLITE_AFF_MASK   0x47

Definition at line 17407 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_AFF_NONE

◆ SQLITE_AFF_NUMERIC

◆ SQLITE_AFF_REAL

◆ SQLITE_AFF_TEXT

◆ SQLITE_AllOpts

#define SQLITE_AllOpts   0xffff /* All optimizations */

Definition at line 17058 of file sqlite3.c.

◆ SQLITE_ALLOW_COVERING_INDEX_SCAN

#define SQLITE_ALLOW_COVERING_INDEX_SCAN   1

Definition at line 20511 of file sqlite3.c.

◆ SQLITE_ALTER_TABLE

#define SQLITE_ALTER_TABLE   26 /* Database Name Table Name */

Definition at line 4145 of file sqlite3.c.

Referenced by sqlite3AlterFinishAddColumn(), and sqlite3AlterRenameColumn().

◆ SQLITE_AMALGAMATION

#define SQLITE_AMALGAMATION   1

Definition at line 21 of file sqlite3.c.

◆ SQLITE_ANALYZE

#define SQLITE_ANALYZE   28 /* Table Name NULL */

Definition at line 4147 of file sqlite3.c.

Referenced by analyzeOneTable().

◆ SQLITE_ANY

#define SQLITE_ANY   5 /* Deprecated */

Definition at line 6256 of file sqlite3.c.

Referenced by sqlite3CreateFunc().

◆ SQLITE_API

#define SQLITE_API

Definition at line 1100 of file sqlite3.c.

◆ SQLITE_APICALL

#define SQLITE_APICALL

Definition at line 1106 of file sqlite3.c.

◆ SQLITE_ASCII

#define SQLITE_ASCII   1

Definition at line 14281 of file sqlite3.c.

◆ SQLITE_ATTACH

#define SQLITE_ATTACH   24 /* Filename NULL */

Definition at line 4143 of file sqlite3.c.

Referenced by sqlite3Attach().

◆ SQLITE_AUTH

#define SQLITE_AUTH   23 /* Authorization denied */

Definition at line 1493 of file sqlite3.c.

Referenced by sqlite3AuthCheck(), and sqlite3AuthReadCol().

◆ SQLITE_AUTH_USER

#define SQLITE_AUTH_USER   (SQLITE_AUTH | (1<<8))

Definition at line 1590 of file sqlite3.c.

Referenced by attachFunc(), and sqlite3FinishCoding().

◆ SQLITE_AutoIndex

#define SQLITE_AutoIndex   0x00008000 /* Enable automatic indexes */

Definition at line 16994 of file sqlite3.c.

Referenced by openDatabase(), and whereLoopAddBtree().

◆ SQLITE_BIG_DBL

#define SQLITE_BIG_DBL   (1e99)

Definition at line 14161 of file sqlite3.c.

Referenced by whereLoopAddVirtualOne().

◆ SQLITE_BIGENDIAN

#define SQLITE_BIGENDIAN   (*(char *)(&sqlite3one)==0)

Definition at line 14454 of file sqlite3.c.

Referenced by walDecodeFrame(), walEncodeFrame(), and walIndexRecover().

◆ SQLITE_BLDF1_INDEXED

#define SQLITE_BLDF1_INDEXED   0x0001 /* An index is used */

Definition at line 141334 of file sqlite3.c.

Referenced by whereLoopAddBtree(), and whereLoopAddBtreeIndex().

◆ SQLITE_BLDF1_UNIQUE

#define SQLITE_BLDF1_UNIQUE   0x0002 /* All keys of a UNIQUE index used */

Definition at line 141335 of file sqlite3.c.

Referenced by whereLoopAddBtreeIndex().

◆ SQLITE_BLDF2_2NDPASS

#define SQLITE_BLDF2_2NDPASS   0x0004 /* Second builder pass needed */

Definition at line 141337 of file sqlite3.c.

Referenced by sqlite3WhereBegin(), and whereLoopAddBtreeIndex().

◆ SQLITE_BLOB

#define SQLITE_BLOB   4

Definition at line 5793 of file sqlite3.c.

Referenced by db_push_value(), instrFunc(), likeFunc(), quoteFunc(), substrFunc(), and vm_push_column().

◆ SQLITE_BTREE_H

#define SQLITE_BTREE_H

Definition at line 15014 of file sqlite3.c.

◆ SQLITE_BUSY

◆ SQLITE_BUSY_RECOVERY

#define SQLITE_BUSY_RECOVERY   (SQLITE_BUSY | (1<<8))

Definition at line 1557 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and walTryBeginRead().

◆ SQLITE_BUSY_SNAPSHOT

#define SQLITE_BUSY_SNAPSHOT   (SQLITE_BUSY | (2<<8))

◆ SQLITE_BUSY_TIMEOUT

#define SQLITE_BUSY_TIMEOUT   (SQLITE_BUSY | (3<<8))

◆ SQLITE_BYTEORDER

#define SQLITE_BYTEORDER   0

Definition at line 14437 of file sqlite3.c.

◆ SQLITE_CacheSpill

#define SQLITE_CacheSpill   0x00000020 /* OK to spill pager cache */

Definition at line 16983 of file sqlite3.c.

Referenced by openDatabase(), setAllPagerFlags(), and sqlite3Pragma().

◆ SQLITE_CALLBACK

#define SQLITE_CALLBACK

Definition at line 1112 of file sqlite3.c.

◆ SQLITE_CANTOPEN

#define SQLITE_CANTOPEN   14 /* Unable to open the database file */

◆ SQLITE_CANTOPEN_BKPT

◆ SQLITE_CANTOPEN_CONVPATH

#define SQLITE_CANTOPEN_CONVPATH   (SQLITE_CANTOPEN | (4<<8))

Definition at line 1563 of file sqlite3.c.

◆ SQLITE_CANTOPEN_DIRTYWAL

#define SQLITE_CANTOPEN_DIRTYWAL   (SQLITE_CANTOPEN | (5<<8)) /* Not Used */

Definition at line 1564 of file sqlite3.c.

◆ SQLITE_CANTOPEN_FULLPATH

#define SQLITE_CANTOPEN_FULLPATH   (SQLITE_CANTOPEN | (3<<8))

Definition at line 1562 of file sqlite3.c.

◆ SQLITE_CANTOPEN_ISDIR

#define SQLITE_CANTOPEN_ISDIR   (SQLITE_CANTOPEN | (2<<8))

Definition at line 1561 of file sqlite3.c.

◆ SQLITE_CANTOPEN_NOTEMPDIR

#define SQLITE_CANTOPEN_NOTEMPDIR   (SQLITE_CANTOPEN | (1<<8))

Definition at line 1560 of file sqlite3.c.

◆ SQLITE_CANTOPEN_SYMLINK

#define SQLITE_CANTOPEN_SYMLINK   (SQLITE_CANTOPEN | (6<<8))

Definition at line 1565 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_CDECL

#define SQLITE_CDECL

Definition at line 1103 of file sqlite3.c.

◆ SQLITE_CellSizeCk

#define SQLITE_CellSizeCk   0x00200000 /* Check btree cell sizes on load */

Definition at line 17000 of file sqlite3.c.

Referenced by btreeInitPage(), openDatabase(), and sqlite3BtreeIntegrityCheck().

◆ SQLITE_CHECKPOINT_FULL

#define SQLITE_CHECKPOINT_FULL   1 /* Wait for writers, then checkpoint */

Definition at line 10137 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ SQLITE_CHECKPOINT_PASSIVE

#define SQLITE_CHECKPOINT_PASSIVE   0 /* Do as much as possible w/o blocking */

◆ SQLITE_CHECKPOINT_RESTART

#define SQLITE_CHECKPOINT_RESTART   2 /* Like FULL but wait for for readers */

Definition at line 10138 of file sqlite3.c.

Referenced by sqlite3Pragma(), sqlite3VdbeExec(), and walCheckpoint().

◆ SQLITE_CHECKPOINT_TRUNCATE

#define SQLITE_CHECKPOINT_TRUNCATE   3 /* Like RESTART but also truncate WAL */

Definition at line 10139 of file sqlite3.c.

Referenced by sqlite3Pragma(), sqlite3VdbeExec(), and walCheckpoint().

◆ SQLITE_CkptFullFSync

#define SQLITE_CkptFullFSync   0x00000010 /* Use full fsync for checkpoint */

Definition at line 16982 of file sqlite3.c.

Referenced by openDatabase(), and setAllPagerFlags().

◆ SQLITE_CONFIG_COVERING_INDEX_SCAN

#define SQLITE_CONFIG_COVERING_INDEX_SCAN   20 /* int */

Definition at line 3097 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_GETMALLOC

#define SQLITE_CONFIG_GETMALLOC   5 /* sqlite3_mem_methods* */

Definition at line 3082 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_GETMUTEX

#define SQLITE_CONFIG_GETMUTEX   11 /* sqlite3_mutex_methods* */

Definition at line 3088 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_GETPCACHE

#define SQLITE_CONFIG_GETPCACHE   15 /* no-op */

Definition at line 3092 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_GETPCACHE2

#define SQLITE_CONFIG_GETPCACHE2   19 /* sqlite3_pcache_methods2* */

Definition at line 3096 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_HEAP

#define SQLITE_CONFIG_HEAP   8 /* void*, int nByte, int min */

Definition at line 3085 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_LOG

#define SQLITE_CONFIG_LOG   16 /* xFunc, void* */

Definition at line 3093 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_LOOKASIDE

#define SQLITE_CONFIG_LOOKASIDE   13 /* int int */

Definition at line 3090 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_MALLOC

#define SQLITE_CONFIG_MALLOC   4 /* sqlite3_mem_methods* */

Definition at line 3081 of file sqlite3.c.

Referenced by sqlite3_config(), and sqlite3MemSetDefault().

◆ SQLITE_CONFIG_MEMDB_MAXSIZE

#define SQLITE_CONFIG_MEMDB_MAXSIZE   29 /* sqlite3_int64 */

Definition at line 3106 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_MEMSTATUS

#define SQLITE_CONFIG_MEMSTATUS   9 /* boolean */

Definition at line 3086 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_MMAP_SIZE

#define SQLITE_CONFIG_MMAP_SIZE   22 /* sqlite3_int64, sqlite3_int64 */

Definition at line 3099 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_MULTITHREAD

#define SQLITE_CONFIG_MULTITHREAD   2 /* nil */

Definition at line 3079 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_MUTEX

#define SQLITE_CONFIG_MUTEX   10 /* sqlite3_mutex_methods* */

Definition at line 3087 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_PAGECACHE

#define SQLITE_CONFIG_PAGECACHE   7 /* void*, int sz, int N */

Definition at line 3084 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_PCACHE

#define SQLITE_CONFIG_PCACHE   14 /* no-op */

Definition at line 3091 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_PCACHE2

#define SQLITE_CONFIG_PCACHE2   18 /* sqlite3_pcache_methods2* */

Definition at line 3095 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_PCACHE_HDRSZ

#define SQLITE_CONFIG_PCACHE_HDRSZ   24 /* int *psz */

Definition at line 3101 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_PMASZ

#define SQLITE_CONFIG_PMASZ   25 /* unsigned int szPma */

Definition at line 3102 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_SCRATCH

#define SQLITE_CONFIG_SCRATCH   6 /* No longer used */

Definition at line 3083 of file sqlite3.c.

◆ SQLITE_CONFIG_SERIALIZED

#define SQLITE_CONFIG_SERIALIZED   3 /* nil */

Definition at line 3080 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_SINGLETHREAD

#define SQLITE_CONFIG_SINGLETHREAD   1 /* nil */

Definition at line 3078 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_SMALL_MALLOC

#define SQLITE_CONFIG_SMALL_MALLOC   27 /* boolean */

Definition at line 3104 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_SORTERREF_SIZE

#define SQLITE_CONFIG_SORTERREF_SIZE   28 /* int nByte */

Definition at line 3105 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_SQLLOG

#define SQLITE_CONFIG_SQLLOG   21 /* xSqllog, void* */

Definition at line 3098 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_STMTJRNL_SPILL

#define SQLITE_CONFIG_STMTJRNL_SPILL   26 /* int nByte */

Definition at line 3103 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_URI

#define SQLITE_CONFIG_URI   17 /* int */

Definition at line 3094 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONFIG_WIN32_HEAPSIZE

#define SQLITE_CONFIG_WIN32_HEAPSIZE   23 /* int nByte */

Definition at line 3100 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_CONSTRAINT

#define SQLITE_CONSTRAINT   19 /* Abort due to constraint violation */

◆ SQLITE_CONSTRAINT_CHECK

#define SQLITE_CONSTRAINT_CHECK   (SQLITE_CONSTRAINT | (1<<8))

Definition at line 1576 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks().

◆ SQLITE_CONSTRAINT_COMMITHOOK

#define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))

Definition at line 1577 of file sqlite3.c.

Referenced by vdbeCommit().

◆ SQLITE_CONSTRAINT_FOREIGNKEY

#define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))

◆ SQLITE_CONSTRAINT_FUNCTION

#define SQLITE_CONSTRAINT_FUNCTION   (SQLITE_CONSTRAINT | (4<<8))

Definition at line 1579 of file sqlite3.c.

◆ SQLITE_CONSTRAINT_NOTNULL

#define SQLITE_CONSTRAINT_NOTNULL   (SQLITE_CONSTRAINT | (5<<8))

Definition at line 1580 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks().

◆ SQLITE_CONSTRAINT_PINNED

#define SQLITE_CONSTRAINT_PINNED   (SQLITE_CONSTRAINT |(11<<8))

Definition at line 1586 of file sqlite3.c.

Referenced by saveCursorPosition().

◆ SQLITE_CONSTRAINT_PRIMARYKEY

#define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))

Definition at line 1581 of file sqlite3.c.

◆ SQLITE_CONSTRAINT_ROWID

#define SQLITE_CONSTRAINT_ROWID   (SQLITE_CONSTRAINT |(10<<8))

Definition at line 1585 of file sqlite3.c.

◆ SQLITE_CONSTRAINT_TRIGGER

#define SQLITE_CONSTRAINT_TRIGGER   (SQLITE_CONSTRAINT | (7<<8))

Definition at line 1582 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget().

◆ SQLITE_CONSTRAINT_UNIQUE

#define SQLITE_CONSTRAINT_UNIQUE   (SQLITE_CONSTRAINT | (8<<8))

Definition at line 1583 of file sqlite3.c.

◆ SQLITE_CONSTRAINT_VTAB

#define SQLITE_CONSTRAINT_VTAB   (SQLITE_CONSTRAINT | (9<<8))

Definition at line 1584 of file sqlite3.c.

◆ SQLITE_COPY

#define SQLITE_COPY   0 /* No longer used */

Definition at line 4152 of file sqlite3.c.

◆ SQLITE_CORE

#define SQLITE_CORE   1

Definition at line 20 of file sqlite3.c.

◆ SQLITE_CORRUPT

#define SQLITE_CORRUPT   11 /* The database disk image is malformed */

◆ SQLITE_CORRUPT_BKPT

◆ SQLITE_CORRUPT_INDEX

#define SQLITE_CORRUPT_INDEX   (SQLITE_CORRUPT | (3<<8))

Definition at line 1568 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_CORRUPT_PAGE

#define SQLITE_CORRUPT_PAGE ( pMemPage)    SQLITE_CORRUPT_PGNO(pMemPage->pgno)

◆ SQLITE_CORRUPT_PGNO

#define SQLITE_CORRUPT_PGNO ( P)    sqlite3CorruptError(__LINE__)

Definition at line 19283 of file sqlite3.c.

Referenced by allocateBtreePage(), getAndInitPage(), and ptrmapGet().

◆ SQLITE_CORRUPT_SEQUENCE

#define SQLITE_CORRUPT_SEQUENCE   (SQLITE_CORRUPT | (2<<8))

Definition at line 1567 of file sqlite3.c.

Referenced by autoIncBegin().

◆ SQLITE_CORRUPT_VTAB

#define SQLITE_CORRUPT_VTAB   (SQLITE_CORRUPT | (1<<8))

Definition at line 1566 of file sqlite3.c.

◆ SQLITE_CountOfView

#define SQLITE_CountOfView   0x0200 /* The count-of-view optimization */

Definition at line 17050 of file sqlite3.c.

Referenced by sqlite3Select().

◆ SQLITE_CountRows

#define SQLITE_CountRows   HI(0x00001) /* Count rows changed by INSERT, */

◆ SQLITE_CoverIdxScan

#define SQLITE_CoverIdxScan   0x0020 /* Covering index scans */

Definition at line 17046 of file sqlite3.c.

Referenced by whereLoopAddBtree().

◆ SQLITE_CREATE_INDEX

#define SQLITE_CREATE_INDEX   1 /* Index Name Table Name */

Definition at line 4120 of file sqlite3.c.

Referenced by sqlite3CreateIndex().

◆ SQLITE_CREATE_TABLE

#define SQLITE_CREATE_TABLE   2 /* Table Name NULL */

Definition at line 4121 of file sqlite3.c.

Referenced by sqlite3StartTable().

◆ SQLITE_CREATE_TEMP_INDEX

#define SQLITE_CREATE_TEMP_INDEX   3 /* Index Name Table Name */

Definition at line 4122 of file sqlite3.c.

Referenced by sqlite3CreateIndex().

◆ SQLITE_CREATE_TEMP_TABLE

#define SQLITE_CREATE_TEMP_TABLE   4 /* Table Name NULL */

Definition at line 4123 of file sqlite3.c.

Referenced by sqlite3StartTable().

◆ SQLITE_CREATE_TEMP_TRIGGER

#define SQLITE_CREATE_TEMP_TRIGGER   5 /* Trigger Name Table Name */

Definition at line 4124 of file sqlite3.c.

Referenced by sqlite3BeginTrigger().

◆ SQLITE_CREATE_TEMP_VIEW

#define SQLITE_CREATE_TEMP_VIEW   6 /* View Name NULL */

Definition at line 4125 of file sqlite3.c.

Referenced by sqlite3StartTable().

◆ SQLITE_CREATE_TRIGGER

#define SQLITE_CREATE_TRIGGER   7 /* Trigger Name Table Name */

Definition at line 4126 of file sqlite3.c.

Referenced by sqlite3BeginTrigger().

◆ SQLITE_CREATE_VIEW

#define SQLITE_CREATE_VIEW   8 /* View Name NULL */

Definition at line 4127 of file sqlite3.c.

Referenced by sqlite3StartTable().

◆ SQLITE_CREATE_VTABLE

#define SQLITE_CREATE_VTABLE   29 /* Table Name Module Name */

Definition at line 4148 of file sqlite3.c.

Referenced by sqlite3VtabBeginParse().

◆ SQLITE_CursorHints

#define SQLITE_CursorHints   0x0400 /* Add OP_CursorHint opcodes */

Definition at line 17051 of file sqlite3.c.

◆ SQLITE_DBCONFIG_DEFENSIVE

#define SQLITE_DBCONFIG_DEFENSIVE   1010 /* int int* */

Definition at line 3387 of file sqlite3.c.

◆ SQLITE_DBCONFIG_DQS_DDL

#define SQLITE_DBCONFIG_DQS_DDL   1014 /* int int* */

Definition at line 3391 of file sqlite3.c.

◆ SQLITE_DBCONFIG_DQS_DML

#define SQLITE_DBCONFIG_DQS_DML   1013 /* int int* */

Definition at line 3390 of file sqlite3.c.

◆ SQLITE_DBCONFIG_ENABLE_FKEY

#define SQLITE_DBCONFIG_ENABLE_FKEY   1002 /* int int* */

Definition at line 3379 of file sqlite3.c.

◆ SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER

#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER   1004 /* int int* */

Definition at line 3381 of file sqlite3.c.

◆ SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION

#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION   1005 /* int int* */

Definition at line 3382 of file sqlite3.c.

◆ SQLITE_DBCONFIG_ENABLE_QPSG

#define SQLITE_DBCONFIG_ENABLE_QPSG   1007 /* int int* */

Definition at line 3384 of file sqlite3.c.

◆ SQLITE_DBCONFIG_ENABLE_TRIGGER

#define SQLITE_DBCONFIG_ENABLE_TRIGGER   1003 /* int int* */

Definition at line 3380 of file sqlite3.c.

◆ SQLITE_DBCONFIG_ENABLE_VIEW

#define SQLITE_DBCONFIG_ENABLE_VIEW   1015 /* int int* */

Definition at line 3392 of file sqlite3.c.

◆ SQLITE_DBCONFIG_LEGACY_ALTER_TABLE

#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE   1012 /* int int* */

Definition at line 3389 of file sqlite3.c.

◆ SQLITE_DBCONFIG_LEGACY_FILE_FORMAT

#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT   1016 /* int int* */

Definition at line 3393 of file sqlite3.c.

◆ SQLITE_DBCONFIG_LOOKASIDE

#define SQLITE_DBCONFIG_LOOKASIDE   1001 /* void* int int */

Definition at line 3378 of file sqlite3.c.

◆ SQLITE_DBCONFIG_MAINDBNAME

#define SQLITE_DBCONFIG_MAINDBNAME   1000 /* const char* */

Definition at line 3377 of file sqlite3.c.

◆ SQLITE_DBCONFIG_MAX

#define SQLITE_DBCONFIG_MAX   1017 /* Largest DBCONFIG */

Definition at line 3395 of file sqlite3.c.

◆ SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE

#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE   1006 /* int int* */

Definition at line 3383 of file sqlite3.c.

◆ SQLITE_DBCONFIG_RESET_DATABASE

#define SQLITE_DBCONFIG_RESET_DATABASE   1009 /* int int* */

Definition at line 3386 of file sqlite3.c.

◆ SQLITE_DBCONFIG_TRIGGER_EQP

#define SQLITE_DBCONFIG_TRIGGER_EQP   1008 /* int int* */

Definition at line 3385 of file sqlite3.c.

◆ SQLITE_DBCONFIG_TRUSTED_SCHEMA

#define SQLITE_DBCONFIG_TRUSTED_SCHEMA   1017 /* int int* */

Definition at line 3394 of file sqlite3.c.

◆ SQLITE_DBCONFIG_WRITABLE_SCHEMA

#define SQLITE_DBCONFIG_WRITABLE_SCHEMA   1011 /* int int* */

Definition at line 3388 of file sqlite3.c.

◆ SQLITE_DBSTATUS_CACHE_HIT

#define SQLITE_DBSTATUS_CACHE_HIT   7

Definition at line 9204 of file sqlite3.c.

Referenced by sqlite3PagerCacheStat().

◆ SQLITE_DBSTATUS_CACHE_MISS

#define SQLITE_DBSTATUS_CACHE_MISS   8

Definition at line 9205 of file sqlite3.c.

Referenced by sqlite3PagerCacheStat().

◆ SQLITE_DBSTATUS_CACHE_SPILL

#define SQLITE_DBSTATUS_CACHE_SPILL   12

Definition at line 9209 of file sqlite3.c.

◆ SQLITE_DBSTATUS_CACHE_USED

#define SQLITE_DBSTATUS_CACHE_USED   1

Definition at line 9198 of file sqlite3.c.

◆ SQLITE_DBSTATUS_CACHE_USED_SHARED

#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11

Definition at line 9208 of file sqlite3.c.

◆ SQLITE_DBSTATUS_CACHE_WRITE

#define SQLITE_DBSTATUS_CACHE_WRITE   9

Definition at line 9206 of file sqlite3.c.

Referenced by sqlite3PagerCacheStat().

◆ SQLITE_DBSTATUS_DEFERRED_FKS

#define SQLITE_DBSTATUS_DEFERRED_FKS   10

Definition at line 9207 of file sqlite3.c.

◆ SQLITE_DBSTATUS_LOOKASIDE_HIT

#define SQLITE_DBSTATUS_LOOKASIDE_HIT   4

Definition at line 9201 of file sqlite3.c.

◆ SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL

#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL   6

Definition at line 9203 of file sqlite3.c.

◆ SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE

#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE   5

Definition at line 9202 of file sqlite3.c.

◆ SQLITE_DBSTATUS_LOOKASIDE_USED

#define SQLITE_DBSTATUS_LOOKASIDE_USED   0

Definition at line 9197 of file sqlite3.c.

◆ SQLITE_DBSTATUS_MAX

#define SQLITE_DBSTATUS_MAX   12 /* Largest defined DBSTATUS */

Definition at line 9210 of file sqlite3.c.

◆ SQLITE_DBSTATUS_SCHEMA_USED

#define SQLITE_DBSTATUS_SCHEMA_USED   2

Definition at line 9199 of file sqlite3.c.

◆ SQLITE_DBSTATUS_STMT_USED

#define SQLITE_DBSTATUS_STMT_USED   3

Definition at line 9200 of file sqlite3.c.

◆ SQLITE_DEFAULT_AUTOVACUUM

#define SQLITE_DEFAULT_AUTOVACUUM   0

Definition at line 15026 of file sqlite3.c.

Referenced by sqlite3BtreeOpen().

◆ SQLITE_DEFAULT_CACHE_SIZE

#define SQLITE_DEFAULT_CACHE_SIZE   -2000

Definition at line 13347 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), sqlite3InitOne(), and sqlite3Pragma().

◆ SQLITE_DEFAULT_FILE_FORMAT

#define SQLITE_DEFAULT_FILE_FORMAT   4

Definition at line 14183 of file sqlite3.c.

◆ SQLITE_DEFAULT_FILE_PERMISSIONS

#define SQLITE_DEFAULT_FILE_PERMISSIONS   0644

Definition at line 33509 of file sqlite3.c.

Referenced by robust_open().

◆ SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT

#define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT   -1

Definition at line 14776 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_DEFAULT_LOOKASIDE

#define SQLITE_DEFAULT_LOOKASIDE   1200,40 /* 48KB of memory */

Definition at line 20557 of file sqlite3.c.

◆ SQLITE_DEFAULT_MEMSTATUS

#define SQLITE_DEFAULT_MEMSTATUS   1

Definition at line 13589 of file sqlite3.c.

◆ SQLITE_DEFAULT_MMAP_SIZE

#define SQLITE_DEFAULT_MMAP_SIZE   0

Definition at line 14527 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_DEFAULT_PAGE_SIZE

#define SQLITE_DEFAULT_PAGE_SIZE   4096

Definition at line 13400 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_DEFAULT_PCACHE_INITSZ

#define SQLITE_DEFAULT_PCACHE_INITSZ   20

Definition at line 14232 of file sqlite3.c.

◆ SQLITE_DEFAULT_PROXYDIR_PERMISSIONS

#define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS   0755

Definition at line 33516 of file sqlite3.c.

◆ SQLITE_DEFAULT_RECURSIVE_TRIGGERS

#define SQLITE_DEFAULT_RECURSIVE_TRIGGERS   0

Definition at line 14191 of file sqlite3.c.

◆ SQLITE_DEFAULT_SECTOR_SIZE

#define SQLITE_DEFAULT_SECTOR_SIZE   4096

Definition at line 16314 of file sqlite3.c.

Referenced by setDeviceCharacteristics(), and sqlite3OsDeviceCharacteristics().

◆ SQLITE_DEFAULT_SORTERREF_SIZE

#define SQLITE_DEFAULT_SORTERREF_SIZE   0x7fffffff

Definition at line 14239 of file sqlite3.c.

Referenced by sqlite3_config().

◆ SQLITE_DEFAULT_SYNCHRONOUS

#define SQLITE_DEFAULT_SYNCHRONOUS   2

Definition at line 16592 of file sqlite3.c.

Referenced by attachFunc(), lockBtree(), and openDatabase().

◆ SQLITE_DEFAULT_WAL_AUTOCHECKPOINT

#define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT   1000

Definition at line 13355 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_DEFAULT_WAL_SYNCHRONOUS

#define SQLITE_DEFAULT_WAL_SYNCHRONOUS   SQLITE_DEFAULT_SYNCHRONOUS

Definition at line 16595 of file sqlite3.c.

Referenced by lockBtree().

◆ SQLITE_DEFAULT_WORKER_THREADS

#define SQLITE_DEFAULT_WORKER_THREADS   0

Definition at line 14215 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_Defensive

#define SQLITE_Defensive   0x10000000 /* Input SQL is likely hostile */

Definition at line 17007 of file sqlite3.c.

Referenced by openDatabase(), and sqlite3Pragma().

◆ SQLITE_DeferFKs

#define SQLITE_DeferFKs   0x00080000 /* Defer all FK constraints */

◆ SQLITE_DELETE

#define SQLITE_DELETE   9 /* Table Name NULL */

Definition at line 4128 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), and sqlite3VdbeExec().

◆ SQLITE_DENY

#define SQLITE_DENY   1 /* Abort the SQL statement with an error */

◆ SQLITE_DEPRECATED

#define SQLITE_DEPRECATED

Definition at line 1131 of file sqlite3.c.

◆ SQLITE_DESERIALIZE_FREEONCLOSE

#define SQLITE_DESERIALIZE_FREEONCLOSE   1 /* Call sqlite3_free() on close */

Definition at line 10848 of file sqlite3.c.

◆ SQLITE_DESERIALIZE_READONLY

#define SQLITE_DESERIALIZE_READONLY   4 /* Database is read-only */

Definition at line 10850 of file sqlite3.c.

◆ SQLITE_DESERIALIZE_RESIZEABLE

#define SQLITE_DESERIALIZE_RESIZEABLE   2 /* Resize using sqlite3_realloc64() */

Definition at line 10849 of file sqlite3.c.

◆ SQLITE_DETACH

#define SQLITE_DETACH   25 /* Database Name NULL */

Definition at line 4144 of file sqlite3.c.

Referenced by sqlite3Detach().

◆ SQLITE_DETERMINISTIC

#define SQLITE_DETERMINISTIC   0x000000800

Definition at line 6324 of file sqlite3.c.

Referenced by sqlite3CreateFunc().

◆ SQLITE_DIRECTONLY

#define SQLITE_DIRECTONLY   0x000080000

Definition at line 6325 of file sqlite3.c.

Referenced by sqlite3CreateFunc().

◆ SQLITE_DistinctOpt

#define SQLITE_DistinctOpt   0x0010 /* DISTINCT using indexes */

Definition at line 17045 of file sqlite3.c.

Referenced by sqlite3WhereBegin().

◆ SQLITE_DONE

◆ SQLITE_DQS

#define SQLITE_DQS   3

◆ SQLITE_DqsDDL

#define SQLITE_DqsDDL   0x20000000 /* dbl-quoted strings allowed in DDL*/

Definition at line 17008 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_DqsDML

#define SQLITE_DqsDML   0x40000000 /* dbl-quoted strings allowed in DML*/

Definition at line 17009 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_DROP_INDEX

#define SQLITE_DROP_INDEX   10 /* Index Name Table Name */

Definition at line 4129 of file sqlite3.c.

◆ SQLITE_DROP_TABLE

#define SQLITE_DROP_TABLE   11 /* Table Name NULL */

Definition at line 4130 of file sqlite3.c.

◆ SQLITE_DROP_TEMP_INDEX

#define SQLITE_DROP_TEMP_INDEX   12 /* Index Name Table Name */

Definition at line 4131 of file sqlite3.c.

◆ SQLITE_DROP_TEMP_TABLE

#define SQLITE_DROP_TEMP_TABLE   13 /* Table Name NULL */

Definition at line 4132 of file sqlite3.c.

◆ SQLITE_DROP_TEMP_TRIGGER

#define SQLITE_DROP_TEMP_TRIGGER   14 /* Trigger Name Table Name */

Definition at line 4133 of file sqlite3.c.

◆ SQLITE_DROP_TEMP_VIEW

#define SQLITE_DROP_TEMP_VIEW   15 /* View Name NULL */

Definition at line 4134 of file sqlite3.c.

◆ SQLITE_DROP_TRIGGER

#define SQLITE_DROP_TRIGGER   16 /* Trigger Name Table Name */

Definition at line 4135 of file sqlite3.c.

◆ SQLITE_DROP_VIEW

#define SQLITE_DROP_VIEW   17 /* View Name NULL */

Definition at line 4136 of file sqlite3.c.

◆ SQLITE_DROP_VTABLE

#define SQLITE_DROP_VTABLE   30 /* Table Name Module Name */

Definition at line 4149 of file sqlite3.c.

◆ SQLITE_DYNAMIC

◆ SQLITE_ECEL_DUP

#define SQLITE_ECEL_DUP   0x01 /* Deep, not shallow copies */

◆ SQLITE_ECEL_FACTOR

#define SQLITE_ECEL_FACTOR   0x02 /* Factor out constant terms */

Definition at line 19666 of file sqlite3.c.

Referenced by sqlite3ExprCodeExprList(), and sqlite3ExprCodeTarget().

◆ SQLITE_ECEL_OMITREF

#define SQLITE_ECEL_OMITREF   0x08 /* Omit if ExprList.u.x.iOrderByCol */

Definition at line 19668 of file sqlite3.c.

Referenced by selectInnerLoop(), and sqlite3ExprCodeExprList().

◆ SQLITE_ECEL_REF

#define SQLITE_ECEL_REF   0x04 /* Use ExprList.u.x.iOrderByCol */

Definition at line 19667 of file sqlite3.c.

Referenced by selectInnerLoop(), and sqlite3ExprCodeExprList().

◆ SQLITE_EMPTY

#define SQLITE_EMPTY   16 /* Internal use only */

◆ SQLITE_ENABLE_LOCKING_STYLE

#define SQLITE_ENABLE_LOCKING_STYLE   0

Definition at line 33414 of file sqlite3.c.

◆ SQLITE_EnableQPSG

#define SQLITE_EnableQPSG   0x00800000 /* Query Planner Stability Guarantee*/

◆ SQLITE_EnableTrigger

#define SQLITE_EnableTrigger   0x00040000 /* True to enable triggers */

Definition at line 16997 of file sqlite3.c.

Referenced by openDatabase(), and sqlite3TriggersExist().

◆ SQLITE_EnableView

#define SQLITE_EnableView   0x80000000 /* Enable the use of views */

Definition at line 17010 of file sqlite3.c.

Referenced by openDatabase(), and selectExpander().

◆ SQLITE_ERROR

◆ SQLITE_ERROR_MISSING_COLLSEQ

#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))

Definition at line 1520 of file sqlite3.c.

Referenced by sqlite3GetCollSeq(), and sqlite3KeyInfoOfIndex().

◆ SQLITE_ERROR_RETRY

#define SQLITE_ERROR_RETRY   (SQLITE_ERROR | (2<<8))

Definition at line 1521 of file sqlite3.c.

Referenced by sqlite3KeyInfoOfIndex().

◆ SQLITE_ERROR_SNAPSHOT

#define SQLITE_ERROR_SNAPSHOT   (SQLITE_ERROR | (3<<8))

Definition at line 1522 of file sqlite3.c.

Referenced by sqlite3WalBeginReadTransaction().

◆ SQLITE_EXPERIMENTAL

#define SQLITE_EXPERIMENTAL

Definition at line 1132 of file sqlite3.c.

◆ SQLITE_EXTENSION_INIT1

#define SQLITE_EXTENSION_INIT1   /*no-op*/

Definition at line 124243 of file sqlite3.c.

◆ SQLITE_EXTENSION_INIT2

#define SQLITE_EXTENSION_INIT2 ( v)    (void)v; /* unused parameter */

Definition at line 124244 of file sqlite3.c.

◆ SQLITE_EXTENSION_INIT3

#define SQLITE_EXTENSION_INIT3   /*no-op*/

Definition at line 124245 of file sqlite3.c.

◆ SQLITE_EXTERN

#define SQLITE_EXTERN   extern

Definition at line 1097 of file sqlite3.c.

◆ SQLITE_FactorOutConst

#define SQLITE_FactorOutConst   0x0008 /* Constant factoring */

Definition at line 17044 of file sqlite3.c.

◆ SQLITE_FAIL

#define SQLITE_FAIL   3

Definition at line 10287 of file sqlite3.c.

Referenced by sqlite3_vtab_on_conflict().

◆ SQLITE_FAULTINJECTOR_COUNT

#define SQLITE_FAULTINJECTOR_COUNT   1

Definition at line 20210 of file sqlite3.c.

◆ SQLITE_FAULTINJECTOR_MALLOC

#define SQLITE_FAULTINJECTOR_MALLOC   0

Definition at line 20209 of file sqlite3.c.

◆ SQLITE_FCNTL_BEGIN_ATOMIC_WRITE

#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE   31

Definition at line 2208 of file sqlite3.c.

Referenced by sqlite3PagerCommitPhaseOne().

◆ SQLITE_FCNTL_BUSYHANDLER

#define SQLITE_FCNTL_BUSYHANDLER   15

Definition at line 2193 of file sqlite3.c.

Referenced by sqlite3PagerSetBusyHandler().

◆ SQLITE_FCNTL_CHUNK_SIZE

#define SQLITE_FCNTL_CHUNK_SIZE   6

Definition at line 2184 of file sqlite3.c.

◆ SQLITE_FCNTL_CKPT_DONE

#define SQLITE_FCNTL_CKPT_DONE   37

Definition at line 2214 of file sqlite3.c.

Referenced by walCheckpoint().

◆ SQLITE_FCNTL_CKPT_START

#define SQLITE_FCNTL_CKPT_START   39

Definition at line 2216 of file sqlite3.c.

Referenced by walCheckpoint().

◆ SQLITE_FCNTL_COMMIT_ATOMIC_WRITE

#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE   32

Definition at line 2209 of file sqlite3.c.

Referenced by sqlite3PagerCommitPhaseOne().

◆ SQLITE_FCNTL_COMMIT_PHASETWO

#define SQLITE_FCNTL_COMMIT_PHASETWO   22

Definition at line 2199 of file sqlite3.c.

Referenced by pager_end_transaction(), and sqlite3OsFileControl().

◆ SQLITE_FCNTL_DATA_VERSION

#define SQLITE_FCNTL_DATA_VERSION   35

Definition at line 2212 of file sqlite3.c.

◆ SQLITE_FCNTL_DB_UNCHANGED

#define SQLITE_FCNTL_DB_UNCHANGED   0xca093fa0

Definition at line 16448 of file sqlite3.c.

Referenced by pager_playback().

◆ SQLITE_FCNTL_FILE_POINTER

#define SQLITE_FCNTL_FILE_POINTER   7

Definition at line 2185 of file sqlite3.c.

◆ SQLITE_FCNTL_GET_LOCKPROXYFILE

#define SQLITE_FCNTL_GET_LOCKPROXYFILE   2

Definition at line 2180 of file sqlite3.c.

◆ SQLITE_FCNTL_HAS_MOVED

#define SQLITE_FCNTL_HAS_MOVED   20

Definition at line 2197 of file sqlite3.c.

Referenced by databaseIsUnmoved().

◆ SQLITE_FCNTL_JOURNAL_POINTER

#define SQLITE_FCNTL_JOURNAL_POINTER   28

Definition at line 2205 of file sqlite3.c.

◆ SQLITE_FCNTL_LAST_ERRNO

#define SQLITE_FCNTL_LAST_ERRNO   4

Definition at line 2182 of file sqlite3.c.

◆ SQLITE_FCNTL_LOCK_TIMEOUT

#define SQLITE_FCNTL_LOCK_TIMEOUT   34

Definition at line 2211 of file sqlite3.c.

Referenced by sqlite3OsFileControl().

◆ SQLITE_FCNTL_LOCKSTATE

#define SQLITE_FCNTL_LOCKSTATE   1

Definition at line 2179 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ SQLITE_FCNTL_MMAP_SIZE

#define SQLITE_FCNTL_MMAP_SIZE   18

Definition at line 2195 of file sqlite3.c.

Referenced by sqlite3Pragma(), and vdbeSorterOpenTempFile().

◆ SQLITE_FCNTL_OVERWRITE

#define SQLITE_FCNTL_OVERWRITE   11

Definition at line 2189 of file sqlite3.c.

Referenced by sqlite3BtreeCopyFile().

◆ SQLITE_FCNTL_PDB

#define SQLITE_FCNTL_PDB   30

Definition at line 2207 of file sqlite3.c.

Referenced by sqlite3BtreeOpen().

◆ SQLITE_FCNTL_PERSIST_WAL

#define SQLITE_FCNTL_PERSIST_WAL   10

Definition at line 2188 of file sqlite3.c.

◆ SQLITE_FCNTL_POWERSAFE_OVERWRITE

#define SQLITE_FCNTL_POWERSAFE_OVERWRITE   13

Definition at line 2191 of file sqlite3.c.

◆ SQLITE_FCNTL_PRAGMA

#define SQLITE_FCNTL_PRAGMA   14

Definition at line 2192 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ SQLITE_FCNTL_RBU

#define SQLITE_FCNTL_RBU   26

Definition at line 2203 of file sqlite3.c.

◆ SQLITE_FCNTL_RESERVE_BYTES

#define SQLITE_FCNTL_RESERVE_BYTES   38

Definition at line 2215 of file sqlite3.c.

◆ SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE

#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE   33

Definition at line 2210 of file sqlite3.c.

Referenced by sqlite3PagerCommitPhaseOne().

◆ SQLITE_FCNTL_SET_LOCKPROXYFILE

#define SQLITE_FCNTL_SET_LOCKPROXYFILE   3

Definition at line 2181 of file sqlite3.c.

◆ SQLITE_FCNTL_SIZE_HINT

#define SQLITE_FCNTL_SIZE_HINT   5

Definition at line 2183 of file sqlite3.c.

Referenced by pager_write_pagelist(), and walCheckpoint().

◆ SQLITE_FCNTL_SIZE_LIMIT

#define SQLITE_FCNTL_SIZE_LIMIT   36

Definition at line 2213 of file sqlite3.c.

◆ SQLITE_FCNTL_SYNC

#define SQLITE_FCNTL_SYNC   21

Definition at line 2198 of file sqlite3.c.

Referenced by sqlite3PagerSync().

◆ SQLITE_FCNTL_SYNC_OMITTED

#define SQLITE_FCNTL_SYNC_OMITTED   8

Definition at line 2186 of file sqlite3.c.

◆ SQLITE_FCNTL_TEMPFILENAME

#define SQLITE_FCNTL_TEMPFILENAME   16

Definition at line 2194 of file sqlite3.c.

◆ SQLITE_FCNTL_TRACE

#define SQLITE_FCNTL_TRACE   19

Definition at line 2196 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_FCNTL_VFS_POINTER

#define SQLITE_FCNTL_VFS_POINTER   27

Definition at line 2204 of file sqlite3.c.

◆ SQLITE_FCNTL_VFSNAME

#define SQLITE_FCNTL_VFSNAME   12

Definition at line 2190 of file sqlite3.c.

◆ SQLITE_FCNTL_WAL_BLOCK

#define SQLITE_FCNTL_WAL_BLOCK   24

Definition at line 2201 of file sqlite3.c.

◆ SQLITE_FCNTL_WIN32_AV_RETRY

#define SQLITE_FCNTL_WIN32_AV_RETRY   9

Definition at line 2187 of file sqlite3.c.

◆ SQLITE_FCNTL_WIN32_GET_HANDLE

#define SQLITE_FCNTL_WIN32_GET_HANDLE   29

Definition at line 2206 of file sqlite3.c.

◆ SQLITE_FCNTL_WIN32_SET_HANDLE

#define SQLITE_FCNTL_WIN32_SET_HANDLE   23

Definition at line 2200 of file sqlite3.c.

◆ SQLITE_FCNTL_ZIPVFS

#define SQLITE_FCNTL_ZIPVFS   25

Definition at line 2202 of file sqlite3.c.

◆ SQLITE_FILE_HEADER

#define SQLITE_FILE_HEADER   "SQLite format 3"

Definition at line 63718 of file sqlite3.c.

◆ SQLITE_FLOAT

#define SQLITE_FLOAT   2

Definition at line 5792 of file sqlite3.c.

Referenced by db_push_value(), isDate(), quoteFunc(), and vm_push_column().

◆ SQLITE_ForeignKeys

#define SQLITE_ForeignKeys   0x00004000 /* Enforce foreign key constraints */

◆ SQLITE_FORMAT

#define SQLITE_FORMAT   24 /* Not used */

Definition at line 1494 of file sqlite3.c.

◆ SQLITE_FP_PRECISION_LIMIT

#define SQLITE_FP_PRECISION_LIMIT   100000000

Definition at line 28335 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ SQLITE_FRAME_MAGIC

#define SQLITE_FRAME_MAGIC   0x879fb71e

Definition at line 20891 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_FREE

#define SQLITE_FREE ( x)    free(x)

Definition at line 23624 of file sqlite3.c.

Referenced by sqlite3MemFree().

◆ SQLITE_FSFLAGS_IS_MSDOS

#define SQLITE_FSFLAGS_IS_MSDOS   0x1

Definition at line 33496 of file sqlite3.c.

Referenced by findInodeInfo(), and unixOpen().

◆ SQLITE_Fts3Tokenizer

#define SQLITE_Fts3Tokenizer   0x00400000 /* Enable fts3_tokenizer(2) */

Definition at line 17001 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_FULL

#define SQLITE_FULL   13 /* Insertion failed because database is full */

◆ SQLITE_FullColNames

#define SQLITE_FullColNames   0x00000004 /* Show full column names on SELECT */

Definition at line 16980 of file sqlite3.c.

Referenced by generateColumnNames(), and selectExpander().

◆ SQLITE_FullFSync

#define SQLITE_FullFSync   0x00000008 /* Use full fsync on the backend */

Definition at line 16981 of file sqlite3.c.

Referenced by setAllPagerFlags().

◆ SQLITE_FUNC_CASE

#define SQLITE_FUNC_CASE   0x0008 /* Case-sensitive LIKE-type function */

◆ SQLITE_FUNC_CONSTANT

#define SQLITE_FUNC_CONSTANT   0x0800 /* Constant inputs give a constant output */

Definition at line 17155 of file sqlite3.c.

Referenced by resolveExprStep(), and sqlite3CreateFunc().

◆ SQLITE_FUNC_COUNT

#define SQLITE_FUNC_COUNT   0x0100 /* Built-in count(*) aggregate */

Definition at line 17152 of file sqlite3.c.

Referenced by isSimpleCount(), and sqlite3RegisterBuiltinFunctions().

◆ SQLITE_FUNC_DIRECT

#define SQLITE_FUNC_DIRECT   0x00080000 /* Not for use in TRIGGERs or VIEWs */

◆ SQLITE_FUNC_ENCMASK

#define SQLITE_FUNC_ENCMASK   0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */

Definition at line 17145 of file sqlite3.c.

Referenced by matchQuality(), and sqlite3CreateFunc().

◆ SQLITE_FUNC_EPHEM

#define SQLITE_FUNC_EPHEM   0x0010 /* Ephemeral. Delete with VDBE */

Definition at line 17148 of file sqlite3.c.

Referenced by freeEphemeralFunction(), and sqlite3VtabOverloadFunction().

◆ SQLITE_FUNC_HASH

#define SQLITE_FUNC_HASH ( C,
L )   (((C)+(L))%SQLITE_FUNC_HASH_SZ)

Definition at line 16763 of file sqlite3.c.

Referenced by sqlite3FindFunction().

◆ SQLITE_FUNC_HASH_SZ

#define SQLITE_FUNC_HASH_SZ   23

Definition at line 16759 of file sqlite3.c.

Referenced by sqlite3Pragma(), and sqlite3RegisterBuiltinFunctions().

◆ SQLITE_FUNC_INLINE

#define SQLITE_FUNC_INLINE   0x00400000 /* Functions implemented in-line */

Definition at line 17165 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget().

◆ SQLITE_FUNC_INTERNAL

#define SQLITE_FUNC_INTERNAL   0x00040000 /* For use by NestedParse() only */

Definition at line 17161 of file sqlite3.c.

Referenced by resolveExprStep().

◆ SQLITE_FUNC_LENGTH

#define SQLITE_FUNC_LENGTH   0x0040 /* Built-in length() function */

Definition at line 17150 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3RegisterBuiltinFunctions().

◆ SQLITE_FUNC_LIKE

#define SQLITE_FUNC_LIKE   0x0004 /* Candidate for the LIKE optimization */

◆ SQLITE_FUNC_MINMAX

#define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */

◆ SQLITE_FUNC_NEEDCOLL

#define SQLITE_FUNC_NEEDCOLL   0x0020 /* sqlite3GetFuncCollSeq() might be called*/

◆ SQLITE_FUNC_OFFSET

#define SQLITE_FUNC_OFFSET   0x8000 /* Built-in sqlite_offset() function */

Definition at line 17159 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3RegisterBuiltinFunctions().

◆ SQLITE_FUNC_SLOCHNG

#define SQLITE_FUNC_SLOCHNG
Value:
0x2000 /* "Slow Change". Value constant during a
** single query - might change over time */

Definition at line 17157 of file sqlite3.c.

Referenced by resolveExprStep().

◆ SQLITE_FUNC_SUBTYPE

#define SQLITE_FUNC_SUBTYPE   0x00100000 /* Result likely to have sub-type */

Definition at line 17163 of file sqlite3.c.

Referenced by sqlite3WindowRewrite().

◆ SQLITE_FUNC_TEST

#define SQLITE_FUNC_TEST   0x4000 /* Built-in testing functions */

Definition at line 17158 of file sqlite3.c.

◆ SQLITE_FUNC_TYPEOF

#define SQLITE_FUNC_TYPEOF   0x0080 /* Built-in typeof() function */

Definition at line 17151 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget(), and sqlite3RegisterBuiltinFunctions().

◆ SQLITE_FUNC_UNLIKELY

#define SQLITE_FUNC_UNLIKELY   0x0400 /* Built-in unlikely() function */

Definition at line 17154 of file sqlite3.c.

Referenced by resolveExprStep(), and sqlite3RegisterBuiltinFunctions().

◆ SQLITE_FUNC_UNSAFE

#define SQLITE_FUNC_UNSAFE   0x00200000 /* Function has side effects */

◆ SQLITE_FUNC_WINDOW

#define SQLITE_FUNC_WINDOW   0x00010000 /* Built-in window-only function */

Definition at line 17160 of file sqlite3.c.

Referenced by resolveExprStep(), and sqlite3WindowUpdate().

◆ SQLITE_FUNCTION

#define SQLITE_FUNCTION   31 /* NULL Function Name */

Definition at line 4150 of file sqlite3.c.

Referenced by resolveExprStep().

◆ SQLITE_GET_LOCKPROXYFILE

#define SQLITE_GET_LOCKPROXYFILE   SQLITE_FCNTL_GET_LOCKPROXYFILE

Definition at line 2219 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ SQLITE_GroupByOrder

#define SQLITE_GroupByOrder   0x0004 /* GROUPBY cover of ORDERBY */

Definition at line 17043 of file sqlite3.c.

Referenced by sqlite3Select().

◆ SQLITE_HASH_H

#define SQLITE_HASH_H

Definition at line 13857 of file sqlite3.c.

◆ SQLITE_IDXTYPE_APPDEF

#define SQLITE_IDXTYPE_APPDEF   0 /* Created using CREATE INDEX */

Definition at line 17817 of file sqlite3.c.

Referenced by deleteTable(), sqlite3CreateIndex(), and yy_reduce().

◆ SQLITE_IDXTYPE_IPK

#define SQLITE_IDXTYPE_IPK   3 /* INTEGER PRIMARY KEY index */

Definition at line 17820 of file sqlite3.c.

Referenced by whereLoopAddBtree(), and whereLoopInsert().

◆ SQLITE_IDXTYPE_PRIMARYKEY

#define SQLITE_IDXTYPE_PRIMARYKEY   2 /* Is the PRIMARY KEY for the table */

◆ SQLITE_IDXTYPE_UNIQUE

#define SQLITE_IDXTYPE_UNIQUE   1 /* Implements a UNIQUE constraint */

Definition at line 17818 of file sqlite3.c.

Referenced by yy_reduce().

◆ SQLITE_IGNORE

#define SQLITE_IGNORE   2 /* Don't allow access, but don't generate an error */

◆ SQLITE_IgnoreChecks

#define SQLITE_IgnoreChecks   0x00000200 /* Do not enforce check constraints */

Definition at line 16988 of file sqlite3.c.

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3Pragma().

◆ SQLITE_INDEX_CONSTRAINT_EQ

#define SQLITE_INDEX_CONSTRAINT_EQ   2

Definition at line 7947 of file sqlite3.c.

Referenced by allocateIndexInfo(), and pragmaVtabBestIndex().

◆ SQLITE_INDEX_CONSTRAINT_FUNCTION

#define SQLITE_INDEX_CONSTRAINT_FUNCTION   150

Definition at line 7961 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_GE

#define SQLITE_INDEX_CONSTRAINT_GE   32

Definition at line 7951 of file sqlite3.c.

Referenced by allocateIndexInfo().

◆ SQLITE_INDEX_CONSTRAINT_GLOB

#define SQLITE_INDEX_CONSTRAINT_GLOB   66

Definition at line 7954 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_GT

#define SQLITE_INDEX_CONSTRAINT_GT   4

Definition at line 7948 of file sqlite3.c.

Referenced by allocateIndexInfo().

◆ SQLITE_INDEX_CONSTRAINT_IS

#define SQLITE_INDEX_CONSTRAINT_IS   72

Definition at line 7960 of file sqlite3.c.

Referenced by allocateIndexInfo().

◆ SQLITE_INDEX_CONSTRAINT_ISNOT

#define SQLITE_INDEX_CONSTRAINT_ISNOT   69

Definition at line 7957 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_ISNOTNULL

#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL   70

Definition at line 7958 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_ISNULL

#define SQLITE_INDEX_CONSTRAINT_ISNULL   71

Definition at line 7959 of file sqlite3.c.

Referenced by allocateIndexInfo().

◆ SQLITE_INDEX_CONSTRAINT_LE

#define SQLITE_INDEX_CONSTRAINT_LE   8

Definition at line 7949 of file sqlite3.c.

Referenced by allocateIndexInfo().

◆ SQLITE_INDEX_CONSTRAINT_LIKE

#define SQLITE_INDEX_CONSTRAINT_LIKE   65

Definition at line 7953 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_LT

#define SQLITE_INDEX_CONSTRAINT_LT   16

Definition at line 7950 of file sqlite3.c.

Referenced by allocateIndexInfo().

◆ SQLITE_INDEX_CONSTRAINT_MATCH

#define SQLITE_INDEX_CONSTRAINT_MATCH   64

Definition at line 7952 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_NE

#define SQLITE_INDEX_CONSTRAINT_NE   68

Definition at line 7956 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_CONSTRAINT_REGEXP

#define SQLITE_INDEX_CONSTRAINT_REGEXP   67

Definition at line 7955 of file sqlite3.c.

Referenced by isAuxiliaryVtabOperator().

◆ SQLITE_INDEX_SCAN_UNIQUE

#define SQLITE_INDEX_SCAN_UNIQUE   1 /* Scan visits at most 1 row */

Definition at line 7937 of file sqlite3.c.

Referenced by whereLoopAddVirtualOne().

◆ SQLITE_INNOCUOUS

#define SQLITE_INNOCUOUS   0x000200000

Definition at line 6327 of file sqlite3.c.

Referenced by sqlite3CreateFunc().

◆ SQLITE_INSERT

#define SQLITE_INSERT   18 /* Table Name NULL */

◆ SQLITE_INT_TO_PTR

◆ SQLITE_INTEGER

#define SQLITE_INTEGER   1

Definition at line 5791 of file sqlite3.c.

Referenced by absFunc(), db_push_value(), isDate(), quoteFunc(), statPush(), sumStep(), and vm_push_column().

◆ SQLITE_INTEGRITY_CHECK_ERROR_MAX

#define SQLITE_INTEGRITY_CHECK_ERROR_MAX   100

◆ SQLITE_INTERNAL

#define SQLITE_INTERNAL   2 /* Internal logic error in SQLite */

Definition at line 1472 of file sqlite3.c.

◆ SQLITE_INTERRUPT

#define SQLITE_INTERRUPT   9 /* Operation terminated by sqlite3_interrupt()*/

◆ SQLITE_IOCAP_ATOMIC

#define SQLITE_IOCAP_ATOMIC   0x00000001

Definition at line 1661 of file sqlite3.c.

Referenced by jrnlBufferSize(), and sqlite3PagerOpen().

◆ SQLITE_IOCAP_ATOMIC16K

#define SQLITE_IOCAP_ATOMIC16K   0x00000040

Definition at line 1667 of file sqlite3.c.

◆ SQLITE_IOCAP_ATOMIC1K

#define SQLITE_IOCAP_ATOMIC1K   0x00000004

Definition at line 1663 of file sqlite3.c.

◆ SQLITE_IOCAP_ATOMIC2K

#define SQLITE_IOCAP_ATOMIC2K   0x00000008

Definition at line 1664 of file sqlite3.c.

◆ SQLITE_IOCAP_ATOMIC32K

#define SQLITE_IOCAP_ATOMIC32K   0x00000080

Definition at line 1668 of file sqlite3.c.

◆ SQLITE_IOCAP_ATOMIC4K

#define SQLITE_IOCAP_ATOMIC4K   0x00000010

Definition at line 1665 of file sqlite3.c.

◆ SQLITE_IOCAP_ATOMIC512

#define SQLITE_IOCAP_ATOMIC512   0x00000002

Definition at line 1662 of file sqlite3.c.

Referenced by jrnlBufferSize(), and sqlite3PagerOpen().

◆ SQLITE_IOCAP_ATOMIC64K

#define SQLITE_IOCAP_ATOMIC64K   0x00000100

Definition at line 1669 of file sqlite3.c.

Referenced by jrnlBufferSize(), and sqlite3PagerOpen().

◆ SQLITE_IOCAP_ATOMIC8K

#define SQLITE_IOCAP_ATOMIC8K   0x00000020

Definition at line 1666 of file sqlite3.c.

◆ SQLITE_IOCAP_BATCH_ATOMIC

#define SQLITE_IOCAP_BATCH_ATOMIC   0x00004000

◆ SQLITE_IOCAP_IMMUTABLE

#define SQLITE_IOCAP_IMMUTABLE   0x00002000

Definition at line 1674 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_IOCAP_POWERSAFE_OVERWRITE

#define SQLITE_IOCAP_POWERSAFE_OVERWRITE   0x00001000

Definition at line 1673 of file sqlite3.c.

Referenced by setDeviceCharacteristics(), setSectorSize(), and sqlite3WalOpen().

◆ SQLITE_IOCAP_SAFE_APPEND

#define SQLITE_IOCAP_SAFE_APPEND   0x00000200

Definition at line 1670 of file sqlite3.c.

Referenced by syncJournal(), and writeJournalHdr().

◆ SQLITE_IOCAP_SEQUENTIAL

#define SQLITE_IOCAP_SEQUENTIAL   0x00000400

Definition at line 1671 of file sqlite3.c.

Referenced by sqlite3WalOpen(), syncJournal(), and vdbeCommit().

◆ SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN

#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN   0x00000800

Definition at line 1672 of file sqlite3.c.

Referenced by hasHotJournal(), and pager_unlock().

◆ SQLITE_IOERR

◆ SQLITE_IOERR_ACCESS

#define SQLITE_IOERR_ACCESS   (SQLITE_IOERR | (13<<8))

Definition at line 1535 of file sqlite3.c.

Referenced by unixAccess(), unixOpen(), and vdbeSorterOpenTempFile().

◆ SQLITE_IOERR_AUTH

#define SQLITE_IOERR_AUTH   (SQLITE_IOERR | (28<<8))

Definition at line 1550 of file sqlite3.c.

◆ SQLITE_IOERR_BEGIN_ATOMIC

#define SQLITE_IOERR_BEGIN_ATOMIC   (SQLITE_IOERR | (29<<8))

Definition at line 1551 of file sqlite3.c.

◆ SQLITE_IOERR_BLOCKED

#define SQLITE_IOERR_BLOCKED   (SQLITE_IOERR | (11<<8))

Definition at line 1533 of file sqlite3.c.

Referenced by sqlite3PagerCommitPhaseOne().

◆ SQLITE_IOERR_CHECKRESERVEDLOCK

#define SQLITE_IOERR_CHECKRESERVEDLOCK   (SQLITE_IOERR | (14<<8))

◆ SQLITE_IOERR_CLOSE

#define SQLITE_IOERR_CLOSE   (SQLITE_IOERR | (16<<8))

Definition at line 1538 of file sqlite3.c.

Referenced by robust_close().

◆ SQLITE_IOERR_COMMIT_ATOMIC

#define SQLITE_IOERR_COMMIT_ATOMIC   (SQLITE_IOERR | (30<<8))

Definition at line 1552 of file sqlite3.c.

◆ SQLITE_IOERR_CONVPATH

#define SQLITE_IOERR_CONVPATH   (SQLITE_IOERR | (26<<8))

Definition at line 1548 of file sqlite3.c.

◆ SQLITE_IOERR_DATA

#define SQLITE_IOERR_DATA   (SQLITE_IOERR | (32<<8))

Definition at line 1554 of file sqlite3.c.

◆ SQLITE_IOERR_DELETE

#define SQLITE_IOERR_DELETE   (SQLITE_IOERR | (10<<8))

Definition at line 1532 of file sqlite3.c.

Referenced by unixDelete().

◆ SQLITE_IOERR_DELETE_NOENT

#define SQLITE_IOERR_DELETE_NOENT   (SQLITE_IOERR | (23<<8))

Definition at line 1545 of file sqlite3.c.

Referenced by unixDelete().

◆ SQLITE_IOERR_DIR_CLOSE

#define SQLITE_IOERR_DIR_CLOSE   (SQLITE_IOERR | (17<<8))

Definition at line 1539 of file sqlite3.c.

◆ SQLITE_IOERR_DIR_FSYNC

#define SQLITE_IOERR_DIR_FSYNC   (SQLITE_IOERR | (5<<8))

Definition at line 1527 of file sqlite3.c.

Referenced by unixDelete().

◆ SQLITE_IOERR_FSTAT

#define SQLITE_IOERR_FSTAT   (SQLITE_IOERR | (7<<8))

Definition at line 1529 of file sqlite3.c.

Referenced by fcntlSizeHint(), and unixOpenSharedMemory().

◆ SQLITE_IOERR_FSYNC

#define SQLITE_IOERR_FSYNC   (SQLITE_IOERR | (4<<8))

Definition at line 1526 of file sqlite3.c.

Referenced by unixSync().

◆ SQLITE_IOERR_GETTEMPPATH

#define SQLITE_IOERR_GETTEMPPATH   (SQLITE_IOERR | (25<<8))

Definition at line 1547 of file sqlite3.c.

Referenced by unixGetTempname().

◆ SQLITE_IOERR_LOCK

#define SQLITE_IOERR_LOCK   (SQLITE_IOERR | (15<<8))

Definition at line 1537 of file sqlite3.c.

Referenced by dotlockLock(), sqliteErrorFromPosixError(), unixLock(), and unixLockSharedMemory().

◆ SQLITE_IOERR_MMAP

#define SQLITE_IOERR_MMAP   (SQLITE_IOERR | (24<<8))

Definition at line 1546 of file sqlite3.c.

◆ SQLITE_IOERR_NOMEM

#define SQLITE_IOERR_NOMEM   (SQLITE_IOERR | (12<<8))

◆ SQLITE_IOERR_NOMEM_BKPT

#define SQLITE_IOERR_NOMEM_BKPT   SQLITE_IOERR_NOMEM

Definition at line 19277 of file sqlite3.c.

Referenced by unixShmMap().

◆ SQLITE_IOERR_RDLOCK

#define SQLITE_IOERR_RDLOCK   (SQLITE_IOERR | (9<<8))

Definition at line 1531 of file sqlite3.c.

Referenced by posixUnlock(), and sqliteErrorFromPosixError().

◆ SQLITE_IOERR_READ

#define SQLITE_IOERR_READ   (SQLITE_IOERR | (1<<8))

Definition at line 1523 of file sqlite3.c.

Referenced by unixRead(), and vdbePmaReaderSeek().

◆ SQLITE_IOERR_ROLLBACK_ATOMIC

#define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))

Definition at line 1553 of file sqlite3.c.

◆ SQLITE_IOERR_SEEK

#define SQLITE_IOERR_SEEK   (SQLITE_IOERR | (22<<8))

Definition at line 1544 of file sqlite3.c.

◆ SQLITE_IOERR_SHMLOCK

#define SQLITE_IOERR_SHMLOCK   (SQLITE_IOERR | (20<<8))

Definition at line 1542 of file sqlite3.c.

◆ SQLITE_IOERR_SHMMAP

#define SQLITE_IOERR_SHMMAP   (SQLITE_IOERR | (21<<8))

Definition at line 1543 of file sqlite3.c.

Referenced by unixShmMap().

◆ SQLITE_IOERR_SHMOPEN

#define SQLITE_IOERR_SHMOPEN   (SQLITE_IOERR | (18<<8))

Definition at line 1540 of file sqlite3.c.

Referenced by unixLockSharedMemory().

◆ SQLITE_IOERR_SHMSIZE

#define SQLITE_IOERR_SHMSIZE   (SQLITE_IOERR | (19<<8))

Definition at line 1541 of file sqlite3.c.

Referenced by unixShmMap().

◆ SQLITE_IOERR_SHORT_READ

◆ SQLITE_IOERR_TRUNCATE

#define SQLITE_IOERR_TRUNCATE   (SQLITE_IOERR | (6<<8))

Definition at line 1528 of file sqlite3.c.

Referenced by fcntlSizeHint().

◆ SQLITE_IOERR_UNLOCK

#define SQLITE_IOERR_UNLOCK   (SQLITE_IOERR | (8<<8))

Definition at line 1530 of file sqlite3.c.

Referenced by dotlockUnlock(), posixUnlock(), sqliteErrorFromPosixError(), and unixLock().

◆ SQLITE_IOERR_VNODE

#define SQLITE_IOERR_VNODE   (SQLITE_IOERR | (27<<8))

Definition at line 1549 of file sqlite3.c.

◆ SQLITE_IOERR_WRITE

#define SQLITE_IOERR_WRITE   (SQLITE_IOERR | (3<<8))

Definition at line 1525 of file sqlite3.c.

Referenced by fcntlSizeHint(), and unixWrite().

◆ SQLITE_JUMPIFNULL

◆ SQLITE_KEEPNULL

#define SQLITE_KEEPNULL   0x08 /* Used by vector == or <> */

Definition at line 17418 of file sqlite3.c.

Referenced by codeVectorCompare(), and sqlite3VdbeExec().

◆ SQLITE_LAST_ERRNO

#define SQLITE_LAST_ERRNO   SQLITE_FCNTL_LAST_ERRNO

Definition at line 2221 of file sqlite3.c.

◆ SQLITE_LegacyAlter

#define SQLITE_LegacyAlter   0x04000000 /* Legacy ALTER TABLE behaviour */

Definition at line 17005 of file sqlite3.c.

Referenced by openDatabase(), renameTableFunc(), renameTableTest(), and sqlite3VdbeExec().

◆ SQLITE_LegacyFileFmt

#define SQLITE_LegacyFileFmt   0x00000002 /* Create new databases in format 1 */

Definition at line 16979 of file sqlite3.c.

Referenced by openDatabase(), sqlite3InitOne(), and sqlite3StartTable().

◆ SQLITE_LIMIT_ATTACHED

#define SQLITE_LIMIT_ATTACHED   7

Definition at line 4951 of file sqlite3.c.

Referenced by attachFunc(), and sqlite3_limit().

◆ SQLITE_LIMIT_COLUMN

#define SQLITE_LIMIT_COLUMN   2

◆ SQLITE_LIMIT_COMPOUND_SELECT

#define SQLITE_LIMIT_COMPOUND_SELECT   4

Definition at line 4948 of file sqlite3.c.

Referenced by parserDoubleLinkSelect(), and sqlite3_limit().

◆ SQLITE_LIMIT_EXPR_DEPTH

#define SQLITE_LIMIT_EXPR_DEPTH   3

Definition at line 4947 of file sqlite3.c.

Referenced by sqlite3_limit(), and sqlite3ExprCheckHeight().

◆ SQLITE_LIMIT_FUNCTION_ARG

#define SQLITE_LIMIT_FUNCTION_ARG   6

Definition at line 4950 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_LIMIT_LENGTH

#define SQLITE_LIMIT_LENGTH   0

◆ SQLITE_LIMIT_LIKE_PATTERN_LENGTH

#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH   8

Definition at line 4952 of file sqlite3.c.

Referenced by likeFunc(), and sqlite3_limit().

◆ SQLITE_LIMIT_SQL_LENGTH

#define SQLITE_LIMIT_SQL_LENGTH   1

Definition at line 4945 of file sqlite3.c.

Referenced by sqlite3_limit(), and sqlite3RunParser().

◆ SQLITE_LIMIT_TRIGGER_DEPTH

#define SQLITE_LIMIT_TRIGGER_DEPTH   10

Definition at line 4954 of file sqlite3.c.

Referenced by sqlite3_limit(), and sqlite3VdbeExec().

◆ SQLITE_LIMIT_VARIABLE_NUMBER

#define SQLITE_LIMIT_VARIABLE_NUMBER   9

Definition at line 4953 of file sqlite3.c.

Referenced by sqlite3_limit(), and sqlite3ExprAssignVarNumber().

◆ SQLITE_LIMIT_VDBE_OP

#define SQLITE_LIMIT_VDBE_OP   5

Definition at line 4949 of file sqlite3.c.

Referenced by growOpArray(), and sqlite3_limit().

◆ SQLITE_LIMIT_WORKER_THREADS

#define SQLITE_LIMIT_WORKER_THREADS   11

Definition at line 4955 of file sqlite3.c.

Referenced by openDatabase(), sqlite3_limit(), sqlite3Pragma(), and sqlite3VdbeSorterInit().

◆ SQLITE_LITTLEENDIAN

#define SQLITE_LITTLEENDIAN   (*(char *)(&sqlite3one)==1)

Definition at line 14455 of file sqlite3.c.

◆ SQLITE_LoadExtension

#define SQLITE_LoadExtension   0x00010000 /* Enable load_extension */

Definition at line 16995 of file sqlite3.c.

Referenced by openDatabase(), and sqlite3LoadExtension().

◆ SQLITE_LoadExtFunc

#define SQLITE_LoadExtFunc   0x00020000 /* Enable load_extension() SQL func */

Definition at line 16996 of file sqlite3.c.

Referenced by loadExt().

◆ SQLITE_LOCK_EXCLUSIVE

#define SQLITE_LOCK_EXCLUSIVE   4

Definition at line 1688 of file sqlite3.c.

◆ SQLITE_LOCK_NONE

#define SQLITE_LOCK_NONE   0

Definition at line 1684 of file sqlite3.c.

◆ SQLITE_LOCK_PENDING

#define SQLITE_LOCK_PENDING   3

Definition at line 1687 of file sqlite3.c.

◆ SQLITE_LOCK_RESERVED

#define SQLITE_LOCK_RESERVED   2

Definition at line 1686 of file sqlite3.c.

◆ SQLITE_LOCK_SHARED

#define SQLITE_LOCK_SHARED   1

Definition at line 1685 of file sqlite3.c.

◆ SQLITE_LOCKED

#define SQLITE_LOCKED   6 /* A table in the database is locked */

◆ SQLITE_LOCKED_SHAREDCACHE

#define SQLITE_LOCKED_SHAREDCACHE   (SQLITE_LOCKED | (1<<8))

◆ SQLITE_LOCKED_VTAB

#define SQLITE_LOCKED_VTAB   (SQLITE_LOCKED | (2<<8))

Definition at line 1556 of file sqlite3.c.

◆ SQLITE_MAGIC_BUSY

#define SQLITE_MAGIC_BUSY   0xf03b7906 /* Database currently in use */

Definition at line 17080 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_MAGIC_CLOSED

#define SQLITE_MAGIC_CLOSED   0x9f3c2d33 /* Database is closed */

Definition at line 17078 of file sqlite3.c.

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ SQLITE_MAGIC_ERROR

#define SQLITE_MAGIC_ERROR   0xb5357930 /* An SQLITE_MISUSE error occurred */

Definition at line 17081 of file sqlite3.c.

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ SQLITE_MAGIC_OPEN

#define SQLITE_MAGIC_OPEN   0xa029a697 /* Database is open */

Definition at line 17077 of file sqlite3.c.

Referenced by openDatabase(), and sqlite3SafetyCheckOk().

◆ SQLITE_MAGIC_SICK

#define SQLITE_MAGIC_SICK   0x4b771290 /* Error and awaiting close */

Definition at line 17079 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_MAGIC_ZOMBIE

#define SQLITE_MAGIC_ZOMBIE   0x64cffc7f /* Close with last statement close */

Definition at line 17082 of file sqlite3.c.

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ SQLITE_MALLOC

#define SQLITE_MALLOC ( x)    malloc(x)

Definition at line 23623 of file sqlite3.c.

Referenced by sqlite3MemMalloc().

◆ SQLITE_MALLOC_SOFT_LIMIT

#define SQLITE_MALLOC_SOFT_LIMIT   1024

Definition at line 13630 of file sqlite3.c.

Referenced by rehash().

◆ SQLITE_MATCH

#define SQLITE_MATCH   0

Definition at line 117682 of file sqlite3.c.

Referenced by likeFunc(), and patternCompare().

◆ SQLITE_MAX_ATTACHED

#define SQLITE_MAX_ATTACHED   10

◆ SQLITE_MAX_COLUMN

#define SQLITE_MAX_COLUMN   2000

Definition at line 13282 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_COMPOUND_SELECT

#define SQLITE_MAX_COMPOUND_SELECT   500

Definition at line 13319 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_DEFAULT_PAGE_SIZE

#define SQLITE_MAX_DEFAULT_PAGE_SIZE   8192

Definition at line 13415 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_MAX_EXPR_DEPTH

#define SQLITE_MAX_EXPR_DEPTH   1000

Definition at line 13307 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_FILE_FORMAT

#define SQLITE_MAX_FILE_FORMAT   4

Definition at line 14181 of file sqlite3.c.

Referenced by sqlite3InitOne(), and sqlite3StartTable().

◆ SQLITE_MAX_FUNCTION_ARG

#define SQLITE_MAX_FUNCTION_ARG   127

Definition at line 13334 of file sqlite3.c.

Referenced by sqlite3_limit(), and sqlite3CreateFunc().

◆ SQLITE_MAX_LENGTH

◆ SQLITE_MAX_LIKE_PATTERN_LENGTH

#define SQLITE_MAX_LIKE_PATTERN_LENGTH   50000

Definition at line 13439 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_MEMORY

#define SQLITE_MAX_MEMORY   0

Definition at line 27351 of file sqlite3.c.

◆ SQLITE_MAX_MMAP_SIZE

#define SQLITE_MAX_MMAP_SIZE   0

Definition at line 14517 of file sqlite3.c.

Referenced by sqlite3_config(), and vdbeSorterOpenTempFile().

◆ SQLITE_MAX_PAGE_COUNT

#define SQLITE_MAX_PAGE_COUNT   1073741823

Definition at line 13431 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_MAX_PAGE_SIZE

#define SQLITE_MAX_PAGE_SIZE   65536

◆ SQLITE_MAX_PMASZ

#define SQLITE_MAX_PMASZ   (1<<29)

Definition at line 94033 of file sqlite3.c.

Referenced by sqlite3VdbeSorterInit().

◆ SQLITE_MAX_SCHEMA_RETRY

#define SQLITE_MAX_SCHEMA_RETRY   50

Definition at line 20730 of file sqlite3.c.

Referenced by sqlite3_step().

◆ SQLITE_MAX_SQL_LENGTH

#define SQLITE_MAX_SQL_LENGTH   1000000000

Definition at line 13293 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_SRCLIST

#define SQLITE_MAX_SRCLIST   200

Definition at line 114677 of file sqlite3.c.

Referenced by sqlite3SrcListEnlarge().

◆ SQLITE_MAX_SYMLINKS

#define SQLITE_MAX_SYMLINKS   100

Definition at line 33527 of file sqlite3.c.

Referenced by unixFullPathname().

◆ SQLITE_MAX_TRIGGER_DEPTH

#define SQLITE_MAX_TRIGGER_DEPTH   1000

Definition at line 13450 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_U32

#define SQLITE_MAX_U32   ((((u64)1)<<32)-1)

Definition at line 14343 of file sqlite3.c.

Referenced by sqlite3GetVarint32(), and sqlite3VdbeIdxRowid().

◆ SQLITE_MAX_VARIABLE_NUMBER

#define SQLITE_MAX_VARIABLE_NUMBER   32766

Definition at line 13376 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_VDBE_OP

#define SQLITE_MAX_VDBE_OP   250000000

Definition at line 13327 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_MAX_WORKER_THREADS

#define SQLITE_MAX_WORKER_THREADS   8

◆ SQLITE_MEMDB_DEFAULT_MAXSIZE

#define SQLITE_MEMDB_DEFAULT_MAXSIZE   1073741824

Definition at line 20566 of file sqlite3.c.

◆ SQLITE_MINIMUM_FILE_DESCRIPTOR

#define SQLITE_MINIMUM_FILE_DESCRIPTOR   3

Definition at line 34196 of file sqlite3.c.

Referenced by robust_open().

◆ SQLITE_MISMATCH

#define SQLITE_MISMATCH   20 /* Data type mismatch */

Definition at line 1490 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_MISUSE

#define SQLITE_MISUSE   21 /* Library used incorrectly */

◆ SQLITE_MISUSE_BKPT

◆ SQLITE_MSVC_H

#define SQLITE_MSVC_H

Definition at line 866 of file sqlite3.c.

◆ SQLITE_MUTEX_FAST

#define SQLITE_MUTEX_FAST   0

◆ SQLITE_MUTEX_NREF

#define SQLITE_MUTEX_NREF   0

Definition at line 26258 of file sqlite3.c.

◆ SQLITE_MUTEX_PTHREADS

#define SQLITE_MUTEX_PTHREADS

Definition at line 16536 of file sqlite3.c.

◆ SQLITE_MUTEX_RECURSIVE

#define SQLITE_MUTEX_RECURSIVE   1

◆ SQLITE_MUTEX_STATIC_APP1

#define SQLITE_MUTEX_STATIC_APP1   8 /* For use by application */

Definition at line 8639 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_APP2

#define SQLITE_MUTEX_STATIC_APP2   9 /* For use by application */

Definition at line 8640 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_APP3

#define SQLITE_MUTEX_STATIC_APP3   10 /* For use by application */

Definition at line 8641 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_LRU

#define SQLITE_MUTEX_STATIC_LRU   6 /* lru page list */

Definition at line 8636 of file sqlite3.c.

Referenced by pcache1Init().

◆ SQLITE_MUTEX_STATIC_LRU2

#define SQLITE_MUTEX_STATIC_LRU2   7 /* NOT USED */

Definition at line 8637 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_MAIN

◆ SQLITE_MUTEX_STATIC_MASTER

#define SQLITE_MUTEX_STATIC_MASTER   2

Definition at line 8647 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_MEM

#define SQLITE_MUTEX_STATIC_MEM   3 /* sqlite3_malloc() */

Definition at line 8632 of file sqlite3.c.

Referenced by sqlite3MallocInit().

◆ SQLITE_MUTEX_STATIC_MEM2

#define SQLITE_MUTEX_STATIC_MEM2   4 /* NOT USED */

Definition at line 8633 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_OPEN

#define SQLITE_MUTEX_STATIC_OPEN   4 /* sqlite3BtreeOpen() */

Definition at line 8634 of file sqlite3.c.

Referenced by sqlite3BtreeOpen().

◆ SQLITE_MUTEX_STATIC_PMEM

#define SQLITE_MUTEX_STATIC_PMEM   7 /* sqlite3PageMalloc() */

Definition at line 8638 of file sqlite3.c.

Referenced by pcache1Init().

◆ SQLITE_MUTEX_STATIC_PRNG

#define SQLITE_MUTEX_STATIC_PRNG   5 /* sqlite3_randomness() */

Definition at line 8635 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_VFS1

#define SQLITE_MUTEX_STATIC_VFS1   11 /* For use by built-in VFS */

Definition at line 8642 of file sqlite3.c.

Referenced by sqlite3_os_init().

◆ SQLITE_MUTEX_STATIC_VFS2

#define SQLITE_MUTEX_STATIC_VFS2   12 /* For use by extension VFS */

Definition at line 8643 of file sqlite3.c.

◆ SQLITE_MUTEX_STATIC_VFS3

#define SQLITE_MUTEX_STATIC_VFS3   13 /* For use by application VFS */

Definition at line 8644 of file sqlite3.c.

◆ SQLITE_MX_JUMP_OPCODE

#define SQLITE_MX_JUMP_OPCODE   62 /* Maximum JUMP opcode */

Definition at line 15784 of file sqlite3.c.

Referenced by resolveP2Values().

◆ SQLITE_N_BTREE_META

#define SQLITE_N_BTREE_META   16

Definition at line 15019 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_N_KEYWORD

#define SQLITE_N_KEYWORD   145

Definition at line 159870 of file sqlite3.c.

◆ SQLITE_N_LIMIT

#define SQLITE_N_LIMIT   (SQLITE_LIMIT_WORKER_THREADS+1)

Definition at line 16671 of file sqlite3.c.

Referenced by sqlite3_limit().

◆ SQLITE_NO_TSAN

#define SQLITE_NO_TSAN

Definition at line 60111 of file sqlite3.c.

◆ SQLITE_NoCkptOnClose

#define SQLITE_NoCkptOnClose   0x00000800 /* No checkpoint on close()/DETACH */

Definition at line 16990 of file sqlite3.c.

Referenced by sqlite3PagerClose().

◆ SQLITE_NOINLINE

#define SQLITE_NOINLINE

Definition at line 13529 of file sqlite3.c.

◆ SQLITE_NOLFS

#define SQLITE_NOLFS   22 /* Uses OS features not supported on host */

Definition at line 1492 of file sqlite3.c.

Referenced by findInodeInfo().

◆ SQLITE_NOMATCH

#define SQLITE_NOMATCH   1

Definition at line 117683 of file sqlite3.c.

Referenced by patternCompare().

◆ SQLITE_NOMEM

◆ SQLITE_NOMEM_BKPT

#define SQLITE_NOMEM_BKPT   SQLITE_NOMEM

Definition at line 19276 of file sqlite3.c.

Referenced by accessPayload(), attachFunc(), balance_nonroot(), btreeCursor(), btreeMoveto(), btreeSetHasContent(), corruptSchema(), findInodeInfo(), getPageNormal(), growOpArray(), multiSelect(), multiSelectOrderBy(), openDatabase(), pager_delsuper(), pager_open_journal(), pagerOpenSavepoint(), pagerPlaybackSavepoint(), saveCursorKey(), setSharedCacheTableLock(), sqlite3_auto_extension(), sqlite3_backup_init(), sqlite3_complete16(), sqlite3_exec(), sqlite3_get_table(), sqlite3_get_table_cb(), sqlite3_initialize(), sqlite3_step(), sqlite3AnalysisLoad(), sqlite3BitvecSet(), sqlite3BtreeMovetoUnpacked(), sqlite3BtreeOpen(), sqlite3ColumnsFromExprList(), sqlite3CreateFunc(), sqlite3InitOne(), sqlite3LoadExtension(), sqlite3OomFault(), sqlite3OsInit(), sqlite3PagerOpen(), sqlite3PagerSetPagesize(), sqlite3ParseUri(), sqlite3PcacheFetchStress(), sqlite3RunParser(), sqlite3StartTable(), sqlite3Step(), sqlite3VdbeExec(), sqlite3VdbeHalt(), sqlite3VdbeMemExpandBlob(), sqlite3VdbeMemGrow(), sqlite3VdbeMemSetStr(), sqlite3VdbeMemStringify(), sqlite3VdbeMemTranslate(), sqlite3VdbeSetColName(), sqlite3VdbeSorterCompare(), sqlite3VdbeSorterInit(), sqlite3WalOpen(), unixFullPathname(), unixOpen(), unixOpenSharedMemory(), unixShmMap(), valueFromExpr(), vdbeCommit(), vdbeCompareMemString(), vdbeIncrMergerNew(), vdbeMemAddTerminator(), vdbeMergeEngineLevel0(), vdbePmaReadBlob(), vdbePmaReaderSeek(), vdbeSortAllocUnpacked(), vdbeSorterAddToTree(), vdbeSorterFlushPMA(), vdbeSorterMergeTreeBuild(), vdbeSorterSetupMerge(), vtabCallConstructor(), walBeginShmUnreliable(), walCheckpoint(), walIndexPageRealloc(), walIndexRecover(), walIteratorInit(), walRewriteChecksums(), whereLoopAddBtreeIndex(), whereLoopAddVirtual(), whereLoopInsert(), wherePathSolver(), and withExpand().

◆ SQLITE_NoSchemaError

#define SQLITE_NoSchemaError   0x08000000 /* Do not report schema parse errors*/

Definition at line 17006 of file sqlite3.c.

Referenced by sqlite3InitOne().

◆ SQLITE_NOTADB

#define SQLITE_NOTADB   26 /* File opened that is not a database file */

Definition at line 1496 of file sqlite3.c.

Referenced by lockBtree().

◆ SQLITE_NOTFOUND

◆ SQLITE_NOTICE

#define SQLITE_NOTICE   27 /* Notifications from sqlite3_log() */

Definition at line 1497 of file sqlite3.c.

◆ SQLITE_NOTICE_RECOVER_ROLLBACK

#define SQLITE_NOTICE_RECOVER_ROLLBACK   (SQLITE_NOTICE | (2<<8))

Definition at line 1588 of file sqlite3.c.

Referenced by pager_playback().

◆ SQLITE_NOTICE_RECOVER_WAL

#define SQLITE_NOTICE_RECOVER_WAL   (SQLITE_NOTICE | (1<<8))

Definition at line 1587 of file sqlite3.c.

Referenced by walIndexRecover().

◆ SQLITE_NOTNULL

#define SQLITE_NOTNULL   0x90 /* Assert that operands are never NULL */

Definition at line 17422 of file sqlite3.c.

Referenced by fkLookupParent(), sqlite3GenerateConstraintChecks(), and sqlite3Pragma().

◆ SQLITE_NOWILDCARDMATCH

#define SQLITE_NOWILDCARDMATCH   2

Definition at line 117684 of file sqlite3.c.

Referenced by patternCompare().

◆ SQLITE_NULL

#define SQLITE_NULL   5

◆ SQLITE_NullCallback

#define SQLITE_NullCallback   0x00000100 /* Invoke the callback once if the */

Definition at line 16986 of file sqlite3.c.

Referenced by sqlite3_exec().

◆ SQLITE_NULLEQ

◆ SQLITE_OK

#define SQLITE_OK   0 /* Successful result */

Definition at line 1469 of file sqlite3.c.

Referenced by accessPayload(), addToSavepointBitvecs(), allocateBtreePage(), allocateCursor(), allocateSpace(), anotherValidCursor(), attachFunc(), autoVacuumCommit(), backupOnePage(), backupTruncateFile(), balance(), balance_deeper(), balance_nonroot(), balance_quick(), blobSeekToRow(), btreeCreateTable(), btreeDropTable(), btreeGetPage(), btreeGetUnusedPage(), btreeInitPage(), btreeLockCarefully(), btreeNext(), btreePrevious(), btreeRestoreCursorPosition(), btreeSetHasContent(), changeTempStorage(), checkPtrmap(), checkReadTransaction(), copyNodeContent(), copyPayload(), createFunctionApi(), createModule(), databaseIsUnmoved(), db_do_next_row(), db_do_rows(), db_load_extension(), db_prepare(), db_register_function(), dbvm_bind_names(), dbvm_bind_values(), decodeFlags(), defragmentPage(), dotlockCheckReservedLock(), dotlockLock(), dotlockUnlock(), doWalCallbacks(), editPage(), execSql(), fcntlSizeHint(), fillInCell(), findCreateFileMode(), freePage2(), freeSpace(), getAndInitPage(), getOverflowPage(), getPageNormal(), growOpArray(), hasHotJournal(), incrVacuumStep(), insertCell(), invalidateTempStorage(), isFatalError(), localtimeOffset(), lockBtree(), lsqlite_do_open(), lsqlite_open_ptr(), modifyPagePointer(), moveToLeftmost(), moveToRightmost(), moveToRoot(), multiSelect(), newDatabase(), noopMutexAlloc(), noopMutexFree(), openDatabase(), openDirectory(), openSubJournal(), pager_delsuper(), pager_end_transaction(), pager_error(), pager_incr_changecounter(), pager_open_journal(), pager_playback(), pager_playback_one_page(), pager_truncate(), pager_unlock(), pager_write(), pager_write_pagelist(), pagerBeginReadTransaction(), pagerLockDb(), pagerOpenSavepoint(), pagerOpentemp(), pagerOpenWal(), pagerOpenWalIfPresent(), pagerPagecount(), pagerPlaybackSavepoint(), pagerStress(), pagerSyncHotJournal(), pagerUndoCallback(), pagerUnlockDb(), pagerWalFrames(), pagerWriteLargeSector(), parseModifier(), pcache1Init(), posixUnlock(), pragmaVtabBestIndex(), pthreadMutexEnd(), ptrmapGet(), ptrmapPut(), querySharedCacheTableLock(), read32bits(), readDbPage(), readJournalHdr(), readSuperJournal(), rebuildPage(), relocatePage(), renameColumnFunc(), renameEditSql(), renameParseSql(), renameResolveTrigger(), renameTableFunc(), renameTableTest(), resolveAttachExpr(), resolveExprStep(), robust_ftruncate(), saveAllCursors(), saveCursorKey(), saveCursorPosition(), saveCursorsOnList(), schemaIsValid(), setChildPtrmaps(), setSharedCacheTableLock(), sqlite3_auto_extension(), sqlite3_backup_init(), sqlite3_blob_reopen(), sqlite3_collation_needed(), sqlite3_collation_needed16(), sqlite3_config(), sqlite3_declare_vtab(), sqlite3_enable_shared_cache(), sqlite3_exec(), sqlite3_finalize(), sqlite3_get_table(), sqlite3_global_recover(), sqlite3_initialize(), sqlite3_memory_alarm(), sqlite3_mutex_try(), sqlite3_os_end(), sqlite3_os_init(), sqlite3_overload_function(), sqlite3_prepare16_v2(), sqlite3_prepare16_v3(), sqlite3_prepare_v2(), sqlite3_reset(), sqlite3_set_authorizer(), sqlite3_shutdown(), sqlite3_step(), sqlite3_table_column_metadata(), sqlite3_value_blob(), sqlite3_vfs_register(), sqlite3_vtab_config(), sqlite3_wal_autocheckpoint(), sqlite3AlterBeginAddColumn(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3AnalysisLoad(), sqlite3Analyze(), sqlite3AuthCheck(), sqlite3AuthReadCol(), sqlite3BitvecSet(), sqlite3BtreeBeginTrans(), sqlite3BtreeCheckpoint(), sqlite3BtreeClearTable(), sqlite3BtreeCommitPhaseOne(), sqlite3BtreeCommitPhaseTwo(), sqlite3BtreeCopyFile(), sqlite3BtreeCount(), sqlite3BtreeCursorRestore(), sqlite3BtreeDelete(), sqlite3BtreeGetMeta(), sqlite3BtreeIncrVacuum(), sqlite3BtreeInsert(), sqlite3BtreeLockTable(), sqlite3BtreeMovetoUnpacked(), sqlite3BtreeNext(), sqlite3BtreeOpen(), sqlite3BtreePutData(), sqlite3BtreeRollback(), sqlite3BtreeSavepoint(), sqlite3BtreeSchemaLocked(), sqlite3BtreeSetAutoVacuum(), sqlite3BtreeSetCacheSize(), sqlite3BtreeSetPagerFlags(), sqlite3BtreeSetPageSize(), sqlite3BtreeSetVersion(), sqlite3BtreeTripAllCursors(), sqlite3CheckCollSeq(), sqlite3CheckObjectName(), sqlite3Checkpoint(), sqlite3ColumnsFromExprList(), sqlite3CreateFunc(), sqlite3CreateIndex(), sqlite3DeleteFrom(), sqlite3DropTrigger(), sqlite3ExpandSubquery(), sqlite3ExprCheckHeight(), sqlite3ExprCodeTarget(), sqlite3FaultSim(), sqlite3FinishCoding(), sqlite3IndexedByLookup(), sqlite3Init(), sqlite3InitCallback(), sqlite3InitOne(), sqlite3LeaveMutexAndCloseZombie(), sqlite3LoadExtension(), sqlite3LocateTable(), sqlite3MallocInit(), sqlite3MutexEnd(), sqlite3MutexInit(), sqlite3OsUnfetch(), sqlite3PagerBegin(), sqlite3PagerCheckpoint(), sqlite3PagerClose(), sqlite3PagerCloseWal(), sqlite3PagerCommitPhaseOne(), sqlite3PagerCommitPhaseTwo(), sqlite3PagerExclusiveLock(), sqlite3PagerMovepage(), sqlite3PagerOpen(), sqlite3PagerOpenWal(), sqlite3PagerReadFileheader(), sqlite3PagerRollback(), sqlite3PagerSavepoint(), sqlite3PagerSetJournalMode(), sqlite3PagerSetPagesize(), sqlite3PagerSharedLock(), sqlite3PagerSync(), sqlite3PagerWrite(), sqlite3ParseUri(), sqlite3PcacheFetchStress(), sqlite3Pragma(), sqlite3Prepare16(), sqlite3RegisterPerConnectionBuiltinFunctions(), sqlite3Reindex(), sqlite3Reprepare(), sqlite3ResolveExprNames(), sqlite3ResolveSelfReference(), sqlite3RunParser(), sqlite3StartTable(), sqlite3Step(), sqlite3UpsertAnalyzeTarget(), sqlite3VdbeChangeEncoding(), sqlite3VdbeCheckFk(), sqlite3VdbeCursorMoveto(), sqlite3VdbeExec(), sqlite3VdbeFinishMoveto(), sqlite3VdbeHalt(), sqlite3VdbeIdxKeyCompare(), sqlite3VdbeIdxRowid(), sqlite3VdbeList(), sqlite3VdbeMemCast(), sqlite3VdbeMemClearAndResize(), sqlite3VdbeMemExpandBlob(), sqlite3VdbeMemFromBtree(), sqlite3VdbeMemGrow(), sqlite3VdbeMemHandleBom(), sqlite3VdbeMemMakeWriteable(), sqlite3VdbeMemNumerify(), sqlite3VdbeMemSetRowSet(), sqlite3VdbeMemSetStr(), sqlite3VdbeMemStringify(), sqlite3VdbeMemTranslate(), sqlite3VdbeNextOpcode(), sqlite3VdbeResetStepResult(), sqlite3VdbeSorterCompare(), sqlite3VdbeSorterInit(), sqlite3VdbeSorterNext(), sqlite3VdbeSorterRewind(), sqlite3VtabBegin(), sqlite3VtabCallConnect(), sqlite3VtabCallCreate(), sqlite3VtabCallDestroy(), sqlite3VtabSavepoint(), sqlite3VtabSync(), sqlite3WalBeginReadTransaction(), sqlite3WalBeginWriteTransaction(), sqlite3WalCheckpoint(), sqlite3WalDefaultHook(), sqlite3WalExclusiveMode(), sqlite3WalFindFrame(), sqlite3WalOpen(), sqlite3WalSavepointUndo(), sqlite3WalUndo(), sqlite3WindowRewrite(), subjournalPage(), syncJournal(), synthCollSeq(), unixCheckReservedLock(), unixCurrentTimeInt64(), unixDelete(), unixFetch(), unixFullPathname(), unixGetTempname(), unixLock(), unixLockSharedMemory(), unixOpen(), unixOpenSharedMemory(), unixRead(), unixSetSystemCall(), unixShmLock(), unixShmMap(), unixShmSystemLock(), unixShmUnmap(), unixSync(), unixUnfetch(), unixWrite(), valueFromExpr(), valueToText(), vdbeCloseStatement(), vdbeCommit(), vdbeIncrMergerNew(), vdbeIncrPopulate(), vdbeIncrSwap(), vdbeMemAddTerminator(), vdbeMergeEngineInit(), vdbeMergeEngineLevel0(), vdbeMergeEngineStep(), vdbePmaReadBlob(), vdbePmaReaderIncrInit(), vdbePmaReaderIncrMergeInit(), vdbePmaReaderInit(), vdbePmaReaderSeek(), vdbeSortAllocUnpacked(), vdbeSorterAddToTree(), vdbeSorterFlushPMA(), vdbeSorterJoinThread(), vdbeSorterListToPMA(), vdbeSorterMapFile(), vdbeSorterMergeTreeBuild(), vdbeSorterOpenTempFile(), vdbeSorterSetupMerge(), vdbeSorterSort(), vdbeUnbind(), vtabBestIndex(), vtabCallConstructor(), walBeginShmUnreliable(), walCheckpoint(), walHashGet(), walIndexAppend(), walIndexPageRealloc(), walIndexReadHdr(), walIndexRecover(), walIteratorInit(), walLockShared(), walRestartLog(), walRewriteChecksums(), walTryBeginRead(), whereLoopAddBtree(), whereLoopAddBtreeIndex(), whereLoopAddOr(), whereLoopAddVirtual(), whereLoopAddVirtualOne(), whereLoopInsert(), wherePathSolver(), whereRangeScanEst(), withExpand(), writeJournalHdr(), writeSuperJournal(), xferOptimization(), and zeroJournalHdr().

◆ SQLITE_OK_LOAD_PERMANENTLY

#define SQLITE_OK_LOAD_PERMANENTLY   (SQLITE_OK | (1<<8))

Definition at line 1591 of file sqlite3.c.

Referenced by sqlite3LoadExtension().

◆ SQLITE_OK_SYMLINK

#define SQLITE_OK_SYMLINK   (SQLITE_OK | (2<<8))

Definition at line 1592 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), sqlite3PagerOpen(), and unixFullPathname().

◆ SQLITE_OmitNoopJoin

#define SQLITE_OmitNoopJoin   0x0100 /* Omit unused tables in joins */

Definition at line 17049 of file sqlite3.c.

Referenced by sqlite3WhereBegin().

◆ SQLITE_OPEN_AUTOPROXY

#define SQLITE_OPEN_AUTOPROXY   0x00000020 /* VFS only */

Definition at line 1606 of file sqlite3.c.

Referenced by unixOpen().

◆ SQLITE_OPEN_CREATE

◆ SQLITE_OPEN_DELETEONCLOSE

#define SQLITE_OPEN_DELETEONCLOSE   0x00000008 /* VFS only */

◆ SQLITE_OPEN_EXCLUSIVE

#define SQLITE_OPEN_EXCLUSIVE   0x00000010 /* VFS only */

◆ SQLITE_OPEN_FULLMUTEX

#define SQLITE_OPEN_FULLMUTEX   0x00010000 /* Ok for sqlite3_open_v2() */

Definition at line 1617 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_OPEN_MAIN_DB

#define SQLITE_OPEN_MAIN_DB   0x00000100 /* VFS only */

Definition at line 1609 of file sqlite3.c.

Referenced by attachFunc(), openDatabase(), sqlite3BtreeOpen(), and unixOpen().

◆ SQLITE_OPEN_MAIN_JOURNAL

#define SQLITE_OPEN_MAIN_JOURNAL   0x00000800 /* VFS only */

◆ SQLITE_OPEN_MASTER_JOURNAL

#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000 /* VFS only */

Definition at line 1625 of file sqlite3.c.

◆ SQLITE_OPEN_MEMORY

#define SQLITE_OPEN_MEMORY   0x00000080 /* Ok for sqlite3_open_v2() */

Definition at line 1608 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), sqlite3PagerOpen(), and sqlite3ParseUri().

◆ SQLITE_OPEN_NOFOLLOW

#define SQLITE_OPEN_NOFOLLOW   0x01000000 /* Ok for sqlite3_open_v2() */

Definition at line 1621 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ SQLITE_OPEN_NOMUTEX

#define SQLITE_OPEN_NOMUTEX   0x00008000 /* Ok for sqlite3_open_v2() */

Definition at line 1616 of file sqlite3.c.

Referenced by openDatabase().

◆ SQLITE_OPEN_PRIVATECACHE

#define SQLITE_OPEN_PRIVATECACHE   0x00040000 /* Ok for sqlite3_open_v2() */

Definition at line 1619 of file sqlite3.c.

Referenced by openDatabase(), and sqlite3ParseUri().

◆ SQLITE_OPEN_READONLY

#define SQLITE_OPEN_READONLY   0x00000001 /* Ok for sqlite3_open_v2() */

◆ SQLITE_OPEN_READWRITE

◆ SQLITE_OPEN_SHAREDCACHE

#define SQLITE_OPEN_SHAREDCACHE   0x00020000 /* Ok for sqlite3_open_v2() */

Definition at line 1618 of file sqlite3.c.

Referenced by openDatabase(), sqlite3BtreeOpen(), and sqlite3ParseUri().

◆ SQLITE_OPEN_SUBJOURNAL

#define SQLITE_OPEN_SUBJOURNAL   0x00002000 /* VFS only */

Definition at line 1614 of file sqlite3.c.

Referenced by openDatabase(), openSubJournal(), and unixOpen().

◆ SQLITE_OPEN_SUPER_JOURNAL

#define SQLITE_OPEN_SUPER_JOURNAL   0x00004000 /* VFS only */

Definition at line 1615 of file sqlite3.c.

Referenced by openDatabase(), pager_delsuper(), unixOpen(), and vdbeCommit().

◆ SQLITE_OPEN_TEMP_DB

#define SQLITE_OPEN_TEMP_DB   0x00000200 /* VFS only */

Definition at line 1610 of file sqlite3.c.

Referenced by openDatabase(), sqlite3BtreeOpen(), and unixOpen().

◆ SQLITE_OPEN_TEMP_JOURNAL

#define SQLITE_OPEN_TEMP_JOURNAL   0x00001000 /* VFS only */

Definition at line 1613 of file sqlite3.c.

Referenced by openDatabase(), pager_open_journal(), unixOpen(), and vdbeSorterOpenTempFile().

◆ SQLITE_OPEN_TRANSIENT_DB

#define SQLITE_OPEN_TRANSIENT_DB   0x00000400 /* VFS only */

Definition at line 1611 of file sqlite3.c.

Referenced by openDatabase(), sqlite3VdbeExec(), and unixOpen().

◆ SQLITE_OPEN_URI

#define SQLITE_OPEN_URI   0x00000040 /* Ok for sqlite3_open_v2() */

Definition at line 1607 of file sqlite3.c.

Referenced by findCreateFileMode(), sqlite3BtreeOpen(), sqlite3ParseUri(), and unixOpen().

◆ SQLITE_OPEN_WAL

#define SQLITE_OPEN_WAL   0x00080000 /* VFS only */

Definition at line 1620 of file sqlite3.c.

Referenced by findCreateFileMode(), openDatabase(), sqlite3WalOpen(), and unixOpen().

◆ SQLITE_OrderByIdxJoin

#define SQLITE_OrderByIdxJoin   0x0040 /* ORDER BY of joins via index */

Definition at line 17047 of file sqlite3.c.

Referenced by wherePathSatisfiesOrderBy().

◆ SQLITE_OS_OTHER

#define SQLITE_OS_OTHER   0

Definition at line 16279 of file sqlite3.c.

◆ SQLITE_OS_SETUP_H

#define SQLITE_OS_SETUP_H

Definition at line 16258 of file sqlite3.c.

◆ SQLITE_OS_UNIX

#define SQLITE_OS_UNIX   1

Definition at line 16287 of file sqlite3.c.

◆ SQLITE_OS_WIN

#define SQLITE_OS_WIN   0

Definition at line 16286 of file sqlite3.c.

◆ SQLITE_PAGER_H

#define SQLITE_PAGER_H

Definition at line 14768 of file sqlite3.c.

◆ SQLITE_PERM

#define SQLITE_PERM   3 /* Access permission denied */

Definition at line 1473 of file sqlite3.c.

Referenced by sqlite3ParseUri(), and sqliteErrorFromPosixError().

◆ SQLITE_POWERSAFE_OVERWRITE

#define SQLITE_POWERSAFE_OVERWRITE   1

Definition at line 13580 of file sqlite3.c.

◆ SQLITE_PRAGMA

#define SQLITE_PRAGMA   19 /* Pragma Name 1st arg or NULL */

Definition at line 4138 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ SQLITE_PREPARE_MASK

#define SQLITE_PREPARE_MASK   0x0f /* Mask of public flags */

Definition at line 15793 of file sqlite3.c.

◆ SQLITE_PREPARE_NO_VTAB

#define SQLITE_PREPARE_NO_VTAB   0x04

Definition at line 4994 of file sqlite3.c.

◆ SQLITE_PREPARE_NORMALIZE

#define SQLITE_PREPARE_NORMALIZE   0x02

Definition at line 4993 of file sqlite3.c.

◆ SQLITE_PREPARE_PERSISTENT

#define SQLITE_PREPARE_PERSISTENT   0x01

Definition at line 4992 of file sqlite3.c.

◆ SQLITE_PREPARE_SAVESQL

#define SQLITE_PREPARE_SAVESQL   0x80 /* Preserve SQL text */

◆ SQLITE_PRINT_BUF_SIZE

#define SQLITE_PRINT_BUF_SIZE   70

Definition at line 28327 of file sqlite3.c.

Referenced by renderLogMsg().

◆ SQLITE_PRINTF_INTERNAL

#define SQLITE_PRINTF_INTERNAL   0x01 /* Internal-use-only converters allowed */

Definition at line 18977 of file sqlite3.c.

Referenced by sqlite3_str_vappendf(), and sqlite3BtreeIntegrityCheck().

◆ SQLITE_PRINTF_MALLOCED

#define SQLITE_PRINTF_MALLOCED   0x04 /* True if xText is allocated space */

◆ SQLITE_PRINTF_SQLFUNC

#define SQLITE_PRINTF_SQLFUNC   0x02 /* SQL function arguments to VXPrintf */

Definition at line 18978 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ SQLITE_PRIVATE

#define SQLITE_PRIVATE   static

Definition at line 23 of file sqlite3.c.

Referenced by sqlite3RunParser().

◆ SQLITE_PropagateConst

#define SQLITE_PropagateConst   0x8000 /* The constant propagation opt */

Definition at line 17057 of file sqlite3.c.

Referenced by sqlite3Select().

◆ SQLITE_PROTOCOL

#define SQLITE_PROTOCOL   15 /* Database lock protocol error */

Definition at line 1485 of file sqlite3.c.

Referenced by sqlite3WalBeginReadTransaction(), walRestartLog(), and walTryBeginRead().

◆ SQLITE_PTR_TO_INT

#define SQLITE_PTR_TO_INT ( X)    ((int)(((char*)X)-(char*)0))

◆ SQLITE_PTRSIZE

#define SQLITE_PTRSIZE   8

Definition at line 14393 of file sqlite3.c.

Referenced by sqlite3_initialize().

◆ SQLITE_PushDown

#define SQLITE_PushDown   0x1000 /* The push-down optimization */

Definition at line 17054 of file sqlite3.c.

Referenced by sqlite3Select().

◆ SQLITE_QUERY_PLANNER_LIMIT

#define SQLITE_QUERY_PLANNER_LIMIT   20000

Definition at line 141353 of file sqlite3.c.

◆ SQLITE_QUERY_PLANNER_LIMIT_INCR

#define SQLITE_QUERY_PLANNER_LIMIT_INCR   1000

Definition at line 141356 of file sqlite3.c.

◆ SQLITE_QueryFlattener

#define SQLITE_QueryFlattener   0x0001 /* Query flattening */

Definition at line 17041 of file sqlite3.c.

Referenced by flattenSubquery(), and sqlite3Select().

◆ SQLITE_QueryOnly

#define SQLITE_QueryOnly   0x00100000 /* Disable database changes */

Definition at line 16999 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_RANGE

#define SQLITE_RANGE   25 /* 2nd parameter to sqlite3_bind out of range */

Definition at line 1495 of file sqlite3.c.

Referenced by columnMem(), and vdbeUnbind().

◆ SQLITE_READ

#define SQLITE_READ   20 /* Table Name Column Name */

Definition at line 4139 of file sqlite3.c.

Referenced by sqlite3AuthReadCol(), and sqlite3Select().

◆ SQLITE_READONLY

◆ SQLITE_READONLY_CANTINIT

#define SQLITE_READONLY_CANTINIT   (SQLITE_READONLY | (5<<8))

◆ SQLITE_READONLY_CANTLOCK

#define SQLITE_READONLY_CANTLOCK   (SQLITE_READONLY | (2<<8))

Definition at line 1570 of file sqlite3.c.

◆ SQLITE_READONLY_DBMOVED

#define SQLITE_READONLY_DBMOVED   (SQLITE_READONLY | (4<<8))

Definition at line 1572 of file sqlite3.c.

Referenced by databaseIsUnmoved().

◆ SQLITE_READONLY_DIRECTORY

#define SQLITE_READONLY_DIRECTORY   (SQLITE_READONLY | (6<<8))

Definition at line 1574 of file sqlite3.c.

Referenced by unixOpen().

◆ SQLITE_READONLY_RECOVERY

#define SQLITE_READONLY_RECOVERY   (SQLITE_READONLY | (1<<8))

Definition at line 1569 of file sqlite3.c.

Referenced by walIndexReadHdr().

◆ SQLITE_READONLY_ROLLBACK

#define SQLITE_READONLY_ROLLBACK   (SQLITE_READONLY | (3<<8))

Definition at line 1571 of file sqlite3.c.

Referenced by sqlite3PagerSharedLock().

◆ SQLITE_ReadUncommit

#define SQLITE_ReadUncommit   0x00000400 /* READ UNCOMMITTED in shared-cache */

◆ SQLITE_REALLOC

#define SQLITE_REALLOC ( x,
y )   realloc((x),(y))

Definition at line 23625 of file sqlite3.c.

Referenced by sqlite3MemRealloc().

◆ SQLITE_RecTriggers

#define SQLITE_RecTriggers   0x00002000 /* Enable recursive triggers */

◆ SQLITE_RECURSIVE

#define SQLITE_RECURSIVE   33 /* NULL NULL */

Definition at line 4153 of file sqlite3.c.

Referenced by generateWithRecursiveQuery().

◆ SQLITE_REINDEX

#define SQLITE_REINDEX   27 /* Index Name NULL */

Definition at line 4146 of file sqlite3.c.

Referenced by sqlite3RefillIndex().

◆ SQLITE_REPLACE

#define SQLITE_REPLACE   5

Definition at line 10289 of file sqlite3.c.

Referenced by sqlite3_vtab_on_conflict().

◆ SQLITE_ResetDatabase

#define SQLITE_ResetDatabase   0x02000000 /* Reset the database */

Definition at line 17004 of file sqlite3.c.

Referenced by lockBtree(), sqlite3BtreeBeginTrans(), and sqlite3InitOne().

◆ SQLITE_ReverseOrder

#define SQLITE_ReverseOrder   0x00001000 /* Reverse unordered SELECTs */

Definition at line 16991 of file sqlite3.c.

Referenced by openDatabase(), and sqlite3WhereBegin().

◆ SQLITE_ROLLBACK

#define SQLITE_ROLLBACK   1

Definition at line 10285 of file sqlite3.c.

Referenced by sqlite3_vtab_on_conflict().

◆ SQLITE_ROW

#define SQLITE_ROW   100 /* sqlite3_step() has another row ready */

◆ SQLITE_SAVEPOINT

#define SQLITE_SAVEPOINT   32 /* Operation Savepoint Name */

Definition at line 4151 of file sqlite3.c.

◆ SQLITE_SCANSTAT_EST

#define SQLITE_SCANSTAT_EST   2

Definition at line 10340 of file sqlite3.c.

◆ SQLITE_SCANSTAT_EXPLAIN

#define SQLITE_SCANSTAT_EXPLAIN   4

Definition at line 10342 of file sqlite3.c.

◆ SQLITE_SCANSTAT_NAME

#define SQLITE_SCANSTAT_NAME   3

Definition at line 10341 of file sqlite3.c.

◆ SQLITE_SCANSTAT_NLOOP

#define SQLITE_SCANSTAT_NLOOP   0

Definition at line 10338 of file sqlite3.c.

◆ SQLITE_SCANSTAT_NVISIT

#define SQLITE_SCANSTAT_NVISIT   1

Definition at line 10339 of file sqlite3.c.

◆ SQLITE_SCANSTAT_SELECTID

#define SQLITE_SCANSTAT_SELECTID   5

Definition at line 10343 of file sqlite3.c.

◆ SQLITE_SCHEMA

#define SQLITE_SCHEMA   17 /* The database schema changed */

◆ SQLITE_SELECT

#define SQLITE_SELECT   21 /* NULL NULL */

Definition at line 4140 of file sqlite3.c.

Referenced by flattenSubquery(), and sqlite3Select().

◆ SQLITE_SERIALIZE_NOCOPY

#define SQLITE_SERIALIZE_NOCOPY   0x001 /* Do no memory allocations */

Definition at line 10787 of file sqlite3.c.

◆ SQLITE_SET_LOCKPROXYFILE

#define SQLITE_SET_LOCKPROXYFILE   SQLITE_FCNTL_SET_LOCKPROXYFILE

Definition at line 2220 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ SQLITE_SHM_EXCLUSIVE

#define SQLITE_SHM_EXCLUSIVE   8

Definition at line 2505 of file sqlite3.c.

Referenced by unixShmLock().

◆ SQLITE_SHM_LOCK

#define SQLITE_SHM_LOCK   2

Definition at line 2503 of file sqlite3.c.

Referenced by unixShmLock().

◆ SQLITE_SHM_NLOCK

#define SQLITE_SHM_NLOCK   8

Definition at line 2515 of file sqlite3.c.

Referenced by unixShmLock(), and unixShmSystemLock().

◆ SQLITE_SHM_SHARED

#define SQLITE_SHM_SHARED   4

Definition at line 2504 of file sqlite3.c.

Referenced by unixShmLock(), and walLockExclusive().

◆ SQLITE_SHM_UNLOCK

#define SQLITE_SHM_UNLOCK   1

Definition at line 2502 of file sqlite3.c.

Referenced by unixShmLock(), and walLockExclusive().

◆ SQLITE_ShortColNames

#define SQLITE_ShortColNames   0x00000040 /* Show short columns names */

Definition at line 16984 of file sqlite3.c.

Referenced by generateColumnNames(), openDatabase(), and selectExpander().

◆ SQLITE_SimplifyJoin

#define SQLITE_SimplifyJoin   0x2000 /* Convert LEFT JOIN to JOIN */

Definition at line 17055 of file sqlite3.c.

Referenced by sqlite3Select().

◆ SQLITE_SKIP_UTF8

#define SQLITE_SKIP_UTF8 ( zIn)
Value:
{ \
if( (*(zIn++))>=0xc0 ){ \
while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
} \
}

Definition at line 19250 of file sqlite3.c.

19250
19251/*
19252** Assuming zIn points to the first byte of a UTF-8 character,
19253** advance zIn to point to the first byte of the next UTF-8 character.
19254*/

Referenced by patternCompare(), sqlite3_str_vappendf(), sqlite3Utf8CharLen(), and substrFunc().

◆ SQLITE_SkipScan

#define SQLITE_SkipScan   0x4000 /* Skip-scans */

Definition at line 17056 of file sqlite3.c.

Referenced by whereLoopAddBtreeIndex().

◆ SQLITE_SO_ASC

#define SQLITE_SO_ASC   0 /* Sort in ascending order */

Definition at line 17376 of file sqlite3.c.

Referenced by yy_reduce().

◆ SQLITE_SO_DESC

#define SQLITE_SO_DESC   1 /* Sort in ascending order */

Definition at line 17377 of file sqlite3.c.

Referenced by sqlite3AddPrimaryKey(), and yy_reduce().

◆ SQLITE_SO_UNDEFINED

#define SQLITE_SO_UNDEFINED   -1 /* No sort order specified */

Definition at line 17378 of file sqlite3.c.

Referenced by parserAddExprIdListTerm(), sqlite3CreateIndex(), and yy_reduce().

◆ SQLITE_SORTER_PMASZ

#define SQLITE_SORTER_PMASZ   250

Definition at line 20525 of file sqlite3.c.

◆ SQLITE_SOURCE_ID [1/2]

#define SQLITE_SOURCE_ID   "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f"

Definition at line 1176 of file sqlite3.c.

Referenced by sqlite3_sourceid().

◆ SQLITE_SOURCE_ID [2/2]

#define SQLITE_SOURCE_ID   "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2"

Definition at line 1176 of file sqlite3.c.

◆ SQLITE_Stat4

#define SQLITE_Stat4   0x0800 /* Use STAT4 data */

◆ SQLITE_STAT4_SAMPLES

#define SQLITE_STAT4_SAMPLES   1

Definition at line 107693 of file sqlite3.c.

Referenced by statInit().

◆ SQLITE_STATIC

◆ SQLITE_STATUS_MALLOC_COUNT

#define SQLITE_STATUS_MALLOC_COUNT   9

Definition at line 9059 of file sqlite3.c.

Referenced by mallocWithAlarm().

◆ SQLITE_STATUS_MALLOC_SIZE

#define SQLITE_STATUS_MALLOC_SIZE   5

Definition at line 9055 of file sqlite3.c.

Referenced by mallocWithAlarm(), and sqlite3StatusHighwater().

◆ SQLITE_STATUS_MEMORY_USED

#define SQLITE_STATUS_MEMORY_USED   0

◆ SQLITE_STATUS_PAGECACHE_OVERFLOW

#define SQLITE_STATUS_PAGECACHE_OVERFLOW   2

Definition at line 9052 of file sqlite3.c.

Referenced by pcache1Alloc().

◆ SQLITE_STATUS_PAGECACHE_SIZE

#define SQLITE_STATUS_PAGECACHE_SIZE   7

Definition at line 9057 of file sqlite3.c.

Referenced by pcache1Alloc(), and sqlite3StatusHighwater().

◆ SQLITE_STATUS_PAGECACHE_USED

#define SQLITE_STATUS_PAGECACHE_USED   1

Definition at line 9051 of file sqlite3.c.

Referenced by pcache1Alloc().

◆ SQLITE_STATUS_PARSER_STACK

#define SQLITE_STATUS_PARSER_STACK   6

Definition at line 9056 of file sqlite3.c.

Referenced by sqlite3RunParser(), and sqlite3StatusHighwater().

◆ SQLITE_STATUS_SCRATCH_OVERFLOW

#define SQLITE_STATUS_SCRATCH_OVERFLOW   4 /* NOT USED */

Definition at line 9054 of file sqlite3.c.

◆ SQLITE_STATUS_SCRATCH_SIZE

#define SQLITE_STATUS_SCRATCH_SIZE   8 /* NOT USED */

Definition at line 9058 of file sqlite3.c.

◆ SQLITE_STATUS_SCRATCH_USED

#define SQLITE_STATUS_SCRATCH_USED   3 /* NOT USED */

Definition at line 9053 of file sqlite3.c.

◆ SQLITE_STDCALL

#define SQLITE_STDCALL   SQLITE_APICALL

Definition at line 1109 of file sqlite3.c.

◆ SQLITE_STMTJRNL_SPILL

#define SQLITE_STMTJRNL_SPILL   (64*1024)

Definition at line 20537 of file sqlite3.c.

◆ SQLITE_STMTSTATUS_AUTOINDEX

#define SQLITE_STMTSTATUS_AUTOINDEX   3

Definition at line 9296 of file sqlite3.c.

Referenced by constructAutomaticIndex().

◆ SQLITE_STMTSTATUS_FULLSCAN_STEP

#define SQLITE_STMTSTATUS_FULLSCAN_STEP   1

Definition at line 9294 of file sqlite3.c.

◆ SQLITE_STMTSTATUS_MEMUSED

#define SQLITE_STMTSTATUS_MEMUSED   99

Definition at line 9300 of file sqlite3.c.

◆ SQLITE_STMTSTATUS_REPREPARE

#define SQLITE_STMTSTATUS_REPREPARE   5

Definition at line 9298 of file sqlite3.c.

◆ SQLITE_STMTSTATUS_RUN

#define SQLITE_STMTSTATUS_RUN   6

Definition at line 9299 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_STMTSTATUS_SORT

#define SQLITE_STMTSTATUS_SORT   2

Definition at line 9295 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_STMTSTATUS_VM_STEP

#define SQLITE_STMTSTATUS_VM_STEP   4

Definition at line 9297 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_STOREP2

#define SQLITE_STOREP2   0x20 /* Store result in reg[P2] rather than jump */

Definition at line 17420 of file sqlite3.c.

Referenced by codeVectorCompare(), sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ SQLITE_SUBTYPE

#define SQLITE_SUBTYPE   0x000100000

Definition at line 6326 of file sqlite3.c.

Referenced by sqlite3CreateFunc().

◆ SQLITE_SYNC_DATAONLY

#define SQLITE_SYNC_DATAONLY   0x00010

Definition at line 1718 of file sqlite3.c.

Referenced by syncJournal(), unixSync(), and zeroJournalHdr().

◆ SQLITE_SYNC_FULL

#define SQLITE_SYNC_FULL   0x00003

Definition at line 1717 of file sqlite3.c.

Referenced by sqlite3PagerSetFlags(), syncJournal(), and unixSync().

◆ SQLITE_SYNC_NORMAL

#define SQLITE_SYNC_NORMAL   0x00002

◆ SQLITE_SYSAPI

#define SQLITE_SYSAPI

Definition at line 1115 of file sqlite3.c.

◆ SQLITE_SYSTEM_MALLOC

#define SQLITE_SYSTEM_MALLOC   1

Definition at line 13622 of file sqlite3.c.

◆ SQLITE_TCLAPI

#define SQLITE_TCLAPI

Definition at line 840 of file sqlite3.c.

◆ SQLITE_TEMP_FILE_PREFIX

#define SQLITE_TEMP_FILE_PREFIX   "etilqs_"

Definition at line 16339 of file sqlite3.c.

Referenced by unixGetTempname().

◆ SQLITE_TEMP_STORE

#define SQLITE_TEMP_STORE   1

Definition at line 14199 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ SQLITE_TESTCTRL_ALWAYS

#define SQLITE_TESTCTRL_ALWAYS   13

Definition at line 8744 of file sqlite3.c.

◆ SQLITE_TESTCTRL_ASSERT

#define SQLITE_TESTCTRL_ASSERT   12

Definition at line 8743 of file sqlite3.c.

◆ SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS

#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS   10

Definition at line 8741 of file sqlite3.c.

◆ SQLITE_TESTCTRL_BITVEC_TEST

#define SQLITE_TESTCTRL_BITVEC_TEST   8

Definition at line 8739 of file sqlite3.c.

◆ SQLITE_TESTCTRL_BYTEORDER

#define SQLITE_TESTCTRL_BYTEORDER   22

Definition at line 8755 of file sqlite3.c.

◆ SQLITE_TESTCTRL_EXPLAIN_STMT

#define SQLITE_TESTCTRL_EXPLAIN_STMT   19 /* NOT USED */

Definition at line 8751 of file sqlite3.c.

◆ SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS

#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS   29

Definition at line 8762 of file sqlite3.c.

◆ SQLITE_TESTCTRL_FAULT_INSTALL

#define SQLITE_TESTCTRL_FAULT_INSTALL   9

Definition at line 8740 of file sqlite3.c.

◆ SQLITE_TESTCTRL_FIRST

#define SQLITE_TESTCTRL_FIRST   5

Definition at line 8735 of file sqlite3.c.

◆ SQLITE_TESTCTRL_IMPOSTER

#define SQLITE_TESTCTRL_IMPOSTER   25

Definition at line 8758 of file sqlite3.c.

◆ SQLITE_TESTCTRL_INTERNAL_FUNCTIONS

#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS   17

Definition at line 8749 of file sqlite3.c.

◆ SQLITE_TESTCTRL_ISINIT

#define SQLITE_TESTCTRL_ISINIT   23

Definition at line 8756 of file sqlite3.c.

◆ SQLITE_TESTCTRL_ISKEYWORD

#define SQLITE_TESTCTRL_ISKEYWORD   16 /* NOT USED */

Definition at line 8747 of file sqlite3.c.

◆ SQLITE_TESTCTRL_LAST

#define SQLITE_TESTCTRL_LAST   29 /* Largest TESTCTRL */

Definition at line 8763 of file sqlite3.c.

◆ SQLITE_TESTCTRL_LOCALTIME_FAULT

#define SQLITE_TESTCTRL_LOCALTIME_FAULT   18

Definition at line 8750 of file sqlite3.c.

◆ SQLITE_TESTCTRL_NEVER_CORRUPT

#define SQLITE_TESTCTRL_NEVER_CORRUPT   20

Definition at line 8753 of file sqlite3.c.

◆ SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD

#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD   19

Definition at line 8752 of file sqlite3.c.

◆ SQLITE_TESTCTRL_OPTIMIZATIONS

#define SQLITE_TESTCTRL_OPTIMIZATIONS   15

Definition at line 8746 of file sqlite3.c.

◆ SQLITE_TESTCTRL_PARSER_COVERAGE

#define SQLITE_TESTCTRL_PARSER_COVERAGE   26

Definition at line 8759 of file sqlite3.c.

◆ SQLITE_TESTCTRL_PENDING_BYTE

#define SQLITE_TESTCTRL_PENDING_BYTE   11

Definition at line 8742 of file sqlite3.c.

◆ SQLITE_TESTCTRL_PRNG_RESET

#define SQLITE_TESTCTRL_PRNG_RESET   7 /* NOT USED */

Definition at line 8738 of file sqlite3.c.

◆ SQLITE_TESTCTRL_PRNG_RESTORE

#define SQLITE_TESTCTRL_PRNG_RESTORE   6

Definition at line 8737 of file sqlite3.c.

◆ SQLITE_TESTCTRL_PRNG_SAVE

#define SQLITE_TESTCTRL_PRNG_SAVE   5

Definition at line 8736 of file sqlite3.c.

◆ SQLITE_TESTCTRL_PRNG_SEED

#define SQLITE_TESTCTRL_PRNG_SEED   28

Definition at line 8761 of file sqlite3.c.

◆ SQLITE_TESTCTRL_RESERVE

#define SQLITE_TESTCTRL_RESERVE   14 /* NOT USED */

Definition at line 8745 of file sqlite3.c.

◆ SQLITE_TESTCTRL_RESULT_INTREAL

#define SQLITE_TESTCTRL_RESULT_INTREAL   27

Definition at line 8760 of file sqlite3.c.

◆ SQLITE_TESTCTRL_SCRATCHMALLOC

#define SQLITE_TESTCTRL_SCRATCHMALLOC   17 /* NOT USED */

Definition at line 8748 of file sqlite3.c.

◆ SQLITE_TESTCTRL_SORTER_MMAP

#define SQLITE_TESTCTRL_SORTER_MMAP   24

Definition at line 8757 of file sqlite3.c.

◆ SQLITE_TESTCTRL_VDBE_COVERAGE

#define SQLITE_TESTCTRL_VDBE_COVERAGE   21

Definition at line 8754 of file sqlite3.c.

◆ SQLITE_TEXT

#define SQLITE_TEXT   3

◆ SQLITE_THREADS_IMPLEMENTED

#define SQLITE_THREADS_IMPLEMENTED   1 /* Prevent the single-thread code below */

Definition at line 30403 of file sqlite3.c.

◆ SQLITE_THREADSAFE

#define SQLITE_THREADSAFE   1 /* IMP: R-07272-22309 */

Definition at line 13571 of file sqlite3.c.

Referenced by removeFromSharingList(), and sqlite3BtreeOpen().

◆ SQLITE_TOKEN_KEYWORD

#define SQLITE_TOKEN_KEYWORD   0x2 /* Token is a keyword. */

Definition at line 17851 of file sqlite3.c.

◆ SQLITE_TOKEN_QUOTED

#define SQLITE_TOKEN_QUOTED   0x1 /* Token is a quoted identifier. */

Definition at line 17850 of file sqlite3.c.

◆ SQLITE_TOOBIG

#define SQLITE_TOOBIG   18 /* String or BLOB exceeds size limit */

◆ SQLITE_TRACE_CLOSE

#define SQLITE_TRACE_CLOSE   0x08

Definition at line 4247 of file sqlite3.c.

◆ SQLITE_TRACE_LEGACY

#define SQLITE_TRACE_LEGACY   0x40 /* Use the legacy xTrace */

Definition at line 16807 of file sqlite3.c.

Referenced by sqlite3_trace(), and sqlite3VdbeExec().

◆ SQLITE_TRACE_NONLEGACY_MASK

#define SQLITE_TRACE_NONLEGACY_MASK   0x0f /* Normal flags */

Definition at line 16813 of file sqlite3.c.

Referenced by sqlite3_profile().

◆ SQLITE_TRACE_PROFILE

#define SQLITE_TRACE_PROFILE   0x02

Definition at line 4245 of file sqlite3.c.

Referenced by invokeProfileCallback(), and sqlite3Step().

◆ SQLITE_TRACE_ROW

#define SQLITE_TRACE_ROW   0x04

Definition at line 4246 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_TRACE_STMT

#define SQLITE_TRACE_STMT   0x01

Definition at line 4244 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ SQLITE_TRACE_XPROFILE

#define SQLITE_TRACE_XPROFILE   0x80 /* Use the legacy xProfile */

Definition at line 16808 of file sqlite3.c.

Referenced by invokeProfileCallback(), sqlite3_profile(), and sqlite3Step().

◆ SQLITE_TRANSACTION

#define SQLITE_TRANSACTION   22 /* Operation NULL */

Definition at line 4141 of file sqlite3.c.

Referenced by sqlite3EndTransaction().

◆ SQLITE_TRANSIENT

◆ SQLITE_Transitive

#define SQLITE_Transitive   0x0080 /* Transitive constraints */

Definition at line 17048 of file sqlite3.c.

Referenced by termIsEquivalence().

◆ SQLITE_TriggerEQP

#define SQLITE_TriggerEQP   0x01000000 /* Show trigger EXPLAIN QUERY PLAN */

Definition at line 17003 of file sqlite3.c.

Referenced by sqlite3VdbeList().

◆ SQLITE_TrustedSchema

#define SQLITE_TrustedSchema
Value:
0x00000080 /* Allow unsafe functions and
** vtabs in the schema definition */

Definition at line 16985 of file sqlite3.c.

Referenced by openDatabase(), selectExpander(), and sqlite3ExprFunctionUsable().

◆ SQLITE_UPDATE

#define SQLITE_UPDATE   23 /* Table Name Column Name */

Definition at line 4142 of file sqlite3.c.

Referenced by sqlite3Update(), and sqlite3VdbeExec().

◆ SQLITE_USE_URI

#define SQLITE_USE_URI   0

Definition at line 20503 of file sqlite3.c.

◆ SQLITE_UTF16

#define SQLITE_UTF16   4 /* Use native byte order */

Definition at line 6255 of file sqlite3.c.

Referenced by sqlite3CreateFunc().

◆ SQLITE_UTF16_ALIGNED

#define SQLITE_UTF16_ALIGNED   8 /* sqlite3_create_collation only */

Definition at line 6257 of file sqlite3.c.

Referenced by sqlite3ValueText(), and valueToText().

◆ SQLITE_UTF16BE

◆ SQLITE_UTF16LE

◆ SQLITE_UTF16NATIVE

◆ SQLITE_UTF8

◆ SQLITE_VDBE_H

#define SQLITE_VDBE_H

Definition at line 15412 of file sqlite3.c.

◆ SQLITE_VDBEINT_H

#define SQLITE_VDBEINT_H

Definition at line 20723 of file sqlite3.c.

◆ SQLITE_VERSION

#define SQLITE_VERSION   "3.33.0"

Definition at line 1174 of file sqlite3.c.

◆ SQLITE_VERSION_NUMBER

#define SQLITE_VERSION_NUMBER   3033000

Definition at line 1175 of file sqlite3.c.

Referenced by pager_write_changecounter(), and sqlite3_threadsafe().

◆ SQLITE_VTAB_CONSTRAINT_SUPPORT

#define SQLITE_VTAB_CONSTRAINT_SUPPORT   1

Definition at line 10223 of file sqlite3.c.

Referenced by sqlite3_vtab_config().

◆ SQLITE_VTAB_DIRECTONLY

#define SQLITE_VTAB_DIRECTONLY   3

Definition at line 10225 of file sqlite3.c.

Referenced by sqlite3_vtab_config().

◆ SQLITE_VTAB_INNOCUOUS

#define SQLITE_VTAB_INNOCUOUS   2

Definition at line 10224 of file sqlite3.c.

Referenced by sqlite3_vtab_config().

◆ SQLITE_VTABRISK_High

#define SQLITE_VTABRISK_High   2

Definition at line 17481 of file sqlite3.c.

Referenced by sqlite3_vtab_config().

◆ SQLITE_VTABRISK_Low

#define SQLITE_VTABRISK_Low   0

Definition at line 17479 of file sqlite3.c.

Referenced by sqlite3_vtab_config().

◆ SQLITE_VTABRISK_Normal

#define SQLITE_VTABRISK_Normal   1

Definition at line 17480 of file sqlite3.c.

Referenced by vtabCallConstructor().

◆ SQLITE_WAL_H

#define SQLITE_WAL_H

Definition at line 51585 of file sqlite3.c.

◆ SQLITE_WARNING

#define SQLITE_WARNING   28 /* Warnings from sqlite3_log() */

Definition at line 1498 of file sqlite3.c.

Referenced by lookupName(), robust_open(), and verifyDbFile().

◆ SQLITE_WARNING_AUTOINDEX

#define SQLITE_WARNING_AUTOINDEX   (SQLITE_WARNING | (1<<8))

Definition at line 1589 of file sqlite3.c.

Referenced by constructAutomaticIndex().

◆ SQLITE_WHEREINT_H

#define SQLITE_WHEREINT_H

Definition at line 140932 of file sqlite3.c.

◆ SQLITE_WIN32_DATA_DIRECTORY_TYPE

#define SQLITE_WIN32_DATA_DIRECTORY_TYPE   1

Definition at line 7155 of file sqlite3.c.

◆ SQLITE_WIN32_TEMP_DIRECTORY_TYPE

#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE   2

Definition at line 7156 of file sqlite3.c.

◆ SQLITE_WindowFunc

#define SQLITE_WindowFunc   0x0002 /* Use xInverse for window functions */

Definition at line 17042 of file sqlite3.c.

◆ SQLITE_WITHIN

#define SQLITE_WITHIN ( P,
S,
E )   (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E)))

◆ SQLITE_WriteSchema

#define SQLITE_WriteSchema   0x00000001 /* OK to update SQLITE_SCHEMA */

Definition at line 16978 of file sqlite3.c.

Referenced by corruptSchema(), and sqlite3Pragma().

◆ SQLITE_WSD

#define SQLITE_WSD

Definition at line 14632 of file sqlite3.c.

◆ sqliteHashData

◆ sqliteHashFirst

◆ sqliteHashNext

◆ SQLITEINT_H

#define SQLITEINT_H

Definition at line 806 of file sqlite3.c.

◆ SRT_Coroutine

#define SRT_Coroutine   13 /* Generate a single row of result */

◆ SRT_Discard

#define SRT_Discard   4 /* Do not save the results anywhere */

Definition at line 18571 of file sqlite3.c.

Referenced by selectInnerLoop(), and sqlite3Select().

◆ SRT_DistFifo

#define SRT_DistFifo   6 /* Like SRT_Fifo, but unique results only */

Definition at line 18573 of file sqlite3.c.

Referenced by generateWithRecursiveQuery(), selectInnerLoop(), and sqlite3Select().

◆ SRT_DistQueue

#define SRT_DistQueue   8 /* Like SRT_Queue, but unique results only */

Definition at line 18575 of file sqlite3.c.

Referenced by generateWithRecursiveQuery(), selectInnerLoop(), and sqlite3Select().

◆ SRT_EphemTab

#define SRT_EphemTab   12 /* Create transient tab and store like SRT_Table */

◆ SRT_Except

#define SRT_Except   2 /* Remove result from a UNION index */

Definition at line 18569 of file sqlite3.c.

Referenced by multiSelect(), selectInnerLoop(), and sqlite3Select().

◆ SRT_Exists

#define SRT_Exists   3 /* Store 1 if the result is not empty */

◆ SRT_Fifo

#define SRT_Fifo   5 /* Store result as data with an automatic rowid */

Definition at line 18572 of file sqlite3.c.

Referenced by generateWithRecursiveQuery(), selectInnerLoop(), and sqlite3Select().

◆ SRT_Mem

#define SRT_Mem   10 /* Store result in a memory cell */

◆ SRT_Output

#define SRT_Output   9 /* Output each row of result */

◆ SRT_Queue

#define SRT_Queue   7 /* Store result in an queue */

Definition at line 18574 of file sqlite3.c.

Referenced by generateWithRecursiveQuery(), selectInnerLoop(), and sqlite3Select().

◆ SRT_Set

#define SRT_Set   11 /* Store results as keys in an index */

◆ SRT_Table

#define SRT_Table   14 /* Store result as data with an automatic rowid */

◆ SRT_Union

#define SRT_Union   1 /* Store result as keys in an index */

Definition at line 18568 of file sqlite3.c.

Referenced by multiSelect(), selectInnerLoop(), and sqlite3Select().

◆ SRT_Upfrom

#define SRT_Upfrom   15 /* Store result as data with rowid */

Definition at line 18586 of file sqlite3.c.

Referenced by generateSortTail(), selectInnerLoop(), and updateFromSelect().

◆ SRVAL

#define SRVAL ( p)    ((void*)((SorterRecord*)(p) + 1))

Definition at line 94334 of file sqlite3.c.

Referenced by vdbeSorterListToPMA().

◆ STAT_GET_NDLT

#define STAT_GET_NDLT   4 /* "ndlt" column of stat[34] entry */

Definition at line 108336 of file sqlite3.c.

Referenced by analyzeOneTable(), and statGet().

◆ STAT_GET_NEQ

#define STAT_GET_NEQ   2 /* "neq" column of stat[34] entry */

Definition at line 108334 of file sqlite3.c.

Referenced by analyzeOneTable(), and statGet().

◆ STAT_GET_NLT

#define STAT_GET_NLT   3 /* "nlt" column of stat[34] entry */

Definition at line 108335 of file sqlite3.c.

Referenced by analyzeOneTable(), and statGet().

◆ STAT_GET_ROWID

#define STAT_GET_ROWID   1 /* "rowid" column of stat[34] entry */

Definition at line 108333 of file sqlite3.c.

Referenced by analyzeOneTable(), and statGet().

◆ STAT_GET_STAT1

#define STAT_GET_STAT1   0 /* "stat" column of stat1 table */

Definition at line 108332 of file sqlite3.c.

Referenced by analyzeOneTable(), and statGet().

◆ STR_FUNCTION

#define STR_FUNCTION ( zName,
nArg,
pArg,
bNC,
xFunc )
Value:
pArg, 0, xFunc, 0, 0, 0, #zName, }

Definition at line 17264 of file sqlite3.c.

17264#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
17265 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
17266 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterDateTimeFunctions().

◆ SWAP

#define SWAP ( TYPE,
A,
B )   {TYPE t=A; A=B; B=t;}

◆ swapMixedEndianFloat

#define swapMixedEndianFloat ( X)

Definition at line 81517 of file sqlite3.c.

Referenced by serialGet(), and sqlite3VdbeSerialPut().

◆ TERM_ANDINFO

#define TERM_ANDINFO   0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */

Definition at line 141196 of file sqlite3.c.

Referenced by exprAnalyzeOrTerm(), and sqlite3WhereClauseClear().

◆ TERM_CODED

#define TERM_CODED   0x0004 /* This term is already coded */

◆ TERM_COPIED

#define TERM_COPIED   0x0008 /* Has a child */

Definition at line 141194 of file sqlite3.c.

Referenced by exprAnalyze(), and exprAnalyzeOrTerm().

◆ TERM_DYNAMIC

#define TERM_DYNAMIC   0x0001 /* Need to call sqlite3ExprDelete(db, pExpr) */

◆ TERM_HEURTRUTH

#define TERM_HEURTRUTH   0x2000 /* Heuristic truthProb used */

Definition at line 141208 of file sqlite3.c.

Referenced by whereLoopAddBtreeIndex(), and whereLoopOutputAdjust().

◆ TERM_HIGHTRUTH

#define TERM_HIGHTRUTH   0 /* Only used with STAT4 */

Definition at line 141212 of file sqlite3.c.

Referenced by whereLoopAddBtreeIndex(), and whereLoopOutputAdjust().

◆ TERM_IS

#define TERM_IS   0x0800 /* Term.pExpr is an IS operator */

Definition at line 141206 of file sqlite3.c.

Referenced by codeAllEqualityTerms(), and exprAnalyze().

◆ TERM_LIKE

#define TERM_LIKE   0x0400 /* The original LIKE operator */

Definition at line 141205 of file sqlite3.c.

Referenced by disableTerm(), and exprAnalyze().

◆ TERM_LIKECOND

#define TERM_LIKECOND   0x0200 /* Conditionally this LIKE operator term */

Definition at line 141204 of file sqlite3.c.

Referenced by disableTerm().

◆ TERM_LIKEOPT

#define TERM_LIKEOPT   0x0100 /* Virtual terms from the LIKE optimization */

◆ TERM_OR_OK

#define TERM_OR_OK   0x0040 /* Used during OR-clause processing */

Definition at line 141197 of file sqlite3.c.

Referenced by exprAnalyzeOrTerm().

◆ TERM_ORINFO

#define TERM_ORINFO   0x0010 /* Need to free the WhereTerm.u.pOrInfo object */

Definition at line 141195 of file sqlite3.c.

Referenced by exprAnalyzeOrTerm(), and sqlite3WhereClauseClear().

◆ TERM_VARSELECT

#define TERM_VARSELECT   0x1000 /* Term.pExpr contains a correlated sub-query */

Definition at line 141207 of file sqlite3.c.

Referenced by exprAnalyze().

◆ TERM_VIRTUAL

#define TERM_VIRTUAL   0x0002 /* Added by the optimizer. Do not code */

◆ TERM_VNULL

#define TERM_VNULL   0x0000 /* Disabled if not using stat4 */

◆ TEST_FUNC

#define TEST_FUNC ( zName,
nArg,
iArg,
mFlags )
Value:

Definition at line 17251 of file sqlite3.c.

17251#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
17252 {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
17253 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
17254#define TEST_FUNC(zName, nArg, iArg, mFlags) \

Referenced by sqlite3RegisterBuiltinFunctions().

◆ TESTBIT

#define TESTBIT ( V,
I )   (V[I>>3]&(1<<(I&7)))!=0

Definition at line 48764 of file sqlite3.c.

Referenced by sqlite3BitvecBuiltinTest().

◆ testcase

#define testcase ( X)

Definition at line 13686 of file sqlite3.c.

Referenced by addToSavepointBitvecs(), allocateBtreePage(), allocateIndexInfo(), allocateSpace(), analyzeAggregate(), applyAffinity(), balance_nonroot(), blobSeekToRow(), btreeInitPage(), btreeParseCellAdjustSizeForOverflow(), cellSizePtr(), codeAllEqualityTerms(), codeDeferredSeek(), codeEqualityTerm(), codeVectorCompare(), compare2pow63(), constructAutomaticIndex(), contextMalloc(), convertToWithoutRowidTable(), createTableStmt(), defragmentPage(), dropCell(), exprAnalyze(), exprAnalyzeOrTerm(), exprCodeBetween(), exprNodeIsConstant(), fillInCell(), fkActionTrigger(), flattenSubquery(), generateOutputSubroutine(), generateSortTail(), getAndInitPage(), getPageNormal(), impliesNotNullRow(), isAuxiliaryVtabOperator(), isCandidateForInOpt(), isDupColumn(), keywordCode(), likeFunc(), lookupName(), moveToParent(), multiSelect(), numericType(), openDatabase(), pageFindSlot(), pager_playback(), pager_playback_one_page(), pager_truncate(), pagerOpenWalIfPresent(), pagerStress(), propagateConstantExprRewrite(), ptrmapPutOvflPtr(), readJournalHdr(), rebuildPage(), recomputeColumnsNotIndexed(), replaceFunc(), resolveExprStep(), saveCursorsOnList(), selectExpander(), selectInnerLoop(), serialGet(), sqlite3_aggregate_context(), sqlite3_str_vappendf(), sqlite3AddDefaultValue(), sqlite3AddInt64(), sqlite3AtoF(), sqlite3Atoi64(), sqlite3AuthCheck(), sqlite3BtreeConnectionCount(), sqlite3BtreeInsert(), sqlite3BtreeIntegrityCheck(), sqlite3BtreeMovetoUnpacked(), sqlite3CodeRhsOfIN(), sqlite3CodeSubselect(), sqlite3ColumnsFromExprList(), sqlite3ComputeGeneratedColumns(), sqlite3CreateFunc(), sqlite3CreateIndex(), sqlite3DbMallocZero(), sqlite3DeleteFrom(), sqlite3EndTable(), sqlite3ExprAssignVarNumber(), sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3ExprReferencesUpdatedColumn(), sqlite3FindInIndex(), sqlite3GenerateConstraintChecks(), sqlite3GenerateRowDelete(), sqlite3GetInt32(), sqlite3GetToken(), sqlite3Insert(), sqlite3JoinType(), sqlite3MemCompare(), sqlite3MemMalloc(), sqlite3MemRealloc(), sqlite3PagerDontWrite(), sqlite3PagerOpen(), sqlite3ResolveExprListNames(), sqlite3ResolveExprNames(), sqlite3SafetyCheckOk(), sqlite3Select(), sqlite3StrAccumEnlarge(), sqlite3TriggerInsertStep(), sqlite3UnlinkAndDeleteTable(), sqlite3Update(), sqlite3VdbeDeleteAuxData(), sqlite3VdbeExec(), sqlite3VdbeExpandSql(), sqlite3VdbeFindCompare(), sqlite3VdbeIdxRowid(), sqlite3VdbeMemExpandBlob(), sqlite3VdbeMemGrow(), sqlite3VdbeMemNumerify(), sqlite3VdbeMemSetStr(), sqlite3VdbeRecordCompareWithSkip(), sqlite3WalBeginReadTransaction(), sqlite3WalCheckpoint(), sqlite3WalReadFrame(), sqlite3WhereBegin(), sqlite3WhereEnd(), sqlite3WhereFindTerm(), strftimeFunc(), substExpr(), termCanDriveIndex(), updateAccumulator(), valueFromExpr(), vdbeMemClearExternAndSetNull(), vdbePmaReaderSeek(), vdbeRecordCompareInt(), vdbeRecordDecodeInt(), vdbeSorterMapFile(), walCheckpoint(), walCleanupHash(), walIndexPageRealloc(), walIndexReadHdr(), walIndexRecover(), walIndexTryHdr(), walkExpr(), walRestartLog(), whereClauseInsert(), whereIndexExprTransNode(), whereLoopAddBtree(), whereLoopAddBtreeIndex(), whereLoopAddOr(), whereLoopAddVirtualOne(), whereLoopOutputAdjust(), wherePathSatisfiesOrderBy(), wherePathSolver(), whereRangeScanEst(), whereRangeVectorLen(), whereScanNext(), whereShortCut(), windowCodeRangeTest(), xferOptimization(), and yy_reduce().

◆ TESTONLY

◆ TF_Autoincrement

#define TF_Autoincrement   0x0008 /* Integer primary key is autoincrement */

◆ TF_Ephemeral

#define TF_Ephemeral   0x0002 /* An ephemeral table */

◆ TF_HasGenerated

#define TF_HasGenerated   0x0060 /* Combo: HasVirtual + HasStored */

◆ TF_HasNotNull

#define TF_HasNotNull   0x0800 /* Contains NOT NULL constraints */

◆ TF_HasPrimaryKey

#define TF_HasPrimaryKey   0x0004 /* Table has a primary key */

Definition at line 17537 of file sqlite3.c.

Referenced by sqlite3AddPrimaryKey(), and sqlite3EndTable().

◆ TF_HasStat1

#define TF_HasStat1   0x0010 /* nRowLogEst set from sqlite_stat1 */

Definition at line 17539 of file sqlite3.c.

Referenced by analysisLoader().

◆ TF_HasStored

#define TF_HasStored   0x0040 /* Has one or more STORED columns */

◆ TF_HasVirtual

#define TF_HasVirtual   0x0020 /* Has one or more VIRTUAL columns */

◆ TF_NoVisibleRowid

#define TF_NoVisibleRowid   0x0200 /* No user-visible "rowid" column */

Definition at line 17545 of file sqlite3.c.

Referenced by sqlite3_declare_vtab(), sqlite3EndTable(), withExpand(), and yy_reduce().

◆ TF_OOOHidden

#define TF_OOOHidden   0x0400 /* Out-of-Order hidden columns */

Definition at line 17546 of file sqlite3.c.

Referenced by sqlite3Insert(), and vtabCallConstructor().

◆ TF_Readonly

#define TF_Readonly   0x0001 /* Read-only system table */

Definition at line 17535 of file sqlite3.c.

Referenced by sqlite3EndTable(), and tabIsReadOnly().

◆ TF_Shadow

#define TF_Shadow   0x1000 /* True for a shadow table */

Definition at line 17548 of file sqlite3.c.

Referenced by isAlterableTable(), sqlite3EndTable(), and tabIsReadOnly().

◆ TF_StatsUsed

#define TF_StatsUsed
Value:
0x0100 /* Query planner decisions affected by
** Index.aiRowLogEst[] values */

Definition at line 17544 of file sqlite3.c.

Referenced by sqlite3Pragma(), and whereLoopAddBtree().

◆ TF_WithoutRowid

#define TF_WithoutRowid   0x0080 /* No rowid. PRIMARY KEY is the key */

◆ threadid

#define threadid   pthread_self()

Definition at line 33865 of file sqlite3.c.

Referenced by mg_join_thread().

◆ THREE_BYTE_INT

#define THREE_BYTE_INT ( x)    (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])

Definition at line 81574 of file sqlite3.c.

Referenced by vdbeRecordCompareInt(), and vdbeRecordDecodeInt().

◆ TIMER_ELAPSED

#define TIMER_ELAPSED   ((sqlite_uint64)0)

Definition at line 33785 of file sqlite3.c.

Referenced by seekAndRead(), and seekAndWriteFd().

◆ TIMER_END

#define TIMER_END

Definition at line 33784 of file sqlite3.c.

Referenced by seekAndRead(), and seekAndWriteFd().

◆ TIMER_START

#define TIMER_START

Definition at line 33783 of file sqlite3.c.

Referenced by seekAndRead(), and seekAndWriteFd().

◆ TK_ABORT

#define TK_ABORT   27

Definition at line 13969 of file sqlite3.c.

◆ TK_ACTION

#define TK_ACTION   28

Definition at line 13970 of file sqlite3.c.

◆ TK_ADD

#define TK_ADD   160

Definition at line 14102 of file sqlite3.c.

◆ TK_AFTER

#define TK_AFTER   29

Definition at line 13971 of file sqlite3.c.

◆ TK_AGG_COLUMN

◆ TK_AGG_FUNCTION

◆ TK_ALL

◆ TK_ALTER

#define TK_ALTER   159

Definition at line 14101 of file sqlite3.c.

◆ TK_ALWAYS

#define TK_ALWAYS   96

Definition at line 14038 of file sqlite3.c.

◆ TK_ANALYZE

#define TK_ANALYZE   30

Definition at line 13972 of file sqlite3.c.

◆ TK_AND

◆ TK_ANY

#define TK_ANY   100

Definition at line 14042 of file sqlite3.c.

◆ TK_AS

#define TK_AS   24

Definition at line 13966 of file sqlite3.c.

Referenced by exprAnalyze().

◆ TK_ASC

#define TK_ASC   31

Definition at line 13973 of file sqlite3.c.

◆ TK_ASTERISK

#define TK_ASTERISK   177

◆ TK_ATTACH

#define TK_ATTACH   32

Definition at line 13974 of file sqlite3.c.

◆ TK_AUTOINCR

#define TK_AUTOINCR   124

Definition at line 14066 of file sqlite3.c.

◆ TK_BEFORE

#define TK_BEFORE   33

Definition at line 13975 of file sqlite3.c.

Referenced by sqlite3BeginTrigger(), and yy_reduce().

◆ TK_BEGIN

#define TK_BEGIN   5

Definition at line 13947 of file sqlite3.c.

◆ TK_BETWEEN

◆ TK_BITAND

#define TK_BITAND   101

Definition at line 14043 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_BITNOT

#define TK_BITNOT   112

Definition at line 14054 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_BITOR

#define TK_BITOR   102

Definition at line 14044 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_BLOB

◆ TK_BY

#define TK_BY   34

Definition at line 13976 of file sqlite3.c.

◆ TK_CASCADE

#define TK_CASCADE   35

Definition at line 13977 of file sqlite3.c.

◆ TK_CASE

#define TK_CASE   154

Definition at line 14096 of file sqlite3.c.

Referenced by impliesNotNullRow(), sqlite3ExprCodeTarget(), and yy_reduce().

◆ TK_CAST

#define TK_CAST   36

◆ TK_CHECK

#define TK_CHECK   122

Definition at line 14064 of file sqlite3.c.

◆ TK_COLLATE

◆ TK_COLUMN

◆ TK_COLUMNKW

#define TK_COLUMNKW   60

Definition at line 14002 of file sqlite3.c.

◆ TK_COMMA

#define TK_COMMA   26

Definition at line 13968 of file sqlite3.c.

Referenced by sqlite3GetToken().

◆ TK_COMMIT

#define TK_COMMIT   10

Definition at line 13952 of file sqlite3.c.

Referenced by sqlite3EndTransaction().

◆ TK_CONCAT

#define TK_CONCAT   110

◆ TK_CONFLICT

#define TK_CONFLICT   37

Definition at line 13979 of file sqlite3.c.

◆ TK_CONSTRAINT

#define TK_CONSTRAINT   117

Definition at line 14059 of file sqlite3.c.

◆ TK_CREATE

#define TK_CREATE   17

Definition at line 13959 of file sqlite3.c.

◆ TK_CTIME_KW

#define TK_CTIME_KW   99

Definition at line 14041 of file sqlite3.c.

◆ TK_CURRENT

#define TK_CURRENT   85

Definition at line 14027 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), sqlite3WindowUpdate(), windowFullScan(), and yy_reduce().

◆ TK_DATABASE

#define TK_DATABASE   38

Definition at line 13980 of file sqlite3.c.

◆ TK_DEFAULT

#define TK_DEFAULT   118

Definition at line 14060 of file sqlite3.c.

◆ TK_DEFERRABLE

#define TK_DEFERRABLE   129

Definition at line 14071 of file sqlite3.c.

◆ TK_DEFERRED

#define TK_DEFERRED   7

Definition at line 13949 of file sqlite3.c.

Referenced by yy_reduce().

◆ TK_DELETE

◆ TK_DESC

#define TK_DESC   39

Definition at line 13981 of file sqlite3.c.

◆ TK_DETACH

#define TK_DETACH   40

Definition at line 13982 of file sqlite3.c.

◆ TK_DISTINCT

#define TK_DISTINCT   138

Definition at line 14080 of file sqlite3.c.

◆ TK_DO

#define TK_DO   61

◆ TK_DOT

◆ TK_DROP

#define TK_DROP   131

Definition at line 14073 of file sqlite3.c.

◆ TK_EACH

#define TK_EACH   41

Definition at line 13983 of file sqlite3.c.

◆ TK_ELSE

◆ TK_END

◆ TK_EQ

◆ TK_ESCAPE

#define TK_ESCAPE   58

Definition at line 14000 of file sqlite3.c.

◆ TK_EXCEPT

#define TK_EXCEPT   134

Definition at line 14076 of file sqlite3.c.

Referenced by multiSelect(), and multiSelectOrderBy().

◆ TK_EXCLUDE

#define TK_EXCLUDE   91

Definition at line 14033 of file sqlite3.c.

◆ TK_EXCLUSIVE

#define TK_EXCLUSIVE   9

Definition at line 13951 of file sqlite3.c.

◆ TK_EXISTS

#define TK_EXISTS   20

◆ TK_EXPLAIN

#define TK_EXPLAIN   2

Definition at line 13944 of file sqlite3.c.

◆ TK_FAIL

#define TK_FAIL   42

Definition at line 13984 of file sqlite3.c.

◆ TK_FILTER

#define TK_FILTER   163

Definition at line 14105 of file sqlite3.c.

Referenced by sqlite3RunParser(), and yy_reduce().

◆ TK_FIRST

#define TK_FIRST   83

Definition at line 14025 of file sqlite3.c.

◆ TK_FLOAT

◆ TK_FOLLOWING

#define TK_FOLLOWING   86

Definition at line 14028 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), sqlite3WindowUpdate(), and windowCodeOp().

◆ TK_FOR

#define TK_FOR   62

Definition at line 14004 of file sqlite3.c.

Referenced by forstat(), forstat(), forstat(), forstat(), statement(), statement(), statement(), and statement().

◆ TK_FOREIGN

#define TK_FOREIGN   130

Definition at line 14072 of file sqlite3.c.

◆ TK_FROM

#define TK_FROM   140

Definition at line 14082 of file sqlite3.c.

◆ TK_FUNCTION

◆ TK_GE

◆ TK_GENERATED

#define TK_GENERATED   95

Definition at line 14037 of file sqlite3.c.

◆ TK_GROUP

#define TK_GROUP   144

Definition at line 14086 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep().

◆ TK_GROUPS

#define TK_GROUPS   92

Definition at line 14034 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ TK_GT

◆ TK_HAVING

#define TK_HAVING   145

Definition at line 14087 of file sqlite3.c.

◆ TK_ID

◆ TK_IF

#define TK_IF   18

Definition at line 13960 of file sqlite3.c.

Referenced by ifstat(), ifstat(), ifstat(), ifstat(), statement(), statement(), statement(), and statement().

◆ TK_IF_NULL_ROW

◆ TK_IGNORE

#define TK_IGNORE   63

Definition at line 14005 of file sqlite3.c.

◆ TK_ILLEGAL

#define TK_ILLEGAL   180

Definition at line 14122 of file sqlite3.c.

Referenced by findNextHostParameter(), sqlite3GetToken(), and sqlite3RunParser().

◆ TK_IMMEDIATE

#define TK_IMMEDIATE   8

Definition at line 13950 of file sqlite3.c.

◆ TK_IN

◆ TK_INDEX

#define TK_INDEX   158

Definition at line 14100 of file sqlite3.c.

◆ TK_INDEXED

#define TK_INDEXED   114

Definition at line 14056 of file sqlite3.c.

◆ TK_INITIALLY

#define TK_INITIALLY   64

Definition at line 14006 of file sqlite3.c.

◆ TK_INSERT

#define TK_INSERT   125

◆ TK_INSTEAD

#define TK_INSTEAD   65

Definition at line 14007 of file sqlite3.c.

Referenced by sqlite3BeginTrigger(), and yy_reduce().

◆ TK_INTEGER

◆ TK_INTERSECT

#define TK_INTERSECT   135

Definition at line 14077 of file sqlite3.c.

Referenced by multiSelect(), and multiSelectOrderBy().

◆ TK_INTO

#define TK_INTO   148

Definition at line 14090 of file sqlite3.c.

◆ TK_IS

◆ TK_ISNOT

◆ TK_ISNULL

◆ TK_JOIN

#define TK_JOIN   141

Definition at line 14083 of file sqlite3.c.

◆ TK_JOIN_KW

#define TK_JOIN_KW   116

Definition at line 14058 of file sqlite3.c.

Referenced by getToken().

◆ TK_KEY

#define TK_KEY   67

Definition at line 14009 of file sqlite3.c.

◆ TK_LAST

#define TK_LAST   84

Definition at line 14026 of file sqlite3.c.

◆ TK_LE

◆ TK_LIKE_KW

#define TK_LIKE_KW   47

Definition at line 13989 of file sqlite3.c.

◆ TK_LIMIT

#define TK_LIMIT   146

Definition at line 14088 of file sqlite3.c.

Referenced by computeLimitRegisters(), sqlite3CodeSubselect(), and yy_reduce().

◆ TK_LP

#define TK_LP   22

Definition at line 13964 of file sqlite3.c.

Referenced by analyzeFilterKeyword(), sqlite3GetToken(), and sqlite3RunParser().

◆ TK_LSHIFT

#define TK_LSHIFT   103

Definition at line 14045 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_LT

◆ TK_MATCH

#define TK_MATCH   46

Definition at line 13988 of file sqlite3.c.

Referenced by exprAnalyze().

◆ TK_MINUS

#define TK_MINUS   106

Definition at line 14048 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_NE

◆ TK_NO

#define TK_NO   66

Definition at line 14008 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowFullScan().

◆ TK_NOT

◆ TK_NOTHING

#define TK_NOTHING   149

Definition at line 14091 of file sqlite3.c.

◆ TK_NOTNULL

◆ TK_NULL

◆ TK_NULLS

#define TK_NULLS   82

Definition at line 14024 of file sqlite3.c.

◆ TK_OF

#define TK_OF   68

Definition at line 14010 of file sqlite3.c.

◆ TK_OFFSET

#define TK_OFFSET   69

Definition at line 14011 of file sqlite3.c.

◆ TK_ON

#define TK_ON   113

Definition at line 14055 of file sqlite3.c.

◆ TK_OR

◆ TK_ORDER

#define TK_ORDER   143

Definition at line 14085 of file sqlite3.c.

◆ TK_OTHERS

#define TK_OTHERS   93

Definition at line 14035 of file sqlite3.c.

◆ TK_OVER

#define TK_OVER   162

Definition at line 14104 of file sqlite3.c.

Referenced by analyzeFilterKeyword(), getToken(), and sqlite3RunParser().

◆ TK_PARTITION

#define TK_PARTITION   87

Definition at line 14029 of file sqlite3.c.

◆ TK_PLAN

#define TK_PLAN   4

Definition at line 13946 of file sqlite3.c.

◆ TK_PLUS

#define TK_PLUS   105

Definition at line 14047 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), sqlite3GetToken(), and yy_reduce().

◆ TK_PRAGMA

#define TK_PRAGMA   70

Definition at line 14012 of file sqlite3.c.

◆ TK_PRECEDING

#define TK_PRECEDING   88

Definition at line 14030 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ TK_PRIMARY

#define TK_PRIMARY   120

Definition at line 14062 of file sqlite3.c.

◆ TK_QUERY

#define TK_QUERY   3

Definition at line 13945 of file sqlite3.c.

◆ TK_RAISE

#define TK_RAISE   71

Definition at line 14013 of file sqlite3.c.

Referenced by fkActionTrigger(), sqlite3ExprCodeTarget(), sqlite3ExprCompare(), and yy_reduce().

◆ TK_RANGE

#define TK_RANGE   89

Definition at line 14031 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), sqlite3WindowUpdate(), and windowCodeOp().

◆ TK_RECURSIVE

#define TK_RECURSIVE   72

Definition at line 14014 of file sqlite3.c.

◆ TK_REFERENCES

#define TK_REFERENCES   123

Definition at line 14065 of file sqlite3.c.

◆ TK_REGISTER

◆ TK_REINDEX

#define TK_REINDEX   97

Definition at line 14039 of file sqlite3.c.

◆ TK_RELEASE

#define TK_RELEASE   14

Definition at line 13956 of file sqlite3.c.

◆ TK_REM

#define TK_REM   109

Definition at line 14051 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_RENAME

#define TK_RENAME   98

Definition at line 14040 of file sqlite3.c.

◆ TK_REPLACE

#define TK_REPLACE   73

Definition at line 14015 of file sqlite3.c.

◆ TK_RESTRICT

#define TK_RESTRICT   74

Definition at line 14016 of file sqlite3.c.

◆ TK_ROLLBACK

#define TK_ROLLBACK   12

Definition at line 13954 of file sqlite3.c.

Referenced by sqlite3EndTransaction().

◆ TK_ROW

#define TK_ROW   75

Definition at line 14017 of file sqlite3.c.

Referenced by exprRowColumn(), resolveExprStep(), updateFromSelect(), and updateVirtualTable().

◆ TK_ROWS

#define TK_ROWS   76

Definition at line 14018 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), sqlite3WindowUpdate(), and windowCodeOp().

◆ TK_RP

#define TK_RP   23

Definition at line 13965 of file sqlite3.c.

Referenced by sqlite3GetToken(), and sqlite3RunParser().

◆ TK_RSHIFT

#define TK_RSHIFT   104

Definition at line 14046 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_SAVEPOINT

#define TK_SAVEPOINT   13

Definition at line 13955 of file sqlite3.c.

◆ TK_SELECT

◆ TK_SELECT_COLUMN

◆ TK_SEMI

#define TK_SEMI   1

Definition at line 13943 of file sqlite3.c.

Referenced by sqlite3GetToken(), and sqlite3RunParser().

◆ TK_SET

#define TK_SET   128

Definition at line 14070 of file sqlite3.c.

◆ TK_SLASH

#define TK_SLASH   108

Definition at line 14050 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_SPACE

#define TK_SPACE   179

Definition at line 14121 of file sqlite3.c.

Referenced by getToken(), sqlite3GetToken(), and sqlite3RunParser().

◆ TK_SPAN

◆ TK_STAR

#define TK_STAR   107

Definition at line 14049 of file sqlite3.c.

Referenced by exprImpliesNotNull(), sqlite3ExprCodeTarget(), and sqlite3GetToken().

◆ TK_STRING

◆ TK_TABLE

#define TK_TABLE   16

Definition at line 13958 of file sqlite3.c.

◆ TK_TEMP

#define TK_TEMP   21

Definition at line 13963 of file sqlite3.c.

◆ TK_THEN

#define TK_THEN   156

Definition at line 14098 of file sqlite3.c.

Referenced by test_then_block(), test_then_block(), test_then_block(), and test_then_block().

◆ TK_TIES

#define TK_TIES   94

Definition at line 14036 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowFullScan().

◆ TK_TO

#define TK_TO   15

Definition at line 13957 of file sqlite3.c.

◆ TK_TRANSACTION

#define TK_TRANSACTION   6

Definition at line 13948 of file sqlite3.c.

◆ TK_TRIGGER

#define TK_TRIGGER   77

◆ TK_TRUEFALSE

#define TK_TRUEFALSE   167

◆ TK_TRUTH

◆ TK_UMINUS

◆ TK_UNBOUNDED

◆ TK_UNION

#define TK_UNION   132

◆ TK_UNIQUE

#define TK_UNIQUE   121

Definition at line 14063 of file sqlite3.c.

◆ TK_UPDATE

◆ TK_UPLUS

◆ TK_USING

#define TK_USING   142

Definition at line 14084 of file sqlite3.c.

◆ TK_VACUUM

#define TK_VACUUM   78

Definition at line 14020 of file sqlite3.c.

◆ TK_VALUES

#define TK_VALUES   137

Definition at line 14079 of file sqlite3.c.

◆ TK_VARIABLE

◆ TK_VECTOR

◆ TK_VIEW

#define TK_VIEW   79

Definition at line 14021 of file sqlite3.c.

◆ TK_VIRTUAL

#define TK_VIRTUAL   80

Definition at line 14022 of file sqlite3.c.

◆ TK_WHEN

#define TK_WHEN   155

Definition at line 14097 of file sqlite3.c.

◆ TK_WHERE

#define TK_WHERE   147

Definition at line 14089 of file sqlite3.c.

◆ TK_WINDOW

#define TK_WINDOW   161

Definition at line 14103 of file sqlite3.c.

Referenced by getToken(), and sqlite3RunParser().

◆ TK_WITH

#define TK_WITH   81

Definition at line 14023 of file sqlite3.c.

◆ TK_WITHOUT

#define TK_WITHOUT   25

Definition at line 13967 of file sqlite3.c.

◆ tkCREATE

#define tkCREATE   4

Definition at line 160651 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkEND

#define tkEND   7

Definition at line 160654 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkEXPLAIN

#define tkEXPLAIN   3

Definition at line 160650 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkOTHER

#define tkOTHER   2

Definition at line 160648 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkSEMI

#define tkSEMI   0

Definition at line 160646 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkTEMP

#define tkTEMP   5

Definition at line 160652 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkTRIGGER

#define tkTRIGGER   6

Definition at line 160653 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ tkWS

#define tkWS   1

Definition at line 160647 of file sqlite3.c.

Referenced by sqlite3_complete().

◆ TOKEN

#define TOKEN   yyminor

◆ TRACE

#define TRACE ( X)

◆ TRANS_NONE

◆ TRANS_READ

#define TRANS_READ   1

◆ TRANS_WRITE

◆ TRIGGER_AFTER

#define TRIGGER_AFTER   2

◆ TRIGGER_BEFORE

#define TRIGGER_BEFORE   1

◆ TWO_BYTE_INT

#define TWO_BYTE_INT ( x)    (256*(i8)((x)[0])|(x)[1])

Definition at line 81573 of file sqlite3.c.

Referenced by vdbeRecordCompareInt(), and vdbeRecordDecodeInt().

◆ UINT16_TYPE

#define UINT16_TYPE   unsigned short int

Definition at line 14302 of file sqlite3.c.

◆ UINT32_TYPE

#define UINT32_TYPE   unsigned int

Definition at line 14295 of file sqlite3.c.

◆ UINT8_TYPE

#define UINT8_TYPE   unsigned char

Definition at line 14316 of file sqlite3.c.

◆ UNIX_SHM_BASE

#define UNIX_SHM_BASE   ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */

Definition at line 37831 of file sqlite3.c.

Referenced by sqlite3WalOpen(), and unixShmLock().

◆ UNIX_SHM_DMS

#define UNIX_SHM_DMS   (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */

Definition at line 37832 of file sqlite3.c.

Referenced by unixLockSharedMemory().

◆ UNIXFILE_DELETE

#define UNIXFILE_DELETE   0x20 /* Delete on close */

Definition at line 33636 of file sqlite3.c.

Referenced by closeUnixFile(), and unixOpen().

◆ UNIXFILE_DIRSYNC

#define UNIXFILE_DIRSYNC   0x08 /* Directory sync needed */

Definition at line 33631 of file sqlite3.c.

Referenced by unixOpen(), and unixSync().

◆ UNIXFILE_EXCL

#define UNIXFILE_EXCL   0x01 /* Connections from one process only */

Definition at line 33627 of file sqlite3.c.

Referenced by unixFileLock().

◆ UNIXFILE_NOLOCK

#define UNIXFILE_NOLOCK   0x80 /* Do no file locking */

Definition at line 33638 of file sqlite3.c.

Referenced by unixOpen(), and verifyDbFile().

◆ UNIXFILE_PERSIST_WAL

#define UNIXFILE_PERSIST_WAL   0x04 /* Persistent WAL mode */

Definition at line 33629 of file sqlite3.c.

◆ UNIXFILE_PSOW

#define UNIXFILE_PSOW   0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */

Definition at line 33635 of file sqlite3.c.

Referenced by setDeviceCharacteristics().

◆ UNIXFILE_RDONLY

#define UNIXFILE_RDONLY   0x02 /* Connection is read only */

Definition at line 33628 of file sqlite3.c.

Referenced by unixFileLock(), and unixOpen().

◆ UNIXFILE_URI

#define UNIXFILE_URI   0x40 /* Filename might have query parameters */

Definition at line 33637 of file sqlite3.c.

Referenced by unixOpen().

◆ unixLogError

#define unixLogError ( a,
b,
c )   unixLogErrorAtLine(a,b,c,__LINE__)

◆ UNIXVFS

#define UNIXVFS ( VFSNAME,
FINDER )
Value:
{ \
3, /* iVersion */ \
sizeof(unixFile), /* szOsFile */ \
MAX_PATHNAME, /* mxPathname */ \
0, /* pNext */ \
VFSNAME, /* zName */ \
(void*)&FINDER, /* pAppData */ \
unixOpen, /* xOpen */ \
unixDelete, /* xDelete */ \
unixAccess, /* xAccess */ \
unixFullPathname, /* xFullPathname */ \
unixDlOpen, /* xDlOpen */ \
unixDlError, /* xDlError */ \
unixDlSym, /* xDlSym */ \
unixDlClose, /* xDlClose */ \
unixRandomness, /* xRandomness */ \
unixSleep, /* xSleep */ \
unixCurrentTime, /* xCurrentTime */ \
unixGetLastError, /* xGetLastError */ \
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
unixSetSystemCall, /* xSetSystemCall */ \
unixGetSystemCall, /* xGetSystemCall */ \
unixNextSystemCall, /* xNextSystemCall */ \
}
static sqlite3_syscall_ptr unixGetSystemCall(sqlite3_vfs *pNotUsed, const char *zName)
Definition sqlite3.c:34156
static void(*)(void) unixDlSym(sqlite3_vfs *NotUsed, void *p, const char *zSym)
Definition sqlite3.c:39994
static int unixFullPathname(sqlite3_vfs *pVfs, const char *zPath, int nOut, char *zOut)
Definition sqlite3.c:39880
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow)
Definition sqlite3.c:40150
static int unixAccess(sqlite3_vfs *NotUsed, const char *zPath, int flags, int *pResOut)
Definition sqlite3.c:39820
static void * unixDlOpen(sqlite3_vfs *NotUsed, const char *zFilename)
Definition sqlite3.c:39972
static int unixDelete(sqlite3_vfs *NotUsed, const char *zPath, int dirSync)
Definition sqlite3.c:39772
static int unixOpen(sqlite3_vfs *pVfs, const char *zPath, sqlite3_file *pFile, int flags, int *pOutFlags)
Definition sqlite3.c:39498
static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf)
Definition sqlite3.c:40031
static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow)
Definition sqlite3.c:40118
static const char * unixNextSystemCall(sqlite3_vfs *p, const char *zName)
Definition sqlite3.c:34175
#define MAX_PATHNAME
Definition sqlite3.c:33522
static void unixDlError(sqlite3_vfs *NotUsed, int nBuf, char *zBufOut)
Definition sqlite3.c:39984
static int unixSleep(sqlite3_vfs *NotUsed, int microseconds)
Definition sqlite3.c:40078
static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3)
Definition sqlite3.c:40168
static void unixDlClose(sqlite3_vfs *NotUsed, void *pHandle)
Definition sqlite3.c:40017
static int unixSetSystemCall(sqlite3_vfs *pNotUsed, const char *zName, sqlite3_syscall_ptr pNewFunc)
Definition sqlite3.c:34113

◆ UNKNOWN_LOCK

#define UNKNOWN_LOCK   (EXCLUSIVE_LOCK+1)

Definition at line 52109 of file sqlite3.c.

Referenced by pager_unlock(), pagerLockDb(), pagerUnlockDb(), and sqlite3PagerSharedLock().

◆ unlikely

#define unlikely ( X)    (X)

Definition at line 13838 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions(), and sqlite3VdbeIdxRowid().

◆ UNUSED_PARAMETER

◆ UNUSED_PARAMETER2

◆ UPDATE_MAX_BLOBSIZE

#define UPDATE_MAX_BLOBSIZE ( P)

Definition at line 85349 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ UpperToLower

#define UpperToLower   sqlite3UpperToLower

Definition at line 31448 of file sqlite3.c.

◆ USEFETCH

#define USEFETCH ( x)    0

◆ Utf8Read

#define Utf8Read ( A)    (A[0]<0x80?*(A++):sqlite3Utf8Read(&A))

Definition at line 117668 of file sqlite3.c.

Referenced by patternCompare().

◆ valueFromFunction

#define valueFromFunction ( a,
b,
c,
d,
e,
f )   SQLITE_OK

Definition at line 77290 of file sqlite3.c.

Referenced by valueFromExpr().

◆ VDBE_DISPLAY_P4

#define VDBE_DISPLAY_P4   1

Definition at line 20740 of file sqlite3.c.

◆ VDBE_MAGIC_DEAD

#define VDBE_MAGIC_DEAD   0x5606c3c8 /* The VDBE has been deallocated */

Definition at line 21163 of file sqlite3.c.

◆ VDBE_MAGIC_HALT

#define VDBE_MAGIC_HALT   0x319c2973 /* VDBE has completed execution */

Definition at line 21161 of file sqlite3.c.

Referenced by sqlite3VdbeHalt().

◆ VDBE_MAGIC_INIT

#define VDBE_MAGIC_INIT   0x16bceaa5 /* Building a VDBE program */

◆ VDBE_MAGIC_RESET

#define VDBE_MAGIC_RESET   0x48fa9f76 /* Reset and ready to run again */

Definition at line 21162 of file sqlite3.c.

Referenced by sqlite3VdbeReset().

◆ VDBE_MAGIC_RUN

#define VDBE_MAGIC_RUN   0x2df20da3 /* VDBE is ready to execute */

◆ VDBE_OFFSET_LINENO

#define VDBE_OFFSET_LINENO ( x)    0

Definition at line 16001 of file sqlite3.c.

Referenced by autoIncrementEnd(), and sqlite3Pragma().

◆ vdbeAssertFieldCountWithinLimits

#define vdbeAssertFieldCountWithinLimits ( A,
B,
C )

Definition at line 81934 of file sqlite3.c.

Referenced by vdbeRecordCompareInt(), and vdbeRecordCompareString().

◆ VdbeBranchTaken

#define VdbeBranchTaken ( I,
M )

Definition at line 85410 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ VdbeComment

◆ VdbeCoverage

◆ VdbeCoverageAlwaysTaken

#define VdbeCoverageAlwaysTaken ( v)

Definition at line 15996 of file sqlite3.c.

◆ VdbeCoverageEqNe

#define VdbeCoverageEqNe ( v)

Definition at line 16000 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), windowFullScan(), and windowIfNewPeer().

◆ VdbeCoverageIf

◆ VdbeCoverageNeverNull

#define VdbeCoverageNeverNull ( v)

Definition at line 15998 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), windowFullScan(), and windowReturnOneRow().

◆ VdbeCoverageNeverNullIf

#define VdbeCoverageNeverNullIf ( v,
x )

Definition at line 15999 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowCheckValue().

◆ VdbeCoverageNeverTaken

#define VdbeCoverageNeverTaken ( v)

◆ VdbeFrameMem

#define VdbeFrameMem ( p)    ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])

Definition at line 20897 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3VdbeFrameDelete().

◆ vdbeInvokeSqllog

#define vdbeInvokeSqllog ( x)

Definition at line 81003 of file sqlite3.c.

Referenced by sqlite3VdbeReset().

◆ VdbeMemDynamic

#define VdbeMemDynamic ( X)     (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)

◆ VdbeModuleComment

◆ VdbeNoopComment

#define VdbeNoopComment ( X)

◆ vdbeSorterBlockDebug

#define vdbeSorterBlockDebug ( x,
y,
z )

Definition at line 94979 of file sqlite3.c.

Referenced by vdbeSorterJoinThread().

◆ vdbeSorterExtendFile

#define vdbeSorterExtendFile ( x,
y,
z )

Definition at line 95170 of file sqlite3.c.

Referenced by vdbeSorterListToPMA(), and vdbeSorterOpenTempFile().

◆ vdbeSorterPopulateDebug

#define vdbeSorterPopulateDebug ( x,
y )

Definition at line 94978 of file sqlite3.c.

Referenced by vdbeIncrPopulate().

◆ vdbeSorterRewindDebug

#define vdbeSorterRewindDebug ( y)

Definition at line 94977 of file sqlite3.c.

Referenced by sqlite3VdbeSorterRewind().

◆ vdbeSorterWorkDebug

#define vdbeSorterWorkDebug ( x,
y )

Definition at line 94976 of file sqlite3.c.

Referenced by vdbeSorterListToPMA().

◆ vfsList

#define vfsList   GLOBAL(sqlite3_vfs *, vfsList)

Definition at line 23301 of file sqlite3.c.

Referenced by sqlite3_vfs_find(), and sqlite3_vfs_register().

◆ VFUNCTION

#define VFUNCTION ( zName,
nArg,
iArg,
bNC,
xFunc )
Value:
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }

Definition at line 17242 of file sqlite3.c.

17242#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
17243 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
17244 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ VisibleRowid

#define VisibleRowid ( X)    (((X)->tabFlags & TF_NoVisibleRowid)==0)

Definition at line 17584 of file sqlite3.c.

Referenced by lookupName().

◆ VVA_ONLY

◆ WAGGREGATE

#define WAGGREGATE ( zName,
nArg,
arg,
nc,
xStep,
xFinal,
xValue,
xInverse,
f )
Value:
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}

Definition at line 17270 of file sqlite3.c.

17270#define LIKEFUNC(zName, nArg, arg, flags) \
17271 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
17272 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ WAL_ALL_BUT_WRITE

#define WAL_ALL_BUT_WRITE   1

Definition at line 59689 of file sqlite3.c.

Referenced by walIndexRecover().

◆ WAL_CKPT_LOCK

#define WAL_CKPT_LOCK   1

◆ WAL_EXCLUSIVE_MODE

#define WAL_EXCLUSIVE_MODE   1

Definition at line 59876 of file sqlite3.c.

Referenced by sqlite3WalExclusiveMode().

◆ WAL_FRAME_HDRSIZE

#define WAL_FRAME_HDRSIZE   24

◆ WAL_HDRSIZE

#define WAL_HDRSIZE   32

Definition at line 59810 of file sqlite3.c.

Referenced by walBeginShmUnreliable(), and walIndexRecover().

◆ WAL_HEAPMEMORY_MODE

#define WAL_HEAPMEMORY_MODE   2

◆ WAL_MAGIC

#define WAL_MAGIC   0x377f0682

Definition at line 59821 of file sqlite3.c.

Referenced by walIndexRecover().

◆ WAL_MAX_VERSION

#define WAL_MAX_VERSION   3007000

Definition at line 59671 of file sqlite3.c.

Referenced by walIndexRecover().

◆ WAL_NORMAL_MODE

#define WAL_NORMAL_MODE   0

Definition at line 59875 of file sqlite3.c.

Referenced by sqlite3WalExclusiveMode(), sqlite3WalOpen(), and walIndexReadHdr().

◆ WAL_NREADER

#define WAL_NREADER   (SQLITE_SHM_NLOCK-3)

◆ WAL_RDONLY

#define WAL_RDONLY   1 /* The WAL file is readonly */

Definition at line 59883 of file sqlite3.c.

Referenced by sqlite3WalOpen().

◆ WAL_RDWR

#define WAL_RDWR   0 /* Normal read/write connection */

Definition at line 59882 of file sqlite3.c.

◆ WAL_READ_LOCK

#define WAL_READ_LOCK ( I)    (3+(I))

◆ WAL_RECOVER_LOCK

#define WAL_RECOVER_LOCK   2

Definition at line 59691 of file sqlite3.c.

Referenced by walTryBeginRead().

◆ WAL_RETRY

#define WAL_RETRY   (-1)

◆ WAL_SAVEPOINT_NDATA

#define WAL_SAVEPOINT_NDATA   4

Definition at line 51617 of file sqlite3.c.

◆ WAL_SHM_RDONLY

#define WAL_SHM_RDONLY   2 /* The SHM file is readonly */

◆ WAL_SYNC_FLAGS

#define WAL_SYNC_FLAGS ( X)    ((X)&0x03)

Definition at line 51592 of file sqlite3.c.

Referenced by walWriteToLog().

◆ WAL_WRITE_LOCK

#define WAL_WRITE_LOCK   0

◆ walDisableBlocking

#define walDisableBlocking ( x)

Definition at line 61226 of file sqlite3.c.

Referenced by sqlite3WalBeginReadTransaction(), sqlite3WalCheckpoint(), and walBusyLock().

◆ walEnableBlocking

#define walEnableBlocking ( x)    0

Definition at line 61225 of file sqlite3.c.

Referenced by sqlite3WalBeginReadTransaction(), and sqlite3WalCheckpoint().

◆ walFrameOffset

#define walFrameOffset ( iFrame,
szPage )
Value:
( \
WAL_HDRSIZE + ((iFrame)-1)*(i64)((szPage)+WAL_FRAME_HDRSIZE) \
)
sqlite_int64 i64
Definition sqlite3.c:14329
#define WAL_HDRSIZE
Definition sqlite3.c:59810
#define WAL_FRAME_HDRSIZE
Definition sqlite3.c:59807

Definition at line 59828 of file sqlite3.c.

59828
59829/*
59830** Return the offset of frame iFrame in the write-ahead log file,

Referenced by sqlite3WalReadFrame(), walBeginShmUnreliable(), walCheckpoint(), walIndexRecover(), and walRewriteChecksums().

◆ WALINDEX_HDR_SIZE

#define WALINDEX_HDR_SIZE   (sizeof(WalIndexHdr)*2+sizeof(WalCkptInfo))

Definition at line 59804 of file sqlite3.c.

Referenced by sqlite3WalOpen(), walHashGet(), and walIndexRecover().

◆ WALINDEX_LOCK_OFFSET

#define WALINDEX_LOCK_OFFSET   (sizeof(WalIndexHdr)*2+offsetof(WalCkptInfo,aLock))

Definition at line 59803 of file sqlite3.c.

Referenced by sqlite3WalOpen().

◆ WALINDEX_MAX_VERSION

#define WALINDEX_MAX_VERSION   3007000

Definition at line 59672 of file sqlite3.c.

Referenced by walIndexReadHdr(), and walIndexWriteHdr().

◆ WALINDEX_PGSZ

#define WALINDEX_PGSZ
Value:
( \
)
#define HASHTABLE_NPAGE
Definition sqlite3.c:59927
u16 ht_slot
Definition sqlite3.c:59890
#define HASHTABLE_NSLOT
Definition sqlite3.c:59929

Definition at line 59939 of file sqlite3.c.

59939** wal-index is smaller than usual. This is so that there is a complete
59940** hash-table on each aligned 32KB page of the wal-index.
59941*/
guint index
#define KB(i)

Referenced by walBeginShmUnreliable(), walIndexPageRealloc(), and walIndexRecover().

◆ walLockWriter

#define walLockWriter ( pWal)    walLockExclusive((pWal), WAL_WRITE_LOCK, 1)

Definition at line 61227 of file sqlite3.c.

Referenced by walIndexReadHdr().

◆ WALTRACE

#define WALTRACE ( X)

◆ WHERE_AUTO_INDEX

#define WHERE_AUTO_INDEX   0x00004000 /* Uses an ephemeral index */

◆ WHERE_BIGNULL_SORT

#define WHERE_BIGNULL_SORT   0x00080000 /* Column nEq of index is BIGNULL */

Definition at line 141532 of file sqlite3.c.

Referenced by sqlite3WhereBegin(), and wherePathSatisfiesOrderBy().

◆ WHERE_BOTH_LIMIT

#define WHERE_BOTH_LIMIT   0x00000030 /* Both x>EXPR and x<EXPR */

Definition at line 141519 of file sqlite3.c.

Referenced by sqlite3WhereExplainOneScan().

◆ WHERE_BTM_LIMIT

#define WHERE_BTM_LIMIT   0x00000020 /* x>EXPR or x>=EXPR constraint */

◆ WHERE_COLUMN_EQ

#define WHERE_COLUMN_EQ   0x00000001 /* x=EXPR */

◆ WHERE_COLUMN_IN

#define WHERE_COLUMN_IN   0x00000004 /* x IN (...) */

◆ WHERE_COLUMN_NULL

#define WHERE_COLUMN_NULL   0x00000008 /* x IS NULL */

Definition at line 141515 of file sqlite3.c.

Referenced by whereLoopAddBtreeIndex().

◆ WHERE_COLUMN_RANGE

#define WHERE_COLUMN_RANGE   0x00000002 /* x<EXPR and/or x>EXPR */

Definition at line 141513 of file sqlite3.c.

Referenced by sqlite3WhereBegin(), and whereLoopAddBtreeIndex().

◆ WHERE_CONSTRAINT

#define WHERE_CONSTRAINT   0x0000000f /* Any of the WHERE_COLUMN_xxx values */

Definition at line 141516 of file sqlite3.c.

Referenced by sqlite3WhereBegin(), and sqlite3WhereExplainOneScan().

◆ WHERE_DISTINCT_NOOP

#define WHERE_DISTINCT_NOOP   0 /* DISTINCT keyword not used */

Definition at line 18323 of file sqlite3.c.

Referenced by selectInnerLoop(), sqlite3Select(), and wherePathSolver().

◆ WHERE_DISTINCT_ORDERED

#define WHERE_DISTINCT_ORDERED   2 /* All duplicates are adjacent */

Definition at line 18325 of file sqlite3.c.

Referenced by selectInnerLoop(), sqlite3WhereBegin(), sqlite3WhereEnd(), and wherePathSolver().

◆ WHERE_DISTINCT_UNIQUE

#define WHERE_DISTINCT_UNIQUE   1 /* No duplicates */

Definition at line 18324 of file sqlite3.c.

Referenced by selectInnerLoop(), sqlite3WhereBegin(), and whereShortCut().

◆ WHERE_DISTINCT_UNORDERED

#define WHERE_DISTINCT_UNORDERED   3 /* Duplicates are scattered */

Definition at line 18326 of file sqlite3.c.

Referenced by selectInnerLoop(), sqlite3Select(), and sqlite3WhereBegin().

◆ WHERE_DISTINCTBY

#define WHERE_DISTINCTBY   0x0080 /* pOrderby is really a DISTINCT clause */

Definition at line 18311 of file sqlite3.c.

Referenced by sqlite3WhereBegin(), wherePathSatisfiesOrderBy(), and wherePathSolver().

◆ WHERE_DUPLICATES_OK

#define WHERE_DUPLICATES_OK   0x0010 /* Ok to return a row more than once */

Definition at line 18308 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), and sqlite3WhereBegin().

◆ WHERE_GROUPBY

#define WHERE_GROUPBY   0x0040 /* pOrderBy is really a GROUP BY */

Definition at line 18310 of file sqlite3.c.

Referenced by sqlite3Select(), sqlite3WhereIsSorted(), and wherePathSatisfiesOrderBy().

◆ WHERE_IDX_ONLY

#define WHERE_IDX_ONLY   0x00000040 /* Use index only - omit table */

◆ WHERE_IN_ABLE

#define WHERE_IN_ABLE   0x00000800 /* Able to support an IN operator */

Definition at line 141524 of file sqlite3.c.

Referenced by codeEqualityTerm(), and sqlite3WhereEnd().

◆ WHERE_IN_EARLYOUT

#define WHERE_IN_EARLYOUT   0x00040000 /* Perhaps quit IN loops early */

Definition at line 141531 of file sqlite3.c.

Referenced by codeEqualityTerm(), and sqlite3WhereEnd().

◆ WHERE_INDEXED

◆ WHERE_IPK

#define WHERE_IPK   0x00000100 /* x is the INTEGER PRIMARY KEY */

◆ WHERE_LOOP_XFER_SZ

#define WHERE_LOOP_XFER_SZ   offsetof(WhereLoop,nLSlot)

Definition at line 141062 of file sqlite3.c.

◆ WHERE_MULTI_OR

#define WHERE_MULTI_OR   0x00002000 /* OR using multiple indices */

◆ WHERE_ONEPASS_DESIRED

#define WHERE_ONEPASS_DESIRED   0x0004 /* Want to do one-pass UPDATE/DELETE */

◆ WHERE_ONEPASS_MULTIROW

#define WHERE_ONEPASS_MULTIROW   0x0008 /* ONEPASS is ok with multiple rows */

Definition at line 18307 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), sqlite3Update(), and sqlite3WhereBegin().

◆ WHERE_ONEROW

#define WHERE_ONEROW   0x00001000 /* Selects no more than one row */

◆ WHERE_OR_SUBCLAUSE

#define WHERE_OR_SUBCLAUSE
Value:
0x0020 /* Processing a sub-WHERE as part of
** the OR optimization */

Definition at line 18309 of file sqlite3.c.

Referenced by codeDeferredSeek(), sqlite3WhereBegin(), sqlite3WhereEnd(), sqlite3WhereExplainOneScan(), whereLoopAddBtree(), and whereShortCut().

◆ WHERE_ORDERBY_LIMIT

#define WHERE_ORDERBY_LIMIT   0x0800 /* ORDERBY+LIMIT on the inner loop */

Definition at line 18315 of file sqlite3.c.

Referenced by wherePathSatisfiesOrderBy(), and wherePathSolver().

◆ WHERE_ORDERBY_MAX

#define WHERE_ORDERBY_MAX   0x0002 /* ORDER BY processing for max() func */

◆ WHERE_ORDERBY_MIN

#define WHERE_ORDERBY_MIN   0x0001 /* ORDER BY processing for min() func */

◆ WHERE_ORDERBY_NORMAL

#define WHERE_ORDERBY_NORMAL   0x0000 /* No-op */

Definition at line 18303 of file sqlite3.c.

Referenced by minMaxQuery(), and sqlite3Select().

◆ WHERE_PARTIALIDX

#define WHERE_PARTIALIDX   0x00020000 /* The automatic index is partial */

Definition at line 141530 of file sqlite3.c.

Referenced by constructAutomaticIndex(), and sqlite3WhereExplainOneScan().

◆ WHERE_SEEK_TABLE

#define WHERE_SEEK_TABLE   0x0400 /* Do not defer seeks on main table */

Definition at line 18314 of file sqlite3.c.

Referenced by sqlite3DeleteFrom().

◆ WHERE_SEEK_UNIQ_TABLE

#define WHERE_SEEK_UNIQ_TABLE   0x1000 /* Do not defer seeks if unique */

Definition at line 18316 of file sqlite3.c.

Referenced by sqlite3Update().

◆ WHERE_SKIPSCAN

#define WHERE_SKIPSCAN   0x00008000 /* Uses the skip-scan algorithm */

◆ WHERE_SORTBYGROUP

#define WHERE_SORTBYGROUP   0x0200 /* Support sqlite3WhereIsSorted() */

Definition at line 18313 of file sqlite3.c.

Referenced by sqlite3Select(), sqlite3WhereIsSorted(), and wherePathSolver().

◆ WHERE_TOP_LIMIT

#define WHERE_TOP_LIMIT   0x00000010 /* x<EXPR or x<=EXPR constraint */

◆ WHERE_UNQ_WANTED

#define WHERE_UNQ_WANTED   0x00010000 /* WHERE_ONEROW would have been helpful*/

Definition at line 141529 of file sqlite3.c.

Referenced by whereLoopAddBtreeIndex().

◆ WHERE_USE_LIMIT

#define WHERE_USE_LIMIT   0x4000 /* Use the LIMIT in cost estimates */

Definition at line 18318 of file sqlite3.c.

Referenced by sqlite3Select(), sqlite3WhereBegin(), and whereSortingCost().

◆ WHERE_VIRTUALTABLE

◆ WHERE_WANT_DISTINCT

#define WHERE_WANT_DISTINCT   0x0100 /* All output needs to be distinct */

Definition at line 18312 of file sqlite3.c.

Referenced by sqlite3Select(), sqlite3WhereBegin(), wherePathSolver(), and whereShortCut().

◆ WHERETRACE

◆ WHERETRACE_ALL_LOOPS

#define WHERETRACE_ALL_LOOPS ( W,
C )

Definition at line 150204 of file sqlite3.c.

Referenced by sqlite3WhereBegin().

◆ whereTraceIndexInfoInputs

#define whereTraceIndexInfoInputs ( A)

Definition at line 146259 of file sqlite3.c.

Referenced by vtabBestIndex().

◆ whereTraceIndexInfoOutputs

#define whereTraceIndexInfoOutputs ( A)

Definition at line 146260 of file sqlite3.c.

Referenced by vtabBestIndex().

◆ WINDOW_AGGINVERSE

#define WINDOW_AGGINVERSE   2

Definition at line 152873 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ WINDOW_AGGSTEP

#define WINDOW_AGGSTEP   3

Definition at line 152874 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ WINDOW_ENDING_INT

#define WINDOW_ENDING_INT   1

Definition at line 152584 of file sqlite3.c.

◆ WINDOW_ENDING_NUM

#define WINDOW_ENDING_NUM   4

Definition at line 152587 of file sqlite3.c.

◆ WINDOW_NTH_VALUE_INT

#define WINDOW_NTH_VALUE_INT   2

Definition at line 152585 of file sqlite3.c.

◆ WINDOW_RETURN_ROW

#define WINDOW_RETURN_ROW   1

Definition at line 152872 of file sqlite3.c.

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ WINDOW_STARTING_INT

#define WINDOW_STARTING_INT   0

Definition at line 152583 of file sqlite3.c.

◆ WINDOW_STARTING_NUM

#define WINDOW_STARTING_NUM   3

Definition at line 152586 of file sqlite3.c.

Referenced by windowCheckValue().

◆ WINDOWFUNCALL

#define WINDOWFUNCALL ( name,
nArg,
extra )
Value:
{ \
nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
name ## InvFunc, name ## Name, {0} \
}
const char * name
Definition lsqlite3.c:2154
#define SQLITE_FUNC_WINDOW
Definition sqlite3.c:17160

Definition at line 151742 of file sqlite3.c.

151742 assert(0); /*NO_TEST*/
151743} /*NO_TEST*/
151744static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ }
151745
151746/* Window functions that use all window interfaces: xStep, xFinal,
static void noopValueFunc(sqlite3_context *p)
Definition sqlite3.c:151738

Referenced by sqlite3WindowFunctions().

◆ WINDOWFUNCNOOP

#define WINDOWFUNCNOOP ( name,
nArg,
extra )
Value:
{ \
nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
noopStepFunc, name ## Name, {0} \
}
static void noopStepFunc(sqlite3_context *p, int n, sqlite3_value **a)
Definition sqlite3.c:151728

Definition at line 151750 of file sqlite3.c.

151750 name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
151751 name ## InvFunc, name ## Name, {0} \
151752}
151753
151754/* Window functions that are implemented using bytecode and thus have

Referenced by sqlite3WindowFunctions().

◆ WINDOWFUNCX

#define WINDOWFUNCX ( name,
nArg,
extra )
Value:
{ \
nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \
noopStepFunc, name ## Name, {0} \
}

Definition at line 151759 of file sqlite3.c.

151759 noopStepFunc, name ## Name, {0} \
151760}
151761
151762/* Window functions that use all window interfaces: xStep, the
151763** same routine for xFinalize and xValue and which never call

Referenced by sqlite3WindowFunctions().

◆ WO_ALL

#define WO_ALL   0x1fff /* Mask of all possible WO_* values */

Definition at line 141504 of file sqlite3.c.

Referenced by allocateIndexInfo(), and exprAnalyze().

◆ WO_AND

#define WO_AND   0x0400 /* Two or more AND-connected terms */

Definition at line 141500 of file sqlite3.c.

Referenced by exprAnalyzeOrTerm(), whereLoopAddOr(), and whereNthSubterm().

◆ WO_AUX

#define WO_AUX   0x0040 /* Op useful to virtual tables only */

Definition at line 141496 of file sqlite3.c.

Referenced by allocateIndexInfo(), exprAnalyze(), and exprAnalyzeOrTerm().

◆ WO_EQ

◆ WO_EQUIV

#define WO_EQUIV   0x0800 /* Of the form A==B, both columns */

Definition at line 141501 of file sqlite3.c.

Referenced by allocateIndexInfo(), exprAnalyze(), and whereScanNext().

◆ WO_GE

#define WO_GE   (WO_EQ<<(TK_GE-TK_EQ))

◆ WO_GT

#define WO_GT   (WO_EQ<<(TK_GT-TK_EQ))

◆ WO_IN

◆ WO_IS

◆ WO_ISNULL

#define WO_ISNULL   0x0100

◆ WO_LE

#define WO_LE   (WO_EQ<<(TK_LE-TK_EQ))

◆ WO_LT

#define WO_LT   (WO_EQ<<(TK_LT-TK_EQ))

◆ WO_NOOP

#define WO_NOOP   0x1000 /* This term does not restrict search space */

Definition at line 141502 of file sqlite3.c.

◆ WO_OR

#define WO_OR   0x0200 /* Two or more OR-connected terms */

Definition at line 141499 of file sqlite3.c.

Referenced by exprAnalyzeOrTerm(), and whereLoopAddOr().

◆ WO_SINGLE

#define WO_SINGLE   0x01ff /* Mask of all non-compound WO_* values */

Definition at line 141505 of file sqlite3.c.

Referenced by exprAnalyzeOrTerm().

◆ WRC_Abort

◆ WRC_Continue

◆ WRC_Prune

◆ WRITE_LOCK

#define WRITE_LOCK   2

◆ WRITE_UTF16BE

#define WRITE_UTF16BE ( zOut,
c )
Value:
{ \
if( c<=0xFFFF ){ \
*zOut++ = (u8)((c>>8)&0x00FF); \
*zOut++ = (u8)(c&0x00FF); \
}else{ \
*zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
*zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
*zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
*zOut++ = (u8)(c&0x00FF); \
} \
}

Definition at line 30738 of file sqlite3.c.

30738 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
30739 *zOut++ = (u8)(c&0x00FF); \
30740 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
30741 } \
30742}
30743
30744#define WRITE_UTF16BE(zOut, c) { \
30745 if( c<=0xFFFF ){ \
30746 *zOut++ = (u8)((c>>8)&0x00FF); \
30747 *zOut++ = (u8)(c&0x00FF); \
30748 }else{ \

Referenced by sqlite3VdbeMemTranslate().

◆ WRITE_UTF16LE

#define WRITE_UTF16LE ( zOut,
c )
Value:
{ \
if( c<=0xFFFF ){ \
*zOut++ = (u8)(c&0x00FF); \
*zOut++ = (u8)((c>>8)&0x00FF); \
}else{ \
*zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
*zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
*zOut++ = (u8)(c&0x00FF); \
*zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
} \
}

Definition at line 30726 of file sqlite3.c.

30726 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
30727 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
30728 *zOut++ = 0x80 + (u8)(c & 0x3F); \
30729 } \
30730}
30731
30732#define WRITE_UTF16LE(zOut, c) { \
30733 if( c<=0xFFFF ){ \
30734 *zOut++ = (u8)(c&0x00FF); \
30735 *zOut++ = (u8)((c>>8)&0x00FF); \
30736 }else{ \

Referenced by sqlite3VdbeMemTranslate().

◆ WRITE_UTF8

#define WRITE_UTF8 ( zOut,
c )
Value:
{ \
if( c<0x00080 ){ \
*zOut++ = (u8)(c&0xFF); \
} \
else if( c<0x00800 ){ \
*zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
*zOut++ = 0x80 + (u8)(c & 0x3F); \
} \
else if( c<0x10000 ){ \
*zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
*zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
*zOut++ = 0x80 + (u8)(c & 0x3F); \
}else{ \
*zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
*zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
*zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
*zOut++ = 0x80 + (u8)(c & 0x3F); \
} \
}

Definition at line 30706 of file sqlite3.c.

30706 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
30707 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
30708 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
30709};
30710
30711
30712#define WRITE_UTF8(zOut, c) { \
30713 if( c<0x00080 ){ \
30714 *zOut++ = (u8)(c&0xFF); \
30715 } \
30716 else if( c<0x00800 ){ \
30717 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
30718 *zOut++ = 0x80 + (u8)(c & 0x3F); \
30719 } \
30720 else if( c<0x10000 ){ \
30721 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
30722 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
30723 *zOut++ = 0x80 + (u8)(c & 0x3F); \
30724 }else{ \

Referenced by sqlite3VdbeMemTranslate().

◆ wsdAutoext

#define wsdAutoext   sqlite3Autoext

◆ wsdAutoextInit

#define wsdAutoextInit

◆ wsdHooks

#define wsdHooks   sqlite3Hooks

Definition at line 23447 of file sqlite3.c.

Referenced by sqlite3BenignMallocHooks(), and sqlite3EndBenignMalloc().

◆ wsdHooksInit

#define wsdHooksInit

Definition at line 23446 of file sqlite3.c.

Referenced by sqlite3BenignMallocHooks().

◆ wsdPrng

#define wsdPrng   sqlite3Prng

◆ wsdStat

#define wsdStat   sqlite3Stat

◆ wsdStatInit

#define wsdStatInit

Definition at line 21374 of file sqlite3.c.

Referenced by sqlite3StatusHighwater(), sqlite3StatusUp(), and sqlite3StatusValue().

◆ XN_EXPR

◆ XN_ROWID

◆ YY_ACCEPT_ACTION

#define YY_ACCEPT_ACTION   1189

Definition at line 154522 of file sqlite3.c.

Referenced by sqlite3Parser().

◆ YY_ACTTAB_COUNT

#define YY_ACTTAB_COUNT   (1962)

Definition at line 154592 of file sqlite3.c.

Referenced by yy_find_shift_action().

◆ YY_ERROR_ACTION

#define YY_ERROR_ACTION   1188

Definition at line 154521 of file sqlite3.c.

Referenced by sqlite3Parser(), and yy_reduce().

◆ YY_MAX_REDUCE

#define YY_MAX_REDUCE   1575

Definition at line 154525 of file sqlite3.c.

◆ YY_MAX_SHIFT

#define YY_MAX_SHIFT   552

Definition at line 154518 of file sqlite3.c.

Referenced by yy_find_shift_action(), yy_reduce(), and yy_shift().

◆ YY_MAX_SHIFTREDUCE

#define YY_MAX_SHIFTREDUCE   1187

Definition at line 154520 of file sqlite3.c.

Referenced by sqlite3Parser(), and yy_reduce().

◆ YY_MIN_REDUCE

#define YY_MIN_REDUCE   1191

Definition at line 154524 of file sqlite3.c.

Referenced by sqlite3Parser(), and yy_shift().

◆ YY_MIN_SHIFTREDUCE

#define YY_MIN_SHIFTREDUCE   803

Definition at line 154519 of file sqlite3.c.

Referenced by yy_shift().

◆ YY_NLOOKAHEAD

#define YY_NLOOKAHEAD   ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))

Definition at line 154527 of file sqlite3.c.

Referenced by yy_find_shift_action().

◆ YY_NO_ACTION

#define YY_NO_ACTION   1190

Definition at line 154523 of file sqlite3.c.

◆ YY_REDUCE_COUNT

#define YY_REDUCE_COUNT   (391)

Definition at line 155070 of file sqlite3.c.

◆ YY_REDUCE_MAX

#define YY_REDUCE_MAX   (1625)

Definition at line 155072 of file sqlite3.c.

◆ YY_REDUCE_MIN

#define YY_REDUCE_MIN   (-262)

Definition at line 155071 of file sqlite3.c.

◆ YY_SHIFT_COUNT

#define YY_SHIFT_COUNT   (552)

Definition at line 155009 of file sqlite3.c.

Referenced by yy_find_shift_action().

◆ YY_SHIFT_MAX

#define YY_SHIFT_MAX   (1951)

Definition at line 155011 of file sqlite3.c.

◆ YY_SHIFT_MIN

#define YY_SHIFT_MIN   (0)

Definition at line 155010 of file sqlite3.c.

◆ YYACTIONTYPE

#define YYACTIONTYPE   unsigned short int

Definition at line 154478 of file sqlite3.c.

Referenced by sqlite3Parser(), and yy_reduce().

◆ YYCODETYPE

#define YYCODETYPE   unsigned short int

Definition at line 154476 of file sqlite3.c.

Referenced by sqlite3Parser(), yy_find_shift_action(), and yy_reduce().

◆ YYFALLBACK

#define YYFALLBACK   1

Definition at line 154513 of file sqlite3.c.

◆ YYMALLOCARGTYPE

#define YYMALLOCARGTYPE   u64

Definition at line 154269 of file sqlite3.c.

◆ YYNOCODE

#define YYNOCODE   310

Definition at line 154477 of file sqlite3.c.

Referenced by sqlite3Parser(), yy_find_shift_action(), and yy_reduce().

◆ YYNOERRORRECOVERY

#define YYNOERRORRECOVERY   1

Definition at line 154239 of file sqlite3.c.

◆ YYNRULE

#define YYNRULE   385

Definition at line 154515 of file sqlite3.c.

◆ YYNRULE_WITH_ACTION

#define YYNRULE_WITH_ACTION   325

Definition at line 154516 of file sqlite3.c.

Referenced by yy_reduce().

◆ YYNSTATE

#define YYNSTATE   553

Definition at line 154514 of file sqlite3.c.

◆ YYNTOKEN

#define YYNTOKEN   181

Definition at line 154517 of file sqlite3.c.

Referenced by yy_find_shift_action().

◆ YYPARSEFREENEVERNULL

#define YYPARSEFREENEVERNULL   1

Definition at line 154250 of file sqlite3.c.

◆ YYSTACKDEPTH

#define YYSTACKDEPTH   100

Definition at line 154501 of file sqlite3.c.

Referenced by sqlite3ParserInit().

◆ yytestcase

#define yytestcase ( X)    testcase(X)

Definition at line 154244 of file sqlite3.c.

Referenced by yy_reduce().

◆ yyTraceShift

#define yyTraceShift ( X,
Y,
Z )

Definition at line 156620 of file sqlite3.c.

Referenced by yy_reduce().

◆ YYWILDCARD

#define YYWILDCARD   100

Definition at line 154479 of file sqlite3.c.

Referenced by yy_find_shift_action().

Typedef Documentation

◆ AggInfo

typedef struct AggInfo AggInfo

Definition at line 14659 of file sqlite3.c.

◆ analysisInfo

typedef struct analysisInfo analysisInfo

Definition at line 109007 of file sqlite3.c.

◆ AuthContext

typedef struct AuthContext AuthContext

Definition at line 14660 of file sqlite3.c.

◆ AutoincInfo

typedef struct AutoincInfo AutoincInfo

Definition at line 14661 of file sqlite3.c.

◆ AuxData

typedef struct AuxData AuxData

Definition at line 20761 of file sqlite3.c.

◆ BenignMallocHooks

typedef struct BenignMallocHooks BenignMallocHooks

Definition at line 23429 of file sqlite3.c.

◆ bft

typedef unsigned bft

Definition at line 21048 of file sqlite3.c.

◆ Bitmask

typedef u64 Bitmask

Definition at line 14720 of file sqlite3.c.

◆ Bitvec

typedef struct Bitvec Bitvec

Definition at line 14662 of file sqlite3.c.

◆ Bool

typedef unsigned Bool

Definition at line 20755 of file sqlite3.c.

◆ BtCursor

typedef struct BtCursor BtCursor

Definition at line 15037 of file sqlite3.c.

◆ BtLock

typedef struct BtLock BtLock

Definition at line 63702 of file sqlite3.c.

◆ Btree

typedef struct Btree Btree

Definition at line 15036 of file sqlite3.c.

◆ BtreePayload

typedef struct BtreePayload BtreePayload

Definition at line 15039 of file sqlite3.c.

◆ BtShared

typedef struct BtShared BtShared

Definition at line 15038 of file sqlite3.c.

◆ BusyHandler

typedef struct BusyHandler BusyHandler

Definition at line 14563 of file sqlite3.c.

◆ CellArray

typedef struct CellArray CellArray

Definition at line 71359 of file sqlite3.c.

◆ CellInfo

typedef struct CellInfo CellInfo

Definition at line 63703 of file sqlite3.c.

◆ CollSeq

typedef struct CollSeq CollSeq

Definition at line 14663 of file sqlite3.c.

◆ Column

typedef struct Column Column

Definition at line 14664 of file sqlite3.c.

◆ CountCtx

typedef struct CountCtx CountCtx

Definition at line 118648 of file sqlite3.c.

◆ DateTime

typedef struct DateTime DateTime

Definition at line 21775 of file sqlite3.c.

◆ Db

typedef struct Db Db

Definition at line 14665 of file sqlite3.c.

◆ DbFixer

typedef struct DbFixer DbFixer

Definition at line 18954 of file sqlite3.c.

◆ DblquoteStr

typedef struct DblquoteStr DblquoteStr

Definition at line 21070 of file sqlite3.c.

◆ DbPage

typedef struct PgHdr DbPage

Definition at line 14793 of file sqlite3.c.

◆ DistinctCtx

typedef struct DistinctCtx DistinctCtx

Definition at line 129315 of file sqlite3.c.

◆ et_info

typedef struct et_info et_info

◆ etByte

typedef unsigned char etByte

Definition at line 28178 of file sqlite3.c.

◆ Expr

typedef struct Expr Expr

Definition at line 14667 of file sqlite3.c.

◆ ExprList

typedef struct ExprList ExprList

Definition at line 14668 of file sqlite3.c.

◆ FileChunk

typedef struct FileChunk FileChunk

Definition at line 97099 of file sqlite3.c.

◆ FilePoint

typedef struct FilePoint FilePoint

Definition at line 97098 of file sqlite3.c.

◆ FKey

typedef struct FKey FKey

Definition at line 14669 of file sqlite3.c.

◆ fts5_api

typedef struct fts5_api fts5_api

Definition at line 13181 of file sqlite3.c.

◆ fts5_extension_function

typedef void(* fts5_extension_function) (const Fts5ExtensionApi *pApi, Fts5Context *pFts, sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)

Definition at line 12686 of file sqlite3.c.

◆ fts5_tokenizer

typedef struct fts5_tokenizer fts5_tokenizer

Definition at line 13145 of file sqlite3.c.

◆ Fts5Context

typedef struct Fts5Context Fts5Context

Definition at line 12683 of file sqlite3.c.

◆ Fts5ExtensionApi

typedef struct Fts5ExtensionApi Fts5ExtensionApi

Definition at line 12682 of file sqlite3.c.

◆ Fts5PhraseIter

typedef struct Fts5PhraseIter Fts5PhraseIter

Definition at line 12684 of file sqlite3.c.

◆ Fts5Tokenizer

typedef struct Fts5Tokenizer Fts5Tokenizer

Definition at line 13144 of file sqlite3.c.

◆ FuncDef

typedef struct FuncDef FuncDef

Definition at line 14671 of file sqlite3.c.

◆ FuncDefHash

typedef struct FuncDefHash FuncDefHash

Definition at line 14672 of file sqlite3.c.

◆ FuncDestructor

typedef struct FuncDestructor FuncDestructor

Definition at line 14670 of file sqlite3.c.

◆ Hash

typedef struct Hash Hash

Definition at line 13860 of file sqlite3.c.

◆ HashElem

typedef struct HashElem HashElem

Definition at line 13861 of file sqlite3.c.

◆ HiddenIndexInfo

typedef struct HiddenIndexInfo HiddenIndexInfo

Definition at line 145636 of file sqlite3.c.

◆ ht_slot

typedef u16 ht_slot

Definition at line 59890 of file sqlite3.c.

◆ i16

typedef INT16_TYPE i16

Definition at line 14333 of file sqlite3.c.

◆ i64

typedef sqlite_int64 i64

Definition at line 14329 of file sqlite3.c.

◆ i8

typedef INT8_TYPE i8

Definition at line 14335 of file sqlite3.c.

◆ IdList

typedef struct IdList IdList

Definition at line 14673 of file sqlite3.c.

◆ IdxExprTrans

typedef struct IdxExprTrans IdxExprTrans

◆ Incrblob

typedef struct Incrblob Incrblob

Definition at line 93391 of file sqlite3.c.

◆ IncrMerger

typedef struct IncrMerger IncrMerger

Definition at line 94045 of file sqlite3.c.

◆ Index

typedef struct Index Index

Definition at line 14674 of file sqlite3.c.

◆ IndexSample

typedef struct IndexSample IndexSample

Definition at line 14675 of file sqlite3.c.

◆ IntegrityCk

typedef struct IntegrityCk IntegrityCk

Definition at line 64143 of file sqlite3.c.

◆ KeyClass

typedef struct KeyClass KeyClass

Definition at line 14676 of file sqlite3.c.

◆ KeyInfo

typedef struct KeyInfo KeyInfo

Definition at line 14677 of file sqlite3.c.

◆ LogEst

typedef INT16_TYPE LogEst

Definition at line 14380 of file sqlite3.c.

◆ Lookaside

typedef struct Lookaside Lookaside

Definition at line 14678 of file sqlite3.c.

◆ LookasideSlot

typedef struct LookasideSlot LookasideSlot

Definition at line 14679 of file sqlite3.c.

◆ Mem

typedef struct sqlite3_value Mem

Definition at line 15426 of file sqlite3.c.

◆ MemJournal

typedef struct MemJournal MemJournal

Definition at line 97097 of file sqlite3.c.

◆ MemPage

typedef struct MemPage MemPage

Definition at line 63701 of file sqlite3.c.

◆ MergeEngine

typedef struct MergeEngine MergeEngine

Definition at line 94038 of file sqlite3.c.

◆ Module

typedef struct Module Module

Definition at line 14680 of file sqlite3.c.

◆ NameContext

typedef struct NameContext NameContext

Definition at line 14681 of file sqlite3.c.

◆ Op

typedef struct VdbeOp Op

Definition at line 20750 of file sqlite3.c.

◆ Pager

typedef struct Pager Pager

Definition at line 14788 of file sqlite3.c.

◆ PagerSavepoint

typedef struct PagerSavepoint PagerSavepoint

Definition at line 52133 of file sqlite3.c.

◆ Parse

typedef struct Parse Parse

Definition at line 14682 of file sqlite3.c.

◆ PCache

typedef struct PCache PCache

Definition at line 16038 of file sqlite3.c.

◆ PCache1

typedef struct PCache1 PCache1

Definition at line 49843 of file sqlite3.c.

◆ PgFreeslot

typedef struct PgFreeslot PgFreeslot

Definition at line 49845 of file sqlite3.c.

◆ PgHdr

typedef struct PgHdr PgHdr

Definition at line 16037 of file sqlite3.c.

◆ PgHdr1

typedef struct PgHdr1 PgHdr1

Definition at line 49844 of file sqlite3.c.

◆ Pgno

typedef u32 Pgno

Definition at line 14783 of file sqlite3.c.

◆ PGroup

typedef struct PGroup PGroup

Definition at line 49846 of file sqlite3.c.

◆ PmaReader

typedef struct PmaReader PmaReader

Definition at line 94039 of file sqlite3.c.

◆ PmaWriter

typedef struct PmaWriter PmaWriter

Definition at line 94040 of file sqlite3.c.

◆ PragmaName

typedef struct PragmaName PragmaName

◆ PragmaVtab

typedef struct PragmaVtab PragmaVtab

Definition at line 128024 of file sqlite3.c.

◆ PragmaVtabCursor

typedef struct PragmaVtabCursor PragmaVtabCursor

Definition at line 128025 of file sqlite3.c.

◆ PreUpdate

typedef struct PreUpdate PreUpdate

Definition at line 14683 of file sqlite3.c.

◆ PrintfArguments

typedef struct PrintfArguments PrintfArguments

Definition at line 14684 of file sqlite3.c.

◆ RecordCompare

typedef int(* RecordCompare) (int, const void *, UnpackedRecord *)

Definition at line 15904 of file sqlite3.c.

◆ RenameCtx

typedef struct RenameCtx RenameCtx

Definition at line 106446 of file sqlite3.c.

◆ RenameToken

typedef struct RenameToken RenameToken

Definition at line 14685 of file sqlite3.c.

◆ RowLoadInfo

typedef struct RowLoadInfo RowLoadInfo

Definition at line 129820 of file sqlite3.c.

◆ RowSet

typedef struct RowSet RowSet

Definition at line 14686 of file sqlite3.c.

◆ Savepoint

typedef struct Savepoint Savepoint

Definition at line 14687 of file sqlite3.c.

◆ ScanStatus

typedef struct ScanStatus ScanStatus

Definition at line 21053 of file sqlite3.c.

◆ Schema

typedef struct Schema Schema

Definition at line 14666 of file sqlite3.c.

◆ Select

typedef struct Select Select

Definition at line 14688 of file sqlite3.c.

◆ SelectDest

typedef struct SelectDest SelectDest

Definition at line 14690 of file sqlite3.c.

◆ SortCtx

typedef struct SortCtx SortCtx

Definition at line 129341 of file sqlite3.c.

◆ SorterCompare

typedef int(* SorterCompare) (SortSubtask *, int *, const void *, int, const void *, int)

Definition at line 94172 of file sqlite3.c.

◆ SorterFile

typedef struct SorterFile SorterFile

Definition at line 94043 of file sqlite3.c.

◆ SorterList

typedef struct SorterList SorterList

Definition at line 94044 of file sqlite3.c.

◆ SorterRecord

typedef struct SorterRecord SorterRecord

Definition at line 94041 of file sqlite3.c.

◆ SortSubtask

typedef struct SortSubtask SortSubtask

Definition at line 94042 of file sqlite3.c.

◆ sqlite3

typedef struct sqlite3 sqlite3

Definition at line 1297 of file sqlite3.c.

◆ sqlite3_api_routines

typedef struct sqlite3_api_routines sqlite3_api_routines

Definition at line 2244 of file sqlite3.c.

◆ sqlite3_backup

typedef struct sqlite3_backup sqlite3_backup

Definition at line 9539 of file sqlite3.c.

◆ sqlite3_blob

typedef struct sqlite3_blob sqlite3_blob

Definition at line 8124 of file sqlite3.c.

◆ sqlite3_callback

typedef int(* sqlite3_callback) (void *, int, char **, char **)

Definition at line 1386 of file sqlite3.c.

◆ sqlite3_context

typedef struct sqlite3_context sqlite3_context

Definition at line 5306 of file sqlite3.c.

◆ sqlite3_destructor_type

typedef void(* sqlite3_destructor_type) (void *)

Definition at line 6669 of file sqlite3.c.

◆ sqlite3_file

typedef struct sqlite3_file sqlite3_file

Definition at line 1731 of file sqlite3.c.

◆ sqlite3_index_info

typedef struct sqlite3_index_info sqlite3_index_info

Definition at line 7738 of file sqlite3.c.

◆ sqlite3_int64

Definition at line 1329 of file sqlite3.c.

◆ sqlite3_io_methods

typedef struct sqlite3_io_methods sqlite3_io_methods

Definition at line 1830 of file sqlite3.c.

◆ sqlite3_loadext_entry

typedef int(* sqlite3_loadext_entry) (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pThunk)

Definition at line 123933 of file sqlite3.c.

◆ sqlite3_mem_methods

typedef struct sqlite3_mem_methods sqlite3_mem_methods

Definition at line 2713 of file sqlite3.c.

◆ sqlite3_module

typedef struct sqlite3_module sqlite3_module

Definition at line 7740 of file sqlite3.c.

◆ sqlite3_mutex

typedef struct sqlite3_mutex sqlite3_mutex

Definition at line 2234 of file sqlite3.c.

◆ sqlite3_mutex_methods

typedef struct sqlite3_mutex_methods sqlite3_mutex_methods

Definition at line 8572 of file sqlite3.c.

◆ sqlite3_pcache

Definition at line 9313 of file sqlite3.c.

◆ sqlite3_pcache_methods

typedef struct sqlite3_pcache_methods sqlite3_pcache_methods

Definition at line 9513 of file sqlite3.c.

◆ sqlite3_pcache_methods2

typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2

Definition at line 9490 of file sqlite3.c.

◆ sqlite3_pcache_page

typedef struct sqlite3_pcache_page sqlite3_pcache_page

Definition at line 9325 of file sqlite3.c.

◆ sqlite3_rtree_dbl

typedef double sqlite3_rtree_dbl

Definition at line 10896 of file sqlite3.c.

◆ sqlite3_rtree_geometry

typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry

Definition at line 10887 of file sqlite3.c.

◆ sqlite3_rtree_query_info

typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info

Definition at line 10888 of file sqlite3.c.

◆ sqlite3_snapshot

typedef struct sqlite3_snapshot sqlite3_snapshot

◆ sqlite3_stmt

typedef struct sqlite3_stmt sqlite3_stmt

Definition at line 4844 of file sqlite3.c.

◆ sqlite3_str

typedef struct sqlite3_str sqlite3_str

Definition at line 8832 of file sqlite3.c.

◆ sqlite3_syscall_ptr

typedef void(* sqlite3_syscall_ptr) (void)

Definition at line 2416 of file sqlite3.c.

◆ sqlite3_uint64

Definition at line 1330 of file sqlite3.c.

◆ sqlite3_value

typedef struct sqlite3_value sqlite3_value

Definition at line 5292 of file sqlite3.c.

◆ sqlite3_vfs

typedef struct sqlite3_vfs sqlite3_vfs

Definition at line 2415 of file sqlite3.c.

◆ sqlite3_vtab

typedef struct sqlite3_vtab sqlite3_vtab

Definition at line 7737 of file sqlite3.c.

◆ sqlite3_vtab_cursor

typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor

Definition at line 7739 of file sqlite3.c.

◆ sqlite3_xauth

typedef int(* sqlite3_xauth) (void *, int, const char *, const char *, const char *, const char *)

Definition at line 16799 of file sqlite3.c.

◆ sqlite3AutoExtList

typedef struct sqlite3AutoExtList sqlite3AutoExtList

Definition at line 124927 of file sqlite3.c.

◆ sqlite3StatType

typedef struct sqlite3StatType sqlite3StatType

Definition at line 21340 of file sqlite3.c.

◆ sqlite3StatValueType

Definition at line 21336 of file sqlite3.c.

◆ sqlite_int64

typedef long long int sqlite_int64

Definition at line 1326 of file sqlite3.c.

◆ sqlite_uint64

typedef unsigned long long int sqlite_uint64

Definition at line 1327 of file sqlite3.c.

◆ SQLiteThread

typedef struct SQLiteThread SQLiteThread

Definition at line 14689 of file sqlite3.c.

◆ SrcList

typedef struct SrcList SrcList

Definition at line 14691 of file sqlite3.c.

◆ StatAccum

typedef struct StatAccum StatAccum

Definition at line 107807 of file sqlite3.c.

◆ StatSample

typedef struct StatSample StatSample

Definition at line 107808 of file sqlite3.c.

◆ StrAccum

typedef struct sqlite3_str StrAccum

Definition at line 14692 of file sqlite3.c.

◆ SubProgram

typedef struct SubProgram SubProgram

Definition at line 15427 of file sqlite3.c.

◆ SubstContext

typedef struct SubstContext SubstContext

◆ SumCtx

typedef struct SumCtx SumCtx

Definition at line 118551 of file sqlite3.c.

◆ Table

typedef struct Table Table

Definition at line 14693 of file sqlite3.c.

◆ TableLock

typedef struct TableLock TableLock

Definition at line 14694 of file sqlite3.c.

◆ TabResult

typedef struct TabResult TabResult

◆ Token

typedef struct Token Token

Definition at line 14695 of file sqlite3.c.

◆ TreeView

typedef struct TreeView TreeView

Definition at line 14696 of file sqlite3.c.

◆ Trigger

typedef struct Trigger Trigger

Definition at line 14697 of file sqlite3.c.

◆ TriggerPrg

typedef struct TriggerPrg TriggerPrg

Definition at line 14698 of file sqlite3.c.

◆ TriggerStep

typedef struct TriggerStep TriggerStep

Definition at line 14699 of file sqlite3.c.

◆ tRowcnt

typedef u32 tRowcnt

Definition at line 14354 of file sqlite3.c.

◆ u16

typedef UINT16_TYPE u16

Definition at line 14332 of file sqlite3.c.

◆ u32

typedef UINT32_TYPE u32

Definition at line 14331 of file sqlite3.c.

◆ u64

typedef sqlite_uint64 u64

Definition at line 14330 of file sqlite3.c.

◆ u8

typedef UINT8_TYPE u8

Definition at line 14334 of file sqlite3.c.

◆ unixFile

typedef struct unixFile unixFile

Definition at line 33561 of file sqlite3.c.

◆ unixInodeInfo

typedef struct unixInodeInfo unixInodeInfo

Definition at line 33542 of file sqlite3.c.

◆ unixShm

typedef struct unixShm unixShm

Definition at line 33540 of file sqlite3.c.

◆ unixShmNode

typedef struct unixShmNode unixShmNode

Definition at line 33541 of file sqlite3.c.

◆ UnixUnusedFd

typedef struct UnixUnusedFd UnixUnusedFd

Definition at line 33543 of file sqlite3.c.

◆ UnpackedRecord

typedef struct UnpackedRecord UnpackedRecord

Definition at line 14700 of file sqlite3.c.

◆ Upsert

typedef struct Upsert Upsert

Definition at line 14701 of file sqlite3.c.

◆ uptr

typedef u64 uptr

Definition at line 14404 of file sqlite3.c.

◆ Vdbe

typedef struct Vdbe Vdbe

Definition at line 15420 of file sqlite3.c.

◆ VdbeCursor

typedef struct VdbeCursor VdbeCursor

Definition at line 20779 of file sqlite3.c.

◆ VdbeFrame

typedef struct VdbeFrame VdbeFrame

Definition at line 20865 of file sqlite3.c.

◆ VdbeOp

typedef struct VdbeOp VdbeOp

Definition at line 15473 of file sqlite3.c.

◆ VdbeOpList

typedef struct VdbeOpList VdbeOpList

Definition at line 15499 of file sqlite3.c.

◆ VdbeSorter

typedef struct VdbeSorter VdbeSorter

Definition at line 20758 of file sqlite3.c.

◆ VList

typedef int VList

Definition at line 14742 of file sqlite3.c.

◆ VtabCtx

typedef struct VtabCtx VtabCtx

Definition at line 14703 of file sqlite3.c.

◆ VTable

typedef struct VTable VTable

Definition at line 14702 of file sqlite3.c.

◆ Wal

typedef struct Wal Wal

Definition at line 51622 of file sqlite3.c.

◆ WalCkptInfo

typedef struct WalCkptInfo WalCkptInfo

Definition at line 59699 of file sqlite3.c.

◆ WalHashLoc

typedef struct WalHashLoc WalHashLoc

Definition at line 60309 of file sqlite3.c.

◆ WalIndexHdr

typedef struct WalIndexHdr WalIndexHdr

Definition at line 59697 of file sqlite3.c.

◆ WalIterator

typedef struct WalIterator WalIterator

Definition at line 59698 of file sqlite3.c.

◆ Walker

typedef struct Walker Walker

Definition at line 14704 of file sqlite3.c.

◆ WalWriter

typedef struct WalWriter WalWriter

◆ WhereAndInfo

typedef struct WhereAndInfo WhereAndInfo

Definition at line 140953 of file sqlite3.c.

◆ WhereClause

typedef struct WhereClause WhereClause

Definition at line 140950 of file sqlite3.c.

◆ WhereConst

typedef struct WhereConst WhereConst

Definition at line 133496 of file sqlite3.c.

◆ WhereExprMod

typedef struct WhereExprMod WhereExprMod

Definition at line 141366 of file sqlite3.c.

◆ WhereInfo

typedef struct WhereInfo WhereInfo

Definition at line 14705 of file sqlite3.c.

◆ WhereLevel

typedef struct WhereLevel WhereLevel

Definition at line 140954 of file sqlite3.c.

◆ WhereLoop

typedef struct WhereLoop WhereLoop

Definition at line 140955 of file sqlite3.c.

◆ WhereLoopBuilder

typedef struct WhereLoopBuilder WhereLoopBuilder

Definition at line 140958 of file sqlite3.c.

◆ WhereMaskSet

typedef struct WhereMaskSet WhereMaskSet

Definition at line 140951 of file sqlite3.c.

◆ WhereOrCost

typedef struct WhereOrCost WhereOrCost

Definition at line 140960 of file sqlite3.c.

◆ WhereOrInfo

typedef struct WhereOrInfo WhereOrInfo

Definition at line 140952 of file sqlite3.c.

◆ WhereOrSet

typedef struct WhereOrSet WhereOrSet

Definition at line 140961 of file sqlite3.c.

◆ WherePath

typedef struct WherePath WherePath

Definition at line 140956 of file sqlite3.c.

◆ WhereScan

typedef struct WhereScan WhereScan

Definition at line 140959 of file sqlite3.c.

◆ WhereTerm

typedef struct WhereTerm WhereTerm

Definition at line 140957 of file sqlite3.c.

◆ Window

typedef struct Window Window

Definition at line 14706 of file sqlite3.c.

◆ WindowCodeArg

typedef struct WindowCodeArg WindowCodeArg

Definition at line 152647 of file sqlite3.c.

◆ WindowCsrAndReg

typedef struct WindowCsrAndReg WindowCsrAndReg

Definition at line 152648 of file sqlite3.c.

◆ WindowRewrite

typedef struct WindowRewrite WindowRewrite

Definition at line 151893 of file sqlite3.c.

◆ With

typedef struct With With

Definition at line 14707 of file sqlite3.c.

◆ yDbMask

typedef unsigned int yDbMask

Definition at line 18655 of file sqlite3.c.

◆ ynVar

typedef i16 ynVar

Definition at line 17925 of file sqlite3.c.

◆ yyParser

typedef struct yyParser yyParser

Definition at line 155421 of file sqlite3.c.

◆ yyStackEntry

typedef struct yyStackEntry yyStackEntry

Definition at line 155398 of file sqlite3.c.

Function Documentation

◆ absFunc()

static void absFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117190 of file sqlite3.c.

117196 {
117197 assert( argc==1 );
117198 UNUSED_PARAMETER(argc);
117199 switch( sqlite3_value_type(argv[0]) ){
117200 case SQLITE_INTEGER: {
117201 i64 iVal = sqlite3_value_int64(argv[0]);
117202 if( iVal<0 ){
117203 if( iVal==SMALLEST_INT64 ){
117204 /* IMP: R-31676-45509 If X is the integer -9223372036854775808
117205 ** then abs(X) throws an integer overflow error since there is no
117206 ** equivalent positive 64-bit two complement value. */
117207 sqlite3_result_error(context, "integer overflow", -1);
117208 return;
117209 }
117210 iVal = -iVal;
117211 }
117212 sqlite3_result_int64(context, iVal);
117213 break;
117214 }
117215 case SQLITE_NULL: {
117216 /* IMP: R-37434-19929 Abs(X) returns NULL if X is NULL. */
117217 sqlite3_result_null(context);
117218 break;
117219 }
117220 default: {
117221 /* Because sqlite3_value_double() returns 0.0 if the argument is not
117222 ** something that can be converted into a number, we have:
117223 ** IMP: R-01992-00519 Abs(X) returns 0.0 if X is a string or blob
117224 ** that cannot be converted to a numeric value.
117225 */
117226 double rVal = sqlite3_value_double(argv[0]);
SQLITE_API double sqlite3_value_double(sqlite3_value *)
Definition sqlite3.c:83172
SQLITE_API void sqlite3_result_error(sqlite3_context *, const char *, int)
Definition sqlite3.c:83407
#define SQLITE_INTEGER
Definition sqlite3.c:5791
#define SMALLEST_INT64
Definition sqlite3.c:14466
SQLITE_API void sqlite3_result_int64(sqlite3_context *, sqlite3_int64)
Definition sqlite3.c:83423
SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value *)
Definition sqlite3.c:83178
SQLITE_API int sqlite3_value_type(sqlite3_value *)
Definition sqlite3.c:83216
SQLITE_API void sqlite3_result_null(sqlite3_context *)
Definition sqlite3.c:83427
#define SQLITE_NULL
Definition sqlite3.c:5794

References SMALLEST_INT64, sqlite3_result_double(), sqlite3_result_error(), sqlite3_result_int64(), sqlite3_result_null(), sqlite3_value_double(), sqlite3_value_int64(), sqlite3_value_type(), SQLITE_INTEGER, SQLITE_NULL, and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ accessPayload()

static int accessPayload ( BtCursor * pCur,
u32 offset,
u32 amt,
unsigned char * pBuf,
int eOp )
static

Definition at line 69259 of file sqlite3.c.

69271 {
69272 unsigned char *aPayload;
69273 int rc = SQLITE_OK;
69274 int iIdx = 0;
69275 MemPage *pPage = pCur->pPage; /* Btree page of current entry */
69276 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
69277#ifdef SQLITE_DIRECT_OVERFLOW_READ
69278 unsigned char * const pBufStart = pBuf; /* Start of original out buffer */
69279#endif
69280
69281 assert( pPage );
69282 assert( eOp==0 || eOp==1 );
69283 assert( pCur->eState==CURSOR_VALID );
69284 assert( pCur->ix<pPage->nCell );
69285 assert( cursorHoldsMutex(pCur) );
69286
69287 getCellInfo(pCur);
69288 aPayload = pCur->info.pPayload;
69289 assert( offset+amt <= pCur->info.nPayload );
69290
69291 assert( aPayload > pPage->aData );
69292 if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){
69293 /* Trying to read or write past the end of the data is an error. The
69294 ** conditional above is really:
69295 ** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
69296 ** but is recast into its current form to avoid integer overflow problems
69297 */
69298 return SQLITE_CORRUPT_PAGE(pPage);
69299 }
69300
69301 /* Check if data must be read/written to/from the btree page itself. */
69302 if( offset<pCur->info.nLocal ){
69303 int a = amt;
69304 if( a+offset>pCur->info.nLocal ){
69305 a = pCur->info.nLocal - offset;
69306 }
69307 rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage);
69308 offset = 0;
69309 pBuf += a;
69310 amt -= a;
69311 }else{
69312 offset -= pCur->info.nLocal;
69313 }
69314
69315
69316 if( rc==SQLITE_OK && amt>0 ){
69317 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
69318 Pgno nextPage;
69319
69320 nextPage = get4byte(&aPayload[pCur->info.nLocal]);
69321
69322 /* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
69323 **
69324 ** The aOverflow[] array is sized at one entry for each overflow page
69325 ** in the overflow chain. The page number of the first overflow page is
69326 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
69327 ** means "not yet known" (the cache is lazily populated).
69328 */
69329 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
69330 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
69331 if( pCur->aOverflow==0
69332 || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow)
69333 ){
69334 Pgno *aNew = (Pgno*)sqlite3Realloc(
69335 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
69336 );
69337 if( aNew==0 ){
69338 return SQLITE_NOMEM_BKPT;
69339 }else{
69340 pCur->aOverflow = aNew;
69341 }
69342 }
69343 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
69344 pCur->curFlags |= BTCF_ValidOvfl;
69345 }else{
69346 /* If the overflow page-list cache has been allocated and the
69347 ** entry for the first required overflow page is valid, skip
69348 ** directly to it.
69349 */
69350 if( pCur->aOverflow[offset/ovflSize] ){
69351 iIdx = (offset/ovflSize);
69352 nextPage = pCur->aOverflow[iIdx];
69353 offset = (offset%ovflSize);
69354 }
69355 }
69356
69357 assert( rc==SQLITE_OK && amt>0 );
69358 while( nextPage ){
69359 /* If required, populate the overflow page-list cache. */
69360 if( nextPage > pBt->nPage ) return SQLITE_CORRUPT_BKPT;
69361 assert( pCur->aOverflow[iIdx]==0
69362 || pCur->aOverflow[iIdx]==nextPage
69363 || CORRUPT_DB );
69364 pCur->aOverflow[iIdx] = nextPage;
69365
69366 if( offset>=ovflSize ){
69367 /* The only reason to read this page is to obtain the page
69368 ** number for the next page in the overflow chain. The page
69369 ** data is not required. So first try to lookup the overflow
69370 ** page-list cache, if any, then fall back to the getOverflowPage()
69371 ** function.
69372 */
69373 assert( pCur->curFlags & BTCF_ValidOvfl );
69374 assert( pCur->pBtree->db==pBt->db );
69375 if( pCur->aOverflow[iIdx+1] ){
69376 nextPage = pCur->aOverflow[iIdx+1];
69377 }else{
69378 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
69379 }
69380 offset -= ovflSize;
69381 }else{
69382 /* Need to read this page properly. It contains some of the
69383 ** range of data that is being read (eOp==0) or written (eOp!=0).
69384 */
69385 int a = amt;
69386 if( a + offset > ovflSize ){
69387 a = ovflSize - offset;
69388 }
69389
69390#ifdef SQLITE_DIRECT_OVERFLOW_READ
69391 /* If all the following are true:
69392 **
69393 ** 1) this is a read operation, and
69394 ** 2) data is required from the start of this overflow page, and
69395 ** 3) there are no dirty pages in the page-cache
69396 ** 4) the database is file-backed, and
69397 ** 5) the page is not in the WAL file
69398 ** 6) at least 4 bytes have already been read into the output buffer
69399 **
69400 ** then data can be read directly from the database file into the
69401 ** output buffer, bypassing the page-cache altogether. This speeds
69402 ** up loading large records that span many overflow pages.
69403 */
69404 if( eOp==0 /* (1) */
69405 && offset==0 /* (2) */
69406 && sqlite3PagerDirectReadOk(pBt->pPager, nextPage) /* (3,4,5) */
69407 && &pBuf[-4]>=pBufStart /* (6) */
69408 ){
69410 u8 aSave[4];
69411 u8 *aWrite = &pBuf[-4];
69412 assert( aWrite>=pBufStart ); /* due to (6) */
69413 memcpy(aSave, aWrite, 4);
69414 rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
69415 if( rc && nextPage>pBt->nPage ) rc = SQLITE_CORRUPT_BKPT;
69416 nextPage = get4byte(aWrite);
69417 memcpy(aWrite, aSave, 4);
69418 }else
69419#endif
69420
69421 {
69422 DbPage *pDbPage;
69423 rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
69424 (eOp==0 ? PAGER_GET_READONLY : 0)
69425 );
69426 if( rc==SQLITE_OK ){
69427 aPayload = sqlite3PagerGetData(pDbPage);
69428 nextPage = get4byte(aPayload);
69429 rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
69430 sqlite3PagerUnref(pDbPage);
69431 offset = 0;
69432 }
69433 }
69434 amt -= a;
69435 if( amt==0 ) return rc;
69436 pBuf += a;
69437 }
69438 if( rc ) break;
69439 iIdx++;
69440 }
69441 }
69442
#define BTCF_ValidOvfl
Definition sqlite3.c:64008
SQLITE_PRIVATE sqlite3_file * sqlite3PagerFile(Pager *)
Definition sqlite3.c:58694
#define SQLITE_CORRUPT_BKPT
Definition sqlite3.c:19267
#define SQLITE_NOMEM_BKPT
Definition sqlite3.c:19276
static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur)
Definition sqlite3.c:69023
SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *, void *, int amt, i64 offset)
Definition sqlite3.c:23049
SQLITE_PRIVATE void * sqlite3PagerGetData(DbPage *)
Definition sqlite3.c:58890
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *)
Definition sqlite3.c:57397
#define PAGER_GET_READONLY
Definition sqlite3.c:14839
SQLITE_PRIVATE int sqlite3MallocSize(void *)
Definition sqlite3.c:27643
#define get4byte
Definition sqlite3.c:64165
SQLITE_PRIVATE void * sqlite3Realloc(void *, u64)
Definition sqlite3.c:27765
u64 uptr
Definition sqlite3.c:14404
u32 Pgno
Definition sqlite3.c:14783
SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag)
Definition sqlite3.c:57342
static int copyPayload(void *pPayload, void *pBuf, int nByte, int eOp, DbPage *pDbPage)
Definition sqlite3.c:69209
static int getOverflowPage(BtShared *pBt, Pgno ovfl, MemPage **ppPage, Pgno *pPgnoNext)
Definition sqlite3.c:69141
#define CURSOR_VALID
Definition sqlite3.c:64044
#define CORRUPT_DB
Definition sqlite3.c:19085
#define SQLITE_CORRUPT_PAGE(pMemPage)
Definition sqlite3.c:64617
Btree * pBtree
Definition sqlite3.c:63982
BtShared * pBt
Definition sqlite3.c:63989
CellInfo info
Definition sqlite3.c:63991
u8 curFlags
Definition sqlite3.c:63977
MemPage * pPage
Definition sqlite3.c:63999
Pgno * aOverflow
Definition sqlite3.c:63983
u32 usableSize
Definition sqlite3.c:63896
u32 nPage
Definition sqlite3.c:63898
sqlite3 * db
Definition sqlite3.c:63878
u32 pageSize
Definition sqlite3.c:63895
Pager * pPager
Definition sqlite3.c:63877
sqlite3 * db
Definition sqlite3.c:63814
u16 nLocal
Definition sqlite3.c:63934
u8 * pPayload
Definition sqlite3.c:63932
u32 nPayload
Definition sqlite3.c:63933
u8 * aData
Definition sqlite3.c:63765
u16 nCell
Definition sqlite3.c:63759
DbPage * pDbPage
Definition sqlite3.c:63769

References MemPage::aData, BtCursor::aOverflow, BTCF_ValidOvfl, copyPayload(), CORRUPT_DB, BtCursor::curFlags, CURSOR_VALID, Btree::db, BtShared::db, BtCursor::eState, get4byte, getCellInfo(), getOverflowPage(), BtCursor::info, BtCursor::ix, MemPage::nCell, CellInfo::nLocal, BtShared::nPage, CellInfo::nPayload, PAGER_GET_READONLY, BtShared::pageSize, BtCursor::pBt, BtCursor::pBtree, MemPage::pDbPage, BtCursor::pPage, BtShared::pPager, CellInfo::pPayload, sqlite3MallocSize(), sqlite3OsRead(), sqlite3PagerFile(), sqlite3PagerGet(), sqlite3PagerGetData(), sqlite3PagerUnref(), sqlite3Realloc(), SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_PAGE, SQLITE_NOMEM_BKPT, SQLITE_OK, and BtShared::usableSize.

Referenced by sqlite3BtreeMovetoUnpacked(), and sqlite3BtreePayload().

◆ accessPayloadChecked()

static SQLITE_NOINLINE int accessPayloadChecked ( BtCursor * pCur,
u32 offset,
u32 amt,
void * pBuf )
static

Definition at line 69475 of file sqlite3.c.

69486 {
69487 int rc;
69488 if ( pCur->eState==CURSOR_INVALID ){
#define CURSOR_INVALID
Definition sqlite3.c:64045

References CURSOR_INVALID, and BtCursor::eState.

◆ actionName()

static const char * actionName ( u8 action)
static

Definition at line 125978 of file sqlite3.c.

125984 {
125985 const char *zName;
125986 switch( action ){
125987 case OE_SetNull: zName = "SET NULL"; break;
125988 case OE_SetDflt: zName = "SET DEFAULT"; break;
125989 case OE_Cascade: zName = "CASCADE"; break;
#define OE_SetNull
Definition sqlite3.c:17664
#define OE_Cascade
Definition sqlite3.c:17666
#define OE_SetDflt
Definition sqlite3.c:17665

References OE_Cascade, OE_None, OE_Restrict, OE_SetDflt, OE_SetNull, and zName.

Referenced by sqlite3Pragma().

◆ addAggInfoColumn()

static int addAggInfoColumn ( sqlite3 * db,
AggInfo * pInfo )
static

Definition at line 105507 of file sqlite3.c.

105513 {
105514 int i;
105515 pInfo->aCol = sqlite3ArrayAllocate(
105516 db,
105517 pInfo->aCol,
SQLITE_PRIVATE void * sqlite3ArrayAllocate(sqlite3 *, void *, int, int *, int *)
Definition sqlite3.c:114587
struct AggInfo::AggInfo_col * aCol

Referenced by analyzeAggregate().

◆ addAggInfoFunc()

static int addAggInfoFunc ( sqlite3 * db,
AggInfo * pInfo )
static

Definition at line 105523 of file sqlite3.c.

105529 {
105530 int i;
105531 pInfo->aFunc = sqlite3ArrayAllocate(
105532 db,
105533 pInfo->aFunc,
struct AggInfo::AggInfo_func * aFunc

Referenced by analyzeAggregate().

◆ addArgumentToVtab()

static void addArgumentToVtab ( Parse * pParse)
static

Definition at line 139996 of file sqlite3.c.

140002 {
140003 if( pParse->sArg.z && pParse->pNewTable ){
Table * pNewTable
Definition sqlite3.c:18762
Token sArg
Definition sqlite3.c:18769
const char * z
Definition sqlite3.c:17864

References addModuleArgument(), Parse::db, Token::n, Parse::pNewTable, Parse::sArg, sqlite3DbStrNDup(), and Token::z.

◆ addModuleArgument()

static void addModuleArgument ( Parse * pParse,
Table * pTable,
char * zArg )
static

Definition at line 139925 of file sqlite3.c.

139931 {
139932 sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
139933 char **azModuleArg;
139934 sqlite3 *db = pParse->db;
139935 if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
139936 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
139937 }
139938 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
139939 if( azModuleArg==0 ){
139940 sqlite3DbFree(db, zArg);
139941 }else{
sqlite_int64 sqlite3_int64
Definition sqlite3.c:1329
#define SQLITE_LIMIT_COLUMN
Definition sqlite3.c:4946
SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *, void *)
Definition sqlite3.c:27757
SQLITE_PRIVATE void * sqlite3DbRealloc(sqlite3 *, void *, u64)
Definition sqlite3.c:27956
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *, const char *,...)
Definition sqlite3.c:31363
sqlite3 * db
Definition sqlite3.c:18680
char * zName
Definition sqlite3.c:17488
int nModuleArg
Definition sqlite3.c:17512
char ** azModuleArg
Definition sqlite3.c:17513
int aLimit[SQLITE_N_LIMIT]
Definition sqlite3.c:16853

References sqlite3::aLimit, Table::azModuleArg, Parse::db, Table::nModuleArg, sqlite3DbFree(), sqlite3DbRealloc(), sqlite3ErrorMsg(), SQLITE_LIMIT_COLUMN, and Table::zName.

Referenced by addArgumentToVtab(), sqlite3VtabBeginParse(), and sqlite3VtabEponymousTableInit().

◆ addToSavepointBitvecs()

static int addToSavepointBitvecs ( Pager * pPager,
Pgno pgno )
static

Definition at line 53484 of file sqlite3.c.

53490 {
53491 int ii; /* Loop counter */
53492 int rc = SQLITE_OK; /* Result code */
53493
53494 for(ii=0; ii<pPager->nSavepoint; ii++){
53495 PagerSavepoint *p = &pPager->aSavepoint[ii];
53496 if( pgno<=p->nOrig ){
53497 rc |= sqlite3BitvecSet(p->pInSavepoint, pgno);
SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec *, u32)
Definition sqlite3.c:48628
Bitvec * pInSavepoint
Definition sqlite3.c:52137
int nSavepoint
Definition sqlite3.c:52368
PagerSavepoint * aSavepoint
Definition sqlite3.c:52367

References Pager::aSavepoint, Pager::nSavepoint, PagerSavepoint::pInSavepoint, sqlite3BitvecSet(), SQLITE_NOMEM, SQLITE_OK, and testcase.

Referenced by getPageNormal().

◆ addToVTrans()

static void addToVTrans ( sqlite3 * db,
VTable * pVTab )
static

Definition at line 140311 of file sqlite3.c.

Referenced by sqlite3VtabBegin(), and sqlite3VtabCallCreate().

◆ addWhereTerm()

static void addWhereTerm ( Parse * pParse,
SrcList * pSrc,
int iLeft,
int iColLeft,
int iRight,
int iColRight,
int isOuterJoin,
Expr ** ppWhere )
static

Definition at line 129615 of file sqlite3.c.

129630 {
129631 sqlite3 *db = pParse->db;
129632 Expr *pE1;
129633 Expr *pE2;
129634 Expr *pEq;
129635
129636 assert( iLeft<iRight );
129637 assert( pSrc->nSrc>iRight );
129638 assert( pSrc->a[iLeft].pTab );
129639 assert( pSrc->a[iRight].pTab );
129640
129641 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
129642 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
129643
129644 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
129645 if( pEq && isOuterJoin ){
#define TK_EQ
Definition sqlite3.c:13995
#define EP_FromJoin
Definition sqlite3.c:18060
SQLITE_PRIVATE Expr * sqlite3PExpr(Parse *, int, Expr *, Expr *)
Definition sqlite3.c:100601
SQLITE_PRIVATE Expr * sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int)
Definition sqlite3.c:98400
#define ExprSetProperty(E, P)
Definition sqlite3.c:18105
struct SrcList::SrcList_item a[1]
int nSrc
Definition sqlite3.c:18250

References SrcList::a, Parse::db, EP_FromJoin, EP_NoReduce, EP_Reduced, EP_TokenOnly, ExprHasProperty, ExprSetProperty, ExprSetVVAProperty, Expr::iRightJoinTable, Expr::iTable, SrcList::nSrc, SrcList::SrcList_item::pTab, sqlite3CreateColumnExpr(), sqlite3ExprAnd(), sqlite3PExpr(), and TK_EQ.

Referenced by sqliteProcessJoin().

◆ agginfoFree()

static void agginfoFree ( sqlite3 * db,
AggInfo * p )
static

Definition at line 128882 of file sqlite3.c.

◆ agginfoPersistExprCb()

static int agginfoPersistExprCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 105458 of file sqlite3.c.

105464 {
105466 && pExpr->pAggInfo!=0
105467 ){
105468 AggInfo *pAggInfo = pExpr->pAggInfo;
105469 int iAgg = pExpr->iAgg;
105470 Parse *pParse = pWalker->pParse;
105471 sqlite3 *db = pParse->db;
105472 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
105473 if( pExpr->op==TK_AGG_COLUMN ){
105474 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
105475 if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
105476 pExpr = sqlite3ExprDup(db, pExpr, 0);
105477 if( pExpr ){
105478 pAggInfo->aCol[iAgg].pCExpr = pExpr;
105479 pParse->pConstExpr =
105480 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105481 }
105482 }
105483 }else{
105484 assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
105485 if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
105486 pExpr = sqlite3ExprDup(db, pExpr, 0);
105487 if( pExpr ){
105488 pAggInfo->aFunc[iAgg].pFExpr = pExpr;
105489 pParse->pConstExpr =
105490 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
#define EP_Reduced
Definition sqlite3.c:18073
SQLITE_PRIVATE ExprList * sqlite3ExprListAppend(Parse *, ExprList *, Expr *)
Definition sqlite3.c:101344
SQLITE_PRIVATE Expr * sqlite3ExprDup(sqlite3 *, Expr *, int)
Definition sqlite3.c:101161
#define ALWAYS(X)
Definition sqlite3.c:13736
#define EP_TokenOnly
Definition sqlite3.c:18074
#define ExprHasProperty(E, P)
Definition sqlite3.c:18103
#define TK_AGG_FUNCTION
Definition sqlite3.c:14107
#define TK_AGG_COLUMN
Definition sqlite3.c:14108
u8 op
Definition sqlite3.c:17994
AggInfo * pAggInfo
Definition sqlite3.c:18041
i16 iAgg
Definition sqlite3.c:18039
ExprList * pConstExpr
Definition sqlite3.c:18705
Parse * pParse
Definition sqlite3.c:19091

References AggInfo::aCol, AggInfo::aFunc, ALWAYS, Parse::db, EP_Reduced, EP_TokenOnly, ExprHasProperty, Expr::iAgg, Expr::op, Expr::pAggInfo, AggInfo::AggInfo_col::pCExpr, Parse::pConstExpr, AggInfo::AggInfo_func::pFExpr, Walker::pParse, sqlite3ExprDup(), sqlite3ExprListAppend(), TK_AGG_COLUMN, TK_AGG_FUNCTION, and WRC_Continue.

◆ allocateBtreePage()

static int allocateBtreePage ( BtShared * pBt,
MemPage ** ppPage,
Pgno * pPgno,
Pgno nearby,
u8 eMode )
static

Definition at line 70389 of file sqlite3.c.

70401 {
70402 MemPage *pPage1;
70403 int rc;
70404 u32 n; /* Number of pages on the freelist */
70405 u32 k; /* Number of leaves on the trunk of the freelist */
70406 MemPage *pTrunk = 0;
70407 MemPage *pPrevTrunk = 0;
70408 Pgno mxPage; /* Total size of the database file */
70409
70410 assert( sqlite3_mutex_held(pBt->mutex) );
70411 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
70412 pPage1 = pBt->pPage1;
70413 mxPage = btreePagecount(pBt);
70414 /* EVIDENCE-OF: R-05119-02637 The 4-byte big-endian integer at offset 36
70415 ** stores stores the total number of pages on the freelist. */
70416 n = get4byte(&pPage1->aData[36]);
70417 testcase( n==mxPage-1 );
70418 if( n>=mxPage ){
70419 return SQLITE_CORRUPT_BKPT;
70420 }
70421 if( n>0 ){
70422 /* There are pages on the freelist. Reuse one of those pages. */
70423 Pgno iTrunk;
70424 u8 searchList = 0; /* If the free-list must be searched for 'nearby' */
70425 u32 nSearch = 0; /* Count of the number of search attempts */
70426
70427 /* If eMode==BTALLOC_EXACT and a query of the pointer-map
70428 ** shows that the page 'nearby' is somewhere on the free-list, then
70429 ** the entire-list will be searched for that page.
70430 */
70431#ifndef SQLITE_OMIT_AUTOVACUUM
70432 if( eMode==BTALLOC_EXACT ){
70433 if( nearby<=mxPage ){
70434 u8 eType;
70435 assert( nearby>0 );
70436 assert( pBt->autoVacuum );
70437 rc = ptrmapGet(pBt, nearby, &eType, 0);
70438 if( rc ) return rc;
70439 if( eType==PTRMAP_FREEPAGE ){
70440 searchList = 1;
70441 }
70442 }
70443 }else if( eMode==BTALLOC_LE ){
70444 searchList = 1;
70445 }
70446#endif
70447
70448 /* Decrement the free-list count by 1. Set iTrunk to the index of the
70449 ** first free-list trunk page. iPrevTrunk is initially 1.
70450 */
70451 rc = sqlite3PagerWrite(pPage1->pDbPage);
70452 if( rc ) return rc;
70453 put4byte(&pPage1->aData[36], n-1);
70454
70455 /* The code within this loop is run only once if the 'searchList' variable
70456 ** is not true. Otherwise, it runs once for each trunk-page on the
70457 ** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT)
70458 ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
70459 */
70460 do {
70461 pPrevTrunk = pTrunk;
70462 if( pPrevTrunk ){
70463 /* EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
70464 ** is the page number of the next freelist trunk page in the list or
70465 ** zero if this is the last freelist trunk page. */
70466 iTrunk = get4byte(&pPrevTrunk->aData[0]);
70467 }else{
70468 /* EVIDENCE-OF: R-59841-13798 The 4-byte big-endian integer at offset 32
70469 ** stores the page number of the first page of the freelist, or zero if
70470 ** the freelist is empty. */
70471 iTrunk = get4byte(&pPage1->aData[32]);
70472 }
70473 testcase( iTrunk==mxPage );
70474 if( iTrunk>mxPage || nSearch++ > n ){
70475 rc = SQLITE_CORRUPT_PGNO(pPrevTrunk ? pPrevTrunk->pgno : 1);
70476 }else{
70477 rc = btreeGetUnusedPage(pBt, iTrunk, &pTrunk, 0);
70478 }
70479 if( rc ){
70480 pTrunk = 0;
70481 goto end_allocate_page;
70482 }
70483 assert( pTrunk!=0 );
70484 assert( pTrunk->aData!=0 );
70485 /* EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
70486 ** is the number of leaf page pointers to follow. */
70487 k = get4byte(&pTrunk->aData[4]);
70488 if( k==0 && !searchList ){
70489 /* The trunk has no leaves and the list is not being searched.
70490 ** So extract the trunk page itself and use it as the newly
70491 ** allocated page */
70492 assert( pPrevTrunk==0 );
70493 rc = sqlite3PagerWrite(pTrunk->pDbPage);
70494 if( rc ){
70495 goto end_allocate_page;
70496 }
70497 *pPgno = iTrunk;
70498 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
70499 *ppPage = pTrunk;
70500 pTrunk = 0;
70501 TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
70502 }else if( k>(u32)(pBt->usableSize/4 - 2) ){
70503 /* Value of k is out of range. Database corruption */
70504 rc = SQLITE_CORRUPT_PGNO(iTrunk);
70505 goto end_allocate_page;
70506#ifndef SQLITE_OMIT_AUTOVACUUM
70507 }else if( searchList
70508 && (nearby==iTrunk || (iTrunk<nearby && eMode==BTALLOC_LE))
70509 ){
70510 /* The list is being searched and this trunk page is the page
70511 ** to allocate, regardless of whether it has leaves.
70512 */
70513 *pPgno = iTrunk;
70514 *ppPage = pTrunk;
70515 searchList = 0;
70516 rc = sqlite3PagerWrite(pTrunk->pDbPage);
70517 if( rc ){
70518 goto end_allocate_page;
70519 }
70520 if( k==0 ){
70521 if( !pPrevTrunk ){
70522 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
70523 }else{
70524 rc = sqlite3PagerWrite(pPrevTrunk->pDbPage);
70525 if( rc!=SQLITE_OK ){
70526 goto end_allocate_page;
70527 }
70528 memcpy(&pPrevTrunk->aData[0], &pTrunk->aData[0], 4);
70529 }
70530 }else{
70531 /* The trunk page is required by the caller but it contains
70532 ** pointers to free-list leaves. The first leaf becomes a trunk
70533 ** page in this case.
70534 */
70535 MemPage *pNewTrunk;
70536 Pgno iNewTrunk = get4byte(&pTrunk->aData[8]);
70537 if( iNewTrunk>mxPage ){
70538 rc = SQLITE_CORRUPT_PGNO(iTrunk);
70539 goto end_allocate_page;
70540 }
70541 testcase( iNewTrunk==mxPage );
70542 rc = btreeGetUnusedPage(pBt, iNewTrunk, &pNewTrunk, 0);
70543 if( rc!=SQLITE_OK ){
70544 goto end_allocate_page;
70545 }
70546 rc = sqlite3PagerWrite(pNewTrunk->pDbPage);
70547 if( rc!=SQLITE_OK ){
70548 releasePage(pNewTrunk);
70549 goto end_allocate_page;
70550 }
70551 memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4);
70552 put4byte(&pNewTrunk->aData[4], k-1);
70553 memcpy(&pNewTrunk->aData[8], &pTrunk->aData[12], (k-1)*4);
70554 releasePage(pNewTrunk);
70555 if( !pPrevTrunk ){
70556 assert( sqlite3PagerIswriteable(pPage1->pDbPage) );
70557 put4byte(&pPage1->aData[32], iNewTrunk);
70558 }else{
70559 rc = sqlite3PagerWrite(pPrevTrunk->pDbPage);
70560 if( rc ){
70561 goto end_allocate_page;
70562 }
70563 put4byte(&pPrevTrunk->aData[0], iNewTrunk);
70564 }
70565 }
70566 pTrunk = 0;
70567 TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
70568#endif
70569 }else if( k>0 ){
70570 /* Extract a leaf from the trunk */
70571 u32 closest;
70572 Pgno iPage;
70573 unsigned char *aData = pTrunk->aData;
70574 if( nearby>0 ){
70575 u32 i;
70576 closest = 0;
70577 if( eMode==BTALLOC_LE ){
70578 for(i=0; i<k; i++){
70579 iPage = get4byte(&aData[8+i*4]);
70580 if( iPage<=nearby ){
70581 closest = i;
70582 break;
70583 }
70584 }
70585 }else{
70586 int dist;
70587 dist = sqlite3AbsInt32(get4byte(&aData[8]) - nearby);
70588 for(i=1; i<k; i++){
70589 int d2 = sqlite3AbsInt32(get4byte(&aData[8+i*4]) - nearby);
70590 if( d2<dist ){
70591 closest = i;
70592 dist = d2;
70593 }
70594 }
70595 }
70596 }else{
70597 closest = 0;
70598 }
70599
70600 iPage = get4byte(&aData[8+closest*4]);
70601 testcase( iPage==mxPage );
70602 if( iPage>mxPage ){
70603 rc = SQLITE_CORRUPT_PGNO(iTrunk);
70604 goto end_allocate_page;
70605 }
70606 testcase( iPage==mxPage );
70607 if( !searchList
70608 || (iPage==nearby || (iPage<nearby && eMode==BTALLOC_LE))
70609 ){
70610 int noContent;
70611 *pPgno = iPage;
70612 TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d"
70613 ": %d more free pages\n",
70614 *pPgno, closest+1, k, pTrunk->pgno, n-1));
70615 rc = sqlite3PagerWrite(pTrunk->pDbPage);
70616 if( rc ) goto end_allocate_page;
70617 if( closest<k-1 ){
70618 memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
70619 }
70620 put4byte(&aData[4], k-1);
70621 noContent = !btreeGetHasContent(pBt, *pPgno)? PAGER_GET_NOCONTENT : 0;
70622 rc = btreeGetUnusedPage(pBt, *pPgno, ppPage, noContent);
70623 if( rc==SQLITE_OK ){
70624 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
70625 if( rc!=SQLITE_OK ){
70626 releasePage(*ppPage);
70627 *ppPage = 0;
70628 }
70629 }
70630 searchList = 0;
70631 }
70632 }
70633 releasePage(pPrevTrunk);
70634 pPrevTrunk = 0;
70635 }while( searchList );
70636 }else{
70637 /* There are no pages on the freelist, so append a new page to the
70638 ** database image.
70639 **
70640 ** Normally, new pages allocated by this block can be requested from the
70641 ** pager layer with the 'no-content' flag set. This prevents the pager
70642 ** from trying to read the pages content from disk. However, if the
70643 ** current transaction has already run one or more incremental-vacuum
70644 ** steps, then the page we are about to allocate may contain content
70645 ** that is required in the event of a rollback. In this case, do
70646 ** not set the no-content flag. This causes the pager to load and journal
70647 ** the current page content before overwriting it.
70648 **
70649 ** Note that the pager will not actually attempt to load or journal
70650 ** content for any page that really does lie past the end of the database
70651 ** file on disk. So the effects of disabling the no-content optimization
70652 ** here are confined to those pages that lie between the end of the
70653 ** database image and the end of the database file.
70654 */
70655 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate))? PAGER_GET_NOCONTENT:0;
70656
70657 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
70658 if( rc ) return rc;
70659 pBt->nPage++;
70660 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
70661
70662#ifndef SQLITE_OMIT_AUTOVACUUM
70663 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
70664 /* If *pPgno refers to a pointer-map page, allocate two new pages
70665 ** at the end of the file instead of one. The first allocated page
70666 ** becomes a new pointer-map page, the second is used by the caller.
70667 */
70668 MemPage *pPg = 0;
70669 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
70670 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
70671 rc = btreeGetUnusedPage(pBt, pBt->nPage, &pPg, bNoContent);
70672 if( rc==SQLITE_OK ){
70673 rc = sqlite3PagerWrite(pPg->pDbPage);
70674 releasePage(pPg);
70675 }
70676 if( rc ) return rc;
70677 pBt->nPage++;
70678 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
70679 }
70680#endif
70681 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
70682 *pPgno = pBt->nPage;
70683
70684 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
70685 rc = btreeGetUnusedPage(pBt, *pPgno, ppPage, bNoContent);
70686 if( rc ) return rc;
70687 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
70688 if( rc!=SQLITE_OK ){
70689 releasePage(*ppPage);
70690 *ppPage = 0;
70691 }
70692 TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
70693 }
70694
70695 assert( CORRUPT_DB || *pPgno!=PENDING_BYTE_PAGE(pBt) );
70696
70697end_allocate_page:
static int btreeGetHasContent(BtShared *pBt, Pgno pgno)
Definition sqlite3.c:65091
#define PTRMAP_FREEPAGE
Definition sqlite3.c:64106
#define BTALLOC_EXACT
Definition sqlite3.c:64527
#define PAGER_GET_NOCONTENT
Definition sqlite3.c:14838
#define PTRMAP_ISPAGE(pBt, pgno)
Definition sqlite3.c:64072
#define TRACE(X)
Definition sqlite3.c:64509
#define BTALLOC_ANY
Definition sqlite3.c:64526
#define BTALLOC_LE
Definition sqlite3.c:64528
SQLITE_PRIVATE int sqlite3AbsInt32(int)
Definition sqlite3.c:32640
static int btreeGetUnusedPage(BtShared *pBt, Pgno pgno, MemPage **ppPage, int flags)
Definition sqlite3.c:66730
static void releasePage(MemPage *pPage)
Definition sqlite3.c:66707
static Pgno btreePagecount(BtShared *pBt)
Definition sqlite3.c:66618
#define put4byte
Definition sqlite3.c:64166
#define IfNotOmitAV(expr)
Definition sqlite3.c:64537
#define testcase(X)
Definition sqlite3.c:13686
SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *)
#define SQLITE_CORRUPT_PGNO(P)
Definition sqlite3.c:19283
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *)
Definition sqlite3.c:57833
static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno)
Definition sqlite3.c:65522
#define PENDING_BYTE_PAGE(pBt)
Definition sqlite3.c:64053
u8 eType
Definition sqlite3.c:22327
MemPage * pPage1
Definition sqlite3.c:63880
sqlite3_mutex * mutex
Definition sqlite3.c:63901
u8 bDoTruncate
Definition sqlite3.c:63885
u8 autoVacuum
Definition sqlite3.c:63883
Pgno pgno
Definition sqlite3.c:63747

References MemPage::aData, BtShared::autoVacuum, BtShared::bDoTruncate, BTALLOC_ANY, BTALLOC_EXACT, BTALLOC_LE, btreeGetHasContent(), btreeGetUnusedPage(), btreePagecount(), CORRUPT_DB, eType, get4byte, IfNotOmitAV, BtShared::mutex, BtShared::nPage, PAGER_GET_NOCONTENT, MemPage::pDbPage, PENDING_BYTE_PAGE, MemPage::pgno, BtShared::pPage1, PTRMAP_FREEPAGE, PTRMAP_ISPAGE, ptrmapGet(), put4byte, releasePage(), sqlite3_mutex_held(), sqlite3AbsInt32(), sqlite3PagerPageRefcount(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_PGNO, SQLITE_OK, testcase, TRACE, and BtShared::usableSize.

Referenced by balance_deeper(), balance_nonroot(), balance_quick(), btreeCreateTable(), fillInCell(), and incrVacuumStep().

◆ allocateCursor()

static VdbeCursor * allocateCursor ( Vdbe * p,
int iCur,
int nField,
int iDb,
u8 eCurType )
static

Definition at line 85472 of file sqlite3.c.

85484 {
85485 /* Find the memory cell that will be used to store the blob of memory
85486 ** required for this VdbeCursor structure. It is convenient to use a
85487 ** vdbe memory cell to manage the memory allocation required for a
85488 ** VdbeCursor structure for the following reasons:
85489 **
85490 ** * Sometimes cursor numbers are used for a couple of different
85491 ** purposes in a vdbe program. The different uses might require
85492 ** different sized allocations. Memory cells provide growable
85493 ** allocations.
85494 **
85495 ** * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
85496 ** be freed lazily via the sqlite3_release_memory() API. This
85497 ** minimizes the number of malloc calls made by the system.
85498 **
85499 ** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
85500 ** the top of the register space. Cursor 1 is at Mem[p->nMem-1].
85501 ** Cursor 2 is at Mem[p->nMem-2]. And so forth.
85502 */
85503 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
85504
85505 int nByte;
85506 VdbeCursor *pCx = 0;
85507 nByte =
85508 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
85509 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
85510
85511 assert( iCur>=0 && iCur<p->nCursor );
85512 if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
85513 /* Before calling sqlite3VdbeFreeCursor(), ensure the isEphemeral flag
85514 ** is clear. Otherwise, if this is an ephemeral cursor created by
85515 ** OP_OpenDup, the cursor will not be closed and will still be part
85516 ** of a BtShared.pCursor list. */
85517 if( p->apCsr[iCur]->pBtx==0 ) p->apCsr[iCur]->isEphemeral = 0;
85518 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
85519 p->apCsr[iCur] = 0;
85520 }
85521 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
85522 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
85523 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
85524 pCx->eCurType = eCurType;
85525 pCx->iDb = iDb;
85526 pCx->nField = nField;
85527 pCx->aOffset = &pCx->aType[nField];
85528 if( eCurType==CURTYPE_BTREE ){
85529 pCx->uc.pCursor = (BtCursor*)
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor *)
Definition sqlite3.c:80200
#define offsetof(STRUCTURE, FIELD)
Definition sqlite3.c:14256
#define ROUND8(x)
Definition sqlite3.c:14472
SQLITE_PRIVATE int sqlite3BtreeCursorSize(void)
Definition sqlite3.c:68949
#define CURTYPE_BTREE
Definition sqlite3.c:20764
SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n)
Definition sqlite3.c:76116
u32 * aOffset
Definition sqlite3.c:20824
union VdbeCursor::@117 uc
Btree * pBtx
Definition sqlite3.c:20794
BtCursor * pCursor
Definition sqlite3.c:20814
u32 aType[1]
Definition sqlite3.c:20835
Bool isEphemeral
Definition sqlite3.c:20790
int nMem
Definition sqlite3.c:21089
VdbeCursor ** apCsr
Definition sqlite3.c:21102
Mem * aMem
Definition sqlite3.c:21100

References Vdbe::aMem, VdbeCursor::aOffset, Vdbe::apCsr, VdbeCursor::aType, CURTYPE_BTREE, VdbeCursor::eCurType, VdbeCursor::iDb, VdbeCursor::isEphemeral, VdbeCursor::nField, Vdbe::nMem, offsetof, VdbeCursor::pBtx, VdbeCursor::pCursor, ROUND8, sqlite3BtreeCursorSize(), sqlite3BtreeCursorZero(), sqlite3VdbeFreeCursor(), sqlite3VdbeMemClearAndResize(), SQLITE_OK, VdbeCursor::uc, and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ allocateIndexInfo()

static sqlite3_index_info * allocateIndexInfo ( Parse * pParse,
WhereClause * pWC,
Bitmask mUnusable,
struct SrcList_item * pSrc,
ExprList * pOrderBy,
u16 * pmNoOmit )
static

Definition at line 146509 of file sqlite3.c.

146522 {
146523 int i, j;
146524 int nTerm;
146525 struct sqlite3_index_constraint *pIdxCons;
146526 struct sqlite3_index_orderby *pIdxOrderBy;
146527 struct sqlite3_index_constraint_usage *pUsage;
146528 struct HiddenIndexInfo *pHidden;
146529 WhereTerm *pTerm;
146530 int nOrderBy;
146531 sqlite3_index_info *pIdxInfo;
146532 u16 mNoOmit = 0;
146533
146534 /* Count the number of possible WHERE clause constraints referring
146535 ** to this virtual table */
146536 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
146537 if( pTerm->leftCursor != pSrc->iCursor ) continue;
146538 if( pTerm->prereqRight & mUnusable ) continue;
146539 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
146540 testcase( pTerm->eOperator & WO_IN );
146541 testcase( pTerm->eOperator & WO_ISNULL );
146542 testcase( pTerm->eOperator & WO_IS );
146543 testcase( pTerm->eOperator & WO_ALL );
146544 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
146545 if( pTerm->wtFlags & TERM_VNULL ) continue;
146546 assert( pTerm->u.leftColumn>=(-1) );
146547 nTerm++;
146548 }
146549
146550 /* If the ORDER BY clause contains only columns in the current
146551 ** virtual table then allocate space for the aOrderBy part of
146552 ** the sqlite3_index_info structure.
146553 */
146554 nOrderBy = 0;
146555 if( pOrderBy ){
146556 int n = pOrderBy->nExpr;
146557 for(i=0; i<n; i++){
146558 Expr *pExpr = pOrderBy->a[i].pExpr;
146559 if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break;
146560 if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
146561 }
146562 if( i==n){
146563 nOrderBy = n;
146564 }
146565 }
146566
146567 /* Allocate the sqlite3_index_info structure
146568 */
146569 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
146570 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
146571 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
146572 if( pIdxInfo==0 ){
146573 sqlite3ErrorMsg(pParse, "out of memory");
146574 return 0;
146575 }
146576 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
146577 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
146578 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
146579 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
146580 pIdxInfo->nOrderBy = nOrderBy;
146581 pIdxInfo->aConstraint = pIdxCons;
146582 pIdxInfo->aOrderBy = pIdxOrderBy;
146583 pIdxInfo->aConstraintUsage = pUsage;
146584 pHidden->pWC = pWC;
146585 pHidden->pParse = pParse;
146586 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
146587 u16 op;
146588 if( pTerm->leftCursor != pSrc->iCursor ) continue;
146589 if( pTerm->prereqRight & mUnusable ) continue;
146590 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
146591 testcase( pTerm->eOperator & WO_IN );
146592 testcase( pTerm->eOperator & WO_IS );
146593 testcase( pTerm->eOperator & WO_ISNULL );
146594 testcase( pTerm->eOperator & WO_ALL );
146595 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
146596 if( pTerm->wtFlags & TERM_VNULL ) continue;
146597
146598 /* tag-20191211-002: WHERE-clause constraints are not useful to the
146599 ** right-hand table of a LEFT JOIN. See tag-20191211-001 for the
146600 ** equivalent restriction for ordinary tables. */
146601 if( (pSrc->fg.jointype & JT_LEFT)!=0
146602 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
146603 ){
146604 continue;
146605 }
146606 assert( pTerm->u.leftColumn>=(-1) );
146607 pIdxCons[j].iColumn = pTerm->u.leftColumn;
146608 pIdxCons[j].iTermOffset = i;
146609 op = pTerm->eOperator & WO_ALL;
146610 if( op==WO_IN ) op = WO_EQ;
146611 if( op==WO_AUX ){
146612 pIdxCons[j].op = pTerm->eMatchOp;
146613 }else if( op & (WO_ISNULL|WO_IS) ){
146614 if( op==WO_ISNULL ){
146615 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
146616 }else{
146617 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_IS;
146618 }
146619 }else{
146620 pIdxCons[j].op = (u8)op;
146621 /* The direct assignment in the previous line is possible only because
146622 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
146623 ** following asserts verify this fact. */
146629 assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );
146630
146631 if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
146632 && sqlite3ExprIsVector(pTerm->pExpr->pRight)
146633 ){
146634 testcase( j!=i );
146635 if( j<16 ) mNoOmit |= (1 << j);
146636 if( op==WO_LT ) pIdxCons[j].op = WO_LE;
146637 if( op==WO_GT ) pIdxCons[j].op = WO_GE;
146638 }
146639 }
146640
146641 j++;
146642 }
146643 pIdxInfo->nConstraint = j;
146644 for(i=0; i<nOrderBy; i++){
146645 Expr *pExpr = pOrderBy->a[i].pExpr;
146646 pIdxOrderBy[i].iColumn = pExpr->iColumn;
#define WO_IN
Definition sqlite3.c:141490
#define WO_GE
Definition sqlite3.c:141495
#define SQLITE_INDEX_CONSTRAINT_LT
Definition sqlite3.c:7950
#define WO_EQUIV
Definition sqlite3.c:141501
#define WO_GT
Definition sqlite3.c:141494
SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr)
Definition sqlite3.c:100116
#define SQLITE_INDEX_CONSTRAINT_LE
Definition sqlite3.c:7949
#define SQLITE_INDEX_CONSTRAINT_IS
Definition sqlite3.c:7960
UINT16_TYPE u16
Definition sqlite3.c:14332
#define WO_ISNULL
Definition sqlite3.c:141498
#define SQLITE_INDEX_CONSTRAINT_GE
Definition sqlite3.c:7951
SQLITE_PRIVATE void * sqlite3DbMallocZero(sqlite3 *, u64)
Definition sqlite3.c:27849
#define WO_LT
Definition sqlite3.c:141492
#define SQLITE_INDEX_CONSTRAINT_ISNULL
Definition sqlite3.c:7959
#define SQLITE_INDEX_CONSTRAINT_EQ
Definition sqlite3.c:7947
#define WO_LE
Definition sqlite3.c:141493
#define IsPowerOfTwo(X)
Definition sqlite3.c:14599
#define TERM_VNULL
Definition sqlite3.c:141201
#define TK_COLUMN
Definition sqlite3.c:14106
#define SQLITE_INDEX_CONSTRAINT_GT
Definition sqlite3.c:7948
#define WO_AUX
Definition sqlite3.c:141496
#define KEYINFO_ORDER_BIGNULL
Definition sqlite3.c:17693
#define JT_LEFT
Definition sqlite3.c:18290
#define WO_EQ
Definition sqlite3.c:141491
#define WO_IS
Definition sqlite3.c:141497
#define WO_ALL
Definition sqlite3.c:141504
int nExpr
Definition sqlite3.c:18180
struct ExprList::ExprList_item a[1]
Expr * pRight
Definition sqlite3.c:18015
ynVar iColumn
Definition sqlite3.c:18036
int iTable
Definition sqlite3.c:18029
WhereClause * pWC
Definition sqlite3.c:145638
WhereTerm * a
Definition sqlite3.c:141252
union WhereTerm::@125 u
Bitmask prereqRight
Definition sqlite3.c:141184
int leftColumn
Definition sqlite3.c:141180
int leftCursor
Definition sqlite3.c:141177
u16 eOperator
Definition sqlite3.c:141173
Expr * pExpr
Definition sqlite3.c:141169
struct sqlite3_index_info::sqlite3_index_constraint * aConstraint
struct sqlite3_index_info::sqlite3_index_orderby * aOrderBy
struct sqlite3_index_info::sqlite3_index_constraint_usage * aConstraintUsage

References ExprList::a, WhereClause::a, sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, sqlite3_index_info::aOrderBy, Parse::db, WhereTerm::eMatchOp, WhereTerm::eOperator, EP_FromJoin, ExprHasProperty, Expr::iColumn, IsPowerOfTwo, Expr::iTable, JT_LEFT, KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, WhereTerm::leftColumn, WhereTerm::leftCursor, sqlite3_index_info::nConstraint, ExprList::nExpr, sqlite3_index_info::nOrderBy, WhereClause::nTerm, Expr::op, ExprList::ExprList_item::pExpr, WhereTerm::pExpr, HiddenIndexInfo::pParse, WhereTerm::prereqRight, Expr::pRight, HiddenIndexInfo::pWC, ExprList::ExprList_item::sortFlags, sqlite3DbMallocZero(), sqlite3ErrorMsg(), sqlite3ExprIsVector(), SQLITE_INDEX_CONSTRAINT_EQ, SQLITE_INDEX_CONSTRAINT_GE, SQLITE_INDEX_CONSTRAINT_GT, SQLITE_INDEX_CONSTRAINT_IS, SQLITE_INDEX_CONSTRAINT_ISNULL, SQLITE_INDEX_CONSTRAINT_LE, SQLITE_INDEX_CONSTRAINT_LT, TERM_VNULL, testcase, TK_COLUMN, WhereTerm::u, WO_ALL, WO_AUX, WO_EQ, WO_EQUIV, WO_GE, WO_GT, WO_IN, WO_IS, WO_ISNULL, WO_LE, WO_LT, and WhereTerm::wtFlags.

Referenced by whereLoopAddVirtual().

◆ allocateSpace()

static int allocateSpace ( MemPage * pPage,
int nByte,
int * pIdx )
static

Definition at line 66089 of file sqlite3.c.

66095 {
66096 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
66097 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
66098 int top; /* First byte of cell content area */
66099 int rc = SQLITE_OK; /* Integer return code */
66100 int gap; /* First byte of gap between cell pointers and cell content */
66101
66102 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
66103 assert( pPage->pBt );
66104 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
66105 assert( nByte>=0 ); /* Minimum cell size is 4 */
66106 assert( pPage->nFree>=nByte );
66107 assert( pPage->nOverflow==0 );
66108 assert( nByte < (int)(pPage->pBt->usableSize-8) );
66109
66110 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
66111 gap = pPage->cellOffset + 2*pPage->nCell;
66112 assert( gap<=65536 );
66113 /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size
66114 ** and the reserved space is zero (the usual value for reserved space)
66115 ** then the cell content offset of an empty page wants to be 65536.
66116 ** However, that integer is too large to be stored in a 2-byte unsigned
66117 ** integer, so a value of 0 is used in its place. */
66118 top = get2byte(&data[hdr+5]);
66119 assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */
66120 if( gap>top ){
66121 if( top==0 && pPage->pBt->usableSize==65536 ){
66122 top = 65536;
66123 }else{
66124 return SQLITE_CORRUPT_PAGE(pPage);
66125 }
66126 }
66127
66128 /* If there is enough space between gap and top for one more cell pointer,
66129 ** and if the freelist is not empty, then search the
66130 ** freelist looking for a slot big enough to satisfy the request.
66131 */
66132 testcase( gap+2==top );
66133 testcase( gap+1==top );
66134 testcase( gap==top );
66135 if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
66136 u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
66137 if( pSpace ){
66138 int g2;
66139 assert( pSpace+nByte<=data+pPage->pBt->usableSize );
66140 *pIdx = g2 = (int)(pSpace-data);
66141 if( NEVER(g2<=gap) ){
66142 return SQLITE_CORRUPT_PAGE(pPage);
66143 }else{
66144 return SQLITE_OK;
66145 }
66146 }else if( rc ){
66147 return rc;
66148 }
66149 }
66150
66151 /* The request could not be fulfilled using a freelist slot. Check
66152 ** to see if defragmentation is necessary.
66153 */
66154 testcase( gap+2+nByte==top );
66155 if( gap+2+nByte>top ){
66156 assert( pPage->nCell>0 || CORRUPT_DB );
66157 assert( pPage->nFree>=0 );
66158 rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
66159 if( rc ) return rc;
66160 top = get2byteNotZero(&data[hdr+5]);
66161 assert( gap+2+nByte<=top );
66162 }
66163
66164
66165 /* Allocate memory from the gap in between the cell pointer array
66166 ** and the cell content area. The btreeComputeFreeSpace() call has already
66167 ** validated the freelist. Given that the freelist is valid, there
66168 ** is no way that the allocation can extend off the end of the page.
66169 ** The assert() below verifies the previous sentence.
66170 */
static int defragmentPage(MemPage *pPage, int nMaxFrag)
Definition sqlite3.c:65885
#define NEVER(X)
Definition sqlite3.c:13737
static u8 * pageFindSlot(MemPage *pPg, int nByte, int *pRc)
Definition sqlite3.c:66021
#define get2byte(x)
Definition sqlite3.c:64163
#define get2byteNotZero(X)
Definition sqlite3.c:64521
#define MIN(A, B)
Definition sqlite3.c:14263
u8 hdrOffset
Definition sqlite3.c:63751
u16 cellOffset
Definition sqlite3.c:63757
u8 nOverflow
Definition sqlite3.c:63754
int nFree
Definition sqlite3.c:63758
BtShared * pBt
Definition sqlite3.c:63764

References MemPage::aData, MemPage::cellOffset, CORRUPT_DB, defragmentPage(), get2byte, get2byteNotZero, MemPage::hdrOffset, MemPage::leaf, MIN, BtShared::mutex, MemPage::nCell, NEVER, MemPage::nFree, MemPage::nOverflow, pageFindSlot(), MemPage::pBt, MemPage::pDbPage, put2byte, sqlite3_mutex_held(), SQLITE_CORRUPT_PAGE, SQLITE_OK, testcase, and BtShared::usableSize.

Referenced by insertCell().

◆ allocateTempSpace()

static void allocateTempSpace ( BtShared * pBt)
static

Definition at line 67146 of file sqlite3.c.

67152 {
67153 if( !pBt->pTmpSpace ){
67154 pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
67155
67156 /* One of the uses of pBt->pTmpSpace is to format cells before
67157 ** inserting them into a leaf page (function fillInCell()). If
67158 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
67159 ** by the various routines that manipulate binary cells. Which
67160 ** can mean that fillInCell() only initializes the first 2 or 3
67161 ** bytes of pTmpSpace, but that the first 4 bytes are copied from
67162 ** it into a database page. This is not actually a problem, but it
67163 ** does cause a valgrind error when the 1 or 2 bytes of unitialized
67164 ** data is passed to system call write(). So to avoid this error,
67165 ** zero the first 4 bytes of temp space here.
67166 **
67167 ** Also: Provide four bytes of initialized space before the
67168 ** beginning of pTmpSpace as an area available to prepend the
67169 ** left-child pointer to the beginning of a cell.
67170 */
SQLITE_PRIVATE void * sqlite3PageMalloc(int)
Definition sqlite3.c:50252
u8 * pTmpSpace
Definition sqlite3.c:63909

References BtShared::pageSize, BtShared::pTmpSpace, and sqlite3PageMalloc().

Referenced by btreeCursor().

◆ allocSpace()

static void * allocSpace ( struct ReusableSpace * p,
void * pBuf,
sqlite3_int64 nByte )
static

Definition at line 79999 of file sqlite3.c.

80009 {
80010 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
80011 if( pBuf==0 ){
80012 nByte = ROUND8(nByte);
80013 if( nByte <= p->nFree ){
80014 p->nFree -= nByte;
80015 pBuf = &p->pSpace[p->nFree];
80016 }else{
#define EIGHT_BYTE_ALIGNMENT(X)
Definition sqlite3.c:14491
sqlite3_int64 nFree
Definition sqlite3.c:79981

References EIGHT_BYTE_ALIGNMENT, ReusableSpace::nFree, ReusableSpace::nNeeded, ReusableSpace::pSpace, and ROUND8.

Referenced by sqlite3VdbeMakeReady().

◆ allowedOp()

static int allowedOp ( int op)
static

Definition at line 144091 of file sqlite3.c.

144097 {

References TK_EQ, TK_GE, TK_GT, TK_IN, TK_IS, TK_ISNULL, TK_LE, and TK_LT.

Referenced by exprAnalyze(), and exprAnalyzeOrTerm().

◆ alsoAnInt()

static int alsoAnInt ( Mem * pRec,
double rValue,
i64 * piValue )
static

Definition at line 85537 of file sqlite3.c.

85543 {
85544 i64 iValue = (double)rValue;

References sqlite3_value::enc, sqlite3_value::n, sqlite3Atoi64(), sqlite3RealSameAsInt(), and sqlite3_value::z.

Referenced by applyNumericAffinity().

◆ analysisLoader()

static int analysisLoader ( void * pData,
int argc,
char ** argv,
char ** NotUsed )
static

Definition at line 109091 of file sqlite3.c.

109097 {
109098 analysisInfo *pInfo = (analysisInfo*)pData;
109099 Index *pIndex;
109100 Table *pTable;
109101 const char *z;
109102
109103 assert( argc==3 );
109104 UNUSED_PARAMETER2(NotUsed, argc);
109105
109106 if( argv==0 || argv[0]==0 || argv[2]==0 ){
109107 return 0;
109108 }
109109 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
109110 if( pTable==0 ){
109111 return 0;
109112 }
109113 if( argv[1]==0 ){
109114 pIndex = 0;
109115 }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
109116 pIndex = sqlite3PrimaryKeyIndex(pTable);
109117 }else{
109118 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
109119 }
109120 z = argv[2];
109121
109122 if( pIndex ){
109123 tRowcnt *aiRowEst = 0;
109124 int nCol = pIndex->nKeyCol+1;
109125#ifdef SQLITE_ENABLE_STAT4
109126 /* Index.aiRowEst may already be set here if there are duplicate
109127 ** sqlite_stat1 entries for this index. In that case just clobber
109128 ** the old data with the new instead of allocating a new array. */
109129 if( pIndex->aiRowEst==0 ){
109130 pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
109131 if( pIndex->aiRowEst==0 ) sqlite3OomFault(pInfo->db);
109132 }
109133 aiRowEst = pIndex->aiRowEst;
109134#endif
109135 pIndex->bUnordered = 0;
109136 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
109137 pIndex->hasStat1 = 1;
109138 if( pIndex->pPartIdxWhere==0 ){
109139 pTable->nRowLogEst = pIndex->aiRowLogEst[0];
109140 pTable->tabFlags |= TF_HasStat1;
109141 }
109142 }else{
109143 Index fakeIdx;
109144 fakeIdx.szIdxRow = pTable->szTabRow;
109145#ifdef SQLITE_ENABLE_COSTMULT
109146 fakeIdx.pTable = pTable;
109147#endif
109148 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *)
Definition sqlite3.c:28071
static void decodeIntArray(char *zIntArray, int nOut, tRowcnt *aOut, LogEst *aLog, Index *pIndex)
Definition sqlite3.c:109018
u32 tRowcnt
Definition sqlite3.c:14354
#define TF_HasStat1
Definition sqlite3.c:17539
SQLITE_PRIVATE Index * sqlite3FindIndex(sqlite3 *, const char *, const char *)
Definition sqlite3.c:110865
SQLITE_API int sqlite3_stricmp(const char *, const char *)
Definition sqlite3.c:31460
SQLITE_PRIVATE void * sqlite3MallocZero(u64)
Definition sqlite3.c:27837
#define UNUSED_PARAMETER2(x, y)
Definition sqlite3.c:14654
SQLITE_PRIVATE Index * sqlite3PrimaryKeyIndex(Table *)
Definition sqlite3.c:111310
SQLITE_PRIVATE Table * sqlite3FindTable(sqlite3 *, const char *, const char *)
Definition sqlite3.c:110699
Table * pTable
Definition sqlite3.c:17780
LogEst * aiRowLogEst
Definition sqlite3.c:17779
LogEst szIdxRow
Definition sqlite3.c:17789
Expr * pPartIdxWhere
Definition sqlite3.c:17786
unsigned hasStat1
Definition sqlite3.c:17799
u16 nKeyCol
Definition sqlite3.c:17790
unsigned bUnordered
Definition sqlite3.c:17794
LogEst szTabRow
Definition sqlite3.c:17503
u32 tabFlags
Definition sqlite3.c:17498
LogEst nRowLogEst
Definition sqlite3.c:17502
sqlite3 * db
Definition sqlite3.c:109009
const char * zDatabase
Definition sqlite3.c:109010

References Index::aiRowLogEst, Index::bUnordered, analysisInfo::db, decodeIntArray(), Index::hasStat1, Index::nKeyCol, Table::nRowLogEst, Index::pPartIdxWhere, Index::pTable, sqlite3_stricmp(), sqlite3FindIndex(), sqlite3FindTable(), sqlite3MallocZero(), sqlite3OomFault(), sqlite3PrimaryKeyIndex(), Index::szIdxRow, Table::szTabRow, Table::tabFlags, TF_HasStat1, UNUSED_PARAMETER2, and analysisInfo::zDatabase.

Referenced by sqlite3AnalysisLoad().

◆ analyzeAggregate()

static int analyzeAggregate ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 105540 of file sqlite3.c.

105546 {
105547 int i;
105548 NameContext *pNC = pWalker->u.pNC;
105549 Parse *pParse = pNC->pParse;
105550 SrcList *pSrcList = pNC->pSrcList;
105551 AggInfo *pAggInfo = pNC->uNC.pAggInfo;
105552
105553 assert( pNC->ncFlags & NC_UAggInfo );
105554 switch( pExpr->op ){
105555 case TK_AGG_COLUMN:
105556 case TK_COLUMN: {
105557 testcase( pExpr->op==TK_AGG_COLUMN );
105558 testcase( pExpr->op==TK_COLUMN );
105559 /* Check to see if the column is in one of the tables in the FROM
105560 ** clause of the aggregate query */
105561 if( ALWAYS(pSrcList!=0) ){
105562 struct SrcList_item *pItem = pSrcList->a;
105563 for(i=0; i<pSrcList->nSrc; i++, pItem++){
105564 struct AggInfo_col *pCol;
105565 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
105566 if( pExpr->iTable==pItem->iCursor ){
105567 /* If we reach this point, it means that pExpr refers to a table
105568 ** that is in the FROM clause of the aggregate query.
105569 **
105570 ** Make an entry for the column in pAggInfo->aCol[] if there
105571 ** is not an entry there already.
105572 */
105573 int k;
105574 pCol = pAggInfo->aCol;
105575 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
105576 if( pCol->iTable==pExpr->iTable &&
105577 pCol->iColumn==pExpr->iColumn ){
105578 break;
105579 }
105580 }
105581 if( (k>=pAggInfo->nColumn)
105582 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
105583 ){
105584 pCol = &pAggInfo->aCol[k];
105585 pCol->pTab = pExpr->y.pTab;
105586 pCol->iTable = pExpr->iTable;
105587 pCol->iColumn = pExpr->iColumn;
105588 pCol->iMem = ++pParse->nMem;
105589 pCol->iSorterColumn = -1;
105590 pCol->pCExpr = pExpr;
105591 if( pAggInfo->pGroupBy ){
105592 int j, n;
105593 ExprList *pGB = pAggInfo->pGroupBy;
105594 struct ExprList_item *pTerm = pGB->a;
105595 n = pGB->nExpr;
105596 for(j=0; j<n; j++, pTerm++){
105597 Expr *pE = pTerm->pExpr;
105598 if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
105599 pE->iColumn==pExpr->iColumn ){
105600 pCol->iSorterColumn = j;
105601 break;
105602 }
105603 }
105604 }
105605 if( pCol->iSorterColumn<0 ){
105606 pCol->iSorterColumn = pAggInfo->nSortingColumn++;
105607 }
105608 }
105609 /* There is now an entry for pExpr in pAggInfo->aCol[] (either
105610 ** because it was there before or because we just created it).
105611 ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
105612 ** pAggInfo->aCol[] entry.
105613 */
105615 pExpr->pAggInfo = pAggInfo;
105616 pExpr->op = TK_AGG_COLUMN;
105617 pExpr->iAgg = (i16)k;
105618 break;
105619 } /* endif pExpr->iTable==pItem->iCursor */
105620 } /* end loop over pSrcList */
105621 }
105622 return WRC_Prune;
105623 }
105624 case TK_AGG_FUNCTION: {
105625 if( (pNC->ncFlags & NC_InAggFunc)==0
105626 && pWalker->walkerDepth==pExpr->op2
105627 ){
105628 /* Check to see if pExpr is a duplicate of another aggregate
105629 ** function that is already in the pAggInfo structure
105630 */
105631 struct AggInfo_func *pItem = pAggInfo->aFunc;
105632 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
105633 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
105634 break;
105635 }
105636 }
105637 if( i>=pAggInfo->nFunc ){
105638 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
105639 */
105640 u8 enc = ENC(pParse->db);
105641 i = addAggInfoFunc(pParse->db, pAggInfo);
105642 if( i>=0 ){
105643 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105644 pItem = &pAggInfo->aFunc[i];
105645 pItem->pFExpr = pExpr;
105646 pItem->iMem = ++pParse->nMem;
105647 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105648 pItem->pFunc = sqlite3FindFunction(pParse->db,
105649 pExpr->u.zToken,
105650 pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
105651 if( pExpr->flags & EP_Distinct ){
105652 pItem->iDistinct = pParse->nTab++;
105653 }else{
105654 pItem->iDistinct = -1;
105655 }
105656 }
105657 }
105658 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
105659 */
105660 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
105662 pExpr->iAgg = (i16)i;
105663 pExpr->pAggInfo = pAggInfo;
105664 return WRC_Prune;
105665 }else{
#define NC_InAggFunc
Definition sqlite3.c:18389
#define EP_NoReduce
Definition sqlite3.c:18113
SQLITE_PRIVATE FuncDef * sqlite3FindFunction(sqlite3 *, const char *, int, u8, u8)
Definition sqlite3.c:115931
static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo)
Definition sqlite3.c:105507
#define WRC_Prune
Definition sqlite3.c:19138
INT16_TYPE i16
Definition sqlite3.c:14333
#define EP_xIsSelect
Definition sqlite3.c:18071
#define ENC(db)
Definition sqlite3.c:16961
#define NC_UAggInfo
Definition sqlite3.c:18382
#define EP_IntValue
Definition sqlite3.c:18070
static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo)
Definition sqlite3.c:105523
#define EP_Distinct
Definition sqlite3.c:18061
#define ExprSetVVAProperty(E, P)
Definition sqlite3.c:18125
SQLITE_PRIVATE int sqlite3ExprCompare(Parse *, Expr *, Expr *, int)
Definition sqlite3.c:104941
int nFunc
Definition sqlite3.c:17909
int nSortingColumn
Definition sqlite3.c:17888
int nColumn
Definition sqlite3.c:17899
ExprList * pGroupBy
Definition sqlite3.c:17890
u8 op2
Definition sqlite3.c:17996
Table * pTab
Definition sqlite3.c:18043
union Expr::@107 u
union Expr::@108 x
ExprList * pList
Definition sqlite3.c:18017
union Expr::@109 y
u32 flags
Definition sqlite3.c:18003
char * zToken
Definition sqlite3.c:18005
Parse * pParse
Definition sqlite3.c:18350
SrcList * pSrcList
Definition sqlite3.c:18351
union NameContext::@115 uNC
AggInfo * pAggInfo
Definition sqlite3.c:18354
int nTab
Definition sqlite3.c:18697
int nMem
Definition sqlite3.c:18698
int walkerDepth
Definition sqlite3.c:19095
union Walker::@116 u
NameContext * pNC
Definition sqlite3.c:19098

References ExprList::a, SrcList::a, AggInfo::aCol, addAggInfoColumn(), addAggInfoFunc(), AggInfo::aFunc, ALWAYS, Parse::db, ENC, EP_Distinct, EP_IntValue, EP_NoReduce, EP_Reduced, EP_TokenOnly, EP_xIsSelect, ExprHasProperty, ExprSetVVAProperty, Expr::flags, Expr::iAgg, Expr::iColumn, Expr::iTable, NC_InAggFunc, NC_UAggInfo, NameContext::ncFlags, AggInfo::nColumn, ExprList::nExpr, AggInfo::nFunc, Parse::nMem, AggInfo::nSortingColumn, SrcList::nSrc, Parse::nTab, Expr::op, Expr::op2, Expr::pAggInfo, NameContext::pAggInfo, AggInfo::AggInfo_func::pFExpr, AggInfo::pGroupBy, Expr::pList, Walker::pNC, NameContext::pParse, NameContext::pSrcList, AggInfo::AggInfo_col::pTab, Expr::pTab, sqlite3ExprCompare(), sqlite3FindFunction(), testcase, TK_AGG_COLUMN, TK_AGG_FUNCTION, TK_COLUMN, Expr::u, Walker::u, NameContext::uNC, Walker::walkerDepth, WRC_Continue, WRC_Prune, Expr::x, Expr::y, and Expr::zToken.

Referenced by sqlite3ExprAnalyzeAggregates().

◆ analyzeDatabase()

static void analyzeDatabase ( Parse * pParse,
int iDb )
static

Definition at line 108897 of file sqlite3.c.

108903 {
108904 sqlite3 *db = pParse->db;
108905 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
108906 HashElem *k;
108907 int iStatCur;
108908 int iMem;
108909 int iTab;
108910
108911 sqlite3BeginWriteOperation(pParse, 0, iDb);
108912 iStatCur = pParse->nTab;
108913 pParse->nTab += 3;
108914 openStatTable(pParse, iDb, iStatCur, 0, 0);
108915 iMem = pParse->nMem+1;
108916 iTab = pParse->nTab;
108917 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *, int, int)
Definition sqlite3.c:115169
static void openStatTable(Parse *pParse, int iDb, int iStatCur, const char *zWhere, const char *zWhereType)
Definition sqlite3.c:107709
Schema * pSchema
Definition sqlite3.c:16610
Db * aDb
Definition sqlite3.c:16824

Referenced by sqlite3Analyze().

◆ analyzeFilterKeyword()

static int analyzeFilterKeyword ( const unsigned char * z,
int lastToken )
static

Definition at line 159996 of file sqlite3.c.

159996 {
159997 int t = getToken(&z);
159998 if( t==TK_LP || t==TK_ID ) return TK_OVER;
159999 }
160000 return TK_ID;
160001}
#define TK_LP
Definition sqlite3.c:13964
static int getToken(const unsigned char **pz)
Definition sqlite3.c:159932
#define TK_OVER
Definition sqlite3.c:14104
#define TK_ID
Definition sqlite3.c:14001

References getToken(), TK_ID, TK_LP, and TK_OVER.

Referenced by sqlite3RunParser().

◆ analyzeOneTable()

static void analyzeOneTable ( Parse * pParse,
Table * pTab,
Index * pOnlyIdx,
int iStatCur,
int iMem,
int iTab )
static

Definition at line 108525 of file sqlite3.c.

108538 {
108539 sqlite3 *db = pParse->db; /* Database handle */
108540 Index *pIdx; /* An index to being analyzed */
108541 int iIdxCur; /* Cursor open on index being analyzed */
108542 int iTabCur; /* Table cursor */
108543 Vdbe *v; /* The virtual machine being built up */
108544 int i; /* Loop counter */
108545 int jZeroRows = -1; /* Jump from here if number of rows is zero */
108546 int iDb; /* Index of database containing pTab */
108547 u8 needTableCnt = 1; /* True to count the table */
108548 int regNewRowid = iMem++; /* Rowid for the inserted record */
108549 int regStat = iMem++; /* Register to hold StatAccum object */
108550 int regChng = iMem++; /* Index of changed index field */
108551 int regRowid = iMem++; /* Rowid argument passed to stat_push() */
108552 int regTemp = iMem++; /* Temporary use register */
108553 int regTemp2 = iMem++; /* Second temporary use register */
108554 int regTabname = iMem++; /* Register containing table name */
108555 int regIdxname = iMem++; /* Register containing index name */
108556 int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */
108557 int regPrev = iMem; /* MUST BE LAST (see below) */
108558#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
108559 Table *pStat1 = 0;
108560#endif
108561
108562 pParse->nMem = MAX(pParse->nMem, iMem);
108563 v = sqlite3GetVdbe(pParse);
108564 if( v==0 || NEVER(pTab==0) ){
108565 return;
108566 }
108567 if( pTab->tnum==0 ){
108568 /* Do not gather statistics on views or virtual tables */
108569 return;
108570 }
108571 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
108572 /* Do not gather statistics on system tables */
108573 return;
108574 }
108575 assert( sqlite3BtreeHoldsAllMutexes(db) );
108576 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108577 assert( iDb>=0 );
108578 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
108579#ifndef SQLITE_OMIT_AUTHORIZATION
108580 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
108581 db->aDb[iDb].zDbSName ) ){
108582 return;
108583 }
108584#endif
108585
108586#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
108587 if( db->xPreUpdateCallback ){
108588 pStat1 = (Table*)sqlite3DbMallocZero(db, sizeof(Table) + 13);
108589 if( pStat1==0 ) return;
108590 pStat1->zName = (char*)&pStat1[1];
108591 memcpy(pStat1->zName, "sqlite_stat1", 13);
108592 pStat1->nCol = 3;
108593 pStat1->iPKey = -1;
108594 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB);
108595 }
108596#endif
108597
108598 /* Establish a read-lock on the table at the shared-cache level.
108599 ** Open a read-only cursor on the table. Also allocate a cursor number
108600 ** to use for scanning indexes (iIdxCur). No index cursor is opened at
108601 ** this time though. */
108602 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
108603 iTabCur = iTab++;
108604 iIdxCur = iTab++;
108605 pParse->nTab = MAX(pParse->nTab, iTab);
108606 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
108607 sqlite3VdbeLoadString(v, regTabname, pTab->zName);
108608
108609 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
108610 int nCol; /* Number of columns in pIdx. "N" */
108611 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
108612 int addrNextRow; /* Address of "next_row:" */
108613 const char *zIdxName; /* Name of the index */
108614 int nColTest; /* Number of columns to test for changes */
108615
108616 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
108617 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
108618 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){
108619 nCol = pIdx->nKeyCol;
108620 zIdxName = pTab->zName;
108621 nColTest = nCol - 1;
108622 }else{
108623 nCol = pIdx->nColumn;
108624 zIdxName = pIdx->zName;
108625 nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
108626 }
108627
108628 /* Populate the register containing the index name. */
108629 sqlite3VdbeLoadString(v, regIdxname, zIdxName);
108630 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
108631
108632 /*
108633 ** Pseudo-code for loop that calls stat_push():
108634 **
108635 ** Rewind csr
108636 ** if eof(csr) goto end_of_scan;
108637 ** regChng = 0
108638 ** goto chng_addr_0;
108639 **
108640 ** next_row:
108641 ** regChng = 0
108642 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
108643 ** regChng = 1
108644 ** if( idx(1) != regPrev(1) ) goto chng_addr_1
108645 ** ...
108646 ** regChng = N
108647 ** goto chng_addr_N
108648 **
108649 ** chng_addr_0:
108650 ** regPrev(0) = idx(0)
108651 ** chng_addr_1:
108652 ** regPrev(1) = idx(1)
108653 ** ...
108654 **
108655 ** endDistinctTest:
108656 ** regRowid = idx(rowid)
108657 ** stat_push(P, regChng, regRowid)
108658 ** Next csr
108659 ** if !eof(csr) goto next_row;
108660 **
108661 ** end_of_scan:
108662 */
108663
108664 /* Make sure there are enough memory cells allocated to accommodate
108665 ** the regPrev array and a trailing rowid (the rowid slot is required
108666 ** when building a record to insert into the sample column of
108667 ** the sqlite_stat4 table. */
108668 pParse->nMem = MAX(pParse->nMem, regPrev+nColTest);
108669
108670 /* Open a read-only cursor on the index being analyzed. */
108671 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
108672 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
108673 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
108674 VdbeComment((v, "%s", pIdx->zName));
108675
108676 /* Invoke the stat_init() function. The arguments are:
108677 **
108678 ** (1) the number of columns in the index including the rowid
108679 ** (or for a WITHOUT ROWID table, the number of PK columns),
108680 ** (2) the number of columns in the key without the rowid/pk
108681 ** (3) estimated number of rows in the index,
108682 */
108683 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1);
108684 assert( regRowid==regStat+2 );
108685 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid);
108686#ifdef SQLITE_ENABLE_STAT4
108688 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regTemp);
108689 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
108690 VdbeCoverage(v);
108691 }else
108692#endif
108693 {
108694 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
108695 VdbeCoverage(v);
108696 sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, 1);
108697 }
108698 assert( regTemp2==regStat+4 );
108699 sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2);
108700 sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
108701 &statInitFuncdef, 0);
108702
108703 /* Implementation of the following:
108704 **
108705 ** Rewind csr
108706 ** if eof(csr) goto end_of_scan;
108707 ** regChng = 0
108708 ** goto next_push_0;
108709 **
108710 */
108711 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
108712 addrNextRow = sqlite3VdbeCurrentAddr(v);
108713
108714 if( nColTest>0 ){
108715 int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
108716 int *aGotoChng; /* Array of jump instruction addresses */
108717 aGotoChng = sqlite3DbMallocRawNN(db, sizeof(int)*nColTest);
108718 if( aGotoChng==0 ) continue;
108719
108720 /*
108721 ** next_row:
108722 ** regChng = 0
108723 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
108724 ** regChng = 1
108725 ** if( idx(1) != regPrev(1) ) goto chng_addr_1
108726 ** ...
108727 ** regChng = N
108728 ** goto endDistinctTest
108729 */
108731 addrNextRow = sqlite3VdbeCurrentAddr(v);
108732 if( nColTest==1 && pIdx->nKeyCol==1 && IsUniqueIndex(pIdx) ){
108733 /* For a single-column UNIQUE index, once we have found a non-NULL
108734 ** row, we know that all the rest will be distinct, so skip
108735 ** subsequent distinctness tests. */
108736 sqlite3VdbeAddOp2(v, OP_NotNull, regPrev, endDistinctTest);
108737 VdbeCoverage(v);
108738 }
108739 for(i=0; i<nColTest; i++){
108740 char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
108741 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
108742 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
108744 aGotoChng[i] =
108745 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
108747 VdbeCoverage(v);
108748 }
108749 sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
108750 sqlite3VdbeGoto(v, endDistinctTest);
108751
108752
108753 /*
108754 ** chng_addr_0:
108755 ** regPrev(0) = idx(0)
108756 ** chng_addr_1:
108757 ** regPrev(1) = idx(1)
108758 ** ...
108759 */
108760 sqlite3VdbeJumpHere(v, addrNextRow-1);
108761 for(i=0; i<nColTest; i++){
108762 sqlite3VdbeJumpHere(v, aGotoChng[i]);
108763 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
108765 }
108766 sqlite3VdbeResolveLabel(v, endDistinctTest);
108767 sqlite3DbFree(db, aGotoChng);
108768 }
108769
108770 /*
108771 ** chng_addr_N:
108772 ** regRowid = idx(rowid) // STAT4 only
108773 ** stat_push(P, regChng, regRowid) // 3rd parameter STAT4 only
108774 ** Next csr
108775 ** if !eof(csr) goto next_row;
108776 */
108777#ifdef SQLITE_ENABLE_STAT4
108779 assert( regRowid==(regStat+2) );
108780 if( HasRowid(pTab) ){
108781 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
108782 }else{
108783 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
108784 int j, k, regKey;
108785 regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
108786 for(j=0; j<pPk->nKeyCol; j++){
108787 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
108788 assert( k>=0 && k<pIdx->nColumn );
108789 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
108791 }
108792 sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
108793 sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
108794 }
108795 }
108796#endif
108797 assert( regChng==(regStat+1) );
108798 {
108799 sqlite3VdbeAddFunctionCall(pParse, 1, regStat, regTemp, 2+IsStat4,
108800 &statPushFuncdef, 0);
108801 if( db->nAnalysisLimit ){
108802 int j1, j2, j3;
108803 j1 = sqlite3VdbeAddOp1(v, OP_IsNull, regTemp); VdbeCoverage(v);
108804 j2 = sqlite3VdbeAddOp1(v, OP_If, regTemp); VdbeCoverage(v);
108805 j3 = sqlite3VdbeAddOp4Int(v, OP_SeekGT, iIdxCur, 0, regPrev, 1);
108806 VdbeCoverage(v);
108807 sqlite3VdbeJumpHere(v, j1);
108808 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
108809 sqlite3VdbeJumpHere(v, j2);
108810 sqlite3VdbeJumpHere(v, j3);
108811 }else{
108812 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
108813 }
108814 }
108815
108816 /* Add the entry to the stat1 table. */
108817 callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1);
108818 assert( "BBB"[0]==SQLITE_AFF_TEXT );
108819 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
108820 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
108821 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
108822#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
108823 sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE);
108824#endif
108826
108827 /* Add the entries to the stat4 table. */
108828#ifdef SQLITE_ENABLE_STAT4
108829 if( OptimizationEnabled(db, SQLITE_Stat4) && db->nAnalysisLimit==0 ){
108830 int regEq = regStat1;
108831 int regLt = regStat1+1;
108832 int regDLt = regStat1+2;
108833 int regSample = regStat1+3;
108834 int regCol = regStat1+4;
108835 int regSampleRowid = regCol + nCol;
108836 int addrNext;
108837 int addrIsNull;
108838 u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
108839
108840 pParse->nMem = MAX(pParse->nMem, regCol+nCol);
108841
108842 addrNext = sqlite3VdbeCurrentAddr(v);
108843 callStatGet(pParse, regStat, STAT_GET_ROWID, regSampleRowid);
108844 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
108845 VdbeCoverage(v);
108846 callStatGet(pParse, regStat, STAT_GET_NEQ, regEq);
108847 callStatGet(pParse, regStat, STAT_GET_NLT, regLt);
108848 callStatGet(pParse, regStat, STAT_GET_NDLT, regDLt);
108849 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
108850 VdbeCoverage(v);
108851 for(i=0; i<nCol; i++){
108852 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
108853 }
108854 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);
108855 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
108856 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
108857 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
108858 sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext); /* P1==1 for end-of-loop */
108859 sqlite3VdbeJumpHere(v, addrIsNull);
108860 }
108861#endif /* SQLITE_ENABLE_STAT4 */
108862
108863 /* End of analysis */
108864 sqlite3VdbeJumpHere(v, addrRewind);
108865 }
108866
108867
108868 /* Create a single sqlite_stat1 entry containing NULL as the index
108869 ** name and the row count as the content.
108870 */
108871 if( pOnlyIdx==0 && needTableCnt ){
108872 VdbeComment((v, "%s", pTab->zName));
108873 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
108874 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
108875 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
108876 assert( "BBB"[0]==SQLITE_AFF_TEXT );
108877 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
108878 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
108879 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *, int)
Definition sqlite3.c:78296
#define OP_IfNot
Definition sqlite3.c:15586
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *, int)
Definition sqlite3.c:78003
#define OP_OpenRead
Definition sqlite3.c:15662
#define SQLITE_AFF_TEXT
Definition sqlite3.c:17396
#define VdbeCoverage(v)
Definition sqlite3.c:15994
#define OP_SeekGT
Definition sqlite3.c:15591
#define OPFLAG_APPEND
Definition sqlite3.c:18842
#define OP_Rewind
Definition sqlite3.c:15603
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *, int, int, int, int)
Definition sqlite3.c:77966
SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc)
Definition sqlite3.c:117864
#define OP_NotNull
Definition sqlite3.c:15617
#define analyzeVdbeCommentIndexWithColumnName(a, b, c)
Definition sqlite3.c:108518
#define OP_Count
Definition sqlite3.c:15658
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *, Index *)
Definition sqlite3.c:79091
#define OP_IdxRowid
Definition sqlite3.c:15700
#define OP_Noop
Definition sqlite3.c:15739
#define OP_Column
Definition sqlite3.c:15655
#define OP_NotExists
Definition sqlite3.c:15598
#define P4_TABLE
Definition sqlite3.c:15511
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *)
Definition sqlite3.c:78623
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe *, int, int)
Definition sqlite3.c:78006
#define OP_NotFound
Definition sqlite3.c:15595
#define SQLITE_ANALYZE
Definition sqlite3.c:4147
static const FuncDef statInitFuncdef
Definition sqlite3.c:108030
SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index *, i16)
Definition sqlite3.c:111322
#define OptimizationEnabled(db, mask)
Definition sqlite3.c:17064
#define OP_Ne
Definition sqlite3.c:15618
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe *, int, int, int, int, const char *zP4, int)
Definition sqlite3.c:78060
#define P4_COLLSEQ
Definition sqlite3.c:15507
SQLITE_PRIVATE int sqlite3GetTempRange(Parse *, int)
Definition sqlite3.c:105730
SQLITE_PRIVATE Vdbe * sqlite3GetVdbe(Parse *)
Definition sqlite3.c:131442
SQLITE_PRIVATE CollSeq * sqlite3LocateCollSeq(Parse *pParse, const char *zName)
Definition sqlite3.c:115791
SQLITE_PRIVATE int sqlite3AuthCheck(Parse *, int, const char *, const char *, const char *)
Definition sqlite3.c:110310
#define STAT_GET_NDLT
Definition sqlite3.c:108336
#define IsPrimaryKeyIndex(X)
Definition sqlite3.c:17823
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Parse *)
Definition sqlite3.c:78272
#define OP_Integer
Definition sqlite3.c:15635
#define STAT_GET_NLT
Definition sqlite3.c:108335
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *, int addr)
Definition sqlite3.c:78797
#define STAT_GET_STAT1
Definition sqlite3.c:108332
#define OP_Null
Definition sqlite3.c:15638
#define P4_DYNBLOB
Definition sqlite3.c:15524
#define SQLITE_NULLEQ
Definition sqlite3.c:17421
SQLITE_PRIVATE void sqlite3OpenTable(Parse *, int iCur, int iDb, Table *, int)
Definition sqlite3.c:120573
#define OP_IsNull
Definition sqlite3.c:15616
#define STAT_GET_ROWID
Definition sqlite3.c:108333
#define OP_MakeRecord
Definition sqlite3.c:15657
#define IsUniqueIndex(X)
Definition sqlite3.c:17826
#define VdbeComment(X)
Definition sqlite3.c:15933
#define STAT_GET_NEQ
Definition sqlite3.c:108334
static void callStatGet(Parse *pParse, int regStat, int iParam, int regOut)
Definition sqlite3.c:108484
#define OP_Goto
Definition sqlite3.c:15577
#define OP_If
Definition sqlite3.c:15584
SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *, int, int)
Definition sqlite3.c:105744
#define SQLITE_Stat4
Definition sqlite3.c:17052
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse *, Index *, int, int, int)
Definition sqlite3.c:103192
static const FuncDef statPushFuncdef
Definition sqlite3.c:108320
SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *, int)
Definition sqlite3.c:78015
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *, u16 P5)
Definition sqlite3.c:78788
#define MAX(A, B)
Definition sqlite3.c:14266
SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *)
Definition sqlite3.c:128852
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *, int addr, const char *zP4, int N)
Definition sqlite3.c:79028
#define OP_Next
Definition sqlite3.c:15571
#define HasRowid(X)
Definition sqlite3.c:17583
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe *, int, int, int)
Definition sqlite3.c:78009
#define OP_NewRowid
Definition sqlite3.c:15686
SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(Parse *, int, int, int, int, const FuncDef *, int)
Definition sqlite3.c:78084
#define IsStat4
Definition sqlite3.c:107691
SQLITE_PRIVATE void * sqlite3DbMallocRawNN(sqlite3 *, u64)
Definition sqlite3.c:27900
#define OP_Insert
Definition sqlite3.c:15687
SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe *, int, const char *)
Definition sqlite3.c:78022
SQLITE_PRIVATE void sqlite3TableLock(Parse *, int, Pgno, u8, const char *)
Definition sqlite3.c:110437
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe *, int, int, int, int, int)
Definition sqlite3.c:78215
char * zDbSName
Definition sqlite3.c:16606
const char ** azColl
Definition sqlite3.c:17785
Index * pNext
Definition sqlite3.c:17782
unsigned uniqNotNull
Definition sqlite3.c:17795
i16 * aiColumn
Definition sqlite3.c:17778
char * zName
Definition sqlite3.c:17777
Pgno tnum
Definition sqlite3.c:17788
u16 nColumn
Definition sqlite3.c:17791
Schema * pSchema
Definition sqlite3.c:17783
Vdbe * pVdbe
Definition sqlite3.c:18682
i16 nCol
Definition sqlite3.c:17500
Schema * pSchema
Definition sqlite3.c:17517
Pgno tnum
Definition sqlite3.c:17496
Index * pIndex
Definition sqlite3.c:17490
i16 iPKey
Definition sqlite3.c:17499
int nAnalysisLimit
Definition sqlite3.c:16928

References sqlite3::aDb, Index::aiColumn, analyzeVdbeCommentIndexWithColumnName, Index::azColl, callStatGet(), Parse::db, HasRowid, Table::iPKey, IsPrimaryKeyIndex, IsStat4, IsUniqueIndex, MAX, sqlite3::nAnalysisLimit, Table::nCol, Index::nColumn, NEVER, Index::nKeyCol, Parse::nMem, Parse::nTab, OP_Column, OP_Count, OP_Goto, OP_IdxRowid, OP_If, OP_IfNot, OP_Insert, OP_Integer, OP_IsNull, OP_MakeRecord, OP_Ne, OP_NewRowid, OP_Next, OP_Noop, OP_NotExists, OP_NotFound, OP_NotNull, OP_Null, OP_OpenRead, OP_Rewind, OP_SeekGT, OPFLAG_APPEND, OptimizationEnabled, P4_COLLSEQ, P4_DYNBLOB, P4_TABLE, Table::pIndex, Index::pNext, Index::pPartIdxWhere, Table::pSchema, Index::pSchema, Index::pTable, Parse::pVdbe, sqlite3_strlike(), sqlite3AuthCheck(), sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3DbMallocZero(), sqlite3ExprCodeLoadIndexColumn(), sqlite3GetTempRange(), sqlite3GetVdbe(), sqlite3LocateCollSeq(), sqlite3OpenTable(), sqlite3PrimaryKeyIndex(), sqlite3ReleaseTempRange(), sqlite3SchemaToIndex(), sqlite3TableColumnToIndex(), sqlite3TableLock(), sqlite3VdbeAddFunctionCall(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeLoadString(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VdbeSetP4KeyInfo(), SQLITE_AFF_TEXT, SQLITE_ANALYZE, SQLITE_NULLEQ, SQLITE_Stat4, STAT_GET_NDLT, STAT_GET_NEQ, STAT_GET_NLT, STAT_GET_ROWID, STAT_GET_STAT1, statInitFuncdef, statPushFuncdef, Table::tnum, Index::tnum, Index::uniqNotNull, VdbeComment, VdbeCoverage, Db::zDbSName, Table::zName, and Index::zName.

Referenced by analyzeTable().

◆ analyzeOverKeyword()

static int analyzeOverKeyword ( const unsigned char * z,
int lastToken )
static

Definition at line 159989 of file sqlite3.c.

159995 {

Referenced by sqlite3RunParser().

◆ analyzeTable()

static void analyzeTable ( Parse * pParse,
Table * pTab,
Index * pOnlyIdx )
static

Definition at line 108924 of file sqlite3.c.

108930 {
108931 int iDb;
108932 int iStatCur;
108933
108934 assert( pTab!=0 );
108935 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
108936 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
108937 sqlite3BeginWriteOperation(pParse, 0, iDb);
108938 iStatCur = pParse->nTab;
108939 pParse->nTab += 3;
108940 if( pOnlyIdx ){
108941 openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");

References analyzeOneTable(), Parse::db, loadAnalysis(), Parse::nMem, Parse::nTab, openStatTable(), Table::pSchema, sqlite3BeginWriteOperation(), sqlite3SchemaToIndex(), Table::zName, and Index::zName.

Referenced by sqlite3Analyze().

◆ analyzeWindowKeyword()

static int analyzeWindowKeyword ( const unsigned char * z)
static

Definition at line 159981 of file sqlite3.c.

159982 :
159983**
159984** * the previous token was TK_RP, and
159985** * the next token is TK_LP.
159986*/
159987static int analyzeWindowKeyword(const unsigned char *z){
159988 int t;
#define next(ls)
static int analyzeWindowKeyword(const unsigned char *z)
Definition sqlite3.c:159981
#define TK_RP
Definition sqlite3.c:13965

Referenced by sqlite3RunParser().

◆ anotherValidCursor()

static int anotherValidCursor ( BtCursor * pCur)
static

Definition at line 72838 of file sqlite3.c.

72844 {
72845 BtCursor *pOther;
72846 for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){
72847 if( pOther!=pCur
72848 && pOther->eState==CURSOR_VALID
72849 && pOther->pPage==pCur->pPage
BtCursor * pNext
Definition sqlite3.c:63990
BtCursor * pCursor
Definition sqlite3.c:63879

References CURSOR_VALID, BtCursor::eState, BtCursor::pBt, BtShared::pCursor, BtCursor::pNext, BtCursor::pPage, SQLITE_CORRUPT_BKPT, and SQLITE_OK.

Referenced by balance().

◆ apiOomError()

static SQLITE_NOINLINE int apiOomError ( sqlite3 * db)
static

Definition at line 28103 of file sqlite3.c.

Referenced by sqlite3ApiExit().

◆ appendText()

static char * appendText ( char * p,
const char * z )
static

Definition at line 165226 of file sqlite3.c.

Referenced by sqlite3_create_filename().

◆ applyAffinity()

static void applyAffinity ( Mem * pRec,
char affinity,
u8 enc )
static

Definition at line 85601 of file sqlite3.c.

85603 :
85605** No-op. pRec is unchanged.
85606*/
85607static void applyAffinity(
85608 Mem *pRec, /* The value to apply affinity to */
85609 char affinity, /* The affinity to be applied */
85610 u8 enc /* Use this text encoding */
85611){
85612 if( affinity>=SQLITE_AFF_NUMERIC ){
85613 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
85614 || affinity==SQLITE_AFF_NUMERIC );
85615 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
85616 if( (pRec->flags & MEM_Real)==0 ){
85617 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
85618 }else{
85620 }
85621 }
85622 }else if( affinity==SQLITE_AFF_TEXT ){
85623 /* Only attempt the conversion to TEXT if there is an integer or real
85624 ** representation (blob and NULL do not get converted) but no string
85625 ** representation. It would be harmless to repeat the conversion if
85626 ** there is already a string rep, but it is pointless to waste those
85627 ** CPU cycles. */
85628 if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
85629 if( (pRec->flags&(MEM_Real|MEM_Int|MEM_IntReal)) ){
85630 testcase( pRec->flags & MEM_Int );
85631 testcase( pRec->flags & MEM_Real );
85632 testcase( pRec->flags & MEM_IntReal );
#define MEM_Int
Definition sqlite3.c:20950
#define SQLITE_AFF_NONE
Definition sqlite3.c:17394
#define SQLITE_AFF_REAL
Definition sqlite3.c:17399
static void applyNumericAffinity(Mem *pRec, int bTryForInt)
Definition sqlite3.c:85561
#define MEM_Real
Definition sqlite3.c:20951
#define SQLITE_AFF_INTEGER
Definition sqlite3.c:17398
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *)
Definition sqlite3.c:76476
static void applyAffinity(Mem *pRec, char affinity, u8 enc)
Definition sqlite3.c:85601
#define MEM_Str
Definition sqlite3.c:20949
#define SQLITE_AFF_NUMERIC
Definition sqlite3.c:17397
#define MEM_IntReal
Definition sqlite3.c:20953

References applyNumericAffinity(), sqlite3_value::flags, MEM_Int, MEM_IntReal, MEM_Real, MEM_Str, sqlite3VdbeIntegerAffinity(), sqlite3VdbeMemStringify(), SQLITE_AFF_INTEGER, SQLITE_AFF_NUMERIC, SQLITE_AFF_REAL, SQLITE_AFF_TEXT, and testcase.

Referenced by sqlite3VdbeExec().

◆ applyNumericAffinity()

static void applyNumericAffinity ( Mem * pRec,
int bTryForInt )
static

Definition at line 85561 of file sqlite3.c.

85567 {
85568 double rValue;
85569 u8 enc = pRec->enc;
85570 int rc;
85571 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
85572 rc = sqlite3AtoF(pRec->z, &rValue, pRec->n, enc);
85573 if( rc<=0 ) return;
85574 if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
85575 pRec->flags |= MEM_Int;
85576 }else{
85577 pRec->u.r = rValue;
85578 pRec->flags |= MEM_Real;
85579 if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
85580 }
static int alsoAnInt(Mem *pRec, double rValue, i64 *piValue)
Definition sqlite3.c:85537
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *, int, u8)
Definition sqlite3.c:31584
union sqlite3_value::MemValue u

References alsoAnInt(), sqlite3_value::enc, sqlite3_value::flags, sqlite3_value::MemValue::i, MEM_Int, MEM_IntReal, MEM_Real, MEM_Str, sqlite3_value::n, sqlite3_value::MemValue::r, sqlite3AtoF(), sqlite3VdbeIntegerAffinity(), sqlite3_value::u, and sqlite3_value::z.

Referenced by applyAffinity(), sqlite3_value_numeric_type(), and sqlite3VdbeExec().

◆ areDoubleQuotedStringsEnabled()

static int areDoubleQuotedStringsEnabled ( sqlite3 * db,
NameContext * pTopNC )
static

Definition at line 97920 of file sqlite3.c.

97926 {
97927 if( db->init.busy ) return 1; /* Always support for legacy schemas */
97928 if( pTopNC->ncFlags & NC_IsDDL ){
97929 /* Currently parsing a DDL statement */
97930 if( sqlite3WritableSchema(db) && (db->flags & SQLITE_DqsDML)!=0 ){
97931 return 1;
97932 }
#define NC_IsDDL
Definition sqlite3.c:18388
SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3 *)
Definition sqlite3.c:111250
#define SQLITE_DqsDML
Definition sqlite3.c:17009
struct sqlite3::sqlite3InitInfo init
u64 flags
Definition sqlite3.c:16827

Referenced by lookupName().

◆ attachBackupObject()

static void attachBackupObject ( sqlite3_backup * p)
static

Definition at line 75359 of file sqlite3.c.

75365 {
75366 sqlite3_backup **pp;

◆ attachFunc()

static void attachFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 109562 of file sqlite3.c.

109572 {
109573 int i;
109574 int rc = 0;
109575 sqlite3 *db = sqlite3_context_db_handle(context);
109576 const char *zName;
109577 const char *zFile;
109578 char *zPath = 0;
109579 char *zErr = 0;
109580 unsigned int flags;
109581 Db *aNew; /* New array of Db pointers */
109582 Db *pNew; /* Db object for the newly attached database */
109583 char *zErrDyn = 0;
109584 sqlite3_vfs *pVfs;
109585
109586 UNUSED_PARAMETER(NotUsed);
109587 zFile = (const char *)sqlite3_value_text(argv[0]);
109588 zName = (const char *)sqlite3_value_text(argv[1]);
109589 if( zFile==0 ) zFile = "";
109590 if( zName==0 ) zName = "";
109591
109592#ifdef SQLITE_ENABLE_DESERIALIZE
109593# define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb)
109594#else
109595# define REOPEN_AS_MEMDB(db) (0)
109596#endif
109597
109598 if( REOPEN_AS_MEMDB(db) ){
109599 /* This is not a real ATTACH. Instead, this routine is being called
109600 ** from sqlite3_deserialize() to close database db->init.iDb and
109601 ** reopen it as a MemDB */
109602 pVfs = sqlite3_vfs_find("memdb");
109603 if( pVfs==0 ) return;
109604 pNew = &db->aDb[db->init.iDb];
109605 if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt);
109606 pNew->pBt = 0;
109607 pNew->pSchema = 0;
109608 rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB);
109609 }else{
109610 /* This is a real ATTACH
109611 **
109612 ** Check for the following errors:
109613 **
109614 ** * Too many attached databases,
109615 ** * Transaction currently open
109616 ** * Specified database name already being used.
109617 */
109618 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
109619 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
109621 );
109622 goto attach_error;
109623 }
109624 for(i=0; i<db->nDb; i++){
109625 assert( zName );
109626 if( sqlite3DbIsNamed(db, i, zName) ){
109627 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
109628 goto attach_error;
109629 }
109630 }
109631
109632 /* Allocate the new entry in the db->aDb[] array and initialize the schema
109633 ** hash tables.
109634 */
109635 if( db->aDb==db->aDbStatic ){
109636 aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
109637 if( aNew==0 ) return;
109638 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
109639 }else{
109640 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
109641 if( aNew==0 ) return;
109642 }
109643 db->aDb = aNew;
109644 pNew = &db->aDb[db->nDb];
109645 memset(pNew, 0, sizeof(*pNew));
109646
109647 /* Open the database file. If the btree is successfully opened, use
109648 ** it to obtain the database schema. At this point the schema may
109649 ** or may not be initialized.
109650 */
109651 flags = db->openFlags;
109652 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
109653 if( rc!=SQLITE_OK ){
109654 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
109655 sqlite3_result_error(context, zErr, -1);
109656 sqlite3_free(zErr);
109657 return;
109658 }
109659 assert( pVfs );
109660 flags |= SQLITE_OPEN_MAIN_DB;
109661 rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
109662 db->nDb++;
109663 pNew->zDbSName = sqlite3DbStrDup(db, zName);
109664 }
109665 db->noSharedCache = 0;
109666 if( rc==SQLITE_CONSTRAINT ){
109667 rc = SQLITE_ERROR;
109668 zErrDyn = sqlite3MPrintf(db, "database is already attached");
109669 }else if( rc==SQLITE_OK ){
109670 Pager *pPager;
109671 pNew->pSchema = sqlite3SchemaGet(db, pNew->pBt);
109672 if( !pNew->pSchema ){
109673 rc = SQLITE_NOMEM_BKPT;
109674 }else if( pNew->pSchema->file_format && pNew->pSchema->enc!=ENC(db) ){
109675 zErrDyn = sqlite3MPrintf(db,
109676 "attached databases must use the same text encoding as main database");
109677 rc = SQLITE_ERROR;
109678 }
109679 sqlite3BtreeEnter(pNew->pBt);
109680 pPager = sqlite3BtreePager(pNew->pBt);
109683 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
109684#ifndef SQLITE_OMIT_PAGER_PRAGMAS
109687#endif
109688 sqlite3BtreeLeave(pNew->pBt);
109689 }
109691 if( rc==SQLITE_OK && pNew->zDbSName==0 ){
109692 rc = SQLITE_NOMEM_BKPT;
109693 }
109694 sqlite3_free_filename( zPath );
109695
109696 /* If the file was opened successfully, read the schema for the new database.
109697 ** If this fails, or if opening the file failed, then close the file and
109698 ** remove the entry from the db->aDb[] array. i.e. put everything back the
109699 ** way we found it.
109700 */
109701 if( rc==SQLITE_OK ){
109703 db->init.iDb = 0;
109704 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
109705 if( !REOPEN_AS_MEMDB(db) ){
109706 rc = sqlite3Init(db, &zErrDyn);
109707 }
109709 assert( zErrDyn==0 || rc!=SQLITE_OK );
109710 }
109711#ifdef SQLITE_USER_AUTHENTICATION
109712 if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
109713 u8 newAuth = 0;
109714 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
109715 if( newAuth<db->auth.authLevel ){
109716 rc = SQLITE_AUTH_USER;
109717 }
109718 }
109719#endif
109720 if( rc ){
109721 if( !REOPEN_AS_MEMDB(db) ){
109722 int iDb = db->nDb - 1;
109723 assert( iDb>=2 );
109724 if( db->aDb[iDb].pBt ){
109725 sqlite3BtreeClose(db->aDb[iDb].pBt);
109726 db->aDb[iDb].pBt = 0;
109727 db->aDb[iDb].pSchema = 0;
109728 }
109730 db->nDb = iDb;
109731 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
109732 sqlite3OomFault(db);
109733 sqlite3DbFree(db, zErrDyn);
109734 zErrDyn = sqlite3MPrintf(db, "out of memory");
109735 }else if( zErrDyn==0 ){
109736 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
109737 }
109738 }
109739 goto attach_error;
109740 }
109741
109742 return;
109743
109744attach_error:
109745 /* Return an error if we get here */
SQLITE_API sqlite3_vfs * sqlite3_vfs_find(const char *zVfsName)
Definition sqlite3.c:23307
SQLITE_API void sqlite3_free_filename(char *)
Definition sqlite3.c:165277
SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree *, int)
Definition sqlite3.c:67437
SQLITE_PRIVATE char * sqlite3DbStrDup(sqlite3 *, const char *)
Definition sqlite3.c:28018
SQLITE_PRIVATE int sqlite3BtreeOpen(sqlite3_vfs *pVfs, const char *zFilename, sqlite3 *db, Btree **ppBtree, int flags, int vfsFlags)
Definition sqlite3.c:66809
SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int)
Definition sqlite3.c:58913
#define SQLITE_LIMIT_ATTACHED
Definition sqlite3.c:4951
SQLITE_PRIVATE char * sqlite3MPrintf(sqlite3 *, const char *,...)
Definition sqlite3.c:29286
SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *)
Definition sqlite3.c:64378
#define PAGER_SYNCHRONOUS_FULL
Definition sqlite3.c:14851
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *)
Definition sqlite3.c:110989
#define SQLITE_OPEN_MAIN_DB
Definition sqlite3.c:1609
#define REOPEN_AS_MEMDB(db)
SQLITE_PRIVATE void sqlite3BtreeLeave(Btree *)
Definition sqlite3.c:64309
SQLITE_PRIVATE int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName)
Definition sqlite3.c:109540
SQLITE_API sqlite3 * sqlite3_context_db_handle(sqlite3_context *)
Definition sqlite3.c:83794
#define SQLITE_IOERR_NOMEM
Definition sqlite3.c:1534
#define SQLITE_CONSTRAINT
Definition sqlite3.c:1489
SQLITE_API void sqlite3_free(void *)
Definition sqlite3.c:27692
SQLITE_PRIVATE int sqlite3BtreeClose(Btree *)
Definition sqlite3.c:67186
#define SQLITE_DEFAULT_SYNCHRONOUS
Definition sqlite3.c:16592
SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *)
Definition sqlite3.c:64366
#define SQLITE_AUTH_USER
Definition sqlite3.c:1590
#define SQLITE_NOMEM
Definition sqlite3.c:1477
SQLITE_PRIVATE struct Pager * sqlite3BtreePager(Btree *)
Definition sqlite3.c:74095
SQLITE_PRIVATE int sqlite3ParseUri(const char *, const char *, unsigned int *, sqlite3_vfs **, char **, char **)
Definition sqlite3.c:163798
#define PAGER_FLAGS_MASK
Definition sqlite3.c:14857
#define DBFLAG_SchemaKnownOk
Definition sqlite3.c:17032
SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree *, unsigned)
Definition sqlite3.c:67301
SQLITE_PRIVATE Schema * sqlite3SchemaGet(sqlite3 *, Btree *)
Definition sqlite3.c:116055
SQLITE_PRIVATE int sqlite3Init(sqlite3 *, char **)
Definition sqlite3.c:128749
SQLITE_API const unsigned char * sqlite3_value_text(sqlite3_value *)
Definition sqlite3.c:83198
SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *)
Definition sqlite3.c:64237
#define SQLITE_ERROR
Definition sqlite3.c:1471
u8 safety_level
Definition sqlite3.c:16608
Btree * pBt
Definition sqlite3.c:16607
u8 file_format
Definition sqlite3.c:16638
const char * zName
Definition sqlite3.c:2422
int nDb
Definition sqlite3.c:16825
u32 mDbFlags
Definition sqlite3.c:16826
sqlite3_vfs * pVfs
Definition sqlite3.c:16820
u8 noSharedCache
Definition sqlite3.c:16847
unsigned int openFlags
Definition sqlite3.c:16831
Db aDbStatic[2]
Definition sqlite3.c:16926
u8 dfltLockMode
Definition sqlite3.c:16841

References sqlite3::aDb, sqlite3::aDbStatic, sqlite3::aLimit, DBFLAG_SchemaKnownOk, sqlite3::dfltLockMode, Schema::enc, ENC, Schema::file_format, sqlite3::flags, sqlite3::sqlite3InitInfo::iDb, sqlite3::init, sqlite3::mDbFlags, sqlite3::nDb, sqlite3::noSharedCache, sqlite3::openFlags, PAGER_FLAGS_MASK, PAGER_SYNCHRONOUS_FULL, Db::pBt, Db::pSchema, sqlite3::pVfs, REOPEN_AS_MEMDB, Db::safety_level, sqlite3_context_db_handle(), sqlite3_free(), sqlite3_free_filename(), sqlite3_result_error(), sqlite3_result_error_code(), sqlite3_value_text(), sqlite3_vfs_find(), sqlite3BtreeClose(), sqlite3BtreeEnter(), sqlite3BtreeEnterAll(), sqlite3BtreeLeave(), sqlite3BtreeLeaveAll(), sqlite3BtreeOpen(), sqlite3BtreePager(), sqlite3BtreeSecureDelete(), sqlite3BtreeSetPagerFlags(), sqlite3DbFree(), sqlite3DbIsNamed(), sqlite3DbMallocRawNN(), sqlite3DbRealloc(), sqlite3DbStrDup(), sqlite3Init(), sqlite3MPrintf(), sqlite3OomFault(), sqlite3PagerLockingMode(), sqlite3ParseUri(), sqlite3ResetAllSchemasOfConnection(), sqlite3SchemaGet(), SQLITE_AUTH_USER, SQLITE_CONSTRAINT, SQLITE_DEFAULT_SYNCHRONOUS, SQLITE_ERROR, SQLITE_IOERR_NOMEM, SQLITE_LIMIT_ATTACHED, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_MAIN_DB, UNUSED_PARAMETER, Db::zDbSName, sqlite3_vfs::zName, and zName.

Referenced by sqlite3Attach().

◆ autoIncBegin()

static int autoIncBegin ( Parse * pParse,
int iDb,
Table * pTab )
static

Definition at line 120888 of file sqlite3.c.

120898 {
120899 int memId = 0; /* Register holding maximum rowid */
120900 assert( pParse->db->aDb[iDb].pSchema!=0 );
120901 if( (pTab->tabFlags & TF_Autoincrement)!=0
120902 && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0
120903 ){
120904 Parse *pToplevel = sqlite3ParseToplevel(pParse);
120905 AutoincInfo *pInfo;
120906 Table *pSeqTab = pParse->db->aDb[iDb].pSchema->pSeqTab;
120907
120908 /* Verify that the sqlite_sequence table exists and is an ordinary
120909 ** rowid table with exactly two columns.
120910 ** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */
120911 if( pSeqTab==0
120912 || !HasRowid(pSeqTab)
120913 || IsVirtual(pSeqTab)
120914 || pSeqTab->nCol!=2
120915 ){
120916 pParse->nErr++;
120917 pParse->rc = SQLITE_CORRUPT_SEQUENCE;
120918 return 0;
120919 }
120920
120921 pInfo = pToplevel->pAinc;
120922 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
120923 if( pInfo==0 ){
120924 pInfo = sqlite3DbMallocRawNN(pParse->db, sizeof(*pInfo));
120925 if( pInfo==0 ) return 0;
120926 pInfo->pNext = pToplevel->pAinc;
120927 pToplevel->pAinc = pInfo;
120928 pInfo->pTab = pTab;
120929 pInfo->iDb = iDb;
120930 pToplevel->nMem++; /* Register to hold name of table */
120931 pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
#define sqlite3ParseToplevel(p)
Definition sqlite3.c:19787
#define IsVirtual(X)
Definition sqlite3.c:17556
#define DBFLAG_Vacuum
Definition sqlite3.c:17030
#define SQLITE_CORRUPT_SEQUENCE
Definition sqlite3.c:1567
#define TF_Autoincrement
Definition sqlite3.c:17538
Table * pTab
Definition sqlite3.c:18613
AutoincInfo * pNext
Definition sqlite3.c:18612
AutoincInfo * pAinc
Definition sqlite3.c:18717
int rc
Definition sqlite3.c:18683
int nErr
Definition sqlite3.c:18696
Table * pSeqTab
Definition sqlite3.c:16637

References sqlite3::aDb, Parse::db, DBFLAG_Vacuum, HasRowid, AutoincInfo::iDb, IsVirtual, sqlite3::mDbFlags, Table::nCol, Parse::nErr, Parse::nMem, Parse::pAinc, AutoincInfo::pNext, Db::pSchema, Schema::pSeqTab, AutoincInfo::pTab, Parse::rc, AutoincInfo::regCtr, sqlite3DbMallocRawNN(), sqlite3ParseToplevel, SQLITE_CORRUPT_SEQUENCE, Table::tabFlags, and TF_Autoincrement.

Referenced by sqlite3Insert(), and xferOptimization().

◆ autoIncrementEnd()

static SQLITE_NOINLINE void autoIncrementEnd ( Parse * pParse)
static

Definition at line 121011 of file sqlite3.c.

121017 {
121018 AutoincInfo *p;
121019 Vdbe *v = pParse->pVdbe;
121020 sqlite3 *db = pParse->db;
121021
121022 assert( v );
121023 for(p = pParse->pAinc; p; p = p->pNext){
121024 static const int iLn = VDBE_OFFSET_LINENO(2);
121025 static const VdbeOpList autoIncEnd[] = {
121026 /* 0 */ {OP_NotNull, 0, 2, 0},
121027 /* 1 */ {OP_NewRowid, 0, 0, 0},
121028 /* 2 */ {OP_MakeRecord, 0, 2, 0},
121029 /* 3 */ {OP_Insert, 0, 0, 0},
121030 /* 4 */ {OP_Close, 0, 0, 0}
121031 };
121032 VdbeOp *aOp;
121033 Db *pDb = &db->aDb[p->iDb];
121034 int iRec;
121035 int memId = p->regCtr;
121036
121037 iRec = sqlite3GetTempReg(pParse);
121038 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
121039 sqlite3VdbeAddOp3(v, OP_Le, memId+2, sqlite3VdbeCurrentAddr(v)+7, memId);
121040 VdbeCoverage(v);
121041 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
121042 aOp = sqlite3VdbeAddOpList(v, ArraySize(autoIncEnd), autoIncEnd, iLn);
121043 if( aOp==0 ) break;
121044 aOp[0].p1 = memId+1;
121045 aOp[1].p2 = memId+1;
121046 aOp[2].p1 = memId-1;
121047 aOp[2].p3 = iRec;
#define OP_Close
Definition sqlite3.c:15682
#define ArraySize(X)
Definition sqlite3.c:14594
#define OP_OpenWrite
Definition sqlite3.c:15663
SQLITE_PRIVATE int sqlite3GetTempReg(Parse *)
Definition sqlite3.c:105707
#define VDBE_OFFSET_LINENO(x)
Definition sqlite3.c:16001
SQLITE_PRIVATE VdbeOp * sqlite3VdbeAddOpList(Vdbe *, int nOp, VdbeOpList const *aOp, int iLineno)
Definition sqlite3.c:78700
#define OP_Le
Definition sqlite3.c:15621
int p1
Definition sqlite3.c:15438
int p2
Definition sqlite3.c:15439
int p3
Definition sqlite3.c:15440

References sqlite3::aDb, ArraySize, Parse::db, AutoincInfo::iDb, OP_Close, OP_Insert, OP_Le, OP_MakeRecord, OP_NewRowid, OP_NotNull, OP_OpenWrite, VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, Parse::pAinc, AutoincInfo::pNext, Db::pSchema, Schema::pSeqTab, Parse::pVdbe, AutoincInfo::regCtr, sqlite3GetTempReg(), sqlite3OpenTable(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOpList(), sqlite3VdbeCurrentAddr(), VDBE_OFFSET_LINENO, and VdbeCoverage.

◆ autoIncStep()

static void autoIncStep ( Parse * pParse,
int memId,
int regRowid )
static

Definition at line 120998 of file sqlite3.c.

References OP_MemMax, Parse::pVdbe, and sqlite3VdbeAddOp2().

Referenced by sqlite3Insert(), and xferOptimization().

◆ autoVacuumCommit()

static int autoVacuumCommit ( BtShared * pBt)
static

Definition at line 68394 of file sqlite3.c.

68400 {
68401 int rc = SQLITE_OK;
68402 Pager *pPager = pBt->pPager;
68403 VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager); )
68404
68405 assert( sqlite3_mutex_held(pBt->mutex) );
68407 assert(pBt->autoVacuum);
68408 if( !pBt->incrVacuum ){
68409 Pgno nFin; /* Number of pages in database after autovacuuming */
68410 Pgno nFree; /* Number of pages on the freelist initially */
68411 Pgno iFree; /* The next page to be freed */
68412 Pgno nOrig; /* Database size before freeing */
68413
68414 nOrig = btreePagecount(pBt);
68415 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
68416 /* It is not possible to create a database for which the final page
68417 ** is either a pointer-map page or the pending-byte page. If one
68418 ** is encountered, this indicates corruption.
68419 */
68420 return SQLITE_CORRUPT_BKPT;
68421 }
68422
68423 nFree = get4byte(&pBt->pPage1->aData[36]);
68424 nFin = finalDbSize(pBt, nOrig, nFree);
68425 if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT;
68426 if( nFin<nOrig ){
68427 rc = saveAllCursors(pBt, 0, 0);
68428 }
68429 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
68430 rc = incrVacuumStep(pBt, nFin, iFree, 1);
68431 }
68432 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
68433 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
68434 put4byte(&pBt->pPage1->aData[32], 0);
68435 put4byte(&pBt->pPage1->aData[36], 0);
68436 put4byte(&pBt->pPage1->aData[28], nFin);
68437 pBt->bDoTruncate = 1;
68438 pBt->nPage = nFin;
68439 }
68440 if( rc!=SQLITE_OK ){
68441 sqlite3PagerRollback(pPager);
static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit)
Definition sqlite3.c:68230
static Pgno finalDbSize(BtShared *pBt, Pgno nOrig, Pgno nFree)
Definition sqlite3.c:68326
#define VVA_ONLY(X)
Definition sqlite3.c:13711
static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept)
Definition sqlite3.c:65224
static void invalidateAllOverflowCache(BtShared *pBt)
Definition sqlite3.c:64987
#define SQLITE_DONE
Definition sqlite3.c:1500
SQLITE_PRIVATE int sqlite3PagerRollback(Pager *)
Definition sqlite3.c:58360
u8 incrVacuum
Definition sqlite3.c:63884

References MemPage::aData, BtShared::autoVacuum, BtShared::bDoTruncate, btreePagecount(), finalDbSize(), get4byte, BtShared::incrVacuum, incrVacuumStep(), invalidateAllOverflowCache(), BtShared::mutex, BtShared::nPage, MemPage::pDbPage, PENDING_BYTE_PAGE, BtShared::pPage1, BtShared::pPager, PTRMAP_ISPAGE, put4byte, saveAllCursors(), sqlite3_mutex_held(), sqlite3PagerRollback(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_DONE, SQLITE_OK, and VVA_ONLY.

Referenced by sqlite3BtreeCommitPhaseOne().

◆ avgFinalize()

static void avgFinalize ( sqlite3_context * context)
static

Definition at line 118630 of file sqlite3.c.

118631 {
118632 sqlite3_result_int64(context, p->iSum);
118633 }
118634 }
118635}
118636static void avgFinalize(sqlite3_context *context){
static void avgFinalize(sqlite3_context *context)
Definition sqlite3.c:118630

Referenced by sqlite3RegisterBuiltinFunctions().

◆ backupOnePage()

static int backupOnePage ( sqlite3_backup * p,
Pgno iSrcPg,
const u8 * zSrcData,
int bUpdate )
static

Definition at line 75277 of file sqlite3.c.

75288 {
75289 Pager * const pDestPager = sqlite3BtreePager(p->pDest);
75290 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc);
75291 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest);
75292 const int nCopy = MIN(nSrcPgsz, nDestPgsz);
75293 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
75294 int rc = SQLITE_OK;
75295 i64 iOff;
75296
75297 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
75298 assert( p->bDestLocked );
75299 assert( !isFatalError(p->rc) );
75300 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
75301 assert( zSrcData );
75302
75303 /* Catch the case where the destination is an in-memory database and the
75304 ** page sizes of the source and destination differ.
75305 */
75306 if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){
75307 rc = SQLITE_READONLY;
75308 }
75309
75310 /* This loop runs once for each destination page spanned by the source
75311 ** page. For each iteration, variable iOff is set to the byte offset
75312 ** of the destination page.
75313 */
75314 for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
75315 DbPage *pDestPg = 0;
75316 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
75317 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
75318 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
75319 && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
75320 ){
75321 const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
75322 u8 *zDestData = sqlite3PagerGetData(pDestPg);
75323 u8 *zOut = &zDestData[iOff%nDestPgsz];
75324
75325 /* Copy the data from the source page into the destination page.
75326 ** Then clear the Btree layer MemPage.isInit flag. Both this module
75327 ** and the pager code use this trick (clearing the first byte
75328 ** of the page 'extra' space to invalidate the Btree layers
75329 ** cached parse of the page). MemPage.isInit is marked
75330 ** "MUST BE FIRST" for this purpose.
75331 */
75332 memcpy(zOut, zIn, nCopy);
75333 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
75334 if( iOff==0 && bUpdate==0 ){
75336 }
static int isFatalError(int rc)
Definition sqlite3.c:75268
#define SQLITE_READONLY
Definition sqlite3.c:1478
SQLITE_PRIVATE Pgno sqlite3BtreeLastPage(Btree *)
Definition sqlite3.c:66621
SQLITE_PRIVATE void * sqlite3PagerGetExtra(DbPage *)
Definition sqlite3.c:58899
SQLITE_PRIVATE void sqlite3Put4byte(u8 *, u32)
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree *)
Definition sqlite3.c:67365
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *)
Definition sqlite3.c:58497
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p)
Definition sqlite3.c:67380
BtShared * pBt
Definition sqlite3.c:63815
Btree * pDest
Definition sqlite3.c:75073

References sqlite3_backup::bDestLocked, isFatalError(), MIN, Btree::pBt, sqlite3_backup::pDest, PENDING_BYTE_PAGE, sqlite3_backup::pSrc, sqlite3_backup::rc, sqlite3BtreeGetPageSize(), sqlite3BtreeGetReserveNoMutex(), sqlite3BtreeLastPage(), sqlite3BtreePager(), sqlite3PagerGet(), sqlite3PagerGetData(), sqlite3PagerGetExtra(), sqlite3PagerIsMemdb(), sqlite3PagerUnref(), sqlite3PagerWrite(), sqlite3Put4byte(), SQLITE_OK, and SQLITE_READONLY.

Referenced by backupUpdate().

◆ backupTruncateFile()

static int backupTruncateFile ( sqlite3_file * pFile,
i64 iSize )
static

Definition at line 75346 of file sqlite3.c.

75352 {
75353 i64 iCurrent;

References sqlite3OsFileSize(), sqlite3OsTruncate(), and SQLITE_OK.

◆ backupUpdate()

static SQLITE_NOINLINE void backupUpdate ( sqlite3_backup * p,
Pgno iPage,
const u8 * aData )
static

Definition at line 75715 of file sqlite3.c.

75725 {
75726 assert( p!=0 );
75727 do{
75728 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
75729 if( !isFatalError(p->rc) && iPage<p->iNext ){
75730 /* The backup process p has already copied page iPage. But now it
75731 ** has been modified by a transaction on the source pager. Copy
75732 ** the new data into the backup.
75733 */
75734 int rc;
75735 assert( p->pDestDb );
75737 rc = backupOnePage(p, iPage, aData, 1);
75739 assert( rc!=SQLITE_BUSY && rc!=SQLITE_LOCKED );
SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *)
Definition sqlite3.c:25954
#define SQLITE_BUSY
Definition sqlite3.c:1475
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *)
Definition sqlite3.c:25980
static int backupOnePage(sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData, int bUpdate)
Definition sqlite3.c:75277
#define SQLITE_LOCKED
Definition sqlite3.c:1476
sqlite3 * pDestDb
Definition sqlite3.c:75072
sqlite3_mutex * mutex
Definition sqlite3.c:16823

References backupOnePage(), isFatalError(), sqlite3::mutex, BtShared::mutex, Btree::pBt, sqlite3_backup::pDestDb, sqlite3_backup::pSrc, sqlite3_backup::rc, sqlite3_mutex_enter(), sqlite3_mutex_held(), sqlite3_mutex_leave(), SQLITE_BUSY, and SQLITE_LOCKED.

◆ balance()

static int balance ( BtCursor * pCur)
static

Definition at line 72861 of file sqlite3.c.

72861 :
72862**
72863** balance_quick()
72864** balance_deeper()
72865** balance_nonroot()
72866*/
72867static int balance(BtCursor *pCur){
72868 int rc = SQLITE_OK;
72869 const int nMin = pCur->pBt->usableSize * 2 / 3;
72870 u8 aBalanceQuickSpace[13];
72871 u8 *pFree = 0;
72872
72873 VVA_ONLY( int balance_quick_called = 0 );
72874 VVA_ONLY( int balance_deeper_called = 0 );
72875
72876 do {
72877 int iPage;
72878 MemPage *pPage = pCur->pPage;
72879
72880 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
72881 if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
72882 break;
72883 }else if( (iPage = pCur->iPage)==0 ){
72884 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
72885 /* The root page of the b-tree is overfull. In this case call the
72886 ** balance_deeper() function to create a new child for the root-page
72887 ** and copy the current contents of the root-page to it. The
72888 ** next iteration of the do-loop will balance the child page.
72889 */
72890 assert( balance_deeper_called==0 );
72891 VVA_ONLY( balance_deeper_called++ );
72892 rc = balance_deeper(pPage, &pCur->apPage[1]);
72893 if( rc==SQLITE_OK ){
72894 pCur->iPage = 1;
72895 pCur->ix = 0;
72896 pCur->aiIdx[0] = 0;
72897 pCur->apPage[0] = pPage;
72898 pCur->pPage = pCur->apPage[1];
72899 assert( pCur->pPage->nOverflow );
72900 }
72901 }else{
72902 break;
72903 }
72904 }else{
72905 MemPage * const pParent = pCur->apPage[iPage-1];
72906 int const iIdx = pCur->aiIdx[iPage-1];
72907
72908 rc = sqlite3PagerWrite(pParent->pDbPage);
72909 if( rc==SQLITE_OK && pParent->nFree<0 ){
72910 rc = btreeComputeFreeSpace(pParent);
72911 }
72912 if( rc==SQLITE_OK ){
72913#ifndef SQLITE_OMIT_QUICKBALANCE
72914 if( pPage->intKeyLeaf
72915 && pPage->nOverflow==1
72916 && pPage->aiOvfl[0]==pPage->nCell
72917 && pParent->pgno!=1
72918 && pParent->nCell==iIdx
72919 ){
72920 /* Call balance_quick() to create a new sibling of pPage on which
72921 ** to store the overflow cell. balance_quick() inserts a new cell
72922 ** into pParent, which may cause pParent overflow. If this
72923 ** happens, the next iteration of the do-loop will balance pParent
72924 ** use either balance_nonroot() or balance_deeper(). Until this
72925 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
72926 ** buffer.
72927 **
72928 ** The purpose of the following assert() is to check that only a
72929 ** single call to balance_quick() is made for each call to this
72930 ** function. If this were not verified, a subtle bug involving reuse
72931 ** of the aBalanceQuickSpace[] might sneak in.
72932 */
72933 assert( balance_quick_called==0 );
72934 VVA_ONLY( balance_quick_called++ );
72935 rc = balance_quick(pParent, pPage, aBalanceQuickSpace);
72936 }else
72937#endif
72938 {
72939 /* In this case, call balance_nonroot() to redistribute cells
72940 ** between pPage and up to 2 of its sibling pages. This involves
72941 ** modifying the contents of pParent, which may cause pParent to
72942 ** become overfull or underfull. The next iteration of the do-loop
72943 ** will balance the parent page to correct this.
72944 **
72945 ** If the parent page becomes overfull, the overflow cell or cells
72946 ** are stored in the pSpace buffer allocated immediately below.
72947 ** A subsequent iteration of the do-loop will deal with this by
72948 ** calling balance_nonroot() (balance_deeper() may be called first,
72949 ** but it doesn't deal with overflow cells - just moves them to a
72950 ** different page). Once this subsequent call to balance_nonroot()
72951 ** has completed, it is safe to release the pSpace buffer used by
72952 ** the previous call, as the overflow cell data will have been
72953 ** copied either into the body of a database page or into the new
72954 ** pSpace buffer passed to the latter call to balance_nonroot().
72955 */
72956 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
72957 rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1,
72958 pCur->hints&BTREE_BULKLOAD);
72959 if( pFree ){
72960 /* If pFree is not NULL, it points to the pSpace buffer used
72961 ** by a previous call to balance_nonroot(). Its contents are
72962 ** now stored either on real database pages or within the
72963 ** new pSpace buffer, so it may be safely freed here. */
72964 sqlite3PageFree(pFree);
72965 }
72966
72967 /* The pSpace buffer will be freed after the next call to
72968 ** balance_nonroot(), or just before this function returns, whichever
72969 ** comes first. */
72970 pFree = pSpace;
72971 }
72972 }
72973
72974 pPage->nOverflow = 0;
72975
72976 /* The next iteration of the do-loop balances the parent page. */
72977 releasePage(pPage);
72978 pCur->iPage--;
72979 assert( pCur->iPage>=0 );
72980 pCur->pPage = pCur->apPage[pCur->iPage];
72981 }
72982 }while( rc==SQLITE_OK );
static int anotherValidCursor(BtCursor *pCur)
Definition sqlite3.c:72838
static int balance(BtCursor *pCur)
Definition sqlite3.c:72861
static int btreeComputeFreeSpace(MemPage *pPage)
Definition sqlite3.c:66345
static int balance_nonroot(MemPage *pParent, int iParentIdx, u8 *aOvflSpace, int isRoot, int bBulk)
Definition sqlite3.c:71994
SQLITE_PRIVATE void sqlite3PageFree(void *)
Definition sqlite3.c:50260
static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace)
Definition sqlite3.c:71757
static int balance_deeper(MemPage *pRoot, MemPage **ppChild)
Definition sqlite3.c:72780
#define BTREE_BULKLOAD
Definition sqlite3.c:15194
u16 aiIdx[BTCURSOR_MAX_DEPTH-1]
Definition sqlite3.c:63997
MemPage * apPage[BTCURSOR_MAX_DEPTH-1]
Definition sqlite3.c:64000
u16 aiOvfl[4]
Definition sqlite3.c:63761
u8 intKeyLeaf
Definition sqlite3.c:63746

References BtCursor::aiIdx, MemPage::aiOvfl, anotherValidCursor(), BtCursor::apPage, balance_deeper(), balance_nonroot(), balance_quick(), BTREE_BULKLOAD, btreeComputeFreeSpace(), BtCursor::hints, MemPage::intKeyLeaf, BtCursor::iPage, BtCursor::ix, MemPage::nCell, NEVER, MemPage::nFree, MemPage::nOverflow, BtShared::pageSize, BtCursor::pBt, MemPage::pDbPage, MemPage::pgno, BtCursor::pPage, releasePage(), sqlite3PageFree(), sqlite3PageMalloc(), sqlite3PagerWrite(), SQLITE_OK, BtShared::usableSize, and VVA_ONLY.

Referenced by sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ balance_deeper()

static int balance_deeper ( MemPage * pRoot,
MemPage ** ppChild )
static

Definition at line 72780 of file sqlite3.c.

72786 {
72787 int rc; /* Return value from subprocedures */
72788 MemPage *pChild = 0; /* Pointer to a new child page */
72789 Pgno pgnoChild = 0; /* Page number of the new child page */
72790 BtShared *pBt = pRoot->pBt; /* The BTree */
72791
72792 assert( pRoot->nOverflow>0 );
72793 assert( sqlite3_mutex_held(pBt->mutex) );
72794
72795 /* Make pRoot, the root page of the b-tree, writable. Allocate a new
72796 ** page that will become the new right-child of pPage. Copy the contents
72797 ** of the node stored on pRoot into the new child page.
72798 */
72799 rc = sqlite3PagerWrite(pRoot->pDbPage);
72800 if( rc==SQLITE_OK ){
72801 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
72802 copyNodeContent(pRoot, pChild, &rc);
72803 if( ISAUTOVACUUM ){
72804 ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
72805 }
72806 }
72807 if( rc ){
72808 *ppChild = 0;
72809 releasePage(pChild);
72810 return rc;
72811 }
72812 assert( sqlite3PagerIswriteable(pChild->pDbPage) );
72813 assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
72814 assert( pChild->nCell==pRoot->nCell || CORRUPT_DB );
72815
72816 TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
72817
72818 /* Copy the overflow cells from pRoot to pChild */
72819 memcpy(pChild->aiOvfl, pRoot->aiOvfl,
72820 pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
72821 memcpy(pChild->apOvfl, pRoot->apOvfl,
72822 pRoot->nOverflow*sizeof(pRoot->apOvfl[0]));
72823 pChild->nOverflow = pRoot->nOverflow;
72824
72825 /* Zero the contents of pRoot. Then install pChild as the right-child. */
#define PTRMAP_BTREE
Definition sqlite3.c:64109
static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC)
Definition sqlite3.c:65463
#define ISAUTOVACUUM
Definition sqlite3.c:64127
static void copyNodeContent(MemPage *pFrom, MemPage *pTo, int *pRC)
Definition sqlite3.c:71912
static int allocateBtreePage(BtShared *, MemPage **, Pgno *, Pgno, u8)
Definition sqlite3.c:70389
u8 * apOvfl[4]
Definition sqlite3.c:63763

References MemPage::aData, MemPage::aiOvfl, allocateBtreePage(), MemPage::apOvfl, copyNodeContent(), CORRUPT_DB, MemPage::hdrOffset, ISAUTOVACUUM, BtShared::mutex, MemPage::nCell, MemPage::nOverflow, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, PTF_LEAF, PTRMAP_BTREE, ptrmapPut(), put4byte, releasePage(), sqlite3_mutex_held(), sqlite3PagerWrite(), SQLITE_OK, TRACE, and zeroPage().

Referenced by balance().

◆ balance_nonroot()

static int balance_nonroot ( MemPage * pParent,
int iParentIdx,
u8 * aOvflSpace,
int isRoot,
int bBulk )
static

Definition at line 71994 of file sqlite3.c.

72006 {
72007 BtShared *pBt; /* The whole database */
72008 int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
72009 int nNew = 0; /* Number of pages in apNew[] */
72010 int nOld; /* Number of pages in apOld[] */
72011 int i, j, k; /* Loop counters */
72012 int nxDiv; /* Next divider slot in pParent->aCell[] */
72013 int rc = SQLITE_OK; /* The return code */
72014 u16 leafCorrection; /* 4 if pPage is a leaf. 0 if not */
72015 int leafData; /* True if pPage is a leaf of a LEAFDATA tree */
72016 int usableSpace; /* Bytes in pPage beyond the header */
72017 int pageFlags; /* Value of pPage->aData[0] */
72018 int iSpace1 = 0; /* First unused byte of aSpace1[] */
72019 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
72020 int szScratch; /* Size of scratch memory requested */
72021 MemPage *apOld[NB]; /* pPage and up to two siblings */
72022 MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
72023 u8 *pRight; /* Location in parent of right-sibling pointer */
72024 u8 *apDiv[NB-1]; /* Divider cells in pParent */
72025 int cntNew[NB+2]; /* Index in b.paCell[] of cell after i-th page */
72026 int cntOld[NB+2]; /* Old index in b.apCell[] */
72027 int szNew[NB+2]; /* Combined size of cells placed on i-th page */
72028 u8 *aSpace1; /* Space for copies of dividers cells */
72029 Pgno pgno; /* Temp var to store a page number in */
72030 u8 abDone[NB+2]; /* True after i'th new page is populated */
72031 Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
72032 Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
72033 u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
72034 CellArray b; /* Parsed information on cells being balanced */
72035
72036 memset(abDone, 0, sizeof(abDone));
72037 b.nCell = 0;
72038 b.apCell = 0;
72039 pBt = pParent->pBt;
72040 assert( sqlite3_mutex_held(pBt->mutex) );
72041 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
72042
72043 /* At this point pParent may have at most one overflow cell. And if
72044 ** this overflow cell is present, it must be the cell with
72045 ** index iParentIdx. This scenario comes about when this function
72046 ** is called (indirectly) from sqlite3BtreeDelete().
72047 */
72048 assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
72049 assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
72050
72051 if( !aOvflSpace ){
72052 return SQLITE_NOMEM_BKPT;
72053 }
72054 assert( pParent->nFree>=0 );
72055
72056 /* Find the sibling pages to balance. Also locate the cells in pParent
72057 ** that divide the siblings. An attempt is made to find NN siblings on
72058 ** either side of pPage. More siblings are taken from one side, however,
72059 ** if there are fewer than NN siblings on the other side. If pParent
72060 ** has NB or fewer children then all children of pParent are taken.
72061 **
72062 ** This loop also drops the divider cells from the parent page. This
72063 ** way, the remainder of the function does not have to deal with any
72064 ** overflow cells in the parent page, since if any existed they will
72065 ** have already been removed.
72066 */
72067 i = pParent->nOverflow + pParent->nCell;
72068 if( i<2 ){
72069 nxDiv = 0;
72070 }else{
72071 assert( bBulk==0 || bBulk==1 );
72072 if( iParentIdx==0 ){
72073 nxDiv = 0;
72074 }else if( iParentIdx==i ){
72075 nxDiv = i-2+bBulk;
72076 }else{
72077 nxDiv = iParentIdx-1;
72078 }
72079 i = 2-bBulk;
72080 }
72081 nOld = i+1;
72082 if( (i+nxDiv-pParent->nOverflow)==pParent->nCell ){
72083 pRight = &pParent->aData[pParent->hdrOffset+8];
72084 }else{
72085 pRight = findCell(pParent, i+nxDiv-pParent->nOverflow);
72086 }
72087 pgno = get4byte(pRight);
72088 while( 1 ){
72089 rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
72090 if( rc ){
72091 memset(apOld, 0, (i+1)*sizeof(MemPage*));
72092 goto balance_cleanup;
72093 }
72094 if( apOld[i]->nFree<0 ){
72095 rc = btreeComputeFreeSpace(apOld[i]);
72096 if( rc ){
72097 memset(apOld, 0, (i)*sizeof(MemPage*));
72098 goto balance_cleanup;
72099 }
72100 }
72101 if( (i--)==0 ) break;
72102
72103 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
72104 apDiv[i] = pParent->apOvfl[0];
72105 pgno = get4byte(apDiv[i]);
72106 szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
72107 pParent->nOverflow = 0;
72108 }else{
72109 apDiv[i] = findCell(pParent, i+nxDiv-pParent->nOverflow);
72110 pgno = get4byte(apDiv[i]);
72111 szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
72112
72113 /* Drop the cell from the parent page. apDiv[i] still points to
72114 ** the cell within the parent, even though it has been dropped.
72115 ** This is safe because dropping a cell only overwrites the first
72116 ** four bytes of it, and this function does not need the first
72117 ** four bytes of the divider cell. So the pointer is safe to use
72118 ** later on.
72119 **
72120 ** But not if we are in secure-delete mode. In secure-delete mode,
72121 ** the dropCell() routine will overwrite the entire cell with zeroes.
72122 ** In this case, temporarily copy the cell into the aOvflSpace[]
72123 ** buffer. It will be copied out again as soon as the aSpace[] buffer
72124 ** is allocated. */
72125 if( pBt->btsFlags & BTS_FAST_SECURE ){
72126 int iOff;
72127
72128 iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
72129 if( (iOff+szNew[i])>(int)pBt->usableSize ){
72131 memset(apOld, 0, (i+1)*sizeof(MemPage*));
72132 goto balance_cleanup;
72133 }else{
72134 memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]);
72135 apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData];
72136 }
72137 }
72138 dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc);
72139 }
72140 }
72141
72142 /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
72143 ** alignment */
72144 nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
72145 nMaxCells = (nMaxCells + 3)&~3;
72146
72147 /*
72148 ** Allocate space for memory structures
72149 */
72150 szScratch =
72151 nMaxCells*sizeof(u8*) /* b.apCell */
72152 + nMaxCells*sizeof(u16) /* b.szCell */
72153 + pBt->pageSize; /* aSpace1 */
72154
72155 assert( szScratch<=7*(int)pBt->pageSize );
72156 b.apCell = sqlite3StackAllocRaw(0, szScratch );
72157 if( b.apCell==0 ){
72158 rc = SQLITE_NOMEM_BKPT;
72159 goto balance_cleanup;
72160 }
72161 b.szCell = (u16*)&b.apCell[nMaxCells];
72162 aSpace1 = (u8*)&b.szCell[nMaxCells];
72163 assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
72164
72165 /*
72166 ** Load pointers to all cells on sibling pages and the divider cells
72167 ** into the local b.apCell[] array. Make copies of the divider cells
72168 ** into space obtained from aSpace1[]. The divider cells have already
72169 ** been removed from pParent.
72170 **
72171 ** If the siblings are on leaf pages, then the child pointers of the
72172 ** divider cells are stripped from the cells before they are copied
72173 ** into aSpace1[]. In this way, all cells in b.apCell[] are without
72174 ** child pointers. If siblings are not leaves, then all cell in
72175 ** b.apCell[] include child pointers. Either way, all cells in b.apCell[]
72176 ** are alike.
72177 **
72178 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
72179 ** leafData: 1 if pPage holds key+data and pParent holds only keys.
72180 */
72181 b.pRef = apOld[0];
72182 leafCorrection = b.pRef->leaf*4;
72183 leafData = b.pRef->intKeyLeaf;
72184 for(i=0; i<nOld; i++){
72185 MemPage *pOld = apOld[i];
72186 int limit = pOld->nCell;
72187 u8 *aData = pOld->aData;
72188 u16 maskPage = pOld->maskPage;
72189 u8 *piCell = aData + pOld->cellOffset;
72190 u8 *piEnd;
72191 VVA_ONLY( int nCellAtStart = b.nCell; )
72192
72193 /* Verify that all sibling pages are of the same "type" (table-leaf,
72194 ** table-interior, index-leaf, or index-interior).
72195 */
72196 if( pOld->aData[0]!=apOld[0]->aData[0] ){
72198 goto balance_cleanup;
72199 }
72200
72201 /* Load b.apCell[] with pointers to all cells in pOld. If pOld
72202 ** contains overflow cells, include them in the b.apCell[] array
72203 ** in the correct spot.
72204 **
72205 ** Note that when there are multiple overflow cells, it is always the
72206 ** case that they are sequential and adjacent. This invariant arises
72207 ** because multiple overflows can only occurs when inserting divider
72208 ** cells into a parent on a prior balance, and divider cells are always
72209 ** adjacent and are inserted in order. There is an assert() tagged
72210 ** with "NOTE 1" in the overflow cell insertion loop to prove this
72211 ** invariant.
72212 **
72213 ** This must be done in advance. Once the balance starts, the cell
72214 ** offset section of the btree page will be overwritten and we will no
72215 ** long be able to find the cells if a pointer to each cell is not saved
72216 ** first.
72217 */
72218 memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
72219 if( pOld->nOverflow>0 ){
72220 if( NEVER(limit<pOld->aiOvfl[0]) ){
72222 goto balance_cleanup;
72223 }
72224 limit = pOld->aiOvfl[0];
72225 for(j=0; j<limit; j++){
72226 b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
72227 piCell += 2;
72228 b.nCell++;
72229 }
72230 for(k=0; k<pOld->nOverflow; k++){
72231 assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
72232 b.apCell[b.nCell] = pOld->apOvfl[k];
72233 b.nCell++;
72234 }
72235 }
72236 piEnd = aData + pOld->cellOffset + 2*pOld->nCell;
72237 while( piCell<piEnd ){
72238 assert( b.nCell<nMaxCells );
72239 b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
72240 piCell += 2;
72241 b.nCell++;
72242 }
72243 assert( (b.nCell-nCellAtStart)==(pOld->nCell+pOld->nOverflow) );
72244
72245 cntOld[i] = b.nCell;
72246 if( i<nOld-1 && !leafData){
72247 u16 sz = (u16)szNew[i];
72248 u8 *pTemp;
72249 assert( b.nCell<nMaxCells );
72250 b.szCell[b.nCell] = sz;
72251 pTemp = &aSpace1[iSpace1];
72252 iSpace1 += sz;
72253 assert( sz<=pBt->maxLocal+23 );
72254 assert( iSpace1 <= (int)pBt->pageSize );
72255 memcpy(pTemp, apDiv[i], sz);
72256 b.apCell[b.nCell] = pTemp+leafCorrection;
72257 assert( leafCorrection==0 || leafCorrection==4 );
72258 b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection;
72259 if( !pOld->leaf ){
72260 assert( leafCorrection==0 );
72261 assert( pOld->hdrOffset==0 );
72262 /* The right pointer of the child page pOld becomes the left
72263 ** pointer of the divider cell */
72264 memcpy(b.apCell[b.nCell], &pOld->aData[8], 4);
72265 }else{
72266 assert( leafCorrection==4 );
72267 while( b.szCell[b.nCell]<4 ){
72268 /* Do not allow any cells smaller than 4 bytes. If a smaller cell
72269 ** does exist, pad it with 0x00 bytes. */
72270 assert( b.szCell[b.nCell]==3 || CORRUPT_DB );
72271 assert( b.apCell[b.nCell]==&aSpace1[iSpace1-3] || CORRUPT_DB );
72272 aSpace1[iSpace1++] = 0x00;
72273 b.szCell[b.nCell]++;
72274 }
72275 }
72276 b.nCell++;
72277 }
72278 }
72279
72280 /*
72281 ** Figure out the number of pages needed to hold all b.nCell cells.
72282 ** Store this number in "k". Also compute szNew[] which is the total
72283 ** size of all cells on the i-th page and cntNew[] which is the index
72284 ** in b.apCell[] of the cell that divides page i from page i+1.
72285 ** cntNew[k] should equal b.nCell.
72286 **
72287 ** Values computed by this block:
72288 **
72289 ** k: The total number of sibling pages
72290 ** szNew[i]: Spaced used on the i-th sibling page.
72291 ** cntNew[i]: Index in b.apCell[] and b.szCell[] for the first cell to
72292 ** the right of the i-th sibling page.
72293 ** usableSpace: Number of bytes of space available on each sibling.
72294 **
72295 */
72296 usableSpace = pBt->usableSize - 12 + leafCorrection;
72297 for(i=k=0; i<nOld; i++, k++){
72298 MemPage *p = apOld[i];
72299 b.apEnd[k] = p->aDataEnd;
72300 b.ixNx[k] = cntOld[i];
72301 if( k && b.ixNx[k]==b.ixNx[k-1] ){
72302 k--; /* Omit b.ixNx[] entry for child pages with no cells */
72303 }
72304 if( !leafData ){
72305 k++;
72306 b.apEnd[k] = pParent->aDataEnd;
72307 b.ixNx[k] = cntOld[i]+1;
72308 }
72309 assert( p->nFree>=0 );
72310 szNew[i] = usableSpace - p->nFree;
72311 for(j=0; j<p->nOverflow; j++){
72312 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
72313 }
72314 cntNew[i] = cntOld[i];
72315 }
72316 k = nOld;
72317 for(i=0; i<k; i++){
72318 int sz;
72319 while( szNew[i]>usableSpace ){
72320 if( i+1>=k ){
72321 k = i+2;
72322 if( k>NB+2 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
72323 szNew[k-1] = 0;
72324 cntNew[k-1] = b.nCell;
72325 }
72326 sz = 2 + cachedCellSize(&b, cntNew[i]-1);
72327 szNew[i] -= sz;
72328 if( !leafData ){
72329 if( cntNew[i]<b.nCell ){
72330 sz = 2 + cachedCellSize(&b, cntNew[i]);
72331 }else{
72332 sz = 0;
72333 }
72334 }
72335 szNew[i+1] += sz;
72336 cntNew[i]--;
72337 }
72338 while( cntNew[i]<b.nCell ){
72339 sz = 2 + cachedCellSize(&b, cntNew[i]);
72340 if( szNew[i]+sz>usableSpace ) break;
72341 szNew[i] += sz;
72342 cntNew[i]++;
72343 if( !leafData ){
72344 if( cntNew[i]<b.nCell ){
72345 sz = 2 + cachedCellSize(&b, cntNew[i]);
72346 }else{
72347 sz = 0;
72348 }
72349 }
72350 szNew[i+1] -= sz;
72351 }
72352 if( cntNew[i]>=b.nCell ){
72353 k = i+1;
72354 }else if( cntNew[i] <= (i>0 ? cntNew[i-1] : 0) ){
72356 goto balance_cleanup;
72357 }
72358 }
72359
72360 /*
72361 ** The packing computed by the previous block is biased toward the siblings
72362 ** on the left side (siblings with smaller keys). The left siblings are
72363 ** always nearly full, while the right-most sibling might be nearly empty.
72364 ** The next block of code attempts to adjust the packing of siblings to
72365 ** get a better balance.
72366 **
72367 ** This adjustment is more than an optimization. The packing above might
72368 ** be so out of balance as to be illegal. For example, the right-most
72369 ** sibling might be completely empty. This adjustment is not optional.
72370 */
72371 for(i=k-1; i>0; i--){
72372 int szRight = szNew[i]; /* Size of sibling on the right */
72373 int szLeft = szNew[i-1]; /* Size of sibling on the left */
72374 int r; /* Index of right-most cell in left sibling */
72375 int d; /* Index of first cell to the left of right sibling */
72376
72377 r = cntNew[i-1] - 1;
72378 d = r + 1 - leafData;
72379 (void)cachedCellSize(&b, d);
72380 do{
72381 assert( d<nMaxCells );
72382 assert( r<nMaxCells );
72383 (void)cachedCellSize(&b, r);
72384 if( szRight!=0
72385 && (bBulk || szRight+b.szCell[d]+2 > szLeft-(b.szCell[r]+(i==k-1?0:2)))){
72386 break;
72387 }
72388 szRight += b.szCell[d] + 2;
72389 szLeft -= b.szCell[r] + 2;
72390 cntNew[i-1] = r;
72391 r--;
72392 d--;
72393 }while( r>=0 );
72394 szNew[i] = szRight;
72395 szNew[i-1] = szLeft;
72396 if( cntNew[i-1] <= (i>1 ? cntNew[i-2] : 0) ){
72398 goto balance_cleanup;
72399 }
72400 }
72401
72402 /* Sanity check: For a non-corrupt database file one of the follwing
72403 ** must be true:
72404 ** (1) We found one or more cells (cntNew[0])>0), or
72405 ** (2) pPage is a virtual root page. A virtual root page is when
72406 ** the real root page is page 1 and we are the only child of
72407 ** that page.
72408 */
72409 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
72410 TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n",
72411 apOld[0]->pgno, apOld[0]->nCell,
72412 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
72413 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
72414 ));
72415
72416 /*
72417 ** Allocate k new pages. Reuse old pages where possible.
72418 */
72419 pageFlags = apOld[0]->aData[0];
72420 for(i=0; i<k; i++){
72421 MemPage *pNew;
72422 if( i<nOld ){
72423 pNew = apNew[i] = apOld[i];
72424 apOld[i] = 0;
72425 rc = sqlite3PagerWrite(pNew->pDbPage);
72426 nNew++;
72427 if( rc ) goto balance_cleanup;
72428 }else{
72429 assert( i>0 );
72430 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
72431 if( rc ) goto balance_cleanup;
72432 zeroPage(pNew, pageFlags);
72433 apNew[i] = pNew;
72434 nNew++;
72435 cntOld[i] = b.nCell;
72436
72437 /* Set the pointer-map entry for the new sibling page. */
72438 if( ISAUTOVACUUM ){
72439 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
72440 if( rc!=SQLITE_OK ){
72441 goto balance_cleanup;
72442 }
72443 }
72444 }
72445 }
72446
72447 /*
72448 ** Reassign page numbers so that the new pages are in ascending order.
72449 ** This helps to keep entries in the disk file in order so that a scan
72450 ** of the table is closer to a linear scan through the file. That in turn
72451 ** helps the operating system to deliver pages from the disk more rapidly.
72452 **
72453 ** An O(n^2) insertion sort algorithm is used, but since n is never more
72454 ** than (NB+2) (a small constant), that should not be a problem.
72455 **
72456 ** When NB==3, this one optimization makes the database about 25% faster
72457 ** for large insertions and deletions.
72458 */
72459 for(i=0; i<nNew; i++){
72460 aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
72461 aPgFlags[i] = apNew[i]->pDbPage->flags;
72462 for(j=0; j<i; j++){
72463 if( aPgno[j]==aPgno[i] ){
72464 /* This branch is taken if the set of sibling pages somehow contains
72465 ** duplicate entries. This can happen if the database is corrupt.
72466 ** It would be simpler to detect this as part of the loop below, but
72467 ** we do the detection here in order to avoid populating the pager
72468 ** cache with two separate objects associated with the same
72469 ** page number. */
72470 assert( CORRUPT_DB );
72472 goto balance_cleanup;
72473 }
72474 }
72475 }
72476 for(i=0; i<nNew; i++){
72477 int iBest = 0; /* aPgno[] index of page number to use */
72478 for(j=1; j<nNew; j++){
72479 if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
72480 }
72481 pgno = aPgOrder[iBest];
72482 aPgOrder[iBest] = 0xffffffff;
72483 if( iBest!=i ){
72484 if( iBest>i ){
72485 sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
72486 }
72487 sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
72488 apNew[i]->pgno = pgno;
72489 }
72490 }
72491
72492 TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
72493 "%d(%d nc=%d) %d(%d nc=%d)\n",
72494 apNew[0]->pgno, szNew[0], cntNew[0],
72495 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
72496 nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
72497 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
72498 nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
72499 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
72500 nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
72501 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
72502 nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
72503 ));
72504
72505 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
72506 assert( nNew>=1 && nNew<=ArraySize(apNew) );
72507 assert( apNew[nNew-1]!=0 );
72508 put4byte(pRight, apNew[nNew-1]->pgno);
72509
72510 /* If the sibling pages are not leaves, ensure that the right-child pointer
72511 ** of the right-most new sibling page is set to the value that was
72512 ** originally in the same field of the right-most old sibling page. */
72513 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
72514 MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
72515 memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
72516 }
72517
72518 /* Make any required updates to pointer map entries associated with
72519 ** cells stored on sibling pages following the balance operation. Pointer
72520 ** map entries associated with divider cells are set by the insertCell()
72521 ** routine. The associated pointer map entries are:
72522 **
72523 ** a) if the cell contains a reference to an overflow chain, the
72524 ** entry associated with the first page in the overflow chain, and
72525 **
72526 ** b) if the sibling pages are not leaves, the child page associated
72527 ** with the cell.
72528 **
72529 ** If the sibling pages are not leaves, then the pointer map entry
72530 ** associated with the right-child of each sibling may also need to be
72531 ** updated. This happens below, after the sibling pages have been
72532 ** populated, not here.
72533 */
72534 if( ISAUTOVACUUM ){
72535 MemPage *pOld;
72536 MemPage *pNew = pOld = apNew[0];
72537 int cntOldNext = pNew->nCell + pNew->nOverflow;
72538 int iNew = 0;
72539 int iOld = 0;
72540
72541 for(i=0; i<b.nCell; i++){
72542 u8 *pCell = b.apCell[i];
72543 while( i==cntOldNext ){
72544 iOld++;
72545 assert( iOld<nNew || iOld<nOld );
72546 assert( iOld>=0 && iOld<NB );
72547 pOld = iOld<nNew ? apNew[iOld] : apOld[iOld];
72548 cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
72549 }
72550 if( i==cntNew[iNew] ){
72551 pNew = apNew[++iNew];
72552 if( !leafData ) continue;
72553 }
72554
72555 /* Cell pCell is destined for new sibling page pNew. Originally, it
72556 ** was either part of sibling page iOld (possibly an overflow cell),
72557 ** or else the divider cell to the left of sibling page iOld. So,
72558 ** if sibling page iOld had the same page number as pNew, and if
72559 ** pCell really was a part of sibling page iOld (not a divider or
72560 ** overflow cell), we can skip updating the pointer map entries. */
72561 if( iOld>=nNew
72562 || pNew->pgno!=aPgno[iOld]
72563 || !SQLITE_WITHIN(pCell,pOld->aData,pOld->aDataEnd)
72564 ){
72565 if( !leafCorrection ){
72566 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
72567 }
72568 if( cachedCellSize(&b,i)>pNew->minLocal ){
72569 ptrmapPutOvflPtr(pNew, pOld, pCell, &rc);
72570 }
72571 if( rc ) goto balance_cleanup;
72572 }
72573 }
72574 }
72575
72576 /* Insert new divider cells into pParent. */
72577 for(i=0; i<nNew-1; i++){
72578 u8 *pCell;
72579 u8 *pTemp;
72580 int sz;
72581 MemPage *pNew = apNew[i];
72582 j = cntNew[i];
72583
72584 assert( j<nMaxCells );
72585 assert( b.apCell[j]!=0 );
72586 pCell = b.apCell[j];
72587 sz = b.szCell[j] + leafCorrection;
72588 pTemp = &aOvflSpace[iOvflSpace];
72589 if( !pNew->leaf ){
72590 memcpy(&pNew->aData[8], pCell, 4);
72591 }else if( leafData ){
72592 /* If the tree is a leaf-data tree, and the siblings are leaves,
72593 ** then there is no divider cell in b.apCell[]. Instead, the divider
72594 ** cell consists of the integer key for the right-most cell of
72595 ** the sibling-page assembled above only.
72596 */
72597 CellInfo info;
72598 j--;
72599 pNew->xParseCell(pNew, b.apCell[j], &info);
72600 pCell = pTemp;
72601 sz = 4 + putVarint(&pCell[4], info.nKey);
72602 pTemp = 0;
72603 }else{
72604 pCell -= 4;
72605 /* Obscure case for non-leaf-data trees: If the cell at pCell was
72606 ** previously stored on a leaf node, and its reported size was 4
72607 ** bytes, then it may actually be smaller than this
72608 ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
72609 ** any cell). But it is important to pass the correct size to
72610 ** insertCell(), so reparse the cell now.
72611 **
72612 ** This can only happen for b-trees used to evaluate "IN (SELECT ...)"
72613 ** and WITHOUT ROWID tables with exactly one column which is the
72614 ** primary key.
72615 */
72616 if( b.szCell[j]==4 ){
72617 assert(leafCorrection==4);
72618 sz = pParent->xCellSize(pParent, pCell);
72619 }
72620 }
72621 iOvflSpace += sz;
72622 assert( sz<=pBt->maxLocal+23 );
72623 assert( iOvflSpace <= (int)pBt->pageSize );
72624 insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
72625 if( rc!=SQLITE_OK ) goto balance_cleanup;
72626 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
72627 }
72628
72629 /* Now update the actual sibling pages. The order in which they are updated
72630 ** is important, as this code needs to avoid disrupting any page from which
72631 ** cells may still to be read. In practice, this means:
72632 **
72633 ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
72634 ** then it is not safe to update page apNew[iPg] until after
72635 ** the left-hand sibling apNew[iPg-1] has been updated.
72636 **
72637 ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
72638 ** then it is not safe to update page apNew[iPg] until after
72639 ** the right-hand sibling apNew[iPg+1] has been updated.
72640 **
72641 ** If neither of the above apply, the page is safe to update.
72642 **
72643 ** The iPg value in the following loop starts at nNew-1 goes down
72644 ** to 0, then back up to nNew-1 again, thus making two passes over
72645 ** the pages. On the initial downward pass, only condition (1) above
72646 ** needs to be tested because (2) will always be true from the previous
72647 ** step. On the upward pass, both conditions are always true, so the
72648 ** upwards pass simply processes pages that were missed on the downward
72649 ** pass.
72650 */
72651 for(i=1-nNew; i<nNew; i++){
72652 int iPg = i<0 ? -i : i;
72653 assert( iPg>=0 && iPg<nNew );
72654 if( abDone[iPg] ) continue; /* Skip pages already processed */
72655 if( i>=0 /* On the upwards pass, or... */
72656 || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */
72657 ){
72658 int iNew;
72659 int iOld;
72660 int nNewCell;
72661
72662 /* Verify condition (1): If cells are moving left, update iPg
72663 ** only after iPg-1 has already been updated. */
72664 assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
72665
72666 /* Verify condition (2): If cells are moving right, update iPg
72667 ** only after iPg+1 has already been updated. */
72668 assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] );
72669
72670 if( iPg==0 ){
72671 iNew = iOld = 0;
72672 nNewCell = cntNew[0];
72673 }else{
72674 iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : b.nCell;
72675 iNew = cntNew[iPg-1] + !leafData;
72676 nNewCell = cntNew[iPg] - iNew;
72677 }
72678
72679 rc = editPage(apNew[iPg], iOld, iNew, nNewCell, &b);
72680 if( rc ) goto balance_cleanup;
72681 abDone[iPg]++;
72682 apNew[iPg]->nFree = usableSpace-szNew[iPg];
72683 assert( apNew[iPg]->nOverflow==0 );
72684 assert( apNew[iPg]->nCell==nNewCell );
72685 }
72686 }
72687
72688 /* All pages have been processed exactly once */
72689 assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
72690
72691 assert( nOld>0 );
72692 assert( nNew>0 );
72693
72694 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
72695 /* The root page of the b-tree now contains no cells. The only sibling
72696 ** page is the right-child of the parent. Copy the contents of the
72697 ** child page into the parent, decreasing the overall height of the
72698 ** b-tree structure by one. This is described as the "balance-shallower"
72699 ** sub-algorithm in some documentation.
72700 **
72701 ** If this is an auto-vacuum database, the call to copyNodeContent()
72702 ** sets all pointer-map entries corresponding to database image pages
72703 ** for which the pointer is stored within the content being copied.
72704 **
72705 ** It is critical that the child page be defragmented before being
72706 ** copied into the parent, because if the parent is page 1 then it will
72707 ** by smaller than the child due to the database header, and so all the
72708 ** free space needs to be up front.
72709 */
72710 assert( nNew==1 || CORRUPT_DB );
72711 rc = defragmentPage(apNew[0], -1);
72712 testcase( rc!=SQLITE_OK );
72713 assert( apNew[0]->nFree ==
72714 (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
72715 - apNew[0]->nCell*2)
72716 || rc!=SQLITE_OK
72717 );
72718 copyNodeContent(apNew[0], pParent, &rc);
72719 freePage(apNew[0], &rc);
72720 }else if( ISAUTOVACUUM && !leafCorrection ){
72721 /* Fix the pointer map entries associated with the right-child of each
72722 ** sibling page. All other pointer map entries have already been taken
72723 ** care of. */
72724 for(i=0; i<nNew; i++){
72725 u32 key = get4byte(&apNew[i]->aData[8]);
72726 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
72727 }
72728 }
72729
72730 assert( pParent->isInit );
72731 TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
72732 nOld, nNew, b.nCell));
72733
72734 /* Free any old pages that were not reused as new pages.
72735 */
72736 for(i=nNew; i<nOld; i++){
72737 freePage(apOld[i], &rc);
72738 }
72739
72740#if 0
72741 if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
72742 /* The ptrmapCheckPages() contains assert() statements that verify that
72743 ** all pointer map pages are set correctly. This is helpful while
72744 ** debugging. This is usually disabled because a corrupt database may
72745 ** cause an assert() statement to fail. */
72746 ptrmapCheckPages(apNew, nNew);
72747 ptrmapCheckPages(&pParent, 1);
72748 }
72749#endif
72750
72751 /*
72752 ** Cleanup before returning.
72753 */
72754balance_cleanup:
72756 for(i=0; i<nOld; i++){
72757 releasePage(apOld[i]);
72758 }
static int editPage(MemPage *pPg, int iOld, int iNew, int nNew, CellArray *pCArray)
Definition sqlite3.c:71629
#define SQLITE_PTR_TO_INT(X)
Definition sqlite3.c:13514
static void insertCell(MemPage *pPage, int i, u8 *pCell, int sz, u8 *pTemp, Pgno iChild, int *pRC)
Definition sqlite3.c:71184
static void zeroPage(MemPage *pPage, int flags)
Definition sqlite3.c:66521
#define SQLITE_WITHIN(P, S, E)
Definition sqlite3.c:14415
#define get2byteAligned(x)
Definition sqlite3.c:64180
static u16 cachedCellSize(CellArray *p, int N)
Definition sqlite3.c:71397
static void dropCell(MemPage *pPage, int idx, int sz, int *pRC)
Definition sqlite3.c:71128
#define NB
Definition sqlite3.c:71294
#define MX_CELL(pBt)
Definition sqlite3.c:63698
#define sqlite3StackFree(D, P)
Definition sqlite3.c:19387
#define PTF_LEAF
Definition sqlite3.c:63728
#define sqlite3StackAllocRaw(D, N)
Definition sqlite3.c:19385
SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *, Pgno, u16)
Definition sqlite3.c:58881
static void freePage(MemPage *pPage, int *pRC)
Definition sqlite3.c:70845
static int getAndInitPage(BtShared *pBt, Pgno pgno, MemPage **ppPage, BtCursor *pCur, int bReadOnly)
Definition sqlite3.c:66639
#define findCell(P, I)
Definition sqlite3.c:65569
#define BTS_FAST_SECURE
Definition sqlite3.c:63919
static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell, int *pRC)
Definition sqlite3.c:65854
#define putVarint
Definition sqlite3.c:19876
u16 btsFlags
Definition sqlite3.c:63890
MemPage * pRef
Definition sqlite3.c:71362
u16 * szCell
Definition sqlite3.c:71364
u8 ** apCell
Definition sqlite3.c:71363
u8 * apEnd[NB *2]
Definition sqlite3.c:71365
int ixNx[NB *2]
Definition sqlite3.c:71366
u8 isInit
Definition sqlite3.c:63743
u16 minLocal
Definition sqlite3.c:63756
u16 maskPage
Definition sqlite3.c:63760
u8 * aDataEnd
Definition sqlite3.c:63766
void(* xParseCell)(MemPage *, u8 *, CellInfo *)
Definition sqlite3.c:63771
u16(* xCellSize)(MemPage *, u8 *)
Definition sqlite3.c:63770
u16 flags
Definition sqlite3.c:16055

References MemPage::aData, MemPage::aDataEnd, MemPage::aiOvfl, allocateBtreePage(), CellArray::apCell, CellArray::apEnd, MemPage::apOvfl, ArraySize, btreeComputeFreeSpace(), BTS_FAST_SECURE, BtShared::btsFlags, cachedCellSize(), MemPage::cellOffset, copyNodeContent(), CORRUPT_DB, defragmentPage(), dropCell(), editPage(), EIGHT_BYTE_ALIGNMENT, findCell, PgHdr::flags, freePage(), get2byteAligned, get2byteNotZero, get4byte, getAndInitPage(), MemPage::hdrOffset, insertCell(), MemPage::intKeyLeaf, ISAUTOVACUUM, MemPage::isInit, CellArray::ixNx, MemPage::leaf, MemPage::maskPage, MemPage::minLocal, BtShared::mutex, MX_CELL, NB, MemPage::nCell, CellArray::nCell, NEVER, MemPage::nFree, CellInfo::nKey, MemPage::nOverflow, BtShared::nPage, BtShared::pageSize, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, CellArray::pRef, PTF_LEAF, PTRMAP_BTREE, ptrmapPut(), ptrmapPutOvflPtr(), put4byte, putVarint, releasePage(), sqlite3_mutex_held(), sqlite3PagerRekey(), sqlite3PagerWrite(), sqlite3StackAllocRaw, sqlite3StackFree, SQLITE_CORRUPT_BKPT, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_PTR_TO_INT, SQLITE_WITHIN, CellArray::szCell, testcase, TRACE, BtShared::usableSize, VVA_ONLY, MemPage::xCellSize, MemPage::xParseCell, and zeroPage().

Referenced by balance().

◆ balance_quick()

static int balance_quick ( MemPage * pParent,
MemPage * pPage,
u8 * pSpace )
static

Definition at line 71757 of file sqlite3.c.

71763 {
71764 BtShared *const pBt = pPage->pBt; /* B-Tree Database */
71765 MemPage *pNew; /* Newly allocated page */
71766 int rc; /* Return Code */
71767 Pgno pgnoNew; /* Page number of pNew */
71768
71769 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
71770 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
71771 assert( pPage->nOverflow==1 );
71772
71773 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
71774 assert( pPage->nFree>=0 );
71775 assert( pParent->nFree>=0 );
71776
71777 /* Allocate a new page. This page will become the right-sibling of
71778 ** pPage. Make the parent page writable, so that the new divider cell
71779 ** may be inserted. If both these operations are successful, proceed.
71780 */
71781 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
71782
71783 if( rc==SQLITE_OK ){
71784
71785 u8 *pOut = &pSpace[4];
71786 u8 *pCell = pPage->apOvfl[0];
71787 u16 szCell = pPage->xCellSize(pPage, pCell);
71788 u8 *pStop;
71789 CellArray b;
71790
71791 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
71792 assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
71794 b.nCell = 1;
71795 b.pRef = pPage;
71796 b.apCell = &pCell;
71797 b.szCell = &szCell;
71798 b.apEnd[0] = pPage->aDataEnd;
71799 b.ixNx[0] = 2;
71800 rc = rebuildPage(&b, 0, 1, pNew);
71801 if( NEVER(rc) ){
71802 releasePage(pNew);
71803 return rc;
71804 }
71805 pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
71806
71807 /* If this is an auto-vacuum database, update the pointer map
71808 ** with entries for the new page, and any pointer from the
71809 ** cell on the page to an overflow page. If either of these
71810 ** operations fails, the return code is set, but the contents
71811 ** of the parent page are still manipulated by thh code below.
71812 ** That is Ok, at this point the parent page is guaranteed to
71813 ** be marked as dirty. Returning an error code will cause a
71814 ** rollback, undoing any changes made to the parent page.
71815 */
71816 if( ISAUTOVACUUM ){
71817 ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
71818 if( szCell>pNew->minLocal ){
71819 ptrmapPutOvflPtr(pNew, pNew, pCell, &rc);
71820 }
71821 }
71822
71823 /* Create a divider cell to insert into pParent. The divider cell
71824 ** consists of a 4-byte page number (the page number of pPage) and
71825 ** a variable length key value (which must be the same value as the
71826 ** largest key on pPage).
71827 **
71828 ** To find the largest key value on pPage, first find the right-most
71829 ** cell on pPage. The first two fields of this cell are the
71830 ** record-length (a variable length integer at most 32-bits in size)
71831 ** and the key value (a variable length integer, may have any value).
71832 ** The first of the while(...) loops below skips over the record-length
71833 ** field. The second while(...) loop copies the key value from the
71834 ** cell on pPage into the pSpace buffer.
71835 */
71836 pCell = findCell(pPage, pPage->nCell-1);
71837 pStop = &pCell[9];
71838 while( (*(pCell++)&0x80) && pCell<pStop );
71839 pStop = &pCell[9];
71840 while( ((*(pOut++) = *(pCell++))&0x80) && pCell<pStop );
71841
71842 /* Insert the new divider cell into pParent. */
71843 if( rc==SQLITE_OK ){
71844 insertCell(pParent, pParent->nCell, pSpace, (int)(pOut-pSpace),
71845 0, pPage->pgno, &rc);
71846 }
71847
71848 /* Set the right-child pointer of pParent to point to the new page. */
71849 put4byte(&pParent->aData[pParent->hdrOffset+8], pgnoNew);
71850
#define PTF_INTKEY
Definition sqlite3.c:63725
#define PTF_LEAFDATA
Definition sqlite3.c:63727
static int rebuildPage(CellArray *pCArray, int iFirst, int nCell, MemPage *pPg)
Definition sqlite3.c:71416

References MemPage::aData, MemPage::aDataEnd, allocateBtreePage(), CellArray::apCell, CellArray::apEnd, MemPage::apOvfl, MemPage::cellOffset, CORRUPT_DB, findCell, MemPage::hdrOffset, insertCell(), ISAUTOVACUUM, CellArray::ixNx, MemPage::minLocal, BtShared::mutex, MemPage::nCell, CellArray::nCell, NEVER, MemPage::nFree, MemPage::nOverflow, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, CellArray::pRef, PTF_INTKEY, PTF_LEAF, PTF_LEAFDATA, PTRMAP_BTREE, ptrmapPut(), ptrmapPutOvflPtr(), put4byte, rebuildPage(), releasePage(), sqlite3_mutex_held(), SQLITE_CORRUPT_BKPT, SQLITE_OK, CellArray::szCell, BtShared::usableSize, MemPage::xCellSize, and zeroPage().

Referenced by balance().

◆ binaryCompareP5()

static u8 binaryCompareP5 ( const Expr * pExpr1,
const Expr * pExpr2,
int jumpIfNull )
static

Definition at line 100019 of file sqlite3.c.

◆ binaryToUnaryIfNull()

static void binaryToUnaryIfNull ( Parse * pParse,
Expr * pY,
Expr * pA,
int op )
static

Definition at line 154379 of file sqlite3.c.

154385 {
154386 sqlite3 *db = pParse->db;

Referenced by yy_reduce().

◆ binCollFunc()

static int binCollFunc ( void * NotUsed,
int nKey1,
const void * pKey1,
int nKey2,
const void * pKey2 )
static

Definition at line 161985 of file sqlite3.c.

161995 {
161996 int rc, n;
161997 UNUSED_PARAMETER(NotUsed);
161998 n = nKey1<nKey2 ? nKey1 : nKey2;
161999 /* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
162000 ** strings byte by byte using the memcmp() function from the standard C
162001 ** library. */
162002 assert( pKey1 && pKey2 );

Referenced by openDatabase().

◆ bindText()

static int bindText ( sqlite3_stmt * pStmt,
int i,
const void * zData,
int nData,
void(*)(void *) xDel,
u8 encoding )
static

Definition at line 84354 of file sqlite3.c.

84367 {
84368 Vdbe *p = (Vdbe *)pStmt;
84369 Mem *pVar;
84370 int rc;
84371
84372 rc = vdbeUnbind(p, i);
84373 if( rc==SQLITE_OK ){
84374 if( zData!=0 ){
84375 pVar = &p->aVar[i-1];
84376 rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
84377 if( rc==SQLITE_OK && encoding!=0 ){
84378 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
84379 }
84380 if( rc ){
84381 sqlite3Error(p->db, rc);
84382 rc = sqlite3ApiExit(p->db, rc);
84383 }
84384 }
SQLITE_PRIVATE void sqlite3Error(sqlite3 *, int)
Definition sqlite3.c:31291
SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem *, const char *, int, u8, void(*)(void *))
Definition sqlite3.c:76892
SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int)
Definition sqlite3.c:76021
static int vdbeUnbind(Vdbe *p, int i)
Definition sqlite3.c:84311
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int)
Definition sqlite3.c:28121
sqlite3 * db
Definition sqlite3.c:21084
Mem * aVar
Definition sqlite3.c:21103

Referenced by sqlite3_bind_blob64(), sqlite3_bind_text64(), and sqlite3_bind_value().

◆ blobReadWrite()

static int blobReadWrite ( sqlite3_blob * pBlob,
void * z,
int n,
int iOffset,
int(*)(BtCursor *, u32, u32, void *) xCall )
static

Definition at line 93740 of file sqlite3.c.

93752 {
93753 int rc;
93754 Incrblob *p = (Incrblob *)pBlob;
93755 Vdbe *v;
93756 sqlite3 *db;
93757
93758 if( p==0 ) return SQLITE_MISUSE_BKPT;
93759 db = p->db;
93761 v = (Vdbe*)p->pStmt;
93762
93763 if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){
93764 /* Request is out of range. Return a transient error. */
93765 rc = SQLITE_ERROR;
93766 }else if( v==0 ){
93767 /* If there is no statement handle, then the blob-handle has
93768 ** already been invalidated. Return SQLITE_ABORT in this case.
93769 */
93770 rc = SQLITE_ABORT;
93771 }else{
93772 /* Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
93773 ** returned, clean-up the statement handle.
93774 */
93775 assert( db == v->db );
93777
93778#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
93779 if( xCall==sqlite3BtreePutData && db->xPreUpdateCallback ){
93780 /* If a pre-update hook is registered and this is a write cursor,
93781 ** invoke it here.
93782 **
93783 ** TODO: The preupdate-hook is passed SQLITE_DELETE, even though this
93784 ** operation should really be an SQLITE_UPDATE. This is probably
93785 ** incorrect, but is convenient because at this point the new.* values
93786 ** are not easily obtainable. And for the sessions module, an
93787 ** SQLITE_UPDATE where the PK columns do not change is handled in the
93788 ** same way as an SQLITE_DELETE (the SQLITE_DELETE code is actually
93789 ** slightly more efficient). Since you cannot write to a PK column
93790 ** using the incremental-blob API, this works. For the sessions module
93791 ** anyhow.
93792 */
93793 sqlite3_int64 iKey;
93794 iKey = sqlite3BtreeIntegerKey(p->pCsr);
93795 sqlite3VdbePreUpdateHook(
93796 v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1
93797 );
93798 }
93799#endif
93800
93801 rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
93803 if( rc==SQLITE_ABORT ){
93805 p->pStmt = 0;
93806 }else{
93807 v->rc = rc;
93808 }
SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor *, u32 offset, u32 amt, void *)
Definition sqlite3.c:74920
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor *)
Definition sqlite3.c:69053
#define SQLITE_ABORT
Definition sqlite3.c:1474
#define SQLITE_MISUSE_BKPT
Definition sqlite3.c:19268
SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor *)
Definition sqlite3.c:64468
SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor *)
Definition sqlite3.c:64464
#define SQLITE_DELETE
Definition sqlite3.c:4128
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *)
Definition sqlite3.c:81114
sqlite3_stmt * pStmt
Definition sqlite3.c:93397
Table * pTab
Definition sqlite3.c:93400
char * zDb
Definition sqlite3.c:93399
sqlite3 * db
Definition sqlite3.c:93398
int nByte
Definition sqlite3.c:93393
BtCursor * pCsr
Definition sqlite3.c:93396
int iOffset
Definition sqlite3.c:93394
int rc
Definition sqlite3.c:21093

◆ blobSeekToRow()

static int blobSeekToRow ( Incrblob * p,
sqlite3_int64 iRow,
char ** pzErr )
static

Definition at line 93421 of file sqlite3.c.

93427 {
93428 int rc; /* Error code */
93429 char *zErr = 0; /* Error message */
93430 Vdbe *v = (Vdbe *)p->pStmt;
93431
93432 /* Set the value of register r[1] in the SQL statement to integer iRow.
93433 ** This is done directly as a performance optimization
93434 */
93435 v->aMem[1].flags = MEM_Int;
93436 v->aMem[1].u.i = iRow;
93437
93438 /* If the statement has been run before (and is paused at the OP_ResultRow)
93439 ** then back it up to the point where it does the OP_NotExists. This could
93440 ** have been down with an extra OP_Goto, but simply setting the program
93441 ** counter is faster. */
93442 if( v->pc>4 ){
93443 v->pc = 4;
93444 assert( v->aOp[v->pc].opcode==OP_NotExists );
93445 rc = sqlite3VdbeExec(v);
93446 }else{
93447 rc = sqlite3_step(p->pStmt);
93448 }
93449 if( rc==SQLITE_ROW ){
93450 VdbeCursor *pC = v->apCsr[0];
93451 u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
93452 testcase( pC->nHdrParsed==p->iCol );
93453 testcase( pC->nHdrParsed==p->iCol+1 );
93454 if( type<12 ){
93455 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
93456 type==0?"null": type==7?"real": "integer"
93457 );
93458 rc = SQLITE_ERROR;
93460 p->pStmt = 0;
93461 }else{
93462 p->iOffset = pC->aType[p->iCol + pC->nField];
93464 p->pCsr = pC->uc.pCursor;
93466 }
93467 }
93468
93469 if( rc==SQLITE_ROW ){
93470 rc = SQLITE_OK;
93471 }else if( p->pStmt ){
93472 rc = sqlite3_finalize(p->pStmt);
93473 p->pStmt = 0;
93474 if( rc==SQLITE_OK ){
93475 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
93476 rc = SQLITE_ERROR;
93477 }else{
93478 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
93479 }
93480 }
93481
#define SQLITE_ROW
Definition sqlite3.c:1499
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt)
Definition sqlite3.c:83080
SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe *)
Definition sqlite3.c:85979
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32)
Definition sqlite3.c:81453
SQLITE_API int sqlite3_step(sqlite3_stmt *)
Definition sqlite3.c:83730
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *)
Definition sqlite3.c:74968
SQLITE_API const char * sqlite3_errmsg(sqlite3 *)
Definition sqlite3.c:163483
u16 nHdrParsed
Definition sqlite3.c:20822

References Vdbe::aMem, Vdbe::aOp, Vdbe::apCsr, VdbeCursor::aType, Incrblob::db, sqlite3_value::flags, sqlite3_value::MemValue::i, Incrblob::iCol, Incrblob::iOffset, MEM_Int, Incrblob::nByte, VdbeCursor::nField, VdbeCursor::nHdrParsed, OP_NotExists, VdbeOp::opcode, Vdbe::pc, Incrblob::pCsr, VdbeCursor::pCursor, Incrblob::pStmt, sqlite3_errmsg(), sqlite3_finalize(), sqlite3_step(), sqlite3BtreeIncrblobCursor(), sqlite3MPrintf(), sqlite3VdbeExec(), sqlite3VdbeSerialTypeLen(), SQLITE_DONE, SQLITE_ERROR, SQLITE_OK, SQLITE_ROW, testcase, sqlite3_value::u, and VdbeCursor::uc.

Referenced by sqlite3_blob_reopen().

◆ btreeCellSizeCheck()

static SQLITE_NOINLINE int btreeCellSizeCheck ( MemPage * pPage)
static

Definition at line 66427 of file sqlite3.c.

66433 {
66434 int iCellFirst; /* First allowable cell or freeblock offset */
66435 int iCellLast; /* Last possible cell or freeblock offset */
66436 int i; /* Index into the cell pointer array */
66437 int sz; /* Size of a cell */
66438 int pc; /* Address of a freeblock within pPage->aData[] */
66439 u8 *data; /* Equal to pPage->aData */
66440 int usableSize; /* Maximum usable space on the page */
66441 int cellOffset; /* Start of cell content area */
66442
66443 iCellFirst = pPage->cellOffset + 2*pPage->nCell;
66444 usableSize = pPage->pBt->usableSize;
66445 iCellLast = usableSize - 4;
66446 data = pPage->aData;
66447 cellOffset = pPage->cellOffset;
66448 if( !pPage->leaf ) iCellLast--;
66449 for(i=0; i<pPage->nCell; i++){
66450 pc = get2byteAligned(&data[cellOffset+i*2]);
66451 testcase( pc==iCellFirst );
66452 testcase( pc==iCellLast );
66453 if( pc<iCellFirst || pc>iCellLast ){
66454 return SQLITE_CORRUPT_PAGE(pPage);
66455 }
66456 sz = pPage->xCellSize(pPage, &data[pc]);
66457 testcase( pc+sz==usableSize );

Referenced by btreeInitPage().

◆ btreeClearHasContent()

static void btreeClearHasContent ( BtShared * pBt)
static

Definition at line 65100 of file sqlite3.c.

Referenced by sqlite3BtreeCommitPhaseTwo(), and sqlite3BtreeRollback().

◆ btreeComputeFreeSpace()

static int btreeComputeFreeSpace ( MemPage * pPage)
static

Definition at line 66345 of file sqlite3.c.

66351 {
66352 int pc; /* Address of a freeblock within pPage->aData[] */
66353 u8 hdr; /* Offset to beginning of page header */
66354 u8 *data; /* Equal to pPage->aData */
66355 int usableSize; /* Amount of usable space on each page */
66356 int nFree; /* Number of unused bytes on the page */
66357 int top; /* First byte of the cell content area */
66358 int iCellFirst; /* First allowable cell or freeblock offset */
66359 int iCellLast; /* Last possible cell or freeblock offset */
66360
66361 assert( pPage->pBt!=0 );
66362 assert( pPage->pBt->db!=0 );
66363 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
66364 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
66365 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
66366 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
66367 assert( pPage->isInit==1 );
66368 assert( pPage->nFree<0 );
66369
66370 usableSize = pPage->pBt->usableSize;
66371 hdr = pPage->hdrOffset;
66372 data = pPage->aData;
66373 /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
66374 ** the start of the cell content area. A zero value for this integer is
66375 ** interpreted as 65536. */
66376 top = get2byteNotZero(&data[hdr+5]);
66377 iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
66378 iCellLast = usableSize - 4;
66379
66380 /* Compute the total free space on the page
66381 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
66382 ** start of the first freeblock on the page, or is zero if there are no
66383 ** freeblocks. */
66384 pc = get2byte(&data[hdr+1]);
66385 nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
66386 if( pc>0 ){
66387 u32 next, size;
66388 if( pc<top ){
66389 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
66390 ** always be at least one cell before the first freeblock.
66391 */
66392 return SQLITE_CORRUPT_PAGE(pPage);
66393 }
66394 while( 1 ){
66395 if( pc>iCellLast ){
66396 /* Freeblock off the end of the page */
66397 return SQLITE_CORRUPT_PAGE(pPage);
66398 }
66399 next = get2byte(&data[pc]);
66400 size = get2byte(&data[pc+2]);
66401 nFree = nFree + size;
66402 if( next<=pc+size+3 ) break;
66403 pc = next;
66404 }
66405 if( next>0 ){
66406 /* Freeblock not in ascending order */
66407 return SQLITE_CORRUPT_PAGE(pPage);
66408 }
66409 if( pc+size>(unsigned int)usableSize ){
66410 /* Last freeblock extends past page end */
66411 return SQLITE_CORRUPT_PAGE(pPage);
66412 }
66413 }
66414
66415 /* At this point, nFree contains the sum of the offset to the start
66416 ** of the cell-content area plus the number of free bytes within
66417 ** the cell-content area. If this is greater than the usable-size
66418 ** of the page, then the page must be corrupted. This check also
66419 ** serves to verify that the offset to the start of the cell-content
66420 ** area, according to the page header, lies within the page.
66421 */
u8 childPtrSize
Definition sqlite3.c:63752

Referenced by balance(), balance_nonroot(), checkTreePage(), copyNodeContent(), sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ btreeCreateTable()

static int btreeCreateTable ( Btree * p,
Pgno * piTable,
int createTabFlags )
static

Definition at line 73578 of file sqlite3.c.

73579 :
73580**
73581** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
73582** BTREE_ZERODATA Used for SQL indices
73583*/
73584static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
73585 BtShared *pBt = p->pBt;
73586 MemPage *pRoot;
73587 Pgno pgnoRoot;
73588 int rc;
73589 int ptfFlags; /* Page-type flage for the root page of new table */
73590
73591 assert( sqlite3BtreeHoldsMutex(p) );
73592 assert( pBt->inTransaction==TRANS_WRITE );
73593 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
73594
73595#ifdef SQLITE_OMIT_AUTOVACUUM
73596 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
73597 if( rc ){
73598 return rc;
73599 }
73600#else
73601 if( pBt->autoVacuum ){
73602 Pgno pgnoMove; /* Move a page here to make room for the root-page */
73603 MemPage *pPageMove; /* The page to move to. */
73604
73605 /* Creating a new table may probably require moving an existing database
73606 ** to make room for the new tables root page. In case this page turns
73607 ** out to be an overflow page, delete all overflow page-map caches
73608 ** held by open cursors.
73609 */
73611
73612 /* Read the value of meta[3] from the database to determine where the
73613 ** root page of the new table should go. meta[3] is the largest root-page
73614 ** created so far, so the new root-page is (meta[3]+1).
73615 */
73617 if( pgnoRoot>btreePagecount(pBt) ){
73618 return SQLITE_CORRUPT_BKPT;
73619 }
73620 pgnoRoot++;
73621
73622 /* The new root-page may not be allocated on a pointer-map page, or the
73623 ** PENDING_BYTE page.
73624 */
73625 while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
73626 pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
73627 pgnoRoot++;
73628 }
73629 assert( pgnoRoot>=3 );
73630
73631 /* Allocate a page. The page that currently resides at pgnoRoot will
73632 ** be moved to the allocated page (unless the allocated page happens
73633 ** to reside at pgnoRoot).
73634 */
73635 rc = allocateBtreePage(pBt, &pPageMove, &pgnoMove, pgnoRoot, BTALLOC_EXACT);
73636 if( rc!=SQLITE_OK ){
73637 return rc;
73638 }
73639
73640 if( pgnoMove!=pgnoRoot ){
73641 /* pgnoRoot is the page that will be used for the root-page of
73642 ** the new table (assuming an error did not occur). But we were
73643 ** allocated pgnoMove. If required (i.e. if it was not allocated
73644 ** by extending the file), the current page at position pgnoMove
73645 ** is already journaled.
73646 */
73647 u8 eType = 0;
73648 Pgno iPtrPage = 0;
73649
73650 /* Save the positions of any open cursors. This is required in
73651 ** case they are holding a reference to an xFetch reference
73652 ** corresponding to page pgnoRoot. */
73653 rc = saveAllCursors(pBt, 0, 0);
73654 releasePage(pPageMove);
73655 if( rc!=SQLITE_OK ){
73656 return rc;
73657 }
73658
73659 /* Move the page currently at pgnoRoot to pgnoMove. */
73660 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
73661 if( rc!=SQLITE_OK ){
73662 return rc;
73663 }
73664 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
73667 }
73668 if( rc!=SQLITE_OK ){
73669 releasePage(pRoot);
73670 return rc;
73671 }
73672 assert( eType!=PTRMAP_ROOTPAGE );
73673 assert( eType!=PTRMAP_FREEPAGE );
73674 rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
73675 releasePage(pRoot);
73676
73677 /* Obtain the page at pgnoRoot */
73678 if( rc!=SQLITE_OK ){
73679 return rc;
73680 }
73681 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
73682 if( rc!=SQLITE_OK ){
73683 return rc;
73684 }
73685 rc = sqlite3PagerWrite(pRoot->pDbPage);
73686 if( rc!=SQLITE_OK ){
73687 releasePage(pRoot);
73688 return rc;
73689 }
73690 }else{
73691 pRoot = pPageMove;
73692 }
73693
73694 /* Update the pointer-map and meta-data with the new root-page number. */
73695 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
73696 if( rc ){
73697 releasePage(pRoot);
73698 return rc;
73699 }
73700
73701 /* When the new root page was allocated, page 1 was made writable in
73702 ** order either to increase the database filesize, or to decrement the
73703 ** freelist count. Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
73704 */
73705 assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
73706 rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
73707 if( NEVER(rc) ){
73708 releasePage(pRoot);
73709 return rc;
73710 }
73711
73712 }else{
73713 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
73714 if( rc ) return rc;
73715 }
73716#endif
73717 assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
73718 if( createTabFlags & BTREE_INTKEY ){
73719 ptfFlags = PTF_INTKEY | PTF_LEAFDATA | PTF_LEAF;
73720 }else{
73721 ptfFlags = PTF_ZERODATA | PTF_LEAF;
73722 }
static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags)
Definition sqlite3.c:73578
#define PTF_ZERODATA
Definition sqlite3.c:63726
#define TRANS_WRITE
Definition sqlite3.c:63839
#define PTRMAP_ROOTPAGE
Definition sqlite3.c:64105
SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree *, int idx, u32 value)
Definition sqlite3.c:73994
SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue)
Definition sqlite3.c:73964
#define BTS_READ_ONLY
Definition sqlite3.c:63915
static int btreeGetPage(BtShared *pBt, Pgno pgno, MemPage **ppPage, int flags)
Definition sqlite3.c:66582
#define BTREE_INTKEY
Definition sqlite3.c:15111
#define PTRMAP_PAGENO(pBt, pgno)
Definition sqlite3.c:64070
static int relocatePage(BtShared *pBt, MemPage *pDbPage, u8 eType, Pgno iPtrPage, Pgno iFreePage, int isCommit)
Definition sqlite3.c:68136
#define BTREE_LARGEST_ROOT_PAGE
Definition sqlite3.c:15145
u8 inTransaction
Definition sqlite3.c:63887

References allocateBtreePage(), BtShared::autoVacuum, BTALLOC_EXACT, BTREE_INTKEY, BTREE_LARGEST_ROOT_PAGE, btreeGetPage(), btreePagecount(), BTS_READ_ONLY, BtShared::btsFlags, eType, BtShared::inTransaction, invalidateAllOverflowCache(), NEVER, Btree::pBt, MemPage::pDbPage, PENDING_BYTE_PAGE, BtShared::pPage1, PTF_INTKEY, PTF_LEAF, PTF_LEAFDATA, PTF_ZERODATA, PTRMAP_FREEPAGE, PTRMAP_PAGENO, PTRMAP_ROOTPAGE, ptrmapGet(), ptrmapPut(), releasePage(), relocatePage(), saveAllCursors(), sqlite3BtreeGetMeta(), sqlite3BtreeUpdateMeta(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_OK, and TRANS_WRITE.

◆ btreeCursor()

static int btreeCursor ( Btree * p,
Pgno iTable,
int wrFlag,
struct KeyInfo * pKeyInfo,
BtCursor * pCur )
static

Definition at line 68849 of file sqlite3.c.

68861 {
68862 BtShared *pBt = p->pBt; /* Shared b-tree handle */
68863 BtCursor *pX; /* Looping over other all cursors */
68864
68865 assert( sqlite3BtreeHoldsMutex(p) );
68866 assert( wrFlag==0
68867 || wrFlag==BTREE_WRCSR
68868 || wrFlag==(BTREE_WRCSR|BTREE_FORDELETE)
68869 );
68870
68871 /* The following assert statements verify that if this is a sharable
68872 ** b-tree database, the connection is holding the required table locks,
68873 ** and that no other connection has any open cursor that conflicts with
68874 ** this lock. The iTable<1 term disables the check for corrupt schemas. */
68875 assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, (wrFlag?2:1))
68876 || iTable<1 );
68877 assert( wrFlag==0 || !hasReadConflicts(p, iTable) );
68878
68879 /* Assert that the caller has opened the required transaction. */
68880 assert( p->inTrans>TRANS_NONE );
68881 assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
68882 assert( pBt->pPage1 && pBt->pPage1->aData );
68883 assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );
68884
68885 if( wrFlag ){
68886 allocateTempSpace(pBt);
68887 if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT;
68888 }
68889 if( iTable<=1 ){
68890 if( iTable<1 ){
68891 return SQLITE_CORRUPT_BKPT;
68892 }else if( btreePagecount(pBt)==0 ){
68893 assert( wrFlag==0 );
68894 iTable = 0;
68895 }
68896 }
68897
68898 /* Now that no other errors can occur, finish filling in the BtCursor
68899 ** variables and link the cursor into the BtShared list. */
68900 pCur->pgnoRoot = iTable;
68901 pCur->iPage = -1;
68902 pCur->pKeyInfo = pKeyInfo;
68903 pCur->pBtree = p;
68904 pCur->pBt = pBt;
68905 pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
68906 pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
68907 /* If there are two or more cursors on the same btree, then all such
68908 ** cursors *must* have the BTCF_Multiple flag set. */
68909 for(pX=pBt->pCursor; pX; pX=pX->pNext){
68910 if( pX->pgnoRoot==iTable ){
68911 pX->curFlags |= BTCF_Multiple;
68912 pCur->curFlags |= BTCF_Multiple;
68913 }
static void allocateTempSpace(BtShared *pBt)
Definition sqlite3.c:67146
#define BTCF_Multiple
Definition sqlite3.c:64011
#define BTREE_WRCSR
Definition sqlite3.c:15220
#define BTCF_WriteFlag
Definition sqlite3.c:64006
#define BTREE_FORDELETE
Definition sqlite3.c:15221
Pgno pgnoRoot
Definition sqlite3.c:63993
struct KeyInfo * pKeyInfo
Definition sqlite3.c:63998
u8 curPagerFlags
Definition sqlite3.c:63978
u8 inTrans
Definition sqlite3.c:63816

References MemPage::aData, allocateTempSpace(), BTCF_Multiple, BTCF_WriteFlag, BTREE_FORDELETE, BTREE_WRCSR, btreePagecount(), BTS_READ_ONLY, BtShared::btsFlags, BtCursor::curFlags, BtCursor::curPagerFlags, Btree::inTrans, BtCursor::iPage, PAGER_GET_READONLY, Btree::pBt, BtCursor::pBt, BtCursor::pBtree, BtShared::pCursor, BtCursor::pgnoRoot, BtCursor::pKeyInfo, BtCursor::pNext, BtShared::pPage1, BtShared::pTmpSpace, SQLITE_CORRUPT_BKPT, SQLITE_NOMEM_BKPT, TRANS_NONE, and TRANS_WRITE.

◆ btreeCursorWithLock()

static int btreeCursorWithLock ( Btree * p,
Pgno iTable,
int wrFlag,
struct KeyInfo * pKeyInfo,
BtCursor * pCur )
static

Definition at line 68914 of file sqlite3.c.

68926 {

◆ btreeDropTable()

static int btreeDropTable ( Btree * p,
Pgno iTable,
int * piMoved )
static

Definition at line 73850 of file sqlite3.c.

73856 {
73857 int rc;
73858 MemPage *pPage = 0;
73859 BtShared *pBt = p->pBt;
73860
73861 assert( sqlite3BtreeHoldsMutex(p) );
73862 assert( p->inTrans==TRANS_WRITE );
73863 assert( iTable>=2 );
73864 if( iTable>btreePagecount(pBt) ){
73865 return SQLITE_CORRUPT_BKPT;
73866 }
73867
73868 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
73869 if( rc ) return rc;
73870 rc = sqlite3BtreeClearTable(p, iTable, 0);
73871 if( rc ){
73872 releasePage(pPage);
73873 return rc;
73874 }
73875
73876 *piMoved = 0;
73877
73878#ifdef SQLITE_OMIT_AUTOVACUUM
73879 freePage(pPage, &rc);
73880 releasePage(pPage);
73881#else
73882 if( pBt->autoVacuum ){
73883 Pgno maxRootPgno;
73885
73886 if( iTable==maxRootPgno ){
73887 /* If the table being dropped is the table with the largest root-page
73888 ** number in the database, put the root page on the free list.
73889 */
73890 freePage(pPage, &rc);
73891 releasePage(pPage);
73892 if( rc!=SQLITE_OK ){
73893 return rc;
73894 }
73895 }else{
73896 /* The table being dropped does not have the largest root-page
73897 ** number in the database. So move the page that does into the
73898 ** gap left by the deleted root-page.
73899 */
73900 MemPage *pMove;
73901 releasePage(pPage);
73902 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
73903 if( rc!=SQLITE_OK ){
73904 return rc;
73905 }
73906 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
73907 releasePage(pMove);
73908 if( rc!=SQLITE_OK ){
73909 return rc;
73910 }
73911 pMove = 0;
73912 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
73913 freePage(pMove, &rc);
73914 releasePage(pMove);
73915 if( rc!=SQLITE_OK ){
73916 return rc;
73917 }
73918 *piMoved = maxRootPgno;
73919 }
73920
73921 /* Set the new 'max-root-page' value in the database header. This
73922 ** is the old value less one, less one more if that happens to
73923 ** be a root-page number, less one again if that is the
73924 ** PENDING_BYTE_PAGE.
73925 */
73926 maxRootPgno--;
73927 while( maxRootPgno==PENDING_BYTE_PAGE(pBt)
73928 || PTRMAP_ISPAGE(pBt, maxRootPgno) ){
73929 maxRootPgno--;
73930 }
73931 assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) );
73932
73933 rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno);
73934 }else{
SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *, int, int *)
Definition sqlite3.c:73802

References BtShared::autoVacuum, BTREE_LARGEST_ROOT_PAGE, btreeGetPage(), btreePagecount(), freePage(), Btree::inTrans, Btree::pBt, PENDING_BYTE_PAGE, PTRMAP_ISPAGE, PTRMAP_ROOTPAGE, releasePage(), relocatePage(), sqlite3BtreeClearTable(), sqlite3BtreeGetMeta(), sqlite3BtreeUpdateMeta(), SQLITE_CORRUPT_BKPT, SQLITE_OK, and TRANS_WRITE.

◆ btreeEndTransaction()

static void btreeEndTransaction ( Btree * p)
static

Definition at line 68500 of file sqlite3.c.

68506 {
68507 BtShared *pBt = p->pBt;
68508 sqlite3 *db = p->db;
68509 assert( sqlite3BtreeHoldsMutex(p) );
68510
68511#ifndef SQLITE_OMIT_AUTOVACUUM
68512 pBt->bDoTruncate = 0;
68513#endif
68514 if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){
68515 /* If there are other active statements that belong to this database
68516 ** handle, downgrade to a read-only transaction. The other statements
68517 ** may still be reading from the database. */
68519 p->inTrans = TRANS_READ;
68520 }else{
68521 /* If the handle had any kind of transaction open, decrement the
68522 ** transaction count of the shared btree. If the transaction count
68523 ** reaches 0, set the shared state to TRANS_NONE. The unlockBtreeIfUnused()
68524 ** call below will unlock the pager. */
68525 if( p->inTrans!=TRANS_NONE ){
68527 pBt->nTransaction--;
68528 if( 0==pBt->nTransaction ){
68530 }
68531 }
68532
68533 /* Set the current transaction state to TRANS_NONE and unlock the
68534 ** pager if this call closed the only read or write transaction. */
#define TRANS_READ
Definition sqlite3.c:63838
static void downgradeAllSharedCacheTableLocks(Btree *p)
Definition sqlite3.c:64934
static void clearAllSharedCacheTableLocks(Btree *p)
Definition sqlite3.c:64890
int nTransaction
Definition sqlite3.c:63897
int nVdbeRead
Definition sqlite3.c:16865

Referenced by sqlite3BtreeCommitPhaseTwo(), and sqlite3BtreeRollback().

◆ btreeEnterAll()

static void SQLITE_NOINLINE btreeEnterAll ( sqlite3 * db)
static

Definition at line 64352 of file sqlite3.c.

64358 {
64359 int i;
64360 int skipOk = 1;
64361 Btree *p;
64362 assert( sqlite3_mutex_held(db->mutex) );
64363 for(i=0; i<db->nDb; i++){
64364 p = db->aDb[i].pBt;
64365 if( p && p->sharable ){
u8 sharable
Definition sqlite3.c:63817

References sqlite3::aDb, sqlite3::mutex, sqlite3::nDb, Db::pBt, Btree::sharable, and sqlite3_mutex_held().

◆ btreeGetHasContent()

static int btreeGetHasContent ( BtShared * pBt,
Pgno pgno )
static

Definition at line 65091 of file sqlite3.c.

References BtShared::pHasContent, sqlite3BitvecSize(), and sqlite3BitvecTestNotNull().

Referenced by allocateBtreePage().

◆ btreeGetPage()

static int btreeGetPage ( BtShared * pBt,
Pgno pgno,
MemPage ** ppPage,
int flags )
static

◆ btreeGetUnusedPage()

static int btreeGetUnusedPage ( BtShared * pBt,
Pgno pgno,
MemPage ** ppPage,
int flags )
static

Definition at line 66730 of file sqlite3.c.

66730 :
66731**
66732** * If the page is already in use for some other purpose, immediately
66733** release it and return an SQLITE_CURRUPT error.
66734** * Make sure the isInit flag is clear
66735*/
66736static int btreeGetUnusedPage(
66737 BtShared *pBt, /* The btree */
66738 Pgno pgno, /* Number of the page to fetch */
66739 MemPage **ppPage, /* Return the page in this parameter */
66740 int flags /* PAGER_GET_NOCONTENT or PAGER_GET_READONLY */
66741){
66742 int rc = btreeGetPage(pBt, pgno, ppPage, flags);
66743 if( rc==SQLITE_OK ){
66744 if( sqlite3PagerPageRefcount((*ppPage)->pDbPage)>1 ){
66745 releasePage(*ppPage);
66746 *ppPage = 0;
66747 return SQLITE_CORRUPT_BKPT;
66748 }
static void error(LoadState *S, const char *why)
SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *)
Definition sqlite3.c:58438

References btreeGetPage(), MemPage::isInit, releasePage(), sqlite3PagerPageRefcount(), SQLITE_CORRUPT_BKPT, and SQLITE_OK.

Referenced by allocateBtreePage().

◆ btreeHeapInsert()

static void btreeHeapInsert ( u32 * aHeap,
u32 x )
static

Definition at line 74293 of file sqlite3.c.

74299 {
74300 u32 j, i = ++aHeap[0];
74301 aHeap[i] = x;
74302 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){

Referenced by checkTreePage().

◆ btreeHeapPull()

static int btreeHeapPull ( u32 * aHeap,
u32 * pOut )
static

Definition at line 74303 of file sqlite3.c.

74309 {
74310 u32 j, i, x;
74311 if( (x = aHeap[0])==0 ) return 0;
74312 *pOut = aHeap[1];
74313 aHeap[1] = aHeap[x];
74314 aHeap[x] = 0xffffffff;
74315 aHeap[0]--;
74316 i = 1;
74317 while( (j = i*2)<=aHeap[0] ){
74318 if( aHeap[j]>aHeap[j+1] ) j++;
74319 if( aHeap[i]<aHeap[j] ) break;
74320 x = aHeap[i];

Referenced by checkTreePage().

◆ btreeInitPage()

static int btreeInitPage ( MemPage * pPage)
static

Definition at line 66468 of file sqlite3.c.

66474 {
66475 u8 *data; /* Equal to pPage->aData */
66476 BtShared *pBt; /* The main btree structure */
66477
66478 assert( pPage->pBt!=0 );
66479 assert( pPage->pBt->db!=0 );
66480 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
66481 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
66482 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
66483 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
66484 assert( pPage->isInit==0 );
66485
66486 pBt = pPage->pBt;
66487 data = pPage->aData + pPage->hdrOffset;
66488 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
66489 ** the b-tree page type. */
66490 if( decodeFlags(pPage, data[0]) ){
66491 return SQLITE_CORRUPT_PAGE(pPage);
66492 }
66493 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
66494 pPage->maskPage = (u16)(pBt->pageSize - 1);
66495 pPage->nOverflow = 0;
66496 pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
66497 pPage->aCellIdx = data + pPage->childPtrSize + 8;
66498 pPage->aDataEnd = pPage->aData + pBt->usableSize;
66499 pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
66500 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
66501 ** number of cells on the page. */
66502 pPage->nCell = get2byte(&data[3]);
66503 if( pPage->nCell>MX_CELL(pBt) ){
66504 /* To many cells for a single page. The page must be corrupt */
66505 return SQLITE_CORRUPT_PAGE(pPage);
66506 }
66507 testcase( pPage->nCell==MX_CELL(pBt) );
66508 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
66509 ** possible for a root page of a table that contains no rows) then the
66510 ** offset to the cell content area will equal the page size minus the
66511 ** bytes of reserved space. */
66512 assert( pPage->nCell>0
66513 || get2byteNotZero(&data[5])==(int)pBt->usableSize
66514 || CORRUPT_DB );
66515 pPage->nFree = -1; /* Indicate that this value is yet uncomputed */
static int decodeFlags(MemPage *pPage, int flagByte)
Definition sqlite3.c:66292
u8 * aDataOfst
Definition sqlite3.c:63768
u8 * aCellIdx
Definition sqlite3.c:63767

References MemPage::aCellIdx, MemPage::aData, MemPage::aDataEnd, MemPage::aDataOfst, btreeCellSizeCheck(), MemPage::cellOffset, MemPage::childPtrSize, CORRUPT_DB, BtShared::db, decodeFlags(), sqlite3::flags, get2byte, get2byteNotZero, MemPage::hdrOffset, MemPage::isInit, MemPage::maskPage, BtShared::mutex, MX_CELL, MemPage::nCell, MemPage::nFree, MemPage::nOverflow, BtShared::pageSize, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, sqlite3_mutex_held(), sqlite3PagerGetData(), sqlite3PagerGetExtra(), SQLITE_CellSizeCk, SQLITE_CORRUPT_PAGE, SQLITE_OK, testcase, and BtShared::usableSize.

Referenced by checkTreePage(), copyNodeContent(), getAndInitPage(), modifyPagePointer(), pageReinit(), and setChildPtrmaps().

◆ btreeInvokeBusyHandler()

static int btreeInvokeBusyHandler ( void * pArg)
static

Definition at line 66781 of file sqlite3.c.

Referenced by sqlite3BtreeBeginTrans(), and sqlite3BtreeOpen().

◆ btreeLeaveAll()

static void SQLITE_NOINLINE btreeLeaveAll ( sqlite3 * db)
static

Definition at line 64369 of file sqlite3.c.

64372 {
64373 if( db->noSharedCache==0 ) btreeEnterAll(db);
64374}
64375static void SQLITE_NOINLINE btreeLeaveAll(sqlite3 *db){
64376 int i;
64377 Btree *p;
#define SQLITE_NOINLINE
Definition sqlite3.c:13529
static void SQLITE_NOINLINE btreeLeaveAll(sqlite3 *db)
Definition sqlite3.c:64369
static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db)
Definition sqlite3.c:64352

◆ btreeLockCarefully()

static void SQLITE_NOINLINE btreeLockCarefully ( Btree * p)
static

Definition at line 64271 of file sqlite3.c.

64277 {
64278 Btree *pLater;
64279
64280 /* In most cases, we should be able to acquire the lock we
64281 ** want without having to go through the ascending lock
64282 ** procedure that follows. Just be sure not to block.
64283 */
64285 p->pBt->db = p->db;
64286 p->locked = 1;
64287 return;
64288 }
64289
64290 /* To avoid deadlock, first release all locks with a larger
64291 ** BtShared address. Then acquire our lock. Then reacquire
64292 ** the other BtShared locks that we used to hold in ascending
64293 ** order.
64294 */
64295 for(pLater=p->pNext; pLater; pLater=pLater->pNext){
64296 assert( pLater->sharable );
64297 assert( pLater->pNext==0 || pLater->pNext->pBt>pLater->pBt );
64298 assert( !pLater->locked || pLater->wantToLock>0 );
64299 if( pLater->locked ){
64300 unlockBtreeMutex(pLater);
64301 }
64302 }
64303 lockBtreeMutex(p);
SQLITE_API int sqlite3_mutex_try(sqlite3_mutex *)
Definition sqlite3.c:25965
static void SQLITE_NOINLINE unlockBtreeMutex(Btree *p)
Definition sqlite3.c:64207
static void lockBtreeMutex(Btree *p)
Definition sqlite3.c:64193
u8 locked
Definition sqlite3.c:63818
int wantToLock
Definition sqlite3.c:63820
Btree * pNext
Definition sqlite3.c:63823

References Btree::db, BtShared::db, lockBtreeMutex(), Btree::locked, BtShared::mutex, Btree::pBt, Btree::pNext, Btree::sharable, sqlite3_mutex_try(), SQLITE_OK, unlockBtreeMutex(), and Btree::wantToLock.

Referenced by sqlite3BtreeEnter().

◆ btreeMoveto()

static int btreeMoveto ( BtCursor * pCur,
const void * pKey,
i64 nKey,
int bias,
int * pRes )
static

Definition at line 65278 of file sqlite3.c.

65290 {
65291 int rc; /* Status code */
65292 UnpackedRecord *pIdxKey; /* Unpacked index key */
65293
65294 if( pKey ){
65295 KeyInfo *pKeyInfo = pCur->pKeyInfo;
65296 assert( nKey==(i64)(int)nKey );
65297 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
65298 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
65299 sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
65300 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
65302 goto moveto_done;
65303 }
65304 }else{
65305 pIdxKey = 0;
65306 }
65307 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo *, int, const void *, UnpackedRecord *)
Definition sqlite3.c:81748
SQLITE_PRIVATE UnpackedRecord * sqlite3VdbeAllocUnpackedRecord(KeyInfo *)
Definition sqlite3.c:81728
SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(BtCursor *, UnpackedRecord *pUnKey, i64 intKey, int bias, int *pRes)
Definition sqlite3.c:69888
u16 nAllField
Definition sqlite3.c:17683

References KeyInfo::db, KeyInfo::nAllField, UnpackedRecord::nField, BtCursor::pKeyInfo, sqlite3BtreeMovetoUnpacked(), sqlite3DbFree(), sqlite3VdbeAllocUnpackedRecord(), sqlite3VdbeRecordUnpack(), SQLITE_CORRUPT_BKPT, and SQLITE_NOMEM_BKPT.

Referenced by btreeRestoreCursorPosition(), and sqlite3BtreeInsert().

◆ btreeNext()

static SQLITE_NOINLINE int btreeNext ( BtCursor * pCur)
static

Definition at line 70192 of file sqlite3.c.

70198 {
70199 int rc;
70200 int idx;
70201 MemPage *pPage;
70202
70203 assert( cursorOwnsBtShared(pCur) );
70204 if( pCur->eState!=CURSOR_VALID ){
70205 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
70206 rc = restoreCursorPosition(pCur);
70207 if( rc!=SQLITE_OK ){
70208 return rc;
70209 }
70210 if( CURSOR_INVALID==pCur->eState ){
70211 return SQLITE_DONE;
70212 }
70213 if( pCur->eState==CURSOR_SKIPNEXT ){
70214 pCur->eState = CURSOR_VALID;
70215 if( pCur->skipNext>0 ) return SQLITE_OK;
70216 }
70217 }
70218
70219 pPage = pCur->pPage;
70220 idx = ++pCur->ix;
70221 if( !pPage->isInit ){
70222 /* The only known way for this to happen is for there to be a
70223 ** recursive SQL function that does a DELETE operation as part of a
70224 ** SELECT which deletes content out from under an active cursor
70225 ** in a corrupt database file where the table being DELETE-ed from
70226 ** has pages in common with the table being queried. See TH3
70227 ** module cov1/btree78.test testcase 220 (2018-06-08) for an
70228 ** example. */
70229 return SQLITE_CORRUPT_BKPT;
70230 }
70231
70232 /* If the database file is corrupt, it is possible for the value of idx
70233 ** to be invalid here. This can only occur if a second cursor modifies
70234 ** the page while cursor pCur is holding a reference to it. Which can
70235 ** only happen if the database is corrupt in such a way as to link the
70236 ** page into more than one b-tree structure.
70237 **
70238 ** Update 2019-12-23: appears to long longer be possible after the
70239 ** addition of anotherValidCursor() condition on balance_deeper(). */
70240 harmless( idx>pPage->nCell );
70241
70242 if( idx>=pPage->nCell ){
70243 if( !pPage->leaf ){
70244 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
70245 if( rc ) return rc;
70246 return moveToLeftmost(pCur);
70247 }
70248 do{
70249 if( pCur->iPage==0 ){
70250 pCur->eState = CURSOR_INVALID;
70251 return SQLITE_DONE;
70252 }
70253 moveToParent(pCur);
70254 pPage = pCur->pPage;
70255 }while( pCur->ix>=pPage->nCell );
70256 if( pPage->intKey ){
70257 return sqlite3BtreeNext(pCur, 0);
70258 }else{
70259 return SQLITE_OK;
70260 }
70261 }
#define harmless(X)
Definition sqlite3.c:13757
static int moveToChild(BtCursor *pCur, u32 newPgno)
Definition sqlite3.c:69571
#define restoreCursorPosition(p)
Definition sqlite3.c:65342
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *, int flags)
Definition sqlite3.c:70262
static void moveToParent(BtCursor *pCur)
Definition sqlite3.c:69620
static int moveToLeftmost(BtCursor *pCur)
Definition sqlite3.c:69748
int skipNext
Definition sqlite3.c:63980
u8 intKey
Definition sqlite3.c:63745

References MemPage::aData, BTCF_ValidOvfl, BtCursor::curFlags, CURSOR_INVALID, CURSOR_SKIPNEXT, CURSOR_VALID, BtCursor::eState, get4byte, harmless, MemPage::hdrOffset, MemPage::intKey, BtCursor::iPage, MemPage::isInit, BtCursor::ix, MemPage::leaf, moveToChild(), moveToLeftmost(), moveToParent(), MemPage::nCell, BtCursor::pPage, restoreCursorPosition, BtCursor::skipNext, sqlite3BtreeNext(), SQLITE_CORRUPT_BKPT, SQLITE_DONE, and SQLITE_OK.

◆ btreeOverwriteCell()

static int btreeOverwriteCell ( BtCursor * pCur,
const BtreePayload * pX )
static

Definition at line 73030 of file sqlite3.c.

73036 {
73037 int iOffset; /* Next byte of pX->pData to write */
73038 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
73039 int rc; /* Return code */
73040 MemPage *pPage = pCur->pPage; /* Page being written */
73041 BtShared *pBt; /* Btree */
73042 Pgno ovflPgno; /* Next overflow page to write */
73043 u32 ovflPageSize; /* Size to write on overflow page */
73044
73045 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
73046 || pCur->info.pPayload < pPage->aData + pPage->cellOffset
73047 ){
73048 return SQLITE_CORRUPT_BKPT;
73049 }
73050 /* Overwrite the local portion first */
73051 rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
73052 0, pCur->info.nLocal);
73053 if( rc ) return rc;
73054 if( pCur->info.nLocal==nTotal ) return SQLITE_OK;
73055
73056 /* Now overwrite the overflow pages */
73057 iOffset = pCur->info.nLocal;
73058 assert( nTotal>=0 );
73059 assert( iOffset>=0 );
73060 ovflPgno = get4byte(pCur->info.pPayload + iOffset);
73061 pBt = pPage->pBt;
73062 ovflPageSize = pBt->usableSize - 4;
73063 do{
73064 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
73065 if( rc ) return rc;
73066 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
73068 }else{
73069 if( iOffset+ovflPageSize<(u32)nTotal ){
73070 ovflPgno = get4byte(pPage->aData);
73071 }else{
73072 ovflPageSize = nTotal - iOffset;
73073 }
73074 rc = btreeOverwriteContent(pPage, pPage->aData+4, pX,
73075 iOffset, ovflPageSize);
73076 }
static int btreeOverwriteContent(MemPage *pPage, u8 *pDest, const BtreePayload *pX, int iOffset, int iAmt)
Definition sqlite3.c:72987

Referenced by sqlite3BtreeInsert().

◆ btreeOverwriteContent()

static int btreeOverwriteContent ( MemPage * pPage,
u8 * pDest,
const BtreePayload * pX,
int iOffset,
int iAmt )
static

Definition at line 72987 of file sqlite3.c.

72999 {
73000 int nData = pX->nData - iOffset;
73001 if( nData<=0 ){
73002 /* Overwritting with zeros */
73003 int i;
73004 for(i=0; i<iAmt && pDest[i]==0; i++){}
73005 if( i<iAmt ){
73006 int rc = sqlite3PagerWrite(pPage->pDbPage);
73007 if( rc ) return rc;
73008 memset(pDest + i, 0, iAmt - i);
73009 }
73010 }else{
73011 if( nData<iAmt ){
73012 /* Mixed read data and zeros at the end. Make a recursive call
73013 ** to write the zeros then fall through to write the real data */
73014 int rc = btreeOverwriteContent(pPage, pDest+nData, pX, iOffset+nData,
73015 iAmt-nData);
73016 if( rc ) return rc;
73017 iAmt = nData;
73018 }
73019 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
73020 int rc = sqlite3PagerWrite(pPage->pDbPage);
73021 if( rc ) return rc;
73022 /* In a corrupt database, it is possible for the source and destination
73023 ** buffers to overlap. This is harmless since the database is already
73024 ** corrupt but it does cause valgrind and ASAN warnings. So use
const void * pData
Definition sqlite3.c:15291

◆ btreePagecount()

◆ btreePageFromDbPage()

static MemPage * btreePageFromDbPage ( DbPage * pDbPage,
Pgno pgno,
BtShared * pBt )
static

Definition at line 66558 of file sqlite3.c.

66564 {
66565 MemPage *pPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
66566 if( pgno!=pPage->pgno ){
66567 pPage->aData = sqlite3PagerGetData(pDbPage);
66568 pPage->pDbPage = pDbPage;
66569 pPage->pBt = pBt;

References MemPage::aData, MemPage::hdrOffset, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, sqlite3PagerGetData(), and sqlite3PagerGetExtra().

Referenced by btreeGetPage(), btreePageLookup(), and getAndInitPage().

◆ btreePageLookup()

static MemPage * btreePageLookup ( BtShared * pBt,
Pgno pgno )
static

Definition at line 66604 of file sqlite3.c.

66610 {
66611 DbPage *pDbPage;
66612 assert( sqlite3_mutex_held(pBt->mutex) );

References btreePageFromDbPage(), BtShared::mutex, BtShared::pPager, sqlite3_mutex_held(), and sqlite3PagerLookup().

Referenced by freePage2().

◆ btreeParseCell()

static void btreeParseCell ( MemPage * pPage,
int iCell,
CellInfo * pInfo )
static

Definition at line 65748 of file sqlite3.c.

65750 {
65751 btreeParseCellAdjustSizeForOverflow(pPage, pCell, pInfo);
65752 }
65753}
65754static void btreeParseCell(
static void btreeParseCell(MemPage *pPage, int iCell, CellInfo *pInfo)
Definition sqlite3.c:65748
static SQLITE_NOINLINE void btreeParseCellAdjustSizeForOverflow(MemPage *pPage, u8 *pCell, CellInfo *pInfo)
Definition sqlite3.c:65581

◆ btreeParseCellAdjustSizeForOverflow()

static SQLITE_NOINLINE void btreeParseCellAdjustSizeForOverflow ( MemPage * pPage,
u8 * pCell,
CellInfo * pInfo )
static

Definition at line 65581 of file sqlite3.c.

65591 {
65592 /* If the payload will not fit completely on the local page, we have
65593 ** to decide how much to store locally and how much to spill onto
65594 ** overflow pages. The strategy is to minimize the amount of unused
65595 ** space on overflow pages while keeping the amount of local storage
65596 ** in between minLocal and maxLocal.
65597 **
65598 ** Warning: changing the way overflow payload is distributed in any
65599 ** way will result in an incompatible file format.
65600 */
65601 int minLocal; /* Minimum amount of payload held locally */
65602 int maxLocal; /* Maximum amount of payload held locally */
65603 int surplus; /* Overflow payload available for local storage */
65604
65605 minLocal = pPage->minLocal;
65606 maxLocal = pPage->maxLocal;
65607 surplus = minLocal + (pInfo->nPayload - minLocal)%(pPage->pBt->usableSize-4);
65608 testcase( surplus==maxLocal );
65609 testcase( surplus==maxLocal+1 );
65610 if( surplus <= maxLocal ){
u16 maxLocal
Definition sqlite3.c:63755

References MemPage::maxLocal, MemPage::minLocal, CellInfo::nLocal, CellInfo::nPayload, CellInfo::nSize, MemPage::pBt, CellInfo::pPayload, testcase, and BtShared::usableSize.

◆ btreeParseCellPtr()

static void btreeParseCellPtr ( MemPage * pPage,
u8 * pCell,
CellInfo * pInfo )
static

Definition at line 65643 of file sqlite3.c.

65653 {
65654 u8 *pIter; /* For scanning through pCell */
65655 u32 nPayload; /* Number of bytes of cell payload */
65656 u64 iKey; /* Extracted Key value */
65657
65658 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65659 assert( pPage->leaf==0 || pPage->leaf==1 );
65660 assert( pPage->intKeyLeaf );
65661 assert( pPage->childPtrSize==0 );
65662 pIter = pCell;
65663
65664 /* The next block of code is equivalent to:
65665 **
65666 ** pIter += getVarint32(pIter, nPayload);
65667 **
65668 ** The code is inlined to avoid a function call.
65669 */
65670 nPayload = *pIter;
65671 if( nPayload>=0x80 ){
65672 u8 *pEnd = &pIter[8];
65673 nPayload &= 0x7f;
65674 do{
65675 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
65676 }while( (*pIter)>=0x80 && pIter<pEnd );
65677 }
65678 pIter++;
65679
65680 /* The next block of code is equivalent to:
65681 **
65682 ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
65683 **
65684 ** The code is inlined to avoid a function call.
65685 */
65686 iKey = *pIter;
65687 if( iKey>=0x80 ){
65688 u8 *pEnd = &pIter[7];
65689 iKey &= 0x7f;
65690 while(1){
65691 iKey = (iKey<<7) | (*++pIter & 0x7f);
65692 if( (*pIter)<0x80 ) break;
65693 if( pIter>=pEnd ){
65694 iKey = (iKey<<8) | *++pIter;
65695 break;
65696 }
65697 }
65698 }
65699 pIter++;
65700
65701 pInfo->nKey = *(i64*)&iKey;
65702 pInfo->nPayload = nPayload;
65703 pInfo->pPayload = pIter;
65704 testcase( nPayload==pPage->maxLocal );
65705 testcase( nPayload==pPage->maxLocal+1 );
65706 if( nPayload<=pPage->maxLocal ){
65707 /* This is the (easy) common case where the entire payload fits
65708 ** on the local page. No overflow is required.
65709 */
65710 pInfo->nSize = nPayload + (u16)(pIter - pCell);
sqlite_uint64 u64
Definition sqlite3.c:14330
u16 nSize
Definition sqlite3.c:63935

Referenced by decodeFlags().

◆ btreeParseCellPtrIndex()

static void btreeParseCellPtrIndex ( MemPage * pPage,
u8 * pCell,
CellInfo * pInfo )
static

Definition at line 65711 of file sqlite3.c.

65713 {
65714 btreeParseCellAdjustSizeForOverflow(pPage, pCell, pInfo);
65715 }
65716}
65717static void btreeParseCellPtrIndex(
65718 MemPage *pPage, /* Page containing the cell */
65719 u8 *pCell, /* Pointer to the cell text. */
65720 CellInfo *pInfo /* Fill in this structure */
65721){
65722 u8 *pIter; /* For scanning through pCell */
65723 u32 nPayload; /* Number of bytes of cell payload */
65724
65725 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65726 assert( pPage->leaf==0 || pPage->leaf==1 );
65727 assert( pPage->intKeyLeaf==0 );
65728 pIter = pCell + pPage->childPtrSize;
65729 nPayload = *pIter;
65730 if( nPayload>=0x80 ){
65731 u8 *pEnd = &pIter[8];
65732 nPayload &= 0x7f;
65733 do{
65734 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
65735 }while( *(pIter)>=0x80 && pIter<pEnd );
65736 }
65737 pIter++;
65738 pInfo->nKey = nPayload;
65739 pInfo->nPayload = nPayload;
65740 pInfo->pPayload = pIter;
65741 testcase( nPayload==pPage->maxLocal );
65742 testcase( nPayload==pPage->maxLocal+1 );
65743 if( nPayload<=pPage->maxLocal ){
65744 /* This is the (easy) common case where the entire payload fits
65745 ** on the local page. No overflow is required.
65746 */
65747 pInfo->nSize = nPayload + (u16)(pIter - pCell);
static void btreeParseCellPtrIndex(MemPage *pPage, u8 *pCell, CellInfo *pInfo)
Definition sqlite3.c:65711

Referenced by decodeFlags().

◆ btreeParseCellPtrNoPayload()

static void btreeParseCellPtrNoPayload ( MemPage * pPage,
u8 * pCell,
CellInfo * pInfo )
static

Definition at line 65626 of file sqlite3.c.

65636 {
65637 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65638 assert( pPage->leaf==0 );
65639 assert( pPage->childPtrSize==4 );
65640#ifndef SQLITE_DEBUG
65641 UNUSED_PARAMETER(pPage);
65642#endif

References MemPage::childPtrSize, MemPage::leaf, BtShared::mutex, MemPage::pBt, sqlite3_mutex_held(), and UNUSED_PARAMETER.

Referenced by decodeFlags().

◆ btreePrevious()

static SQLITE_NOINLINE int btreePrevious ( BtCursor * pCur)
static

Definition at line 70302 of file sqlite3.c.

70308 {
70309 int rc;
70310 MemPage *pPage;
70311
70312 assert( cursorOwnsBtShared(pCur) );
70313 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
70314 assert( pCur->info.nSize==0 );
70315 if( pCur->eState!=CURSOR_VALID ){
70316 rc = restoreCursorPosition(pCur);
70317 if( rc!=SQLITE_OK ){
70318 return rc;
70319 }
70320 if( CURSOR_INVALID==pCur->eState ){
70321 return SQLITE_DONE;
70322 }
70323 if( CURSOR_SKIPNEXT==pCur->eState ){
70324 pCur->eState = CURSOR_VALID;
70325 if( pCur->skipNext<0 ) return SQLITE_OK;
70326 }
70327 }
70328
70329 pPage = pCur->pPage;
70330 assert( pPage->isInit );
70331 if( !pPage->leaf ){
70332 int idx = pCur->ix;
70333 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
70334 if( rc ) return rc;
70335 rc = moveToRightmost(pCur);
70336 }else{
70337 while( pCur->ix==0 ){
70338 if( pCur->iPage==0 ){
70339 pCur->eState = CURSOR_INVALID;
70340 return SQLITE_DONE;
70341 }
70342 moveToParent(pCur);
70343 }
70344 assert( pCur->info.nSize==0 );
70345 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
70346
70347 pCur->ix--;
70348 pPage = pCur->pPage;
70349 if( pPage->intKey && !pPage->leaf ){
70350 rc = sqlite3BtreePrevious(pCur, 0);
static int moveToRightmost(BtCursor *pCur)
Definition sqlite3.c:69773
#define BTCF_ValidNKey
Definition sqlite3.c:64007
#define BTCF_AtLast
Definition sqlite3.c:64009
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *, int flags)
Definition sqlite3.c:70351

References BTCF_AtLast, BTCF_ValidNKey, BTCF_ValidOvfl, BtCursor::curFlags, CURSOR_INVALID, CURSOR_SKIPNEXT, CURSOR_VALID, BtCursor::eState, findCell, get4byte, BtCursor::info, MemPage::intKey, BtCursor::iPage, MemPage::isInit, BtCursor::ix, MemPage::leaf, moveToChild(), moveToParent(), moveToRightmost(), CellInfo::nSize, BtCursor::pPage, restoreCursorPosition, BtCursor::skipNext, sqlite3BtreePrevious(), SQLITE_DONE, and SQLITE_OK.

◆ btreeReleaseAllCursorPages()

static void btreeReleaseAllCursorPages ( BtCursor * pCur)
static

Definition at line 65108 of file sqlite3.c.

65114 {
65115 int i;
65116 if( pCur->iPage>=0 ){
65117 for(i=0; i<pCur->iPage; i++){

Referenced by saveCursorPosition(), saveCursorsOnList(), sqlite3BtreeDelete(), sqlite3BtreeInsert(), and sqlite3BtreeTripAllCursors().

◆ btreeRestoreCursorPosition()

static int btreeRestoreCursorPosition ( BtCursor * pCur)
static

Definition at line 65316 of file sqlite3.c.

65322 {
65323 int rc;
65324 int skipNext = 0;
65325 assert( cursorOwnsBtShared(pCur) );
65326 assert( pCur->eState>=CURSOR_REQUIRESEEK );
65327 if( pCur->eState==CURSOR_FAULT ){
65328 return pCur->skipNext;
65329 }
65330 pCur->eState = CURSOR_INVALID;
65331 if( sqlite3FaultSim(410) ){
65332 rc = SQLITE_IOERR;
65333 }else{
65334 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
65335 }
65336 if( rc==SQLITE_OK ){
65337 sqlite3_free(pCur->pKey);
65338 pCur->pKey = 0;
65339 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
65340 if( skipNext ) pCur->skipNext = skipNext;
static int btreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int bias, int *pRes)
Definition sqlite3.c:65278
#define CURSOR_FAULT
Definition sqlite3.c:64048
#define SQLITE_IOERR
Definition sqlite3.c:1480
SQLITE_PRIVATE int sqlite3FaultSim(int)
Definition sqlite3.c:31234
void * pKey
Definition sqlite3.c:63984

References btreeMoveto(), CURSOR_FAULT, CURSOR_INVALID, CURSOR_REQUIRESEEK, CURSOR_VALID, BtCursor::eState, BtCursor::nKey, BtCursor::pKey, BtCursor::skipNext, sqlite3_free(), sqlite3FaultSim(), SQLITE_IOERR, and SQLITE_OK.

Referenced by sqlite3BtreeDelete().

◆ btreeSetHasContent()

static int btreeSetHasContent ( BtShared * pBt,
Pgno pgno )
static

Definition at line 65069 of file sqlite3.c.

65075 {
65076 int rc = SQLITE_OK;
65077 if( !pBt->pHasContent ){
65078 assert( pgno<=pBt->nPage );
65080 if( !pBt->pHasContent ){
65081 rc = SQLITE_NOMEM_BKPT;
65082 }
SQLITE_PRIVATE Bitvec * sqlite3BitvecCreate(u32)
Definition sqlite3.c:48574
Bitvec * pHasContent
Definition sqlite3.c:63902

References BtShared::nPage, BtShared::pHasContent, sqlite3BitvecCreate(), sqlite3BitvecSet(), sqlite3BitvecSize(), SQLITE_NOMEM_BKPT, and SQLITE_OK.

Referenced by freePage2().

◆ btreeSetNPage()

static void btreeSetNPage ( BtShared * pBt,
MemPage * pPage1 )
static

Definition at line 68663 of file sqlite3.c.

68669 {

Referenced by sqlite3BtreeRollback(), and sqlite3BtreeSavepoint().

◆ cachedCellSize()

static u16 cachedCellSize ( CellArray * p,
int N )
static

Definition at line 71397 of file sqlite3.c.

71397 {
71398 assert( N>=0 && N<p->nCell );
71399 assert( p->szCell[N]==0 );
71400 p->szCell[N] = p->pRef->xCellSize(p->pRef, p->apCell[N]);
71401 return p->szCell[N];

References CellArray::apCell, CellArray::pRef, CellArray::szCell, and MemPage::xCellSize.

Referenced by balance_nonroot(), and editPage().

◆ callCollNeeded()

static void callCollNeeded ( sqlite3 * db,
int enc,
const char * zName )
static

Definition at line 115559 of file sqlite3.c.

115565 {
115566 assert( !db->xCollNeeded || !db->xCollNeeded16 );
115567 if( db->xCollNeeded ){
115568 char *zExternal = sqlite3DbStrDup(db, zName);
115569 if( !zExternal ) return;
115570 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
115571 sqlite3DbFree(db, zExternal);
115572 }
115573#ifndef SQLITE_OMIT_UTF16
115574 if( db->xCollNeeded16 ){
115575 char const *zExternal;
115576 sqlite3_value *pTmp = sqlite3ValueNew(db);
115578 zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
115579 if( zExternal ){
#define SQLITE_UTF16NATIVE
Definition sqlite3.c:14456
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value *, int, const void *, u8, void(*)(void *))
Definition sqlite3.c:77687
#define SQLITE_STATIC
Definition sqlite3.c:6670
SQLITE_PRIVATE sqlite3_value * sqlite3ValueNew(sqlite3 *)
Definition sqlite3.c:77116
SQLITE_PRIVATE const void * sqlite3ValueText(sqlite3_value *, u8)
Definition sqlite3.c:77098
void(* xCollNeeded)(void *, sqlite3 *, int eTextRep, const char *)
Definition sqlite3.c:16898
void(* xCollNeeded16)(void *, sqlite3 *, int eTextRep, const void *)
Definition sqlite3.c:16899
void * pCollNeededArg
Definition sqlite3.c:16900

References ENC, sqlite3::pCollNeededArg, sqlite3DbFree(), sqlite3DbStrDup(), sqlite3ValueFree(), sqlite3ValueNew(), sqlite3ValueSetStr(), sqlite3ValueText(), SQLITE_STATIC, SQLITE_UTF16NATIVE, SQLITE_UTF8, sqlite3::xCollNeeded, sqlite3::xCollNeeded16, and zName.

Referenced by sqlite3GetCollSeq().

◆ callFinaliser()

static void callFinaliser ( sqlite3 * db,
int offset )
static

Definition at line 140492 of file sqlite3.c.

140498 {
140499 int i;
140500 if( db->aVTrans ){
140501 VTable **aVTrans = db->aVTrans;
140502 db->aVTrans = 0;
140503 for(i=0; i<db->nVTrans; i++){
140504 VTable *pVTab = aVTrans[i];
140505 sqlite3_vtab *p = pVTab->pVtab;
140506 if( p ){
140507 int (*x)(sqlite3_vtab *);
140508 x = *(int (**)(sqlite3_vtab *))((char *)p->pModule + offset);
140509 if( x ) x(p);
140510 }
140511 pVTab->iSavepoint = 0;
int iSavepoint
Definition sqlite3.c:17473
sqlite3_vtab * pVtab
Definition sqlite3.c:17469
const sqlite3_module * pModule
Definition sqlite3.c:8045
int nVTrans
Definition sqlite3.c:16917
VTable ** aVTrans
Definition sqlite3.c:16920

References sqlite3::aVTrans, VTable::iSavepoint, sqlite3::nVTrans, sqlite3_vtab::pModule, VTable::pVtab, sqlite3DbFree(), and sqlite3VtabUnlock().

◆ callStatGet()

static void callStatGet ( Parse * pParse,
int regStat,
int iParam,
int regOut )
static

Definition at line 108484 of file sqlite3.c.

108487 {0}
108488};
108489
108490static void callStatGet(Parse *pParse, int regStat, int iParam, int regOut){
108491#ifdef SQLITE_ENABLE_STAT4
108492 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Integer, iParam, regStat+1);
108493#elif SQLITE_DEBUG
108494 assert( iParam==STAT_GET_STAT1 );
108495#else

Referenced by analyzeOneTable().

◆ cannotBeFunction()

static int cannotBeFunction ( Parse * pParse,
struct SrcList_item * pFrom )
static

Definition at line 133996 of file sqlite3.c.

134002 {

References sqlite3ErrorMsg().

Referenced by selectExpander(), and withExpand().

◆ cdateFunc()

static void cdateFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 22866 of file sqlite3.c.

References dateFunc(), and UNUSED_PARAMETER2.

Referenced by sqlite3RegisterDateTimeFunctions().

◆ cellSizePtr()

static u16 cellSizePtr ( MemPage * pPage,
u8 * pCell )
static

Definition at line 65768 of file sqlite3.c.

65774 {
65775 u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
65776 u8 *pEnd; /* End mark for a varint */
65777 u32 nSize; /* Size value to return */
65778
65779#ifdef SQLITE_DEBUG
65780 /* The value returned by this function should always be the same as
65781 ** the (CellInfo.nSize) value found by doing a full parse of the
65782 ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
65783 ** this function verifies that this invariant is not violated. */
65784 CellInfo debuginfo;
65785 pPage->xParseCell(pPage, pCell, &debuginfo);
65786#endif
65787
65788 nSize = *pIter;
65789 if( nSize>=0x80 ){
65790 pEnd = &pIter[8];
65791 nSize &= 0x7f;
65792 do{
65793 nSize = (nSize<<7) | (*++pIter & 0x7f);
65794 }while( *(pIter)>=0x80 && pIter<pEnd );
65795 }
65796 pIter++;
65797 if( pPage->intKey ){
65798 /* pIter now points at the 64-bit integer key value, a variable length
65799 ** integer. The following block moves pIter to point at the first byte
65800 ** past the end of the key value. */
65801 pEnd = &pIter[9];
65802 while( (*pIter++)&0x80 && pIter<pEnd );
65803 }
65804 testcase( nSize==pPage->maxLocal );
65805 testcase( nSize==pPage->maxLocal+1 );
65806 if( nSize<=pPage->maxLocal ){
65807 nSize += (u32)(pIter - pCell);
65808 if( nSize<4 ) nSize = 4;
65809 }else{
65810 int minLocal = pPage->minLocal;
65811 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
65812 testcase( nSize==pPage->maxLocal );
65813 testcase( nSize==pPage->maxLocal+1 );
65814 if( nSize>pPage->maxLocal ){
65815 nSize = minLocal;

References MemPage::childPtrSize, MemPage::intKey, MemPage::maxLocal, MemPage::minLocal, MemPage::pBt, testcase, BtShared::usableSize, and MemPage::xParseCell.

Referenced by decodeFlags(), and sqlite3BtreeDelete().

◆ cellSizePtrNoPayload()

static u16 cellSizePtrNoPayload ( MemPage * pPage,
u8 * pCell )
static

Definition at line 65816 of file sqlite3.c.

65822 {
65823 u8 *pIter = pCell + 4; /* For looping over bytes of pCell */
65824 u8 *pEnd; /* End mark for a varint */
65825
65826#ifdef SQLITE_DEBUG
65827 /* The value returned by this function should always be the same as
65828 ** the (CellInfo.nSize) value found by doing a full parse of the
65829 ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
65830 ** this function verifies that this invariant is not violated. */
65831 CellInfo debuginfo;
65832 pPage->xParseCell(pPage, pCell, &debuginfo);
65833#else
65834 UNUSED_PARAMETER(pPage);
65835#endif
65836

Referenced by decodeFlags().

◆ changes()

static void changes ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 117622 of file sqlite3.c.

117624 : R-62073-11209 The changes() SQL function is a wrapper
117625** around the sqlite3_changes() C/C++ function and hence follows the same
117626** rules for counting changes.
117627*/
117628static void changes(
117629 sqlite3_context *context,
117630 int NotUsed,
static void changes(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117622
SQLITE_API int sqlite3_changes(sqlite3 *)
Definition sqlite3.c:162082

References sqlite3_changes(), sqlite3_context_db_handle(), sqlite3_result_int(), and UNUSED_PARAMETER2.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ changeTempStorage()

static int changeTempStorage ( Parse * pParse,
const char * zStorageType )
static

Definition at line 125892 of file sqlite3.c.

125898 {
125899 int ts = getTempStore(zStorageType);
125900 sqlite3 *db = pParse->db;
125901 if( db->temp_store==ts ) return SQLITE_OK;
static int getTempStore(const char *z)
Definition sqlite3.c:125852
u8 temp_store
Definition sqlite3.c:16838

References Parse::db, getTempStore(), invalidateTempStorage(), SQLITE_ERROR, SQLITE_OK, and sqlite3::temp_store.

Referenced by sqlite3Pragma().

◆ charFunc()

static void charFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118170 of file sqlite3.c.

118180 {
118181 unsigned char *z, *zOut;
118182 int i;
118183 zOut = z = sqlite3_malloc64( argc*4+1 );
118184 if( z==0 ){
118186 return;
118187 }
118188 for(i=0; i<argc; i++){
118189 sqlite3_int64 x;
118190 unsigned c;
118191 x = sqlite3_value_int64(argv[i]);
118192 if( x<0 || x>0x10ffff ) x = 0xfffd;
118193 c = (unsigned)(x & 0x1fffff);
118194 if( c<0x00080 ){
118195 *zOut++ = (u8)(c&0xFF);
118196 }else if( c<0x00800 ){
118197 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F);
118198 *zOut++ = 0x80 + (u8)(c & 0x3F);
118199 }else if( c<0x10000 ){
118200 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F);
118201 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
118202 *zOut++ = 0x80 + (u8)(c & 0x3F);
118203 }else{
118204 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07);
118205 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
SQLITE_API void * sqlite3_malloc64(sqlite3_uint64)
Definition sqlite3.c:27621
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *)
Definition sqlite3.c:83540

References sqlite3_free(), sqlite3_malloc64(), sqlite3_result_error_nomem(), sqlite3_result_text64(), sqlite3_value_int64(), and SQLITE_UTF8.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ checkAppendMsg()

static void checkAppendMsg ( IntegrityCk * pCheck,
const char * zFormat,
... )
static

Definition at line 74103 of file sqlite3.c.

74113 {
74114 va_list ap;
74115 if( !pCheck->mxErr ) return;
74116 pCheck->mxErr--;
74117 pCheck->nErr++;
74118 va_start(ap, zFormat);
74119 if( pCheck->errMsg.nChar ){
74120 sqlite3_str_append(&pCheck->errMsg, "\n", 1);
74121 }
74122 if( pCheck->zPfx ){
74123 sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
74124 }
SQLITE_API void sqlite3_str_appendf(sqlite3_str *, const char *zFormat,...)
Definition sqlite3.c:29440
SQLITE_API void sqlite3_str_append(sqlite3_str *, const char *zIn, int N)
Definition sqlite3.c:29123
const char * zPfx
Definition sqlite3.c:64152
StrAccum errMsg
Definition sqlite3.c:64155

Referenced by checkList(), checkPtrmap(), checkRef(), checkTreePage(), and sqlite3BtreeIntegrityCheck().

◆ checkColumnOverlap()

static int checkColumnOverlap ( IdList * pIdList,
ExprList * pEList )
static

◆ checkConstraintExprNode()

static int checkConstraintExprNode ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 121897 of file sqlite3.c.

121903 {
121904 if( pExpr->op==TK_COLUMN ){
121905 assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
121906 if( pExpr->iColumn>=0 ){
121907 if( pWalker->u.aiCol[pExpr->iColumn]>=0 ){
121908 pWalker->eCode |= CKCNSTRNT_COLUMN;
121909 }
#define CKCNSTRNT_COLUMN
Definition sqlite3.c:121889
u16 eCode
Definition sqlite3.c:19096
int * aiCol
Definition sqlite3.c:19104

References Walker::aiCol, CKCNSTRNT_COLUMN, CKCNSTRNT_ROWID, Walker::eCode, Expr::iColumn, Expr::op, TK_COLUMN, Walker::u, and WRC_Continue.

Referenced by sqlite3ExprReferencesUpdatedColumn().

◆ checkList()

static void checkList ( IntegrityCk * pCheck,
int isFreeList,
Pgno iPage,
u32 N )
static

Definition at line 74204 of file sqlite3.c.

74215 {
74216 int i;
74217 u32 expected = N;
74218 int nErrAtStart = pCheck->nErr;
74219 while( iPage!=0 && pCheck->mxErr ){
74220 DbPage *pOvflPage;
74221 unsigned char *pOvflData;
74222 if( checkRef(pCheck, iPage) ) break;
74223 N--;
74224 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
74225 checkAppendMsg(pCheck, "failed to get page %d", iPage);
74226 break;
74227 }
74228 pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage);
74229 if( isFreeList ){
74230 u32 n = (u32)get4byte(&pOvflData[4]);
74231#ifndef SQLITE_OMIT_AUTOVACUUM
74232 if( pCheck->pBt->autoVacuum ){
74233 checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0);
74234 }
74235#endif
74236 if( n>pCheck->pBt->usableSize/4-2 ){
74237 checkAppendMsg(pCheck,
74238 "freelist leaf count too big on page %d", iPage);
74239 N--;
74240 }else{
74241 for(i=0; i<(int)n; i++){
74242 Pgno iFreePage = get4byte(&pOvflData[8+i*4]);
74243#ifndef SQLITE_OMIT_AUTOVACUUM
74244 if( pCheck->pBt->autoVacuum ){
74245 checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0);
74246 }
74247#endif
74248 checkRef(pCheck, iFreePage);
74249 }
74250 N -= n;
74251 }
74252 }
74253#ifndef SQLITE_OMIT_AUTOVACUUM
74254 else{
74255 /* If this database supports auto-vacuum and iPage is not the last
74256 ** page in this overflow list, check that the pointer-map entry for
74257 ** the following page matches iPage.
74258 */
74259 if( pCheck->pBt->autoVacuum && N>0 ){
74260 i = get4byte(pOvflData);
74261 checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage);
74262 }
74263 }
74264#endif
74265 iPage = get4byte(pOvflData);
74266 sqlite3PagerUnref(pOvflPage);
74267 }
74268 if( N && nErrAtStart==pCheck->nErr ){
static void checkPtrmap(IntegrityCk *pCheck, Pgno iChild, u8 eType, Pgno iParent)
Definition sqlite3.c:74175
#define PTRMAP_OVERFLOW2
Definition sqlite3.c:64108
static void checkAppendMsg(IntegrityCk *pCheck, const char *zFormat,...)
Definition sqlite3.c:74103
static int checkRef(IntegrityCk *pCheck, Pgno iPage)
Definition sqlite3.c:74155
BtShared * pBt
Definition sqlite3.c:64145
Pager * pPager
Definition sqlite3.c:64146

References BtShared::autoVacuum, checkAppendMsg(), checkPtrmap(), checkRef(), get4byte, IntegrityCk::mxErr, IntegrityCk::nErr, IntegrityCk::pBt, IntegrityCk::pPager, PTRMAP_FREEPAGE, PTRMAP_OVERFLOW2, sqlite3PagerGet(), sqlite3PagerGetData(), sqlite3PagerUnref(), and BtShared::usableSize.

Referenced by checkTreePage(), and sqlite3BtreeIntegrityCheck().

◆ checkPtrmap()

static void checkPtrmap ( IntegrityCk * pCheck,
Pgno iChild,
u8 eType,
Pgno iParent )
static

Definition at line 74175 of file sqlite3.c.

74186 {
74187 int rc;
74188 u8 ePtrmapType;
74189 Pgno iPtrmapParent;
74190
74191 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
74192 if( rc!=SQLITE_OK ){
74193 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->bOomFault = 1;
74194 checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
74195 return;
74196 }
74197

References IntegrityCk::bOomFault, checkAppendMsg(), eType, IntegrityCk::pBt, ptrmapGet(), SQLITE_IOERR_NOMEM, SQLITE_NOMEM, and SQLITE_OK.

Referenced by checkList(), checkTreePage(), and sqlite3BtreeIntegrityCheck().

◆ checkReadTransaction()

static int checkReadTransaction ( sqlite3 * db,
Btree * p )
static

Definition at line 75175 of file sqlite3.c.

75181 {

References sqlite3BtreeIsInReadTrans(), sqlite3ErrorWithMsg(), SQLITE_ERROR, and SQLITE_OK.

Referenced by sqlite3_backup_init().

◆ checkRef()

static int checkRef ( IntegrityCk * pCheck,
Pgno iPage )
static

Definition at line 74155 of file sqlite3.c.

74161 {
74162 if( iPage>pCheck->nPage || iPage==0 ){
74163 checkAppendMsg(pCheck, "invalid page number %d", iPage);
74164 return 1;
74165 }
74166 if( getPageReferenced(pCheck, iPage) ){
74167 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
static int getPageReferenced(IntegrityCk *pCheck, Pgno iPg)
Definition sqlite3.c:74133

References AtomicLoad, checkAppendMsg(), IntegrityCk::db, getPageReferenced(), sqlite3::isInterrupted, IntegrityCk::nPage, setPageReferenced(), and sqlite3::u1.

Referenced by checkList(), and checkTreePage().

◆ checkTreePage()

static int checkTreePage ( IntegrityCk * pCheck,
Pgno iPage,
i64 * piMinKey,
i64 maxKey )
static

Definition at line 74337 of file sqlite3.c.

74348 {
74349 MemPage *pPage = 0; /* The page being analyzed */
74350 int i; /* Loop counter */
74351 int rc; /* Result code from subroutine call */
74352 int depth = -1, d2; /* Depth of a subtree */
74353 int pgno; /* Page number */
74354 int nFrag; /* Number of fragmented bytes on the page */
74355 int hdr; /* Offset to the page header */
74356 int cellStart; /* Offset to the start of the cell pointer array */
74357 int nCell; /* Number of cells */
74358 int doCoverageCheck = 1; /* True if cell coverage checking should be done */
74359 int keyCanBeEqual = 1; /* True if IPK can be equal to maxKey
74360 ** False if IPK must be strictly less than maxKey */
74361 u8 *data; /* Page content */
74362 u8 *pCell; /* Cell content */
74363 u8 *pCellIdx; /* Next element of the cell pointer array */
74364 BtShared *pBt; /* The BtShared object that owns pPage */
74365 u32 pc; /* Address of a cell */
74366 u32 usableSize; /* Usable size of the page */
74367 u32 contentOffset; /* Offset to the start of the cell content area */
74368 u32 *heap = 0; /* Min-heap used for checking cell coverage */
74369 u32 x, prev = 0; /* Next and previous entry on the min-heap */
74370 const char *saved_zPfx = pCheck->zPfx;
74371 int saved_v1 = pCheck->v1;
74372 int saved_v2 = pCheck->v2;
74373 u8 savedIsInit = 0;
74374
74375 /* Check that the page exists
74376 */
74377 pBt = pCheck->pBt;
74378 usableSize = pBt->usableSize;
74379 if( iPage==0 ) return 0;
74380 if( checkRef(pCheck, iPage) ) return 0;
74381 pCheck->zPfx = "Page %u: ";
74382 pCheck->v1 = iPage;
74383 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
74384 checkAppendMsg(pCheck,
74385 "unable to get the page. error code=%d", rc);
74386 goto end_of_check;
74387 }
74388
74389 /* Clear MemPage.isInit to make sure the corruption detection code in
74390 ** btreeInitPage() is executed. */
74391 savedIsInit = pPage->isInit;
74392 pPage->isInit = 0;
74393 if( (rc = btreeInitPage(pPage))!=0 ){
74394 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
74395 checkAppendMsg(pCheck,
74396 "btreeInitPage() returns error code %d", rc);
74397 goto end_of_check;
74398 }
74399 if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
74400 assert( rc==SQLITE_CORRUPT );
74401 checkAppendMsg(pCheck, "free space corruption", rc);
74402 goto end_of_check;
74403 }
74404 data = pPage->aData;
74405 hdr = pPage->hdrOffset;
74406
74407 /* Set up for cell analysis */
74408 pCheck->zPfx = "On tree page %u cell %d: ";
74409 contentOffset = get2byteNotZero(&data[hdr+5]);
74410 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
74411
74412 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
74413 ** number of cells on the page. */
74414 nCell = get2byte(&data[hdr+3]);
74415 assert( pPage->nCell==nCell );
74416
74417 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
74418 ** immediately follows the b-tree page header. */
74419 cellStart = hdr + 12 - 4*pPage->leaf;
74420 assert( pPage->aCellIdx==&data[cellStart] );
74421 pCellIdx = &data[cellStart + 2*(nCell-1)];
74422
74423 if( !pPage->leaf ){
74424 /* Analyze the right-child page of internal pages */
74425 pgno = get4byte(&data[hdr+8]);
74426#ifndef SQLITE_OMIT_AUTOVACUUM
74427 if( pBt->autoVacuum ){
74428 pCheck->zPfx = "On page %u at right child: ";
74429 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
74430 }
74431#endif
74432 depth = checkTreePage(pCheck, pgno, &maxKey, maxKey);
74433 keyCanBeEqual = 0;
74434 }else{
74435 /* For leaf pages, the coverage check will occur in the same loop
74436 ** as the other cell checks, so initialize the heap. */
74437 heap = pCheck->heap;
74438 heap[0] = 0;
74439 }
74440
74441 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
74442 ** integer offsets to the cell contents. */
74443 for(i=nCell-1; i>=0 && pCheck->mxErr; i--){
74444 CellInfo info;
74445
74446 /* Check cell size */
74447 pCheck->v2 = i;
74448 assert( pCellIdx==&data[cellStart + i*2] );
74449 pc = get2byteAligned(pCellIdx);
74450 pCellIdx -= 2;
74451 if( pc<contentOffset || pc>usableSize-4 ){
74452 checkAppendMsg(pCheck, "Offset %d out of range %d..%d",
74453 pc, contentOffset, usableSize-4);
74454 doCoverageCheck = 0;
74455 continue;
74456 }
74457 pCell = &data[pc];
74458 pPage->xParseCell(pPage, pCell, &info);
74459 if( pc+info.nSize>usableSize ){
74460 checkAppendMsg(pCheck, "Extends off end of page");
74461 doCoverageCheck = 0;
74462 continue;
74463 }
74464
74465 /* Check for integer primary key out of range */
74466 if( pPage->intKey ){
74467 if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
74468 checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
74469 }
74470 maxKey = info.nKey;
74471 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
74472 }
74473
74474 /* Check the content overflow list */
74475 if( info.nPayload>info.nLocal ){
74476 u32 nPage; /* Number of pages on the overflow chain */
74477 Pgno pgnoOvfl; /* First page of the overflow chain */
74478 assert( pc + info.nSize - 4 <= usableSize );
74479 nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
74480 pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
74481#ifndef SQLITE_OMIT_AUTOVACUUM
74482 if( pBt->autoVacuum ){
74483 checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage);
74484 }
74485#endif
74486 checkList(pCheck, 0, pgnoOvfl, nPage);
74487 }
74488
74489 if( !pPage->leaf ){
74490 /* Check sanity of left child page for internal pages */
74491 pgno = get4byte(pCell);
74492#ifndef SQLITE_OMIT_AUTOVACUUM
74493 if( pBt->autoVacuum ){
74494 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
74495 }
74496#endif
74497 d2 = checkTreePage(pCheck, pgno, &maxKey, maxKey);
74498 keyCanBeEqual = 0;
74499 if( d2!=depth ){
74500 checkAppendMsg(pCheck, "Child page depth differs");
74501 depth = d2;
74502 }
74503 }else{
74504 /* Populate the coverage-checking heap for leaf pages */
74505 btreeHeapInsert(heap, (pc<<16)|(pc+info.nSize-1));
74506 }
74507 }
74508 *piMinKey = maxKey;
74509
74510 /* Check for complete coverage of the page
74511 */
74512 pCheck->zPfx = 0;
74513 if( doCoverageCheck && pCheck->mxErr>0 ){
74514 /* For leaf pages, the min-heap has already been initialized and the
74515 ** cells have already been inserted. But for internal pages, that has
74516 ** not yet been done, so do it now */
74517 if( !pPage->leaf ){
74518 heap = pCheck->heap;
74519 heap[0] = 0;
74520 for(i=nCell-1; i>=0; i--){
74521 u32 size;
74522 pc = get2byteAligned(&data[cellStart+i*2]);
74523 size = pPage->xCellSize(pPage, &data[pc]);
74524 btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
74525 }
74526 }
74527 /* Add the freeblocks to the min-heap
74528 **
74529 ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
74530 ** is the offset of the first freeblock, or zero if there are no
74531 ** freeblocks on the page.
74532 */
74533 i = get2byte(&data[hdr+1]);
74534 while( i>0 ){
74535 int size, j;
74536 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
74537 size = get2byte(&data[i+2]);
74538 assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
74539 btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
74540 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
74541 ** big-endian integer which is the offset in the b-tree page of the next
74542 ** freeblock in the chain, or zero if the freeblock is the last on the
74543 ** chain. */
74544 j = get2byte(&data[i]);
74545 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
74546 ** increasing offset. */
74547 assert( j==0 || j>i+size ); /* Enforced by btreeComputeFreeSpace() */
74548 assert( (u32)j<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
74549 i = j;
74550 }
74551 /* Analyze the min-heap looking for overlap between cells and/or
74552 ** freeblocks, and counting the number of untracked bytes in nFrag.
74553 **
74554 ** Each min-heap entry is of the form: (start_address<<16)|end_address.
74555 ** There is an implied first entry the covers the page header, the cell
74556 ** pointer index, and the gap between the cell pointer index and the start
74557 ** of cell content.
74558 **
74559 ** The loop below pulls entries from the min-heap in order and compares
74560 ** the start_address against the previous end_address. If there is an
74561 ** overlap, that means bytes are used multiple times. If there is a gap,
74562 ** that gap is added to the fragmentation count.
74563 */
74564 nFrag = 0;
74565 prev = contentOffset - 1; /* Implied first min-heap entry */
74566 while( btreeHeapPull(heap,&x) ){
74567 if( (prev&0xffff)>=(x>>16) ){
74568 checkAppendMsg(pCheck,
74569 "Multiple uses for byte %u of page %u", x>>16, iPage);
74570 break;
74571 }else{
74572 nFrag += (x>>16) - (prev&0xffff) - 1;
74573 prev = x;
74574 }
74575 }
74576 nFrag += usableSize - (prev&0xffff) - 1;
74577 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
74578 ** is stored in the fifth field of the b-tree page header.
74579 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
74580 ** number of fragmented free bytes within the cell content area.
74581 */
74582 if( heap[0]==0 && nFrag!=data[hdr+7] ){
74583 checkAppendMsg(pCheck,
74584 "Fragmentation of %d bytes reported as %d on page %u",
74585 nFrag, data[hdr+7], iPage);
74586 }
74587 }
74588
74589end_of_check:
74590 if( !doCoverageCheck ) pPage->isInit = savedIsInit;
guint depth
static void checkList(IntegrityCk *pCheck, int isFreeList, Pgno iPage, u32 N)
Definition sqlite3.c:74204
static int btreeInitPage(MemPage *pPage)
Definition sqlite3.c:66468
#define SQLITE_CORRUPT
Definition sqlite3.c:1481
static void btreeHeapInsert(u32 *aHeap, u32 x)
Definition sqlite3.c:74293
static int checkTreePage(IntegrityCk *pCheck, Pgno iPage, i64 *piMinKey, i64 maxKey)
Definition sqlite3.c:74337
static int btreeHeapPull(u32 *aHeap, u32 *pOut)
Definition sqlite3.c:74303
#define PTRMAP_OVERFLOW1
Definition sqlite3.c:64107

References MemPage::aCellIdx, MemPage::aData, BtShared::autoVacuum, btreeComputeFreeSpace(), btreeGetPage(), btreeHeapInsert(), btreeHeapPull(), btreeInitPage(), checkAppendMsg(), checkList(), checkPtrmap(), checkRef(), checkTreePage(), depth, get2byte, get2byteAligned, get2byteNotZero, get4byte, MemPage::hdrOffset, IntegrityCk::heap, MemPage::intKey, MemPage::isInit, MemPage::leaf, IntegrityCk::mxErr, MemPage::nCell, CellInfo::nKey, CellInfo::nLocal, CellInfo::nPayload, CellInfo::nSize, IntegrityCk::pBt, PTRMAP_BTREE, PTRMAP_OVERFLOW1, releasePage(), SQLITE_CORRUPT, BtShared::usableSize, IntegrityCk::v1, IntegrityCk::v2, MemPage::xCellSize, MemPage::xParseCell, and IntegrityCk::zPfx.

Referenced by checkTreePage(), and sqlite3BtreeIntegrityCheck().

◆ clearAllSharedCacheTableLocks()

static void clearAllSharedCacheTableLocks ( Btree * p)
static

Definition at line 64890 of file sqlite3.c.

64896 {
64897 BtShared *pBt = p->pBt;
64898 BtLock **ppIter = &pBt->pLock;
64899
64900 assert( sqlite3BtreeHoldsMutex(p) );
64901 assert( p->sharable || 0==*ppIter );
64902 assert( p->inTrans>0 );
64903
64904 while( *ppIter ){
64905 BtLock *pLock = *ppIter;
64906 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
64907 assert( pLock->pBtree->inTrans>=pLock->eLock );
64908 if( pLock->pBtree==p ){
64909 *ppIter = pLock->pNext;
64910 assert( pLock->iTable!=1 || pLock==&p->lock );
64911 if( pLock->iTable!=1 ){
64912 sqlite3_free(pLock);
64913 }
64914 }else{
64915 ppIter = &pLock->pNext;
64916 }
64917 }
64918
64919 assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
64920 if( pBt->pWriter==p ){
64921 pBt->pWriter = 0;
64923 }else if( pBt->nTransaction==2 ){
64924 /* This function is called when Btree p is concluding its
64925 ** transaction. If there currently exists a writer, and p is not
64926 ** that writer, then the number of locks held by connections other
64927 ** than the writer must be about to drop to zero. In this case
64928 ** set the BTS_PENDING flag to 0.
64929 **
#define BTS_EXCLUSIVE
Definition sqlite3.c:63922
#define BTS_PENDING
Definition sqlite3.c:63923
Pgno iTable
Definition sqlite3.c:63783
Btree * pBtree
Definition sqlite3.c:63782
u8 eLock
Definition sqlite3.c:63784
BtLock * pNext
Definition sqlite3.c:63785
Btree * pWriter
Definition sqlite3.c:63907
BtLock * pLock
Definition sqlite3.c:63906
BtLock lock
Definition sqlite3.c:63826

References BTS_EXCLUSIVE, BTS_PENDING, BtShared::btsFlags, BtLock::eLock, Btree::inTrans, BtLock::iTable, Btree::lock, BtShared::nTransaction, Btree::pBt, BtLock::pBtree, BtShared::pLock, BtLock::pNext, BtShared::pWriter, Btree::sharable, and sqlite3_free().

◆ clearCell()

static int clearCell ( MemPage * pPage,
unsigned char * pCell,
CellInfo * pInfo )
static

Definition at line 70855 of file sqlite3.c.

70865 {
70866 BtShared *pBt;
70867 Pgno ovflPgno;
70868 int rc;
70869 int nOvfl;
70870 u32 ovflPageSize;
70871
70872 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
70873 pPage->xParseCell(pPage, pCell, pInfo);
70874 if( pInfo->nLocal==pInfo->nPayload ){
70875 return SQLITE_OK; /* No overflow pages. Return without doing anything */
70876 }
70877 testcase( pCell + pInfo->nSize == pPage->aDataEnd );
70878 testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd );
70879 if( pCell + pInfo->nSize > pPage->aDataEnd ){
70880 /* Cell extends past end of page */
70881 return SQLITE_CORRUPT_PAGE(pPage);
70882 }
70883 ovflPgno = get4byte(pCell + pInfo->nSize - 4);
70884 pBt = pPage->pBt;
70885 assert( pBt->usableSize > 4 );
70886 ovflPageSize = pBt->usableSize - 4;
70887 nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize;
70888 assert( nOvfl>0 ||
70889 (CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize)
70890 );
70891 while( nOvfl-- ){
70892 Pgno iNext = 0;
70893 MemPage *pOvfl = 0;
70894 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
70895 /* 0 is not a legal page number and page 1 cannot be an
70896 ** overflow page. Therefore if ovflPgno<2 or past the end of the
70897 ** file the database must be corrupt. */
70898 return SQLITE_CORRUPT_BKPT;
70899 }
70900 if( nOvfl ){
70901 rc = getOverflowPage(pBt, ovflPgno, &pOvfl, &iNext);
70902 if( rc ) return rc;
70903 }
70904
70905 if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
70906 && sqlite3PagerPageRefcount(pOvfl->pDbPage)!=1
70907 ){
70908 /* There is no reason any cursor should have an outstanding reference
70909 ** to an overflow page belonging to a cell that is being deleted/updated.
70910 ** So if there exists more than one reference to this page, then it
70911 ** must not really be an overflow page and the database must be corrupt.
70912 ** It is helpful to detect this before calling freePage2(), as
70913 ** freePage2() may zero the page contents if secure-delete mode is
70914 ** enabled. If this 'overflow' page happens to be a page that the
70915 ** caller is iterating through or using in some other way, this
70916 ** can be problematic.
70917 */
70919 }else{
70920 rc = freePage2(pBt, pOvfl, ovflPgno);
70921 }
70922
70923 if( pOvfl ){
70924 sqlite3PagerUnref(pOvfl->pDbPage);
static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage)
Definition sqlite3.c:70711
static MemPage * btreePageLookup(BtShared *pBt, Pgno pgno)
Definition sqlite3.c:66604

Referenced by sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ clearDatabasePage()

static int clearDatabasePage ( BtShared * pBt,
Pgno pgno,
int freePageFlag,
int * pnChange )
static

Definition at line 73735 of file sqlite3.c.

73746 {
73747 MemPage *pPage;
73748 int rc;
73749 unsigned char *pCell;
73750 int i;
73751 int hdr;
73752 CellInfo info;
73753
73754 assert( sqlite3_mutex_held(pBt->mutex) );
73755 if( pgno>btreePagecount(pBt) ){
73756 return SQLITE_CORRUPT_BKPT;
73757 }
73758 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
73759 if( rc ) return rc;
73760 if( pPage->bBusy ){
73762 goto cleardatabasepage_out;
73763 }
73764 pPage->bBusy = 1;
73765 hdr = pPage->hdrOffset;
73766 for(i=0; i<pPage->nCell; i++){
73767 pCell = findCell(pPage, i);
73768 if( !pPage->leaf ){
73769 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
73770 if( rc ) goto cleardatabasepage_out;
73771 }
73772 rc = clearCell(pPage, pCell, &info);
73773 if( rc ) goto cleardatabasepage_out;
73774 }
73775 if( !pPage->leaf ){
73776 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
73777 if( rc ) goto cleardatabasepage_out;
73778 }else if( pnChange ){
73779 assert( pPage->intKey || CORRUPT_DB );
73780 testcase( !pPage->intKey );
73781 *pnChange += pPage->nCell;
73782 }
73783 if( freePageFlag ){
73784 freePage(pPage, &rc);
73785 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
73786 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
73787 }
static int clearCell(MemPage *pPage, unsigned char *pCell, CellInfo *pInfo)
Definition sqlite3.c:70855
static int clearDatabasePage(BtShared *pBt, Pgno pgno, int freePageFlag, int *pnChange)
Definition sqlite3.c:73735

Referenced by sqlite3BtreeClearTable().

◆ clearSelect()

static void clearSelect ( sqlite3 * db,
Select * p,
int bFree )
static

Definition at line 129371 of file sqlite3.c.

129377 {
129378 while( p ){
129379 Select *pPrior = p->pPrior;
129381 sqlite3SrcListDelete(db, p->pSrc);
129382 sqlite3ExprDelete(db, p->pWhere);
129384 sqlite3ExprDelete(db, p->pHaving);
129386 sqlite3ExprDelete(db, p->pLimit);
129387#ifndef SQLITE_OMIT_WINDOWFUNC
129388 if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
129390 }
129391#endif
SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p)
Definition sqlite3.c:152282
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *, SrcList *)
Definition sqlite3.c:114852
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *, Expr *)
Definition sqlite3.c:100849
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *, ExprList *)
Definition sqlite3.c:101578
#define OK_IF_ALWAYS_TRUE(X)
Definition sqlite3.c:13771
Expr * pWhere
Definition sqlite3.c:18448
Expr * pLimit
Definition sqlite3.c:18454
SrcList * pSrc
Definition sqlite3.c:18447
Select * pPrior
Definition sqlite3.c:18452
ExprList * pGroupBy
Definition sqlite3.c:18449
ExprList * pOrderBy
Definition sqlite3.c:18451
Window * pWinDefn
Definition sqlite3.c:18458
ExprList * pEList
Definition sqlite3.c:18446
Expr * pHaving
Definition sqlite3.c:18450

References OK_IF_ALWAYS_TRUE, Select::pEList, Select::pGroupBy, Select::pHaving, Select::pLimit, Select::pOrderBy, Select::pPrior, Select::pSrc, Select::pWhere, Select::pWinDefn, Select::pWith, sqlite3DbFreeNN(), sqlite3ExprDelete(), sqlite3ExprListDelete(), sqlite3SrcListDelete(), sqlite3WindowListDelete(), and sqlite3WithDelete().

Referenced by sqlite3SelectNew().

◆ clearYMD_HMS_TZ()

static void clearYMD_HMS_TZ ( DateTime * p)
static

Definition at line 22184 of file sqlite3.c.

Referenced by parseModifier().

◆ closeAllCursors()

static void closeAllCursors ( Vdbe * p)
static

Definition at line 80284 of file sqlite3.c.

80290 {
80291 if( p->pFrame ){
80292 VdbeFrame *pFrame;
80293 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
80295 p->pFrame = 0;
80296 p->nFrame = 0;
80297 }
80298 assert( p->nFrame==0 );
80300 if( p->aMem ){
80301 releaseMemArray(p->aMem, p->nMem);
80302 }
80303 while( p->pDelFrame ){
80304 VdbeFrame *pDel = p->pDelFrame;
80305 p->pDelFrame = pDel->pParent;
static void releaseMemArray(Mem *p, int N)
Definition sqlite3.c:79613
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *)
Definition sqlite3.c:80255
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame *)
Definition sqlite3.c:79802
static void closeCursorsInFrame(Vdbe *p)
Definition sqlite3.c:80237
VdbeFrame * pParent
Definition sqlite3.c:20868
int nFrame
Definition sqlite3.c:21145
VdbeFrame * pDelFrame
Definition sqlite3.c:21144
VdbeFrame * pFrame
Definition sqlite3.c:21143

References Vdbe::aMem, closeCursorsInFrame(), Vdbe::db, Vdbe::nFrame, Vdbe::nMem, Vdbe::pAuxData, Vdbe::pDelFrame, Vdbe::pFrame, VdbeFrame::pParent, releaseMemArray(), sqlite3VdbeDeleteAuxData(), sqlite3VdbeFrameDelete(), and sqlite3VdbeFrameRestore().

Referenced by sqlite3VdbeHalt().

◆ closeCursorsInFrame()

static void closeCursorsInFrame ( Vdbe * p)
static

Definition at line 80237 of file sqlite3.c.

80243 {
80244 if( p->apCsr ){
80245 int i;
80246 for(i=0; i<p->nCursor; i++){
80247 VdbeCursor *pC = p->apCsr[i];
80248 if( pC ){
int nCursor
Definition sqlite3.c:21090

Referenced by closeAllCursors(), and sqlite3VdbeFrameRestore().

◆ closePendingFds()

static void closePendingFds ( unixFile * pFile)
static

Definition at line 34846 of file sqlite3.c.

34852 {
34853 unixInodeInfo *pInode = pFile->pInode;
34854 UnixUnusedFd *p;
34855 UnixUnusedFd *pNext;
34856 assert( unixFileMutexHeld(pFile) );
34857 for(p=pInode->pUnused; p; p=pNext){
unixInodeInfo * pInode
Definition sqlite3.c:33565
UnixUnusedFd * pUnused
Definition sqlite3.c:34709

Referenced by posixUnlock(), and releaseInodeInfo().

◆ closeUnixFile()

static int closeUnixFile ( sqlite3_file * id)
static

Definition at line 35628 of file sqlite3.c.

35634 {
35635 unixFile *pFile = (unixFile*)id;
35636#if SQLITE_MAX_MMAP_SIZE>0
35637 unixUnmapfile(pFile);
35638#endif
35639 if( pFile->h>=0 ){
35640 robust_close(pFile, pFile->h, __LINE__);
35641 pFile->h = -1;
35642 }
35643#if OS_VXWORKS
35644 if( pFile->pId ){
35645 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
35646 osUnlink(pFile->pId->zCanonicalName);
35647 }
35648 vxworksReleaseFileId(pFile->pId);
35649 pFile->pId = 0;
35650 }
35651#endif
35652#ifdef SQLITE_UNLINK_AFTER_CLOSE
35653 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
35654 osUnlink(pFile->zPath);
35655 sqlite3_free(*(char**)&pFile->zPath);
35656 pFile->zPath = 0;
35657 }
35658#endif
#define UNIXFILE_DELETE
Definition sqlite3.c:33636
#define osUnlink
static void robust_close(unixFile *pFile, int h, int lineno)
Definition sqlite3.c:34828
unsigned short int ctrlFlags
Definition sqlite3.c:33568
const char * zPath
Definition sqlite3.c:33572

References unixFile::ctrlFlags, unixFile::h, OpenCounter, OSTRACE, osUnlink, unixFile::pPreallocatedUnused, robust_close(), sqlite3_free(), UNIXFILE_DELETE, and unixFile::zPath.

◆ codeAllEqualityTerms()

static int codeAllEqualityTerms ( Parse * pParse,
WhereLevel * pLevel,
int bRev,
int nExtraReg,
char ** pzAff )
static

Definition at line 142180 of file sqlite3.c.

142192 {
142193 u16 nEq; /* The number of == or IN constraints to code */
142194 u16 nSkip; /* Number of left-most columns to skip */
142195 Vdbe *v = pParse->pVdbe; /* The vm under construction */
142196 Index *pIdx; /* The index being used for this loop */
142197 WhereTerm *pTerm; /* A single constraint term */
142198 WhereLoop *pLoop; /* The WhereLoop object */
142199 int j; /* Loop counter */
142200 int regBase; /* Base register */
142201 int nReg; /* Number of registers to allocate */
142202 char *zAff; /* Affinity string to return */
142203
142204 /* This module is only called on query plans that use an index. */
142205 pLoop = pLevel->pWLoop;
142206 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
142207 nEq = pLoop->u.btree.nEq;
142208 nSkip = pLoop->nSkip;
142209 pIdx = pLoop->u.btree.pIndex;
142210 assert( pIdx!=0 );
142211
142212 /* Figure out how many memory cells we will need then allocate them.
142213 */
142214 regBase = pParse->nMem + 1;
142215 nReg = pLoop->u.btree.nEq + nExtraReg;
142216 pParse->nMem += nReg;
142217
142218 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
142219 assert( zAff!=0 || pParse->db->mallocFailed );
142220
142221 if( nSkip ){
142222 int iIdxCur = pLevel->iIdxCur;
142223 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
142224 VdbeCoverageIf(v, bRev==0);
142225 VdbeCoverageIf(v, bRev!=0);
142226 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
142227 j = sqlite3VdbeAddOp0(v, OP_Goto);
142228 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
142229 iIdxCur, 0, regBase, nSkip);
142230 VdbeCoverageIf(v, bRev==0);
142231 VdbeCoverageIf(v, bRev!=0);
142232 sqlite3VdbeJumpHere(v, j);
142233 for(j=0; j<nSkip; j++){
142234 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
142235 testcase( pIdx->aiColumn[j]==XN_EXPR );
142236 VdbeComment((v, "%s", explainIndexColumnName(pIdx, j)));
142237 }
142238 }
142239
142240 /* Evaluate the equality constraints
142241 */
142242 assert( zAff==0 || (int)strlen(zAff)>=nEq );
142243 for(j=nSkip; j<nEq; j++){
142244 int r1;
142245 pTerm = pLoop->aLTerm[j];
142246 assert( pTerm!=0 );
142247 /* The following testcase is true for indices with redundant columns.
142248 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
142249 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
142250 testcase( pTerm->wtFlags & TERM_VIRTUAL );
142251 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
142252 if( r1!=regBase+j ){
142253 if( nReg==1 ){
142254 sqlite3ReleaseTempReg(pParse, regBase);
142255 regBase = r1;
142256 }else{
142257 sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
142258 }
142259 }
142260 if( pTerm->eOperator & WO_IN ){
142261 if( pTerm->pExpr->flags & EP_xIsSelect ){
142262 /* No affinity ever needs to be (or should be) applied to a value
142263 ** from the RHS of an "? IN (SELECT ...)" expression. The
142264 ** sqlite3FindInIndex() routine has already ensured that the
142265 ** affinity of the comparison has been applied to the value. */
142266 if( zAff ) zAff[j] = SQLITE_AFF_BLOB;
142267 }
142268 }else if( (pTerm->eOperator & WO_ISNULL)==0 ){
142269 Expr *pRight = pTerm->pExpr->pRight;
142270 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
142271 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
142272 VdbeCoverage(v);
142273 }
142274 if( zAff ){
142275 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
142276 zAff[j] = SQLITE_AFF_BLOB;
142277 }
142278 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
142279 zAff[j] = SQLITE_AFF_BLOB;
142280 }
SQLITE_PRIVATE const char * sqlite3IndexAffinityStr(sqlite3 *, Index *)
Definition sqlite3.c:120619
#define SQLITE_AFF_BLOB
Definition sqlite3.c:17395
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr *, char)
Definition sqlite3.c:102023
#define TERM_IS
Definition sqlite3.c:141206
#define TERM_VIRTUAL
Definition sqlite3.c:141192
SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *, int)
Definition sqlite3.c:105718
static const char * explainIndexColumnName(Index *pIdx, int i)
Definition sqlite3.c:141544
#define TERM_CODED
Definition sqlite3.c:141193
#define XN_EXPR
Definition sqlite3.c:17832
#define OP_Last
Definition sqlite3.c:15599
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr *)
Definition sqlite3.c:101989
#define VdbeCoverageIf(v, x)
Definition sqlite3.c:15995
static int codeEqualityTerm(Parse *pParse, WhereTerm *pTerm, WhereLevel *pLevel, int iEq, int bRev, int iTarget)
Definition sqlite3.c:142009
SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2)
Definition sqlite3.c:99959
#define OP_SeekLT
Definition sqlite3.c:15588
#define WHERE_VIRTUALTABLE
Definition sqlite3.c:141523
#define OP_SCopy
Definition sqlite3.c:15644
struct WhereLoop * pWLoop
Definition sqlite3.c:141010
Index * pIndex
Definition sqlite3.c:141048
union WhereLoop::@122 u
WhereTerm ** aLTerm
Definition sqlite3.c:141064
struct WhereLoop::@122::@123 btree
u8 mallocFailed
Definition sqlite3.c:16839

References WhereLevel::addrBrk, WhereLevel::addrSkip, Index::aiColumn, WhereLoop::aLTerm, WhereLoop::btree, codeEqualityTerm(), Parse::db, WhereTerm::eOperator, EP_xIsSelect, explainIndexColumnName(), Expr::flags, WhereLevel::iIdxCur, sqlite3::mallocFailed, WhereLoop::nEq, Parse::nMem, WhereLoop::nSkip, OP_Column, OP_Goto, OP_IsNull, OP_Last, OP_Rewind, OP_SCopy, OP_SeekGT, OP_SeekLT, WhereTerm::pExpr, WhereLoop::pIndex, Expr::pRight, Parse::pVdbe, WhereLevel::pWLoop, sqlite3CompareAffinity(), sqlite3DbStrDup(), sqlite3ExprCanBeNull(), sqlite3ExprNeedsNoAffinityChange(), sqlite3IndexAffinityStr(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4Int(), sqlite3VdbeJumpHere(), SQLITE_AFF_BLOB, TERM_CODED, TERM_IS, TERM_VIRTUAL, testcase, WhereLoop::u, VdbeComment, VdbeCoverage, VdbeCoverageIf, WHERE_VIRTUALTABLE, WO_IN, WO_ISNULL, WhereLoop::wsFlags, WhereTerm::wtFlags, XN_EXPR, and Index::zName.

◆ codeApplyAffinity()

static void codeApplyAffinity ( Parse * pParse,
int base,
int n,
char * zAff )
static

Definition at line 141844 of file sqlite3.c.

141850 {
141851 Vdbe *v = pParse->pVdbe;
141852 if( zAff==0 ){
141853 assert( pParse->db->mallocFailed );
141854 return;
141855 }
141856 assert( v!=0 );
141857
141858 /* Adjust base and n to skip over SQLITE_AFF_BLOB and SQLITE_AFF_NONE
141859 ** entries at the beginning and end of the affinity string.
141860 */
141862 while( n>0 && zAff[0]<=SQLITE_AFF_BLOB ){
141863 n--;
141864 base++;
141865 zAff++;
141866 }
141867 while( n>1 && zAff[n-1]<=SQLITE_AFF_BLOB ){
141868 n--;
141869 }

References Parse::db, sqlite3::mallocFailed, OP_Affinity, Parse::pVdbe, sqlite3VdbeAddOp4(), SQLITE_AFF_BLOB, and SQLITE_AFF_NONE.

◆ codeAttach()

static void codeAttach ( Parse * pParse,
int type,
FuncDef const * pFunc,
Expr * pAuthArg,
Expr * pFilename,
Expr * pDbname,
Expr * pKey )
static

Definition at line 109815 of file sqlite3.c.

109829 {
109830 int rc;
109831 NameContext sName;
109832 Vdbe *v;
109833 sqlite3* db = pParse->db;
109834 int regArgs;
109835
109836 if( pParse->nErr ) goto attach_end;
109837 memset(&sName, 0, sizeof(NameContext));
109838 sName.pParse = pParse;
109839
109840 if(
109841 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
109842 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
109843 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
109844 ){
109845 goto attach_end;
109846 }
109847
109848#ifndef SQLITE_OMIT_AUTHORIZATION
109849 if( pAuthArg ){
109850 char *zAuthArg;
109851 if( pAuthArg->op==TK_STRING ){
109852 zAuthArg = pAuthArg->u.zToken;
109853 }else{
109854 zAuthArg = 0;
109855 }
109856 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
109857 if(rc!=SQLITE_OK ){
109858 goto attach_end;
109859 }
109860 }
109861#endif /* SQLITE_OMIT_AUTHORIZATION */
109862
109863
109864 v = sqlite3GetVdbe(pParse);
109865 regArgs = sqlite3GetTempRange(pParse, 4);
109866 sqlite3ExprCode(pParse, pFilename, regArgs);
109867 sqlite3ExprCode(pParse, pDbname, regArgs+1);
109868 sqlite3ExprCode(pParse, pKey, regArgs+2);
109869
109870 assert( v || db->mallocFailed );
109871 if( v ){
109872 sqlite3VdbeAddFunctionCall(pParse, 0, regArgs+3-pFunc->nArg, regArgs+3,
109873 pFunc->nArg, pFunc, 0);
109874 /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
109875 ** statement only). For DETACH, set it to false (expire all existing
109876 ** statements).
109877 */
109879 }
static int resolveAttachExpr(NameContext *pName, Expr *pExpr)
Definition sqlite3.c:109523
SQLITE_PRIVATE void sqlite3ExprCode(Parse *, Expr *, int)
Definition sqlite3.c:104341
#define OP_Expire
Definition sqlite3.c:15724
#define TK_STRING
Definition sqlite3.c:14057
#define SQLITE_ATTACH
Definition sqlite3.c:4143

Referenced by sqlite3Attach(), and sqlite3Detach().

◆ codeCompare()

static int codeCompare ( Parse * pParse,
Expr * pLeft,
Expr * pRight,
int opcode,
int in1,
int in2,
int dest,
int jumpIfNull,
int isCommuted )
static

Definition at line 100080 of file sqlite3.c.

100095 {
100096 int p5;
100097 int addr;
100098 CollSeq *p4;
100099
100100 if( pParse->nErr ) return 0;
100101 if( isCommuted ){
100102 p4 = sqlite3BinaryCompareCollSeq(pParse, pRight, pLeft);
100103 }else{
100104 p4 = sqlite3BinaryCompareCollSeq(pParse, pLeft, pRight);
100105 }
SQLITE_PRIVATE CollSeq * sqlite3BinaryCompareCollSeq(Parse *, const Expr *, const Expr *)
Definition sqlite3.c:100041

Referenced by codeVectorCompare(), sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), and sqlite3ExprIfTrue().

◆ codeDeferredSeek()

static void codeDeferredSeek ( WhereInfo * pWInfo,
Index * pIdx,
int iCur,
int iIdxCur )
static

Definition at line 142552 of file sqlite3.c.

142563 {
142564 Parse *pParse = pWInfo->pParse; /* Parse context */
142565 Vdbe *v = pParse->pVdbe; /* Vdbe to generate code within */
142566
142567 assert( iIdxCur>0 );
142568 assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 );
142569
142570 pWInfo->bDeferredSeek = 1;
142571 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
142572 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
142573 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
142574 ){
142575 int i;
142576 Table *pTab = pIdx->pTable;
142577 u32 *ai = (u32*)sqlite3DbMallocZero(pParse->db, sizeof(u32)*(pTab->nCol+1));
142578 if( ai ){
142579 ai[0] = pTab->nCol;
142580 for(i=0; i<pIdx->nColumn-1; i++){
142581 int x1, x2;
142582 assert( pIdx->aiColumn[i]<pTab->nCol );
142583 x1 = pIdx->aiColumn[i];
142584 x2 = sqlite3TableColumnToStorage(pTab, x1);
142585 testcase( x1!=x2 );
#define OP_DeferredSeek
Definition sqlite3.c:15699
SQLITE_PRIVATE i16 sqlite3TableColumnToStorage(Table *, i16)
Definition sqlite3.c:111390
#define DbMaskAllZero(M)
Definition sqlite3.c:18659
#define WHERE_OR_SUBCLAUSE
Definition sqlite3.c:18309
Parse * pParse
Definition sqlite3.c:141384
u16 wctrlFlags
Definition sqlite3.c:141393
unsigned bDeferredSeek
Definition sqlite3.c:141399

References Index::aiColumn, WhereInfo::bDeferredSeek, Parse::db, DbMaskAllZero, Table::nCol, Index::nColumn, OP_DeferredSeek, P4_INTARRAY, WhereInfo::pParse, Index::pTable, Parse::pVdbe, sqlite3DbMallocZero(), sqlite3ParseToplevel, sqlite3TableColumnToStorage(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP4(), testcase, WhereInfo::wctrlFlags, and WHERE_OR_SUBCLAUSE.

◆ codeDistinct()

static void codeDistinct ( Parse * pParse,
int iTab,
int addrRepeat,
int N,
int iMem )
static

Definition at line 130038 of file sqlite3.c.

130050 {
130051 Vdbe *v;
130052 int r1;
130053
130054 v = pParse->pVdbe;
130055 r1 = sqlite3GetTempReg(pParse);

References OP_Found, OP_IdxInsert, OP_MakeRecord, OPFLAG_USESEEKRESULT, Parse::pVdbe, sqlite3GetTempReg(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), and VdbeCoverage.

Referenced by selectInnerLoop(), and updateAccumulator().

◆ codeEqualityTerm()

static int codeEqualityTerm ( Parse * pParse,
WhereTerm * pTerm,
WhereLevel * pLevel,
int iEq,
int bRev,
int iTarget )
static

Definition at line 142009 of file sqlite3.c.

142022 {
142023 Expr *pX = pTerm->pExpr;
142024 Vdbe *v = pParse->pVdbe;
142025 int iReg; /* Register holding results */
142026
142027 assert( pLevel->pWLoop->aLTerm[iEq]==pTerm );
142028 assert( iTarget>0 );
142029 if( pX->op==TK_EQ || pX->op==TK_IS ){
142030 iReg = sqlite3ExprCodeTarget(pParse, pX->pRight, iTarget);
142031 }else if( pX->op==TK_ISNULL ){
142032 iReg = iTarget;
142033 sqlite3VdbeAddOp2(v, OP_Null, 0, iReg);
142034#ifndef SQLITE_OMIT_SUBQUERY
142035 }else{
142036 int eType = IN_INDEX_NOOP;
142037 int iTab;
142038 struct InLoop *pIn;
142039 WhereLoop *pLoop = pLevel->pWLoop;
142040 int i;
142041 int nEq = 0;
142042 int *aiMap = 0;
142043
142044 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
142045 && pLoop->u.btree.pIndex!=0
142046 && pLoop->u.btree.pIndex->aSortOrder[iEq]
142047 ){
142048 testcase( iEq==0 );
142049 testcase( bRev );
142050 bRev = !bRev;
142051 }
142052 assert( pX->op==TK_IN );
142053 iReg = iTarget;
142054
142055 for(i=0; i<iEq; i++){
142056 if( pLoop->aLTerm[i] && pLoop->aLTerm[i]->pExpr==pX ){
142057 disableTerm(pLevel, pTerm);
142058 return iTarget;
142059 }
142060 }
142061 for(i=iEq;i<pLoop->nLTerm; i++){
142062 assert( pLoop->aLTerm[i]!=0 );
142063 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
142064 }
142065
142066 iTab = 0;
142067 if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
142068 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
142069 }else{
142070 sqlite3 *db = pParse->db;
142071 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
142072
142073 if( !db->mallocFailed ){
142074 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
142075 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
142076 pTerm->pExpr->iTable = iTab;
142077 }
142078 sqlite3ExprDelete(db, pX);
142079 pX = pTerm->pExpr;
142080 }
142081
142082 if( eType==IN_INDEX_INDEX_DESC ){
142083 testcase( bRev );
142084 bRev = !bRev;
142085 }
142086 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
142087 VdbeCoverageIf(v, bRev);
142088 VdbeCoverageIf(v, !bRev);
142089 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
142090
142091 pLoop->wsFlags |= WHERE_IN_ABLE;
142092 if( pLevel->u.in.nIn==0 ){
142093 pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
142094 }
142095
142096 i = pLevel->u.in.nIn;
142097 pLevel->u.in.nIn += nEq;
142098 pLevel->u.in.aInLoop =
142099 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
142100 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
142101 pIn = pLevel->u.in.aInLoop;
142102 if( pIn ){
142103 int iMap = 0; /* Index in aiMap[] */
142104 pIn += i;
142105 for(i=iEq;i<pLoop->nLTerm; i++){
142106 if( pLoop->aLTerm[i]->pExpr==pX ){
142107 int iOut = iReg + i - iEq;
142108 if( eType==IN_INDEX_ROWID ){
142109 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
142110 }else{
142111 int iCol = aiMap ? aiMap[iMap++] : 0;
142112 pIn->addrInTop = sqlite3VdbeAddOp3(v,OP_Column,iTab, iCol, iOut);
142113 }
142115 if( i==iEq ){
142116 pIn->iCur = iTab;
142117 pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
142118 if( iEq>0 ){
142119 pIn->iBase = iReg - i;
142120 pIn->nPrefix = i;
142121 pLoop->wsFlags |= WHERE_IN_EARLYOUT;
142122 }else{
142123 pIn->nPrefix = 0;
142124 }
142125 }else{
142126 pIn->eEndLoopOp = OP_Noop;
142127 }
142128 pIn++;
142129 }
142130 }
142131 }else{
142132 pLevel->u.in.nIn = 0;
142133 }
#define IN_INDEX_INDEX_DESC
Definition sqlite3.c:20231
static Expr * removeUnindexableInClauseTerms(Parse *pParse, int iEq, WhereLoop *pLoop, Expr *pX)
Definition sqlite3.c:141927
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *, Expr *, int)
Definition sqlite3.c:103502
static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm)
Definition sqlite3.c:141812
SQLITE_PRIVATE void * sqlite3DbReallocOrFree(sqlite3 *, void *, u64)
Definition sqlite3.c:28002
#define OP_Rowid
Definition sqlite3.c:15693
#define IN_INDEX_LOOP
Definition sqlite3.c:20238
#define TK_IN
Definition sqlite3.c:13991
#define WHERE_IN_EARLYOUT
Definition sqlite3.c:141531
#define WHERE_IN_ABLE
Definition sqlite3.c:141524
SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int *, int *, int *)
Definition sqlite3.c:102229
#define IN_INDEX_ROWID
Definition sqlite3.c:20228
#define IN_INDEX_NOOP
Definition sqlite3.c:20232
#define OP_Prev
Definition sqlite3.c:15570
#define WHERE_MULTI_OR
Definition sqlite3.c:141526
#define TK_ISNULL
Definition sqlite3.c:13992
#define TK_IS
Definition sqlite3.c:13987
Select * pSelect
Definition sqlite3.c:18018
u8 * aSortOrder
Definition sqlite3.c:17784
struct WhereLevel::@120::@121::InLoop * aInLoop
struct WhereLevel::@120::@121 in
union WhereLevel::@120 u

References WhereLevel::addrNxt, WhereLevel::aInLoop, WhereLoop::aLTerm, Index::aSortOrder, WhereLoop::btree, Parse::db, disableTerm(), EP_xIsSelect, eType, Expr::flags, WhereLevel::in, IN_INDEX_INDEX_DESC, IN_INDEX_LOOP, IN_INDEX_NOOP, IN_INDEX_ROWID, Expr::iTable, sqlite3::mallocFailed, ExprList::nExpr, WhereLevel::nIn, WhereLoop::nLTerm, Expr::op, OP_Column, OP_IsNull, OP_Last, OP_Next, OP_Noop, OP_Null, OP_Prev, OP_Rewind, OP_Rowid, Select::pEList, WhereTerm::pExpr, WhereLoop::pIndex, Expr::pRight, Expr::pSelect, Parse::pVdbe, WhereLevel::pWLoop, removeUnindexableInClauseTerms(), sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3DbReallocOrFree(), sqlite3ExprCodeTarget(), sqlite3ExprDelete(), sqlite3FindInIndex(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeMakeLabel(), testcase, TK_EQ, TK_IN, TK_IS, TK_ISNULL, WhereLevel::u, WhereLoop::u, VdbeCoverage, VdbeCoverageIf, WHERE_IN_ABLE, WHERE_IN_EARLYOUT, WHERE_MULTI_OR, WHERE_VIRTUALTABLE, WhereLoop::wsFlags, and Expr::x.

Referenced by codeAllEqualityTerms().

◆ codeExprOrVector()

static void codeExprOrVector ( Parse * pParse,
Expr * p,
int iReg,
int nReg )
static

Definition at line 142596 of file sqlite3.c.

142602 {
142603 assert( nReg>0 );
142604 if( p && sqlite3ExprIsVector(p) ){
142605#ifndef SQLITE_OMIT_SUBQUERY
142606 if( (p->flags & EP_xIsSelect) ){
142607 Vdbe *v = pParse->pVdbe;
142608 int iSelect;
142609 assert( p->op==TK_SELECT );
142610 iSelect = sqlite3CodeSubselect(pParse, p);
142611 sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
142612 }else
142613#endif
142614 {
142615 int i;
142616 ExprList *pList = p->x.pList;
142617 assert( nReg<=pList->nExpr );
142618 for(i=0; i<nReg; i++){
142619 sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
142620 }
#define OP_Copy
Definition sqlite3.c:15643
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *)
Definition sqlite3.c:102725
#define TK_SELECT
Definition sqlite3.c:14078

References ExprList::a, EP_xIsSelect, Expr::flags, Expr::op, OP_Copy, ExprList::ExprList_item::pExpr, Expr::pList, Parse::pVdbe, sqlite3CodeSubselect(), sqlite3ExprCode(), sqlite3ExprIsVector(), sqlite3VdbeAddOp3(), TK_SELECT, and Expr::x.

◆ codeInteger()

static void codeInteger ( Parse * pParse,
Expr * pExpr,
int negFlag,
int iMem )
static

Definition at line 103155 of file sqlite3.c.

103161 {
103162 Vdbe *v = pParse->pVdbe;
103163 if( pExpr->flags & EP_IntValue ){
103164 int i = pExpr->u.iValue;
103165 assert( i>=0 );
103166 if( negFlag ) i = -i;
103167 sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
103168 }else{
103169 int c;
103170 i64 value;
103171 const char *z = pExpr->u.zToken;
103172 assert( z!=0 );
103173 c = sqlite3DecOrHexToI64(z, &value);
103174 if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
103175#ifdef SQLITE_OMIT_FLOATING_POINT
103176 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
103177#else
103178#ifndef SQLITE_OMIT_HEX_INTEGER
103179 if( sqlite3_strnicmp(z,"0x",2)==0 ){
103180 sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z);
103181 }else
103182#endif
103183 {
103184 codeReal(v, z, negFlag, iMem);
103185 }
103186#endif
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *, i64 *)
Definition sqlite3.c:31951
static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem)
Definition sqlite3.c:103137
SQLITE_API int sqlite3_strnicmp(const char *, const char *, int)
Definition sqlite3.c:31487
int iValue
Definition sqlite3.c:18006

References codeReal(), EP_IntValue, Expr::flags, Expr::iValue, OP_Int64, OP_Integer, P4_INT64, Parse::pVdbe, SMALLEST_INT64, sqlite3_strnicmp(), sqlite3DecOrHexToI64(), sqlite3ErrorMsg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp4Dup8(), Expr::u, value, and Expr::zToken.

Referenced by sqlite3ExprCodeTarget().

◆ codeOffset()

static void codeOffset ( Vdbe * v,
int iOffset,
int iContinue )
static

◆ codeReal()

static void codeReal ( Vdbe * v,
const char * z,
int negateFlag,
int iMem )
static

Definition at line 103137 of file sqlite3.c.

103143 {
103144 if( ALWAYS(z!=0) ){
103145 double value;

References ALWAYS, OP_Real, P4_REAL, sqlite3AtoF(), sqlite3IsNaN(), sqlite3Strlen30(), sqlite3VdbeAddOp4Dup8(), SQLITE_UTF8, and value.

Referenced by codeInteger(), and sqlite3ExprCodeTarget().

◆ codeRowTrigger()

static TriggerPrg * codeRowTrigger ( Parse * pParse,
Trigger * pTrigger,
Table * pTab,
int orconf )
static

Definition at line 137279 of file sqlite3.c.

137290 {
137291 Parse *pTop = sqlite3ParseToplevel(pParse);
137292 sqlite3 *db = pParse->db; /* Database handle */
137293 TriggerPrg *pPrg; /* Value to return */
137294 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
137295 Vdbe *v; /* Temporary VM */
137296 NameContext sNC; /* Name context for sub-vdbe */
137297 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
137298 Parse *pSubParse; /* Parse context for sub-vdbe */
137299 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
137300
137301 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
137302 assert( pTop->pVdbe );
137303
137304 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
137305 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
137306 ** list of the top-level Parse object sooner rather than later. */
137307 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
137308 if( !pPrg ) return 0;
137309 pPrg->pNext = pTop->pTriggerPrg;
137310 pTop->pTriggerPrg = pPrg;
137311 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
137312 if( !pProgram ) return 0;
137313 sqlite3VdbeLinkSubProgram(pTop->pVdbe, pProgram);
137314 pPrg->pTrigger = pTrigger;
137315 pPrg->orconf = orconf;
137316 pPrg->aColmask[0] = 0xffffffff;
137317 pPrg->aColmask[1] = 0xffffffff;
137318
137319 /* Allocate and populate a new Parse context to use for coding the
137320 ** trigger sub-program. */
137321 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
137322 if( !pSubParse ) return 0;
137323 memset(&sNC, 0, sizeof(sNC));
137324 sNC.pParse = pSubParse;
137325 pSubParse->db = db;
137326 pSubParse->pTriggerTab = pTab;
137327 pSubParse->pToplevel = pTop;
137328 pSubParse->zAuthContext = pTrigger->zName;
137329 pSubParse->eTriggerOp = pTrigger->op;
137330 pSubParse->nQueryLoop = pParse->nQueryLoop;
137331 pSubParse->disableVtab = pParse->disableVtab;
137332
137333 v = sqlite3GetVdbe(pSubParse);
137334 if( v ){
137335 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
137336 pTrigger->zName, onErrorText(orconf),
137337 (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
137338 (pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
137339 (pTrigger->op==TK_INSERT ? "INSERT" : ""),
137340 (pTrigger->op==TK_DELETE ? "DELETE" : ""),
137341 pTab->zName
137342 ));
137343#ifndef SQLITE_OMIT_TRACE
137344 if( pTrigger->zName ){
137345 sqlite3VdbeChangeP4(v, -1,
137346 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
137347 );
137348 }
137349#endif
137350
137351 /* If one was specified, code the WHEN clause. If it evaluates to false
137352 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
137353 ** OP_Halt inserted at the end of the program. */
137354 if( pTrigger->pWhen ){
137355 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
137356 if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
137357 && db->mallocFailed==0
137358 ){
137359 iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
137360 sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
137361 }
137362 sqlite3ExprDelete(db, pWhen);
137363 }
137364
137365 /* Code the trigger program into the sub-vdbe. */
137366 codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);
137367
137368 /* Insert an OP_Halt at the end of the sub-program. */
137369 if( iEndTrigger ){
137370 sqlite3VdbeResolveLabel(v, iEndTrigger);
137371 }
137373 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
137374
137375 transferParseError(pParse, pSubParse);
137376 if( db->mallocFailed==0 && pParse->nErr==0 ){
137377 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
137378 }
137379 pProgram->nMem = pSubParse->nMem;
137380 pProgram->nCsr = pSubParse->nTab;
137381 pProgram->token = (void *)pTrigger;
137382 pPrg->aColmask[0] = pSubParse->oldmask;
137383 pPrg->aColmask[1] = pSubParse->newmask;
137385 }
137386
137387 assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
#define TRIGGER_BEFORE
Definition sqlite3.c:18892
static int codeTriggerProgram(Parse *pParse, TriggerStep *pStepList, int orconf)
Definition sqlite3.c:137159
#define TK_DELETE
Definition sqlite3.c:14068
SQLITE_PRIVATE VdbeOp * sqlite3VdbeTakeOpArray(Vdbe *, int *, int *)
Definition sqlite3.c:78680
#define sqlite3StackAllocZero(D, N)
Definition sqlite3.c:19386
#define TK_INSERT
Definition sqlite3.c:14067
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext *, Expr *)
Definition sqlite3.c:99544
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *)
Definition sqlite3.c:78918
#define TK_UPDATE
Definition sqlite3.c:14069
static void transferParseError(Parse *pTo, Parse *pFrom)
Definition sqlite3.c:137263
static Table * tableOfTrigger(Trigger *pTrigger)
Definition sqlite3.c:136998
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *)
Definition sqlite3.c:81209
#define P4_DYNAMIC
Definition sqlite3.c:15514
#define SQLITE_JUMPIFNULL
Definition sqlite3.c:17419
#define OP_Halt
Definition sqlite3.c:15634
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse *, Expr *, int, int)
Definition sqlite3.c:104695
TriggerPrg * pTriggerPrg
Definition sqlite3.c:18773
const char * zAuthContext
Definition sqlite3.c:18767
Table * pZombieTab
Definition sqlite3.c:18772
u8 disableVtab
Definition sqlite3.c:18693
u32 newmask
Definition sqlite3.c:18725
Parse * pToplevel
Definition sqlite3.c:18718
int nMaxArg
Definition sqlite3.c:18711
Table * pTriggerTab
Definition sqlite3.c:18719
u32 oldmask
Definition sqlite3.c:18724
u8 eTriggerOp
Definition sqlite3.c:18726
u32 nQueryLoop
Definition sqlite3.c:18723
VdbeOp * aOp
Definition sqlite3.c:15480
void * token
Definition sqlite3.c:15485
TriggerPrg * pNext
Definition sqlite3.c:18638
SubProgram * pProgram
Definition sqlite3.c:18639
u32 aColmask[2]
Definition sqlite3.c:18641
Trigger * pTrigger
Definition sqlite3.c:18637
Expr * pWhen
Definition sqlite3.c:18876
TriggerStep * step_list
Definition sqlite3.c:18881
char * zName
Definition sqlite3.c:18872

Referenced by getRowTrigger().

◆ codeTableLocks()

static void codeTableLocks ( Parse * pParse)
static

Definition at line 110479 of file sqlite3.c.

110485 {
110486 int i;
110487 Vdbe *pVdbe;
110488
110489 pVdbe = sqlite3GetVdbe(pParse);
110490 assert( pVdbe!=0 ); /* sqlite3GetVdbe cannot fail: VDBE already allocated */
110491
110492 for(i=0; i<pParse->nTableLock; i++){
int nTableLock
Definition sqlite3.c:18714

Referenced by sqlite3FinishCoding().

◆ codeTriggerProgram()

static int codeTriggerProgram ( Parse * pParse,
TriggerStep * pStepList,
int orconf )
static

Definition at line 137159 of file sqlite3.c.

137169 {
137170 TriggerStep *pStep;
137171 Vdbe *v = pParse->pVdbe;
137172 sqlite3 *db = pParse->db;
137173
137174 assert( pParse->pTriggerTab && pParse->pToplevel );
137175 assert( pStepList );
137176 assert( v!=0 );
137177 for(pStep=pStepList; pStep; pStep=pStep->pNext){
137178 /* Figure out the ON CONFLICT policy that will be used for this step
137179 ** of the trigger program. If the statement that caused this trigger
137180 ** to fire had an explicit ON CONFLICT, then use it. Otherwise, use
137181 ** the ON CONFLICT policy that was specified as part of the trigger
137182 ** step statement. Example:
137183 **
137184 ** CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
137185 ** INSERT OR REPLACE INTO t2 VALUES(new.a, new.b);
137186 ** END;
137187 **
137188 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
137189 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
137190 */
137191 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
137192 assert( pParse->okConstFactor==0 );
137193
137194#ifndef SQLITE_OMIT_TRACE
137195 if( pStep->zSpan ){
137196 sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0,
137197 sqlite3MPrintf(db, "-- %s", pStep->zSpan),
137198 P4_DYNAMIC);
137199 }
137200#endif
137201
137202 switch( pStep->op ){
137203 case TK_UPDATE: {
137204 sqlite3Update(pParse,
137205 sqlite3TriggerStepSrc(pParse, pStep),
137206 sqlite3ExprListDup(db, pStep->pExprList, 0),
137207 sqlite3ExprDup(db, pStep->pWhere, 0),
137208 pParse->eOrconf, 0, 0, 0
137209 );
137210 break;
137211 }
137212 case TK_INSERT: {
137213 sqlite3Insert(pParse,
137214 sqlite3TriggerStepSrc(pParse, pStep),
137215 sqlite3SelectDup(db, pStep->pSelect, 0),
137216 sqlite3IdListDup(db, pStep->pIdList),
137217 pParse->eOrconf,
137218 sqlite3UpsertDup(db, pStep->pUpsert)
137219 );
137220 break;
137221 }
137222 case TK_DELETE: {
137223 sqlite3DeleteFrom(pParse,
137224 sqlite3TriggerStepSrc(pParse, pStep),
137225 sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
137226 );
137227 break;
137228 }
137229 default: assert( pStep->op==TK_SELECT ); {
137230 SelectDest sDest;
137231 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
137233 sqlite3Select(pParse, pSelect, &sDest);
137234 sqlite3SelectDelete(db, pSelect);
137235 break;
137236 }
137237 }
137238 if( pStep->op!=TK_SELECT ){
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *, Select *)
Definition sqlite3.c:129468
SQLITE_PRIVATE void sqlite3Update(Parse *, SrcList *, ExprList *, Expr *, int, ExprList *, Expr *, Upsert *)
Definition sqlite3.c:137872
#define SRT_Discard
Definition sqlite3.c:18571
SQLITE_PRIVATE SrcList * sqlite3TriggerStepSrc(Parse *, TriggerStep *)
Definition sqlite3.c:137129
SQLITE_PRIVATE int sqlite3Select(Parse *, Select *, SelectDest *)
Definition sqlite3.c:135064
SQLITE_PRIVATE void sqlite3DeleteFrom(Parse *, SrcList *, Expr *, ExprList *, Expr *)
Definition sqlite3.c:116309
#define OP_Trace
Definition sqlite3.c:15736
#define OE_Default
Definition sqlite3.c:17667
SQLITE_PRIVATE Upsert * sqlite3UpsertDup(sqlite3 *, Upsert *)
Definition sqlite3.c:138936
SQLITE_PRIVATE void sqlite3Insert(Parse *, SrcList *, Select *, IdList *, int, Upsert *)
Definition sqlite3.c:121167
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest *, int, int)
Definition sqlite3.c:129396
SQLITE_PRIVATE ExprList * sqlite3ExprListDup(sqlite3 *, ExprList *, int)
Definition sqlite3.c:101165
SQLITE_PRIVATE IdList * sqlite3IdListDup(sqlite3 *, IdList *)
Definition sqlite3.c:101257
SQLITE_PRIVATE Select * sqlite3SelectDup(sqlite3 *, Select *, int)
Definition sqlite3.c:101281
u8 eOrconf
Definition sqlite3.c:18727
u8 okConstFactor
Definition sqlite3.c:18691
TriggerStep * pNext
Definition sqlite3.c:18945
ExprList * pExprList
Definition sqlite3.c:18941
IdList * pIdList
Definition sqlite3.c:18942
Select * pSelect
Definition sqlite3.c:18937
Upsert * pUpsert
Definition sqlite3.c:18943
char * zSpan
Definition sqlite3.c:18944
Expr * pWhere
Definition sqlite3.c:18940

◆ codeVectorCompare()

static void codeVectorCompare ( Parse * pParse,
Expr * pExpr,
int dest,
u8 op,
u8 p5 )
static

Definition at line 100294 of file sqlite3.c.

100294 :
100295**
100296** if pExpr->op==TK_IS: op==TK_EQ and p5==SQLITE_NULLEQ
100297** if pExpr->op==TK_ISNOT: op==TK_NE and p5==SQLITE_NULLEQ
100298** otherwise: op==pExpr->op and p5==0
100299*/
100300static void codeVectorCompare(
100301 Parse *pParse, /* Code generator context */
100302 Expr *pExpr, /* The comparison operation */
100303 int dest, /* Write results into this register */
100304 u8 op, /* Comparison operator */
100305 u8 p5 /* SQLITE_NULLEQ or zero */
100306){
100307 Vdbe *v = pParse->pVdbe;
100308 Expr *pLeft = pExpr->pLeft;
100309 Expr *pRight = pExpr->pRight;
100310 int nLeft = sqlite3ExprVectorSize(pLeft);
100311 int i;
100312 int regLeft = 0;
100313 int regRight = 0;
100314 u8 opx = op;
100315 int addrDone = sqlite3VdbeMakeLabel(pParse);
100316 int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
100317
100318 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
100319 if( pParse->nErr ) return;
100320 if( nLeft!=sqlite3ExprVectorSize(pRight) ){
100321 sqlite3ErrorMsg(pParse, "row value misused");
100322 return;
100323 }
100324 assert( pExpr->op==TK_EQ || pExpr->op==TK_NE
100325 || pExpr->op==TK_IS || pExpr->op==TK_ISNOT
100326 || pExpr->op==TK_LT || pExpr->op==TK_GT
100327 || pExpr->op==TK_LE || pExpr->op==TK_GE
100328 );
100329 assert( pExpr->op==op || (pExpr->op==TK_IS && op==TK_EQ)
100330 || (pExpr->op==TK_ISNOT && op==TK_NE) );
100331 assert( p5==0 || pExpr->op!=op );
100332 assert( p5==SQLITE_NULLEQ || pExpr->op==op );
100333
100334 p5 |= SQLITE_STOREP2;
100335 if( opx==TK_LE ) opx = TK_LT;
100336 if( opx==TK_GE ) opx = TK_GT;
100337
100338 regLeft = exprCodeSubselect(pParse, pLeft);
100339 regRight = exprCodeSubselect(pParse, pRight);
100340
100341 for(i=0; 1 /*Loop exits by "break"*/; i++){
100342 int regFree1 = 0, regFree2 = 0;
100343 Expr *pL, *pR;
100344 int r1, r2;
100345 assert( i>=0 && i<nLeft );
100346 r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, &regFree1);
100347 r2 = exprVectorRegister(pParse, pRight, i, regRight, &pR, &regFree2);
100348 codeCompare(pParse, pL, pR, opx, r1, r2, dest, p5, isCommuted);
100349 testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
100350 testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
100351 testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
100352 testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
100353 testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
100354 testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
100355 sqlite3ReleaseTempReg(pParse, regFree1);
100356 sqlite3ReleaseTempReg(pParse, regFree2);
100357 if( i==nLeft-1 ){
100358 break;
100359 }
100360 if( opx==TK_EQ ){
100361 sqlite3VdbeAddOp2(v, OP_IfNot, dest, addrDone); VdbeCoverage(v);
100362 p5 |= SQLITE_KEEPNULL;
100363 }else if( opx==TK_NE ){
100364 sqlite3VdbeAddOp2(v, OP_If, dest, addrDone); VdbeCoverage(v);
100365 p5 |= SQLITE_KEEPNULL;
100366 }else{
100367 assert( op==TK_LT || op==TK_GT || op==TK_LE || op==TK_GE );
100368 sqlite3VdbeAddOp2(v, OP_ElseNotEq, 0, addrDone);
100369 VdbeCoverageIf(v, op==TK_LT);
100370 VdbeCoverageIf(v, op==TK_GT);
100371 VdbeCoverageIf(v, op==TK_LE);
#define TK_GT
Definition sqlite3.c:13996
static int exprVectorRegister(Parse *pParse, Expr *pVector, int iField, int regSelect, Expr **ppExpr, int *pRegFree)
Definition sqlite3.c:100261
#define SQLITE_KEEPNULL
Definition sqlite3.c:17418
#define OP_Lt
Definition sqlite3.c:15622
#define OP_ElseNotEq
Definition sqlite3.c:15624
static int codeCompare(Parse *pParse, Expr *pLeft, Expr *pRight, int opcode, int in1, int in2, int dest, int jumpIfNull, int isCommuted)
Definition sqlite3.c:100080
#define ExprHasVVAProperty(E, P)
Definition sqlite3.c:18126
#define SQLITE_STOREP2
Definition sqlite3.c:17420
static int exprCodeSubselect(Parse *pParse, Expr *pExpr)
Definition sqlite3.c:100233
#define EP_Immutable
Definition sqlite3.c:18114
SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr)
Definition sqlite3.c:100126
#define EP_Commuted
Definition sqlite3.c:18069
#define TK_GE
Definition sqlite3.c:13999
#define TK_LT
Definition sqlite3.c:13998
#define OP_Ge
Definition sqlite3.c:15623
static void codeVectorCompare(Parse *pParse, Expr *pExpr, int dest, u8 op, u8 p5)
Definition sqlite3.c:100294
#define OP_Gt
Definition sqlite3.c:15620
#define TK_LE
Definition sqlite3.c:13997
#define TK_NE
Definition sqlite3.c:13994
#define OP_Eq
Definition sqlite3.c:15619
#define TK_ISNOT
Definition sqlite3.c:14110
Expr * pLeft
Definition sqlite3.c:18014

References codeCompare(), EP_Commuted, EP_Immutable, exprCodeSubselect(), ExprHasProperty, ExprHasVVAProperty, exprVectorRegister(), Parse::nErr, Expr::op, OP_ElseNotEq, OP_Eq, OP_Ge, OP_Gt, OP_If, OP_IfNot, OP_Le, OP_Lt, OP_Ne, Expr::pLeft, Expr::pRight, Parse::pVdbe, sqlite3ErrorMsg(), sqlite3ExprVectorSize(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_KEEPNULL, SQLITE_NULLEQ, SQLITE_STOREP2, testcase, TK_EQ, TK_GE, TK_GT, TK_IS, TK_ISNOT, TK_LE, TK_LT, TK_NE, VdbeCoverage, and VdbeCoverageIf.

Referenced by sqlite3ExprCodeTarget().

◆ collationMatch()

static int collationMatch ( const char * zColl,
Index * pIndex )
static

Definition at line 115294 of file sqlite3.c.

115300 {
115301 int i;
115302 assert( zColl!=0 );
115303 for(i=0; i<pIndex->nColumn; i++){
115304 const char *z = pIndex->azColl[i];
115305 assert( z!=0 || pIndex->aiColumn[i]<0 );

References Index::aiColumn, Index::azColl, Index::nColumn, and sqlite3StrICmp().

Referenced by reindexTable().

◆ columnIndex()

static int columnIndex ( Table * pTab,
const char * zCol )
static

Definition at line 129558 of file sqlite3.c.

129564 {
129565 int i;
129566 u8 h = sqlite3StrIHash(zCol);
SQLITE_PRIVATE u8 sqlite3StrIHash(const char *)
Definition sqlite3.c:31503

Referenced by sqliteProcessJoin(), and tableAndColumnIndex().

◆ columnMallocFailure()

static void columnMallocFailure ( sqlite3_stmt * pStmt)
static

Definition at line 84071 of file sqlite3.c.

84078{
84079 /* If malloc() failed during an encoding conversion within an
84080 ** sqlite3_column_XXX API, then set the return code of the statement to
84081 ** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
84082 ** and _finalize() will return NOMEM.
84083 */
84084 Vdbe *p = (Vdbe *)pStmt;
84085 if( p ){

References Vdbe::db, sqlite3::mutex, Vdbe::rc, sqlite3_mutex_held(), sqlite3_mutex_leave(), and sqlite3ApiExit().

Referenced by sqlite3_column_type().

◆ columnMem()

static Mem * columnMem ( sqlite3_stmt * pStmt,
int i )
static

Definition at line 84036 of file sqlite3.c.

84042 {
84043 Vdbe *pVm;
84044 Mem *pOut;
84045
84046 pVm = (Vdbe *)pStmt;
84047 if( pVm==0 ) return (Mem*)columnNullValue();
84048 assert( pVm->db );
84050 if( pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
84051 pOut = &pVm->pResultSet[i];
static const Mem * columnNullValue(void)
Definition sqlite3.c:83996
Mem * pResultSet
Definition sqlite3.c:21112

References columnNullValue(), Vdbe::db, sqlite3::mutex, Vdbe::pResultSet, sqlite3_mutex_enter(), sqlite3Error(), and SQLITE_RANGE.

Referenced by sqlite3_column_type().

◆ columnName()

static const void * columnName ( sqlite3_stmt * pStmt,
int N,
int useUtf16,
int useType )
static

Definition at line 84169 of file sqlite3.c.

84180 {
84181 const void *ret;
84182 Vdbe *p;
84183 int n;
84184 sqlite3 *db;
84185#ifdef SQLITE_ENABLE_API_ARMOR
84186 if( pStmt==0 ){
84187 (void)SQLITE_MISUSE_BKPT;
84188 return 0;
84189 }
84190#endif
84191 ret = 0;
84192 p = (Vdbe *)pStmt;
84193 db = p->db;
84194 assert( db!=0 );
84195 n = sqlite3_column_count(pStmt);
84196 if( N<n && N>=0 ){
84197 N += useType*n;
84199 assert( db->mallocFailed==0 );
84200#ifndef SQLITE_OMIT_UTF16
84201 if( useUtf16 ){
84203 }else
84204#endif
84205 {
84207 }
84208 /* A malloc may have failed inside of the _text() call. If this
84209 ** is the case, clear the mallocFailed flag and return NULL.
84210 */
84211 if( db->mallocFailed ){
84212 sqlite3OomClear(db);
SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *)
Definition sqlite3.c:28091
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt)
Definition sqlite3.c:83978
SQLITE_API const void * sqlite3_value_text16(sqlite3_value *)
Definition sqlite3.c:83202
Mem * aColName
Definition sqlite3.c:21111

References Vdbe::aColName, Vdbe::db, sqlite3::mallocFailed, sqlite3::mutex, sqlite3_column_count(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_value_text(), sqlite3_value_text16(), sqlite3OomClear(), and SQLITE_MISUSE_BKPT.

Referenced by sqlite3_column_decltype16(), and sqlite3_column_name16().

◆ columnNullValue()

static const Mem * columnNullValue ( void )
static

Definition at line 83996 of file sqlite3.c.

84002 {
84003 /* Even though the Mem structure contains an element
84004 ** of type i64, on certain architectures (x86) with certain compiler
84005 ** switches (-Os), gcc may align this Mem object on a 4-byte boundary
84006 ** instead of an 8-byte one. This all works fine, except that when
84007 ** running with SQLITE_DEBUG defined the SQLite code sometimes assert()s
84008 ** that a Mem structure is located on an 8-byte boundary. To prevent
84009 ** these assert()s from failing, when building with SQLITE_DEBUG defined
84010 ** using gcc, we force nullMem to be 8-byte aligned using the magical
84011 ** __attribute__((aligned(8))) macro. */
84012 static const Mem nullMem
84013#if defined(SQLITE_DEBUG) && defined(__GNUC__)
84014 __attribute__((aligned(8)))
84015#endif
84016 = {
84017 /* .u = */ {0},
84018 /* .flags = */ (u16)MEM_Null,
84019 /* .enc = */ (u8)0,
84020 /* .eSubtype = */ (u8)0,
84021 /* .n = */ (int)0,
84022 /* .z = */ (char*)0,
84023 /* .zMalloc = */ (char*)0,
84024 /* .szMalloc = */ (int)0,
84025 /* .uTemp = */ (u32)0,
84026 /* .db = */ (sqlite3*)0,
84027 /* .xDel = */ (void(*)(void*))0,
84028#ifdef SQLITE_DEBUG

Referenced by columnMem().

◆ columnTypeImpl()

static const char * columnTypeImpl ( NameContext * pNC,
Expr * pExpr )
static

Definition at line 130952 of file sqlite3.c.

130968 {
130969 char const *zType = 0;
130970 int j;
130971#ifdef SQLITE_ENABLE_COLUMN_METADATA
130972 char const *zOrigDb = 0;
130973 char const *zOrigTab = 0;
130974 char const *zOrigCol = 0;
130975#endif
130976
130977 assert( pExpr!=0 );
130978 assert( pNC->pSrcList!=0 );
130979 switch( pExpr->op ){
130980 case TK_COLUMN: {
130981 /* The expression is a column. Locate the table the column is being
130982 ** extracted from in NameContext.pSrcList. This table may be real
130983 ** database table or a subquery.
130984 */
130985 Table *pTab = 0; /* Table structure column is extracted from */
130986 Select *pS = 0; /* Select the column is extracted from */
130987 int iCol = pExpr->iColumn; /* Index of column in pTab */
130988 while( pNC && !pTab ){
130989 SrcList *pTabList = pNC->pSrcList;
130990 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
130991 if( j<pTabList->nSrc ){
130992 pTab = pTabList->a[j].pTab;
130993 pS = pTabList->a[j].pSelect;
130994 }else{
130995 pNC = pNC->pNext;
130996 }
130997 }
130998
130999 if( pTab==0 ){
131000 /* At one time, code such as "SELECT new.x" within a trigger would
131001 ** cause this condition to run. Since then, we have restructured how
131002 ** trigger code is generated and so this condition is no longer
131003 ** possible. However, it can still be true for statements like
131004 ** the following:
131005 **
131006 ** CREATE TABLE t1(col INTEGER);
131007 ** SELECT (SELECT t1.col) FROM FROM t1;
131008 **
131009 ** when columnType() is called on the expression "t1.col" in the
131010 ** sub-select. In this case, set the column type to NULL, even
131011 ** though it should really be "INTEGER".
131012 **
131013 ** This is not a problem, as the column type of "t1.col" is never
131014 ** used. When columnType() is called on the expression
131015 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
131016 ** branch below. */
131017 break;
131018 }
131019
131020 assert( pTab && pExpr->y.pTab==pTab );
131021 if( pS ){
131022 /* The "table" is actually a sub-select or a view in the FROM clause
131023 ** of the SELECT statement. Return the declaration type and origin
131024 ** data for the result-set column of the sub-select.
131025 */
131026 if( iCol>=0 && iCol<pS->pEList->nExpr ){
131027 /* If iCol is less than zero, then the expression requests the
131028 ** rowid of the sub-select or view. This expression is legal (see
131029 ** test case misc2.2.2) - it always evaluates to NULL.
131030 */
131031 NameContext sNC;
131032 Expr *p = pS->pEList->a[iCol].pExpr;
131033 sNC.pSrcList = pS->pSrc;
131034 sNC.pNext = pNC;
131035 sNC.pParse = pNC->pParse;
131036 zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol);
131037 }
131038 }else{
131039 /* A real table or a CTE table */
131040 assert( !pS );
131041#ifdef SQLITE_ENABLE_COLUMN_METADATA
131042 if( iCol<0 ) iCol = pTab->iPKey;
131043 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
131044 if( iCol<0 ){
131045 zType = "INTEGER";
131046 zOrigCol = "rowid";
131047 }else{
131048 zOrigCol = pTab->aCol[iCol].zName;
131049 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
131050 }
131051 zOrigTab = pTab->zName;
131052 if( pNC->pParse && pTab->pSchema ){
131053 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
131054 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
131055 }
131056#else
131057 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
131058 if( iCol<0 ){
131059 zType = "INTEGER";
131060 }else{
131061 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
131062 }
131063#endif
131064 }
131065 break;
131066 }
131067#ifndef SQLITE_OMIT_SUBQUERY
131068 case TK_SELECT: {
131069 /* The expression is a sub-select. Return the declaration type and
131070 ** origin info for the single column in the result set of the SELECT
131071 ** statement.
131072 */
131073 NameContext sNC;
131074 Select *pS = pExpr->x.pSelect;
131075 Expr *p = pS->pEList->a[0].pExpr;
131076 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
131077 sNC.pSrcList = pS->pSrc;
131078 sNC.pNext = pNC;
131079 sNC.pParse = pNC->pParse;
131080 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
131081 break;
131082 }
131083#endif
131084 }
131085
131086#ifdef SQLITE_ENABLE_COLUMN_METADATA
131087 if( pzOrigDb ){
131088 assert( pzOrigTab && pzOrigCol );
131089 *pzOrigDb = zOrigDb;
#define columnType(A, B, C, D, E)
Definition sqlite3.c:130950
SQLITE_PRIVATE char * sqlite3ColumnType(Column *, char *)
Definition sqlite3.c:31271
#define XN_ROWID
Definition sqlite3.c:17831
char * zName
Definition sqlite3.c:17332
NameContext * pNext
Definition sqlite3.c:18357
Column * aCol
Definition sqlite3.c:17489

References ExprList::a, SrcList::a, Table::aCol, sqlite3::aDb, columnType, Parse::db, EP_xIsSelect, ExprHasProperty, SrcList::SrcList_item::iCursor, Table::iPKey, ExprList::nExpr, SrcList::nSrc, Select::pEList, ExprList::ExprList_item::pExpr, NameContext::pNext, NameContext::pParse, Table::pSchema, SrcList::SrcList_item::pSelect, Select::pSrc, NameContext::pSrcList, SrcList::SrcList_item::pTab, sqlite3ColumnType(), sqlite3SchemaToIndex(), TK_COLUMN, TK_SELECT, XN_ROWID, Db::zDbSName, Column::zName, and Table::zName.

◆ compare2pow63()

static int compare2pow63 ( const char * zNum,
int incr )
static

Definition at line 31816 of file sqlite3.c.

31822 {
31823 int c = 0;
31824 int i;
31825 /* 012345678901234567 */
31826 const char *pow63 = "922337203685477580";
31827 for(i=0; c==0 && i<18; i++){
31828 c = (zNum[i*incr]-pow63[i])*10;
31829 }
31830 if( c==0 ){
31831 c = zNum[18*incr] - '8';

References testcase.

Referenced by sqlite3Atoi64().

◆ comparisonAffinity()

static char comparisonAffinity ( const Expr * pExpr)
static

Definition at line 99981 of file sqlite3.c.

99987 {
99988 char aff;
99989 assert( pExpr->op==TK_EQ || pExpr->op==TK_IN || pExpr->op==TK_LT ||
99990 pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE ||
99991 pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
99992 assert( pExpr->pLeft );
99993 aff = sqlite3ExprAffinity(pExpr->pLeft);
99994 if( pExpr->pRight ){
99995 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
99996 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr)
Definition sqlite3.c:99753

Referenced by sqlite3IndexAffinityOk().

◆ compileoptiongetFunc()

static void compileoptiongetFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118049 of file sqlite3.c.

118059 {
118060 int n;
118061 assert( argc==1 );
118062 UNUSED_PARAMETER(argc);

References sqlite3_value_int(), and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ compileoptionusedFunc()

static void compileoptionusedFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118025 of file sqlite3.c.

118035 {
118036 const char *zOptName;
118037 assert( argc==1 );
118038 UNUSED_PARAMETER(argc);
118039 /* IMP: R-39564-36305 The sqlite_compileoption_used() SQL
118040 ** function is a wrapper around the sqlite3_compileoption_used() C/C++

References sqlite3_compileoption_used(), sqlite3_result_int(), sqlite3_value_text(), and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ computeCellSize()

static SQLITE_NOINLINE u16 computeCellSize ( CellArray * p,
int N )
static

Definition at line 71391 of file sqlite3.c.

◆ computeHMS()

static void computeHMS ( DateTime * p)
static

Definition at line 22157 of file sqlite3.c.

22162 {
22163 int s;
22164 if( p->validHMS ) return;
22165 computeJD(p);
22166 s = (int)((p->iJD + 43200000) % 86400000);
22167 p->s = s/1000.0;
22168 s = (int)p->s;
22169 p->s -= s;
22170 p->h = s/3600;
22171 s -= p->h*3600;
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318
static void computeJD(DateTime *p)
Definition sqlite3.c:21960
double s
Definition sqlite3.c:21781
char validHMS
Definition sqlite3.c:21785
sqlite3_int64 iJD
Definition sqlite3.c:21777

Referenced by timeFunc().

◆ computeJD()

static void computeJD ( DateTime * p)
static

Definition at line 21960 of file sqlite3.c.

21960 :MM:SS to julian day. We always assume
21961** that the YYYY-MM-DD is according to the Gregorian calendar.
21962**
21963** Reference: Meeus page 61
21964*/
21965static void computeJD(DateTime *p){
21966 int Y, M, D, A, B, X1, X2;
21967
21968 if( p->validJD ) return;
21969 if( p->validYMD ){
21970 Y = p->Y;
21971 M = p->M;
21972 D = p->D;
21973 }else{
21974 Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
21975 M = 1;
21976 D = 1;
21977 }
21978 if( Y<-4713 || Y>9999 || p->rawS ){
21979 datetimeError(p);
21980 return;
21981 }
21982 if( M<=2 ){
21983 Y--;
21984 M += 12;
21985 }
21986 A = Y/100;
21987 B = 2 - A + (A/4);
21988 X1 = 36525*(Y+4716)/100;
21989 X2 = 306001*(M+1)/10000;
21990 p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
21991 p->validJD = 1;
21992 if( p->validHMS ){
21993 p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000);
21994 if( p->validTZ ){
21995 p->iJD -= p->tz*60000;
21996 p->validYMD = 0;
#define SS(x)
Definition print.c:158
static void datetimeError(DateTime *p)
Definition sqlite3.c:21949
char rawS
Definition sqlite3.c:21783
char validJD
Definition sqlite3.c:21782
char validYMD
Definition sqlite3.c:21784
char validTZ
Definition sqlite3.c:21786

References DateTime::D, datetimeError(), DateTime::h, DateTime::iJD, DateTime::M, DateTime::m, DateTime::rawS, DateTime::s, DateTime::tz, DateTime::validHMS, DateTime::validJD, DateTime::validTZ, DateTime::validYMD, and DateTime::Y.

Referenced by isDate(), juliandayFunc(), localtimeOffset(), parseModifier(), parseYyyyMmDd(), and strftimeFunc().

◆ computeLimitRegisters()

static void computeLimitRegisters ( Parse * pParse,
Select * p,
int iBreak )
static

Definition at line 131478 of file sqlite3.c.

131484 {
131485 Vdbe *v = 0;
131486 int iLimit = 0;
131487 int iOffset;
131488 int n;
131489 Expr *pLimit = p->pLimit;
131490
131491 if( p->iLimit ) return;
131492
131493 /*
131494 ** "LIMIT -1" always shows all rows. There is some
131495 ** controversy about what the correct behavior should be.
131496 ** The current implementation interprets "LIMIT 0" to mean
131497 ** no rows.
131498 */
131499 if( pLimit ){
131500 assert( pLimit->op==TK_LIMIT );
131501 assert( pLimit->pLeft!=0 );
131502 p->iLimit = iLimit = ++pParse->nMem;
131503 v = sqlite3GetVdbe(pParse);
131504 assert( v!=0 );
131505 if( sqlite3ExprIsInteger(pLimit->pLeft, &n) ){
131506 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
131507 VdbeComment((v, "LIMIT counter"));
131508 if( n==0 ){
131509 sqlite3VdbeGoto(v, iBreak);
131510 }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
131511 p->nSelectRow = sqlite3LogEst((u64)n);
131512 p->selFlags |= SF_FixedLimit;
131513 }
131514 }else{
131515 sqlite3ExprCode(pParse, pLimit->pLeft, iLimit);
131517 VdbeComment((v, "LIMIT counter"));
131518 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
131519 }
131520 if( pLimit->pRight ){
131521 p->iOffset = iOffset = ++pParse->nMem;
131522 pParse->nMem++; /* Allocate an extra register for limit+offset */
131523 sqlite3ExprCode(pParse, pLimit->pRight, iOffset);
SQLITE_PRIVATE LogEst sqlite3LogEst(u64)
Definition sqlite3.c:32710
#define OP_MustBeInt
Definition sqlite3.c:15581
#define SF_FixedLimit
Definition sqlite3.c:18485
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr *, int *)
Definition sqlite3.c:101943
#define TK_LIMIT
Definition sqlite3.c:14088
u32 selFlags
Definition sqlite3.c:18442
int iLimit
Definition sqlite3.c:18443
int iOffset
Definition sqlite3.c:18443
LogEst nSelectRow
Definition sqlite3.c:18441

References Select::iLimit, Select::iOffset, Parse::nMem, Select::nSelectRow, Expr::op, OP_IfNot, OP_Integer, OP_MustBeInt, OP_OffsetLimit, Expr::pLeft, Select::pLimit, Expr::pRight, Select::selFlags, SF_FixedLimit, sqlite3ExprCode(), sqlite3ExprIsInteger(), sqlite3GetVdbe(), sqlite3LogEst(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeGoto(), TK_LIMIT, VdbeComment, and VdbeCoverage.

Referenced by generateWithRecursiveQuery(), multiSelect(), multiSelectOrderBy(), and sqlite3Select().

◆ computeNumericType()

static u16 SQLITE_NOINLINE computeNumericType ( Mem * pMem)
static

Definition at line 85668 of file sqlite3.c.

85674 {
85675 int rc;
85676 sqlite3_int64 ix;
85677 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
85678 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
85679 ExpandBlob(pMem);
85680 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
85681 if( rc<=0 ){
85682 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
85683 pMem->u.i = ix;
85684 return MEM_Int;
85685 }else{
85686 return MEM_Real;
85687 }
#define MEM_Blob
Definition sqlite3.c:20952
SQLITE_PRIVATE int sqlite3Atoi64(const char *, i64 *, int, u8)
Definition sqlite3.c:31849
#define ExpandBlob(P)
Definition sqlite3.c:21321

References sqlite3_value::enc, ExpandBlob, sqlite3_value::flags, sqlite3_value::MemValue::i, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Real, MEM_Str, sqlite3_value::n, sqlite3_value::MemValue::r, sqlite3AtoF(), sqlite3Atoi64(), sqlite3_value::u, and sqlite3_value::z.

Referenced by numericType().

◆ computeYMD()

static void computeYMD ( DateTime * p)
static

Definition at line 22128 of file sqlite3.c.

22133 {
22134 int Z, A, B, C, D, E, X1;
22135 if( p->validYMD ) return;
22136 if( !p->validJD ){
22137 p->Y = 2000;
22138 p->M = 1;
22139 p->D = 1;
22140 }else if( !validJulianDay(p->iJD) ){
22141 datetimeError(p);
22142 return;
22143 }else{
22144 Z = (int)((p->iJD + 43200000)/86400000);
22145 A = (int)((Z - 1867216.25)/36524.25);
22146 A = Z + 1 + A - (A/4);
22147 B = A + 1524;
22148 C = (int)((B - 122.1)/365.25);
22149 D = (36525*(C&32767))/100;
22150 E = (int)((B-D)/30.6001);
22151 X1 = (int)(30.6001*E);
22152 p->D = B - D - X1;
static int validJulianDay(sqlite3_int64 iJD)
Definition sqlite3.c:22121

Referenced by dateFunc(), and parseModifier().

◆ computeYMD_HMS()

static void computeYMD_HMS ( DateTime * p)
static

Definition at line 22176 of file sqlite3.c.

Referenced by datetimeFunc(), localtimeOffset(), parseModifier(), and strftimeFunc().

◆ connectionIsBusy()

static int connectionIsBusy ( sqlite3 * db)
static

Definition at line 162173 of file sqlite3.c.

162179 {
162180 int j;
162181 assert( sqlite3_mutex_held(db->mutex) );
162182 if( db->pVdbe ) return 1;
struct Vdbe * pVdbe
Definition sqlite3.c:16821

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ constInsert()

static void constInsert ( WhereConst * pConst,
Expr * pColumn,
Expr * pValue,
Expr * pExpr )
static

Definition at line 133512 of file sqlite3.c.

133523 {
133524 int i;
133525 assert( pColumn->op==TK_COLUMN );
133526 assert( sqlite3ExprIsConstant(pValue) );
133527
133528 if( ExprHasProperty(pColumn, EP_FixedCol) ) return;
133529 if( sqlite3ExprAffinity(pValue)!=0 ) return;
133530 if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
133531 return;
133532 }
133533
133534 /* 2018-10-25 ticket [cf5ed20f]
133535 ** Make sure the same pColumn is not inserted more than once */
133536 for(i=0; i<pConst->nConst; i++){
133537 const Expr *pE2 = pConst->apExpr[i*2];
133538 assert( pE2->op==TK_COLUMN );
133539 if( pE2->iTable==pColumn->iTable
133540 && pE2->iColumn==pColumn->iColumn
133541 ){
133542 return; /* Already present. Return without doing anything. */
133543 }
133544 }
133545
133546 pConst->nConst++;
133547 pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
133548 pConst->nConst*2*sizeof(Expr*));
133549 if( pConst->apExpr==0 ){
#define EP_FixedCol
Definition sqlite3.c:18063
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *)
Definition sqlite3.c:101803
SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq *)
Definition sqlite3.c:162023
SQLITE_PRIVATE CollSeq * sqlite3ExprCompareCollSeq(Parse *, const Expr *)
Definition sqlite3.c:100069
Expr ** apExpr
Definition sqlite3.c:133501
Parse * pParse
Definition sqlite3.c:133498

References WhereConst::apExpr, Parse::db, EP_FixedCol, ExprHasProperty, Expr::iColumn, Expr::iTable, WhereConst::nConst, Expr::op, WhereConst::pParse, sqlite3DbReallocOrFree(), sqlite3ExprAffinity(), sqlite3ExprCompareCollSeq(), sqlite3ExprIsConstant(), sqlite3IsBinary(), and TK_COLUMN.

Referenced by findConstInWhere().

◆ constructAutomaticIndex()

static void constructAutomaticIndex ( Parse * pParse,
WhereClause * pWC,
struct SrcList_item * pSrc,
Bitmask notReady,
WhereLevel * pLevel )
static

Definition at line 146302 of file sqlite3.c.

146314 {
146315 int nKeyCol; /* Number of columns in the constructed index */
146316 WhereTerm *pTerm; /* A single term of the WHERE clause */
146317 WhereTerm *pWCEnd; /* End of pWC->a[] */
146318 Index *pIdx; /* Object describing the transient index */
146319 Vdbe *v; /* Prepared statement under construction */
146320 int addrInit; /* Address of the initialization bypass jump */
146321 Table *pTable; /* The table being indexed */
146322 int addrTop; /* Top of the index fill loop */
146323 int regRecord; /* Register holding an index record */
146324 int n; /* Column counter */
146325 int i; /* Loop counter */
146326 int mxBitCol; /* Maximum column in pSrc->colUsed */
146327 CollSeq *pColl; /* Collating sequence to on a column */
146328 WhereLoop *pLoop; /* The Loop object */
146329 char *zNotUsed; /* Extra space on the end of pIdx */
146330 Bitmask idxCols; /* Bitmap of columns used for indexing */
146331 Bitmask extraCols; /* Bitmap of additional columns */
146332 u8 sentWarning = 0; /* True if a warnning has been issued */
146333 Expr *pPartial = 0; /* Partial Index Expression */
146334 int iContinue = 0; /* Jump here to skip excluded rows */
146335 struct SrcList_item *pTabItem; /* FROM clause term being indexed */
146336 int addrCounter = 0; /* Address where integer counter is initialized */
146337 int regBase; /* Array of registers where record is assembled */
146338
146339 /* Generate code to skip over the creation and initialization of the
146340 ** transient index on 2nd and subsequent iterations of the loop. */
146341 v = pParse->pVdbe;
146342 assert( v!=0 );
146343 addrInit = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
146344
146345 /* Count the number of columns that will be added to the index
146346 ** and used to match WHERE clause constraints */
146347 nKeyCol = 0;
146348 pTable = pSrc->pTab;
146349 pWCEnd = &pWC->a[pWC->nTerm];
146350 pLoop = pLevel->pWLoop;
146351 idxCols = 0;
146352 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
146353 Expr *pExpr = pTerm->pExpr;
146354 assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */
146355 || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */
146356 || pLoop->prereq!=0 ); /* table of a LEFT JOIN */
146357 if( pLoop->prereq==0
146358 && (pTerm->wtFlags & TERM_VIRTUAL)==0
146359 && !ExprHasProperty(pExpr, EP_FromJoin)
146360 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
146361 pPartial = sqlite3ExprAnd(pParse, pPartial,
146362 sqlite3ExprDup(pParse->db, pExpr, 0));
146363 }
146364 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
146365 int iCol = pTerm->u.leftColumn;
146366 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
146367 testcase( iCol==BMS );
146368 testcase( iCol==BMS-1 );
146369 if( !sentWarning ){
146371 "automatic index on %s(%s)", pTable->zName,
146372 pTable->aCol[iCol].zName);
146373 sentWarning = 1;
146374 }
146375 if( (idxCols & cMask)==0 ){
146376 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
146377 goto end_auto_index_create;
146378 }
146379 pLoop->aLTerm[nKeyCol++] = pTerm;
146380 idxCols |= cMask;
146381 }
146382 }
146383 }
146384 assert( nKeyCol>0 );
146385 pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
146388
146389 /* Count the number of additional columns needed to create a
146390 ** covering index. A "covering index" is an index that contains all
146391 ** columns that are needed by the query. With a covering index, the
146392 ** original table never needs to be accessed. Automatic indices must
146393 ** be a covering index because the index will not be updated if the
146394 ** original table changes and the index and table cannot both be used
146395 ** if they go out of sync.
146396 */
146397 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
146398 mxBitCol = MIN(BMS-1,pTable->nCol);
146399 testcase( pTable->nCol==BMS-1 );
146400 testcase( pTable->nCol==BMS-2 );
146401 for(i=0; i<mxBitCol; i++){
146402 if( extraCols & MASKBIT(i) ) nKeyCol++;
146403 }
146404 if( pSrc->colUsed & MASKBIT(BMS-1) ){
146405 nKeyCol += pTable->nCol - BMS + 1;
146406 }
146407
146408 /* Construct the Index object to describe this index */
146409 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
146410 if( pIdx==0 ) goto end_auto_index_create;
146411 pLoop->u.btree.pIndex = pIdx;
146412 pIdx->zName = "auto-index";
146413 pIdx->pTable = pTable;
146414 n = 0;
146415 idxCols = 0;
146416 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
146417 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
146418 int iCol = pTerm->u.leftColumn;
146419 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
146420 testcase( iCol==BMS-1 );
146421 testcase( iCol==BMS );
146422 if( (idxCols & cMask)==0 ){
146423 Expr *pX = pTerm->pExpr;
146424 idxCols |= cMask;
146425 pIdx->aiColumn[n] = pTerm->u.leftColumn;
146426 pColl = sqlite3ExprCompareCollSeq(pParse, pX);
146427 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
146428 pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
146429 n++;
146430 }
146431 }
146432 }
146433 assert( (u32)n==pLoop->u.btree.nEq );
146434
146435 /* Add additional columns needed to make the automatic index into
146436 ** a covering index */
146437 for(i=0; i<mxBitCol; i++){
146438 if( extraCols & MASKBIT(i) ){
146439 pIdx->aiColumn[n] = i;
146440 pIdx->azColl[n] = sqlite3StrBINARY;
146441 n++;
146442 }
146443 }
146444 if( pSrc->colUsed & MASKBIT(BMS-1) ){
146445 for(i=BMS-1; i<pTable->nCol; i++){
146446 pIdx->aiColumn[n] = i;
146447 pIdx->azColl[n] = sqlite3StrBINARY;
146448 n++;
146449 }
146450 }
146451 assert( n==nKeyCol );
146452 pIdx->aiColumn[n] = XN_ROWID;
146453 pIdx->azColl[n] = sqlite3StrBINARY;
146454
146455 /* Create the automatic index */
146456 assert( pLevel->iIdxCur>=0 );
146457 pLevel->iIdxCur = pParse->nTab++;
146458 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
146459 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
146460 VdbeComment((v, "for %s", pTable->zName));
146461
146462 /* Fill the automatic index with content */
146463 pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
146464 if( pTabItem->fg.viaCoroutine ){
146465 int regYield = pTabItem->regReturn;
146466 addrCounter = sqlite3VdbeAddOp2(v, OP_Integer, 0, 0);
146467 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
146468 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
146469 VdbeCoverage(v);
146470 VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
146471 }else{
146472 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
146473 }
146474 if( pPartial ){
146475 iContinue = sqlite3VdbeMakeLabel(pParse);
146476 sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
146477 pLoop->wsFlags |= WHERE_PARTIALIDX;
146478 }
146479 regRecord = sqlite3GetTempReg(pParse);
146480 regBase = sqlite3GenerateIndexKey(
146481 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
146482 );
146483 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
146485 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
146486 if( pTabItem->fg.viaCoroutine ){
146487 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
146488 testcase( pParse->db->mallocFailed );
146489 assert( pLevel->iIdxCur>0 );
146490 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
146491 pTabItem->regResult, pLevel->iIdxCur);
146492 sqlite3VdbeGoto(v, addrTop);
146493 pTabItem->fg.viaCoroutine = 0;
146494 }else{
146495 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
146497 }
146498 sqlite3VdbeJumpHere(v, addrTop);
146499 sqlite3ReleaseTempReg(pParse, regRecord);
146500
#define WHERE_PARTIALIDX
Definition sqlite3.c:141530
#define OP_Once
Definition sqlite3.c:15583
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat,...)
Definition sqlite3.c:29399
#define SQLITE_WARNING_AUTOINDEX
Definition sqlite3.c:1589
#define SQLITE_STMTSTATUS_AUTOINDEX
Definition sqlite3.c:9296
#define WHERE_IDX_ONLY
Definition sqlite3.c:141520
#define WHERE_INDEXED
Definition sqlite3.c:141522
#define BMS
Definition sqlite3.c:14726
static int termCanDriveIndex(WhereTerm *pTerm, struct SrcList_item *pSrc, Bitmask notReady)
Definition sqlite3.c:146269
#define OP_InitCoroutine
Definition sqlite3.c:15579
#define OP_Yield
Definition sqlite3.c:15580
#define OP_OpenAutoindex
Definition sqlite3.c:15665
#define OP_IdxInsert
Definition sqlite3.c:15696
SQLITE_PRIVATE Index * sqlite3AllocateIndexObject(sqlite3 *, i16, int, char **)
Definition sqlite3.c:113808
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *, int addr, int P2)
Definition sqlite3.c:78782
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse *, Index *, int, int, int, int *, Index *, int)
Definition sqlite3.c:116973
#define OPFLAG_USESEEKRESULT
Definition sqlite3.c:18843
#define MASKBIT(n)
Definition sqlite3.c:14731
#define WHERE_COLUMN_EQ
Definition sqlite3.c:141512
static void translateColumnToCopy(Parse *pParse, int iStart, int iTabCur, int iRegister, int iAutoidxCur)
Definition sqlite3.c:146187
SQLITE_PRIVATE Expr * sqlite3ExprAnd(Parse *, Expr *, Expr *)
Definition sqlite3.c:100646
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *, int)
Definition sqlite3.c:101830
static int whereLoopResize(sqlite3 *, WhereLoop *, int)
Definition sqlite3.c:147496
#define WHERE_AUTO_INDEX
Definition sqlite3.c:141527
u64 Bitmask
Definition sqlite3.c:14720
SQLITE_PRIVATE const char sqlite3StrBINARY[]
Definition sqlite3.c:20683
char * zName
Definition sqlite3.c:17366
i16 iRightJoinTable
Definition sqlite3.c:18040
WhereInfo * pWInfo
Definition sqlite3.c:141246
SrcList * pTabList
Definition sqlite3.c:141385
Bitmask prereq
Definition sqlite3.c:141032

References SrcList::a, WhereClause::a, Table::aCol, Index::aiColumn, WhereLoop::aLTerm, Index::azColl, BMS, WhereLoop::btree, Parse::db, EP_FromJoin, ExprHasProperty, WhereLevel::iFrom, WhereLevel::iIdxCur, Expr::iRightJoinTable, WhereLevel::iTabCur, WhereTerm::leftColumn, sqlite3::mallocFailed, MASKBIT, MIN, Table::nCol, WhereLoop::nEq, Parse::nErr, WhereLoop::nLTerm, Parse::nTab, WhereClause::nTerm, OP_IdxInsert, OP_InitCoroutine, OP_Integer, OP_Next, OP_Once, OP_OpenAutoindex, OP_Rewind, OP_Yield, OPFLAG_USESEEKRESULT, WhereTerm::pExpr, WhereLoop::pIndex, WhereLoop::prereq, Index::pTable, WhereInfo::pTabList, Parse::pVdbe, WhereClause::pWInfo, WhereLevel::pWLoop, sqlite3_log(), sqlite3AllocateIndexObject(), sqlite3ExprAnd(), sqlite3ExprCompareCollSeq(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprIfFalse(), sqlite3ExprIsTableConstant(), sqlite3GenerateIndexKey(), sqlite3GetTempReg(), sqlite3ReleaseTempReg(), sqlite3StrBINARY, sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP2(), sqlite3VdbeChangeP5(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VdbeSetP4KeyInfo(), SQLITE_JUMPIFNULL, SQLITE_STMTSTATUS_AUTOINDEX, SQLITE_WARNING_AUTOINDEX, TERM_VIRTUAL, termCanDriveIndex(), testcase, translateColumnToCopy(), WhereLoop::u, WhereTerm::u, VdbeComment, VdbeCoverage, WHERE_AUTO_INDEX, WHERE_COLUMN_EQ, WHERE_IDX_ONLY, WHERE_INDEXED, WHERE_PARTIALIDX, whereLoopResize(), WhereLoop::wsFlags, WhereTerm::wtFlags, XN_ROWID, Column::zName, CollSeq::zName, Table::zName, and Index::zName.

Referenced by sqlite3WhereBegin().

◆ contextMalloc()

static void * contextMalloc ( sqlite3_context * context,
i64 nByte )
static

Definition at line 117479 of file sqlite3.c.

117485 {
117486 char *z;
117487 sqlite3 *db = sqlite3_context_db_handle(context);
117488 assert( nByte>0 );
117489 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
117490 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
117491 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
117493 z = 0;
117494 }else{
117495 z = sqlite3Malloc(nByte);
SQLITE_PRIVATE void * sqlite3Malloc(u64)
Definition sqlite3.c:27590
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *)
Definition sqlite3.c:83532
#define SQLITE_LIMIT_LENGTH
Definition sqlite3.c:4944

References sqlite3::aLimit, sqlite3_context_db_handle(), sqlite3_result_error_nomem(), sqlite3_result_error_toobig(), sqlite3Malloc(), SQLITE_LIMIT_LENGTH, and testcase.

Referenced by quoteFunc(), and replaceFunc().

◆ convertCompoundSelectToSubquery()

static int convertCompoundSelectToSubquery ( Walker * pWalker,
Select * p )
static

Definition at line 133931 of file sqlite3.c.

133931 ://www.sqlite.org/src/info/6709574d2a
133932**
133933** This transformation is only needed for EXCEPT, INTERSECT, and UNION.
133934** The UNION ALL operator works fine with multiSelectOrderBy() even when
133935** there are COLLATE terms in the ORDER BY.
133936*/
133937static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
133938 int i;
133939 Select *pNew;
133940 Select *pX;
133941 sqlite3 *db;
133942 struct ExprList_item *a;
133943 SrcList *pNewSrc;
133944 Parse *pParse;
133945 Token dummy;
133946
133947 if( p->pPrior==0 ) return WRC_Continue;
133948 if( p->pOrderBy==0 ) return WRC_Continue;
133949 for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
133950 if( pX==0 ) return WRC_Continue;
133951 a = p->pOrderBy->a;
133952#ifndef SQLITE_OMIT_WINDOWFUNC
133953 /* If iOrderByCol is already non-zero, then it has already been matched
133954 ** to a result column of the SELECT statement. This occurs when the
133955 ** SELECT is rewritten for window-functions processing and then passed
133956 ** to sqlite3SelectPrep() and similar a second time. The rewriting done
133957 ** by this function is not required in this case. */
133958 if( a[0].u.x.iOrderByCol ) return WRC_Continue;
133959#endif
133960 for(i=p->pOrderBy->nExpr-1; i>=0; i--){
133961 if( a[i].pExpr->flags & EP_Collate ) break;
133962 }
133963 if( i<0 ) return WRC_Continue;
133964
133965 /* If we reach this point, that means the transformation is required. */
133966
133967 pParse = pWalker->pParse;
133968 db = pParse->db;
133969 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
133970 if( pNew==0 ) return WRC_Abort;
133971 memset(&dummy, 0, sizeof(dummy));
133972 pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0,0);
133973 if( pNewSrc==0 ) return WRC_Abort;
133974 *pNew = *p;
133975 p->pSrc = pNewSrc;
133976 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ASTERISK, 0));
133977 p->op = TK_SELECT;
133978 p->pWhere = 0;
133979 pNew->pGroupBy = 0;
133980 pNew->pHaving = 0;
133981 pNew->pOrderBy = 0;
133982 p->pPrior = 0;
133983 p->pNext = 0;
133984 p->pWith = 0;
133985#ifndef SQLITE_OMIT_WINDOWFUNC
133986 p->pWinDefn = 0;
133987#endif
133988 p->selFlags &= ~SF_Compound;
133989 assert( (p->selFlags & SF_Converted)==0 );
#define EP_Collate
Definition sqlite3.c:18068
#define TK_ASTERISK
Definition sqlite3.c:14119
#define SF_Converted
Definition sqlite3.c:18487
SQLITE_PRIVATE Expr * sqlite3Expr(sqlite3 *, int, const char *)
Definition sqlite3.c:100554
static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p)
Definition sqlite3.c:133931
#define TK_ALL
Definition sqlite3.c:14075
SQLITE_PRIVATE SrcList * sqlite3SrcListAppendFromTerm(Parse *, SrcList *, Token *, Token *, Token *, Select *, Expr *, IdList *)
Definition sqlite3.c:114886
#define WRC_Abort
Definition sqlite3.c:19139
#define WRC_Continue
Definition sqlite3.c:19137
static int multiSelectOrderBy(Parse *pParse, Select *p, SelectDest *pDest)
Definition sqlite3.c:132439

References ExprList::a, Parse::db, dummy, EP_Collate, Expr::flags, ExprList::nExpr, Select::op, Select::pEList, Select::pGroupBy, Select::pHaving, Select::pLimit, Select::pNext, Select::pOrderBy, Walker::pParse, Select::pPrior, Select::pSrc, Select::pWhere, Select::pWinDefn, Select::pWith, Select::selFlags, SF_Converted, sqlite3DbMallocZero(), sqlite3Expr(), sqlite3ExprListAppend(), sqlite3SrcListAppendFromTerm(), TK_ALL, TK_ASTERISK, TK_SELECT, WRC_Abort, and WRC_Continue.

Referenced by sqlite3SelectExpand().

◆ convertToWithoutRowidTable()

static void convertToWithoutRowidTable ( Parse * pParse,
Table * pTab )
static

Definition at line 112425 of file sqlite3.c.

112431 {
112432 Index *pIdx;
112433 Index *pPk;
112434 int nPk;
112435 int nExtra;
112436 int i, j;
112437 sqlite3 *db = pParse->db;
112438 Vdbe *v = pParse->pVdbe;
112439
112440 /* Mark every PRIMARY KEY column as NOT NULL (except for imposter tables)
112441 */
112442 if( !db->init.imposterTable ){
112443 for(i=0; i<pTab->nCol; i++){
112444 if( (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0 ){
112445 pTab->aCol[i].notNull = OE_Abort;
112446 }
112447 }
112448 pTab->tabFlags |= TF_HasNotNull;
112449 }
112450
112451 /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
112452 ** into BTREE_BLOBKEY.
112453 */
112454 if( pParse->addrCrTab ){
112455 assert( v );
112457 }
112458
112459 /* Locate the PRIMARY KEY index. Or, if this table was originally
112460 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
112461 */
112462 if( pTab->iPKey>=0 ){
112463 ExprList *pList;
112464 Token ipkToken;
112465 sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
112466 pList = sqlite3ExprListAppend(pParse, 0,
112467 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
112468 if( pList==0 ) return;
112469 if( IN_RENAME_OBJECT ){
112470 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
112471 }
112472 pList->a[0].sortFlags = pParse->iPkSortOrder;
112473 assert( pParse->pNewTable==pTab );
112474 pTab->iPKey = -1;
112475 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
112477 if( db->mallocFailed || pParse->nErr ) return;
112478 pPk = sqlite3PrimaryKeyIndex(pTab);
112479 assert( pPk->nKeyCol==1 );
112480 }else{
112481 pPk = sqlite3PrimaryKeyIndex(pTab);
112482 assert( pPk!=0 );
112483
112484 /*
112485 ** Remove all redundant columns from the PRIMARY KEY. For example, change
112486 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
112487 ** code assumes the PRIMARY KEY contains no repeated columns.
112488 */
112489 for(i=j=1; i<pPk->nKeyCol; i++){
112490 if( isDupColumn(pPk, j, pPk, i) ){
112491 pPk->nColumn--;
112492 }else{
112493 testcase( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) );
112494 pPk->azColl[j] = pPk->azColl[i];
112495 pPk->aSortOrder[j] = pPk->aSortOrder[i];
112496 pPk->aiColumn[j++] = pPk->aiColumn[i];
112497 }
112498 }
112499 pPk->nKeyCol = j;
112500 }
112501 assert( pPk!=0 );
112502 pPk->isCovering = 1;
112503 if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
112504 nPk = pPk->nColumn = pPk->nKeyCol;
112505
112506 /* Bypass the creation of the PRIMARY KEY btree and the sqlite_schema
112507 ** table entry. This is only required if currently generating VDBE
112508 ** code for a CREATE TABLE (not when parsing one as part of reading
112509 ** a database schema). */
112510 if( v && pPk->tnum>0 ){
112511 assert( db->init.busy==0 );
112512 sqlite3VdbeChangeOpcode(v, (int)pPk->tnum, OP_Goto);
112513 }
112514
112515 /* The root page of the PRIMARY KEY is the table root page */
112516 pPk->tnum = pTab->tnum;
112517
112518 /* Update the in-memory representation of all UNIQUE indices by converting
112519 ** the final rowid column into one or more columns of the PRIMARY KEY.
112520 */
112521 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
112522 int n;
112523 if( IsPrimaryKeyIndex(pIdx) ) continue;
112524 for(i=n=0; i<nPk; i++){
112525 if( !isDupColumn(pIdx, pIdx->nKeyCol, pPk, i) ){
112526 testcase( hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) );
112527 n++;
112528 }
112529 }
112530 if( n==0 ){
112531 /* This index is a superset of the primary key */
112532 pIdx->nColumn = pIdx->nKeyCol;
112533 continue;
112534 }
112535 if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
112536 for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
112537 if( !isDupColumn(pIdx, pIdx->nKeyCol, pPk, i) ){
112538 testcase( hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) );
112539 pIdx->aiColumn[j] = pPk->aiColumn[i];
112540 pIdx->azColl[j] = pPk->azColl[i];
112541 if( pPk->aSortOrder[i] ){
112542 /* See ticket https://www.sqlite.org/src/info/bba7b69f9849b5bf */
112543 pIdx->bAscKeyBug = 1;
112544 }
112545 j++;
112546 }
112547 }
112548 assert( pIdx->nColumn>=pIdx->nKeyCol+n );
112549 assert( pIdx->nColumn>=j );
112550 }
112551
112552 /* Add all table columns to the PRIMARY KEY index
112553 */
112554 nExtra = 0;
112555 for(i=0; i<pTab->nCol; i++){
112556 if( !hasColumn(pPk->aiColumn, nPk, i)
112557 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) nExtra++;
112558 }
112559 if( resizeIndexObject(db, pPk, nPk+nExtra) ) return;
112560 for(i=0, j=nPk; i<pTab->nCol; i++){
112561 if( !hasColumn(pPk->aiColumn, j, i)
112562 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
112563 ){
112564 assert( j<pPk->nColumn );
112565 pPk->aiColumn[j] = i;
112566 pPk->azColl[j] = sqlite3StrBINARY;
112567 j++;
#define COLFLAG_PRIMKEY
Definition sqlite3.c:17344
#define TF_HasNotNull
Definition sqlite3.c:17547
static int isDupColumn(Index *pIdx, int nKey, Index *pPk, int iCol)
Definition sqlite3.c:112346
#define IN_RENAME_OBJECT
Definition sqlite3.c:18806
#define COLFLAG_VIRTUAL
Definition sqlite3.c:17349
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *, int addr, int P3)
Definition sqlite3.c:78785
static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N)
Definition sqlite3.c:112269
SQLITE_PRIVATE Expr * sqlite3ExprAlloc(sqlite3 *, int, const Token *, int)
Definition sqlite3.c:100506
#define OE_Abort
Definition sqlite3.c:17658
SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse *, void *pTo, void *pFrom)
Definition sqlite3.c:106529
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *, int addr, u8)
Definition sqlite3.c:78776
#define BTREE_BLOBKEY
Definition sqlite3.c:15112
#define SQLITE_IDXTYPE_PRIMARYKEY
Definition sqlite3.c:17819
SQLITE_PRIVATE void sqlite3CreateIndex(Parse *, Token *, Token *, SrcList *, ExprList *, int, Token *, Expr *, int, int, u8)
Definition sqlite3.c:113869
static int hasColumn(const i16 *aiCol, int nCol, int x)
Definition sqlite3.c:112323
SQLITE_PRIVATE void sqlite3TokenInit(Token *, char *)
Definition sqlite3.c:31442
u8 notNull
Definition sqlite3.c:17335
u16 colFlags
Definition sqlite3.c:17339
unsigned bAscKeyBug
Definition sqlite3.c:17801
unsigned isCovering
Definition sqlite3.c:17797
u8 iPkSortOrder
Definition sqlite3.c:18749
int addrCrTab
Definition sqlite3.c:18722
u8 keyConf
Definition sqlite3.c:17507

References ExprList::a, Table::aCol, Parse::addrCrTab, Index::aiColumn, Index::aSortOrder, Index::azColl, Index::bAscKeyBug, BTREE_BLOBKEY, sqlite3::sqlite3InitInfo::busy, COLFLAG_PRIMKEY, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, hasColumn(), sqlite3::sqlite3InitInfo::imposterTable, IN_RENAME_OBJECT, sqlite3::init, Table::iPKey, Parse::iPkSortOrder, Index::isCovering, isDupColumn(), IsPrimaryKeyIndex, Table::keyConf, sqlite3::mallocFailed, Table::nCol, Index::nColumn, Parse::nErr, Index::nKeyCol, Table::nNVCol, Column::notNull, OE_Abort, OP_Goto, ExprList::ExprList_item::pExpr, Table::pIndex, Parse::pNewTable, Index::pNext, Parse::pVdbe, recomputeColumnsNotIndexed(), resizeIndexObject(), ExprList::ExprList_item::sortFlags, sqlite3CreateIndex(), sqlite3ExprAlloc(), sqlite3ExprListAppend(), sqlite3PrimaryKeyIndex(), sqlite3RenameTokenRemap(), sqlite3StrBINARY, sqlite3TokenInit(), sqlite3VdbeChangeOpcode(), sqlite3VdbeChangeP3(), SQLITE_IDXTYPE_PRIMARYKEY, Table::tabFlags, testcase, TF_HasNotNull, TK_ID, Table::tnum, Index::tnum, Index::uniqNotNull, and Column::zName.

Referenced by sqlite3EndTable().

◆ copyNodeContent()

static void copyNodeContent ( MemPage * pFrom,
MemPage * pTo,
int * pRC )
static

Definition at line 71912 of file sqlite3.c.

71918 {
71919 if( (*pRC)==SQLITE_OK ){
71920 BtShared * const pBt = pFrom->pBt;
71921 u8 * const aFrom = pFrom->aData;
71922 u8 * const aTo = pTo->aData;
71923 int const iFromHdr = pFrom->hdrOffset;
71924 int const iToHdr = ((pTo->pgno==1) ? 100 : 0);
71925 int rc;
71926 int iData;
71927
71928
71929 assert( pFrom->isInit );
71930 assert( pFrom->nFree>=iToHdr );
71931 assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize );
71932
71933 /* Copy the b-tree node content from page pFrom to page pTo. */
71934 iData = get2byte(&aFrom[iFromHdr+5]);
71935 memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
71936 memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell);
71937
71938 /* Reinitialize page pTo so that the contents of the MemPage structure
71939 ** match the new data. The initialization of pTo can actually fail under
71940 ** fairly obscure circumstances, even though it is a copy of initialized
71941 ** page pFrom.
71942 */
71943 pTo->isInit = 0;
71944 rc = btreeInitPage(pTo);
71945 if( rc==SQLITE_OK ) rc = btreeComputeFreeSpace(pTo);
71946 if( rc!=SQLITE_OK ){
71947 *pRC = rc;
71948 return;
71949 }
71950
71951 /* If this is an auto-vacuum database, update the pointer-map entries
71952 ** for any b-tree or overflow pages that pTo now contains the pointers to.

References MemPage::aData, btreeComputeFreeSpace(), btreeInitPage(), MemPage::cellOffset, get2byte, MemPage::hdrOffset, ISAUTOVACUUM, MemPage::isInit, MemPage::nCell, MemPage::nFree, MemPage::pBt, MemPage::pgno, setChildPtrmaps(), SQLITE_OK, and BtShared::usableSize.

Referenced by balance_deeper(), and balance_nonroot().

◆ copyPayload()

static int copyPayload ( void * pPayload,
void * pBuf,
int nByte,
int eOp,
DbPage * pDbPage )
static

Definition at line 69209 of file sqlite3.c.

69221 {
69222 if( eOp ){
69223 /* Copy data from buffer to page (a write operation) */
69224 int rc = sqlite3PagerWrite(pDbPage);
69225 if( rc!=SQLITE_OK ){
69226 return rc;
69227 }
69228 memcpy(pPayload, pBuf, nByte);

References sqlite3PagerWrite(), and SQLITE_OK.

Referenced by accessPayload().

◆ corruptSchema()

static void corruptSchema ( InitData * pData,
const char * zObj,
const char * zExtra )
static

Definition at line 128355 of file sqlite3.c.

128365 {
128366 sqlite3 *db = pData->db;
128367 if( db->mallocFailed ){
128368 pData->rc = SQLITE_NOMEM_BKPT;
128369 }else if( pData->pzErrMsg[0]!=0 ){
128370 /* A error message has already been generated. Do not overwrite it */
128371 }else if( pData->mInitFlags & INITFLAG_AlterTable ){
128372 *pData->pzErrMsg = sqlite3DbStrDup(db, zExtra);
128373 pData->rc = SQLITE_ERROR;
128374 }else if( db->flags & SQLITE_WriteSchema ){
128375 pData->rc = SQLITE_CORRUPT_BKPT;
128376 }else{
128377 char *z;
128378 if( zObj==0 ) zObj = "?";
#define INITFLAG_AlterTable
Definition sqlite3.c:19001
#define SQLITE_WriteSchema
Definition sqlite3.c:16978
u32 mInitFlags
Definition sqlite3.c:18993
char ** pzErrMsg
Definition sqlite3.c:18990
sqlite3 * db
Definition sqlite3.c:18989

References InitData::db, sqlite3::flags, INITFLAG_AlterTable, sqlite3::mallocFailed, InitData::mInitFlags, InitData::pzErrMsg, InitData::rc, sqlite3DbStrDup(), sqlite3MPrintf(), SQLITE_CORRUPT_BKPT, SQLITE_ERROR, SQLITE_NOMEM_BKPT, and SQLITE_WriteSchema.

Referenced by sqlite3InitCallback().

◆ countFinalize()

static void countFinalize ( sqlite3_context * context)
static

Definition at line 118675 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ countInverse()

static void countInverse ( sqlite3_context * ctx,
int argc,
sqlite3_value ** argv )
static

Definition at line 118681 of file sqlite3.c.

118681 {
118682 CountCtx *p;
118683 p = sqlite3_aggregate_context(context, 0);
118684 sqlite3_result_int64(context, p ? p->n : 0);
118685}
118686#ifndef SQLITE_OMIT_WINDOWFUNC
118687static void countInverse(sqlite3_context *ctx, int argc, sqlite3_value **argv){
118688 CountCtx *p;
118689 p = sqlite3_aggregate_context(ctx, sizeof(*p));
118690 /* p is always non-NULL since countStep() will have been called first */
118691 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && ALWAYS(p) ){
SQLITE_API void * sqlite3_aggregate_context(sqlite3_context *, int nBytes)
Definition sqlite3.c:83867
static void countInverse(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Definition sqlite3.c:118681

References CountCtx::n, sqlite3_aggregate_context(), and sqlite3_result_int64().

Referenced by sqlite3RegisterBuiltinFunctions().

◆ countLookasideSlots()

static u32 countLookasideSlots ( LookasideSlot * p)
static

Definition at line 21489 of file sqlite3.c.

21494 {
21495 u32 cnt = 0;
21496 while( p ){

◆ countStep()

static void countStep ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118659 of file sqlite3.c.

118665 {
118666 CountCtx *p;
118667 p = sqlite3_aggregate_context(context, sizeof(*p));
118668 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
118669 p->n++;
118670 }
118671
118672#ifndef SQLITE_OMIT_DEPRECATED
118673 /* The sqlite3_aggregate_count() function is deprecated. But just to make
118674 ** sure it still operates correctly, verify that its count agrees with our

Referenced by sqlite3RegisterBuiltinFunctions().

◆ createAggContext()

static SQLITE_NOINLINE void * createAggContext ( sqlite3_context * p,
int nByte )
static

Definition at line 83845 of file sqlite3.c.

83851 {
83852 Mem *pMem = p->pMem;
83853 assert( (pMem->flags & MEM_Agg)==0 );
83854 if( nByte<=0 ){
83856 pMem->z = 0;
83857 }else{
83858 sqlite3VdbeMemClearAndResize(pMem, nByte);
83859 pMem->flags = MEM_Agg;
83860 pMem->u.pDef = p->pFunc;
SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *)
Definition sqlite3.c:76646
FuncDef * pFunc
Definition sqlite3.c:21035

Referenced by sqlite3_aggregate_context().

◆ createCollation()

static int createCollation ( sqlite3 * db,
const char * zName,
u8 enc,
void * pCtx,
int(*)(void *, int, const void *, int, const void *) xCompare,
void(*)(void *) xDel )
static

Definition at line 163588 of file sqlite3.c.

163601 {
163602 CollSeq *pColl;
163603 int enc2;
163604
163605 assert( sqlite3_mutex_held(db->mutex) );
163606
163607 /* If SQLITE_UTF16 is specified as the encoding type, transform this
163608 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
163609 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
163610 */
163611 enc2 = enc;
163612 testcase( enc2==SQLITE_UTF16 );
163614 if( enc2==SQLITE_UTF16 || enc2==SQLITE_UTF16_ALIGNED ){
163615 enc2 = SQLITE_UTF16NATIVE;
163616 }
163617 if( enc2<SQLITE_UTF8 || enc2>SQLITE_UTF16BE ){
163618 return SQLITE_MISUSE_BKPT;
163619 }
163620
163621 /* Check if this call is removing or replacing an existing collation
163622 ** sequence. If so, and there are active VMs, return busy. If there
163623 ** are no active VMs, invalidate any pre-compiled statements.
163624 */
163625 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
163626 if( pColl && pColl->xCmp ){
163627 if( db->nVdbeActive ){
163629 "unable to delete/modify collation sequence due to active statements");
163630 return SQLITE_BUSY;
163631 }
163633
163634 /* If collation sequence pColl was created directly by a call to
163635 ** sqlite3_create_collation, and not generated by synthCollSeq(),
163636 ** then any copies made by synthCollSeq() need to be invalidated.
163637 ** Also, collation destructor - CollSeq.xDel() - function may need
163638 ** to be called.
163639 */
163640 if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
163641 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
163642 int j;
163643 for(j=0; j<3; j++){
163644 CollSeq *p = &aColl[j];
163645 if( p->enc==pColl->enc ){
163646 if( p->xDel ){
163647 p->xDel(p->pUser);
163648 }
163649 p->xCmp = 0;
163650 }
163651 }
163652 }
163653 }
163654
163655 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
163656 if( pColl==0 ) return SQLITE_NOMEM_BKPT;
163657 pColl->xCmp = xCompare;
SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3 *, int, const char *,...)
Definition sqlite3.c:31330
#define SQLITE_UTF16BE
Definition sqlite3.c:6254
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *, int)
Definition sqlite3.c:82779
SQLITE_PRIVATE void * sqlite3HashFind(const Hash *, const char *pKey)
Definition sqlite3.c:33094
#define SQLITE_UTF16
Definition sqlite3.c:6255
#define SQLITE_UTF16_ALIGNED
Definition sqlite3.c:6257
SQLITE_PRIVATE CollSeq * sqlite3FindCollSeq(sqlite3 *, u8 enc, const char *, int)
Definition sqlite3.c:115695
void * pUser
Definition sqlite3.c:17368
int(* xCmp)(void *, int, const void *, int, const void *)
Definition sqlite3.c:17369
void(* xDel)(void *)
Definition sqlite3.c:17370
Hash aCollSeq
Definition sqlite3.c:16924
int nVdbeActive
Definition sqlite3.c:16864

Referenced by openDatabase().

◆ createFunctionApi()

static int createFunctionApi ( sqlite3 * db,
const char * zFunc,
int nArg,
int enc,
void * p,
void(*)(sqlite3_context *, int, sqlite3_value **) xSFunc,
void(*)(sqlite3_context *, int, sqlite3_value **) xStep,
void(*)(sqlite3_context *) xFinal,
void(*)(sqlite3_context *) xValue,
void(*)(sqlite3_context *, int, sqlite3_value **) xInverse,
void(*)(void *) xDestroy )
static

Definition at line 162885 of file sqlite3.c.

162885 :
162886**
162890*/
162891static int createFunctionApi(
162892 sqlite3 *db,
162893 const char *zFunc,
162894 int nArg,
162895 int enc,
162896 void *p,
162897 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**),
162898 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
162899 void (*xFinal)(sqlite3_context*),
162900 void (*xValue)(sqlite3_context*),
162901 void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
162902 void(*xDestroy)(void*)
162903){
162904 int rc = SQLITE_ERROR;
162905 FuncDestructor *pArg = 0;
162906
162907#ifdef SQLITE_ENABLE_API_ARMOR
162908 if( !sqlite3SafetyCheckOk(db) ){
162909 return SQLITE_MISUSE_BKPT;
162910 }
162911#endif
162913 if( xDestroy ){
162914 pArg = (FuncDestructor *)sqlite3Malloc(sizeof(FuncDestructor));
162915 if( !pArg ){
162916 sqlite3OomFault(db);
162917 xDestroy(p);
162918 goto out;
162919 }
162920 pArg->nRef = 0;
162921 pArg->xDestroy = xDestroy;
162922 pArg->pUserData = p;
162923 }
162924 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p,
162925 xSFunc, xStep, xFinal, xValue, xInverse, pArg
162926 );
162927 if( pArg && pArg->nRef==0 ){
162928 assert( rc!=SQLITE_OK );
162929 xDestroy(p);
162930 sqlite3_free(pArg);
162931 }
SQLITE_API int sqlite3_create_function(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *))
Definition sqlite3.c:162936
SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, void(*)(sqlite3_context *, int, sqlite3_value **), void(*)(sqlite3_context *, int, sqlite3_value **), void(*)(sqlite3_context *), void(*)(sqlite3_context *), void(*)(sqlite3_context *, int, sqlite3_value **), FuncDestructor *pDestructor)
Definition sqlite3.c:162765
SQLITE_API int sqlite3_create_window_function(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *), void(*xValue)(sqlite3_context *), void(*xInverse)(sqlite3_context *, int, sqlite3_value **), void(*xDestroy)(void *))
Definition sqlite3.c:162963
static int createFunctionApi(sqlite3 *db, const char *zFunc, int nArg, int enc, void *p, void(*xSFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *), void(*xValue)(sqlite3_context *), void(*xInverse)(sqlite3_context *, int, sqlite3_value **), void(*xDestroy)(void *))
Definition sqlite3.c:162885
SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *)
Definition sqlite3.c:32542
SQLITE_API int sqlite3_create_function_v2(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *), void(*xDestroy)(void *))
Definition sqlite3.c:162949
void * pUserData
Definition sqlite3.c:17127
void(* xDestroy)(void *)
Definition sqlite3.c:17126

References sqlite3::mutex, FuncDestructor::nRef, FuncDestructor::pUserData, sqlite3_free(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3CreateFunc(), sqlite3Malloc(), sqlite3OomFault(), sqlite3SafetyCheckOk(), SQLITE_ERROR, SQLITE_MISUSE_BKPT, SQLITE_OK, and FuncDestructor::xDestroy.

Referenced by sqlite3_create_function16(), sqlite3_create_function_v2(), and sqlite3_create_window_function().

◆ createMask()

static void createMask ( WhereMaskSet * pMaskSet,
int iCursor )
static

Definition at line 145838 of file sqlite3.c.

References ArraySize, WhereMaskSet::ix, and WhereMaskSet::n.

Referenced by sqlite3WhereBegin().

◆ createModule()

static int createModule ( sqlite3 * db,
const char * zName,
const sqlite3_module * pModule,
void * pAux,
void(*)(void *) xDestroy )
static

Definition at line 139658 of file sqlite3.c.

139670 {
139671 int rc = SQLITE_OK;
139672

References sqlite3::mutex, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3VtabCreateModule(), SQLITE_OK, and zName.

◆ createTableStmt()

static char * createTableStmt ( sqlite3 * db,
Table * p )
static

Definition at line 112201 of file sqlite3.c.

112207 {
112208 int i, k, n;
112209 char *zStmt;
112210 char *zSep, *zSep2, *zEnd;
112211 Column *pCol;
112212 n = 0;
112213 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
112214 n += identLength(pCol->zName) + 5;
112215 }
112216 n += identLength(p->zName);
112217 if( n<50 ){
112218 zSep = "";
112219 zSep2 = ",";
112220 zEnd = ")";
112221 }else{
112222 zSep = "\n ";
112223 zSep2 = ",\n ";
112224 zEnd = "\n)";
112225 }
112226 n += 35 + 6*p->nCol;
112227 zStmt = sqlite3DbMallocRaw(0, n);
112228 if( zStmt==0 ){
112229 sqlite3OomFault(db);
112230 return 0;
112231 }
112232 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
112233 k = sqlite3Strlen30(zStmt);
112234 identPut(zStmt, &k, p->zName);
112235 zStmt[k++] = '(';
112236 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
112237 static const char * const azType[] = {
112238 /* SQLITE_AFF_BLOB */ "",
112239 /* SQLITE_AFF_TEXT */ " TEXT",
112240 /* SQLITE_AFF_NUMERIC */ " NUM",
112241 /* SQLITE_AFF_INTEGER */ " INT",
112242 /* SQLITE_AFF_REAL */ " REAL"
112243 };
112244 int len;
112245 const char *zType;
112246
112247 sqlite3_snprintf(n-k, &zStmt[k], zSep);
112248 k += sqlite3Strlen30(&zStmt[k]);
112249 zSep = zSep2;
112250 identPut(zStmt, &k, pCol->zName);
112251 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
112252 assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
112258
112259 zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
112260 len = sqlite3Strlen30(zType);
112261 assert( pCol->affinity==SQLITE_AFF_BLOB
112262 || pCol->affinity==sqlite3AffinityType(zType, 0) );
112263 memcpy(&zStmt[k], zType, len);
static int identLength(const char *z)
Definition sqlite3.c:112152
SQLITE_PRIVATE int sqlite3Strlen30(const char *)
Definition sqlite3.c:31259
static void identPut(char *z, int *pIdx, char *zSignedIdent)
Definition sqlite3.c:112173
SQLITE_API char * sqlite3_snprintf(int, char *, const char *,...)
Definition sqlite3.c:29363
SQLITE_PRIVATE void * sqlite3DbMallocRaw(sqlite3 *, u64)
Definition sqlite3.c:27893
SQLITE_PRIVATE char sqlite3AffinityType(const char *, Column *)
Definition sqlite3.c:111756
char affinity
Definition sqlite3.c:17336

References Table::aCol, Column::affinity, ArraySize, identLength(), identPut(), Table::nCol, sqlite3_snprintf(), sqlite3AffinityType(), sqlite3DbMallocRaw(), sqlite3OomFault(), sqlite3Strlen30(), SQLITE_AFF_BLOB, SQLITE_AFF_INTEGER, SQLITE_AFF_NUMERIC, SQLITE_AFF_REAL, SQLITE_AFF_TEXT, testcase, Column::zName, and Table::zName.

Referenced by sqlite3EndTable().

◆ ctimeFunc()

static void ctimeFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 22852 of file sqlite3.c.

References timeFunc(), and UNUSED_PARAMETER2.

Referenced by sqlite3RegisterDateTimeFunctions().

◆ ctimestampFunc()

static void ctimestampFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 22880 of file sqlite3.c.

References datetimeFunc(), and UNUSED_PARAMETER2.

Referenced by sqlite3RegisterDateTimeFunctions().

◆ cume_distInvFunc()

static void cume_distInvFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151545 of file sqlite3.c.

151547 {
151548 p->nTotal++;
151549 }
151550}
151551static void cume_distInvFunc(
151552 sqlite3_context *pCtx,
151553 int nArg,
151554 sqlite3_value **apArg
151555){
static void cume_distInvFunc(sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
Definition sqlite3.c:151545

◆ cume_distStepFunc()

static void cume_distStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151532 of file sqlite3.c.

151542 {
151543 struct CallCount *p;
151544 UNUSED_PARAMETER(nArg); assert( nArg==0 );

References UNUSED_PARAMETER.

◆ cume_distValueFunc()

static void cume_distValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151556 of file sqlite3.c.

151562 {
151563 struct CallCount *p;

◆ databaseIsUnmoved()

static int databaseIsUnmoved ( Pager * pPager)
static

Definition at line 55751 of file sqlite3.c.

55757 {
55758 int bHasMoved = 0;
55759 int rc;
55760
55761 if( pPager->tempFile ) return SQLITE_OK;
55762 if( pPager->dbSize==0 ) return SQLITE_OK;
55763 assert( pPager->zFilename && pPager->zFilename[0] );
55764 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved);
55765 if( rc==SQLITE_NOTFOUND ){
55766 /* If the HAS_MOVED file-control is unimplemented, assume that the file
55767 ** has not been moved. That is the historical behavior of SQLite: prior to
55768 ** version 3.8.3, it never checked */
#define SQLITE_NOTFOUND
Definition sqlite3.c:1482
#define SQLITE_FCNTL_HAS_MOVED
Definition sqlite3.c:2197
SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *, int, void *)
Definition sqlite3.c:23088
sqlite3_file * fd
Definition sqlite3.c:52361
char * zFilename
Definition sqlite3.c:52386
u8 tempFile
Definition sqlite3.c:52330
Pgno dbSize
Definition sqlite3.c:52352

References Pager::dbSize, Pager::fd, sqlite3OsFileControl(), SQLITE_FCNTL_HAS_MOVED, SQLITE_NOTFOUND, SQLITE_OK, SQLITE_READONLY_DBMOVED, Pager::tempFile, and Pager::zFilename.

Referenced by pager_open_journal(), and sqlite3PagerClose().

◆ databaseName()

static const char * databaseName ( const char * zName)
static

Definition at line 165215 of file sqlite3.c.

References zName.

Referenced by sqlite3_filename_journal(), sqlite3_free_filename(), and sqlite3_uri_parameter().

◆ dateFunc()

static void dateFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 22681 of file sqlite3.c.

22690 {
22691 DateTime x;
22692 if( isDate(context, argc, argv, &x)==0 ){
22693 char zBuf[100];
static int isDate(sqlite3_context *context, int argc, sqlite3_value **argv, DateTime *p)
Definition sqlite3.c:22582

References computeYMD(), DateTime::D, isDate(), DateTime::M, sqlite3_result_text(), sqlite3_snprintf(), SQLITE_TRANSIENT, and DateTime::Y.

Referenced by cdateFunc(), and sqlite3RegisterDateTimeFunctions().

◆ datetimeError()

static void datetimeError ( DateTime * p)
static

Definition at line 21949 of file sqlite3.c.

Referenced by computeJD().

◆ datetimeFunc()

static void datetimeFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 22642 of file sqlite3.c.

22651 {
22652 DateTime x;
22653 if( isDate(context, argc, argv, &x)==0 ){
22654 char zBuf[100];
22655 computeYMD_HMS(&x);
static void computeYMD_HMS(DateTime *p)
Definition sqlite3.c:22176

References computeYMD_HMS(), DateTime::D, DateTime::h, isDate(), DateTime::M, DateTime::m, DateTime::s, sqlite3_result_text(), sqlite3_snprintf(), SQLITE_TRANSIENT, and DateTime::Y.

Referenced by ctimestampFunc(), and sqlite3RegisterDateTimeFunctions().

◆ dbMallocRawFinish()

static SQLITE_NOINLINE void * dbMallocRawFinish ( sqlite3 * db,
u64 n )
static

Definition at line 27861 of file sqlite3.c.

27866 {
27867 void *p;
27868 assert( db!=0 );
27869 p = sqlite3Malloc(n);

References Lookaside::bDisable, sqlite3::lookaside, MEMTYPE_HEAP, MEMTYPE_LOOKASIDE, sqlite3Malloc(), sqlite3MemdebugSetType, and sqlite3OomFault().

◆ dbReallocFinish()

static SQLITE_NOINLINE void * dbReallocFinish ( sqlite3 * db,
void * p,
u64 n )
static

Definition at line 27972 of file sqlite3.c.

27977 {
27978 void *pNew = 0;
27979 assert( db!=0 );
27980 assert( p!=0 );
27981 if( db->mallocFailed==0 ){
27982 if( isLookaside(db, p) ){
27983 pNew = sqlite3DbMallocRawNN(db, n);
27984 if( pNew ){
27985 memcpy(pNew, p, lookasideMallocSize(db, p));
27986 sqlite3DbFree(db, p);
27987 }
27988 }else{
27992 pNew = sqlite3Realloc(p, n);
27993 if( !pNew ){
27994 sqlite3OomFault(db);
27995 }
#define sqlite3MemdebugSetType(X, Y)
Definition sqlite3.c:20327
#define sqlite3MemdebugHasType(X, Y)
Definition sqlite3.c:20328
static int isLookaside(sqlite3 *db, void *p)
Definition sqlite3.c:27632
#define MEMTYPE_LOOKASIDE
Definition sqlite3.c:20332
#define MEMTYPE_HEAP
Definition sqlite3.c:20331
#define sqlite3MemdebugNoType(X, Y)
Definition sqlite3.c:20329
static int lookasideMallocSize(sqlite3 *db, void *p)
Definition sqlite3.c:27647

◆ decodeFlags()

static int decodeFlags ( MemPage * pPage,
int flagByte )
static

Definition at line 66292 of file sqlite3.c.

66298 {
66299 BtShared *pBt; /* A copy of pPage->pBt */
66300
66301 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
66302 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
66303 pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
66304 flagByte &= ~PTF_LEAF;
66305 pPage->childPtrSize = 4-4*pPage->leaf;
66306 pPage->xCellSize = cellSizePtr;
66307 pBt = pPage->pBt;
66308 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
66309 /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
66310 ** interior table b-tree page. */
66311 assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
66312 /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
66313 ** leaf table b-tree page. */
66314 assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
66315 pPage->intKey = 1;
66316 if( pPage->leaf ){
66317 pPage->intKeyLeaf = 1;
66319 }else{
66320 pPage->intKeyLeaf = 0;
66323 }
66324 pPage->maxLocal = pBt->maxLeaf;
66325 pPage->minLocal = pBt->minLeaf;
66326 }else if( flagByte==PTF_ZERODATA ){
66327 /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
66328 ** interior index b-tree page. */
66329 assert( (PTF_ZERODATA)==2 );
66330 /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
66331 ** leaf index b-tree page. */
66332 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
66333 pPage->intKey = 0;
66334 pPage->intKeyLeaf = 0;
66336 pPage->maxLocal = pBt->maxLocal;
66337 pPage->minLocal = pBt->minLocal;
66338 }else{
66339 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
static void btreeParseCellPtr(MemPage *pPage, u8 *pCell, CellInfo *pInfo)
Definition sqlite3.c:65643
static void btreeParseCellPtrNoPayload(MemPage *pPage, u8 *pCell, CellInfo *pInfo)
Definition sqlite3.c:65626
static u16 cellSizePtr(MemPage *pPage, u8 *pCell)
Definition sqlite3.c:65768
static u16 cellSizePtrNoPayload(MemPage *pPage, u8 *pCell)
Definition sqlite3.c:65816
u16 maxLocal
Definition sqlite3.c:63891
u16 maxLeaf
Definition sqlite3.c:63893
u16 minLeaf
Definition sqlite3.c:63894
u16 minLocal
Definition sqlite3.c:63892

References btreeParseCellPtr(), btreeParseCellPtrIndex(), btreeParseCellPtrNoPayload(), cellSizePtr(), cellSizePtrNoPayload(), MemPage::childPtrSize, MemPage::hdrOffset, MemPage::intKey, MemPage::intKeyLeaf, MemPage::leaf, MemPage::max1bytePayload, BtShared::max1bytePayload, BtShared::maxLeaf, MemPage::maxLocal, BtShared::maxLocal, BtShared::minLeaf, MemPage::minLocal, BtShared::minLocal, BtShared::mutex, MemPage::pBt, MemPage::pgno, PTF_INTKEY, PTF_LEAF, PTF_LEAFDATA, PTF_ZERODATA, sqlite3_mutex_held(), SQLITE_CORRUPT_PAGE, SQLITE_OK, MemPage::xCellSize, and MemPage::xParseCell.

Referenced by btreeInitPage().

◆ decodeIntArray()

static void decodeIntArray ( char * zIntArray,
int nOut,
tRowcnt * aOut,
LogEst * aLog,
Index * pIndex )
static

Definition at line 109018 of file sqlite3.c.

109030 {
109031 char *z = zIntArray;
109032 int c;
109033 int i;
109034 tRowcnt v;
109035
109036#ifdef SQLITE_ENABLE_STAT4
109037 if( z==0 ) z = "";
109038#else
109039 assert( z!=0 );
109040#endif
109041 for(i=0; *z && i<nOut; i++){
109042 v = 0;
109043 while( (c=z[0])>='0' && c<='9' ){
109044 v = v*10 + c - '0';
109045 z++;
109046 }
109047#ifdef SQLITE_ENABLE_STAT4
109048 if( aOut ) aOut[i] = v;
109049 if( aLog ) aLog[i] = sqlite3LogEst(v);
109050#else
109051 assert( aOut==0 );
109052 UNUSED_PARAMETER(aOut);
109053 assert( aLog!=0 );
109054 aLog[i] = sqlite3LogEst(v);
109055#endif
109056 if( *z==' ' ) z++;
109057 }
109058#ifndef SQLITE_ENABLE_STAT4
109059 assert( pIndex!=0 ); {
109060#else
109061 if( pIndex ){
109062#endif
109063 pIndex->bUnordered = 0;
109064 pIndex->noSkipScan = 0;
109065 while( z[0] ){
109066 if( sqlite3_strglob("unordered*", z)==0 ){
109067 pIndex->bUnordered = 1;
109068 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
109069 int sz = sqlite3Atoi(z+3);
109070 if( sz<2 ) sz = 2;
109071 pIndex->szIdxRow = sqlite3LogEst(sz);
109072 }else if( sqlite3_strglob("noskipscan*", z)==0 ){
109073 pIndex->noSkipScan = 1;
109074 }
109075#ifdef SQLITE_ENABLE_COSTMULT
109076 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
109077 pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
109078 }
SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr)
Definition sqlite3.c:117856
SQLITE_PRIVATE int sqlite3Atoi(const char *)
Definition sqlite3.c:32040
unsigned noSkipScan
Definition sqlite3.c:17798

References Index::bUnordered, Index::noSkipScan, Index::pTable, sqlite3_strglob(), sqlite3Atoi(), sqlite3LogEst(), Index::szIdxRow, and UNUSED_PARAMETER.

Referenced by analysisLoader().

◆ defragmentPage()

static int defragmentPage ( MemPage * pPage,
int nMaxFrag )
static

Definition at line 65885 of file sqlite3.c.

65886 : R-44582-60138 SQLite may from time to time reorganize a
65887** b-tree page so that there are no freeblocks or fragment bytes, all
65888** unused bytes are contained in the unallocated space region, and all
65889** cells are packed tightly at the end of the page.
65890*/
65891static int defragmentPage(MemPage *pPage, int nMaxFrag){
65892 int i; /* Loop counter */
65893 int pc; /* Address of the i-th cell */
65894 int hdr; /* Offset to the page header */
65895 int size; /* Size of a cell */
65896 int usableSize; /* Number of usable bytes on a page */
65897 int cellOffset; /* Offset to the cell pointer array */
65898 int cbrk; /* Offset to the cell content area */
65899 int nCell; /* Number of cells on the page */
65900 unsigned char *data; /* The page data */
65901 unsigned char *temp; /* Temp area for cell content */
65902 unsigned char *src; /* Source of content */
65903 int iCellFirst; /* First allowable cell index */
65904 int iCellLast; /* Last possible cell index */
65905
65906 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
65907 assert( pPage->pBt!=0 );
65908 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
65909 assert( pPage->nOverflow==0 );
65910 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65911 temp = 0;
65912 src = data = pPage->aData;
65913 hdr = pPage->hdrOffset;
65914 cellOffset = pPage->cellOffset;
65915 nCell = pPage->nCell;
65916 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
65917 iCellFirst = cellOffset + 2*nCell;
65918 usableSize = pPage->pBt->usableSize;
65919
65920 /* This block handles pages with two or fewer free blocks and nMaxFrag
65921 ** or fewer fragmented bytes. In this case it is faster to move the
65922 ** two (or one) blocks of cells using memmove() and add the required
65923 ** offsets to each pointer in the cell-pointer array than it is to
65924 ** reconstruct the entire page. */
65925 if( (int)data[hdr+7]<=nMaxFrag ){
65926 int iFree = get2byte(&data[hdr+1]);
65927 if( iFree>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
65928 if( iFree ){
65929 int iFree2 = get2byte(&data[iFree]);
65930 if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
65931 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
65932 u8 *pEnd = &data[cellOffset + nCell*2];
65933 u8 *pAddr;
65934 int sz2 = 0;
65935 int sz = get2byte(&data[iFree+2]);
65936 int top = get2byte(&data[hdr+5]);
65937 if( top>=iFree ){
65938 return SQLITE_CORRUPT_PAGE(pPage);
65939 }
65940 if( iFree2 ){
65941 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
65942 sz2 = get2byte(&data[iFree2+2]);
65943 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
65944 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
65945 sz += sz2;
65946 }else if( NEVER(iFree+sz>usableSize) ){
65947 return SQLITE_CORRUPT_PAGE(pPage);
65948 }
65949
65950 cbrk = top+sz;
65951 assert( cbrk+(iFree-top) <= usableSize );
65952 memmove(&data[cbrk], &data[top], iFree-top);
65953 for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
65954 pc = get2byte(pAddr);
65955 if( pc<iFree ){ put2byte(pAddr, pc+sz); }
65956 else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); }
65957 }
65958 goto defragment_out;
65959 }
65960 }
65961 }
65962
65963 cbrk = usableSize;
65964 iCellLast = usableSize - 4;
65965 for(i=0; i<nCell; i++){
65966 u8 *pAddr; /* The i-th cell pointer */
65967 pAddr = &data[cellOffset + i*2];
65968 pc = get2byte(pAddr);
65969 testcase( pc==iCellFirst );
65970 testcase( pc==iCellLast );
65971 /* These conditions have already been verified in btreeInitPage()
65972 ** if PRAGMA cell_size_check=ON.
65973 */
65974 if( pc<iCellFirst || pc>iCellLast ){
65975 return SQLITE_CORRUPT_PAGE(pPage);
65976 }
65977 assert( pc>=iCellFirst && pc<=iCellLast );
65978 size = pPage->xCellSize(pPage, &src[pc]);
65979 cbrk -= size;
65980 if( cbrk<iCellFirst || pc+size>usableSize ){
65981 return SQLITE_CORRUPT_PAGE(pPage);
65982 }
65983 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
65984 testcase( cbrk+size==usableSize );
65985 testcase( pc+size==usableSize );
65986 put2byte(pAddr, cbrk);
65987 if( temp==0 ){
65988 int x;
65989 if( cbrk==pc ) continue;
65990 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
65991 x = get2byte(&data[hdr+5]);
65992 memcpy(&temp[x], &data[x], (cbrk+size) - x);
65993 src = temp;
65994 }
65995 memcpy(&data[cbrk], &src[pc], size);
65996 }
65997 data[hdr+7] = 0;
65998
65999 defragment_out:
66000 assert( pPage->nFree>=0 );
66001 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
66002 return SQLITE_CORRUPT_PAGE(pPage);
66003 }
66004 assert( cbrk>=iCellFirst );
66005 put2byte(&data[hdr+5], cbrk);
union @139 unused
#define SQLITE_MAX_PAGE_SIZE
Definition sqlite3.c:13393
#define put2byte(p, v)
Definition sqlite3.c:64164
SQLITE_PRIVATE void * sqlite3PagerTempSpace(Pager *)
Definition sqlite3.c:55453

References MemPage::aData, MemPage::cellOffset, CORRUPT_DB, get2byte, MemPage::hdrOffset, BtShared::mutex, MemPage::nCell, NEVER, MemPage::nFree, MemPage::nOverflow, MemPage::pBt, MemPage::pDbPage, BtShared::pPager, put2byte, sqlite3_mutex_held(), sqlite3PagerTempSpace(), SQLITE_CORRUPT_PAGE, SQLITE_MAX_PAGE_SIZE, SQLITE_OK, testcase, BtShared::usableSize, and MemPage::xCellSize.

Referenced by allocateSpace(), and balance_nonroot().

◆ deleteTable()

static void SQLITE_NOINLINE deleteTable ( sqlite3 * db,
Table * pTable )
static

Definition at line 111051 of file sqlite3.c.

111057 {
111058 Index *pIndex, *pNext;
111059
111060#ifdef SQLITE_DEBUG
111061 /* Record the number of outstanding lookaside allocations in schema Tables
111062 ** prior to doing any free() operations. Since schema Tables do not use
111063 ** lookaside, this number should not change.
111064 **
111065 ** If malloc has already failed, it may be that it failed while allocating
111066 ** a Table object that was going to be marked ephemeral. So do not check
111067 ** that no lookaside memory is used in this case either. */
111068 int nLookaside = 0;
111069 if( db && !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
111070 nLookaside = sqlite3LookasideUsed(db, 0);
111071 }
111072#endif
111073
111074 /* Delete all indices associated with this table. */
111075 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
111076 pNext = pIndex->pNext;
111077 assert( pIndex->pSchema==pTable->pSchema
111078 || (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
111079 if( (db==0 || db->pnBytesFreed==0) && !IsVirtual(pTable) ){
111080 char *zName = pIndex->zName;
111081 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
111082 &pIndex->pSchema->idxHash, zName, 0
111083 );
111084 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
111085 assert( pOld==pIndex || pOld==0 );
111086 }
111087 sqlite3FreeIndex(db, pIndex);
111088 }
111089
111090 /* Delete any foreign keys attached to this table. */
111091 sqlite3FkDelete(db, pTable);
111092
111093 /* Delete the Table structure itself.
111094 */
111095 sqlite3DeleteColumnNames(db, pTable);
111096 sqlite3DbFree(db, pTable->zName);
111097 sqlite3DbFree(db, pTable->zColAff);
111098 sqlite3SelectDelete(db, pTable->pSelect);
111099 sqlite3ExprListDelete(db, pTable->pCheck);
111100#ifndef SQLITE_OMIT_VIRTUALTABLE
111101 sqlite3VtabClear(db, pTable);
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *)
Definition sqlite3.c:139908
SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *, int *)
Definition sqlite3.c:21501
#define TESTONLY(X)
Definition sqlite3.c:13697
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table *)
Definition sqlite3.c:120507
#define TF_Ephemeral
Definition sqlite3.c:17536
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *, Table *)
Definition sqlite3.c:111021
SQLITE_PRIVATE void sqlite3FreeIndex(sqlite3 *, Index *)
Definition sqlite3.c:110885
SQLITE_PRIVATE void * sqlite3HashInsert(Hash *, const char *pKey, void *pData)
Definition sqlite3.c:33114
#define SQLITE_IDXTYPE_APPDEF
Definition sqlite3.c:17817
unsigned idxType
Definition sqlite3.c:17793
int * pnBytesFreed
Definition sqlite3.c:16934

References Schema::idxHash, Index::idxType, IsVirtual, sqlite3::mallocFailed, Table::pCheck, Table::pIndex, sqlite3::pnBytesFreed, Index::pNext, Table::pSchema, Index::pSchema, Table::pSelect, sqlite3DbFree(), sqlite3DeleteColumnNames(), sqlite3ExprListDelete(), sqlite3FkDelete(), sqlite3FreeIndex(), sqlite3HashInsert(), sqlite3LookasideUsed(), sqlite3SelectDelete(), sqlite3VtabClear(), SQLITE_IDXTYPE_APPDEF, Table::tabFlags, TESTONLY, TF_Ephemeral, Table::zColAff, Table::zName, Index::zName, and zName.

◆ dense_rankStepFunc()

static void dense_rankStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151337 of file sqlite3.c.

151347 {

◆ dense_rankValueFunc()

static void dense_rankValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151348 of file sqlite3.c.

151354 {
151355 struct CallCount *p;
151356 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151357 if( p ){
151358 if( p->nStep ){

◆ destroyRootPage()

static void destroyRootPage ( Parse * pParse,
int iTable,
int iDb )
static

Definition at line 113228 of file sqlite3.c.

113234 {
113235 Vdbe *v = sqlite3GetVdbe(pParse);
113236 int r1 = sqlite3GetTempReg(pParse);
113237 if( iTable<2 ) sqlite3ErrorMsg(pParse, "corrupt schema");
113238 sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
113239 sqlite3MayAbort(pParse);
113240#ifndef SQLITE_OMIT_AUTOVACUUM
113241 /* OP_Destroy stores an in integer r1. If this integer
113242 ** is non-zero, then it is the root page number of a table moved to
113243 ** location iTable. The following code modifies the sqlite_schema table to
113244 ** reflect this.
113245 **
113246 ** The "#NNN" in the SQL is a special constant that means whatever value
113247 ** is in register NNN. See grammar rules associated with the TK_REGISTER
113248 ** token for additional information.
113249 */
113250 sqlite3NestedParse(pParse,
SQLITE_PRIVATE void sqlite3MayAbort(Parse *)
Definition sqlite3.c:115204
#define OP_Destroy
Definition sqlite3.c:15702
SQLITE_PRIVATE void sqlite3NestedParse(Parse *, const char *,...)
Definition sqlite3.c:110647

References sqlite3::aDb, Parse::db, DFLT_SCHEMA_TABLE, OP_Destroy, sqlite3ErrorMsg(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3MayAbort(), sqlite3NestedParse(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp3(), and Db::zDbSName.

Referenced by destroyTable().

◆ destroyTable()

static void destroyTable ( Parse * pParse,
Table * pTab )
static

Definition at line 113258 of file sqlite3.c.

113264 {
113265 /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
113266 ** is not defined), then it is important to call OP_Destroy on the
113267 ** table and index root-pages in order, starting with the numerically
113268 ** largest root-page number. This guarantees that none of the root-pages
113269 ** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
113270 ** following were coded:
113271 **
113272 ** OP_Destroy 4 0
113273 ** ...
113274 ** OP_Destroy 5 0
113275 **
113276 ** and root page 5 happened to be the largest root-page number in the
113277 ** database, then root page 5 would be moved to page 4 by the
113278 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
113279 ** a free-list page.
113280 */
113281 Pgno iTab = pTab->tnum;
113282 Pgno iDestroyed = 0;
113283
113284 while( 1 ){
113285 Index *pIdx;
113286 Pgno iLargest = 0;
113287
113288 if( iDestroyed==0 || iTab<iDestroyed ){
113289 iLargest = iTab;
113290 }
113291 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113292 Pgno iIdx = pIdx->tnum;
113293 assert( pIdx->pSchema==pTab->pSchema );
113294 if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
113295 iLargest = iIdx;
113296 }
113297 }
113298 if( iLargest==0 ){
113299 return;
113300 }else{
113301 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);

References Parse::db, destroyRootPage(), sqlite3::nDb, Table::pIndex, Index::pNext, Table::pSchema, Index::pSchema, sqlite3SchemaToIndex(), Table::tnum, and Index::tnum.

◆ detachFunc()

static void detachFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 109755 of file sqlite3.c.

109755 :
109756**
109757** DETACH DATABASE x
109758**
109759** SELECT sqlite_detach(x)
109760*/
109761static void detachFunc(
109762 sqlite3_context *context,
109763 int NotUsed,
109764 sqlite3_value **argv
109765){
109766 const char *zName = (const char *)sqlite3_value_text(argv[0]);
109767 sqlite3 *db = sqlite3_context_db_handle(context);
109768 int i;
109769 Db *pDb = 0;
109770 HashElem *pEntry;
109771 char zErr[128];
109772
109773 UNUSED_PARAMETER(NotUsed);
109774
109775 if( zName==0 ) zName = "";
109776 for(i=0; i<db->nDb; i++){
109777 pDb = &db->aDb[i];
109778 if( pDb->pBt==0 ) continue;
109779 if( sqlite3DbIsNamed(db, i, zName) ) break;
109780 }
109781
109782 if( i>=db->nDb ){
109783 sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
109784 goto detach_error;
109785 }
109786 if( i<2 ){
109787 sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
109788 goto detach_error;
109789 }
109791 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
109792 goto detach_error;
109793 }
109794
109795 /* If any TEMP triggers reference the schema being detached, move those
109796 ** triggers to reference the TEMP schema itself. */
109797 assert( db->aDb[1].pSchema );
109798 pEntry = sqliteHashFirst(&db->aDb[1].pSchema->trigHash);
109799 while( pEntry ){
109800 Trigger *pTrig = (Trigger*)sqliteHashData(pEntry);
109801 if( pTrig->pTabSchema==pDb->pSchema ){
109802 pTrig->pTabSchema = pTrig->pSchema;
109803 }
109804 pEntry = sqliteHashNext(pEntry);
109805 }
109806
109807 sqlite3BtreeClose(pDb->pBt);
109808 pDb->pBt = 0;
109809 pDb->pSchema = 0;
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *)
Definition sqlite3.c:74825
#define sqliteHashNext(E)
Definition sqlite3.c:13927
static void detachFunc(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:109755
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree *)
Definition sqlite3.c:74831
#define sqliteHashFirst(H)
Definition sqlite3.c:13926
#define sqliteHashData(E)
Definition sqlite3.c:13928
Hash trigHash
Definition sqlite3.c:16635
Schema * pSchema
Definition sqlite3.c:18879
Schema * pTabSchema
Definition sqlite3.c:18880

References sqlite3::aDb, sqlite3::nDb, Db::pBt, Db::pSchema, Trigger::pSchema, Trigger::pTabSchema, sqlite3_context_db_handle(), sqlite3_result_error(), sqlite3_snprintf(), sqlite3_value_text(), sqlite3BtreeClose(), sqlite3BtreeIsInBackup(), sqlite3BtreeIsInReadTrans(), sqlite3CollapseDatabaseArray(), sqlite3DbIsNamed(), sqliteHashData, sqliteHashFirst, sqliteHashNext, Schema::trigHash, UNUSED_PARAMETER, and zName.

Referenced by sqlite3Detach().

◆ disableLookaside()

static void disableLookaside ( Parse * pParse)
static

Definition at line 154288 of file sqlite3.c.

154288 { int eType; Expr *pExpr; };
154289
154290/*
154291** Disable lookaside memory allocation for objects that might be
154292** shared across database connections.

References FrameBound::eType, and FrameBound::pExpr.

Referenced by yy_reduce().

◆ disableTerm()

static void disableTerm ( WhereLevel * pLevel,
WhereTerm * pTerm )
static

Definition at line 141812 of file sqlite3.c.

141818 {
141819 int nLoop = 0;
141820 assert( pTerm!=0 );
141821 while( (pTerm->wtFlags & TERM_CODED)==0
141822 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
141823 && (pLevel->notReady & pTerm->prereqAll)==0
141824 ){
141825 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
141826 pTerm->wtFlags |= TERM_LIKECOND;
141827 }else{
141828 pTerm->wtFlags |= TERM_CODED;
141829 }
141830 if( pTerm->iParent<0 ) break;
141831 pTerm = &pTerm->pWC->a[pTerm->iParent];
#define TERM_LIKECOND
Definition sqlite3.c:141204
#define TERM_LIKE
Definition sqlite3.c:141205
Bitmask notReady
Definition sqlite3.c:141011
WhereClause * pWC
Definition sqlite3.c:141170
Bitmask prereqAll
Definition sqlite3.c:141185

References WhereClause::a, EP_FromJoin, ExprHasProperty, WhereLevel::iLeftJoin, WhereTerm::iParent, WhereTerm::nChild, WhereLevel::notReady, WhereTerm::pExpr, WhereTerm::prereqAll, WhereTerm::pWC, TERM_CODED, TERM_LIKE, TERM_LIKECOND, and WhereTerm::wtFlags.

Referenced by codeEqualityTerm().

◆ disconnectAllVtab()

static void disconnectAllVtab ( sqlite3 * db)
static

Definition at line 162142 of file sqlite3.c.

162148 {
162149#ifndef SQLITE_OMIT_VIRTUALTABLE
162150 int i;
162151 HashElem *p;
162153 for(i=0; i<db->nDb; i++){
162154 Schema *pSchema = db->aDb[i].pSchema;
162155 if( pSchema ){
162156 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
162157 Table *pTab = (Table *)sqliteHashData(p);
162158 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
162159 }
162160 }
162161 }
162162 for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
162163 Module *pMod = (Module *)sqliteHashData(p);
162164 if( pMod->pEpoTab ){
162165 sqlite3VtabDisconnect(db, pMod->pEpoTab);
162166 }
162167 }
SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p)
Definition sqlite3.c:139839
Table * pEpoTab
Definition sqlite3.c:17311
Hash tblHash
Definition sqlite3.c:16633
Hash aModule
Definition sqlite3.c:16918

◆ dotlockCheckReservedLock()

static int dotlockCheckReservedLock ( sqlite3_file * id,
int * pResOut )
static

Definition at line 35776 of file sqlite3.c.

35782 {
35783 int rc = SQLITE_OK;
35784 int reserved = 0;
35785 unixFile *pFile = (unixFile*)id;
35786
35788
#define SimulateIOError(A)
Definition sqlite3.c:33824
#define SQLITE_IOERR_CHECKRESERVEDLOCK
Definition sqlite3.c:1536

References unixFile::h, unixFile::lockingContext, osAccess, OSTRACE, SimulateIOError, SQLITE_IOERR_CHECKRESERVEDLOCK, and SQLITE_OK.

◆ dotlockClose()

static int dotlockClose ( sqlite3_file * id)
static

Definition at line 35910 of file sqlite3.c.

35916 {

◆ dotlockLock()

static int dotlockLock ( sqlite3_file * id,
int eFileLock )
static

Definition at line 35817 of file sqlite3.c.

35820 : EXCLUSIVE.
35821** But we track the other locking levels internally.
35822*/
35823static int dotlockLock(sqlite3_file *id, int eFileLock) {
35824 unixFile *pFile = (unixFile*)id;
35825 char *zLockFile = (char *)pFile->lockingContext;
35826 int rc = SQLITE_OK;
35827
35828
35829 /* If we have any lock, then the lock file already exists. All we have
35830 ** to do is adjust our internal record of the lock level.
35831 */
35832 if( pFile->eFileLock > NO_LOCK ){
35833 pFile->eFileLock = eFileLock;
35834 /* Always update the timestamp on the old file */
35835#ifdef HAVE_UTIME
35836 utime(zLockFile, NULL);
35837#else
35838 utimes(zLockFile, NULL);
35839#endif
35840 return SQLITE_OK;
35841 }
35842
35843 /* grab an exclusive lock */
35844 rc = osMkdir(zLockFile, 0777);
35845 if( rc<0 ){
35846 /* failed to open/create the lock directory */
35847 int tErrno = errno;
35848 if( EEXIST == tErrno ){
35849 rc = SQLITE_BUSY;
35850 } else {
35852 if( rc!=SQLITE_BUSY ){
35853 storeLastErrno(pFile, tErrno);
35854 }
35855 }
35856 return rc;
#define NULL
Definition gmacros.h:924
#define SQLITE_IOERR_LOCK
Definition sqlite3.c:1537
static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr)
Definition sqlite3.c:34404
#define NO_LOCK
Definition sqlite3.c:16359
static void storeLastErrno(unixFile *pFile, int error)
Definition sqlite3.c:34839
static int dotlockLock(sqlite3_file *id, int eFileLock)
Definition sqlite3.c:35817
#define osMkdir
void * lockingContext
Definition sqlite3.c:33570

References unixFile::eFileLock, unixFile::lockingContext, NO_LOCK, NULL, osMkdir, SQLITE_BUSY, SQLITE_IOERR_LOCK, SQLITE_OK, sqliteErrorFromPosixError(), and storeLastErrno().

◆ dotlockUnlock()

static int dotlockUnlock ( sqlite3_file * id,
int eFileLock )
static

Definition at line 35867 of file sqlite3.c.

35873 {
35874 unixFile *pFile = (unixFile*)id;
35875 char *zLockFile = (char *)pFile->lockingContext;
35876 int rc;
35877
35878 assert( pFile );
35879 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
35880 pFile->eFileLock, osGetpid(0)));
35881 assert( eFileLock<=SHARED_LOCK );
35882
35883 /* no-op if possible */
35884 if( pFile->eFileLock==eFileLock ){
35885 return SQLITE_OK;
35886 }
35887
35888 /* To downgrade to shared, simply update our internal notion of the
35889 ** lock state. No need to mess with the file on disk.
35890 */
35891 if( eFileLock==SHARED_LOCK ){
35892 pFile->eFileLock = SHARED_LOCK;
35893 return SQLITE_OK;
35894 }
35895
35896 /* To fully unlock the database, delete the lock file */
35897 assert( eFileLock==NO_LOCK );
35898 rc = osRmdir(zLockFile);
35899 if( rc<0 ){
35900 int tErrno = errno;
35901 if( tErrno==ENOENT ){
35902 rc = SQLITE_OK;
35903 }else{
35905 storeLastErrno(pFile, tErrno);
#define osRmdir
#define SQLITE_IOERR_UNLOCK
Definition sqlite3.c:1530
#define OSTRACE(X)
Definition sqlite3.c:13799
#define SHARED_LOCK
Definition sqlite3.c:16360
#define osGetpid(X)
Definition sqlite3.c:33531

References unixFile::eFileLock, unixFile::h, unixFile::lockingContext, NO_LOCK, osGetpid, osRmdir, OSTRACE, SHARED_LOCK, SQLITE_IOERR_UNLOCK, SQLITE_OK, and storeLastErrno().

◆ doubleToInt64()

static SQLITE_NOINLINE i64 doubleToInt64 ( double r)
static

Definition at line 76375 of file sqlite3.c.

76381 {
76382#ifdef SQLITE_OMIT_FLOATING_POINT
76383 /* When floating-point is omitted, double and int64 are the same thing */
76384 return r;
76385#else
76386 /*
76387 ** Many compilers we encounter do not define constants for the
76388 ** minimum and maximum 64-bit integers, or they define them
76389 ** inconsistently. And many do not understand the "LL" notation.
76390 ** So we define our own static constants here using nothing
76391 ** larger than a 32-bit integer constant.
76392 */
76393 static const i64 maxInt = LARGEST_INT64;
76394 static const i64 minInt = SMALLEST_INT64;
76395
76396 if( r<=(double)minInt ){
76397 return minInt;
76398 }else if( r>=(double)maxInt ){
#define LARGEST_INT64
Definition sqlite3.c:14464

References LARGEST_INT64, and SMALLEST_INT64.

◆ doWalCallbacks()

static int doWalCallbacks ( sqlite3 * db)
static

Definition at line 83566 of file sqlite3.c.

83572 {
83573 int rc = SQLITE_OK;
83574#ifndef SQLITE_OMIT_WAL
83575 int i;
83576 for(i=0; i<db->nDb; i++){
83577 Btree *pBt = db->aDb[i].pBt;
83578 if( pBt ){
83579 int nEntry;
83580 sqlite3BtreeEnter(pBt);
83582 sqlite3BtreeLeave(pBt);
83583 if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){
83584 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager)
Definition sqlite3.c:59115
int(* xWalCallback)(void *, sqlite3 *, const char *, int)
Definition sqlite3.c:16895
void * pWalArg
Definition sqlite3.c:16896

References sqlite3::aDb, sqlite3::nDb, Db::pBt, sqlite3::pWalArg, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3BtreePager(), sqlite3PagerWalCallback(), SQLITE_OK, sqlite3::xWalCallback, and Db::zDbSName.

Referenced by sqlite3Step().

◆ downgradeAllSharedCacheTableLocks()

static void downgradeAllSharedCacheTableLocks ( Btree * p)
static

Definition at line 64934 of file sqlite3.c.

64940 {
64941 BtShared *pBt = p->pBt;
64942 if( pBt->pWriter==p ){
64943 BtLock *pLock;
64944 pBt->pWriter = 0;

◆ dropCell()

static void dropCell ( MemPage * pPage,
int idx,
int sz,
int * pRC )
static

Definition at line 71128 of file sqlite3.c.

71134 {
71135 u32 pc; /* Offset to cell content of cell being deleted */
71136 u8 *data; /* pPage->aData */
71137 u8 *ptr; /* Used to move bytes around within data[] */
71138 int rc; /* The return code */
71139 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
71140
71141 if( *pRC ) return;
71142 assert( idx>=0 && idx<pPage->nCell );
71143 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
71144 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
71145 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
71146 assert( pPage->nFree>=0 );
71147 data = pPage->aData;
71148 ptr = &pPage->aCellIdx[2*idx];
71149 pc = get2byte(ptr);
71150 hdr = pPage->hdrOffset;
71151 testcase( pc==get2byte(&data[hdr+5]) );
71152 testcase( pc+sz==pPage->pBt->usableSize );
71153 if( pc+sz > pPage->pBt->usableSize ){
71154 *pRC = SQLITE_CORRUPT_BKPT;
71155 return;
71156 }
71157 rc = freeSpace(pPage, pc, sz);
71158 if( rc ){
71159 *pRC = rc;
71160 return;
71161 }
71162 pPage->nCell--;
71163 if( pPage->nCell==0 ){
71164 memset(&data[hdr+1], 0, 4);
71165 data[hdr+7] = 0;
71166 put2byte(&data[hdr+5], pPage->pBt->usableSize);
71167 pPage->nFree = pPage->pBt->usableSize - pPage->hdrOffset
71168 - pPage->childPtrSize - 8;
static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize)
Definition sqlite3.c:66185

References MemPage::aCellIdx, MemPage::aData, MemPage::childPtrSize, CORRUPT_DB, freeSpace(), get2byte, MemPage::hdrOffset, BtShared::mutex, MemPage::nCell, MemPage::nFree, MemPage::pBt, MemPage::pDbPage, put2byte, sqlite3_mutex_held(), SQLITE_CORRUPT_BKPT, testcase, and BtShared::usableSize.

Referenced by balance_nonroot(), sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ dupedExprNodeSize()

static int dupedExprNodeSize ( Expr * p,
int flags )
static

Definition at line 100941 of file sqlite3.c.

100947 {

References dupedExprStructSize(), EP_IntValue, ExprHasProperty, ROUND8, sqlite3Strlen30NN, Expr::u, and Expr::zToken.

Referenced by dupedExprSize(), and exprDup().

◆ dupedExprSize()

static int dupedExprSize ( Expr * p,
int flags )
static

Definition at line 100962 of file sqlite3.c.

100968 {
100969 int nByte = 0;
100970 if( p ){
100971 nByte = dupedExprNodeSize(p, flags);
static int dupedExprNodeSize(Expr *p, int flags)
Definition sqlite3.c:100941

References dupedExprNodeSize(), dupedExprSize(), EXPRDUP_REDUCE, Expr::pLeft, and Expr::pRight.

Referenced by dupedExprSize(), and exprDup().

◆ dupedExprStructSize()

static int dupedExprStructSize ( Expr * p,
int flags )
static

Definition at line 100910 of file sqlite3.c.

100916 {
100917 int nSize;
100918 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
100919 assert( EXPR_FULLSIZE<=0xfff );
100920 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
100921 if( 0==flags || p->op==TK_SELECT_COLUMN
100922#ifndef SQLITE_OMIT_WINDOWFUNC
100924#endif
100925 ){
100926 nSize = EXPR_FULLSIZE;
100927 }else{
100928 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
100929 assert( !ExprHasProperty(p, EP_FromJoin) );
100930 assert( !ExprHasProperty(p, EP_MemToken) );
100931 assert( !ExprHasVVAProperty(p, EP_NoReduce) );
100932 if( p->pLeft || p->x.pList ){
100933 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
100934 }else{
#define EP_MemToken
Definition sqlite3.c:18076
#define EXPR_FULLSIZE
Definition sqlite3.c:18135
#define EXPRDUP_REDUCE
Definition sqlite3.c:18143
#define TK_SELECT_COLUMN
Definition sqlite3.c:14117
#define EXPR_REDUCEDSIZE
Definition sqlite3.c:18136

References EP_FromJoin, EP_MemToken, EP_NoReduce, EP_Reduced, EP_TokenOnly, EP_WinFunc, EXPR_FULLSIZE, EXPR_REDUCEDSIZE, EXPR_TOKENONLYSIZE, EXPRDUP_REDUCE, ExprHasProperty, ExprHasVVAProperty, Expr::op, Expr::pLeft, Expr::pList, Expr::pRight, TK_SELECT_COLUMN, and Expr::x.

Referenced by dupedExprNodeSize(), and exprDup().

◆ editPage()

static int editPage ( MemPage * pPg,
int iOld,
int iNew,
int nNew,
CellArray * pCArray )
static

Definition at line 71629 of file sqlite3.c.

71641 {
71642 u8 * const aData = pPg->aData;
71643 const int hdr = pPg->hdrOffset;
71644 u8 *pBegin = &pPg->aCellIdx[nNew * 2];
71645 int nCell = pPg->nCell; /* Cells stored on pPg */
71646 u8 *pData;
71647 u8 *pCellptr;
71648 int i;
71649 int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
71650 int iNewEnd = iNew + nNew;
71651
71652#ifdef SQLITE_DEBUG
71653 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
71654 memcpy(pTmp, aData, pPg->pBt->usableSize);
71655#endif
71656
71657 /* Remove cells from the start and end of the page */
71658 assert( nCell>=0 );
71659 if( iOld<iNew ){
71660 int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
71661 if( NEVER(nShift>nCell) ) return SQLITE_CORRUPT_BKPT;
71662 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
71663 nCell -= nShift;
71664 }
71665 if( iNewEnd < iOldEnd ){
71666 int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
71667 assert( nCell>=nTail );
71668 nCell -= nTail;
71669 }
71670
71671 pData = &aData[get2byteNotZero(&aData[hdr+5])];
71672 if( pData<pBegin ) goto editpage_fail;
71673
71674 /* Add cells to the start of the page */
71675 if( iNew<iOld ){
71676 int nAdd = MIN(nNew,iOld-iNew);
71677 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
71678 assert( nAdd>=0 );
71679 pCellptr = pPg->aCellIdx;
71680 memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
71681 if( pageInsertArray(
71682 pPg, pBegin, &pData, pCellptr,
71683 iNew, nAdd, pCArray
71684 ) ) goto editpage_fail;
71685 nCell += nAdd;
71686 }
71687
71688 /* Add any overflow cells */
71689 for(i=0; i<pPg->nOverflow; i++){
71690 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
71691 if( iCell>=0 && iCell<nNew ){
71692 pCellptr = &pPg->aCellIdx[iCell * 2];
71693 if( nCell>iCell ){
71694 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
71695 }
71696 nCell++;
71697 cachedCellSize(pCArray, iCell+iNew);
71698 if( pageInsertArray(
71699 pPg, pBegin, &pData, pCellptr,
71700 iCell+iNew, 1, pCArray
71701 ) ) goto editpage_fail;
71702 }
71703 }
71704
71705 /* Append cells to the end of the page */
71706 assert( nCell>=0 );
71707 pCellptr = &pPg->aCellIdx[nCell*2];
71708 if( pageInsertArray(
71709 pPg, pBegin, &pData, pCellptr,
71710 iNew+nCell, nNew-nCell, pCArray
71711 ) ) goto editpage_fail;
71712
71713 pPg->nCell = nNew;
71714 pPg->nOverflow = 0;
71715
71716 put2byte(&aData[hdr+3], pPg->nCell);
71717 put2byte(&aData[hdr+5], pData - aData);
71718
71719#ifdef SQLITE_DEBUG
71720 for(i=0; i<nNew && !CORRUPT_DB; i++){
71721 u8 *pCell = pCArray->apCell[i+iNew];
71722 int iOff = get2byteAligned(&pPg->aCellIdx[i*2]);
71723 if( SQLITE_WITHIN(pCell, aData, &aData[pPg->pBt->usableSize]) ){
71724 pCell = &pTmp[pCell - aData];
71725 }
71726 assert( 0==memcmp(pCell, &aData[iOff],
71727 pCArray->pRef->xCellSize(pCArray->pRef, pCArray->apCell[i+iNew])) );
71728 }
71729#endif
71730
static int pageFreeArray(MemPage *pPg, int iFirst, int nCell, CellArray *pCArray)
Definition sqlite3.c:71572
static int pageInsertArray(MemPage *pPg, u8 *pBegin, u8 **ppData, u8 *pCellptr, int iFirst, int nCell, CellArray *pCArray)
Definition sqlite3.c:71507

References MemPage::aCellIdx, MemPage::aData, MemPage::aiOvfl, CellArray::apCell, cachedCellSize(), CORRUPT_DB, get2byteAligned, get2byteNotZero, MemPage::hdrOffset, MIN, MemPage::nCell, NEVER, MemPage::nOverflow, pageFreeArray(), pageInsertArray(), MemPage::pBt, populateCellCache(), BtShared::pPager, CellArray::pRef, put2byte, rebuildPage(), sqlite3PagerTempSpace(), SQLITE_CORRUPT_BKPT, SQLITE_OK, SQLITE_WITHIN, BtShared::usableSize, and MemPage::xCellSize.

Referenced by balance_nonroot().

◆ enlargeAndAppend()

static void SQLITE_NOINLINE enlargeAndAppend ( StrAccum * p,
const char * z,
int N )
static

Definition at line 29111 of file sqlite3.c.

29117 {

References sqlite3_str::nChar, sqlite3StrAccumEnlarge(), and sqlite3_str::zText.

◆ errlogFunc()

static void errlogFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

◆ estimateIndexWidth()

static void estimateIndexWidth ( Index * pIdx)
static

Definition at line 112307 of file sqlite3.c.

112313 {
112314 unsigned wIndex = 0;
112315 int i;
112316 const Column *aCol = pIdx->pTable->aCol;
112317 for(i=0; i<pIdx->nColumn; i++){

Referenced by sqlite3CreateIndex(), and sqlite3EndTable().

◆ estimateTableWidth()

static void estimateTableWidth ( Table * pTab)
static

Definition at line 112293 of file sqlite3.c.

112299 {
112300 unsigned wTable = 0;
112301 const Column *pTabCol;
112302 int i;

Referenced by sqlite3EndTable().

◆ estLog()

static LogEst estLog ( LogEst N)
static

Definition at line 146171 of file sqlite3.c.

Referenced by whereLoopAddBtree(), whereLoopAddBtreeIndex(), and whereSortingCost().

◆ et_getdigit()

static char et_getdigit ( LONGDOUBLE_TYPE * val,
int * cnt )
static

Definition at line 28260 of file sqlite3.c.

28260 : *val = 1.4159 function return = '3'
28261**
28262** The counter *cnt is incremented each time. After counter exceeds
28263** 16 (the number of significant digits in a 64-bit float) '0' is
28264** always returned.
28265*/
28266static char et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
28267 int digit;
28269 if( (*cnt)<=0 ) return '0';
28270 (*cnt)--;
static int digit(int c)
static char et_getdigit(LONGDOUBLE_TYPE *val, int *cnt)
Definition sqlite3.c:28260
#define LONGDOUBLE_TYPE
Definition sqlite3.c:14327

References digit(), and LONGDOUBLE_TYPE.

Referenced by sqlite3_str_vappendf().

◆ execSql()

static int execSql ( sqlite3 * db,
char ** pzErrMsg,
const char * zSql )
static

Definition at line 139196 of file sqlite3.c.

139202 {
139203 sqlite3_stmt *pStmt;
139204 int rc;
139205
139206 /* printf("SQL: [%s]\n", zSql); fflush(stdout); */
139207 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
139208 if( rc!=SQLITE_OK ) return rc;
139209 while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
139210 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
139211 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
139212 /* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
139213 ** or INSERT. Historically there have been attacks that first
139214 ** corrupt the sqlite_schema.sql field with other kinds of statements
139215 ** then run VACUUM to get those statements to execute at inappropriate
139216 ** times. */
139217 if( zSubSql
139218 && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
139219 ){
139220 rc = execSql(db, pzErrMsg, zSubSql);
139221 if( rc!=SQLITE_OK ) break;
139222 }
139223 }
139224 assert( rc!=SQLITE_ROW );
139225 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql)
Definition sqlite3.c:139196
SQLITE_API int sqlite3_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail)
Definition sqlite3.c:129146
SQLITE_API const unsigned char * sqlite3_column_text(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84126
struct sqlite3_stmt sqlite3_stmt
Definition sqlite3.c:4844

References execSql(), sqlite3_column_text(), sqlite3_prepare_v2(), sqlite3_step(), sqlite3_strnicmp(), SQLITE_DONE, SQLITE_OK, and SQLITE_ROW.

Referenced by execSql().

◆ execSqlF()

static int execSqlF ( sqlite3 * db,
char ** pzErrMsg,
const char * zSql,
... )
static

Definition at line 139226 of file sqlite3.c.

139226 {
139227 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
139228 }
139229 (void)sqlite3_finalize(pStmt);
139230 return rc;
139231}
139232static int execSqlF(sqlite3 *db, char **pzErrMsg, const char *zSql, ...){
139233 char *z;
139234 va_list ap;
139235 int rc;
139236 va_start(ap, zSql);
139237 z = sqlite3VMPrintf(db, zSql, ap);
SQLITE_PRIVATE char * sqlite3VMPrintf(sqlite3 *, const char *, va_list)
Definition sqlite3.c:29266
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3 *, const char *)
Definition sqlite3.c:28060
static int execSqlF(sqlite3 *db, char **pzErrMsg, const char *zSql,...)
Definition sqlite3.c:139226

References sqlite3_errmsg(), and sqlite3SetString().

◆ explainAppendTerm()

static void explainAppendTerm ( StrAccum * pStr,
Index * pIdx,
int nTerm,
int iTerm,
int bAnd,
const char * zOp )
static

Definition at line 141559 of file sqlite3.c.

141572 {
141573 int i;
141574
141575 assert( nTerm>=1 );
141576 if( bAnd ) sqlite3_str_append(pStr, " AND ", 5);
141577
141578 if( nTerm>1 ) sqlite3_str_append(pStr, "(", 1);
141579 for(i=0; i<nTerm; i++){
141580 if( i ) sqlite3_str_append(pStr, ",", 1);
141581 sqlite3_str_appendall(pStr, explainIndexColumnName(pIdx, iTerm+i));
141582 }
141583 if( nTerm>1 ) sqlite3_str_append(pStr, ")", 1);
141584
141585 sqlite3_str_append(pStr, zOp, 1);
141586
141587 if( nTerm>1 ) sqlite3_str_append(pStr, "(", 1);
SQLITE_API void sqlite3_str_appendall(sqlite3_str *, const char *zIn)
Definition sqlite3.c:29140

References explainIndexColumnName(), sqlite3_str_append(), and sqlite3_str_appendall().

Referenced by explainIndexRange().

◆ explainIndexColumnName()

static const char * explainIndexColumnName ( Index * pIdx,
int i )
static

◆ explainIndexRange()

static void explainIndexRange ( StrAccum * pStr,
WhereLoop * pLoop )
static

Definition at line 141603 of file sqlite3.c.

141605 :
141606**
141607** "a=? AND b>?"
141608*/
141609static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop){
141610 Index *pIndex = pLoop->u.btree.pIndex;
141611 u16 nEq = pLoop->u.btree.nEq;
141612 u16 nSkip = pLoop->nSkip;
141613 int i, j;
141614
141615 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
141616 sqlite3_str_append(pStr, " (", 2);
141617 for(i=0; i<nEq; i++){
141618 const char *z = explainIndexColumnName(pIndex, i);
141619 if( i ) sqlite3_str_append(pStr, " AND ", 5);
141620 sqlite3_str_appendf(pStr, i>=nSkip ? "%s=?" : "ANY(%s)", z);
141621 }
141622
141623 j = i;
141624 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
141625 explainAppendTerm(pStr, pIndex, pLoop->u.btree.nBtm, j, i, ">");
141626 i = 1;
static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop)
Definition sqlite3.c:141603
#define WHERE_TOP_LIMIT
Definition sqlite3.c:141517
static void explainAppendTerm(StrAccum *pStr, Index *pIdx, int nTerm, int iTerm, int bAnd, const char *zOp)
Definition sqlite3.c:141559
#define WHERE_BTM_LIMIT
Definition sqlite3.c:141518

References WhereLoop::btree, explainAppendTerm(), explainIndexColumnName(), WhereLoop::nBtm, WhereLoop::nEq, WhereLoop::nSkip, WhereLoop::nTop, WhereLoop::pIndex, sqlite3_str_append(), sqlite3_str_appendf(), WhereLoop::u, WHERE_BTM_LIMIT, WHERE_TOP_LIMIT, and WhereLoop::wsFlags.

Referenced by sqlite3WhereExplainOneScan().

◆ explainSimpleCount()

static void explainSimpleCount ( Parse * pParse,
Table * pTab,
Index * pIdx )
static

Definition at line 134849 of file sqlite3.c.

134859 {
134860 if( pParse->explain==2 ){
134861 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
134862 sqlite3VdbeExplain(pParse, 0, "SCAN TABLE %s%s%s",
SQLITE_PRIVATE void sqlite3VdbeExplain(Parse *, u8, const char *,...)
Definition sqlite3.c:78164
u8 explain
Definition sqlite3.c:18750

References Parse::explain, HasRowid, IsPrimaryKeyIndex, sqlite3VdbeExplain(), Table::zName, and Index::zName.

Referenced by sqlite3Select().

◆ explainTempTable()

static void explainTempTable ( Parse * pParse,
const char * zUsage )
static

Definition at line 130701 of file sqlite3.c.

References ExplainQueryPlan.

Referenced by sqlite3Select().

◆ exprAnalyze()

static void exprAnalyze ( SrcList * pSrc,
WhereClause * pWC,
int idxTerm )
static

Definition at line 145018 of file sqlite3.c.

145028 {
145029 WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */
145030 WhereTerm *pTerm; /* The term to be analyzed */
145031 WhereMaskSet *pMaskSet; /* Set of table index masks */
145032 Expr *pExpr; /* The expression to be analyzed */
145033 Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
145034 Bitmask prereqAll; /* Prerequesites of pExpr */
145035 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
145036 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
145037 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
145038 int noCase = 0; /* uppercase equivalent to lowercase */
145039 int op; /* Top-level operator. pExpr->op */
145040 Parse *pParse = pWInfo->pParse; /* Parsing context */
145041 sqlite3 *db = pParse->db; /* Database connection */
145042 unsigned char eOp2 = 0; /* op2 value for LIKE/REGEXP/GLOB */
145043 int nLeft; /* Number of elements on left side vector */
145044
145045 if( db->mallocFailed ){
145046 return;
145047 }
145048 pTerm = &pWC->a[idxTerm];
145049 pMaskSet = &pWInfo->sMaskSet;
145050 pExpr = pTerm->pExpr;
145051 assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
145052 prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft);
145053 op = pExpr->op;
145054 if( op==TK_IN ){
145055 assert( pExpr->pRight==0 );
145056 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
145057 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
145058 pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect);
145059 }else{
145060 pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList);
145061 }
145062 }else if( op==TK_ISNULL ){
145063 pTerm->prereqRight = 0;
145064 }else{
145065 pTerm->prereqRight = sqlite3WhereExprUsage(pMaskSet, pExpr->pRight);
145066 }
145067 pMaskSet->bVarSelect = 0;
145068 prereqAll = sqlite3WhereExprUsageNN(pMaskSet, pExpr);
145069 if( pMaskSet->bVarSelect ) pTerm->wtFlags |= TERM_VARSELECT;
145070 if( ExprHasProperty(pExpr, EP_FromJoin) ){
145071 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
145072 prereqAll |= x;
145073 extraRight = x-1; /* ON clause terms may not be used with an index
145074 ** on left table of a LEFT JOIN. Ticket #3015 */
145075 if( (prereqAll>>1)>=x ){
145076 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
145077 return;
145078 }
145079 }
145080 pTerm->prereqAll = prereqAll;
145081 pTerm->leftCursor = -1;
145082 pTerm->iParent = -1;
145083 pTerm->eOperator = 0;
145084 if( allowedOp(op) ){
145085 int aiCurCol[2];
145086 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
145087 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
145088 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
145089
145090 if( pTerm->iField>0 ){
145091 assert( op==TK_IN );
145092 assert( pLeft->op==TK_VECTOR );
145093 pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
145094 }
145095
145096 if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
145097 pTerm->leftCursor = aiCurCol[0];
145098 pTerm->u.leftColumn = aiCurCol[1];
145099 pTerm->eOperator = operatorMask(op) & opMask;
145100 }
145101 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
145102 if( pRight
145103 && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
145104 ){
145105 WhereTerm *pNew;
145106 Expr *pDup;
145107 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
145108 assert( pTerm->iField==0 );
145109 if( pTerm->leftCursor>=0 ){
145110 int idxNew;
145111 pDup = sqlite3ExprDup(db, pExpr, 0);
145112 if( db->mallocFailed ){
145113 sqlite3ExprDelete(db, pDup);
145114 return;
145115 }
145116 idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
145117 if( idxNew==0 ) return;
145118 pNew = &pWC->a[idxNew];
145119 markTermAsChild(pWC, idxNew, idxTerm);
145120 if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
145121 pTerm = &pWC->a[idxTerm];
145122 pTerm->wtFlags |= TERM_COPIED;
145123
145124 if( termIsEquivalence(pParse, pDup) ){
145125 pTerm->eOperator |= WO_EQUIV;
145126 eExtraOp = WO_EQUIV;
145127 }
145128 }else{
145129 pDup = pExpr;
145130 pNew = pTerm;
145131 }
145132 pNew->wtFlags |= exprCommute(pParse, pDup);
145133 pNew->leftCursor = aiCurCol[0];
145134 pNew->u.leftColumn = aiCurCol[1];
145135 testcase( (prereqLeft | extraRight) != prereqLeft );
145136 pNew->prereqRight = prereqLeft | extraRight;
145137 pNew->prereqAll = prereqAll;
145138 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
145139 }
145140 }
145141
145142#ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION
145143 /* If a term is the BETWEEN operator, create two new virtual terms
145144 ** that define the range that the BETWEEN implements. For example:
145145 **
145146 ** a BETWEEN b AND c
145147 **
145148 ** is converted into:
145149 **
145150 ** (a BETWEEN b AND c) AND (a>=b) AND (a<=c)
145151 **
145152 ** The two new terms are added onto the end of the WhereClause object.
145153 ** The new terms are "dynamic" and are children of the original BETWEEN
145154 ** term. That means that if the BETWEEN term is coded, the children are
145155 ** skipped. Or, if the children are satisfied by an index, the original
145156 ** BETWEEN term is skipped.
145157 */
145158 else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
145159 ExprList *pList = pExpr->x.pList;
145160 int i;
145161 static const u8 ops[] = {TK_GE, TK_LE};
145162 assert( pList!=0 );
145163 assert( pList->nExpr==2 );
145164 for(i=0; i<2; i++){
145165 Expr *pNewExpr;
145166 int idxNew;
145167 pNewExpr = sqlite3PExpr(pParse, ops[i],
145168 sqlite3ExprDup(db, pExpr->pLeft, 0),
145169 sqlite3ExprDup(db, pList->a[i].pExpr, 0));
145170 transferJoinMarkings(pNewExpr, pExpr);
145171 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
145172 testcase( idxNew==0 );
145173 exprAnalyze(pSrc, pWC, idxNew);
145174 pTerm = &pWC->a[idxTerm];
145175 markTermAsChild(pWC, idxNew, idxTerm);
145176 }
145177 }
145178#endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
145179
145180#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
145181 /* Analyze a term that is composed of two or more subterms connected by
145182 ** an OR operator.
145183 */
145184 else if( pExpr->op==TK_OR ){
145185 assert( pWC->op==TK_AND );
145186 exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
145187 pTerm = &pWC->a[idxTerm];
145188 }
145189#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
145190
145191#ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
145192 /* Add constraints to reduce the search space on a LIKE or GLOB
145193 ** operator.
145194 **
145195 ** A like pattern of the form "x LIKE 'aBc%'" is changed into constraints
145196 **
145197 ** x>='ABC' AND x<'abd' AND x LIKE 'aBc%'
145198 **
145199 ** The last character of the prefix "abc" is incremented to form the
145200 ** termination condition "abd". If case is not significant (the default
145201 ** for LIKE) then the lower-bound is made all uppercase and the upper-
145202 ** bound is made all lowercase so that the bounds also work when comparing
145203 ** BLOBs.
145204 */
145205 if( pWC->op==TK_AND
145206 && isLikeOrGlob(pParse, pExpr, &pStr1, &isComplete, &noCase)
145207 ){
145208 Expr *pLeft; /* LHS of LIKE/GLOB operator */
145209 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
145210 Expr *pNewExpr1;
145211 Expr *pNewExpr2;
145212 int idxNew1;
145213 int idxNew2;
145214 const char *zCollSeqName; /* Name of collating sequence */
145215 const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
145216
145217 pLeft = pExpr->x.pList->a[1].pExpr;
145218 pStr2 = sqlite3ExprDup(db, pStr1, 0);
145219
145220 /* Convert the lower bound to upper-case and the upper bound to
145221 ** lower-case (upper-case is less than lower-case in ASCII) so that
145222 ** the range constraints also work for BLOBs
145223 */
145224 if( noCase && !pParse->db->mallocFailed ){
145225 int i;
145226 char c;
145227 pTerm->wtFlags |= TERM_LIKE;
145228 for(i=0; (c = pStr1->u.zToken[i])!=0; i++){
145229 pStr1->u.zToken[i] = sqlite3Toupper(c);
145230 pStr2->u.zToken[i] = sqlite3Tolower(c);
145231 }
145232 }
145233
145234 if( !db->mallocFailed ){
145235 u8 c, *pC; /* Last character before the first wildcard */
145236 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1];
145237 c = *pC;
145238 if( noCase ){
145239 /* The point is to increment the last character before the first
145240 ** wildcard. But if we increment '@', that will push it into the
145241 ** alphabetic range where case conversions will mess up the
145242 ** inequality. To avoid this, make sure to also run the full
145243 ** LIKE on all candidate expressions by clearing the isComplete flag
145244 */
145245 if( c=='A'-1 ) isComplete = 0;
145246 c = sqlite3UpperToLower[c];
145247 }
145248 *pC = c + 1;
145249 }
145250 zCollSeqName = noCase ? "NOCASE" : sqlite3StrBINARY;
145251 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
145252 pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
145253 sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
145254 pStr1);
145255 transferJoinMarkings(pNewExpr1, pExpr);
145256 idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
145257 testcase( idxNew1==0 );
145258 exprAnalyze(pSrc, pWC, idxNew1);
145259 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
145260 pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
145261 sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
145262 pStr2);
145263 transferJoinMarkings(pNewExpr2, pExpr);
145264 idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
145265 testcase( idxNew2==0 );
145266 exprAnalyze(pSrc, pWC, idxNew2);
145267 pTerm = &pWC->a[idxTerm];
145268 if( isComplete ){
145269 markTermAsChild(pWC, idxNew1, idxTerm);
145270 markTermAsChild(pWC, idxNew2, idxTerm);
145271 }
145272 }
145273#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
145274
145275#ifndef SQLITE_OMIT_VIRTUALTABLE
145276 /* Add a WO_AUX auxiliary term to the constraint set if the
145277 ** current expression is of the form "column OP expr" where OP
145278 ** is an operator that gets passed into virtual tables but which is
145279 ** not normally optimized for ordinary tables. In other words, OP
145280 ** is one of MATCH, LIKE, GLOB, REGEXP, !=, IS, IS NOT, or NOT NULL.
145281 ** This information is used by the xBestIndex methods of
145282 ** virtual tables. The native query optimizer does not attempt
145283 ** to do anything with MATCH functions.
145284 */
145285 if( pWC->op==TK_AND ){
145286 Expr *pRight = 0, *pLeft = 0;
145287 int res = isAuxiliaryVtabOperator(db, pExpr, &eOp2, &pLeft, &pRight);
145288 while( res-- > 0 ){
145289 int idxNew;
145290 WhereTerm *pNewTerm;
145291 Bitmask prereqColumn, prereqExpr;
145292
145293 prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
145294 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
145295 if( (prereqExpr & prereqColumn)==0 ){
145296 Expr *pNewExpr;
145297 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
145298 0, sqlite3ExprDup(db, pRight, 0));
145299 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
145300 ExprSetProperty(pNewExpr, EP_FromJoin);
145301 pNewExpr->iRightJoinTable = pExpr->iRightJoinTable;
145302 }
145303 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
145304 testcase( idxNew==0 );
145305 pNewTerm = &pWC->a[idxNew];
145306 pNewTerm->prereqRight = prereqExpr;
145307 pNewTerm->leftCursor = pLeft->iTable;
145308 pNewTerm->u.leftColumn = pLeft->iColumn;
145309 pNewTerm->eOperator = WO_AUX;
145310 pNewTerm->eMatchOp = eOp2;
145311 markTermAsChild(pWC, idxNew, idxTerm);
145312 pTerm = &pWC->a[idxTerm];
145313 pTerm->wtFlags |= TERM_COPIED;
145314 pNewTerm->prereqAll = pTerm->prereqAll;
145315 }
145316 SWAP(Expr*, pLeft, pRight);
145317 }
145318 }
145319#endif /* SQLITE_OMIT_VIRTUALTABLE */
145320
145321 /* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
145322 ** new terms for each component comparison - "a = ?" and "b = ?". The
145323 ** new terms completely replace the original vector comparison, which is
145324 ** no longer used.
145325 **
145326 ** This is only required if at least one side of the comparison operation
145327 ** is not a sub-select. */
145328 if( pWC->op==TK_AND
145329 && (pExpr->op==TK_EQ || pExpr->op==TK_IS)
145330 && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1
145331 && sqlite3ExprVectorSize(pExpr->pRight)==nLeft
145332 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
145333 || (pExpr->pRight->flags & EP_xIsSelect)==0)
145334 ){
145335 int i;
145336 for(i=0; i<nLeft; i++){
145337 int idxNew;
145338 Expr *pNew;
145339 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
145340 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
145341
145342 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
145343 transferJoinMarkings(pNew, pExpr);
145344 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
145345 exprAnalyze(pSrc, pWC, idxNew);
145346 }
145347 pTerm = &pWC->a[idxTerm];
145348 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
145349 pTerm->eOperator = 0;
145350 }
145351
145352 /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
145353 ** a virtual term for each vector component. The expression object
145354 ** used by each such virtual term is pExpr (the full vector IN(...)
145355 ** expression). The WhereTerm.iField variable identifies the index within
145356 ** the vector on the LHS that the virtual term represents.
145357 **
145358 ** This only works if the RHS is a simple SELECT (not a compound) that does
145359 ** not use window functions.
145360 */
145361 if( pWC->op==TK_AND && pExpr->op==TK_IN && pTerm->iField==0
145362 && pExpr->pLeft->op==TK_VECTOR
145363 && pExpr->x.pSelect->pPrior==0
145364#ifndef SQLITE_OMIT_WINDOWFUNC
145365 && pExpr->x.pSelect->pWin==0
145366#endif
145367 ){
145368 int i;
145369 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
145370 int idxNew;
145371 idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL);
145372 pWC->a[idxNew].iField = i+1;
145373 exprAnalyze(pSrc, pWC, idxNew);
145374 markTermAsChild(pWC, idxNew, idxTerm);
145375 }
145376 }
145377
145378#ifdef SQLITE_ENABLE_STAT4
145379 /* When sqlite_stat4 histogram data is available an operator of the
145380 ** form "x IS NOT NULL" can sometimes be evaluated more efficiently
145381 ** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
145382 ** virtual term of that form.
145383 **
145384 ** Note that the virtual term must be tagged with TERM_VNULL.
145385 */
145386 if( pExpr->op==TK_NOTNULL
145387 && pExpr->pLeft->op==TK_COLUMN
145388 && pExpr->pLeft->iColumn>=0
145389 && !ExprHasProperty(pExpr, EP_FromJoin)
145391 ){
145392 Expr *pNewExpr;
145393 Expr *pLeft = pExpr->pLeft;
145394 int idxNew;
145395 WhereTerm *pNewTerm;
145396
145397 pNewExpr = sqlite3PExpr(pParse, TK_GT,
145398 sqlite3ExprDup(db, pLeft, 0),
145399 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
145400
145401 idxNew = whereClauseInsert(pWC, pNewExpr,
145403 if( idxNew ){
145404 pNewTerm = &pWC->a[idxNew];
145405 pNewTerm->prereqRight = 0;
145406 pNewTerm->leftCursor = pLeft->iTable;
145407 pNewTerm->u.leftColumn = pLeft->iColumn;
145408 pNewTerm->eOperator = WO_GT;
145409 markTermAsChild(pWC, idxNew, idxTerm);
145410 pTerm = &pWC->a[idxTerm];
145411 pTerm->wtFlags |= TERM_COPIED;
145412 pNewTerm->prereqAll = pTerm->prereqAll;
145413 }
145414 }
145415#endif /* SQLITE_ENABLE_STAT4 */
145416
145417 /* Prevent ON clause terms of a LEFT JOIN from being used to drive
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *, Expr *)
Definition sqlite3.c:145526
#define TK_COLLATE
Definition sqlite3.c:14053
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *, ExprList *)
Definition sqlite3.c:145529
static u16 operatorMask(int op)
Definition sqlite3.c:144126
static int isAuxiliaryVtabOperator(sqlite3 *db, Expr *pExpr, unsigned char *peOp2, Expr **ppLeft, Expr **ppRight)
Definition sqlite3.c:144336
#define TERM_DYNAMIC
Definition sqlite3.c:141191
#define TERM_LIKEOPT
Definition sqlite3.c:141203
#define TK_NULL
Definition sqlite3.c:14061
static void transferJoinMarkings(Expr *pDerived, Expr *pBase)
Definition sqlite3.c:144441
static int exprMightBeIndexed(SrcList *pFrom, Bitmask mPrereq, int *aiCurCol, Expr *pExpr, int op)
Definition sqlite3.c:144973
#define TK_MATCH
Definition sqlite3.c:13988
static u16 exprCommute(Parse *pParse, Expr *pExpr)
Definition sqlite3.c:144103
SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet *, int)
Definition sqlite3.c:145819
SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *, Expr *)
Definition sqlite3.c:102840
static int isLikeOrGlob(Parse *pParse, Expr *pExpr, Expr **ppPrefix, int *pisComplete, int *pnoCase)
Definition sqlite3.c:144164
#define TK_BETWEEN
Definition sqlite3.c:13990
static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags)
Definition sqlite3.c:144050
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet *, Expr *)
Definition sqlite3.c:145498
#define TK_VECTOR
Definition sqlite3.c:14116
SQLITE_PRIVATE Expr * sqlite3ExprSkipCollate(Expr *)
Definition sqlite3.c:99824
static Bitmask exprSelectUsage(WhereMaskSet *pMaskSet, Select *pS)
Definition sqlite3.c:144912
static int allowedOp(int op)
Definition sqlite3.c:144091
static void markTermAsChild(WhereClause *pWC, int iChild, int iParent)
Definition sqlite3.c:144451
static int termIsEquivalence(Parse *pParse, Expr *pExpr)
Definition sqlite3.c:144889
static void exprAnalyzeOrTerm(SrcList *pSrc, WhereClause *pWC, int idxTerm)
Definition sqlite3.c:144618
#define TERM_COPIED
Definition sqlite3.c:141194
static void exprAnalyze(SrcList *, WhereClause *, int)
Definition sqlite3.c:145018
#define sqlite3Tolower(x)
Definition sqlite3.c:19324
#define TK_AND
Definition sqlite3.c:13986
#define TK_OR
Definition sqlite3.c:13985
SQLITE_PRIVATE Expr * sqlite3ExprAddCollateString(Parse *, Expr *, const char *)
Definition sqlite3.c:99814
SQLITE_PRIVATE Expr * sqlite3ExprForVectorField(Parse *, Expr *, int)
Definition sqlite3.c:100187
#define sqlite3Toupper(x)
Definition sqlite3.c:19318
#define TK_NOTNULL
Definition sqlite3.c:13993
#define TK_AS
Definition sqlite3.c:13966
#define TERM_VARSELECT
Definition sqlite3.c:141207
#define SWAP(TYPE, A, B)
Definition sqlite3.c:14272
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]
Definition sqlite3.c:20387
Window * pWin
Definition sqlite3.c:18457
WhereMaskSet sMaskSet
Definition sqlite3.c:141409

References ExprList::a, WhereClause::a, allowedOp(), WhereMaskSet::bVarSelect, Parse::db, WhereTerm::eMatchOp, WhereTerm::eOperator, EP_FromJoin, EP_xIsSelect, exprAnalyze(), exprAnalyzeOrTerm(), exprCommute(), ExprHasProperty, exprMightBeIndexed(), exprSelectUsage(), ExprSetProperty, Expr::flags, Expr::iColumn, WhereTerm::iField, WhereTerm::iParent, Expr::iRightJoinTable, isAuxiliaryVtabOperator(), isLikeOrGlob(), Expr::iTable, WhereTerm::leftColumn, WhereTerm::leftCursor, sqlite3::mallocFailed, markTermAsChild(), ExprList::nExpr, Expr::op, WhereClause::op, operatorMask(), OptimizationEnabled, ExprList::ExprList_item::pExpr, WhereTerm::pExpr, Expr::pLeft, Expr::pList, WhereInfo::pParse, Select::pPrior, WhereTerm::prereqAll, WhereTerm::prereqRight, Expr::pRight, Expr::pSelect, Select::pWin, WhereClause::pWInfo, WhereInfo::sMaskSet, sqlite3ErrorMsg(), sqlite3ExprAddCollateString(), sqlite3ExprAlloc(), sqlite3ExprCheckIN(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprForVectorField(), sqlite3ExprSkipCollate(), sqlite3ExprVectorSize(), sqlite3PExpr(), sqlite3StrBINARY, sqlite3Strlen30(), sqlite3Tolower, sqlite3Toupper, sqlite3UpperToLower, sqlite3WhereExprListUsage(), sqlite3WhereExprUsage(), sqlite3WhereExprUsageNN(), sqlite3WhereGetMask(), SQLITE_Stat4, SWAP, TERM_CODED, TERM_COPIED, TERM_DYNAMIC, TERM_IS, TERM_LIKE, TERM_LIKEOPT, TERM_VARSELECT, TERM_VIRTUAL, TERM_VNULL, termIsEquivalence(), testcase, TK_AND, TK_AS, TK_BETWEEN, TK_COLLATE, TK_COLUMN, TK_EQ, TK_GE, TK_GT, TK_IN, TK_IS, TK_ISNULL, TK_LE, TK_LT, TK_MATCH, TK_NOTNULL, TK_NULL, TK_OR, TK_VECTOR, transferJoinMarkings(), Expr::u, WhereTerm::u, whereClauseInsert(), WO_ALL, WO_AUX, WO_EQUIV, WO_GT, WhereTerm::wtFlags, Expr::x, and Expr::zToken.

Referenced by exprAnalyze(), exprAnalyzeOrTerm(), sqlite3WhereExprAnalyze(), and whereCombineDisjuncts().

◆ exprAnalyzeOrTerm()

static void exprAnalyzeOrTerm ( SrcList * pSrc,
WhereClause * pWC,
int idxTerm )
static

Definition at line 144618 of file sqlite3.c.

144619 :
144620**
144621** If none of cases 1, 2, or 3 apply, then leave the eOperator set to
144622** zero. This term is not useful for search.
144623*/
144624static void exprAnalyzeOrTerm(
144625 SrcList *pSrc, /* the FROM clause */
144626 WhereClause *pWC, /* the complete WHERE clause */
144627 int idxTerm /* Index of the OR-term to be analyzed */
144628){
144629 WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */
144630 Parse *pParse = pWInfo->pParse; /* Parser context */
144631 sqlite3 *db = pParse->db; /* Database connection */
144632 WhereTerm *pTerm = &pWC->a[idxTerm]; /* The term to be analyzed */
144633 Expr *pExpr = pTerm->pExpr; /* The expression of the term */
144634 int i; /* Loop counters */
144635 WhereClause *pOrWc; /* Breakup of pTerm into subterms */
144636 WhereTerm *pOrTerm; /* A Sub-term within the pOrWc */
144637 WhereOrInfo *pOrInfo; /* Additional information associated with pTerm */
144638 Bitmask chngToIN; /* Tables that might satisfy case 1 */
144639 Bitmask indexable; /* Tables that are indexable, satisfying case 2 */
144640
144641 /*
144642 ** Break the OR clause into its separate subterms. The subterms are
144643 ** stored in a WhereClause structure containing within the WhereOrInfo
144644 ** object that is attached to the original OR clause term.
144645 */
144646 assert( (pTerm->wtFlags & (TERM_DYNAMIC|TERM_ORINFO|TERM_ANDINFO))==0 );
144647 assert( pExpr->op==TK_OR );
144648 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
144649 if( pOrInfo==0 ) return;
144650 pTerm->wtFlags |= TERM_ORINFO;
144651 pOrWc = &pOrInfo->wc;
144652 memset(pOrWc->aStatic, 0, sizeof(pOrWc->aStatic));
144653 sqlite3WhereClauseInit(pOrWc, pWInfo);
144654 sqlite3WhereSplit(pOrWc, pExpr, TK_OR);
144655 sqlite3WhereExprAnalyze(pSrc, pOrWc);
144656 if( db->mallocFailed ) return;
144657 assert( pOrWc->nTerm>=2 );
144658
144659 /*
144660 ** Compute the set of tables that might satisfy cases 1 or 3.
144661 */
144662 indexable = ~(Bitmask)0;
144663 chngToIN = ~(Bitmask)0;
144664 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){
144665 if( (pOrTerm->eOperator & WO_SINGLE)==0 ){
144666 WhereAndInfo *pAndInfo;
144667 assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 );
144668 chngToIN = 0;
144669 pAndInfo = sqlite3DbMallocRawNN(db, sizeof(*pAndInfo));
144670 if( pAndInfo ){
144671 WhereClause *pAndWC;
144672 WhereTerm *pAndTerm;
144673 int j;
144674 Bitmask b = 0;
144675 pOrTerm->u.pAndInfo = pAndInfo;
144676 pOrTerm->wtFlags |= TERM_ANDINFO;
144677 pOrTerm->eOperator = WO_AND;
144678 pAndWC = &pAndInfo->wc;
144679 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
144680 sqlite3WhereClauseInit(pAndWC, pWC->pWInfo);
144681 sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
144682 sqlite3WhereExprAnalyze(pSrc, pAndWC);
144683 pAndWC->pOuter = pWC;
144684 if( !db->mallocFailed ){
144685 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
144686 assert( pAndTerm->pExpr );
144687 if( allowedOp(pAndTerm->pExpr->op)
144688 || pAndTerm->eOperator==WO_AUX
144689 ){
144690 b |= sqlite3WhereGetMask(&pWInfo->sMaskSet, pAndTerm->leftCursor);
144691 }
144692 }
144693 }
144694 indexable &= b;
144695 }
144696 }else if( pOrTerm->wtFlags & TERM_COPIED ){
144697 /* Skip this term for now. We revisit it when we process the
144698 ** corresponding TERM_VIRTUAL term */
144699 }else{
144700 Bitmask b;
144701 b = sqlite3WhereGetMask(&pWInfo->sMaskSet, pOrTerm->leftCursor);
144702 if( pOrTerm->wtFlags & TERM_VIRTUAL ){
144703 WhereTerm *pOther = &pOrWc->a[pOrTerm->iParent];
144704 b |= sqlite3WhereGetMask(&pWInfo->sMaskSet, pOther->leftCursor);
144705 }
144706 indexable &= b;
144707 if( (pOrTerm->eOperator & WO_EQ)==0 ){
144708 chngToIN = 0;
144709 }else{
144710 chngToIN &= b;
144711 }
144712 }
144713 }
144714
144715 /*
144716 ** Record the set of tables that satisfy case 3. The set might be
144717 ** empty.
144718 */
144719 pOrInfo->indexable = indexable;
144720 if( indexable ){
144721 pTerm->eOperator = WO_OR;
144722 pWC->hasOr = 1;
144723 }else{
144724 pTerm->eOperator = WO_OR;
144725 }
144726
144727 /* For a two-way OR, attempt to implementation case 2.
144728 */
144729 if( indexable && pOrWc->nTerm==2 ){
144730 int iOne = 0;
144731 WhereTerm *pOne;
144732 while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){
144733 int iTwo = 0;
144734 WhereTerm *pTwo;
144735 while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){
144736 whereCombineDisjuncts(pSrc, pWC, pOne, pTwo);
144737 }
144738 }
144739 }
144740
144741 /*
144742 ** chngToIN holds a set of tables that *might* satisfy case 1. But
144743 ** we have to do some additional checking to see if case 1 really
144744 ** is satisfied.
144745 **
144746 ** chngToIN will hold either 0, 1, or 2 bits. The 0-bit case means
144747 ** that there is no possibility of transforming the OR clause into an
144748 ** IN operator because one or more terms in the OR clause contain
144749 ** something other than == on a column in the single table. The 1-bit
144750 ** case means that every term of the OR clause is of the form
144751 ** "table.column=expr" for some single table. The one bit that is set
144752 ** will correspond to the common table. We still need to check to make
144753 ** sure the same column is used on all terms. The 2-bit case is when
144754 ** the all terms are of the form "table1.column=table2.column". It
144755 ** might be possible to form an IN operator with either table1.column
144756 ** or table2.column as the LHS if either is common to every term of
144757 ** the OR clause.
144758 **
144759 ** Note that terms of the form "table.column1=table.column2" (the
144760 ** same table on both sizes of the ==) cannot be optimized.
144761 */
144762 if( chngToIN ){
144763 int okToChngToIN = 0; /* True if the conversion to IN is valid */
144764 int iColumn = -1; /* Column index on lhs of IN operator */
144765 int iCursor = -1; /* Table cursor common to all terms */
144766 int j = 0; /* Loop counter */
144767
144768 /* Search for a table and column that appears on one side or the
144769 ** other of the == operator in every subterm. That table and column
144770 ** will be recorded in iCursor and iColumn. There might not be any
144771 ** such table and column. Set okToChngToIN if an appropriate table
144772 ** and column is found but leave okToChngToIN false if not found.
144773 */
144774 for(j=0; j<2 && !okToChngToIN; j++){
144775 Expr *pLeft = 0;
144776 pOrTerm = pOrWc->a;
144777 for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){
144778 assert( pOrTerm->eOperator & WO_EQ );
144779 pOrTerm->wtFlags &= ~TERM_OR_OK;
144780 if( pOrTerm->leftCursor==iCursor ){
144781 /* This is the 2-bit case and we are on the second iteration and
144782 ** current term is from the first iteration. So skip this term. */
144783 assert( j==1 );
144784 continue;
144785 }
144786 if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet,
144787 pOrTerm->leftCursor))==0 ){
144788 /* This term must be of the form t1.a==t2.b where t2 is in the
144789 ** chngToIN set but t1 is not. This term will be either preceded
144790 ** or follwed by an inverted copy (t2.b==t1.a). Skip this term
144791 ** and use its inversion. */
144792 testcase( pOrTerm->wtFlags & TERM_COPIED );
144793 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
144794 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
144795 continue;
144796 }
144797 iColumn = pOrTerm->u.leftColumn;
144798 iCursor = pOrTerm->leftCursor;
144799 pLeft = pOrTerm->pExpr->pLeft;
144800 break;
144801 }
144802 if( i<0 ){
144803 /* No candidate table+column was found. This can only occur
144804 ** on the second iteration */
144805 assert( j==1 );
144806 assert( IsPowerOfTwo(chngToIN) );
144807 assert( chngToIN==sqlite3WhereGetMask(&pWInfo->sMaskSet, iCursor) );
144808 break;
144809 }
144810 testcase( j==1 );
144811
144812 /* We have found a candidate table and column. Check to see if that
144813 ** table and column is common to every term in the OR clause */
144814 okToChngToIN = 1;
144815 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
144816 assert( pOrTerm->eOperator & WO_EQ );
144817 if( pOrTerm->leftCursor!=iCursor ){
144818 pOrTerm->wtFlags &= ~TERM_OR_OK;
144819 }else if( pOrTerm->u.leftColumn!=iColumn || (iColumn==XN_EXPR
144820 && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1)
144821 )){
144822 okToChngToIN = 0;
144823 }else{
144824 int affLeft, affRight;
144825 /* If the right-hand side is also a column, then the affinities
144826 ** of both right and left sides must be such that no type
144827 ** conversions are required on the right. (Ticket #2249)
144828 */
144829 affRight = sqlite3ExprAffinity(pOrTerm->pExpr->pRight);
144830 affLeft = sqlite3ExprAffinity(pOrTerm->pExpr->pLeft);
144831 if( affRight!=0 && affRight!=affLeft ){
144832 okToChngToIN = 0;
144833 }else{
144834 pOrTerm->wtFlags |= TERM_OR_OK;
144835 }
144836 }
144837 }
144838 }
144839
144840 /* At this point, okToChngToIN is true if original pTerm satisfies
144841 ** case 1. In that case, construct a new virtual term that is
144842 ** pTerm converted into an IN operator.
144843 */
144844 if( okToChngToIN ){
144845 Expr *pDup; /* A transient duplicate expression */
144846 ExprList *pList = 0; /* The RHS of the IN operator */
144847 Expr *pLeft = 0; /* The LHS of the IN operator */
144848 Expr *pNew; /* The complete IN operator */
144849
144850 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
144851 if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
144852 assert( pOrTerm->eOperator & WO_EQ );
144853 assert( pOrTerm->leftCursor==iCursor );
144854 assert( pOrTerm->u.leftColumn==iColumn );
144855 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
144856 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
144857 pLeft = pOrTerm->pExpr->pLeft;
144858 }
144859 assert( pLeft!=0 );
144860 pDup = sqlite3ExprDup(db, pLeft, 0);
144861 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
144862 if( pNew ){
144863 int idxNew;
144864 transferJoinMarkings(pNew, pExpr);
144865 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
144866 pNew->x.pList = pList;
144867 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
144868 testcase( idxNew==0 );
144869 exprAnalyze(pSrc, pWC, idxNew);
144870 /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where used again */
144871 markTermAsChild(pWC, idxNew, idxTerm);
static void whereCombineDisjuncts(SrcList *pSrc, WhereClause *pWC, WhereTerm *pOne, WhereTerm *pTwo)
Definition sqlite3.c:144492
SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause *, Expr *, u8)
Definition sqlite3.c:145441
#define TERM_ORINFO
Definition sqlite3.c:141195
#define WO_AND
Definition sqlite3.c:141500
#define WO_SINGLE
Definition sqlite3.c:141505
static WhereTerm * whereNthSubterm(WhereTerm *pTerm, int N)
Definition sqlite3.c:144462
SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause *, WhereInfo *)
Definition sqlite3.c:145456
#define TERM_OR_OK
Definition sqlite3.c:141197
#define TERM_ANDINFO
Definition sqlite3.c:141196
#define WO_OR
Definition sqlite3.c:141499
SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList *, WhereClause *)
Definition sqlite3.c:145549
WhereClause wc
Definition sqlite3.c:141274
WhereTerm aStatic[8]
Definition sqlite3.c:141256
WhereClause * pOuter
Definition sqlite3.c:141247
Bitmask indexable
Definition sqlite3.c:141266
WhereClause wc
Definition sqlite3.c:141265
WhereAndInfo * pAndInfo
Definition sqlite3.c:141182
WhereOrInfo * pOrInfo
Definition sqlite3.c:141181

References WhereClause::a, allowedOp(), WhereClause::aStatic, Parse::db, WhereTerm::eOperator, EP_xIsSelect, exprAnalyze(), ExprHasProperty, WhereClause::hasOr, WhereOrInfo::indexable, WhereTerm::iParent, IsPowerOfTwo, WhereTerm::leftColumn, WhereTerm::leftCursor, sqlite3::mallocFailed, markTermAsChild(), WhereClause::nTerm, Expr::op, WhereTerm::pAndInfo, WhereTerm::pExpr, Expr::pLeft, Expr::pList, WhereTerm::pOrInfo, WhereClause::pOuter, WhereInfo::pParse, Expr::pRight, WhereClause::pWInfo, WhereInfo::sMaskSet, sqlite3DbMallocRawNN(), sqlite3DbMallocZero(), sqlite3ExprAffinity(), sqlite3ExprCompare(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3ExprListDelete(), sqlite3PExpr(), sqlite3WhereClauseInit(), sqlite3WhereExprAnalyze(), sqlite3WhereGetMask(), sqlite3WhereSplit(), TERM_ANDINFO, TERM_COPIED, TERM_DYNAMIC, TERM_OR_OK, TERM_ORINFO, TERM_VIRTUAL, testcase, TK_AND, TK_IN, TK_OR, transferJoinMarkings(), WhereTerm::u, WhereOrInfo::wc, WhereAndInfo::wc, whereClauseInsert(), whereCombineDisjuncts(), whereNthSubterm(), WO_AND, WO_AUX, WO_EQ, WO_OR, WO_SINGLE, WhereTerm::wtFlags, Expr::x, and XN_EXPR.

Referenced by exprAnalyze().

◆ exprCodeBetween()

static void exprCodeBetween ( Parse * pParse,
Expr * pExpr,
int dest,
void(*)(Parse *, Expr *, int, int) xJump,
int jumpIfNull )
static

Definition at line 104481 of file sqlite3.c.

104481 : Store the boolean result in reg[dest]
104482** sqlite3ExprIfTrue: Jump to dest if true
104483** sqlite3ExprIfFalse: Jump to dest if false
104484**
104485** The jumpIfNull parameter is ignored if xJumpIf is NULL.
104486*/
104487static void exprCodeBetween(
104488 Parse *pParse, /* Parsing and code generating context */
104489 Expr *pExpr, /* The BETWEEN expression */
104490 int dest, /* Jump destination or storage location */
104491 void (*xJump)(Parse*,Expr*,int,int), /* Action to take */
104492 int jumpIfNull /* Take the jump if the BETWEEN is NULL */
104493){
104494 Expr exprAnd; /* The AND operator in x>=y AND x<=z */
104495 Expr compLeft; /* The x>=y term */
104496 Expr compRight; /* The x<=z term */
104497 int regFree1 = 0; /* Temporary use register */
104498 Expr *pDel = 0;
104499 sqlite3 *db = pParse->db;
104500
104501 memset(&compLeft, 0, sizeof(Expr));
104502 memset(&compRight, 0, sizeof(Expr));
104503 memset(&exprAnd, 0, sizeof(Expr));
104504
104505 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
104506 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
104507 if( db->mallocFailed==0 ){
104508 exprAnd.op = TK_AND;
104509 exprAnd.pLeft = &compLeft;
104510 exprAnd.pRight = &compRight;
104511 compLeft.op = TK_GE;
104512 compLeft.pLeft = pDel;
104513 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
104514 compRight.op = TK_LE;
104515 compRight.pLeft = pDel;
104516 compRight.pRight = pExpr->x.pList->a[1].pExpr;
104517 exprToRegister(pDel, exprCodeVector(pParse, pDel, &regFree1));
104518 if( xJump ){
104519 xJump(pParse, &exprAnd, dest, jumpIfNull);
104520 }else{
104521 /* Mark the expression is being from the ON or USING clause of a join
104522 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
104523 ** it into the Parse.pConstExpr list. We should use a new bit for this,
104524 ** for clarity, but we are out of bits in the Expr.flags field so we
104525 ** have to reuse the EP_FromJoin bit. Bummer. */
104526 pDel->flags |= EP_FromJoin;
104527 sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
104528 }
104529 sqlite3ReleaseTempReg(pParse, regFree1);
104530 }
104531 sqlite3ExprDelete(db, pDel);
104532
104533 /* Ensure adequate test coverage */
104534 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1==0 );
104535 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1!=0 );
104536 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1==0 );
104537 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1!=0 );
static void exprCodeBetween(Parse *, Expr *, int, void(*)(Parse *, Expr *, int, int), int)
Definition sqlite3.c:104481
static void exprToRegister(Expr *pExpr, int iReg)
Definition sqlite3.c:103329
static int exprCodeVector(Parse *pParse, Expr *p, int *piToFree)
Definition sqlite3.c:103347
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse *, Expr *, int, int)
Definition sqlite3.c:104553

References ExprList::a, Parse::db, EP_FromJoin, EP_xIsSelect, exprCodeVector(), ExprHasProperty, exprToRegister(), Expr::flags, sqlite3::mallocFailed, Expr::op, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pRight, sqlite3ExprCodeTarget(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3ReleaseTempReg(), testcase, TK_AND, TK_GE, TK_LE, and Expr::x.

Referenced by sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), and sqlite3ExprIfTrue().

◆ exprCodeInlineFunction()

static int exprCodeInlineFunction ( Parse * pParse,
ExprList * pFarg,
int iFuncId,
int target )
static

Definition at line 103386 of file sqlite3.c.

103397 {
103398 int nFarg;
103399 Vdbe *v = pParse->pVdbe;
103400 assert( v!=0 );
103401 assert( pFarg!=0 );
103402 nFarg = pFarg->nExpr;
103403 assert( nFarg>0 ); /* All in-line functions have at least one argument */
103404 switch( iFuncId ){
103405 case INLINEFUNC_coalesce: {
103406 /* Attempt a direct implementation of the built-in COALESCE() and
103407 ** IFNULL() functions. This avoids unnecessary evaluation of
103408 ** arguments past the first non-NULL argument.
103409 */
103410 int endCoalesce = sqlite3VdbeMakeLabel(pParse);
103411 int i;
103412 assert( nFarg>=2 );
103413 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
103414 for(i=1; i<nFarg; i++){
103415 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
103416 VdbeCoverage(v);
103417 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
103418 }
103420 sqlite3VdbeResolveLabel(v, endCoalesce);
103421 break;
103422 }
103423 case INLINEFUNC_iif: {
103424 Expr caseExpr;
103425 memset(&caseExpr, 0, sizeof(caseExpr));
103426 caseExpr.op = TK_CASE;
103427 caseExpr.x.pList = pFarg;
103428 return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
103429 }
103430
103431 default: {
103432 /* The UNLIKELY() function is a no-op. The result is the value
103433 ** of the first argument.
103434 */
103435 assert( nFarg==1 || nFarg==2 );
103436 target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
103437 break;
103438 }
103439
103440 /***********************************************************************
103441 ** Test-only SQL functions that are only usable if enabled
103442 ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
103443 */
103445 /* Compare two expressions using sqlite3ExprCompare() */
103446 assert( nFarg==2 );
103448 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
103449 target);
103450 break;
103451 }
103452
103454 /* Compare two expressions using sqlite3ExprImpliesExpr() */
103455 assert( nFarg==2 );
103457 sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
103458 target);
103459 break;
103460 }
103461
103463 /* REsult of sqlite3ExprImpliesNonNullRow() */
103464 Expr *pA1;
103465 assert( nFarg==2 );
103466 pA1 = pFarg->a[1].pExpr;
103467 if( pA1->op==TK_COLUMN ){
103469 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable),
103470 target);
103471 }else{
103472 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
103473 }
103474 break;
103475 }
103476
103477#ifdef SQLITE_DEBUG
103478 case INLINEFUNC_affinity: {
103479 /* The AFFINITY() function evaluates to a string that describes
103480 ** the type affinity of the argument. This is used for testing of
103481 ** the SQLite type logic.
103482 */
103483 const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
103484 char aff;
103485 assert( nFarg==1 );
103486 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
103487 sqlite3VdbeLoadString(v, target,
103488 (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *, int)
Definition sqlite3.c:105285
#define INLINEFUNC_implies_nonnull_row
Definition sqlite3.c:17169
#define INLINEFUNC_coalesce
Definition sqlite3.c:17168
#define INLINEFUNC_affinity
Definition sqlite3.c:17172
#define TK_CASE
Definition sqlite3.c:14096
#define INLINEFUNC_iif
Definition sqlite3.c:17173
static void setDoNotMergeFlagOnCopy(Vdbe *v)
Definition sqlite3.c:103376
#define INLINEFUNC_expr_implies_expr
Definition sqlite3.c:17170
#define INLINEFUNC_expr_compare
Definition sqlite3.c:17171
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse *, Expr *, Expr *, int)
Definition sqlite3.c:105153

Referenced by sqlite3ExprCodeTarget().

◆ exprCodeSubselect()

static int exprCodeSubselect ( Parse * pParse,
Expr * pExpr )
static

Definition at line 100233 of file sqlite3.c.

100239 {
100240 int reg = 0;
100241#ifndef SQLITE_OMIT_SUBQUERY

References Expr::op, sqlite3CodeSubselect(), and TK_SELECT.

Referenced by codeVectorCompare().

◆ exprCodeVector()

static int exprCodeVector ( Parse * pParse,
Expr * p,
int * piToFree )
static

Definition at line 103347 of file sqlite3.c.

103353 {
103354 int iResult;
103355 int nResult = sqlite3ExprVectorSize(p);
103356 if( nResult==1 ){
103357 iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
103358 }else{
103359 *piFreeable = 0;
103360 if( p->op==TK_SELECT ){
103361#if SQLITE_OMIT_SUBQUERY
103362 iResult = 0;
103363#else
103364 iResult = sqlite3CodeSubselect(pParse, p);
103365#endif
103366 }else{
103367 int i;
103368 iResult = pParse->nMem+1;
103369 pParse->nMem += nResult;
103370 for(i=0; i<nResult; i++){
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *, Expr *, int *)
Definition sqlite3.c:104314

References ExprList::a, Parse::nMem, Expr::op, ExprList::ExprList_item::pExpr, Expr::pList, sqlite3CodeSubselect(), sqlite3ExprCodeFactorable(), sqlite3ExprCodeTemp(), sqlite3ExprVectorSize(), TK_SELECT, and Expr::x.

Referenced by exprCodeBetween(), sqlite3ExprCodeIN(), and sqlite3ExprCodeTarget().

◆ exprColumnFlagUnion()

static int exprColumnFlagUnion ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 120754 of file sqlite3.c.

120760 {

Referenced by sqlite3ComputeGeneratedColumns().

◆ exprCommute()

static u16 exprCommute ( Parse * pParse,
Expr * pExpr )
static

Definition at line 144103 of file sqlite3.c.

144109 {
144110 if( pExpr->pLeft->op==TK_VECTOR
144111 || pExpr->pRight->op==TK_VECTOR
144112 || sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, pExpr->pRight) !=
144113 sqlite3BinaryCompareCollSeq(pParse, pExpr->pRight, pExpr->pLeft)
144114 ){
144115 pExpr->flags ^= EP_Commuted;
144116 }
144117 SWAP(Expr*,pExpr->pRight,pExpr->pLeft);
144118 if( pExpr->op>=TK_GT ){
144119 assert( TK_LT==TK_GT+2 );
144120 assert( TK_GE==TK_LE+2 );
144121 assert( TK_GT>TK_EQ );

Referenced by exprAnalyze().

◆ exprCompareVariable()

static int exprCompareVariable ( Parse * pParse,
Expr * pVar,
Expr * pExpr )
static

Definition at line 104889 of file sqlite3.c.

104895 {
104896 int res = 0;
104897 int iVar;
104898 sqlite3_value *pL, *pR = 0;
104899
104900 sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, SQLITE_AFF_BLOB, &pR);
104901 if( pR ){
104902 iVar = pVar->iColumn;
104903 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar);
104905 if( pL ){
104906 if( sqlite3_value_type(pL)==SQLITE_TEXT ){
104907 sqlite3_value_text(pL); /* Make sure the encoding is UTF-8 */
104908 }
104909 res = 0==sqlite3MemCompare(pL, pR, 0);
104910 }
SQLITE_PRIVATE sqlite3_value * sqlite3VdbeGetBoundValue(Vdbe *, int, u8)
Definition sqlite3.c:82808
SQLITE_PRIVATE int sqlite3MemCompare(const Mem *, const Mem *, const CollSeq *)
Definition sqlite3.c:82056
#define SQLITE_TEXT
Definition sqlite3.c:5798
SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe *, int)
Definition sqlite3.c:82830
SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **)
Definition sqlite3.c:77458
Vdbe * pReprepare
Definition sqlite3.c:18760

References Parse::db, Expr::iColumn, Parse::pReprepare, Parse::pVdbe, sqlite3_value_text(), sqlite3_value_type(), sqlite3MemCompare(), sqlite3ValueFree(), sqlite3ValueFromExpr(), sqlite3VdbeGetBoundValue(), sqlite3VdbeSetVarmask(), SQLITE_AFF_BLOB, SQLITE_TEXT, and SQLITE_UTF8.

Referenced by sqlite3ExprCompare().

◆ exprDup()

static Expr * exprDup ( sqlite3 * db,
Expr * p,
int dupFlags,
u8 ** pzBuffer )
static

Definition at line 100981 of file sqlite3.c.

100987 {
100988 Expr *pNew; /* Value to return */
100989 u8 *zAlloc; /* Memory space from which to build Expr object */
100990 u32 staticFlag; /* EP_Static if space not obtained from malloc */
100991
100992 assert( db!=0 );
100993 assert( p );
100994 assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
100995 assert( pzBuffer==0 || dupFlags==EXPRDUP_REDUCE );
100996
100997 /* Figure out where to write the new Expr structure. */
100998 if( pzBuffer ){
100999 zAlloc = *pzBuffer;
101000 staticFlag = EP_Static;
101001 }else{
101002 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
101003 staticFlag = 0;
101004 }
101005 pNew = (Expr *)zAlloc;
101006
101007 if( pNew ){
101008 /* Set nNewSize to the size allocated for the structure pointed to
101009 ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
101010 ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
101011 ** by the copy of the p->u.zToken string (if any).
101012 */
101013 const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
101014 const int nNewSize = nStructSize & 0xfff;
101015 int nToken;
101016 if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
101017 nToken = sqlite3Strlen30(p->u.zToken) + 1;
101018 }else{
101019 nToken = 0;
101020 }
101021 if( dupFlags ){
101022 assert( ExprHasProperty(p, EP_Reduced)==0 );
101023 memcpy(zAlloc, p, nNewSize);
101024 }else{
101025 u32 nSize = (u32)exprStructSize(p);
101026 memcpy(zAlloc, p, nSize);
101027 if( nSize<EXPR_FULLSIZE ){
101028 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
101029 }
101030 }
101031
101032 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
101034 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
101035 pNew->flags |= staticFlag;
101037 if( dupFlags ){
101039 }
101040
101041 /* Copy the p->u.zToken string, if any. */
101042 if( nToken ){
101043 char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
101044 memcpy(zToken, p->u.zToken, nToken);
101045 }
101046
101047 if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){
101048 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
101049 if( ExprHasProperty(p, EP_xIsSelect) ){
101050 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
101051 }else{
101052 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
101053 }
101054 }
101055
101056 /* Fill in pNew->pLeft and pNew->pRight. */
101058 zAlloc += dupedExprNodeSize(p, dupFlags);
101059 if( !ExprHasProperty(pNew, EP_TokenOnly|EP_Leaf) ){
101060 pNew->pLeft = p->pLeft ?
101061 exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0;
101062 pNew->pRight = p->pRight ?
101063 exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0;
101064 }
101065#ifndef SQLITE_OMIT_WINDOWFUNC
101066 if( ExprHasProperty(p, EP_WinFunc) ){
101067 pNew->y.pWin = sqlite3WindowDup(db, pNew, p->y.pWin);
101068 assert( ExprHasProperty(pNew, EP_WinFunc) );
101069 }
101070#endif /* SQLITE_OMIT_WINDOWFUNC */
101071 if( pzBuffer ){
101072 *pzBuffer = zAlloc;
101073 }
101074 }else{
101076 if( pNew->op==TK_SELECT_COLUMN ){
101077 pNew->pLeft = p->pLeft;
101078 assert( p->iColumn==0 || p->pRight==0 );
101079 assert( p->pRight==0 || p->pRight==p->pLeft );
101080 }else{
101081 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
101082 }
SQLITE_PRIVATE Window * sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p)
Definition sqlite3.c:153473
static Expr * exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer)
Definition sqlite3.c:100981
static int exprStructSize(Expr *p)
Definition sqlite3.c:100870
static int dupedExprSize(Expr *p, int flags)
Definition sqlite3.c:100962
#define ExprClearVVAProperties(E)
Definition sqlite3.c:18127
#define EP_Static
Definition sqlite3.c:18087
static int dupedExprStructSize(Expr *p, int flags)
Definition sqlite3.c:100910
#define EP_Leaf
Definition sqlite3.c:18083
Window * pWin
Definition sqlite3.c:18045

References dupedExprNodeSize(), dupedExprSize(), dupedExprStructSize(), EP_Immutable, EP_IntValue, EP_Leaf, EP_MemToken, EP_Reduced, EP_Static, EP_TokenOnly, EP_WinFunc, EP_xIsSelect, EXPR_FULLSIZE, ExprClearVVAProperties, exprDup(), EXPRDUP_REDUCE, ExprHasProperty, ExprSetVVAProperty, exprStructSize(), Expr::flags, Expr::iColumn, Expr::op, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pSelect, Expr::pWin, sqlite3DbMallocRawNN(), sqlite3ExprDup(), sqlite3ExprListDup(), sqlite3SelectDup(), sqlite3Strlen30(), sqlite3WindowDup(), TK_SELECT_COLUMN, Expr::u, Expr::x, Expr::y, and Expr::zToken.

Referenced by exprDup(), and sqlite3ExprListDup().

◆ exprIdxCover()

static int exprIdxCover ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 105323 of file sqlite3.c.

105329 {
105330 if( pExpr->op==TK_COLUMN
105331 && pExpr->iTable==pWalker->u.pIdxCover->iCur
105332 && sqlite3TableColumnToIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0
Index * pIdx
Definition sqlite3.c:105314
struct IdxCover * pIdxCover
Definition sqlite3.c:19105

References Walker::eCode, Expr::iColumn, IdxCover::iCur, Expr::iTable, Expr::op, IdxCover::pIdx, Walker::pIdxCover, sqlite3TableColumnToIndex(), TK_COLUMN, Walker::u, WRC_Abort, and WRC_Continue.

Referenced by sqlite3ExprCoveredByIndex().

◆ exprImpliesNotNull()

static int exprImpliesNotNull ( Parse * pParse,
Expr * p,
Expr * pNN,
int iTab,
int seenNot )
static

Definition at line 105057 of file sqlite3.c.

105069 {
105070 assert( p );
105071 assert( pNN );
105072 if( sqlite3ExprCompare(pParse, p, pNN, iTab)==0 ){
105073 return pNN->op!=TK_NULL;
105074 }
105075 switch( p->op ){
105076 case TK_IN: {
105077 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
105078 assert( ExprHasProperty(p,EP_xIsSelect)
105079 || (p->x.pList!=0 && p->x.pList->nExpr>0) );
105080 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
105081 }
105082 case TK_BETWEEN: {
105083 ExprList *pList = p->x.pList;
105084 assert( pList!=0 );
105085 assert( pList->nExpr==2 );
105086 if( seenNot ) return 0;
105087 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
105088 || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1)
105089 ){
105090 return 1;
105091 }
105092 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
105093 }
105094 case TK_EQ:
105095 case TK_NE:
105096 case TK_LT:
105097 case TK_LE:
105098 case TK_GT:
105099 case TK_GE:
105100 case TK_PLUS:
105101 case TK_MINUS:
105102 case TK_BITOR:
105103 case TK_LSHIFT:
105104 case TK_RSHIFT:
105105 case TK_CONCAT:
105106 seenNot = 1;
105107 /* no break */ deliberate_fall_through
105108 case TK_STAR:
105109 case TK_REM:
105110 case TK_BITAND:
105111 case TK_SLASH: {
105112 if( exprImpliesNotNull(pParse, p->pRight, pNN, iTab, seenNot) ) return 1;
105113 /* no break */ deliberate_fall_through
105114 }
105115 case TK_SPAN:
105116 case TK_COLLATE:
105117 case TK_UPLUS:
105118 case TK_UMINUS: {
105119 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, seenNot);
105120 }
105121 case TK_TRUTH: {
105122 if( seenNot ) return 0;
105123 if( p->op2!=TK_IS ) return 0;
105124 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
105125 }
105126 case TK_BITNOT:
static int exprImpliesNotNull(Parse *pParse, Expr *p, Expr *pNN, int iTab, int seenNot)
Definition sqlite3.c:105057
#define TK_REM
Definition sqlite3.c:14051
#define TK_STAR
Definition sqlite3.c:14049
#define TK_SLASH
Definition sqlite3.c:14050
#define TK_UPLUS
Definition sqlite3.c:14113
#define TK_PLUS
Definition sqlite3.c:14047
#define TK_UMINUS
Definition sqlite3.c:14112
#define TK_SPAN
Definition sqlite3.c:14120
#define TK_RSHIFT
Definition sqlite3.c:14046
#define TK_BITAND
Definition sqlite3.c:14043
#define TK_CONCAT
Definition sqlite3.c:14052
#define TK_MINUS
Definition sqlite3.c:14048
#define TK_LSHIFT
Definition sqlite3.c:14045
#define TK_BITOR
Definition sqlite3.c:14044
#define TK_TRUTH
Definition sqlite3.c:14114
#define TK_BITNOT
Definition sqlite3.c:14054
#define deliberate_fall_through
Definition sqlite3.c:1008

References ExprList::a, deliberate_fall_through, EP_xIsSelect, ExprHasProperty, exprImpliesNotNull(), ExprList::nExpr, Expr::op, Expr::op2, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pRight, sqlite3ExprCompare(), TK_BETWEEN, TK_BITAND, TK_BITNOT, TK_BITOR, TK_COLLATE, TK_CONCAT, TK_EQ, TK_GE, TK_GT, TK_IN, TK_IS, TK_LE, TK_LSHIFT, TK_LT, TK_MINUS, TK_NE, TK_NOT, TK_NULL, TK_PLUS, TK_REM, TK_RSHIFT, TK_SLASH, TK_SPAN, TK_STAR, TK_TRUTH, TK_UMINUS, TK_UPLUS, and Expr::x.

Referenced by exprImpliesNotNull(), and sqlite3ExprImpliesExpr().

◆ exprINAffinity()

static char * exprINAffinity ( Parse * pParse,
Expr * pExpr )
static

Definition at line 102452 of file sqlite3.c.

102458 {
102459 Expr *pLeft = pExpr->pLeft;
102460 int nVal = sqlite3ExprVectorSize(pLeft);
102461 Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
102462 char *zRet;
102463
102464 assert( pExpr->op==TK_IN );
102465 zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
102466 if( zRet ){
102467 int i;
102468 for(i=0; i<nVal; i++){
102469 Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
102470 char a = sqlite3ExprAffinity(pA);
102471 if( pSelect ){
102472 zRet[i] = sqlite3CompareAffinity(pSelect->pEList->a[i].pExpr, a);
102473 }else{
102474 zRet[i] = a;
SQLITE_PRIVATE Expr * sqlite3VectorFieldSubexpr(Expr *, int)
Definition sqlite3.c:100153

References ExprList::a, Parse::db, EP_xIsSelect, Expr::flags, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pSelect, sqlite3CompareAffinity(), sqlite3DbMallocRaw(), sqlite3ExprAffinity(), sqlite3ExprVectorSize(), sqlite3VectorFieldSubexpr(), TK_IN, and Expr::x.

Referenced by sqlite3CodeRhsOfIN(), and sqlite3ExprCodeIN().

◆ exprIsConst()

static int exprIsConst ( Expr * p,
int initFlag,
int iCur )
static

Definition at line 101782 of file sqlite3.c.

101782 :
101783 testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail() disallows */
101784 testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail() disallows */
101785 return WRC_Continue;
101786 }
101787}
101788static int exprIsConst(Expr *p, int initFlag, int iCur){
101789 Walker w;
101790 w.eCode = initFlag;
101793#ifdef SQLITE_DEBUG
SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *, Select *)
Definition sqlite3.c:101605
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:101710
static int exprIsConst(Expr *p, int initFlag, int iCur)
Definition sqlite3.c:101782
#define TK_EXISTS
Definition sqlite3.c:13962
int(* xExprCallback)(Walker *, Expr *)
Definition sqlite3.c:19092
int(* xSelectCallback)(Walker *, Select *)
Definition sqlite3.c:19093

Referenced by sqlite3ExprIsConstant(), sqlite3ExprIsConstantNotJoin(), sqlite3ExprIsConstantOrFunction(), and sqlite3ExprIsTableConstant().

◆ exprIsDeterministic()

static int exprIsDeterministic ( Expr * p)
static

Definition at line 150175 of file sqlite3.c.

150181 {
150182 Walker w;
150183 memset(&w, 0, sizeof(w));

References Walker::eCode, exprNodeIsDeterministic(), sqlite3SelectWalkFail(), sqlite3WalkExpr(), Walker::xExprCallback, and Walker::xSelectCallback.

Referenced by sqlite3WhereBegin().

◆ exprListAppendList()

static ExprList * exprListAppendList ( Parse * pParse,
ExprList * pList,
ExprList * pAppend,
int bIntToNull )
static

Definition at line 152049 of file sqlite3.c.

152060 {
152061 if( pAppend ){
152062 int i;
152063 int nInit = pList ? pList->nExpr : 0;
152064 for(i=0; i<pAppend->nExpr; i++){
152065 Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
152066 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
152067 if( bIntToNull && pDup ){
152068 int iDummy;
152069 Expr *pSub;
152070 for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){
152071 assert( pSub );
152072 }
152073 if( sqlite3ExprIsInteger(pSub, &iDummy) ){
152074 pSub->op = TK_NULL;
152076 pSub->u.zToken = 0;
152077 }
152078 }
#define EP_IsFalse
Definition sqlite3.c:18089
#define EP_IsTrue
Definition sqlite3.c:18088
#define EP_Skip
Definition sqlite3.c:18072

Referenced by sqlite3WindowRewrite().

◆ exprListDeleteNN()

static SQLITE_NOINLINE void exprListDeleteNN ( sqlite3 * db,
ExprList * pList )
static

Definition at line 101567 of file sqlite3.c.

101573 {
101574 int i = pList->nExpr;
101575 struct ExprList_item *pItem = pList->a;
101576 assert( pList->nExpr>0 );
101577 do{

◆ exprMightBeIndexed()

static int exprMightBeIndexed ( SrcList * pFrom,
Bitmask mPrereq,
int * aiCurCol,
Expr * pExpr,
int op )
static

Definition at line 144973 of file sqlite3.c.

144985 {
144986 /* If this expression is a vector to the left or right of a
144987 ** inequality constraint (>, <, >= or <=), perform the processing
144988 ** on the first element of the vector. */
144989 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
144990 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
144991 assert( op<=TK_GE );
144992 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
144993 pExpr = pExpr->x.pList->a[0].pExpr;
144994 }
144995
144996 if( pExpr->op==TK_COLUMN ){
144997 aiCurCol[0] = pExpr->iTable;
144998 aiCurCol[1] = pExpr->iColumn;

Referenced by exprAnalyze().

◆ exprMightBeIndexed2()

static SQLITE_NOINLINE int exprMightBeIndexed2 ( SrcList * pFrom,
Bitmask mPrereq,
int * aiCurCol,
Expr * pExpr )
static

Definition at line 144949 of file sqlite3.c.

144960 {
144961 Index *pIdx;
144962 int i;
144963 int iCur;
144964 for(i=0; mPrereq>1; i++, mPrereq>>=1){}
144965 iCur = pFrom->a[i].iCursor;
144966 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
144967 if( pIdx->aColExpr==0 ) continue;
144968 for(i=0; i<pIdx->nKeyCol; i++){
144969 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
144970 if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
144971 aiCurCol[0] = iCur;
144972 aiCurCol[1] = XN_EXPR;
SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr *, Expr *, int)
Definition sqlite3.c:105044
ExprList * aColExpr
Definition sqlite3.c:17787

References ExprList::a, SrcList::a, Index::aColExpr, Index::aiColumn, SrcList::SrcList_item::iCursor, Index::nKeyCol, ExprList::ExprList_item::pExpr, Table::pIndex, Index::pNext, SrcList::SrcList_item::pTab, sqlite3ExprCompareSkip(), and XN_EXPR.

◆ exprNodeIsConstant()

static int exprNodeIsConstant ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 101710 of file sqlite3.c.

101716 {
101717
101718 /* If pWalker->eCode is 2 then any term of the expression that comes from
101719 ** the ON or USING clauses of a left join disqualifies the expression
101720 ** from being considered constant. */
101721 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
101722 pWalker->eCode = 0;
101723 return WRC_Abort;
101724 }
101725
101726 switch( pExpr->op ){
101727 /* Consider functions to be constant if all their arguments are constant
101728 ** and either pWalker->eCode==4 or 5 or the function has the
101729 ** SQLITE_FUNC_CONST flag. */
101730 case TK_FUNCTION:
101731 if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc))
101732 && !ExprHasProperty(pExpr, EP_WinFunc)
101733 ){
101734 if( pWalker->eCode==5 ) ExprSetProperty(pExpr, EP_FromDDL);
101735 return WRC_Continue;
101736 }else{
101737 pWalker->eCode = 0;
101738 return WRC_Abort;
101739 }
101740 case TK_ID:
101741 /* Convert "true" or "false" in a DEFAULT clause into the
101742 ** appropriate TK_TRUEFALSE operator */
101743 if( sqlite3ExprIdToTrueFalse(pExpr) ){
101744 return WRC_Prune;
101745 }
101746 /* no break */ deliberate_fall_through
101747 case TK_COLUMN:
101748 case TK_AGG_FUNCTION:
101749 case TK_AGG_COLUMN:
101750 testcase( pExpr->op==TK_ID );
101751 testcase( pExpr->op==TK_COLUMN );
101752 testcase( pExpr->op==TK_AGG_FUNCTION );
101753 testcase( pExpr->op==TK_AGG_COLUMN );
101754 if( ExprHasProperty(pExpr, EP_FixedCol) && pWalker->eCode!=2 ){
101755 return WRC_Continue;
101756 }
101757 if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
101758 return WRC_Continue;
101759 }
101760 /* no break */ deliberate_fall_through
101761 case TK_IF_NULL_ROW:
101762 case TK_REGISTER:
101763 case TK_DOT:
101764 testcase( pExpr->op==TK_REGISTER );
101765 testcase( pExpr->op==TK_IF_NULL_ROW );
101766 testcase( pExpr->op==TK_DOT );
101767 pWalker->eCode = 0;
101768 return WRC_Abort;
101769 case TK_VARIABLE:
101770 if( pWalker->eCode==5 ){
101771 /* Silently convert bound parameters that appear inside of CREATE
101772 ** statements into a NULL when parsing the CREATE statement text out
101773 ** of the sqlite_schema table */
101774 pExpr->op = TK_NULL;
101775 }else if( pWalker->eCode==4 ){
101776 /* A bound parameter in a CREATE statement that originates from
101777 ** sqlite3_prepare() causes an error */
101778 pWalker->eCode = 0;
101779 return WRC_Abort;
101780 }
101781 /* no break */ deliberate_fall_through
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *)
Definition sqlite3.c:101631
#define TK_IF_NULL_ROW
Definition sqlite3.c:14118
#define TK_FUNCTION
Definition sqlite3.c:14111
#define EP_ConstFunc
Definition sqlite3.c:18079
#define TK_DOT
Definition sqlite3.c:14081
#define TK_REGISTER
Definition sqlite3.c:14115
#define TK_VARIABLE
Definition sqlite3.c:14095
#define EP_FromDDL
Definition sqlite3.c:18090
int iCur
Definition sqlite3.c:19100

References deliberate_fall_through, Walker::eCode, EP_ConstFunc, EP_FixedCol, EP_FromDDL, EP_FromJoin, EP_WinFunc, ExprHasProperty, ExprSetProperty, Walker::iCur, Expr::iTable, Expr::op, sqlite3ExprIdToTrueFalse(), testcase, TK_AGG_COLUMN, TK_AGG_FUNCTION, TK_COLUMN, TK_DOT, TK_FUNCTION, TK_ID, TK_IF_NULL_ROW, TK_NULL, TK_REGISTER, TK_VARIABLE, Walker::u, WRC_Abort, WRC_Continue, and WRC_Prune.

◆ exprNodeIsConstantOrGroupBy()

static int exprNodeIsConstantOrGroupBy ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 101838 of file sqlite3.c.

101844 {
101845 ExprList *pGroupBy = pWalker->u.pGroupBy;
101846 int i;
101847
101848 /* Check if pExpr is identical to any GROUP BY term. If so, consider
101849 ** it constant. */
101850 for(i=0; i<pGroupBy->nExpr; i++){
101851 Expr *p = pGroupBy->a[i].pExpr;
101852 if( sqlite3ExprCompare(0, pExpr, p, -1)<2 ){
101853 CollSeq *pColl = sqlite3ExprNNCollSeq(pWalker->pParse, p);
101854 if( sqlite3IsBinary(pColl) ){
101855 return WRC_Prune;
101856 }
101857 }
101858 }
101859
101860 /* Check if pExpr is a sub-select. If so, consider it variable. */
101861 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
SQLITE_PRIVATE CollSeq * sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr)
Definition sqlite3.c:99938
ExprList * pGroupBy
Definition sqlite3.c:19107

Referenced by sqlite3ExprIsConstantOrGroupBy().

◆ exprNodeIsDeterministic()

static int exprNodeIsDeterministic ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 150162 of file sqlite3.c.

150168 {

Referenced by exprIsDeterministic().

◆ exprProbability()

static int exprProbability ( Expr * p)
static

Definition at line 98468 of file sqlite3.c.

98474 {
98475 double r = -1.0;

References Expr::op, sqlite3AtoF(), sqlite3Strlen30(), SQLITE_UTF8, TK_FLOAT, Expr::u, and Expr::zToken.

Referenced by resolveExprStep().

◆ exprRowColumn()

static Expr * exprRowColumn ( Parse * pParse,
int iCol )
static

Definition at line 137734 of file sqlite3.c.

References Expr::iColumn, sqlite3PExpr(), and TK_ROW.

Referenced by updateFromSelect(), and updateVirtualTable().

◆ exprSelectUsage()

static Bitmask exprSelectUsage ( WhereMaskSet * pMaskSet,
Select * pS )
static

Definition at line 144912 of file sqlite3.c.

144918 {
144919 Bitmask mask = 0;
144920 while( pS ){
144921 SrcList *pSrc = pS->pSrc;
144922 mask |= sqlite3WhereExprListUsage(pMaskSet, pS->pEList);
144923 mask |= sqlite3WhereExprListUsage(pMaskSet, pS->pGroupBy);
144924 mask |= sqlite3WhereExprListUsage(pMaskSet, pS->pOrderBy);
144925 mask |= sqlite3WhereExprUsage(pMaskSet, pS->pWhere);
144926 mask |= sqlite3WhereExprUsage(pMaskSet, pS->pHaving);
144927 if( ALWAYS(pSrc!=0) ){
144928 int i;
144929 for(i=0; i<pSrc->nSrc; i++){
144930 mask |= exprSelectUsage(pMaskSet, pSrc->a[i].pSelect);
144931 mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].pOn);
144932 if( pSrc->a[i].fg.isTabFunc ){
144933 mask |= sqlite3WhereExprListUsage(pMaskSet, pSrc->a[i].u1.pFuncArg);
144934 }
#define mask(n)
union SrcList::SrcList_item::@114 u1
struct SrcList::SrcList_item::@113 fg

References SrcList::a, ALWAYS, exprSelectUsage(), SrcList::SrcList_item::fg, SrcList::SrcList_item::isTabFunc, mask, SrcList::nSrc, Select::pEList, SrcList::SrcList_item::pFuncArg, Select::pGroupBy, Select::pHaving, SrcList::SrcList_item::pOn, Select::pOrderBy, Select::pPrior, SrcList::SrcList_item::pSelect, Select::pSrc, Select::pWhere, sqlite3WhereExprListUsage(), sqlite3WhereExprUsage(), and SrcList::SrcList_item::u1.

Referenced by exprAnalyze(), exprSelectUsage(), and sqlite3WhereExprUsageNN().

◆ exprSetHeight()

static void exprSetHeight ( Expr * p)
static

Definition at line 100437 of file sqlite3.c.

100443 {
100444 int nHeight = 0;
100445 heightOfExpr(p->pLeft, &nHeight);
100446 heightOfExpr(p->pRight, &nHeight);
100447 if( ExprHasProperty(p, EP_xIsSelect) ){
100448 heightOfSelect(p->x.pSelect, &nHeight);
static void heightOfExpr(Expr *p, int *pnHeight)
Definition sqlite3.c:100400
static void heightOfSelect(Select *pSelect, int *pnHeight)
Definition sqlite3.c:100415

References EP_Propagate, EP_xIsSelect, ExprHasProperty, Expr::flags, heightOfExpr(), heightOfExprList(), heightOfSelect(), Expr::nHeight, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pSelect, sqlite3ExprListFlags(), and Expr::x.

Referenced by sqlite3ExprAttachSubtrees(), and sqlite3ExprSetHeightAndFlags().

◆ exprSrcCount()

static int exprSrcCount ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 105391 of file sqlite3.c.

105397 {
105398 /* There was once a NEVER() on the second term on the grounds that
105399 ** sqlite3FunctionUsesThisSrc() was always called before
105400 ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet
105401 ** been converted into TK_AGG_COLUMN. But this is no longer true due
105402 ** to window functions - sqlite3WindowRewrite() may now indirectly call
105403 ** FunctionUsesThisSrc() when creating a new sub-select. */
105404 if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){
105405 int i;
105406 struct SrcCount *p = pWalker->u.pSrcCount;
105407 SrcList *pSrc = p->pSrc;
105408 int nSrc = pSrc ? pSrc->nSrc : 0;
105409 for(i=0; i<nSrc; i++){
105410 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
105411 }
105412 if( i<nSrc ){
105413 p->nThis++;
105414 }else if( pExpr->iTable<p->iSrcInner ){
105415 /* In a well-formed parse tree (no name resolution errors),
105416 ** TK_COLUMN nodes with smaller Expr.iTable values are in an
int iSrcInner
Definition sqlite3.c:105369
SrcList * pSrc
Definition sqlite3.c:105368
struct SrcCount * pSrcCount
Definition sqlite3.c:19102

Referenced by sqlite3FunctionUsesThisSrc().

◆ exprStructSize()

static int exprStructSize ( Expr * p)
static

Definition at line 100870 of file sqlite3.c.

References EP_Reduced, EP_TokenOnly, EXPR_FULLSIZE, EXPR_REDUCEDSIZE, EXPR_TOKENONLYSIZE, and ExprHasProperty.

Referenced by exprDup().

◆ exprTableColumn()

static Expr * exprTableColumn ( sqlite3 * db,
Table * pTab,
int iCursor,
i16 iCol )
static

Definition at line 119598 of file sqlite3.c.

119609 {
119610 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
119611 if( pExpr ){

Referenced by fkScanChildren().

◆ exprTableRegister()

static Expr * exprTableRegister ( Parse * pParse,
Table * pTab,
int regBase,
i16 iCol )
static

Definition at line 119566 of file sqlite3.c.

119577 {
119578 Expr *pExpr;
119579 Column *pCol;
119580 const char *zColl;
119581 sqlite3 *db = pParse->db;
119582
119583 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
119584 if( pExpr ){
119585 if( iCol>=0 && iCol!=pTab->iPKey ){
119586 pCol = &pTab->aCol[iCol];
119587 pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1;
119588 pExpr->affExpr = pCol->affinity;
119589 zColl = pCol->zColl;
119590 if( zColl==0 ) zColl = db->pDfltColl->zName;
119591 pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
119592 }else{
char * zColl
Definition sqlite3.c:17334
char affExpr
Definition sqlite3.c:17995
CollSeq * pDfltColl
Definition sqlite3.c:16822

References Table::aCol, Expr::affExpr, Column::affinity, Parse::db, Table::iPKey, Expr::iTable, sqlite3::pDfltColl, sqlite3Expr(), sqlite3ExprAddCollateString(), sqlite3TableColumnToStorage(), SQLITE_AFF_INTEGER, TK_REGISTER, Column::zColl, and CollSeq::zName.

Referenced by fkScanChildren().

◆ exprToRegister()

static void exprToRegister ( Expr * pExpr,
int iReg )
static

◆ exprVectorRegister()

static int exprVectorRegister ( Parse * pParse,
Expr * pVector,
int iField,
int regSelect,
Expr ** ppExpr,
int * pRegFree )
static

Definition at line 100261 of file sqlite3.c.

100274 {
100275 u8 op = pVector->op;
100276 assert( op==TK_VECTOR || op==TK_REGISTER || op==TK_SELECT );
100277 if( op==TK_REGISTER ){
100278 *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
100279 return pVector->iTable+iField;
100280 }
100281 if( op==TK_SELECT ){

References ExprList::a, Expr::iTable, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pList, Expr::pSelect, sqlite3ExprCodeTemp(), sqlite3VectorFieldSubexpr(), TK_REGISTER, TK_SELECT, TK_VECTOR, and Expr::x.

Referenced by codeVectorCompare().

◆ fcntlSizeHint()

static int fcntlSizeHint ( unixFile * pFile,
i64 nByte )
static

Definition at line 37393 of file sqlite3.c.

37399 {
37400 if( pFile->szChunk>0 ){
37401 i64 nSize; /* Required file size */
37402 struct stat buf; /* Used to hold return values of fstat() */
37403
37404 if( osFstat(pFile->h, &buf) ){
37405 return SQLITE_IOERR_FSTAT;
37406 }
37407
37408 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
37409 if( nSize>(i64)buf.st_size ){
37410
37411#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
37412 /* The code below is handling the return value of osFallocate()
37413 ** correctly. posix_fallocate() is defined to "returns zero on success,
37414 ** or an error number on failure". See the manpage for details. */
37415 int err;
37416 do{
37417 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
37418 }while( err==EINTR );
37419 if( err && err!=EINVAL ) return SQLITE_IOERR_WRITE;
37420#else
37421 /* If the OS does not have posix_fallocate(), fake it. Write a
37422 ** single byte to the last byte in each block that falls entirely
37423 ** within the extended region. Then, if required, a single byte
37424 ** at offset (nSize-1), to set the size of the file correctly.
37425 ** This is a similar technique to that used by glibc on systems
37426 ** that do not have a real fallocate() call.
37427 */
37428 int nBlk = buf.st_blksize; /* File-system block size */
37429 int nWrite = 0; /* Number of bytes written by seekAndWrite */
37430 i64 iWrite; /* Next offset to write to */
37431
37432 iWrite = (buf.st_size/nBlk)*nBlk + nBlk - 1;
37433 assert( iWrite>=buf.st_size );
37434 assert( ((iWrite+1)%nBlk)==0 );
37435 for(/*no-op*/; iWrite<nSize+nBlk-1; iWrite+=nBlk ){
37436 if( iWrite>=nSize ) iWrite = nSize - 1;
37437 nWrite = seekAndWrite(pFile, iWrite, "", 1);
37438 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
37439 }
37440#endif
37441 }
37442 }
37443
37444#if SQLITE_MAX_MMAP_SIZE>0
37445 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
37446 int rc;
37447 if( pFile->szChunk<=0 ){
37448 if( robust_ftruncate(pFile->h, nByte) ){
37449 storeLastErrno(pFile, errno);
37450 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
37451 }
37452 }
37453
37454 rc = unixMapfile(pFile, nByte);
static int robust_ftruncate(int h, sqlite3_int64 sz)
Definition sqlite3.c:34379
#define osFstat
#define unixLogError(a, b, c)
Definition sqlite3.c:34762
#define osFallocate
#define SQLITE_IOERR_WRITE
Definition sqlite3.c:1525
#define SQLITE_IOERR_TRUNCATE
Definition sqlite3.c:1528
#define SQLITE_IOERR_FSTAT
Definition sqlite3.c:1529
static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt)
Definition sqlite3.c:36978
int szChunk
Definition sqlite3.c:33574

References unixFile::h, osFallocate, osFstat, robust_ftruncate(), seekAndWrite(), SQLITE_IOERR_FSTAT, SQLITE_IOERR_TRUNCATE, SQLITE_IOERR_WRITE, SQLITE_OK, storeLastErrno(), unixFile::szChunk, unixLogError, and unixFile::zPath.

◆ fetchPayload()

static const void * fetchPayload ( BtCursor * pCur,
u32 * pAmt )
static

Definition at line 69518 of file sqlite3.c.

69527 {
69528 int amt;
69529 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
69530 assert( pCur->eState==CURSOR_VALID );
69531 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
69532 assert( cursorOwnsBtShared(pCur) );
69533 assert( pCur->ix<pCur->pPage->nCell );
69534 assert( pCur->info.nSize>0 );
69535 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
69536 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
69537 amt = pCur->info.nLocal;
69538 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
69539 /* There is too little space on the page for the expected amount
69540 ** of local content. Database must be corrupt. */

References MemPage::aData, MemPage::aDataEnd, CORRUPT_DB, CURSOR_VALID, Btree::db, BtCursor::eState, BtCursor::info, BtCursor::iPage, BtCursor::ix, MAX, sqlite3::mutex, MemPage::nCell, CellInfo::nLocal, CellInfo::nSize, BtCursor::pBtree, BtCursor::pPage, CellInfo::pPayload, and sqlite3_mutex_held().

Referenced by sqlite3BtreePayloadFetch().

◆ fileHasMoved()

static int fileHasMoved ( unixFile * pFile)
static

Definition at line 34994 of file sqlite3.c.

35000 {
35001#if OS_VXWORKS
35002 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
35003#else
struct unixFileId fileId
Definition sqlite3.c:34703

Referenced by verifyDbFile().

◆ fillInCell()

static int fillInCell ( MemPage * pPage,
unsigned char * pCell,
const BtreePayload * pX,
int * pnSize )
static

Definition at line 70938 of file sqlite3.c.

70949 {
70950 int nPayload;
70951 const u8 *pSrc;
70952 int nSrc, n, rc, mn;
70953 int spaceLeft;
70954 MemPage *pToRelease;
70955 unsigned char *pPrior;
70956 unsigned char *pPayload;
70957 BtShared *pBt;
70958 Pgno pgnoOvfl;
70959 int nHeader;
70960
70961 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
70962
70963 /* pPage is not necessarily writeable since pCell might be auxiliary
70964 ** buffer space that is separate from the pPage buffer area */
70965 assert( pCell<pPage->aData || pCell>=&pPage->aData[pPage->pBt->pageSize]
70966 || sqlite3PagerIswriteable(pPage->pDbPage) );
70967
70968 /* Fill in the header. */
70969 nHeader = pPage->childPtrSize;
70970 if( pPage->intKey ){
70971 nPayload = pX->nData + pX->nZero;
70972 pSrc = pX->pData;
70973 nSrc = pX->nData;
70974 assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */
70975 nHeader += putVarint32(&pCell[nHeader], nPayload);
70976 nHeader += putVarint(&pCell[nHeader], *(u64*)&pX->nKey);
70977 }else{
70978 assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
70979 nSrc = nPayload = (int)pX->nKey;
70980 pSrc = pX->pKey;
70981 nHeader += putVarint32(&pCell[nHeader], nPayload);
70982 }
70983
70984 /* Fill in the payload */
70985 pPayload = &pCell[nHeader];
70986 if( nPayload<=pPage->maxLocal ){
70987 /* This is the common case where everything fits on the btree page
70988 ** and no overflow pages are required. */
70989 n = nHeader + nPayload;
70990 testcase( n==3 );
70991 testcase( n==4 );
70992 if( n<4 ) n = 4;
70993 *pnSize = n;
70994 assert( nSrc<=nPayload );
70995 testcase( nSrc<nPayload );
70996 memcpy(pPayload, pSrc, nSrc);
70997 memset(pPayload+nSrc, 0, nPayload-nSrc);
70998 return SQLITE_OK;
70999 }
71000
71001 /* If we reach this point, it means that some of the content will need
71002 ** to spill onto overflow pages.
71003 */
71004 mn = pPage->minLocal;
71005 n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
71006 testcase( n==pPage->maxLocal );
71007 testcase( n==pPage->maxLocal+1 );
71008 if( n > pPage->maxLocal ) n = mn;
71009 spaceLeft = n;
71010 *pnSize = n + nHeader + 4;
71011 pPrior = &pCell[nHeader+n];
71012 pToRelease = 0;
71013 pgnoOvfl = 0;
71014 pBt = pPage->pBt;
71015
71016 /* At this point variables should be set as follows:
71017 **
71018 ** nPayload Total payload size in bytes
71019 ** pPayload Begin writing payload here
71020 ** spaceLeft Space available at pPayload. If nPayload>spaceLeft,
71021 ** that means content must spill into overflow pages.
71022 ** *pnSize Size of the local cell (not counting overflow pages)
71023 ** pPrior Where to write the pgno of the first overflow page
71024 **
71025 ** Use a call to btreeParseCellPtr() to verify that the values above
71026 ** were computed correctly.
71027 */
71028#ifdef SQLITE_DEBUG
71029 {
71030 CellInfo info;
71031 pPage->xParseCell(pPage, pCell, &info);
71032 assert( nHeader==(int)(info.pPayload - pCell) );
71033 assert( info.nKey==pX->nKey );
71034 assert( *pnSize == info.nSize );
71035 assert( spaceLeft == info.nLocal );
71036 }
71037#endif
71038
71039 /* Write the payload into the local Cell and any extra into overflow pages */
71040 while( 1 ){
71041 n = nPayload;
71042 if( n>spaceLeft ) n = spaceLeft;
71043
71044 /* If pToRelease is not zero than pPayload points into the data area
71045 ** of pToRelease. Make sure pToRelease is still writeable. */
71046 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
71047
71048 /* If pPayload is part of the data area of pPage, then make sure pPage
71049 ** is still writeable */
71050 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
71051 || sqlite3PagerIswriteable(pPage->pDbPage) );
71052
71053 if( nSrc>=n ){
71054 memcpy(pPayload, pSrc, n);
71055 }else if( nSrc>0 ){
71056 n = nSrc;
71057 memcpy(pPayload, pSrc, n);
71058 }else{
71059 memset(pPayload, 0, n);
71060 }
71061 nPayload -= n;
71062 if( nPayload<=0 ) break;
71063 pPayload += n;
71064 pSrc += n;
71065 nSrc -= n;
71066 spaceLeft -= n;
71067 if( spaceLeft==0 ){
71068 MemPage *pOvfl = 0;
71069#ifndef SQLITE_OMIT_AUTOVACUUM
71070 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
71071 if( pBt->autoVacuum ){
71072 do{
71073 pgnoOvfl++;
71074 } while(
71075 PTRMAP_ISPAGE(pBt, pgnoOvfl) || pgnoOvfl==PENDING_BYTE_PAGE(pBt)
71076 );
71077 }
71078#endif
71079 rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
71080#ifndef SQLITE_OMIT_AUTOVACUUM
71081 /* If the database supports auto-vacuum, and the second or subsequent
71082 ** overflow page is being allocated, add an entry to the pointer-map
71083 ** for that page now.
71084 **
71085 ** If this is the first overflow page, then write a partial entry
71086 ** to the pointer-map. If we write nothing to this pointer-map slot,
71087 ** then the optimistic overflow chain processing in clearCell()
71088 ** may misinterpret the uninitialized values and delete the
71089 ** wrong pages from the database.
71090 */
71091 if( pBt->autoVacuum && rc==SQLITE_OK ){
71093 ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
71094 if( rc ){
71095 releasePage(pOvfl);
71096 }
71097 }
71098#endif
71099 if( rc ){
71100 releasePage(pToRelease);
71101 return rc;
71102 }
71103
71104 /* If pToRelease is not zero than pPrior points into the data area
71105 ** of pToRelease. Make sure pToRelease is still writeable. */
71106 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
71107
71108 /* If pPrior is part of the data area of pPage, then make sure pPage
71109 ** is still writeable */
71110 assert( pPrior<pPage->aData || pPrior>=&pPage->aData[pBt->pageSize]
71111 || sqlite3PagerIswriteable(pPage->pDbPage) );
71112
71113 put4byte(pPrior, pgnoOvfl);
71114 releasePage(pToRelease);
71115 pToRelease = pOvfl;
71116 pPrior = pOvfl->aData;
71117 put4byte(pPrior, 0);
71118 pPayload = &pOvfl->aData[4];
#define putVarint32(A, B)
Definition sqlite3.c:19872
const void * pKey
Definition sqlite3.c:15289
sqlite3_int64 nKey
Definition sqlite3.c:15290

References MemPage::aData, allocateBtreePage(), BtShared::autoVacuum, MemPage::childPtrSize, eType, MemPage::intKey, MemPage::intKeyLeaf, MemPage::maxLocal, MemPage::minLocal, BtShared::mutex, BtreePayload::nData, BtreePayload::nKey, CellInfo::nKey, CellInfo::nLocal, CellInfo::nSize, BtreePayload::nZero, BtShared::pageSize, MemPage::pBt, BtreePayload::pData, MemPage::pDbPage, PENDING_BYTE_PAGE, BtreePayload::pKey, CellInfo::pPayload, PTRMAP_ISPAGE, PTRMAP_OVERFLOW1, PTRMAP_OVERFLOW2, ptrmapPut(), put4byte, putVarint, putVarint32, releasePage(), sqlite3_mutex_held(), SQLITE_OK, testcase, BtShared::usableSize, and MemPage::xParseCell.

Referenced by sqlite3BtreeInsert().

◆ finalDbSize()

static Pgno finalDbSize ( BtShared * pBt,
Pgno nOrig,
Pgno nFree )
static

Definition at line 68326 of file sqlite3.c.

68332 {
68333 int nEntry; /* Number of entries on one ptrmap page */
68334 Pgno nPtrmap; /* Number of PtrMap pages to be freed */
68335 Pgno nFin; /* Return value */
68336
68337 nEntry = pBt->usableSize/5;
68338 nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+nEntry)/nEntry;
68339 nFin = nOrig - nFree - nPtrmap;
68340 if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<PENDING_BYTE_PAGE(pBt) ){
68341 nFin--;
68342 }

References PENDING_BYTE_PAGE, PTRMAP_ISPAGE, PTRMAP_PAGENO, and BtShared::usableSize.

Referenced by autoVacuumCommit(), and sqlite3BtreeIncrVacuum().

◆ finalizeAggFunctions()

static void finalizeAggFunctions ( Parse * pParse,
AggInfo * pAggInfo )
static

Definition at line 134730 of file sqlite3.c.

134736 {
134737 Vdbe *v = pParse->pVdbe;
134738 int i;
134739 struct AggInfo_func *pF;
134740 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){

Referenced by sqlite3Select().

◆ findBtree()

static Btree * findBtree ( sqlite3 * pErrorDb,
sqlite3 * pDb,
const char * zDb )
static

Definition at line 75132 of file sqlite3.c.

75138 {
75139 int i = sqlite3FindDbName(pDb, zDb);
75140
75141 if( i==1 ){
75142 Parse sParse;
75143 int rc = 0;
75144 memset(&sParse, 0, sizeof(sParse));
75145 sParse.db = pDb;
75146 if( sqlite3OpenTempDatabase(&sParse) ){
75147 sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
75148 rc = SQLITE_ERROR;
75149 }
75150 sqlite3DbFree(pErrorDb, sParse.zErrMsg);
75151 sqlite3ParserReset(&sParse);
75152 if( rc ){
75153 return 0;
75154 }
75155 }
75156
75157 if( i<0 ){
SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *)
Definition sqlite3.c:111172
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *)
Definition sqlite3.c:115091
SQLITE_PRIVATE void sqlite3ParserReset(Parse *)
Definition sqlite3.c:128891
char * zErrMsg
Definition sqlite3.c:18681

References sqlite3::aDb, Parse::db, Db::pBt, Parse::rc, sqlite3DbFree(), sqlite3ErrorWithMsg(), sqlite3FindDbName(), sqlite3OpenTempDatabase(), sqlite3ParserReset(), SQLITE_ERROR, and Parse::zErrMsg.

Referenced by sqlite3_backup_init().

◆ findCollSeqEntry()

static CollSeq * findCollSeqEntry ( sqlite3 * db,
const char * zName,
int create )
static

Definition at line 115643 of file sqlite3.c.

115653 {
115654 CollSeq *pColl;
115655 pColl = sqlite3HashFind(&db->aCollSeq, zName);
115656
115657 if( 0==pColl && create ){
115658 int nName = sqlite3Strlen30(zName) + 1;
115659 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName);
115660 if( pColl ){
115661 CollSeq *pDel = 0;
115662 pColl[0].zName = (char*)&pColl[3];
115663 pColl[0].enc = SQLITE_UTF8;
115664 pColl[1].zName = (char*)&pColl[3];
115665 pColl[1].enc = SQLITE_UTF16LE;
115666 pColl[2].zName = (char*)&pColl[3];
115667 pColl[2].enc = SQLITE_UTF16BE;
115668 memcpy(pColl[0].zName, zName, nName);
115669 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
115670
115671 /* If a malloc() failure occurred in sqlite3HashInsert(), it will
115672 ** return the pColl pointer to be deleted (because it wasn't added
115673 ** to the hash table).
115674 */
115675 assert( pDel==0 || pDel==pColl );
115676 if( pDel!=0 ){
115677 sqlite3OomFault(db);
115678 sqlite3DbFree(db, pDel);
u8 nName
Definition sqlite3.c:22328
#define SQLITE_UTF16LE
Definition sqlite3.c:6253

References sqlite3::aCollSeq, CollSeq::enc, nName, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3HashFind(), sqlite3HashInsert(), sqlite3OomFault(), sqlite3Strlen30(), SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, CollSeq::zName, and zName.

Referenced by sqlite3FindCollSeq().

◆ findConstInWhere()

static void findConstInWhere ( WhereConst * pConst,
Expr * pExpr )
static

Definition at line 133557 of file sqlite3.c.

133563 {
133564 Expr *pRight, *pLeft;
133565 if( pExpr==0 ) return;
133566 if( ExprHasProperty(pExpr, EP_FromJoin) ) return;
133567 if( pExpr->op==TK_AND ){
133568 findConstInWhere(pConst, pExpr->pRight);
133569 findConstInWhere(pConst, pExpr->pLeft);
133570 return;
133571 }
133572 if( pExpr->op!=TK_EQ ) return;
133573 pRight = pExpr->pRight;
133574 pLeft = pExpr->pLeft;
133575 assert( pRight!=0 );
133576 assert( pLeft!=0 );
133577 if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){
static void findConstInWhere(WhereConst *pConst, Expr *pExpr)
Definition sqlite3.c:133557

References constInsert(), EP_FromJoin, ExprHasProperty, findConstInWhere(), Expr::op, Expr::pLeft, Expr::pRight, sqlite3ExprIsConstant(), TK_AND, TK_COLUMN, and TK_EQ.

Referenced by findConstInWhere(), and propagateConstants().

◆ findCreateFileMode()

static int findCreateFileMode ( const char * zPath,
int flags,
mode_t * pMode,
uid_t * pUid,
gid_t * pGid )
static

Definition at line 39421 of file sqlite3.c.

39433 {
39434 int rc = SQLITE_OK; /* Return Code */
39435 *pMode = 0;
39436 *pUid = 0;
39437 *pGid = 0;
39439 char zDb[MAX_PATHNAME+1]; /* Database file path */
39440 int nDb; /* Number of valid bytes in zDb */
39441
39442 /* zPath is a path to a WAL or journal file. The following block derives
39443 ** the path to the associated database file from zPath. This block handles
39444 ** the following naming conventions:
39445 **
39446 ** "<path to db>-journal"
39447 ** "<path to db>-wal"
39448 ** "<path to db>-journalNN"
39449 ** "<path to db>-walNN"
39450 **
39451 ** where NN is a decimal number. The NN naming schemes are
39452 ** used by the test_multiplex.c module.
39453 */
39454 nDb = sqlite3Strlen30(zPath) - 1;
39455 while( zPath[nDb]!='-' ){
39456 /* In normal operation, the journal file name will always contain
39457 ** a '-' character. However in 8+3 filename mode, or if a corrupt
39458 ** rollback journal specifies a super-journal with a goofy name, then
39459 ** the '-' might be missing. */
39460 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
39461 nDb--;
39462 }
39463 memcpy(zDb, zPath, nDb);
39464 zDb[nDb] = '\0';
39465
39466 rc = getFileMode(zDb, pMode, pUid, pGid);
39467 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
39468 *pMode = 0600;
39469 }else if( flags & SQLITE_OPEN_URI ){
39470 /* If this is a main database file and the file was opened using a URI
39471 ** filename, check for the "modeof" parameter. If present, interpret
39472 ** its value as a filename and try to copy the mode, uid and gid from
39473 ** that file. */
39474 const char *z = sqlite3_uri_parameter(zPath, "modeof");
#define SQLITE_OPEN_MAIN_JOURNAL
Definition sqlite3.c:1612
#define SQLITE_OPEN_WAL
Definition sqlite3.c:1620
#define SQLITE_OPEN_DELETEONCLOSE
Definition sqlite3.c:1604
static int getFileMode(const char *zFile, mode_t *pMode, uid_t *pUid, gid_t *pGid)
Definition sqlite3.c:39382
SQLITE_API const char * sqlite3_uri_parameter(const char *zFilename, const char *zParam)
Definition sqlite3.c:165295
#define SQLITE_OPEN_URI
Definition sqlite3.c:1607

References getFileMode(), MAX_PATHNAME, sqlite3_uri_parameter(), sqlite3Strlen30(), SQLITE_OK, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_URI, and SQLITE_OPEN_WAL.

Referenced by unixOpen().

◆ findElementWithHash()

static HashElem * findElementWithHash ( const Hash * pH,
const char * pKey,
unsigned int * pHash )
static

Definition at line 33024 of file sqlite3.c.

33034 {
33035 HashElem *elem; /* Used to loop thru the element list */
33036 unsigned int count; /* Number of elements left to test */
33037 unsigned int h; /* The computed hash */
33038 static HashElem nullElement = { 0, 0, 0, 0 };
33039
33040 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
33041 struct _ht *pEntry;
33042 h = strHash(pKey) % pH->htsize;
33043 pEntry = &pH->ht[h];
33044 elem = pEntry->chain;
33045 count = pEntry->count;
33046 }else{
33047 h = 0;
33048 elem = pH->first;
33049 count = pH->count;
33050 }
33051 if( pHash ) *pHash = h;
33052 while( count-- ){
33053 assert( elem!=0 );
33054 if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *)
Definition sqlite3.c:31468
static unsigned int strHash(const char *z)
Definition sqlite3.c:32932
const char * pKey
Definition sqlite3.c:13903
unsigned int htsize
Definition sqlite3.c:13885
HashElem * first
Definition sqlite3.c:13887
unsigned int count
Definition sqlite3.c:13886
struct Hash::_ht * ht

References Hash::count, Hash::first, Hash::ht, Hash::htsize, HashElem::next, HashElem::pKey, sqlite3StrICmp(), and strHash().

Referenced by sqlite3HashInsert().

◆ findIndexCol()

static int findIndexCol ( Parse * pParse,
ExprList * pList,
int iBase,
Index * pIdx,
int iCol )
static

Definition at line 146058 of file sqlite3.c.

146070 {
146071 int i;
146072 const char *zColl = pIdx->azColl[iCol];
146073
146074 for(i=0; i<pList->nExpr; i++){
146076 if( p->op==TK_COLUMN
146077 && p->iColumn==pIdx->aiColumn[iCol]
146078 && p->iTable==iBase
146079 ){
146080 CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
146081 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
146082 return i;
SQLITE_PRIVATE Expr * sqlite3ExprSkipCollateAndLikely(Expr *)
Definition sqlite3.c:99837

References ExprList::a, Index::aiColumn, Index::azColl, Expr::iColumn, Expr::iTable, ExprList::nExpr, Expr::op, ExprList::ExprList_item::pExpr, sqlite3ExprNNCollSeq(), sqlite3ExprSkipCollateAndLikely(), sqlite3StrICmp(), TK_COLUMN, and CollSeq::zName.

Referenced by isDistinctRedundant().

◆ findInodeInfo()

static int findInodeInfo ( unixFile * pFile,
unixInodeInfo ** ppInode )
static

Definition at line 34902 of file sqlite3.c.

34911 {
34912 int rc; /* System call return code */
34913 int fd; /* The file descriptor for pFile */
34914 struct unixFileId fileId; /* Lookup key for the unixInodeInfo */
34915 struct stat statbuf; /* Low-level file information */
34916 unixInodeInfo *pInode = 0; /* Candidate unixInodeInfo object */
34917
34918 assert( unixMutexHeld() );
34919
34920 /* Get low-level information about the file that we can used to
34921 ** create a unique name for the file.
34922 */
34923 fd = pFile->h;
34924 rc = osFstat(fd, &statbuf);
34925 if( rc!=0 ){
34926 storeLastErrno(pFile, errno);
34927#if defined(EOVERFLOW) && defined(SQLITE_DISABLE_LFS)
34928 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
34929#endif
34930 return SQLITE_IOERR;
34931 }
34932
34933#ifdef __APPLE__
34934 /* On OS X on an msdos filesystem, the inode number is reported
34935 ** incorrectly for zero-size files. See ticket #3260. To work
34936 ** around this problem (we consider it a bug in OS X, not SQLite)
34937 ** we always increase the file size to 1 by writing a single byte
34938 ** prior to accessing the inode number. The one byte written is
34939 ** an ASCII 'S' character which also happens to be the first byte
34940 ** in the header of every SQLite database. In this way, if there
34941 ** is a race condition such that another thread has already populated
34942 ** the first page of the database, no damage is done.
34943 */
34944 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
34945 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
34946 if( rc!=1 ){
34947 storeLastErrno(pFile, errno);
34948 return SQLITE_IOERR;
34949 }
34950 rc = osFstat(fd, &statbuf);
34951 if( rc!=0 ){
34952 storeLastErrno(pFile, errno);
34953 return SQLITE_IOERR;
34954 }
34955 }
34956#endif
34957
34958 memset(&fileId, 0, sizeof(fileId));
34959 fileId.dev = statbuf.st_dev;
34960#if OS_VXWORKS
34961 fileId.pId = pFile->pId;
34962#else
34963 fileId.ino = (u64)statbuf.st_ino;
34964#endif
34965 assert( unixMutexHeld() );
34966 pInode = inodeList;
34967 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
34968 pInode = pInode->pNext;
34969 }
34970 if( pInode==0 ){
34971 pInode = sqlite3_malloc64( sizeof(*pInode) );
34972 if( pInode==0 ){
34973 return SQLITE_NOMEM_BKPT;
34974 }
34975 memset(pInode, 0, sizeof(*pInode));
34976 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
34977 if( sqlite3GlobalConfig.bCoreMutex ){
34978 pInode->pLockMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
34979 if( pInode->pLockMutex==0 ){
34980 sqlite3_free(pInode);
34981 return SQLITE_NOMEM_BKPT;
34982 }
34983 }
34984 pInode->nRef = 1;
34985 assert( unixMutexHeld() );
34986 pInode->pNext = inodeList;
34987 pInode->pPrev = 0;
34988 if( inodeList ) inodeList->pPrev = pInode;
34989 inodeList = pInode;
#define osWrite
#define SQLITE_MUTEX_FAST
Definition sqlite3.c:8629
#define SQLITE_NOLFS
Definition sqlite3.c:1492
SQLITE_API sqlite3_mutex * sqlite3_mutex_alloc(int)
Definition sqlite3.c:25922
#define sqlite3GlobalConfig
Definition sqlite3.c:14634
#define SQLITE_FSFLAGS_IS_MSDOS
Definition sqlite3.c:33496
static unixInodeInfo * inodeList
Definition sqlite3.c:34728
int lastErrno
Definition sqlite3.c:33569
unixInodeInfo * pPrev
Definition sqlite3.c:34713
unixInodeInfo * pNext
Definition sqlite3.c:34712

References unixFileId::dev, unixFile::h, unixFileId::ino, inodeList, unixFile::lastErrno, unixInodeInfo::nRef, osFstat, osWrite, unixInodeInfo::pNext, unixInodeInfo::pPrev, sqlite3_free(), sqlite3_malloc64(), sqlite3_mutex_alloc(), sqlite3GlobalConfig, SQLITE_FSFLAGS_IS_MSDOS, SQLITE_IOERR, SQLITE_MUTEX_FAST, SQLITE_NOLFS, SQLITE_NOMEM_BKPT, and storeLastErrno().

◆ findNextHostParameter()

static int findNextHostParameter ( const char * zSql,
int * pnToken )
static

Definition at line 85064 of file sqlite3.c.

85070 {
85071 int tokenType;
85072 int nTotal = 0;
85073 int n;
85074
85075 *pnToken = 0;
85076 while( zSql[0] ){
85077 n = sqlite3GetToken((u8*)zSql, &tokenType);
85078 assert( n>0 && tokenType!=TK_ILLEGAL );
85079 if( tokenType==TK_VARIABLE ){
85080 *pnToken = n;
85081 break;
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *)
Definition sqlite3.c:160008
#define TK_ILLEGAL
Definition sqlite3.c:14122

References sqlite3GetToken(), TK_ILLEGAL, and TK_VARIABLE.

Referenced by sqlite3VdbeExpandSql().

◆ findReusableFd()

static UnixUnusedFd * findReusableFd ( const char * zPath,
int flags )
static

Definition at line 39332 of file sqlite3.c.

39338 {
39339 UnixUnusedFd *pUnused = 0;
39340
39341 /* Do not search for an unused file descriptor on vxworks. Not because
39342 ** vxworks would not benefit from the change (it might, we're not sure),
39343 ** but because no way to test it is currently available. It is better
39344 ** not to risk breaking vxworks support for the sake of such an obscure
39345 ** feature. */
39346#if !OS_VXWORKS
39347 struct stat sStat; /* Results of stat() call */
39348
39350
39351 /* A stat() call may fail for various reasons. If this happens, it is
39352 ** almost certain that an open() call on the same path will also fail.
39353 ** For this reason, if an error occurs in the stat() call here, it is
39354 ** ignored and -1 is returned. The caller will try to open a new file
39355 ** descriptor on the same path, fail, and return an error to SQLite.
39356 **
39357 ** Even if a subsequent open() call does succeed, the consequences of
39358 ** not searching for a reusable file descriptor are not dire. */
39359 if( inodeList!=0 && 0==osStat(zPath, &sStat) ){
39360 unixInodeInfo *pInode;
39361
39362 pInode = inodeList;
39363 while( pInode && (pInode->fileId.dev!=sStat.st_dev
39364 || pInode->fileId.ino!=(u64)sStat.st_ino) ){
39365 pInode = pInode->pNext;
39366 }
39367 if( pInode ){
39368 UnixUnusedFd **pp;
39369 assert( sqlite3_mutex_notheld(pInode->pLockMutex) );
39372 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
39373 pUnused = *pp;
39374 if( pUnused ){
39375 *pp = pUnused->pNext;
39376 }
#define SQLITE_OPEN_READWRITE
Definition sqlite3.c:1602
SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *)
#define SQLITE_OPEN_READONLY
Definition sqlite3.c:1601
static void unixEnterMutex(void)
Definition sqlite3.c:34279
#define osStat
UnixUnusedFd * pNext
Definition sqlite3.c:33554
dev_t dev
Definition sqlite3.c:34662
sqlite3_mutex * pLockMutex
Definition sqlite3.c:34704

References unixFileId::dev, unixInodeInfo::fileId, UnixUnusedFd::flags, unixFileId::ino, inodeList, osStat, unixInodeInfo::pLockMutex, UnixUnusedFd::pNext, unixInodeInfo::pNext, unixInodeInfo::pUnused, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_mutex_notheld(), SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, unixEnterMutex(), and unixLeaveMutex().

Referenced by unixOpen().

◆ findRightmost()

static Select * findRightmost ( Select * p)
static

Definition at line 129475 of file sqlite3.c.

Referenced by multiSelect(), and selectPopWith().

◆ first_valueFinalizeFunc()

static void first_valueFinalizeFunc ( sqlite3_context * pCtx)
static

Definition at line 151438 of file sqlite3.c.

151444 {
151445 struct NthValueCtx *p;
151446 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));

◆ first_valueStepFunc()

static void first_valueStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151422 of file sqlite3.c.

151432 {
151433 struct NthValueCtx *p;
151434 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151435 if( p && p->pValue==0 ){
151436 p->pValue = sqlite3_value_dup(apArg[0]);
151437 if( !p->pValue ){
SQLITE_API sqlite3_value * sqlite3_value_dup(const sqlite3_value *)
Definition sqlite3.c:83313
sqlite3_value * pValue
Definition sqlite3.c:151367

◆ fkActionTrigger()

static Trigger * fkActionTrigger ( Parse * pParse,
Table * pTab,
FKey * pFKey,
ExprList * pChanges )
static

Definition at line 120283 of file sqlite3.c.

120294 {
120295 sqlite3 *db = pParse->db; /* Database handle */
120296 int action; /* One of OE_None, OE_Cascade etc. */
120297 Trigger *pTrigger; /* Trigger definition to return */
120298 int iAction = (pChanges!=0); /* 1 for UPDATE, 0 for DELETE */
120299
120300 action = pFKey->aAction[iAction];
120301 if( action==OE_Restrict && (db->flags & SQLITE_DeferFKs) ){
120302 return 0;
120303 }
120304 pTrigger = pFKey->apTrigger[iAction];
120305
120306 if( action!=OE_None && !pTrigger ){
120307 char const *zFrom; /* Name of child table */
120308 int nFrom; /* Length in bytes of zFrom */
120309 Index *pIdx = 0; /* Parent key index for this FK */
120310 int *aiCol = 0; /* child table cols -> parent key cols */
120311 TriggerStep *pStep = 0; /* First (only) step of trigger program */
120312 Expr *pWhere = 0; /* WHERE clause of trigger step */
120313 ExprList *pList = 0; /* Changes list if ON UPDATE CASCADE */
120314 Select *pSelect = 0; /* If RESTRICT, "SELECT RAISE(...)" */
120315 int i; /* Iterator variable */
120316 Expr *pWhen = 0; /* WHEN clause for the trigger */
120317
120318 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0;
120319 assert( aiCol || pFKey->nCol==1 );
120320
120321 for(i=0; i<pFKey->nCol; i++){
120322 Token tOld = { "old", 3 }; /* Literal "old" token */
120323 Token tNew = { "new", 3 }; /* Literal "new" token */
120324 Token tFromCol; /* Name of column in child table */
120325 Token tToCol; /* Name of column in parent table */
120326 int iFromCol; /* Idx of column in child table */
120327 Expr *pEq; /* tFromCol = OLD.tToCol */
120328
120329 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
120330 assert( iFromCol>=0 );
120331 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
120332 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
120333 sqlite3TokenInit(&tToCol,
120334 pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName);
120335 sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName);
120336
120337 /* Create the expression "OLD.zToCol = zFromCol". It is important
120338 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
120339 ** that the affinity and collation sequence associated with the
120340 ** parent table are used for the comparison. */
120341 pEq = sqlite3PExpr(pParse, TK_EQ,
120342 sqlite3PExpr(pParse, TK_DOT,
120343 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
120344 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
120345 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
120346 );
120347 pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
120348
120349 /* For ON UPDATE, construct the next term of the WHEN clause.
120350 ** The final WHEN clause will be like this:
120351 **
120352 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
120353 */
120354 if( pChanges ){
120355 pEq = sqlite3PExpr(pParse, TK_IS,
120356 sqlite3PExpr(pParse, TK_DOT,
120357 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
120358 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
120359 sqlite3PExpr(pParse, TK_DOT,
120360 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
120361 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
120362 );
120363 pWhen = sqlite3ExprAnd(pParse, pWhen, pEq);
120364 }
120365
120366 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
120367 Expr *pNew;
120368 if( action==OE_Cascade ){
120369 pNew = sqlite3PExpr(pParse, TK_DOT,
120370 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
120371 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
120372 }else if( action==OE_SetDflt ){
120373 Column *pCol = pFKey->pFrom->aCol + iFromCol;
120374 Expr *pDflt;
120375 if( pCol->colFlags & COLFLAG_GENERATED ){
120376 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
120377 testcase( pCol->colFlags & COLFLAG_STORED );
120378 pDflt = 0;
120379 }else{
120380 pDflt = pCol->pDflt;
120381 }
120382 if( pDflt ){
120383 pNew = sqlite3ExprDup(db, pDflt, 0);
120384 }else{
120385 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
120386 }
120387 }else{
120388 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
120389 }
120390 pList = sqlite3ExprListAppend(pParse, pList, pNew);
120391 sqlite3ExprListSetName(pParse, pList, &tFromCol, 0);
120392 }
120393 }
120394 sqlite3DbFree(db, aiCol);
120395
120396 zFrom = pFKey->pFrom->zName;
120397 nFrom = sqlite3Strlen30(zFrom);
120398
120399 if( action==OE_Restrict ){
120400 Token tFrom;
120401 Expr *pRaise;
120402
120403 tFrom.z = zFrom;
120404 tFrom.n = nFrom;
120405 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
120406 if( pRaise ){
120407 pRaise->affExpr = OE_Abort;
120408 }
120409 pSelect = sqlite3SelectNew(pParse,
120410 sqlite3ExprListAppend(pParse, 0, pRaise),
120411 sqlite3SrcListAppend(pParse, 0, &tFrom, 0),
120412 pWhere,
120413 0, 0, 0, 0, 0
120414 );
120415 pWhere = 0;
120416 }
120417
120418 /* Disable lookaside memory allocation */
120420
120421 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
120422 sizeof(Trigger) + /* struct Trigger */
120423 sizeof(TriggerStep) + /* Single step in trigger program */
120424 nFrom + 1 /* Space for pStep->zTarget */
120425 );
120426 if( pTrigger ){
120427 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
120428 pStep->zTarget = (char *)&pStep[1];
120429 memcpy((char *)pStep->zTarget, zFrom, nFrom);
120430
120431 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
120432 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
120433 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
120434 if( pWhen ){
120435 pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
120436 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
120437 }
120438 }
120439
120440 /* Re-enable the lookaside buffer, if it was disabled earlier. */
120442
120443 sqlite3ExprDelete(db, pWhere);
120444 sqlite3ExprDelete(db, pWhen);
120445 sqlite3ExprListDelete(db, pList);
120446 sqlite3SelectDelete(db, pSelect);
120447 if( db->mallocFailed==1 ){
120448 fkTriggerDelete(db, pTrigger);
120449 return 0;
120450 }
120451 assert( pStep!=0 );
120452 assert( pTrigger!=0 );
120453
120454 switch( action ){
120455 case OE_Restrict:
120456 pStep->op = TK_SELECT;
120457 break;
120458 case OE_Cascade:
120459 if( !pChanges ){
120460 pStep->op = TK_DELETE;
120461 break;
120462 }
120463 /* no break */ deliberate_fall_through
120464 default:
120465 pStep->op = TK_UPDATE;
120466 }
120467 pStep->pTrig = pTrigger;
120468 pTrigger->pSchema = pTab->pSchema;
120469 pTrigger->pTabSchema = pTab->pSchema;
SQLITE_PRIVATE Select * sqlite3SelectNew(Parse *, ExprList *, SrcList *, Expr *, ExprList *, Expr *, ExprList *, u32, Expr *)
Definition sqlite3.c:129410
#define TK_NOT
Definition sqlite3.c:13961
#define OE_None
Definition sqlite3.c:17656
#define SQLITE_DeferFKs
Definition sqlite3.c:16998
static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p)
Definition sqlite3.c:119786
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse *, ExprList *, Token *, int)
Definition sqlite3.c:101494
#define TK_RAISE
Definition sqlite3.c:14013
struct TriggerStep TriggerStep
Definition sqlite3.c:14699
#define COLFLAG_GENERATED
Definition sqlite3.c:17353
#define DisableLookaside
Definition sqlite3.c:16740
#define EnableLookaside
Definition sqlite3.c:16741
SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse *, Table *, FKey *, Index **, int **)
Definition sqlite3.c:119278
#define COLFLAG_STORED
Definition sqlite3.c:17350
#define OE_Restrict
Definition sqlite3.c:17663
SQLITE_PRIVATE SrcList * sqlite3SrcListAppend(Parse *, SrcList *, Token *, Token *)
Definition sqlite3.c:114789
Expr * pDflt
Definition sqlite3.c:17333
struct FKey::sColMap aCol[1]
int nCol
Definition sqlite3.c:17620
u8 aAction[2]
Definition sqlite3.c:17623
Table * pFrom
Definition sqlite3.c:17615
Trigger * apTrigger[2]
Definition sqlite3.c:17624
unsigned int n
Definition sqlite3.c:17865
char * zTarget
Definition sqlite3.c:18938
Trigger * pTrig
Definition sqlite3.c:18936

References FKey::aAction, Table::aCol, FKey::aCol, Expr::affExpr, Index::aiColumn, FKey::apTrigger, COLFLAG_GENERATED, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, deliberate_fall_through, DisableLookaside, EnableLookaside, EXPRDUP_REDUCE, fkTriggerDelete(), sqlite3::flags, FKey::sColMap::iFrom, Table::iPKey, sqlite3::mallocFailed, Token::n, Table::nCol, FKey::nCol, OE_Abort, OE_Cascade, OE_None, OE_Restrict, OE_SetDflt, Trigger::op, TriggerStep::op, Column::pDflt, TriggerStep::pExprList, FKey::pFrom, Table::pSchema, Trigger::pSchema, TriggerStep::pSelect, Trigger::pTabSchema, TriggerStep::pTrig, Trigger::pWhen, TriggerStep::pWhere, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3Expr(), sqlite3ExprAlloc(), sqlite3ExprAnd(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3ExprListDelete(), sqlite3ExprListDup(), sqlite3ExprListSetName(), sqlite3FkLocateIndex(), sqlite3PExpr(), sqlite3SelectDelete(), sqlite3SelectDup(), sqlite3SelectNew(), sqlite3SrcListAppend(), sqlite3Strlen30(), sqlite3TokenInit(), SQLITE_DeferFKs, Trigger::step_list, testcase, TK_DELETE, TK_DOT, TK_EQ, TK_ID, TK_IS, TK_NOT, TK_NULL, TK_RAISE, TK_SELECT, TK_UPDATE, Token::z, Column::zName, Table::zName, and TriggerStep::zTarget.

◆ fkChildIsModified()

static int fkChildIsModified ( Table * pTab,
FKey * p,
int * aChange,
int bChngRowid )
static

Definition at line 119877 of file sqlite3.c.

119888 {
119889 int i;
119890 for(i=0; i<p->nCol; i++){

References FKey::aCol, FKey::sColMap::iFrom, Table::iPKey, and FKey::nCol.

Referenced by sqlite3FkCheck(), and sqlite3FkRequired().

◆ fkLookupParent()

static void fkLookupParent ( Parse * pParse,
int iDb,
Table * pTab,
Index * pIdx,
FKey * pFKey,
int * aiCol,
int regData,
int nIncr,
int isIgnore )
static

Definition at line 119413 of file sqlite3.c.

119429 {
119430 int i; /* Iterator variable */
119431 Vdbe *v = sqlite3GetVdbe(pParse); /* Vdbe to add code to */
119432 int iCur = pParse->nTab - 1; /* Cursor number to use */
119433 int iOk = sqlite3VdbeMakeLabel(pParse); /* jump here if parent key found */
119434
119436 (!pFKey->isDeferred
119437 && !(pParse->db->flags & SQLITE_DeferFKs)
119438 && !pParse->pToplevel
119439 && !pParse->isMultiWrite) ? OE_Abort : OE_Ignore);
119440
119441 /* If nIncr is less than zero, then check at runtime if there are any
119442 ** outstanding constraints to resolve. If there are not, there is no need
119443 ** to check if deleting this row resolves any outstanding violations.
119444 **
119445 ** Check if any of the key columns in the child table row are NULL. If
119446 ** any are, then the constraint is considered satisfied. No need to
119447 ** search for a matching row in the parent table. */
119448 if( nIncr<0 ){
119449 sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
119450 VdbeCoverage(v);
119451 }
119452 for(i=0; i<pFKey->nCol; i++){
119453 int iReg = sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[i]) + regData + 1;
119454 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
119455 }
119456
119457 if( isIgnore==0 ){
119458 if( pIdx==0 ){
119459 /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
119460 ** column of the parent table (table pTab). */
119461 int iMustBeInt; /* Address of MustBeInt instruction */
119462 int regTemp = sqlite3GetTempReg(pParse);
119463
119464 /* Invoke MustBeInt to coerce the child key value to an integer (i.e.
119465 ** apply the affinity of the parent key). If this fails, then there
119466 ** is no matching parent key. Before using MustBeInt, make a copy of
119467 ** the value. Otherwise, the value inserted into the child key column
119468 ** will have INTEGER affinity applied to it, which may not be correct. */
119470 sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[0])+1+regData, regTemp);
119471 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
119472 VdbeCoverage(v);
119473
119474 /* If the parent table is the same as the child table, and we are about
119475 ** to increment the constraint-counter (i.e. this is an INSERT operation),
119476 ** then check if the row being inserted matches itself. If so, do not
119477 ** increment the constraint-counter. */
119478 if( pTab==pFKey->pFrom && nIncr==1 ){
119479 sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
119481 }
119482
119483 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
119484 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
119485 sqlite3VdbeGoto(v, iOk);
119487 sqlite3VdbeJumpHere(v, iMustBeInt);
119488 sqlite3ReleaseTempReg(pParse, regTemp);
119489 }else{
119490 int nCol = pFKey->nCol;
119491 int regTemp = sqlite3GetTempRange(pParse, nCol);
119492 int regRec = sqlite3GetTempReg(pParse);
119493
119494 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
119495 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
119496 for(i=0; i<nCol; i++){
119498 sqlite3TableColumnToStorage(pFKey->pFrom, aiCol[i])+1+regData,
119499 regTemp+i);
119500 }
119501
119502 /* If the parent table is the same as the child table, and we are about
119503 ** to increment the constraint-counter (i.e. this is an INSERT operation),
119504 ** then check if the row being inserted matches itself. If so, do not
119505 ** increment the constraint-counter.
119506 **
119507 ** If any of the parent-key values are NULL, then the row cannot match
119508 ** itself. So set JUMPIFNULL to make sure we do the OP_Found if any
119509 ** of the parent-key values are NULL (at this point it is known that
119510 ** none of the child key values are).
119511 */
119512 if( pTab==pFKey->pFrom && nIncr==1 ){
119513 int iJump = sqlite3VdbeCurrentAddr(v) + nCol + 1;
119514 for(i=0; i<nCol; i++){
119515 int iChild = sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[i])
119516 +1+regData;
119517 int iParent = 1+regData;
119518 iParent += sqlite3TableColumnToStorage(pIdx->pTable,
119519 pIdx->aiColumn[i]);
119520 assert( pIdx->aiColumn[i]>=0 );
119521 assert( aiCol[i]!=pTab->iPKey );
119522 if( pIdx->aiColumn[i]==pTab->iPKey ){
119523 /* The parent key is a composite key that includes the IPK column */
119524 iParent = regData;
119525 }
119526 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
119528 }
119529 sqlite3VdbeGoto(v, iOk);
119530 }
119531
119532 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
119533 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
119534 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
119535
119536 sqlite3ReleaseTempReg(pParse, regRec);
119537 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
119538 }
119539 }
119540
119541 if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
119542 && !pParse->pToplevel
119543 && !pParse->isMultiWrite
119544 ){
119545 /* Special case: If this is an INSERT statement that will insert exactly
119546 ** one row into the table, raise a constraint immediately instead of
119547 ** incrementing a counter. This is necessary as the VM code is being
119548 ** generated for will not open a statement transaction. */
119549 assert( nIncr==1 );
119552 }else{
119553 if( nIncr>0 && pFKey->isDeferred==0 ){
119554 sqlite3MayAbort(pParse);
119555 }
#define P4_STATIC
Definition sqlite3.c:15506
#define OP_Found
Definition sqlite3.c:15596
#define SQLITE_NOTNULL
Definition sqlite3.c:17422
#define SQLITE_CONSTRAINT_FOREIGNKEY
Definition sqlite3.c:1578
SQLITE_PRIVATE void sqlite3HaltConstraint(Parse *, int, int, char *, i8, u8)
Definition sqlite3.c:115214
#define OE_Ignore
Definition sqlite3.c:17660
#define sqlite3VdbeVerifyAbortable(A, B)
Definition sqlite3.c:15823
#define P5_ConstraintFK
Definition sqlite3.c:15530
#define OP_FkIfZero
Definition sqlite3.c:15613
u8 isDeferred
Definition sqlite3.c:17622
u8 isMultiWrite
Definition sqlite3.c:18688

References Index::aiColumn, Parse::db, sqlite3::flags, Table::iPKey, FKey::isDeferred, Parse::isMultiWrite, FKey::nCol, Parse::nTab, OE_Abort, OE_Ignore, OP_Close, OP_Copy, OP_Eq, OP_FkCounter, OP_FkIfZero, OP_Found, OP_IsNull, OP_MakeRecord, OP_MustBeInt, OP_Ne, OP_NotExists, OP_OpenRead, OP_SCopy, P4_STATIC, P5_ConstraintFK, FKey::pFrom, Index::pTable, Parse::pToplevel, sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3HaltConstraint(), sqlite3IndexAffinityStr(), sqlite3MayAbort(), sqlite3OpenTable(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3TableColumnToStorage(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VdbeSetP4KeyInfo(), sqlite3VdbeVerifyAbortable, SQLITE_CONSTRAINT_FOREIGNKEY, SQLITE_DeferFKs, SQLITE_JUMPIFNULL, SQLITE_NOTNULL, Index::tnum, and VdbeCoverage.

Referenced by sqlite3FkCheck().

◆ fkParentIsModified()

static int fkParentIsModified ( Table * pTab,
FKey * p,
int * aChange,
int bChngRowid )
static

Definition at line 119904 of file sqlite3.c.

119915 {
119916 int i;
119917 for(i=0; i<p->nCol; i++){
119918 char *zKey = p->aCol[i].zCol;
119919 int iKey;
119920 for(iKey=0; iKey<pTab->nCol; iKey++){
119921 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
119922 Column *pCol = &pTab->aCol[iKey];
119923 if( zKey ){
119924 if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
119925 }else if( pCol->colFlags & COLFLAG_PRIMKEY ){
119926 return 1;

References Table::aCol, FKey::aCol, COLFLAG_PRIMKEY, Column::colFlags, Table::iPKey, Table::nCol, FKey::nCol, sqlite3StrICmp(), FKey::sColMap::zCol, and Column::zName.

Referenced by sqlite3FkCheck(), and sqlite3FkRequired().

◆ fkScanChildren()

static void fkScanChildren ( Parse * pParse,
SrcList * pSrc,
Table * pTab,
Index * pIdx,
FKey * pFKey,
int * aiCol,
int regData,
int nIncr )
static

Definition at line 119645 of file sqlite3.c.

119660 {
119661 sqlite3 *db = pParse->db; /* Database handle */
119662 int i; /* Iterator variable */
119663 Expr *pWhere = 0; /* WHERE clause to scan with */
119664 NameContext sNameContext; /* Context used to resolve WHERE clause */
119665 WhereInfo *pWInfo; /* Context used by sqlite3WhereXXX() */
119666 int iFkIfZero = 0; /* Address of OP_FkIfZero */
119667 Vdbe *v = sqlite3GetVdbe(pParse);
119668
119669 assert( pIdx==0 || pIdx->pTable==pTab );
119670 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
119671 assert( pIdx!=0 || pFKey->nCol==1 );
119672 assert( pIdx!=0 || HasRowid(pTab) );
119673
119674 if( nIncr<0 ){
119675 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
119676 VdbeCoverage(v);
119677 }
119678
119679 /* Create an Expr object representing an SQL expression like:
119680 **
119681 ** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
119682 **
119683 ** The collation sequence used for the comparison should be that of
119684 ** the parent key columns. The affinity of the parent key column should
119685 ** be applied to each child key value before the comparison takes place.
119686 */
119687 for(i=0; i<pFKey->nCol; i++){
119688 Expr *pLeft; /* Value from parent table row */
119689 Expr *pRight; /* Column ref to child table */
119690 Expr *pEq; /* Expression (pLeft = pRight) */
119691 i16 iCol; /* Index of column in child table */
119692 const char *zCol; /* Name of column in child table */
119693
119694 iCol = pIdx ? pIdx->aiColumn[i] : -1;
119695 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
119696 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
119697 assert( iCol>=0 );
119698 zCol = pFKey->pFrom->aCol[iCol].zName;
119699 pRight = sqlite3Expr(db, TK_ID, zCol);
119700 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
119701 pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
119702 }
119703
119704 /* If the child table is the same as the parent table, then add terms
119705 ** to the WHERE clause that prevent this entry from being scanned.
119706 ** The added WHERE clause terms are like this:
119707 **
119708 ** $current_rowid!=rowid
119709 ** NOT( $current_a==a AND $current_b==b AND ... )
119710 **
119711 ** The first form is used for rowid tables. The second form is used
119712 ** for WITHOUT ROWID tables. In the second form, the *parent* key is
119713 ** (a,b,...). Either the parent or primary key could be used to
119714 ** uniquely identify the current row, but the parent key is more convenient
119715 ** as the required values have already been loaded into registers
119716 ** by the caller.
119717 */
119718 if( pTab==pFKey->pFrom && nIncr>0 ){
119719 Expr *pNe; /* Expression (pLeft != pRight) */
119720 Expr *pLeft; /* Value from parent table row */
119721 Expr *pRight; /* Column ref to child table */
119722 if( HasRowid(pTab) ){
119723 pLeft = exprTableRegister(pParse, pTab, regData, -1);
119724 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
119725 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight);
119726 }else{
119727 Expr *pEq, *pAll = 0;
119728 assert( pIdx!=0 );
119729 for(i=0; i<pIdx->nKeyCol; i++){
119730 i16 iCol = pIdx->aiColumn[i];
119731 assert( iCol>=0 );
119732 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
119733 pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
119734 pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
119735 pAll = sqlite3ExprAnd(pParse, pAll, pEq);
119736 }
119737 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
119738 }
119739 pWhere = sqlite3ExprAnd(pParse, pWhere, pNe);
119740 }
119741
119742 /* Resolve the references in the WHERE clause. */
119743 memset(&sNameContext, 0, sizeof(NameContext));
119744 sNameContext.pSrcList = pSrc;
119745 sNameContext.pParse = pParse;
119746 sqlite3ResolveExprNames(&sNameContext, pWhere);
119747
119748 /* Create VDBE to loop through the entries in pSrc that match the WHERE
119749 ** clause. For each row found, increment either the deferred or immediate
119750 ** foreign key constraint counter. */
119751 if( pParse->nErr==0 ){
119752 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
119753 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
119754 if( pWInfo ){
119755 sqlite3WhereEnd(pWInfo);
119756 }
119757 }
119758
static Expr * exprTableColumn(sqlite3 *db, Table *pTab, int iCursor, i16 iCol)
Definition sqlite3.c:119598
static Expr * exprTableRegister(Parse *pParse, Table *pTab, int regBase, i16 iCol)
Definition sqlite3.c:119566
SQLITE_PRIVATE WhereInfo * sqlite3WhereBegin(Parse *, SrcList *, Expr *, ExprList *, ExprList *, u16, int)
Definition sqlite3.c:150295
#define OP_FkCounter
Definition sqlite3.c:15715
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *)
Definition sqlite3.c:150889

References SrcList::a, Table::aCol, FKey::aCol, Index::aiColumn, Parse::db, exprTableColumn(), exprTableRegister(), HasRowid, SrcList::SrcList_item::iCursor, FKey::sColMap::iFrom, FKey::isDeferred, FKey::nCol, Parse::nErr, Index::nKeyCol, OP_FkCounter, OP_FkIfZero, FKey::pFrom, NameContext::pParse, NameContext::pSrcList, Index::pTable, sqlite3Expr(), sqlite3ExprAnd(), sqlite3ExprDelete(), sqlite3GetVdbe(), sqlite3PExpr(), sqlite3ResolveExprNames(), sqlite3VdbeAddOp2(), sqlite3VdbeJumpHereOrPopInst(), sqlite3WhereBegin(), sqlite3WhereEnd(), TK_EQ, TK_ID, TK_IS, TK_NE, TK_NOT, VdbeCoverage, and Column::zName.

Referenced by sqlite3FkCheck().

◆ fkTriggerDelete()

static void fkTriggerDelete ( sqlite3 * dbMem,
Trigger * p )
static

◆ flattenSubquery()

static int flattenSubquery ( Parse * pParse,
Select * p,
int iFrom,
int isAgg )
static

Definition at line 133077 of file sqlite3.c.

133088 {
133089 const char *zSavedAuthContext = pParse->zAuthContext;
133090 Select *pParent; /* Current UNION ALL term of the other query */
133091 Select *pSub; /* The inner query or "subquery" */
133092 Select *pSub1; /* Pointer to the rightmost select in sub-query */
133093 SrcList *pSrc; /* The FROM clause of the outer query */
133094 SrcList *pSubSrc; /* The FROM clause of the subquery */
133095 int iParent; /* VDBE cursor number of the pSub result set temp table */
133096 int iNewParent = -1;/* Replacement table for iParent */
133097 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
133098 int i; /* Loop counter */
133099 Expr *pWhere; /* The WHERE clause */
133100 struct SrcList_item *pSubitem; /* The subquery */
133101 sqlite3 *db = pParse->db;
133102 Walker w; /* Walker to persist agginfo data */
133103
133104 /* Check to see if flattening is permitted. Return 0 if not.
133105 */
133106 assert( p!=0 );
133107 assert( p->pPrior==0 );
133108 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
133109 pSrc = p->pSrc;
133110 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
133111 pSubitem = &pSrc->a[iFrom];
133112 iParent = pSubitem->iCursor;
133113 pSub = pSubitem->pSelect;
133114 assert( pSub!=0 );
133115
133116#ifndef SQLITE_OMIT_WINDOWFUNC
133117 if( p->pWin || pSub->pWin ) return 0; /* Restriction (25) */
133118#endif
133119
133120 pSubSrc = pSub->pSrc;
133121 assert( pSubSrc );
133122 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
133123 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
133124 ** because they could be computed at compile-time. But when LIMIT and OFFSET
133125 ** became arbitrary expressions, we were forced to add restrictions (13)
133126 ** and (14). */
133127 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
133128 if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */
133129 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
133130 return 0; /* Restriction (15) */
133131 }
133132 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
133133 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
133134 if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
133135 return 0; /* Restrictions (8)(9) */
133136 }
133137 if( p->pOrderBy && pSub->pOrderBy ){
133138 return 0; /* Restriction (11) */
133139 }
133140 if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
133141 if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
133142 if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
133143 return 0; /* Restriction (21) */
133144 }
133145 if( pSub->selFlags & (SF_Recursive) ){
133146 return 0; /* Restrictions (22) */
133147 }
133148
133149 /*
133150 ** If the subquery is the right operand of a LEFT JOIN, then the
133151 ** subquery may not be a join itself (3a). Example of why this is not
133152 ** allowed:
133153 **
133154 ** t1 LEFT OUTER JOIN (t2 JOIN t3)
133155 **
133156 ** If we flatten the above, we would get
133157 **
133158 ** (t1 LEFT OUTER JOIN t2) JOIN t3
133159 **
133160 ** which is not at all the same thing.
133161 **
133162 ** If the subquery is the right operand of a LEFT JOIN, then the outer
133163 ** query cannot be an aggregate. (3c) This is an artifact of the way
133164 ** aggregates are processed - there is no mechanism to determine if
133165 ** the LEFT JOIN table should be all-NULL.
133166 **
133167 ** See also tickets #306, #350, and #3300.
133168 */
133169 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
133170 isLeftJoin = 1;
133171 if( pSubSrc->nSrc>1 /* (3a) */
133172 || isAgg /* (3b) */
133173 || IsVirtual(pSubSrc->a[0].pTab) /* (3c) */
133174 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
133175 ){
133176 return 0;
133177 }
133178 }
133179#ifdef SQLITE_EXTRA_IFNULLROW
133180 else if( iFrom>0 && !isAgg ){
133181 /* Setting isLeftJoin to -1 causes OP_IfNullRow opcodes to be generated for
133182 ** every reference to any result column from subquery in a join, even
133183 ** though they are not necessary. This will stress-test the OP_IfNullRow
133184 ** opcode. */
133185 isLeftJoin = -1;
133186 }
133187#endif
133188
133189 /* Restriction (17): If the sub-query is a compound SELECT, then it must
133190 ** use only the UNION ALL operator. And none of the simple select queries
133191 ** that make up the compound SELECT are allowed to be aggregate or distinct
133192 ** queries.
133193 */
133194 if( pSub->pPrior ){
133195 if( pSub->pOrderBy ){
133196 return 0; /* Restriction (20) */
133197 }
133198 if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
133199 return 0; /* (17d1), (17d2), or (17d3) */
133200 }
133201 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
133204 assert( pSub->pSrc!=0 );
133205 assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
133206 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
133207 || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
133208 || pSub1->pSrc->nSrc<1 /* (17c) */
133209#ifndef SQLITE_OMIT_WINDOWFUNC
133210 || pSub1->pWin /* (17e) */
133211#endif
133212 ){
133213 return 0;
133214 }
133215 testcase( pSub1->pSrc->nSrc>1 );
133216 }
133217
133218 /* Restriction (18). */
133219 if( p->pOrderBy ){
133220 int ii;
133221 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
133222 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
133223 }
133224 }
133225 }
133226
133227 /* Ex-restriction (23):
133228 ** The only way that the recursive part of a CTE can contain a compound
133229 ** subquery is for the subquery to be one term of a join. But if the
133230 ** subquery is a join, then the flattening has already been stopped by
133231 ** restriction (17d3)
133232 */
133233 assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 );
133234
133235 /***** If we reach this point, flattening is permitted. *****/
133236 SELECTTRACE(1,pParse,p,("flatten %u.%p from term %d\n",
133237 pSub->selId, pSub, iFrom));
133238
133239 /* Authorize the subquery */
133240 pParse->zAuthContext = pSubitem->zName;
133241 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
133242 testcase( i==SQLITE_DENY );
133243 pParse->zAuthContext = zSavedAuthContext;
133244
133245 /* If the sub-query is a compound SELECT statement, then (by restrictions
133246 ** 17 and 18 above) it must be a UNION ALL and the parent query must
133247 ** be of the form:
133248 **
133249 ** SELECT <expr-list> FROM (<sub-query>) <where-clause>
133250 **
133251 ** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block
133252 ** creates N-1 copies of the parent query without any ORDER BY, LIMIT or
133253 ** OFFSET clauses and joins them to the left-hand-side of the original
133254 ** using UNION ALL operators. In this case N is the number of simple
133255 ** select statements in the compound sub-query.
133256 **
133257 ** Example:
133258 **
133259 ** SELECT a+1 FROM (
133260 ** SELECT x FROM tab
133261 ** UNION ALL
133262 ** SELECT y FROM tab
133263 ** UNION ALL
133264 ** SELECT abs(z*2) FROM tab2
133265 ** ) WHERE a!=5 ORDER BY 1
133266 **
133267 ** Transformed into:
133268 **
133269 ** SELECT x+1 FROM tab WHERE x+1!=5
133270 ** UNION ALL
133271 ** SELECT y+1 FROM tab WHERE y+1!=5
133272 ** UNION ALL
133273 ** SELECT abs(z*2)+1 FROM tab2 WHERE abs(z*2)+1!=5
133274 ** ORDER BY 1
133275 **
133276 ** We call this the "compound-subquery flattening".
133277 */
133278 for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){
133279 Select *pNew;
133280 ExprList *pOrderBy = p->pOrderBy;
133281 Expr *pLimit = p->pLimit;
133282 Select *pPrior = p->pPrior;
133283 p->pOrderBy = 0;
133284 p->pSrc = 0;
133285 p->pPrior = 0;
133286 p->pLimit = 0;
133287 pNew = sqlite3SelectDup(db, p, 0);
133288 p->pLimit = pLimit;
133289 p->pOrderBy = pOrderBy;
133290 p->pSrc = pSrc;
133291 p->op = TK_ALL;
133292 if( pNew==0 ){
133293 p->pPrior = pPrior;
133294 }else{
133295 pNew->pPrior = pPrior;
133296 if( pPrior ) pPrior->pNext = pNew;
133297 pNew->pNext = p;
133298 p->pPrior = pNew;
133299 SELECTTRACE(2,pParse,p,("compound-subquery flattener"
133300 " creates %u as peer\n",pNew->selId));
133301 }
133302 if( db->mallocFailed ) return 1;
133303 }
133304
133305 /* Begin flattening the iFrom-th entry of the FROM clause
133306 ** in the outer query.
133307 */
133308 pSub = pSub1 = pSubitem->pSelect;
133309
133310 /* Delete the transient table structure associated with the
133311 ** subquery
133312 */
133313 sqlite3DbFree(db, pSubitem->zDatabase);
133314 sqlite3DbFree(db, pSubitem->zName);
133315 sqlite3DbFree(db, pSubitem->zAlias);
133316 pSubitem->zDatabase = 0;
133317 pSubitem->zName = 0;
133318 pSubitem->zAlias = 0;
133319 pSubitem->pSelect = 0;
133320
133321 /* Defer deleting the Table object associated with the
133322 ** subquery until code generation is
133323 ** complete, since there may still exist Expr.pTab entries that
133324 ** refer to the subquery even after flattening. Ticket #3346.
133325 **
133326 ** pSubitem->pTab is always non-NULL by test restrictions and tests above.
133327 */
133328 if( ALWAYS(pSubitem->pTab!=0) ){
133329 Table *pTabToDel = pSubitem->pTab;
133330 if( pTabToDel->nTabRef==1 ){
133331 Parse *pToplevel = sqlite3ParseToplevel(pParse);
133332 pTabToDel->pNextZombie = pToplevel->pZombieTab;
133333 pToplevel->pZombieTab = pTabToDel;
133334 }else{
133335 pTabToDel->nTabRef--;
133336 }
133337 pSubitem->pTab = 0;
133338 }
133339
133340 /* The following loop runs once for each term in a compound-subquery
133341 ** flattening (as described above). If we are doing a different kind
133342 ** of flattening - a flattening other than a compound-subquery flattening -
133343 ** then this loop only runs once.
133344 **
133345 ** This loop moves all of the FROM elements of the subquery into the
133346 ** the FROM clause of the outer query. Before doing this, remember
133347 ** the cursor number for the original outer query FROM element in
133348 ** iParent. The iParent cursor will never be used. Subsequent code
133349 ** will scan expressions looking for iParent references and replace
133350 ** those references with expressions that resolve to the subquery FROM
133351 ** elements we are now copying in.
133352 */
133353 for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
133354 int nSubSrc;
133355 u8 jointype = 0;
133356 assert( pSub!=0 );
133357 pSubSrc = pSub->pSrc; /* FROM clause of subquery */
133358 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
133359 pSrc = pParent->pSrc; /* FROM clause of the outer query */
133360
133361 if( pSrc ){
133362 assert( pParent==p ); /* First time through the loop */
133363 jointype = pSubitem->fg.jointype;
133364 }else{
133365 assert( pParent!=p ); /* 2nd and subsequent times through the loop */
133366 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
133367 if( pSrc==0 ) break;
133368 pParent->pSrc = pSrc;
133369 }
133370
133371 /* The subquery uses a single slot of the FROM clause of the outer
133372 ** query. If the subquery has more than one element in its FROM clause,
133373 ** then expand the outer query to make space for it to hold all elements
133374 ** of the subquery.
133375 **
133376 ** Example:
133377 **
133378 ** SELECT * FROM tabA, (SELECT * FROM sub1, sub2), tabB;
133379 **
133380 ** The outer query has 3 slots in its FROM clause. One slot of the
133381 ** outer query (the middle slot) is used by the subquery. The next
133382 ** block of code will expand the outer query FROM clause to 4 slots.
133383 ** The middle slot is expanded to two slots in order to make space
133384 ** for the two elements in the FROM clause of the subquery.
133385 */
133386 if( nSubSrc>1 ){
133387 pSrc = sqlite3SrcListEnlarge(pParse, pSrc, nSubSrc-1,iFrom+1);
133388 if( pSrc==0 ) break;
133389 pParent->pSrc = pSrc;
133390 }
133391
133392 /* Transfer the FROM clause terms from the subquery into the
133393 ** outer query.
133394 */
133395 for(i=0; i<nSubSrc; i++){
133396 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
133397 assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
133398 pSrc->a[i+iFrom] = pSubSrc->a[i];
133399 iNewParent = pSubSrc->a[i].iCursor;
133400 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
133401 }
133402 pSrc->a[iFrom].fg.jointype = jointype;
133403
133404 /* Now begin substituting subquery result set expressions for
133405 ** references to the iParent in the outer query.
133406 **
133407 ** Example:
133408 **
133409 ** SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b;
133410 ** \ \_____________ subquery __________/ /
133411 ** \_____________________ outer query ______________________________/
133412 **
133413 ** We look at every expression in the outer query and every place we see
133414 ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
133415 */
133416 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
133417 /* At this point, any non-zero iOrderByCol values indicate that the
133418 ** ORDER BY column expression is identical to the iOrderByCol'th
133419 ** expression returned by SELECT statement pSub. Since these values
133420 ** do not necessarily correspond to columns in SELECT statement pParent,
133421 ** zero them before transfering the ORDER BY clause.
133422 **
133423 ** Not doing this may cause an error if a subsequent call to this
133424 ** function attempts to flatten a compound sub-query into pParent
133425 ** (the only way this can happen is if the compound sub-query is
133426 ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */
133427 ExprList *pOrderBy = pSub->pOrderBy;
133428 for(i=0; i<pOrderBy->nExpr; i++){
133429 pOrderBy->a[i].u.x.iOrderByCol = 0;
133430 }
133431 assert( pParent->pOrderBy==0 );
133432 pParent->pOrderBy = pOrderBy;
133433 pSub->pOrderBy = 0;
133434 }
133435 pWhere = pSub->pWhere;
133436 pSub->pWhere = 0;
133437 if( isLeftJoin>0 ){
133438 sqlite3SetJoinExpr(pWhere, iNewParent);
133439 }
133440 if( pWhere ){
133441 if( pParent->pWhere ){
133442 pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
133443 }else{
133444 pParent->pWhere = pWhere;
133445 }
133446 }
133447 if( db->mallocFailed==0 ){
133448 SubstContext x;
133449 x.pParse = pParse;
133450 x.iTable = iParent;
133451 x.iNewTable = iNewParent;
133452 x.isLeftJoin = isLeftJoin;
133453 x.pEList = pSub->pEList;
133454 substSelect(&x, pParent, 0);
133455 }
133456
133457 /* The flattened query is a compound if either the inner or the
133458 ** outer query is a compound. */
133459 pParent->selFlags |= pSub->selFlags & SF_Compound;
133460 assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */
133461
133462 /*
133463 ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;
133464 **
133465 ** One is tempted to try to add a and b to combine the limits. But this
133466 ** does not work if either limit is negative.
133467 */
133468 if( pSub->pLimit ){
133469 pParent->pLimit = pSub->pLimit;
133470 pSub->pLimit = 0;
133471 }
133472
133473 /* Recompute the SrcList_item.colUsed masks for the flattened
133474 ** tables. */
133475 for(i=0; i<nSubSrc; i++){
133476 recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]);
133477 }
133478 }
133479
133480 /* Finially, delete what is left of the subquery and return
133481 ** success.
133482 */
133484 sqlite3WalkSelect(&w,pSub1);
133485 sqlite3SelectDelete(db, pSub1);
133486
133487#if SELECTTRACE_ENABLED
133488 if( sqlite3_unsupported_selecttrace & 0x100 ){
133489 SELECTTRACE(0x100,pParse,p,("After flattening:\n"));
#define SELECTTRACE(K, P, S, X)
Definition sqlite3.c:14550
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *, IdList *)
Definition sqlite3.c:114645
#define SF_Recursive
Definition sqlite3.c:18484
#define SQLITE_QueryFlattener
Definition sqlite3.c:17041
SQLITE_PRIVATE int sqlite3WalkSelect(Walker *, Select *)
Definition sqlite3.c:97691
SQLITE_PRIVATE SrcList * sqlite3SrcListEnlarge(Parse *, SrcList *, int, int)
Definition sqlite3.c:114700
static void substSelect(SubstContext *, Select *, int)
Definition sqlite3.c:132862
#define SF_NoopOrderBy
Definition sqlite3.c:18493
SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *, int)
Definition sqlite3.c:129674
#define SQLITE_DENY
Definition sqlite3.c:4097
#define SQLITE_SELECT
Definition sqlite3.c:4140
#define SF_Compound
Definition sqlite3.c:18479
#define SF_Aggregate
Definition sqlite3.c:18474
static void recomputeColumnsUsed(Select *pSelect, struct SrcList_item *pSrcItem)
Definition sqlite3.c:132906
SQLITE_API u32 sqlite3_unsupported_selecttrace
Definition sqlite3.c:20669
#define JT_OUTER
Definition sqlite3.c:18292
SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker *, Parse *)
Definition sqlite3.c:105496
#define OptimizationDisabled(db, mask)
Definition sqlite3.c:17063
#define SF_Distinct
Definition sqlite3.c:18471
union ExprList::ExprList_item::@111 u
struct ExprList::ExprList_item::@111::@112 x
Select * pNext
Definition sqlite3.c:18453
u32 selId
Definition sqlite3.c:18444
ExprList * pEList
Definition sqlite3.c:132751
Parse * pParse
Definition sqlite3.c:132747
u32 nTabRef
Definition sqlite3.c:17497
Table * pNextZombie
Definition sqlite3.c:17518

References ExprList::a, SrcList::a, ALWAYS, Parse::db, SrcList::SrcList_item::fg, SrcList::SrcList_item::iCursor, SubstContext::iNewTable, ExprList::ExprList_item::iOrderByCol, SubstContext::isLeftJoin, SrcList::SrcList_item::isTabFunc, IsVirtual, SubstContext::iTable, SrcList::SrcList_item::jointype, JT_OUTER, sqlite3::mallocFailed, ExprList::nExpr, SrcList::nSrc, Table::nTabRef, Select::op, OptimizationDisabled, Select::pEList, SubstContext::pEList, Select::pLimit, Select::pNext, Table::pNextZombie, Select::pOrderBy, SubstContext::pParse, Select::pPrior, Expr::pRight, Select::pSrc, SrcList::SrcList_item::pTab, SrcList::SrcList_item::pUsing, Select::pWhere, Select::pWin, Parse::pZombieTab, recomputeColumnsUsed(), SELECTTRACE, Select::selFlags, Select::selId, SF_Aggregate, SF_Compound, SF_Distinct, SF_NoopOrderBy, SF_Recursive, sqlite3_unsupported_selecttrace, sqlite3AggInfoPersistWalkerInit(), sqlite3AuthCheck(), sqlite3DbFree(), sqlite3IdListDelete(), sqlite3ParseToplevel, sqlite3PExpr(), sqlite3SelectDelete(), sqlite3SelectDup(), sqlite3SetJoinExpr(), sqlite3SrcListAppend(), sqlite3SrcListEnlarge(), sqlite3WalkSelect(), SQLITE_DENY, SQLITE_QueryFlattener, SQLITE_SELECT, substSelect(), testcase, TESTONLY, TK_ALL, TK_AND, ExprList::ExprList_item::u, ExprList::ExprList_item::x, and Parse::zAuthContext.

Referenced by sqlite3Select().

◆ freeEphemeralFunction()

static void freeEphemeralFunction ( sqlite3 * db,
FuncDef * pDef )
static

Definition at line 78834 of file sqlite3.c.

References FuncDef::funcFlags, sqlite3DbFreeNN(), and SQLITE_FUNC_EPHEM.

Referenced by sqlite3VdbeAddFunctionCall().

◆ freeP4()

static void freeP4 ( sqlite3 * db,
int p4type,
void * p4 )
static

Definition at line 78851 of file sqlite3.c.

78853 {
78854 freeEphemeralFunction(db, p->pFunc);
78855 sqlite3DbFreeNN(db, p);
78856}
78857static void freeP4(sqlite3 *db, int p4type, void *p4){
78858 assert( db );
78859 switch( p4type ){
78860 case P4_FUNCCTX: {
78862 break;
78863 }
78864 case P4_REAL:
78865 case P4_INT64:
78866 case P4_DYNAMIC:
78867 case P4_DYNBLOB:
78868 case P4_INTARRAY: {
78869 sqlite3DbFree(db, p4);
78870 break;
78871 }
78872 case P4_KEYINFO: {
78873 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
78874 break;
78875 }
78876#ifdef SQLITE_ENABLE_CURSOR_HINTS
78877 case P4_EXPR: {
78878 sqlite3ExprDelete(db, (Expr*)p4);
78879 break;
78880 }
78881#endif
78882 case P4_FUNCDEF: {
78884 break;
78885 }
78886 case P4_MEM: {
78887 if( db->pnBytesFreed==0 ){
78889 }else{
78890 freeP4Mem(db, (Mem*)p4);
78891 }
78892 break;
78893 }
#define P4_INT64
Definition sqlite3.c:15521
static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p)
Definition sqlite3.c:78843
#define P4_KEYINFO
Definition sqlite3.c:15516
#define P4_FUNCCTX
Definition sqlite3.c:15523
#define P4_REAL
Definition sqlite3.c:15520
#define P4_FUNCDEF
Definition sqlite3.c:15515
#define P4_INTARRAY
Definition sqlite3.c:15522
SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *, void *)
Definition sqlite3.c:27720
static void freeP4(sqlite3 *db, int p4type, void *p4)
Definition sqlite3.c:78851
SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *)
Definition sqlite3.c:130609
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef)
Definition sqlite3.c:78834
static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p)
Definition sqlite3.c:78847
#define P4_EXPR
Definition sqlite3.c:15517
#define P4_MEM
Definition sqlite3.c:15518
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *)
Definition sqlite3.c:77700

Referenced by sqlite3VdbeAppendP4(), vdbeChangeP4Full(), and vdbeFreeOpArray().

◆ freeP4FuncCtx()

static SQLITE_NOINLINE void freeP4FuncCtx ( sqlite3 * db,
sqlite3_context * p )
static

Definition at line 78847 of file sqlite3.c.

78849 {
78850 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);

References sqlite3DbFree(), sqlite3_value::szMalloc, and sqlite3_value::zMalloc.

◆ freeP4Mem()

static SQLITE_NOINLINE void freeP4Mem ( sqlite3 * db,
Mem * p )
static

Definition at line 78843 of file sqlite3.c.

◆ freePage()

static void freePage ( MemPage * pPage,
int * pRC )
static

Definition at line 70845 of file sqlite3.c.

Referenced by balance_nonroot(), and btreeDropTable().

◆ freePage2()

static int freePage2 ( BtShared * pBt,
MemPage * pMemPage,
Pgno iPage )
static

Definition at line 70711 of file sqlite3.c.

70717 {
70718 MemPage *pTrunk = 0; /* Free-list trunk page */
70719 Pgno iTrunk = 0; /* Page number of free-list trunk page */
70720 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
70721 MemPage *pPage; /* Page being freed. May be NULL. */
70722 int rc; /* Return Code */
70723 u32 nFree; /* Initial number of pages on free-list */
70724
70725 assert( sqlite3_mutex_held(pBt->mutex) );
70726 assert( CORRUPT_DB || iPage>1 );
70727 assert( !pMemPage || pMemPage->pgno==iPage );
70728
70729 if( iPage<2 || iPage>pBt->nPage ){
70730 return SQLITE_CORRUPT_BKPT;
70731 }
70732 if( pMemPage ){
70733 pPage = pMemPage;
70734 sqlite3PagerRef(pPage->pDbPage);
70735 }else{
70736 pPage = btreePageLookup(pBt, iPage);
70737 }
70738
70739 /* Increment the free page count on pPage1 */
70740 rc = sqlite3PagerWrite(pPage1->pDbPage);
70741 if( rc ) goto freepage_out;
70742 nFree = get4byte(&pPage1->aData[36]);
70743 put4byte(&pPage1->aData[36], nFree+1);
70744
70745 if( pBt->btsFlags & BTS_SECURE_DELETE ){
70746 /* If the secure_delete option is enabled, then
70747 ** always fully overwrite deleted information with zeros.
70748 */
70749 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
70750 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
70751 ){
70752 goto freepage_out;
70753 }
70754 memset(pPage->aData, 0, pPage->pBt->pageSize);
70755 }
70756
70757 /* If the database supports auto-vacuum, write an entry in the pointer-map
70758 ** to indicate that the page is free.
70759 */
70760 if( ISAUTOVACUUM ){
70761 ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
70762 if( rc ) goto freepage_out;
70763 }
70764
70765 /* Now manipulate the actual database free-list structure. There are two
70766 ** possibilities. If the free-list is currently empty, or if the first
70767 ** trunk page in the free-list is full, then this page will become a
70768 ** new free-list trunk page. Otherwise, it will become a leaf of the
70769 ** first trunk page in the current free-list. This block tests if it
70770 ** is possible to add the page as a new free-list leaf.
70771 */
70772 if( nFree!=0 ){
70773 u32 nLeaf; /* Initial number of leaf cells on trunk page */
70774
70775 iTrunk = get4byte(&pPage1->aData[32]);
70776 if( iTrunk>btreePagecount(pBt) ){
70778 goto freepage_out;
70779 }
70780 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
70781 if( rc!=SQLITE_OK ){
70782 goto freepage_out;
70783 }
70784
70785 nLeaf = get4byte(&pTrunk->aData[4]);
70786 assert( pBt->usableSize>32 );
70787 if( nLeaf > (u32)pBt->usableSize/4 - 2 ){
70789 goto freepage_out;
70790 }
70791 if( nLeaf < (u32)pBt->usableSize/4 - 8 ){
70792 /* In this case there is room on the trunk page to insert the page
70793 ** being freed as a new leaf.
70794 **
70795 ** Note that the trunk page is not really full until it contains
70796 ** usableSize/4 - 2 entries, not usableSize/4 - 8 entries as we have
70797 ** coded. But due to a coding error in versions of SQLite prior to
70798 ** 3.6.0, databases with freelist trunk pages holding more than
70799 ** usableSize/4 - 8 entries will be reported as corrupt. In order
70800 ** to maintain backwards compatibility with older versions of SQLite,
70801 ** we will continue to restrict the number of entries to usableSize/4 - 8
70802 ** for now. At some point in the future (once everyone has upgraded
70803 ** to 3.6.0 or later) we should consider fixing the conditional above
70804 ** to read "usableSize/4-2" instead of "usableSize/4-8".
70805 **
70806 ** EVIDENCE-OF: R-19920-11576 However, newer versions of SQLite still
70807 ** avoid using the last six entries in the freelist trunk page array in
70808 ** order that database files created by newer versions of SQLite can be
70809 ** read by older versions of SQLite.
70810 */
70811 rc = sqlite3PagerWrite(pTrunk->pDbPage);
70812 if( rc==SQLITE_OK ){
70813 put4byte(&pTrunk->aData[4], nLeaf+1);
70814 put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
70815 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
70817 }
70818 rc = btreeSetHasContent(pBt, iPage);
70819 }
70820 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
70821 goto freepage_out;
70822 }
70823 }
70824
70825 /* If control flows to this point, then it was not possible to add the
70826 ** the page being freed as a leaf page of the first trunk in the free-list.
70827 ** Possibly because the free-list is empty, or possibly because the
70828 ** first trunk in the free-list is full. Either way, the page being freed
70829 ** will become the new first trunk page in the free-list.
70830 */
70831 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
70832 goto freepage_out;
70833 }
70834 rc = sqlite3PagerWrite(pPage->pDbPage);
70835 if( rc!=SQLITE_OK ){
70836 goto freepage_out;
70837 }
70838 put4byte(pPage->aData, iTrunk);
70839 put4byte(&pPage->aData[4], 0);
70840 put4byte(&pPage1->aData[32], iPage);
70841 TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, iTrunk));
70842
70843freepage_out:
70844 if( pPage ){
SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage *)
Definition sqlite3.c:57882
SQLITE_PRIVATE void sqlite3PagerRef(DbPage *)
Definition sqlite3.c:55854
static int btreeSetHasContent(BtShared *pBt, Pgno pgno)
Definition sqlite3.c:65069
#define BTS_SECURE_DELETE
Definition sqlite3.c:63917

References MemPage::aData, btreeGetPage(), btreePagecount(), btreePageLookup(), btreeSetHasContent(), BTS_SECURE_DELETE, BtShared::btsFlags, CORRUPT_DB, get4byte, ISAUTOVACUUM, BtShared::mutex, BtShared::nPage, BtShared::pageSize, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, BtShared::pPage1, PTRMAP_FREEPAGE, ptrmapPut(), put4byte, sqlite3_mutex_held(), sqlite3PagerDontWrite(), sqlite3PagerRef(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_OK, TRACE, and BtShared::usableSize.

◆ freeSpace()

static int freeSpace ( MemPage * pPage,
u16 iStart,
u16 iSize )
static

Definition at line 66185 of file sqlite3.c.

66191 {
66192 u16 iPtr; /* Address of ptr to next freeblock */
66193 u16 iFreeBlk; /* Address of the next freeblock */
66194 u8 hdr; /* Page header size. 0 or 100 */
66195 u8 nFrag = 0; /* Reduction in fragmentation */
66196 u16 iOrigSize = iSize; /* Original value of iSize */
66197 u16 x; /* Offset to cell content area */
66198 u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */
66199 unsigned char *data = pPage->aData; /* Page content */
66200
66201 assert( pPage->pBt!=0 );
66202 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
66203 assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
66204 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
66205 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
66206 assert( iSize>=4 ); /* Minimum cell size is 4 */
66207 assert( iStart<=pPage->pBt->usableSize-4 );
66208
66209 /* The list of freeblocks must be in ascending order. Find the
66210 ** spot on the list where iStart should be inserted.
66211 */
66212 hdr = pPage->hdrOffset;
66213 iPtr = hdr + 1;
66214 if( data[iPtr+1]==0 && data[iPtr]==0 ){
66215 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
66216 }else{
66217 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
66218 if( iFreeBlk<iPtr+4 ){
66219 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
66220 return SQLITE_CORRUPT_PAGE(pPage);
66221 }
66222 iPtr = iFreeBlk;
66223 }
66224 if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
66225 return SQLITE_CORRUPT_PAGE(pPage);
66226 }
66227 assert( iFreeBlk>iPtr || iFreeBlk==0 );
66228
66229 /* At this point:
66230 ** iFreeBlk: First freeblock after iStart, or zero if none
66231 ** iPtr: The address of a pointer to iFreeBlk
66232 **
66233 ** Check to see if iFreeBlk should be coalesced onto the end of iStart.
66234 */
66235 if( iFreeBlk && iEnd+3>=iFreeBlk ){
66236 nFrag = iFreeBlk - iEnd;
66237 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
66238 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
66239 if( iEnd > pPage->pBt->usableSize ){
66240 return SQLITE_CORRUPT_PAGE(pPage);
66241 }
66242 iSize = iEnd - iStart;
66243 iFreeBlk = get2byte(&data[iFreeBlk]);
66244 }
66245
66246 /* If iPtr is another freeblock (that is, if iPtr is not the freelist
66247 ** pointer in the page header) then check to see if iStart should be
66248 ** coalesced onto the end of iPtr.
66249 */
66250 if( iPtr>hdr+1 ){
66251 int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
66252 if( iPtrEnd+3>=iStart ){
66253 if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage);
66254 nFrag += iStart - iPtrEnd;
66255 iSize = iEnd - iPtr;
66256 iStart = iPtr;
66257 }
66258 }
66259 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
66260 data[hdr+7] -= nFrag;
66261 }
66262 x = get2byte(&data[hdr+5]);
66263 if( iStart<=x ){
66264 /* The new freeblock is at the beginning of the cell content area,
66265 ** so just extend the cell content area rather than create another
66266 ** freelist entry */
66267 if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage);
66268 if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
66269 put2byte(&data[hdr+1], iFreeBlk);
66270 put2byte(&data[hdr+5], iEnd);
66271 }else{
66272 /* Insert the new freeblock into the freelist */
66273 put2byte(&data[iPtr], iStart);
66274 }
66275 if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
66276 /* Overwrite deleted information with zeros when the secure_delete
66277 ** option is enabled */
66278 memset(&data[iStart], 0, iSize);

References MemPage::aData, BTS_FAST_SECURE, BtShared::btsFlags, MemPage::childPtrSize, CORRUPT_DB, get2byte, MemPage::hdrOffset, BtShared::mutex, MemPage::nFree, MemPage::pBt, MemPage::pDbPage, put2byte, sqlite3_mutex_held(), SQLITE_CORRUPT_PAGE, SQLITE_OK, and BtShared::usableSize.

Referenced by dropCell(), and pageFreeArray().

◆ freeTempSpace()

static void freeTempSpace ( BtShared * pBt)
static

Definition at line 67175 of file sqlite3.c.

67181 {

Referenced by lockBtree(), and sqlite3BtreeSetPageSize().

◆ full_fsync()

static int full_fsync ( int fd,
int fullSync,
int dataOnly )
static

Definition at line 37122 of file sqlite3.c.

37128 {
37129 int rc;
37130
37131 /* The following "ifdef/elif/else/" block has the same structure as
37132 ** the one below. It is replicated here solely to avoid cluttering
37133 ** up the real code with the UNUSED_PARAMETER() macros.
37134 */
37135#ifdef SQLITE_NO_SYNC
37136 UNUSED_PARAMETER(fd);
37137 UNUSED_PARAMETER(fullSync);
37138 UNUSED_PARAMETER(dataOnly);
37139#elif HAVE_FULLFSYNC
37140 UNUSED_PARAMETER(dataOnly);
37141#else
37142 UNUSED_PARAMETER(fullSync);
37143 UNUSED_PARAMETER(dataOnly);
37144#endif
37145
37146 /* Record the number of times that we do a normal fsync() and
37147 ** FULLSYNC. This is used during testing to verify that this procedure
37148 ** gets called with the correct arguments.
37149 */
37150#ifdef SQLITE_TEST
37151 if( fullSync ) sqlite3_fullsync_count++;
37152 sqlite3_sync_count++;
37153#endif
37154
37155 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
37156 ** no-op. But go ahead and call fstat() to validate the file
37157 ** descriptor as we need a method to provoke a failure during
37158 ** coverate testing.
37159 */
37160#ifdef SQLITE_NO_SYNC
37161 {
37162 struct stat buf;
37163 rc = osFstat(fd, &buf);
37164 }
37165#elif HAVE_FULLFSYNC
37166 if( fullSync ){
37167 rc = osFcntl(fd, F_FULLFSYNC, 0);
37168 }else{
37169 rc = 1;
37170 }
37171 /* If the FULLFSYNC failed, fall back to attempting an fsync().
37172 ** It shouldn't be possible for fullfsync to fail on the local
37173 ** file system (on OSX), so failure indicates that FULLFSYNC
37174 ** isn't supported for this file system. So, attempt an fsync
37175 ** and (for now) ignore the overhead of a superfluous fcntl call.
37176 ** It'd be better to detect fullfsync support once and avoid
37177 ** the fcntl call every time sync is called.
37178 */
37179 if( rc ) rc = fsync(fd);
37180
37181#elif defined(__APPLE__)
37182 /* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly
37183 ** so currently we default to the macro that redefines fdatasync to fsync
37184 */
37185 rc = fsync(fd);
37186#else
37187 rc = fdatasync(fd);
37188#if OS_VXWORKS
37189 if( rc==-1 && errno==ENOTSUP ){
37190 rc = fsync(fd);
37191 }
37192#endif /* OS_VXWORKS */
37193#endif /* ifdef SQLITE_NO_SYNC elif HAVE_FULLFSYNC */
#define fdatasync
Definition sqlite3.c:37083
#define osFcntl

References fdatasync, OS_VXWORKS, osFcntl, osFstat, and UNUSED_PARAMETER.

Referenced by unixDelete(), and unixSync().

◆ functionDestroy()

static void functionDestroy ( sqlite3 * db,
FuncDef * p )
static

Definition at line 162127 of file sqlite3.c.

162133 {
162134 FuncDestructor *pDestructor = p->u.pDestructor;
162135 if( pDestructor ){
162136 pDestructor->nRef--;
FuncDestructor * pDestructor
Definition sqlite3.c:17106
union FuncDef::@106 u

References FuncDestructor::nRef, FuncDef::pDestructor, FuncDestructor::pUserData, sqlite3DbFree(), FuncDef::u, and FuncDestructor::xDestroy.

Referenced by sqlite3CreateFunc(), and sqlite3LeaveMutexAndCloseZombie().

◆ gatherSelectWindows()

static void gatherSelectWindows ( Select * p)
static

Definition at line 101132 of file sqlite3.c.

101135 {
101136 return p==pWalker->u.pSelect ? WRC_Continue : WRC_Prune;
101137}
101138static void gatherSelectWindows(Select *p){
101139 Walker w;
static int gatherSelectWindowsCallback(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:101118
static void gatherSelectWindows(Select *p)
Definition sqlite3.c:101132

◆ gatherSelectWindowsCallback()

static int gatherSelectWindowsCallback ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 101118 of file sqlite3.c.

101124 {
101125 if( pExpr->op==TK_FUNCTION && ExprHasProperty(pExpr, EP_WinFunc) ){
101126 Select *pSelect = pWalker->u.pSelect;
101127 Window *pWin = pExpr->y.pWin;
101128 assert( pWin );
Select * pSelect
Definition sqlite3.c:19108

References EP_WinFunc, ExprHasProperty, Expr::op, Walker::pSelect, Expr::pWin, TK_FUNCTION, Walker::u, and Expr::y.

◆ gatherSelectWindowsSelectCallback()

static int gatherSelectWindowsSelectCallback ( Walker * pWalker,
Select * p )
static

Definition at line 101129 of file sqlite3.c.

◆ generateColumnNames()

static void generateColumnNames ( Parse * pParse,
Select * pSelect )
static

Definition at line 131162 of file sqlite3.c.

131162 : COLUMN. Otherwise use zSpan.
131163**
131164** full=ON, short=ANY: If the result refers directly to a table column,
131165** then the result column name with the table name
131166** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.
131167*/
131168static void generateColumnNames(
131169 Parse *pParse, /* Parser context */
131170 Select *pSelect /* Generate column names for this SELECT statement */
131171){
131172 Vdbe *v = pParse->pVdbe;
131173 int i;
131174 Table *pTab;
131175 SrcList *pTabList;
131176 ExprList *pEList;
131177 sqlite3 *db = pParse->db;
131178 int fullName; /* TABLE.COLUMN if no AS clause and is a direct table ref */
131179 int srcName; /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
131180
131181#ifndef SQLITE_OMIT_EXPLAIN
131182 /* If this is an EXPLAIN, skip this step */
131183 if( pParse->explain ){
131184 return;
131185 }
131186#endif
131187
131188 if( pParse->colNamesSet ) return;
131189 /* Column names are determined by the left-most term of a compound select */
131190 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
131191 SELECTTRACE(1,pParse,pSelect,("generating column names\n"));
131192 pTabList = pSelect->pSrc;
131193 pEList = pSelect->pEList;
131194 assert( v!=0 );
131195 assert( pTabList!=0 );
131196 pParse->colNamesSet = 1;
131197 fullName = (db->flags & SQLITE_FullColNames)!=0;
131198 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
131199 sqlite3VdbeSetNumCols(v, pEList->nExpr);
131200 for(i=0; i<pEList->nExpr; i++){
131201 Expr *p = pEList->a[i].pExpr;
131202
131203 assert( p!=0 );
131204 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
131205 assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
131206 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
131207 /* An AS clause always takes first priority */
131208 char *zName = pEList->a[i].zEName;
131210 }else if( srcName && p->op==TK_COLUMN ){
131211 char *zCol;
131212 int iCol = p->iColumn;
131213 pTab = p->y.pTab;
131214 assert( pTab!=0 );
131215 if( iCol<0 ) iCol = pTab->iPKey;
131216 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
131217 if( iCol<0 ){
131218 zCol = "rowid";
131219 }else{
131220 zCol = pTab->aCol[iCol].zName;
131221 }
131222 if( fullName ){
131223 char *zName = 0;
131224 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
131226 }else{
131228 }
131229 }else{
131230 const char *z = pEList->a[i].zEName;
SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe *, int, int, const char *, void(*)(void *))
Definition sqlite3.c:80339
#define SQLITE_DYNAMIC
Definition sqlite3.c:14609
SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe *, int)
Definition sqlite3.c:80314
#define SQLITE_ShortColNames
Definition sqlite3.c:16984
#define SQLITE_FullColNames
Definition sqlite3.c:16980
#define ENAME_NAME
Definition sqlite3.c:18203
#define SQLITE_TRANSIENT
Definition sqlite3.c:6671
static void generateColumnNames(Parse *pParse, Select *pSelect)
Definition sqlite3.c:131162
#define COLNAME_NAME
Definition sqlite3.c:15536
u8 colNamesSet
Definition sqlite3.c:18684

References ExprList::a, Table::aCol, COLNAME_NAME, Parse::colNamesSet, Parse::db, ExprList::ExprList_item::eEName, ENAME_NAME, Parse::explain, sqlite3::flags, generateColumnTypes(), Expr::iColumn, Table::iPKey, ExprList::nExpr, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, Select::pPrior, Select::pSrc, Expr::pTab, Parse::pVdbe, SELECTTRACE, sqlite3DbStrDup(), sqlite3MPrintf(), sqlite3VdbeSetColName(), sqlite3VdbeSetNumCols(), SQLITE_DYNAMIC, SQLITE_FullColNames, SQLITE_ShortColNames, SQLITE_TRANSIENT, TK_AGG_COLUMN, TK_COLUMN, Expr::y, ExprList::ExprList_item::zEName, Column::zName, Table::zName, and zName.

Referenced by sqlite3Select().

◆ generateColumnTypes()

static void generateColumnTypes ( Parse * pParse,
SrcList * pTabList,
ExprList * pEList )
static

Definition at line 131095 of file sqlite3.c.

131105 {
131106#ifndef SQLITE_OMIT_DECLTYPE
131107 Vdbe *v = pParse->pVdbe;
131108 int i;
131109 NameContext sNC;
131110 sNC.pSrcList = pTabList;
131111 sNC.pParse = pParse;
131112 sNC.pNext = 0;
131113 for(i=0; i<pEList->nExpr; i++){
131114 Expr *p = pEList->a[i].pExpr;
131115 const char *zType;
131116#ifdef SQLITE_ENABLE_COLUMN_METADATA
131117 const char *zOrigDb = 0;
131118 const char *zOrigTab = 0;
131119 const char *zOrigCol = 0;
131120 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
131121
131122 /* The vdbe must make its own copy of the column-type and other
131123 ** column specific strings, in case the schema is reset before this
131124 ** virtual machine is deleted.
131125 */
131129#else
#define COLNAME_COLUMN
Definition sqlite3.c:15540
#define COLNAME_TABLE
Definition sqlite3.c:15539
#define COLNAME_DATABASE
Definition sqlite3.c:15538

Referenced by generateColumnNames().

◆ generateOutputSubroutine()

static int generateOutputSubroutine ( Parse * pParse,
Select * p,
SelectDest * pIn,
SelectDest * pDest,
int regReturn,
int regPrev,
KeyInfo * pKeyInfo,
int iBreak )
static

Definition at line 132229 of file sqlite3.c.

132244 {
132245 Vdbe *v = pParse->pVdbe;
132246 int iContinue;
132247 int addr;
132248
132249 addr = sqlite3VdbeCurrentAddr(v);
132250 iContinue = sqlite3VdbeMakeLabel(pParse);
132251
132252 /* Suppress duplicates for UNION, EXCEPT, and INTERSECT
132253 */
132254 if( regPrev ){
132255 int addr1, addr2;
132256 addr1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
132257 addr2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
132258 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
132259 sqlite3VdbeAddOp3(v, OP_Jump, addr2+2, iContinue, addr2+2); VdbeCoverage(v);
132260 sqlite3VdbeJumpHere(v, addr1);
132261 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
132262 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
132263 }
132264 if( pParse->db->mallocFailed ) return 0;
132265
132266 /* Suppress the first OFFSET entries if there is an OFFSET clause
132267 */
132268 codeOffset(v, p->iOffset, iContinue);
132269
132270 assert( pDest->eDest!=SRT_Exists );
132271 assert( pDest->eDest!=SRT_Table );
132272 switch( pDest->eDest ){
132273 /* Store the result as data using a unique key.
132274 */
132275 case SRT_EphemTab: {
132276 int r1 = sqlite3GetTempReg(pParse);
132277 int r2 = sqlite3GetTempReg(pParse);
132278 sqlite3VdbeAddOp3(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst, r1);
132279 sqlite3VdbeAddOp2(v, OP_NewRowid, pDest->iSDParm, r2);
132280 sqlite3VdbeAddOp3(v, OP_Insert, pDest->iSDParm, r1, r2);
132282 sqlite3ReleaseTempReg(pParse, r2);
132283 sqlite3ReleaseTempReg(pParse, r1);
132284 break;
132285 }
132286
132287#ifndef SQLITE_OMIT_SUBQUERY
132288 /* If we are creating a set for an "expr IN (SELECT ...)".
132289 */
132290 case SRT_Set: {
132291 int r1;
132292 testcase( pIn->nSdst>1 );
132293 r1 = sqlite3GetTempReg(pParse);
132295 r1, pDest->zAffSdst, pIn->nSdst);
132297 pIn->iSdst, pIn->nSdst);
132298 sqlite3ReleaseTempReg(pParse, r1);
132299 break;
132300 }
132301
132302 /* If this is a scalar select that is part of an expression, then
132303 ** store the results in the appropriate memory cell and break out
132304 ** of the scan loop. Note that the select might return multiple columns
132305 ** if it is the RHS of a row-value IN operator.
132306 */
132307 case SRT_Mem: {
132308 if( pParse->nErr==0 ){
132309 testcase( pIn->nSdst>1 );
132310 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst);
132311 }
132312 /* The LIMIT clause will jump out of the loop for us */
132313 break;
132314 }
132315#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
132316
132317 /* The results are stored in a sequence of registers
132318 ** starting at pDest->iSdst. Then the co-routine yields.
132319 */
132320 case SRT_Coroutine: {
132321 if( pDest->iSdst==0 ){
132322 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
132323 pDest->nSdst = pIn->nSdst;
132324 }
132325 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
132326 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
132327 break;
132328 }
132329
132330 /* If none of the above, then the result destination must be
132331 ** SRT_Output. This routine is never called with any other
132332 ** destination other than the ones handled above or SRT_Output.
132333 **
132334 ** For SRT_Output, results are stored in a sequence of registers.
132335 ** Then the OP_ResultRow opcode is used to cause sqlite3_step() to
132336 ** return the next row of result.
132337 */
132338 default: {
132339 assert( pDest->eDest==SRT_Output );
132340 sqlite3VdbeAddOp2(v, OP_ResultRow, pIn->iSdst, pIn->nSdst);
132341 break;
132342 }
132343 }
132344
132345 /* Jump to the end of the loop if the LIMIT is reached.
132346 */
132347 if( p->iLimit ){
132349 }
132350
132351 /* Generate the subroutine return
#define SRT_Output
Definition sqlite3.c:18580
#define OP_Compare
Definition sqlite3.c:15652
#define SRT_Mem
Definition sqlite3.c:18581
#define SRT_EphemTab
Definition sqlite3.c:18583
#define SRT_Exists
Definition sqlite3.c:18570
#define OP_ResultRow
Definition sqlite3.c:15646
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *, int, int, int)
Definition sqlite3.c:103320
#define SRT_Coroutine
Definition sqlite3.c:18584
#define SRT_Table
Definition sqlite3.c:18585
#define OP_DecrJumpZero
Definition sqlite3.c:15625
SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoRef(KeyInfo *)
Definition sqlite3.c:130620
#define SRT_Set
Definition sqlite3.c:18582
#define OP_Jump
Definition sqlite3.c:15582
static void codeOffset(Vdbe *v, int iOffset, int iContinue)
Definition sqlite3.c:130018
char * zAffSdst
Definition sqlite3.c:18598

References codeOffset(), Parse::db, SelectDest::eDest, Select::iLimit, Select::iOffset, SelectDest::iSDParm, SelectDest::iSdst, sqlite3::mallocFailed, Parse::nErr, SelectDest::nSdst, OP_Compare, OP_Copy, OP_DecrJumpZero, OP_IdxInsert, OP_IfNot, OP_Insert, OP_Integer, OP_Jump, OP_MakeRecord, OP_NewRowid, OP_ResultRow, OP_Return, OP_Yield, OPFLAG_APPEND, P4_KEYINFO, Parse::pVdbe, sqlite3ExprCodeMove(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3KeyInfoRef(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SRT_Coroutine, SRT_EphemTab, SRT_Exists, SRT_Mem, SRT_Output, SRT_Set, SRT_Table, testcase, VdbeCoverage, and SelectDest::zAffSdst.

Referenced by multiSelectOrderBy().

◆ generateSortTail()

static void generateSortTail ( Parse * pParse,
Select * p,
SortCtx * pSort,
int nColumn,
SelectDest * pDest )
static

Definition at line 130727 of file sqlite3.c.

130739 {
130740 Vdbe *v = pParse->pVdbe; /* The prepared statement */
130741 int addrBreak = pSort->labelDone; /* Jump here to exit loop */
130742 int addrContinue = sqlite3VdbeMakeLabel(pParse);/* Jump here for next cycle */
130743 int addr; /* Top of output loop. Jump for Next. */
130744 int addrOnce = 0;
130745 int iTab;
130746 ExprList *pOrderBy = pSort->pOrderBy;
130747 int eDest = pDest->eDest;
130748 int iParm = pDest->iSDParm;
130749 int regRow;
130750 int regRowid;
130751 int iCol;
130752 int nKey; /* Number of key columns in sorter record */
130753 int iSortTab; /* Sorter cursor to read from */
130754 int i;
130755 int bSeq; /* True if sorter record includes seq. no. */
130756 int nRefKey = 0;
130757 struct ExprList_item *aOutEx = p->pEList->a;
130758
130759 assert( addrBreak<0 );
130760 if( pSort->labelBkOut ){
130761 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
130762 sqlite3VdbeGoto(v, addrBreak);
130764 }
130765
130766#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130767 /* Open any cursors needed for sorter-reference expressions */
130768 for(i=0; i<pSort->nDefer; i++){
130769 Table *pTab = pSort->aDefer[i].pTab;
130770 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
130771 sqlite3OpenTable(pParse, pSort->aDefer[i].iCsr, iDb, pTab, OP_OpenRead);
130772 nRefKey = MAX(nRefKey, pSort->aDefer[i].nKey);
130773 }
130774#endif
130775
130776 iTab = pSort->iECursor;
130777 if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
130778 regRowid = 0;
130779 regRow = pDest->iSdst;
130780 }else{
130781 regRowid = sqlite3GetTempReg(pParse);
130782 if( eDest==SRT_EphemTab || eDest==SRT_Table ){
130783 regRow = sqlite3GetTempReg(pParse);
130784 nColumn = 0;
130785 }else{
130786 regRow = sqlite3GetTempRange(pParse, nColumn);
130787 }
130788 }
130789 nKey = pOrderBy->nExpr - pSort->nOBSat;
130790 if( pSort->sortFlags & SORTFLAG_UseSorter ){
130791 int regSortOut = ++pParse->nMem;
130792 iSortTab = pParse->nTab++;
130793 if( pSort->labelBkOut ){
130794 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
130795 }
130796 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut,
130797 nKey+1+nColumn+nRefKey);
130798 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
130799 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
130800 VdbeCoverage(v);
130801 codeOffset(v, p->iOffset, addrContinue);
130802 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
130803 bSeq = 0;
130804 }else{
130805 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
130806 codeOffset(v, p->iOffset, addrContinue);
130807 iSortTab = iTab;
130808 bSeq = 1;
130809 }
130810 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
130811#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130812 if( aOutEx[i].bSorterRef ) continue;
130813#endif
130814 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
130815 }
130816#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130817 if( pSort->nDefer ){
130818 int iKey = iCol+1;
130819 int regKey = sqlite3GetTempRange(pParse, nRefKey);
130820
130821 for(i=0; i<pSort->nDefer; i++){
130822 int iCsr = pSort->aDefer[i].iCsr;
130823 Table *pTab = pSort->aDefer[i].pTab;
130824 int nKey = pSort->aDefer[i].nKey;
130825
130826 sqlite3VdbeAddOp1(v, OP_NullRow, iCsr);
130827 if( HasRowid(pTab) ){
130828 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iKey++, regKey);
130830 sqlite3VdbeCurrentAddr(v)+1, regKey);
130831 }else{
130832 int k;
130833 int iJmp;
130834 assert( sqlite3PrimaryKeyIndex(pTab)->nKeyCol==nKey );
130835 for(k=0; k<nKey; k++){
130836 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iKey++, regKey+k);
130837 }
130838 iJmp = sqlite3VdbeCurrentAddr(v);
130839 sqlite3VdbeAddOp4Int(v, OP_SeekGE, iCsr, iJmp+2, regKey, nKey);
130840 sqlite3VdbeAddOp4Int(v, OP_IdxLE, iCsr, iJmp+3, regKey, nKey);
130841 sqlite3VdbeAddOp1(v, OP_NullRow, iCsr);
130842 }
130843 }
130844 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
130845 }
130846#endif
130847 for(i=nColumn-1; i>=0; i--){
130848#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130849 if( aOutEx[i].bSorterRef ){
130850 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
130851 }else
130852#endif
130853 {
130854 int iRead;
130855 if( aOutEx[i].u.x.iOrderByCol ){
130856 iRead = aOutEx[i].u.x.iOrderByCol-1;
130857 }else{
130858 iRead = iCol--;
130859 }
130860 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
130861 VdbeComment((v, "%s", aOutEx[i].zEName));
130862 }
130863 }
130864 switch( eDest ){
130865 case SRT_Table:
130866 case SRT_EphemTab: {
130867 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq, regRow);
130868 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
130869 sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
130871 break;
130872 }
130873#ifndef SQLITE_OMIT_SUBQUERY
130874 case SRT_Set: {
130875 assert( nColumn==sqlite3Strlen30(pDest->zAffSdst) );
130876 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, nColumn, regRowid,
130877 pDest->zAffSdst, nColumn);
130878 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, regRowid, regRow, nColumn);
130879 break;
130880 }
130881 case SRT_Mem: {
130882 /* The LIMIT clause will terminate the loop for us */
130883 break;
130884 }
130885#endif
130886 case SRT_Upfrom: {
130887 int i2 = pDest->iSDParm2;
130888 int r1 = sqlite3GetTempReg(pParse);
130889 sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
130890 if( i2<0 ){
130891 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, regRow);
130892 }else{
130893 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regRow, i2);
130894 }
130895 break;
130896 }
130897 default: {
130898 assert( eDest==SRT_Output || eDest==SRT_Coroutine );
130899 testcase( eDest==SRT_Output );
130900 testcase( eDest==SRT_Coroutine );
130901 if( eDest==SRT_Output ){
130902 sqlite3VdbeAddOp2(v, OP_ResultRow, pDest->iSdst, nColumn);
130903 }else{
130904 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
130905 }
130906 break;
130907 }
130908 }
130909 if( regRowid ){
130910 if( eDest==SRT_Set ){
130911 sqlite3ReleaseTempRange(pParse, regRow, nColumn);
130912 }else{
130913 sqlite3ReleaseTempReg(pParse, regRow);
130914 }
130915 sqlite3ReleaseTempReg(pParse, regRowid);
130916 }
130917 /* The bottom of the loop
130918 */
130919 sqlite3VdbeResolveLabel(v, addrContinue);
130920 if( pSort->sortFlags & SORTFLAG_UseSorter ){
130921 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
#define OP_Gosub
Definition sqlite3.c:15578
#define OP_SeekGE
Definition sqlite3.c:15590
#define OP_OpenPseudo
Definition sqlite3.c:15680
#define OP_SorterSort
Definition sqlite3.c:15601
#define OP_NullRow
Definition sqlite3.c:15694
#define OP_SeekRowid
Definition sqlite3.c:15597
#define SORTFLAG_UseSorter
Definition sqlite3.c:129362
#define OP_Sort
Definition sqlite3.c:15602
#define OP_SorterNext
Definition sqlite3.c:15569
#define OP_SorterData
Definition sqlite3.c:15691
#define SRT_Upfrom
Definition sqlite3.c:18586
#define OP_IdxLE
Definition sqlite3.c:15604
int labelDone
Definition sqlite3.c:129349
int nOBSat
Definition sqlite3.c:129344
ExprList * pOrderBy
Definition sqlite3.c:129343
int regReturn
Definition sqlite3.c:129346
int labelBkOut
Definition sqlite3.c:129347
u8 sortFlags
Definition sqlite3.c:129351
int iECursor
Definition sqlite3.c:129345

References ExprList::a, codeOffset(), Parse::db, SelectDest::eDest, HasRowid, SortCtx::iECursor, Select::iOffset, SelectDest::iSDParm, SelectDest::iSDParm2, SelectDest::iSdst, SortCtx::labelBkOut, SortCtx::labelDone, MAX, ExprList::nExpr, Parse::nMem, SortCtx::nOBSat, Parse::nTab, OP_Column, OP_Gosub, OP_IdxInsert, OP_IdxLE, OP_Insert, OP_MakeRecord, OP_NewRowid, OP_Next, OP_NullRow, OP_Once, OP_OpenPseudo, OP_OpenRead, OP_ResultRow, OP_Return, OP_SeekGE, OP_SeekRowid, OP_Sort, OP_SorterData, OP_SorterNext, OP_SorterSort, OP_Yield, OPFLAG_APPEND, Select::pEList, SortCtx::pOrderBy, Table::pSchema, Parse::pVdbe, SortCtx::regReturn, SORTFLAG_UseSorter, SortCtx::sortFlags, sqlite3ExprCode(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3OpenTable(), sqlite3PrimaryKeyIndex(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3SchemaToIndex(), sqlite3Strlen30(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SRT_Coroutine, SRT_EphemTab, SRT_Mem, SRT_Output, SRT_Set, SRT_Table, SRT_Upfrom, testcase, VdbeComment, VdbeCoverage, and SelectDest::zAffSdst.

Referenced by sqlite3Select().

◆ generateWithRecursiveQuery()

static void generateWithRecursiveQuery ( Parse * pParse,
Select * p,
SelectDest * pDest )
static

Definition at line 131627 of file sqlite3.c.

131637 {
131638 SrcList *pSrc = p->pSrc; /* The FROM clause of the recursive query */
131639 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
131640 Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */
131641 Select *pSetup = p->pPrior; /* The setup query */
131642 int addrTop; /* Top of the loop */
131643 int addrCont, addrBreak; /* CONTINUE and BREAK addresses */
131644 int iCurrent = 0; /* The Current table */
131645 int regCurrent; /* Register holding Current table */
131646 int iQueue; /* The Queue table */
131647 int iDistinct = 0; /* To ensure unique results if UNION */
131648 int eDest = SRT_Fifo; /* How to write to Queue */
131649 SelectDest destQueue; /* SelectDest targetting the Queue table */
131650 int i; /* Loop counter */
131651 int rc; /* Result code */
131652 ExprList *pOrderBy; /* The ORDER BY clause */
131653 Expr *pLimit; /* Saved LIMIT and OFFSET */
131654 int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
131655
131656#ifndef SQLITE_OMIT_WINDOWFUNC
131657 if( p->pWin ){
131658 sqlite3ErrorMsg(pParse, "cannot use window functions in recursive queries");
131659 return;
131660 }
131661#endif
131662
131663 /* Obtain authorization to do a recursive query */
131664 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
131665
131666 /* Process the LIMIT and OFFSET clauses, if they exist */
131667 addrBreak = sqlite3VdbeMakeLabel(pParse);
131668 p->nSelectRow = 320; /* 4 billion rows */
131669 computeLimitRegisters(pParse, p, addrBreak);
131670 pLimit = p->pLimit;
131671 regLimit = p->iLimit;
131672 regOffset = p->iOffset;
131673 p->pLimit = 0;
131674 p->iLimit = p->iOffset = 0;
131675 pOrderBy = p->pOrderBy;
131676
131677 /* Locate the cursor number of the Current table */
131678 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
131679 if( pSrc->a[i].fg.isRecursive ){
131680 iCurrent = pSrc->a[i].iCursor;
131681 break;
131682 }
131683 }
131684
131685 /* Allocate cursors numbers for Queue and Distinct. The cursor number for
131686 ** the Distinct table must be exactly one greater than Queue in order
131687 ** for the SRT_DistFifo and SRT_DistQueue destinations to work. */
131688 iQueue = pParse->nTab++;
131689 if( p->op==TK_UNION ){
131690 eDest = pOrderBy ? SRT_DistQueue : SRT_DistFifo;
131691 iDistinct = pParse->nTab++;
131692 }else{
131693 eDest = pOrderBy ? SRT_Queue : SRT_Fifo;
131694 }
131695 sqlite3SelectDestInit(&destQueue, eDest, iQueue);
131696
131697 /* Allocate cursors for Current, Queue, and Distinct. */
131698 regCurrent = ++pParse->nMem;
131699 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iCurrent, regCurrent, nCol);
131700 if( pOrderBy ){
131701 KeyInfo *pKeyInfo = multiSelectOrderByKeyInfo(pParse, p, 1);
131702 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, iQueue, pOrderBy->nExpr+2, 0,
131703 (char*)pKeyInfo, P4_KEYINFO);
131704 destQueue.pOrderBy = pOrderBy;
131705 }else{
131706 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iQueue, nCol);
131707 }
131708 VdbeComment((v, "Queue table"));
131709 if( iDistinct ){
131710 p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iDistinct, 0);
131712 }
131713
131714 /* Detach the ORDER BY clause from the compound SELECT */
131715 p->pOrderBy = 0;
131716
131717 /* Store the results of the setup-query in Queue. */
131718 pSetup->pNext = 0;
131719 ExplainQueryPlan((pParse, 1, "SETUP"));
131720 rc = sqlite3Select(pParse, pSetup, &destQueue);
131721 pSetup->pNext = p;
131722 if( rc ) goto end_of_recursive_query;
131723
131724 /* Find the next row in the Queue and output that row */
131725 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v);
131726
131727 /* Transfer the next row in Queue over to Current */
131728 sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
131729 if( pOrderBy ){
131730 sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
131731 }else{
131732 sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
131733 }
131734 sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
131735
131736 /* Output the single row in Current */
131737 addrCont = sqlite3VdbeMakeLabel(pParse);
131738 codeOffset(v, regOffset, addrCont);
131739 selectInnerLoop(pParse, p, iCurrent,
131740 0, 0, pDest, addrCont, addrBreak);
131741 if( regLimit ){
131742 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
131743 VdbeCoverage(v);
131744 }
131745 sqlite3VdbeResolveLabel(v, addrCont);
131746
131747 /* Execute the recursive SELECT taking the single row in Current as
131748 ** the value for the recursive-table. Store the results in the Queue.
131749 */
131750 if( p->selFlags & SF_Aggregate ){
131751 sqlite3ErrorMsg(pParse, "recursive aggregate queries not supported");
131752 }else{
131753 p->pPrior = 0;
131754 ExplainQueryPlan((pParse, 1, "RECURSIVE STEP"));
131755 sqlite3Select(pParse, p, &destQueue);
131756 assert( p->pPrior==0 );
131757 p->pPrior = pSetup;
131758 }
131759
131760 /* Keep running the loop until the Queue is empty */
131761 sqlite3VdbeGoto(v, addrTop);
131762 sqlite3VdbeResolveLabel(v, addrBreak);
131763
#define OP_RowData
Definition sqlite3.c:15692
static void selectInnerLoop(Parse *pParse, Select *p, int srcTab, SortCtx *pSort, DistinctCtx *pDistinct, SelectDest *pDest, int iContinue, int iBreak)
Definition sqlite3.c:130147
#define OP_OpenEphemeral
Definition sqlite3.c:15666
#define OP_Delete
Definition sqlite3.c:15688
static KeyInfo * multiSelectOrderByKeyInfo(Parse *pParse, Select *p, int nExtra)
Definition sqlite3.c:131561
#define SQLITE_RECURSIVE
Definition sqlite3.c:4153
#define SRT_DistFifo
Definition sqlite3.c:18573
#define ExplainQueryPlan(P)
Definition sqlite3.c:15830
#define SRT_Queue
Definition sqlite3.c:18574
#define SRT_Fifo
Definition sqlite3.c:18572
#define SF_UsesEphemeral
Definition sqlite3.c:18476
#define TK_UNION
Definition sqlite3.c:14074
#define SRT_DistQueue
Definition sqlite3.c:18575
static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak)
Definition sqlite3.c:131478
ExprList * pOrderBy
Definition sqlite3.c:18599
int addrOpenEphm[2]
Definition sqlite3.c:18445

References SrcList::a, Select::addrOpenEphm, ALWAYS, codeOffset(), computeLimitRegisters(), Parse::db, ExplainQueryPlan, SrcList::SrcList_item::fg, SrcList::SrcList_item::iCursor, Select::iLimit, Select::iOffset, SrcList::SrcList_item::isRecursive, multiSelectOrderByKeyInfo(), ExprList::nExpr, Parse::nMem, Select::nSelectRow, Parse::nTab, Select::op, OP_Column, OP_DecrJumpZero, OP_Delete, OP_NullRow, OP_OpenEphemeral, OP_OpenPseudo, OP_Rewind, OP_RowData, P4_KEYINFO, Select::pEList, Select::pLimit, Select::pNext, Select::pOrderBy, SelectDest::pOrderBy, Select::pPrior, Select::pSrc, Parse::pVdbe, Select::pWin, selectInnerLoop(), Select::selFlags, SF_Aggregate, SF_UsesEphemeral, sqlite3AuthCheck(), sqlite3ErrorMsg(), sqlite3ExprListDelete(), sqlite3Select(), sqlite3SelectDestInit(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeGoto(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_RECURSIVE, SRT_DistFifo, SRT_DistQueue, SRT_Fifo, SRT_Queue, TK_UNION, VdbeComment, and VdbeCoverage.

Referenced by multiSelect().

◆ getAndInitPage()

static int getAndInitPage ( BtShared * pBt,
Pgno pgno,
MemPage ** ppPage,
BtCursor * pCur,
int bReadOnly )
static

Definition at line 66639 of file sqlite3.c.

66651 {
66652 int rc;
66653 DbPage *pDbPage;
66654 assert( sqlite3_mutex_held(pBt->mutex) );
66655 assert( pCur==0 || ppPage==&pCur->pPage );
66656 assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
66657 assert( pCur==0 || pCur->iPage>0 );
66658
66659 if( pgno>btreePagecount(pBt) ){
66661 goto getAndInitPage_error1;
66662 }
66663 rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
66664 if( rc ){
66665 goto getAndInitPage_error1;
66666 }
66667 *ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
66668 if( (*ppPage)->isInit==0 ){
66669 btreePageFromDbPage(pDbPage, pgno, pBt);
66670 rc = btreeInitPage(*ppPage);
66671 if( rc!=SQLITE_OK ){
66672 goto getAndInitPage_error2;
66673 }
66674 }
66675 assert( (*ppPage)->pgno==pgno );
66676 assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
66677
66678 /* If obtaining a child page for a cursor, we must verify that the page is
66679 ** compatible with the root page. */
66680 if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
66681 rc = SQLITE_CORRUPT_PGNO(pgno);
66682 goto getAndInitPage_error2;
66683 }
66684 return SQLITE_OK;
66685
66686getAndInitPage_error2:
66687 releasePage(*ppPage);
66688getAndInitPage_error1:
66689 if( pCur ){
66690 pCur->iPage--;
static MemPage * btreePageFromDbPage(DbPage *pDbPage, Pgno pgno, BtShared *pBt)
Definition sqlite3.c:66558
u8 curIntKey
Definition sqlite3.c:63995

References BtCursor::apPage, btreeInitPage(), btreePagecount(), btreePageFromDbPage(), BtCursor::curIntKey, BtCursor::curPagerFlags, BtCursor::iPage, BtShared::mutex, BtCursor::pPage, BtShared::pPager, releasePage(), sqlite3_mutex_held(), sqlite3PagerGet(), sqlite3PagerGetData(), sqlite3PagerGetExtra(), SQLITE_CORRUPT, SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_PGNO, SQLITE_OK, and testcase.

Referenced by balance_nonroot(), moveToChild(), and moveToRoot().

◆ getAutoVacuum()

static int getAutoVacuum ( const char * z)
static

Definition at line 125836 of file sqlite3.c.

125842 {
125843 int i;

References BTREE_AUTOVACUUM_FULL, BTREE_AUTOVACUUM_INCR, BTREE_AUTOVACUUM_NONE, sqlite3Atoi(), and sqlite3StrICmp().

Referenced by sqlite3Pragma().

◆ getCellInfo()

static SQLITE_NOINLINE void getCellInfo ( BtCursor * pCur)
static

Definition at line 69023 of file sqlite3.c.

69029 {
69030 if( pCur->info.nSize==0 ){

Referenced by accessPayload(), sqlite3BtreeInsert(), sqlite3BtreeIntegerKey(), sqlite3BtreeMovetoUnpacked(), and sqlite3BtreePayloadSize().

◆ getDigits()

static int getDigits ( const char * zDate,
const char * zFormat,
... )
static

Definition at line 21819 of file sqlite3.c.

21824 {
21825 /* The aMx[] array translates the 3rd character of each format
21826 ** spec into a max size: a b c d e f */
21827 static const u16 aMx[] = { 12, 14, 24, 31, 59, 9999 };
21828 va_list ap;
21829 int cnt = 0;
21830 char nextC;
21831 va_start(ap, zFormat);
21832 do{
21833 char N = zFormat[0] - '0';
21834 char min = zFormat[1] - '0';
21835 int val = 0;
21836 u16 max;
21837
21838 assert( zFormat[2]>='a' && zFormat[2]<='f' );
21839 max = aMx[zFormat[2] - 'a'];
21840 nextC = zFormat[3];
21841 val = 0;
21842 while( N-- ){
21843 if( !sqlite3Isdigit(*zDate) ){
21844 goto end_getDigits;
21845 }
21846 val = val*10 + *zDate - '0';
21847 zDate++;
21848 }
21849 if( val<(int)min || val>(int)max || (nextC!=0 && nextC!=*zDate) ){
21850 goto end_getDigits;
21851 }
21852 *va_arg(ap,int*) = val;
21853 zDate++;
21854 cnt++;
21855 zFormat += 4;
#define sqlite3Isdigit(x)
Definition sqlite3.c:19322

References sqlite3Isdigit.

Referenced by parseHhMmSs(), parseTimezone(), and parseYyyyMmDd().

◆ getDoubleArg()

static double getDoubleArg ( PrintfArguments * p)
static

Definition at line 28290 of file sqlite3.c.

28292 {
28293 if( p->nArg<=p->nUsed ) return 0;

References PrintfArguments::nArg, and PrintfArguments::nUsed.

Referenced by sqlite3_str_vappendf().

◆ getFileMode()

static int getFileMode ( const char * zFile,
mode_t * pMode,
uid_t * pUid,
gid_t * pGid )
static

Definition at line 39382 of file sqlite3.c.

39393 {
39394 struct stat sStat; /* Output of stat() on database file */
39395 int rc = SQLITE_OK;
39396 if( 0==osStat(zFile, &sStat) ){
39397 *pMode = sStat.st_mode & 0777;
39398 *pUid = sStat.st_uid;

Referenced by findCreateFileMode().

◆ getIntArg()

static sqlite3_int64 getIntArg ( PrintfArguments * p)
static

Definition at line 28286 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ getLockingMode()

static int getLockingMode ( const char * z)
static

◆ getOverflowPage()

static int getOverflowPage ( BtShared * pBt,
Pgno ovfl,
MemPage ** ppPage,
Pgno * pPgnoNext )
static

Definition at line 69141 of file sqlite3.c.

69152 {
69153 Pgno next = 0;
69154 MemPage *pPage = 0;
69155 int rc = SQLITE_OK;
69156
69157 assert( sqlite3_mutex_held(pBt->mutex) );
69158 assert(pPgnoNext);
69159
69160#ifndef SQLITE_OMIT_AUTOVACUUM
69161 /* Try to find the next page in the overflow list using the
69162 ** autovacuum pointer-map pages. Guess that the next page in
69163 ** the overflow list is page number (ovfl+1). If that guess turns
69164 ** out to be wrong, fall back to loading the data of page
69165 ** number ovfl to determine the next page number.
69166 */
69167 if( pBt->autoVacuum ){
69168 Pgno pgno;
69169 Pgno iGuess = ovfl+1;
69170 u8 eType;
69171
69172 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
69173 iGuess++;
69174 }
69175
69176 if( iGuess<=btreePagecount(pBt) ){
69177 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
69178 if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
69179 next = iGuess;
69180 rc = SQLITE_DONE;
69181 }
69182 }
69183 }
69184#endif
69185
69186 assert( next==0 || rc==SQLITE_DONE );
69187 if( rc==SQLITE_OK ){
69188 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
69189 assert( rc==SQLITE_OK || pPage==0 );
69190 if( rc==SQLITE_OK ){
69191 next = get4byte(pPage->aData);
69192 }
69193 }
69194
69195 *pPgnoNext = next;
69196 if( ppPage ){

References MemPage::aData, BtShared::autoVacuum, btreeGetPage(), btreePagecount(), eType, get4byte, BtShared::mutex, next, PAGER_GET_READONLY, PENDING_BYTE_PAGE, PTRMAP_ISPAGE, PTRMAP_OVERFLOW2, ptrmapGet(), releasePage(), sqlite3_mutex_held(), SQLITE_DONE, and SQLITE_OK.

Referenced by accessPayload().

◆ getPageError()

static int getPageError ( Pager * pPager,
Pgno pgno,
DbPage ** ppPage,
int flags )
static

Definition at line 57326 of file sqlite3.c.

57337 {

Referenced by setGetterMethod().

◆ getPageNormal()

static int getPageNormal ( Pager * pPager,
Pgno pgno,
DbPage ** ppPage,
int flags )
static

Definition at line 57155 of file sqlite3.c.

57166 {
57167 int rc = SQLITE_OK;
57168 PgHdr *pPg;
57169 u8 noContent; /* True if PAGER_GET_NOCONTENT is set */
57170 sqlite3_pcache_page *pBase;
57171
57172 assert( pPager->errCode==SQLITE_OK );
57173 assert( pPager->eState>=PAGER_READER );
57174 assert( assert_pager_state(pPager) );
57175 assert( pPager->hasHeldSharedLock==1 );
57176
57177 if( pgno==0 ) return SQLITE_CORRUPT_BKPT;
57178 pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
57179 if( pBase==0 ){
57180 pPg = 0;
57181 rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
57182 if( rc!=SQLITE_OK ) goto pager_acquire_err;
57183 if( pBase==0 ){
57184 rc = SQLITE_NOMEM_BKPT;
57185 goto pager_acquire_err;
57186 }
57187 }
57188 pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
57189 assert( pPg==(*ppPage) );
57190 assert( pPg->pgno==pgno );
57191 assert( pPg->pPager==pPager || pPg->pPager==0 );
57192
57193 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
57194 if( pPg->pPager && !noContent ){
57195 /* In this case the pcache already contains an initialized copy of
57196 ** the page. Return without further ado. */
57197 assert( pgno!=PAGER_MJ_PGNO(pPager) );
57198 pPager->aStat[PAGER_STAT_HIT]++;
57199 return SQLITE_OK;
57200
57201 }else{
57202 /* The pager cache has created a new page. Its content needs to
57203 ** be initialized. But first some error checks:
57204 **
57205 ** (*) obsolete. Was: maximum page number is 2^31
57206 ** (2) Never try to fetch the locking page
57207 */
57208 if( pgno==PAGER_MJ_PGNO(pPager) ){
57210 goto pager_acquire_err;
57211 }
57212
57213 pPg->pPager = pPager;
57214
57215 assert( !isOpen(pPager->fd) || !MEMDB );
57216 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
57217 if( pgno>pPager->mxPgno ){
57218 rc = SQLITE_FULL;
57219 goto pager_acquire_err;
57220 }
57221 if( noContent ){
57222 /* Failure to set the bits in the InJournal bit-vectors is benign.
57223 ** It merely means that we might do some extra work to journal a
57224 ** page that does not need to be journaled. Nevertheless, be sure
57225 ** to test the case where a malloc error occurs while trying to set
57226 ** a bit in a bit vector.
57227 */
57229 if( pgno<=pPager->dbOrigSize ){
57230 TESTONLY( rc = ) sqlite3BitvecSet(pPager->pInJournal, pgno);
57231 testcase( rc==SQLITE_NOMEM );
57232 }
57233 TESTONLY( rc = ) addToSavepointBitvecs(pPager, pgno);
57234 testcase( rc==SQLITE_NOMEM );
57236 }
57237 memset(pPg->pData, 0, pPager->pageSize);
57238 IOTRACE(("ZERO %p %d\n", pPager, pgno));
57239 }else{
57240 assert( pPg->pPager==pPager );
57241 pPager->aStat[PAGER_STAT_MISS]++;
57242 rc = readDbPage(pPg);
57243 if( rc!=SQLITE_OK ){
57244 goto pager_acquire_err;
57245 }
57246 }
57247 pager_set_pagehash(pPg);
57248 }
57249 return SQLITE_OK;
57250
57251pager_acquire_err:
57252 assert( rc!=SQLITE_OK );
57253 if( pPg ){
#define SQLITE_FULL
Definition sqlite3.c:1483
#define IOTRACE(A)
Definition sqlite3.c:20290
SQLITE_PRIVATE PgHdr * sqlite3PcacheFetchFinish(PCache *, Pgno, sqlite3_pcache_page *pPage)
Definition sqlite3.c:49359
SQLITE_PRIVATE void sqlite3BeginBenignMalloc(void)
Definition sqlite3.c:23469
SQLITE_PRIVATE void sqlite3EndBenignMalloc(void)
Definition sqlite3.c:23475
#define pager_set_pagehash(X)
Definition sqlite3.c:52968
SQLITE_PRIVATE sqlite3_pcache_page * sqlite3PcacheFetch(PCache *, Pgno, int createFlag)
Definition sqlite3.c:49236
#define isOpen(pFd)
Definition sqlite3.c:52503
SQLITE_PRIVATE int sqlite3PcacheFetchStress(PCache *, Pgno, sqlite3_pcache_page **)
Definition sqlite3.c:49277
#define PAGER_STAT_HIT
Definition sqlite3.c:52409
static int addToSavepointBitvecs(Pager *pPager, Pgno pgno)
Definition sqlite3.c:53484
#define PAGER_MJ_PGNO(x)
Definition sqlite3.c:14803
#define MEMDB
Definition sqlite3.c:52478
#define PAGER_STAT_MISS
Definition sqlite3.c:52410
#define PAGER_READER
Definition sqlite3.c:52054
static int readDbPage(PgHdr *pPg)
Definition sqlite3.c:54651
int aStat[4]
Definition sqlite3.c:52390
u8 hasHeldSharedLock
Definition sqlite3.c:52351
Pgno mxPgno
Definition sqlite3.c:52384
int errCode
Definition sqlite3.c:52356
PCache * pPCache
Definition sqlite3.c:52397
u8 eState
Definition sqlite3.c:52344
Pager * pPager
Definition sqlite3.c:16050
Pgno pgno
Definition sqlite3.c:16051

References addToSavepointBitvecs(), Pager::aStat, Pager::dbSize, Pager::errCode, Pager::eState, Pager::fd, Pager::hasHeldSharedLock, IOTRACE, isOpen, MEMDB, Pager::mxPgno, PAGER_GET_NOCONTENT, PAGER_MJ_PGNO, PAGER_READER, pager_set_pagehash, PAGER_STAT_HIT, PAGER_STAT_MISS, pagerUnlockIfUnused(), Pager::pageSize, PgHdr::pData, PgHdr::pgno, Pager::pInJournal, PgHdr::pPager, Pager::pPCache, readDbPage(), sqlite3BeginBenignMalloc(), sqlite3BitvecSet(), sqlite3EndBenignMalloc(), sqlite3PcacheDrop(), sqlite3PcacheFetch(), sqlite3PcacheFetchFinish(), sqlite3PcacheFetchStress(), SQLITE_CORRUPT_BKPT, SQLITE_FULL, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, and TESTONLY.

Referenced by setGetterMethod().

◆ getPageReferenced()

static int getPageReferenced ( IntegrityCk * pCheck,
Pgno iPg )
static

Definition at line 74133 of file sqlite3.c.

References IntegrityCk::aPgRef.

Referenced by checkRef(), and sqlite3BtreeIntegrityCheck().

◆ getRowTrigger()

static TriggerPrg * getRowTrigger ( Parse * pParse,
Trigger * pTrigger,
Table * pTab,
int orconf )
static

Definition at line 137395 of file sqlite3.c.

137406 {
137407 Parse *pRoot = sqlite3ParseToplevel(pParse);
137408 TriggerPrg *pPrg;
137409
137410 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
137411
137412 /* It may be that this trigger has already been coded (or is in the
137413 ** process of being coded). If this is the case, then an entry with
137414 ** a matching TriggerPrg.pTrigger field will be present somewhere
137415 ** in the Parse.pTriggerPrg list. Search for such an entry. */
137416 for(pPrg=pRoot->pTriggerPrg;
137417 pPrg && (pPrg->pTrigger!=pTrigger || pPrg->orconf!=orconf);
137418 pPrg=pPrg->pNext
137419 );
137420
137421 /* If an existing TriggerPrg could not be located, create a new one. */

References codeRowTrigger(), TriggerPrg::orconf, TriggerPrg::pNext, TriggerPrg::pTrigger, Parse::pTriggerPrg, sqlite3ParseToplevel, tableOfTrigger(), and Trigger::zName.

Referenced by sqlite3CodeRowTriggerDirect(), and sqlite3TriggerColmask().

◆ getSafetyLevel()

static u8 getSafetyLevel ( const char * z,
int omitFull,
u8 dflt )
static

Definition at line 125783 of file sqlite3.c.

125789 {
125790 /* 123456789 123456789 123 */
125791 static const char zText[] = "onoffalseyestruextrafull";
125792 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 15, 20};
125793 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 5, 4};
125794 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
125795 /* on no off false yes true extra full */
125796 int i, n;
125797 if( sqlite3Isdigit(*z) ){
125798 return (u8)sqlite3Atoi(z);
125799 }
125800 n = sqlite3Strlen30(z);
125801 for(i=0; i<ArraySize(iLength); i++){
125802 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
125803 && (!omitFull || iValue[i]<=1)
#define sqlite3StrNICmp
Definition sqlite3.c:19345

References ArraySize, sqlite3Atoi(), sqlite3Isdigit, sqlite3Strlen30(), and sqlite3StrNICmp.

Referenced by sqlite3Pragma().

◆ getTempStore()

static int getTempStore ( const char * z)
static

Definition at line 125852 of file sqlite3.c.

125858 {
125859 if( z[0]>='0' && z[0]<='2' ){
125860 return z[0] - '0';
125861 }else if( sqlite3StrICmp(z, "file")==0 ){
125862 return 1;

References sqlite3StrICmp().

Referenced by changeTempStorage().

◆ getTextArg()

static char * getTextArg ( PrintfArguments * p)
static

Definition at line 28294 of file sqlite3.c.

28296 {
28297 if( p->nArg<=p->nUsed ) return 0.0;

Referenced by sqlite3_str_vappendf().

◆ getToken()

static int getToken ( const unsigned char ** pz)
static

Definition at line 159932 of file sqlite3.c.

159938 {
159939 const unsigned char *z = *pz;
159940 int t; /* Token type to return */
159941 do {
159942 z += sqlite3GetToken(z, &t);
159943 }while( t==TK_SPACE );
159944 if( t==TK_ID
159945 || t==TK_STRING
159946 || t==TK_JOIN_KW
159947 || t==TK_WINDOW
159948 || t==TK_OVER
SQLITE_PRIVATE int sqlite3ParserFallback(int)
Definition sqlite3.c:159245
#define TK_SPACE
Definition sqlite3.c:14121
#define TK_JOIN_KW
Definition sqlite3.c:14058
#define TK_WINDOW
Definition sqlite3.c:14103

References sqlite3GetToken(), sqlite3ParserFallback(), TK_ID, TK_JOIN_KW, TK_OVER, TK_SPACE, TK_STRING, and TK_WINDOW.

Referenced by analyzeFilterKeyword().

◆ groupConcatFinalize()

static void groupConcatFinalize ( sqlite3_context * context)
static

Definition at line 118825 of file sqlite3.c.

118831 {
118832 StrAccum *pAccum;
118833 pAccum = sqlite3_aggregate_context(context, 0);
118834 if( pAccum ){
118835 if( pAccum->accError==SQLITE_TOOBIG ){
118837 }else if( pAccum->accError==SQLITE_NOMEM ){
#define SQLITE_TOOBIG
Definition sqlite3.c:1488

Referenced by sqlite3RegisterBuiltinFunctions().

◆ groupConcatInverse()

static void groupConcatInverse ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118794 of file sqlite3.c.

118804 {
118805 int n;
118806 StrAccum *pAccum;
118807 assert( argc==1 || argc==2 );
118808 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
118809 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
118810 /* pAccum is always non-NULL since groupConcatStep() will have always
118811 ** run frist to initialize it */
118812 if( ALWAYS(pAccum) ){
118813 n = sqlite3_value_bytes(argv[0]);
118814 if( argc==2 ){
118815 n += sqlite3_value_bytes(argv[1]);
118816 }else{
118817 n++;
118818 }
118819 if( n>=(int)pAccum->nChar ){
118820 pAccum->nChar = 0;
118821 }else{
SQLITE_API int sqlite3_value_bytes(sqlite3_value *)
Definition sqlite3.c:83166

Referenced by sqlite3RegisterBuiltinFunctions().

◆ groupConcatStep()

static void groupConcatStep ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118761 of file sqlite3.c.

118771 {
118772 const char *zVal;
118773 StrAccum *pAccum;
118774 const char *zSep;
118775 int nVal, nSep;
118776 assert( argc==1 || argc==2 );
118777 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
118778 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
118779
118780 if( pAccum ){
118781 sqlite3 *db = sqlite3_context_db_handle(context);
118782 int firstTerm = pAccum->mxAlloc==0;
118783 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
118784 if( !firstTerm ){
118785 if( argc==2 ){
118786 zSep = (char*)sqlite3_value_text(argv[1]);
118787 nSep = sqlite3_value_bytes(argv[1]);
118788 }else{
118789 zSep = ",";
118790 nSep = 1;
118791 }
118792 if( zSep ) sqlite3_str_append(pAccum, zSep, nSep);

Referenced by sqlite3RegisterBuiltinFunctions().

◆ groupConcatValue()

static void groupConcatValue ( sqlite3_context * context)
static

Definition at line 118840 of file sqlite3.c.

118846 {
118847 sqlite3_str *pAccum;
118848 pAccum = (sqlite3_str*)sqlite3_aggregate_context(context, 0);
118849 if( pAccum ){
118850 if( pAccum->accError==SQLITE_TOOBIG ){
118852 }else if( pAccum->accError==SQLITE_NOMEM ){

Referenced by sqlite3RegisterBuiltinFunctions().

◆ growOp3()

static SQLITE_NOINLINE int growOp3 ( Vdbe * p,
int op,
int p1,
int p2,
int p3 )
static

Definition at line 77960 of file sqlite3.c.

◆ growOpArray()

static int growOpArray ( Vdbe * v,
int nOp )
static

Definition at line 77889 of file sqlite3.c.

77895 {
77896 VdbeOp *pNew;
77897 Parse *p = v->pParse;
77898
77899 /* The SQLITE_TEST_REALLOC_STRESS compile-time option is designed to force
77900 ** more frequent reallocs and hence provide more opportunities for
77901 ** simulated OOM faults. SQLITE_TEST_REALLOC_STRESS is generally used
77902 ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
77903 ** by the minimum* amount required until the size reaches 512. Normal
77904 ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
77905 ** size of the op array or add 1KB of space, whichever is smaller. */
77906#ifdef SQLITE_TEST_REALLOC_STRESS
77907 sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc
77908 : (sqlite3_int64)v->nOpAlloc+nOp);
77909#else
77910 sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc
77911 : (sqlite3_int64)(1024/sizeof(Op)));
77912 UNUSED_PARAMETER(nOp);
77913#endif
77914
77915 /* Ensure that the size of a VDBE does not grow too large */
77916 if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
77917 sqlite3OomFault(p->db);
77918 return SQLITE_NOMEM;
77919 }
77920
77921 assert( nOp<=(1024/sizeof(Op)) );
77922 assert( nNew>=(v->nOpAlloc+nOp) );
77923 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
77924 if( pNew ){
#define SQLITE_LIMIT_VDBE_OP
Definition sqlite3.c:4949
Op * aOp
Definition sqlite3.c:21108
Parse * pParse
Definition sqlite3.c:21086
int nOpAlloc
Definition sqlite3.c:21110

References sqlite3::aLimit, Vdbe::aOp, Parse::db, Vdbe::nOpAlloc, Vdbe::pParse, sqlite3DbMallocSize(), sqlite3DbRealloc(), sqlite3OomFault(), SQLITE_LIMIT_VDBE_OP, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, Parse::szOpAlloc, and UNUSED_PARAMETER.

Referenced by sqlite3VdbeAddOp3(), and sqlite3VdbeAddOpList().

◆ growVTrans()

static int growVTrans ( sqlite3 * db)
static

Definition at line 140288 of file sqlite3.c.

140294 {
140295 const int ARRAY_INCR = 5;
140296
140297 /* Grow the sqlite3.aVTrans array if required */
140298 if( (db->nVTrans%ARRAY_INCR)==0 ){
140299 VTable **aVTrans;
140300 sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)*
140301 ((sqlite3_int64)db->nVTrans + ARRAY_INCR);
140302 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
140303 if( !aVTrans ){
140304 return SQLITE_NOMEM_BKPT;
140305 }

Referenced by sqlite3VtabBegin(), and sqlite3VtabCallCreate().

◆ handleMovedCursor()

static int SQLITE_NOINLINE handleMovedCursor ( VdbeCursor * p)
static

Definition at line 81261 of file sqlite3.c.

81267 {
81268 int isDifferentRow, rc;
81269 assert( p->eCurType==CURTYPE_BTREE );
81270 assert( p->uc.pCursor!=0 );

References CACHE_STALE, VdbeCursor::cacheStatus, CURTYPE_BTREE, VdbeCursor::eCurType, VdbeCursor::nullRow, VdbeCursor::pCursor, sqlite3BtreeCursorHasMoved(), sqlite3BtreeCursorRestore(), and VdbeCursor::uc.

Referenced by sqlite3VdbeCursorMoveto().

◆ hasColumn()

static int hasColumn ( const i16 * aiCol,
int nCol,
int x )
static

Definition at line 112323 of file sqlite3.c.

112329 {
112330 while( nCol-- > 0 ){
112331 assert( aiCol[0]>=0 );

Referenced by convertToWithoutRowidTable(), and sqlite3CreateIndex().

◆ hasHotJournal()

static int hasHotJournal ( Pager * pPager,
int * pExists )
static

Definition at line 56754 of file sqlite3.c.

56760 {
56761 sqlite3_vfs * const pVfs = pPager->pVfs;
56762 int rc = SQLITE_OK; /* Return code */
56763 int exists = 1; /* True if a journal file is present */
56764 int jrnlOpen = !!isOpen(pPager->jfd);
56765
56766 assert( pPager->useJournal );
56767 assert( isOpen(pPager->fd) );
56768 assert( pPager->eState==PAGER_OPEN );
56769
56770 assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
56772 ));
56773
56774 *pExists = 0;
56775 if( !jrnlOpen ){
56776 rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists);
56777 }
56778 if( rc==SQLITE_OK && exists ){
56779 int locked = 0; /* True if some process holds a RESERVED lock */
56780
56781 /* Race condition here: Another process might have been holding the
56782 ** the RESERVED lock and have a journal open at the sqlite3OsAccess()
56783 ** call above, but then delete the journal and drop the lock before
56784 ** we get to the following sqlite3OsCheckReservedLock() call. If that
56785 ** is the case, this routine might think there is a hot journal when
56786 ** in fact there is none. This results in a false-positive which will
56787 ** be dealt with by the playback routine. Ticket #3883.
56788 */
56789 rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
56790 if( rc==SQLITE_OK && !locked ){
56791 Pgno nPage; /* Number of pages in database file */
56792
56793 assert( pPager->tempFile==0 );
56794 rc = pagerPagecount(pPager, &nPage);
56795 if( rc==SQLITE_OK ){
56796 /* If the database is zero pages in size, that means that either (1) the
56797 ** journal is a remnant from a prior database with the same name where
56798 ** the database file but not the journal was deleted, or (2) the initial
56799 ** transaction that populates a new database is being rolled back.
56800 ** In either case, the journal file can be deleted. However, take care
56801 ** not to delete the journal file if it is already open due to
56802 ** journal_mode=PERSIST.
56803 */
56804 if( nPage==0 && !jrnlOpen ){
56806 if( pagerLockDb(pPager, RESERVED_LOCK)==SQLITE_OK ){
56807 sqlite3OsDelete(pVfs, pPager->zJournal, 0);
56808 if( !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
56809 }
56811 }else{
56812 /* The journal file exists and no other connection has a reserved
56813 ** or greater lock on the database file. Now check that there is
56814 ** at least one non-zero bytes at the start of the journal file.
56815 ** If there is, then we consider this journal to be hot. If not,
56816 ** it can be ignored.
56817 */
56818 if( !jrnlOpen ){
56820 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &f);
56821 }
56822 if( rc==SQLITE_OK ){
56823 u8 first = 0;
56824 rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
56825 if( rc==SQLITE_IOERR_SHORT_READ ){
56826 rc = SQLITE_OK;
56827 }
56828 if( !jrnlOpen ){
56829 sqlite3OsClose(pPager->jfd);
56830 }
56831 *pExists = (first!=0);
56832 }else if( rc==SQLITE_CANTOPEN ){
56833 /* If we cannot open the rollback journal file in order to see if
56834 ** it has a zero header, that might be due to an I/O error, or
56835 ** it might be due to the race condition described above and in
56836 ** ticket #3883. Either way, assume that the journal is hot.
56837 ** This might be a false positive. But if it is, then the
56838 ** automatic journal playback and recovery mechanism will deal
56839 ** with it under an EXCLUSIVE lock where we do not need to
56840 ** worry so much with race conditions.
56841 */
56842 *pExists = 1;
56843 rc = SQLITE_OK;
56844 }
56845 }
SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int *)
Definition sqlite3.c:23166
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
Definition sqlite3.c:1672
SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id)
Definition sqlite3.c:23117
static int pagerPagecount(Pager *pPager, Pgno *pnPage)
Definition sqlite3.c:54908
#define RESERVED_LOCK
Definition sqlite3.c:16361
#define SQLITE_IOERR_SHORT_READ
Definition sqlite3.c:1524
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int)
Definition sqlite3.c:23183
static int pagerLockDb(Pager *pPager, int eLock)
Definition sqlite3.c:52859
#define SQLITE_ACCESS_EXISTS
Definition sqlite3.c:2476
static int pagerUnlockDb(Pager *pPager, int eLock)
Definition sqlite3.c:52831
#define PAGER_OPEN
Definition sqlite3.c:52053
SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut)
Definition sqlite3.c:23075
SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file *)
Definition sqlite3.c:23043
#define SQLITE_CANTOPEN
Definition sqlite3.c:1484
SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut)
Definition sqlite3.c:23188
u8 exclusiveMode
Definition sqlite3.c:52322
sqlite3_file * jfd
Definition sqlite3.c:52362
char * zJournal
Definition sqlite3.c:52387
u8 useJournal
Definition sqlite3.c:52324
sqlite3_vfs * pVfs
Definition sqlite3.c:52321

References Pager::eState, Pager::exclusiveMode, Pager::fd, isOpen, Pager::jfd, PAGER_OPEN, pagerLockDb(), pagerPagecount(), pagerUnlockDb(), Pager::pVfs, RESERVED_LOCK, SHARED_LOCK, sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), sqlite3OsAccess(), sqlite3OsCheckReservedLock(), sqlite3OsClose(), sqlite3OsDelete(), sqlite3OsDeviceCharacteristics(), sqlite3OsOpen(), sqlite3OsRead(), SQLITE_ACCESS_EXISTS, SQLITE_CANTOPEN, SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN, SQLITE_IOERR_SHORT_READ, SQLITE_OK, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_READONLY, Pager::tempFile, Pager::useJournal, and Pager::zJournal.

Referenced by sqlite3PagerSharedLock().

◆ havingToWhere()

static void havingToWhere ( Parse * pParse,
Select * p )
static

Definition at line 134912 of file sqlite3.c.

134918 {
134919 Walker sWalker;
134920 memset(&sWalker, 0, sizeof(sWalker));
134921 sWalker.pParse = pParse;
134923 sWalker.u.pSelect = p;
134924 sqlite3WalkExpr(&sWalker, p->pHaving);
134925#if SELECTTRACE_ENABLED
SQLITE_PRIVATE int sqlite3WalkExpr(Walker *, Expr *)
Definition sqlite3.c:97600
static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:134878

References Walker::eCode, havingToWhereExprCb(), Select::pHaving, Walker::pParse, Walker::pSelect, SELECTTRACE, sqlite3_unsupported_selecttrace, sqlite3WalkExpr(), Walker::u, and Walker::xExprCallback.

Referenced by sqlite3Select().

◆ havingToWhereExprCb()

static int havingToWhereExprCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 134878 of file sqlite3.c.

134884 {
134885 if( pExpr->op!=TK_AND ){
134886 Select *pS = pWalker->u.pSelect;
134887 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){
134888 sqlite3 *db = pWalker->pParse->db;
134889 Expr *pNew = sqlite3Expr(db, TK_INTEGER, "1");
134890 if( pNew ){
134891 Expr *pWhere = pS->pWhere;
134892 SWAP(Expr, *pNew, *pExpr);
134893 pNew = sqlite3ExprAnd(pWalker->pParse, pWhere, pNew);
134894 pS->pWhere = pNew;
134895 pWalker->eCode = 1;
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *, Expr *, ExprList *)
Definition sqlite3.c:101882
#define TK_INTEGER
Definition sqlite3.c:14094

References Parse::db, Walker::eCode, Expr::op, Select::pGroupBy, Walker::pParse, Walker::pSelect, Select::pWhere, sqlite3Expr(), sqlite3ExprAnd(), sqlite3ExprIsConstantOrGroupBy(), SWAP, TK_AND, TK_INTEGER, Walker::u, WRC_Continue, and WRC_Prune.

Referenced by havingToWhere().

◆ heightOfExpr()

static void heightOfExpr ( Expr * p,
int * pnHeight )
static

Definition at line 100400 of file sqlite3.c.

100406 {

Referenced by exprSetHeight(), and heightOfSelect().

◆ heightOfExprList()

static void heightOfExprList ( ExprList * p,
int * pnHeight )
static

Definition at line 100407 of file sqlite3.c.

100407 {
100408 if( p->nHeight>*pnHeight ){
100409 *pnHeight = p->nHeight;
100410 }
100411 }
100412}
100413static void heightOfExprList(ExprList *p, int *pnHeight){
100414 if( p ){
static void heightOfExprList(ExprList *p, int *pnHeight)
Definition sqlite3.c:100407

References Expr::nHeight.

Referenced by exprSetHeight().

◆ heightOfSelect()

static void heightOfSelect ( Select * pSelect,
int * pnHeight )
static

Definition at line 100415 of file sqlite3.c.

100416 {
100417 heightOfExpr(p->a[i].pExpr, pnHeight);
100418 }
100419 }
100420}
100421static void heightOfSelect(Select *pSelect, int *pnHeight){
100422 Select *p;
100423 for(p=pSelect; p; p=p->pPrior){
100424 heightOfExpr(p->pWhere, pnHeight);
100425 heightOfExpr(p->pHaving, pnHeight);

References ExprList::a, heightOfExpr(), and ExprList::ExprList_item::pExpr.

Referenced by exprSetHeight().

◆ hexFunc()

static void hexFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118211 of file sqlite3.c.

118221 {
118222 int i, n;
118223 const unsigned char *pBlob;
118224 char *zHex, *z;
118225 assert( argc==1 );
118226 UNUSED_PARAMETER(argc);
118227 pBlob = sqlite3_value_blob(argv[0]);
118228 n = sqlite3_value_bytes(argv[0]);
118229 assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
118230 z = zHex = contextMalloc(context, ((i64)n)*2 + 1);
118231 if( zHex ){
118232 for(i=0; i<n; i++, pBlob++){
118233 unsigned char c = *pBlob;
118234 *(z++) = hexdigits[(c>>4)&0xf];
static void * contextMalloc(sqlite3_context *context, i64 nByte)
Definition sqlite3.c:117479
static const char hexdigits[]
Definition sqlite3.c:118067
SQLITE_API const void * sqlite3_value_blob(sqlite3_value *)
Definition sqlite3.c:83153

Referenced by sqlite3RegisterBuiltinFunctions().

◆ identLength()

static int identLength ( const char * z)
static

Definition at line 112152 of file sqlite3.c.

112158 {

Referenced by createTableStmt().

◆ identPut()

static void identPut ( char * z,
int * pIdx,
char * zSignedIdent )
static

Definition at line 112173 of file sqlite3.c.

112179 {
112180 unsigned char *zIdent = (unsigned char*)zSignedIdent;
112181 int i, j, needQuote;
112182 i = *pIdx;
112183
112184 for(j=0; zIdent[j]; j++){
112185 if( !sqlite3Isalnum(zIdent[j]) && zIdent[j]!='_' ) break;
112186 }
112187 needQuote = sqlite3Isdigit(zIdent[0])
112188 || sqlite3KeywordCode(zIdent, j)!=TK_ID
112189 || zIdent[j]!=0
112190 || j==0;
112191
112192 if( needQuote ) z[i++] = '"';
112193 for(j=0; zIdent[j]; j++){
112194 z[i++] = zIdent[j];
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *, int)
Definition sqlite3.c:159865
#define sqlite3Isalnum(x)
Definition sqlite3.c:19320

References sqlite3Isalnum, sqlite3Isdigit, sqlite3KeywordCode(), and TK_ID.

Referenced by createTableStmt().

◆ impliesNotNullRow()

static int impliesNotNullRow ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 105180 of file sqlite3.c.

105186 {
105187 testcase( pExpr->op==TK_AGG_COLUMN );
105188 testcase( pExpr->op==TK_AGG_FUNCTION );
105189 if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
105190 switch( pExpr->op ){
105191 case TK_ISNOT:
105192 case TK_ISNULL:
105193 case TK_NOTNULL:
105194 case TK_IS:
105195 case TK_OR:
105196 case TK_VECTOR:
105197 case TK_CASE:
105198 case TK_IN:
105199 case TK_FUNCTION:
105200 case TK_TRUTH:
105201 testcase( pExpr->op==TK_ISNOT );
105202 testcase( pExpr->op==TK_ISNULL );
105203 testcase( pExpr->op==TK_NOTNULL );
105204 testcase( pExpr->op==TK_IS );
105205 testcase( pExpr->op==TK_OR );
105206 testcase( pExpr->op==TK_VECTOR );
105207 testcase( pExpr->op==TK_CASE );
105208 testcase( pExpr->op==TK_IN );
105209 testcase( pExpr->op==TK_FUNCTION );
105210 testcase( pExpr->op==TK_TRUTH );
105211 return WRC_Prune;
105212 case TK_COLUMN:
105213 if( pWalker->u.iCur==pExpr->iTable ){
105214 pWalker->eCode = 1;
105215 return WRC_Abort;
105216 }
105217 return WRC_Prune;
105218
105219 case TK_AND:
105220 if( pWalker->eCode==0 ){
105221 sqlite3WalkExpr(pWalker, pExpr->pLeft);
105222 if( pWalker->eCode ){
105223 pWalker->eCode = 0;
105224 sqlite3WalkExpr(pWalker, pExpr->pRight);
105225 }
105226 }
105227 return WRC_Prune;
105228
105229 case TK_BETWEEN:
105230 if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
105231 assert( pWalker->eCode );
105232 return WRC_Abort;
105233 }
105234 return WRC_Prune;
105235
105236 /* Virtual tables are allowed to use constraints like x=NULL. So
105237 ** a term of the form x=y does not prove that y is not null if x
105238 ** is the column of a virtual table */
105239 case TK_EQ:
105240 case TK_NE:
105241 case TK_LT:
105242 case TK_LE:
105243 case TK_GT:
105244 case TK_GE: {
105245 Expr *pLeft = pExpr->pLeft;
105246 Expr *pRight = pExpr->pRight;
105247 testcase( pExpr->op==TK_EQ );
105248 testcase( pExpr->op==TK_NE );
105249 testcase( pExpr->op==TK_LT );
105250 testcase( pExpr->op==TK_LE );
105251 testcase( pExpr->op==TK_GT );
105252 testcase( pExpr->op==TK_GE );
105253 /* The y.pTab=0 assignment in wherecode.c always happens after the
105254 ** impliesNotNullRow() test */
105255 if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
105256 && IsVirtual(pLeft->y.pTab))
105257 || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
105258 && IsVirtual(pRight->y.pTab))
105259 ){
105260 return WRC_Prune;
105261 }

References ALWAYS, deliberate_fall_through, Walker::eCode, EP_FromJoin, ExprHasProperty, Walker::iCur, IsVirtual, Expr::iTable, Expr::op, Expr::pLeft, Expr::pRight, Expr::pTab, sqlite3WalkExpr(), testcase, TK_AGG_COLUMN, TK_AGG_FUNCTION, TK_AND, TK_BETWEEN, TK_CASE, TK_COLUMN, TK_EQ, TK_FUNCTION, TK_GE, TK_GT, TK_IN, TK_IS, TK_ISNOT, TK_ISNULL, TK_LE, TK_LT, TK_NE, TK_NOTNULL, TK_OR, TK_TRUTH, TK_VECTOR, Walker::u, WRC_Abort, WRC_Continue, WRC_Prune, and Expr::y.

Referenced by sqlite3ExprImpliesNonNullRow().

◆ incrAggDepth()

static int incrAggDepth ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 97784 of file sqlite3.c.

◆ incrAggFunctionDepth()

static void incrAggFunctionDepth ( Expr * pExpr,
int N )
static

Definition at line 97788 of file sqlite3.c.

97790 {
97791 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n;
97792 return WRC_Continue;
97793}
97794static void incrAggFunctionDepth(Expr *pExpr, int N){
97795 if( N>0 ){
97796 Walker w;
static void incrAggFunctionDepth(Expr *pExpr, int N)
Definition sqlite3.c:97788

References Walker::n, Expr::op, Expr::op2, TK_AGG_FUNCTION, Walker::u, and WRC_Continue.

Referenced by resolveAlias().

◆ incrVacuumStep()

static int incrVacuumStep ( BtShared * pBt,
Pgno nFin,
Pgno iLastPg,
int bCommit )
static

Definition at line 68230 of file sqlite3.c.

68236 {
68237 Pgno nFreeList; /* Number of pages still on the free-list */
68238 int rc;
68239
68240 assert( sqlite3_mutex_held(pBt->mutex) );
68241 assert( iLastPg>nFin );
68242
68243 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
68244 u8 eType;
68245 Pgno iPtrPage;
68246
68247 nFreeList = get4byte(&pBt->pPage1->aData[36]);
68248 if( nFreeList==0 ){
68249 return SQLITE_DONE;
68250 }
68251
68252 rc = ptrmapGet(pBt, iLastPg, &eType, &iPtrPage);
68253 if( rc!=SQLITE_OK ){
68254 return rc;
68255 }
68256 if( eType==PTRMAP_ROOTPAGE ){
68257 return SQLITE_CORRUPT_BKPT;
68258 }
68259
68260 if( eType==PTRMAP_FREEPAGE ){
68261 if( bCommit==0 ){
68262 /* Remove the page from the files free-list. This is not required
68263 ** if bCommit is non-zero. In that case, the free-list will be
68264 ** truncated to zero after this function returns, so it doesn't
68265 ** matter if it still contains some garbage entries.
68266 */
68267 Pgno iFreePg;
68268 MemPage *pFreePg;
68269 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iLastPg, BTALLOC_EXACT);
68270 if( rc!=SQLITE_OK ){
68271 return rc;
68272 }
68273 assert( iFreePg==iLastPg );
68274 releasePage(pFreePg);
68275 }
68276 } else {
68277 Pgno iFreePg; /* Index of free page to move pLastPg to */
68278 MemPage *pLastPg;
68279 u8 eMode = BTALLOC_ANY; /* Mode parameter for allocateBtreePage() */
68280 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
68281
68282 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
68283 if( rc!=SQLITE_OK ){
68284 return rc;
68285 }
68286
68287 /* If bCommit is zero, this loop runs exactly once and page pLastPg
68288 ** is swapped with the first free page pulled off the free list.
68289 **
68290 ** On the other hand, if bCommit is greater than zero, then keep
68291 ** looping until a free-page located within the first nFin pages
68292 ** of the file is found.
68293 */
68294 if( bCommit==0 ){
68295 eMode = BTALLOC_LE;
68296 iNear = nFin;
68297 }
68298 do {
68299 MemPage *pFreePg;
68300 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
68301 if( rc!=SQLITE_OK ){
68302 releasePage(pLastPg);
68303 return rc;
68304 }
68305 releasePage(pFreePg);
68306 }while( bCommit && iFreePg>nFin );
68307 assert( iFreePg<iLastPg );
68308
68309 rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
68310 releasePage(pLastPg);
68311 if( rc!=SQLITE_OK ){
68312 return rc;
68313 }
68314 }
68315 }
68316
68317 if( bCommit==0 ){
68318 do {
68319 iLastPg--;

References MemPage::aData, allocateBtreePage(), BtShared::bDoTruncate, BTALLOC_ANY, BTALLOC_EXACT, BTALLOC_LE, btreeGetPage(), eType, get4byte, BtShared::mutex, BtShared::nPage, PENDING_BYTE_PAGE, BtShared::pPage1, PTRMAP_FREEPAGE, PTRMAP_ISPAGE, PTRMAP_ROOTPAGE, ptrmapGet(), releasePage(), relocatePage(), sqlite3_mutex_held(), SQLITE_CORRUPT_BKPT, SQLITE_DONE, and SQLITE_OK.

Referenced by autoVacuumCommit(), and sqlite3BtreeIncrVacuum().

◆ indexColumnIsBeingUpdated()

static int indexColumnIsBeingUpdated ( Index * pIdx,
int iCol,
int * aXRef,
int chngRowid )
static

Definition at line 137688 of file sqlite3.c.

137699 {
137700 i16 iIdxCol = pIdx->aiColumn[iCol];
137701 assert( iIdxCol!=XN_ROWID ); /* Cannot index rowid */
137702 if( iIdxCol>=0 ){
137703 return aXRef[iIdxCol]>=0;
137704 }

References ExprList::a, Index::aColExpr, Index::aiColumn, ExprList::ExprList_item::pExpr, sqlite3ExprReferencesUpdatedColumn(), XN_EXPR, and XN_ROWID.

Referenced by sqlite3Update().

◆ indexColumnNotNull()

static int indexColumnNotNull ( Index * pIdx,
int iCol )
static

Definition at line 146087 of file sqlite3.c.

146093 {
146094 int j;
146095 assert( pIdx!=0 );
146096 assert( iCol>=0 && iCol<pIdx->nColumn );
146097 j = pIdx->aiColumn[iCol];
146098 if( j>=0 ){
146099 return pIdx->pTable->aCol[j].notNull;
146100 }else if( j==(-1) ){
146101 return 1;

Referenced by isDistinctRedundant(), and whereLoopAddBtreeIndex().

◆ indexMightHelpWithOrderBy()

static int indexMightHelpWithOrderBy ( WhereLoopBuilder * pBuilder,
Index * pIndex,
int iCursor )
static

Definition at line 148405 of file sqlite3.c.

148415 {
148416 ExprList *pOB;
148417 ExprList *aColExpr;
148418 int ii, jj;
148419
148420 if( pIndex->bUnordered ) return 0;
148421 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
148422 for(ii=0; ii<pOB->nExpr; ii++){
148423 Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
148424 if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
148425 if( pExpr->iColumn<0 ) return 1;
148426 for(jj=0; jj<pIndex->nKeyCol; jj++){
148427 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
148428 }
148429 }else if( (aColExpr = pIndex->aColExpr)!=0 ){
148430 for(jj=0; jj<pIndex->nKeyCol; jj++){
148431 if( pIndex->aiColumn[jj]!=XN_EXPR ) continue;
148432 if( sqlite3ExprCompareSkip(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){
148433 return 1;
ExprList * pOrderBy
Definition sqlite3.c:141386
WhereInfo * pWInfo
Definition sqlite3.c:141319

References ExprList::a, Index::aColExpr, Index::aiColumn, Index::bUnordered, Expr::iColumn, Expr::iTable, ExprList::nExpr, Index::nKeyCol, Expr::op, ExprList::ExprList_item::pExpr, WhereInfo::pOrderBy, WhereLoopBuilder::pWInfo, sqlite3ExprCompareSkip(), sqlite3ExprSkipCollateAndLikely(), TK_COLUMN, and XN_EXPR.

Referenced by whereLoopAddBtree().

◆ indexWhereClauseMightChange()

static int indexWhereClauseMightChange ( Index * pIdx,
int * aXRef,
int chngRowid )
static

Definition at line 137718 of file sqlite3.c.

References Index::pPartIdxWhere, and sqlite3ExprReferencesUpdatedColumn().

Referenced by sqlite3Update().

◆ initMemArray()

static void initMemArray ( Mem * p,
int N,
sqlite3 * db,
u16 flags )
static

Definition at line 79598 of file sqlite3.c.

79604 {
79605 while( (N--)>0 ){
79606 p->db = db;
79607 p->flags = flags;
79608 p->szMalloc = 0;
sqlite3 * db
Definition sqlite3.c:20921

Referenced by sqlite3VdbeMakeReady(), and sqlite3VdbeSetNumCols().

◆ innerLoopLoadRow()

static void innerLoopLoadRow ( Parse * pParse,
Select * pSelect,
RowLoadInfo * pInfo )
static

Definition at line 129834 of file sqlite3.c.

129844 {
129845 sqlite3ExprCodeExprList(pParse, pSelect->pEList, pInfo->regResult,
129846 0, pInfo->ecelFlags);
129847#ifdef SQLITE_ENABLE_SORTER_REFERENCES
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse *, ExprList *, int, int, u8)
Definition sqlite3.c:104406

Referenced by makeSorterRecord(), and selectInnerLoop().

◆ insertCell()

static void insertCell ( MemPage * pPage,
int i,
u8 * pCell,
int sz,
u8 * pTemp,
Pgno iChild,
int * pRC )
static

Definition at line 71184 of file sqlite3.c.

71198 {
71199 int idx = 0; /* Where to write new cell content in data[] */
71200 int j; /* Loop counter */
71201 u8 *data; /* The content of the whole page */
71202 u8 *pIns; /* The point in pPage->aCellIdx[] where no cell inserted */
71203
71204 assert( *pRC==SQLITE_OK );
71205 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
71206 assert( MX_CELL(pPage->pBt)<=10921 );
71207 assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
71208 assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
71209 assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
71210 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
71211 assert( sz==pPage->xCellSize(pPage, pCell) || CORRUPT_DB );
71212 assert( pPage->nFree>=0 );
71213 if( pPage->nOverflow || sz+2>pPage->nFree ){
71214 if( pTemp ){
71215 memcpy(pTemp, pCell, sz);
71216 pCell = pTemp;
71217 }
71218 if( iChild ){
71219 put4byte(pCell, iChild);
71220 }
71221 j = pPage->nOverflow++;
71222 /* Comparison against ArraySize-1 since we hold back one extra slot
71223 ** as a contingency. In other words, never need more than 3 overflow
71224 ** slots but 4 are allocated, just to be safe. */
71225 assert( j < ArraySize(pPage->apOvfl)-1 );
71226 pPage->apOvfl[j] = pCell;
71227 pPage->aiOvfl[j] = (u16)i;
71228
71229 /* When multiple overflows occur, they are always sequential and in
71230 ** sorted order. This invariants arise because multiple overflows can
71231 ** only occur when inserting divider cells into the parent page during
71232 ** balancing, and the dividers are adjacent and sorted.
71233 */
71234 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
71235 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
71236 }else{
71237 int rc = sqlite3PagerWrite(pPage->pDbPage);
71238 if( rc!=SQLITE_OK ){
71239 *pRC = rc;
71240 return;
71241 }
71242 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
71243 data = pPage->aData;
71244 assert( &data[pPage->cellOffset]==pPage->aCellIdx );
71245 rc = allocateSpace(pPage, sz, &idx);
71246 if( rc ){ *pRC = rc; return; }
71247 /* The allocateSpace() routine guarantees the following properties
71248 ** if it returns successfully */
71249 assert( idx >= 0 );
71250 assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
71251 assert( idx+sz <= (int)pPage->pBt->usableSize );
71252 pPage->nFree -= (u16)(2 + sz);
71253 if( iChild ){
71254 /* In a corrupt database where an entry in the cell index section of
71255 ** a btree page has a value of 3 or less, the pCell value might point
71256 ** as many as 4 bytes in front of the start of the aData buffer for
71257 ** the source page. Make sure this does not cause problems by not
71258 ** reading the first 4 bytes */
71259 memcpy(&data[idx+4], pCell+4, sz-4);
71260 put4byte(&data[idx], iChild);
71261 }else{
71262 memcpy(&data[idx], pCell, sz);
71263 }
71264 pIns = pPage->aCellIdx + i*2;
71265 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
71266 put2byte(pIns, idx);
71267 pPage->nCell++;
71268 /* increment the cell count */
71269 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
71270 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
71271#ifndef SQLITE_OMIT_AUTOVACUUM
71272 if( pPage->pBt->autoVacuum ){
71273 /* The cell may contain a pointer to an overflow page. If so, write
71274 ** the entry for the overflow page into the pointer map.
static int allocateSpace(MemPage *pPage, int nByte, int *pIdx)
Definition sqlite3.c:66089

References MemPage::aCellIdx, MemPage::aData, MemPage::aiOvfl, allocateSpace(), MemPage::apOvfl, ArraySize, BtShared::autoVacuum, MemPage::cellOffset, CORRUPT_DB, get2byte, MemPage::hdrOffset, BtShared::mutex, MX_CELL, MemPage::nCell, MemPage::nFree, MemPage::nOverflow, MemPage::pBt, MemPage::pDbPage, ptrmapPutOvflPtr(), put2byte, put4byte, sqlite3_mutex_held(), sqlite3PagerWrite(), SQLITE_OK, BtShared::usableSize, and MemPage::xCellSize.

Referenced by balance_nonroot(), balance_quick(), sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ insertElement()

static void insertElement ( Hash * pH,
struct _ht * pEntry,
HashElem * pNew )
static

Definition at line 32949 of file sqlite3.c.

32959 {
32960 HashElem *pHead; /* First element already in pEntry */
32961 if( pEntry ){
32962 pHead = pEntry->count ? pEntry->chain : 0;
32963 pEntry->count++;
32964 pEntry->chain = pNew;
32965 }else{
32966 pHead = 0;
32967 }
32968 if( pHead ){
32969 pNew->next = pHead;
32970 pNew->prev = pHead->prev;
32971 if( pHead->prev ){ pHead->prev->next = pNew; }
32972 else { pH->first = pNew; }
32973 pHead->prev = pNew;
32974 }else{
HashElem * next
Definition sqlite3.c:13901
HashElem * prev
Definition sqlite3.c:13901

Referenced by rehash(), and sqlite3HashInsert().

◆ instrFunc()

static void instrFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117239 of file sqlite3.c.

117249 {
117250 const unsigned char *zHaystack;
117251 const unsigned char *zNeedle;
117252 int nHaystack;
117253 int nNeedle;
117254 int typeHaystack, typeNeedle;
117255 int N = 1;
117256 int isText;
117257 unsigned char firstChar;
117258 sqlite3_value *pC1 = 0;
117259 sqlite3_value *pC2 = 0;
117260
117261 UNUSED_PARAMETER(argc);
117262 typeHaystack = sqlite3_value_type(argv[0]);
117263 typeNeedle = sqlite3_value_type(argv[1]);
117264 if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return;
117265 nHaystack = sqlite3_value_bytes(argv[0]);
117266 nNeedle = sqlite3_value_bytes(argv[1]);
117267 if( nNeedle>0 ){
117268 if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){
117269 zHaystack = sqlite3_value_blob(argv[0]);
117270 zNeedle = sqlite3_value_blob(argv[1]);
117271 isText = 0;
117272 }else if( typeHaystack!=SQLITE_BLOB && typeNeedle!=SQLITE_BLOB ){
117273 zHaystack = sqlite3_value_text(argv[0]);
117274 zNeedle = sqlite3_value_text(argv[1]);
117275 isText = 1;
117276 }else{
117277 pC1 = sqlite3_value_dup(argv[0]);
117278 zHaystack = sqlite3_value_text(pC1);
117279 if( zHaystack==0 ) goto endInstrOOM;
117280 nHaystack = sqlite3_value_bytes(pC1);
117281 pC2 = sqlite3_value_dup(argv[1]);
117282 zNeedle = sqlite3_value_text(pC2);
117283 if( zNeedle==0 ) goto endInstrOOM;
117284 nNeedle = sqlite3_value_bytes(pC2);
117285 isText = 1;
117286 }
117287 if( zNeedle==0 || (nHaystack && zHaystack==0) ) goto endInstrOOM;
117288 firstChar = zNeedle[0];
117289 while( nNeedle<=nHaystack
117290 && (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0)
117291 ){
117292 N++;
117293 do{
117294 nHaystack--;
117295 zHaystack++;
117296 }while( isText && (zHaystack[0]&0xc0)==0x80 );
117297 }
117298 if( nNeedle>nHaystack ) N = 0;
117299 }
117300 sqlite3_result_int(context, N);
117301endInstr:
117302 sqlite3_value_free(pC1);
SQLITE_API void sqlite3_result_int(sqlite3_context *, int)
Definition sqlite3.c:83419
#define SQLITE_BLOB
Definition sqlite3.c:5793
SQLITE_API void sqlite3_value_free(sqlite3_value *)
Definition sqlite3.c:83336

References sqlite3_result_error_nomem(), sqlite3_result_int(), sqlite3_value_blob(), sqlite3_value_bytes(), sqlite3_value_dup(), sqlite3_value_free(), sqlite3_value_text(), sqlite3_value_type(), SQLITE_BLOB, SQLITE_NULL, and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ integrityCheckResultRow()

static int integrityCheckResultRow ( Vdbe * v)
static

Definition at line 126093 of file sqlite3.c.

126093 :
126094**
126095** Generate code to output a single-column result row with a value of the
126096** string held in register 3. Decrement the result count in register 1
126097** and halt if the maximum number of result rows have been issued.
126098*/
126099static int integrityCheckResultRow(Vdbe *v){
126100 int addr;
static const char * output
static int integrityCheckResultRow(Vdbe *v)
Definition sqlite3.c:126093

References OP_Halt, OP_IfPos, OP_ResultRow, sqlite3VdbeAddOp0(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeCurrentAddr(), and VdbeCoverage.

Referenced by sqlite3Pragma().

◆ invalidateAllOverflowCache()

static void invalidateAllOverflowCache ( BtShared * pBt)
static

◆ invalidateIncrblobCursors()

static void invalidateIncrblobCursors ( Btree * pBtree,
Pgno pgnoRoot,
i64 iRow,
int isClearTable )
static

Definition at line 65009 of file sqlite3.c.

65020 {
65021 BtCursor *p;
65022 if( pBtree->hasIncrblobCur==0 ) return;
65023 assert( sqlite3BtreeHoldsMutex(pBtree) );
65024 pBtree->hasIncrblobCur = 0;
65025 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
65026 if( (p->curFlags & BTCF_Incrblob)!=0 ){
65027 pBtree->hasIncrblobCur = 1;
#define BTCF_Incrblob
Definition sqlite3.c:64010
u8 hasIncrblobCur
Definition sqlite3.c:63819

References BTCF_Incrblob, BtCursor::curFlags, CURSOR_INVALID, BtCursor::eState, Btree::hasIncrblobCur, BtCursor::info, CellInfo::nKey, Btree::pBt, BtShared::pCursor, BtCursor::pgnoRoot, and BtCursor::pNext.

Referenced by sqlite3BtreeClearTable(), sqlite3BtreeDelete(), and sqlite3BtreeInsert().

◆ invalidateTempStorage()

static int invalidateTempStorage ( Parse * pParse)
static

Definition at line 125870 of file sqlite3.c.

125876 {
125877 sqlite3 *db = pParse->db;
125878 if( db->aDb[1].pBt!=0 ){
125879 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
125880 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
125881 "from within a transaction");
125882 return SQLITE_ERROR;
125883 }
u8 autoCommit
Definition sqlite3.c:16837

References sqlite3::aDb, sqlite3::autoCommit, Parse::db, Db::pBt, sqlite3BtreeClose(), sqlite3BtreeIsInReadTrans(), sqlite3ErrorMsg(), sqlite3ResetAllSchemasOfConnection(), SQLITE_ERROR, and SQLITE_OK.

Referenced by changeTempStorage(), and sqlite3Pragma().

◆ invokeProfileCallback()

static SQLITE_NOINLINE void invokeProfileCallback ( sqlite3 * db,
Vdbe * p )
static

Definition at line 83042 of file sqlite3.c.

83048 {
83049 sqlite3_int64 iNow;
83050 sqlite3_int64 iElapse;
83051 assert( p->startTime>0 );
83052 assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
83053 assert( db->init.busy==0 );
83054 assert( p->zSql!=0 );
83055 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
83056 iElapse = (iNow - p->startTime)*1000000;
83057#ifndef SQLITE_OMIT_DEPRECATED
83058 if( db->xProfile ){
83059 db->xProfile(db->pProfileArg, p->zSql, iElapse);
83060 }
#define SQLITE_TRACE_XPROFILE
Definition sqlite3.c:16808
#define SQLITE_TRACE_PROFILE
Definition sqlite3.c:4245
SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64 *)
Definition sqlite3.c:23238
i64 startTime
Definition sqlite3.c:21116
char * zSql
Definition sqlite3.c:21137
u8 mTrace
Definition sqlite3.c:16846
void * pProfileArg
Definition sqlite3.c:16878
void(* xProfile)(void *, const char *, u64)
Definition sqlite3.c:16877

References sqlite3::sqlite3InitInfo::busy, sqlite3::init, sqlite3::mTrace, sqlite3::pProfileArg, sqlite3::pTraceArg, sqlite3::pVfs, sqlite3OsCurrentTimeInt64(), SQLITE_TRACE_PROFILE, SQLITE_TRACE_XPROFILE, Vdbe::startTime, sqlite3::trace, sqlite3::xProfile, sqlite3::xV2, and Vdbe::zSql.

◆ invokeValueDestructor()

static int invokeValueDestructor ( const void * p,
void(*)(void *) xDel,
sqlite3_context * pCtx )
static

Definition at line 83363 of file sqlite3.c.

83364 {
83365 if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
83367 }
83368}
83369static int invokeValueDestructor(
83370 const void *p, /* Value to destroy */
83371 void (*xDel)(void*), /* The destructor */
83372 sqlite3_context *pCtx /* Set a SQLITE_TOOBIG error if no NULL */
83373){
83374 assert( xDel!=SQLITE_DYNAMIC );
83375 if( xDel==0 ){
83376 /* noop */
83377 }else if( xDel==SQLITE_TRANSIENT ){
83378 /* noop */
static int invokeValueDestructor(const void *p, void(*xDel)(void *), sqlite3_context *pCtx)
Definition sqlite3.c:83363

References sqlite3_context::pOut, sqlite3_result_error_toobig(), sqlite3VdbeMemSetStr(), and SQLITE_TOOBIG.

Referenced by sqlite3_bind_double(), and sqlite3_result_double().

◆ IOMETHODS()

IOMETHODS ( posixIoFinder ,
posixIoMethods ,
IOMETHODS( 3,
unixClose ,
unixLock ,
unixUnlock ,
unixCheckReservedLock ,
unixShmMap  )

Definition at line 38844 of file sqlite3.c.

38971 {
38972 static const struct Mapping {
38973 const char *zFilesystem; /* Filesystem type name */
38974 const sqlite3_io_methods *pMethods; /* Appropriate locking method */
38975 } aMap[] = {
38976 { "hfs", &posixIoMethods },
38977 { "ufs", &posixIoMethods },
38978 { "afpfs", &afpIoMethods },
38979 { "smbfs", &afpIoMethods },
38980 { "webdav", &nolockIoMethods },
38981 { 0, 0 }
38982 };
38983 int i;
38984 struct statfs fsInfo;
38985 struct flock lockInfo;
38986
38987 if( !filePath ){
38988 /* If filePath==NULL that means we are dealing with a transient file
38989 ** that does not need to be locked. */
38990 return &nolockIoMethods;
38991 }
38992 if( statfs(filePath, &fsInfo) != -1 ){
38993 if( fsInfo.f_flags & MNT_RDONLY ){
38994 return &nolockIoMethods;
38995 }
38996 for(i=0; aMap[i].zFilesystem; i++){
38997 if( strcmp(fsInfo.f_fstypename, aMap[i].zFilesystem)==0 ){
38998 return aMap[i].pMethods;
38999 }
39000 }
39001 }
39002
39003 /* Default case. Handles, amongst others, "nfs".
39004 ** Test byte-range lock using fcntl(). If the call succeeds,
39005 ** assume that the file-system supports POSIX style locks.
39006 */
39007 lockInfo.l_len = 1;
39008 lockInfo.l_start = 0;
39009 lockInfo.l_whence = SEEK_SET;
39010 lockInfo.l_type = F_RDLCK;
39011 if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
39012 if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){
39013 return &nfsIoMethods;
39014 } else {
39015 return &posixIoMethods;
39016 }
39017 }else{
39018 return &dotlockIoMethods;
39019 }
39020}
39021static const sqlite3_io_methods
39022 *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
39023
39024#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
39025
39026#if OS_VXWORKS
39027/*
39028** This "finder" function for VxWorks checks to see if posix advisory
39029** locking works. If it does, then that is what is used. If it does not
39030** work, then fallback to named semaphore locking.
39031*/
39032static const sqlite3_io_methods *vxworksIoFinderImpl(
39033 const char *filePath, /* name of the database file */
39034 unixFile *pNew /* the open file object */
39035){
39036 struct flock lockInfo;
39037
39038 if( !filePath ){
39039 /* If filePath==NULL that means we are dealing with a transient file
39040 ** that does not need to be locked. */
39041 return &nolockIoMethods;
39042 }
39043
39044 /* Test if fcntl() is supported and use POSIX style locks.
39045 ** Otherwise fall back to the named semaphore method.
39046 */
39047 lockInfo.l_len = 1;
39048 lockInfo.l_start = 0;
39049 lockInfo.l_whence = SEEK_SET;
39050 lockInfo.l_type = F_RDLCK;
39051 if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
39052 return &posixIoMethods;
39053 }else{
39054 return &semIoMethods;
39055 }
39056}
39057static const sqlite3_io_methods
39058 *(*const vxworksIoFinder)(const char*,unixFile*) = vxworksIoFinderImpl;
39059
39060#endif /* OS_VXWORKS */
39061
39062/*
39063** An abstract type for a pointer to an IO method finder function:
39064*/
39065typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
39066
39067
39068/****************************************************************************
39069**************************** sqlite3_vfs methods ****************************
39070**
39071** This division contains the implementation of methods on the
39072** sqlite3_vfs object.
39073*/
39074
39075/*
39076** Initialize the contents of the unixFile structure pointed to by pId.
39077*/
39078static int fillInUnixFile(
39079 sqlite3_vfs *pVfs, /* Pointer to vfs object */
39080 int h, /* Open file descriptor of file being opened */
39081 sqlite3_file *pId, /* Write to the unixFile structure here */
39082 const char *zFilename, /* Name of the file being opened */
39083 int ctrlFlags /* Zero or more UNIXFILE_* values */
39084){
39085 const sqlite3_io_methods *pLockingStyle;
39086 unixFile *pNew = (unixFile *)pId;
39087 int rc = SQLITE_OK;
39088
39089 assert( pNew->pInode==NULL );
39090
39091 /* No locking occurs in temporary files */
39092 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
39093
39094 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
39095 pNew->h = h;
39096 pNew->pVfs = pVfs;
39097 pNew->zPath = zFilename;
39098 pNew->ctrlFlags = (u8)ctrlFlags;
39099#if SQLITE_MAX_MMAP_SIZE>0
39100 pNew->mmapSizeMax = sqlite3GlobalConfig.szMmap;
39101#endif
39102 if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
39103 "psow", SQLITE_POWERSAFE_OVERWRITE) ){
39104 pNew->ctrlFlags |= UNIXFILE_PSOW;
39105 }
39106 if( strcmp(pVfs->zName,"unix-excl")==0 ){
39107 pNew->ctrlFlags |= UNIXFILE_EXCL;
39108 }
39109
39110#if OS_VXWORKS
39111 pNew->pId = vxworksFindFileId(zFilename);
39112 if( pNew->pId==0 ){
39113 ctrlFlags |= UNIXFILE_NOLOCK;
39114 rc = SQLITE_NOMEM_BKPT;
39115 }
39116#endif
39117
39118 if( ctrlFlags & UNIXFILE_NOLOCK ){
39119 pLockingStyle = &nolockIoMethods;
39120 }else{
39121 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
39122#if SQLITE_ENABLE_LOCKING_STYLE
39123 /* Cache zFilename in the locking context (AFP and dotlock override) for
39124 ** proxyLock activation is possible (remote proxy is based on db name)
39125 ** zFilename remains valid until file is closed, to support */
39126 pNew->lockingContext = (void*)zFilename;
39127#endif
39128 }
39129
39130 if( pLockingStyle == &posixIoMethods
39131#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
39132 || pLockingStyle == &nfsIoMethods
39133#endif
39134 ){
39136 rc = findInodeInfo(pNew, &pNew->pInode);
39137 if( rc!=SQLITE_OK ){
39138 /* If an error occurred in findInodeInfo(), close the file descriptor
39139 ** immediately, before releasing the mutex. findInodeInfo() may fail
39140 ** in two scenarios:
39141 **
39142 ** (a) A call to fstat() failed.
39143 ** (b) A malloc failed.
39144 **
39145 ** Scenario (b) may only occur if the process is holding no other
39146 ** file descriptors open on the same file. If there were other file
39147 ** descriptors on this file, then no malloc would be required by
39148 ** findInodeInfo(). If this is the case, it is quite safe to close
39149 ** handle h - as it is guaranteed that no posix locks will be released
39150 ** by doing so.
39151 **
39152 ** If scenario (a) caused the error then things are not so safe. The
39153 ** implicit assumption here is that if fstat() fails, things are in
39154 ** such bad shape that dropping a lock or two doesn't matter much.
39155 */
39156 robust_close(pNew, h, __LINE__);
39157 h = -1;
39158 }
39160 }
39161
39162#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
39163 else if( pLockingStyle == &afpIoMethods ){
39164 /* AFP locking uses the file path so it needs to be included in
39165 ** the afpLockingContext.
39166 */
39167 afpLockingContext *pCtx;
39168 pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
39169 if( pCtx==0 ){
39170 rc = SQLITE_NOMEM_BKPT;
39171 }else{
39172 /* NB: zFilename exists and remains valid until the file is closed
39173 ** according to requirement F11141. So we do not need to make a
39174 ** copy of the filename. */
39175 pCtx->dbPath = zFilename;
39176 pCtx->reserved = 0;
39177 srandomdev();
39179 rc = findInodeInfo(pNew, &pNew->pInode);
39180 if( rc!=SQLITE_OK ){
39182 robust_close(pNew, h, __LINE__);
39183 h = -1;
39184 }
39186 }
39187 }
39188#endif
39189
39190 else if( pLockingStyle == &dotlockIoMethods ){
39191 /* Dotfile locking uses the file path so it needs to be included in
39192 ** the dotlockLockingContext
39193 */
39194 char *zLockFile;
39195 int nFilename;
39196 assert( zFilename!=0 );
39197 nFilename = (int)strlen(zFilename) + 6;
39198 zLockFile = (char *)sqlite3_malloc64(nFilename);
39199 if( zLockFile==0 ){
39200 rc = SQLITE_NOMEM_BKPT;
39201 }else{
39202 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
39203 }
39204 pNew->lockingContext = zLockFile;
39205 }
39206
39207#if OS_VXWORKS
39208 else if( pLockingStyle == &semIoMethods ){
39209 /* Named semaphore locking uses the file path so it needs to be
39210 ** included in the semLockingContext
39211 */
39213 rc = findInodeInfo(pNew, &pNew->pInode);
39214 if( (rc==SQLITE_OK) && (pNew->pInode->pSem==NULL) ){
39215 char *zSemName = pNew->pInode->aSemName;
39216 int n;
39217 sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem",
39218 pNew->pId->zCanonicalName);
39219 for( n=1; zSemName[n]; n++ )
39220 if( zSemName[n]=='/' ) zSemName[n] = '_';
39221 pNew->pInode->pSem = sem_open(zSemName, O_CREAT, 0666, 1);
39222 if( pNew->pInode->pSem == SEM_FAILED ){
39223 rc = SQLITE_NOMEM_BKPT;
39224 pNew->pInode->aSemName[0] = '\0';
39225 }
39226 }
39228 }
39229#endif
39230
39231 storeLastErrno(pNew, 0);
39232#if OS_VXWORKS
39233 if( rc!=SQLITE_OK ){
39234 if( h>=0 ) robust_close(pNew, h, __LINE__);
39235 h = -1;
39236 osUnlink(zFilename);
39237 pNew->ctrlFlags |= UNIXFILE_DELETE;
39238 }
39239#endif
39240 if( rc!=SQLITE_OK ){
39241 if( h>=0 ) robust_close(pNew, h, __LINE__);
39242 }else{
#define DOTLOCK_SUFFIX
Definition sqlite3.c:35764
SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault)
Definition sqlite3.c:165318
#define UNIXFILE_EXCL
Definition sqlite3.c:33627
#define UNIXFILE_NOLOCK
Definition sqlite3.c:33638
#define SQLITE_ENABLE_LOCKING_STYLE
Definition sqlite3.c:33414
#define UNIXFILE_PSOW
Definition sqlite3.c:33635
#define SQLITE_POWERSAFE_OVERWRITE
Definition sqlite3.c:13580
static int findInodeInfo(unixFile *pFile, unixInodeInfo **ppInode)
Definition sqlite3.c:34902
#define UNIXFILE_URI
Definition sqlite3.c:33637
static void unixLeaveMutex(void)
Definition sqlite3.c:34283
void * pAppData
Definition sqlite3.c:2423
sqlite3_vfs * pVfs
Definition sqlite3.c:33564

◆ isAllZero()

static int isAllZero ( const char * z,
int n )
static

Definition at line 81980 of file sqlite3.c.

81986 {

Referenced by sqlite3BlobCompare(), and sqlite3VdbeRecordCompareWithSkip().

◆ isAlterableTable()

static int isAlterableTable ( Parse * pParse,
Table * pTab )
static

Definition at line 105824 of file sqlite3.c.

105830 {
105831 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
105832#ifndef SQLITE_OMIT_VIRTUALTABLE
105833 || ( (pTab->tabFlags & TF_Shadow)!=0
105834 && sqlite3ReadOnlyShadowTables(pParse->db)
105835 )
105836#endif
SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db)
Definition sqlite3.c:113403
#define TF_Shadow
Definition sqlite3.c:17548

References Parse::db, sqlite3ErrorMsg(), sqlite3ReadOnlyShadowTables(), sqlite3StrNICmp, Table::tabFlags, TF_Shadow, and Table::zName.

Referenced by sqlite3AlterBeginAddColumn(), and sqlite3AlterRenameColumn().

◆ isAuxiliaryVtabOperator()

static int isAuxiliaryVtabOperator ( sqlite3 * db,
Expr * pExpr,
unsigned char * peOp2,
Expr ** ppLeft,
Expr ** ppRight )
static

Definition at line 144336 of file sqlite3.c.

144348 {
144349 if( pExpr->op==TK_FUNCTION ){
144350 static const struct Op2 {
144351 const char *zOp;
144352 unsigned char eOp2;
144353 } aOp[] = {
144354 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
144355 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
144356 { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
144357 { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
144358 };
144359 ExprList *pList;
144360 Expr *pCol; /* Column reference */
144361 int i;
144362
144363 pList = pExpr->x.pList;
144364 if( pList==0 || pList->nExpr!=2 ){
144365 return 0;
144366 }
144367
144368 /* Built-in operators MATCH, GLOB, LIKE, and REGEXP attach to a
144369 ** virtual table on their second argument, which is the same as
144370 ** the left-hand side operand in their in-fix form.
144371 **
144372 ** vtab_column MATCH expression
144373 ** MATCH(expression,vtab_column)
144374 */
144375 pCol = pList->a[1].pExpr;
144376 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
144377 if( ExprIsVtab(pCol) ){
144378 for(i=0; i<ArraySize(aOp); i++){
144379 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
144380 *peOp2 = aOp[i].eOp2;
144381 *ppRight = pList->a[0].pExpr;
144382 *ppLeft = pCol;
144383 return 1;
144384 }
144385 }
144386 }
144387
144388 /* We can also match against the first column of overloaded
144389 ** functions where xFindFunction returns a value of at least
144390 ** SQLITE_INDEX_CONSTRAINT_FUNCTION.
144391 **
144392 ** OVERLOADED(vtab_column,expression)
144393 **
144394 ** Historically, xFindFunction expected to see lower-case function
144395 ** names. But for this use case, xFindFunction is expected to deal
144396 ** with function names in an arbitrary case.
144397 */
144398 pCol = pList->a[0].pExpr;
144399 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
144400 if( ExprIsVtab(pCol) ){
144401 sqlite3_vtab *pVtab;
144402 sqlite3_module *pMod;
144403 void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
144404 void *pNotUsed;
144405 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
144406 assert( pVtab!=0 );
144407 assert( pVtab->pModule!=0 );
144408 pMod = (sqlite3_module *)pVtab->pModule;
144409 if( pMod->xFindFunction!=0 ){
144410 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
144412 *peOp2 = i;
144413 *ppRight = pList->a[1].pExpr;
144414 *ppLeft = pCol;
144415 return 1;
144416 }
144417 }
144418 }
144419 }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
144420 int res = 0;
144421 Expr *pLeft = pExpr->pLeft;
144422 Expr *pRight = pExpr->pRight;
144423 testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
144424 if( ExprIsVtab(pLeft) ){
144425 res++;
144426 }
144427 testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
144428 if( pRight && ExprIsVtab(pRight) ){
144429 res++;
144430 SWAP(Expr*, pLeft, pRight);
144431 }
144432 *ppLeft = pLeft;
144433 *ppRight = pRight;
144434 if( pExpr->op==TK_NE ) *peOp2 = SQLITE_INDEX_CONSTRAINT_NE;
#define SQLITE_INDEX_CONSTRAINT_LIKE
Definition sqlite3.c:7953
#define SQLITE_INDEX_CONSTRAINT_REGEXP
Definition sqlite3.c:7955
#define SQLITE_INDEX_CONSTRAINT_NE
Definition sqlite3.c:7956
#define SQLITE_INDEX_CONSTRAINT_FUNCTION
Definition sqlite3.c:7961
#define SQLITE_INDEX_CONSTRAINT_MATCH
Definition sqlite3.c:7952
SQLITE_PRIVATE VTable * sqlite3GetVTable(sqlite3 *, Table *)
Definition sqlite3.c:139763
#define SQLITE_INDEX_CONSTRAINT_GLOB
Definition sqlite3.c:7954
#define ExprIsVtab(X)
Definition sqlite3.c:17557

References ExprList::a, ArraySize, ExprIsVtab, ExprList::nExpr, Expr::op, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, sqlite3_vtab::pModule, Expr::pRight, Expr::pTab, VTable::pVtab, sqlite3GetVTable(), sqlite3StrICmp(), SQLITE_INDEX_CONSTRAINT_FUNCTION, SQLITE_INDEX_CONSTRAINT_GLOB, SQLITE_INDEX_CONSTRAINT_ISNOT, SQLITE_INDEX_CONSTRAINT_ISNOTNULL, SQLITE_INDEX_CONSTRAINT_LIKE, SQLITE_INDEX_CONSTRAINT_MATCH, SQLITE_INDEX_CONSTRAINT_NE, SQLITE_INDEX_CONSTRAINT_REGEXP, SWAP, testcase, TK_COLUMN, TK_FUNCTION, TK_ISNOT, TK_NE, TK_NOTNULL, Expr::u, Expr::x, sqlite3_module::xFindFunction, Expr::y, and Expr::zToken.

Referenced by exprAnalyze().

◆ isCandidateForInOpt()

static Select * isCandidateForInOpt ( Expr * pX)
static

Definition at line 102074 of file sqlite3.c.

102080 {
102081 Select *p;
102082 SrcList *pSrc;
102083 ExprList *pEList;
102084 Table *pTab;
102085 int i;
102086 if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */
102087 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
102088 p = pX->x.pSelect;
102089 if( p->pPrior ) return 0; /* Not a compound SELECT */
102090 if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
102093 return 0; /* No DISTINCT keyword and no aggregate functions */
102094 }
102095 assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
102096 if( p->pLimit ) return 0; /* Has no LIMIT clause */
102097 if( p->pWhere ) return 0; /* Has no WHERE clause */
102098 pSrc = p->pSrc;
102099 assert( pSrc!=0 );
102100 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
102101 if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
102102 pTab = pSrc->a[0].pTab;
102103 assert( pTab!=0 );
102104 assert( pTab->pSelect==0 ); /* FROM clause is not a view */
102105 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
102106 pEList = p->pEList;
102107 assert( pEList!=0 );
102108 /* All SELECT results must be columns. */
102109 for(i=0; i<pEList->nExpr; i++){
#define EP_VarSelect
Definition sqlite3.c:18065
Select * pSelect
Definition sqlite3.c:17491

References ExprList::a, SrcList::a, EP_VarSelect, EP_xIsSelect, ExprHasProperty, SrcList::SrcList_item::iCursor, IsVirtual, Expr::iTable, ExprList::nExpr, SrcList::nSrc, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, Select::pGroupBy, Select::pLimit, Select::pPrior, Table::pSelect, Expr::pSelect, SrcList::SrcList_item::pSelect, Select::pSrc, SrcList::SrcList_item::pTab, Select::pWhere, Select::selFlags, SF_Aggregate, SF_Distinct, testcase, TK_COLUMN, and Expr::x.

Referenced by sqlite3FindInIndex().

◆ isDate()

static int isDate ( sqlite3_context * context,
int argc,
sqlite3_value ** argv,
DateTime * p )
static

Definition at line 22582 of file sqlite3.c.

22592 {
22593 int i, n;
22594 const unsigned char *z;
22595 int eType;
22596 memset(p, 0, sizeof(*p));
22597 if( argc==0 ){
22598 return setDateTimeToCurrent(context, p);
22599 }
22600 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
22601 || eType==SQLITE_INTEGER ){
22603 }else{
22604 z = sqlite3_value_text(argv[0]);
22605 if( !z || parseDateOrTime(context, (char*)z, p) ){
22606 return 1;
22607 }
22608 }
22609 for(i=1; i<argc; i++){
22610 z = sqlite3_value_text(argv[i]);
22611 n = sqlite3_value_bytes(argv[i]);
22612 if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
#define SQLITE_FLOAT
Definition sqlite3.c:5792
static int parseModifier(sqlite3_context *pCtx, const char *z, int n, DateTime *p)
Definition sqlite3.c:22365
static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p)
Definition sqlite3.c:22047
static int parseDateOrTime(sqlite3_context *context, const char *zDate, DateTime *p)
Definition sqlite3.c:22088
static void setRawDateNumber(DateTime *p, double r)
Definition sqlite3.c:22063

References computeJD(), eType, DateTime::iJD, DateTime::isError, parseDateOrTime(), parseModifier(), setDateTimeToCurrent(), setRawDateNumber(), sqlite3_value_bytes(), sqlite3_value_double(), sqlite3_value_text(), sqlite3_value_type(), SQLITE_FLOAT, SQLITE_INTEGER, and validJulianDay().

Referenced by dateFunc(), datetimeFunc(), juliandayFunc(), strftimeFunc(), and timeFunc().

◆ isDistinctRedundant()

static int isDistinctRedundant ( Parse * pParse,
SrcList * pTabList,
WhereClause * pWC,
ExprList * pDistinct )
static

Definition at line 146110 of file sqlite3.c.

146121 {
146122 Table *pTab;
146123 Index *pIdx;
146124 int i;
146125 int iBase;
146126
146127 /* If there is more than one table or sub-select in the FROM clause of
146128 ** this query, then it will not be possible to show that the DISTINCT
146129 ** clause is redundant. */
146130 if( pTabList->nSrc!=1 ) return 0;
146131 iBase = pTabList->a[0].iCursor;
146132 pTab = pTabList->a[0].pTab;
146133
146134 /* If any of the expressions is an IPK column on table iBase, then return
146135 ** true. Note: The (p->iTable==iBase) part of this test may be false if the
146136 ** current SELECT is a correlated sub-query.
146137 */
146138 for(i=0; i<pDistinct->nExpr; i++){
146139 Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
146140 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
146141 }
146142
146143 /* Loop through all indices on the table, checking each to see if it makes
146144 ** the DISTINCT qualifier redundant. It does so if:
146145 **
146146 ** 1. The index is itself UNIQUE, and
146147 **
146148 ** 2. All of the columns in the index are either part of the pDistinct
146149 ** list, or else the WHERE clause contains a term of the form "col=X",
146150 ** where X is a constant value. The collation sequences of the
146151 ** comparison and select-list expressions must match those of the index.
146152 **
146153 ** 3. All of those index columns for which the WHERE clause does not
146154 ** contain a "col=X" term are subject to a NOT NULL constraint.
146155 */
146156 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
146157 if( !IsUniqueIndex(pIdx) ) continue;
146158 for(i=0; i<pIdx->nKeyCol; i++){
146159 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
146160 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
146161 if( indexColumnNotNull(pIdx, i)==0 ) break;
146162 }
146163 }
146164 if( i==pIdx->nKeyCol ){
146165 /* This index implies that the DISTINCT qualifier is redundant. */
static int indexColumnNotNull(Index *pIdx, int iCol)
Definition sqlite3.c:146087
static int findIndexCol(Parse *pParse, ExprList *pList, int iBase, Index *pIdx, int iCol)
Definition sqlite3.c:146058
SQLITE_PRIVATE WhereTerm * sqlite3WhereFindTerm(WhereClause *pWC, int iCur, int iColumn, Bitmask notReady, u32 op, Index *pIdx)
Definition sqlite3.c:146024

References ExprList::a, SrcList::a, findIndexCol(), Expr::iColumn, SrcList::SrcList_item::iCursor, indexColumnNotNull(), IsUniqueIndex, Expr::iTable, ExprList::nExpr, Index::nKeyCol, SrcList::nSrc, Expr::op, ExprList::ExprList_item::pExpr, Table::pIndex, Index::pNext, SrcList::SrcList_item::pTab, sqlite3ExprSkipCollateAndLikely(), sqlite3WhereFindTerm(), TK_COLUMN, and WO_EQ.

Referenced by sqlite3WhereBegin().

◆ isDupColumn()

static int isDupColumn ( Index * pIdx,
int nKey,
Index * pPk,
int iCol )
static

Definition at line 112346 of file sqlite3.c.

112352 {
112353 int i, j;
112354 assert( nKey<=pIdx->nColumn );
112355 assert( iCol<MAX(pPk->nColumn,pPk->nKeyCol) );
112356 assert( pPk->idxType==SQLITE_IDXTYPE_PRIMARYKEY );
112357 assert( pPk->pTable->tabFlags & TF_WithoutRowid );
112358 assert( pPk->pTable==pIdx->pTable );
112359 testcase( pPk==pIdx );
112360 j = pPk->aiColumn[iCol];
112361 assert( j!=XN_ROWID && j!=XN_EXPR );
112362 for(i=0; i<nKey; i++){
112363 assert( pIdx->aiColumn[i]>=0 || j>=0 );
112364 if( pIdx->aiColumn[i]==j
112365 && sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
#define TF_WithoutRowid
Definition sqlite3.c:17543

References Index::aiColumn, Index::azColl, Index::idxType, MAX, Index::nColumn, Index::nKeyCol, Index::pTable, sqlite3StrICmp(), SQLITE_IDXTYPE_PRIMARYKEY, Table::tabFlags, testcase, TF_WithoutRowid, XN_EXPR, and XN_ROWID.

Referenced by convertToWithoutRowidTable(), and sqlite3CreateIndex().

◆ isFatalError()

static int isFatalError ( int rc)
static

Definition at line 75268 of file sqlite3.c.

References ALWAYS, SQLITE_BUSY, SQLITE_LOCKED, and SQLITE_OK.

Referenced by backupOnePage(), and backupUpdate().

◆ isLikeOrGlob()

static int isLikeOrGlob ( Parse * pParse,
Expr * pExpr,
Expr ** ppPrefix,
int * pisComplete,
int * pnoCase )
static

Definition at line 144164 of file sqlite3.c.

144176 {
144177 const u8 *z = 0; /* String on RHS of LIKE operator */
144178 Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
144179 ExprList *pList; /* List of operands to the LIKE operator */
144180 u8 c; /* One character in z[] */
144181 int cnt; /* Number of non-wildcard prefix characters */
144182 u8 wc[4]; /* Wildcard characters */
144183 sqlite3 *db = pParse->db; /* Database connection */
144184 sqlite3_value *pVal = 0;
144185 int op; /* Opcode of pRight */
144186 int rc; /* Result code to return */
144187
144188 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, (char*)wc) ){
144189 return 0;
144190 }
144191#ifdef SQLITE_EBCDIC
144192 if( *pnoCase ) return 0;
144193#endif
144194 pList = pExpr->x.pList;
144195 pLeft = pList->a[1].pExpr;
144196
144197 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
144198 op = pRight->op;
144199 if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
144200 Vdbe *pReprepare = pParse->pReprepare;
144201 int iCol = pRight->iColumn;
144202 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_BLOB);
144203 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
144204 z = sqlite3_value_text(pVal);
144205 }
144206 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
144207 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
144208 }else if( op==TK_STRING ){
144209 z = (u8*)pRight->u.zToken;
144210 }
144211 if( z ){
144212
144213 /* Count the number of prefix characters prior to the first wildcard */
144214 cnt = 0;
144215 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
144216 cnt++;
144217 if( c==wc[3] && z[cnt]!=0 ) cnt++;
144218 }
144219
144220 /* The optimization is possible only if (1) the pattern does not begin
144221 ** with a wildcard and if (2) the non-wildcard prefix does not end with
144222 ** an (illegal 0xff) character, or (3) the pattern does not consist of
144223 ** a single escape character. The second condition is necessary so
144224 ** that we can increment the prefix key to find an upper bound for the
144225 ** range search. The third is because the caller assumes that the pattern
144226 ** consists of at least one character after all escapes have been
144227 ** removed. */
144228 if( cnt!=0 && 255!=(u8)z[cnt-1] && (cnt>1 || z[0]!=wc[3]) ){
144229 Expr *pPrefix;
144230
144231 /* A "complete" match if the pattern ends with "*" or "%" */
144232 *pisComplete = c==wc[0] && z[cnt+1]==0;
144233
144234 /* Get the pattern prefix. Remove all escapes from the prefix. */
144235 pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
144236 if( pPrefix ){
144237 int iFrom, iTo;
144238 char *zNew = pPrefix->u.zToken;
144239 zNew[cnt] = 0;
144240 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
144241 if( zNew[iFrom]==wc[3] ) iFrom++;
144242 zNew[iTo++] = zNew[iFrom];
144243 }
144244 zNew[iTo] = 0;
144245 assert( iTo>0 );
144246
144247 /* If the LHS is not an ordinary column with TEXT affinity, then the
144248 ** pattern prefix boundaries (both the start and end boundaries) must
144249 ** not look like a number. Otherwise the pattern might be treated as
144250 ** a number, which will invalidate the LIKE optimization.
144251 **
144252 ** Getting this right has been a persistent source of bugs in the
144253 ** LIKE optimization. See, for example:
144254 ** 2018-09-10 https://sqlite.org/src/info/c94369cae9b561b1
144255 ** 2019-05-02 https://sqlite.org/src/info/b043a54c3de54b28
144256 ** 2019-06-10 https://sqlite.org/src/info/fd76310a5e843e07
144257 ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
144258 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
144259 */
144260 if( pLeft->op!=TK_COLUMN
144262 || IsVirtual(pLeft->y.pTab) /* Value might be numeric */
144263 ){
144264 int isNum;
144265 double rDummy;
144266 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
144267 if( isNum<=0 ){
144268 if( iTo==1 && zNew[0]=='-' ){
144269 isNum = +1;
144270 }else{
144271 zNew[iTo-1]++;
144272 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
144273 zNew[iTo-1]--;
144274 }
144275 }
144276 if( isNum>0 ){
144277 sqlite3ExprDelete(db, pPrefix);
144278 sqlite3ValueFree(pVal);
144279 return 0;
144280 }
144281 }
144282 }
144283 *ppPrefix = pPrefix;
144284
144285 /* If the RHS pattern is a bound parameter, make arrangements to
144286 ** reprepare the statement when that parameter is rebound */
144287 if( op==TK_VARIABLE ){
144288 Vdbe *v = pParse->pVdbe;
144289 sqlite3VdbeSetVarmask(v, pRight->iColumn);
144290 if( *pisComplete && pRight->u.zToken[1] ){
144291 /* If the rhs of the LIKE expression is a variable, and the current
144292 ** value of the variable means there is no need to invoke the LIKE
144293 ** function, then no OP_Variable will be added to the program.
144294 ** This causes problems for the sqlite3_bind_parameter_name()
144295 ** API. To work around them, add a dummy OP_Variable here.
144296 */
144297 int r1 = sqlite3GetTempReg(pParse);
144298 sqlite3ExprCodeTarget(pParse, pRight, r1);
144300 sqlite3ReleaseTempReg(pParse, r1);
144301 }
144302 }
144303 }else{
144304 z = 0;
144305 }
#define SQLITE_EnableQPSG
Definition sqlite3.c:17002
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *, Expr *, int *, char *)
Definition sqlite3.c:118909

References ExprList::a, Parse::db, sqlite3::flags, Expr::iColumn, IsVirtual, Expr::op, ExprList::ExprList_item::pExpr, Expr::pList, Parse::pReprepare, Expr::pTab, Parse::pVdbe, sqlite3_value_text(), sqlite3_value_type(), sqlite3AtoF(), sqlite3Expr(), sqlite3ExprAffinity(), sqlite3ExprCodeTarget(), sqlite3ExprDelete(), sqlite3ExprSkipCollate(), sqlite3GetTempReg(), sqlite3IsLikeFunction(), sqlite3ReleaseTempReg(), sqlite3ValueFree(), sqlite3VdbeChangeP3(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetBoundValue(), sqlite3VdbeSetVarmask(), SQLITE_AFF_BLOB, SQLITE_AFF_TEXT, SQLITE_EnableQPSG, SQLITE_TEXT, SQLITE_UTF8, TK_COLUMN, TK_REGISTER, TK_STRING, TK_VARIABLE, Expr::u, Expr::x, Expr::y, and Expr::zToken.

Referenced by exprAnalyze().

◆ isLookaside()

static int isLookaside ( sqlite3 * db,
void * p )
static

Definition at line 27632 of file sqlite3.c.

References sqlite3::lookaside, Lookaside::pEnd, Lookaside::pStart, and SQLITE_WITHIN.

◆ isRealTable()

static int isRealTable ( Parse * pParse,
Table * pTab )
static

Definition at line 106305 of file sqlite3.c.

106311 {
106312 const char *zType = 0;
106313#ifndef SQLITE_OMIT_VIEW
106314 if( pTab->pSelect ){
106315 zType = "view";
106316 }
106317#endif
106318#ifndef SQLITE_OMIT_VIRTUALTABLE
106319 if( IsVirtual(pTab) ){
106320 zType = "virtual table";
106321 }
106322#endif
106323 if( zType ){

References IsVirtual, Table::pSelect, sqlite3ErrorMsg(), and Table::zName.

Referenced by sqlite3AlterRenameColumn().

◆ isSelfJoinView()

static struct SrcList_item * isSelfJoinView ( SrcList * pTabList,
struct SrcList_item * pThis )
static

Definition at line 134932 of file sqlite3.c.

134941 {
134942 struct SrcList_item *pItem;
134943 for(pItem = pTabList->a; pItem<pThis; pItem++){
134944 Select *pS1;
134945 if( pItem->pSelect==0 ) continue;
134946 if( pItem->fg.viaCoroutine ) continue;
134947 if( pItem->zName==0 ) continue;
134948 assert( pItem->pTab!=0 );
134949 assert( pThis->pTab!=0 );
134950 if( pItem->pTab->pSchema!=pThis->pTab->pSchema ) continue;
134951 if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
134952 pS1 = pItem->pSelect;
134953 if( pItem->pTab->pSchema==0 && pThis->pSelect->selId!=pS1->selId ){
134954 /* The query flattener left two different CTE tables with identical
134955 ** names in the same FROM clause. */
134956 continue;
134957 }
134958 if( sqlite3ExprCompare(0, pThis->pSelect->pWhere, pS1->pWhere, -1)
134959 || sqlite3ExprCompare(0, pThis->pSelect->pHaving, pS1->pHaving, -1)
134960 ){
134961 /* The view was modified by some other optimization such as
134962 ** pushDownWhereTerms() */

References SrcList::a, Select::pHaving, Select::pWhere, Select::selId, sqlite3_stricmp(), and sqlite3ExprCompare().

Referenced by sqlite3Select().

◆ isSetNullAction()

static int isSetNullAction ( Parse * pParse,
FKey * pFKey )
static

Definition at line 119933 of file sqlite3.c.

119939 {
119940 Parse *pTop = sqlite3ParseToplevel(pParse);
119941 if( pTop->pTriggerPrg ){
119942 Trigger *p = pTop->pTriggerPrg->pTrigger;
119943 if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
119944 || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)

References FKey::aAction, FKey::apTrigger, OE_SetNull, TriggerPrg::pTrigger, Parse::pTriggerPrg, and sqlite3ParseToplevel.

Referenced by sqlite3FkCheck().

◆ isSimpleCount()

static Table * isSimpleCount ( Select * p,
AggInfo * pAggInfo )
static

Definition at line 133861 of file sqlite3.c.

133867 {
133868 Table *pTab;
133869 Expr *pExpr;
133870
133871 assert( !p->pGroupBy );
133872
133873 if( p->pWhere || p->pEList->nExpr!=1
133874 || p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect
133875 ){
133876 return 0;
133877 }
133878 pTab = p->pSrc->a[0].pTab;
133879 pExpr = p->pEList->a[0].pExpr;
133880 assert( pTab && !pTab->pSelect && pExpr );
133881
133882 if( IsVirtual(pTab) ) return 0;
133883 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;

References ExprList::a, SrcList::a, AggInfo::aFunc, EP_Distinct, EP_WinFunc, ExprHasProperty, FuncDef::funcFlags, IsVirtual, NEVER, ExprList::nExpr, AggInfo::nFunc, SrcList::nSrc, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, AggInfo::AggInfo_func::pFunc, Select::pGroupBy, Table::pSelect, SrcList::SrcList_item::pSelect, Select::pSrc, SrcList::SrcList_item::pTab, Select::pWhere, SQLITE_FUNC_COUNT, and TK_AGG_FUNCTION.

Referenced by sqlite3Select().

◆ journalHdrOffset()

static i64 journalHdrOffset ( Pager * pPager)
static

Definition at line 53053 of file sqlite3.c.

53059 {
53060 i64 offset = 0;
53061 i64 c = pPager->journalOff;
53062 if( c ){
53063 offset = ((c-1)/JOURNAL_HDR_SZ(pPager) + 1) * JOURNAL_HDR_SZ(pPager);
#define JOURNAL_HDR_SZ(pPager)
Definition sqlite3.c:52467
i64 journalOff
Definition sqlite3.c:52364

References JOURNAL_HDR_SZ, and Pager::journalOff.

Referenced by readJournalHdr(), syncJournal(), writeJournalHdr(), and writeSuperJournal().

◆ jrnlBufferSize()

static int jrnlBufferSize ( Pager * pPager)
static

Definition at line 52892 of file sqlite3.c.

52898 {
52899 assert( !MEMDB );
52900
52901#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
52902 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
52903 int dc; /* Device characteristics */
52904
52905 assert( isOpen(pPager->fd) );
52906 dc = sqlite3OsDeviceCharacteristics(pPager->fd);
52907#else
52908 UNUSED_PARAMETER(pPager);
52909#endif
52910
52911#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
52912 if( pPager->dbSize>0 && (dc&SQLITE_IOCAP_BATCH_ATOMIC) ){
52913 return -1;
52914 }
52915#endif
52916
52917#ifdef SQLITE_ENABLE_ATOMIC_WRITE
52918 {
52919 int nSector = pPager->sectorSize;
52920 int szPage = pPager->pageSize;
52921
52922 assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
52923 assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
52924 if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
52925 return 0;
52926 }
52927 }
#define SQLITE_IOCAP_ATOMIC512
Definition sqlite3.c:1662
#define SQLITE_IOCAP_BATCH_ATOMIC
Definition sqlite3.c:1675
#define SQLITE_IOCAP_ATOMIC64K
Definition sqlite3.c:1669
#define SQLITE_IOCAP_ATOMIC
Definition sqlite3.c:1661
u32 sectorSize
Definition sqlite3.c:52382
int pageSize
Definition sqlite3.c:52383

References Pager::dbSize, Pager::fd, isOpen, JOURNAL_HDR_SZ, JOURNAL_PG_SZ, MEMDB, Pager::pageSize, Pager::sectorSize, sqlite3OsDeviceCharacteristics(), SQLITE_IOCAP_ATOMIC, SQLITE_IOCAP_ATOMIC512, SQLITE_IOCAP_ATOMIC64K, SQLITE_IOCAP_BATCH_ATOMIC, and UNUSED_PARAMETER.

Referenced by pager_open_journal(), and sqlite3PagerCommitPhaseOne().

◆ juliandayFunc()

static void juliandayFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 22625 of file sqlite3.c.

22634 {
22635 DateTime x;

References computeJD(), DateTime::iJD, isDate(), and sqlite3_result_double().

Referenced by sqlite3RegisterDateTimeFunctions().

◆ keywordCode()

static int keywordCode ( const char * z,
int n,
int * pType )
static

Definition at line 159693 of file sqlite3.c.

159693 : PRECEDING
159694** 126: UPDATE UNIQUE
159695*/
159696/* Check to see if z[0..n-1] is a keyword. If it is, write the
159697** parser symbol code for that keyword into *pType. Always
159698** return the integer n (the length of the token). */
159699static int keywordCode(const char *z, int n, int *pType){
159700 int i, j;
159701 const char *zKW;
159702 if( n>=2 ){
159703 i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) % 127;
159704 for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){
159705 if( aKWLen[i]!=n ) continue;
159706 zKW = &zKWText[aKWOffset[i]];
159707#ifdef SQLITE_ASCII
159708 if( (z[0]&~0x20)!=zKW[0] ) continue;
159709 if( (z[1]&~0x20)!=zKW[1] ) continue;
159710 j = 2;
159711 while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }
159712#endif
159713#ifdef SQLITE_EBCDIC
159714 if( toupper(z[0])!=zKW[0] ) continue;
159715 if( toupper(z[1])!=zKW[1] ) continue;
159716 j = 2;
159717 while( j<n && toupper(z[j])==zKW[j] ){ j++; }
159718#endif
159719 if( j<n ) continue;
159720 testcase( i==0 ); /* REINDEX */
159721 testcase( i==1 ); /* INDEXED */
159722 testcase( i==2 ); /* INDEX */
159723 testcase( i==3 ); /* DESC */
159724 testcase( i==4 ); /* ESCAPE */
159725 testcase( i==5 ); /* EACH */
159726 testcase( i==6 ); /* CHECK */
159727 testcase( i==7 ); /* KEY */
159728 testcase( i==8 ); /* BEFORE */
159729 testcase( i==9 ); /* FOREIGN */
159730 testcase( i==10 ); /* FOR */
159731 testcase( i==11 ); /* IGNORE */
159732 testcase( i==12 ); /* REGEXP */
159733 testcase( i==13 ); /* EXPLAIN */
159734 testcase( i==14 ); /* INSTEAD */
159735 testcase( i==15 ); /* ADD */
159736 testcase( i==16 ); /* DATABASE */
159737 testcase( i==17 ); /* AS */
159738 testcase( i==18 ); /* SELECT */
159739 testcase( i==19 ); /* TABLE */
159740 testcase( i==20 ); /* LEFT */
159741 testcase( i==21 ); /* THEN */
159742 testcase( i==22 ); /* END */
159743 testcase( i==23 ); /* DEFERRABLE */
159744 testcase( i==24 ); /* ELSE */
159745 testcase( i==25 ); /* EXCLUDE */
159746 testcase( i==26 ); /* DELETE */
159747 testcase( i==27 ); /* TEMPORARY */
159748 testcase( i==28 ); /* TEMP */
159749 testcase( i==29 ); /* OR */
159750 testcase( i==30 ); /* ISNULL */
159751 testcase( i==31 ); /* NULLS */
159752 testcase( i==32 ); /* SAVEPOINT */
159753 testcase( i==33 ); /* INTERSECT */
159754 testcase( i==34 ); /* TIES */
159755 testcase( i==35 ); /* NOTNULL */
159756 testcase( i==36 ); /* NOT */
159757 testcase( i==37 ); /* NO */
159758 testcase( i==38 ); /* NULL */
159759 testcase( i==39 ); /* LIKE */
159760 testcase( i==40 ); /* EXCEPT */
159761 testcase( i==41 ); /* TRANSACTION */
159762 testcase( i==42 ); /* ACTION */
159763 testcase( i==43 ); /* ON */
159764 testcase( i==44 ); /* NATURAL */
159765 testcase( i==45 ); /* ALTER */
159766 testcase( i==46 ); /* RAISE */
159767 testcase( i==47 ); /* EXCLUSIVE */
159768 testcase( i==48 ); /* EXISTS */
159769 testcase( i==49 ); /* CONSTRAINT */
159770 testcase( i==50 ); /* INTO */
159771 testcase( i==51 ); /* OFFSET */
159772 testcase( i==52 ); /* OF */
159773 testcase( i==53 ); /* SET */
159774 testcase( i==54 ); /* TRIGGER */
159775 testcase( i==55 ); /* RANGE */
159776 testcase( i==56 ); /* GENERATED */
159777 testcase( i==57 ); /* DETACH */
159778 testcase( i==58 ); /* HAVING */
159779 testcase( i==59 ); /* GLOB */
159780 testcase( i==60 ); /* BEGIN */
159781 testcase( i==61 ); /* INNER */
159782 testcase( i==62 ); /* REFERENCES */
159783 testcase( i==63 ); /* UNIQUE */
159784 testcase( i==64 ); /* QUERY */
159785 testcase( i==65 ); /* WITHOUT */
159786 testcase( i==66 ); /* WITH */
159787 testcase( i==67 ); /* OUTER */
159788 testcase( i==68 ); /* RELEASE */
159789 testcase( i==69 ); /* ATTACH */
159790 testcase( i==70 ); /* BETWEEN */
159791 testcase( i==71 ); /* NOTHING */
159792 testcase( i==72 ); /* GROUPS */
159793 testcase( i==73 ); /* GROUP */
159794 testcase( i==74 ); /* CASCADE */
159795 testcase( i==75 ); /* ASC */
159796 testcase( i==76 ); /* DEFAULT */
159797 testcase( i==77 ); /* CASE */
159798 testcase( i==78 ); /* COLLATE */
159799 testcase( i==79 ); /* CREATE */
159800 testcase( i==80 ); /* CURRENT_DATE */
159801 testcase( i==81 ); /* IMMEDIATE */
159802 testcase( i==82 ); /* JOIN */
159803 testcase( i==83 ); /* INSERT */
159804 testcase( i==84 ); /* MATCH */
159805 testcase( i==85 ); /* PLAN */
159806 testcase( i==86 ); /* ANALYZE */
159807 testcase( i==87 ); /* PRAGMA */
159808 testcase( i==88 ); /* ABORT */
159809 testcase( i==89 ); /* UPDATE */
159810 testcase( i==90 ); /* VALUES */
159811 testcase( i==91 ); /* VIRTUAL */
159812 testcase( i==92 ); /* ALWAYS */
159813 testcase( i==93 ); /* WHEN */
159814 testcase( i==94 ); /* WHERE */
159815 testcase( i==95 ); /* RECURSIVE */
159816 testcase( i==96 ); /* AFTER */
159817 testcase( i==97 ); /* RENAME */
159818 testcase( i==98 ); /* AND */
159819 testcase( i==99 ); /* DEFERRED */
159820 testcase( i==100 ); /* DISTINCT */
159821 testcase( i==101 ); /* IS */
159822 testcase( i==102 ); /* AUTOINCREMENT */
159823 testcase( i==103 ); /* TO */
159824 testcase( i==104 ); /* IN */
159825 testcase( i==105 ); /* CAST */
159826 testcase( i==106 ); /* COLUMN */
159827 testcase( i==107 ); /* COMMIT */
159828 testcase( i==108 ); /* CONFLICT */
159829 testcase( i==109 ); /* CROSS */
159830 testcase( i==110 ); /* CURRENT_TIMESTAMP */
159831 testcase( i==111 ); /* CURRENT_TIME */
159832 testcase( i==112 ); /* CURRENT */
159833 testcase( i==113 ); /* PARTITION */
159834 testcase( i==114 ); /* DROP */
159835 testcase( i==115 ); /* PRECEDING */
159836 testcase( i==116 ); /* FAIL */
159837 testcase( i==117 ); /* LAST */
159838 testcase( i==118 ); /* FILTER */
159839 testcase( i==119 ); /* REPLACE */
159840 testcase( i==120 ); /* FIRST */
159841 testcase( i==121 ); /* FOLLOWING */
159842 testcase( i==122 ); /* FROM */
159843 testcase( i==123 ); /* FULL */
159844 testcase( i==124 ); /* LIMIT */
159845 testcase( i==125 ); /* IF */
159846 testcase( i==126 ); /* ORDER */
159847 testcase( i==127 ); /* RESTRICT */
159848 testcase( i==128 ); /* OTHERS */
159849 testcase( i==129 ); /* OVER */
159850 testcase( i==130 ); /* RIGHT */
159851 testcase( i==131 ); /* ROLLBACK */
159852 testcase( i==132 ); /* ROWS */
159853 testcase( i==133 ); /* ROW */
159854 testcase( i==134 ); /* UNBOUNDED */
159855 testcase( i==135 ); /* UNION */
159856 testcase( i==136 ); /* USING */
159857 testcase( i==137 ); /* VACUUM */
159858 testcase( i==138 ); /* VIEW */
159859 testcase( i==139 ); /* WINDOW */
159860 testcase( i==140 ); /* DO */
159861 testcase( i==141 ); /* BY */
159862 testcase( i==142 ); /* INITIALLY */
159863 testcase( i==143 ); /* ALL */
159864 testcase( i==144 ); /* PRIMARY */
static const unsigned char aKWLen[145]
Definition sqlite3.c:159499
static const unsigned char aKWNext[145]
Definition sqlite3.c:159484
static const char zKWText[647]
Definition sqlite3.c:159430
#define charMap(X)
Definition sqlite3.c:159366
static const unsigned char aKWHash[127]
Definition sqlite3.c:159469
static const unsigned short int aKWOffset[145]
Definition sqlite3.c:159515
static int keywordCode(const char *z, int n, int *pType)
Definition sqlite3.c:159693

References aKWHash, aKWLen, aKWNext, aKWOffset, charMap, testcase, and zKWText.

Referenced by sqlite3_keyword_name(), and sqlite3GetToken().

◆ last_insert_rowid()

static void last_insert_rowid ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 117602 of file sqlite3.c.

117612 {
117613 sqlite3 *db = sqlite3_context_db_handle(context);

Referenced by sqlite3RegisterBuiltinFunctions().

◆ last_valueFinalizeFunc()

static void last_valueFinalizeFunc ( sqlite3_context * pCtx)
static

Definition at line 151689 of file sqlite3.c.

151691 {
151692 sqlite3_result_value(pCtx, p->pVal);
151693 }
151694}
151695static void last_valueFinalizeFunc(sqlite3_context *pCtx){
151696 struct LastValueCtx *p;
151697 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
SQLITE_API void sqlite3_result_value(sqlite3_context *, sqlite3_value *)
Definition sqlite3.c:83503
static void last_valueFinalizeFunc(sqlite3_context *pCtx)
Definition sqlite3.c:151689

References LastValueCtx::pVal, and sqlite3_result_value().

◆ last_valueInvFunc()

static void last_valueInvFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151665 of file sqlite3.c.

151666 {
151667 p->nVal++;
151668 }
151669 }
151670}
151671static void last_valueInvFunc(
151672 sqlite3_context *pCtx,
151673 int nArg,
151674 sqlite3_value **apArg
151675){
151676 struct LastValueCtx *p;
151677 UNUSED_PARAMETER(nArg);
151678 UNUSED_PARAMETER(apArg);
151679 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151680 if( ALWAYS(p) ){
151681 p->nVal--;
static void last_valueInvFunc(sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
Definition sqlite3.c:151665

◆ last_valueStepFunc()

static void last_valueStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151647 of file sqlite3.c.

151657 {
151658 struct LastValueCtx *p;
151659 UNUSED_PARAMETER(nArg);
151660 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151661 if( p ){
151663 p->pVal = sqlite3_value_dup(apArg[0]);
151664 if( p->pVal==0 ){
sqlite3_value * pVal
Definition sqlite3.c:151640

◆ last_valueValueFunc()

static void last_valueValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151682 of file sqlite3.c.

151682 {
151683 sqlite3_value_free(p->pVal);
151684 p->pVal = 0;
151685 }
151686 }
151687}
151688static void last_valueValueFunc(sqlite3_context *pCtx){
static void last_valueValueFunc(sqlite3_context *pCtx)
Definition sqlite3.c:151682

References LastValueCtx::pVal, and sqlite3_value_free().

◆ lengthFunc()

static void lengthFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117148 of file sqlite3.c.

117158 {
117159 assert( argc==1 );
117160 UNUSED_PARAMETER(argc);
117161 switch( sqlite3_value_type(argv[0]) ){
117162 case SQLITE_BLOB:
117163 case SQLITE_INTEGER:
117164 case SQLITE_FLOAT: {
117165 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
117166 break;
117167 }
117168 case SQLITE_TEXT: {
117169 const unsigned char *z = sqlite3_value_text(argv[0]);
117170 const unsigned char *z0;
117171 unsigned char c;
117172 if( z==0 ) return;
117173 z0 = z;
117174 while( (c = *z)!=0 ){
117175 z++;
117176 if( c>=0xc0 ){
117177 while( (*z & 0xc0)==0x80 ){ z++; z0++; }
117178 }
117179 }
117180 sqlite3_result_int(context, (int)(z-z0));
117181 break;
117182 }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ likeFunc()

static void likeFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117890 of file sqlite3.c.

117900 {
117901 const unsigned char *zA, *zB;
117902 u32 escape;
117903 int nPat;
117904 sqlite3 *db = sqlite3_context_db_handle(context);
117905 struct compareInfo *pInfo = sqlite3_user_data(context);
117906 struct compareInfo backupInfo;
117907
117908#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
117909 if( sqlite3_value_type(argv[0])==SQLITE_BLOB
117910 || sqlite3_value_type(argv[1])==SQLITE_BLOB
117911 ){
117912#ifdef SQLITE_TEST
117913 sqlite3_like_count++;
117914#endif
117915 sqlite3_result_int(context, 0);
117916 return;
117917 }
117918#endif
117919
117920 /* Limit the length of the LIKE or GLOB pattern to avoid problems
117921 ** of deep recursion and N*N behavior in patternCompare().
117922 */
117923 nPat = sqlite3_value_bytes(argv[0]);
117926 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
117927 sqlite3_result_error(context, "LIKE or GLOB pattern too complex", -1);
117928 return;
117929 }
117930 if( argc==3 ){
117931 /* The escape character string must consist of a single UTF-8 character.
117932 ** Otherwise, return an error.
117933 */
117934 const unsigned char *zEsc = sqlite3_value_text(argv[2]);
117935 if( zEsc==0 ) return;
117936 if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
117937 sqlite3_result_error(context,
117938 "ESCAPE expression must be a single character", -1);
117939 return;
117940 }
117941 escape = sqlite3Utf8Read(&zEsc);
117942 if( escape==pInfo->matchAll || escape==pInfo->matchOne ){
117943 memcpy(&backupInfo, pInfo, sizeof(backupInfo));
117944 pInfo = &backupInfo;
117945 if( escape==pInfo->matchAll ) pInfo->matchAll = 0;
117946 if( escape==pInfo->matchOne ) pInfo->matchOne = 0;
117947 }
117948 }else{
117949 escape = pInfo->matchSet;
117950 }
117951 zB = sqlite3_value_text(argv[0]);
117952 zA = sqlite3_value_text(argv[1]);
117953 if( zA && zB ){
117954#ifdef SQLITE_TEST
SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte)
Definition sqlite3.c:31057
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH
Definition sqlite3.c:4952
SQLITE_API void * sqlite3_user_data(sqlite3_context *)
Definition sqlite3.c:83779
SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8 **)

References sqlite3::aLimit, compareInfo::matchAll, compareInfo::matchOne, compareInfo::matchSet, patternCompare(), sqlite3_context_db_handle(), sqlite3_result_error(), sqlite3_result_int(), sqlite3_user_data(), sqlite3_value_bytes(), sqlite3_value_text(), sqlite3_value_type(), sqlite3Utf8CharLen(), sqlite3Utf8Read(), SQLITE_BLOB, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, SQLITE_MATCH, and testcase.

Referenced by sqlite3RegisterLikeFunctions().

◆ loadAnalysis()

static void loadAnalysis ( Parse * pParse,
int iDb )
static

Definition at line 108887 of file sqlite3.c.

References OP_LoadAnalysis, sqlite3GetVdbe(), and sqlite3VdbeAddOp1().

Referenced by analyzeTable().

◆ loadExt()

static void loadExt ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118520 of file sqlite3.c.

118526 {
118527 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
118528 const char *zProc;
118529 sqlite3 *db = sqlite3_context_db_handle(context);
118530 char *zErrMsg = 0;
118531
118532 /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
118533 ** flag is set. See the sqlite3_enable_load_extension() API.
118534 */
118535 if( (db->flags & SQLITE_LoadExtFunc)==0 ){
118536 sqlite3_result_error(context, "not authorized", -1);
118537 return;
118538 }
118539
118540 if( argc==2 ){
118541 zProc = (const char *)sqlite3_value_text(argv[1]);
118542 }else{
118543 zProc = 0;
#define SQLITE_LoadExtFunc
Definition sqlite3.c:16996

References sqlite3::flags, sqlite3_context_db_handle(), sqlite3_free(), sqlite3_load_extension(), sqlite3_result_error(), sqlite3_value_text(), and SQLITE_LoadExtFunc.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ localtimeOffset()

static sqlite3_int64 localtimeOffset ( DateTime * p,
sqlite3_context * pCtx,
int * pRc )
static

Definition at line 22261 of file sqlite3.c.

22270 {
22271 DateTime x, y;
22272 time_t t;
22273 struct tm sLocal;
22274
22275 /* Initialize the contents of sLocal to avoid a compiler warning. */
22276 memset(&sLocal, 0, sizeof(sLocal));
22277
22278 x = *p;
22279 computeYMD_HMS(&x);
22280 if( x.Y<1971 || x.Y>=2038 ){
22281 /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
22282 ** works for years between 1970 and 2037. For dates outside this range,
22283 ** SQLite attempts to map the year into an equivalent year within this
22284 ** range, do the calculation, then map the year back.
22285 */
22286 x.Y = 2000;
22287 x.M = 1;
22288 x.D = 1;
22289 x.h = 0;
22290 x.m = 0;
22291 x.s = 0.0;
22292 } else {
22293 int s = (int)(x.s + 0.5);
22294 x.s = s;
22295 }
22296 x.tz = 0;
22297 x.validJD = 0;
22298 computeJD(&x);
22299 t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
22300 if( osLocaltime(&t, &sLocal) ){
22301 sqlite3_result_error(pCtx, "local time unavailable", -1);
22302 *pRc = SQLITE_ERROR;
22303 return 0;
22304 }
22305 y.Y = sLocal.tm_year + 1900;
22306 y.M = sLocal.tm_mon + 1;
22307 y.D = sLocal.tm_mday;
22308 y.h = sLocal.tm_hour;
22309 y.m = sLocal.tm_min;
22310 y.s = sLocal.tm_sec;
22311 y.validYMD = 1;
22312 y.validHMS = 1;
22313 y.validJD = 0;
22314 y.rawS = 0;
22315 y.validTZ = 0;
static int osLocaltime(time_t *t, struct tm *pTm)
Definition sqlite3.c:22222

References computeJD(), computeYMD_HMS(), DateTime::D, DateTime::h, DateTime::iJD, DateTime::isError, DateTime::M, DateTime::m, osLocaltime(), DateTime::rawS, DateTime::s, s, sqlite3_result_error(), SQLITE_ERROR, SQLITE_OK, DateTime::tz, DateTime::validHMS, DateTime::validJD, DateTime::validTZ, DateTime::validYMD, and DateTime::Y.

Referenced by parseModifier().

◆ lockBtree()

static int lockBtree ( BtShared * pBt)
static

Definition at line 67538 of file sqlite3.c.

67544 {
67545 int rc; /* Result code from subfunctions */
67546 MemPage *pPage1; /* Page 1 of the database file */
67547 u32 nPage; /* Number of pages in the database */
67548 u32 nPageFile = 0; /* Number of pages in the database file */
67549 u32 nPageHeader; /* Number of pages in the database according to hdr */
67550
67551 assert( sqlite3_mutex_held(pBt->mutex) );
67552 assert( pBt->pPage1==0 );
67553 rc = sqlite3PagerSharedLock(pBt->pPager);
67554 if( rc!=SQLITE_OK ) return rc;
67555 rc = btreeGetPage(pBt, 1, &pPage1, 0);
67556 if( rc!=SQLITE_OK ) return rc;
67557
67558 /* Do some checking to help insure the file we opened really is
67559 ** a valid database file.
67560 */
67561 nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
67562 sqlite3PagerPagecount(pBt->pPager, (int*)&nPageFile);
67563 if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){
67564 nPage = nPageFile;
67565 }
67566 if( (pBt->db->flags & SQLITE_ResetDatabase)!=0 ){
67567 nPage = 0;
67568 }
67569 if( nPage>0 ){
67570 u32 pageSize;
67571 u32 usableSize;
67572 u8 *page1 = pPage1->aData;
67573 rc = SQLITE_NOTADB;
67574 /* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
67575 ** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
67576 ** 61 74 20 33 00. */
67577 if( memcmp(page1, zMagicHeader, 16)!=0 ){
67578 goto page1_init_failed;
67579 }
67580
67581#ifdef SQLITE_OMIT_WAL
67582 if( page1[18]>1 ){
67583 pBt->btsFlags |= BTS_READ_ONLY;
67584 }
67585 if( page1[19]>1 ){
67586 goto page1_init_failed;
67587 }
67588#else
67589 if( page1[18]>2 ){
67590 pBt->btsFlags |= BTS_READ_ONLY;
67591 }
67592 if( page1[19]>2 ){
67593 goto page1_init_failed;
67594 }
67595
67596 /* If the write version is set to 2, this database should be accessed
67597 ** in WAL mode. If the log is not already open, open it now. Then
67598 ** return SQLITE_OK and return without populating BtShared.pPage1.
67599 ** The caller detects this and calls this function again. This is
67600 ** required as the version of page 1 currently in the page1 buffer
67601 ** may not be the latest version - there may be a newer one in the log
67602 ** file.
67603 */
67604 if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
67605 int isOpen = 0;
67606 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
67607 if( rc!=SQLITE_OK ){
67608 goto page1_init_failed;
67609 }else{
67611 if( isOpen==0 ){
67612 releasePageOne(pPage1);
67613 return SQLITE_OK;
67614 }
67615 }
67616 rc = SQLITE_NOTADB;
67617 }else{
67619 }
67620#endif
67621
67622 /* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
67623 ** fractions and the leaf payload fraction values must be 64, 32, and 32.
67624 **
67625 ** The original design allowed these amounts to vary, but as of
67626 ** version 3.6.0, we require them to be fixed.
67627 */
67628 if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
67629 goto page1_init_failed;
67630 }
67631 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
67632 ** determined by the 2-byte integer located at an offset of 16 bytes from
67633 ** the beginning of the database file. */
67634 pageSize = (page1[16]<<8) | (page1[17]<<16);
67635 /* EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
67636 ** between 512 and 65536 inclusive. */
67637 if( ((pageSize-1)&pageSize)!=0
67638 || pageSize>SQLITE_MAX_PAGE_SIZE
67639 || pageSize<=256
67640 ){
67641 goto page1_init_failed;
67642 }
67644 assert( (pageSize & 7)==0 );
67645 /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
67646 ** integer at offset 20 is the number of bytes of space at the end of
67647 ** each page to reserve for extensions.
67648 **
67649 ** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
67650 ** determined by the one-byte unsigned integer found at an offset of 20
67651 ** into the database file header. */
67652 usableSize = pageSize - page1[20];
67653 if( (u32)pageSize!=pBt->pageSize ){
67654 /* After reading the first page of the database assuming a page size
67655 ** of BtShared.pageSize, we have discovered that the page-size is
67656 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
67657 ** zero and return SQLITE_OK. The caller will call this function
67658 ** again with the correct page-size.
67659 */
67660 releasePageOne(pPage1);
67661 pBt->usableSize = usableSize;
67662 pBt->pageSize = pageSize;
67663 freeTempSpace(pBt);
67664 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
67665 pageSize-usableSize);
67666 return rc;
67667 }
67668 if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
67670 goto page1_init_failed;
67671 }
67672 /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
67673 ** be less than 480. In other words, if the page size is 512, then the
67674 ** reserved space size cannot exceed 32. */
67675 if( usableSize<480 ){
67676 goto page1_init_failed;
67677 }
67678 pBt->pageSize = pageSize;
67679 pBt->usableSize = usableSize;
67680#ifndef SQLITE_OMIT_AUTOVACUUM
67681 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
67682 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
67683#endif
67684 }
67685
67686 /* maxLocal is the maximum amount of payload to store locally for
67687 ** a cell. Make sure it is small enough so that at least minFanout
67688 ** cells can will fit on one page. We assume a 10-byte page header.
67689 ** Besides the payload, the cell must store:
67690 ** 2-byte pointer to the cell
67691 ** 4-byte child pointer
67692 ** 9-byte nKey value
67693 ** 4-byte nData value
67694 ** 4-byte overflow page pointer
67695 ** So a cell consists of a 2-byte pointer, a header which is as much as
67696 ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
67697 ** page pointer.
67698 */
67699 pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23);
67700 pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23);
67701 pBt->maxLeaf = (u16)(pBt->usableSize - 35);
67702 pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23);
67703 if( pBt->maxLocal>127 ){
67704 pBt->max1bytePayload = 127;
67705 }else{
67706 pBt->max1bytePayload = (u8)pBt->maxLocal;
67707 }
67708 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
67709 pBt->pPage1 = pPage1;
67710 pBt->nPage = nPage;
67711 return SQLITE_OK;
#define setDefaultSyncFlag(pBt, safety_level)
Definition sqlite3.c:67522
#define BTS_NO_WAL
Definition sqlite3.c:63921
SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager)
Definition sqlite3.c:56874
SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen)
Definition sqlite3.c:59198
#define MX_CELL_SIZE(pBt)
Definition sqlite3.c:63691
#define SQLITE_ResetDatabase
Definition sqlite3.c:17004
#define SQLITE_NOTADB
Definition sqlite3.c:1496
static void releasePageOne(MemPage *pPage)
Definition sqlite3.c:66710
#define SQLITE_DEFAULT_WAL_SYNCHRONOUS
Definition sqlite3.c:16595
#define BTS_PAGESIZE_FIXED
Definition sqlite3.c:63916
SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager *, u32 *, int)
Definition sqlite3.c:55385
static const char zMagicHeader[]
Definition sqlite3.c:64499
SQLITE_PRIVATE void sqlite3PagerPagecount(Pager *, int *)
Definition sqlite3.c:55542
static void freeTempSpace(BtShared *pBt)
Definition sqlite3.c:67175
u8 max1bytePayload
Definition sqlite3.c:63888

References MemPage::aData, BtShared::autoVacuum, btreeGetPage(), BTS_NO_WAL, BTS_PAGESIZE_FIXED, BTS_READ_ONLY, BtShared::btsFlags, BtShared::db, sqlite3::flags, freeTempSpace(), get4byte, BtShared::incrVacuum, isOpen, BtShared::max1bytePayload, BtShared::maxLeaf, BtShared::maxLocal, BtShared::minLeaf, BtShared::minLocal, BtShared::mutex, MX_CELL_SIZE, BtShared::nPage, BtShared::pageSize, BtShared::pPage1, BtShared::pPager, releasePageOne(), setDefaultSyncFlag, sqlite3_mutex_held(), sqlite3PagerOpenWal(), sqlite3PagerPagecount(), sqlite3PagerSetPagesize(), sqlite3PagerSharedLock(), sqlite3WritableSchema(), SQLITE_CORRUPT_BKPT, SQLITE_DEFAULT_SYNCHRONOUS, SQLITE_DEFAULT_WAL_SYNCHRONOUS, SQLITE_MAX_PAGE_SIZE, SQLITE_NOTADB, SQLITE_OK, SQLITE_ResetDatabase, BtShared::usableSize, and zMagicHeader.

Referenced by sqlite3BtreeBeginTrans().

◆ lockBtreeMutex()

static void lockBtreeMutex ( Btree * p)
static

◆ logBadConnection()

static void logBadConnection ( const char * zType)
static

Definition at line 32521 of file sqlite3.c.

References sqlite3_log(), and SQLITE_MISUSE.

Referenced by sqlite3SafetyCheckOk().

◆ lookasideMallocSize()

static int lookasideMallocSize ( sqlite3 * db,
void * p )
static

Definition at line 27647 of file sqlite3.c.

27648 {
27650 return sqlite3GlobalConfig.m.xSize(p);
27651}
27652static int lookasideMallocSize(sqlite3 *db, void *p){
27653#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE

References MEMTYPE_HEAP, sqlite3GlobalConfig, and sqlite3MemdebugHasType.

◆ lookupName()

static int lookupName ( Parse * pParse,
const char * zDb,
const char * zTab,
const char * zCol,
NameContext * pNC,
Expr * pExpr )
static

Definition at line 97986 of file sqlite3.c.

97999 {
98000 int i, j; /* Loop counters */
98001 int cnt = 0; /* Number of matching column names */
98002 int cntTab = 0; /* Number of matching table names */
98003 int nSubquery = 0; /* How many levels of subquery */
98004 sqlite3 *db = pParse->db; /* The database connection */
98005 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
98006 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
98007 NameContext *pTopNC = pNC; /* First namecontext in the list */
98008 Schema *pSchema = 0; /* Schema of the expression */
98009 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
98010 Table *pTab = 0; /* Table hold the row */
98011 Column *pCol; /* A column of pTab */
98012
98013 assert( pNC ); /* the name context cannot be NULL. */
98014 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
98015 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
98016
98017 /* Initialize the node to no-match */
98018 pExpr->iTable = -1;
98020
98021 /* Translate the schema name in zDb into a pointer to the corresponding
98022 ** schema. If not found, pSchema will remain NULL and nothing will match
98023 ** resulting in an appropriate error message toward the end of this routine
98024 */
98025 if( zDb ){
98026 testcase( pNC->ncFlags & NC_PartIdx );
98027 testcase( pNC->ncFlags & NC_IsCheck );
98028 if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
98029 /* Silently ignore database qualifiers inside CHECK constraints and
98030 ** partial indices. Do not raise errors because that might break
98031 ** legacy and because it does not hurt anything to just ignore the
98032 ** database name. */
98033 zDb = 0;
98034 }else{
98035 for(i=0; i<db->nDb; i++){
98036 assert( db->aDb[i].zDbSName );
98037 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
98038 pSchema = db->aDb[i].pSchema;
98039 break;
98040 }
98041 }
98042 if( i==db->nDb && sqlite3StrICmp("main", zDb)==0 ){
98043 /* This branch is taken when the main database has been renamed
98044 ** using SQLITE_DBCONFIG_MAINDBNAME. */
98045 pSchema = db->aDb[0].pSchema;
98046 zDb = db->aDb[0].zDbSName;
98047 }
98048 }
98049 }
98050
98051 /* Start at the inner-most context and move outward until a match is found */
98052 assert( pNC && cnt==0 );
98053 do{
98054 ExprList *pEList;
98055 SrcList *pSrcList = pNC->pSrcList;
98056
98057 if( pSrcList ){
98058 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
98059 u8 hCol;
98060 pTab = pItem->pTab;
98061 assert( pTab!=0 && pTab->zName!=0 );
98062 assert( pTab->nCol>0 );
98063 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
98064 int hit = 0;
98065 pEList = pItem->pSelect->pEList;
98066 for(j=0; j<pEList->nExpr; j++){
98067 if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){
98068 cnt++;
98069 cntTab = 2;
98070 pMatch = pItem;
98071 pExpr->iColumn = j;
98072 hit = 1;
98073 }
98074 }
98075 if( hit || zTab==0 ) continue;
98076 }
98077 if( zDb && pTab->pSchema!=pSchema ){
98078 continue;
98079 }
98080 if( zTab ){
98081 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
98082 assert( zTabName!=0 );
98083 if( sqlite3StrICmp(zTabName, zTab)!=0 ){
98084 continue;
98085 }
98086 if( IN_RENAME_OBJECT && pItem->zAlias ){
98087 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
98088 }
98089 }
98090 if( 0==(cntTab++) ){
98091 pMatch = pItem;
98092 }
98093 hCol = sqlite3StrIHash(zCol);
98094 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
98095 if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
98096 /* If there has been exactly one prior match and this match
98097 ** is for the right-hand table of a NATURAL JOIN or is in a
98098 ** USING clause, then skip this match.
98099 */
98100 if( cnt==1 ){
98101 if( pItem->fg.jointype & JT_NATURAL ) continue;
98102 if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
98103 }
98104 cnt++;
98105 pMatch = pItem;
98106 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
98107 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
98108 break;
98109 }
98110 }
98111 }
98112 if( pMatch ){
98113 pExpr->iTable = pMatch->iCursor;
98114 pExpr->y.pTab = pMatch->pTab;
98115 /* RIGHT JOIN not (yet) supported */
98116 assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
98117 if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
98119 }
98120 pSchema = pExpr->y.pTab->pSchema;
98121 }
98122 } /* if( pSrcList ) */
98123
98124#if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT)
98125 /* If we have not already resolved the name, then maybe
98126 ** it is a new.* or old.* trigger argument reference. Or
98127 ** maybe it is an excluded.* from an upsert.
98128 */
98129 if( zDb==0 && zTab!=0 && cntTab==0 ){
98130 pTab = 0;
98131#ifndef SQLITE_OMIT_TRIGGER
98132 if( pParse->pTriggerTab!=0 ){
98133 int op = pParse->eTriggerOp;
98134 assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
98135 if( op!=TK_DELETE && sqlite3StrICmp("new",zTab) == 0 ){
98136 pExpr->iTable = 1;
98137 pTab = pParse->pTriggerTab;
98138 }else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
98139 pExpr->iTable = 0;
98140 pTab = pParse->pTriggerTab;
98141 }
98142 }
98143#endif /* SQLITE_OMIT_TRIGGER */
98144#ifndef SQLITE_OMIT_UPSERT
98145 if( (pNC->ncFlags & NC_UUpsert)!=0 ){
98146 Upsert *pUpsert = pNC->uNC.pUpsert;
98147 if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){
98148 pTab = pUpsert->pUpsertSrc->a[0].pTab;
98150 }
98151 }
98152#endif /* SQLITE_OMIT_UPSERT */
98153
98154 if( pTab ){
98155 int iCol;
98156 u8 hCol = sqlite3StrIHash(zCol);
98157 pSchema = pTab->pSchema;
98158 cntTab++;
98159 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
98160 if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
98161 if( iCol==pTab->iPKey ){
98162 iCol = -1;
98163 }
98164 break;
98165 }
98166 }
98167 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
98168 /* IMP: R-51414-32910 */
98169 iCol = -1;
98170 }
98171 if( iCol<pTab->nCol ){
98172 cnt++;
98173#ifndef SQLITE_OMIT_UPSERT
98174 if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
98175 testcase( iCol==(-1) );
98176 if( IN_RENAME_OBJECT ){
98177 pExpr->iColumn = iCol;
98178 pExpr->y.pTab = pTab;
98179 eNewExprOp = TK_COLUMN;
98180 }else{
98181 pExpr->iTable = pNC->uNC.pUpsert->regData +
98182 sqlite3TableColumnToStorage(pTab, iCol);
98183 eNewExprOp = TK_REGISTER;
98184 ExprSetProperty(pExpr, EP_Alias);
98185 }
98186 }else
98187#endif /* SQLITE_OMIT_UPSERT */
98188 {
98189#ifndef SQLITE_OMIT_TRIGGER
98190 if( iCol<0 ){
98191 pExpr->affExpr = SQLITE_AFF_INTEGER;
98192 }else if( pExpr->iTable==0 ){
98193 testcase( iCol==31 );
98194 testcase( iCol==32 );
98195 pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
98196 }else{
98197 testcase( iCol==31 );
98198 testcase( iCol==32 );
98199 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
98200 }
98201 pExpr->y.pTab = pTab;
98202 pExpr->iColumn = (i16)iCol;
98203 eNewExprOp = TK_TRIGGER;
98204#endif /* SQLITE_OMIT_TRIGGER */
98205 }
98206 }
98207 }
98208 }
98209#endif /* !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) */
98210
98211 /*
98212 ** Perhaps the name is a reference to the ROWID
98213 */
98214 if( cnt==0
98215 && cntTab==1
98216 && pMatch
98217 && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
98218 && sqlite3IsRowid(zCol)
98219 && VisibleRowid(pMatch->pTab)
98220 ){
98221 cnt = 1;
98222 pExpr->iColumn = -1;
98223 pExpr->affExpr = SQLITE_AFF_INTEGER;
98224 }
98225
98226 /*
98227 ** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z
98228 ** might refer to an result-set alias. This happens, for example, when
98229 ** we are resolving names in the WHERE clause of the following command:
98230 **
98231 ** SELECT a+b AS x FROM table WHERE x<10;
98232 **
98233 ** In cases like this, replace pExpr with a copy of the expression that
98234 ** forms the result set entry ("a+b" in the example) and return immediately.
98235 ** Note that the expression in the result set should have already been
98236 ** resolved by the time the WHERE clause is resolved.
98237 **
98238 ** The ability to use an output result-set column in the WHERE, GROUP BY,
98239 ** or HAVING clauses, or as part of a larger expression in the ORDER BY
98240 ** clause is not standard SQL. This is a (goofy) SQLite extension, that
98241 ** is supported for backwards compatibility only. Hence, we issue a warning
98242 ** on sqlite3_log() whenever the capability is used.
98243 */
98244 if( (pNC->ncFlags & NC_UEList)!=0
98245 && cnt==0
98246 && zTab==0
98247 ){
98248 pEList = pNC->uNC.pEList;
98249 assert( pEList!=0 );
98250 for(j=0; j<pEList->nExpr; j++){
98251 char *zAs = pEList->a[j].zEName;
98252 if( pEList->a[j].eEName==ENAME_NAME
98253 && sqlite3_stricmp(zAs, zCol)==0
98254 ){
98255 Expr *pOrig;
98256 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
98257 assert( pExpr->x.pList==0 );
98258 assert( pExpr->x.pSelect==0 );
98259 pOrig = pEList->a[j].pExpr;
98260 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
98261 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
98262 return WRC_Abort;
98263 }
98264 if( ExprHasProperty(pOrig, EP_Win)
98265 && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC )
98266 ){
98267 sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
98268 return WRC_Abort;
98269 }
98270 if( sqlite3ExprVectorSize(pOrig)!=1 ){
98271 sqlite3ErrorMsg(pParse, "row value misused");
98272 return WRC_Abort;
98273 }
98274 resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
98275 cnt = 1;
98276 pMatch = 0;
98277 assert( zTab==0 && zDb==0 );
98278 if( IN_RENAME_OBJECT ){
98279 sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
98280 }
98281 goto lookupname_end;
98282 }
98283 }
98284 }
98285
98286 /* Advance to the next name context. The loop will exit when either
98287 ** we have a match (cnt>0) or when we run out of name contexts.
98288 */
98289 if( cnt ) break;
98290 pNC = pNC->pNext;
98291 nSubquery++;
98292 }while( pNC );
98293
98294
98295 /*
98296 ** If X and Y are NULL (in other words if only the column name Z is
98297 ** supplied) and the value of Z is enclosed in double-quotes, then
98298 ** Z is a string literal if it doesn't match any column names. In that
98299 ** case, we need to return right away and not make any changes to
98300 ** pExpr.
98301 **
98302 ** Because no reference was made to outer contexts, the pNC->nRef
98303 ** fields are not changed in any context.
98304 */
98305 if( cnt==0 && zTab==0 ){
98306 assert( pExpr->op==TK_ID );
98307 if( ExprHasProperty(pExpr,EP_DblQuoted)
98308 && areDoubleQuotedStringsEnabled(db, pTopNC)
98309 ){
98310 /* If a double-quoted identifier does not match any known column name,
98311 ** then treat it as a string.
98312 **
98313 ** This hack was added in the early days of SQLite in a misguided attempt
98314 ** to be compatible with MySQL 3.x, which used double-quotes for strings.
98315 ** I now sorely regret putting in this hack. The effect of this hack is
98316 ** that misspelled identifier names are silently converted into strings
98317 ** rather than causing an error, to the frustration of countless
98318 ** programmers. To all those frustrated programmers, my apologies.
98319 **
98320 ** Someday, I hope to get rid of this hack. Unfortunately there is
98321 ** a huge amount of legacy SQL that uses it. So for now, we just
98322 ** issue a warning.
98323 */
98325 "double-quoted string literal: \"%w\"", zCol);
98326#ifdef SQLITE_ENABLE_NORMALIZE
98327 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
98328#endif
98329 pExpr->op = TK_STRING;
98330 pExpr->y.pTab = 0;
98331 return WRC_Prune;
98332 }
98333 if( sqlite3ExprIdToTrueFalse(pExpr) ){
98334 return WRC_Prune;
98335 }
98336 }
98337
98338 /*
98339 ** cnt==0 means there was not match. cnt>1 means there were two or
98340 ** more matches. Either way, we have an error.
98341 */
98342 if( cnt!=1 ){
98343 const char *zErr;
98344 zErr = cnt==0 ? "no such column" : "ambiguous column name";
98345 if( zDb ){
98346 sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol);
98347 }else if( zTab ){
98348 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
98349 }else{
98350 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
98351 }
98352 pParse->checkSchema = 1;
98353 pTopNC->nErr++;
98354 }
98355
98356 /* If a column from a table in pSrcList is referenced, then record
98357 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
98358 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
98359 ** set if the 63rd or any subsequent column is used.
98360 **
98361 ** The colUsed mask is an optimization used to help determine if an
98362 ** index is a covering index. The correct answer is still obtained
98363 ** if the mask contains extra set bits. However, it is important to
98364 ** avoid setting bits beyond the maximum column number of the table.
98365 ** (See ticket [b92e5e8ec2cdbaa1]).
98366 **
98367 ** If a generated column is referenced, set bits for every column
98368 ** of the table.
98369 */
98370 if( pExpr->iColumn>=0 && pMatch!=0 ){
98371 pMatch->colUsed |= sqlite3ExprColUsed(pExpr);
98372 }
98373
98374 /* Clean up and return
98375 */
98376 sqlite3ExprDelete(db, pExpr->pLeft);
98377 pExpr->pLeft = 0;
98378 sqlite3ExprDelete(db, pExpr->pRight);
98379 pExpr->pRight = 0;
98380 pExpr->op = eNewExprOp;
98381 ExprSetProperty(pExpr, EP_Leaf);
98382lookupname_end:
98383 if( cnt==1 ){
98384 assert( pNC!=0 );
98385 if( !ExprHasProperty(pExpr, EP_Alias) ){
98386 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
98387 }
98388 /* Increment the nRef value on all name contexts from TopNC up to
98389 ** the point where the name matched. */
98390 for(;;){
98391 assert( pTopNC!=0 );
98392 pTopNC->nRef++;
98393 if( pTopNC==pNC ) break;
98394 pTopNC = pTopNC->pNext;
#define SF_NestedFrom
Definition sqlite3.c:18482
#define NC_AllowWin
Definition sqlite3.c:18386
#define EXCLUDED_TABLE_NUMBER
Definition sqlite3.c:97771
SQLITE_PRIVATE int sqlite3IsRowid(const char *)
Definition sqlite3.c:102059
#define EP_Agg
Definition sqlite3.c:18064
#define NC_AllowAgg
Definition sqlite3.c:18373
#define TK_TRIGGER
Definition sqlite3.c:14019
static int areDoubleQuotedStringsEnabled(sqlite3 *db, NameContext *pTopNC)
Definition sqlite3.c:97920
#define JT_NATURAL
Definition sqlite3.c:18289
#define JT_RIGHT
Definition sqlite3.c:18291
#define NC_UUpsert
Definition sqlite3.c:18383
#define EP_CanBeNull
Definition sqlite3.c:18080
#define EP_Win
Definition sqlite3.c:18075
SQLITE_PRIVATE void sqlite3AuthRead(Parse *, Expr *, Schema *, SrcList *)
Definition sqlite3.c:110252
#define VisibleRowid(X)
Definition sqlite3.c:17584
SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *)
Definition sqlite3.c:97938
#define EP_DblQuoted
Definition sqlite3.c:18066
SQLITE_PRIVATE int sqlite3MatchEName(const struct ExprList_item *, const char *, const char *, const char *)
Definition sqlite3.c:97891
#define NC_UEList
Definition sqlite3.c:18381
#define SQLITE_WARNING
Definition sqlite3.c:1498
static int nameInUsingClause(IdList *pUsing, const char *zCol)
Definition sqlite3.c:97874
#define EP_Alias
Definition sqlite3.c:18082
static void resolveAlias(Parse *pParse, ExprList *pEList, int iCol, Expr *pExpr, const char *zType, int nSubquery)
Definition sqlite3.c:97817
u8 hName
Definition sqlite3.c:17338
ExprList * pEList
Definition sqlite3.c:18353
Upsert * pUpsert
Definition sqlite3.c:18355
u8 checkSchema
Definition sqlite3.c:18685
SrcList * pUpsertSrc
Definition sqlite3.c:18416
int regData
Definition sqlite3.c:18417

References ExprList::a, SrcList::a, Table::aCol, sqlite3::aDb, Expr::affExpr, areDoubleQuotedStringsEnabled(), Parse::checkSchema, Parse::db, ExprList::ExprList_item::eEName, ENAME_NAME, EP_Agg, EP_Alias, EP_CanBeNull, EP_DblQuoted, EP_Leaf, EP_NoReduce, EP_Reduced, EP_TokenOnly, EP_Win, Parse::eTriggerOp, EXCLUDED_TABLE_NUMBER, ExprHasProperty, ExprSetProperty, ExprSetVVAProperty, Column::hName, Expr::iColumn, IN_RENAME_OBJECT, Table::iPKey, Expr::iTable, JT_LEFT, JT_NATURAL, JT_RIGHT, nameInUsingClause(), NC_AllowAgg, NC_AllowWin, NC_GenCol, NC_IdxExpr, NC_IsCheck, NC_PartIdx, NC_UEList, NC_UUpsert, NameContext::ncFlags, Table::nCol, sqlite3::nDb, NameContext::nErr, Parse::newmask, ExprList::nExpr, NameContext::nRef, SrcList::nSrc, Parse::oldmask, Expr::op, NameContext::pEList, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, NameContext::pNext, Expr::pRight, Db::pSchema, Table::pSchema, Expr::pSelect, NameContext::pSrcList, Expr::pTab, SrcList::SrcList_item::pTab, Parse::pTriggerTab, NameContext::pUpsert, Upsert::pUpsertSrc, Parse::pVdbe, Upsert::regData, resolveAlias(), SF_NestedFrom, sqlite3_log(), sqlite3_stricmp(), sqlite3AuthRead(), sqlite3ErrorMsg(), sqlite3ExprColUsed(), sqlite3ExprDelete(), sqlite3ExprIdToTrueFalse(), sqlite3ExprVectorSize(), sqlite3IsRowid(), sqlite3MatchEName(), sqlite3RenameTokenRemap(), sqlite3StrICmp(), sqlite3StrIHash(), sqlite3TableColumnToStorage(), SQLITE_AFF_INTEGER, SQLITE_WARNING, testcase, TK_COLUMN, TK_DELETE, TK_ID, TK_INSERT, TK_REGISTER, TK_STRING, TK_TRIGGER, TK_UPDATE, NameContext::uNC, VisibleRowid, WRC_Abort, WRC_Prune, Expr::x, Expr::y, Db::zDbSName, ExprList::ExprList_item::zEName, Column::zName, and Table::zName.

Referenced by resolveExprStep().

◆ lowerFunc()

static void lowerFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117519 of file sqlite3.c.

117525 {
117526 char *z1;
117527 const char *z2;
117528 int i, n;
117529 UNUSED_PARAMETER(argc);
117530 z2 = (char*)sqlite3_value_text(argv[0]);
117531 n = sqlite3_value_bytes(argv[0]);
117532 /* Verify that the call to _bytes() does not invalidate the _text() pointer */
117533 assert( z2==(char*)sqlite3_value_text(argv[0]) );
117534 if( z2 ){
117535 z1 = contextMalloc(context, ((i64)n)+1);
117536 if( z1 ){
117537 for(i=0; i<n; i++){

Referenced by sqlite3RegisterBuiltinFunctions().

◆ makeColumnPartOfPrimaryKey()

static void makeColumnPartOfPrimaryKey ( Parse * pParse,
Column * pCol )
static

Definition at line 111903 of file sqlite3.c.

111909 {
111910 pCol->colFlags |= COLFLAG_PRIMKEY;
111911#ifndef SQLITE_OMIT_GENERATED_COLUMNS
111912 if( pCol->colFlags & COLFLAG_GENERATED ){
111913 testcase( pCol->colFlags & COLFLAG_VIRTUAL );

Referenced by sqlite3AddPrimaryKey().

◆ makeSorterRecord()

static int makeSorterRecord ( Parse * pParse,
SortCtx * pSort,
Select * pSelect,
int regBase,
int nBase )
static

Definition at line 129855 of file sqlite3.c.

129867 {
129868 int nOBSat = pSort->nOBSat;
129869 Vdbe *v = pParse->pVdbe;
129870 int regOut = ++pParse->nMem;

References innerLoopLoadRow(), Parse::nMem, SortCtx::nOBSat, OP_MakeRecord, SortCtx::pDeferredRowLoad, Parse::pVdbe, and sqlite3VdbeAddOp3().

◆ mallocWithAlarm()

static void mallocWithAlarm ( int n,
void ** pp )
static

Definition at line 27541 of file sqlite3.c.

27546 {
27547 void *p;
27548 int nFull;
27549 assert( sqlite3_mutex_held(mem0.mutex) );
27550 assert( n>0 );
27551
27552 /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
27553 ** implementation of malloc_good_size(), which must be called in debug
27554 ** mode and specifically when the DMD "Dark Matter Detector" is enabled
27555 ** or else a crash results. Hence, do not attempt to optimize out the
27556 ** following xRoundup() call. */
27557 nFull = sqlite3GlobalConfig.m.xRoundup(n);
27558
27560 if( mem0.alarmThreshold>0 ){
27562 if( nUsed >= mem0.alarmThreshold - nFull ){
27563 AtomicStore(&mem0.nearlyFull, 1);
27564 sqlite3MallocAlarm(nFull);
27565 if( mem0.hardLimit ){
27567 if( nUsed >= mem0.hardLimit - nFull ){
27568 *pp = 0;
27569 return;
27570 }
27571 }
27572 }else{
27573 AtomicStore(&mem0.nearlyFull, 0);
27574 }
27575 }
27576 p = sqlite3GlobalConfig.m.xMalloc(nFull);
27577#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
27578 if( p==0 && mem0.alarmThreshold>0 ){
27579 sqlite3MallocAlarm(nFull);
27580 p = sqlite3GlobalConfig.m.xMalloc(nFull);
27581 }
27582#endif
27583 if( p ){
27584 nFull = sqlite3MallocSize(p);
#define SQLITE_STATUS_MALLOC_SIZE
Definition sqlite3.c:9055
#define mem0
Definition sqlite3.c:27369
SQLITE_PRIVATE void sqlite3StatusHighwater(int, int)
Definition sqlite3.c:21427
SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int)
Definition sqlite3.c:21382
#define AtomicStore(PTR, VAL)
Definition sqlite3.c:13477
#define SQLITE_STATUS_MEMORY_USED
Definition sqlite3.c:9050
static void sqlite3MallocAlarm(int nByte)
Definition sqlite3.c:27530

References AtomicStore, mem0, sqlite3_mutex_held(), sqlite3GlobalConfig, sqlite3MallocAlarm(), sqlite3MallocSize(), sqlite3StatusHighwater(), sqlite3StatusUp(), sqlite3StatusValue(), SQLITE_STATUS_MALLOC_COUNT, SQLITE_STATUS_MALLOC_SIZE, and SQLITE_STATUS_MEMORY_USED.

Referenced by sqlite3Malloc().

◆ markTermAsChild()

static void markTermAsChild ( WhereClause * pWC,
int iChild,
int iParent )
static

Definition at line 144451 of file sqlite3.c.

Referenced by exprAnalyze(), and exprAnalyzeOrTerm().

◆ matchQuality()

static int matchQuality ( FuncDef * p,
int nArg,
u8 enc )
static

Definition at line 115834 of file sqlite3.c.

115844 {
115845 int match;
115846 assert( p->nArg>=-1 );
115847
115848 /* Wrong number of arguments means "no match" */
115849 if( p->nArg!=nArg ){
115850 if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
115851 if( p->nArg>=0 ) return 0;
115852 }
115853
115854 /* Give a better score to a function with a specific number of arguments
115855 ** than to function that accepts any number of arguments. */
115856 if( p->nArg==nArg ){
115857 match = 4;
115858 }else{
115859 match = 1;
115860 }
115861
115862 /* Bonus points if the text encoding matches */
115863 if( enc==(p->funcFlags & SQLITE_FUNC_ENCMASK) ){
115864 match += 2; /* Exact encoding match */
static const char * match(MatchState *ms, const char *s, const char *p)
#define SQLITE_FUNC_ENCMASK
Definition sqlite3.c:17145
#define FUNC_PERFECT_MATCH
Definition sqlite3.c:115833
void(* xSFunc)(sqlite3_context *, int, sqlite3_value **)
Definition sqlite3.c:17099
u32 funcFlags
Definition sqlite3.c:17096

References FUNC_PERFECT_MATCH, FuncDef::funcFlags, match(), FuncDef::nArg, SQLITE_FUNC_ENCMASK, and FuncDef::xSFunc.

Referenced by sqlite3FindFunction().

◆ measureAllocationSize()

static SQLITE_NOINLINE void measureAllocationSize ( sqlite3 * db,
void * p )
static

Definition at line 27711 of file sqlite3.c.

References sqlite3::pnBytesFreed, and sqlite3DbMallocSize().

Referenced by sqlite3DbFreeNN().

◆ memIntValue()

static SQLITE_NOINLINE i64 memIntValue ( Mem * pMem)
static

Definition at line 76411 of file sqlite3.c.

◆ memjrnlClose()

static int memjrnlClose ( sqlite3_file * pJfd)
static

Definition at line 97349 of file sqlite3.c.

◆ memjrnlCreateFile()

static int memjrnlCreateFile ( MemJournal * p)
static

Definition at line 97215 of file sqlite3.c.

97221 {
97222 int rc;
97223 sqlite3_file *pReal = (sqlite3_file*)p;
97224 MemJournal copy = *p;
97225
97226 memset(p, 0, sizeof(MemJournal));
97227 rc = sqlite3OsOpen(copy.pVfs, copy.zJournal, pReal, copy.flags, 0);
97228 if( rc==SQLITE_OK ){
97229 int nChunk = copy.nChunkSize;
97230 i64 iOff = 0;
97231 FileChunk *pIter;
97232 for(pIter=copy.pFirst; pIter; pIter=pIter->pNext){
97233 if( iOff + nChunk > copy.endpoint.iOffset ){
97234 nChunk = copy.endpoint.iOffset - iOff;
97235 }
97236 rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nChunk, iOff);
97237 if( rc ) break;
97238 iOff += nChunk;
97239 }
97240 if( rc==SQLITE_OK ){
97241 /* No error has occurred. Free the in-memory buffers. */
97242 memjrnlFreeChunks(&copy);
97243 }
97244 }
97245 if( rc!=SQLITE_OK ){
97246 /* If an error occurred while creating or writing to the file, restore
97247 ** the original before returning. This way, SQLite uses the in-memory
97248 ** journal data to roll back changes made to the internal page-cache
SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file *, const void *, int amt, i64 offset)
Definition sqlite3.c:23053
static void memjrnlFreeChunks(MemJournal *p)
Definition sqlite3.c:97202
u8 zChunk[8]
Definition sqlite3.c:97109
FileChunk * pNext
Definition sqlite3.c:97108
sqlite3_int64 iOffset
Definition sqlite3.c:97128
int nChunkSize
Definition sqlite3.c:97138
sqlite3_vfs * pVfs
Definition sqlite3.c:97147
const char * zJournal
Definition sqlite3.c:97148
FilePoint endpoint
Definition sqlite3.c:97143
FileChunk * pFirst
Definition sqlite3.c:97142

◆ memjrnlFileSize()

static int memjrnlFileSize ( sqlite3_file * pJfd,
sqlite_int64 * pSize )
static

Definition at line 97369 of file sqlite3.c.

◆ memjrnlFreeChunks()

static void memjrnlFreeChunks ( MemJournal * p)
static

Definition at line 97202 of file sqlite3.c.

97208 {
97209 FileChunk *pIter;
97210 FileChunk *pNext;

Referenced by memjrnlTruncate().

◆ memjrnlRead()

static int memjrnlRead ( sqlite3_file * pJfd,
void * zBuf,
int iAmt,
sqlite_int64 iOfst )
static

Definition at line 97155 of file sqlite3.c.

97166 {
97167 MemJournal *p = (MemJournal *)pJfd;
97168 u8 *zOut = zBuf;
97169 int nRead = iAmt;
97170 int iChunkOffset;
97171 FileChunk *pChunk;
97172
97173 if( (iAmt+iOfst)>p->endpoint.iOffset ){
97175 }
97176 assert( p->readpoint.iOffset==0 || p->readpoint.pChunk!=0 );
97177 if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
97178 sqlite3_int64 iOff = 0;
97179 for(pChunk=p->pFirst;
97180 ALWAYS(pChunk) && (iOff+p->nChunkSize)<=iOfst;
97181 pChunk=pChunk->pNext
97182 ){
97183 iOff += p->nChunkSize;
97184 }
97185 }else{
97186 pChunk = p->readpoint.pChunk;
97187 assert( pChunk!=0 );
97188 }
97189
97190 iChunkOffset = (int)(iOfst%p->nChunkSize);
97191 do {
97192 int iSpace = p->nChunkSize - iChunkOffset;
97193 int nCopy = MIN(nRead, (p->nChunkSize - iChunkOffset));
97194 memcpy(zOut, (u8*)pChunk->zChunk + iChunkOffset, nCopy);
97195 zOut += nCopy;
97196 nRead -= iSpace;
97197 iChunkOffset = 0;
FileChunk * pChunk
Definition sqlite3.c:97129
FilePoint readpoint
Definition sqlite3.c:97144

◆ memjrnlSync()

static int memjrnlSync ( sqlite3_file * pJfd,
int flags )
static

Definition at line 97361 of file sqlite3.c.

References UNUSED_PARAMETER2.

◆ memjrnlTruncate()

static int memjrnlTruncate ( sqlite3_file * pJfd,
sqlite_int64 size )
static

Definition at line 97333 of file sqlite3.c.

97339 {
97340 MemJournal *p = (MemJournal *)pJfd;
97341 if( ALWAYS(size==0) ){
97343 p->nSize = 0;
97344 p->endpoint.pChunk = 0;

References ALWAYS, MemJournal::endpoint, FilePoint::iOffset, memjrnlFreeChunks(), MemJournal::nSize, FilePoint::pChunk, and MemJournal::readpoint.

◆ memjrnlWrite()

static int memjrnlWrite ( sqlite3_file * pJfd,
const void * zBuf,
int iAmt,
sqlite_int64 iOfst )
static

Definition at line 97254 of file sqlite3.c.

97265 {
97266 MemJournal *p = (MemJournal *)pJfd;
97267 int nWrite = iAmt;
97268 u8 *zWrite = (u8 *)zBuf;
97269
97270 /* If the file should be created now, create it and write the new data
97271 ** into the file on disk. */
97272 if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){
97273 int rc = memjrnlCreateFile(p);
97274 if( rc==SQLITE_OK ){
97275 rc = sqlite3OsWrite(pJfd, zBuf, iAmt, iOfst);
97276 }
97277 return rc;
97278 }
97279
97280 /* If the contents of this write should be stored in memory */
97281 else{
97282 /* An in-memory journal file should only ever be appended to. Random
97283 ** access writes are not required. The only exception to this is when
97284 ** the in-memory journal is being used by a connection using the
97285 ** atomic-write optimization. In this case the first 28 bytes of the
97286 ** journal file may be written as part of committing the transaction. */
97287 assert( iOfst==p->endpoint.iOffset || iOfst==0 );
97288#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
97289 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
97290 if( iOfst==0 && p->pFirst ){
97291 assert( p->nChunkSize>iAmt );
97292 memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
97293 }else
97294#else
97295 assert( iOfst>0 || p->pFirst==0 );
97296#endif
97297 {
97298 while( nWrite>0 ){
97299 FileChunk *pChunk = p->endpoint.pChunk;
97300 int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize);
97301 int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset);
97302
97303 if( iChunkOffset==0 ){
97304 /* New chunk is required to extend the file. */
97306 if( !pNew ){
97308 }
97309 pNew->pNext = 0;
97310 if( pChunk ){
97311 assert( p->pFirst );
97312 pChunk->pNext = pNew;
97313 }else{
97314 assert( !p->pFirst );
97315 p->pFirst = pNew;
97316 }
97317 p->endpoint.pChunk = pNew;
97318 }
97319
97320 memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace);
97321 zWrite += iSpace;
97322 nWrite -= iSpace;
97323 p->endpoint.iOffset += iSpace;
97324 }
static int memjrnlCreateFile(MemJournal *p)
Definition sqlite3.c:97215
#define fileChunkSize(nChunkSize)
Definition sqlite3.c:97121
SQLITE_API void * sqlite3_malloc(int)
Definition sqlite3.c:27615
#define SQLITE_IOERR_NOMEM_BKPT
Definition sqlite3.c:19277

◆ memRealValue()

static SQLITE_NOINLINE double memRealValue ( Mem * pMem)
static

Definition at line 76439 of file sqlite3.c.

◆ minMaxFinalize()

static void minMaxFinalize ( sqlite3_context * context)
static

Definition at line 118754 of file sqlite3.c.

118754 {
118755 minMaxValueFinalize(context, 1);
118756}
static void minMaxValueFinalize(sqlite3_context *context, int bValue)
Definition sqlite3.c:118737

References minMaxValueFinalize().

Referenced by sqlite3RegisterBuiltinFunctions().

◆ minmaxFunc()

static void minmaxFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117093 of file sqlite3.c.

117103 {
117104 int i;
117105 int mask; /* 0 for min() or 0xffffffff for max() */
117106 int iBest;
117107 CollSeq *pColl;
117108
117109 assert( argc>1 );
117110 mask = sqlite3_user_data(context)==0 ? 0 : -1;
117111 pColl = sqlite3GetFuncCollSeq(context);
117112 assert( pColl );
117113 assert( mask==-1 || mask==0 );
117114 iBest = 0;
117115 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
117116 for(i=1; i<argc; i++){
117117 if( sqlite3_value_type(argv[i])==SQLITE_NULL ) return;
117118 if( (sqlite3MemCompare(argv[iBest], argv[i], pColl)^mask)>=0 ){
static CollSeq * sqlite3GetFuncCollSeq(sqlite3_context *context)
Definition sqlite3.c:117071

Referenced by sqlite3RegisterBuiltinFunctions().

◆ minMaxQuery()

static u8 minMaxQuery ( sqlite3 * db,
Expr * pFunc,
ExprList ** ppMinMax )
static

Definition at line 133819 of file sqlite3.c.

133825 {
133826 int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
133827 ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */
133828 const char *zFunc; /* Name of aggregate function pFunc */
133829 ExprList *pOrderBy;
133830 u8 sortFlags = 0;
133831
133832 assert( *ppMinMax==0 );
133833 assert( pFunc->op==TK_AGG_FUNCTION );
133834 assert( !IsWindowFunc(pFunc) );
133835 if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){
133836 return eRet;
133837 }
133838 zFunc = pFunc->u.zToken;
133839 if( sqlite3StrICmp(zFunc, "min")==0 ){
133840 eRet = WHERE_ORDERBY_MIN;
133841 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
133842 sortFlags = KEYINFO_ORDER_BIGNULL;
133843 }
133844 }else if( sqlite3StrICmp(zFunc, "max")==0 ){
133845 eRet = WHERE_ORDERBY_MAX;
133846 sortFlags = KEYINFO_ORDER_DESC;
133847 }else{
133848 return eRet;
#define IsWindowFunc(p)
Definition sqlite3.c:18152
#define WHERE_ORDERBY_MAX
Definition sqlite3.c:18305
#define WHERE_ORDERBY_MIN
Definition sqlite3.c:18304
#define KEYINFO_ORDER_DESC
Definition sqlite3.c:17692
#define WHERE_ORDERBY_NORMAL
Definition sqlite3.c:18303

References ExprList::a, EP_WinFunc, ExprHasProperty, IsWindowFunc, KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, sqlite3::mallocFailed, ExprList::nExpr, Expr::op, ExprList::ExprList_item::pExpr, Expr::pList, ExprList::ExprList_item::sortFlags, sqlite3ExprCanBeNull(), sqlite3ExprListDup(), sqlite3StrICmp(), TK_AGG_FUNCTION, Expr::u, WHERE_ORDERBY_MAX, WHERE_ORDERBY_MIN, WHERE_ORDERBY_NORMAL, Expr::x, and Expr::zToken.

Referenced by sqlite3Select().

◆ minmaxStep()

static void minmaxStep ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 118699 of file sqlite3.c.

118709 {
118710 Mem *pArg = (Mem *)argv[0];
118711 Mem *pBest;
118712 UNUSED_PARAMETER(NotUsed);
118713
118714 pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
118715 if( !pBest ) return;
118716
118717 if( sqlite3_value_type(pArg)==SQLITE_NULL ){
118718 if( pBest->flags ) sqlite3SkipAccumulatorLoad(context);
118719 }else if( pBest->flags ){
118720 int max;
118721 int cmp;
118722 CollSeq *pColl = sqlite3GetFuncCollSeq(context);
118723 /* This step function is used for both the min() and max() aggregates,
118724 ** the only difference between the two being that the sense of the
118725 ** comparison is inverted. For the max() aggregate, the
118726 ** sqlite3_user_data() function returns (void *)-1. For min() it
118727 ** returns (void *)db, where db is the sqlite3* database pointer.
118728 ** Therefore the next statement sets variable 'max' to 1 for the max()
118729 ** aggregate, or 0 for min().
118730 */
118731 max = sqlite3_user_data(context)!=0;
118732 cmp = sqlite3MemCompare(pBest, pArg, pColl);
118733 if( (max && cmp<0) || (!max && cmp>0) ){
118734 sqlite3VdbeMemCopy(pBest, pArg);
118735 }else{
SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *, const Mem *)
Definition sqlite3.c:76843
static void sqlite3SkipAccumulatorLoad(sqlite3_context *context)
Definition sqlite3.c:117084

References sqlite3_value::flags, sqlite3_aggregate_context(), sqlite3_user_data(), sqlite3_value_type(), sqlite3GetFuncCollSeq(), sqlite3MemCompare(), sqlite3SkipAccumulatorLoad(), sqlite3VdbeMemCopy(), SQLITE_NULL, and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ minMaxValue()

static void minMaxValue ( sqlite3_context * context)
static

Definition at line 118748 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ minMaxValueFinalize()

static void minMaxValueFinalize ( sqlite3_context * context,
int bValue )
static

Definition at line 118737 of file sqlite3.c.

118738 {
118739 pBest->db = sqlite3_context_db_handle(context);
118740 sqlite3VdbeMemCopy(pBest, pArg);
118741 }
118742}
118743static void minMaxValueFinalize(sqlite3_context *context, int bValue){
118744 sqlite3_value *pRes;
118745 pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
118746 if( pRes ){

Referenced by minMaxFinalize().

◆ mkFullPathname()

static int mkFullPathname ( const char * zPath,
char * zOut,
int nOut )
static

Definition at line 39847 of file sqlite3.c.

39857 {
39858 int nPath = sqlite3Strlen30(zPath);
39859 int iOff = 0;
39860 if( zPath[0]!='/' ){
39861 if( osGetcwd(zOut, nOut-2)==0 ){
39862 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
39863 }
39864 iOff = sqlite3Strlen30(zOut);
39865 zOut[iOff++] = '/';
39866 }
39867 if( (iOff+nPath+1)>nOut ){
39868 /* SQLite assumes that xFullPathname() nul-terminates the output buffer
39869 ** even if it returns an error. */
#define osGetcwd
#define SQLITE_CANTOPEN_BKPT
Definition sqlite3.c:19269

Referenced by unixFullPathname().

◆ modifyPagePointer()

static int modifyPagePointer ( MemPage * pPage,
Pgno iFrom,
Pgno iTo,
u8 eType )
static

Definition at line 68075 of file sqlite3.c.

68075 : pPage is a btree-page. The pointer points at an overflow
68076** page pointed to by one of the cells on pPage.
68077**
68078** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
68079** overflow page in the list.
68080*/
68081static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
68082 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68083 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
68084 if( eType==PTRMAP_OVERFLOW2 ){
68085 /* The pointer is always the first 4 bytes of the page in this case. */
68086 if( get4byte(pPage->aData)!=iFrom ){
68087 return SQLITE_CORRUPT_PAGE(pPage);
68088 }
68089 put4byte(pPage->aData, iTo);
68090 }else{
68091 int i;
68092 int nCell;
68093 int rc;
68094
68095 rc = pPage->isInit ? SQLITE_OK : btreeInitPage(pPage);
68096 if( rc ) return rc;
68097 nCell = pPage->nCell;
68098
68099 for(i=0; i<nCell; i++){
68100 u8 *pCell = findCell(pPage, i);
68101 if( eType==PTRMAP_OVERFLOW1 ){
68102 CellInfo info;
68103 pPage->xParseCell(pPage, pCell, &info);
68104 if( info.nLocal<info.nPayload ){
68105 if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
68106 return SQLITE_CORRUPT_PAGE(pPage);
68107 }
68108 if( iFrom==get4byte(pCell+info.nSize-4) ){
68109 put4byte(pCell+info.nSize-4, iTo);
68110 break;
68111 }
68112 }
68113 }else{
68114 if( get4byte(pCell)==iFrom ){
68115 put4byte(pCell, iTo);
68116 break;
68117 }
68118 }
68119 }
68120
68121 if( i==nCell ){
68122 if( eType!=PTRMAP_BTREE ||
68123 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
68124 return SQLITE_CORRUPT_PAGE(pPage);
static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType)
Definition sqlite3.c:68075

References MemPage::aData, btreeInitPage(), eType, findCell, get4byte, MemPage::hdrOffset, MemPage::isInit, BtShared::mutex, MemPage::nCell, CellInfo::nLocal, CellInfo::nPayload, CellInfo::nSize, MemPage::pBt, MemPage::pDbPage, PTRMAP_BTREE, PTRMAP_OVERFLOW1, PTRMAP_OVERFLOW2, put4byte, sqlite3_mutex_held(), SQLITE_CORRUPT_PAGE, SQLITE_OK, BtShared::usableSize, and MemPage::xParseCell.

Referenced by relocatePage().

◆ moveToChild()

static int moveToChild ( BtCursor * pCur,
u32 newPgno )
static

Definition at line 69571 of file sqlite3.c.

69577 {
69578 BtShared *pBt = pCur->pBt;
69579
69580 assert( cursorOwnsBtShared(pCur) );
69581 assert( pCur->eState==CURSOR_VALID );
69582 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
69583 assert( pCur->iPage>=0 );
69584 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
69585 return SQLITE_CORRUPT_BKPT;
69586 }
69587 pCur->info.nSize = 0;
#define BTCURSOR_MAX_DEPTH
Definition sqlite3.c:63947

References BtCursor::aiIdx, BtCursor::apPage, BTCF_ValidNKey, BTCF_ValidOvfl, BTCURSOR_MAX_DEPTH, BtCursor::curFlags, BtCursor::curPagerFlags, CURSOR_VALID, BtCursor::eState, getAndInitPage(), BtCursor::info, BtCursor::iPage, BtCursor::ix, CellInfo::nSize, BtCursor::pBt, BtCursor::pPage, and SQLITE_CORRUPT_BKPT.

Referenced by btreeNext(), btreePrevious(), moveToLeftmost(), moveToRightmost(), moveToRoot(), sqlite3BtreeCount(), and sqlite3BtreeMovetoUnpacked().

◆ moveToLeftmost()

static int moveToLeftmost ( BtCursor * pCur)
static

Definition at line 69748 of file sqlite3.c.

69754 {
69755 Pgno pgno;
69756 int rc = SQLITE_OK;
69757 MemPage *pPage;
69758
69759 assert( cursorOwnsBtShared(pCur) );
69760 assert( pCur->eState==CURSOR_VALID );
69761 while( rc==SQLITE_OK && !(pPage = pCur->pPage)->leaf ){

References CURSOR_VALID, BtCursor::eState, findCell, get4byte, BtCursor::ix, moveToChild(), MemPage::nCell, BtCursor::pPage, and SQLITE_OK.

Referenced by btreeNext().

◆ moveToParent()

static void moveToParent ( BtCursor * pCur)
static

Definition at line 69620 of file sqlite3.c.

69626 {
69627 MemPage *pLeaf;
69628 assert( cursorOwnsBtShared(pCur) );
69629 assert( pCur->eState==CURSOR_VALID );
69630 assert( pCur->iPage>0 );
69631 assert( pCur->pPage );
69633 pCur->apPage[pCur->iPage-1],
69634 pCur->aiIdx[pCur->iPage-1],
69635 pCur->pPage->pgno
69636 );
69637 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
69638 pCur->info.nSize = 0;
#define assertParentIndex(x, y, z)
Definition sqlite3.c:69609

References BtCursor::aiIdx, BtCursor::apPage, assertParentIndex, BTCF_ValidNKey, BTCF_ValidOvfl, BtCursor::curFlags, CURSOR_VALID, BtCursor::eState, BtCursor::info, BtCursor::iPage, BtCursor::ix, MemPage::nCell, CellInfo::nSize, MemPage::pgno, BtCursor::pPage, releasePageNotNull(), and testcase.

Referenced by btreeNext(), btreePrevious(), and sqlite3BtreeCount().

◆ moveToRightmost()

static int moveToRightmost ( BtCursor * pCur)
static

Definition at line 69773 of file sqlite3.c.

69779 {
69780 Pgno pgno;
69781 int rc = SQLITE_OK;
69782 MemPage *pPage = 0;
69783
69784 assert( cursorOwnsBtShared(pCur) );
69785 assert( pCur->eState==CURSOR_VALID );
69786 while( !(pPage = pCur->pPage)->leaf ){
69787 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
69788 pCur->ix = pPage->nCell;
69789 rc = moveToChild(pCur, pgno);
69790 if( rc ) return rc;

References MemPage::aData, BTCF_ValidNKey, BtCursor::curFlags, CURSOR_VALID, BtCursor::eState, get4byte, MemPage::hdrOffset, BtCursor::info, BtCursor::ix, moveToChild(), MemPage::nCell, CellInfo::nSize, BtCursor::pPage, and SQLITE_OK.

Referenced by btreePrevious().

◆ moveToRoot()

static int moveToRoot ( BtCursor * pCur)
static

Definition at line 69661 of file sqlite3.c.

69667 {
69668 MemPage *pRoot;
69669 int rc = SQLITE_OK;
69670
69671 assert( cursorOwnsBtShared(pCur) );
69673 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
69674 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
69675 assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
69676 assert( pCur->pgnoRoot>0 || pCur->iPage<0 );
69677
69678 if( pCur->iPage>=0 ){
69679 if( pCur->iPage ){
69681 while( --pCur->iPage ){
69682 releasePageNotNull(pCur->apPage[pCur->iPage]);
69683 }
69684 pCur->pPage = pCur->apPage[0];
69685 goto skip_init;
69686 }
69687 }else if( pCur->pgnoRoot==0 ){
69688 pCur->eState = CURSOR_INVALID;
69689 return SQLITE_EMPTY;
69690 }else{
69691 assert( pCur->iPage==(-1) );
69692 if( pCur->eState>=CURSOR_REQUIRESEEK ){
69693 if( pCur->eState==CURSOR_FAULT ){
69694 assert( pCur->skipNext!=SQLITE_OK );
69695 return pCur->skipNext;
69696 }
69698 }
69699 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
69700 0, pCur->curPagerFlags);
69701 if( rc!=SQLITE_OK ){
69702 pCur->eState = CURSOR_INVALID;
69703 return rc;
69704 }
69705 pCur->iPage = 0;
69706 pCur->curIntKey = pCur->pPage->intKey;
69707 }
69708 pRoot = pCur->pPage;
69709 assert( pRoot->pgno==pCur->pgnoRoot );
69710
69711 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
69712 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
69713 ** NULL, the caller expects a table b-tree. If this is not the case,
69714 ** return an SQLITE_CORRUPT error.
69715 **
69716 ** Earlier versions of SQLite assumed that this test could not fail
69717 ** if the root page was already loaded when this function was called (i.e.
69718 ** if pCur->iPage>=0). But this is not so if the database is corrupted
69719 ** in such a way that page pRoot is linked into a second b-tree table
69720 ** (or the freelist). */
69721 assert( pRoot->intKey==1 || pRoot->intKey==0 );
69722 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
69723 return SQLITE_CORRUPT_PAGE(pCur->pPage);
69724 }
69725
69726skip_init:
69727 pCur->ix = 0;
69728 pCur->info.nSize = 0;
69730
69731 pRoot = pCur->pPage;
69732 if( pRoot->nCell>0 ){
69733 pCur->eState = CURSOR_VALID;
69734 }else if( !pRoot->leaf ){
69735 Pgno subpage;
69736 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
69737 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
69738 pCur->eState = CURSOR_VALID;
69739 rc = moveToChild(pCur, subpage);
static void releasePageNotNull(MemPage *pPage)
Definition sqlite3.c:66698
SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *)
Definition sqlite3.c:65266
#define SQLITE_EMPTY
Definition sqlite3.c:1486

References MemPage::aData, BtCursor::apPage, BTCF_AtLast, BTCF_ValidNKey, BTCF_ValidOvfl, BtCursor::curFlags, BtCursor::curIntKey, BtCursor::curPagerFlags, CURSOR_FAULT, CURSOR_INVALID, CURSOR_REQUIRESEEK, CURSOR_VALID, BtCursor::eState, get4byte, getAndInitPage(), MemPage::hdrOffset, BtCursor::info, MemPage::intKey, BtCursor::iPage, MemPage::isInit, BtCursor::ix, MemPage::leaf, moveToChild(), MemPage::nCell, CellInfo::nSize, Btree::pBt, BtCursor::pBtree, MemPage::pgno, BtCursor::pgnoRoot, BtCursor::pKeyInfo, BtCursor::pPage, releasePageNotNull(), BtCursor::skipNext, sqlite3BtreeClearCursor(), SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_PAGE, SQLITE_EMPTY, and SQLITE_OK.

Referenced by sqlite3BtreeCount(), sqlite3BtreeDelete(), and sqlite3BtreeMovetoUnpacked().

◆ multiSelect()

static int multiSelect ( Parse * pParse,
Select * p,
SelectDest * pDest )
static

Definition at line 131852 of file sqlite3.c.

131862 {
131863 int rc = SQLITE_OK; /* Success code from a subroutine */
131864 Select *pPrior; /* Another SELECT immediately to our left */
131865 Vdbe *v; /* Generate code to this VDBE */
131866 SelectDest dest; /* Alternative data destination */
131867 Select *pDelete = 0; /* Chain of simple selects to delete */
131868 sqlite3 *db; /* Database connection */
131869
131870 /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only
131871 ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
131872 */
131873 assert( p && p->pPrior ); /* Calling function guarantees this much */
131874 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
131875 assert( p->selFlags & SF_Compound );
131876 db = pParse->db;
131877 pPrior = p->pPrior;
131878 dest = *pDest;
131879 if( pPrior->pOrderBy || pPrior->pLimit ){
131880 sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
131881 pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op));
131882 rc = 1;
131883 goto multi_select_end;
131884 }
131885
131886 v = sqlite3GetVdbe(pParse);
131887 assert( v!=0 ); /* The VDBE already created by calling function */
131888
131889 /* Create the destination temporary table if necessary
131890 */
131891 if( dest.eDest==SRT_EphemTab ){
131892 assert( p->pEList );
131894 dest.eDest = SRT_Table;
131895 }
131896
131897 /* Special handling for a compound-select that originates as a VALUES clause.
131898 */
131899 if( p->selFlags & SF_MultiValue ){
131900 rc = multiSelectValues(pParse, p, &dest);
131901 if( rc>=0 ) goto multi_select_end;
131902 rc = SQLITE_OK;
131903 }
131904
131905 /* Make sure all SELECTs in the statement have the same number of elements
131906 ** in their result sets.
131907 */
131908 assert( p->pEList && pPrior->pEList );
131909 assert( p->pEList->nExpr==pPrior->pEList->nExpr );
131910
131911#ifndef SQLITE_OMIT_CTE
131912 if( p->selFlags & SF_Recursive ){
131913 generateWithRecursiveQuery(pParse, p, &dest);
131914 }else
131915#endif
131916
131917 /* Compound SELECTs that have an ORDER BY clause are handled separately.
131918 */
131919 if( p->pOrderBy ){
131920 return multiSelectOrderBy(pParse, p, pDest);
131921 }else{
131922
131923#ifndef SQLITE_OMIT_EXPLAIN
131924 if( pPrior->pPrior==0 ){
131925 ExplainQueryPlan((pParse, 1, "COMPOUND QUERY"));
131926 ExplainQueryPlan((pParse, 1, "LEFT-MOST SUBQUERY"));
131927 }
131928#endif
131929
131930 /* Generate code for the left and right SELECT statements.
131931 */
131932 switch( p->op ){
131933 case TK_ALL: {
131934 int addr = 0;
131935 int nLimit;
131936 assert( !pPrior->pLimit );
131937 pPrior->iLimit = p->iLimit;
131938 pPrior->iOffset = p->iOffset;
131939 pPrior->pLimit = p->pLimit;
131940 rc = sqlite3Select(pParse, pPrior, &dest);
131941 p->pLimit = 0;
131942 if( rc ){
131943 goto multi_select_end;
131944 }
131945 p->pPrior = 0;
131946 p->iLimit = pPrior->iLimit;
131947 p->iOffset = pPrior->iOffset;
131948 if( p->iLimit ){
131949 addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v);
131950 VdbeComment((v, "Jump ahead if LIMIT reached"));
131951 if( p->iOffset ){
131953 p->iLimit, p->iOffset+1, p->iOffset);
131954 }
131955 }
131956 ExplainQueryPlan((pParse, 1, "UNION ALL"));
131957 rc = sqlite3Select(pParse, p, &dest);
131958 testcase( rc!=SQLITE_OK );
131959 pDelete = p->pPrior;
131960 p->pPrior = pPrior;
131962 if( pPrior->pLimit
131963 && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit)
131964 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
131965 ){
131966 p->nSelectRow = sqlite3LogEst((u64)nLimit);
131967 }
131968 if( addr ){
131969 sqlite3VdbeJumpHere(v, addr);
131970 }
131971 break;
131972 }
131973 case TK_EXCEPT:
131974 case TK_UNION: {
131975 int unionTab; /* Cursor number of the temp table holding result */
131976 u8 op = 0; /* One of the SRT_ operations to apply to self */
131977 int priorOp; /* The SRT_ operation to apply to prior selects */
131978 Expr *pLimit; /* Saved values of p->nLimit */
131979 int addr;
131980 SelectDest uniondest;
131981
131982 testcase( p->op==TK_EXCEPT );
131983 testcase( p->op==TK_UNION );
131984 priorOp = SRT_Union;
131985 if( dest.eDest==priorOp ){
131986 /* We can reuse a temporary table generated by a SELECT to our
131987 ** right.
131988 */
131989 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
131990 unionTab = dest.iSDParm;
131991 }else{
131992 /* We will need to create our own temporary table to hold the
131993 ** intermediate results.
131994 */
131995 unionTab = pParse->nTab++;
131996 assert( p->pOrderBy==0 );
131997 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
131998 assert( p->addrOpenEphm[0] == -1 );
131999 p->addrOpenEphm[0] = addr;
132001 assert( p->pEList );
132002 }
132003
132004 /* Code the SELECT statements to our left
132005 */
132006 assert( !pPrior->pOrderBy );
132007 sqlite3SelectDestInit(&uniondest, priorOp, unionTab);
132008 rc = sqlite3Select(pParse, pPrior, &uniondest);
132009 if( rc ){
132010 goto multi_select_end;
132011 }
132012
132013 /* Code the current SELECT statement
132014 */
132015 if( p->op==TK_EXCEPT ){
132016 op = SRT_Except;
132017 }else{
132018 assert( p->op==TK_UNION );
132019 op = SRT_Union;
132020 }
132021 p->pPrior = 0;
132022 pLimit = p->pLimit;
132023 p->pLimit = 0;
132024 uniondest.eDest = op;
132025 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
132026 selectOpName(p->op)));
132027 rc = sqlite3Select(pParse, p, &uniondest);
132028 testcase( rc!=SQLITE_OK );
132029 assert( p->pOrderBy==0 );
132030 pDelete = p->pPrior;
132031 p->pPrior = pPrior;
132032 p->pOrderBy = 0;
132033 if( p->op==TK_UNION ){
132035 }
132036 sqlite3ExprDelete(db, p->pLimit);
132037 p->pLimit = pLimit;
132038 p->iLimit = 0;
132039 p->iOffset = 0;
132040
132041 /* Convert the data in the temporary table into whatever form
132042 ** it is that we currently need.
132043 */
132044 assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
132045 assert( p->pEList || db->mallocFailed );
132046 if( dest.eDest!=priorOp && db->mallocFailed==0 ){
132047 int iCont, iBreak, iStart;
132048 iBreak = sqlite3VdbeMakeLabel(pParse);
132049 iCont = sqlite3VdbeMakeLabel(pParse);
132050 computeLimitRegisters(pParse, p, iBreak);
132051 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
132052 iStart = sqlite3VdbeCurrentAddr(v);
132053 selectInnerLoop(pParse, p, unionTab,
132054 0, 0, &dest, iCont, iBreak);
132055 sqlite3VdbeResolveLabel(v, iCont);
132056 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
132057 sqlite3VdbeResolveLabel(v, iBreak);
132058 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
132059 }
132060 break;
132061 }
132062 default: assert( p->op==TK_INTERSECT ); {
132063 int tab1, tab2;
132064 int iCont, iBreak, iStart;
132065 Expr *pLimit;
132066 int addr;
132067 SelectDest intersectdest;
132068 int r1;
132069
132070 /* INTERSECT is different from the others since it requires
132071 ** two temporary tables. Hence it has its own case. Begin
132072 ** by allocating the tables we will need.
132073 */
132074 tab1 = pParse->nTab++;
132075 tab2 = pParse->nTab++;
132076 assert( p->pOrderBy==0 );
132077
132078 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
132079 assert( p->addrOpenEphm[0] == -1 );
132080 p->addrOpenEphm[0] = addr;
132082 assert( p->pEList );
132083
132084 /* Code the SELECTs to our left into temporary table "tab1".
132085 */
132086 sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
132087 rc = sqlite3Select(pParse, pPrior, &intersectdest);
132088 if( rc ){
132089 goto multi_select_end;
132090 }
132091
132092 /* Code the current SELECT into temporary table "tab2"
132093 */
132094 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
132095 assert( p->addrOpenEphm[1] == -1 );
132096 p->addrOpenEphm[1] = addr;
132097 p->pPrior = 0;
132098 pLimit = p->pLimit;
132099 p->pLimit = 0;
132100 intersectdest.iSDParm = tab2;
132101 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
132102 selectOpName(p->op)));
132103 rc = sqlite3Select(pParse, p, &intersectdest);
132104 testcase( rc!=SQLITE_OK );
132105 pDelete = p->pPrior;
132106 p->pPrior = pPrior;
132107 if( p->nSelectRow>pPrior->nSelectRow ){
132108 p->nSelectRow = pPrior->nSelectRow;
132109 }
132110 sqlite3ExprDelete(db, p->pLimit);
132111 p->pLimit = pLimit;
132112
132113 /* Generate code to take the intersection of the two temporary
132114 ** tables.
132115 */
132116 if( rc ) break;
132117 assert( p->pEList );
132118 iBreak = sqlite3VdbeMakeLabel(pParse);
132119 iCont = sqlite3VdbeMakeLabel(pParse);
132120 computeLimitRegisters(pParse, p, iBreak);
132121 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
132122 r1 = sqlite3GetTempReg(pParse);
132123 iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
132124 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
132125 VdbeCoverage(v);
132126 sqlite3ReleaseTempReg(pParse, r1);
132127 selectInnerLoop(pParse, p, tab1,
132128 0, 0, &dest, iCont, iBreak);
132129 sqlite3VdbeResolveLabel(v, iCont);
132130 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
132131 sqlite3VdbeResolveLabel(v, iBreak);
132132 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
132133 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
132134 break;
132135 }
132136 }
132137
132138 #ifndef SQLITE_OMIT_EXPLAIN
132139 if( p->pNext==0 ){
132140 ExplainQueryPlanPop(pParse);
132141 }
132142 #endif
132143 }
132144 if( pParse->nErr ) goto multi_select_end;
132145
132146 /* Compute collating sequences used by
132147 ** temporary tables needed to implement the compound select.
132148 ** Attach the KeyInfo structure to all temporary tables.
132149 **
132150 ** This section is run by the right-most SELECT statement only.
132151 ** SELECT statements to the left always skip this part. The right-most
132152 ** SELECT might also skip this part if it has no ORDER BY clause and
132153 ** no temp tables are required.
132154 */
132155 if( p->selFlags & SF_UsesEphemeral ){
132156 int i; /* Loop counter */
132157 KeyInfo *pKeyInfo; /* Collating sequence for the result set */
132158 Select *pLoop; /* For looping through SELECT statements */
132159 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
132160 int nCol; /* Number of columns in result set */
132161
132162 assert( p->pNext==0 );
132163 nCol = p->pEList->nExpr;
132164 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
132165 if( !pKeyInfo ){
132166 rc = SQLITE_NOMEM_BKPT;
132167 goto multi_select_end;
132168 }
132169 for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
132170 *apColl = multiSelectCollSeq(pParse, p, i);
132171 if( 0==*apColl ){
132172 *apColl = db->pDfltColl;
132173 }
132174 }
132175
132176 for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
132177 for(i=0; i<2; i++){
132178 int addr = pLoop->addrOpenEphm[i];
132179 if( addr<0 ){
132180 /* If [0] is unused then [1] is also unused. So we can
132181 ** always safely abort as soon as the first unused slot is found */
132182 assert( pLoop->addrOpenEphm[1]<0 );
132183 break;
132184 }
132185 sqlite3VdbeChangeP2(v, addr, nCol);
132186 sqlite3VdbeChangeP4(v, addr, (char*)sqlite3KeyInfoRef(pKeyInfo),
132187 P4_KEYINFO);
132188 pLoop->addrOpenEphm[i] = -1;
132189 }
132190 }
132191 sqlite3KeyInfoUnref(pKeyInfo);
132192 }
132193
static CollSeq * multiSelectCollSeq(Parse *pParse, Select *p, int iCol)
Definition sqlite3.c:131535
#define SF_MultiValue
Definition sqlite3.c:18481
#define TK_INTERSECT
Definition sqlite3.c:14077
#define SRT_Except
Definition sqlite3.c:18569
#define TK_EXCEPT
Definition sqlite3.c:14076
SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst, LogEst)
Definition sqlite3.c:32683
#define SRT_Union
Definition sqlite3.c:18568
static const char * selectOpName(int id)
Definition sqlite3.c:130679
static int multiSelectValues(Parse *pParse, Select *p, SelectDest *pDest)
Definition sqlite3.c:131789
#define ExplainQueryPlanPop(P)
Definition sqlite3.c:15831
#define OP_OffsetLimit
Definition sqlite3.c:15718
static void generateWithRecursiveQuery(Parse *pParse, Select *p, SelectDest *pDest)
Definition sqlite3.c:131627
SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoAlloc(sqlite3 *, int, int)
Definition sqlite3.c:130589
static Select * findRightmost(Select *p)
Definition sqlite3.c:129475
CollSeq * aColl[1]
Definition sqlite3.c:17686

References KeyInfo::aColl, Select::addrOpenEphm, computeLimitRegisters(), Parse::db, SelectDest::eDest, ExplainQueryPlan, ExplainQueryPlanPop, findRightmost(), generateWithRecursiveQuery(), Select::iLimit, Select::iOffset, SelectDest::iSDParm, SelectDest::iSdst, sqlite3::mallocFailed, multiSelectCollSeq(), multiSelectOrderBy(), multiSelectValues(), Parse::nErr, ExprList::nExpr, SelectDest::nSdst, Select::nSelectRow, Parse::nTab, Select::op, OP_Close, OP_IfNot, OP_Next, OP_NotFound, OP_OffsetLimit, OP_OpenEphemeral, OP_Rewind, OP_RowData, P4_KEYINFO, sqlite3::pDfltColl, Select::pEList, Expr::pLeft, Select::pLimit, Select::pNext, Select::pOrderBy, Select::pPrior, selectInnerLoop(), selectOpName(), Select::selFlags, SF_Compound, SF_MultiValue, SF_Recursive, SF_UsesEphemeral, sqlite3ErrorMsg(), sqlite3ExprDelete(), sqlite3ExprIsInteger(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3KeyInfoAlloc(), sqlite3KeyInfoRef(), sqlite3KeyInfoUnref(), sqlite3LogEst(), sqlite3LogEstAdd(), sqlite3ReleaseTempReg(), sqlite3Select(), sqlite3SelectDelete(), sqlite3SelectDestInit(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP2(), sqlite3VdbeChangeP4(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_NOMEM_BKPT, SQLITE_OK, SRT_EphemTab, SRT_Except, SRT_Table, SRT_Union, testcase, TK_ALL, TK_EXCEPT, TK_INTERSECT, TK_UNION, VdbeComment, and VdbeCoverage.

Referenced by sqlite3Select().

◆ multiSelectCollSeq()

static CollSeq * multiSelectCollSeq ( Parse * pParse,
Select * p,
int iCol )
static

Definition at line 131535 of file sqlite3.c.

131541 {
131542 CollSeq *pRet;
131543 if( p->pPrior ){
131544 pRet = multiSelectCollSeq(pParse, p->pPrior, iCol);
131545 }else{
131546 pRet = 0;
131547 }
131548 assert( iCol>=0 );
131549 /* iCol must be less than p->pEList->nExpr. Otherwise an error would
131550 ** have been thrown during name resolution and we would not have gotten

References ExprList::a, ALWAYS, multiSelectCollSeq(), ExprList::nExpr, Select::pEList, ExprList::ExprList_item::pExpr, Select::pPrior, and sqlite3ExprCollSeq().

Referenced by multiSelect(), multiSelectCollSeq(), multiSelectOrderBy(), and multiSelectOrderByKeyInfo().

◆ multiSelectOrderBy()

static int multiSelectOrderBy ( Parse * pParse,
Select * p,
SelectDest * pDest )
static

Definition at line 132439 of file sqlite3.c.

132449 {
132450 int i, j; /* Loop counters */
132451 Select *pPrior; /* Another SELECT immediately to our left */
132452 Vdbe *v; /* Generate code to this VDBE */
132453 SelectDest destA; /* Destination for coroutine A */
132454 SelectDest destB; /* Destination for coroutine B */
132455 int regAddrA; /* Address register for select-A coroutine */
132456 int regAddrB; /* Address register for select-B coroutine */
132457 int addrSelectA; /* Address of the select-A coroutine */
132458 int addrSelectB; /* Address of the select-B coroutine */
132459 int regOutA; /* Address register for the output-A subroutine */
132460 int regOutB; /* Address register for the output-B subroutine */
132461 int addrOutA; /* Address of the output-A subroutine */
132462 int addrOutB = 0; /* Address of the output-B subroutine */
132463 int addrEofA; /* Address of the select-A-exhausted subroutine */
132464 int addrEofA_noB; /* Alternate addrEofA if B is uninitialized */
132465 int addrEofB; /* Address of the select-B-exhausted subroutine */
132466 int addrAltB; /* Address of the A<B subroutine */
132467 int addrAeqB; /* Address of the A==B subroutine */
132468 int addrAgtB; /* Address of the A>B subroutine */
132469 int regLimitA; /* Limit register for select-A */
132470 int regLimitB; /* Limit register for select-A */
132471 int regPrev; /* A range of registers to hold previous output */
132472 int savedLimit; /* Saved value of p->iLimit */
132473 int savedOffset; /* Saved value of p->iOffset */
132474 int labelCmpr; /* Label for the start of the merge algorithm */
132475 int labelEnd; /* Label for the end of the overall SELECT stmt */
132476 int addr1; /* Jump instructions that get retargetted */
132477 int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
132478 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
132479 KeyInfo *pKeyMerge; /* Comparison information for merging rows */
132480 sqlite3 *db; /* Database connection */
132481 ExprList *pOrderBy; /* The ORDER BY clause */
132482 int nOrderBy; /* Number of terms in the ORDER BY clause */
132483 u32 *aPermute; /* Mapping from ORDER BY terms to result set columns */
132484
132485 assert( p->pOrderBy!=0 );
132486 assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
132487 db = pParse->db;
132488 v = pParse->pVdbe;
132489 assert( v!=0 ); /* Already thrown the error if VDBE alloc failed */
132490 labelEnd = sqlite3VdbeMakeLabel(pParse);
132491 labelCmpr = sqlite3VdbeMakeLabel(pParse);
132492
132493
132494 /* Patch up the ORDER BY clause
132495 */
132496 op = p->op;
132497 pPrior = p->pPrior;
132498 assert( pPrior->pOrderBy==0 );
132499 pOrderBy = p->pOrderBy;
132500 assert( pOrderBy );
132501 nOrderBy = pOrderBy->nExpr;
132502
132503 /* For operators other than UNION ALL we have to make sure that
132504 ** the ORDER BY clause covers every term of the result set. Add
132505 ** terms to the ORDER BY clause as necessary.
132506 */
132507 if( op!=TK_ALL ){
132508 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
132509 struct ExprList_item *pItem;
132510 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
132511 assert( pItem->u.x.iOrderByCol>0 );
132512 if( pItem->u.x.iOrderByCol==i ) break;
132513 }
132514 if( j==nOrderBy ){
132515 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
132516 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
132517 pNew->flags |= EP_IntValue;
132518 pNew->u.iValue = i;
132519 p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
132520 if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
132521 }
132522 }
132523 }
132524
132525 /* Compute the comparison permutation and keyinfo that is used with
132526 ** the permutation used to determine if the next
132527 ** row of results comes from selectA or selectB. Also add explicit
132528 ** collations to the ORDER BY clause terms so that when the subqueries
132529 ** to the right and the left are evaluated, they use the correct
132530 ** collation.
132531 */
132532 aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1));
132533 if( aPermute ){
132534 struct ExprList_item *pItem;
132535 aPermute[0] = nOrderBy;
132536 for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
132537 assert( pItem->u.x.iOrderByCol>0 );
132538 assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr );
132539 aPermute[i] = pItem->u.x.iOrderByCol - 1;
132540 }
132541 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
132542 }else{
132543 pKeyMerge = 0;
132544 }
132545
132546 /* Reattach the ORDER BY clause to the query.
132547 */
132548 p->pOrderBy = pOrderBy;
132549 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
132550
132551 /* Allocate a range of temporary registers and the KeyInfo needed
132552 ** for the logic that removes duplicate result rows when the
132553 ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
132554 */
132555 if( op==TK_ALL ){
132556 regPrev = 0;
132557 }else{
132558 int nExpr = p->pEList->nExpr;
132559 assert( nOrderBy>=nExpr || db->mallocFailed );
132560 regPrev = pParse->nMem+1;
132561 pParse->nMem += nExpr+1;
132562 sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
132563 pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
132564 if( pKeyDup ){
132565 assert( sqlite3KeyInfoIsWriteable(pKeyDup) );
132566 for(i=0; i<nExpr; i++){
132567 pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
132568 pKeyDup->aSortFlags[i] = 0;
132569 }
132570 }
132571 }
132572
132573 /* Separate the left and the right query from one another
132574 */
132575 p->pPrior = 0;
132576 pPrior->pNext = 0;
132577 sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
132578 if( pPrior->pPrior==0 ){
132579 sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
132580 }
132581
132582 /* Compute the limit registers */
132583 computeLimitRegisters(pParse, p, labelEnd);
132584 if( p->iLimit && op==TK_ALL ){
132585 regLimitA = ++pParse->nMem;
132586 regLimitB = ++pParse->nMem;
132587 sqlite3VdbeAddOp2(v, OP_Copy, p->iOffset ? p->iOffset+1 : p->iLimit,
132588 regLimitA);
132589 sqlite3VdbeAddOp2(v, OP_Copy, regLimitA, regLimitB);
132590 }else{
132591 regLimitA = regLimitB = 0;
132592 }
132593 sqlite3ExprDelete(db, p->pLimit);
132594 p->pLimit = 0;
132595
132596 regAddrA = ++pParse->nMem;
132597 regAddrB = ++pParse->nMem;
132598 regOutA = ++pParse->nMem;
132599 regOutB = ++pParse->nMem;
132600 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
132601 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
132602
132603 ExplainQueryPlan((pParse, 1, "MERGE (%s)", selectOpName(p->op)));
132604
132605 /* Generate a coroutine to evaluate the SELECT statement to the
132606 ** left of the compound operator - the "A" select.
132607 */
132608 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
132609 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
132610 VdbeComment((v, "left SELECT"));
132611 pPrior->iLimit = regLimitA;
132612 ExplainQueryPlan((pParse, 1, "LEFT"));
132613 sqlite3Select(pParse, pPrior, &destA);
132614 sqlite3VdbeEndCoroutine(v, regAddrA);
132615 sqlite3VdbeJumpHere(v, addr1);
132616
132617 /* Generate a coroutine to evaluate the SELECT statement on
132618 ** the right - the "B" select
132619 */
132620 addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
132621 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
132622 VdbeComment((v, "right SELECT"));
132623 savedLimit = p->iLimit;
132624 savedOffset = p->iOffset;
132625 p->iLimit = regLimitB;
132626 p->iOffset = 0;
132627 ExplainQueryPlan((pParse, 1, "RIGHT"));
132628 sqlite3Select(pParse, p, &destB);
132629 p->iLimit = savedLimit;
132630 p->iOffset = savedOffset;
132631 sqlite3VdbeEndCoroutine(v, regAddrB);
132632
132633 /* Generate a subroutine that outputs the current row of the A
132634 ** select as the next output row of the compound select.
132635 */
132636 VdbeNoopComment((v, "Output routine for A"));
132637 addrOutA = generateOutputSubroutine(pParse,
132638 p, &destA, pDest, regOutA,
132639 regPrev, pKeyDup, labelEnd);
132640
132641 /* Generate a subroutine that outputs the current row of the B
132642 ** select as the next output row of the compound select.
132643 */
132644 if( op==TK_ALL || op==TK_UNION ){
132645 VdbeNoopComment((v, "Output routine for B"));
132646 addrOutB = generateOutputSubroutine(pParse,
132647 p, &destB, pDest, regOutB,
132648 regPrev, pKeyDup, labelEnd);
132649 }
132650 sqlite3KeyInfoUnref(pKeyDup);
132651
132652 /* Generate a subroutine to run when the results from select A
132653 ** are exhausted and only data in select B remains.
132654 */
132655 if( op==TK_EXCEPT || op==TK_INTERSECT ){
132656 addrEofA_noB = addrEofA = labelEnd;
132657 }else{
132658 VdbeNoopComment((v, "eof-A subroutine"));
132659 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
132660 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
132661 VdbeCoverage(v);
132662 sqlite3VdbeGoto(v, addrEofA);
132664 }
132665
132666 /* Generate a subroutine to run when the results from select B
132667 ** are exhausted and only data in select A remains.
132668 */
132669 if( op==TK_INTERSECT ){
132670 addrEofB = addrEofA;
132671 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
132672 }else{
132673 VdbeNoopComment((v, "eof-B subroutine"));
132674 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
132675 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
132676 sqlite3VdbeGoto(v, addrEofB);
132677 }
132678
132679 /* Generate code to handle the case of A<B
132680 */
132681 VdbeNoopComment((v, "A-lt-B subroutine"));
132682 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
132683 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
132684 sqlite3VdbeGoto(v, labelCmpr);
132685
132686 /* Generate code to handle the case of A==B
132687 */
132688 if( op==TK_ALL ){
132689 addrAeqB = addrAltB;
132690 }else if( op==TK_INTERSECT ){
132691 addrAeqB = addrAltB;
132692 addrAltB++;
132693 }else{
132694 VdbeNoopComment((v, "A-eq-B subroutine"));
132695 addrAeqB =
132696 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
132697 sqlite3VdbeGoto(v, labelCmpr);
132698 }
132699
132700 /* Generate code to handle the case of A>B
132701 */
132702 VdbeNoopComment((v, "A-gt-B subroutine"));
132703 addrAgtB = sqlite3VdbeCurrentAddr(v);
132704 if( op==TK_ALL || op==TK_UNION ){
132705 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
132706 }
132707 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
132708 sqlite3VdbeGoto(v, labelCmpr);
132709
132710 /* This code runs once to initialize everything.
132711 */
132712 sqlite3VdbeJumpHere(v, addr1);
132713 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
132714 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
132715
132716 /* Implement the main merge loop
132717 */
132718 sqlite3VdbeResolveLabel(v, labelCmpr);
132719 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
132720 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
132721 (char*)pKeyMerge, P4_KEYINFO);
132723 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
132724
132725 /* Jump to the this point in order to terminate the query.
132726 */
132727 sqlite3VdbeResolveLabel(v, labelEnd);
132728
132729 /* Reassembly the compound query so that it will be freed correctly
132730 ** by the calling function */
132731 if( p->pPrior ){
132732 sqlite3SelectDelete(db, p->pPrior);
132733 }
132734 p->pPrior = pPrior;
132735 pPrior->pNext = p;
#define VdbeNoopComment(X)
Definition sqlite3.c:15934
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse *, Select *, ExprList *, const char *)
Definition sqlite3.c:99118
#define OP_Permutation
Definition sqlite3.c:15651
static int generateOutputSubroutine(Parse *pParse, Select *p, SelectDest *pIn, SelectDest *pDest, int regReturn, int regPrev, KeyInfo *pKeyInfo, int iBreak)
Definition sqlite3.c:132229
SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe *, int)
Definition sqlite3.c:78234
#define OPFLAG_PERMUTE
Definition sqlite3.c:18851
u8 * aSortFlags
Definition sqlite3.c:17685

References ExprList::a, KeyInfo::aColl, KeyInfo::aSortFlags, computeLimitRegisters(), Parse::db, EP_IntValue, ExplainQueryPlan, ExplainQueryPlanPop, Expr::flags, generateOutputSubroutine(), Select::iLimit, Select::iOffset, ExprList::ExprList_item::iOrderByCol, SelectDest::iSdst, Expr::iValue, sqlite3::mallocFailed, multiSelectCollSeq(), multiSelectOrderByKeyInfo(), Parse::nErr, ExprList::nExpr, Parse::nMem, Select::nSelectRow, Select::op, OP_Compare, OP_Copy, OP_Gosub, OP_InitCoroutine, OP_Integer, OP_Jump, OP_Permutation, OP_Yield, OPFLAG_PERMUTE, P4_INTARRAY, P4_KEYINFO, Select::pEList, Select::pLimit, Select::pNext, Select::pOrderBy, Select::pPrior, Parse::pVdbe, selectOpName(), sqlite3DbMallocRawNN(), sqlite3Expr(), sqlite3ExprDelete(), sqlite3ExprListAppend(), sqlite3ExprListDup(), sqlite3KeyInfoAlloc(), sqlite3KeyInfoUnref(), sqlite3LogEstAdd(), sqlite3ResolveOrderGroupBy(), sqlite3Select(), sqlite3SelectDelete(), sqlite3SelectDestInit(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeEndCoroutine(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_NOMEM_BKPT, SRT_Coroutine, TK_ALL, TK_EXCEPT, TK_INTEGER, TK_INTERSECT, TK_UNION, Expr::u, ExprList::ExprList_item::u, VdbeComment, VdbeCoverage, VdbeNoopComment, and ExprList::ExprList_item::x.

Referenced by multiSelect().

◆ multiSelectOrderByKeyInfo()

static KeyInfo * multiSelectOrderByKeyInfo ( Parse * pParse,
Select * p,
int nExtra )
static

Definition at line 131561 of file sqlite3.c.

131567 {
131568 ExprList *pOrderBy = p->pOrderBy;
131569 int nOrderBy = p->pOrderBy->nExpr;
131570 sqlite3 *db = pParse->db;
131571 KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
131572 if( pRet ){
131573 int i;
131574 for(i=0; i<nOrderBy; i++){
131575 struct ExprList_item *pItem = &pOrderBy->a[i];
131576 Expr *pTerm = pItem->pExpr;
131577 CollSeq *pColl;
131578
131579 if( pTerm->flags & EP_Collate ){
131580 pColl = sqlite3ExprCollSeq(pParse, pTerm);
131581 }else{
131582 pColl = multiSelectCollSeq(pParse, p, pItem->u.x.iOrderByCol-1);
131583 if( pColl==0 ) pColl = db->pDfltColl;
131584 pOrderBy->a[i].pExpr =
131585 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
131586 }
131587 assert( sqlite3KeyInfoIsWriteable(pRet) );
131588 pRet->aColl[i] = pColl;
SQLITE_PRIVATE CollSeq * sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr)
Definition sqlite3.c:99866

References ExprList::a, KeyInfo::aColl, KeyInfo::aSortFlags, Parse::db, EP_Collate, Expr::flags, multiSelectCollSeq(), ExprList::nExpr, sqlite3::pDfltColl, ExprList::ExprList_item::pExpr, Select::pOrderBy, ExprList::ExprList_item::sortFlags, sqlite3ExprAddCollateString(), sqlite3ExprCollSeq(), sqlite3KeyInfoAlloc(), and CollSeq::zName.

Referenced by generateWithRecursiveQuery(), and multiSelectOrderBy().

◆ multiSelectValues()

static int multiSelectValues ( Parse * pParse,
Select * p,
SelectDest * pDest )
static

Definition at line 131789 of file sqlite3.c.

131791 : "SELECT (VALUES(1),(2),(3))").
131792** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
131793** Since the limit is exactly 1, we only need to evalutes the left-most VALUES.
131794*/
131795static int multiSelectValues(
131796 Parse *pParse, /* Parsing context */
131797 Select *p, /* The right-most of SELECTs to be coded */
131798 SelectDest *pDest /* What to do with query results */
131799){
131800 int nRow = 1;
131801 int rc = 0;
131802 int bShowAll = p->pLimit==0;
131803 assert( p->selFlags & SF_MultiValue );
131804 do{
131805 assert( p->selFlags & SF_Values );
131806 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
131807 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
131808#ifndef SQLITE_OMIT_WINDOWFUNC
131809 if( p->pWin ) return -1;
131810#endif
131811 if( p->pPrior==0 ) break;
131812 assert( p->pPrior->pNext==p );
131813 p = p->pPrior;
131814 nRow += bShowAll;
131815 }while(1);
131816 ExplainQueryPlan((pParse, 0, "SCAN %d CONSTANT ROW%s", nRow,
131817 nRow==1 ? "" : "S"));
131818 while( p ){
131819 selectInnerLoop(pParse, p, -1, 0, 0, pDest, 1, 1);
#define LIMIT
lu_byte left
#define SF_Values
Definition sqlite3.c:18480

References ExplainQueryPlan, ExprList::nExpr, Select::nSelectRow, Select::op, Select::pEList, Select::pLimit, Select::pNext, Select::pPrior, Select::pWin, selectInnerLoop(), Select::selFlags, SF_MultiValue, SF_Values, TK_ALL, and TK_SELECT.

Referenced by multiSelect().

◆ nameInUsingClause()

static int nameInUsingClause ( IdList * pUsing,
const char * zCol )
static

Definition at line 97874 of file sqlite3.c.

97880 {
97881 if( pUsing ){
97882 int k;

References IdList::a, IdList::nId, sqlite3StrICmp(), and IdList::IdList_item::zName.

Referenced by lookupName().

◆ newDatabase()

static int newDatabase ( BtShared * pBt)
static

Definition at line 67762 of file sqlite3.c.

67768 {
67769 MemPage *pP1;
67770 unsigned char *data;
67771 int rc;
67772
67773 assert( sqlite3_mutex_held(pBt->mutex) );
67774 if( pBt->nPage>0 ){
67775 return SQLITE_OK;
67776 }
67777 pP1 = pBt->pPage1;
67778 assert( pP1!=0 );
67779 data = pP1->aData;
67780 rc = sqlite3PagerWrite(pP1->pDbPage);
67781 if( rc ) return rc;
67782 memcpy(data, zMagicHeader, sizeof(zMagicHeader));
67783 assert( sizeof(zMagicHeader)==16 );
67784 data[16] = (u8)((pBt->pageSize>>8)&0xff);
67785 data[17] = (u8)((pBt->pageSize>>16)&0xff);
67786 data[18] = 1;
67787 data[19] = 1;
67788 assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize);
67789 data[20] = (u8)(pBt->pageSize - pBt->usableSize);
67790 data[21] = 64;
67791 data[22] = 32;
67792 data[23] = 32;
67793 memset(&data[24], 0, 100-24);
67796#ifndef SQLITE_OMIT_AUTOVACUUM
67797 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
67798 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
67799 put4byte(&data[36 + 4*4], pBt->autoVacuum);

References MemPage::aData, BtShared::autoVacuum, BTS_PAGESIZE_FIXED, BtShared::btsFlags, BtShared::incrVacuum, BtShared::mutex, BtShared::nPage, BtShared::pageSize, MemPage::pDbPage, BtShared::pPage1, PTF_INTKEY, PTF_LEAF, PTF_LEAFDATA, put4byte, sqlite3_mutex_held(), sqlite3PagerWrite(), SQLITE_OK, BtShared::usableSize, zeroPage(), and zMagicHeader.

Referenced by sqlite3BtreeBeginTrans(), sqlite3BtreeNewDb(), and sqlite3BtreeSavepoint().

◆ nocaseCollatingFunc()

static int nocaseCollatingFunc ( void * NotUsed,
int nKey1,
const void * pKey1,
int nKey2,
const void * pKey2 )
static

Definition at line 162037 of file sqlite3.c.

162047 {
162048 int r = sqlite3StrNICmp(
162049 (const char *)pKey1, (const char *)pKey2, (nKey1<nKey2)?nKey1:nKey2);

References sqlite3StrNICmp, and UNUSED_PARAMETER.

Referenced by openDatabase().

◆ nolockCheckReservedLock()

static int nolockCheckReservedLock ( sqlite3_file * NotUsed,
int * pResOut )
static

Definition at line 35714 of file sqlite3.c.

◆ nolockClose()

static int nolockClose ( sqlite3_file * id)
static

Definition at line 35731 of file sqlite3.c.

◆ nolockLock()

static int nolockLock ( sqlite3_file * NotUsed,
int NotUsed2 )
static

Definition at line 35719 of file sqlite3.c.

35720 {
35721 UNUSED_PARAMETER(NotUsed);
35722 *pResOut = 0;

References UNUSED_PARAMETER.

Referenced by unixShmBarrier().

◆ nolockUnlock()

static int nolockUnlock ( sqlite3_file * NotUsed,
int NotUsed2 )
static

Definition at line 35723 of file sqlite3.c.

35725 {
35726 UNUSED_PARAMETER2(NotUsed, NotUsed2);

◆ noopMutexAlloc()

static sqlite3_mutex * noopMutexAlloc ( int id)
static

Definition at line 26045 of file sqlite3.c.

26048 { return SQLITE_OK; }

References SQLITE_OK.

◆ noopMutexEnd()

static int noopMutexEnd ( void )
static

Definition at line 26044 of file sqlite3.c.

◆ noopMutexEnter()

static void noopMutexEnter ( sqlite3_mutex * p)
static

Definition at line 26050 of file sqlite3.c.

26050{

◆ noopMutexFree()

static void noopMutexFree ( sqlite3_mutex * p)
static

Definition at line 26049 of file sqlite3.c.

26049{ return SQLITE_OK; }

References SQLITE_OK.

◆ noopMutexInit()

static int noopMutexInit ( void )
static

Definition at line 26043 of file sqlite3.c.

◆ noopMutexLeave()

static void noopMutexLeave ( sqlite3_mutex * p)
static

Definition at line 26055 of file sqlite3.c.

26055{ UNUSED_PARAMETER(p); return; }

References UNUSED_PARAMETER.

◆ noopMutexTry()

static int noopMutexTry ( sqlite3_mutex * p)
static

Definition at line 26051 of file sqlite3.c.

26054 { UNUSED_PARAMETER(p); return; }

◆ noopStepFunc()

static void noopStepFunc ( sqlite3_context * p,
int n,
sqlite3_value ** a )
static

Definition at line 151728 of file sqlite3.c.

Referenced by windowAggStep().

◆ noopValueFunc()

static void noopValueFunc ( sqlite3_context * p)
static

Definition at line 151738 of file sqlite3.c.

151738{ /*NO_TEST*/

References UNUSED_PARAMETER.

◆ notValidImpl()

static void notValidImpl ( Parse * pParse,
NameContext * pNC,
const char * zMsg,
Expr * pExpr )
static

Definition at line 98442 of file sqlite3.c.

98442 {...}
98443**
98444** As an optimization, since the conditional is almost always false
98445** (because errors are rare), the conditional is moved outside of the
98446** function call using a macro.
98447*/
98448static void notValidImpl(
98449 Parse *pParse, /* Leave error message here */
98450 NameContext *pNC, /* The name context */
98451 const char *zMsg, /* Type of error */
98452 Expr *pExpr /* Invalidate this expression on error */
98453){
98454 const char *zIn = "partial index WHERE clauses";
98455 if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
98456#ifndef SQLITE_OMIT_CHECK
98457 else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
98458#endif

References NC_IdxExpr, NC_IsCheck, and NameContext::ncFlags.

◆ nth_valueFinalizeFunc()

static void nth_valueFinalizeFunc ( sqlite3_context * pCtx)
static

Definition at line 151410 of file sqlite3.c.

151411 :
151413 pCtx, "second argument to nth_value must be a positive integer", -1
151414 );
151415}
151416static void nth_valueFinalizeFunc(sqlite3_context *pCtx){
151417 struct NthValueCtx *p;
151418 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
static void nth_valueFinalizeFunc(sqlite3_context *pCtx)
Definition sqlite3.c:151410

◆ nth_valueStepFunc()

static void nth_valueStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151369 of file sqlite3.c.

151371 {
151372 i64 nStep;
151373 sqlite3_value *pValue;
151374};
151375static void nth_valueStepFunc(
151376 sqlite3_context *pCtx,
151377 int nArg,
151378 sqlite3_value **apArg
151379){
151380 struct NthValueCtx *p;
151381 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151382 if( p ){
151383 i64 iVal;
151384 switch( sqlite3_value_numeric_type(apArg[1]) ){
151385 case SQLITE_INTEGER:
151386 iVal = sqlite3_value_int64(apArg[1]);
151387 break;
151388 case SQLITE_FLOAT: {
151389 double fVal = sqlite3_value_double(apArg[1]);
151390 if( ((i64)fVal)!=fVal ) goto error_out;
151391 iVal = (i64)fVal;
151392 break;
151393 }
151394 default:
151395 goto error_out;
151396 }
151397 if( iVal<=0 ) goto error_out;
151398
151399 p->nStep++;
151400 if( iVal==p->nStep ){
151401 p->pValue = sqlite3_value_dup(apArg[0]);
151402 if( !p->pValue ){
151404 }
151405 }
151406 }
151407 UNUSED_PARAMETER(nArg);
151408 UNUSED_PARAMETER(apArg);
151409 return;
static void nth_valueStepFunc(sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
Definition sqlite3.c:151369
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *)
Definition sqlite3.c:85640

References NthValueCtx::nStep, and NthValueCtx::pValue.

◆ ntileInvFunc()

static void ntileInvFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151601 of file sqlite3.c.

151611 {

◆ ntileStepFunc()

static void ntileStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151581 of file sqlite3.c.

151591 {
151592 struct NtileCtx *p;
151593 assert( nArg==1 ); UNUSED_PARAMETER(nArg);
151594 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151595 if( p ){
151596 if( p->nTotal==0 ){
151597 p->nParam = sqlite3_value_int64(apArg[0]);
151598 if( p->nParam<=0 ){
151600 pCtx, "argument of ntile must be a positive integer", -1

References NtileCtx::nParam, NtileCtx::nTotal, sqlite3_aggregate_context(), sqlite3_result_error(), sqlite3_value_int64(), and UNUSED_PARAMETER.

◆ ntileValueFunc()

static void ntileValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151612 of file sqlite3.c.

151618 {
151619 struct NtileCtx *p;
151620 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151621 if( p && p->nParam>0 ){
151622 int nSize = (p->nTotal / p->nParam);
151623 if( nSize==0 ){
151624 sqlite3_result_int64(pCtx, p->iRow+1);
151625 }else{
151626 i64 nLarge = p->nTotal - p->nParam*nSize;
151627 i64 iSmall = nLarge*(nSize+1);
151628 i64 iRow = p->iRow;
151629
151630 assert( (nLarge*(nSize+1) + (p->nParam-nLarge)*nSize)==p->nTotal );
151631
151632 if( iRow<iSmall ){
151633 sqlite3_result_int64(pCtx, 1 + iRow/(nSize+1));

◆ nullifFunc()

static void nullifFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

◆ numberOfCachePages()

static int numberOfCachePages ( PCache * p)
static

Definition at line 49113 of file sqlite3.c.

49119 {
49120 if( p->szCache>=0 ){
49121 /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
49122 ** suggested cache size is set to N. */
49123 return p->szCache;
49124 }else{
49125 /* IMPLEMANTATION-OF: R-59858-46238 If the argument N is negative, then the
int szCache
Definition sqlite3.c:48918

Referenced by sqlite3PcacheFetchStress(), and sqlite3PcacheSetSpillsize().

◆ numericType()

static u16 numericType ( Mem * pMem)
static

Definition at line 85696 of file sqlite3.c.

85702 {
85703 if( pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal) ){
85704 testcase( pMem->flags & MEM_Int );
85705 testcase( pMem->flags & MEM_Real );
85706 testcase( pMem->flags & MEM_IntReal );
85707 return pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal);
85708 }
85709 if( pMem->flags & (MEM_Str|MEM_Blob) ){

References computeNumericType(), sqlite3_value::flags, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Real, MEM_Str, and testcase.

Referenced by sqlite3VdbeExec().

◆ openDatabase()

static int openDatabase ( const char * zFilename,
sqlite3 ** ppDb,
unsigned int flags,
const char * zVfs )
static

Definition at line 164053 of file sqlite3.c.

164064 {
164065 sqlite3 *db; /* Store allocated handle here */
164066 int rc; /* Return code */
164067 int isThreadsafe; /* True for threadsafe connections */
164068 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
164069 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
164070 int i; /* Loop counter */
164071
164072#ifdef SQLITE_ENABLE_API_ARMOR
164073 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
164074#endif
164075 *ppDb = 0;
164076#ifndef SQLITE_OMIT_AUTOINIT
164077 rc = sqlite3_initialize();
164078 if( rc ) return rc;
164079#endif
164080
164081 if( sqlite3GlobalConfig.bCoreMutex==0 ){
164082 isThreadsafe = 0;
164083 }else if( flags & SQLITE_OPEN_NOMUTEX ){
164084 isThreadsafe = 0;
164085 }else if( flags & SQLITE_OPEN_FULLMUTEX ){
164086 isThreadsafe = 1;
164087 }else{
164088 isThreadsafe = sqlite3GlobalConfig.bFullMutex;
164089 }
164090
164091 if( flags & SQLITE_OPEN_PRIVATECACHE ){
164092 flags &= ~SQLITE_OPEN_SHAREDCACHE;
164093 }else if( sqlite3GlobalConfig.sharedCacheEnabled ){
164094 flags |= SQLITE_OPEN_SHAREDCACHE;
164095 }
164096
164097 /* Remove harmful bits from the flags parameter
164098 **
164099 ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
164100 ** dealt with in the previous code block. Besides these, the only
164101 ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
164102 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
164103 ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
164104 ** off all other flags.
164105 */
164106 flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
164118 );
164119
164120 /* Allocate the sqlite data structure */
164121 db = sqlite3MallocZero( sizeof(sqlite3) );
164122 if( db==0 ) goto opendb_out;
164123 if( isThreadsafe
164124#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
164125 || sqlite3GlobalConfig.bCoreMutex
164126#endif
164127 ){
164129 if( db->mutex==0 ){
164130 sqlite3_free(db);
164131 db = 0;
164132 goto opendb_out;
164133 }
164134 if( isThreadsafe==0 ){
164136 }
164137 }
164139 db->errMask = 0xff;
164140 db->nDb = 2;
164141 db->magic = SQLITE_MAGIC_BUSY;
164142 db->aDb = db->aDbStatic;
164143 db->lookaside.bDisable = 1;
164144 db->lookaside.sz = 0;
164145
164146 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
164147 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
164149 db->autoCommit = 1;
164150 db->nextAutovac = -1;
164151 db->szMmap = sqlite3GlobalConfig.szMmap;
164152 db->nextPagesize = 0;
164153 db->nMaxSorterMmap = 0x7FFFFFFF;
164158#if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
164160#endif
164161/* The SQLITE_DQS compile-time option determines the default settings
164162** for SQLITE_DBCONFIG_DQS_DDL and SQLITE_DBCONFIG_DQS_DML.
164163**
164164** SQLITE_DQS SQLITE_DBCONFIG_DQS_DDL SQLITE_DBCONFIG_DQS_DML
164165** ---------- ----------------------- -----------------------
164166** undefined on on
164167** 3 on on
164168** 2 on off
164169** 1 off on
164170** 0 off off
164171**
164172** Legacy behavior is 3 (double-quoted string literals are allowed anywhere)
164173** and so that is the default. But developers are encouranged to use
164174** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
164175*/
164176#if !defined(SQLITE_DQS)
164177# define SQLITE_DQS 3
164178#endif
164179#if (SQLITE_DQS&1)==1
164180 | SQLITE_DqsDML
164181#endif
164182#if (SQLITE_DQS&2)==2
164183 | SQLITE_DqsDDL
164184#endif
164185
164186#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
164188#endif
164189#if SQLITE_DEFAULT_CKPTFULLFSYNC
164191#endif
164192#if SQLITE_DEFAULT_FILE_FORMAT<4
164194#endif
164195#ifdef SQLITE_ENABLE_LOAD_EXTENSION
164197#endif
164198#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
164200#endif
164201#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
164203#endif
164204#if defined(SQLITE_REVERSE_UNORDERED_SELECTS)
164206#endif
164207#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
164209#endif
164210#if defined(SQLITE_ENABLE_FTS3_TOKENIZER)
164212#endif
164213#if defined(SQLITE_ENABLE_QPSG)
164215#endif
164216#if defined(SQLITE_DEFAULT_DEFENSIVE)
164218#endif
164219#if defined(SQLITE_DEFAULT_LEGACY_ALTER_TABLE)
164221#endif
164222 ;
164224#ifndef SQLITE_OMIT_VIRTUALTABLE
164225 sqlite3HashInit(&db->aModule);
164226#endif
164227
164228 /* Add the default collation sequence BINARY. BINARY works for both UTF-8
164229 ** and UTF-16, so add a version for each to avoid any unnecessary
164230 ** conversions. The only error that can occur here is a malloc() failure.
164231 **
164232 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
164233 ** functions:
164234 */
164238 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
164239 createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
164240 if( db->mallocFailed ){
164241 goto opendb_out;
164242 }
164243
164244 /* Parse the filename/URI argument
164245 **
164246 ** Only allow sensible combinations of bits in the flags argument.
164247 ** Throw an error if any non-sense combination is used. If we
164248 ** do not block illegal combinations here, it could trigger
164249 ** assert() statements in deeper layers. Sensible combinations
164250 ** are:
164251 **
164252 ** 1: SQLITE_OPEN_READONLY
164253 ** 2: SQLITE_OPEN_READWRITE
164254 ** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
164255 */
164256 db->openFlags = flags;
164257 assert( SQLITE_OPEN_READONLY == 0x01 );
164258 assert( SQLITE_OPEN_READWRITE == 0x02 );
164259 assert( SQLITE_OPEN_CREATE == 0x04 );
164260 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
164261 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
164262 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
164263 if( ((1<<(flags&7)) & 0x46)==0 ){
164264 rc = SQLITE_MISUSE_BKPT; /* IMP: R-18321-05872 */
164265 }else{
164266 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
164267 }
164268 if( rc!=SQLITE_OK ){
164269 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
164270 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
164271 sqlite3_free(zErrMsg);
164272 goto opendb_out;
164273 }
164274
164275 /* Open the backend database driver */
164276 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
164277 flags | SQLITE_OPEN_MAIN_DB);
164278 if( rc!=SQLITE_OK ){
164279 if( rc==SQLITE_IOERR_NOMEM ){
164280 rc = SQLITE_NOMEM_BKPT;
164281 }
164282 sqlite3Error(db, rc);
164283 goto opendb_out;
164284 }
164285 sqlite3BtreeEnter(db->aDb[0].pBt);
164286 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
164287 if( !db->mallocFailed ){
164289 }
164290 sqlite3BtreeLeave(db->aDb[0].pBt);
164291 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
164292
164293 /* The default safety_level for the main database is FULL; for the temp
164294 ** database it is OFF. This matches the pager layer defaults.
164295 */
164296 db->aDb[0].zDbSName = "main";
164298 db->aDb[1].zDbSName = "temp";
164300
164301 db->magic = SQLITE_MAGIC_OPEN;
164302 if( db->mallocFailed ){
164303 goto opendb_out;
164304 }
164305
164306 /* Register all built-in functions, but do not attempt to read the
164307 ** database schema yet. This is delayed until the first time the database
164308 ** is accessed.
164309 */
164310 sqlite3Error(db, SQLITE_OK);
164312 rc = sqlite3_errcode(db);
164313
164314
164315 /* Load compiled-in extensions */
164316 for(i=0; rc==SQLITE_OK && i<ArraySize(sqlite3BuiltinExtensions); i++){
164317 rc = sqlite3BuiltinExtensions[i](db);
164318 }
164319
164320 /* Load automatic extensions - extensions that have been registered
164321 ** using the sqlite3_automatic_extension() API.
164322 */
164323 if( rc==SQLITE_OK ){
164325 rc = sqlite3_errcode(db);
164326 if( rc!=SQLITE_OK ){
164327 goto opendb_out;
164328 }
164329 }
164330
164331#ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS
164332 /* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time
164333 ** option gives access to internal functions by default.
164334 ** Testing use only!!! */
164336#endif
164337
164338 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
164339 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
164340 ** mode. Doing nothing at all also makes NORMAL the default.
164341 */
164342#ifdef SQLITE_DEFAULT_LOCKING_MODE
164343 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
164345 SQLITE_DEFAULT_LOCKING_MODE);
164346#endif
164347
164348 if( rc ) sqlite3Error(db, rc);
164349
164350 /* Enable the lookaside-malloc subsystem */
164351 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
164352 sqlite3GlobalConfig.nLookaside);
164353
164355
164356opendb_out:
164357 if( db ){
164358 assert( db->mutex!=0 || isThreadsafe==0
164359 || sqlite3GlobalConfig.bFullMutex==0 );
164361 }
164362 rc = sqlite3_errcode(db);
164363 assert( db!=0 || rc==SQLITE_NOMEM );
164364 if( rc==SQLITE_NOMEM ){
164365 sqlite3_close(db);
164366 db = 0;
164367 }else if( rc!=SQLITE_OK ){
164368 db->magic = SQLITE_MAGIC_SICK;
164369 }
164370 *ppDb = db;
164371#ifdef SQLITE_ENABLE_SQLLOG
164372 if( sqlite3GlobalConfig.xSqllog ){
164373 /* Opening a db handle. Fourth parameter is passed 0. */
164374 void *pArg = sqlite3GlobalConfig.pSqllogArg;
static const int aHardLimit[]
Definition sqlite3.c:163665
#define SQLITE_OPEN_CREATE
Definition sqlite3.c:1603
#define SQLITE_LegacyAlter
Definition sqlite3.c:17005
#define SQLITE_OPEN_PRIVATECACHE
Definition sqlite3.c:1619
SQLITE_PRIVATE sqlite3_mutex * sqlite3MutexAlloc(int)
Definition sqlite3.c:25931
#define SQLITE_CellSizeCk
Definition sqlite3.c:17000
static int rtrimCollFunc(void *pUser, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
Definition sqlite3.c:162008
#define SQLITE_OPEN_TEMP_DB
Definition sqlite3.c:1610
#define SQLITE_MUTEX_RECURSIVE
Definition sqlite3.c:8630
#define SQLITE_MAGIC_OPEN
Definition sqlite3.c:17077
#define SQLITE_CkptFullFSync
Definition sqlite3.c:16982
static int createCollation(sqlite3 *db, const char *zName, u8 enc, void *pCtx, int(*xCompare)(void *, int, const void *, int, const void *), void(*xDel)(void *))
Definition sqlite3.c:163588
#define SQLITE_LIMIT_WORKER_THREADS
Definition sqlite3.c:4955
#define SQLITE_ForeignKeys
Definition sqlite3.c:16993
#define SQLITE_OPEN_FULLMUTEX
Definition sqlite3.c:1617
#define SQLITE_OPEN_EXCLUSIVE
Definition sqlite3.c:1605
#define SQLITE_OPEN_TEMP_JOURNAL
Definition sqlite3.c:1613
#define SQLITE_Fts3Tokenizer
Definition sqlite3.c:17001
#define SQLITE_OPEN_SUBJOURNAL
Definition sqlite3.c:1614
#define SQLITE_OPEN_SHAREDCACHE
Definition sqlite3.c:1618
static int(*const sqlite3BuiltinExtensions[])(sqlite3 *)
Definition sqlite3.c:161057
#define DBFLAG_InternalFunc
Definition sqlite3.c:17033
#define SQLITE_DqsDDL
Definition sqlite3.c:17008
SQLITE_PRIVATE void sqlite3HashInit(Hash *)
Definition sqlite3.c:32900
#define SQLITE_EnableView
Definition sqlite3.c:17010
#define SQLITE_CacheSpill
Definition sqlite3.c:16983
#define SQLITE_Defensive
Definition sqlite3.c:17007
SQLITE_API int sqlite3_errcode(sqlite3 *db)
Definition sqlite3.c:163553
#define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
Definition sqlite3.c:13355
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt)
Definition sqlite3.c:161743
#define SQLITE_EnableTrigger
Definition sqlite3.c:16997
#define SQLITE_DEFAULT_WORKER_THREADS
Definition sqlite3.c:14215
static int binCollFunc(void *NotUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
Definition sqlite3.c:161985
#define SQLITE_AutoIndex
Definition sqlite3.c:16994
SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8)
Definition sqlite3.c:115717
SQLITE_API int sqlite3_initialize(void)
Definition sqlite3.c:161196
#define SQLITE_OPEN_NOMUTEX
Definition sqlite3.c:1616
static int nocaseCollatingFunc(void *NotUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
Definition sqlite3.c:162037
#define sqlite3MutexWarnOnContention(x)
Definition sqlite3.c:19428
SQLITE_API int sqlite3_close(sqlite3 *)
Definition sqlite3.c:162246
#define SQLITE_ReverseOrder
Definition sqlite3.c:16991
#define SCHEMA_ENC(db)
Definition sqlite3.c:16960
#define SQLITE_TrustedSchema
Definition sqlite3.c:16985
#define SQLITE_RecTriggers
Definition sqlite3.c:16992
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N)
Definition sqlite3.c:163281
#define SQLITE_LegacyFileFmt
Definition sqlite3.c:16979
SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *)
Definition sqlite3.c:125047
#define SQLITE_MAGIC_BUSY
Definition sqlite3.c:17080
#define SQLITE_MAGIC_SICK
Definition sqlite3.c:17079
SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3 *)
Definition sqlite3.c:118863
#define PAGER_SYNCHRONOUS_OFF
Definition sqlite3.c:14849
#define SQLITE_LoadExtension
Definition sqlite3.c:16995
#define SQLITE_OPEN_SUPER_JOURNAL
Definition sqlite3.c:1615
#define SQLITE_OPEN_TRANSIENT_DB
Definition sqlite3.c:1611
u32 bDisable
Definition sqlite3.c:16719
int nMaxSorterMmap
Definition sqlite3.c:16854
int errMask
Definition sqlite3.c:16833
signed char nextAutovac
Definition sqlite3.c:16842
i64 szMmap
Definition sqlite3.c:16829
Lookaside lookaside
Definition sqlite3.c:16906
int nextPagesize
Definition sqlite3.c:16849
u32 magic
Definition sqlite3.c:16850

References sqlite3::aCollSeq, sqlite3::aDb, sqlite3::aDbStatic, aHardLimit, sqlite3::aLimit, sqlite3::aModule, ArraySize, sqlite3::autoCommit, Lookaside::bDisable, binCollFunc(), createCollation(), DBFLAG_InternalFunc, sqlite3::dfltLockMode, sqlite3::errMask, sqlite3::flags, sqlite3::lookaside, sqlite3::magic, sqlite3::mallocFailed, sqlite3::mDbFlags, sqlite3::mutex, sqlite3::nDb, sqlite3::nextAutovac, sqlite3::nextPagesize, sqlite3::nMaxSorterMmap, nocaseCollatingFunc(), sqlite3::openFlags, PAGER_SYNCHRONOUS_OFF, Db::pBt, Db::pSchema, sqlite3::pVfs, rtrimCollFunc(), Db::safety_level, SCHEMA_ENC, setupLookaside(), sqlite3_close(), sqlite3_errcode(), sqlite3_free(), sqlite3_free_filename(), sqlite3_initialize(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_wal_autocheckpoint(), sqlite3AutoLoadExtensions(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3BtreeOpen(), sqlite3BtreePager(), sqlite3BuiltinExtensions, sqlite3Error(), sqlite3ErrorWithMsg(), sqlite3GlobalConfig, sqlite3HashInit(), sqlite3MallocZero(), sqlite3MutexAlloc(), sqlite3MutexWarnOnContention, sqlite3OomFault(), sqlite3PagerLockingMode(), sqlite3ParseUri(), sqlite3RegisterPerConnectionBuiltinFunctions(), sqlite3SchemaGet(), sqlite3SetTextEncoding(), sqlite3StrBINARY, SQLITE_AutoIndex, SQLITE_CacheSpill, SQLITE_CellSizeCk, SQLITE_CkptFullFSync, SQLITE_DEFAULT_SYNCHRONOUS, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT, SQLITE_DEFAULT_WORKER_THREADS, SQLITE_Defensive, SQLITE_DqsDDL, SQLITE_DqsDML, SQLITE_EnableQPSG, SQLITE_EnableTrigger, SQLITE_EnableView, SQLITE_ForeignKeys, SQLITE_Fts3Tokenizer, SQLITE_IOERR_NOMEM, SQLITE_LegacyAlter, SQLITE_LegacyFileFmt, SQLITE_LIMIT_WORKER_THREADS, SQLITE_LoadExtension, SQLITE_MAGIC_BUSY, SQLITE_MAGIC_OPEN, SQLITE_MAGIC_SICK, SQLITE_MISUSE_BKPT, SQLITE_MUTEX_RECURSIVE, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_EXCLUSIVE, SQLITE_OPEN_FULLMUTEX, SQLITE_OPEN_MAIN_DB, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE, SQLITE_OPEN_SUBJOURNAL, SQLITE_OPEN_SUPER_JOURNAL, SQLITE_OPEN_TEMP_DB, SQLITE_OPEN_TEMP_JOURNAL, SQLITE_OPEN_TRANSIENT_DB, SQLITE_OPEN_WAL, SQLITE_RecTriggers, SQLITE_ReverseOrder, SQLITE_ShortColNames, SQLITE_TrustedSchema, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, Lookaside::sz, sqlite3::szMmap, testcase, and Db::zDbSName.

Referenced by sqlite3_open_v2().

◆ openDirectory()

static int openDirectory ( const char * zFilename,
int * pFd )
static

Definition at line 37218 of file sqlite3.c.

37224 {
37225 int ii;
37226 int fd = -1;
37227 char zDirname[MAX_PATHNAME+1];
37228
37229 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
37230 for(ii=(int)strlen(zDirname); ii>0 && zDirname[ii]!='/'; ii--);
37231 if( ii>0 ){
37232 zDirname[ii] = '\0';
37233 }else{
37234 if( zDirname[0]!='/' ) zDirname[0] = '.';
37235 zDirname[1] = 0;
37236 }
37237 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
37238 if( fd>=0 ){
static int robust_open(const char *z, int f, mode_t m)
Definition sqlite3.c:34216
#define O_BINARY
Definition sqlite3.c:33857

References MAX_PATHNAME, O_BINARY, OSTRACE, robust_open(), sqlite3_snprintf(), SQLITE_CANTOPEN_BKPT, SQLITE_OK, and unixLogError.

◆ openStatTable()

static void openStatTable ( Parse * pParse,
int iDb,
int iStatCur,
const char * zWhere,
const char * zWhereType )
static

Definition at line 107709 of file sqlite3.c.

107721 {
107722 static const struct {
107723 const char *zName;
107724 const char *zCols;
107725 } aTable[] = {
107726 { "sqlite_stat1", "tbl,idx,stat" },
107727#if defined(SQLITE_ENABLE_STAT4)
107728 { "sqlite_stat4", "tbl,idx,neq,nlt,ndlt,sample" },
107729#else
107730 { "sqlite_stat4", 0 },
107731#endif
107732 { "sqlite_stat3", 0 },
107733 };
107734 int i;
107735 sqlite3 *db = pParse->db;
107736 Db *pDb;
107737 Vdbe *v = sqlite3GetVdbe(pParse);
107738 u32 aRoot[ArraySize(aTable)];
107739 u8 aCreateTbl[ArraySize(aTable)];
107740#ifdef SQLITE_ENABLE_STAT4
107741 const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1;
107742#else
107743 const int nToOpen = 1;
107744#endif
107745
107746 if( v==0 ) return;
107747 assert( sqlite3BtreeHoldsAllMutexes(db) );
107748 assert( sqlite3VdbeDb(v)==db );
107749 pDb = &db->aDb[iDb];
107750
107751 /* Create new statistic tables if they do not exist, or clear them
107752 ** if they do already exist.
107753 */
107754 for(i=0; i<ArraySize(aTable); i++){
107755 const char *zTab = aTable[i].zName;
107756 Table *pStat;
107757 aCreateTbl[i] = 0;
107758 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
107759 if( i<nToOpen ){
107760 /* The sqlite_statN table does not exist. Create it. Note that a
107761 ** side-effect of the CREATE TABLE statement is to leave the rootpage
107762 ** of the new table in register pParse->regRoot. This is important
107763 ** because the OpenWrite opcode below will be needing it. */
107764 sqlite3NestedParse(pParse,
107765 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
107766 );
107767 aRoot[i] = (u32)pParse->regRoot;
107768 aCreateTbl[i] = OPFLAG_P2ISREG;
107769 }
107770 }else{
107771 /* The table already exists. If zWhere is not NULL, delete all entries
107772 ** associated with the table zWhere. If zWhere is NULL, delete the
107773 ** entire contents of the table. */
107774 aRoot[i] = pStat->tnum;
107775 sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
107776 if( zWhere ){
107777 sqlite3NestedParse(pParse,
107778 "DELETE FROM %Q.%s WHERE %s=%Q",
107779 pDb->zDbSName, zTab, zWhereType, zWhere
107780 );
107781#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
107782 }else if( db->xPreUpdateCallback ){
107783 sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
107784#endif
107785 }else{
107786 /* The sqlite_stat[134] table already exists. Delete all rows. */
107787 sqlite3VdbeAddOp2(v, OP_Clear, (int)aRoot[i], iDb);
107788 }
107789 }
107790 }
107791
107792 /* Open the sqlite_stat[134] tables for writing. */
107793 for(i=0; i<nToOpen; i++){
#define OPFLAG_P2ISREG
Definition sqlite3.c:18850
SQLITE_PRIVATE sqlite3 * sqlite3VdbeDb(Vdbe *)
Definition sqlite3.c:82789
#define OP_Clear
Definition sqlite3.c:15703
int regRoot
Definition sqlite3.c:18710

References sqlite3::aDb, ArraySize, Parse::db, OP_Clear, OP_OpenWrite, OPFLAG_P2ISREG, OptimizationEnabled, Parse::regRoot, sqlite3FindTable(), sqlite3GetVdbe(), sqlite3NestedParse(), sqlite3TableLock(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeDb(), SQLITE_Stat4, Table::tnum, VdbeComment, Db::zDbSName, and zName.

Referenced by analyzeTable().

◆ openSubJournal()

static int openSubJournal ( Pager * pPager)
static

◆ operatorMask()

static u16 operatorMask ( int op)
static

Definition at line 144126 of file sqlite3.c.

144132 {
144133 u16 c;
144134 assert( allowedOp(op) );
144135 if( op==TK_IN ){
144136 c = WO_IN;
144137 }else if( op==TK_ISNULL ){
144138 c = WO_ISNULL;
144139 }else if( op==TK_IS ){
144140 c = WO_IS;
144141 }else{
144142 assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
144143 c = (u16)(WO_EQ<<(op-TK_EQ));
144144 }
144145 assert( op!=TK_ISNULL || c==WO_ISNULL );
144146 assert( op!=TK_IN || c==WO_IN );
144147 assert( op!=TK_EQ || c==WO_EQ );
144148 assert( op!=TK_LT || c==WO_LT );

Referenced by exprAnalyze().

◆ osLocaltime()

static int osLocaltime ( time_t * t,
struct tm * pTm )
static

Definition at line 22222 of file sqlite3.c.

22223 : R-62172-00036 In this implementation, the standard C
22224** library function localtime_r() is used to assist in the calculation of
22225** local time.
22226*/
22227static int osLocaltime(time_t *t, struct tm *pTm){
22228 int rc;
22229#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
22230 struct tm *pX;
22231#if SQLITE_THREADSAFE>0
22233#endif
22235 pX = localtime(t);
22236#ifndef SQLITE_UNTESTABLE
22237 if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
22238#endif
22239 if( pX ) *pTm = *pX;
22241 rc = pX==0;
22242#else
22243#ifndef SQLITE_UNTESTABLE
22244 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
22245#endif
22246#if HAVE_LOCALTIME_R
22247 rc = localtime_r(t, pTm)==0;
22248#else
GStaticMutex mutex
#define SQLITE_MUTEX_STATIC_MAIN
Definition sqlite3.c:8631

References mutex, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3GlobalConfig, sqlite3MutexAlloc(), and SQLITE_MUTEX_STATIC_MAIN.

Referenced by localtimeOffset().

◆ out2Prerelease()

static Mem * out2Prerelease ( Vdbe * p,
VdbeOp * pOp )
static

Definition at line 85960 of file sqlite3.c.

85961 {
85963 pOut->flags = MEM_Int;
85964 return pOut;
85965}
85966static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
85967 Mem *pOut;
85968 assert( pOp->p2>0 );
85969 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
85970 pOut = &p->aMem[pOp->p2];
85971 memAboutToChange(p, pOut);
85972 if( VdbeMemDynamic(pOut) ){ /*OPTIMIZATION-IF-FALSE*/
#define memAboutToChange(P, M)
Definition sqlite3.c:85268
#define VdbeMemDynamic(X)
Definition sqlite3.c:20981
static Mem * out2Prerelease(Vdbe *p, VdbeOp *pOp)
Definition sqlite3.c:85960

References sqlite3_value::flags, MEM_Int, and sqlite3VdbeMemSetNull().

Referenced by sqlite3VdbeExec().

◆ out2PrereleaseWithClear()

static SQLITE_NOINLINE Mem * out2PrereleaseWithClear ( Mem * pOut)
static

Definition at line 85955 of file sqlite3.c.

◆ pageFindSlot()

static u8 * pageFindSlot ( MemPage * pPg,
int nByte,
int * pRc )
static

Definition at line 66021 of file sqlite3.c.

66027 {
66028 const int hdr = pPg->hdrOffset; /* Offset to page header */
66029 u8 * const aData = pPg->aData; /* Page data */
66030 int iAddr = hdr + 1; /* Address of ptr to pc */
66031 int pc = get2byte(&aData[iAddr]); /* Address of a free slot */
66032 int x; /* Excess size of the slot */
66033 int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */
66034 int size; /* Size of the free slot */
66035
66036 assert( pc>0 );
66037 while( pc<=maxPC ){
66038 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
66039 ** freeblock form a big-endian integer which is the size of the freeblock
66040 ** in bytes, including the 4-byte header. */
66041 size = get2byte(&aData[pc+2]);
66042 if( (x = size - nByte)>=0 ){
66043 testcase( x==4 );
66044 testcase( x==3 );
66045 if( x<4 ){
66046 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
66047 ** number of bytes in fragments may not exceed 60. */
66048 if( aData[hdr+7]>57 ) return 0;
66049
66050 /* Remove the slot from the free-list. Update the number of
66051 ** fragmented bytes within the page. */
66052 memcpy(&aData[iAddr], &aData[pc], 2);
66053 aData[hdr+7] += (u8)x;
66054 }else if( x+pc > maxPC ){
66055 /* This slot extends off the end of the usable part of the page */
66056 *pRc = SQLITE_CORRUPT_PAGE(pPg);
66057 return 0;
66058 }else{
66059 /* The slot remains on the free-list. Reduce its size to account
66060 ** for the portion used by the new allocation. */
66061 put2byte(&aData[pc+2], x);
66062 }
66063 return &aData[pc + x];
66064 }
66065 iAddr = pc;
66066 pc = get2byte(&aData[pc]);
66067 if( pc<=iAddr+size ){
66068 if( pc ){
66069 /* The next slot in the chain is not past the end of the current slot */
66070 *pRc = SQLITE_CORRUPT_PAGE(pPg);
66071 }
66072 return 0;
66073 }
66074 }

References MemPage::aData, get2byte, MemPage::hdrOffset, MemPage::pBt, put2byte, SQLITE_CORRUPT_PAGE, testcase, and BtShared::usableSize.

Referenced by allocateSpace(), and pageInsertArray().

◆ pageFreeArray()

static int pageFreeArray ( MemPage * pPg,
int iFirst,
int nCell,
CellArray * pCArray )
static

Definition at line 71572 of file sqlite3.c.

71583 {
71584 u8 * const aData = pPg->aData;
71585 u8 * const pEnd = &aData[pPg->pBt->usableSize];
71586 u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
71587 int nRet = 0;
71588 int i;
71589 int iEnd = iFirst + nCell;
71590 u8 *pFree = 0;
71591 int szFree = 0;
71592
71593 for(i=iFirst; i<iEnd; i++){
71594 u8 *pCell = pCArray->apCell[i];
71595 if( SQLITE_WITHIN(pCell, pStart, pEnd) ){
71596 int sz;
71597 /* No need to use cachedCellSize() here. The sizes of all cells that
71598 ** are to be freed have already been computing while deciding which
71599 ** cells need freeing */
71600 sz = pCArray->szCell[i]; assert( sz>0 );
71601 if( pFree!=(pCell + sz) ){
71602 if( pFree ){
71603 assert( pFree>aData && (pFree - aData)<65536 );
71604 freeSpace(pPg, (u16)(pFree - aData), szFree);
71605 }
71606 pFree = pCell;
71607 szFree = sz;
71608 if( pFree+sz>pEnd ) return 0;
71609 }else{
71610 pFree = pCell;
71611 szFree += sz;
71612 }
71613 nRet++;
71614 }
71615 }

References MemPage::aData, CellArray::apCell, MemPage::childPtrSize, freeSpace(), MemPage::hdrOffset, MemPage::pBt, SQLITE_WITHIN, CellArray::szCell, and BtShared::usableSize.

Referenced by editPage().

◆ pageInsertArray()

static int pageInsertArray ( MemPage * pPg,
u8 * pBegin,
u8 ** ppData,
u8 * pCellptr,
int iFirst,
int nCell,
CellArray * pCArray )
static

Definition at line 71507 of file sqlite3.c.

71521 {
71522 int i = iFirst; /* Loop counter - cell index to insert */
71523 u8 *aData = pPg->aData; /* Complete page */
71524 u8 *pData = *ppData; /* Content area. A subset of aData[] */
71525 int iEnd = iFirst + nCell; /* End of loop. One past last cell to ins */
71526 int k; /* Current slot in pCArray->apEnd[] */
71527 u8 *pEnd; /* Maximum extent of cell data */
71528 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
71529 if( iEnd<=iFirst ) return 0;
71530 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
71531 pEnd = pCArray->apEnd[k];
71532 while( 1 /*Exit by break*/ ){
71533 int sz, rc;
71534 u8 *pSlot;
71535 assert( pCArray->szCell[i]!=0 );
71536 sz = pCArray->szCell[i];
71537 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
71538 if( (pData - pBegin)<sz ) return 1;
71539 pData -= sz;
71540 pSlot = pData;
71541 }
71542 /* pSlot and pCArray->apCell[i] will never overlap on a well-formed
71543 ** database. But they might for a corrupt database. Hence use memmove()
71544 ** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
71545 assert( (pSlot+sz)<=pCArray->apCell[i]
71546 || pSlot>=(pCArray->apCell[i]+sz)
71547 || CORRUPT_DB );
71548 if( (uptr)(pCArray->apCell[i]+sz)>(uptr)pEnd
71549 && (uptr)(pCArray->apCell[i])<(uptr)pEnd
71550 ){
71551 assert( CORRUPT_DB );
71552 (void)SQLITE_CORRUPT_BKPT;
71553 return 1;
71554 }
71555 memmove(pSlot, pCArray->apCell[i], sz);
71556 put2byte(pCellptr, (pSlot - aData));
71557 pCellptr += 2;
71558 i++;
71559 if( i>=iEnd ) break;
71560 if( pCArray->ixNx[k]<=i ){
71561 k++;

References MemPage::aData, ALWAYS, CellArray::apCell, CellArray::apEnd, CORRUPT_DB, MemPage::hdrOffset, CellArray::ixNx, NB, pageFindSlot(), put2byte, SQLITE_CORRUPT_BKPT, and CellArray::szCell.

Referenced by editPage().

◆ pager_cksum()

static u32 pager_cksum ( Pager * pPager,
const u8 * aData )
static

Definition at line 53888 of file sqlite3.c.

53894 {
53895 u32 cksum = pPager->cksumInit; /* Checksum value to return */
53896 int i = pPager->pageSize-200; /* Loop counter */
u32 cksumInit
Definition sqlite3.c:52358

References Pager::cksumInit, and Pager::pageSize.

Referenced by pager_playback_one_page().

◆ pager_delsuper()

static int pager_delsuper ( Pager * pPager,
const char * zSuper )
static

Definition at line 54182 of file sqlite3.c.

54183 : This function allocates a single block of memory to load
54184** the entire contents of the super-journal file. This could be
54185** a couple of kilobytes or so - potentially larger than the page
54186** size.
54187*/
54188static int pager_delsuper(Pager *pPager, const char *zSuper){
54189 sqlite3_vfs *pVfs = pPager->pVfs;
54190 int rc; /* Return code */
54191 sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
54192 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
54193 char *zSuperJournal = 0; /* Contents of super-journal file */
54194 i64 nSuperJournal; /* Size of super-journal file */
54195 char *zJournal; /* Pointer to one journal within MJ file */
54196 char *zSuperPtr; /* Space to hold super-journal filename */
54197 int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
54198
54199 /* Allocate space for both the pJournal and pSuper file descriptors.
54200 ** If successful, open the super-journal file for reading.
54201 */
54202 pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
54203 if( !pSuper ){
54204 rc = SQLITE_NOMEM_BKPT;
54205 pJournal = 0;
54206 }else{
54208 rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0);
54209 pJournal = (sqlite3_file *)(((u8 *)pSuper) + pVfs->szOsFile);
54210 }
54211 if( rc!=SQLITE_OK ) goto delsuper_out;
54212
54213 /* Load the entire super-journal file into space obtained from
54214 ** sqlite3_malloc() and pointed to by zSuperJournal. Also obtain
54215 ** sufficient space (in zSuperPtr) to hold the names of super-journal
54216 ** files extracted from regular rollback-journals.
54217 */
54218 rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
54219 if( rc!=SQLITE_OK ) goto delsuper_out;
54220 nSuperPtr = pVfs->mxPathname+1;
54221 zSuperJournal = sqlite3Malloc(nSuperJournal + nSuperPtr + 2);
54222 if( !zSuperJournal ){
54223 rc = SQLITE_NOMEM_BKPT;
54224 goto delsuper_out;
54225 }
54226 zSuperPtr = &zSuperJournal[nSuperJournal+2];
54227 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
54228 if( rc!=SQLITE_OK ) goto delsuper_out;
54229 zSuperJournal[nSuperJournal] = 0;
54230 zSuperJournal[nSuperJournal+1] = 0;
54231
54232 zJournal = zSuperJournal;
54233 while( (zJournal-zSuperJournal)<nSuperJournal ){
54234 int exists;
54235 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
54236 if( rc!=SQLITE_OK ){
54237 goto delsuper_out;
54238 }
54239 if( exists ){
54240 /* One of the journals pointed to by the super-journal exists.
54241 ** Open it and check if it points at the super-journal. If
54242 ** so, return without deleting the super-journal file.
54243 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
54244 ** SUPER_JOURNAL here so that the VFS will not send the zJournal
54245 ** name into sqlite3_database_file_object().
54246 */
54247 int c;
54249 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
54250 if( rc!=SQLITE_OK ){
54251 goto delsuper_out;
54252 }
54253
54254 rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr);
54255 sqlite3OsClose(pJournal);
54256 if( rc!=SQLITE_OK ){
54257 goto delsuper_out;
54258 }
54259
54260 c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
54261 if( c ){
54262 /* We have a match. Do not delete the super-journal file. */
54263 goto delsuper_out;
54264 }
54265 }
54266 zJournal += (sqlite3Strlen30(zJournal)+1);
54267 }
54268
54269 sqlite3OsClose(pSuper);
54270 rc = sqlite3OsDelete(pVfs, zSuper, 0);
54271
54272delsuper_out:
54273 sqlite3_free(zSuperJournal);
54274 if( pSuper ){
static void block(LexState *ls)
SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *, i64 *pSize)
Definition sqlite3.c:23064
static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper)
Definition sqlite3.c:52997
static int pager_delsuper(Pager *pPager, const char *zSuper)
Definition sqlite3.c:54182
int mxPathname
Definition sqlite3.c:2420

References isOpen, sqlite3_vfs::mxPathname, Pager::pVfs, readSuperJournal(), sqlite3_free(), sqlite3Malloc(), sqlite3MallocZero(), sqlite3OsAccess(), sqlite3OsClose(), sqlite3OsDelete(), sqlite3OsFileSize(), sqlite3OsOpen(), sqlite3OsRead(), sqlite3Strlen30(), SQLITE_ACCESS_EXISTS, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_READONLY, SQLITE_OPEN_SUPER_JOURNAL, and sqlite3_vfs::szOsFile.

Referenced by pager_playback().

◆ pager_end_transaction()

static int pager_end_transaction ( Pager * pPager,
int hasSuper,
int bCommit )
static

Definition at line 53707 of file sqlite3.c.

53713 {
53714 int rc = SQLITE_OK; /* Error code from journal finalization operation */
53715 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
53716
53717 /* Do nothing if the pager does not have an open write transaction
53718 ** or at least a RESERVED lock. This function may be called when there
53719 ** is no write-transaction active but a RESERVED or greater lock is
53720 ** held under two circumstances:
53721 **
53722 ** 1. After a successful hot-journal rollback, it is called with
53723 ** eState==PAGER_NONE and eLock==EXCLUSIVE_LOCK.
53724 **
53725 ** 2. If a connection with locking_mode=exclusive holding an EXCLUSIVE
53726 ** lock switches back to locking_mode=normal and then executes a
53727 ** read-transaction, this function is called with eState==PAGER_READER
53728 ** and eLock==EXCLUSIVE_LOCK when the read-transaction is closed.
53729 */
53730 assert( assert_pager_state(pPager) );
53731 assert( pPager->eState!=PAGER_ERROR );
53732 if( pPager->eState<PAGER_WRITER_LOCKED && pPager->eLock<RESERVED_LOCK ){
53733 return SQLITE_OK;
53734 }
53735
53736 releaseAllSavepoints(pPager);
53737 assert( isOpen(pPager->jfd) || pPager->pInJournal==0
53739 );
53740 if( isOpen(pPager->jfd) ){
53741 assert( !pagerUseWal(pPager) );
53742
53743 /* Finalize the journal file. */
53744 if( sqlite3JournalIsInMemory(pPager->jfd) ){
53745 /* assert( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ); */
53746 sqlite3OsClose(pPager->jfd);
53747 }else if( pPager->journalMode==PAGER_JOURNALMODE_TRUNCATE ){
53748 if( pPager->journalOff==0 ){
53749 rc = SQLITE_OK;
53750 }else{
53751 rc = sqlite3OsTruncate(pPager->jfd, 0);
53752 if( rc==SQLITE_OK && pPager->fullSync ){
53753 /* Make sure the new file size is written into the inode right away.
53754 ** Otherwise the journal might resurrect following a power loss and
53755 ** cause the last transaction to roll back. See
53756 ** https://bugzilla.mozilla.org/show_bug.cgi?id=1072773
53757 */
53758 rc = sqlite3OsSync(pPager->jfd, pPager->syncFlags);
53759 }
53760 }
53761 pPager->journalOff = 0;
53762 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
53763 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
53764 ){
53765 rc = zeroJournalHdr(pPager, hasSuper||pPager->tempFile);
53766 pPager->journalOff = 0;
53767 }else{
53768 /* This branch may be executed with Pager.journalMode==MEMORY if
53769 ** a hot-journal was just rolled back. In this case the journal
53770 ** file should be closed and deleted. If this connection writes to
53771 ** the database file, it will do so using an in-memory journal.
53772 */
53773 int bDelete = !pPager->tempFile;
53774 assert( sqlite3JournalIsInMemory(pPager->jfd)==0 );
53775 assert( pPager->journalMode==PAGER_JOURNALMODE_DELETE
53778 );
53779 sqlite3OsClose(pPager->jfd);
53780 if( bDelete ){
53781 rc = sqlite3OsDelete(pPager->pVfs, pPager->zJournal, pPager->extraSync);
53782 }
53783 }
53784 }
53785
53786#ifdef SQLITE_CHECK_PAGES
53787 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
53788 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
53789 PgHdr *p = sqlite3PagerLookup(pPager, 1);
53790 if( p ){
53791 p->pageHash = 0;
53793 }
53794 }
53795#endif
53796
53798 pPager->pInJournal = 0;
53799 pPager->nRec = 0;
53800 if( rc==SQLITE_OK ){
53801 if( MEMDB || pagerFlushOnCommit(pPager, bCommit) ){
53803 }else{
53805 }
53806 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
53807 }
53808
53809 if( pagerUseWal(pPager) ){
53810 /* Drop the WAL write-lock, if any. Also, if the connection was in
53811 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
53812 ** lock held on the database file.
53813 */
53814 rc2 = sqlite3WalEndWriteTransaction(pPager->pWal);
53815 assert( rc2==SQLITE_OK );
53816 }else if( rc==SQLITE_OK && bCommit && pPager->dbFileSize>pPager->dbSize ){
53817 /* This branch is taken when committing a transaction in rollback-journal
53818 ** mode if the database file on disk is larger than the database image.
53819 ** At this point the journal has been finalized and the transaction
53820 ** successfully committed, but the EXCLUSIVE lock is still held on the
53821 ** file. So it is safe to truncate the database file to its minimum
53822 ** required size. */
53823 assert( pPager->eLock==EXCLUSIVE_LOCK );
53824 rc = pager_truncate(pPager, pPager->dbSize);
53825 }
53826
53827 if( rc==SQLITE_OK && bCommit ){
53829 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
53830 }
53831
53832 if( !pPager->exclusiveMode
53833 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
53834 ){
53835 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
SQLITE_PRIVATE int sqlite3WalEndWriteTransaction(Wal *pWal)
Definition sqlite3.c:62620
#define PAGER_WRITER_LOCKED
Definition sqlite3.c:52055
SQLITE_PRIVATE DbPage * sqlite3PagerLookup(Pager *pPager, Pgno pgno)
Definition sqlite3.c:57362
SQLITE_PRIVATE int sqlite3WalExclusiveMode(Wal *pWal, int op)
Definition sqlite3.c:63292
SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *)
Definition sqlite3.c:49470
#define PAGER_JOURNALMODE_WAL
Definition sqlite3.c:14833
#define PAGER_JOURNALMODE_PERSIST
Definition sqlite3.c:14829
#define PAGER_JOURNALMODE_DELETE
Definition sqlite3.c:14828
SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file *, int)
Definition sqlite3.c:23060
#define PAGER_JOURNALMODE_TRUNCATE
Definition sqlite3.c:14831
SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *)
Definition sqlite3.c:57385
SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p)
Definition sqlite3.c:97487
#define pagerUseWal(x)
Definition sqlite3.c:52530
#define SQLITE_FCNTL_COMMIT_PHASETWO
Definition sqlite3.c:2199
SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *)
Definition sqlite3.c:49459
static int zeroJournalHdr(Pager *pPager, int doTruncate)
Definition sqlite3.c:53086
#define PAGER_ERROR
Definition sqlite3.c:52059
static int pager_truncate(Pager *pPager, Pgno nPage)
Definition sqlite3.c:54297
SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *, Pgno x)
Definition sqlite3.c:49515
SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file *, i64 size)
Definition sqlite3.c:23057
SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec *)
Definition sqlite3.c:48736
static void releaseAllSavepoints(Pager *pPager)
Definition sqlite3.c:53465
SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *)
Definition sqlite3.c:49651
#define EXCLUSIVE_LOCK
Definition sqlite3.c:16363
static int pagerFlushOnCommit(Pager *pPager, int bCommit)
Definition sqlite3.c:53647
Pgno dbFileSize
Definition sqlite3.c:52354
Wal * pWal
Definition sqlite3.c:52399
int nRec
Definition sqlite3.c:52357
Bitvec * pInJournal
Definition sqlite3.c:52360
u8 extraSync
Definition sqlite3.c:52327
u8 fullSync
Definition sqlite3.c:52326
u8 syncFlags
Definition sqlite3.c:52328
u8 eLock
Definition sqlite3.c:52345

References Pager::dbFileSize, Pager::dbSize, Pager::eLock, Pager::eState, EXCLUSIVE_LOCK, Pager::exclusiveMode, Pager::extraSync, Pager::fd, Pager::fullSync, isOpen, Pager::jfd, Pager::journalMode, Pager::journalOff, MEMDB, Pager::nRec, PAGER_ERROR, PAGER_JOURNALMODE_DELETE, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_PERSIST, PAGER_JOURNALMODE_TRUNCATE, PAGER_JOURNALMODE_WAL, PAGER_READER, pager_set_pagehash, pager_truncate(), PAGER_WRITER_LOCKED, pagerFlushOnCommit(), pagerUnlockDb(), pagerUseWal, Pager::pInJournal, Pager::pPCache, Pager::pVfs, Pager::pWal, releaseAllSavepoints(), RESERVED_LOCK, Pager::setSuper, SHARED_LOCK, sqlite3BitvecDestroy(), sqlite3JournalIsInMemory(), sqlite3OsClose(), sqlite3OsDelete(), sqlite3OsDeviceCharacteristics(), sqlite3OsFileControl(), sqlite3OsSync(), sqlite3OsTruncate(), sqlite3PagerLookup(), sqlite3PagerUnrefNotNull(), sqlite3PcacheCleanAll(), sqlite3PcacheClearWritable(), sqlite3PcacheRefCount(), sqlite3PcacheTruncate(), sqlite3WalEndWriteTransaction(), sqlite3WalExclusiveMode(), SQLITE_FCNTL_COMMIT_PHASETWO, SQLITE_IOCAP_BATCH_ATOMIC, SQLITE_NOTFOUND, SQLITE_OK, Pager::syncFlags, Pager::tempFile, zeroJournalHdr(), and Pager::zJournal.

Referenced by pager_playback(), pagerUnlockAndRollback(), sqlite3PagerCommitPhaseTwo(), and sqlite3PagerRollback().

◆ pager_error()

static int pager_error ( Pager * pPager,
int rc )
static

Definition at line 53613 of file sqlite3.c.

53619 {
53620 int rc2 = rc & 0xff;
53621 assert( rc==SQLITE_OK || !MEMDB );
53622 assert(
53623 pPager->errCode==SQLITE_FULL ||
53624 pPager->errCode==SQLITE_OK ||
53625 (pPager->errCode & 0xff)==SQLITE_IOERR
53626 );
53627 if( rc2==SQLITE_FULL || rc2==SQLITE_IOERR ){

References Pager::errCode, Pager::eState, MEMDB, PAGER_ERROR, setGetterMethod(), SQLITE_FULL, SQLITE_IOERR, and SQLITE_OK.

Referenced by pagerStress(), sqlite3PagerClose(), sqlite3PagerCommitPhaseTwo(), sqlite3PagerRollback(), and sqlite3PagerSharedLock().

◆ pager_incr_changecounter()

static int pager_incr_changecounter ( Pager * pPager,
int isDirectMode )
static

Definition at line 57916 of file sqlite3.c.

57922 {
57923 int rc = SQLITE_OK;
57924
57925 assert( pPager->eState==PAGER_WRITER_CACHEMOD
57926 || pPager->eState==PAGER_WRITER_DBMOD
57927 );
57928 assert( assert_pager_state(pPager) );
57929
57930 /* Declare and initialize constant integer 'isDirect'. If the
57931 ** atomic-write optimization is enabled in this build, then isDirect
57932 ** is initialized to the value passed as the isDirectMode parameter
57933 ** to this function. Otherwise, it is always set to zero.
57934 **
57935 ** The idea is that if the atomic-write optimization is not
57936 ** enabled at compile time, the compiler can omit the tests of
57937 ** 'isDirect' below, as well as the block enclosed in the
57938 ** "if( isDirect )" condition.
57939 */
57940#ifndef SQLITE_ENABLE_ATOMIC_WRITE
57941# define DIRECT_MODE 0
57942 assert( isDirectMode==0 );
57943 UNUSED_PARAMETER(isDirectMode);
57944#else
57945# define DIRECT_MODE isDirectMode
57946#endif
57947
57948 if( !pPager->changeCountDone && ALWAYS(pPager->dbSize>0) ){
57949 PgHdr *pPgHdr; /* Reference to page 1 */
57950
57951 assert( !pPager->tempFile && isOpen(pPager->fd) );
57952
57953 /* Open page 1 of the file for writing. */
57954 rc = sqlite3PagerGet(pPager, 1, &pPgHdr, 0);
57955 assert( pPgHdr==0 || rc==SQLITE_OK );
57956
57957 /* If page one was fetched successfully, and this function is not
57958 ** operating in direct-mode, make page 1 writable. When not in
57959 ** direct mode, page 1 is always held in cache and hence the PagerGet()
57960 ** above is always successful - hence the ALWAYS on rc==SQLITE_OK.
57961 */
57962 if( !DIRECT_MODE && ALWAYS(rc==SQLITE_OK) ){
57963 rc = sqlite3PagerWrite(pPgHdr);
57964 }
57965
57966 if( rc==SQLITE_OK ){
57967 /* Actually do the update of the change counter */
57969
57970 /* If running in direct mode, write the contents of page 1 to the file. */
57971 if( DIRECT_MODE ){
57972 const void *zBuf;
57973 assert( pPager->dbFileSize>0 );
57974 zBuf = pPgHdr->pData;
57975 if( rc==SQLITE_OK ){
57976 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
57977 pPager->aStat[PAGER_STAT_WRITE]++;
57978 }
57979 if( rc==SQLITE_OK ){
57980 /* Update the pager's copy of the change-counter. Otherwise, the
57981 ** next time a read transaction is opened the cache will be
57982 ** flushed (as the change-counter values will not match). */
57983 const void *pCopy = (const void *)&((const char *)zBuf)[24];
57984 memcpy(&pPager->dbFileVers, pCopy, sizeof(pPager->dbFileVers));
57985 pPager->changeCountDone = 1;
57986 }
57987 }else{
57988 pPager->changeCountDone = 1;
57989 }
57990 }
#define DIRECT_MODE
#define PAGER_STAT_WRITE
Definition sqlite3.c:52411
#define PAGER_WRITER_CACHEMOD
Definition sqlite3.c:52056
#define PAGER_WRITER_DBMOD
Definition sqlite3.c:52057
static void pager_write_changecounter(PgHdr *pPg)
Definition sqlite3.c:54714
u8 changeCountDone
Definition sqlite3.c:52346
char dbFileVers[16]
Definition sqlite3.c:52370
void * pData
Definition sqlite3.c:16046

References ALWAYS, Pager::aStat, Pager::changeCountDone, Pager::dbFileSize, Pager::dbFileVers, Pager::dbSize, DIRECT_MODE, Pager::eState, Pager::fd, isOpen, PAGER_STAT_WRITE, pager_write_changecounter(), PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, Pager::pageSize, PgHdr::pData, sqlite3OsWrite(), sqlite3PagerGet(), sqlite3PagerUnref(), sqlite3PagerWrite(), SQLITE_OK, Pager::tempFile, and UNUSED_PARAMETER.

Referenced by sqlite3PagerCommitPhaseOne().

◆ pager_open_journal()

static int pager_open_journal ( Pager * pPager)
static

Definition at line 57432 of file sqlite3.c.

57438 {
57439 int rc = SQLITE_OK; /* Return code */
57440 sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
57441
57442 assert( pPager->eState==PAGER_WRITER_LOCKED );
57443 assert( assert_pager_state(pPager) );
57444 assert( pPager->pInJournal==0 );
57445
57446 /* If already in the error state, this function is a no-op. But on
57447 ** the other hand, this routine is never called if we are already in
57448 ** an error state. */
57449 if( NEVER(pPager->errCode) ) return pPager->errCode;
57450
57451 if( !pagerUseWal(pPager) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
57452 pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
57453 if( pPager->pInJournal==0 ){
57454 return SQLITE_NOMEM_BKPT;
57455 }
57456
57457 /* Open the journal file if it is not already open. */
57458 if( !isOpen(pPager->jfd) ){
57460 sqlite3MemJournalOpen(pPager->jfd);
57461 }else{
57463 int nSpill;
57464
57465 if( pPager->tempFile ){
57467 nSpill = sqlite3Config.nStmtSpill;
57468 }else{
57469 flags |= SQLITE_OPEN_MAIN_JOURNAL;
57470 nSpill = jrnlBufferSize(pPager);
57471 }
57472
57473 /* Verify that the database still has the same name as it did when
57474 ** it was originally opened. */
57475 rc = databaseIsUnmoved(pPager);
57476 if( rc==SQLITE_OK ){
57477 rc = sqlite3JournalOpen (
57478 pVfs, pPager->zJournal, pPager->jfd, flags, nSpill
57479 );
57480 }
57481 }
57482 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
57483 }
57484
57485
57486 /* Write the first journal header to the journal file and open
57487 ** the sub-journal if necessary.
57488 */
57489 if( rc==SQLITE_OK ){
57490 /* TODO: Check if all of these are really required. */
57491 pPager->nRec = 0;
57492 pPager->journalOff = 0;
57493 pPager->setSuper = 0;
57494 pPager->journalHdr = 0;
57495 rc = writeJournalHdr(pPager);
57496 }
57497 }
57498
57499 if( rc!=SQLITE_OK ){
57501 pPager->pInJournal = 0;
57502 }else{
static int writeJournalHdr(Pager *pPager)
Definition sqlite3.c:53136
#define PAGER_JOURNALMODE_OFF
Definition sqlite3.c:14830
static int databaseIsUnmoved(Pager *pPager)
Definition sqlite3.c:55751
static int jrnlBufferSize(Pager *pPager)
Definition sqlite3.c:52892
SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int)
Definition sqlite3.c:97412
SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *)
Definition sqlite3.c:97448
u8 setSuper
Definition sqlite3.c:52347
i64 journalHdr
Definition sqlite3.c:52365

References databaseIsUnmoved(), Pager::dbSize, Pager::errCode, Pager::eState, isOpen, Pager::jfd, Pager::journalHdr, Pager::journalMode, Pager::journalOff, jrnlBufferSize(), NEVER, Pager::nRec, Sqlite3Config::nStmtSpill, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_OFF, PAGER_WRITER_CACHEMOD, PAGER_WRITER_LOCKED, pagerUseWal, Pager::pInJournal, Pager::pVfs, Pager::setSuper, sqlite3BitvecCreate(), sqlite3BitvecDestroy(), sqlite3Config, sqlite3JournalOpen(), sqlite3MemJournalOpen(), SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_READWRITE, SQLITE_OPEN_TEMP_JOURNAL, Pager::tempFile, writeJournalHdr(), and Pager::zJournal.

Referenced by pager_write().

◆ pager_playback()

static int pager_playback ( Pager * pPager,
int isHot )
static

Definition at line 54440 of file sqlite3.c.

54446 {
54447 sqlite3_vfs *pVfs = pPager->pVfs;
54448 i64 szJ; /* Size of the journal file in bytes */
54449 u32 nRec; /* Number of Records in the journal */
54450 u32 u; /* Unsigned loop counter */
54451 Pgno mxPg = 0; /* Size of the original file in pages */
54452 int rc; /* Result code of a subroutine */
54453 int res = 1; /* Value returned by sqlite3OsAccess() */
54454 char *zSuper = 0; /* Name of super-journal file if any */
54455 int needPagerReset; /* True to reset page prior to first page rollback */
54456 int nPlayback = 0; /* Total number of pages restored from journal */
54457 u32 savedPageSize = pPager->pageSize;
54458
54459 /* Figure out how many records are in the journal. Abort early if
54460 ** the journal is empty.
54461 */
54462 assert( isOpen(pPager->jfd) );
54463 rc = sqlite3OsFileSize(pPager->jfd, &szJ);
54464 if( rc!=SQLITE_OK ){
54465 goto end_playback;
54466 }
54467
54468 /* Read the super-journal name from the journal, if it is present.
54469 ** If a super-journal file name is specified, but the file is not
54470 ** present on disk, then the journal is not hot and does not need to be
54471 ** played back.
54472 **
54473 ** TODO: Technically the following is an error because it assumes that
54474 ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
54475 ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
54476 ** mxPathname is 512, which is the same as the minimum allowable value
54477 ** for pageSize.
54478 */
54479 zSuper = pPager->pTmpSpace;
54480 rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
54481 if( rc==SQLITE_OK && zSuper[0] ){
54482 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
54483 }
54484 zSuper = 0;
54485 if( rc!=SQLITE_OK || !res ){
54486 goto end_playback;
54487 }
54488 pPager->journalOff = 0;
54489 needPagerReset = isHot;
54490
54491 /* This loop terminates either when a readJournalHdr() or
54492 ** pager_playback_one_page() call returns SQLITE_DONE or an IO error
54493 ** occurs.
54494 */
54495 while( 1 ){
54496 /* Read the next journal header from the journal file. If there are
54497 ** not enough bytes left in the journal file for a complete header, or
54498 ** it is corrupted, then a process must have failed while writing it.
54499 ** This indicates nothing more needs to be rolled back.
54500 */
54501 rc = readJournalHdr(pPager, isHot, szJ, &nRec, &mxPg);
54502 if( rc!=SQLITE_OK ){
54503 if( rc==SQLITE_DONE ){
54504 rc = SQLITE_OK;
54505 }
54506 goto end_playback;
54507 }
54508
54509 /* If nRec is 0xffffffff, then this journal was created by a process
54510 ** working in no-sync mode. This means that the rest of the journal
54511 ** file consists of pages, there are no more journal headers. Compute
54512 ** the value of nRec based on this assumption.
54513 */
54514 if( nRec==0xffffffff ){
54515 assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) );
54516 nRec = (int)((szJ - JOURNAL_HDR_SZ(pPager))/JOURNAL_PG_SZ(pPager));
54517 }
54518
54519 /* If nRec is 0 and this rollback is of a transaction created by this
54520 ** process and if this is the final header in the journal, then it means
54521 ** that this part of the journal was being filled but has not yet been
54522 ** synced to disk. Compute the number of pages based on the remaining
54523 ** size of the file.
54524 **
54525 ** The third term of the test was added to fix ticket #2565.
54526 ** When rolling back a hot journal, nRec==0 always means that the next
54527 ** chunk of the journal contains zero pages to be rolled back. But
54528 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
54529 ** the journal, it means that the journal might contain additional
54530 ** pages that need to be rolled back and that the number of pages
54531 ** should be computed based on the journal file size.
54532 */
54533 if( nRec==0 && !isHot &&
54534 pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
54535 nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
54536 }
54537
54538 /* If this is the first header read from the journal, truncate the
54539 ** database file back to its original size.
54540 */
54541 if( pPager->journalOff==JOURNAL_HDR_SZ(pPager) ){
54542 rc = pager_truncate(pPager, mxPg);
54543 if( rc!=SQLITE_OK ){
54544 goto end_playback;
54545 }
54546 pPager->dbSize = mxPg;
54547 }
54548
54549 /* Copy original pages out of the journal and back into the
54550 ** database file and/or page cache.
54551 */
54552 for(u=0; u<nRec; u++){
54553 if( needPagerReset ){
54554 pager_reset(pPager);
54555 needPagerReset = 0;
54556 }
54557 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
54558 if( rc==SQLITE_OK ){
54559 nPlayback++;
54560 }else{
54561 if( rc==SQLITE_DONE ){
54562 pPager->journalOff = szJ;
54563 break;
54564 }else if( rc==SQLITE_IOERR_SHORT_READ ){
54565 /* If the journal has been truncated, simply stop reading and
54566 ** processing the journal. This might happen if the journal was
54567 ** not completely written and synced prior to a crash. In that
54568 ** case, the database should have never been written in the
54569 ** first place so it is OK to simply abandon the rollback. */
54570 rc = SQLITE_OK;
54571 goto end_playback;
54572 }else{
54573 /* If we are unable to rollback, quit and return the error
54574 ** code. This will cause the pager to enter the error state
54575 ** so that no further harm will be done. Perhaps the next
54576 ** process to come along will be able to rollback the database.
54577 */
54578 goto end_playback;
54579 }
54580 }
54581 }
54582 }
54583 /*NOTREACHED*/
54584 assert( 0 );
54585
54586end_playback:
54587 if( rc==SQLITE_OK ){
54588 rc = sqlite3PagerSetPagesize(pPager, &savedPageSize, -1);
54589 }
54590 /* Following a rollback, the database file should be back in its original
54591 ** state prior to the start of the transaction, so invoke the
54592 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
54593 ** assertion that the transaction counter was modified.
54594 */
54595#ifdef SQLITE_DEBUG
54597#endif
54598
54599 /* If this playback is happening automatically as a result of an IO or
54600 ** malloc error that occurred after the change-counter was updated but
54601 ** before the transaction was committed, then the change-counter
54602 ** modification may just have been reverted. If this happens in exclusive
54603 ** mode, then subsequent transactions performed by the connection will not
54604 ** update the change-counter at all. This may lead to cache inconsistency
54605 ** problems for other processes at some point in the future. So, just
54606 ** in case this has happened, clear the changeCountDone flag now.
54607 */
54608 pPager->changeCountDone = pPager->tempFile;
54609
54610 if( rc==SQLITE_OK ){
54611 zSuper = pPager->pTmpSpace;
54612 rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
54613 testcase( rc!=SQLITE_OK );
54614 }
54615 if( rc==SQLITE_OK
54616 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
54617 ){
54618 rc = sqlite3PagerSync(pPager, 0);
54619 }
54620 if( rc==SQLITE_OK ){
54621 rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
54622 testcase( rc!=SQLITE_OK );
54623 }
54624 if( rc==SQLITE_OK && zSuper[0] && res ){
54625 /* If there was a super-journal and this routine will return success,
54626 ** see if it is possible to delete the super-journal.
54627 */
54628 rc = pager_delsuper(pPager, zSuper);
54629 testcase( rc!=SQLITE_OK );
54630 }
54631 if( isHot && nPlayback ){
54632 sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
54633 nPlayback, pPager->zJournal);
54634 }
54635
54636 /* The Pager.sectorSize variable may have been updated while rolling
static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit)
Definition sqlite3.c:53707
static int readJournalHdr(Pager *pPager, int isHot, i64 journalSize, u32 *pNRec, u32 *pDbSize)
Definition sqlite3.c:53254
#define SQLITE_FCNTL_DB_UNCHANGED
Definition sqlite3.c:16448
#define JOURNAL_PG_SZ(pPager)
Definition sqlite3.c:52461
SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *, int, void *)
Definition sqlite3.c:23109
static void pager_reset(Pager *pPager)
Definition sqlite3.c:53447
SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper)
Definition sqlite3.c:57999
static int pager_playback_one_page(Pager *pPager, i64 *pOffset, Bitvec *pDone, int isMainJrnl, int isSavepnt)
Definition sqlite3.c:53935
#define SQLITE_NOTICE_RECOVER_ROLLBACK
Definition sqlite3.c:1588
char * pTmpSpace
Definition sqlite3.c:52396

References Pager::changeCountDone, Pager::dbSize, Pager::eState, Pager::fd, isOpen, Pager::jfd, JOURNAL_HDR_SZ, JOURNAL_PG_SZ, Pager::journalHdr, Pager::journalOff, sqlite3_vfs::mxPathname, pager_delsuper(), pager_end_transaction(), PAGER_OPEN, pager_playback_one_page(), pager_reset(), pager_truncate(), PAGER_WRITER_DBMOD, Pager::pageSize, Pager::pTmpSpace, Pager::pVfs, readJournalHdr(), readSuperJournal(), setSectorSize(), sqlite3_log(), sqlite3OsAccess(), sqlite3OsFileControlHint(), sqlite3OsFileSize(), sqlite3PagerSetPagesize(), sqlite3PagerSync(), SQLITE_ACCESS_EXISTS, SQLITE_DONE, SQLITE_FCNTL_DB_UNCHANGED, SQLITE_IOERR_SHORT_READ, SQLITE_NOTICE_RECOVER_ROLLBACK, SQLITE_OK, Pager::tempFile, testcase, and Pager::zJournal.

Referenced by sqlite3PagerRollback(), and sqlite3PagerSharedLock().

◆ pager_playback_one_page()

static int pager_playback_one_page ( Pager * pPager,
i64 * pOffset,
Bitvec * pDone,
int isMainJrnl,
int isSavepnt )
static

Definition at line 53935 of file sqlite3.c.

53947 {
53948 int rc;
53949 PgHdr *pPg; /* An existing page in the cache */
53950 Pgno pgno; /* The page number of a page in journal */
53951 u32 cksum; /* Checksum used for sanity checking */
53952 char *aData; /* Temporary storage for the page */
53953 sqlite3_file *jfd; /* The file descriptor for the journal file */
53954 int isSynced; /* True if journal page is synced */
53955
53956 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
53957 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
53958 assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
53959 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
53960
53961 aData = pPager->pTmpSpace;
53962 assert( aData ); /* Temp storage must have already been allocated */
53963 assert( pagerUseWal(pPager)==0 || (!isMainJrnl && isSavepnt) );
53964
53965 /* Either the state is greater than PAGER_WRITER_CACHEMOD (a transaction
53966 ** or savepoint rollback done at the request of the caller) or this is
53967 ** a hot-journal rollback. If it is a hot-journal rollback, the pager
53968 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
53969 ** only reads from the main journal, not the sub-journal.
53970 */
53971 assert( pPager->eState>=PAGER_WRITER_CACHEMOD
53972 || (pPager->eState==PAGER_OPEN && pPager->eLock==EXCLUSIVE_LOCK)
53973 );
53974 assert( pPager->eState>=PAGER_WRITER_CACHEMOD || isMainJrnl );
53975
53976 /* Read the page number and page data from the journal or sub-journal
53977 ** file. Return an error code to the caller if an IO error occurs.
53978 */
53979 jfd = isMainJrnl ? pPager->jfd : pPager->sjfd;
53980 rc = read32bits(jfd, *pOffset, &pgno);
53981 if( rc!=SQLITE_OK ) return rc;
53982 rc = sqlite3OsRead(jfd, (u8*)aData, pPager->pageSize, (*pOffset)+4);
53983 if( rc!=SQLITE_OK ) return rc;
53984 *pOffset += pPager->pageSize + 4 + isMainJrnl*4;
53985
53986 /* Sanity checking on the page. This is more important that I originally
53987 ** thought. If a power failure occurs while the journal is being written,
53988 ** it could cause invalid data to be written into the journal. We need to
53989 ** detect this invalid data (with high probability) and ignore it.
53990 */
53991 if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
53992 assert( !isSavepnt );
53993 return SQLITE_DONE;
53994 }
53995 if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){
53996 return SQLITE_OK;
53997 }
53998 if( isMainJrnl ){
53999 rc = read32bits(jfd, (*pOffset)-4, &cksum);
54000 if( rc ) return rc;
54001 if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
54002 return SQLITE_DONE;
54003 }
54004 }
54005
54006 /* If this page has already been played back before during the current
54007 ** rollback, then don't bother to play it back again.
54008 */
54009 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
54010 return rc;
54011 }
54012
54013 /* When playing back page 1, restore the nReserve setting
54014 */
54015 if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
54016 pPager->nReserve = ((u8*)aData)[20];
54017 }
54018
54019 /* If the pager is in CACHEMOD state, then there must be a copy of this
54020 ** page in the pager cache. In this case just update the pager cache,
54021 ** not the database file. The page is left marked dirty in this case.
54022 **
54023 ** An exception to the above rule: If the database is in no-sync mode
54024 ** and a page is moved during an incremental vacuum then the page may
54025 ** not be in the pager cache. Later: if a malloc() or IO error occurs
54026 ** during a Movepage() call, then the page may not be in the cache
54027 ** either. So the condition described in the above paragraph is not
54028 ** assert()able.
54029 **
54030 ** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
54031 ** pager cache if it exists and the main file. The page is then marked
54032 ** not dirty. Since this code is only executed in PAGER_OPEN state for
54033 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
54034 ** if the pager is in OPEN state.
54035 **
54036 ** Ticket #1171: The statement journal might contain page content that is
54037 ** different from the page content at the start of the transaction.
54038 ** This occurs when a page is changed prior to the start of a statement
54039 ** then changed again within the statement. When rolling back such a
54040 ** statement we must not write to the original database unless we know
54041 ** for certain that original page contents are synced into the main rollback
54042 ** journal. Otherwise, a power loss might leave modified data in the
54043 ** database file without an entry in the rollback journal that can
54044 ** restore the database to its original form. Two conditions must be
54045 ** met before writing to the database files. (1) the database must be
54046 ** locked. (2) we know that the original page content is fully synced
54047 ** in the main journal either because the page is not in cache or else
54048 ** the page is marked as needSync==0.
54049 **
54050 ** 2008-04-14: When attempting to vacuum a corrupt database file, it
54051 ** is possible to fail a statement on a database that does not yet exist.
54052 ** Do not attempt to write if database file has never been opened.
54053 */
54054 if( pagerUseWal(pPager) ){
54055 pPg = 0;
54056 }else{
54057 pPg = sqlite3PagerLookup(pPager, pgno);
54058 }
54059 assert( pPg || !MEMDB );
54060 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
54061 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
54062 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
54063 (isMainJrnl?"main-journal":"sub-journal")
54064 ));
54065 if( isMainJrnl ){
54066 isSynced = pPager->noSync || (*pOffset <= pPager->journalHdr);
54067 }else{
54068 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
54069 }
54070 if( isOpen(pPager->fd)
54071 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
54072 && isSynced
54073 ){
54074 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
54075 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
54076 assert( !pagerUseWal(pPager) );
54077
54078 /* Write the data read from the journal back into the database file.
54079 ** This is usually safe even for an encrypted database - as the data
54080 ** was encrypted before it was written to the journal file. The exception
54081 ** is if the data was just read from an in-memory sub-journal. In that
54082 ** case it must be encrypted here before it is copied into the database
54083 ** file. */
54084 rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
54085
54086 if( pgno>pPager->dbFileSize ){
54087 pPager->dbFileSize = pgno;
54088 }
54089 if( pPager->pBackup ){
54090 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
54091 }
54092 }else if( !isMainJrnl && pPg==0 ){
54093 /* If this is a rollback of a savepoint and data was not written to
54094 ** the database and the page is not in-memory, there is a potential
54095 ** problem. When the page is next fetched by the b-tree layer, it
54096 ** will be read from the database file, which may or may not be
54097 ** current.
54098 **
54099 ** There are a couple of different ways this can happen. All are quite
54100 ** obscure. When running in synchronous mode, this can only happen
54101 ** if the page is on the free-list at the start of the transaction, then
54102 ** populated, then moved using sqlite3PagerMovepage().
54103 **
54104 ** The solution is to add an in-memory page to the cache containing
54105 ** the data just read from the sub-journal. Mark the page as dirty
54106 ** and if the pager requires a journal-sync, then mark the page as
54107 ** requiring a journal-sync before it is written.
54108 */
54109 assert( isSavepnt );
54110 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 );
54111 pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
54112 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
54113 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
54114 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
54115 if( rc!=SQLITE_OK ) return rc;
54117 }
54118 if( pPg ){
54119 /* No page should ever be explicitly rolled back that is in use, except
54120 ** for page 1 which is held in use in order to keep the lock on the
54121 ** database active. However such a page may be rolled back as a result
54122 ** of an internal error resulting in an automatic call to
54123 ** sqlite3PagerRollback().
54124 */
54125 void *pData;
54126 pData = pPg->pData;
54127 memcpy(pData, (u8*)aData, pPager->pageSize);
54128 pPager->xReiniter(pPg);
54129 /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
54130 ** that call was dangerous and had no detectable benefit since the cache
54131 ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
54132 ** has been removed. */
54133 pager_set_pagehash(pPg);
54134
54135 /* If this was page 1, then restore the value of Pager.dbFileVers.
54136 ** Do this before any decoding. */
54137 if( pgno==1 ){
#define SPILLFLAG_ROLLBACK
Definition sqlite3.c:52149
#define PGHDR_NEED_SYNC
Definition sqlite3.c:16073
#define pager_datahash(X, Y)
Definition sqlite3.c:52966
SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *)
Definition sqlite3.c:75740
static int read32bits(sqlite3_file *fd, i64 offset, u32 *pRes)
Definition sqlite3.c:52797
#define PAGERID(p)
Definition sqlite3.c:51833
static u32 pager_cksum(Pager *pPager, const u8 *aData)
Definition sqlite3.c:53888
SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec *, u32)
Definition sqlite3.c:48612
#define PAGERTRACE(X)
Definition sqlite3.c:51822
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *)
Definition sqlite3.c:49423
u8 doNotSpill
Definition sqlite3.c:52348
i16 nReserve
Definition sqlite3.c:52380
void(* xReiniter)(DbPage *)
Definition sqlite3.c:52394
sqlite3_backup * pBackup
Definition sqlite3.c:52366
u8 noSync
Definition sqlite3.c:52325

References Pager::dbFileSize, Pager::dbFileVers, Pager::dbSize, Pager::doNotSpill, Pager::eLock, Pager::eState, EXCLUSIVE_LOCK, Pager::fd, PgHdr::flags, isOpen, Pager::jfd, Pager::journalHdr, MEMDB, Pager::noSync, Pager::nReserve, pager_cksum(), pager_datahash, PAGER_MJ_PGNO, PAGER_OPEN, pager_set_pagehash, PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, PAGERID, PAGERTRACE, pagerUseWal, Pager::pageSize, Pager::pBackup, PgHdr::pData, PGHDR_NEED_SYNC, Pager::pTmpSpace, read32bits(), Pager::sjfd, SPILLFLAG_ROLLBACK, sqlite3BackupUpdate(), sqlite3BitvecSet(), sqlite3BitvecTest(), sqlite3OsRead(), sqlite3OsWrite(), sqlite3PagerGet(), sqlite3PagerLookup(), sqlite3PcacheMakeDirty(), sqlite3PcacheRelease(), SQLITE_DONE, SQLITE_OK, Pager::tempFile, testcase, and Pager::xReiniter.

Referenced by pager_playback(), and pagerPlaybackSavepoint().

◆ pager_reset()

static void pager_reset ( Pager * pPager)
static

◆ pager_truncate()

static int pager_truncate ( Pager * pPager,
Pgno nPage )
static

Definition at line 54297 of file sqlite3.c.

54303 {
54304 int rc = SQLITE_OK;
54305 assert( pPager->eState!=PAGER_ERROR );
54306 assert( pPager->eState!=PAGER_READER );
54307
54308 if( isOpen(pPager->fd)
54309 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
54310 ){
54311 i64 currentSize, newSize;
54312 int szPage = pPager->pageSize;
54313 assert( pPager->eLock==EXCLUSIVE_LOCK );
54314 /* TODO: Is it safe to use Pager.dbFileSize here? */
54315 rc = sqlite3OsFileSize(pPager->fd, &currentSize);
54316 newSize = szPage*(i64)nPage;
54317 if( rc==SQLITE_OK && currentSize!=newSize ){
54318 if( currentSize>newSize ){
54319 rc = sqlite3OsTruncate(pPager->fd, newSize);
54320 }else if( (currentSize+szPage)<=newSize ){
54321 char *pTmp = pPager->pTmpSpace;
54322 memset(pTmp, 0, szPage);
54323 testcase( (newSize-szPage) == currentSize );
54324 testcase( (newSize-szPage) > currentSize );
54325 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
54326 }
54327 if( rc==SQLITE_OK ){

References Pager::dbFileSize, Pager::eLock, Pager::eState, EXCLUSIVE_LOCK, Pager::fd, isOpen, PAGER_ERROR, PAGER_OPEN, PAGER_READER, PAGER_WRITER_DBMOD, Pager::pageSize, Pager::pTmpSpace, sqlite3OsFileSize(), sqlite3OsTruncate(), sqlite3OsWrite(), SQLITE_OK, and testcase.

Referenced by pager_end_transaction(), pager_playback(), and sqlite3PagerCommitPhaseOne().

◆ pager_unlock()

static void pager_unlock ( Pager * pPager)
static

Definition at line 53516 of file sqlite3.c.

53522 {
53523
53524 assert( pPager->eState==PAGER_READER
53525 || pPager->eState==PAGER_OPEN
53526 || pPager->eState==PAGER_ERROR
53527 );
53528
53530 pPager->pInJournal = 0;
53531 releaseAllSavepoints(pPager);
53532
53533 if( pagerUseWal(pPager) ){
53534 assert( !isOpen(pPager->jfd) );
53536 pPager->eState = PAGER_OPEN;
53537 }else if( !pPager->exclusiveMode ){
53538 int rc; /* Error code returned by pagerUnlockDb() */
53539 int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
53540
53541 /* If the operating system support deletion of open files, then
53542 ** close the journal file when dropping the database lock. Otherwise
53543 ** another connection with journal_mode=delete might delete the file
53544 ** out from under us.
53545 */
53546 assert( (PAGER_JOURNALMODE_MEMORY & 5)!=1 );
53547 assert( (PAGER_JOURNALMODE_OFF & 5)!=1 );
53548 assert( (PAGER_JOURNALMODE_WAL & 5)!=1 );
53549 assert( (PAGER_JOURNALMODE_DELETE & 5)!=1 );
53550 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
53551 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
53553 || 1!=(pPager->journalMode & 5)
53554 ){
53555 sqlite3OsClose(pPager->jfd);
53556 }
53557
53558 /* If the pager is in the ERROR state and the call to unlock the database
53559 ** file fails, set the current lock to UNKNOWN_LOCK. See the comment
53560 ** above the #define for UNKNOWN_LOCK for an explanation of why this
53561 ** is necessary.
53562 */
53563 rc = pagerUnlockDb(pPager, NO_LOCK);
53564 if( rc!=SQLITE_OK && pPager->eState==PAGER_ERROR ){
53565 pPager->eLock = UNKNOWN_LOCK;
53566 }
53567
53568 /* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
53569 ** without clearing the error code. This is intentional - the error
53570 ** code is cleared and the cache reset in the block below.
53571 */
53572 assert( pPager->errCode || pPager->eState!=PAGER_ERROR );
53573 pPager->eState = PAGER_OPEN;
53574 }
53575
53576 /* If Pager.errCode is set, the contents of the pager cache cannot be
53577 ** trusted. Now that there are no outstanding references to the pager,
53578 ** it can safely move back to PAGER_OPEN state. This happens in both
53579 ** normal and exclusive-locking mode.
53580 */
53581 assert( pPager->errCode==SQLITE_OK || !MEMDB );
53582 if( pPager->errCode ){
53583 if( pPager->tempFile==0 ){
53584 pager_reset(pPager);
53585 pPager->changeCountDone = 0;
53586 pPager->eState = PAGER_OPEN;
53587 }else{
53588 pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
53589 }
53590 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
53591 pPager->errCode = SQLITE_OK;
53592 setGetterMethod(pPager);
SQLITE_PRIVATE void sqlite3WalEndReadTransaction(Wal *pWal)
Definition sqlite3.c:62411
#define USEFETCH(x)
Definition sqlite3.c:52488
#define UNKNOWN_LOCK
Definition sqlite3.c:52109
SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *)
Definition sqlite3.c:23157
static void setGetterMethod(Pager *pPager)
Definition sqlite3.c:52746

References Pager::changeCountDone, Pager::eLock, Pager::errCode, Pager::eState, Pager::exclusiveMode, Pager::fd, isOpen, Pager::jfd, Pager::journalHdr, Pager::journalMode, Pager::journalOff, MEMDB, NO_LOCK, PAGER_ERROR, PAGER_JOURNALMODE_DELETE, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_OFF, PAGER_JOURNALMODE_PERSIST, PAGER_JOURNALMODE_TRUNCATE, PAGER_JOURNALMODE_WAL, PAGER_OPEN, PAGER_READER, pager_reset(), pagerUnlockDb(), pagerUseWal, Pager::pInJournal, Pager::pWal, releaseAllSavepoints(), setGetterMethod(), Pager::setSuper, sqlite3BitvecDestroy(), sqlite3OsClose(), sqlite3OsDeviceCharacteristics(), sqlite3OsUnfetch(), sqlite3WalEndReadTransaction(), SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN, SQLITE_OK, Pager::tempFile, UNKNOWN_LOCK, and USEFETCH.

Referenced by pagerUnlockAndRollback(), sqlite3PagerClose(), sqlite3PagerSetJournalMode(), and sqlite3PagerSharedLock().

◆ pager_wait_on_lock()

static int pager_wait_on_lock ( Pager * pPager,
int locktype )
static

Definition at line 55563 of file sqlite3.c.

55569 {
55570 int rc; /* Return code */
55571
55572 /* Check that this is either a no-op (because the requested lock is
55573 ** already held), or one of the transitions that the busy-handler
55574 ** may be invoked during, according to the comment above
55575 ** sqlite3PagerSetBusyhandler().
55576 */
55577 assert( (pPager->eLock>=locktype)
55578 || (pPager->eLock==NO_LOCK && locktype==SHARED_LOCK)
55579 || (pPager->eLock==RESERVED_LOCK && locktype==EXCLUSIVE_LOCK)
55580 );

References Pager::eLock, EXCLUSIVE_LOCK, NO_LOCK, pagerLockDb(), Pager::pBusyHandlerArg, RESERVED_LOCK, SHARED_LOCK, SQLITE_BUSY, and Pager::xBusyHandler.

Referenced by sqlite3PagerBegin(), sqlite3PagerExclusiveLock(), and sqlite3PagerSharedLock().

◆ pager_write()

static int pager_write ( PgHdr * pPg)
static

Definition at line 57647 of file sqlite3.c.

57653 {
57654 Pager *pPager = pPg->pPager;
57655 int rc = SQLITE_OK;
57656
57657 /* This routine is not called unless a write-transaction has already
57658 ** been started. The journal file may or may not be open at this point.
57659 ** It is never called in the ERROR state.
57660 */
57661 assert( pPager->eState==PAGER_WRITER_LOCKED
57662 || pPager->eState==PAGER_WRITER_CACHEMOD
57663 || pPager->eState==PAGER_WRITER_DBMOD
57664 );
57665 assert( assert_pager_state(pPager) );
57666 assert( pPager->errCode==0 );
57667 assert( pPager->readOnly==0 );
57668 CHECK_PAGE(pPg);
57669
57670 /* The journal file needs to be opened. Higher level routines have already
57671 ** obtained the necessary locks to begin the write-transaction, but the
57672 ** rollback journal might not yet be open. Open it now if this is the case.
57673 **
57674 ** This is done before calling sqlite3PcacheMakeDirty() on the page.
57675 ** Otherwise, if it were done after calling sqlite3PcacheMakeDirty(), then
57676 ** an error might occur and the pager would end up in WRITER_LOCKED state
57677 ** with pages marked as dirty in the cache.
57678 */
57679 if( pPager->eState==PAGER_WRITER_LOCKED ){
57680 rc = pager_open_journal(pPager);
57681 if( rc!=SQLITE_OK ) return rc;
57682 }
57683 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
57684 assert( assert_pager_state(pPager) );
57685
57686 /* Mark the page that is about to be modified as dirty. */
57688
57689 /* If a rollback journal is in use, them make sure the page that is about
57690 ** to change is in the rollback journal, or if the page is a new page off
57691 ** then end of the file, make sure it is marked as PGHDR_NEED_SYNC.
57692 */
57693 assert( (pPager->pInJournal!=0) == isOpen(pPager->jfd) );
57694 if( pPager->pInJournal!=0
57695 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
57696 ){
57697 assert( pagerUseWal(pPager)==0 );
57698 if( pPg->pgno<=pPager->dbOrigSize ){
57700 if( rc!=SQLITE_OK ){
57701 return rc;
57702 }
57703 }else{
57704 if( pPager->eState!=PAGER_WRITER_DBMOD ){
57705 pPg->flags |= PGHDR_NEED_SYNC;
57706 }
57707 PAGERTRACE(("APPEND %d page %d needSync=%d\n",
57708 PAGERID(pPager), pPg->pgno,
57709 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
57710 }
57711 }
57712
57713 /* The PGHDR_DIRTY bit is set above when the page was added to the dirty-list
57714 ** and before writing the page into the rollback journal. Wait until now,
57715 ** after the page has been successfully journalled, before setting the
57716 ** PGHDR_WRITEABLE bit that indicates that the page can be safely modified.
57717 */
57718 pPg->flags |= PGHDR_WRITEABLE;
57719
57720 /* If the statement journal is open and the page is not in it,
57721 ** then write the page into the statement journal.
57722 */
57723 if( pPager->nSavepoint>0 ){
57724 rc = subjournalPageIfRequired(pPg);
57725 }
57726
static int subjournalPageIfRequired(PgHdr *pPg)
Definition sqlite3.c:56189
static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg)
Definition sqlite3.c:57590
SQLITE_PRIVATE int sqlite3BitvecTestNotNull(Bitvec *, u32)
Definition sqlite3.c:48589
static int pager_open_journal(Pager *pPager)
Definition sqlite3.c:57432
#define CHECK_PAGE(x)
Definition sqlite3.c:52969
#define PGHDR_WRITEABLE
Definition sqlite3.c:16072
Pgno dbOrigSize
Definition sqlite3.c:52353
u8 readOnly
Definition sqlite3.c:52332

References CHECK_PAGE, Pager::dbOrigSize, Pager::dbSize, Pager::errCode, Pager::eState, PgHdr::flags, isOpen, Pager::jfd, Pager::nSavepoint, pager_open_journal(), PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, PAGER_WRITER_LOCKED, pagerAddPageToRollbackJournal(), PAGERID, PAGERTRACE, pagerUseWal, PGHDR_NEED_SYNC, PGHDR_WRITEABLE, PgHdr::pgno, Pager::pInJournal, PgHdr::pPager, Pager::readOnly, sqlite3BitvecTestNotNull(), sqlite3PcacheMakeDirty(), SQLITE_OK, and subjournalPageIfRequired().

Referenced by pagerWriteLargeSector(), and sqlite3PagerWrite().

◆ pager_write_changecounter()

static void pager_write_changecounter ( PgHdr * pPg)
static

Definition at line 54714 of file sqlite3.c.

54720 {
54721 u32 change_counter;
54722
54723 /* Increment the value just read and write it back to byte 24. */
54724 change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1;
54725 put32bits(((char*)pPg->pData)+24, change_counter);
54726
SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *)
Definition sqlite3.c:32440
#define put32bits(A, B)
Definition sqlite3.c:52809

References Pager::dbFileVers, PgHdr::pData, PgHdr::pPager, put32bits, sqlite3Get4byte(), and SQLITE_VERSION_NUMBER.

Referenced by pager_incr_changecounter(), pager_write_pagelist(), and pagerWalFrames().

◆ pager_write_pagelist()

static int pager_write_pagelist ( Pager * pPager,
PgHdr * pList )
static

Definition at line 56036 of file sqlite3.c.

56042 {
56043 int rc = SQLITE_OK; /* Return code */
56044
56045 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
56046 assert( !pagerUseWal(pPager) );
56047 assert( pPager->tempFile || pPager->eState==PAGER_WRITER_DBMOD );
56048 assert( pPager->eLock==EXCLUSIVE_LOCK );
56049 assert( isOpen(pPager->fd) || pList->pDirty==0 );
56050
56051 /* If the file is a temp-file has not yet been opened, open it now. It
56052 ** is not possible for rc to be other than SQLITE_OK if this branch
56053 ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
56054 */
56055 if( !isOpen(pPager->fd) ){
56056 assert( pPager->tempFile && rc==SQLITE_OK );
56057 rc = pagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
56058 }
56059
56060 /* Before the first write, give the VFS a hint of what the final
56061 ** file size will be.
56062 */
56063 assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
56064 if( rc==SQLITE_OK
56065 && pPager->dbHintSize<pPager->dbSize
56066 && (pList->pDirty || pList->pgno>pPager->dbHintSize)
56067 ){
56068 sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
56070 pPager->dbHintSize = pPager->dbSize;
56071 }
56072
56073 while( rc==SQLITE_OK && pList ){
56074 Pgno pgno = pList->pgno;
56075
56076 /* If there are dirty pages in the page cache with page numbers greater
56077 ** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
56078 ** make the file smaller (presumably by auto-vacuum code). Do not write
56079 ** any such pages to the file.
56080 **
56081 ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
56082 ** set (set by sqlite3PagerDontWrite()).
56083 */
56084 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
56085 i64 offset = (pgno-1)*(i64)pPager->pageSize; /* Offset to write */
56086 char *pData; /* Data to write */
56087
56088 assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
56089 if( pList->pgno==1 ) pager_write_changecounter(pList);
56090
56091 pData = pList->pData;
56092
56093 /* Write out the page data. */
56094 rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
56095
56096 /* If page 1 was just written, update Pager.dbFileVers to match
56097 ** the value now stored in the database file. If writing this
56098 ** page caused the database file to grow, update dbFileSize.
56099 */
56100 if( pgno==1 ){
56101 memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers));
56102 }
56103 if( pgno>pPager->dbFileSize ){
56104 pPager->dbFileSize = pgno;
56105 }
56106 pPager->aStat[PAGER_STAT_WRITE]++;
56107
56108 /* Update any backup objects copying the contents of this pager. */
56109 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)pList->pData);
56110
56111 PAGERTRACE(("STORE %d page %d hash(%08x)\n",
56112 PAGERID(pPager), pgno, pager_pagehash(pList)));
56113 IOTRACE(("PGOUT %p %d\n", pPager, pgno));
56114 PAGER_INCR(sqlite3_pager_writedb_count);
56115 }else{
56116 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno));
56117 }
#define SQLITE_FCNTL_SIZE_HINT
Definition sqlite3.c:2183
#define PAGER_INCR(v)
Definition sqlite3.c:52425
#define pager_pagehash(X)
Definition sqlite3.c:52967
#define PGHDR_DONT_WRITE
Definition sqlite3.c:16074
static int pagerOpentemp(Pager *pPager, sqlite3_file *pFile, int vfsFlags)
Definition sqlite3.c:55302
u32 vfsFlags
Definition sqlite3.c:52381
Pgno dbHintSize
Definition sqlite3.c:52355
PgHdr * pDirty
Definition sqlite3.c:16049

References Pager::aStat, Pager::dbFileSize, Pager::dbFileVers, Pager::dbHintSize, Pager::dbSize, Pager::eLock, Pager::eState, EXCLUSIVE_LOCK, Pager::fd, PgHdr::flags, IOTRACE, isOpen, PAGER_INCR, pager_pagehash, pager_set_pagehash, PAGER_STAT_WRITE, pager_write_changecounter(), PAGER_WRITER_DBMOD, PAGERID, pagerOpentemp(), PAGERTRACE, pagerUseWal, Pager::pageSize, Pager::pBackup, PgHdr::pData, PgHdr::pDirty, PGHDR_DONT_WRITE, PGHDR_NEED_SYNC, PgHdr::pgno, sqlite3BackupUpdate(), sqlite3OsFileControlHint(), sqlite3OsWrite(), SQLITE_FCNTL_SIZE_HINT, SQLITE_OK, Pager::tempFile, and Pager::vfsFlags.

Referenced by pagerStress(), and sqlite3PagerCommitPhaseOne().

◆ pagerAddPageToRollbackJournal()

static SQLITE_NOINLINE int pagerAddPageToRollbackJournal ( PgHdr * pPg)
static

Definition at line 57590 of file sqlite3.c.

57596 {
57597 Pager *pPager = pPg->pPager;
57598 int rc;
57599 u32 cksum;
57600 char *pData2;
57601 i64 iOff = pPager->journalOff;
57602
57603 /* We should never write to the journal file the page that
57604 ** contains the database locks. The following assert verifies
57605 ** that we do not. */
57606 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
57607
57608 assert( pPager->journalHdr<=pPager->journalOff );
57609 pData2 = pPg->pData;
57610 cksum = pager_cksum(pPager, (u8*)pData2);
57611
57612 /* Even if an IO or diskfull error occurs while journalling the
57613 ** page in the block above, set the need-sync flag for the page.
57614 ** Otherwise, when the transaction is rolled back, the logic in
57615 ** playback_one_page() will think that the page needs to be restored
57616 ** in the database file. And if an IO error occurs while doing so,
57617 ** then corruption may follow.
57618 */
57619 pPg->flags |= PGHDR_NEED_SYNC;
57620
57621 rc = write32bits(pPager->jfd, iOff, pPg->pgno);
57622 if( rc!=SQLITE_OK ) return rc;
57623 rc = sqlite3OsWrite(pPager->jfd, pData2, pPager->pageSize, iOff+4);
57624 if( rc!=SQLITE_OK ) return rc;
57625 rc = write32bits(pPager->jfd, iOff+pPager->pageSize+4, cksum);
57626 if( rc!=SQLITE_OK ) return rc;
57627
57628 IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
57629 pPager->journalOff, pPager->pageSize));
57630 PAGER_INCR(sqlite3_pager_writej_count);
57631 PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
57632 PAGERID(pPager), pPg->pgno,
57633 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
57634
57635 pPager->journalOff += 8 + pPager->pageSize;
57636 pPager->nRec++;
57637 assert( pPager->pInJournal!=0 );
57638 rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
static int write32bits(sqlite3_file *fd, i64 offset, u32 val)
Definition sqlite3.c:52816

Referenced by pager_write().

◆ pagerBeginReadTransaction()

static int pagerBeginReadTransaction ( Pager * pPager)
static

Definition at line 54875 of file sqlite3.c.

54881 {
54882 int rc; /* Return code */
54883 int changed = 0; /* True if cache must be reset */
54884
54885 assert( pagerUseWal(pPager) );
54886 assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
54887
54888 /* sqlite3WalEndReadTransaction() was not called for the previous
54889 ** transaction in locking_mode=EXCLUSIVE. So call it now. If we
54890 ** are in locking_mode=NORMAL and EndRead() was previously called,
54891 ** the duplicate call is harmless.
54892 */
54894
54895 rc = sqlite3WalBeginReadTransaction(pPager->pWal, &changed);
54896 if( rc!=SQLITE_OK || changed ){
SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *)
Definition sqlite3.c:62303

References Pager::eState, Pager::fd, PAGER_OPEN, PAGER_READER, pager_reset(), pagerUseWal, Pager::pWal, sqlite3OsUnfetch(), sqlite3WalBeginReadTransaction(), sqlite3WalEndReadTransaction(), SQLITE_OK, and USEFETCH.

Referenced by sqlite3PagerSharedLock().

◆ pageReinit()

static void pageReinit ( DbPage * pData)
static

Definition at line 66759 of file sqlite3.c.

66765 {
66766 MemPage *pPage;
66767 pPage = (MemPage *)sqlite3PagerGetExtra(pData);
66768 assert( sqlite3PagerPageRefcount(pData)>0 );
66769 if( pPage->isInit ){
66770 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
66771 pPage->isInit = 0;
66772 if( sqlite3PagerPageRefcount(pData)>1 ){
66773 /* pPage might not be a btree page; it might be an overflow page
66774 ** or ptrmap page or a free page. In those cases, the following
66775 ** call to btreeInitPage() will likely return SQLITE_CORRUPT.
66776 ** But no harm is done by this. And it is very important that

References btreeInitPage(), MemPage::isInit, BtShared::mutex, MemPage::pBt, sqlite3_mutex_held(), sqlite3PagerGetExtra(), and sqlite3PagerPageRefcount().

Referenced by sqlite3BtreeOpen().

◆ pagerExclusiveLock()

static int pagerExclusiveLock ( Pager * pPager)
static

Definition at line 59133 of file sqlite3.c.

59139 {
59140 int rc; /* Return code */
59141
59142 assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
59143 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
59144 if( rc!=SQLITE_OK ){
59145 /* If the attempt to grab the exclusive lock failed, release the

Referenced by pagerOpenWal(), and sqlite3PagerCloseWal().

◆ pagerFixMaplimit()

static void pagerFixMaplimit ( Pager * pPager)
static

Definition at line 55162 of file sqlite3.c.

55168 {
55169#if SQLITE_MAX_MMAP_SIZE>0
55170 sqlite3_file *fd = pPager->fd;
55171 if( isOpen(fd) && fd->pMethods->iVersion>=3 ){
55172 sqlite3_int64 sz;
55173 sz = pPager->szMmap;
sqlite3_int64 szMmap
Definition sqlite3.c:52373
const struct sqlite3_io_methods * pMethods
Definition sqlite3.c:1733

Referenced by pagerOpenWal(), sqlite3PagerCloseWal(), and sqlite3PagerSetPagesize().

◆ pagerFlushOnCommit()

static int pagerFlushOnCommit ( Pager * pPager,
int bCommit )
static

◆ pagerFreeMapHdrs()

static void pagerFreeMapHdrs ( Pager * pPager)
static

Definition at line 55737 of file sqlite3.c.

55743 {
55744 PgHdr *p;

Referenced by sqlite3PagerClose().

◆ pagerLockDb()

static int pagerLockDb ( Pager * pPager,
int eLock )
static

Definition at line 52859 of file sqlite3.c.

52865 {
52866 int rc = SQLITE_OK;
52867
52868 assert( eLock==SHARED_LOCK || eLock==RESERVED_LOCK || eLock==EXCLUSIVE_LOCK );
52869 if( pPager->eLock<eLock || pPager->eLock==UNKNOWN_LOCK ){
52870 rc = pPager->noLock ? SQLITE_OK : sqlite3OsLock(pPager->fd, eLock);
52871 if( rc==SQLITE_OK && (pPager->eLock!=UNKNOWN_LOCK||eLock==EXCLUSIVE_LOCK) ){
SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file *, int)
Definition sqlite3.c:23068
u8 noLock
Definition sqlite3.c:52331

References Pager::eLock, EXCLUSIVE_LOCK, Pager::fd, IOTRACE, Pager::noLock, RESERVED_LOCK, SHARED_LOCK, sqlite3OsLock(), SQLITE_OK, and UNKNOWN_LOCK.

Referenced by hasHotJournal(), pager_wait_on_lock(), sqlite3PagerBegin(), sqlite3PagerCloseWal(), sqlite3PagerSetJournalMode(), and sqlite3PagerSharedLock().

◆ pagerOpenSavepoint()

static SQLITE_NOINLINE int pagerOpenSavepoint ( Pager * pPager,
int nSavepoint )
static

Definition at line 58511 of file sqlite3.c.

58517 {
58518 int rc = SQLITE_OK; /* Return code */
58519 int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
58520 int ii; /* Iterator variable */
58521 PagerSavepoint *aNew; /* New Pager.aSavepoint array */
58522
58523 assert( pPager->eState>=PAGER_WRITER_LOCKED );
58524 assert( assert_pager_state(pPager) );
58525 assert( nSavepoint>nCurrent && pPager->useJournal );
58526
58527 /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
58528 ** if the allocation fails. Otherwise, zero the new portion in case a
58529 ** malloc failure occurs while populating it in the for(...) loop below.
58530 */
58532 pPager->aSavepoint, sizeof(PagerSavepoint)*nSavepoint
58533 );
58534 if( !aNew ){
58535 return SQLITE_NOMEM_BKPT;
58536 }
58537 memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
58538 pPager->aSavepoint = aNew;
58539
58540 /* Populate the PagerSavepoint structures just allocated. */
58541 for(ii=nCurrent; ii<nSavepoint; ii++){
58542 aNew[ii].nOrig = pPager->dbSize;
58543 if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
58544 aNew[ii].iOffset = pPager->journalOff;
58545 }else{
58546 aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
58547 }
58548 aNew[ii].iSubRec = pPager->nSubRec;
58549 aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
58550 if( !aNew[ii].pInSavepoint ){
58551 return SQLITE_NOMEM_BKPT;
58552 }
58553 if( pagerUseWal(pPager) ){
58554 sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData);
58555 }
SQLITE_PRIVATE void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData)
Definition sqlite3.c:62682
u32 nSubRec
Definition sqlite3.c:52359

References Pager::aSavepoint, PagerSavepoint::aWalData, Pager::dbSize, Pager::eState, PagerSavepoint::iOffset, isOpen, PagerSavepoint::iSubRec, Pager::jfd, JOURNAL_HDR_SZ, Pager::journalOff, PagerSavepoint::nOrig, Pager::nSavepoint, Pager::nSubRec, PAGER_WRITER_LOCKED, pagerUseWal, PagerSavepoint::pInSavepoint, Pager::pWal, sqlite3BitvecCreate(), sqlite3Realloc(), sqlite3WalSavepoint(), SQLITE_NOMEM_BKPT, SQLITE_OK, and Pager::useJournal.

◆ pagerOpentemp()

static int pagerOpentemp ( Pager * pPager,
sqlite3_file * pFile,
int vfsFlags )
static

Definition at line 55302 of file sqlite3.c.

55312 {
55313 int rc; /* Return code */
55314
55315#ifdef SQLITE_TEST
55316 sqlite3_opentemp_count++; /* Used for testing and analysis only */
55317#endif
55318

References isOpen, Pager::pVfs, sqlite3OsOpen(), SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_EXCLUSIVE, and SQLITE_OPEN_READWRITE.

Referenced by pager_write_pagelist().

◆ pagerOpenWal()

static int pagerOpenWal ( Pager * pPager)
static

Definition at line 59153 of file sqlite3.c.

59159 {
59160 int rc = SQLITE_OK;
59161
59162 assert( pPager->pWal==0 && pPager->tempFile==0 );
59163 assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
59164
59165 /* If the pager is already in exclusive-mode, the WAL module will use
59166 ** heap-memory for the wal-index instead of the VFS shared-memory
59167 ** implementation. Take the exclusive lock now, before opening the WAL
59168 ** file, to make sure this is safe.
59169 */
59170 if( pPager->exclusiveMode ){
59171 rc = pagerExclusiveLock(pPager);
59172 }
59173
59174 /* Open the connection to the log file. If this operation fails,
59175 ** (e.g. due to malloc() failure), return an error code.
59176 */
59177 if( rc==SQLITE_OK ){
59178 rc = sqlite3WalOpen(pPager->pVfs,
59179 pPager->fd, pPager->zWal, pPager->exclusiveMode,
59180 pPager->journalSizeLimit, &pPager->pWal
static int pagerExclusiveLock(Pager *pPager)
Definition sqlite3.c:59133
SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs *, sqlite3_file *, const char *, int, i64, Wal **)
Definition sqlite3.c:60796
char * zWal
Definition sqlite3.c:52400
i64 journalSizeLimit
Definition sqlite3.c:52385

References Pager::eLock, EXCLUSIVE_LOCK, Pager::exclusiveMode, Pager::fd, Pager::journalSizeLimit, pagerExclusiveLock(), pagerFixMaplimit(), Pager::pVfs, Pager::pWal, SHARED_LOCK, sqlite3WalOpen(), SQLITE_OK, Pager::tempFile, and Pager::zWal.

Referenced by sqlite3PagerCloseWal(), and sqlite3PagerOpenWal().

◆ pagerOpenWalIfPresent()

static int pagerOpenWalIfPresent ( Pager * pPager)
static

Definition at line 54968 of file sqlite3.c.

54974 {
54975 int rc = SQLITE_OK;
54976 assert( pPager->eState==PAGER_OPEN );
54977 assert( pPager->eLock>=SHARED_LOCK );
54978
54979 if( !pPager->tempFile ){
54980 int isWal; /* True if WAL file exists */
54981 rc = sqlite3OsAccess(
54982 pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
54983 );
54984 if( rc==SQLITE_OK ){
54985 if( isWal ){
54986 Pgno nPage; /* Size of the database file */
54987
54988 rc = pagerPagecount(pPager, &nPage);
54989 if( rc ) return rc;
54990 if( nPage==0 ){
54991 rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
54992 }else{
54994 rc = sqlite3PagerOpenWal(pPager, 0);
54995 }
54996 }else if( pPager->journalMode==PAGER_JOURNALMODE_WAL ){
SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *)
Definition sqlite3.c:49665

References Pager::eLock, Pager::eState, Pager::journalMode, PAGER_JOURNALMODE_DELETE, PAGER_JOURNALMODE_WAL, PAGER_OPEN, pagerPagecount(), Pager::pPCache, Pager::pVfs, SHARED_LOCK, sqlite3OsAccess(), sqlite3OsDelete(), sqlite3PagerOpenWal(), sqlite3PcachePagecount(), SQLITE_ACCESS_EXISTS, SQLITE_OK, Pager::tempFile, testcase, and Pager::zWal.

Referenced by sqlite3PagerSharedLock().

◆ pagerPagecount()

static int pagerPagecount ( Pager * pPager,
Pgno * pnPage )
static

Definition at line 54908 of file sqlite3.c.

54914 {
54915 Pgno nPage; /* Value to return via *pnPage */
54916
54917 /* Query the WAL sub-system for the database size. The WalDbsize()
54918 ** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
54919 ** if the database size is not available. The database size is not
54920 ** available from the WAL sub-system if the log file is empty or
54921 ** contains no valid committed transactions.
54922 */
54923 assert( pPager->eState==PAGER_OPEN );
54924 assert( pPager->eLock>=SHARED_LOCK );
54925 assert( isOpen(pPager->fd) );
54926 assert( pPager->tempFile==0 );
54927 nPage = sqlite3WalDbsize(pPager->pWal);
54928
54929 /* If the number of pages in the database is not available from the
54930 ** WAL sub-system, determine the page count based on the size of
54931 ** the database file. If the size of the database file is not an
54932 ** integer multiple of the page-size, round up the result.
54933 */
54934 if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
54935 i64 n = 0; /* Size of db file in bytes */
54936 int rc = sqlite3OsFileSize(pPager->fd, &n);
54937 if( rc!=SQLITE_OK ){
54938 return rc;
54939 }
54940 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
54941 }
54942
54943 /* If the current number of pages in the file is greater than the
54944 ** configured maximum pager number, increase the allowed limit so
54945 ** that the file can be read.
54946 */
54947 if( nPage>pPager->mxPgno ){
SQLITE_PRIVATE Pgno sqlite3WalDbsize(Wal *pWal)
Definition sqlite3.c:62551

References ALWAYS, Pager::eLock, Pager::eState, Pager::fd, isOpen, Pager::mxPgno, PAGER_OPEN, Pager::pageSize, Pager::pWal, SHARED_LOCK, sqlite3OsFileSize(), sqlite3WalDbsize(), SQLITE_OK, and Pager::tempFile.

Referenced by hasHotJournal(), pagerOpenWalIfPresent(), and sqlite3PagerSharedLock().

◆ pagerPlaybackSavepoint()

static int pagerPlaybackSavepoint ( Pager * pPager,
PagerSavepoint * pSavepoint )
static

Definition at line 55035 of file sqlite3.c.

55041 {
55042 i64 szJ; /* Effective size of the main journal */
55043 i64 iHdrOff; /* End of first segment of main-journal records */
55044 int rc = SQLITE_OK; /* Return code */
55045 Bitvec *pDone = 0; /* Bitvec to ensure pages played back only once */
55046
55047 assert( pPager->eState!=PAGER_ERROR );
55048 assert( pPager->eState>=PAGER_WRITER_LOCKED );
55049
55050 /* Allocate a bitvec to use to store the set of pages rolled back */
55051 if( pSavepoint ){
55052 pDone = sqlite3BitvecCreate(pSavepoint->nOrig);
55053 if( !pDone ){
55054 return SQLITE_NOMEM_BKPT;
55055 }
55056 }
55057
55058 /* Set the database size back to the value it was before the savepoint
55059 ** being reverted was opened.
55060 */
55061 pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
55062 pPager->changeCountDone = pPager->tempFile;
55063
55064 if( !pSavepoint && pagerUseWal(pPager) ){
55065 return pagerRollbackWal(pPager);
55066 }
55067
55068 /* Use pPager->journalOff as the effective size of the main rollback
55069 ** journal. The actual file might be larger than this in
55070 ** PAGER_JOURNALMODE_TRUNCATE or PAGER_JOURNALMODE_PERSIST. But anything
55071 ** past pPager->journalOff is off-limits to us.
55072 */
55073 szJ = pPager->journalOff;
55074 assert( pagerUseWal(pPager)==0 || szJ==0 );
55075
55076 /* Begin by rolling back records from the main journal starting at
55077 ** PagerSavepoint.iOffset and continuing to the next journal header.
55078 ** There might be records in the main journal that have a page number
55079 ** greater than the current database size (pPager->dbSize) but those
55080 ** will be skipped automatically. Pages are added to pDone as they
55081 ** are played back.
55082 */
55083 if( pSavepoint && !pagerUseWal(pPager) ){
55084 iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
55085 pPager->journalOff = pSavepoint->iOffset;
55086 while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
55087 rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
55088 }
55089 assert( rc!=SQLITE_DONE );
55090 }else{
55091 pPager->journalOff = 0;
55092 }
55093
55094 /* Continue rolling back records out of the main journal starting at
55095 ** the first journal header seen and continuing until the effective end
55096 ** of the main journal file. Continue to skip out-of-range pages and
55097 ** continue adding pages rolled back to pDone.
55098 */
55099 while( rc==SQLITE_OK && pPager->journalOff<szJ ){
55100 u32 ii; /* Loop counter */
55101 u32 nJRec = 0; /* Number of Journal Records */
55102 u32 dummy;
55103 rc = readJournalHdr(pPager, 0, szJ, &nJRec, &dummy);
55104 assert( rc!=SQLITE_DONE );
55105
55106 /*
55107 ** The "pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff"
55108 ** test is related to ticket #2565. See the discussion in the
55109 ** pager_playback() function for additional information.
55110 */
55111 if( nJRec==0
55112 && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
55113 ){
55114 nJRec = (u32)((szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager));
55115 }
55116 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
55117 rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
55118 }
55119 assert( rc!=SQLITE_DONE );
55120 }
55121 assert( rc!=SQLITE_OK || pPager->journalOff>=szJ );
55122
55123 /* Finally, rollback pages from the sub-journal. Page that were
55124 ** previously rolled back out of the main journal (and are hence in pDone)
55125 ** will be skipped. Out-of-range pages are also skipped.
55126 */
55127 if( pSavepoint ){
55128 u32 ii; /* Loop counter */
55129 i64 offset = (i64)pSavepoint->iSubRec*(4+pPager->pageSize);
55130
55131 if( pagerUseWal(pPager) ){
55132 rc = sqlite3WalSavepointUndo(pPager->pWal, pSavepoint->aWalData);
55133 }
55134 for(ii=pSavepoint->iSubRec; rc==SQLITE_OK && ii<pPager->nSubRec; ii++){
55135 assert( offset==(i64)ii*(4+pPager->pageSize) );
55136 rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
55137 }
55138 assert( rc!=SQLITE_DONE );
55139 }
55140
55141 sqlite3BitvecDestroy(pDone);
static int pagerRollbackWal(Pager *pPager)
Definition sqlite3.c:54776
SQLITE_PRIVATE int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData)
Definition sqlite3.c:62696
u32 aWalData[WAL_SAVEPOINT_NDATA]
Definition sqlite3.c:52141

References PagerSavepoint::aWalData, Pager::changeCountDone, Pager::dbOrigSize, Pager::dbSize, dummy, Pager::eState, PagerSavepoint::iHdrOffset, PagerSavepoint::iOffset, PagerSavepoint::iSubRec, JOURNAL_HDR_SZ, JOURNAL_PG_SZ, Pager::journalHdr, Pager::journalOff, PagerSavepoint::nOrig, Pager::nSubRec, PAGER_ERROR, pager_playback_one_page(), PAGER_WRITER_LOCKED, pagerRollbackWal(), pagerUseWal, Pager::pageSize, Pager::pWal, readJournalHdr(), sqlite3BitvecCreate(), sqlite3BitvecDestroy(), sqlite3WalSavepointUndo(), SQLITE_DONE, SQLITE_NOMEM_BKPT, SQLITE_OK, and Pager::tempFile.

Referenced by sqlite3PagerSavepoint().

◆ pagerReleaseMapPage()

static void pagerReleaseMapPage ( PgHdr * pPg)
static

Definition at line 55724 of file sqlite3.c.

55730 {
55731 Pager *pPager = pPg->pPager;
55732 pPager->nMmapOut--;
int nMmapOut
Definition sqlite3.c:52372

References Pager::fd, sqlite3_io_methods::iVersion, Pager::nMmapOut, PgHdr::pDirty, sqlite3_file::pMethods, Pager::pMmapFreelist, and PgHdr::pPager.

Referenced by sqlite3PagerUnrefNotNull().

◆ pagerRollbackWal()

static int pagerRollbackWal ( Pager * pPager)
static

Definition at line 54776 of file sqlite3.c.

54782 {
54783 int rc; /* Return Code */
54784 PgHdr *pList; /* List of dirty pages to revert */
54785
54786 /* For all pages in the cache that are currently dirty or have already
54787 ** been written (but not committed) to the log file, do one of the
54788 ** following:
54789 **
54790 ** + Discard the cached page (if refcount==0), or
54791 ** + Reload page content from the database (if refcount>0).
54792 */
54793 pPager->dbSize = pPager->dbOrigSize;
54794 rc = sqlite3WalUndo(pPager->pWal, pagerUndoCallback, (void *)pPager);
54795 pList = sqlite3PcacheDirtyList(pPager->pPCache);
54796 while( pList && rc==SQLITE_OK ){
54797 PgHdr *pNext = pList->pDirty;
SQLITE_PRIVATE int sqlite3WalUndo(Wal *pWal, int(*xUndo)(void *, Pgno), void *pUndoCtx)
Definition sqlite3.c:62642
SQLITE_PRIVATE PgHdr * sqlite3PcacheDirtyList(PCache *)
Definition sqlite3.c:49637
static int pagerUndoCallback(void *pCtx, Pgno iPg)
Definition sqlite3.c:54741

Referenced by pagerPlaybackSavepoint().

◆ pagerStress()

static int pagerStress ( void * p,
PgHdr * pPg )
static

Definition at line 56216 of file sqlite3.c.

56222 {
56223 Pager *pPager = (Pager *)p;
56224 int rc = SQLITE_OK;
56225
56226 assert( pPg->pPager==pPager );
56227 assert( pPg->flags&PGHDR_DIRTY );
56228
56229 /* The doNotSpill NOSYNC bit is set during times when doing a sync of
56230 ** journal (and adding a new header) is not allowed. This occurs
56231 ** during calls to sqlite3PagerWrite() while trying to journal multiple
56232 ** pages belonging to the same sector.
56233 **
56234 ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
56235 ** regardless of whether or not a sync is required. This is set during
56236 ** a rollback or by user request, respectively.
56237 **
56238 ** Spilling is also prohibited when in an error state since that could
56239 ** lead to database corruption. In the current implementation it
56240 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==3
56241 ** while in the error state, hence it is impossible for this routine to
56242 ** be called in the error state. Nevertheless, we include a NEVER()
56243 ** test for the error state as a safeguard against future changes.
56244 */
56245 if( NEVER(pPager->errCode) ) return SQLITE_OK;
56247 testcase( pPager->doNotSpill & SPILLFLAG_OFF );
56249 if( pPager->doNotSpill
56250 && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0
56251 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
56252 ){
56253 return SQLITE_OK;
56254 }
56255
56256 pPager->aStat[PAGER_STAT_SPILL]++;
56257 pPg->pDirty = 0;
56258 if( pagerUseWal(pPager) ){
56259 /* Write a single frame for this page to the log. */
56260 rc = subjournalPageIfRequired(pPg);
56261 if( rc==SQLITE_OK ){
56262 rc = pagerWalFrames(pPager, pPg, 0, 0);
56263 }
56264 }else{
56265
56266#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
56267 if( pPager->tempFile==0 ){
56268 rc = sqlite3JournalCreate(pPager->jfd);
56269 if( rc!=SQLITE_OK ) return pager_error(pPager, rc);
56270 }
56271#endif
56272
56273 /* Sync the journal file if required. */
56274 if( pPg->flags&PGHDR_NEED_SYNC
56275 || pPager->eState==PAGER_WRITER_CACHEMOD
56276 ){
56277 rc = syncJournal(pPager, 1);
56278 }
56279
56280 /* Write the contents of the page out to the database file. */
56281 if( rc==SQLITE_OK ){
56282 assert( (pPg->flags&PGHDR_NEED_SYNC)==0 );
56283 rc = pager_write_pagelist(pPager, pPg);
56284 }
56285 }
56286
56287 /* Mark the page as clean. */
56288 if( rc==SQLITE_OK ){
static int pagerWalFrames(Pager *pPager, PgHdr *pList, Pgno nTruncate, int isCommit)
Definition sqlite3.c:54808
#define PGHDR_DIRTY
Definition sqlite3.c:16071
static int syncJournal(Pager *pPager, int newHdr)
Definition sqlite3.c:55893
static int pager_write_pagelist(Pager *pPager, PgHdr *pList)
Definition sqlite3.c:56036
#define SPILLFLAG_NOSYNC
Definition sqlite3.c:52150
static int pager_error(Pager *pPager, int rc)
Definition sqlite3.c:53613
#define PAGER_STAT_SPILL
Definition sqlite3.c:52412
#define SPILLFLAG_OFF
Definition sqlite3.c:52148

References Pager::aStat, Pager::doNotSpill, Pager::errCode, Pager::eState, PgHdr::flags, Pager::jfd, NEVER, pager_error(), PAGER_STAT_SPILL, pager_write_pagelist(), PAGER_WRITER_CACHEMOD, PAGERID, PAGERTRACE, pagerUseWal, pagerWalFrames(), PgHdr::pDirty, PGHDR_DIRTY, PGHDR_NEED_SYNC, PgHdr::pgno, PgHdr::pPager, SPILLFLAG_NOSYNC, SPILLFLAG_OFF, SPILLFLAG_ROLLBACK, sqlite3PcacheMakeClean(), SQLITE_OK, subjournalPageIfRequired(), syncJournal(), Pager::tempFile, and testcase.

Referenced by sqlite3PagerOpen().

◆ pagerSyncHotJournal()

static int pagerSyncHotJournal ( Pager * pPager)
static

Definition at line 55658 of file sqlite3.c.

55664 {
55665 int rc = SQLITE_OK;
55666 if( !pPager->noSync ){
55667 rc = sqlite3OsSync(pPager->jfd, SQLITE_SYNC_NORMAL);
#define SQLITE_SYNC_NORMAL
Definition sqlite3.c:1716

References Pager::jfd, Pager::journalHdr, Pager::noSync, sqlite3OsFileSize(), sqlite3OsSync(), SQLITE_OK, and SQLITE_SYNC_NORMAL.

Referenced by sqlite3PagerClose(), and sqlite3PagerSharedLock().

◆ pagerUndoCallback()

static int pagerUndoCallback ( void * pCtx,
Pgno iPg )
static

Definition at line 54741 of file sqlite3.c.

54747 {
54748 int rc = SQLITE_OK;
54749 Pager *pPager = (Pager *)pCtx;
54750 PgHdr *pPg;
54751
54752 assert( pagerUseWal(pPager) );
54753 pPg = sqlite3PagerLookup(pPager, iPg);
54754 if( pPg ){
54755 if( sqlite3PcachePageRefcount(pPg)==1 ){
54756 sqlite3PcacheDrop(pPg);
54757 }else{
54758 rc = readDbPage(pPg);
54759 if( rc==SQLITE_OK ){
54760 pPager->xReiniter(pPg);
54761 }
54763 }
54764 }
54765
54766 /* Normally, if a transaction is rolled back, any backup processes are
54767 ** updated as data is copied out of the rollback journal and into the
54768 ** database. This is not generally possible with a WAL database, as
54769 ** rollback involves simply truncating the log file. Therefore, if one
54770 ** or more frames have already been written to the log (and therefore
54771 ** also copied into the backup databases) as part of this transaction,
SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr *)
Definition sqlite3.c:49658
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *)
Definition sqlite3.c:49409

References pagerUseWal, Pager::pBackup, readDbPage(), sqlite3BackupRestart(), sqlite3PagerLookup(), sqlite3PagerUnrefNotNull(), sqlite3PcacheDrop(), sqlite3PcachePageRefcount(), SQLITE_OK, and Pager::xReiniter.

◆ pagerUnlockAndRollback()

static void pagerUnlockAndRollback ( Pager * pPager)
static

Definition at line 53854 of file sqlite3.c.

53860 {
53861 if( pPager->eState!=PAGER_ERROR && pPager->eState!=PAGER_OPEN ){
53862 assert( assert_pager_state(pPager) );
53863 if( pPager->eState>=PAGER_WRITER_LOCKED ){
53865 sqlite3PagerRollback(pPager);
53867 }else if( !pPager->exclusiveMode ){

References Pager::eState, Pager::exclusiveMode, pager_end_transaction(), PAGER_ERROR, PAGER_OPEN, PAGER_READER, pager_unlock(), PAGER_WRITER_LOCKED, sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), and sqlite3PagerRollback().

Referenced by pagerUnlockIfUnused(), and sqlite3PagerClose().

◆ pagerUnlockDb()

static int pagerUnlockDb ( Pager * pPager,
int eLock )
static

Definition at line 52831 of file sqlite3.c.

52837 {
52838 int rc = SQLITE_OK;
52839
52840 assert( !pPager->exclusiveMode || pPager->eLock==eLock );
52841 assert( eLock==NO_LOCK || eLock==SHARED_LOCK );
52842 assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 );
52843 if( isOpen(pPager->fd) ){
52844 assert( pPager->eLock>=eLock );
52845 rc = pPager->noLock ? SQLITE_OK : sqlite3OsUnlock(pPager->fd, eLock);
52846 if( pPager->eLock!=UNKNOWN_LOCK ){
52847 pPager->eLock = (u8)eLock;
SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file *, int)
Definition sqlite3.c:23072

References Pager::changeCountDone, Pager::eLock, Pager::exclusiveMode, Pager::fd, IOTRACE, isOpen, NO_LOCK, Pager::noLock, pagerUseWal, SHARED_LOCK, sqlite3OsUnlock(), SQLITE_OK, Pager::tempFile, and UNKNOWN_LOCK.

Referenced by hasHotJournal(), pager_end_transaction(), pager_unlock(), sqlite3PagerCloseWal(), sqlite3PagerSetJournalMode(), and sqlite3PagerSharedLock().

◆ pagerUnlockIfUnused()

static void pagerUnlockIfUnused ( Pager * pPager)
static

Definition at line 57091 of file sqlite3.c.

References Pager::nMmapOut, pagerUnlockAndRollback(), Pager::pPCache, and sqlite3PcacheRefCount().

Referenced by getPageNormal().

◆ pagerWalFrames()

static int pagerWalFrames ( Pager * pPager,
PgHdr * pList,
Pgno nTruncate,
int isCommit )
static

Definition at line 54808 of file sqlite3.c.

54819 {
54820 int rc; /* Return code */
54821 int nList; /* Number of pages in pList */
54822 PgHdr *p; /* For looping over pages */
54823
54824 assert( pPager->pWal );
54825 assert( pList );
54826#ifdef SQLITE_DEBUG
54827 /* Verify that the page list is in accending order */
54828 for(p=pList; p && p->pDirty; p=p->pDirty){
54829 assert( p->pgno < p->pDirty->pgno );
54830 }
54831#endif
54832
54833 assert( pList->pDirty==0 || isCommit );
54834 if( isCommit ){
54835 /* If a WAL transaction is being committed, there is no point in writing
54836 ** any pages with page numbers greater than nTruncate into the WAL file.
54837 ** They will never be read by any client. So remove them from the pDirty
54838 ** list here. */
54839 PgHdr **ppNext = &pList;
54840 nList = 0;
54841 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
54842 if( p->pgno<=nTruncate ){
54843 ppNext = &p->pDirty;
54844 nList++;
54845 }
54846 }
54847 assert( pList );
54848 }else{
54849 nList = 1;
54850 }
54851 pPager->aStat[PAGER_STAT_WRITE] += nList;
54852
54853 if( pList->pgno==1 ) pager_write_changecounter(pList);
54854 rc = sqlite3WalFrames(pPager->pWal,
54855 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
54856 );
54857 if( rc==SQLITE_OK && pPager->pBackup ){
54858 for(p=pList; p; p=p->pDirty){
54859 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
54860 }
54861 }
54862
54863#ifdef SQLITE_CHECK_PAGES
54864 pList = sqlite3PcacheDirtyList(pPager->pPCache);
54865 for(p=pList; p; p=p->pDirty){
SQLITE_PRIVATE int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int)
Definition sqlite3.c:62896
u8 walSyncFlags
Definition sqlite3.c:52329

References Pager::aStat, pager_set_pagehash, PAGER_STAT_WRITE, pager_write_changecounter(), Pager::pageSize, Pager::pBackup, PgHdr::pData, PgHdr::pDirty, PgHdr::pgno, Pager::pPCache, Pager::pWal, sqlite3BackupUpdate(), sqlite3PcacheDirtyList(), sqlite3WalFrames(), SQLITE_OK, and Pager::walSyncFlags.

Referenced by pagerStress(), and sqlite3PagerCommitPhaseOne().

◆ pagerWriteLargeSector()

static SQLITE_NOINLINE int pagerWriteLargeSector ( PgHdr * pPg)
static

Definition at line 57739 of file sqlite3.c.

57745 {
57746 int rc = SQLITE_OK; /* Return code */
57747 Pgno nPageCount; /* Total number of pages in database file */
57748 Pgno pg1; /* First page of the sector pPg is located on. */
57749 int nPage = 0; /* Number of pages starting at pg1 to journal */
57750 int ii; /* Loop counter */
57751 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
57752 Pager *pPager = pPg->pPager; /* The pager that owns pPg */
57753 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
57754
57755 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
57756 ** a journal header to be written between the pages journaled by
57757 ** this function.
57758 */
57759 assert( !MEMDB );
57760 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
57761 pPager->doNotSpill |= SPILLFLAG_NOSYNC;
57762
57763 /* This trick assumes that both the page-size and sector-size are
57764 ** an integer power of 2. It sets variable pg1 to the identifier
57765 ** of the first page of the sector pPg is located on.
57766 */
57767 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
57768
57769 nPageCount = pPager->dbSize;
57770 if( pPg->pgno>nPageCount ){
57771 nPage = (pPg->pgno - pg1)+1;
57772 }else if( (pg1+nPagePerSector-1)>nPageCount ){
57773 nPage = nPageCount+1-pg1;
57774 }else{
57775 nPage = nPagePerSector;
57776 }
57777 assert(nPage>0);
57778 assert(pg1<=pPg->pgno);
57779 assert((pg1+nPage)>pPg->pgno);
57780
57781 for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){
57782 Pgno pg = pg1+ii;
57783 PgHdr *pPage;
57784 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
57785 if( pg!=PAGER_MJ_PGNO(pPager) ){
57786 rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
57787 if( rc==SQLITE_OK ){
57788 rc = pager_write(pPage);
57789 if( pPage->flags&PGHDR_NEED_SYNC ){
57790 needSync = 1;
57791 }
57793 }
57794 }
57795 }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
57796 if( pPage->flags&PGHDR_NEED_SYNC ){
57797 needSync = 1;
57798 }
57800 }
57801 }
57802
57803 /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
57804 ** starting at pg1, then it needs to be set for all of them. Because
57805 ** writing to any of these nPage pages may damage the others, the
57806 ** journal file must contain sync()ed copies of all of them
57807 ** before any of them can be written out to the database file.
57808 */
57809 if( rc==SQLITE_OK && needSync ){
57810 assert( !MEMDB );
57811 for(ii=0; ii<nPage; ii++){
57812 PgHdr *pPage = sqlite3PagerLookup(pPager, pg1+ii);
57813 if( pPage ){
57814 pPage->flags |= PGHDR_NEED_SYNC;
57816 }
57817 }
static int pager_write(PgHdr *pPg)
Definition sqlite3.c:57647

References Pager::dbSize, Pager::doNotSpill, PgHdr::flags, MEMDB, PAGER_MJ_PGNO, pager_write(), Pager::pageSize, PGHDR_NEED_SYNC, PgHdr::pgno, Pager::pInJournal, PgHdr::pPager, Pager::sectorSize, SPILLFLAG_NOSYNC, sqlite3BitvecTest(), sqlite3PagerGet(), sqlite3PagerLookup(), sqlite3PagerUnrefNotNull(), and SQLITE_OK.

Referenced by sqlite3PagerWrite().

◆ parseDateOrTime()

static int parseDateOrTime ( sqlite3_context * context,
const char * zDate,
DateTime * p )
static

Definition at line 22088 of file sqlite3.c.

22089 :SS.FFF") is option. The year and date can be omitted as long
22090** as there is a time string. The time string can be omitted as long
22091** as there is a year and date.
22092*/
22093static int parseDateOrTime(
22094 sqlite3_context *context,
22095 const char *zDate,
22096 DateTime *p
22097){
22098 double r;
22099 if( parseYyyyMmDd(zDate,p)==0 ){
22100 return 0;
22101 }else if( parseHhMmSs(zDate, p)==0 ){
22102 return 0;
22103 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
22104 return setDateTimeToCurrent(context, p);
22105 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){

References parseHhMmSs(), parseYyyyMmDd(), setDateTimeToCurrent(), setRawDateNumber(), sqlite3AtoF(), sqlite3NotPureFunc(), sqlite3StrICmp(), sqlite3Strlen30(), and SQLITE_UTF8.

Referenced by isDate().

◆ parseHhMmSs()

static int parseHhMmSs ( const char * zDate,
DateTime * p )
static

Definition at line 21909 of file sqlite3.c.

21914 {
21915 int h, m, s;
21916 double ms = 0.0;
21917 if( getDigits(zDate, "20c:20e", &h, &m)!=2 ){
21918 return 1;
21919 }
21920 zDate += 5;
21921 if( *zDate==':' ){
21922 zDate++;
21923 if( getDigits(zDate, "20e", &s)!=1 ){
21924 return 1;
21925 }
21926 zDate += 2;
21927 if( *zDate=='.' && sqlite3Isdigit(zDate[1]) ){
21928 double rScale = 1.0;
21929 zDate++;
21930 while( sqlite3Isdigit(*zDate) ){
21931 ms = ms*10.0 + *zDate - '0';
21932 rScale *= 10.0;
21933 zDate++;
21934 }
21935 ms /= rScale;
21936 }
21937 }else{
21938 s = 0;
21939 }
21940 p->validJD = 0;
21941 p->rawS = 0;
21942 p->validHMS = 1;
21943 p->h = h;
21944 p->m = m;
static int getDigits(const char *zDate, const char *zFormat,...)
Definition sqlite3.c:21819

References getDigits(), DateTime::h, DateTime::m, parseTimezone(), DateTime::rawS, DateTime::s, s, sqlite3Isdigit, DateTime::tz, DateTime::validHMS, DateTime::validJD, and DateTime::validTZ.

Referenced by parseDateOrTime(), parseModifier(), and parseYyyyMmDd().

◆ parseModifier()

static int parseModifier ( sqlite3_context * pCtx,
const char * z,
int n,
DateTime * p )
static

Definition at line 22365 of file sqlite3.c.

22375 {
22376 int rc = 1;
22377 double r;
22378 switch(sqlite3UpperToLower[(u8)z[0]] ){
22379#ifndef SQLITE_OMIT_LOCALTIME
22380 case 'l': {
22381 /* localtime
22382 **
22383 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
22384 ** show local time.
22385 */
22386 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
22387 computeJD(p);
22388 p->iJD += localtimeOffset(p, pCtx, &rc);
22389 clearYMD_HMS_TZ(p);
22390 }
22391 break;
22392 }
22393#endif
22394 case 'u': {
22395 /*
22396 ** unixepoch
22397 **
22398 ** Treat the current value of p->s as the number of
22399 ** seconds since 1970. Convert to a real julian day number.
22400 */
22401 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
22402 r = p->s*1000.0 + 210866760000000.0;
22403 if( r>=0.0 && r<464269060800000.0 ){
22404 clearYMD_HMS_TZ(p);
22405 p->iJD = (sqlite3_int64)(r + 0.5);
22406 p->validJD = 1;
22407 p->rawS = 0;
22408 rc = 0;
22409 }
22410 }
22411#ifndef SQLITE_OMIT_LOCALTIME
22412 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
22413 if( p->tzSet==0 ){
22414 sqlite3_int64 c1;
22415 computeJD(p);
22416 c1 = localtimeOffset(p, pCtx, &rc);
22417 if( rc==SQLITE_OK ){
22418 p->iJD -= c1;
22419 clearYMD_HMS_TZ(p);
22420 p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
22421 }
22422 p->tzSet = 1;
22423 }else{
22424 rc = SQLITE_OK;
22425 }
22426 }
22427#endif
22428 break;
22429 }
22430 case 'w': {
22431 /*
22432 ** weekday N
22433 **
22434 ** Move the date to the same time on the next occurrence of
22435 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
22436 ** date is already on the appropriate weekday, this is a no-op.
22437 */
22438 if( sqlite3_strnicmp(z, "weekday ", 8)==0
22439 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
22440 && (n=(int)r)==r && n>=0 && r<7 ){
22441 sqlite3_int64 Z;
22442 computeYMD_HMS(p);
22443 p->validTZ = 0;
22444 p->validJD = 0;
22445 computeJD(p);
22446 Z = ((p->iJD + 129600000)/86400000) % 7;
22447 if( Z>n ) Z -= 7;
22448 p->iJD += (n - Z)*86400000;
22449 clearYMD_HMS_TZ(p);
22450 rc = 0;
22451 }
22452 break;
22453 }
22454 case 's': {
22455 /*
22456 ** start of TTTTT
22457 **
22458 ** Move the date backwards to the beginning of the current day,
22459 ** or month or year.
22460 */
22461 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
22462 if( !p->validJD && !p->validYMD && !p->validHMS ) break;
22463 z += 9;
22464 computeYMD(p);
22465 p->validHMS = 1;
22466 p->h = p->m = 0;
22467 p->s = 0.0;
22468 p->rawS = 0;
22469 p->validTZ = 0;
22470 p->validJD = 0;
22471 if( sqlite3_stricmp(z,"month")==0 ){
22472 p->D = 1;
22473 rc = 0;
22474 }else if( sqlite3_stricmp(z,"year")==0 ){
22475 p->M = 1;
22476 p->D = 1;
22477 rc = 0;
22478 }else if( sqlite3_stricmp(z,"day")==0 ){
22479 rc = 0;
22480 }
22481 break;
22482 }
22483 case '+':
22484 case '-':
22485 case '0':
22486 case '1':
22487 case '2':
22488 case '3':
22489 case '4':
22490 case '5':
22491 case '6':
22492 case '7':
22493 case '8':
22494 case '9': {
22495 double rRounder;
22496 int i;
22497 for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
22498 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
22499 rc = 1;
22500 break;
22501 }
22502 if( z[n]==':' ){
22503 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
22504 ** specified number of hours, minutes, seconds, and fractional seconds
22505 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
22506 ** omitted.
22507 */
22508 const char *z2 = z;
22509 DateTime tx;
22510 sqlite3_int64 day;
22511 if( !sqlite3Isdigit(*z2) ) z2++;
22512 memset(&tx, 0, sizeof(tx));
22513 if( parseHhMmSs(z2, &tx) ) break;
22514 computeJD(&tx);
22515 tx.iJD -= 43200000;
22516 day = tx.iJD/86400000;
22517 tx.iJD -= day*86400000;
22518 if( z[0]=='-' ) tx.iJD = -tx.iJD;
22519 computeJD(p);
22520 clearYMD_HMS_TZ(p);
22521 p->iJD += tx.iJD;
22522 rc = 0;
22523 break;
22524 }
22525
22526 /* If control reaches this point, it means the transformation is
22527 ** one of the forms like "+NNN days". */
22528 z += n;
22529 while( sqlite3Isspace(*z) ) z++;
22530 n = sqlite3Strlen30(z);
22531 if( n>10 || n<3 ) break;
22532 if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
22533 computeJD(p);
22534 rc = 1;
22535 rRounder = r<0 ? -0.5 : +0.5;
22536 for(i=0; i<ArraySize(aXformType); i++){
22537 if( aXformType[i].nName==n
22538 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
22539 && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
22540 ){
22541 switch( aXformType[i].eType ){
22542 case 1: { /* Special processing to add months */
22543 int x;
22544 computeYMD_HMS(p);
22545 p->M += (int)r;
22546 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
22547 p->Y += x;
22548 p->M -= x*12;
22549 p->validJD = 0;
22550 r -= (int)r;
22551 break;
22552 }
22553 case 2: { /* Special processing to add years */
22554 int y = (int)r;
22555 computeYMD_HMS(p);
22556 p->Y += y;
22557 p->validJD = 0;
22558 r -= (int)r;
22559 break;
22560 }
22561 }
22562 computeJD(p);
22563 p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
22564 rc = 0;
22565 break;
22566 }
22567 }
22568 clearYMD_HMS_TZ(p);
22569 break;
22570 }
22571 default: {
SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context *)
Definition sqlite3.c:82849
static void clearYMD_HMS_TZ(DateTime *p)
Definition sqlite3.c:22184
static const struct @103 aXformType[]
static void computeYMD(DateTime *p)
Definition sqlite3.c:22128
static sqlite3_int64 localtimeOffset(DateTime *p, sqlite3_context *pCtx, int *pRc)
Definition sqlite3.c:22261
static int parseHhMmSs(const char *zDate, DateTime *p)
Definition sqlite3.c:21909
double rXform
Definition sqlite3.c:22331
#define sqlite3Isspace(x)
Definition sqlite3.c:19319
char tzSet
Definition sqlite3.c:21787

References ArraySize, aXformType, clearYMD_HMS_TZ(), computeJD(), computeYMD(), computeYMD_HMS(), DateTime::D, eType, DateTime::h, DateTime::iJD, localtimeOffset(), DateTime::M, DateTime::m, nName, parseHhMmSs(), DateTime::rawS, rXform, DateTime::s, sqlite3_stricmp(), sqlite3_strnicmp(), sqlite3AtoF(), sqlite3Isdigit, sqlite3Isspace, sqlite3NotPureFunc(), sqlite3Strlen30(), sqlite3UpperToLower, SQLITE_OK, SQLITE_UTF8, DateTime::tzSet, DateTime::validHMS, DateTime::validJD, DateTime::validTZ, DateTime::validYMD, DateTime::Y, and zName.

Referenced by isDate().

◆ parserAddExprIdListTerm()

static ExprList * parserAddExprIdListTerm ( Parse * pParse,
ExprList * pPrior,
Token * pIdToken,
int hasCollate,
int sortOrder )
static

Definition at line 154393 of file sqlite3.c.

154405 {
154406 ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
154407 if( (hasCollate || sortOrder!=SQLITE_SO_UNDEFINED)
154408 && pParse->db->init.busy==0
154409 ){
#define SQLITE_SO_UNDEFINED
Definition sqlite3.c:17378

References sqlite3::sqlite3InitInfo::busy, Parse::db, sqlite3::init, Token::n, sqlite3ErrorMsg(), sqlite3ExprListAppend(), sqlite3ExprListSetName(), SQLITE_SO_UNDEFINED, and Token::z.

Referenced by yy_reduce().

◆ parserDoubleLinkSelect()

static void parserDoubleLinkSelect ( Parse * pParse,
Select * p )
static

Definition at line 154321 of file sqlite3.c.

154327 {
154328 assert( p!=0 );
154329 if( p->pPrior ){
154330 Select *pNext = 0, *pLoop;
154331 int mxSelect, cnt = 0;
154332 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
154333 pLoop->pNext = pNext;
154334 pLoop->selFlags |= SF_Compound;
154335 }
154336 if( (p->selFlags & SF_MultiValue)==0 &&
154337 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
#define SQLITE_LIMIT_COMPOUND_SELECT
Definition sqlite3.c:4948

References sqlite3::aLimit, Parse::db, Select::pPrior, Select::selFlags, SF_Compound, SF_MultiValue, sqlite3ErrorMsg(), and SQLITE_LIMIT_COMPOUND_SELECT.

Referenced by yy_reduce().

◆ parseTimezone()

static int parseTimezone ( const char * zDate,
DateTime * p )
static

Definition at line 21873 of file sqlite3.c.

21878 {
21879 int sgn = 0;
21880 int nHr, nMn;
21881 int c;
21882 while( sqlite3Isspace(*zDate) ){ zDate++; }
21883 p->tz = 0;
21884 c = *zDate;
21885 if( c=='-' ){
21886 sgn = -1;
21887 }else if( c=='+' ){
21888 sgn = +1;
21889 }else if( c=='Z' || c=='z' ){
21890 zDate++;
21891 goto zulu_time;
21892 }else{
21893 return c!=0;
21894 }
21895 zDate++;
21896 if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){
21897 return 1;
21898 }
21899 zDate += 5;
21900 p->tz = sgn*(nMn + nHr*60);

References getDigits(), sqlite3Isspace, DateTime::tz, and DateTime::tzSet.

Referenced by parseHhMmSs().

◆ parseYyyyMmDd()

static int parseYyyyMmDd ( const char * zDate,
DateTime * p )
static

Definition at line 22010 of file sqlite3.c.

22015 {
22016 int Y, M, D, neg;
22017
22018 if( zDate[0]=='-' ){
22019 zDate++;
22020 neg = 1;
22021 }else{
22022 neg = 0;
22023 }
22024 if( getDigits(zDate, "40f-21a-21d", &Y, &M, &D)!=3 ){
22025 return 1;
22026 }
22027 zDate += 10;
22028 while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; }
22029 if( parseHhMmSs(zDate, p)==0 ){
22030 /* We got the time */
22031 }else if( *zDate==0 ){
22032 p->validHMS = 0;
22033 }else{
22034 return 1;
22035 }
22036 p->validJD = 0;
22037 p->validYMD = 1;
22038 p->Y = neg ? -Y : Y;
22039 p->M = M;
22040 p->D = D;

References computeJD(), DateTime::D, getDigits(), DateTime::M, parseHhMmSs(), sqlite3Isspace, DateTime::validHMS, DateTime::validJD, DateTime::validTZ, DateTime::validYMD, and DateTime::Y.

Referenced by parseDateOrTime().

◆ patternCompare()

static int patternCompare ( const u8 * zPattern,
const u8 * zString,
const struct compareInfo * pInfo,
u32 matchOther )
static

Definition at line 117724 of file sqlite3.c.

117735 {
117736 u32 c, c2; /* Next pattern and input string chars */
117737 u32 matchOne = pInfo->matchOne; /* "?" or "_" */
117738 u32 matchAll = pInfo->matchAll; /* "*" or "%" */
117739 u8 noCase = pInfo->noCase; /* True if uppercase==lowercase */
117740 const u8 *zEscaped = 0; /* One past the last escaped input char */
117741
117742 while( (c = Utf8Read(zPattern))!=0 ){
117743 if( c==matchAll ){ /* Match "*" */
117744 /* Skip over multiple "*" characters in the pattern. If there
117745 ** are also "?" characters, skip those as well, but consume a
117746 ** single character of the input string for each "?" skipped */
117747 while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){
117748 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
117749 return SQLITE_NOWILDCARDMATCH;
117750 }
117751 }
117752 if( c==0 ){
117753 return SQLITE_MATCH; /* "*" at the end of the pattern matches */
117754 }else if( c==matchOther ){
117755 if( pInfo->matchSet==0 ){
117756 c = sqlite3Utf8Read(&zPattern);
117757 if( c==0 ) return SQLITE_NOWILDCARDMATCH;
117758 }else{
117759 /* "[...]" immediately follows the "*". We have to do a slow
117760 ** recursive search in this case, but it is an unusual case. */
117761 assert( matchOther<0x80 ); /* '[' is a single-byte character */
117762 while( *zString ){
117763 int bMatch = patternCompare(&zPattern[-1],zString,pInfo,matchOther);
117764 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
117765 SQLITE_SKIP_UTF8(zString);
117766 }
117767 return SQLITE_NOWILDCARDMATCH;
117768 }
117769 }
117770
117771 /* At this point variable c contains the first character of the
117772 ** pattern string past the "*". Search in the input string for the
117773 ** first matching character and recursively continue the match from
117774 ** that point.
117775 **
117776 ** For a case-insensitive search, set variable cx to be the same as
117777 ** c but in the other case and search the input string for either
117778 ** c or cx.
117779 */
117780 if( c<=0x80 ){
117781 char zStop[3];
117782 int bMatch;
117783 if( noCase ){
117784 zStop[0] = sqlite3Toupper(c);
117785 zStop[1] = sqlite3Tolower(c);
117786 zStop[2] = 0;
117787 }else{
117788 zStop[0] = c;
117789 zStop[1] = 0;
117790 }
117791 while(1){
117792 zString += strcspn((const char*)zString, zStop);
117793 if( zString[0]==0 ) break;
117794 zString++;
117795 bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
117796 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
117797 }
117798 }else{
117799 int bMatch;
117800 while( (c2 = Utf8Read(zString))!=0 ){
117801 if( c2!=c ) continue;
117802 bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
117803 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
117804 }
117805 }
117806 return SQLITE_NOWILDCARDMATCH;
117807 }
117808 if( c==matchOther ){
117809 if( pInfo->matchSet==0 ){
117810 c = sqlite3Utf8Read(&zPattern);
117811 if( c==0 ) return SQLITE_NOMATCH;
117812 zEscaped = zPattern;
117813 }else{
117814 u32 prior_c = 0;
117815 int seen = 0;
117816 int invert = 0;
117817 c = sqlite3Utf8Read(&zString);
117818 if( c==0 ) return SQLITE_NOMATCH;
117819 c2 = sqlite3Utf8Read(&zPattern);
117820 if( c2=='^' ){
117821 invert = 1;
117822 c2 = sqlite3Utf8Read(&zPattern);
117823 }
117824 if( c2==']' ){
117825 if( c==']' ) seen = 1;
117826 c2 = sqlite3Utf8Read(&zPattern);
117827 }
117828 while( c2 && c2!=']' ){
117829 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
117830 c2 = sqlite3Utf8Read(&zPattern);
117831 if( c>=prior_c && c<=c2 ) seen = 1;
117832 prior_c = 0;
117833 }else{
117834 if( c==c2 ){
117835 seen = 1;
117836 }
117837 prior_c = c2;
117838 }
117839 c2 = sqlite3Utf8Read(&zPattern);
117840 }
117841 if( c2==0 || (seen ^ invert)==0 ){
117842 return SQLITE_NOMATCH;
117843 }
117844 continue;
117845 }
117846 }
117847 c2 = Utf8Read(zString);
117848 if( c==c2 ) continue;
117849 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
117850 continue;
static int patternCompare(const u8 *zPattern, const u8 *zString, const struct compareInfo *pInfo, u32 matchOther)
Definition sqlite3.c:117724
#define SQLITE_NOWILDCARDMATCH
Definition sqlite3.c:117684
#define Utf8Read(A)
Definition sqlite3.c:117668
#define SQLITE_NOMATCH
Definition sqlite3.c:117683
#define SQLITE_MATCH
Definition sqlite3.c:117682
#define SQLITE_SKIP_UTF8(zIn)
Definition sqlite3.c:19250

References compareInfo::matchAll, compareInfo::matchOne, compareInfo::matchSet, compareInfo::noCase, patternCompare(), sqlite3Tolower, sqlite3Toupper, sqlite3Utf8Read(), SQLITE_MATCH, SQLITE_NOMATCH, SQLITE_NOWILDCARDMATCH, SQLITE_SKIP_UTF8, and Utf8Read.

Referenced by likeFunc(), and patternCompare().

◆ pcache1Alloc()

static void * pcache1Alloc ( int nByte)
static

Definition at line 50091 of file sqlite3.c.

50097 {
50098 void *p = 0;
50099 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
50100 if( nByte<=pcache1.szSlot ){
50102 p = (PgHdr1 *)pcache1.pFree;
50103 if( p ){
50104 pcache1.pFree = pcache1.pFree->pNext;
50105 pcache1.nFreeSlot--;
50106 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
50107 assert( pcache1.nFreeSlot>=0 );
50110 }
50112 }
50113 if( p==0 ){
50114 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
50115 ** it from sqlite3Malloc instead.
50116 */
50117 p = sqlite3Malloc(nByte);
50118#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
50119 if( p ){
50120 int sz = sqlite3MallocSize(p);
#define SQLITE_STATUS_PAGECACHE_USED
Definition sqlite3.c:9051
#define pcache1
Definition sqlite3.c:49994
#define SQLITE_STATUS_PAGECACHE_OVERFLOW
Definition sqlite3.c:9052
SQLITE_PRIVATE void sqlite3StatusUp(int, int)
Definition sqlite3.c:21402
#define SQLITE_STATUS_PAGECACHE_SIZE
Definition sqlite3.c:9057

References MEMTYPE_PCACHE, pcache1, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_mutex_notheld(), sqlite3Malloc(), sqlite3MallocSize(), sqlite3MemdebugSetType, sqlite3StatusHighwater(), sqlite3StatusUp(), SQLITE_STATUS_PAGECACHE_OVERFLOW, SQLITE_STATUS_PAGECACHE_SIZE, and SQLITE_STATUS_PAGECACHE_USED.

◆ pcache1AllocPage()

static PgHdr1 * pcache1AllocPage ( PCache1 * pCache,
int benignMalloc )
static

Definition at line 50179 of file sqlite3.c.

50185 {
50186 PgHdr1 *p = 0;
50187 void *pPg;
50188
50189 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
50190 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
50191 assert( pCache->pFree!=0 );
50192 p = pCache->pFree;
50193 pCache->pFree = p->pNext;
50194 p->pNext = 0;
50195 }else{
50196#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
50197 /* The group mutex must be released before pcache1Alloc() is called. This
50198 ** is because it might call sqlite3_release_memory(), which assumes that
50199 ** this mutex is not held. */
50200 assert( pcache1.separateCache==0 );
50201 assert( pCache->pGroup==&pcache1.grp );
50202 pcache1LeaveMutex(pCache->pGroup);
50203#endif
50204 if( benignMalloc ){ sqlite3BeginBenignMalloc(); }
50205#ifdef SQLITE_PCACHE_SEPARATE_HEADER
50206 pPg = pcache1Alloc(pCache->szPage);
50207 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
50208 if( !pPg || !p ){
50209 pcache1Free(pPg);
50210 sqlite3_free(p);
50211 pPg = 0;
50212 }
50213#else
50214 pPg = pcache1Alloc(pCache->szAlloc);
50215#endif
50216 if( benignMalloc ){ sqlite3EndBenignMalloc(); }
50217#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
50218 pcache1EnterMutex(pCache->pGroup);
50219#endif
50220 if( pPg==0 ) return 0;
50221#ifndef SQLITE_PCACHE_SEPARATE_HEADER
50222 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
50223#endif
50224 p->page.pBuf = pPg;
50225 p->page.pExtra = &p[1];
#define pcache1LeaveMutex(X)
Definition sqlite3.c:50001
static int pcache1InitBulk(PCache1 *pCache)
Definition sqlite3.c:50048
#define pcache1EnterMutex(X)
Definition sqlite3.c:50000
static void * pcache1Alloc(int nByte)
Definition sqlite3.c:50091
static void pcache1Free(void *p)
Definition sqlite3.c:50129
int szPage
Definition sqlite3.c:49931
int szExtra
Definition sqlite3.c:49932
PgHdr1 * pFree
Definition sqlite3.c:49948
int szAlloc
Definition sqlite3.c:49933
unsigned int nPage
Definition sqlite3.c:49945
PGroup * pGroup
Definition sqlite3.c:49929
sqlite3_mutex * mutex
Definition sqlite3.c:49906
sqlite3_pcache_page page
Definition sqlite3.c:49865
PgHdr1 * pNext
Definition sqlite3.c:49869

Referenced by pcache1FetchStage2().

◆ pcache1Cachesize()

static void pcache1Cachesize ( sqlite3_pcache * p,
int nMax )
static

Definition at line 50575 of file sqlite3.c.

50581 {
50582 PCache1 *pCache = (PCache1 *)p;
50583 if( pCache->bPurgeable ){
50584 PGroup *pGroup = pCache->pGroup;
50585 pcache1EnterMutex(pGroup);
50586 pGroup->nMaxPage += (nMax - pCache->nMax);
50587 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
int bPurgeable
Definition sqlite3.c:49934
unsigned int nMax
Definition sqlite3.c:49936
unsigned int nMaxPage
Definition sqlite3.c:49907
unsigned int mxPinned
Definition sqlite3.c:49909
unsigned int nMinPage
Definition sqlite3.c:49908

References PCache1::bPurgeable, PGroup::mxPinned, PCache1::n90pct, PCache1::nMax, PGroup::nMaxPage, PGroup::nMinPage, pcache1EnforceMaxPage(), pcache1EnterMutex, pcache1LeaveMutex, and PCache1::pGroup.

Referenced by sqlite3PCacheSetDefault().

◆ pcache1Create()

static sqlite3_pcache * pcache1Create ( int szPage,
int szExtra,
int bPurgeable )
static

Definition at line 50525 of file sqlite3.c.

50531 {
50532 PCache1 *pCache; /* The newly created page cache */
50533 PGroup *pGroup; /* The group the new page cache will belong to */
50534 int sz; /* Bytes of memory required to allocate the new cache */
50535
50536 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
50537 assert( szExtra < 300 );
50538
50539 sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache;
50540 pCache = (PCache1 *)sqlite3MallocZero(sz);
50541 if( pCache ){
50542 if( pcache1.separateCache ){
50543 pGroup = (PGroup*)&pCache[1];
50544 pGroup->mxPinned = 10;
50545 }else{
50546 pGroup = &pcache1.grp;
50547 }
50548 pcache1EnterMutex(pGroup);
50549 if( pGroup->lru.isAnchor==0 ){
50550 pGroup->lru.isAnchor = 1;
50551 pGroup->lru.pLruPrev = pGroup->lru.pLruNext = &pGroup->lru;
50552 }
50553 pCache->pGroup = pGroup;
50554 pCache->szPage = szPage;
50555 pCache->szExtra = szExtra;
50556 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
50557 pCache->bPurgeable = (bPurgeable ? 1 : 0);
50558 pcache1ResizeHash(pCache);
50559 if( bPurgeable ){
50560 pCache->nMin = 10;
50561 pGroup->nMinPage += pCache->nMin;
50562 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
50563 pCache->pnPurgeable = &pGroup->nPurgeable;
50564 }else{
50565 pCache->pnPurgeable = &pCache->nPurgeableDummy;
50566 }
50567 pcache1LeaveMutex(pGroup);
50568 if( pCache->nHash==0 ){
static void pcache1ResizeHash(PCache1 *p)
Definition sqlite3.c:50298
struct PCache1 PCache1
Definition sqlite3.c:49843
unsigned int nHash
Definition sqlite3.c:49946
unsigned int nPurgeableDummy
Definition sqlite3.c:49939
unsigned int nMin
Definition sqlite3.c:49935
unsigned int * pnPurgeable
Definition sqlite3.c:49930
unsigned int nPurgeable
Definition sqlite3.c:49910
PgHdr1 lru
Definition sqlite3.c:49911
u16 isAnchor
Definition sqlite3.c:49868
PgHdr1 * pLruPrev
Definition sqlite3.c:49872
PgHdr1 * pLruNext
Definition sqlite3.c:49871

References PCache1::bPurgeable, PgHdr1::isAnchor, PGroup::lru, PGroup::mxPinned, PCache1::nHash, PGroup::nMaxPage, PCache1::nMin, PGroup::nMinPage, PGroup::nPurgeable, PCache1::nPurgeableDummy, pcache1, pcache1Destroy(), pcache1EnterMutex, pcache1LeaveMutex, pcache1ResizeHash(), PCache1::pGroup, PgHdr1::pLruNext, PgHdr1::pLruPrev, PCache1::pnPurgeable, ROUND8, sqlite3MallocZero(), PCache1::szAlloc, PCache1::szExtra, and PCache1::szPage.

Referenced by sqlite3PCacheSetDefault().

◆ pcache1Destroy()

static void pcache1Destroy ( sqlite3_pcache * p)
static

Definition at line 50923 of file sqlite3.c.

50929 {
50930 PCache1 *pCache = (PCache1 *)p;
50931 PGroup *pGroup = pCache->pGroup;
50932 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
50933 pcache1EnterMutex(pGroup);
50934 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
50935 assert( pGroup->nMaxPage >= pCache->nMax );
50936 pGroup->nMaxPage -= pCache->nMax;
50937 assert( pGroup->nMinPage >= pCache->nMin );
50938 pGroup->nMinPage -= pCache->nMin;
50939 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
static void pcache1TruncateUnsafe(PCache1 *pCache, unsigned int iLimit)
Definition sqlite3.c:50407

References PCache1::apHash, PCache1::bPurgeable, PGroup::mxPinned, PCache1::nMax, PGroup::nMaxPage, PCache1::nMin, PGroup::nMinPage, PCache1::nPage, PCache1::pBulk, pcache1EnforceMaxPage(), pcache1EnterMutex, pcache1LeaveMutex, pcache1TruncateUnsafe(), PCache1::pGroup, and sqlite3_free().

Referenced by pcache1Create(), and sqlite3PCacheSetDefault().

◆ pcache1EnforceMaxPage()

static void pcache1EnforceMaxPage ( PCache1 * pCache)
static

Definition at line 50382 of file sqlite3.c.

50388 {
50389 PGroup *pGroup = pCache->pGroup;
50390 PgHdr1 *p;
50391 assert( sqlite3_mutex_held(pGroup->mutex) );
50392 while( pGroup->nPurgeable>pGroup->nMaxPage
50393 && (p=pGroup->lru.pLruPrev)->isAnchor==0
50394 ){
50395 assert( p->pCache->pGroup==pGroup );
50396 assert( PAGE_IS_UNPINNED(p) );
50397 pcache1PinPage(p);
static void pcache1RemoveFromHash(PgHdr1 *pPage, int freeFlag)
Definition sqlite3.c:50364
static PgHdr1 * pcache1PinPage(PgHdr1 *pPage)
Definition sqlite3.c:50339
#define PAGE_IS_UNPINNED(p)
Definition sqlite3.c:49881
PCache1 * pCache
Definition sqlite3.c:49870

Referenced by pcache1Cachesize(), pcache1Destroy(), and pcache1Shrink().

◆ pcache1Fetch()

static sqlite3_pcache_page * pcache1Fetch ( sqlite3_pcache * p,
unsigned int iKey,
int createFlag )
static

Definition at line 50802 of file sqlite3.c.

50812 {
50813#if PCACHE1_MIGHT_USE_GROUP_MUTEX || defined(SQLITE_DEBUG)
50814 PCache1 *pCache = (PCache1 *)p;
50815#endif
50816
50817 assert( offsetof(PgHdr1,page)==0 );
50818 assert( pCache->bPurgeable || createFlag!=1 );
50819 assert( pCache->bPurgeable || pCache->nMin==0 );
50820 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
50821 assert( pCache->nMin==0 || pCache->bPurgeable );
50822 assert( pCache->nHash>0 );
50823#if PCACHE1_MIGHT_USE_GROUP_MUTEX
50824 if( pCache->pGroup->mutex ){
50825 return (sqlite3_pcache_page*)pcache1FetchWithMutex(p, iKey, createFlag);

Referenced by sqlite3PCacheSetDefault().

◆ pcache1FetchNoMutex()

static PgHdr1 * pcache1FetchNoMutex ( sqlite3_pcache * p,
unsigned int iKey,
int createFlag )
static

Definition at line 50757 of file sqlite3.c.

50767 {
50768 PCache1 *pCache = (PCache1 *)p;
50769 PgHdr1 *pPage = 0;
50770
50771 /* Step 1: Search the hash table for an existing entry. */
50772 pPage = pCache->apHash[iKey % pCache->nHash];
50773 while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
50774
50775 /* Step 2: If the page was found in the hash table, then return it.
50776 ** If the page was not in the hash table and createFlag is 0, abort.
50777 ** Otherwise (page not in hash and createFlag!=0) continue with
50778 ** subsequent steps to try to create the page. */
50779 if( pPage ){
50780 if( PAGE_IS_UNPINNED(pPage) ){
50781 return pcache1PinPage(pPage);
50782 }else{
50783 return pPage;
50784 }
50785 }else if( createFlag ){
PgHdr1 ** apHash
Definition sqlite3.c:49947
unsigned int iKey
Definition sqlite3.c:49866

References PCache1::apHash, PgHdr1::iKey, PCache1::nHash, PAGE_IS_UNPINNED, pcache1FetchStage2(), pcache1PinPage(), and PgHdr1::pNext.

◆ pcache1FetchStage2()

static SQLITE_NOINLINE PgHdr1 * pcache1FetchStage2 ( PCache1 * pCache,
unsigned int iKey,
int createFlag )
static

Definition at line 50629 of file sqlite3.c.

50639 {
50640 unsigned int nPinned;
50641 PGroup *pGroup = pCache->pGroup;
50642 PgHdr1 *pPage = 0;
50643
50644 /* Step 3: Abort if createFlag is 1 but the cache is nearly full */
50645 assert( pCache->nPage >= pCache->nRecyclable );
50646 nPinned = pCache->nPage - pCache->nRecyclable;
50647 assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
50648 assert( pCache->n90pct == pCache->nMax*9/10 );
50649 if( createFlag==1 && (
50650 nPinned>=pGroup->mxPinned
50651 || nPinned>=pCache->n90pct
50652 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
50653 )){
50654 return 0;
50655 }
50656
50657 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
50658 assert( pCache->nHash>0 && pCache->apHash );
50659
50660 /* Step 4. Try to recycle a page. */
50661 if( pCache->bPurgeable
50662 && !pGroup->lru.pLruPrev->isAnchor
50663 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
50664 ){
50665 PCache1 *pOther;
50666 pPage = pGroup->lru.pLruPrev;
50667 assert( PAGE_IS_UNPINNED(pPage) );
50668 pcache1RemoveFromHash(pPage, 0);
50669 pcache1PinPage(pPage);
50670 pOther = pPage->pCache;
50671 if( pOther->szAlloc != pCache->szAlloc ){
50672 pcache1FreePage(pPage);
50673 pPage = 0;
50674 }else{
50675 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
50676 }
50677 }
50678
50679 /* Step 5. If a usable page buffer has still not been found,
50680 ** attempt to allocate a new one.
50681 */
50682 if( !pPage ){
50683 pPage = pcache1AllocPage(pCache, createFlag==1);
50684 }
50685
50686 if( pPage ){
50687 unsigned int h = iKey % pCache->nHash;
50688 pCache->nPage++;
50689 pPage->iKey = iKey;
50690 pPage->pNext = pCache->apHash[h];
50691 pPage->pCache = pCache;
50692 pPage->pLruNext = 0;
50693 /* pPage->pLruPrev = 0;
50694 ** No need to clear pLruPrev since it is not accessed when pLruNext==0 */
50695 *(void **)pPage->page.pExtra = 0;
50696 pCache->apHash[h] = pPage;
static PgHdr1 * pcache1AllocPage(PCache1 *pCache, int benignMalloc)
Definition sqlite3.c:50179
static int pcache1UnderMemoryPressure(PCache1 *pCache)
Definition sqlite3.c:50281
static void pcache1FreePage(PgHdr1 *p)
Definition sqlite3.c:50230
unsigned int nRecyclable
Definition sqlite3.c:49944
unsigned int n90pct
Definition sqlite3.c:49937

References PCache1::apHash, PCache1::bPurgeable, PgHdr1::iKey, PCache1::iMaxKey, PgHdr1::isAnchor, PGroup::lru, PGroup::mxPinned, PCache1::n90pct, PCache1::nHash, PCache1::nMax, PGroup::nMaxPage, PGroup::nMinPage, PCache1::nPage, PGroup::nPurgeable, PCache1::nRecyclable, PgHdr1::page, PAGE_IS_UNPINNED, PgHdr1::pCache, pcache1AllocPage(), pcache1FreePage(), pcache1PinPage(), pcache1RemoveFromHash(), pcache1ResizeHash(), pcache1UnderMemoryPressure(), sqlite3_pcache_page::pExtra, PCache1::pGroup, PgHdr1::pLruNext, PgHdr1::pLruPrev, PgHdr1::pNext, and PCache1::szAlloc.

Referenced by pcache1FetchNoMutex().

◆ pcache1Free()

static void pcache1Free ( void * p)
static

Definition at line 50129 of file sqlite3.c.

50135 {
50136 if( p==0 ) return;
50137 if( SQLITE_WITHIN(p, pcache1.pStart, pcache1.pEnd) ){
50138 PgFreeslot *pSlot;
50141 pSlot = (PgFreeslot*)p;
50142 pSlot->pNext = pcache1.pFree;
50143 pcache1.pFree = pSlot;
50144 pcache1.nFreeSlot++;
50145 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
50146 assert( pcache1.nFreeSlot<=pcache1.nSlot );
50148 }else{
50151#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
50152 {
50153 int nFreed = 0;
50154 nFreed = sqlite3MallocSize(p);
SQLITE_PRIVATE void sqlite3StatusDown(int, int)
Definition sqlite3.c:21413
#define MEMTYPE_PCACHE
Definition sqlite3.c:20333
PgFreeslot * pNext
Definition sqlite3.c:49957

◆ pcache1FreePage()

static void pcache1FreePage ( PgHdr1 * p)
static

Definition at line 50230 of file sqlite3.c.

50236 {
50237 PCache1 *pCache;
50238 assert( p!=0 );
50239 pCache = p->pCache;
50240 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
50241 if( p->isBulkLocal ){
50242 p->pNext = pCache->pFree;
50243 pCache->pFree = p;
50244 }else{
50245 pcache1Free(p->page.pBuf);
u16 isBulkLocal
Definition sqlite3.c:49867

Referenced by pcache1FetchStage2(), pcache1RemoveFromHash(), and pcache1TruncateUnsafe().

◆ pcache1Init()

static int pcache1Init ( void * NotUsed)
static

Definition at line 50458 of file sqlite3.c.

50464 {
50465 UNUSED_PARAMETER(NotUsed);
50466 assert( pcache1.isInit==0 );
50467 memset(&pcache1, 0, sizeof(pcache1));
50468
50469
50470 /*
50471 ** The pcache1.separateCache variable is true if each PCache has its own
50472 ** private PGroup (mode-1). pcache1.separateCache is false if the single
50473 ** PGroup in pcache1.grp is used for all page caches (mode-2).
50474 **
50475 ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
50476 **
50477 ** * Use a unified cache in single-threaded applications that have
50478 ** configured a start-time buffer for use as page-cache memory using
50479 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
50480 ** pBuf argument.
50481 **
50482 ** * Otherwise use separate caches (mode-1)
50483 */
50484#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
50485 pcache1.separateCache = 0;
50486#elif SQLITE_THREADSAFE
50487 pcache1.separateCache = sqlite3GlobalConfig.pPage==0
50488 || sqlite3GlobalConfig.bCoreMutex>0;
50489#else
50490 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
50491#endif
50492
50493#if SQLITE_THREADSAFE
50494 if( sqlite3GlobalConfig.bCoreMutex ){
50497 }
50498#endif
50499 if( pcache1.separateCache
50500 && sqlite3GlobalConfig.nPage!=0
50501 && sqlite3GlobalConfig.pPage==0
50502 ){
50503 pcache1.nInitPage = sqlite3GlobalConfig.nPage;
50504 }else{
#define SQLITE_MUTEX_STATIC_LRU
Definition sqlite3.c:8636
#define SQLITE_MUTEX_STATIC_PMEM
Definition sqlite3.c:8638

References pcache1, sqlite3GlobalConfig, sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_LRU, SQLITE_MUTEX_STATIC_PMEM, SQLITE_OK, and UNUSED_PARAMETER.

Referenced by sqlite3PCacheSetDefault().

◆ pcache1InitBulk()

static int pcache1InitBulk ( PCache1 * pCache)
static

Definition at line 50048 of file sqlite3.c.

50054 {
50055 i64 szBulk;
50056 char *zBulk;
50057 if( pcache1.nInitPage==0 ) return 0;
50058 /* Do not bother with a bulk allocation if the cache size very small */
50059 if( pCache->nMax<3 ) return 0;
50061 if( pcache1.nInitPage>0 ){
50062 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
50063 }else{
50064 szBulk = -1024 * (i64)pcache1.nInitPage;
50065 }
50066 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
50067 szBulk = pCache->szAlloc*(i64)pCache->nMax;
50068 }
50069 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
50071 if( zBulk ){
50072 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
50073 do{
50074 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
50075 pX->page.pBuf = zBulk;
50076 pX->page.pExtra = &pX[1];
50077 pX->isBulkLocal = 1;
50078 pX->isAnchor = 0;
50079 pX->pNext = pCache->pFree;
50080 pX->pLruPrev = 0; /* Initializing this saves a valgrind error */
void * pBulk
Definition sqlite3.c:49949

◆ pcache1Pagecount()

static int pcache1Pagecount ( sqlite3_pcache * p)
static

Definition at line 50611 of file sqlite3.c.

50617 {
50618 int n;

Referenced by sqlite3PCacheSetDefault().

◆ pcache1PinPage()

static PgHdr1 * pcache1PinPage ( PgHdr1 * pPage)
static

Definition at line 50339 of file sqlite3.c.

50345 {
50346 assert( pPage!=0 );
50347 assert( PAGE_IS_UNPINNED(pPage) );
50348 assert( pPage->pLruNext );
50349 assert( pPage->pLruPrev );
50350 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
50351 pPage->pLruPrev->pLruNext = pPage->pLruNext;
50352 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
50353 pPage->pLruNext = 0;
50354 /* pPage->pLruPrev = 0;

References PgHdr1::isAnchor, PGroup::lru, PGroup::mutex, PCache1::nRecyclable, PAGE_IS_UNPINNED, PgHdr1::pCache, PCache1::pGroup, PgHdr1::pLruNext, PgHdr1::pLruPrev, and sqlite3_mutex_held().

Referenced by pcache1FetchNoMutex(), pcache1FetchStage2(), and pcache1TruncateUnsafe().

◆ pcache1Rekey()

static void pcache1Rekey ( sqlite3_pcache * p,
sqlite3_pcache_page * pPg,
unsigned int iOld,
unsigned int iNew )
static

Definition at line 50868 of file sqlite3.c.

50879 {
50880 PCache1 *pCache = (PCache1 *)p;
50881 PgHdr1 *pPage = (PgHdr1 *)pPg;
50882 PgHdr1 **pp;
50883 unsigned int h;
50884 assert( pPage->iKey==iOld );
50885 assert( pPage->pCache==pCache );
50886
50887 pcache1EnterMutex(pCache->pGroup);
50888
50889 h = iOld%pCache->nHash;
50890 pp = &pCache->apHash[h];
50891 while( (*pp)!=pPage ){
50892 pp = &(*pp)->pNext;
50893 }
50894 *pp = pPage->pNext;
50895
50896 h = iNew%pCache->nHash;
50897 pPage->iKey = iNew;
50898 pPage->pNext = pCache->apHash[h];
50899 pCache->apHash[h] = pPage;

Referenced by sqlite3PCacheSetDefault().

◆ pcache1RemoveFromHash()

static void pcache1RemoveFromHash ( PgHdr1 * pPage,
int freeFlag )
static

Definition at line 50364 of file sqlite3.c.

50370 {
50371 unsigned int h;
50372 PCache1 *pCache = pPage->pCache;
50373 PgHdr1 **pp;
50374
50375 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
50376 h = pPage->iKey % pCache->nHash;

References PCache1::apHash, PgHdr1::iKey, PGroup::mutex, PCache1::nHash, PCache1::nPage, PgHdr1::pCache, pcache1FreePage(), PCache1::pGroup, PgHdr1::pNext, and sqlite3_mutex_held().

Referenced by pcache1FetchStage2(), and pcache1Unpin().

◆ pcache1ResizeHash()

static void pcache1ResizeHash ( PCache1 * p)
static

Definition at line 50298 of file sqlite3.c.

50304 {
50305 PgHdr1 **apNew;
50306 unsigned int nNew;
50307 unsigned int i;
50308
50309 assert( sqlite3_mutex_held(p->pGroup->mutex) );
50310
50311 nNew = p->nHash*2;
50312 if( nNew<256 ){
50313 nNew = 256;
50314 }
50315
50317 if( p->nHash ){ sqlite3BeginBenignMalloc(); }
50318 apNew = (PgHdr1 **)sqlite3MallocZero(sizeof(PgHdr1 *)*nNew);
50319 if( p->nHash ){ sqlite3EndBenignMalloc(); }
50321 if( apNew ){
50322 for(i=0; i<p->nHash; i++){
50323 PgHdr1 *pPage;
50324 PgHdr1 *pNext = p->apHash[i];
50325 while( (pPage = pNext)!=0 ){
50326 unsigned int h = pPage->iKey % nNew;
50327 pNext = pPage->pNext;
50328 pPage->pNext = apNew[h];
50329 apNew[h] = pPage;
50330 }

References PCache1::apHash, PgHdr1::iKey, PGroup::mutex, PCache1::nHash, pcache1EnterMutex, pcache1LeaveMutex, PCache1::pGroup, PgHdr1::pNext, sqlite3_free(), sqlite3_mutex_held(), sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), and sqlite3MallocZero().

Referenced by pcache1Create(), and pcache1FetchStage2().

◆ pcache1Shrink()

static void pcache1Shrink ( sqlite3_pcache * p)
static

Definition at line 50594 of file sqlite3.c.

50600 {
50601 PCache1 *pCache = (PCache1*)p;
50602 if( pCache->bPurgeable ){
50603 PGroup *pGroup = pCache->pGroup;
50604 int savedMaxPage;
50605 pcache1EnterMutex(pGroup);
50606 savedMaxPage = pGroup->nMaxPage;

References PCache1::bPurgeable, PGroup::nMaxPage, pcache1EnforceMaxPage(), pcache1EnterMutex, pcache1LeaveMutex, and PCache1::pGroup.

Referenced by sqlite3PCacheSetDefault().

◆ pcache1Shutdown()

static void pcache1Shutdown ( void * NotUsed)
static

Definition at line 50511 of file sqlite3.c.

References pcache1, and UNUSED_PARAMETER.

Referenced by sqlite3PCacheSetDefault().

◆ pcache1Truncate()

static void pcache1Truncate ( sqlite3_pcache * p,
unsigned int iLimit )
static

Definition at line 50908 of file sqlite3.c.

50914 {
50915 PCache1 *pCache = (PCache1 *)p;
50916 pcache1EnterMutex(pCache->pGroup);

References PCache1::iMaxKey, pcache1EnterMutex, pcache1LeaveMutex, pcache1TruncateUnsafe(), and PCache1::pGroup.

Referenced by sqlite3PCacheSetDefault().

◆ pcache1TruncateUnsafe()

static void pcache1TruncateUnsafe ( PCache1 * pCache,
unsigned int iLimit )
static

Definition at line 50407 of file sqlite3.c.

50416 {
50417 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
50418 unsigned int h, iStop;
50419 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
50420 assert( pCache->iMaxKey >= iLimit );
50421 assert( pCache->nHash > 0 );
50422 if( pCache->iMaxKey - iLimit < pCache->nHash ){
50423 /* If we are just shaving the last few pages off the end of the
50424 ** cache, then there is no point in scanning the entire hash table.
50425 ** Only scan those hash slots that might contain pages that need to
50426 ** be removed. */
50427 h = iLimit % pCache->nHash;
50428 iStop = pCache->iMaxKey % pCache->nHash;
50429 TESTONLY( nPage = -10; ) /* Disable the pCache->nPage validity check */
50430 }else{
50431 /* This is the general case where many pages are being removed.
50432 ** It is necessary to scan the entire hash table */
50433 h = pCache->nHash/2;
50434 iStop = h - 1;
50435 }
50436 for(;;){
50437 PgHdr1 **pp;
50438 PgHdr1 *pPage;
50439 assert( h<pCache->nHash );
50440 pp = &pCache->apHash[h];
50441 while( (pPage = *pp)!=0 ){
50442 if( pPage->iKey>=iLimit ){
50443 pCache->nPage--;
50444 *pp = pPage->pNext;
50445 if( PAGE_IS_UNPINNED(pPage) ) pcache1PinPage(pPage);
50446 pcache1FreePage(pPage);
50447 }else{
50448 pp = &pPage->pNext;
50449 TESTONLY( if( nPage>=0 ) nPage++; )
50450 }
unsigned int iMaxKey
Definition sqlite3.c:49938

References PCache1::apHash, PgHdr1::iKey, PCache1::iMaxKey, PGroup::mutex, PCache1::nHash, PCache1::nPage, PAGE_IS_UNPINNED, pcache1FreePage(), pcache1PinPage(), PCache1::pGroup, PgHdr1::pNext, sqlite3_mutex_held(), and TESTONLY.

Referenced by pcache1Destroy(), and pcache1Truncate().

◆ pcache1UnderMemoryPressure()

static int pcache1UnderMemoryPressure ( PCache1 * pCache)
static

Definition at line 50281 of file sqlite3.c.

50287 {

References pcache1, sqlite3HeapNearlyFull(), PCache1::szExtra, and PCache1::szPage.

Referenced by pcache1FetchStage2().

◆ pcache1Unpin()

static void pcache1Unpin ( sqlite3_pcache * p,
sqlite3_pcache_page * pPg,
int reuseUnlikely )
static

Definition at line 50833 of file sqlite3.c.

50843 {
50844 PCache1 *pCache = (PCache1 *)p;
50845 PgHdr1 *pPage = (PgHdr1 *)pPg;
50846 PGroup *pGroup = pCache->pGroup;
50847
50848 assert( pPage->pCache==pCache );
50849 pcache1EnterMutex(pGroup);
50850
50851 /* It is an error to call this function if the page is already
50852 ** part of the PGroup LRU list.
50853 */
50854 assert( pPage->pLruNext==0 );
50855 assert( PAGE_IS_PINNED(pPage) );
50856
50857 if( reuseUnlikely || pGroup->nPurgeable>pGroup->nMaxPage ){
50858 pcache1RemoveFromHash(pPage, 1);
50859 }else{
50860 /* Add the page to the PGroup LRU list. */
50861 PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
50862 pPage->pLruPrev = &pGroup->lru;
50863 (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
#define PAGE_IS_PINNED(p)
Definition sqlite3.c:49880

References PGroup::lru, PGroup::nMaxPage, PGroup::nPurgeable, PCache1::nRecyclable, PAGE_IS_PINNED, PgHdr1::pCache, pcache1EnterMutex, pcache1RemoveFromHash(), PCache1::pGroup, PgHdr1::pLruNext, and PgHdr1::pLruPrev.

Referenced by sqlite3PCacheSetDefault().

◆ pcacheFetchFinishWithInit()

static SQLITE_NOINLINE PgHdr * pcacheFetchFinishWithInit ( PCache * pCache,
Pgno pgno,
sqlite3_pcache_page * pPage )
static

Definition at line 49333 of file sqlite3.c.

49343 {
49344 PgHdr *pPgHdr;
49345 assert( pPage!=0 );
49346 pPgHdr = (PgHdr*)pPage->pExtra;
49347 assert( pPgHdr->pPage==0 );
49348 memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
49349 pPgHdr->pPage = pPage;
49350 pPgHdr->pData = pPage->pBuf;
49351 pPgHdr->pExtra = (void *)&pPgHdr[1];

References PgHdr::flags, offsetof, sqlite3_pcache_page::pBuf, PgHdr::pCache, PgHdr::pData, PgHdr::pDirty, sqlite3_pcache_page::pExtra, PgHdr::pExtra, PGHDR_CLEAN, PgHdr::pgno, PgHdr::pPage, and sqlite3PcacheFetchFinish().

Referenced by sqlite3PcacheFetchFinish().

◆ pcacheManageDirtyList()

static void pcacheManageDirtyList ( PgHdr * pPage,
u8 addRemove )
static

Definition at line 49031 of file sqlite3.c.

49037 {
49038 PCache *p = pPage->pCache;
49039
49040 pcacheTrace(("%p.DIRTYLIST.%s %d\n", p,
49041 addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
49042 pPage->pgno));
49043 if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
49044 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
49045 assert( pPage->pDirtyPrev || pPage==p->pDirty );
49046
49047 /* Update the PCache1.pSynced variable if necessary. */
49048 if( p->pSynced==pPage ){
49049 p->pSynced = pPage->pDirtyPrev;
49050 }
49051
49052 if( pPage->pDirtyNext ){
49053 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
49054 }else{
49055 assert( pPage==p->pDirtyTail );
49056 p->pDirtyTail = pPage->pDirtyPrev;
49057 }
49058 if( pPage->pDirtyPrev ){
49059 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
49060 }else{
49061 /* If there are now no dirty pages in the cache, set eCreate to 2.
49062 ** This is an optimization that allows sqlite3PcacheFetch() to skip
49063 ** searching for a dirty page to eject from the cache when it might
49064 ** otherwise have to. */
49065 assert( pPage==p->pDirty );
49066 p->pDirty = pPage->pDirtyNext;
49067 assert( p->bPurgeable || p->eCreate==2 );
49068 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
49069 assert( p->bPurgeable==0 || p->eCreate==1 );
49070 p->eCreate = 2;
49071 }
49072 }
49073 }
49074 if( addRemove & PCACHE_DIRTYLIST_ADD ){
49075 pPage->pDirtyPrev = 0;
49076 pPage->pDirtyNext = p->pDirty;
49077 if( pPage->pDirtyNext ){
49078 assert( pPage->pDirtyNext->pDirtyPrev==0 );
49079 pPage->pDirtyNext->pDirtyPrev = pPage;
49080 }else{
49081 p->pDirtyTail = pPage;
49082 if( p->bPurgeable ){
49083 assert( p->eCreate==2 );
49084 p->eCreate = 1;
49085 }
49086 }
49087 p->pDirty = pPage;
49088
49089 /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
49090 ** pSynced to point to it. Checking the NEED_SYNC flag is an
49091 ** optimization, as if pSynced points to a page with the NEED_SYNC
49092 ** flag set sqlite3PcacheFetchStress() searches through all newer
49093 ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
49094 if( !p->pSynced
49095 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
#define PCACHE_DIRTYLIST_REMOVE
Definition sqlite3.c:49021
#define PCACHE_DIRTYLIST_ADD
Definition sqlite3.c:49022
#define pcacheTrace(X)
Definition sqlite3.c:48967
PgHdr * pDirty
Definition sqlite3.c:48915
u8 eCreate
Definition sqlite3.c:48923
PgHdr * pSynced
Definition sqlite3.c:48916
u8 bPurgeable
Definition sqlite3.c:48922
PgHdr * pDirtyTail
Definition sqlite3.c:48915
PCache * pCache
Definition sqlite3.c:16048
PgHdr * pDirtyNext
Definition sqlite3.c:16063
PgHdr * pDirtyPrev
Definition sqlite3.c:16064

References PCache::bPurgeable, PCache::eCreate, PgHdr::flags, PgHdr::pCache, PCACHE_DIRTYLIST_ADD, PCACHE_DIRTYLIST_REMOVE, pcacheDump, pcacheTrace, PCache::pDirty, PgHdr::pDirtyNext, PgHdr::pDirtyPrev, PCache::pDirtyTail, PGHDR_NEED_SYNC, PgHdr::pgno, and PCache::pSynced.

Referenced by sqlite3PcacheDrop().

◆ pcacheMergeDirtyList()

static PgHdr * pcacheMergeDirtyList ( PgHdr * pA,
PgHdr * pB )
static

Definition at line 49565 of file sqlite3.c.

49571 {
49572 PgHdr result, *pTail;
49573 pTail = &result;
49574 assert( pA!=0 && pB!=0 );
49575 for(;;){
49576 if( pA->pgno<pB->pgno ){
49577 pTail->pDirty = pA;
49578 pTail = pA;
49579 pA = pA->pDirty;
49580 if( pA==0 ){
49581 pTail->pDirty = pB;
49582 break;
49583 }
49584 }else{
49585 pTail->pDirty = pB;
49586 pTail = pB;
49587 pB = pB->pDirty;
49588 if( pB==0 ){
49589 pTail->pDirty = pA;

Referenced by pcacheSortDirtyList().

◆ pcacheSortDirtyList()

static PgHdr * pcacheSortDirtyList ( PgHdr * pIn)
static

Definition at line 49602 of file sqlite3.c.

49608 {
49609 PgHdr *a[N_SORT_BUCKET], *p;
49610 int i;
49611 memset(a, 0, sizeof(a));
49612 while( pIn ){
49613 p = pIn;
49614 pIn = p->pDirty;
49615 p->pDirty = 0;
49616 for(i=0; ALWAYS(i<N_SORT_BUCKET-1); i++){
49617 if( a[i]==0 ){
49618 a[i] = p;
49619 break;
49620 }else{
49621 p = pcacheMergeDirtyList(a[i], p);
49622 a[i] = 0;
49623 }
49624 }
49625 if( NEVER(i==N_SORT_BUCKET-1) ){
49626 /* To get here, there need to be 2^(N_SORT_BUCKET) elements in
49627 ** the input list. But that is impossible.
49628 */
49629 a[i] = pcacheMergeDirtyList(a[i], p);
49630 }
49631 }
49632 p = a[0];
#define N_SORT_BUCKET
Definition sqlite3.c:49601
static PgHdr * pcacheMergeDirtyList(PgHdr *pA, PgHdr *pB)
Definition sqlite3.c:49565

References ALWAYS, N_SORT_BUCKET, NEVER, pcacheMergeDirtyList(), and PgHdr::pDirty.

◆ pcacheUnpin()

static void pcacheUnpin ( PgHdr * p)
static

Definition at line 49101 of file sqlite3.c.

49107 {

◆ percent_rankInvFunc()

static void percent_rankInvFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151500 of file sqlite3.c.

151502 {
151503 p->nTotal++;
151504 }
151505}
151506static void percent_rankInvFunc(
151507 sqlite3_context *pCtx,
151508 int nArg,
151509 sqlite3_value **apArg
151510){
static void percent_rankInvFunc(sqlite3_context *pCtx, int nArg, sqlite3_value **apArg)
Definition sqlite3.c:151500

◆ percent_rankStepFunc()

static void percent_rankStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151487 of file sqlite3.c.

151497 {
151498 struct CallCount *p;
151499 UNUSED_PARAMETER(nArg); assert( nArg==0 );

References UNUSED_PARAMETER.

◆ percent_rankValueFunc()

static void percent_rankValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151511 of file sqlite3.c.

151517 {
151518 struct CallCount *p;
151519 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151520 if( p ){
151521 p->nValue = p->nStep;
151522 if( p->nTotal>1 ){
151523 double r = (double)p->nValue / (double)(p->nTotal-1);

◆ populateCellCache()

static void populateCellCache ( CellArray * p,
int idx,
int N )
static

Definition at line 71373 of file sqlite3.c.

71379 {
71380 assert( idx>=0 && idx+N<=p->nCell );
71381 while( N>0 ){
71382 assert( p->apCell[idx]!=0 );
71383 if( p->szCell[idx]==0 ){
71384 p->szCell[idx] = p->pRef->xCellSize(p->pRef, p->apCell[idx]);
71385 }else{
71386 assert( CORRUPT_DB ||

Referenced by editPage().

◆ posixOpen()

static int posixOpen ( const char * zFile,
int flags,
int mode )
static

Definition at line 33911 of file sqlite3.c.

◆ posixUnlock()

static int posixUnlock ( sqlite3_file * id,
int eFileLock,
int handleNFSUnlock )
static

Definition at line 35446 of file sqlite3.c.

35452 {
35453 unixFile *pFile = (unixFile*)id;
35454 unixInodeInfo *pInode;
35455 struct flock lock;
35456 int rc = SQLITE_OK;
35457
35458 assert( pFile );
35459 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
35460 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
35461 osGetpid(0)));
35462
35463 assert( eFileLock<=SHARED_LOCK );
35464 if( pFile->eFileLock<=eFileLock ){
35465 return SQLITE_OK;
35466 }
35467 pInode = pFile->pInode;
35469 assert( pInode->nShared!=0 );
35470 if( pFile->eFileLock>SHARED_LOCK ){
35471 assert( pInode->eFileLock==pFile->eFileLock );
35472
35473#ifdef SQLITE_DEBUG
35474 /* When reducing a lock such that other processes can start
35475 ** reading the database file again, make sure that the
35476 ** transaction counter was updated if any part of the database
35477 ** file changed. If the transaction counter is not updated,
35478 ** other connections to the same file might not realize that
35479 ** the file has changed and hence might not know to flush their
35480 ** cache. The use of a stale cache can lead to database corruption.
35481 */
35482 pFile->inNormalWrite = 0;
35483#endif
35484
35485 /* downgrading to a shared lock on NFS involves clearing the write lock
35486 ** before establishing the readlock - to avoid a race condition we downgrade
35487 ** the lock in 2 blocks, so that part of the range will be covered by a
35488 ** write lock until the rest is covered by a read lock:
35489 ** 1: [WWWWW]
35490 ** 2: [....W]
35491 ** 3: [RRRRW]
35492 ** 4: [RRRR.]
35493 */
35494 if( eFileLock==SHARED_LOCK ){
35495#if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
35496 (void)handleNFSUnlock;
35497 assert( handleNFSUnlock==0 );
35498#endif
35499#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
35500 if( handleNFSUnlock ){
35501 int tErrno; /* Error code from system call errors */
35502 off_t divSize = SHARED_SIZE - 1;
35503
35504 lock.l_type = F_UNLCK;
35505 lock.l_whence = SEEK_SET;
35506 lock.l_start = SHARED_FIRST;
35507 lock.l_len = divSize;
35508 if( unixFileLock(pFile, &lock)==(-1) ){
35509 tErrno = errno;
35511 storeLastErrno(pFile, tErrno);
35512 goto end_unlock;
35513 }
35514 lock.l_type = F_RDLCK;
35515 lock.l_whence = SEEK_SET;
35516 lock.l_start = SHARED_FIRST;
35517 lock.l_len = divSize;
35518 if( unixFileLock(pFile, &lock)==(-1) ){
35519 tErrno = errno;
35521 if( IS_LOCK_ERROR(rc) ){
35522 storeLastErrno(pFile, tErrno);
35523 }
35524 goto end_unlock;
35525 }
35526 lock.l_type = F_UNLCK;
35527 lock.l_whence = SEEK_SET;
35528 lock.l_start = SHARED_FIRST+divSize;
35529 lock.l_len = SHARED_SIZE-divSize;
35530 if( unixFileLock(pFile, &lock)==(-1) ){
35531 tErrno = errno;
35533 storeLastErrno(pFile, tErrno);
35534 goto end_unlock;
35535 }
35536 }else
35537#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
35538 {
35539 lock.l_type = F_RDLCK;
35540 lock.l_whence = SEEK_SET;
35541 lock.l_start = SHARED_FIRST;
35542 lock.l_len = SHARED_SIZE;
35543 if( unixFileLock(pFile, &lock) ){
35544 /* In theory, the call to unixFileLock() cannot fail because another
35545 ** process is holding an incompatible lock. If it does, this
35546 ** indicates that the other process is not following the locking
35547 ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning
35548 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
35549 ** an assert to fail). */
35551 storeLastErrno(pFile, errno);
35552 goto end_unlock;
35553 }
35554 }
35555 }
35556 lock.l_type = F_UNLCK;
35557 lock.l_whence = SEEK_SET;
35558 lock.l_start = PENDING_BYTE;
35559 lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
35560 if( unixFileLock(pFile, &lock)==0 ){
35561 pInode->eFileLock = SHARED_LOCK;
35562 }else{
35564 storeLastErrno(pFile, errno);
35565 goto end_unlock;
35566 }
35567 }
35568 if( eFileLock==NO_LOCK ){
35569 /* Decrement the shared lock counter. Release the lock using an
35570 ** OS call only when all threads in this same process have released
35571 ** the lock.
35572 */
35573 pInode->nShared--;
35574 if( pInode->nShared==0 ){
35575 lock.l_type = F_UNLCK;
35576 lock.l_whence = SEEK_SET;
35577 lock.l_start = lock.l_len = 0L;
35578 if( unixFileLock(pFile, &lock)==0 ){
35579 pInode->eFileLock = NO_LOCK;
35580 }else{
35582 storeLastErrno(pFile, errno);
35583 pInode->eFileLock = NO_LOCK;
35584 pFile->eFileLock = NO_LOCK;
35585 }
35586 }
35587
35588 /* Decrement the count of locks against this same file. When the
35589 ** count reaches zero, close any other file descriptors whose close
35590 ** was deferred because of outstanding locks.
35591 */
35592 pInode->nLock--;
35593 assert( pInode->nLock>=0 );
35594 if( pInode->nLock==0 ) closePendingFds(pFile);
35595 }
35596
35597end_unlock:
static int unixFileLock(unixFile *pFile, struct flock *pLock)
Definition sqlite3.c:35146
#define SHARED_SIZE
Definition sqlite3.c:16427
static void closePendingFds(unixFile *pFile)
Definition sqlite3.c:34846
#define SHARED_FIRST
Definition sqlite3.c:16426
#define RESERVED_BYTE
Definition sqlite3.c:16425
#define PENDING_BYTE
Definition sqlite3.c:16423
#define SQLITE_IOERR_RDLOCK
Definition sqlite3.c:1531
#define IS_LOCK_ERROR(x)
Definition sqlite3.c:33537
unsigned char eFileLock
Definition sqlite3.c:33567
unsigned char eFileLock
Definition sqlite3.c:34707

References closePendingFds(), unixFile::eFileLock, unixInodeInfo::eFileLock, unixFile::h, IS_LOCK_ERROR, unixInodeInfo::nLock, NO_LOCK, unixInodeInfo::nShared, osGetpid, OSTRACE, PENDING_BYTE, unixFile::pInode, unixInodeInfo::pLockMutex, RESERVED_BYTE, SHARED_FIRST, SHARED_LOCK, SHARED_SIZE, sqlite3_mutex_enter(), sqlite3_mutex_leave(), SQLITE_IOERR_RDLOCK, SQLITE_IOERR_UNLOCK, SQLITE_OK, sqliteErrorFromPosixError(), storeLastErrno(), and unixFileLock().

Referenced by unixUnlock().

◆ pragmaFunclistLine()

static void pragmaFunclistLine ( Vdbe * v,
FuncDef * p,
int isBuiltin,
int showInternFuncs )
static

Definition at line 126041 of file sqlite3.c.

126052 {
126053 for(; p; p=p->pNext){
126054 const char *zType;
126055 static const u32 mask =
126061 ;
126062 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
126063
126064 assert( SQLITE_FUNC_ENCMASK==0x3 );
126065 assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 );
126066 assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 );
126067 assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 );
126068
126069 if( p->xSFunc==0 ) continue;
126070 if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0
126071 && showInternFuncs==0
126072 ){
126073 continue;
126074 }
126075 if( p->xValue!=0 ){
126076 zType = "w";
126077 }else if( p->xFinalize!=0 ){
126078 zType = "a";
126079 }else{
126080 zType = "s";
126081 }
126082 sqlite3VdbeMultiLoad(v, 1, "sissii",
126083 p->zName, isBuiltin,
#define SQLITE_DETERMINISTIC
Definition sqlite3.c:6324
#define SQLITE_SUBTYPE
Definition sqlite3.c:6326
SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe *, int, const char *,...)
Definition sqlite3.c:78037
#define SQLITE_INNOCUOUS
Definition sqlite3.c:6327
FuncDef * pNext
Definition sqlite3.c:17098
void(* xFinalize)(sqlite3_context *)
Definition sqlite3.c:17100
void(* xValue)(sqlite3_context *)
Definition sqlite3.c:17101
const char * zName
Definition sqlite3.c:17103

Referenced by sqlite3Pragma().

◆ pragmaLocate()

static const PragmaName * pragmaLocate ( const char * zName)
static

Definition at line 126020 of file sqlite3.c.

126026 {
126027 int upr, lwr, mid = 0, rc;
126028 lwr = 0;
126029 upr = ArraySize(aPragmaName)-1;
126030 while( lwr<=upr ){
126031 mid = (lwr+upr)/2;
126033 if( rc==0 ) break;
126034 if( rc<0 ){
126035 upr = mid - 1;
static const PragmaName aPragmaName[]
Definition sqlite3.c:125254

Referenced by sqlite3Pragma(), and sqlite3PragmaVtabRegister().

◆ pragmaVtabBestIndex()

static int pragmaVtabBestIndex ( sqlite3_vtab * tab,
sqlite3_index_info * pIdxInfo )
static

Definition at line 128118 of file sqlite3.c.

128124 {
128125 PragmaVtab *pTab = (PragmaVtab*)tab;
128126 const struct sqlite3_index_constraint *pConstraint;
128127 int i, j;
128128 int seen[2];
128129
128130 pIdxInfo->estimatedCost = (double)1;
128131 if( pTab->nHidden==0 ){ return SQLITE_OK; }
128132 pConstraint = pIdxInfo->aConstraint;
128133 seen[0] = 0;
128134 seen[1] = 0;
128135 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
128136 if( pConstraint->usable==0 ) continue;
128137 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
128138 if( pConstraint->iColumn < pTab->iHidden ) continue;
128139 j = pConstraint->iColumn - pTab->iHidden;
128140 assert( j < 2 );
128141 seen[j] = i+1;
128142 }
128143 if( seen[0]==0 ){
128144 pIdxInfo->estimatedCost = (double)2147483647;
128145 pIdxInfo->estimatedRows = 2147483647;
128146 return SQLITE_OK;
128147 }
128148 j = seen[0]-1;
128149 pIdxInfo->aConstraintUsage[j].argvIndex = 1;
128150 pIdxInfo->aConstraintUsage[j].omit = 1;
128151 if( seen[1]==0 ) return SQLITE_OK;
128152 pIdxInfo->estimatedCost = (double)20;
sqlite3_int64 estimatedRows
Definition sqlite3.c:7923

References sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, sqlite3_index_info::sqlite3_index_constraint_usage::argvIndex, sqlite3_index_info::estimatedCost, sqlite3_index_info::estimatedRows, sqlite3_index_info::sqlite3_index_constraint::iColumn, PragmaVtab::iHidden, sqlite3_index_info::nConstraint, PragmaVtab::nHidden, sqlite3_index_info::sqlite3_index_constraint_usage::omit, SQLITE_INDEX_CONSTRAINT_EQ, and SQLITE_OK.

◆ pragmaVtabClose()

static int pragmaVtabClose ( sqlite3_vtab_cursor * cur)
static

Definition at line 128177 of file sqlite3.c.

◆ pragmaVtabColumn()

static int pragmaVtabColumn ( sqlite3_vtab_cursor * pVtabCursor,
sqlite3_context * ctx,
int i )
static

Definition at line 128261 of file sqlite3.c.

128271 {
128272 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
128273 PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab);
128274 if( i<pTab->iHidden ){
sqlite3_vtab * pVtab
Definition sqlite3.c:8069

◆ pragmaVtabConnect()

static int pragmaVtabConnect ( sqlite3 * db,
void * pAux,
int argc,
const char *const * argv,
sqlite3_vtab ** ppVtab,
char ** pzErr )
static

Definition at line 128043 of file sqlite3.c.

128055 {
128056 const PragmaName *pPragma = (const PragmaName*)pAux;
128057 PragmaVtab *pTab = 0;
128058 int rc;
128059 int i, j;
128060 char cSep = '(';
128061 StrAccum acc;
128062 char zBuf[200];
128063
128064 UNUSED_PARAMETER(argc);
128065 UNUSED_PARAMETER(argv);
128066 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
128067 sqlite3_str_appendall(&acc, "CREATE TABLE x");
128068 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
128069 sqlite3_str_appendf(&acc, "%c\"%s\"", cSep, pragCName[j]);
128070 cSep = ',';
128071 }
128072 if( i==0 ){
128073 sqlite3_str_appendf(&acc, "(\"%s\"", pPragma->zName);
128074 i++;
128075 }
128076 j = 0;
128077 if( pPragma->mPragFlg & PragFlg_Result1 ){
128078 sqlite3_str_appendall(&acc, ",arg HIDDEN");
128079 j++;
128080 }
128081 if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){
128082 sqlite3_str_appendall(&acc, ",schema HIDDEN");
128083 j++;
128084 }
128085 sqlite3_str_append(&acc, ")", 1);
128086 sqlite3StrAccumFinish(&acc);
128087 assert( strlen(zBuf) < sizeof(zBuf)-1 );
128088 rc = sqlite3_declare_vtab(db, zBuf);
128089 if( rc==SQLITE_OK ){
128090 pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab));
128091 if( pTab==0 ){
128092 rc = SQLITE_NOMEM;
128093 }else{
128094 memset(pTab, 0, sizeof(PragmaVtab));
128095 pTab->pName = pPragma;
128096 pTab->db = db;
128097 pTab->iHidden = i;
128098 pTab->nHidden = j;
128099 }
128100 }else{
#define PragFlg_SchemaReq
Definition sqlite3.c:125181
#define PragFlg_SchemaOpt
Definition sqlite3.c:125180
SQLITE_API int sqlite3_declare_vtab(sqlite3 *, const char *zSQL)
Definition sqlite3.c:140366
static const char *const pragCName[]
Definition sqlite3.c:125187
#define PragFlg_Result1
Definition sqlite3.c:125179
SQLITE_PRIVATE char * sqlite3StrAccumFinish(StrAccum *)
Definition sqlite3.c:29163
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *, sqlite3 *, char *, int, int)
Definition sqlite3.c:29240
const char *const zName
Definition sqlite3.c:125247
const PragmaName * pName
Definition sqlite3.c:128029
sqlite3 * db
Definition sqlite3.c:128028

◆ pragmaVtabCursorClear()

static void pragmaVtabCursorClear ( PragmaVtabCursor * pCsr)
static

Definition at line 128166 of file sqlite3.c.

128172 {
128173 int i;
128174 sqlite3_finalize(pCsr->pPragma);
sqlite3_stmt * pPragma
Definition sqlite3.c:128035

◆ pragmaVtabDisconnect()

static int pragmaVtabDisconnect ( sqlite3_vtab * pVtab)
static

Definition at line 128105 of file sqlite3.c.

◆ pragmaVtabEof()

static int pragmaVtabEof ( sqlite3_vtab_cursor * pVtabCursor)
static

Definition at line 128253 of file sqlite3.c.

◆ pragmaVtabFilter()

static int pragmaVtabFilter ( sqlite3_vtab_cursor * pVtabCursor,
int idxNum,
const char * idxStr,
int argc,
sqlite3_value ** argv )
static

Definition at line 128203 of file sqlite3.c.

128213 {
128214 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
128215 PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab);
128216 int rc;
128217 int i, j;
128218 StrAccum acc;
128219 char *zSql;
128220
128221 UNUSED_PARAMETER(idxNum);
128222 UNUSED_PARAMETER(idxStr);
128223 pragmaVtabCursorClear(pCsr);
128224 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
128225 for(i=0; i<argc; i++, j++){
128226 const char *zText = (const char*)sqlite3_value_text(argv[i]);
128227 assert( j<ArraySize(pCsr->azArg) );
128228 assert( pCsr->azArg[j]==0 );
128229 if( zText ){
128230 pCsr->azArg[j] = sqlite3_mprintf("%s", zText);
128231 if( pCsr->azArg[j]==0 ){
128232 return SQLITE_NOMEM;
128233 }
128234 }
128235 }
128236 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
128237 sqlite3_str_appendall(&acc, "PRAGMA ");
128238 if( pCsr->azArg[1] ){
128239 sqlite3_str_appendf(&acc, "%Q.", pCsr->azArg[1]);
128240 }
128241 sqlite3_str_appendall(&acc, pTab->pName->zName);
128242 if( pCsr->azArg[0] ){
128243 sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]);
128244 }
128245 zSql = sqlite3StrAccumFinish(&acc);
128246 if( zSql==0 ) return SQLITE_NOMEM;
128247 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
128248 sqlite3_free(zSql);
SQLITE_API char * sqlite3_mprintf(const char *,...)
Definition sqlite3.c:29323
#define SQLITE_LIMIT_SQL_LENGTH
Definition sqlite3.c:4945
static void pragmaVtabCursorClear(PragmaVtabCursor *pCsr)
Definition sqlite3.c:128166
char * azArg[2]
Definition sqlite3.c:128037

◆ pragmaVtabNext()

static int pragmaVtabNext ( sqlite3_vtab_cursor * pVtabCursor)
static

Definition at line 128185 of file sqlite3.c.

128191 {
128192 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
128193 int rc = SQLITE_OK;
128194
128195 /* Increment the xRowid value */
128196 pCsr->iRowid++;
128197 assert( pCsr->pPragma );
128198 if( SQLITE_ROW!=sqlite3_step(pCsr->pPragma) ){
sqlite_int64 iRowid
Definition sqlite3.c:128036

◆ pragmaVtabOpen()

static int pragmaVtabOpen ( sqlite3_vtab * pVtab,
sqlite3_vtab_cursor ** ppCursor )
static

Definition at line 128155 of file sqlite3.c.

128161 {
128162 PragmaVtabCursor *pCsr;
128163 pCsr = (PragmaVtabCursor*)sqlite3_malloc(sizeof(*pCsr));

◆ pragmaVtabRowid()

static int pragmaVtabRowid ( sqlite3_vtab_cursor * pVtabCursor,
sqlite_int64 * p )
static

Definition at line 128279 of file sqlite3.c.

◆ preserveExpr()

static void preserveExpr ( IdxExprTrans * pTrans,
Expr * pExpr )
static

Definition at line 142639 of file sqlite3.c.

142645 {
142646 WhereExprMod *pNew;
142647 pNew = sqlite3DbMallocRaw(pTrans->db, sizeof(*pNew));
sqlite3 * db
Definition sqlite3.c:142633

Referenced by whereIndexExprTransNode().

◆ printfFunc()

static void printfFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117307 of file sqlite3.c.

117317 {
117318 PrintfArguments x;
117319 StrAccum str;
117320 const char *zFormat;
117321 int n;
117322 sqlite3 *db = sqlite3_context_db_handle(context);
117323
117324 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
117325 x.nArg = argc-1;
117326 x.nUsed = 0;
117327 x.apArg = argv+1;
117328 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
#define SQLITE_PRINTF_SQLFUNC
Definition sqlite3.c:18978
sqlite3_value ** apArg
Definition sqlite3.c:19448

Referenced by sqlite3RegisterBuiltinFunctions().

◆ printfTempBuf()

static char * printfTempBuf ( sqlite3_str * pAccum,
sqlite3_int64 n )
static

Definition at line 28308 of file sqlite3.c.

28314 {
28315 char *z;
28316 if( pAccum->accError ) return 0;
28317 if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
28319 return 0;
28320 }
static void setStrAccumError(StrAccum *p, u8 eError)
Definition sqlite3.c:28276

References sqlite3_str::accError, sqlite3_str::db, sqlite3_str::mxAlloc, sqlite3_str::nAlloc, setStrAccumError(), sqlite3DbMallocRaw(), SQLITE_NOMEM, and SQLITE_TOOBIG.

Referenced by sqlite3_str_vappendf().

◆ propagateConstantExprRewrite()

static int propagateConstantExprRewrite ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 133585 of file sqlite3.c.

133591 {
133592 int i;
133593 WhereConst *pConst;
133594 if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
133598 return WRC_Continue;
133599 }
133600 pConst = pWalker->u.pConst;
133601 for(i=0; i<pConst->nConst; i++){
133602 Expr *pColumn = pConst->apExpr[i*2];
133603 if( pColumn==pExpr ) continue;
133604 if( pColumn->iTable!=pExpr->iTable ) continue;
133605 if( pColumn->iColumn!=pExpr->iColumn ) continue;
133606 /* A match is found. Add the EP_FixedCol property */
133607 pConst->nChng++;
133608 ExprClearProperty(pExpr, EP_Leaf);
#define ExprClearProperty(E, P)
Definition sqlite3.c:18106
struct WhereConst * pConst
Definition sqlite3.c:19110

References WhereConst::apExpr, Parse::db, EP_FixedCol, EP_FromJoin, EP_Leaf, ExprClearProperty, ExprHasProperty, ExprSetProperty, Expr::iColumn, Expr::iTable, WhereConst::nChng, WhereConst::nConst, Expr::op, Walker::pConst, Expr::pLeft, WhereConst::pParse, sqlite3ExprDup(), testcase, TK_COLUMN, Walker::u, WRC_Continue, and WRC_Prune.

Referenced by propagateConstants().

◆ propagateConstants()

static int propagateConstants ( Parse * pParse,
Select * p )
static

Definition at line 133647 of file sqlite3.c.

133656 {
133657 WhereConst x;
133658 Walker w;
133659 int nChng = 0;
133660 x.pParse = pParse;
133661 do{
133662 x.nConst = 0;
133663 x.nChng = 0;
133664 x.apExpr = 0;
133665 findConstInWhere(&x, p->pWhere);
133666 if( x.nConst ){
133667 memset(&w, 0, sizeof(w));
133668 w.pParse = pParse;
133671 w.xSelectCallback2 = 0;
133672 w.walkerDepth = 0;
133673 w.u.pConst = &x;
133674 sqlite3WalkExpr(&w, p->pWhere);
static int propagateConstantExprRewrite(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:133585
SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker *, Select *)
Definition sqlite3.c:97743
void(* xSelectCallback2)(Walker *, Select *)
Definition sqlite3.c:19094

References WhereConst::apExpr, Parse::db, findConstInWhere(), WhereConst::nChng, WhereConst::nConst, Walker::pConst, Walker::pParse, WhereConst::pParse, propagateConstantExprRewrite(), Select::pWhere, sqlite3DbFree(), sqlite3SelectWalkNoop(), sqlite3WalkExpr(), Walker::u, Walker::walkerDepth, Walker::xExprCallback, Walker::xSelectCallback, and Walker::xSelectCallback2.

Referenced by sqlite3Select().

◆ pthreadMutexAlloc()

static sqlite3_mutex * pthreadMutexAlloc ( int iType)
static

Definition at line 26376 of file sqlite3.c.

26381 {
26382 static sqlite3_mutex staticMutexes[] = {
26395 };
26396 sqlite3_mutex *p;
26397 switch( iType ){
26399 p = sqlite3MallocZero( sizeof(*p) );
26400 if( p ){
26401#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
26402 /* If recursive mutexes are not available, we will have to
26403 ** build our own. See below. */
26404 pthread_mutex_init(&p->mutex, 0);
26405#else
26406 /* Use a recursive mutex if it is available */
26407 pthread_mutexattr_t recursiveAttr;
26408 pthread_mutexattr_init(&recursiveAttr);
26409 pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
26410 pthread_mutex_init(&p->mutex, &recursiveAttr);
26411 pthread_mutexattr_destroy(&recursiveAttr);
26412#endif
26413#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
26414 p->id = SQLITE_MUTEX_RECURSIVE;
26415#endif
26416 }
26417 break;
26418 }
26419 case SQLITE_MUTEX_FAST: {
26420 p = sqlite3MallocZero( sizeof(*p) );
26421 if( p ){
26422 pthread_mutex_init(&p->mutex, 0);
26423#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
26424 p->id = SQLITE_MUTEX_FAST;
26425#endif
26426 }
26427 break;
26428 }
26429 default: {
26430#ifdef SQLITE_ENABLE_API_ARMOR
26431 if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){
26432 (void)SQLITE_MISUSE_BKPT;
26433 return 0;
26434 }
26435#endif
26436 p = &staticMutexes[iType-2];
26437 break;
26438 }
26439 }
#define SQLITE3_MUTEX_INITIALIZER(id)
Definition sqlite3.c:26281
pthread_mutex_t mutex
Definition sqlite3.c:26265

References ArraySize, sqlite3_mutex::mutex, SQLITE3_MUTEX_INITIALIZER, sqlite3MallocZero(), SQLITE_MISUSE_BKPT, SQLITE_MUTEX_FAST, and SQLITE_MUTEX_RECURSIVE.

◆ pthreadMutexEnd()

static int pthreadMutexEnd ( void )
static

Definition at line 26326 of file sqlite3.c.

References SQLITE_OK.

◆ pthreadMutexEnter()

static void pthreadMutexEnter ( sqlite3_mutex * p)
static

Definition at line 26474 of file sqlite3.c.

26479 {
26480 assert( p->id==SQLITE_MUTEX_RECURSIVE || pthreadMutexNotheld(p) );
26481
26482#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
26483 /* If recursive mutexes are not available, then we have to grow
26484 ** our own. This implementation assumes that pthread_equal()
26485 ** is atomic - that it cannot be deceived into thinking self
26486 ** and p->owner are equal if p->owner changes between two values
26487 ** that are not equal to self while the comparison is taking place.
26488 ** This implementation also assumes a coherent cache - that
26489 ** separate processes cannot read different values from the same
26490 ** address at the same time. If either of these two conditions
26491 ** are not met, then the mutexes will fail and problems will result.
26492 */
26493 {
26494 pthread_t self = pthread_self();
26495 if( p->nRef>0 && pthread_equal(p->owner, self) ){
26496 p->nRef++;
26497 }else{
26498 pthread_mutex_lock(&p->mutex);
26499 assert( p->nRef==0 );
26500 p->owner = self;
26501 p->nRef = 1;
26502 }
26503 }
26504#else
26505 /* Use the built-in recursive mutexes if they are available.
26506 */
26507 pthread_mutex_lock(&p->mutex);
26508#if SQLITE_MUTEX_NREF
26509 assert( p->nRef>0 || p->owner==0 );
26510 p->owner = pthread_self();
26511 p->nRef++;
26512#endif
26513#endif
26514
26515#ifdef SQLITE_DEBUG

References sqlite3_mutex::mutex, and SQLITE_MUTEX_RECURSIVE.

◆ pthreadMutexFree()

static void pthreadMutexFree ( sqlite3_mutex * p)
static

Definition at line 26447 of file sqlite3.c.

26452 {
26453 assert( p->nRef==0 );
26454#if SQLITE_ENABLE_API_ARMOR
26455 if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE )
26456#endif
26457 {
26458 pthread_mutex_destroy(&p->mutex);
26459 sqlite3_free(p);
26460 }
26461#ifdef SQLITE_ENABLE_API_ARMOR

References sqlite3_mutex::mutex, sqlite3_free(), SQLITE_MISUSE_BKPT, SQLITE_MUTEX_FAST, and SQLITE_MUTEX_RECURSIVE.

◆ pthreadMutexInit()

static int pthreadMutexInit ( void )
static

Definition at line 26325 of file sqlite3.c.

◆ pthreadMutexLeave()

static void pthreadMutexLeave ( sqlite3_mutex * p)
static

Definition at line 26573 of file sqlite3.c.

26578 {
26579 assert( pthreadMutexHeld(p) );
26580#if SQLITE_MUTEX_NREF
26581 p->nRef--;
26582 if( p->nRef==0 ) p->owner = 0;
26583#endif
26584 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
26585
26586#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
26587 if( p->nRef==0 ){
26588 pthread_mutex_unlock(&p->mutex);
26589 }
26590#else
26591 pthread_mutex_unlock(&p->mutex);
26592#endif
26593
26594#ifdef SQLITE_DEBUG

References sqlite3_mutex::mutex, and SQLITE_MUTEX_RECURSIVE.

◆ pthreadMutexTry()

static int pthreadMutexTry ( sqlite3_mutex * p)
static

Definition at line 26516 of file sqlite3.c.

26516 {
26517 printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
26518 }
26519#endif
26520}
26521static int pthreadMutexTry(sqlite3_mutex *p){
26522 int rc;
26523 assert( p->id==SQLITE_MUTEX_RECURSIVE || pthreadMutexNotheld(p) );
26524
26525#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
26526 /* If recursive mutexes are not available, then we have to grow
26527 ** our own. This implementation assumes that pthread_equal()
26528 ** is atomic - that it cannot be deceived into thinking self
26529 ** and p->owner are equal if p->owner changes between two values
26530 ** that are not equal to self while the comparison is taking place.
26531 ** This implementation also assumes a coherent cache - that
26532 ** separate processes cannot read different values from the same
26533 ** address at the same time. If either of these two conditions
26534 ** are not met, then the mutexes will fail and problems will result.
26535 */
26536 {
26537 pthread_t self = pthread_self();
26538 if( p->nRef>0 && pthread_equal(p->owner, self) ){
26539 p->nRef++;
26540 rc = SQLITE_OK;
26541 }else if( pthread_mutex_trylock(&p->mutex)==0 ){
26542 assert( p->nRef==0 );
26543 p->owner = self;
26544 p->nRef = 1;
26545 rc = SQLITE_OK;
26546 }else{
26547 rc = SQLITE_BUSY;
26548 }
26549 }
26550#else
26551 /* Use the built-in recursive mutexes if they are available.
26552 */
26553 if( pthread_mutex_trylock(&p->mutex)==0 ){
26554#if SQLITE_MUTEX_NREF
26555 p->owner = pthread_self();
26556 p->nRef++;
26557#endif
26558 rc = SQLITE_OK;
26559 }else{
26560 rc = SQLITE_BUSY;
26561 }
26562#endif
26563
26564#ifdef SQLITE_DEBUG
26565 if( rc==SQLITE_OK && p->trace ){
static int pthreadMutexTry(sqlite3_mutex *p)
Definition sqlite3.c:26516
#define printf

References printf.

◆ ptrmapGet()

static int ptrmapGet ( BtShared * pBt,
Pgno key,
u8 * pEType,
Pgno * pPgno )
static

Definition at line 65522 of file sqlite3.c.

65528 {
65529 DbPage *pDbPage; /* The pointer map page */
65530 int iPtrmap; /* Pointer map page index */
65531 u8 *pPtrmap; /* Pointer map page data */
65532 int offset; /* Offset of entry in pointer map */
65533 int rc;
65534
65535 assert( sqlite3_mutex_held(pBt->mutex) );
65536
65537 iPtrmap = PTRMAP_PAGENO(pBt, key);
65538 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
65539 if( rc!=0 ){
65540 return rc;
65541 }
65542 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
65543
65544 offset = PTRMAP_PTROFFSET(iPtrmap, key);
65545 if( offset<0 ){
65546 sqlite3PagerUnref(pDbPage);
65547 return SQLITE_CORRUPT_BKPT;
65548 }
65549 assert( offset <= (int)pBt->usableSize-5 );
65550 assert( pEType!=0 );
65551 *pEType = pPtrmap[offset];
#define PTRMAP_PTROFFSET(pgptrmap, pgno)
Definition sqlite3.c:64071

References get4byte, BtShared::mutex, BtShared::pPager, PTRMAP_PAGENO, PTRMAP_PTROFFSET, sqlite3_mutex_held(), sqlite3PagerGet(), sqlite3PagerGetData(), sqlite3PagerUnref(), SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_PGNO, SQLITE_OK, and BtShared::usableSize.

Referenced by allocateBtreePage(), btreeCreateTable(), checkPtrmap(), getOverflowPage(), and incrVacuumStep().

◆ ptrmapPageno()

static Pgno ptrmapPageno ( BtShared * pBt,
Pgno pgno )
static

Definition at line 65439 of file sqlite3.c.

65445 {
65446 int nPagesPerMapPage;
65447 Pgno iPtrMap, ret;
65448 assert( sqlite3_mutex_held(pBt->mutex) );
65449 if( pgno<2 ) return 0;
65450 nPagesPerMapPage = (pBt->usableSize/5)+1;
65451 iPtrMap = (pgno-2)/nPagesPerMapPage;

References BtShared::mutex, PENDING_BYTE_PAGE, sqlite3_mutex_held(), and BtShared::usableSize.

◆ ptrmapPut()

static void ptrmapPut ( BtShared * pBt,
Pgno key,
u8 eType,
Pgno parent,
int * pRC )
static

Definition at line 65463 of file sqlite3.c.

65469 {
65470 DbPage *pDbPage; /* The pointer map page */
65471 u8 *pPtrmap; /* The pointer map data */
65472 Pgno iPtrmap; /* The pointer map page number */
65473 int offset; /* Offset in pointer map page */
65474 int rc; /* Return code from subfunctions */
65475
65476 if( *pRC ) return;
65477
65478 assert( sqlite3_mutex_held(pBt->mutex) );
65479 /* The super-journal page number must never be used as a pointer map page */
65480 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
65481
65482 assert( pBt->autoVacuum );
65483 if( key==0 ){
65484 *pRC = SQLITE_CORRUPT_BKPT;
65485 return;
65486 }
65487 iPtrmap = PTRMAP_PAGENO(pBt, key);
65488 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
65489 if( rc!=SQLITE_OK ){
65490 *pRC = rc;
65491 return;
65492 }
65493 if( ((char*)sqlite3PagerGetExtra(pDbPage))[0]!=0 ){
65494 /* The first byte of the extra data is the MemPage.isInit byte.
65495 ** If that byte is set, it means this page is also being used
65496 ** as a btree page. */
65497 *pRC = SQLITE_CORRUPT_BKPT;
65498 goto ptrmap_exit;
65499 }
65500 offset = PTRMAP_PTROFFSET(iPtrmap, key);
65501 if( offset<0 ){
65502 *pRC = SQLITE_CORRUPT_BKPT;
65503 goto ptrmap_exit;
65504 }
65505 assert( offset <= (int)pBt->usableSize-5 );
65506 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
65507
65508 if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
65509 TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
65510 *pRC= rc = sqlite3PagerWrite(pDbPage);
65511 if( rc==SQLITE_OK ){
65512 pPtrmap[offset] = eType;
65513 put4byte(&pPtrmap[offset+1], parent);

References BtShared::autoVacuum, eType, get4byte, BtShared::mutex, PENDING_BYTE_PAGE, BtShared::pPager, PTRMAP_ISPAGE, PTRMAP_PAGENO, PTRMAP_PTROFFSET, put4byte, sqlite3_mutex_held(), sqlite3PagerGet(), sqlite3PagerGetData(), sqlite3PagerGetExtra(), sqlite3PagerUnref(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_OK, TRACE, and BtShared::usableSize.

Referenced by balance_deeper(), balance_nonroot(), balance_quick(), btreeCreateTable(), fillInCell(), freePage2(), ptrmapPutOvflPtr(), relocatePage(), and setChildPtrmaps().

◆ ptrmapPutOvflPtr()

static void ptrmapPutOvflPtr ( MemPage * pPage,
MemPage * pSrc,
u8 * pCell,
int * pRC )
static

Definition at line 65854 of file sqlite3.c.

65860 {
65861 CellInfo info;
65862 if( *pRC ) return;
65863 assert( pCell!=0 );
65864 pPage->xParseCell(pPage, pCell, &info);
65865 if( info.nLocal<info.nPayload ){
65866 Pgno ovfl;
65867 if( SQLITE_WITHIN(pSrc->aDataEnd, pCell, pCell+info.nLocal) ){
65868 testcase( pSrc!=pPage );
65869 *pRC = SQLITE_CORRUPT_BKPT;

References MemPage::aDataEnd, get4byte, CellInfo::nLocal, CellInfo::nPayload, CellInfo::nSize, MemPage::pBt, MemPage::pgno, PTRMAP_OVERFLOW1, ptrmapPut(), SQLITE_CORRUPT_BKPT, SQLITE_WITHIN, testcase, and MemPage::xParseCell.

Referenced by balance_nonroot(), balance_quick(), insertCell(), and setChildPtrmaps().

◆ pushDownWhereTerms()

static int pushDownWhereTerms ( Parse * pParse,
Select * pSubq,
Expr * pWhere,
int iCursor,
int isLeftJoin )
static

Definition at line 133730 of file sqlite3.c.

133742 {
133743 Expr *pNew;
133744 int nChng = 0;
133745 Select *pSel;
133746 if( pWhere==0 ) return 0;
133747 if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */
133748
133749#ifndef SQLITE_OMIT_WINDOWFUNC
133750 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
133751 if( pSel->pWin ) return 0; /* restriction (6) */
133752 }
133753#endif
133754
133755#ifdef SQLITE_DEBUG
133756 /* Only the first term of a compound can have a WITH clause. But make
133757 ** sure no other terms are marked SF_Recursive in case something changes
133758 ** in the future.
133759 */
133760 {
133761 Select *pX;
133762 for(pX=pSubq; pX; pX=pX->pPrior){
133763 assert( (pX->selFlags & (SF_Recursive))==0 );
133764 }
133765 }
133766#endif
133767
133768 if( pSubq->pLimit!=0 ){
133769 return 0; /* restriction (3) */
133770 }
133771 while( pWhere->op==TK_AND ){
133772 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
133773 iCursor, isLeftJoin);
133774 pWhere = pWhere->pLeft;
133775 }
133776 if( isLeftJoin
133777 && (ExprHasProperty(pWhere,EP_FromJoin)==0
133778 || pWhere->iRightJoinTable!=iCursor)
133779 ){
133780 return 0; /* restriction (4) */
133781 }
133782 if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
133783 return 0; /* restriction (5) */
133784 }
133785 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
133786 nChng++;
133787 while( pSubq ){
133788 SubstContext x;
133789 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
133790 unsetJoinExpr(pNew, -1);
133791 x.pParse = pParse;
133792 x.iTable = iCursor;
133793 x.iNewTable = iCursor;
133794 x.isLeftJoin = 0;
133795 x.pEList = pSubq->pEList;
133796 pNew = substExpr(&x, pNew);
133797 if( pSubq->selFlags & SF_Aggregate ){
133798 pSubq->pHaving = sqlite3ExprAnd(pParse, pSubq->pHaving, pNew);
133799 }else{
133800 pSubq->pWhere = sqlite3ExprAnd(pParse, pSubq->pWhere, pNew);
static void unsetJoinExpr(Expr *p, int iTable)
Definition sqlite3.c:129697
static int pushDownWhereTerms(Parse *pParse, Select *pSubq, Expr *pWhere, int iCursor, int isLeftJoin)
Definition sqlite3.c:133730
static Expr * substExpr(SubstContext *pSubst, Expr *pExpr)
Definition sqlite3.c:132771

References Parse::db, EP_FromJoin, ExprHasProperty, SubstContext::iNewTable, Expr::iRightJoinTable, SubstContext::isLeftJoin, SubstContext::iTable, Expr::op, Select::pEList, SubstContext::pEList, Select::pHaving, Expr::pLeft, Select::pLimit, SubstContext::pParse, Select::pPrior, Expr::pRight, pushDownWhereTerms(), Select::pWhere, Select::pWin, Select::selFlags, SF_Aggregate, SF_Recursive, sqlite3ExprAnd(), sqlite3ExprDup(), sqlite3ExprIsTableConstant(), substExpr(), TK_AND, and unsetJoinExpr().

Referenced by pushDownWhereTerms(), and sqlite3Select().

◆ pushOntoSorter()

static void pushOntoSorter ( Parse * pParse,
SortCtx * pSort,
Select * pSelect,
int regData,
int regOrigData,
int nData,
int nPrefixReg )
static

Definition at line 129876 of file sqlite3.c.

129890 {
129891 Vdbe *v = pParse->pVdbe; /* Stmt under construction */
129892 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
129893 int nExpr = pSort->pOrderBy->nExpr; /* No. of ORDER BY terms */
129894 int nBase = nExpr + bSeq + nData; /* Fields in sorter record */
129895 int regBase; /* Regs for sorter record */
129896 int regRecord = 0; /* Assembled sorter record */
129897 int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
129898 int op; /* Opcode to add sorter record to sorter */
129899 int iLimit; /* LIMIT counter */
129900 int iSkip = 0; /* End of the sorter insert loop */
129901
129902 assert( bSeq==0 || bSeq==1 );
129903
129904 /* Three cases:
129905 ** (1) The data to be sorted has already been packed into a Record
129906 ** by a prior OP_MakeRecord. In this case nData==1 and regData
129907 ** will be completely unrelated to regOrigData.
129908 ** (2) All output columns are included in the sort record. In that
129909 ** case regData==regOrigData.
129910 ** (3) Some output columns are omitted from the sort record due to
129911 ** the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the
129912 ** SQLITE_ECEL_OMITREF optimization, or due to the
129913 ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
129914 ** regOrigData is 0 to prevent this routine from trying to copy
129915 ** values that might not yet exist.
129916 */
129917 assert( nData==1 || regData==regOrigData || regOrigData==0 );
129918
129919 if( nPrefixReg ){
129920 assert( nPrefixReg==nExpr+bSeq );
129921 regBase = regData - nPrefixReg;
129922 }else{
129923 regBase = pParse->nMem + 1;
129924 pParse->nMem += nBase;
129925 }
129926 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
129927 iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
129928 pSort->labelDone = sqlite3VdbeMakeLabel(pParse);
129929 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
129930 SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
129931 if( bSeq ){
129932 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
129933 }
129934 if( nPrefixReg==0 && nData>0 ){
129935 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
129936 }
129937 if( nOBSat>0 ){
129938 int regPrevKey; /* The first nOBSat columns of the previous row */
129939 int addrFirst; /* Address of the OP_IfNot opcode */
129940 int addrJmp; /* Address of the OP_Jump opcode */
129941 VdbeOp *pOp; /* Opcode that opens the sorter */
129942 int nKey; /* Number of sorting key columns, including OP_Sequence */
129943 KeyInfo *pKI; /* Original KeyInfo on the sorter table */
129944
129945 regRecord = makeSorterRecord(pParse, pSort, pSelect, regBase, nBase);
129946 regPrevKey = pParse->nMem+1;
129947 pParse->nMem += pSort->nOBSat;
129948 nKey = nExpr - pSort->nOBSat + bSeq;
129949 if( bSeq ){
129950 addrFirst = sqlite3VdbeAddOp1(v, OP_IfNot, regBase+nExpr);
129951 }else{
129952 addrFirst = sqlite3VdbeAddOp1(v, OP_SequenceTest, pSort->iECursor);
129953 }
129954 VdbeCoverage(v);
129955 sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
129956 pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
129957 if( pParse->db->mallocFailed ) return;
129958 pOp->p2 = nKey + nData;
129959 pKI = pOp->p4.pKeyInfo;
129960 memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
129961 sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
129962 testcase( pKI->nAllField > pKI->nKeyField+2 );
129963 pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
129964 pKI->nAllField-pKI->nKeyField-1);
129965 pOp = 0; /* Ensure pOp not used after sqltie3VdbeAddOp3() */
129966 addrJmp = sqlite3VdbeCurrentAddr(v);
129967 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
129968 pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
129969 pSort->regReturn = ++pParse->nMem;
129970 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
129972 if( iLimit ){
129973 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, pSort->labelDone);
129974 VdbeCoverage(v);
129975 }
129976 sqlite3VdbeJumpHere(v, addrFirst);
129977 sqlite3ExprCodeMove(pParse, regBase, regPrevKey, pSort->nOBSat);
129978 sqlite3VdbeJumpHere(v, addrJmp);
129979 }
129980 if( iLimit ){
129981 /* At this point the values for the new sorter entry are stored
129982 ** in an array of registers. They need to be composed into a record
129983 ** and inserted into the sorter if either (a) there are currently
129984 ** less than LIMIT+OFFSET items or (b) the new record is smaller than
129985 ** the largest record currently in the sorter. If (b) is true and there
129986 ** are already LIMIT+OFFSET items in the sorter, delete the largest
129987 ** entry before inserting the new one. This way there are never more
129988 ** than LIMIT+OFFSET items in the sorter.
129989 **
129990 ** If the new record does not need to be inserted into the sorter,
129991 ** jump to the next iteration of the loop. If the pSort->labelOBLopt
129992 ** value is not zero, then it is a label of where to jump. Otherwise,
129993 ** just bypass the row insert logic. See the header comment on the
129994 ** sqlite3WhereOrderByLimitOptLabel() function for additional info.
129995 */
129996 int iCsr = pSort->iECursor;
129998 VdbeCoverage(v);
129999 sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0);
130000 iSkip = sqlite3VdbeAddOp4Int(v, OP_IdxLE,
130001 iCsr, 0, regBase+nOBSat, nExpr-nOBSat);
130002 VdbeCoverage(v);
130003 sqlite3VdbeAddOp1(v, OP_Delete, iCsr);
130004 }
130005 if( regRecord==0 ){
130006 regRecord = makeSorterRecord(pParse, pSort, pSelect, regBase, nBase);
130007 }
130008 if( pSort->sortFlags & SORTFLAG_UseSorter ){
130009 op = OP_SorterInsert;
130010 }else{
130011 op = OP_IdxInsert;
130012 }
130013 sqlite3VdbeAddOp4Int(v, op, pSort->iECursor, regRecord,
#define SQLITE_ECEL_REF
Definition sqlite3.c:19667
#define OP_IfNotZero
Definition sqlite3.c:15615
static int makeSorterRecord(Parse *pParse, SortCtx *pSort, Select *pSelect, int regBase, int nBase)
Definition sqlite3.c:129855
SQLITE_PRIVATE VdbeOp * sqlite3VdbeGetOp(Vdbe *, int)
Definition sqlite3.c:79158
SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoFromExprList(Parse *, ExprList *, int, int)
Definition sqlite3.c:130652
#define OP_Sequence
Definition sqlite3.c:15685
#define SQLITE_ECEL_DUP
Definition sqlite3.c:19665
#define OP_SorterInsert
Definition sqlite3.c:15697
#define OP_ResetSorter
Definition sqlite3.c:15704
#define OP_SequenceTest
Definition sqlite3.c:15679
u16 nKeyField
Definition sqlite3.c:17682
int addrSortIndex
Definition sqlite3.c:129348
union VdbeOp::p4union p4
KeyInfo * pKeyInfo
Definition sqlite3.c:15452

Referenced by selectInnerLoop().

◆ putVarint64()

static int SQLITE_NOINLINE putVarint64 ( unsigned char * p,
u64 v )
static

Definition at line 32093 of file sqlite3.c.

32099 {
32100 int i, j, n;
32101 u8 buf[10];
32102 if( v & (((u64)0xff000000)<<32) ){
32103 p[8] = (u8)v;
32104 v >>= 8;
32105 for(i=7; i>=0; i--){
32106 p[i] = (u8)((v & 0x7f) | 0x80);
32107 v >>= 7;
32108 }
32109 return 9;
32110 }
32111 n = 0;
32112 do{
32113 buf[n++] = (u8)((v & 0x7f) | 0x80);
32114 v >>= 7;
32115 }while( v!=0 );
32116 buf[0] &= 0x7f;

◆ querySharedCacheTableLock()

static int querySharedCacheTableLock ( Btree * p,
Pgno iTab,
u8 eLock )
static

Definition at line 64754 of file sqlite3.c.

64760 {
64761 BtShared *pBt = p->pBt;
64762 BtLock *pIter;
64763
64764 assert( sqlite3BtreeHoldsMutex(p) );
64765 assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
64766 assert( p->db!=0 );
64767 assert( !(p->db->flags&SQLITE_ReadUncommit)||eLock==WRITE_LOCK||iTab==1 );
64768
64769 /* If requesting a write-lock, then the Btree must have an open write
64770 ** transaction on this file. And, obviously, for this to be so there
64771 ** must be an open write transaction on the file itself.
64772 */
64773 assert( eLock==READ_LOCK || (p==pBt->pWriter && p->inTrans==TRANS_WRITE) );
64774 assert( eLock==READ_LOCK || pBt->inTransaction==TRANS_WRITE );
64775
64776 /* This routine is a no-op if the shared-cache is not enabled */
64777 if( !p->sharable ){
64778 return SQLITE_OK;
64779 }
64780
64781 /* If some other connection is holding an exclusive lock, the
64782 ** requested lock may not be obtained.
64783 */
64784 if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
64787 }
64788
64789 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
64790 /* The condition (pIter->eLock!=eLock) in the following if(...)
64791 ** statement is a simplification of:
64792 **
64793 ** (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
64794 **
64795 ** since we know that if eLock==WRITE_LOCK, then no other connection
64796 ** may hold a WRITE_LOCK on any table in this file (since there can
64797 ** only be a single writer).
64798 */
64799 assert( pIter->eLock==READ_LOCK || pIter->eLock==WRITE_LOCK );
64800 assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
64801 if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
64802 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
64803 if( eLock==WRITE_LOCK ){
64804 assert( p==pBt->pWriter );
64805 pBt->btsFlags |= BTS_PENDING;
#define sqlite3ConnectionBlocked(x, y)
Definition sqlite3.c:20268
#define SQLITE_ReadUncommit
Definition sqlite3.c:16989
#define READ_LOCK
Definition sqlite3.c:63789
#define SQLITE_LOCKED_SHAREDCACHE
Definition sqlite3.c:1555
#define WRITE_LOCK
Definition sqlite3.c:63790

References BTS_EXCLUSIVE, BTS_PENDING, BtShared::btsFlags, Btree::db, BtLock::eLock, sqlite3::flags, Btree::inTrans, BtShared::inTransaction, BtLock::iTable, Btree::pBt, BtLock::pBtree, BtShared::pLock, BtLock::pNext, BtShared::pWriter, READ_LOCK, Btree::sharable, sqlite3ConnectionBlocked, SQLITE_LOCKED_SHAREDCACHE, SQLITE_OK, SQLITE_ReadUncommit, TRANS_WRITE, and WRITE_LOCK.

Referenced by setSharedCacheTableLock(), sqlite3BtreeBeginTrans(), sqlite3BtreeGetMeta(), sqlite3BtreeLockTable(), and sqlite3BtreeSchemaLocked().

◆ quoteFunc()

static void quoteFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118079 of file sqlite3.c.

118085 {
118086 assert( argc==1 );
118087 UNUSED_PARAMETER(argc);
118088 switch( sqlite3_value_type(argv[0]) ){
118089 case SQLITE_FLOAT: {
118090 double r1, r2;
118091 char zBuf[50];
118092 r1 = sqlite3_value_double(argv[0]);
118093 sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1);
118094 sqlite3AtoF(zBuf, &r2, 20, SQLITE_UTF8);
118095 if( r1!=r2 ){
118096 sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.20e", r1);
118097 }
118098 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
118099 break;
118100 }
118101 case SQLITE_INTEGER: {
118102 sqlite3_result_value(context, argv[0]);
118103 break;
118104 }
118105 case SQLITE_BLOB: {
118106 char *zText = 0;
118107 char const *zBlob = sqlite3_value_blob(argv[0]);
118108 int nBlob = sqlite3_value_bytes(argv[0]);
118109 assert( zBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
118110 zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4);
118111 if( zText ){
118112 int i;
118113 for(i=0; i<nBlob; i++){
118114 zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
118115 zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F];
118116 }
118117 zText[(nBlob*2)+2] = '\'';
118118 zText[(nBlob*2)+3] = '\0';
118119 zText[0] = 'X';
118120 zText[1] = '\'';
118121 sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
118122 sqlite3_free(zText);
118123 }
118124 break;
118125 }
118126 case SQLITE_TEXT: {
118127 int i,j;
118128 u64 n;
118129 const unsigned char *zArg = sqlite3_value_text(argv[0]);
118130 char *z;
118131
118132 if( zArg==0 ) return;
118133 for(i=0, n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; }
118134 z = contextMalloc(context, ((i64)i)+((i64)n)+3);
118135 if( z ){
118136 z[0] = '\'';
118137 for(i=0, j=1; zArg[i]; i++){
118138 z[j++] = zArg[i];
118139 if( zArg[i]=='\'' ){
118140 z[j++] = '\'';
118141 }
118142 }
118143 z[j++] = '\'';
118144 z[j] = 0;
118145 sqlite3_result_text(context, z, j, sqlite3_free);
118146 }
118147 break;
118148 }
118149 default: {
SQLITE_API void sqlite3_result_text(sqlite3_context *, const char *, int, void(*)(void *))
Definition sqlite3.c:83449

References contextMalloc(), hexdigits, sqlite3_free(), sqlite3_result_text(), sqlite3_result_value(), sqlite3_snprintf(), sqlite3_value_blob(), sqlite3_value_bytes(), sqlite3_value_double(), sqlite3_value_text(), sqlite3_value_type(), sqlite3AtoF(), SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_STATIC, SQLITE_TEXT, SQLITE_TRANSIENT, SQLITE_UTF8, and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ randomBlob()

static void randomBlob ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117578 of file sqlite3.c.

117588 {
117589 sqlite3_int64 n;
117590 unsigned char *p;
117591 assert( argc==1 );
117592 UNUSED_PARAMETER(argc);
117593 n = sqlite3_value_int64(argv[0]);
117594 if( n<1 ){
117595 n = 1;
117596 }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ randomFunc()

static void randomFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 117552 of file sqlite3.c.

117562 {
117563 sqlite_int64 r;
117564 UNUSED_PARAMETER2(NotUsed, NotUsed2);
117565 sqlite3_randomness(sizeof(r), &r);
117566 if( r<0 ){
117567 /* We need to prevent a random number of 0x8000000000000000
117568 ** (or -9223372036854775808) since when you do abs() of that
117569 ** number of you get the same value back again. To do this
117570 ** in a way that is testable, mask the sign bit off of negative
117571 ** values, resulting in a positive value. Then take the
117572 ** 2s complement of that positive value. The end result can
long long int sqlite_int64
Definition sqlite3.c:1326
SQLITE_API void sqlite3_randomness(int N, void *P)
Definition sqlite3.c:30261

References LARGEST_INT64, sqlite3_randomness(), sqlite3_result_int64(), and UNUSED_PARAMETER2.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ rankStepFunc()

static void rankStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151456 of file sqlite3.c.

151466 {
151467 struct CallCount *p;
151468 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151469 if( p ){
151470 p->nStep++;
151471 if( p->nValue==0 ){

References CallCount::nStep, CallCount::nValue, and sqlite3_aggregate_context().

◆ rankValueFunc()

static void rankValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151472 of file sqlite3.c.

151478 {
151479 struct CallCount *p;

◆ read32bits()

static int read32bits ( sqlite3_file * fd,
i64 offset,
u32 * pRes )
static

Definition at line 52797 of file sqlite3.c.

52803 {
52804 unsigned char ac[4];

References sqlite3Get4byte(), sqlite3OsRead(), and SQLITE_OK.

Referenced by pager_playback_one_page(), readJournalHdr(), and readSuperJournal().

◆ readDbPage()

static int readDbPage ( PgHdr * pPg)
static

Definition at line 54651 of file sqlite3.c.

54657 {
54658 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
54659 int rc = SQLITE_OK; /* Return code */
54660
54661#ifndef SQLITE_OMIT_WAL
54662 u32 iFrame = 0; /* Frame of WAL containing pgno */
54663
54664 assert( pPager->eState>=PAGER_READER && !MEMDB );
54665 assert( isOpen(pPager->fd) );
54666
54667 if( pagerUseWal(pPager) ){
54668 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
54669 if( rc ) return rc;
54670 }
54671 if( iFrame ){
54672 rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
54673 }else
54674#endif
54675 {
54676 i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
54677 rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
54678 if( rc==SQLITE_IOERR_SHORT_READ ){
54679 rc = SQLITE_OK;
54680 }
54681 }
54682
54683 if( pPg->pgno==1 ){
54684 if( rc ){
54685 /* If the read is unsuccessful, set the dbFileVers[] to something
54686 ** that will never be a valid file version. dbFileVers[] is a copy
54687 ** of bytes 24..39 of the database. Bytes 28..31 should always be
54688 ** zero or the size of the database in page. Bytes 32..35 and 35..39
54689 ** should be page numbers which are never 0xffffffff. So filling
54690 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
54691 **
54692 ** For an encrypted database, the situation is more complex: bytes
54693 ** 24..39 of the database are white noise. But the probability of
54694 ** white noise equaling 16 bytes of 0xff is vanishingly small so
54695 ** we should still be ok.
54696 */
54697 memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
54698 }else{
54699 u8 *dbFileVers = &((u8*)pPg->pData)[24];
54700 memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
54701 }
54702 }
54703 PAGER_INCR(sqlite3_pager_readdb_count);
54704 PAGER_INCR(pPager->nRead);
SQLITE_PRIVATE int sqlite3WalReadFrame(Wal *, u32, int, u8 *)
Definition sqlite3.c:62531
SQLITE_PRIVATE int sqlite3WalFindFrame(Wal *, Pgno, u32 *)
Definition sqlite3.c:62427

References Pager::dbFileVers, Pager::eState, Pager::fd, IOTRACE, isOpen, MEMDB, PAGER_INCR, pager_pagehash, PAGER_READER, PAGERID, PAGERTRACE, pagerUseWal, Pager::pageSize, PgHdr::pData, PgHdr::pgno, PgHdr::pPager, Pager::pWal, sqlite3OsRead(), sqlite3WalFindFrame(), sqlite3WalReadFrame(), SQLITE_IOERR_SHORT_READ, and SQLITE_OK.

Referenced by getPageNormal(), and pagerUndoCallback().

◆ readJournalHdr()

static int readJournalHdr ( Pager * pPager,
int isHot,
i64 journalSize,
u32 * pNRec,
u32 * pDbSize )
static

Definition at line 53254 of file sqlite3.c.

53266 {
53267 int rc; /* Return code */
53268 unsigned char aMagic[8]; /* A buffer to hold the magic header */
53269 i64 iHdrOff; /* Offset of journal header being read */
53270
53271 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
53272
53273 /* Advance Pager.journalOff to the start of the next sector. If the
53274 ** journal file is too small for there to be a header stored at this
53275 ** point, return SQLITE_DONE.
53276 */
53277 pPager->journalOff = journalHdrOffset(pPager);
53278 if( pPager->journalOff+JOURNAL_HDR_SZ(pPager) > journalSize ){
53279 return SQLITE_DONE;
53280 }
53281 iHdrOff = pPager->journalOff;
53282
53283 /* Read in the first 8 bytes of the journal header. If they do not match
53284 ** the magic string found at the start of each journal header, return
53285 ** SQLITE_DONE. If an IO error occurs, return an error code. Otherwise,
53286 ** proceed.
53287 */
53288 if( isHot || iHdrOff!=pPager->journalHdr ){
53289 rc = sqlite3OsRead(pPager->jfd, aMagic, sizeof(aMagic), iHdrOff);
53290 if( rc ){
53291 return rc;
53292 }
53293 if( memcmp(aMagic, aJournalMagic, sizeof(aMagic))!=0 ){
53294 return SQLITE_DONE;
53295 }
53296 }
53297
53298 /* Read the first three 32-bit fields of the journal header: The nRec
53299 ** field, the checksum-initializer and the database size at the start
53300 ** of the transaction. Return an error code if anything goes wrong.
53301 */
53302 if( SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+8, pNRec))
53303 || SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+12, &pPager->cksumInit))
53304 || SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+16, pDbSize))
53305 ){
53306 return rc;
53307 }
53308
53309 if( pPager->journalOff==0 ){
53310 u32 iPageSize; /* Page-size field of journal header */
53311 u32 iSectorSize; /* Sector-size field of journal header */
53312
53313 /* Read the page-size and sector-size journal header fields. */
53314 if( SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+20, &iSectorSize))
53315 || SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+24, &iPageSize))
53316 ){
53317 return rc;
53318 }
53319
53320 /* Versions of SQLite prior to 3.5.8 set the page-size field of the
53321 ** journal header to zero. In this case, assume that the Pager.pageSize
53322 ** variable is already set to the correct page size.
53323 */
53324 if( iPageSize==0 ){
53325 iPageSize = pPager->pageSize;
53326 }
53327
53328 /* Check that the values read from the page-size and sector-size fields
53329 ** are within range. To be 'in range', both values need to be a power
53330 ** of two greater than or equal to 512 or 32, and not greater than their
53331 ** respective compile time maximum limits.
53332 */
53333 if( iPageSize<512 || iSectorSize<32
53334 || iPageSize>SQLITE_MAX_PAGE_SIZE || iSectorSize>MAX_SECTOR_SIZE
53335 || ((iPageSize-1)&iPageSize)!=0 || ((iSectorSize-1)&iSectorSize)!=0
53336 ){
53337 /* If the either the page-size or sector-size in the journal-header is
53338 ** invalid, then the process that wrote the journal-header must have
53339 ** crashed before the header was synced. In this case stop reading
53340 ** the journal file here.
53341 */
53342 return SQLITE_DONE;
53343 }
53344
53345 /* Update the page-size to match the value read from the journal.
53346 ** Use a testcase() macro to make sure that malloc failure within
53347 ** PagerSetPagesize() is tested.
53348 */
53349 rc = sqlite3PagerSetPagesize(pPager, &iPageSize, -1);
53350 testcase( rc!=SQLITE_OK );
53351
53352 /* Update the assumed sector-size to match the value used by
53353 ** the process that created this journal. If this journal was
53354 ** created by a process other than this one, then this routine
53355 ** is being called from within pager_playback(). The local value
53356 ** of Pager.sectorSize is restored at the end of that routine.
53357 */
static const unsigned char aJournalMagic[]
Definition sqlite3.c:52453
#define MAX_SECTOR_SIZE
Definition sqlite3.c:52117
static i64 journalHdrOffset(Pager *pPager)
Definition sqlite3.c:53053

References aJournalMagic, Pager::cksumInit, isOpen, Pager::jfd, JOURNAL_HDR_SZ, Pager::journalHdr, journalHdrOffset(), Pager::journalOff, MAX_SECTOR_SIZE, Pager::pageSize, read32bits(), Pager::sectorSize, sqlite3OsRead(), sqlite3PagerSetPagesize(), SQLITE_DONE, SQLITE_MAX_PAGE_SIZE, SQLITE_OK, and testcase.

Referenced by pager_playback(), and pagerPlaybackSavepoint().

◆ readsTable()

static int readsTable ( Parse * p,
int iDb,
Table * pTab )
static

Definition at line 120717 of file sqlite3.c.

120723 {
120724 Vdbe *v = sqlite3GetVdbe(p);
120725 int i;
120726 int iEnd = sqlite3VdbeCurrentAddr(v);
120727#ifndef SQLITE_OMIT_VIRTUALTABLE
120728 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
120729#endif
120730
120731 for(i=1; i<iEnd; i++){
120732 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
120733 assert( pOp!=0 );
120734 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
120735 Index *pIndex;
120736 Pgno tnum = pOp->p2;
120737 if( tnum==pTab->tnum ){
120738 return 1;
120739 }
120740 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
120741 if( tnum==pIndex->tnum ){
120742 return 1;
120743 }
120744 }
120745 }
120746#ifndef SQLITE_OMIT_VIRTUALTABLE
120747 if( pOp->opcode==OP_VOpen && pOp->p4.pVtab==pVTab ){
120748 assert( pOp->p4.pVtab!=0 );
120749 assert( pOp->p4type==P4_VTAB );
#define OP_VOpen
Definition sqlite3.c:15731
#define P4_VTAB
Definition sqlite3.c:15519
signed char p4type
Definition sqlite3.c:15436
u8 opcode
Definition sqlite3.c:15435
VTable * pVtab
Definition sqlite3.c:15451

References Parse::db, IsVirtual, OP_OpenRead, OP_VOpen, VdbeOp::opcode, VdbeOp::p2, VdbeOp::p3, VdbeOp::p4, P4_VTAB, VdbeOp::p4type, Table::pIndex, Index::pNext, VdbeOp::p4union::pVtab, sqlite3GetVdbe(), sqlite3GetVTable(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetOp(), Table::tnum, and Index::tnum.

Referenced by sqlite3Insert().

◆ readSuperJournal()

static int readSuperJournal ( sqlite3_file * pJrnl,
char * zSuper,
u32 nSuper )
static

Definition at line 52997 of file sqlite3.c.

53003 {
53004 int rc; /* Return code */
53005 u32 len; /* Length in bytes of super-journal name */
53006 i64 szJ; /* Total size in bytes of journal file pJrnl */
53007 u32 cksum; /* MJ checksum value read from journal */
53008 u32 u; /* Unsigned loop counter */
53009 unsigned char aMagic[8]; /* A buffer to hold the magic header */
53010 zSuper[0] = '\0';
53011
53012 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
53013 || szJ<16
53014 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
53015 || len>=nSuper
53016 || len>szJ-16
53017 || len==0
53018 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
53019 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
53020 || memcmp(aMagic, aJournalMagic, 8)
53021 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len))
53022 ){
53023 return rc;
53024 }
53025
53026 /* See if the checksum matches the super-journal name */
53027 for(u=0; u<len; u++){
53028 cksum -= zSuper[u];
53029 }
53030 if( cksum ){
53031 /* If the checksum doesn't add up, then one or more of the disk sectors
53032 ** containing the super-journal filename is corrupted. This means
53033 ** definitely roll back, so just return SQLITE_OK and report a (nul)
53034 ** super-journal filename.
53035 */
53036 len = 0;

References aJournalMagic, read32bits(), sqlite3OsFileSize(), sqlite3OsRead(), and SQLITE_OK.

Referenced by pager_delsuper(), and pager_playback().

◆ rebuildPage()

static int rebuildPage ( CellArray * pCArray,
int iFirst,
int nCell,
MemPage * pPg )
static

Definition at line 71416 of file sqlite3.c.

71427 {
71428 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
71429 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
71430 const int usableSize = pPg->pBt->usableSize;
71431 u8 * const pEnd = &aData[usableSize];
71432 int i = iFirst; /* Which cell to copy from pCArray*/
71433 u32 j; /* Start of cell content area */
71434 int iEnd = i+nCell; /* Loop terminator */
71435 u8 *pCellptr = pPg->aCellIdx;
71436 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
71437 u8 *pData;
71438 int k; /* Current slot in pCArray->apEnd[] */
71439 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
71440
71441 assert( i<iEnd );
71442 j = get2byte(&aData[hdr+5]);
71443 if( NEVER(j>(u32)usableSize) ){ j = 0; }
71444 memcpy(&pTmp[j], &aData[j], usableSize - j);
71445
71446 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
71447 pSrcEnd = pCArray->apEnd[k];
71448
71449 pData = pEnd;
71450 while( 1/*exit by break*/ ){
71451 u8 *pCell = pCArray->apCell[i];
71452 u16 sz = pCArray->szCell[i];
71453 assert( sz>0 );
71454 if( SQLITE_WITHIN(pCell,aData,pEnd) ){
71455 if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
71456 pCell = &pTmp[pCell - aData];
71457 }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
71458 && (uptr)(pCell)<(uptr)pSrcEnd
71459 ){
71460 return SQLITE_CORRUPT_BKPT;
71461 }
71462
71463 pData -= sz;
71464 put2byte(pCellptr, (pData - aData));
71465 pCellptr += 2;
71466 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
71467 memcpy(pData, pCell, sz);
71468 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
71469 testcase( sz!=pPg->xCellSize(pPg,pCell) )
71470 i++;
71471 if( i>=iEnd ) break;
71472 if( pCArray->ixNx[k]<=i ){
71473 k++;
71474 pSrcEnd = pCArray->apEnd[k];
71475 }
71476 }
71477
71478 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
71479 pPg->nCell = nCell;
71480 pPg->nOverflow = 0;
71481

References MemPage::aCellIdx, MemPage::aData, ALWAYS, CellArray::apCell, CellArray::apEnd, CORRUPT_DB, get2byte, MemPage::hdrOffset, CellArray::ixNx, NB, MemPage::nCell, NEVER, MemPage::nOverflow, MemPage::pBt, BtShared::pPager, put2byte, sqlite3PagerTempSpace(), SQLITE_CORRUPT_BKPT, SQLITE_OK, SQLITE_WITHIN, CellArray::szCell, testcase, BtShared::usableSize, and MemPage::xCellSize.

Referenced by balance_quick(), and editPage().

◆ recomputeColumnsNotIndexed()

static void recomputeColumnsNotIndexed ( Index * pIdx)
static

Definition at line 112385 of file sqlite3.c.

112391 {
112392 Bitmask m = 0;
112393 int j;
112394 Table *pTab = pIdx->pTable;
112395 for(j=pIdx->nColumn-1; j>=0; j--){
112396 int x = pIdx->aiColumn[j];
112397 if( x>=0 && (pTab->aCol[x].colFlags & COLFLAG_VIRTUAL)==0 ){
112398 testcase( x==BMS-1 );
112399 testcase( x==BMS-2 );

References Table::aCol, Index::aiColumn, BMS, COLFLAG_VIRTUAL, Column::colFlags, Index::colNotIdxed, MASKBIT, Index::nColumn, Index::pTable, and testcase.

Referenced by convertToWithoutRowidTable(), and sqlite3CreateIndex().

◆ recomputeColumnsUsed()

static void recomputeColumnsUsed ( Select * pSelect,
struct SrcList_item * pSrcItem )
static

Definition at line 132906 of file sqlite3.c.

132915 {
132916 Walker w;
132917 if( NEVER(pSrcItem->pTab==0) ) return;
132918 memset(&w, 0, sizeof(w));

Referenced by flattenSubquery().

◆ recomputeColumnsUsedExpr()

static int recomputeColumnsUsedExpr ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 132897 of file sqlite3.c.

132903 {
132904 struct SrcList_item *pItem;
132905 if( pExpr->op!=TK_COLUMN ) return WRC_Continue;

References Expr::op, TK_COLUMN, and WRC_Continue.

◆ rehash()

static int rehash ( Hash * pH,
unsigned int new_size )
static

Definition at line 32983 of file sqlite3.c.

32989 {
32990 struct _ht *new_ht; /* The new hash table */
32991 HashElem *elem, *next_elem; /* For looping over existing elements */
32992
32993#if SQLITE_MALLOC_SOFT_LIMIT>0
32994 if( new_size*sizeof(struct _ht)>SQLITE_MALLOC_SOFT_LIMIT ){
32995 new_size = SQLITE_MALLOC_SOFT_LIMIT/sizeof(struct _ht);
32996 }
32997 if( new_size==pH->htsize ) return 0;
32998#endif
32999
33000 /* The inability to allocates space for a larger hash table is
33001 ** a performance hit but it is not a fatal error. So mark the
33002 ** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
33003 ** sqlite3MallocZero() to make the allocation, as sqlite3MallocZero()
33004 ** only zeroes the requested number of bytes whereas this module will
33005 ** use the actual amount of space allocated for the hash table (which
33006 ** may be larger than the requested amount).
33007 */
33009 new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) );
33011
33012 if( new_ht==0 ) return 0;
33013 sqlite3_free(pH->ht);
33014 pH->ht = new_ht;
33015 pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
33016 memset(new_ht, 0, new_size*sizeof(struct _ht));
33017 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
#define SQLITE_MALLOC_SOFT_LIMIT
Definition sqlite3.c:13630

References Hash::first, Hash::ht, Hash::htsize, insertElement(), HashElem::next, HashElem::pKey, sqlite3_free(), sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), sqlite3Malloc(), sqlite3MallocSize(), SQLITE_MALLOC_SOFT_LIMIT, and strHash().

Referenced by sqlite3HashInsert().

◆ reindexDatabases()

static void reindexDatabases ( Parse * pParse,
char const * zColl )
static

Definition at line 115334 of file sqlite3.c.

115340 {
115341 Db *pDb; /* A single database */
115342 int iDb; /* The database index number */
115343 sqlite3 *db = pParse->db; /* The database connection */
115344 HashElem *k; /* For looping over tables in pDb */
115345 Table *pTab; /* A table in the database */
115346
115347 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
115348 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
115349 assert( pDb!=0 );

References sqlite3::aDb, Parse::db, sqlite3::nDb, Db::pSchema, reindexTable(), sqliteHashData, sqliteHashFirst, sqliteHashNext, and Schema::tblHash.

Referenced by sqlite3Reindex().

◆ reindexTable()

static void reindexTable ( Parse * pParse,
Table * pTab,
char const * zColl )
static

Definition at line 115313 of file sqlite3.c.

115319 {
115320 if( !IsVirtual(pTab) ){
115321 Index *pIndex; /* An index associated with pTab */
115322
115323 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
115324 if( zColl==0 || collationMatch(zColl, pIndex) ){
115325 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
static int collationMatch(const char *zColl, Index *pIndex)
Definition sqlite3.c:115294

References collationMatch(), Parse::db, IsVirtual, Table::pIndex, Index::pNext, Table::pSchema, sqlite3BeginWriteOperation(), sqlite3RefillIndex(), and sqlite3SchemaToIndex().

Referenced by reindexDatabases(), and sqlite3Reindex().

◆ releaseAllSavepoints()

static void releaseAllSavepoints ( Pager * pPager)
static

Definition at line 53465 of file sqlite3.c.

53471 {
53472 int ii; /* Iterator for looping through Pager.aSavepoint */
53473 for(ii=0; ii<pPager->nSavepoint; ii++){
53475 }
53476 if( !pPager->exclusiveMode || sqlite3JournalIsInMemory(pPager->sjfd) ){
53477 sqlite3OsClose(pPager->sjfd);

References Pager::aSavepoint, Pager::exclusiveMode, Pager::nSavepoint, Pager::nSubRec, PagerSavepoint::pInSavepoint, Pager::sjfd, sqlite3_free(), sqlite3BitvecDestroy(), sqlite3JournalIsInMemory(), and sqlite3OsClose().

Referenced by pager_end_transaction(), and pager_unlock().

◆ releaseInodeInfo()

static void releaseInodeInfo ( unixFile * pFile)
static

Definition at line 34865 of file sqlite3.c.

34871 {
34872 unixInodeInfo *pInode = pFile->pInode;
34873 assert( unixMutexHeld() );
34874 assert( unixFileMutexNotheld(pFile) );
34875 if( ALWAYS(pInode) ){
34876 pInode->nRef--;
34877 if( pInode->nRef==0 ){
34878 assert( pInode->pShmNode==0 );
34880 closePendingFds(pFile);
34882 if( pInode->pPrev ){
34883 assert( pInode->pPrev->pNext==pInode );
34884 pInode->pPrev->pNext = pInode->pNext;
34885 }else{
34886 assert( inodeList==pInode );
34887 inodeList = pInode->pNext;
34888 }
34889 if( pInode->pNext ){
34890 assert( pInode->pNext->pPrev==pInode );
34891 pInode->pNext->pPrev = pInode->pPrev;
unixShmNode * pShmNode
Definition sqlite3.c:34711

References ALWAYS, closePendingFds(), inodeList, unixInodeInfo::nRef, unixFile::pInode, unixInodeInfo::pLockMutex, unixInodeInfo::pNext, unixInodeInfo::pPrev, unixInodeInfo::pShmNode, sqlite3_free(), sqlite3_mutex_enter(), sqlite3_mutex_free(), and sqlite3_mutex_leave().

◆ releaseMemArray()

static void releaseMemArray ( Mem * p,
int N )
static

Definition at line 79613 of file sqlite3.c.

79619 {
79620 if( p && N ){
79621 Mem *pEnd = &p[N];
79622 sqlite3 *db = p->db;
79623 if( db->pnBytesFreed ){
79624 do{
79625 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
79626 }while( (++p)<pEnd );
79627 return;
79628 }
79629 do{
79630 assert( (&p[1])==pEnd || p[0].db==p[1].db );
79631 assert( sqlite3VdbeCheckMemInvariants(p) );
79632
79633 /* This block is really an inlined version of sqlite3VdbeMemRelease()
79634 ** that takes advantage of the fact that the memory cell value is
79635 ** being set to NULL after releasing any dynamic resources.
79636 **
79637 ** The justification for duplicating code is that according to
79638 ** callgrind, this causes a certain test case to hit the CPU 4.7
79639 ** percent less (x86 linux, gcc version 4.1.2, -O6) than if
79640 ** sqlite3MemRelease() were called from here. With -O2, this jumps
79641 ** to 6.6 percent. The test case is inserting 1000 rows into a table
79642 ** with no indexes using a single prepared INSERT statement, bind()
79643 ** and reset(). Inserts are grouped into a transaction.
79644 */
79645 testcase( p->flags & MEM_Agg );
79646 testcase( p->flags & MEM_Dyn );
79648 if( p->flags&(MEM_Agg|MEM_Dyn) ){
79650 }else if( p->szMalloc ){
79651 sqlite3DbFreeNN(db, p->zMalloc);
79652 p->szMalloc = 0;
SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void *)
Definition sqlite3.c:79675
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p)
Definition sqlite3.c:76363
void(* xDel)(void *)
Definition sqlite3.c:20922
char * zMalloc
Definition sqlite3.c:20918

Referenced by closeAllCursors(), sqlite3VdbeClearObject(), sqlite3VdbeFrameDelete(), sqlite3VdbeList(), and sqlite3VdbeSetNumCols().

◆ releasePage()

◆ releasePageNotNull()

static void releasePageNotNull ( MemPage * pPage)
static

Definition at line 66698 of file sqlite3.c.

66704 {
66705 assert( pPage->aData );
66706 assert( pPage->pBt );

References MemPage::aData, and MemPage::pBt.

Referenced by moveToParent(), moveToRoot(), and sqlite3BtreeDelete().

◆ releasePageOne()

static void releasePageOne ( MemPage * pPage)
static

Definition at line 66710 of file sqlite3.c.

66713 {
66714 if( pPage ) releasePageNotNull(pPage);
66715}
66716static void releasePageOne(MemPage *pPage){
66717 assert( pPage!=0 );
66718 assert( pPage->aData );
66719 assert( pPage->pBt );

Referenced by lockBtree(), sqlite3BtreeRollback(), and unlockBtreeIfUnused().

◆ relocatePage()

static int relocatePage ( BtShared * pBt,
MemPage * pDbPage,
u8 eType,
Pgno iPtrPage,
Pgno iFreePage,
int isCommit )
static

Definition at line 68136 of file sqlite3.c.

68149 {
68150 MemPage *pPtrPage; /* The page that contains a pointer to pDbPage */
68151 Pgno iDbPage = pDbPage->pgno;
68152 Pager *pPager = pBt->pPager;
68153 int rc;
68154
68157 assert( sqlite3_mutex_held(pBt->mutex) );
68158 assert( pDbPage->pBt==pBt );
68159 if( iDbPage<3 ) return SQLITE_CORRUPT_BKPT;
68160
68161 /* Move page iDbPage from its current location to page number iFreePage */
68162 TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n",
68163 iDbPage, iFreePage, iPtrPage, eType));
68164 rc = sqlite3PagerMovepage(pPager, pDbPage->pDbPage, iFreePage, isCommit);
68165 if( rc!=SQLITE_OK ){
68166 return rc;
68167 }
68168 pDbPage->pgno = iFreePage;
68169
68170 /* If pDbPage was a btree-page, then it may have child pages and/or cells
68171 ** that point to overflow pages. The pointer map entries for all these
68172 ** pages need to be changed.
68173 **
68174 ** If pDbPage is an overflow page, then the first 4 bytes may store a
68175 ** pointer to a subsequent overflow page. If this is the case, then
68176 ** the pointer map needs to be updated for the subsequent overflow page.
68177 */
68179 rc = setChildPtrmaps(pDbPage);
68180 if( rc!=SQLITE_OK ){
68181 return rc;
68182 }
68183 }else{
68184 Pgno nextOvfl = get4byte(pDbPage->aData);
68185 if( nextOvfl!=0 ){
68186 ptrmapPut(pBt, nextOvfl, PTRMAP_OVERFLOW2, iFreePage, &rc);
68187 if( rc!=SQLITE_OK ){
68188 return rc;
68189 }
68190 }
68191 }
68192
68193 /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
68194 ** that it points at iFreePage. Also fix the pointer map entry for
68195 ** iPtrPage.
68196 */
68197 if( eType!=PTRMAP_ROOTPAGE ){
68198 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
68199 if( rc!=SQLITE_OK ){
68200 return rc;
68201 }
68202 rc = sqlite3PagerWrite(pPtrPage->pDbPage);
68203 if( rc!=SQLITE_OK ){
68204 releasePage(pPtrPage);
68205 return rc;
68206 }
68207 rc = modifyPagePointer(pPtrPage, iDbPage, iFreePage, eType);
68208 releasePage(pPtrPage);
SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *, DbPage *, Pgno, int)
Definition sqlite3.c:58743
static int setChildPtrmaps(MemPage *pPage)
Definition sqlite3.c:68030

References MemPage::aData, btreeGetPage(), eType, get4byte, modifyPagePointer(), BtShared::mutex, MemPage::pBt, MemPage::pDbPage, MemPage::pgno, BtShared::pPager, PTRMAP_BTREE, PTRMAP_OVERFLOW1, PTRMAP_OVERFLOW2, PTRMAP_ROOTPAGE, ptrmapPut(), releasePage(), setChildPtrmaps(), sqlite3_mutex_held(), sqlite3PagerMovepage(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_OK, and TRACE.

Referenced by btreeCreateTable(), btreeDropTable(), and incrVacuumStep().

◆ removeElementGivenHash()

static void removeElementGivenHash ( Hash * pH,
HashElem * elem,
unsigned int h )
static

Definition at line 33059 of file sqlite3.c.

33069 {
33070 struct _ht *pEntry;
33071 if( elem->prev ){
33072 elem->prev->next = elem->next;
33073 }else{
33074 pH->first = elem->next;
33075 }
33076 if( elem->next ){
33077 elem->next->prev = elem->prev;
33078 }
33079 if( pH->ht ){
33080 pEntry = &pH->ht[h];
33081 if( pEntry->chain==elem ){
33082 pEntry->chain = elem->next;
33083 }
33084 assert( pEntry->count>0 );
33085 pEntry->count--;
33086 }
33087 sqlite3_free( elem );
33088 pH->count--;
HashElem * chain
Definition sqlite3.c:13890

Referenced by sqlite3HashInsert().

◆ removeFromSharingList()

static int removeFromSharingList ( BtShared * pBt)
static

Definition at line 67107 of file sqlite3.c.

67113 {
67114#ifndef SQLITE_OMIT_SHARED_CACHE
67115 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; )
67116 BtShared *pList;
67117 int removed = 0;
67118
67119 assert( sqlite3_mutex_notheld(pBt->mutex) );
67121 sqlite3_mutex_enter(pMainMtx);
67122 pBt->nRef--;
67123 if( pBt->nRef<=0 ){
67126 }else{
67128 while( ALWAYS(pList) && pList->pNext!=pBt ){
67129 pList=pList->pNext;
67130 }
67131 if( ALWAYS(pList) ){
67132 pList->pNext = pBt->pNext;
67133 }
67134 }
67135 if( SQLITE_THREADSAFE ){
67137 }
67138 removed = 1;
67139 }
SQLITE_API void sqlite3_mutex_free(sqlite3_mutex *)
Definition sqlite3.c:25943
static BtShared *SQLITE_WSD sqlite3SharedCacheList
Definition sqlite3.c:64554
#define SQLITE_THREADSAFE
Definition sqlite3.c:13571
#define MUTEX_LOGIC(X)
Definition sqlite3.c:16560
#define GLOBAL(t, v)
Definition sqlite3.c:14633
BtShared * pNext
Definition sqlite3.c:63905

References ALWAYS, GLOBAL, BtShared::mutex, MUTEX_LOGIC, BtShared::nRef, BtShared::pNext, sqlite3_mutex_enter(), sqlite3_mutex_free(), sqlite3_mutex_leave(), sqlite3_mutex_notheld(), sqlite3MutexAlloc(), sqlite3SharedCacheList, SQLITE_MUTEX_STATIC_MAIN, and SQLITE_THREADSAFE.

◆ removeUnindexableInClauseTerms()

static Expr * removeUnindexableInClauseTerms ( Parse * pParse,
int iEq,
WhereLoop * pLoop,
Expr * pX )
static

Definition at line 141927 of file sqlite3.c.

141938 {
141939 sqlite3 *db = pParse->db;
141940 Expr *pNew;
141941 pNew = sqlite3ExprDup(db, pX, 0);
141942 if( db->mallocFailed==0 ){
141943 ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
141944 ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
141945 ExprList *pRhs = 0; /* New RHS after modifications */
141946 ExprList *pLhs = 0; /* New LHS after mods */
141947 int i; /* Loop counter */
141948 Select *pSelect; /* Pointer to the SELECT on the RHS */
141949
141950 for(i=iEq; i<pLoop->nLTerm; i++){
141951 if( pLoop->aLTerm[i]->pExpr==pX ){
141952 int iField = pLoop->aLTerm[i]->iField - 1;
141953 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
141954 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
141955 pOrigRhs->a[iField].pExpr = 0;
141956 assert( pOrigLhs->a[iField].pExpr!=0 );
141957 pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
141958 pOrigLhs->a[iField].pExpr = 0;
141959 }
141960 }
141961 sqlite3ExprListDelete(db, pOrigRhs);
141962 sqlite3ExprListDelete(db, pOrigLhs);
141963 pNew->pLeft->x.pList = pLhs;
141964 pNew->x.pSelect->pEList = pRhs;
141965 if( pLhs && pLhs->nExpr==1 ){
141966 /* Take care here not to generate a TK_VECTOR containing only a
141967 ** single value. Since the parser never creates such a vector, some
141968 ** of the subroutines do not handle this case. */
141969 Expr *p = pLhs->a[0].pExpr;
141970 pLhs->a[0].pExpr = 0;
141971 sqlite3ExprDelete(db, pNew->pLeft);
141972 pNew->pLeft = p;
141973 }
141974 pSelect = pNew->x.pSelect;
141975 if( pSelect->pOrderBy ){
141976 /* If the SELECT statement has an ORDER BY clause, zero the
141977 ** iOrderByCol variables. These are set to non-zero when an
141978 ** ORDER BY term exactly matches one of the terms of the
141979 ** result-set. Since the result-set of the SELECT statement may
141980 ** have been modified or reordered, these variables are no longer
141981 ** set correctly. Since setting them is just an optimization,
141982 ** it's easiest just to zero them here. */
141983 ExprList *pOrderBy = pSelect->pOrderBy;
141984 for(i=0; i<pOrderBy->nExpr; i++){
141985 pOrderBy->a[i].u.x.iOrderByCol = 0;
141986 }
141987 }
141988
141989#if 0
141990 printf("For indexing, change the IN expr:\n");
141991 sqlite3TreeViewExpr(0, pX, 0);

References ExprList::a, WhereLoop::aLTerm, Parse::db, WhereTerm::iField, ExprList::ExprList_item::iOrderByCol, sqlite3::mallocFailed, ExprList::nExpr, WhereLoop::nLTerm, Select::pEList, ExprList::ExprList_item::pExpr, WhereTerm::pExpr, Expr::pLeft, Expr::pList, Select::pOrderBy, printf, Expr::pSelect, sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3ExprListDelete(), ExprList::ExprList_item::u, Expr::x, and ExprList::ExprList_item::x.

Referenced by codeEqualityTerm().

◆ renameColumnElistNames()

static void renameColumnElistNames ( Parse * pParse,
RenameCtx * pCtx,
ExprList * pEList,
const char * zOld )
static

Definition at line 106772 of file sqlite3.c.

106783 {
106784 if( pEList ){
106785 int i;
106786 for(i=0; i<pEList->nExpr; i++){
106787 char *zName = pEList->a[i].zEName;
106788 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
106789 && ALWAYS(zName!=0)
106790 && 0==sqlite3_stricmp(zName, zOld)

References ExprList::a, ALWAYS, ExprList::ExprList_item::eEName, ENAME_NAME, ExprList::nExpr, renameTokenFind(), sqlite3_stricmp(), ExprList::ExprList_item::zEName, and zName.

Referenced by renameColumnFunc().

◆ renameColumnExprCb()

static int renameColumnExprCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 106701 of file sqlite3.c.

106707 {
106708 RenameCtx *p = pWalker->u.pRename;
106709 if( pExpr->op==TK_TRIGGER
106710 && pExpr->iColumn==p->iCol
106711 && pWalker->pParse->pTriggerTab==p->pTab
106712 ){
106713 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
106714 }else if( pExpr->op==TK_COLUMN
106715 && pExpr->iColumn==p->iCol
static void renameTokenFind(Parse *pParse, struct RenameCtx *pCtx, void *pPtr)
Definition sqlite3.c:106666
Table * pTab
Definition sqlite3.c:106451
struct RenameCtx * pRename
Definition sqlite3.c:19111

References RenameCtx::iCol, Expr::iColumn, Expr::op, Walker::pParse, Walker::pRename, Expr::pTab, RenameCtx::pTab, Parse::pTriggerTab, renameTokenFind(), TK_COLUMN, TK_TRIGGER, Walker::u, WRC_Continue, and Expr::y.

Referenced by renameColumnFunc().

◆ renameColumnFunc()

static void renameColumnFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 107107 of file sqlite3.c.

107117 {
107118 sqlite3 *db = sqlite3_context_db_handle(context);
107119 RenameCtx sCtx;
107120 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
107121 const char *zDb = (const char*)sqlite3_value_text(argv[3]);
107122 const char *zTable = (const char*)sqlite3_value_text(argv[4]);
107123 int iCol = sqlite3_value_int(argv[5]);
107124 const char *zNew = (const char*)sqlite3_value_text(argv[6]);
107125 int bQuote = sqlite3_value_int(argv[7]);
107126 int bTemp = sqlite3_value_int(argv[8]);
107127 const char *zOld;
107128 int rc;
107129 Parse sParse;
107130 Walker sWalker;
107131 Index *pIdx;
107132 int i;
107133 Table *pTab;
107134#ifndef SQLITE_OMIT_AUTHORIZATION
107135 sqlite3_xauth xAuth = db->xAuth;
107136#endif
107137
107138 UNUSED_PARAMETER(NotUsed);
107139 if( zSql==0 ) return;
107140 if( zTable==0 ) return;
107141 if( zNew==0 ) return;
107142 if( iCol<0 ) return;
107144 pTab = sqlite3FindTable(db, zTable, zDb);
107145 if( pTab==0 || iCol>=pTab->nCol ){
107147 return;
107148 }
107149 zOld = pTab->aCol[iCol].zName;
107150 memset(&sCtx, 0, sizeof(sCtx));
107151 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
107152
107153#ifndef SQLITE_OMIT_AUTHORIZATION
107154 db->xAuth = 0;
107155#endif
107156 rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
107157
107158 /* Find tokens that need to be replaced. */
107159 memset(&sWalker, 0, sizeof(Walker));
107160 sWalker.pParse = &sParse;
107163 sWalker.u.pRename = &sCtx;
107164
107165 sCtx.pTab = pTab;
107166 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
107167 if( sParse.pNewTable ){
107168 Select *pSelect = sParse.pNewTable->pSelect;
107169 if( pSelect ){
107170 pSelect->selFlags &= ~SF_View;
107171 sParse.rc = SQLITE_OK;
107172 sqlite3SelectPrep(&sParse, pSelect, 0);
107173 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
107174 if( rc==SQLITE_OK ){
107175 sqlite3WalkSelect(&sWalker, pSelect);
107176 }
107177 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
107178 }else{
107179 /* A regular table */
107180 int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
107181 FKey *pFKey;
107182 assert( sParse.pNewTable->pSelect==0 );
107183 sCtx.pTab = sParse.pNewTable;
107184 if( bFKOnly==0 ){
107186 &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName
107187 );
107188 if( sCtx.iCol<0 ){
107189 renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey);
107190 }
107191 sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
107192 for(pIdx=sParse.pNewTable->pIndex; pIdx; pIdx=pIdx->pNext){
107193 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
107194 }
107195 for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
107196 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
107197 }
107198 }
107199#ifndef SQLITE_OMIT_GENERATED_COLUMNS
107200 for(i=0; i<sParse.pNewTable->nCol; i++){
107201 sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
107202 }
107203#endif
107204
107205 for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
107206 for(i=0; i<pFKey->nCol; i++){
107207 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
107208 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
107209 }
107210 if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
107211 && 0==sqlite3_stricmp(pFKey->aCol[i].zCol, zOld)
107212 ){
107213 renameTokenFind(&sParse, &sCtx, (void*)pFKey->aCol[i].zCol);
107214 }
107215 }
107216 }
107217 }
107218 }else if( sParse.pNewIndex ){
107219 sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
107220 sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
107221 }else{
107222 /* A trigger */
107223 TriggerStep *pStep;
107224 rc = renameResolveTrigger(&sParse);
107225 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
107226
107227 for(pStep=sParse.pNewTrigger->step_list; pStep; pStep=pStep->pNext){
107228 if( pStep->zTarget ){
107229 Table *pTarget = sqlite3LocateTable(&sParse, 0, pStep->zTarget, zDb);
107230 if( pTarget==pTab ){
107231 if( pStep->pUpsert ){
107232 ExprList *pUpsertSet = pStep->pUpsert->pUpsertSet;
107233 renameColumnElistNames(&sParse, &sCtx, pUpsertSet, zOld);
107234 }
107235 renameColumnIdlistNames(&sParse, &sCtx, pStep->pIdList, zOld);
107236 renameColumnElistNames(&sParse, &sCtx, pStep->pExprList, zOld);
107237 }
107238 }
107239 }
107240
107241
107242 /* Find tokens to edit in UPDATE OF clause */
107243 if( sParse.pTriggerTab==pTab ){
107244 renameColumnIdlistNames(&sParse, &sCtx,sParse.pNewTrigger->pColumns,zOld);
107245 }
107246
107247 /* Find tokens to edit in various expressions and selects */
107248 renameWalkTrigger(&sWalker, sParse.pNewTrigger);
107249 }
107250
107251 assert( rc==SQLITE_OK );
107252 rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote);
107253
107254renameColumnFunc_done:
107255 if( rc!=SQLITE_OK ){
107256 if( sParse.zErrMsg ){
107257 renameColumnParseError(context, 0, argv[1], argv[2], &sParse);
107258 }else{
107259 sqlite3_result_error_code(context, rc);
107260 }
107261 }
107262
107263 renameParseCleanup(&sParse);
static void renameColumnParseError(sqlite3_context *pCtx, int bPost, sqlite3_value *pType, sqlite3_value *pObject, Parse *pParse)
Definition sqlite3.c:106747
SQLITE_PRIVATE int sqlite3WalkExprList(Walker *, ExprList *)
Definition sqlite3.c:97608
SQLITE_API int sqlite3_value_int(sqlite3_value *)
Definition sqlite3.c:83175
static int renameColumnSelectCb(Walker *pWalker, Select *p)
Definition sqlite3.c:106686
static void renameColumnElistNames(Parse *pParse, RenameCtx *pCtx, ExprList *pEList, const char *zOld)
Definition sqlite3.c:106772
static int renameParseSql(Parse *p, const char *zDb, sqlite3 *db, const char *zSql, int bTemp)
Definition sqlite3.c:106819
SQLITE_PRIVATE Table * sqlite3LocateTable(Parse *, u32 flags, const char *, const char *)
Definition sqlite3.c:110777
SQLITE_PRIVATE void sqlite3SelectPrep(Parse *, Select *, NameContext *)
Definition sqlite3.c:134665
static void renameWalkTrigger(Walker *pWalker, Trigger *pTrigger)
Definition sqlite3.c:107042
static int renameEditSql(sqlite3_context *pCtx, RenameCtx *pRename, const char *zSql, const char *zNew, int bQuote)
Definition sqlite3.c:106874
static int renameResolveTrigger(Parse *pParse)
Definition sqlite3.c:106956
static void renameColumnIdlistNames(Parse *pParse, RenameCtx *pCtx, IdList *pIdList, const char *zOld)
Definition sqlite3.c:106797
static void renameParseCleanup(Parse *pParse)
Definition sqlite3.c:107067
int(* sqlite3_xauth)(void *, int, const char *, const char *, const char *, const char *)
Definition sqlite3.c:16799
SQLITE_API void sqlite3_result_error_code(sqlite3_context *, int)
Definition sqlite3.c:83520
static int renameColumnExprCb(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:106701
char * zTo
Definition sqlite3.c:17617
FKey * pNextFrom
Definition sqlite3.c:17616
Trigger * pNewTrigger
Definition sqlite3.c:18766
Index * pNewIndex
Definition sqlite3.c:18763
FKey * pFKey
Definition sqlite3.c:17492
ExprList * pCheck
Definition sqlite3.c:17494
IdList * pColumns
Definition sqlite3.c:18877
ExprList * pUpsertSet
Definition sqlite3.c:18409
sqlite3_xauth xAuth
Definition sqlite3.c:16908

References Table::aCol, FKey::aCol, Index::aColExpr, RenameCtx::iCol, FKey::sColMap::iFrom, Table::iPKey, sqlite3::mallocFailed, Table::nCol, FKey::nCol, Table::pCheck, Trigger::pColumns, Column::pDflt, TriggerStep::pExprList, Table::pFKey, TriggerStep::pIdList, Table::pIndex, RenameCtx::pList, Parse::pNewIndex, Parse::pNewTable, Parse::pNewTrigger, Index::pNext, TriggerStep::pNext, FKey::pNextFrom, Walker::pParse, Index::pPartIdxWhere, Walker::pRename, Table::pSelect, RenameCtx::pTab, Parse::pTriggerTab, TriggerStep::pUpsert, Upsert::pUpsertSet, Parse::rc, renameColumnElistNames(), renameColumnExprCb(), renameColumnIdlistNames(), renameColumnParseError(), renameColumnSelectCb(), renameEditSql(), renameParseCleanup(), renameParseSql(), renameResolveTrigger(), renameTokenFind(), renameTokenFree(), renameWalkTrigger(), Select::selFlags, sqlite3_context_db_handle(), sqlite3_result_error_code(), sqlite3_stricmp(), sqlite3_value_int(), sqlite3_value_text(), sqlite3BtreeEnterAll(), sqlite3BtreeLeaveAll(), sqlite3FindTable(), sqlite3LocateTable(), sqlite3SelectPrep(), sqlite3WalkExpr(), sqlite3WalkExprList(), sqlite3WalkSelect(), SQLITE_NOMEM, SQLITE_OK, Trigger::step_list, Walker::u, UNUSED_PARAMETER, sqlite3::xAuth, Walker::xExprCallback, Walker::xSelectCallback, FKey::sColMap::zCol, Parse::zErrMsg, Column::zName, Table::zName, TriggerStep::zTarget, and FKey::zTo.

◆ renameColumnIdlistNames()

static void renameColumnIdlistNames ( Parse * pParse,
RenameCtx * pCtx,
IdList * pIdList,
const char * zOld )
static

Definition at line 106797 of file sqlite3.c.

106808 {
106809 if( pIdList ){
106810 int i;
106811 for(i=0; i<pIdList->nId; i++){
106812 char *zName = pIdList->a[i].zName;
struct IdList::IdList_item * a
int nId
Definition sqlite3.c:18227

References IdList::a, IdList::nId, renameTokenFind(), sqlite3_stricmp(), IdList::IdList_item::zName, and zName.

Referenced by renameColumnFunc().

◆ renameColumnParseError()

static void renameColumnParseError ( sqlite3_context * pCtx,
int bPost,
sqlite3_value * pType,
sqlite3_value * pObject,
Parse * pParse )
static

Definition at line 106747 of file sqlite3.c.

106759 {
106760 const char *zT = (const char*)sqlite3_value_text(pType);
106761 const char *zN = (const char*)sqlite3_value_text(pObject);
106762 char *zErr;
106763
106764 zErr = sqlite3_mprintf("error in %s %s%s: %s",

References sqlite3_free(), sqlite3_mprintf(), sqlite3_result_error(), sqlite3_value_text(), and Parse::zErrMsg.

Referenced by renameColumnFunc(), renameTableFunc(), and renameTableTest().

◆ renameColumnSelectCb()

static int renameColumnSelectCb ( Walker * pWalker,
Select * p )
static

Definition at line 106686 of file sqlite3.c.

References renameWalkWith(), Select::selFlags, SF_View, WRC_Continue, and WRC_Prune.

Referenced by renameColumnFunc().

◆ renameColumnTokenNext()

static RenameToken * renameColumnTokenNext ( RenameCtx * pCtx)
static

Definition at line 106726 of file sqlite3.c.

106732 {
106733 RenameToken *pBest = pCtx->pList;
106734 RenameToken *pToken;
106735 RenameToken **pp;
106736
106737 for(pToken=pBest->pNext; pToken; pToken=pToken->pNext){
106738 if( pToken->t.z>pBest->t.z ) pBest = pToken;
RenameToken * pList
Definition sqlite3.c:106448
RenameToken * pNext
Definition sqlite3.c:106439

References RenameCtx::pList, RenameToken::pNext, RenameToken::t, and Token::z.

Referenced by renameEditSql().

◆ renameEditSql()

static int renameEditSql ( sqlite3_context * pCtx,
RenameCtx * pRename,
const char * zSql,
const char * zNew,
int bQuote )
static

Definition at line 106874 of file sqlite3.c.

106886 {
106887 int nNew = sqlite3Strlen30(zNew);
106888 int nSql = sqlite3Strlen30(zSql);
106890 int rc = SQLITE_OK;
106891 char *zQuot;
106892 char *zOut;
106893 int nQuot;
106894
106895 /* Set zQuot to point to a buffer containing a quoted copy of the
106896 ** identifier zNew. If the corresponding identifier in the original
106897 ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
106898 ** point to zQuot so that all substitutions are made using the
106899 ** quoted version of the new column name. */
106900 zQuot = sqlite3MPrintf(db, "\"%w\"", zNew);
106901 if( zQuot==0 ){
106902 return SQLITE_NOMEM;
106903 }else{
106904 nQuot = sqlite3Strlen30(zQuot);
106905 }
106906 if( bQuote ){
106907 zNew = zQuot;
106908 nNew = nQuot;
106909 }
106910
106911 /* At this point pRename->pList contains a list of RenameToken objects
106912 ** corresponding to all tokens in the input SQL that must be replaced
106913 ** with the new column name. All that remains is to construct and
106914 ** return the edited SQL string. */
106915 assert( nQuot>=nNew );
106916 zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
106917 if( zOut ){
106918 int nOut = nSql;
106919 memcpy(zOut, zSql, nSql);
106920 while( pRename->pList ){
106921 int iOff; /* Offset of token to replace in zOut */
106922 RenameToken *pBest = renameColumnTokenNext(pRename);
106923
106924 u32 nReplace;
106925 const char *zReplace;
106926 if( sqlite3IsIdChar(*pBest->t.z) ){
106927 nReplace = nNew;
106928 zReplace = zNew;
106929 }else{
106930 nReplace = nQuot;
106931 zReplace = zQuot;
106932 }
106933
106934 iOff = pBest->t.z - zSql;
106935 if( pBest->t.n!=nReplace ){
106936 memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
106937 nOut - (iOff + pBest->t.n)
106938 );
106939 nOut += nReplace - pBest->t.n;
106940 zOut[nOut] = '\0';
106941 }
106942 memcpy(&zOut[iOff], zReplace, nReplace);
106943 sqlite3DbFree(db, pBest);
106944 }
106945
106946 sqlite3_result_text(pCtx, zOut, -1, SQLITE_TRANSIENT);
106947 sqlite3DbFree(db, zOut);
106948 }else{
SQLITE_PRIVATE int sqlite3IsIdChar(u8)
Definition sqlite3.c:159925
static RenameToken * renameColumnTokenNext(RenameCtx *pCtx)
Definition sqlite3.c:106726

References Token::n, RenameCtx::nList, RenameCtx::pList, renameColumnTokenNext(), sqlite3_context_db_handle(), sqlite3_free(), sqlite3_result_text(), sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3IsIdChar(), sqlite3MPrintf(), sqlite3Strlen30(), SQLITE_NOMEM, SQLITE_OK, SQLITE_TRANSIENT, RenameToken::t, and Token::z.

Referenced by renameColumnFunc(), and renameTableFunc().

◆ renameParseCleanup()

static void renameParseCleanup ( Parse * pParse)
static

Definition at line 107067 of file sqlite3.c.

107073 {
107074 sqlite3 *db = pParse->db;
107075 Index *pIdx;
107076 if( pParse->pVdbe ){
107077 sqlite3VdbeFinalize(pParse->pVdbe);
107078 }
107079 sqlite3DeleteTable(db, pParse->pNewTable);
107080 while( (pIdx = pParse->pNewIndex)!=0 ){
107081 pParse->pNewIndex = pIdx->pNext;
107082 sqlite3FreeIndex(db, pIdx);
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *, Table *)
Definition sqlite3.c:111102

Referenced by renameColumnFunc(), renameTableFunc(), and renameTableTest().

◆ renameParseSql()

static int renameParseSql ( Parse * p,
const char * zDb,
sqlite3 * db,
const char * zSql,
int bTemp )
static

Definition at line 106819 of file sqlite3.c.

106831 {
106832 int rc;
106833 char *zErr = 0;
106834
106835 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
106836
106837 /* Parse the SQL statement passed as the first argument. If no error
106838 ** occurs and the parse does not result in a new table, index or
106839 ** trigger object, the database must be corrupt. */
106840 memset(p, 0, sizeof(Parse));
106842 p->db = db;
106843 p->nQueryLoop = 1;
106844 rc = sqlite3RunParser(p, zSql, &zErr);
106845 assert( p->zErrMsg==0 );
106846 assert( rc!=SQLITE_OK || zErr==0 );
106847 p->zErrMsg = zErr;
106848 if( db->mallocFailed ) rc = SQLITE_NOMEM;
106849 if( rc==SQLITE_OK
106850 && p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0
106851 ){
106852 rc = SQLITE_CORRUPT_BKPT;
106853 }
106854
106855#ifdef SQLITE_DEBUG
106856 /* Ensure that all mappings in the Parse.pRename list really do map to
106857 ** a part of the input string. */
106858 if( rc==SQLITE_OK ){
106859 int nSql = sqlite3Strlen30(zSql);
106860 RenameToken *pToken;
106861 for(pToken=p->pRename; pToken; pToken=pToken->pNext){
106862 assert( pToken->t.z>=zSql && &pToken->t.z[pToken->t.n]<=&zSql[nSql] );
106863 }
SQLITE_PRIVATE int sqlite3RunParser(Parse *, const char *, char **)
Definition sqlite3.c:160294
#define PARSE_MODE_RENAME
Definition sqlite3.c:18783
RenameToken * pRename
Definition sqlite3.c:18777
u8 eParseMode
Definition sqlite3.c:18751

References Parse::db, Parse::eParseMode, sqlite3::sqlite3InitInfo::iDb, sqlite3::init, sqlite3::mallocFailed, Token::n, Parse::nQueryLoop, PARSE_MODE_RENAME, Parse::pNewIndex, Parse::pNewTable, Parse::pNewTrigger, RenameToken::pNext, Parse::pRename, sqlite3FindDbName(), sqlite3RunParser(), sqlite3Strlen30(), SQLITE_CORRUPT_BKPT, SQLITE_NOMEM, SQLITE_OK, RenameToken::t, Token::z, and Parse::zErrMsg.

Referenced by renameColumnFunc(), renameTableFunc(), and renameTableTest().

◆ renameReloadSchema()

static void renameReloadSchema ( Parse * pParse,
int iDb )
static

Definition at line 105872 of file sqlite3.c.

105878 {
105879 Vdbe *v = pParse->pVdbe;

Referenced by sqlite3AlterFinishAddColumn(), and sqlite3AlterRenameColumn().

◆ renameResolveTrigger()

static int renameResolveTrigger ( Parse * pParse)
static

Definition at line 106956 of file sqlite3.c.

106962 {
106963 sqlite3 *db = pParse->db;
106964 Trigger *pNew = pParse->pNewTrigger;
106965 TriggerStep *pStep;
106966 NameContext sNC;
106967 int rc = SQLITE_OK;
106968
106969 memset(&sNC, 0, sizeof(sNC));
106970 sNC.pParse = pParse;
106971 assert( pNew->pTabSchema );
106972 pParse->pTriggerTab = sqlite3FindTable(db, pNew->table,
106974 );
106975 pParse->eTriggerOp = pNew->op;
106976 /* ALWAYS() because if the table of the trigger does not exist, the
106977 ** error would have been hit before this point */
106978 if( ALWAYS(pParse->pTriggerTab) ){
106979 rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab);
106980 }
106981
106982 /* Resolve symbols in WHEN clause */
106983 if( rc==SQLITE_OK && pNew->pWhen ){
106984 rc = sqlite3ResolveExprNames(&sNC, pNew->pWhen);
106985 }
106986
106987 for(pStep=pNew->step_list; rc==SQLITE_OK && pStep; pStep=pStep->pNext){
106988 if( pStep->pSelect ){
106989 sqlite3SelectPrep(pParse, pStep->pSelect, &sNC);
106990 if( pParse->nErr ) rc = pParse->rc;
106991 }
106992 if( rc==SQLITE_OK && pStep->zTarget ){
106993 SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep);
106994 if( pSrc ){
106995 int i;
106996 for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){
106997 struct SrcList_item *p = &pSrc->a[i];
106998 p->pTab = sqlite3LocateTableItem(pParse, 0, p);
106999 p->iCursor = pParse->nTab++;
107000 if( p->pTab==0 ){
107001 rc = SQLITE_ERROR;
107002 }else{
107003 p->pTab->nTabRef++;
107004 rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
107005 }
107006 }
107007 sNC.pSrcList = pSrc;
107008 if( rc==SQLITE_OK && pStep->pWhere ){
107009 rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
107010 }
107011 if( rc==SQLITE_OK ){
107012 rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList);
107013 }
107014 assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) );
107015 if( pStep->pUpsert ){
107016 Upsert *pUpsert = pStep->pUpsert;
107017 assert( rc==SQLITE_OK );
107018 pUpsert->pUpsertSrc = pSrc;
107019 sNC.uNC.pUpsert = pUpsert;
107020 sNC.ncFlags = NC_UUpsert;
107021 rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget);
107022 if( rc==SQLITE_OK ){
107023 ExprList *pUpsertSet = pUpsert->pUpsertSet;
107024 rc = sqlite3ResolveExprListNames(&sNC, pUpsertSet);
107025 }
107026 if( rc==SQLITE_OK ){
107027 rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertWhere);
107028 }
107029 if( rc==SQLITE_OK ){
107030 rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertTargetWhere);
107031 }
107032 sNC.ncFlags = 0;
107033 }
107034 sNC.pSrcList = 0;
107035 sqlite3SrcListDelete(db, pSrc);
107036 }else{
SQLITE_PRIVATE Table * sqlite3LocateTableItem(Parse *, u32 flags, struct SrcList_item *)
Definition sqlite3.c:110837
SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext *, ExprList *)
Definition sqlite3.c:99583
SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *, Table *)
Definition sqlite3.c:113032
char * table
Definition sqlite3.c:18873
ExprList * pUpsertTarget
Definition sqlite3.c:18407
Expr * pUpsertTargetWhere
Definition sqlite3.c:18408
Expr * pUpsertWhere
Definition sqlite3.c:18410

References SrcList::a, sqlite3::aDb, ALWAYS, Parse::db, Parse::eTriggerOp, NC_UUpsert, NameContext::ncFlags, Parse::nErr, SrcList::nSrc, Parse::nTab, Trigger::op, TriggerStep::pExprList, Parse::pNewTrigger, TriggerStep::pNext, NameContext::pParse, TriggerStep::pSelect, NameContext::pSrcList, SrcList::SrcList_item::pTab, Trigger::pTabSchema, Parse::pTriggerTab, NameContext::pUpsert, TriggerStep::pUpsert, Upsert::pUpsertSet, Upsert::pUpsertSrc, Upsert::pUpsertTarget, Upsert::pUpsertTargetWhere, Upsert::pUpsertWhere, Trigger::pWhen, TriggerStep::pWhere, Parse::rc, sqlite3FindTable(), sqlite3LocateTableItem(), sqlite3ResolveExprListNames(), sqlite3ResolveExprNames(), sqlite3SchemaToIndex(), sqlite3SelectPrep(), sqlite3SrcListDelete(), sqlite3TriggerStepSrc(), sqlite3ViewGetColumnNames(), SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, Trigger::step_list, Trigger::table, NameContext::uNC, Db::zDbSName, and TriggerStep::zTarget.

Referenced by renameColumnFunc(), renameTableFunc(), and renameTableTest().

◆ renameTableExprCb()

static int renameTableExprCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 107268 of file sqlite3.c.

107274 {

Referenced by renameTableFunc().

◆ renameTableFunc()

static void renameTableFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 107319 of file sqlite3.c.

107320 :
107321**
107322** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
107323** -> 'CREATE TABLE t1(a REFERENCES t3)'
107324*/
107325static void renameTableFunc(
107326 sqlite3_context *context,
107327 int NotUsed,
107328 sqlite3_value **argv
107329){
107330 sqlite3 *db = sqlite3_context_db_handle(context);
107331 const char *zDb = (const char*)sqlite3_value_text(argv[0]);
107332 const char *zInput = (const char*)sqlite3_value_text(argv[3]);
107333 const char *zOld = (const char*)sqlite3_value_text(argv[4]);
107334 const char *zNew = (const char*)sqlite3_value_text(argv[5]);
107335 int bTemp = sqlite3_value_int(argv[6]);
107336 UNUSED_PARAMETER(NotUsed);
107337
107338 if( zInput && zOld && zNew ){
107339 Parse sParse;
107340 int rc;
107341 int bQuote = 1;
107342 RenameCtx sCtx;
107343 Walker sWalker;
107344
107345#ifndef SQLITE_OMIT_AUTHORIZATION
107346 sqlite3_xauth xAuth = db->xAuth;
107347 db->xAuth = 0;
107348#endif
107349
107351
107352 memset(&sCtx, 0, sizeof(RenameCtx));
107353 sCtx.pTab = sqlite3FindTable(db, zOld, zDb);
107354 memset(&sWalker, 0, sizeof(Walker));
107355 sWalker.pParse = &sParse;
107358 sWalker.u.pRename = &sCtx;
107359
107360 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
107361
107362 if( rc==SQLITE_OK ){
107363 int isLegacy = (db->flags & SQLITE_LegacyAlter);
107364 if( sParse.pNewTable ){
107365 Table *pTab = sParse.pNewTable;
107366
107367 if( pTab->pSelect ){
107368 if( isLegacy==0 ){
107369 Select *pSelect = pTab->pSelect;
107370 NameContext sNC;
107371 memset(&sNC, 0, sizeof(sNC));
107372 sNC.pParse = &sParse;
107373
107374 assert( pSelect->selFlags & SF_View );
107375 pSelect->selFlags &= ~SF_View;
107376 sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
107377 if( sParse.nErr ){
107378 rc = sParse.rc;
107379 }else{
107380 sqlite3WalkSelect(&sWalker, pTab->pSelect);
107381 }
107382 }
107383 }else{
107384 /* Modify any FK definitions to point to the new table. */
107385#ifndef SQLITE_OMIT_FOREIGN_KEY
107386 if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
107387 FKey *pFKey;
107388 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
107389 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
107390 renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
107391 }
107392 }
107393 }
107394#endif
107395
107396 /* If this is the table being altered, fix any table refs in CHECK
107397 ** expressions. Also update the name that appears right after the
107398 ** "CREATE [VIRTUAL] TABLE" bit. */
107399 if( sqlite3_stricmp(zOld, pTab->zName)==0 ){
107400 sCtx.pTab = pTab;
107401 if( isLegacy==0 ){
107402 sqlite3WalkExprList(&sWalker, pTab->pCheck);
107403 }
107404 renameTokenFind(&sParse, &sCtx, pTab->zName);
107405 }
107406 }
107407 }
107408
107409 else if( sParse.pNewIndex ){
107410 renameTokenFind(&sParse, &sCtx, sParse.pNewIndex->zName);
107411 if( isLegacy==0 ){
107412 sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
107413 }
107414 }
107415
107416#ifndef SQLITE_OMIT_TRIGGER
107417 else{
107418 Trigger *pTrigger = sParse.pNewTrigger;
107419 TriggerStep *pStep;
107420 if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld)
107421 && sCtx.pTab->pSchema==pTrigger->pTabSchema
107422 ){
107423 renameTokenFind(&sParse, &sCtx, sParse.pNewTrigger->table);
107424 }
107425
107426 if( isLegacy==0 ){
107427 rc = renameResolveTrigger(&sParse);
107428 if( rc==SQLITE_OK ){
107429 renameWalkTrigger(&sWalker, pTrigger);
107430 for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
107431 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
107432 renameTokenFind(&sParse, &sCtx, pStep->zTarget);
107433 }
107434 }
107435 }
107436 }
107437 }
107438#endif
107439 }
107440
107441 if( rc==SQLITE_OK ){
107442 rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
107443 }
107444 if( rc!=SQLITE_OK ){
107445 if( sParse.zErrMsg ){
107446 renameColumnParseError(context, 0, argv[1], argv[2], &sParse);
107447 }else{
107448 sqlite3_result_error_code(context, rc);
107449 }
107450 }
107451
107452 renameParseCleanup(&sParse);
107453 renameTokenFree(db, sCtx.pList);
107455#ifndef SQLITE_OMIT_AUTHORIZATION
static int renameTableExprCb(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:107268
#define SF_View
Definition sqlite3.c:18492
static void renameTableFunc(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:107319
static void renameTokenFree(sqlite3 *db, RenameToken *pToken)
Definition sqlite3.c:106651
static int renameTableSelectCb(Walker *pWalker, Select *pSelect)
Definition sqlite3.c:107279

References sqlite3::flags, Parse::nErr, Table::pCheck, Table::pFKey, RenameCtx::pList, Parse::pNewIndex, Parse::pNewTable, Parse::pNewTrigger, TriggerStep::pNext, FKey::pNextFrom, NameContext::pParse, Walker::pParse, Index::pPartIdxWhere, Walker::pRename, Table::pSchema, Table::pSelect, RenameCtx::pTab, Trigger::pTabSchema, Parse::rc, renameColumnParseError(), renameEditSql(), renameParseCleanup(), renameParseSql(), renameResolveTrigger(), renameTableExprCb(), renameTableSelectCb(), renameTokenFind(), renameTokenFree(), renameWalkTrigger(), Select::selFlags, SF_View, sqlite3_context_db_handle(), sqlite3_result_error_code(), sqlite3_stricmp(), sqlite3_value_int(), sqlite3_value_text(), sqlite3BtreeEnterAll(), sqlite3BtreeLeaveAll(), sqlite3FindTable(), sqlite3SelectPrep(), sqlite3WalkExpr(), sqlite3WalkExprList(), sqlite3WalkSelect(), SQLITE_ForeignKeys, SQLITE_LegacyAlter, SQLITE_OK, Trigger::step_list, Trigger::table, Walker::u, UNUSED_PARAMETER, sqlite3::xAuth, Walker::xExprCallback, Walker::xSelectCallback, Parse::zErrMsg, Table::zName, Index::zName, TriggerStep::zTarget, and FKey::zTo.

◆ renameTableSelectCb()

static int renameTableSelectCb ( Walker * pWalker,
Select * pSelect )
static

Definition at line 107279 of file sqlite3.c.

107285 {
107286 int i;
107287 RenameCtx *p = pWalker->u.pRename;
107288 SrcList *pSrc = pSelect->pSrc;
107289 if( pSelect->selFlags & SF_View ) return WRC_Prune;
107290 if( pSrc==0 ){
107291 assert( pWalker->pParse->db->mallocFailed );
107292 return WRC_Abort;
107293 }
107294 for(i=0; i<pSrc->nSrc; i++){
107295 struct SrcList_item *pItem = &pSrc->a[i];
107296 if( pItem->pTab==p->pTab ){
107297 renameTokenFind(pWalker->pParse, p, pItem->zName);

Referenced by renameTableFunc().

◆ renameTableTest()

static void renameTableTest ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 107476 of file sqlite3.c.

107477 :
107478**
107479** * the SQL argument creates a trigger, and
107480** * the table that the trigger is attached to is in database zDb.
107481*/
107482static void renameTableTest(
107483 sqlite3_context *context,
107484 int NotUsed,
107485 sqlite3_value **argv
107486){
107487 sqlite3 *db = sqlite3_context_db_handle(context);
107488 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
107489 char const *zInput = (const char*)sqlite3_value_text(argv[1]);
107490 int bTemp = sqlite3_value_int(argv[4]);
107491 int isLegacy = (db->flags & SQLITE_LegacyAlter);
107492
107493#ifndef SQLITE_OMIT_AUTHORIZATION
107494 sqlite3_xauth xAuth = db->xAuth;
107495 db->xAuth = 0;
107496#endif
107497
107498 UNUSED_PARAMETER(NotUsed);
107499 if( zDb && zInput ){
107500 int rc;
107501 Parse sParse;
107502 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
107503 if( rc==SQLITE_OK ){
107504 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
107505 NameContext sNC;
107506 memset(&sNC, 0, sizeof(sNC));
107507 sNC.pParse = &sParse;
107508 sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC);
107509 if( sParse.nErr ) rc = sParse.rc;
107510 }
107511
107512 else if( sParse.pNewTrigger ){
107513 if( isLegacy==0 ){
107514 rc = renameResolveTrigger(&sParse);
107515 }
107516 if( rc==SQLITE_OK ){
107517 int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema);
107518 int i2 = sqlite3FindDbName(db, zDb);
107519 if( i1==i2 ) sqlite3_result_int(context, 1);
107520 }
107521 }
107522 }
107523
107524 if( rc!=SQLITE_OK ){
107525 renameColumnParseError(context, 1, argv[2], argv[3], &sParse);
107526 }
107527 renameParseCleanup(&sParse);
static void renameTableTest(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:107476

References sqlite3::flags, Parse::nErr, Parse::pNewTable, Parse::pNewTrigger, NameContext::pParse, Table::pSelect, Trigger::pTabSchema, Parse::rc, renameColumnParseError(), renameParseCleanup(), renameParseSql(), renameResolveTrigger(), sqlite3_context_db_handle(), sqlite3_result_int(), sqlite3_value_int(), sqlite3_value_text(), sqlite3FindDbName(), sqlite3SchemaToIndex(), sqlite3SelectPrep(), SQLITE_LegacyAlter, SQLITE_OK, UNUSED_PARAMETER, and sqlite3::xAuth.

◆ renameTestSchema()

static void renameTestSchema ( Parse * pParse,
const char * zDb,
int bTemp )
static

Definition at line 105845 of file sqlite3.c.

105851 {
105852 sqlite3NestedParse(pParse,
105853 "SELECT 1 "
105854 "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
105855 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105856 " AND sql NOT LIKE 'create virtual%%'"
105857 " AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ",
105858 zDb,
105859 zDb, bTemp
105860 );
105861
105862 if( bTemp==0 ){
105863 sqlite3NestedParse(pParse,
105864 "SELECT 1 "
105865 "FROM temp." DFLT_SCHEMA_TABLE " "
105866 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
#define DFLT_SCHEMA_TABLE
Definition sqlite3.c:14573

References DFLT_SCHEMA_TABLE, and sqlite3NestedParse().

Referenced by sqlite3AlterRenameColumn().

◆ renameTokenFind()

static void renameTokenFind ( Parse * pParse,
struct RenameCtx * pCtx,
void * pPtr )
static

Definition at line 106666 of file sqlite3.c.

106672 {
106673 RenameToken **pp;
106674 assert( pPtr!=0 );
106675 for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
106676 if( (*pp)->p==pPtr ){
106677 RenameToken *pToken = *pp;
106678 *pp = pToken->pNext;
106679 pToken->pNext = pCtx->pList;

References RenameCtx::nList, RenameCtx::pList, RenameToken::pNext, and Parse::pRename.

Referenced by renameColumnElistNames(), renameColumnExprCb(), renameColumnFunc(), renameColumnIdlistNames(), and renameTableFunc().

◆ renameTokenFree()

static void renameTokenFree ( sqlite3 * db,
RenameToken * pToken )
static

Definition at line 106651 of file sqlite3.c.

106657 {
106658 RenameToken *pNext;

Referenced by renameColumnFunc(), and renameTableFunc().

◆ renameUnmapExprCb()

static int renameUnmapExprCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 106543 of file sqlite3.c.

◆ renameUnmapSelectCb()

static int renameUnmapSelectCb ( Walker * pWalker,
Select * p )
static

Definition at line 106587 of file sqlite3.c.

106593 {
106594 Parse *pParse = pWalker->pParse;
106595 int i;
106596 if( pParse->nErr ) return WRC_Abort;
106597 if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
106598 if( ALWAYS(p->pEList) ){
106599 ExprList *pList = p->pEList;
106600 for(i=0; i<pList->nExpr; i++){
106601 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
106602 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
106603 }
106604 }
106605 }
106606 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
106607 SrcList *pSrc = p->pSrc;
106608 for(i=0; i<pSrc->nSrc; i++){
106609 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
106610 if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
106611 unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
static void unmapColumnIdlistNames(Parse *pParse, IdList *pIdList)
Definition sqlite3.c:106572

◆ renameWalkTrigger()

static void renameWalkTrigger ( Walker * pWalker,
Trigger * pTrigger )
static

Definition at line 107042 of file sqlite3.c.

107048 {
107049 TriggerStep *pStep;
107050
107051 /* Find tokens to edit in WHEN clause */
107052 sqlite3WalkExpr(pWalker, pTrigger->pWhen);
107053
107054 /* Find tokens to edit in trigger steps */
107055 for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
107056 sqlite3WalkSelect(pWalker, pStep->pSelect);
107057 sqlite3WalkExpr(pWalker, pStep->pWhere);
107058 sqlite3WalkExprList(pWalker, pStep->pExprList);
107059 if( pStep->pUpsert ){
107060 Upsert *pUpsert = pStep->pUpsert;
107061 sqlite3WalkExprList(pWalker, pUpsert->pUpsertTarget);

Referenced by renameColumnFunc(), and renameTableFunc().

◆ renameWalkWith()

static void renameWalkWith ( Walker * pWalker,
Select * pSelect )
static

Definition at line 106553 of file sqlite3.c.

106559 {
106560 With *pWith = pSelect->pWith;
106561 if( pWith ){
106562 int i;
106563 for(i=0; i<pWith->nCte; i++){
106564 Select *p = pWith->a[i].pSelect;
106565 NameContext sNC;
106566 memset(&sNC, 0, sizeof(sNC));
106567 sNC.pParse = pWalker->pParse;
With * pWith
Definition sqlite3.c:18455
Select * pSelect
Definition sqlite3.c:19151
struct With::Cte a[1]
int nCte
Definition sqlite3.c:19146

Referenced by renameColumnSelectCb().

◆ renderLogMsg()

static void renderLogMsg ( int iErrCode,
const char * zFormat,
va_list ap )
static

Definition at line 29386 of file sqlite3.c.

29392 {
29393 StrAccum acc; /* String accumulator */
29394 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
#define SQLITE_PRINT_BUF_SIZE
Definition sqlite3.c:28327

References sqlite3_str_vappendf(), sqlite3GlobalConfig, sqlite3StrAccumInit(), and SQLITE_PRINT_BUF_SIZE.

◆ replaceFunc()

static void replaceFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118262 of file sqlite3.c.

118272 {
118273 const unsigned char *zStr; /* The input string A */
118274 const unsigned char *zPattern; /* The pattern string B */
118275 const unsigned char *zRep; /* The replacement string C */
118276 unsigned char *zOut; /* The output */
118277 int nStr; /* Size of zStr */
118278 int nPattern; /* Size of zPattern */
118279 int nRep; /* Size of zRep */
118280 i64 nOut; /* Maximum size of zOut */
118281 int loopLimit; /* Last zStr[] that might match zPattern[] */
118282 int i, j; /* Loop counters */
118283 unsigned cntExpand; /* Number zOut expansions */
118284 sqlite3 *db = sqlite3_context_db_handle(context);
118285
118286 assert( argc==3 );
118287 UNUSED_PARAMETER(argc);
118288 zStr = sqlite3_value_text(argv[0]);
118289 if( zStr==0 ) return;
118290 nStr = sqlite3_value_bytes(argv[0]);
118291 assert( zStr==sqlite3_value_text(argv[0]) ); /* No encoding change */
118292 zPattern = sqlite3_value_text(argv[1]);
118293 if( zPattern==0 ){
118294 assert( sqlite3_value_type(argv[1])==SQLITE_NULL
118295 || sqlite3_context_db_handle(context)->mallocFailed );
118296 return;
118297 }
118298 if( zPattern[0]==0 ){
118299 assert( sqlite3_value_type(argv[1])!=SQLITE_NULL );
118300 sqlite3_result_value(context, argv[0]);
118301 return;
118302 }
118303 nPattern = sqlite3_value_bytes(argv[1]);
118304 assert( zPattern==sqlite3_value_text(argv[1]) ); /* No encoding change */
118305 zRep = sqlite3_value_text(argv[2]);
118306 if( zRep==0 ) return;
118307 nRep = sqlite3_value_bytes(argv[2]);
118308 assert( zRep==sqlite3_value_text(argv[2]) );
118309 nOut = nStr + 1;
118310 assert( nOut<SQLITE_MAX_LENGTH );
118311 zOut = contextMalloc(context, (i64)nOut);
118312 if( zOut==0 ){
118313 return;
118314 }
118315 loopLimit = nStr - nPattern;
118316 cntExpand = 0;
118317 for(i=j=0; i<=loopLimit; i++){
118318 if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){
118319 zOut[j++] = zStr[i];
118320 }else{
118321 if( nRep>nPattern ){
118322 nOut += nRep - nPattern;
118323 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
118324 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
118325 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
118327 sqlite3_free(zOut);
118328 return;
118329 }
118330 cntExpand++;
118331 if( (cntExpand&(cntExpand-1))==0 ){
118332 /* Grow the size of the output buffer only on substitutions
118333 ** whose index is a power of two: 1, 2, 4, 8, 16, 32, ... */
118334 u8 *zOld;
118335 zOld = zOut;
118336 zOut = sqlite3Realloc(zOut, (int)nOut + (nOut - nStr - 1));
118337 if( zOut==0 ){
118339 sqlite3_free(zOld);
118340 return;
118341 }
118342 }
118343 }
118344 memcpy(&zOut[j], zRep, nRep);
118345 j += nRep;
118346 i += nPattern-1;
118347 }
118348 }
118349 assert( j+nStr-i+1<=nOut );
#define SQLITE_MAX_LENGTH
Definition sqlite3.c:13261

References sqlite3::aLimit, contextMalloc(), sqlite3_context_db_handle(), sqlite3_free(), sqlite3_result_error_nomem(), sqlite3_result_error_toobig(), sqlite3_result_text(), sqlite3_result_value(), sqlite3_value_bytes(), sqlite3_value_text(), sqlite3_value_type(), sqlite3Realloc(), SQLITE_LIMIT_LENGTH, SQLITE_MAX_LENGTH, SQLITE_NULL, testcase, and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ resetAccumulator()

static void resetAccumulator ( Parse * pParse,
AggInfo * pAggInfo )
static

Definition at line 134688 of file sqlite3.c.

134694 {
134695 Vdbe *v = pParse->pVdbe;
134696 int i;
134697 struct AggInfo_func *pFunc;
134698 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
134699 if( nReg==0 ) return;
134700 if( pParse->nErr || pParse->db->mallocFailed ) return;
134701#ifdef SQLITE_DEBUG
134702 /* Verify that all AggInfo registers are within the range specified by
134703 ** AggInfo.mnReg..AggInfo.mxReg */
134704 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
134705 for(i=0; i<pAggInfo->nColumn; i++){
134706 assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg
134707 && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg );
134708 }
134709 for(i=0; i<pAggInfo->nFunc; i++){
134710 assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg
134711 && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg );
134712 }
134713#endif
134714 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
134715 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
134716 if( pFunc->iDistinct>=0 ){
134717 Expr *pE = pFunc->pFExpr;
134718 assert( !ExprHasProperty(pE, EP_xIsSelect) );
134719 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
134720 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
134721 "argument");
134722 pFunc->iDistinct = -1;
134723 }else{
134724 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
int mxReg
Definition sqlite3.c:17889
int mnReg
Definition sqlite3.c:17889

References AggInfo::aCol, AggInfo::aFunc, Parse::db, EP_xIsSelect, ExprHasProperty, AggInfo::AggInfo_col::iMem, AggInfo::AggInfo_func::iMem, sqlite3::mallocFailed, AggInfo::mnReg, AggInfo::mxReg, AggInfo::nColumn, Parse::nErr, ExprList::nExpr, AggInfo::nFunc, OP_Null, OP_OpenEphemeral, P4_KEYINFO, Expr::pList, Parse::pVdbe, sqlite3ErrorMsg(), sqlite3KeyInfoFromExprList(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), and Expr::x.

Referenced by sqlite3Select().

◆ resizeIndexObject()

static int resizeIndexObject ( sqlite3 * db,
Index * pIdx,
int N )
static

Definition at line 112269 of file sqlite3.c.

112275 {
112276 char *zExtra;
112277 int nByte;
112278 if( pIdx->nColumn>=N ) return SQLITE_OK;
112279 assert( pIdx->isResized==0 );
112280 nByte = (sizeof(char*) + sizeof(i16) + 1)*N;
112281 zExtra = sqlite3DbMallocZero(db, nByte);
112282 if( zExtra==0 ) return SQLITE_NOMEM_BKPT;
112283 memcpy(zExtra, pIdx->azColl, sizeof(char*)*pIdx->nColumn);
112284 pIdx->azColl = (const char**)zExtra;
112285 zExtra += sizeof(char*)*N;
112286 memcpy(zExtra, pIdx->aiColumn, sizeof(i16)*pIdx->nColumn);
112287 pIdx->aiColumn = (i16*)zExtra;
112288 zExtra += sizeof(i16)*N;
unsigned isResized
Definition sqlite3.c:17796

Referenced by convertToWithoutRowidTable().

◆ resizeResolveLabel()

static SQLITE_NOINLINE void resizeResolveLabel ( Parse * p,
Vdbe * v,
int j )
static

Definition at line 78281 of file sqlite3.c.

78287 {
78288 int nNewSize = 10 - p->nLabel;
78290 nNewSize*sizeof(p->aLabel[0]));
78291 if( p->aLabel==0 ){
78292 p->nLabelAlloc = 0;
78293 }else{
78294#ifdef SQLITE_DEBUG
78295 int i;
int * aLabel
Definition sqlite3.c:18704
int nLabel
Definition sqlite3.c:18702
int nLabelAlloc
Definition sqlite3.c:18703

References Parse::aLabel, Parse::db, Parse::nLabel, Parse::nLabelAlloc, and sqlite3DbReallocOrFree().

◆ resolveAlias()

static void resolveAlias ( Parse * pParse,
ExprList * pEList,
int iCol,
Expr * pExpr,
const char * zType,
int nSubquery )
static

Definition at line 97817 of file sqlite3.c.

97830 {
97831 Expr *pOrig; /* The iCol-th column of the result set */
97832 Expr *pDup; /* Copy of pOrig */
97833 sqlite3 *db; /* The database connection */
97834
97835 assert( iCol>=0 && iCol<pEList->nExpr );
97836 pOrig = pEList->a[iCol].pExpr;
97837 assert( pOrig!=0 );
97838 db = pParse->db;
97839 pDup = sqlite3ExprDup(db, pOrig, 0);
97840 if( pDup!=0 ){
97841 if( zType[0]!='G' ) incrAggFunctionDepth(pDup, nSubquery);
97842 if( pExpr->op==TK_COLLATE ){
97843 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
97844 }
97845
97846 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
97847 ** prevents ExprDelete() from deleting the Expr structure itself,
97848 ** allowing it to be repopulated by the memcpy() on the following line.
97849 ** The pExpr->u.zToken might point into memory that will be freed by the
97850 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
97851 ** make a copy of the token before doing the sqlite3DbFree().
97852 */
97853 ExprSetProperty(pExpr, EP_Static);
97854 sqlite3ExprDelete(db, pExpr);
97855 memcpy(pExpr, pDup, sizeof(*pExpr));
97856 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
97857 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
97858 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
97859 pExpr->flags |= EP_MemToken;
97860 }
97861 if( ExprHasProperty(pExpr, EP_WinFunc) ){
97862 if( pExpr->y.pWin!=0 ){
97863 pExpr->y.pWin->pOwner = pExpr;
97864 }else{
97865 assert( db->mallocFailed );
Expr * pOwner
Definition sqlite3.c:19212

References ExprList::a, Parse::db, EP_Alias, EP_IntValue, EP_MemToken, EP_Reduced, EP_Static, EP_TokenOnly, EP_WinFunc, ExprHasProperty, ExprSetProperty, Expr::flags, incrAggFunctionDepth(), sqlite3::mallocFailed, Expr::op, ExprList::ExprList_item::pExpr, Window::pOwner, Expr::pWin, sqlite3DbFree(), sqlite3DbStrDup(), sqlite3ExprAddCollateString(), sqlite3ExprDelete(), sqlite3ExprDup(), TK_COLLATE, Expr::u, Expr::y, and Expr::zToken.

Referenced by lookupName(), and sqlite3ResolveOrderGroupBy().

◆ resolveAsName()

static int resolveAsName ( Parse * pParse,
ExprList * pEList,
Expr * pE )
static

Definition at line 98888 of file sqlite3.c.

98898 {
98899 int i; /* Loop counter */
98900
98901 UNUSED_PARAMETER(pParse);
98902
98903 if( pE->op==TK_ID ){
98904 char *zCol = pE->u.zToken;
98905 for(i=0; i<pEList->nExpr; i++){
98906 if( pEList->a[i].eEName==ENAME_NAME
98907 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
98908 ){

References ExprList::a, ExprList::ExprList_item::eEName, ENAME_NAME, ExprList::nExpr, Expr::op, sqlite3_stricmp(), TK_ID, Expr::u, UNUSED_PARAMETER, ExprList::ExprList_item::zEName, and Expr::zToken.

Referenced by resolveCompoundOrderBy(), and resolveOrderGroupBy().

◆ resolveAttachExpr()

static int resolveAttachExpr ( NameContext * pName,
Expr * pExpr )
static

Definition at line 109523 of file sqlite3.c.

109523 :
109524**
109525** ATTACH DATABASE abc||def AS 'db2'
109526**
109527** will fail because neither abc or def can be resolved.
109528*/
109529static int resolveAttachExpr(NameContext *pName, Expr *pExpr)
109530{
109531 int rc = SQLITE_OK;
109532 if( pExpr ){
109533 if( pExpr->op!=TK_ID ){
109534 rc = sqlite3ResolveExprNames(pName, pExpr);

References Expr::op, sqlite3ResolveExprNames(), SQLITE_OK, TK_ID, and TK_STRING.

◆ resolveCompoundOrderBy()

static int resolveCompoundOrderBy ( Parse * pParse,
Select * pSelect )
static

Definition at line 99001 of file sqlite3.c.

99010 {
99011 int i;
99012 ExprList *pOrderBy;
99013 ExprList *pEList;
99014 sqlite3 *db;
99015 int moreToDo = 1;
99016
99017 pOrderBy = pSelect->pOrderBy;
99018 if( pOrderBy==0 ) return 0;
99019 db = pParse->db;
99020 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
99021 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
99022 return 1;
99023 }
99024 for(i=0; i<pOrderBy->nExpr; i++){
99025 pOrderBy->a[i].done = 0;
99026 }
99027 pSelect->pNext = 0;
99028 while( pSelect->pPrior ){
99029 pSelect->pPrior->pNext = pSelect;
99030 pSelect = pSelect->pPrior;
99031 }
99032 while( pSelect && moreToDo ){
99033 struct ExprList_item *pItem;
99034 moreToDo = 0;
99035 pEList = pSelect->pEList;
99036 assert( pEList!=0 );
99037 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99038 int iCol = -1;
99039 Expr *pE, *pDup;
99040 if( pItem->done ) continue;
99041 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
99042 if( sqlite3ExprIsInteger(pE, &iCol) ){
99043 if( iCol<=0 || iCol>pEList->nExpr ){
99044 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
99045 return 1;
99046 }
99047 }else{
99048 iCol = resolveAsName(pParse, pEList, pE);
99049 if( iCol==0 ){
99050 /* Now test if expression pE matches one of the values returned
99051 ** by pSelect. In the usual case this is done by duplicating the
99052 ** expression, resolving any symbols in it, and then comparing
99053 ** it against each expression returned by the SELECT statement.
99054 ** Once the comparisons are finished, the duplicate expression
99055 ** is deleted.
99056 **
99057 ** Or, if this is running as part of an ALTER TABLE operation,
99058 ** resolve the symbols in the actual expression, not a duplicate.
99059 ** And, if one of the comparisons is successful, leave the expression
99060 ** as is instead of transforming it to an integer as in the usual
99061 ** case. This allows the code in alter.c to modify column
99062 ** refererences within the ORDER BY expression as required. */
99063 if( IN_RENAME_OBJECT ){
99064 pDup = pE;
99065 }else{
99066 pDup = sqlite3ExprDup(db, pE, 0);
99067 }
99068 if( !db->mallocFailed ){
99069 assert(pDup);
99070 iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
99071 }
99072 if( !IN_RENAME_OBJECT ){
99073 sqlite3ExprDelete(db, pDup);
99074 }
99075 }
99076 }
99077 if( iCol>0 ){
99078 /* Convert the ORDER BY term into an integer column number iCol,
99079 ** taking care to preserve the COLLATE clause if it exists */
99080 if( !IN_RENAME_OBJECT ){
99081 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
99082 if( pNew==0 ) return 1;
99083 pNew->flags |= EP_IntValue;
99084 pNew->u.iValue = iCol;
99085 if( pItem->pExpr==pE ){
99086 pItem->pExpr = pNew;
99087 }else{
99088 Expr *pParent = pItem->pExpr;
99089 assert( pParent->op==TK_COLLATE );
99090 while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
99091 assert( pParent->pLeft==pE );
99092 pParent->pLeft = pNew;
99093 }
99094 sqlite3ExprDelete(db, pE);
99095 pItem->u.x.iOrderByCol = (u16)iCol;
99096 }
99097 pItem->done = 1;
99098 }else{
99099 moreToDo = 1;
99100 }
99101 }
99102 pSelect = pSelect->pNext;
99103 }
99104 for(i=0; i<pOrderBy->nExpr; i++){
99105 if( pOrderBy->a[i].done==0 ){
99106 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
static void resolveOutOfRangeError(Parse *pParse, const char *zType, int i, int mx)
Definition sqlite3.c:98975
static int resolveAsName(Parse *pParse, ExprList *pEList, Expr *pE)
Definition sqlite3.c:98888
static int resolveOrderByTermToExprList(Parse *pParse, Select *pSelect, Expr *pE)
Definition sqlite3.c:98928

References ExprList::a, sqlite3::aLimit, Parse::db, ExprList::ExprList_item::done, EP_IntValue, Expr::flags, IN_RENAME_OBJECT, Expr::iValue, sqlite3::mallocFailed, ExprList::nExpr, Expr::op, Select::pEList, Expr::pLeft, Select::pNext, Select::pOrderBy, Select::pPrior, resolveAsName(), resolveOrderByTermToExprList(), resolveOutOfRangeError(), sqlite3ErrorMsg(), sqlite3Expr(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprIsInteger(), sqlite3ExprSkipCollateAndLikely(), SQLITE_LIMIT_COLUMN, TK_COLLATE, TK_INTEGER, and Expr::u.

◆ resolveExprStep()

static int resolveExprStep ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 98488 of file sqlite3.c.

98494 {
98495 NameContext *pNC;
98496 Parse *pParse;
98497
98498 pNC = pWalker->u.pNC;
98499 assert( pNC!=0 );
98500 pParse = pNC->pParse;
98501 assert( pParse==pWalker->pParse );
98502
98503#ifndef NDEBUG
98504 if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
98505 SrcList *pSrcList = pNC->pSrcList;
98506 int i;
98507 for(i=0; i<pNC->pSrcList->nSrc; i++){
98508 assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab);
98509 }
98510 }
98511#endif
98512 switch( pExpr->op ){
98513
98514 /* The special operator TK_ROW means use the rowid for the first
98515 ** column in the FROM clause. This is used by the LIMIT and ORDER BY
98516 ** clause processing on UPDATE and DELETE statements, and by
98517 ** UPDATE ... FROM statement processing.
98518 */
98519 case TK_ROW: {
98520 SrcList *pSrcList = pNC->pSrcList;
98521 struct SrcList_item *pItem;
98522 assert( pSrcList && pSrcList->nSrc>=1 );
98523 pItem = pSrcList->a;
98524 pExpr->op = TK_COLUMN;
98525 pExpr->y.pTab = pItem->pTab;
98526 pExpr->iTable = pItem->iCursor;
98527 pExpr->iColumn--;
98528 pExpr->affExpr = SQLITE_AFF_INTEGER;
98529 break;
98530 }
98531
98532 /* A column name: ID
98533 ** Or table name and column name: ID.ID
98534 ** Or a database, table and column: ID.ID.ID
98535 **
98536 ** The TK_ID and TK_OUT cases are combined so that there will only
98537 ** be one call to lookupName(). Then the compiler will in-line
98538 ** lookupName() for a size reduction and performance increase.
98539 */
98540 case TK_ID:
98541 case TK_DOT: {
98542 const char *zColumn;
98543 const char *zTable;
98544 const char *zDb;
98545 Expr *pRight;
98546
98547 if( pExpr->op==TK_ID ){
98548 zDb = 0;
98549 zTable = 0;
98550 zColumn = pExpr->u.zToken;
98551 }else{
98552 Expr *pLeft = pExpr->pLeft;
98553 testcase( pNC->ncFlags & NC_IdxExpr );
98554 testcase( pNC->ncFlags & NC_GenCol );
98555 sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
98557 pRight = pExpr->pRight;
98558 if( pRight->op==TK_ID ){
98559 zDb = 0;
98560 }else{
98561 assert( pRight->op==TK_DOT );
98562 zDb = pLeft->u.zToken;
98563 pLeft = pRight->pLeft;
98564 pRight = pRight->pRight;
98565 }
98566 zTable = pLeft->u.zToken;
98567 zColumn = pRight->u.zToken;
98568 if( IN_RENAME_OBJECT ){
98569 sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
98570 sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
98571 }
98572 }
98573 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
98574 }
98575
98576 /* Resolve function names
98577 */
98578 case TK_FUNCTION: {
98579 ExprList *pList = pExpr->x.pList; /* The argument list */
98580 int n = pList ? pList->nExpr : 0; /* Number of arguments */
98581 int no_such_func = 0; /* True if no such function exists */
98582 int wrong_num_args = 0; /* True if wrong number of arguments */
98583 int is_agg = 0; /* True if is an aggregate function */
98584 int nId; /* Number of characters in function name */
98585 const char *zId; /* The function name. */
98586 FuncDef *pDef; /* Information about the function */
98587 u8 enc = ENC(pParse->db); /* The database encoding */
98588 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
98589#ifndef SQLITE_OMIT_WINDOWFUNC
98590 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
98591#endif
98592 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
98593 zId = pExpr->u.zToken;
98594 nId = sqlite3Strlen30(zId);
98595 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
98596 if( pDef==0 ){
98597 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
98598 if( pDef==0 ){
98599 no_such_func = 1;
98600 }else{
98601 wrong_num_args = 1;
98602 }
98603 }else{
98604 is_agg = pDef->xFinalize!=0;
98605 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
98607 if( n==2 ){
98608 pExpr->iTable = exprProbability(pList->a[1].pExpr);
98609 if( pExpr->iTable<0 ){
98610 sqlite3ErrorMsg(pParse,
98611 "second argument to likelihood() must be a "
98612 "constant between 0.0 and 1.0");
98613 pNC->nErr++;
98614 }
98615 }else{
98616 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
98617 ** equivalent to likelihood(X, 0.0625).
98618 ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
98619 ** short-hand for likelihood(X,0.0625).
98620 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand
98621 ** for likelihood(X,0.9375).
98622 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent
98623 ** to likelihood(X,0.9375). */
98624 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
98625 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
98626 }
98627 }
98628#ifndef SQLITE_OMIT_AUTHORIZATION
98629 {
98630 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
98631 if( auth!=SQLITE_OK ){
98632 if( auth==SQLITE_DENY ){
98633 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
98634 pDef->zName);
98635 pNC->nErr++;
98636 }
98637 pExpr->op = TK_NULL;
98638 return WRC_Prune;
98639 }
98640 }
98641#endif
98643 /* For the purposes of the EP_ConstFunc flag, date and time
98644 ** functions and other functions that change slowly are considered
98645 ** constant because they are constant for the duration of one query.
98646 ** This allows them to be factored out of inner loops. */
98648 }
98649 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
98650 /* Clearly non-deterministic functions like random(), but also
98651 ** date/time functions that use 'now', and other functions like
98652 ** sqlite_version() that might change over time cannot be used
98653 ** in an index or generated column. Curiously, they can be used
98654 ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
98655 ** all this. */
98656 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
98658 }else{
98659 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
98660 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
98661 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
98662 }
98663 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
98664 && pParse->nested==0
98665 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
98666 ){
98667 /* Internal-use-only functions are disallowed unless the
98668 ** SQL is being compiled using sqlite3NestedParse() or
98669 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
98670 ** used to activate internal functionsn for testing purposes */
98671 no_such_func = 1;
98672 pDef = 0;
98673 }else
98676 ){
98677 sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
98678 }
98679 }
98680
98681 if( 0==IN_RENAME_OBJECT ){
98682#ifndef SQLITE_OMIT_WINDOWFUNC
98683 assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
98684 || (pDef->xValue==0 && pDef->xInverse==0)
98685 || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
98686 );
98687 if( pDef && pDef->xValue==0 && pWin ){
98688 sqlite3ErrorMsg(pParse,
98689 "%.*s() may not be used as a window function", nId, zId
98690 );
98691 pNC->nErr++;
98692 }else if(
98693 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
98694 || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
98695 || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
98696 ){
98697 const char *zType;
98698 if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){
98699 zType = "window";
98700 }else{
98701 zType = "aggregate";
98702 }
98703 sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
98704 pNC->nErr++;
98705 is_agg = 0;
98706 }
98707#else
98708 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
98709 sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
98710 pNC->nErr++;
98711 is_agg = 0;
98712 }
98713#endif
98714 else if( no_such_func && pParse->db->init.busy==0
98715#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
98716 && pParse->explain==0
98717#endif
98718 ){
98719 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
98720 pNC->nErr++;
98721 }else if( wrong_num_args ){
98722 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
98723 nId, zId);
98724 pNC->nErr++;
98725 }
98726#ifndef SQLITE_OMIT_WINDOWFUNC
98727 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
98728 sqlite3ErrorMsg(pParse,
98729 "FILTER may not be used with non-aggregate %.*s()",
98730 nId, zId
98731 );
98732 pNC->nErr++;
98733 }
98734#endif
98735 if( is_agg ){
98736 /* Window functions may not be arguments of aggregate functions.
98737 ** Or arguments of other window functions. But aggregate functions
98738 ** may be arguments for window functions. */
98739#ifndef SQLITE_OMIT_WINDOWFUNC
98740 pNC->ncFlags &= ~(NC_AllowWin | (!pWin ? NC_AllowAgg : 0));
98741#else
98742 pNC->ncFlags &= ~NC_AllowAgg;
98743#endif
98744 }
98745 }
98746#ifndef SQLITE_OMIT_WINDOWFUNC
98747 else if( ExprHasProperty(pExpr, EP_WinFunc) ){
98748 is_agg = 1;
98749 }
98750#endif
98751 sqlite3WalkExprList(pWalker, pList);
98752 if( is_agg ){
98753#ifndef SQLITE_OMIT_WINDOWFUNC
98754 if( pWin ){
98755 Select *pSel = pNC->pWinSelect;
98756 assert( pWin==pExpr->y.pWin );
98757 if( IN_RENAME_OBJECT==0 ){
98758 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
98759 }
98760 sqlite3WalkExprList(pWalker, pWin->pPartition);
98761 sqlite3WalkExprList(pWalker, pWin->pOrderBy);
98762 sqlite3WalkExpr(pWalker, pWin->pFilter);
98763 sqlite3WindowLink(pSel, pWin);
98764 pNC->ncFlags |= NC_HasWin;
98765 }else
98766#endif /* SQLITE_OMIT_WINDOWFUNC */
98767 {
98768 NameContext *pNC2 = pNC;
98769 pExpr->op = TK_AGG_FUNCTION;
98770 pExpr->op2 = 0;
98771#ifndef SQLITE_OMIT_WINDOWFUNC
98772 if( ExprHasProperty(pExpr, EP_WinFunc) ){
98773 sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
98774 }
98775#endif
98776 while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
98777 pExpr->op2++;
98778 pNC2 = pNC2->pNext;
98779 }
98780 assert( pDef!=0 || IN_RENAME_OBJECT );
98781 if( pNC2 && pDef ){
98783 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
98784 pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);
98785
98786 }
98787 }
98788 pNC->ncFlags |= savedAllowFlags;
98789 }
98790 /* FIX ME: Compute pExpr->affinity based on the expected return
98791 ** type of the function
98792 */
98793 return WRC_Prune;
98794 }
98795#ifndef SQLITE_OMIT_SUBQUERY
98796 case TK_SELECT:
98797 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
98798#endif
98799 case TK_IN: {
98800 testcase( pExpr->op==TK_IN );
98801 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
98802 int nRef = pNC->nRef;
98803 testcase( pNC->ncFlags & NC_IsCheck );
98804 testcase( pNC->ncFlags & NC_PartIdx );
98805 testcase( pNC->ncFlags & NC_IdxExpr );
98806 testcase( pNC->ncFlags & NC_GenCol );
98807 sqlite3ResolveNotValid(pParse, pNC, "subqueries",
98809 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
98810 assert( pNC->nRef>=nRef );
98811 if( nRef!=pNC->nRef ){
98813 pNC->ncFlags |= NC_VarSelect;
98814 }
98815 }
98816 break;
98817 }
98818 case TK_VARIABLE: {
98819 testcase( pNC->ncFlags & NC_IsCheck );
98820 testcase( pNC->ncFlags & NC_PartIdx );
98821 testcase( pNC->ncFlags & NC_IdxExpr );
98822 testcase( pNC->ncFlags & NC_GenCol );
98823 sqlite3ResolveNotValid(pParse, pNC, "parameters",
98825 break;
98826 }
98827 case TK_IS:
98828 case TK_ISNOT: {
98830 assert( !ExprHasProperty(pExpr, EP_Reduced) );
98831 /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
98832 ** and "x IS NOT FALSE". */
98833 if( pRight && pRight->op==TK_ID ){
98834 int rc = resolveExprStep(pWalker, pRight);
98835 if( rc==WRC_Abort ) return WRC_Abort;
98836 if( pRight->op==TK_TRUEFALSE ){
98837 pExpr->op2 = pExpr->op;
98838 pExpr->op = TK_TRUTH;
98839 return WRC_Continue;
98840 }
98841 }
98842 /* no break */ deliberate_fall_through
98843 }
98844 case TK_BETWEEN:
98845 case TK_EQ:
98846 case TK_NE:
98847 case TK_LT:
98848 case TK_LE:
98849 case TK_GT:
98850 case TK_GE: {
98851 int nLeft, nRight;
98852 if( pParse->db->mallocFailed ) break;
98853 assert( pExpr->pLeft!=0 );
98854 nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
98855 if( pExpr->op==TK_BETWEEN ){
98856 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
98857 if( nRight==nLeft ){
98858 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
98859 }
98860 }else{
98861 assert( pExpr->pRight!=0 );
98862 nRight = sqlite3ExprVectorSize(pExpr->pRight);
98863 }
98864 if( nLeft!=nRight ){
98865 testcase( pExpr->op==TK_EQ );
98866 testcase( pExpr->op==TK_NE );
98867 testcase( pExpr->op==TK_LT );
98868 testcase( pExpr->op==TK_LE );
98869 testcase( pExpr->op==TK_GT );
98870 testcase( pExpr->op==TK_GE );
98871 testcase( pExpr->op==TK_IS );
98872 testcase( pExpr->op==TK_ISNOT );
98873 testcase( pExpr->op==TK_BETWEEN );
98874 sqlite3ErrorMsg(pParse, "row value misused");
static int resolveExprStep(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:98488
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *, SrcList *)
Definition sqlite3.c:105424
#define sqlite3ResolveNotValid(P, N, M, X, E)
Definition sqlite3.c:98459
#define SQLITE_FUNCTION
Definition sqlite3.c:4150
#define NC_SelfRef
Definition sqlite3.c:18379
#define NC_MinMaxAgg
Definition sqlite3.c:18384
SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse *, Expr *, FuncDef *)
Definition sqlite3.c:100703
#define EP_Unlikely
Definition sqlite3.c:18078
static int lookupName(Parse *pParse, const char *zDb, const char *zTab, const char *zCol, NameContext *pNC, Expr *pExpr)
Definition sqlite3.c:97986
#define TK_ROW
Definition sqlite3.c:14017
#define SQLITE_FUNC_DIRECT
Definition sqlite3.c:17162
#define TK_TRUEFALSE
Definition sqlite3.c:14109
SQLITE_PRIVATE void sqlite3WindowUpdate(Parse *, Window *, Window *, FuncDef *)
Definition sqlite3.c:151818
#define NC_HasAgg
Definition sqlite3.c:18377
SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin)
Definition sqlite3.c:152465
#define NC_HasWin
Definition sqlite3.c:18387
#define SQLITE_FUNC_UNLIKELY
Definition sqlite3.c:17154
#define SQLITE_FUNC_MINMAX
Definition sqlite3.c:17156
#define NC_FromDDL
Definition sqlite3.c:18390
static int exprProbability(Expr *p)
Definition sqlite3.c:98468
#define NC_VarSelect
Definition sqlite3.c:18380
void(* xInverse)(sqlite3_context *, int, sqlite3_value **)
Definition sqlite3.c:17102
Select * pWinSelect
Definition sqlite3.c:18361
u8 nested
Definition sqlite3.c:18686
u32 nAlloc
Definition sqlite3.c:18251
ExprList * pPartition
Definition sqlite3.c:19193
Expr * pFilter
Definition sqlite3.c:19204
ExprList * pOrderBy
Definition sqlite3.c:19194

References ExprList::a, SrcList::a, Expr::affExpr, sqlite3::sqlite3InitInfo::busy, Parse::db, DBFLAG_InternalFunc, deliberate_fall_through, ENC, EP_ConstFunc, EP_FromDDL, EP_Reduced, EP_Unlikely, EP_VarSelect, EP_WinFunc, EP_xIsSelect, Parse::explain, ExprHasProperty, exprProbability(), ExprSetProperty, FuncDef::funcFlags, Expr::iColumn, SrcList::SrcList_item::iCursor, IN_RENAME_OBJECT, sqlite3::init, IsWindowFunc, Expr::iTable, lookupName(), sqlite3::mallocFailed, sqlite3::mDbFlags, SrcList::nAlloc, NC_AllowAgg, NC_AllowWin, NC_FromDDL, NC_GenCol, NC_HasAgg, NC_HasWin, NC_IdxExpr, NC_IsCheck, NC_MinMaxAgg, NC_PartIdx, NC_SelfRef, NC_VarSelect, NameContext::ncFlags, NameContext::nErr, Parse::nErr, Parse::nested, ExprList::nExpr, NameContext::nRef, SrcList::nSrc, Parse::nTab, Expr::op, Expr::op2, ExprList::ExprList_item::pExpr, Window::pFilter, Expr::pLeft, Expr::pList, Walker::pNC, NameContext::pNext, Window::pOrderBy, NameContext::pParse, Walker::pParse, Window::pPartition, Expr::pRight, Expr::pSelect, NameContext::pSrcList, Expr::pTab, Expr::pWin, Select::pWinDefn, NameContext::pWinSelect, resolveExprStep(), sqlite3AuthCheck(), sqlite3ErrorMsg(), sqlite3ExprFunctionUsable(), sqlite3ExprSkipCollateAndLikely(), sqlite3ExprVectorSize(), sqlite3FindFunction(), sqlite3FunctionUsesThisSrc(), sqlite3RenameTokenRemap(), sqlite3ResolveNotValid, sqlite3Strlen30(), sqlite3WalkExpr(), sqlite3WalkExprList(), sqlite3WalkSelect(), sqlite3WindowLink(), sqlite3WindowUpdate(), SQLITE_AFF_INTEGER, SQLITE_DENY, SQLITE_FUNC_CONSTANT, SQLITE_FUNC_DIRECT, SQLITE_FUNC_INTERNAL, SQLITE_FUNC_MINMAX, SQLITE_FUNC_SLOCHNG, SQLITE_FUNC_UNLIKELY, SQLITE_FUNC_UNSAFE, SQLITE_FUNC_WINDOW, SQLITE_FUNCTION, SQLITE_OK, testcase, TK_AGG_FUNCTION, TK_BETWEEN, TK_COLUMN, TK_DOT, TK_EQ, TK_EXISTS, TK_FUNCTION, TK_GE, TK_GT, TK_ID, TK_IN, TK_IS, TK_ISNOT, TK_LE, TK_LT, TK_NE, TK_NULL, TK_ROW, TK_SELECT, TK_TRUEFALSE, TK_TRUTH, TK_VARIABLE, Expr::u, Walker::u, WRC_Abort, WRC_Continue, WRC_Prune, Expr::x, FuncDef::xFinalize, FuncDef::xInverse, FuncDef::xSFunc, FuncDef::xValue, Expr::y, FuncDef::zName, and Expr::zToken.

Referenced by resolveExprStep(), sqlite3ResolveExprListNames(), sqlite3ResolveExprNames(), and sqlite3ResolveSelectNames().

◆ resolveOrderByTermToExprList()

static int resolveOrderByTermToExprList ( Parse * pParse,
Select * pSelect,
Expr * pE )
static

Definition at line 98928 of file sqlite3.c.

98938 {
98939 int i; /* Loop counter */
98940 ExprList *pEList; /* The columns of the result set */
98941 NameContext nc; /* Name context for resolving pE */
98942 sqlite3 *db; /* Database connection */
98943 int rc; /* Return code from subprocedures */
98944 u8 savedSuppErr; /* Saved value of db->suppressErr */
98945
98946 assert( sqlite3ExprIsInteger(pE, &i)==0 );
98947 pEList = pSelect->pEList;
98948
98949 /* Resolve all names in the ORDER BY term expression
98950 */
98951 memset(&nc, 0, sizeof(nc));
98952 nc.pParse = pParse;
98953 nc.pSrcList = pSelect->pSrc;
98954 nc.uNC.pEList = pEList;
98956 nc.nErr = 0;
98957 db = pParse->db;
98958 savedSuppErr = db->suppressErr;
98959 if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
98960 rc = sqlite3ResolveExprNames(&nc, pE);
98961 db->suppressErr = savedSuppErr;
98962 if( rc ) return 0;
98963
98964 /* Try to match the ORDER BY expression against an expression
98965 ** in the result set. Return an 1-based index of the matching
98966 ** result-set entry.
98967 */
98968 for(i=0; i<pEList->nExpr; i++){
98969 if( sqlite3ExprCompare(0, pEList->a[i].pExpr, pE, -1)<2 ){
98970 return i+1;
u8 suppressErr
Definition sqlite3.c:16843

References ExprList::a, Parse::db, IN_RENAME_OBJECT, NC_AllowAgg, NC_UEList, NameContext::ncFlags, NameContext::nErr, ExprList::nExpr, NameContext::pEList, Select::pEList, ExprList::ExprList_item::pExpr, NameContext::pParse, Select::pSrc, NameContext::pSrcList, sqlite3ExprCompare(), sqlite3ExprIsInteger(), sqlite3ResolveExprNames(), sqlite3::suppressErr, and NameContext::uNC.

Referenced by resolveCompoundOrderBy().

◆ resolveOrderGroupBy()

static int resolveOrderGroupBy ( NameContext * pNC,
Select * pSelect,
ExprList * pOrderBy,
const char * zType )
static

Definition at line 99197 of file sqlite3.c.

99208 {
99209 int i, j; /* Loop counters */
99210 int iCol; /* Column number */
99211 struct ExprList_item *pItem; /* A term of the ORDER BY clause */
99212 Parse *pParse; /* Parsing context */
99213 int nResult; /* Number of terms in the result set */
99214
99215 if( pOrderBy==0 ) return 0;
99216 nResult = pSelect->pEList->nExpr;
99217 pParse = pNC->pParse;
99218 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99219 Expr *pE = pItem->pExpr;
99221 if( zType[0]!='G' ){
99222 iCol = resolveAsName(pParse, pSelect->pEList, pE2);
99223 if( iCol>0 ){
99224 /* If an AS-name match is found, mark this ORDER BY column as being
99225 ** a copy of the iCol-th result-set column. The subsequent call to
99226 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
99227 ** copy of the iCol-th result-set expression. */
99228 pItem->u.x.iOrderByCol = (u16)iCol;
99229 continue;
99230 }
99231 }
99232 if( sqlite3ExprIsInteger(pE2, &iCol) ){
99233 /* The ORDER BY term is an integer constant. Again, set the column
99234 ** number so that sqlite3ResolveOrderGroupBy() will convert the
99235 ** order-by term to a copy of the result-set expression */
99236 if( iCol<1 || iCol>0xffff ){
99237 resolveOutOfRangeError(pParse, zType, i+1, nResult);
99238 return 1;
99239 }
99240 pItem->u.x.iOrderByCol = (u16)iCol;
99241 continue;
99242 }
99243
99244 /* Otherwise, treat the ORDER BY term as an ordinary expression */
99245 pItem->u.x.iOrderByCol = 0;
99246 if( sqlite3ResolveExprNames(pNC, pE) ){
99247 return 1;
99248 }
99249 for(j=0; j<pSelect->pEList->nExpr; j++){
99250 if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
99251 /* Since this expresion is being changed into a reference
99252 ** to an identical expression in the result set, remove all Window
99253 ** objects belonging to the expression from the Select.pWin list. */
99254 windowRemoveExprFromSelect(pSelect, pE);
static void windowRemoveExprFromSelect(Select *pSelect, Expr *pExpr)
Definition sqlite3.c:99166

References ExprList::a, ExprList::nExpr, Select::pEList, ExprList::ExprList_item::pExpr, NameContext::pParse, resolveAsName(), resolveOutOfRangeError(), sqlite3ExprCompare(), sqlite3ExprIsInteger(), sqlite3ExprSkipCollateAndLikely(), sqlite3ResolveExprNames(), and windowRemoveExprFromSelect().

◆ resolveOutOfRangeError()

static void resolveOutOfRangeError ( Parse * pParse,
const char * zType,
int i,
int mx )
static

◆ resolveP2Values()

static void resolveP2Values ( Vdbe * p,
int * pMaxFuncArgs )
static

Definition at line 78521 of file sqlite3.c.

78527 {
78528 int nMaxArgs = *pMaxFuncArgs;
78529 Op *pOp;
78530 Parse *pParse = p->pParse;
78531 int *aLabel = pParse->aLabel;
78532 p->readOnly = 1;
78533 p->bIsReader = 0;
78534 pOp = &p->aOp[p->nOp-1];
78535 while(1){
78536
78537 /* Only JUMP opcodes and the short list of special opcodes in the switch
78538 ** below need to be considered. The mkopcodeh.tcl generator script groups
78539 ** all these opcodes together near the front of the opcode list. Skip
78540 ** any opcode that does not need processing by virtual of the fact that
78541 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
78542 */
78543 if( pOp->opcode<=SQLITE_MX_JUMP_OPCODE ){
78544 /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
78545 ** cases from this switch! */
78546 switch( pOp->opcode ){
78547 case OP_Transaction: {
78548 if( pOp->p2!=0 ) p->readOnly = 0;
78549 /* no break */ deliberate_fall_through
78550 }
78551 case OP_AutoCommit:
78552 case OP_Savepoint: {
78553 p->bIsReader = 1;
78554 break;
78555 }
78556#ifndef SQLITE_OMIT_WAL
78557 case OP_Checkpoint:
78558#endif
78559 case OP_Vacuum:
78560 case OP_JournalMode: {
78561 p->readOnly = 0;
78562 p->bIsReader = 1;
78563 break;
78564 }
78565 case OP_Next:
78566 case OP_SorterNext: {
78568 pOp->p4type = P4_ADVANCE;
78569 /* The code generator never codes any of these opcodes as a jump
78570 ** to a label. They are always coded as a jump backwards to a
78571 ** known address */
78572 assert( pOp->p2>=0 );
78573 break;
78574 }
78575 case OP_Prev: {
78577 pOp->p4type = P4_ADVANCE;
78578 /* The code generator never codes any of these opcodes as a jump
78579 ** to a label. They are always coded as a jump backwards to a
78580 ** known address */
78581 assert( pOp->p2>=0 );
78582 break;
78583 }
78584#ifndef SQLITE_OMIT_VIRTUALTABLE
78585 case OP_VUpdate: {
78586 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
78587 break;
78588 }
78589 case OP_VFilter: {
78590 int n;
78591 assert( (pOp - p->aOp) >= 3 );
78592 assert( pOp[-1].opcode==OP_Integer );
78593 n = pOp[-1].p1;
78594 if( n>nMaxArgs ) nMaxArgs = n;
78595 /* Fall through into the default case */
78596 /* no break */ deliberate_fall_through
78597 }
78598#endif
78599 default: {
78600 if( pOp->p2<0 ){
78601 /* The mkopcodeh.tcl script has so arranged things that the only
78602 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
78603 ** have non-negative values for P2. */
78604 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
78605 assert( ADDR(pOp->p2)<-pParse->nLabel );
78606 pOp->p2 = aLabel[ADDR(pOp->p2)];
78607 }
78608 break;
78609 }
78610 }
78611 /* The mkopcodeh.tcl script has so arranged things that the only
78612 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
78613 ** have non-negative values for P2. */
78614 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
78615 }
78616 if( pOp==p->aOp ) break;
78617 pOp--;
78618 }
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]
Definition sqlite3.c:20678
#define OP_Transaction
Definition sqlite3.c:15568
#define ADDR(X)
Definition sqlite3.c:15556
#define OP_AutoCommit
Definition sqlite3.c:15567
#define OPFLG_JUMP
Definition sqlite3.c:15747
#define OP_Vacuum
Definition sqlite3.c:15574
#define OP_VFilter
Definition sqlite3.c:15575
#define OP_Checkpoint
Definition sqlite3.c:15572
#define SQLITE_MX_JUMP_OPCODE
Definition sqlite3.c:15784
#define OP_JournalMode
Definition sqlite3.c:15573
#define OP_VUpdate
Definition sqlite3.c:15576
#define P4_ADVANCE
Definition sqlite3.c:15510
#define OP_Savepoint
Definition sqlite3.c:15566
int nOp
Definition sqlite3.c:21109
bft readOnly
Definition sqlite3.c:21132
bft bIsReader
Definition sqlite3.c:21133
int(* xAdvance)(BtCursor *, int)
Definition sqlite3.c:15459

References ADDR, Parse::aLabel, Vdbe::aOp, Vdbe::bIsReader, Vdbe::db, deliberate_fall_through, Parse::nLabel, Vdbe::nOp, OP_AutoCommit, OP_Checkpoint, OP_Integer, OP_JournalMode, OP_Next, OP_Prev, OP_Savepoint, OP_SorterNext, OP_Transaction, OP_Vacuum, OP_VFilter, OP_VUpdate, VdbeOp::opcode, OPFLG_JUMP, VdbeOp::p1, VdbeOp::p2, VdbeOp::p4, P4_ADVANCE, VdbeOp::p4type, Vdbe::pParse, Vdbe::readOnly, sqlite3BtreeNext(), sqlite3BtreePrevious(), sqlite3DbFree(), sqlite3OpcodeProperty, SQLITE_MX_JUMP_OPCODE, and VdbeOp::p4union::xAdvance.

Referenced by sqlite3VdbeMakeReady(), and sqlite3VdbeTakeOpArray().

◆ resolveRemoveWindowsCb()

static int resolveRemoveWindowsCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 99153 of file sqlite3.c.

99159 {
99160 UNUSED_PARAMETER(pWalker);

◆ resolveSelectStep()

static int resolveSelectStep ( Walker * pWalker,
Select * p )
static

Definition at line 99259 of file sqlite3.c.

99265 {
99266 NameContext *pOuterNC; /* Context that contains this SELECT */
99267 NameContext sNC; /* Name context of this SELECT */
99268 int isCompound; /* True if p is a compound select */
99269 int nCompound; /* Number of compound terms processed so far */
99270 Parse *pParse; /* Parsing context */
99271 int i; /* Loop counter */
99272 ExprList *pGroupBy; /* The GROUP BY clause */
99273 Select *pLeftmost; /* Left-most of SELECT of a compound */
99274 sqlite3 *db; /* Database connection */
99275
99276
99277 assert( p!=0 );
99278 if( p->selFlags & SF_Resolved ){
99279 return WRC_Prune;
99280 }
99281 pOuterNC = pWalker->u.pNC;
99282 pParse = pWalker->pParse;
99283 db = pParse->db;
99284
99285 /* Normally sqlite3SelectExpand() will be called first and will have
99286 ** already expanded this SELECT. However, if this is a subquery within
99287 ** an expression, sqlite3ResolveExprNames() will be called without a
99288 ** prior call to sqlite3SelectExpand(). When that happens, let
99289 ** sqlite3SelectPrep() do all of the processing for this SELECT.
99290 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
99291 ** this routine in the correct order.
99292 */
99293 if( (p->selFlags & SF_Expanded)==0 ){
99294 sqlite3SelectPrep(pParse, p, pOuterNC);
99295 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
99296 }
99297
99298 isCompound = p->pPrior!=0;
99299 nCompound = 0;
99300 pLeftmost = p;
99301 while( p ){
99302 assert( (p->selFlags & SF_Expanded)!=0 );
99303 assert( (p->selFlags & SF_Resolved)==0 );
99304 p->selFlags |= SF_Resolved;
99305
99306 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
99307 ** are not allowed to refer to any names, so pass an empty NameContext.
99308 */
99309 memset(&sNC, 0, sizeof(sNC));
99310 sNC.pParse = pParse;
99311 sNC.pWinSelect = p;
99312 if( sqlite3ResolveExprNames(&sNC, p->pLimit) ){
99313 return WRC_Abort;
99314 }
99315
99316 /* If the SF_Converted flags is set, then this Select object was
99317 ** was created by the convertCompoundSelectToSubquery() function.
99318 ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
99319 ** as if it were part of the sub-query, not the parent. This block
99320 ** moves the pOrderBy down to the sub-query. It will be moved back
99321 ** after the names have been resolved. */
99322 if( p->selFlags & SF_Converted ){
99323 Select *pSub = p->pSrc->a[0].pSelect;
99324 assert( p->pSrc->nSrc==1 && p->pOrderBy );
99325 assert( pSub->pPrior && pSub->pOrderBy==0 );
99326 pSub->pOrderBy = p->pOrderBy;
99327 p->pOrderBy = 0;
99328 }
99329
99330 /* Recursively resolve names in all subqueries
99331 */
99332 for(i=0; i<p->pSrc->nSrc; i++){
99333 struct SrcList_item *pItem = &p->pSrc->a[i];
99334 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
99335 NameContext *pNC; /* Used to iterate name contexts */
99336 int nRef = 0; /* Refcount for pOuterNC and outer contexts */
99337 const char *zSavedContext = pParse->zAuthContext;
99338
99339 /* Count the total number of references to pOuterNC and all of its
99340 ** parent contexts. After resolving references to expressions in
99341 ** pItem->pSelect, check if this value has changed. If so, then
99342 ** SELECT statement pItem->pSelect must be correlated. Set the
99343 ** pItem->fg.isCorrelated flag if this is the case. */
99344 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;
99345
99346 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
99347 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
99348 pParse->zAuthContext = zSavedContext;
99349 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
99350
99351 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
99352 assert( pItem->fg.isCorrelated==0 && nRef<=0 );
99353 pItem->fg.isCorrelated = (nRef!=0);
99354 }
99355 }
99356
99357 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
99358 ** resolve the result-set expression list.
99359 */
99361 sNC.pSrcList = p->pSrc;
99362 sNC.pNext = pOuterNC;
99363
99364 /* Resolve names in the result set. */
99365 if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
99366 sNC.ncFlags &= ~NC_AllowWin;
99367
99368 /* If there are no aggregate functions in the result-set, and no GROUP BY
99369 ** expression, do not allow aggregates in any of the other expressions.
99370 */
99371 assert( (p->selFlags & SF_Aggregate)==0 );
99372 pGroupBy = p->pGroupBy;
99373 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
99374 assert( NC_MinMaxAgg==SF_MinMaxAgg );
99376 }else{
99377 sNC.ncFlags &= ~NC_AllowAgg;
99378 }
99379
99380 /* If a HAVING clause is present, then there must be a GROUP BY clause.
99381 */
99382 if( p->pHaving && !pGroupBy ){
99383 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
99384 return WRC_Abort;
99385 }
99386
99387 /* Add the output column list to the name-context before parsing the
99388 ** other expressions in the SELECT statement. This is so that
99389 ** expressions in the WHERE clause (etc.) can refer to expressions by
99390 ** aliases in the result set.
99391 **
99392 ** Minor point: If this is the case, then the expression will be
99393 ** re-evaluated for each reference to it.
99394 */
99395 assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert))==0 );
99396 sNC.uNC.pEList = p->pEList;
99397 sNC.ncFlags |= NC_UEList;
99398 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
99399 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
99400
99401 /* Resolve names in table-valued-function arguments */
99402 for(i=0; i<p->pSrc->nSrc; i++){
99403 struct SrcList_item *pItem = &p->pSrc->a[i];
99404 if( pItem->fg.isTabFunc
99405 && sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg)
99406 ){
99407 return WRC_Abort;
99408 }
99409 }
99410
99411 /* The ORDER BY and GROUP BY clauses may not refer to terms in
99412 ** outer queries
99413 */
99414 sNC.pNext = 0;
99416
99417 /* If this is a converted compound query, move the ORDER BY clause from
99418 ** the sub-query back to the parent query. At this point each term
99419 ** within the ORDER BY clause has been transformed to an integer value.
99420 ** These integers will be replaced by copies of the corresponding result
99421 ** set expressions by the call to resolveOrderGroupBy() below. */
99422 if( p->selFlags & SF_Converted ){
99423 Select *pSub = p->pSrc->a[0].pSelect;
99424 p->pOrderBy = pSub->pOrderBy;
99425 pSub->pOrderBy = 0;
99426 }
99427
99428 /* Process the ORDER BY clause for singleton SELECT statements.
99429 ** The ORDER BY clause for compounds SELECT statements is handled
99430 ** below, after all of the result-sets for all of the elements of
99431 ** the compound have been resolved.
99432 **
99433 ** If there is an ORDER BY clause on a term of a compound-select other
99434 ** than the right-most term, then that is a syntax error. But the error
99435 ** is not detected until much later, and so we need to go ahead and
99436 ** resolve those symbols on the incorrect ORDER BY for consistency.
99437 */
99438 if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
99439 && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
99440 ){
99441 return WRC_Abort;
99442 }
99443 if( db->mallocFailed ){
99444 return WRC_Abort;
99445 }
99446 sNC.ncFlags &= ~NC_AllowWin;
99447
99448 /* Resolve the GROUP BY clause. At the same time, make sure
99449 ** the GROUP BY clause does not contain aggregate functions.
99450 */
99451 if( pGroupBy ){
99452 struct ExprList_item *pItem;
99453
99454 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
99455 return WRC_Abort;
99456 }
99457 for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){
99458 if( ExprHasProperty(pItem->pExpr, EP_Agg) ){
99459 sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
99460 "the GROUP BY clause");
99461 return WRC_Abort;
99462 }
99463 }
99464 }
99465
99466#ifndef SQLITE_OMIT_WINDOWFUNC
99467 if( IN_RENAME_OBJECT ){
99468 Window *pWin;
99469 for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
99470 if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
99472 ){
99473 return WRC_Abort;
99474 }
99475 }
99476 }
99477#endif
99478
99479 /* If this is part of a compound SELECT, check that it has the right
99480 ** number of expressions in the select list. */
99481 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
99483 return WRC_Abort;
99484 }
99485
99486 /* Advance to the next term of the compound
99487 */
99488 p = p->pPrior;
99489 nCompound++;
99490 }
99491
99492 /* Resolve the ORDER BY on a compound SELECT after all terms of
99493 ** the compound have been resolved.
99494 */
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse *, Select *, NameContext *)
Definition sqlite3.c:99638
#define SF_Resolved
Definition sqlite3.c:18473
static int resolveOrderGroupBy(NameContext *pNC, Select *pSelect, ExprList *pOrderBy, const char *zType)
Definition sqlite3.c:99197
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p)
Definition sqlite3.c:132200
#define SF_Expanded
Definition sqlite3.c:18477
#define SF_MinMaxAgg
Definition sqlite3.c:18483
Window * pNextWin
Definition sqlite3.c:19203

Referenced by sqlite3ResolveExprListNames(), sqlite3ResolveExprNames(), and sqlite3ResolveSelectNames().

◆ returnSingleInt()

static void returnSingleInt ( Vdbe * v,
i64 value )
static

Definition at line 125926 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ returnSingleText()

static void returnSingleText ( Vdbe * v,
const char * zValue )
static

Definition at line 125934 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ robust_close()

static void robust_close ( unixFile * pFile,
int h,
int lineno )
static

◆ robust_ftruncate()

static int robust_ftruncate ( int h,
sqlite3_int64 sz )
static

Definition at line 34379 of file sqlite3.c.

34385 {
34386 int rc;
34387#ifdef __ANDROID__
34388 /* On Android, ftruncate() always uses 32-bit offsets, even if
34389 ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to
34390 ** truncate a file to any size larger than 2GiB. Silently ignore any
34391 ** such attempts. */
34392 if( sz>(sqlite3_int64)0x7FFFFFFF ){

References osFtruncate, and SQLITE_OK.

Referenced by fcntlSizeHint(), and unixLockSharedMemory().

◆ robust_open()

static int robust_open ( const char * z,
int f,
mode_t m )
static

Definition at line 34216 of file sqlite3.c.

34222 {
34223 int fd;
34224 mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
34225 while(1){
34226#if defined(O_CLOEXEC)
34227 fd = osOpen(z,f|O_CLOEXEC,m2);
34228#else
34229 fd = osOpen(z,f,m2);
34230#endif
34231 if( fd<0 ){
34232 if( errno==EINTR ) continue;
34233 break;
34234 }
34235 if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break;
34236 osClose(fd);
34238 "attempt to open \"%s\" as file descriptor %d", z, fd);
34239 fd = -1;
34240 if( osOpen("/dev/null", O_RDONLY, m)<0 ) break;
34241 }
34242 if( fd>=0 ){
34243 if( m!=0 ){
34244 struct stat statbuf;
34245 if( osFstat(fd, &statbuf)==0
34246 && statbuf.st_size==0
34247 && (statbuf.st_mode&0777)!=m
34248 ){
34249 osFchmod(fd, m);
34250 }
34251 }
#define SQLITE_DEFAULT_FILE_PERMISSIONS
Definition sqlite3.c:33509
#define osFchmod
#define SQLITE_MINIMUM_FILE_DESCRIPTOR
Definition sqlite3.c:34196
#define osClose
#define osOpen

References osClose, osFchmod, osFcntl, osFstat, osOpen, sqlite3_log(), SQLITE_DEFAULT_FILE_PERMISSIONS, SQLITE_MINIMUM_FILE_DESCRIPTOR, and SQLITE_WARNING.

Referenced by openDirectory(), unixOpen(), unixOpenSharedMemory(), and unixRandomness().

◆ robustFchown()

static int robustFchown ( int fd,
uid_t uid,
gid_t gid )
static

Definition at line 34099 of file sqlite3.c.

34105 {

References osFchown, and osGeteuid.

Referenced by unixOpen(), and unixOpenSharedMemory().

◆ roundFunc()

static void roundFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117438 of file sqlite3.c.

117444 {
117445 int n = 0;
117446 double r;
117447 char *zBuf;
117448 assert( argc==1 || argc==2 );
117449 if( argc==2 ){
117450 if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
117451 n = sqlite3_value_int(argv[1]);
117452 if( n>30 ) n = 30;
117453 if( n<0 ) n = 0;
117454 }
117455 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
117456 r = sqlite3_value_double(argv[0]);
117457 /* If Y==0 and X will fit in a 64-bit int,
117458 ** handle the rounding directly,
117459 ** otherwise use printf.
117460 */
117461 if( r<-4503599627370496.0 || r>+4503599627370496.0 ){
117462 /* The value has no fractional part so there is nothing to round */
117463 }else if( n==0 ){
117464 r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
117465 }else{
117466 zBuf = sqlite3_mprintf("%.*f",n,r);
117467 if( zBuf==0 ){
117469 return;

Referenced by sqlite3RegisterBuiltinFunctions().

◆ row_numberStepFunc()

static void row_numberStepFunc ( sqlite3_context * pCtx,
int nArg,
sqlite3_value ** apArg )
static

Definition at line 151306 of file sqlite3.c.

◆ row_numberValueFunc()

static void row_numberValueFunc ( sqlite3_context * pCtx)
static

Definition at line 151316 of file sqlite3.c.

151316 {
151317 i64 *p = (i64*)sqlite3_aggregate_context(pCtx, sizeof(*p));
151318 if( p ) (*p)++;
151319 UNUSED_PARAMETER(nArg);

References sqlite3_aggregate_context(), and UNUSED_PARAMETER.

◆ rowSetEntryAlloc()

static struct RowSetEntry * rowSetEntryAlloc ( RowSet * p)
static

Definition at line 51223 of file sqlite3.c.

51229 {
51230 assert( p!=0 );
51231 if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
51232 /* We could allocate a fresh RowSetEntry each time one is needed, but it
51233 ** is more efficient to pull a preallocated entry from the pool */
51234 struct RowSetChunk *pNew;
51235 pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
51236 if( pNew==0 ){
51237 return 0;
51238 }
51239 pNew->pNextChunk = p->pChunk;
51240 p->pChunk = pNew;
struct RowSetChunk * pNextChunk
Definition sqlite3.c:51137
u16 nFresh
Definition sqlite3.c:51153
sqlite3 * db
Definition sqlite3.c:51148
struct RowSetChunk * pChunk
Definition sqlite3.c:51147

References RowSetChunk::aEntry, RowSet::db, RowSet::nFresh, RowSet::pChunk, RowSet::pFresh, RowSetChunk::pNextChunk, ROWSET_ENTRY_PER_CHUNK, and sqlite3DbMallocRawNN().

Referenced by sqlite3RowSetInsert(), and sqlite3RowSetTest().

◆ rowSetEntryMerge()

static struct RowSetEntry * rowSetEntryMerge ( struct RowSetEntry * pA,
struct RowSetEntry * pB )
static

Definition at line 51279 of file sqlite3.c.

51288 {
51289 struct RowSetEntry head;
51290 struct RowSetEntry *pTail;
51291
51292 pTail = &head;
51293 assert( pA!=0 && pB!=0 );
51294 for(;;){
51295 assert( pA->pRight==0 || pA->v<=pA->pRight->v );
51296 assert( pB->pRight==0 || pB->v<=pB->pRight->v );
51297 if( pA->v<=pB->v ){
51298 if( pA->v<pB->v ) pTail = pTail->pRight = pA;
51299 pA = pA->pRight;
51300 if( pA==0 ){
51301 pTail->pRight = pB;
51302 break;
51303 }
51304 }else{
51305 pTail = pTail->pRight = pB;
51306 pB = pB->pRight;
51307 if( pB==0 ){
51308 pTail->pRight = pA;
struct RowSetEntry * pRight
Definition sqlite3.c:51126

References RowSetEntry::pRight, and RowSetEntry::v.

Referenced by sqlite3RowSetTest().

◆ rowSetEntrySort()

static struct RowSetEntry * rowSetEntrySort ( struct RowSetEntry * pIn)
static

Definition at line 51314 of file sqlite3.c.

51320 {
51321 unsigned int i;
51322 struct RowSetEntry *pNext, *aBucket[40];
51323
51324 memset(aBucket, 0, sizeof(aBucket));
51325 while( pIn ){
51326 pNext = pIn->pRight;
51327 pIn->pRight = 0;
51328 for(i=0; aBucket[i]; i++){
51329 pIn = rowSetEntryMerge(aBucket[i], pIn);
51330 aBucket[i] = 0;
51331 }
51332 aBucket[i] = pIn;
51333 pIn = pNext;
51334 }
51335 pIn = aBucket[0];
static struct RowSetEntry * rowSetEntryMerge(struct RowSetEntry *pA, struct RowSetEntry *pB)
Definition sqlite3.c:51279

Referenced by sqlite3RowSetNext(), and sqlite3RowSetTest().

◆ rowSetListToTree()

static struct RowSetEntry * rowSetListToTree ( struct RowSetEntry * pList)
static

Definition at line 51414 of file sqlite3.c.

51420 {
51421 int iDepth; /* Depth of the tree so far */
51422 struct RowSetEntry *p; /* Current tree root */
51423 struct RowSetEntry *pLeft; /* Left subtree */
51424
51425 assert( pList!=0 );
51426 p = pList;
51427 pList = p->pRight;
51428 p->pLeft = p->pRight = 0;
51429 for(iDepth=1; pList; iDepth++){
51430 pLeft = p;
51431 p = pList;
struct RowSetEntry * pLeft
Definition sqlite3.c:51127

Referenced by sqlite3RowSetTest().

◆ rowSetNDeepTree()

static struct RowSetEntry * rowSetNDeepTree ( struct RowSetEntry ** ppList,
int iDepth )
static

Definition at line 51378 of file sqlite3.c.

51387 {
51388 struct RowSetEntry *p; /* Root of the new tree */
51389 struct RowSetEntry *pLeft; /* Left subtree */
51390 if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
51391 /* Prevent unnecessary deep recursion when we run out of entries */
51392 return 0;
51393 }
51394 if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/
51395 /* This branch causes a *balanced* tree to be generated. A valid tree
51396 ** is still generated without this branch, but the tree is wildly
51397 ** unbalanced and inefficient. */
51398 pLeft = rowSetNDeepTree(ppList, iDepth-1);
51399 p = *ppList;
51400 if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
51401 /* It is safe to always return here, but the resulting tree
51402 ** would be unbalanced */
51403 return pLeft;
51404 }
51405 p->pLeft = pLeft;
51406 *ppList = p->pRight;
51407 p->pRight = rowSetNDeepTree(ppList, iDepth-1);
51408 }else{
static struct RowSetEntry * rowSetNDeepTree(struct RowSetEntry **ppList, int iDepth)
Definition sqlite3.c:51378

References RowSetEntry::pLeft, RowSetEntry::pRight, and rowSetNDeepTree().

Referenced by rowSetNDeepTree().

◆ rowSetTreeToList()

static void rowSetTreeToList ( struct RowSetEntry * pIn,
struct RowSetEntry ** ppFirst,
struct RowSetEntry ** ppLast )
static

Definition at line 51343 of file sqlite3.c.

51353 {
51354 assert( pIn!=0 );
51355 if( pIn->pLeft ){
51356 struct RowSetEntry *p;
51357 rowSetTreeToList(pIn->pLeft, ppFirst, &p);
51358 p->pRight = pIn;
51359 }else{
51360 *ppFirst = pIn;
51361 }
51362 if( pIn->pRight ){
static void rowSetTreeToList(struct RowSetEntry *pIn, struct RowSetEntry **ppFirst, struct RowSetEntry **ppLast)
Definition sqlite3.c:51343

References RowSetEntry::pLeft, RowSetEntry::pRight, and rowSetTreeToList().

Referenced by rowSetTreeToList(), and sqlite3RowSetTest().

◆ rtrimCollFunc()

static int rtrimCollFunc ( void * pUser,
int nKey1,
const void * pKey1,
int nKey2,
const void * pKey2 )
static

Definition at line 162008 of file sqlite3.c.

162018 {

Referenced by openDatabase().

◆ saveAllCursors()

static int saveAllCursors ( BtShared * pBt,
Pgno iRoot,
BtCursor * pExcept )
static

Definition at line 65224 of file sqlite3.c.

65226 : This routine merely checks to see if any cursors
65227** need to be saved. It calls out to saveCursorsOnList() in the (unusual)
65228** event that cursors are in need to being saved.
65229*/
65230static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
65231 BtCursor *p;
65232 assert( sqlite3_mutex_held(pBt->mutex) );
65233 assert( pExcept==0 || pExcept->pBt==pBt );
65234 for(p=pBt->pCursor; p; p=p->pNext){
static int SQLITE_NOINLINE saveCursorsOnList(BtCursor *, Pgno, BtCursor *)
Definition sqlite3.c:65241

References BtCursor::curFlags, BtShared::mutex, BtCursor::pBt, BtShared::pCursor, BtCursor::pgnoRoot, BtCursor::pNext, saveCursorsOnList(), sqlite3_mutex_held(), and SQLITE_OK.

Referenced by autoVacuumCommit(), btreeCreateTable(), sqlite3BtreeClearTable(), sqlite3BtreeDelete(), sqlite3BtreeIncrVacuum(), sqlite3BtreeInsert(), sqlite3BtreePutData(), sqlite3BtreeRollback(), and sqlite3BtreeSavepoint().

◆ saveCursorKey()

static int saveCursorKey ( BtCursor * pCur)
static

Definition at line 65132 of file sqlite3.c.

65138 {
65139 int rc = SQLITE_OK;
65140 assert( CURSOR_VALID==pCur->eState );
65141 assert( 0==pCur->pKey );
65142 assert( cursorHoldsMutex(pCur) );
65143
65144 if( pCur->curIntKey ){
65145 /* Only the rowid is required for a table btree */
65146 pCur->nKey = sqlite3BtreeIntegerKey(pCur);
65147 }else{
65148 /* For an index btree, save the complete key content. It is possible
65149 ** that the current key is corrupt. In that case, it is possible that
65150 ** the sqlite3VdbeRecordUnpack() function may overread the buffer by
65151 ** up to the size of 1 varint plus 1 8-byte value when the cursor
65152 ** position is restored. Hence the 17 bytes of padding allocated
65153 ** below. */
65154 void *pKey;
65155 pCur->nKey = sqlite3BtreePayloadSize(pCur);
65156 pKey = sqlite3Malloc( pCur->nKey + 9 + 8 );
65157 if( pKey ){
65158 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
65159 if( rc==SQLITE_OK ){
65160 memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
65161 pCur->pKey = pKey;
65162 }else{
65163 sqlite3_free(pKey);
65164 }
65165 }else{
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor *)
Definition sqlite3.c:69096
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *, u32 offset, u32 amt, void *)
Definition sqlite3.c:69461

References BtCursor::curIntKey, CURSOR_VALID, BtCursor::eState, BtCursor::nKey, BtCursor::pKey, sqlite3_free(), sqlite3BtreeIntegerKey(), sqlite3BtreePayload(), sqlite3BtreePayloadSize(), sqlite3Malloc(), SQLITE_NOMEM_BKPT, and SQLITE_OK.

Referenced by saveCursorPosition(), and sqlite3BtreeDelete().

◆ saveCursorPosition()

static int saveCursorPosition ( BtCursor * pCur)
static

Definition at line 65174 of file sqlite3.c.

65180 {
65181 int rc;
65182
65183 assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState );
65184 assert( 0==pCur->pKey );
65185 assert( cursorHoldsMutex(pCur) );
65186
65187 if( pCur->curFlags & BTCF_Pinned ){
65189 }
65190 if( pCur->eState==CURSOR_SKIPNEXT ){
65191 pCur->eState = CURSOR_VALID;
65192 }else{
65193 pCur->skipNext = 0;
65194 }
65195
65196 rc = saveCursorKey(pCur);
65197 if( rc==SQLITE_OK ){
static int saveCursorKey(BtCursor *pCur)
Definition sqlite3.c:65132
#define BTCF_Pinned
Definition sqlite3.c:64012
static void btreeReleaseAllCursorPages(BtCursor *pCur)
Definition sqlite3.c:65108
#define SQLITE_CONSTRAINT_PINNED
Definition sqlite3.c:1586

References BTCF_AtLast, BTCF_Pinned, BTCF_ValidNKey, BTCF_ValidOvfl, btreeReleaseAllCursorPages(), BtCursor::curFlags, CURSOR_REQUIRESEEK, CURSOR_SKIPNEXT, CURSOR_VALID, BtCursor::eState, BtCursor::pKey, saveCursorKey(), BtCursor::skipNext, SQLITE_CONSTRAINT_PINNED, and SQLITE_OK.

Referenced by saveCursorsOnList(), and sqlite3BtreeTripAllCursors().

◆ saveCursorsOnList()

static int SQLITE_NOINLINE saveCursorsOnList ( BtCursor * p,
Pgno iRoot,
BtCursor * pExcept )
static

Definition at line 65241 of file sqlite3.c.

65251 {
65252 do{
65253 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
65254 if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){
65255 int rc = saveCursorPosition(p);
65256 if( SQLITE_OK!=rc ){
65257 return rc;
65258 }
65259 }else{
65260 testcase( p->iPage>=0 );
static int saveCursorPosition(BtCursor *pCur)
Definition sqlite3.c:65174

References btreeReleaseAllCursorPages(), CURSOR_SKIPNEXT, CURSOR_VALID, BtCursor::eState, BtCursor::iPage, BtCursor::pgnoRoot, BtCursor::pNext, saveCursorPosition(), SQLITE_OK, and testcase.

Referenced by saveAllCursors().

◆ schemaIsValid()

static void schemaIsValid ( Parse * pParse)
static

Definition at line 128803 of file sqlite3.c.

128809 {
128810 sqlite3 *db = pParse->db;
128811 int iDb;
128812 int rc;
128813 int cookie;
128814
128815 assert( pParse->checkSchema );
128816 assert( sqlite3_mutex_held(db->mutex) );
128817 for(iDb=0; iDb<db->nDb; iDb++){
128818 int openedTransaction = 0; /* True if a transaction is opened */
128819 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
128820 if( pBt==0 ) continue;
128821
128822 /* If there is not already a read-only (or read-write) transaction opened
128823 ** on the b-tree database, open one now. If a transaction is opened, it
128824 ** will be closed immediately after reading the meta-value. */
128825 if( !sqlite3BtreeIsInReadTrans(pBt) ){
128826 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
128827 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
128828 sqlite3OomFault(db);
128829 }
128830 if( rc!=SQLITE_OK ) return;
128831 openedTransaction = 1;
128832 }
128833
128834 /* Read the schema cookie from the database. If it does not match the
128835 ** value stored as part of the in-memory schema representation,
128836 ** set Parse.rc to SQLITE_SCHEMA. */
128837 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
128838 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
128839 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
128840 sqlite3ResetOneSchema(db, iDb);
128841 pParse->rc = SQLITE_SCHEMA;
128842 }
128843
#define SQLITE_SCHEMA
Definition sqlite3.c:1487
#define BTREE_SCHEMA_VERSION
Definition sqlite3.c:15142
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *, int)
Definition sqlite3.c:110965
SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *, int, int *)
Definition sqlite3.c:67850
int schema_cookie
Definition sqlite3.c:16631

References sqlite3::aDb, BTREE_SCHEMA_VERSION, Parse::checkSchema, Parse::db, sqlite3::mutex, sqlite3::nDb, Db::pBt, Db::pSchema, Parse::rc, Schema::schema_cookie, sqlite3_mutex_held(), sqlite3BtreeBeginTrans(), sqlite3BtreeCommit(), sqlite3BtreeGetMeta(), sqlite3BtreeIsInReadTrans(), sqlite3OomFault(), sqlite3ResetOneSchema(), SQLITE_IOERR_NOMEM, SQLITE_NOMEM, SQLITE_OK, and SQLITE_SCHEMA.

◆ searchWith()

static struct Cte * searchWith ( With * pWith,
struct SrcList_item * pItem,
With ** ppContext )
static

Definition at line 134015 of file sqlite3.c.

134025 {
134026 const char *zName;
134027 if( pItem->zDatabase==0 && (zName = pItem->zName)!=0 ){
134028 With *p;
134029 for(p=pWith; p; p=p->pOuter){
134030 int i;
134031 for(i=0; i<p->nCte; i++){
134032 if( sqlite3StrICmp(zName, p->a[i].zName)==0 ){
134033 *ppContext = p;
134034 return &p->a[i];
char * zName
Definition sqlite3.c:19149
With * pOuter
Definition sqlite3.c:19147

References With::a, With::nCte, With::pOuter, sqlite3StrICmp(), With::Cte::zName, and zName.

Referenced by withExpand().

◆ seekAndRead()

static int seekAndRead ( unixFile * id,
sqlite3_int64 offset,
void * pBuf,
int cnt )
static

Definition at line 36824 of file sqlite3.c.

36830 {
36831 int got;
36832 int prior = 0;
36833#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
36834 i64 newOffset;
36835#endif
36837 assert( cnt==(cnt&0x1ffff) );
36838 assert( id->h>2 );
36839 do{
36840#if defined(USE_PREAD)
36841 got = osPread(id->h, pBuf, cnt, offset);
36842 SimulateIOError( got = -1 );
36843#elif defined(USE_PREAD64)
36844 got = osPread64(id->h, pBuf, cnt, offset);
36845 SimulateIOError( got = -1 );
36846#else
36847 newOffset = lseek(id->h, offset, SEEK_SET);
36848 SimulateIOError( newOffset = -1 );
36849 if( newOffset<0 ){
36850 storeLastErrno((unixFile*)id, errno);
36851 return -1;
36852 }
36853 got = osRead(id->h, pBuf, cnt);
36854#endif
36855 if( got==cnt ) break;
36856 if( got<0 ){
36857 if( errno==EINTR ){ got = 1; continue; }
36858 prior = 0;
36859 storeLastErrno((unixFile*)id, errno);
36860 break;
36861 }else if( got>0 ){
36862 cnt -= got;
36863 offset += got;
36864 prior += got;
36865 pBuf = (void*)(got + (char*)pBuf);
36866 }
#define TIMER_START
Definition sqlite3.c:33783
#define osPread
#define osPread64
#define osRead

References unixFile::h, osPread, osPread64, osRead, OSTRACE, SimulateIOError, storeLastErrno(), TIMER_ELAPSED, TIMER_END, and TIMER_START.

Referenced by unixRead(), and unixWrite().

◆ seekAndWrite()

static int seekAndWrite ( unixFile * id,
i64 offset,
const void * pBuf,
int cnt )
static

Definition at line 36978 of file sqlite3.c.

References unixFile::h, unixFile::lastErrno, and seekAndWriteFd().

Referenced by fcntlSizeHint(), and unixWrite().

◆ seekAndWriteFd()

static int seekAndWriteFd ( int fd,
i64 iOff,
const void * pBuf,
int nBuf,
int * piErrno )
static

Definition at line 36932 of file sqlite3.c.

36944 {
36945 int rc = 0; /* Value returned by system call */
36946
36947 assert( nBuf==(nBuf&0x1ffff) );
36948 assert( fd>2 );
36949 assert( piErrno!=0 );
36950 nBuf &= 0x1ffff;
36952
36953#if defined(USE_PREAD)
36954 do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
36955#elif defined(USE_PREAD64)
36956 do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
36957#else
36958 do{
36959 i64 iSeek = lseek(fd, iOff, SEEK_SET);
36960 SimulateIOError( iSeek = -1 );
36961 if( iSeek<0 ){
36962 rc = -1;
36963 break;
36964 }
36965 rc = osWrite(fd, pBuf, nBuf);
36966 }while( rc<0 && errno==EINTR );
36967#endif
36968
#define osPwrite64
#define osPwrite

References osPwrite, osPwrite64, OSTRACE, osWrite, SimulateIOError, TIMER_ELAPSED, TIMER_END, and TIMER_START.

Referenced by seekAndWrite(), and unixShmMap().

◆ selectAddSubqueryTypeInfo()

static void selectAddSubqueryTypeInfo ( Walker * pWalker,
Select * p )
static

Definition at line 134606 of file sqlite3.c.

134612 {
134613 Parse *pParse;
134614 int i;
134615 SrcList *pTabList;
134616 struct SrcList_item *pFrom;
134617
134618 assert( p->selFlags & SF_Resolved );
134619 if( p->selFlags & SF_HasTypeInfo ) return;
134620 p->selFlags |= SF_HasTypeInfo;
134621 pParse = pWalker->pParse;
134622 pTabList = p->pSrc;
134623 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
134624 Table *pTab = pFrom->pTab;
134625 assert( pTab!=0 );
134626 if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
134627 /* A sub-query in the FROM clause of a SELECT */
134628 Select *pSel = pFrom->pSelect;
134629 if( pSel ){
134630 while( pSel->pPrior ) pSel = pSel->pPrior;
#define SF_HasTypeInfo
Definition sqlite3.c:18478

References SrcList::a, SrcList::nSrc, Walker::pParse, Select::pPrior, Select::pSrc, Select::selFlags, SF_HasTypeInfo, SF_Resolved, sqlite3SelectAddColumnTypeAndCollation(), SQLITE_AFF_NONE, Table::tabFlags, and TF_Ephemeral.

Referenced by sqlite3SelectAddTypeInfo().

◆ selectExpander()

static int selectExpander ( Walker * pWalker,
Select * p )
static

Definition at line 134266 of file sqlite3.c.

134272 {
134273 Parse *pParse = pWalker->pParse;
134274 int i, j, k;
134275 SrcList *pTabList;
134276 ExprList *pEList;
134277 struct SrcList_item *pFrom;
134278 sqlite3 *db = pParse->db;
134279 Expr *pE, *pRight, *pExpr;
134280 u16 selFlags = p->selFlags;
134281 u32 elistFlags = 0;
134282
134283 p->selFlags |= SF_Expanded;
134284 if( db->mallocFailed ){
134285 return WRC_Abort;
134286 }
134287 assert( p->pSrc!=0 );
134288 if( (selFlags & SF_Expanded)!=0 ){
134289 return WRC_Prune;
134290 }
134291 if( pWalker->eCode ){
134292 /* Renumber selId because it has been copied from a view */
134293 p->selId = ++pParse->nSelect;
134294 }
134295 pTabList = p->pSrc;
134296 pEList = p->pEList;
134297 sqlite3WithPush(pParse, p->pWith, 0);
134298
134299 /* Make sure cursor numbers have been assigned to all entries in
134300 ** the FROM clause of the SELECT statement.
134301 */
134302 sqlite3SrcListAssignCursors(pParse, pTabList);
134303
134304 /* Look up every table named in the FROM clause of the select. If
134305 ** an entry of the FROM clause is a subquery instead of a table or view,
134306 ** then create a transient table structure to describe the subquery.
134307 */
134308 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
134309 Table *pTab;
134310 assert( pFrom->fg.isRecursive==0 || pFrom->pTab!=0 );
134311 if( pFrom->pTab ) continue;
134312 assert( pFrom->fg.isRecursive==0 );
134313#ifndef SQLITE_OMIT_CTE
134314 if( withExpand(pWalker, pFrom) ) return WRC_Abort;
134315 if( pFrom->pTab ) {} else
134316#endif
134317 if( pFrom->zName==0 ){
134318#ifndef SQLITE_OMIT_SUBQUERY
134319 Select *pSel = pFrom->pSelect;
134320 /* A sub-query in the FROM clause of a SELECT */
134321 assert( pSel!=0 );
134322 assert( pFrom->pTab==0 );
134323 if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
134324 if( sqlite3ExpandSubquery(pParse, pFrom) ) return WRC_Abort;
134325#endif
134326 }else{
134327 /* An ordinary table or view name in the FROM clause */
134328 assert( pFrom->pTab==0 );
134329 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
134330 if( pTab==0 ) return WRC_Abort;
134331 if( pTab->nTabRef>=0xffff ){
134332 sqlite3ErrorMsg(pParse, "too many references to \"%s\": max 65535",
134333 pTab->zName);
134334 pFrom->pTab = 0;
134335 return WRC_Abort;
134336 }
134337 pTab->nTabRef++;
134338 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
134339 return WRC_Abort;
134340 }
134341#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
134342 if( IsVirtual(pTab) || pTab->pSelect ){
134343 i16 nCol;
134344 u8 eCodeOrig = pWalker->eCode;
134345 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
134346 assert( pFrom->pSelect==0 );
134347 if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){
134348 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
134349 pTab->zName);
134350 }
134351#ifndef SQLITE_OMIT_VIRTUALTABLE
134352 if( IsVirtual(pTab)
134353 && pFrom->fg.fromDDL
134354 && ALWAYS(pTab->pVTable!=0)
134355 && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
134356 ){
134357 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
134358 pTab->zName);
134359 }
134360#endif
134361 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
134362 nCol = pTab->nCol;
134363 pTab->nCol = -1;
134364 pWalker->eCode = 1; /* Turn on Select.selId renumbering */
134365 sqlite3WalkSelect(pWalker, pFrom->pSelect);
134366 pWalker->eCode = eCodeOrig;
134367 pTab->nCol = nCol;
134368 }
134369#endif
134370 }
134371
134372 /* Locate the index named by the INDEXED BY clause, if any. */
134373 if( sqlite3IndexedByLookup(pParse, pFrom) ){
134374 return WRC_Abort;
134375 }
134376 }
134377
134378 /* Process NATURAL keywords, and ON and USING clauses of joins.
134379 */
134380 if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
134381 return WRC_Abort;
134382 }
134383
134384 /* For every "*" that occurs in the column list, insert the names of
134385 ** all columns in all tables. And for every TABLE.* insert the names
134386 ** of all columns in TABLE. The parser inserted a special expression
134387 ** with the TK_ASTERISK operator for each "*" that it found in the column
134388 ** list. The following code just has to locate the TK_ASTERISK
134389 ** expressions and expand each one to the list of all columns in
134390 ** all tables.
134391 **
134392 ** The first loop just checks to see if there are any "*" operators
134393 ** that need expanding.
134394 */
134395 for(k=0; k<pEList->nExpr; k++){
134396 pE = pEList->a[k].pExpr;
134397 if( pE->op==TK_ASTERISK ) break;
134398 assert( pE->op!=TK_DOT || pE->pRight!=0 );
134399 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
134400 if( pE->op==TK_DOT && pE->pRight->op==TK_ASTERISK ) break;
134401 elistFlags |= pE->flags;
134402 }
134403 if( k<pEList->nExpr ){
134404 /*
134405 ** If we get here it means the result set contains one or more "*"
134406 ** operators that need to be expanded. Loop through each expression
134407 ** in the result set and expand them one by one.
134408 */
134409 struct ExprList_item *a = pEList->a;
134410 ExprList *pNew = 0;
134411 int flags = pParse->db->flags;
134412 int longNames = (flags & SQLITE_FullColNames)!=0
134413 && (flags & SQLITE_ShortColNames)==0;
134414
134415 for(k=0; k<pEList->nExpr; k++){
134416 pE = a[k].pExpr;
134417 elistFlags |= pE->flags;
134418 pRight = pE->pRight;
134419 assert( pE->op!=TK_DOT || pRight!=0 );
134420 if( pE->op!=TK_ASTERISK
134421 && (pE->op!=TK_DOT || pRight->op!=TK_ASTERISK)
134422 ){
134423 /* This particular expression does not need to be expanded.
134424 */
134425 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
134426 if( pNew ){
134427 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
134428 pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
134429 a[k].zEName = 0;
134430 }
134431 a[k].pExpr = 0;
134432 }else{
134433 /* This expression is a "*" or a "TABLE.*" and needs to be
134434 ** expanded. */
134435 int tableSeen = 0; /* Set to 1 when TABLE matches */
134436 char *zTName = 0; /* text of name of TABLE */
134437 if( pE->op==TK_DOT ){
134438 assert( pE->pLeft!=0 );
134439 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
134440 zTName = pE->pLeft->u.zToken;
134441 }
134442 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
134443 Table *pTab = pFrom->pTab;
134444 Select *pSub = pFrom->pSelect;
134445 char *zTabName = pFrom->zAlias;
134446 const char *zSchemaName = 0;
134447 int iDb;
134448 if( zTabName==0 ){
134449 zTabName = pTab->zName;
134450 }
134451 if( db->mallocFailed ) break;
134452 if( pSub==0 || (pSub->selFlags & SF_NestedFrom)==0 ){
134453 pSub = 0;
134454 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
134455 continue;
134456 }
134457 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
134458 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
134459 }
134460 for(j=0; j<pTab->nCol; j++){
134461 char *zName = pTab->aCol[j].zName;
134462 char *zColname; /* The computed column name */
134463 char *zToFree; /* Malloced string that needs to be freed */
134464 Token sColname; /* Computed column name as a token */
134465
134466 assert( zName );
134467 if( zTName && pSub
134468 && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
134469 ){
134470 continue;
134471 }
134472
134473 /* If a column is marked as 'hidden', omit it from the expanded
134474 ** result-set list unless the SELECT has the SF_IncludeHidden
134475 ** bit set.
134476 */
134477 if( (p->selFlags & SF_IncludeHidden)==0
134478 && IsHiddenColumn(&pTab->aCol[j])
134479 ){
134480 continue;
134481 }
134482 tableSeen = 1;
134483
134484 if( i>0 && zTName==0 ){
134485 if( (pFrom->fg.jointype & JT_NATURAL)!=0
134486 && tableAndColumnIndex(pTabList, i, zName, 0, 0, 1)
134487 ){
134488 /* In a NATURAL join, omit the join columns from the
134489 ** table to the right of the join */
134490 continue;
134491 }
134492 if( sqlite3IdListIndex(pFrom->pUsing, zName)>=0 ){
134493 /* In a join with a USING clause, omit columns in the
134494 ** using clause from the table on the right. */
134495 continue;
134496 }
134497 }
134498 pRight = sqlite3Expr(db, TK_ID, zName);
134499 zColname = zName;
134500 zToFree = 0;
134501 if( longNames || pTabList->nSrc>1 ){
134502 Expr *pLeft;
134503 pLeft = sqlite3Expr(db, TK_ID, zTabName);
134504 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
134505 if( zSchemaName ){
134506 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
134507 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr);
134508 }
134509 if( longNames ){
134510 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
134511 zToFree = zColname;
134512 }
134513 }else{
134514 pExpr = pRight;
134515 }
134516 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
134517 sqlite3TokenInit(&sColname, zColname);
134518 sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
134519 if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
134520 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
134521 sqlite3DbFree(db, pX->zEName);
134522 if( pSub ){
134523 pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
134524 testcase( pX->zEName==0 );
134525 }else{
134526 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
134527 zSchemaName, zTabName, zColname);
134528 testcase( pX->zEName==0 );
134529 }
134530 pX->eEName = ENAME_TAB;
134531 }
134532 sqlite3DbFree(db, zToFree);
134533 }
134534 }
134535 if( !tableSeen ){
134536 if( zTName ){
134537 sqlite3ErrorMsg(pParse, "no such table: %s", zTName);
134538 }else{
134539 sqlite3ErrorMsg(pParse, "no tables specified");
134540 }
134541 }
134542 }
134543 }
134544 sqlite3ExprListDelete(db, pEList);
134545 p->pEList = pNew;
134546 }
134547 if( p->pEList ){
134548 if( p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
134549 sqlite3ErrorMsg(pParse, "too many columns in result set");
134550 return WRC_Abort;
134551 }
#define ENAME_TAB
Definition sqlite3.c:18205
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse *, SrcList *)
Definition sqlite3.c:114834
static int sqliteProcessJoin(Parse *pParse, Select *p)
Definition sqlite3.c:129728
SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse *, struct SrcList_item *)
Definition sqlite3.c:134220
SQLITE_PRIVATE void sqlite3WithPush(Parse *, With *, u8)
Definition sqlite3.c:134046
SQLITE_PRIVATE int sqlite3IdListIndex(IdList *, const char *)
Definition sqlite3.c:114659
#define SF_IncludeHidden
Definition sqlite3.c:18488
#define IsHiddenColumn(X)
Definition sqlite3.c:17574
static int tableAndColumnIndex(SrcList *pSrc, int N, const char *zCol, int *piTab, int *piCol, int bIgnoreHidden)
Definition sqlite3.c:129577
static int withExpand(Walker *pWalker, struct SrcList_item *pFrom)
Definition sqlite3.c:134071
static int cannotBeFunction(Parse *pParse, struct SrcList_item *pFrom)
Definition sqlite3.c:133996
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *)
Definition sqlite3.c:133892
int nSelect
Definition sqlite3.c:18712
VTable * pVTable
Definition sqlite3.c:17514
u8 eVtabRisk
Definition sqlite3.c:17472

References ExprList::a, SrcList::a, Table::aCol, sqlite3::aDb, sqlite3::aLimit, ALWAYS, cannotBeFunction(), Parse::db, Walker::eCode, ExprList::ExprList_item::eEName, ENAME_TAB, EP_HasFunc, EP_IntValue, EP_Subquery, VTable::eVtabRisk, ExprHasProperty, sqlite3::flags, Expr::flags, IN_RENAME_OBJECT, IsHiddenColumn, IsVirtual, JT_NATURAL, sqlite3::mallocFailed, Table::nCol, Parse::nErr, ExprList::nExpr, Parse::nSelect, SrcList::nSrc, Table::nTabRef, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pLeft, Walker::pParse, Expr::pRight, Table::pSchema, Table::pSelect, Select::pSrc, Table::pVTable, Select::pWith, Select::selFlags, Select::selId, SF_ComplexResult, SF_Expanded, SF_IncludeHidden, SF_NestedFrom, sqlite3DbFree(), sqlite3DbStrDup(), sqlite3ErrorMsg(), sqlite3ExpandSubquery(), sqlite3Expr(), sqlite3ExprListAppend(), sqlite3ExprListDelete(), sqlite3ExprListSetName(), sqlite3IdListIndex(), sqlite3IndexedByLookup(), sqlite3LocateTableItem(), sqlite3MatchEName(), sqlite3MPrintf(), sqlite3PExpr(), sqlite3SchemaToIndex(), sqlite3SelectDup(), sqlite3SrcListAssignCursors(), sqlite3StrICmp(), sqlite3TokenInit(), sqlite3ViewGetColumnNames(), sqlite3WalkSelect(), sqlite3WithPush(), SQLITE_EnableView, SQLITE_FullColNames, SQLITE_LIMIT_COLUMN, SQLITE_ShortColNames, SQLITE_TrustedSchema, sqliteProcessJoin(), tableAndColumnIndex(), testcase, TK_ASTERISK, TK_DOT, TK_ID, Expr::u, withExpand(), WRC_Abort, WRC_Continue, WRC_Prune, Db::zDbSName, ExprList::ExprList_item::zEName, Column::zName, Table::zName, zName, and Expr::zToken.

Referenced by sqlite3SelectExpand().

◆ selectInnerLoop()

static void selectInnerLoop ( Parse * pParse,
Select * p,
int srcTab,
SortCtx * pSort,
DistinctCtx * pDistinct,
SelectDest * pDest,
int iContinue,
int iBreak )
static

Definition at line 130147 of file sqlite3.c.

130162 {
130163 Vdbe *v = pParse->pVdbe;
130164 int i;
130165 int hasDistinct; /* True if the DISTINCT keyword is present */
130166 int eDest = pDest->eDest; /* How to dispose of results */
130167 int iParm = pDest->iSDParm; /* First argument to disposal method */
130168 int nResultCol; /* Number of result columns */
130169 int nPrefixReg = 0; /* Number of extra registers before regResult */
130170 RowLoadInfo sRowLoadInfo; /* Info for deferred row loading */
130171
130172 /* Usually, regResult is the first cell in an array of memory cells
130173 ** containing the current result row. In this case regOrig is set to the
130174 ** same value. However, if the results are being sent to the sorter, the
130175 ** values for any expressions that are also part of the sort-key are omitted
130176 ** from this array. In this case regOrig is set to zero. */
130177 int regResult; /* Start of memory holding current results */
130178 int regOrig; /* Start of memory holding full result (or 0) */
130179
130180 assert( v );
130181 assert( p->pEList!=0 );
130182 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
130183 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
130184 if( pSort==0 && !hasDistinct ){
130185 assert( iContinue!=0 );
130186 codeOffset(v, p->iOffset, iContinue);
130187 }
130188
130189 /* Pull the requested columns.
130190 */
130191 nResultCol = p->pEList->nExpr;
130192
130193 if( pDest->iSdst==0 ){
130194 if( pSort ){
130195 nPrefixReg = pSort->pOrderBy->nExpr;
130196 if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++;
130197 pParse->nMem += nPrefixReg;
130198 }
130199 pDest->iSdst = pParse->nMem+1;
130200 pParse->nMem += nResultCol;
130201 }else if( pDest->iSdst+nResultCol > pParse->nMem ){
130202 /* This is an error condition that can result, for example, when a SELECT
130203 ** on the right-hand side of an INSERT contains more result columns than
130204 ** there are columns in the table on the left. The error will be caught
130205 ** and reported later. But we need to make sure enough memory is allocated
130206 ** to avoid other spurious errors in the meantime. */
130207 pParse->nMem += nResultCol;
130208 }
130209 pDest->nSdst = nResultCol;
130210 regOrig = regResult = pDest->iSdst;
130211 if( srcTab>=0 ){
130212 for(i=0; i<nResultCol; i++){
130213 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
130214 VdbeComment((v, "%s", p->pEList->a[i].zEName));
130215 }
130216 }else if( eDest!=SRT_Exists ){
130217#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130218 ExprList *pExtra = 0;
130219#endif
130220 /* If the destination is an EXISTS(...) expression, the actual
130221 ** values returned by the SELECT are not required.
130222 */
130223 u8 ecelFlags; /* "ecel" is an abbreviation of "ExprCodeExprList" */
130224 ExprList *pEList;
130225 if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
130226 ecelFlags = SQLITE_ECEL_DUP;
130227 }else{
130228 ecelFlags = 0;
130229 }
130230 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
130231 /* For each expression in p->pEList that is a copy of an expression in
130232 ** the ORDER BY clause (pSort->pOrderBy), set the associated
130233 ** iOrderByCol value to one more than the index of the ORDER BY
130234 ** expression within the sort-key that pushOntoSorter() will generate.
130235 ** This allows the p->pEList field to be omitted from the sorted record,
130236 ** saving space and CPU cycles. */
130237 ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
130238
130239 for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
130240 int j;
130241 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
130242 p->pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
130243 }
130244 }
130245#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130246 selectExprDefer(pParse, pSort, p->pEList, &pExtra);
130247 if( pExtra && pParse->db->mallocFailed==0 ){
130248 /* If there are any extra PK columns to add to the sorter records,
130249 ** allocate extra memory cells and adjust the OpenEphemeral
130250 ** instruction to account for the larger records. This is only
130251 ** required if there are one or more WITHOUT ROWID tables with
130252 ** composite primary keys in the SortCtx.aDefer[] array. */
130253 VdbeOp *pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
130254 pOp->p2 += (pExtra->nExpr - pSort->nDefer);
130255 pOp->p4.pKeyInfo->nAllField += (pExtra->nExpr - pSort->nDefer);
130256 pParse->nMem += pExtra->nExpr;
130257 }
130258#endif
130259
130260 /* Adjust nResultCol to account for columns that are omitted
130261 ** from the sorter by the optimizations in this branch */
130262 pEList = p->pEList;
130263 for(i=0; i<pEList->nExpr; i++){
130264 if( pEList->a[i].u.x.iOrderByCol>0
130265#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130266 || pEList->a[i].bSorterRef
130267#endif
130268 ){
130269 nResultCol--;
130270 regOrig = 0;
130271 }
130272 }
130273
130274 testcase( regOrig );
130275 testcase( eDest==SRT_Set );
130276 testcase( eDest==SRT_Mem );
130277 testcase( eDest==SRT_Coroutine );
130278 testcase( eDest==SRT_Output );
130279 assert( eDest==SRT_Set || eDest==SRT_Mem
130280 || eDest==SRT_Coroutine || eDest==SRT_Output
130281 || eDest==SRT_Upfrom );
130282 }
130283 sRowLoadInfo.regResult = regResult;
130284 sRowLoadInfo.ecelFlags = ecelFlags;
130285#ifdef SQLITE_ENABLE_SORTER_REFERENCES
130286 sRowLoadInfo.pExtra = pExtra;
130287 sRowLoadInfo.regExtraResult = regResult + nResultCol;
130288 if( pExtra ) nResultCol += pExtra->nExpr;
130289#endif
130290 if( p->iLimit
130291 && (ecelFlags & SQLITE_ECEL_OMITREF)!=0
130292 && nPrefixReg>0
130293 ){
130294 assert( pSort!=0 );
130295 assert( hasDistinct==0 );
130296 pSort->pDeferredRowLoad = &sRowLoadInfo;
130297 regOrig = 0;
130298 }else{
130299 innerLoopLoadRow(pParse, p, &sRowLoadInfo);
130300 }
130301 }
130302
130303 /* If the DISTINCT keyword was present on the SELECT statement
130304 ** and this row has been seen before, then do not make this row
130305 ** part of the result.
130306 */
130307 if( hasDistinct ){
130308 switch( pDistinct->eTnctType ){
130309 case WHERE_DISTINCT_ORDERED: {
130310 VdbeOp *pOp; /* No longer required OpenEphemeral instr. */
130311 int iJump; /* Jump destination */
130312 int regPrev; /* Previous row content */
130313
130314 /* Allocate space for the previous row */
130315 regPrev = pParse->nMem+1;
130316 pParse->nMem += nResultCol;
130317
130318 /* Change the OP_OpenEphemeral coded earlier to an OP_Null
130319 ** sets the MEM_Cleared bit on the first register of the
130320 ** previous value. This will cause the OP_Ne below to always
130321 ** fail on the first iteration of the loop even if the first
130322 ** row is all NULLs.
130323 */
130324 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
130325 pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
130326 pOp->opcode = OP_Null;
130327 pOp->p1 = 1;
130328 pOp->p2 = regPrev;
130329 pOp = 0; /* Ensure pOp is not used after sqlite3VdbeAddOp() */
130330
130331 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
130332 for(i=0; i<nResultCol; i++){
130333 CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
130334 if( i<nResultCol-1 ){
130335 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
130336 VdbeCoverage(v);
130337 }else{
130338 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
130339 VdbeCoverage(v);
130340 }
130341 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
130343 }
130344 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
130345 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
130346 break;
130347 }
130348
130349 case WHERE_DISTINCT_UNIQUE: {
130350 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
130351 break;
130352 }
130353
130354 default: {
130355 assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
130356 codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol,
130357 regResult);
130358 break;
130359 }
130360 }
130361 if( pSort==0 ){
130362 codeOffset(v, p->iOffset, iContinue);
130363 }
130364 }
130365
130366 switch( eDest ){
130367 /* In this mode, write each query result to the key of the temporary
130368 ** table iParm.
130369 */
130370#ifndef SQLITE_OMIT_COMPOUND_SELECT
130371 case SRT_Union: {
130372 int r1;
130373 r1 = sqlite3GetTempReg(pParse);
130374 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
130375 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
130376 sqlite3ReleaseTempReg(pParse, r1);
130377 break;
130378 }
130379
130380 /* Construct a record from the query result, but instead of
130381 ** saving that record, use it as a key to delete elements from
130382 ** the temporary table iParm.
130383 */
130384 case SRT_Except: {
130385 sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nResultCol);
130386 break;
130387 }
130388#endif /* SQLITE_OMIT_COMPOUND_SELECT */
130389
130390 /* Store the result as data using a unique key.
130391 */
130392 case SRT_Fifo:
130393 case SRT_DistFifo:
130394 case SRT_Table:
130395 case SRT_EphemTab: {
130396 int r1 = sqlite3GetTempRange(pParse, nPrefixReg+1);
130397 testcase( eDest==SRT_Table );
130398 testcase( eDest==SRT_EphemTab );
130399 testcase( eDest==SRT_Fifo );
130400 testcase( eDest==SRT_DistFifo );
130401 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg);
130402#ifndef SQLITE_OMIT_CTE
130403 if( eDest==SRT_DistFifo ){
130404 /* If the destination is DistFifo, then cursor (iParm+1) is open
130405 ** on an ephemeral index. If the current row is already present
130406 ** in the index, do not write it to the output. If not, add the
130407 ** current row to the index and proceed with writing it to the
130408 ** output table as well. */
130409 int addr = sqlite3VdbeCurrentAddr(v) + 4;
130410 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
130411 VdbeCoverage(v);
130412 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm+1, r1,regResult,nResultCol);
130413 assert( pSort==0 );
130414 }
130415#endif
130416 if( pSort ){
130417 assert( regResult==regOrig );
130418 pushOntoSorter(pParse, pSort, p, r1+nPrefixReg, regOrig, 1, nPrefixReg);
130419 }else{
130420 int r2 = sqlite3GetTempReg(pParse);
130421 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
130422 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
130424 sqlite3ReleaseTempReg(pParse, r2);
130425 }
130426 sqlite3ReleaseTempRange(pParse, r1, nPrefixReg+1);
130427 break;
130428 }
130429
130430 case SRT_Upfrom: {
130431 if( pSort ){
130433 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
130434 }else{
130435 int i2 = pDest->iSDParm2;
130436 int r1 = sqlite3GetTempReg(pParse);
130437
130438 /* If the UPDATE FROM join is an aggregate that matches no rows, it
130439 ** might still be trying to return one row, because that is what
130440 ** aggregates do. Don't record that empty row in the output table. */
130441 sqlite3VdbeAddOp2(v, OP_IsNull, regResult, iBreak); VdbeCoverage(v);
130442
130444 regResult+(i2<0), nResultCol-(i2<0), r1);
130445 if( i2<0 ){
130446 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, regResult);
130447 }else{
130448 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, i2);
130449 }
130450 }
130451 break;
130452 }
130453
130454#ifndef SQLITE_OMIT_SUBQUERY
130455 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
130456 ** then there should be a single item on the stack. Write this
130457 ** item into the set table with bogus data.
130458 */
130459 case SRT_Set: {
130460 if( pSort ){
130461 /* At first glance you would think we could optimize out the
130462 ** ORDER BY in this case since the order of entries in the set
130463 ** does not matter. But there might be a LIMIT clause, in which
130464 ** case the order does matter */
130466 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
130467 }else{
130468 int r1 = sqlite3GetTempReg(pParse);
130469 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
130470 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
130471 r1, pDest->zAffSdst, nResultCol);
130472 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
130473 sqlite3ReleaseTempReg(pParse, r1);
130474 }
130475 break;
130476 }
130477
130478
130479 /* If any row exist in the result set, record that fact and abort.
130480 */
130481 case SRT_Exists: {
130482 sqlite3VdbeAddOp2(v, OP_Integer, 1, iParm);
130483 /* The LIMIT clause will terminate the loop for us */
130484 break;
130485 }
130486
130487 /* If this is a scalar select that is part of an expression, then
130488 ** store the results in the appropriate memory cell or array of
130489 ** memory cells and break out of the scan loop.
130490 */
130491 case SRT_Mem: {
130492 if( pSort ){
130493 assert( nResultCol<=pDest->nSdst );
130495 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
130496 }else{
130497 assert( nResultCol==pDest->nSdst );
130498 assert( regResult==iParm );
130499 /* The LIMIT clause will jump out of the loop for us */
130500 }
130501 break;
130502 }
130503#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
130504
130505 case SRT_Coroutine: /* Send data to a co-routine */
130506 case SRT_Output: { /* Return the results */
130507 testcase( eDest==SRT_Coroutine );
130508 testcase( eDest==SRT_Output );
130509 if( pSort ){
130510 pushOntoSorter(pParse, pSort, p, regResult, regOrig, nResultCol,
130511 nPrefixReg);
130512 }else if( eDest==SRT_Coroutine ){
130513 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
130514 }else{
130515 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
130516 }
130517 break;
130518 }
130519
130520#ifndef SQLITE_OMIT_CTE
130521 /* Write the results into a priority queue that is order according to
130522 ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
130523 ** index with pSO->nExpr+2 columns. Build a key using pSO for the first
130524 ** pSO->nExpr columns, then make sure all keys are unique by adding a
130525 ** final OP_Sequence column. The last column is the record as a blob.
130526 */
130527 case SRT_DistQueue:
130528 case SRT_Queue: {
130529 int nKey;
130530 int r1, r2, r3;
130531 int addrTest = 0;
130532 ExprList *pSO;
130533 pSO = pDest->pOrderBy;
130534 assert( pSO );
130535 nKey = pSO->nExpr;
130536 r1 = sqlite3GetTempReg(pParse);
130537 r2 = sqlite3GetTempRange(pParse, nKey+2);
130538 r3 = r2+nKey+1;
130539 if( eDest==SRT_DistQueue ){
130540 /* If the destination is DistQueue, then cursor (iParm+1) is open
130541 ** on a second ephemeral index that holds all values every previously
130542 ** added to the queue. */
130543 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
130544 regResult, nResultCol);
130545 VdbeCoverage(v);
130546 }
130547 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
130548 if( eDest==SRT_DistQueue ){
130549 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
130551 }
130552 for(i=0; i<nKey; i++){
130554 regResult + pSO->a[i].u.x.iOrderByCol - 1,
130555 r2+i);
130556 }
130557 sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);
130558 sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);
130559 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, r2, nKey+2);
130560 if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
130561 sqlite3ReleaseTempReg(pParse, r1);
130562 sqlite3ReleaseTempRange(pParse, r2, nKey+2);
130563 break;
130564 }
130565#endif /* SQLITE_OMIT_CTE */
130566
130567
130568
130569#if !defined(SQLITE_OMIT_TRIGGER)
130570 /* Discard the results. This is used for SELECT statements inside
130571 ** the body of a TRIGGER. The purpose of such selects is to call
130572 ** user-defined functions that have side effects. We do not care
130573 ** about the actual results of the select.
130574 */
130575 default: {
130576 assert( eDest==SRT_Discard );
130577 break;
130578 }
130579#endif
130580 }
130581
130582 /* Jump to the end of the loop if the LIMIT is reached. Except, if
130583 ** there is a sorter, in which case the sorter has already limited
static void pushOntoSorter(Parse *pParse, SortCtx *pSort, Select *pSelect, int regData, int regOrigData, int nData, int nPrefixReg)
Definition sqlite3.c:129876
#define SQLITE_ECEL_OMITREF
Definition sqlite3.c:19668
#define WHERE_DISTINCT_NOOP
Definition sqlite3.c:18323
#define WHERE_DISTINCT_ORDERED
Definition sqlite3.c:18325
static void codeDistinct(Parse *pParse, int iTab, int addrRepeat, int N, int iMem)
Definition sqlite3.c:130038
#define OP_IdxDelete
Definition sqlite3.c:15698
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe *, int addr)
Definition sqlite3.c:78933
#define WHERE_DISTINCT_UNIQUE
Definition sqlite3.c:18324
static void innerLoopLoadRow(Parse *pParse, Select *pSelect, RowLoadInfo *pInfo)
Definition sqlite3.c:129834
#define WHERE_DISTINCT_UNORDERED
Definition sqlite3.c:18326
struct RowLoadInfo * pDeferredRowLoad
Definition sqlite3.c:129360

References ExprList::a, SortCtx::addrSortIndex, DistinctCtx::addrTnct, ExprList::ExprList_item::bSorterRef, codeDistinct(), codeOffset(), Parse::db, RowLoadInfo::ecelFlags, SelectDest::eDest, DistinctCtx::eTnctType, Select::iLimit, innerLoopLoadRow(), Select::iOffset, ExprList::ExprList_item::iOrderByCol, SelectDest::iSDParm, SelectDest::iSDParm2, SelectDest::iSdst, sqlite3::mallocFailed, KeyInfo::nAllField, ExprList::nExpr, Parse::nMem, SortCtx::nOBSat, SelectDest::nSdst, OP_Column, OP_Copy, OP_DecrJumpZero, OP_Eq, OP_Found, OP_IdxDelete, OP_IdxInsert, OP_Insert, OP_Integer, OP_IsNull, OP_MakeRecord, OP_Ne, OP_NewRowid, OP_Null, OP_ResultRow, OP_SCopy, OP_Sequence, OP_Yield, VdbeOp::opcode, OPFLAG_APPEND, OPFLAG_USESEEKRESULT, VdbeOp::p1, VdbeOp::p2, VdbeOp::p4, P4_COLLSEQ, SortCtx::pDeferredRowLoad, Select::pEList, ExprList::ExprList_item::pExpr, VdbeOp::p4union::pKeyInfo, SelectDest::pOrderBy, SortCtx::pOrderBy, pushOntoSorter(), Parse::pVdbe, RowLoadInfo::regResult, SORTFLAG_UseSorter, SortCtx::sortFlags, sqlite3ExprCollSeq(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3Strlen30(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP4(), sqlite3VdbeChangeP5(), sqlite3VdbeChangeToNoop(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetOp(), sqlite3VdbeJumpHere(), SQLITE_ECEL_DUP, SQLITE_ECEL_OMITREF, SQLITE_ECEL_REF, SQLITE_NULLEQ, SRT_Coroutine, SRT_Discard, SRT_DistFifo, SRT_DistQueue, SRT_EphemTab, SRT_Except, SRT_Exists, SRT_Fifo, SRT_Mem, SRT_Output, SRT_Queue, SRT_Set, SRT_Table, SRT_Union, SRT_Upfrom, DistinctCtx::tabTnct, testcase, ExprList::ExprList_item::u, VdbeComment, VdbeCoverage, WHERE_DISTINCT_NOOP, WHERE_DISTINCT_ORDERED, WHERE_DISTINCT_UNIQUE, WHERE_DISTINCT_UNORDERED, ExprList::ExprList_item::x, SelectDest::zAffSdst, and ExprList::ExprList_item::zEName.

Referenced by generateWithRecursiveQuery(), multiSelect(), multiSelectValues(), and sqlite3Select().

◆ selectOpName()

static const char * selectOpName ( int id)
static

Definition at line 130679 of file sqlite3.c.

130685 {
130686 char *z;
130687 switch( id ){
130688 case TK_ALL: z = "UNION ALL"; break;

Referenced by multiSelect(), multiSelectOrderBy(), and sqlite3SelectWrongNumTermsError().

◆ selectPopWith()

static void selectPopWith ( Walker * pWalker,
Select * p )
static

Definition at line 134199 of file sqlite3.c.

134205 {
134206 Parse *pParse = pWalker->pParse;
134207 if( OK_IF_ALWAYS_TRUE(pParse->pWith) && p->pPrior==0 ){
134208 With *pWith = findRightmost(p)->pWith;
With * pWith
Definition sqlite3.c:18774

References findRightmost(), Parse::nErr, OK_IF_ALWAYS_TRUE, With::pOuter, Walker::pParse, Select::pPrior, Select::pWith, and Parse::pWith.

Referenced by sqlite3SelectExpand().

◆ selectSrcCount()

static int selectSrcCount ( Walker * pWalker,
Select * pSel )
static

◆ selectWindowRewriteEList()

static void selectWindowRewriteEList ( Parse * pParse,
Window * pWin,
SrcList * pSrc,
ExprList * pEList,
Table * pTab,
ExprList ** ppSub )
static

Definition at line 152015 of file sqlite3.c.

152028 {
152029 Walker sWalker;
152030 WindowRewrite sRewrite;
152031
152032 assert( pWin!=0 );
152033 memset(&sWalker, 0, sizeof(Walker));
152034 memset(&sRewrite, 0, sizeof(WindowRewrite));
152035
152036 sRewrite.pSub = *ppSub;
152037 sRewrite.pWin = pWin;
152038 sRewrite.pSrc = pSrc;
152039 sRewrite.pTab = pTab;
152040
152041 sWalker.pParse = pParse;
static int selectWindowRewriteExprCb(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:151907
static int selectWindowRewriteSelectCb(Walker *pWalker, Select *pSelect)
Definition sqlite3.c:151988
ExprList * pSub
Definition sqlite3.c:151897
Window * pWin
Definition sqlite3.c:151895
SrcList * pSrc
Definition sqlite3.c:151896

References Walker::pParse, Walker::pRewrite, WindowRewrite::pSrc, WindowRewrite::pSub, WindowRewrite::pTab, WindowRewrite::pWin, selectWindowRewriteExprCb(), selectWindowRewriteSelectCb(), sqlite3WalkExprList(), Walker::u, Walker::xExprCallback, and Walker::xSelectCallback.

Referenced by sqlite3WindowRewrite().

◆ selectWindowRewriteExprCb()

static int selectWindowRewriteExprCb ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 151907 of file sqlite3.c.

151913 {
151914 struct WindowRewrite *p = pWalker->u.pRewrite;
151915 Parse *pParse = pWalker->pParse;
151916 assert( p!=0 );
151917 assert( p->pWin!=0 );
151918
151919 /* If this function is being called from within a scalar sub-select
151920 ** that used by the SELECT statement being processed, only process
151921 ** TK_COLUMN expressions that refer to it (the outer SELECT). Do
151922 ** not process aggregates or window functions at all, as they belong
151923 ** to the scalar sub-select. */
151924 if( p->pSubSelect ){
151925 if( pExpr->op!=TK_COLUMN ){
151926 return WRC_Continue;
151927 }else{
151928 int nSrc = p->pSrc->nSrc;
151929 int i;
151930 for(i=0; i<nSrc; i++){
151931 if( pExpr->iTable==p->pSrc->a[i].iCursor ) break;
151932 }
151933 if( i==nSrc ) return WRC_Continue;
151934 }
151935 }
151936
151937 switch( pExpr->op ){
151938
151939 case TK_FUNCTION:
151940 if( !ExprHasProperty(pExpr, EP_WinFunc) ){
151941 break;
151942 }else{
151943 Window *pWin;
151944 for(pWin=p->pWin; pWin; pWin=pWin->pNextWin){
151945 if( pExpr->y.pWin==pWin ){
151946 assert( pWin->pOwner==pExpr );
151947 return WRC_Prune;
151948 }
151949 }
151950 }
151951 /* no break */ deliberate_fall_through
151952
151953 case TK_AGG_FUNCTION:
151954 case TK_COLUMN: {
151955 int iCol = -1;
151956 if( p->pSub ){
151957 int i;
151958 for(i=0; i<p->pSub->nExpr; i++){
151959 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
151960 iCol = i;
151961 break;
151962 }
151963 }
151964 }
151965 if( iCol<0 ){
151966 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
151967 if( pDup && pDup->op==TK_AGG_FUNCTION ) pDup->op = TK_FUNCTION;
151968 p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
151969 }
151970 if( p->pSub ){
151971 int f = pExpr->flags & EP_Collate;
151972 assert( ExprHasProperty(pExpr, EP_Static)==0 );
151973 ExprSetProperty(pExpr, EP_Static);
151974 sqlite3ExprDelete(pParse->db, pExpr);
151976 memset(pExpr, 0, sizeof(Expr));
151977
151978 pExpr->op = TK_COLUMN;
151979 pExpr->iColumn = (iCol<0 ? p->pSub->nExpr-1: iCol);
151980 pExpr->iTable = p->pWin->iEphCsr;
151981 pExpr->y.pTab = p->pTab;
151982 pExpr->flags = f;
151983 }
151984 if( pParse->db->mallocFailed ) return WRC_Abort;
151985 break;
151986 }
151987
struct WindowRewrite * pRewrite
Definition sqlite3.c:19109
Select * pSubSelect
Definition sqlite3.c:151899
int iEphCsr
Definition sqlite3.c:19206

References ExprList::a, SrcList::a, Parse::db, deliberate_fall_through, EP_Collate, EP_Static, EP_WinFunc, ExprClearProperty, ExprHasProperty, ExprSetProperty, Expr::flags, Expr::iColumn, SrcList::SrcList_item::iCursor, Window::iEphCsr, Expr::iTable, sqlite3::mallocFailed, ExprList::nExpr, SrcList::nSrc, Expr::op, ExprList::ExprList_item::pExpr, Window::pNextWin, Window::pOwner, Walker::pParse, Walker::pRewrite, WindowRewrite::pSrc, WindowRewrite::pSub, WindowRewrite::pSubSelect, Expr::pTab, WindowRewrite::pTab, Expr::pWin, WindowRewrite::pWin, sqlite3ExprCompare(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprListAppend(), TK_AGG_FUNCTION, TK_COLUMN, TK_FUNCTION, Walker::u, WRC_Abort, WRC_Continue, WRC_Prune, and Expr::y.

Referenced by selectWindowRewriteEList().

◆ selectWindowRewriteSelectCb()

static int selectWindowRewriteSelectCb ( Walker * pWalker,
Select * pSelect )
static

Definition at line 151988 of file sqlite3.c.

151988 : /* no-op */
151989 break;
151990 }
151991
151992 return WRC_Continue;
151993}
151994static int selectWindowRewriteSelectCb(Walker *pWalker, Select *pSelect){
151995 struct WindowRewrite *p = pWalker->u.pRewrite;
151996 Select *pSave = p->pSubSelect;
151997 if( pSave==pSelect ){
151998 return WRC_Continue;
151999 }else{

Referenced by selectWindowRewriteEList().

◆ serialGet()

static u32 serialGet ( const unsigned char * buf,
u32 serial_type,
Mem * pMem )
static

Definition at line 81587 of file sqlite3.c.

81597 {
81598 u64 x = FOUR_BYTE_UINT(buf);
81599 u32 y = FOUR_BYTE_UINT(buf+4);
81600 x = (x<<32) + y;
81601 if( serial_type==6 ){
81602 /* EVIDENCE-OF: R-29851-52272 Value is a big-endian 64-bit
81603 ** twos-complement integer. */
81604 pMem->u.i = *(i64*)&x;
81605 pMem->flags = MEM_Int;
81606 testcase( pMem->u.i<0 );
81607 }else{
81608 /* EVIDENCE-OF: R-57343-49114 Value is a big-endian IEEE 754-2008 64-bit
81609 ** floating point number. */
81610#if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT)
81611 /* Verify that integers and floating point values use the same
81612 ** byte order. Or, that if SQLITE_MIXED_ENDIAN_64BIT_FLOAT is
81613 ** defined that 64-bit floating point values really are mixed
81614 ** endian.
81615 */
81616 static const u64 t1 = ((u64)0x3ff00000)<<32;
81617 static const double r1 = 1.0;
81618 u64 t2 = t1;
81620 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
81621#endif
81622 assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 );
#define swapMixedEndianFloat(X)
Definition sqlite3.c:81517
#define FOUR_BYTE_UINT(x)
Definition sqlite3.c:81575

References sqlite3_value::flags, FOUR_BYTE_UINT, sqlite3_value::MemValue::i, MEM_Int, sqlite3_value::MemValue::r, swapMixedEndianFloat, testcase, and sqlite3_value::u.

◆ setAllPagerFlags()

static void setAllPagerFlags ( sqlite3 * db)
static

Definition at line 125950 of file sqlite3.c.

125956 {
125957 if( db->autoCommit ){
125958 Db *pDb = db->aDb;
125959 int n = db->nDb;
125964 == PAGER_FLAGS_MASK );
125965 assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level );
125966 while( (n--) > 0 ){
125967 if( pDb->pBt ){
#define PAGER_CACHESPILL
Definition sqlite3.c:14856
#define PAGER_FULLFSYNC
Definition sqlite3.c:14854
#define PAGER_CKPT_FULLFSYNC
Definition sqlite3.c:14855
#define PAGER_SYNCHRONOUS_MASK
Definition sqlite3.c:14853
#define SQLITE_FullFSync
Definition sqlite3.c:16981

References sqlite3::aDb, sqlite3::autoCommit, sqlite3::flags, sqlite3::nDb, PAGER_CACHESPILL, PAGER_CKPT_FULLFSYNC, PAGER_FLAGS_MASK, PAGER_FULLFSYNC, PAGER_SYNCHRONOUS_MASK, Db::pBt, Db::safety_level, sqlite3BtreeSetPagerFlags(), SQLITE_CacheSpill, SQLITE_CkptFullFSync, and SQLITE_FullFSync.

Referenced by sqlite3Pragma().

◆ setChildPtrmaps()

static int setChildPtrmaps ( MemPage * pPage)
static

Definition at line 68030 of file sqlite3.c.

68036 {
68037 int i; /* Counter variable */
68038 int nCell; /* Number of cells in page pPage */
68039 int rc; /* Return code */
68040 BtShared *pBt = pPage->pBt;
68041 Pgno pgno = pPage->pgno;
68042
68043 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68044 rc = pPage->isInit ? SQLITE_OK : btreeInitPage(pPage);
68045 if( rc!=SQLITE_OK ) return rc;
68046 nCell = pPage->nCell;
68047
68048 for(i=0; i<nCell; i++){
68049 u8 *pCell = findCell(pPage, i);
68050
68051 ptrmapPutOvflPtr(pPage, pPage, pCell, &rc);
68052
68053 if( !pPage->leaf ){
68054 Pgno childPgno = get4byte(pCell);
68055 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
68056 }
68057 }
68058
68059 if( !pPage->leaf ){

References MemPage::aData, btreeInitPage(), findCell, get4byte, MemPage::hdrOffset, MemPage::isInit, MemPage::leaf, BtShared::mutex, MemPage::nCell, MemPage::pBt, MemPage::pgno, PTRMAP_BTREE, ptrmapPut(), ptrmapPutOvflPtr(), sqlite3_mutex_held(), and SQLITE_OK.

Referenced by copyNodeContent(), and relocatePage().

◆ setDateTimeToCurrent()

static int setDateTimeToCurrent ( sqlite3_context * context,
DateTime * p )
static

Definition at line 22047 of file sqlite3.c.

22052 {
22053 p->iJD = sqlite3StmtCurrentTime(context);
22054 if( p->iJD>0 ){
22055 p->validJD = 1;
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *)
Definition sqlite3.c:83825

References DateTime::iJD, sqlite3StmtCurrentTime(), and DateTime::validJD.

Referenced by isDate(), and parseDateOrTime().

◆ setDestPgsz()

static int setDestPgsz ( sqlite3_backup * p)
static

Definition at line 75163 of file sqlite3.c.

◆ setDeviceCharacteristics()

static void setDeviceCharacteristics ( unixFile * pFd)
static

Definition at line 37604 of file sqlite3.c.

37610 {
37611 assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 );
37612 if( pFd->sectorSize==0 ){
37613#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
37614 int res;
37615 u32 f = 0;
37616
37617 /* Check for support for F2FS atomic batch writes. */
37618 res = osIoctl(pFd->h, F2FS_IOC_GET_FEATURES, &f);
37619 if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){
37621 }
37622#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
37623
37624 /* Set the POWERSAFE_OVERWRITE flag if requested. */
37625 if( pFd->ctrlFlags & UNIXFILE_PSOW ){
int deviceCharacteristics
Definition sqlite3.c:33583
int sectorSize
Definition sqlite3.c:33582

References unixFile::ctrlFlags, unixFile::deviceCharacteristics, unixFile::h, unixFile::sectorSize, SQLITE_DEFAULT_SECTOR_SIZE, SQLITE_IOCAP_BATCH_ATOMIC, SQLITE_IOCAP_POWERSAFE_OVERWRITE, and UNIXFILE_PSOW.

Referenced by unixDeviceCharacteristics(), and unixSectorSize().

◆ setDoNotMergeFlagOnCopy()

static void setDoNotMergeFlagOnCopy ( Vdbe * v)
static

Definition at line 103376 of file sqlite3.c.

Referenced by sqlite3ExprCodeTarget().

◆ setGetterMethod()

static void setGetterMethod ( Pager * pPager)
static

Definition at line 52746 of file sqlite3.c.

52752 {
52753 if( pPager->errCode ){
52754 pPager->xGet = getPageError;
52755#if SQLITE_MAX_MMAP_SIZE>0
52756 }else if( USEFETCH(pPager) ){
static int getPageError(Pager *, Pgno, DbPage **, int)
Definition sqlite3.c:57326
int(* xGet)(Pager *, Pgno, DbPage **, int)
Definition sqlite3.c:52395

References Pager::errCode, getPageError(), getPageNormal(), USEFETCH, and Pager::xGet.

Referenced by pager_error(), pager_unlock(), sqlite3PagerOpen(), sqlite3PagerRollback(), and sqlite3PagerSavepoint().

◆ setPageReferenced()

static void setPageReferenced ( IntegrityCk * pCheck,
Pgno iPg )
static

Definition at line 74141 of file sqlite3.c.

Referenced by checkRef(), and sqlite3BtreeIntegrityCheck().

◆ setPendingFd()

static void setPendingFd ( unixFile * pFile)
static

Definition at line 35423 of file sqlite3.c.

35429 {
35430 unixInodeInfo *pInode = pFile->pInode;
UnixUnusedFd * pPreallocatedUnused
Definition sqlite3.c:33571

◆ setPragmaResultColumnNames()

static void setPragmaResultColumnNames ( Vdbe * v,
const PragmaName * pPragma )
static

Definition at line 125907 of file sqlite3.c.

125916 {
125917 u8 n = pPragma->nPragCName;
125918 sqlite3VdbeSetNumCols(v, n==0 ? 1 : n);
125919 if( n==0 ){
125921 }else{

Referenced by sqlite3Pragma().

◆ setRawDateNumber()

static void setRawDateNumber ( DateTime * p,
double r )
static

Definition at line 22063 of file sqlite3.c.

22068 {
22069 p->s = r;
22070 p->rawS = 1;

References DateTime::iJD, DateTime::rawS, DateTime::s, and DateTime::validJD.

Referenced by isDate(), and parseDateOrTime().

◆ setResultStrOrError()

static void setResultStrOrError ( sqlite3_context * pCtx,
const char * z,
int n,
u8 enc,
void(*)(void *) xDel )
static

◆ setSectorSize()

static void setSectorSize ( Pager * pPager)
static

Definition at line 54367 of file sqlite3.c.

54373 {
54374 assert( isOpen(pPager->fd) || pPager->tempFile );
54375
54376 if( pPager->tempFile
54377 || (sqlite3OsDeviceCharacteristics(pPager->fd) &
54379 ){
54380 /* Sector size doesn't matter for temporary files. Also, the file
54381 ** may not have been opened yet, in which case the OsSectorSize()
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE
Definition sqlite3.c:1673

References Pager::fd, isOpen, Pager::sectorSize, sqlite3OsDeviceCharacteristics(), sqlite3SectorSize(), SQLITE_IOCAP_POWERSAFE_OVERWRITE, and Pager::tempFile.

Referenced by pager_playback(), and sqlite3PagerOpen().

◆ setSharedCacheTableLock()

static int setSharedCacheTableLock ( Btree * p,
Pgno iTable,
u8 eLock )
static

Definition at line 64826 of file sqlite3.c.

64832 {
64833 BtShared *pBt = p->pBt;
64834 BtLock *pLock = 0;
64835 BtLock *pIter;
64836
64837 assert( sqlite3BtreeHoldsMutex(p) );
64838 assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
64839 assert( p->db!=0 );
64840
64841 /* A connection with the read-uncommitted flag set will never try to
64842 ** obtain a read-lock using this function. The only read-lock obtained
64843 ** by a connection in read-uncommitted mode is on the sqlite_schema
64844 ** table, and that lock is obtained in BtreeBeginTrans(). */
64845 assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
64846
64847 /* This function should only be called on a sharable b-tree after it
64848 ** has been determined that no other b-tree holds a conflicting lock. */
64849 assert( p->sharable );
64850 assert( SQLITE_OK==querySharedCacheTableLock(p, iTable, eLock) );
64851
64852 /* First search the list for an existing lock on this table. */
64853 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
64854 if( pIter->iTable==iTable && pIter->pBtree==p ){
64855 pLock = pIter;
64856 break;
64857 }
64858 }
64859
64860 /* If the above search did not find a BtLock struct associating Btree p
64861 ** with table iTable, allocate one and link it into the list.
64862 */
64863 if( !pLock ){
64864 pLock = (BtLock *)sqlite3MallocZero(sizeof(BtLock));
64865 if( !pLock ){
64866 return SQLITE_NOMEM_BKPT;
64867 }
64868 pLock->iTable = iTable;
64869 pLock->pBtree = p;
64870 pLock->pNext = pBt->pLock;
64871 pBt->pLock = pLock;
64872 }
64873
64874 /* Set the BtLock.eLock variable to the maximum of the current lock
64875 ** and the requested lock. This means if a write-lock was already held
64876 ** and a read-lock requested, we don't incorrectly downgrade the lock.
64877 */
64878 assert( WRITE_LOCK>READ_LOCK );
static int querySharedCacheTableLock(Btree *p, Pgno iTab, u8 eLock)
Definition sqlite3.c:64754

References Btree::db, BtLock::eLock, sqlite3::flags, BtLock::iTable, Btree::pBt, BtLock::pBtree, BtShared::pLock, BtLock::pNext, querySharedCacheTableLock(), READ_LOCK, Btree::sharable, sqlite3MallocZero(), SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_ReadUncommit, and WRITE_LOCK.

Referenced by sqlite3BtreeLockTable().

◆ setStrAccumError()

static void setStrAccumError ( StrAccum * p,
u8 eError )
static

Definition at line 28276 of file sqlite3.c.

Referenced by printfTempBuf(), and sqlite3StrAccumEnlarge().

◆ setupLookaside()

static int setupLookaside ( sqlite3 * db,
void * pBuf,
int sz,
int cnt )
static

Definition at line 161743 of file sqlite3.c.

161749 {
161750#ifndef SQLITE_OMIT_LOOKASIDE
161751 void *pStart;
161752 sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
161753 int nBig; /* Number of full-size slots */
161754 int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
161755
161756 if( sqlite3LookasideUsed(db,0)>0 ){
161757 return SQLITE_BUSY;
161758 }
161759 /* Free any existing lookaside buffer for this handle before
161760 ** allocating a new one so we don't have to have space for
161761 ** both at the same time.
161762 */
161763 if( db->lookaside.bMalloced ){
161765 }
161766 /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
161767 ** than a pointer to be useful.
161768 */
161769 sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
161770 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
161771 if( cnt<0 ) cnt = 0;
161772 if( sz==0 || cnt==0 ){
161773 sz = 0;
161774 pStart = 0;
161775 }else if( pBuf==0 ){
161777 pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */
161779 if( pStart ) szAlloc = sqlite3MallocSize(pStart);
161780 }else{
161781 pStart = pBuf;
161782 }
161783#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
161784 if( sz>=LOOKASIDE_SMALL*3 ){
161785 nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
161786 nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
161787 }else if( sz>=LOOKASIDE_SMALL*2 ){
161788 nBig = szAlloc/(LOOKASIDE_SMALL+sz);
161789 nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
161790 }else
161791#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
161792 if( sz>0 ){
161793 nBig = szAlloc/sz;
161794 nSm = 0;
161795 }else{
161796 nBig = nSm = 0;
161797 }
161798 db->lookaside.pStart = pStart;
161799 db->lookaside.pInit = 0;
161800 db->lookaside.pFree = 0;
161801 db->lookaside.sz = (u16)sz;
161802 db->lookaside.szTrue = (u16)sz;
161803 if( pStart ){
161804 int i;
161805 LookasideSlot *p;
161806 assert( sz > (int)sizeof(LookasideSlot*) );
161807 p = (LookasideSlot*)pStart;
161808 for(i=0; i<nBig; i++){
161809 p->pNext = db->lookaside.pInit;
161810 db->lookaside.pInit = p;
161811 p = (LookasideSlot*)&((u8*)p)[sz];
161812 }
161813#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
161814 db->lookaside.pSmallInit = 0;
161815 db->lookaside.pSmallFree = 0;
161816 db->lookaside.pMiddle = p;
161817 for(i=0; i<nSm; i++){
161818 p->pNext = db->lookaside.pSmallInit;
161819 db->lookaside.pSmallInit = p;
161820 p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL];
161821 }
161822#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
161823 assert( ((uptr)p)<=szAlloc + (uptr)pStart );
161824 db->lookaside.pEnd = p;
161825 db->lookaside.bDisable = 0;
161826 db->lookaside.bMalloced = pBuf==0 ?1:0;
161827 db->lookaside.nSlot = nBig+nSm;
161828 }else{
161829 db->lookaside.pStart = db;
161830#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
161831 db->lookaside.pSmallInit = 0;
161832 db->lookaside.pSmallFree = 0;
161833 db->lookaside.pMiddle = db;
161834#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
161835 db->lookaside.pEnd = db;
161836 db->lookaside.bDisable = 1;
161837 db->lookaside.sz = 0;
161838 db->lookaside.bMalloced = 0;
#define LOOKASIDE_SMALL
Definition sqlite3.c:16748
#define ROUNDDOWN8(x)
Definition sqlite3.c:14477
LookasideSlot * pNext
Definition sqlite3.c:16737
LookasideSlot * pInit
Definition sqlite3.c:16725
LookasideSlot * pFree
Definition sqlite3.c:16726
void * pStart
Definition sqlite3.c:16733
LookasideSlot * pSmallInit
Definition sqlite3.c:16728
void * pEnd
Definition sqlite3.c:16734
LookasideSlot * pSmallFree
Definition sqlite3.c:16729
void * pMiddle
Definition sqlite3.c:16730

References Lookaside::bDisable, Lookaside::bMalloced, sqlite3::lookaside, LOOKASIDE_SMALL, Lookaside::nSlot, Lookaside::pEnd, Lookaside::pFree, Lookaside::pInit, Lookaside::pMiddle, LookasideSlot::pNext, Lookaside::pSmallFree, Lookaside::pSmallInit, Lookaside::pStart, ROUNDDOWN8, sqlite3_free(), sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), sqlite3LookasideUsed(), sqlite3Malloc(), sqlite3MallocSize(), SQLITE_BUSY, Lookaside::sz, and Lookaside::szTrue.

Referenced by openDatabase().

◆ sourceidFunc()

static void sourceidFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

◆ sqlite2BtreeKeyCompare()

int sqlite2BtreeKeyCompare ( BtCursor * ,
const void * ,
int ,
int ,
int *  )

◆ sqlite3_aggregate_context()

◆ sqlite3_aggregate_count()

SQLITE_API int sqlite3_aggregate_count ( sqlite3_context * p)

◆ sqlite3_auto_extension()

SQLITE_API int sqlite3_auto_extension ( void(*)(void) xEntryPoint)

Definition at line 124953 of file sqlite3.c.

124961 {
124962 int rc = SQLITE_OK;
124963#ifndef SQLITE_OMIT_AUTOINIT
124964 rc = sqlite3_initialize();
124965 if( rc ){
124966 return rc;
124967 }else
124968#endif
124969 {
124970 u32 i;
124971#if SQLITE_THREADSAFE
124973#endif
124976 for(i=0; i<wsdAutoext.nExt; i++){
124977 if( wsdAutoext.aExt[i]==xInit ) break;
124978 }
124979 if( i==wsdAutoext.nExt ){
124980 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
124981 void (**aNew)(void);
124982 aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
124983 if( aNew==0 ){
124984 rc = SQLITE_NOMEM_BKPT;
124985 }else{
124986 wsdAutoext.aExt = aNew;
124987 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
124988 wsdAutoext.nExt++;
124989 }
SQLITE_API void * sqlite3_realloc64(void *, sqlite3_uint64)
Definition sqlite3.c:27826
#define wsdAutoext
Definition sqlite3.c:124945
#define wsdAutoextInit
Definition sqlite3.c:124944

References mutex, sqlite3_initialize(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_realloc64(), sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_MAIN, SQLITE_NOMEM_BKPT, SQLITE_OK, wsdAutoext, and wsdAutoextInit.

◆ sqlite3_backup_finish()

SQLITE_API int sqlite3_backup_finish ( sqlite3_backup * p)

Definition at line 75625 of file sqlite3.c.

75631 {
75632 sqlite3_backup **pp; /* Ptr to head of pagers backup list */
75633 sqlite3 *pSrcDb; /* Source database connection */
75634 int rc; /* Value to return */
75635
75636 /* Enter the mutexes */
75637 if( p==0 ) return SQLITE_OK;
75638 pSrcDb = p->pSrcDb;
75639 sqlite3_mutex_enter(pSrcDb->mutex);
75641 if( p->pDestDb ){
75643 }
75644
75645 /* Detach this backup from the source pager. */
75646 if( p->pDestDb ){
75647 p->pSrc->nBackup--;
75648 }
75649 if( p->isAttached ){
75651 assert( pp!=0 );
75652 while( *pp!=p ){
75653 pp = &(*pp)->pNext;
75654 assert( pp!=0 );
75655 }
75656 *pp = p->pNext;
75657 }
75658
75659 /* If a transaction is still open on the Btree, roll it back. */
75661
75662 /* Set the error code of the destination database handle. */
75663 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
75664 if( p->pDestDb ){
75665 sqlite3Error(p->pDestDb, rc);
75666
75667 /* Exit the mutexes and free the backup context structure. */
75669 }
75671 if( p->pDestDb ){
75672 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
75673 ** call to sqlite3_backup_init() and is destroyed by a call to
SQLITE_PRIVATE sqlite3_backup ** sqlite3PagerBackupPtr(Pager *)
Definition sqlite3.c:59073
SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *, int, int)
Definition sqlite3.c:68682
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *)
Definition sqlite3.c:162258
int nBackup
Definition sqlite3.c:63821
sqlite3 * pSrcDb
Definition sqlite3.c:75078
sqlite3_backup * pNext
Definition sqlite3.c:75090

Referenced by cleanupbu(), and sqlite3BtreeCopyFile().

◆ sqlite3_backup_init()

SQLITE_API sqlite3_backup * sqlite3_backup_init ( sqlite3 * pDest,
const char * zDestName,
sqlite3 * pSource,
const char * zSourceName )

Definition at line 75191 of file sqlite3.c.

75202 {
75203 sqlite3_backup *p; /* Value to return */
75204
75205#ifdef SQLITE_ENABLE_API_ARMOR
75206 if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){
75207 (void)SQLITE_MISUSE_BKPT;
75208 return 0;
75209 }
75210#endif
75211
75212 /* Lock the source database handle. The destination database
75213 ** handle is not locked in this routine, but it is locked in
75214 ** sqlite3_backup_step(). The user is required to ensure that no
75215 ** other thread accesses the destination handle for the duration
75216 ** of the backup operation. Any attempt to use the destination
75217 ** database connection while a backup is in progress may cause
75218 ** a malfunction or a deadlock.
75219 */
75220 sqlite3_mutex_enter(pSrcDb->mutex);
75221 sqlite3_mutex_enter(pDestDb->mutex);
75222
75223 if( pSrcDb==pDestDb ){
75225 pDestDb, SQLITE_ERROR, "source and destination must be distinct"
75226 );
75227 p = 0;
75228 }else {
75229 /* Allocate space for a new sqlite3_backup object...
75230 ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
75231 ** call to sqlite3_backup_init() and is destroyed by a call to
75232 ** sqlite3_backup_finish(). */
75234 if( !p ){
75236 }
75237 }
75238
75239 /* If the allocation succeeded, populate the new object. */
75240 if( p ){
75241 p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
75242 p->pDest = findBtree(pDestDb, pDestDb, zDestDb);
75243 p->pDestDb = pDestDb;
75244 p->pSrcDb = pSrcDb;
75245 p->iNext = 1;
75246 p->isAttached = 0;
75247
75248 if( 0==p->pSrc || 0==p->pDest
75249 || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
75250 ){
75251 /* One (or both) of the named databases did not exist or an OOM
75252 ** error was hit. Or there is a transaction open on the destination
75253 ** database. The error has already been written into the pDestDb
75254 ** handle. All that is left to do here is free the sqlite3_backup
75255 ** structure. */
75256 sqlite3_free(p);
75257 p = 0;
75258 }
75259 }
75260 if( p ){
75261 p->pSrc->nBackup++;
static Btree * findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb)
Definition sqlite3.c:75132
static int checkReadTransaction(sqlite3 *db, Btree *p)
Definition sqlite3.c:75175

References checkReadTransaction(), findBtree(), sqlite3_backup::iNext, sqlite3_backup::isAttached, sqlite3::mutex, Btree::nBackup, sqlite3_backup::pDest, sqlite3_backup::pDestDb, sqlite3_backup::pSrc, sqlite3_backup::pSrcDb, sqlite3_free(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3Error(), sqlite3ErrorWithMsg(), sqlite3MallocZero(), sqlite3SafetyCheckOk(), SQLITE_ERROR, SQLITE_MISUSE_BKPT, SQLITE_NOMEM_BKPT, and SQLITE_OK.

Referenced by lsqlite_backup_init().

◆ sqlite3_backup_pagecount()

SQLITE_API int sqlite3_backup_pagecount ( sqlite3_backup * p)

Definition at line 75693 of file sqlite3.c.

75699 {
75700#ifdef SQLITE_ENABLE_API_ARMOR
75701 if( p==0 ){

Referenced by dbbu_pagecount().

◆ sqlite3_backup_remaining()

SQLITE_API int sqlite3_backup_remaining ( sqlite3_backup * p)

Definition at line 75679 of file sqlite3.c.

75685 {
75686#ifdef SQLITE_ENABLE_API_ARMOR
75687 if( p==0 ){

Referenced by dbbu_remaining().

◆ sqlite3_backup_step()

SQLITE_API int sqlite3_backup_step ( sqlite3_backup * p,
int nPage )

Definition at line 75371 of file sqlite3.c.

75377 {
75378 int rc;
75379 int destMode; /* Destination journal mode */
75380 int pgszSrc = 0; /* Source page size */
75381 int pgszDest = 0; /* Destination page size */
75382
75383#ifdef SQLITE_ENABLE_API_ARMOR
75384 if( p==0 ) return SQLITE_MISUSE_BKPT;
75385#endif
75388 if( p->pDestDb ){
75390 }
75391
75392 rc = p->rc;
75393 if( !isFatalError(rc) ){
75394 Pager * const pSrcPager = sqlite3BtreePager(p->pSrc); /* Source pager */
75395 Pager * const pDestPager = sqlite3BtreePager(p->pDest); /* Dest pager */
75396 int ii; /* Iterator variable */
75397 int nSrcPage = -1; /* Size of source db in pages */
75398 int bCloseTrans = 0; /* True if src db requires unlocking */
75399
75400 /* If the source pager is currently in a write-transaction, return
75401 ** SQLITE_BUSY immediately.
75402 */
75403 if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
75404 rc = SQLITE_BUSY;
75405 }else{
75406 rc = SQLITE_OK;
75407 }
75408
75409 /* If there is no open read-transaction on the source database, open
75410 ** one now. If a transaction is opened here, then it will be closed
75411 ** before this function exits.
75412 */
75413 if( rc==SQLITE_OK && 0==sqlite3BtreeIsInReadTrans(p->pSrc) ){
75414 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
75415 bCloseTrans = 1;
75416 }
75417
75418 /* If the destination database has not yet been locked (i.e. if this
75419 ** is the first call to backup_step() for the current backup operation),
75420 ** try to set its page size to the same as the source database. This
75421 ** is especially important on ZipVFS systems, as in that case it is
75422 ** not possible to create a database file that uses one page size by
75423 ** writing to it with another. */
75424 if( p->bDestLocked==0 && rc==SQLITE_OK && setDestPgsz(p)==SQLITE_NOMEM ){
75425 rc = SQLITE_NOMEM;
75426 }
75427
75428 /* Lock the destination database, if it is not locked already. */
75429 if( SQLITE_OK==rc && p->bDestLocked==0
75430 && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2,
75431 (int*)&p->iDestSchema))
75432 ){
75433 p->bDestLocked = 1;
75434 }
75435
75436 /* Do not allow backup if the destination database is in WAL mode
75437 ** and the page sizes are different between source and destination */
75438 pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
75439 pgszDest = sqlite3BtreeGetPageSize(p->pDest);
75441 if( SQLITE_OK==rc && destMode==PAGER_JOURNALMODE_WAL && pgszSrc!=pgszDest ){
75442 rc = SQLITE_READONLY;
75443 }
75444
75445 /* Now that there is a read-lock on the source database, query the
75446 ** source pager for the number of pages in the database.
75447 */
75448 nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
75449 assert( nSrcPage>=0 );
75450 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
75451 const Pgno iSrcPg = p->iNext; /* Source page number */
75452 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
75453 DbPage *pSrcPg; /* Source page object */
75454 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
75455 if( rc==SQLITE_OK ){
75456 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
75457 sqlite3PagerUnref(pSrcPg);
75458 }
75459 }
75460 p->iNext++;
75461 }
75462 if( rc==SQLITE_OK ){
75463 p->nPagecount = nSrcPage;
75464 p->nRemaining = nSrcPage+1-p->iNext;
75465 if( p->iNext>(Pgno)nSrcPage ){
75466 rc = SQLITE_DONE;
75467 }else if( !p->isAttached ){
75469 }
75470 }
75471
75472 /* Update the schema version field in the destination database. This
75473 ** is to make sure that the schema-version really does change in
75474 ** the case where the source and destination databases have the
75475 ** same schema version.
75476 */
75477 if( rc==SQLITE_DONE ){
75478 if( nSrcPage==0 ){
75479 rc = sqlite3BtreeNewDb(p->pDest);
75480 nSrcPage = 1;
75481 }
75482 if( rc==SQLITE_OK || rc==SQLITE_DONE ){
75484 }
75485 if( rc==SQLITE_OK ){
75486 if( p->pDestDb ){
75488 }
75489 if( destMode==PAGER_JOURNALMODE_WAL ){
75490 rc = sqlite3BtreeSetVersion(p->pDest, 2);
75491 }
75492 }
75493 if( rc==SQLITE_OK ){
75494 int nDestTruncate;
75495 /* Set nDestTruncate to the final number of pages in the destination
75496 ** database. The complication here is that the destination page
75497 ** size may be different to the source page size.
75498 **
75499 ** If the source page size is smaller than the destination page size,
75500 ** round up. In this case the call to sqlite3OsTruncate() below will
75501 ** fix the size of the file. However it is important to call
75502 ** sqlite3PagerTruncateImage() here so that any pages in the
75503 ** destination file that lie beyond the nDestTruncate page mark are
75504 ** journalled by PagerCommitPhaseOne() before they are destroyed
75505 ** by the file truncation.
75506 */
75507 assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
75508 assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
75509 if( pgszSrc<pgszDest ){
75510 int ratio = pgszDest/pgszSrc;
75511 nDestTruncate = (nSrcPage+ratio-1)/ratio;
75512 if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
75513 nDestTruncate--;
75514 }
75515 }else{
75516 nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
75517 }
75518 assert( nDestTruncate>0 );
75519
75520 if( pgszSrc<pgszDest ){
75521 /* If the source page-size is smaller than the destination page-size,
75522 ** two extra things may need to happen:
75523 **
75524 ** * The destination may need to be truncated, and
75525 **
75526 ** * Data stored on the pages immediately following the
75527 ** pending-byte page in the source database may need to be
75528 ** copied into the destination database.
75529 */
75530 const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
75531 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
75532 Pgno iPg;
75533 int nDstPage;
75534 i64 iOff;
75535 i64 iEnd;
75536
75537 assert( pFile );
75538 assert( nDestTruncate==0
75539 || (i64)nDestTruncate*(i64)pgszDest >= iSize || (
75540 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
75541 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
75542 ));
75543
75544 /* This block ensures that all data required to recreate the original
75545 ** database has been stored in the journal for pDestPager and the
75546 ** journal synced to disk. So at this point we may safely modify
75547 ** the database file in any way, knowing that if a power failure
75548 ** occurs, the original database will be reconstructed from the
75549 ** journal file. */
75550 sqlite3PagerPagecount(pDestPager, &nDstPage);
75551 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
75552 if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){
75553 DbPage *pPg;
75554 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
75555 if( rc==SQLITE_OK ){
75556 rc = sqlite3PagerWrite(pPg);
75557 sqlite3PagerUnref(pPg);
75558 }
75559 }
75560 }
75561 if( rc==SQLITE_OK ){
75562 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
75563 }
75564
75565 /* Write the extra pages and truncate the database file as required */
75566 iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
75567 for(
75568 iOff=PENDING_BYTE+pgszSrc;
75569 rc==SQLITE_OK && iOff<iEnd;
75570 iOff+=pgszSrc
75571 ){
75572 PgHdr *pSrcPg = 0;
75573 const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
75574 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg, 0);
75575 if( rc==SQLITE_OK ){
75576 u8 *zData = sqlite3PagerGetData(pSrcPg);
75577 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
75578 }
75579 sqlite3PagerUnref(pSrcPg);
75580 }
75581 if( rc==SQLITE_OK ){
75582 rc = backupTruncateFile(pFile, iSize);
75583 }
75584
75585 /* Sync the database file to disk. */
75586 if( rc==SQLITE_OK ){
75587 rc = sqlite3PagerSync(pDestPager, 0);
75588 }
75589 }else{
75590 sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
75591 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
75592 }
75593
75594 /* Finish committing the transaction to the destination database. */
75595 if( SQLITE_OK==rc
75597 ){
75598 rc = SQLITE_DONE;
75599 }
75600 }
75601 }
75602
75603 /* If bCloseTrans is true, then this function opened a read transaction
75604 ** on the source database. Close the read transaction here. There is
75605 ** no need to check the return values of the btree methods here, as
75606 ** "committing" a read-only transaction cannot fail.
75607 */
75608 if( bCloseTrans ){
75609 TESTONLY( int rc2 );
75610 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
75611 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
75612 assert( rc2==SQLITE_OK );
75613 }
75614
75615 if( rc==SQLITE_IOERR_NOMEM ){
75616 rc = SQLITE_NOMEM_BKPT;
75617 }
75618 p->rc = rc;
75619 }
75620 if( p->pDestDb ){
SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p)
Definition sqlite3.c:67806
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *, const char *)
Definition sqlite3.c:68473
static int backupTruncateFile(sqlite3_file *pFile, i64 iSize)
Definition sqlite3.c:75346
SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion)
Definition sqlite3.c:74979
static void attachBackupObject(sqlite3_backup *p)
Definition sqlite3.c:75359
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *, int)
Definition sqlite3.c:68562
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *, Pgno)
Definition sqlite3.c:55627
static int setDestPgsz(sqlite3_backup *p)
Definition sqlite3.c:75163
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager *, const char *zSuper, int)
Definition sqlite3.c:58064
SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager *)
Definition sqlite3.c:59037

Referenced by dbbu_step(), and sqlite3BtreeCopyFile().

◆ sqlite3_bind_blob()

SQLITE_API int sqlite3_bind_blob ( sqlite3_stmt * pStmt,
int i,
const void * zData,
int n,
void(*)(void *) xDel )

Definition at line 84390 of file sqlite3.c.

Referenced by dbvm_bind_blob().

◆ sqlite3_bind_blob64()

SQLITE_API int sqlite3_bind_blob64 ( sqlite3_stmt * pStmt,
int i,
const void * zData,
sqlite3_uint64 nData,
void(*)(void *) xDel )

Definition at line 84402 of file sqlite3.c.

84402 {
84403#ifdef SQLITE_ENABLE_API_ARMOR
84404 if( nData<0 ) return SQLITE_MISUSE_BKPT;
84405#endif
84406 return bindText(pStmt, i, zData, nData, xDel, 0);
84407}
84409 sqlite3_stmt *pStmt,
84410 int i,
84411 const void *zData,
84412 sqlite3_uint64 nData,
84413 void (*xDel)(void*)
84414){
84415 assert( xDel!=SQLITE_DYNAMIC );
#define SQLITE_API
Definition sqlite3.c:1100
sqlite_uint64 sqlite3_uint64
Definition sqlite3.c:1330
SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt *, int, const void *, sqlite3_uint64, void(*)(void *))
Definition sqlite3.c:84402
static int bindText(sqlite3_stmt *pStmt, int i, const void *zData, int nData, void(*xDel)(void *), u8 encoding)
Definition sqlite3.c:84354

References bindText(), and SQLITE_MISUSE_BKPT.

◆ sqlite3_bind_double()

SQLITE_API int sqlite3_bind_double ( sqlite3_stmt * pStmt,
int i,
double rValue )

Definition at line 84416 of file sqlite3.c.

84416 {
84417 return invokeValueDestructor(zData, xDel, 0);
84418 }else{
84419 return bindText(pStmt, i, zData, (int)nData, xDel, 0);
84420 }
84421}
84422SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
84423 int rc;
84424 Vdbe *p = (Vdbe *)pStmt;
84425 rc = vdbeUnbind(p, i);
SQLITE_API int sqlite3_bind_double(sqlite3_stmt *, int, double)
Definition sqlite3.c:84416

References invokeValueDestructor().

Referenced by dbvm_bind_index().

◆ sqlite3_bind_int()

SQLITE_API int sqlite3_bind_int ( sqlite3_stmt * p,
int i,
int iValue )

Definition at line 84426 of file sqlite3.c.

84426 {
84427 sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
84428 sqlite3_mutex_leave(p->db->mutex);
SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *, double)
Definition sqlite3.c:76721

References Vdbe::aVar, Vdbe::db, sqlite3::mutex, sqlite3_mutex_leave(), and sqlite3VdbeMemSetDouble().

Referenced by dbvm_bind_index().

◆ sqlite3_bind_int64()

SQLITE_API int sqlite3_bind_int64 ( sqlite3_stmt * pStmt,
int i,
sqlite3_int64 iValue )

Definition at line 84429 of file sqlite3.c.

84432 {
84433 return sqlite3_bind_int64(p, i, (i64)iValue);
84434}
84435SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
84436 int rc;
84437 Vdbe *p = (Vdbe *)pStmt;
84438 rc = vdbeUnbind(p, i);
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *, int, sqlite3_int64)
Definition sqlite3.c:84429

Referenced by dbvm_bind_index().

◆ sqlite3_bind_null()

SQLITE_API int sqlite3_bind_null ( sqlite3_stmt * pStmt,
int i )

Definition at line 84439 of file sqlite3.c.

84439 {
84440 sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
84441 sqlite3_mutex_leave(p->db->mutex);
84442 }
84443 return rc;
84444}
84445SQLITE_API int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
84446 int rc;
84447 Vdbe *p = (Vdbe*)pStmt;
SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *, i64)
Definition sqlite3.c:76686
SQLITE_API int sqlite3_bind_null(sqlite3_stmt *, int)
Definition sqlite3.c:84439

References Vdbe::aVar, Vdbe::db, sqlite3::mutex, sqlite3_mutex_leave(), and sqlite3VdbeMemSetInt64().

Referenced by dbvm_bind_index().

◆ sqlite3_bind_parameter_count()

SQLITE_API int sqlite3_bind_parameter_count ( sqlite3_stmt * pStmt)

◆ sqlite3_bind_parameter_index()

SQLITE_API int sqlite3_bind_parameter_index ( sqlite3_stmt * pStmt,
const char * zName )

Definition at line 84588 of file sqlite3.c.

84590 {

References nName, Vdbe::pVList, sqlite3VListNameToNum(), and zName.

◆ sqlite3_bind_parameter_name()

SQLITE_API const char * sqlite3_bind_parameter_name ( sqlite3_stmt * pStmt,
int i )

Definition at line 84573 of file sqlite3.c.

References Vdbe::pVList, and sqlite3VListNumToName().

Referenced by dbvm_bind_names(), and dbvm_bind_parameter_name().

◆ sqlite3_bind_pointer()

SQLITE_API int sqlite3_bind_pointer ( sqlite3_stmt * pStmt,
int i,
void * pPtr,
const char * zPTtype,
void(*)(void *) xDestructor )

Definition at line 84448 of file sqlite3.c.

84449 {
84450 sqlite3_mutex_leave(p->db->mutex);
84451 }
84452 return rc;
84453}
84455 sqlite3_stmt *pStmt,
84456 int i,
84457 void *pPtr,
84458 const char *zPTtype,
84459 void (*xDestructor)(void*)
84460){
84461 int rc;
84462 Vdbe *p = (Vdbe*)pStmt;
84463 rc = vdbeUnbind(p, i);
84464 if( rc==SQLITE_OK ){
84465 sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt *, int, void *, const char *, void(*)(void *))
Definition sqlite3.c:84448
SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem *, void *, const char *, void(*)(void *))
Definition sqlite3.c:76702

◆ sqlite3_bind_text()

SQLITE_API int sqlite3_bind_text ( sqlite3_stmt * pStmt,
int i,
const char * zData,
int nData,
void(*)(void *) xDel )

Definition at line 84466 of file sqlite3.c.

84467 {
84468 xDestructor(pPtr);
84469 }
84470 return rc;
84471}
84473 sqlite3_stmt *pStmt,
84474 int i,
SQLITE_API int sqlite3_bind_text(sqlite3_stmt *, int, const char *, int, void(*)(void *))
Definition sqlite3.c:84466

Referenced by dbvm_bind_index().

◆ sqlite3_bind_text16()

SQLITE_API int sqlite3_bind_text16 ( sqlite3_stmt * pStmt,
int i,
const void * zData,
int nData,
void(*)(void *) xDel )

Definition at line 84492 of file sqlite3.c.

84492 {
84493 if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
84494 return bindText(pStmt, i, zData, (int)nData, xDel, enc);
84495 }
84496}
84497#ifndef SQLITE_OMIT_UTF16
84499 sqlite3_stmt *pStmt,
84500 int i,
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt *, int, const void *, int, void(*)(void *))
Definition sqlite3.c:84492

◆ sqlite3_bind_text64()

SQLITE_API int sqlite3_bind_text64 ( sqlite3_stmt * pStmt,
int i,
const char * zData,
sqlite3_uint64 nData,
void(*)(void *) xDel,
unsigned char encoding )

Definition at line 84475 of file sqlite3.c.

84478 {
84479 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
84480}
84482 sqlite3_stmt *pStmt,
84483 int i,
84484 const char *zData,
84485 sqlite3_uint64 nData,
84486 void (*xDel)(void*),
84487 unsigned char enc
84488){
84489 assert( xDel!=SQLITE_DYNAMIC );
84490 if( nData>0x7fffffff ){
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt *, int, const char *, sqlite3_uint64, void(*)(void *), unsigned char encoding)
Definition sqlite3.c:84475

References bindText(), and SQLITE_UTF8.

◆ sqlite3_bind_value()

SQLITE_API int sqlite3_bind_value ( sqlite3_stmt * pStmt,
int i,
const sqlite3_value * pValue )

Definition at line 84502 of file sqlite3.c.

84504 {
84505 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
84506}
84507#endif /* SQLITE_OMIT_UTF16 */
84508SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
84509 int rc;
84510 switch( sqlite3_value_type((sqlite3_value*)pValue) ){
84511 case SQLITE_INTEGER: {
84512 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
84513 break;
84514 }
84515 case SQLITE_FLOAT: {
84516 rc = sqlite3_bind_double(pStmt, i, pValue->u.r);
84517 break;
84518 }
84519 case SQLITE_BLOB: {
84520 if( pValue->flags & MEM_Zero ){
84521 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
84522 }else{
84523 rc = sqlite3_bind_blob(pStmt, i, pValue->z, pValue->n,SQLITE_TRANSIENT);
84524 }
84525 break;
84526 }
84527 case SQLITE_TEXT: {
84528 rc = bindText(pStmt,i, pValue->z, pValue->n, SQLITE_TRANSIENT,
84529 pValue->enc);
84530 break;
84531 }
84532 default: {
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt *, int, const void *, int n, void(*)(void *))
Definition sqlite3.c:84390
SQLITE_API int sqlite3_bind_value(sqlite3_stmt *, int, const sqlite3_value *)
Definition sqlite3.c:84502
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *, int, int n)
Definition sqlite3.c:84533

References bindText(), and SQLITE_UTF16NATIVE.

◆ sqlite3_bind_zeroblob()

SQLITE_API int sqlite3_bind_zeroblob ( sqlite3_stmt * pStmt,
int i,
int n )

Definition at line 84533 of file sqlite3.c.

84539 {
84540 int rc;
84541 Vdbe *p = (Vdbe *)pStmt;
84542 rc = vdbeUnbind(p, i);

◆ sqlite3_bind_zeroblob64()

SQLITE_API int sqlite3_bind_zeroblob64 ( sqlite3_stmt * pStmt,
int i,
sqlite3_uint64 n )

Definition at line 84543 of file sqlite3.c.

84543 {
84544 sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
84545 sqlite3_mutex_leave(p->db->mutex);
84546 }
84547 return rc;
84548}
84550 int rc;
84551 Vdbe *p = (Vdbe *)pStmt;
84553 if( n>(u64)p->db->aLimit[SQLITE_LIMIT_LENGTH] ){
84554 rc = SQLITE_TOOBIG;
84555 }else{
84556 assert( (n & 0x7FFFFFFF)==n );
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt *, int, sqlite3_uint64)
Definition sqlite3.c:84543
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *, int)
Definition sqlite3.c:76661

References Vdbe::aVar, Vdbe::db, sqlite3::mutex, sqlite3_mutex_leave(), and sqlite3VdbeMemSetZeroBlob().

◆ sqlite3_blob_bytes()

SQLITE_API int sqlite3_blob_bytes ( sqlite3_blob * pBlob)

Definition at line 93830 of file sqlite3.c.

References Incrblob::nByte, and Incrblob::pStmt.

◆ sqlite3_blob_close()

SQLITE_API int sqlite3_blob_close ( sqlite3_blob * pBlob)

Definition at line 93719 of file sqlite3.c.

93725 {
93726 Incrblob *p = (Incrblob *)pBlob;
93727 int rc;
93728 sqlite3 *db;
93729
93730 if( p ){
93731 sqlite3_stmt *pStmt = p->pStmt;
93732 db = p->db;
93734 sqlite3DbFree(db, p);

◆ sqlite3_blob_open()

SQLITE_API int sqlite3_blob_open ( sqlite3 * db,
const char * zDb,
const char * zTable,
const char * zColumn,
sqlite3_int64 iRow,
int flags,
sqlite3_blob ** ppBlob )

Definition at line 93486 of file sqlite3.c.

93500 {
93501 int nAttempt = 0;
93502 int iCol; /* Index of zColumn in row-record */
93503 int rc = SQLITE_OK;
93504 char *zErr = 0;
93505 Table *pTab;
93506 Incrblob *pBlob = 0;
93507 Parse sParse;
93508
93509#ifdef SQLITE_ENABLE_API_ARMOR
93510 if( ppBlob==0 ){
93511 return SQLITE_MISUSE_BKPT;
93512 }
93513#endif
93514 *ppBlob = 0;
93515#ifdef SQLITE_ENABLE_API_ARMOR
93516 if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
93517 return SQLITE_MISUSE_BKPT;
93518 }
93519#endif
93520 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
93521
93523
93524 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
93525 do {
93526 memset(&sParse, 0, sizeof(Parse));
93527 if( !pBlob ) goto blob_open_out;
93528 sParse.db = db;
93529 sqlite3DbFree(db, zErr);
93530 zErr = 0;
93531
93533 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
93534 if( pTab && IsVirtual(pTab) ){
93535 pTab = 0;
93536 sqlite3ErrorMsg(&sParse, "cannot open virtual table: %s", zTable);
93537 }
93538 if( pTab && !HasRowid(pTab) ){
93539 pTab = 0;
93540 sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
93541 }
93542#ifndef SQLITE_OMIT_VIEW
93543 if( pTab && pTab->pSelect ){
93544 pTab = 0;
93545 sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
93546 }
93547#endif
93548 if( !pTab ){
93549 if( sParse.zErrMsg ){
93550 sqlite3DbFree(db, zErr);
93551 zErr = sParse.zErrMsg;
93552 sParse.zErrMsg = 0;
93553 }
93554 rc = SQLITE_ERROR;
93556 goto blob_open_out;
93557 }
93558 pBlob->pTab = pTab;
93559 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
93560
93561 /* Now search pTab for the exact column. */
93562 for(iCol=0; iCol<pTab->nCol; iCol++) {
93563 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
93564 break;
93565 }
93566 }
93567 if( iCol==pTab->nCol ){
93568 sqlite3DbFree(db, zErr);
93569 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
93570 rc = SQLITE_ERROR;
93572 goto blob_open_out;
93573 }
93574
93575 /* If the value is being opened for writing, check that the
93576 ** column is not indexed, and that it is not part of a foreign key.
93577 */
93578 if( wrFlag ){
93579 const char *zFault = 0;
93580 Index *pIdx;
93581#ifndef SQLITE_OMIT_FOREIGN_KEY
93582 if( db->flags&SQLITE_ForeignKeys ){
93583 /* Check that the column is not part of an FK child key definition. It
93584 ** is not necessary to check if it is part of a parent key, as parent
93585 ** key columns must be indexed. The check below will pick up this
93586 ** case. */
93587 FKey *pFKey;
93588 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
93589 int j;
93590 for(j=0; j<pFKey->nCol; j++){
93591 if( pFKey->aCol[j].iFrom==iCol ){
93592 zFault = "foreign key";
93593 }
93594 }
93595 }
93596 }
93597#endif
93598 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
93599 int j;
93600 for(j=0; j<pIdx->nKeyCol; j++){
93601 /* FIXME: Be smarter about indexes that use expressions */
93602 if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==XN_EXPR ){
93603 zFault = "indexed";
93604 }
93605 }
93606 }
93607 if( zFault ){
93608 sqlite3DbFree(db, zErr);
93609 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
93610 rc = SQLITE_ERROR;
93612 goto blob_open_out;
93613 }
93614 }
93615
93616 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(&sParse);
93617 assert( pBlob->pStmt || db->mallocFailed );
93618 if( pBlob->pStmt ){
93619
93620 /* This VDBE program seeks a btree cursor to the identified
93621 ** db/table/row entry. The reason for using a vdbe program instead
93622 ** of writing code to use the b-tree layer directly is that the
93623 ** vdbe program will take advantage of the various transaction,
93624 ** locking and error handling infrastructure built into the vdbe.
93625 **
93626 ** After seeking the cursor, the vdbe executes an OP_ResultRow.
93627 ** Code external to the Vdbe then "borrows" the b-tree cursor and
93628 ** uses it to implement the blob_read(), blob_write() and
93629 ** blob_bytes() functions.
93630 **
93631 ** The sqlite3_blob_close() function finalizes the vdbe program,
93632 ** which closes the b-tree cursor and (possibly) commits the
93633 ** transaction.
93634 */
93635 static const int iLn = VDBE_OFFSET_LINENO(2);
93636 static const VdbeOpList openBlob[] = {
93637 {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
93638 {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
93639 /* blobSeekToRow() will initialize r[1] to the desired rowid */
93640 {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
93641 {OP_Column, 0, 0, 1}, /* 3 */
93642 {OP_ResultRow, 1, 0, 0}, /* 4 */
93643 {OP_Halt, 0, 0, 0}, /* 5 */
93644 };
93645 Vdbe *v = (Vdbe *)pBlob->pStmt;
93646 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
93647 VdbeOp *aOp;
93648
93649 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag,
93650 pTab->pSchema->schema_cookie,
93651 pTab->pSchema->iGeneration);
93652 sqlite3VdbeChangeP5(v, 1);
93653 assert( sqlite3VdbeCurrentAddr(v)==2 || db->mallocFailed );
93654 aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
93655
93656 /* Make sure a mutex is held on the table to be accessed */
93657 sqlite3VdbeUsesBtree(v, iDb);
93658
93659 if( db->mallocFailed==0 ){
93660 assert( aOp!=0 );
93661 /* Configure the OP_TableLock instruction */
93662#ifdef SQLITE_OMIT_SHARED_CACHE
93663 aOp[0].opcode = OP_Noop;
93664#else
93665 aOp[0].p1 = iDb;
93666 aOp[0].p2 = pTab->tnum;
93667 aOp[0].p3 = wrFlag;
93669 }
93670 if( db->mallocFailed==0 ){
93671#endif
93672
93673 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
93674 ** parameter of the other to pTab->tnum. */
93675 if( wrFlag ) aOp[1].opcode = OP_OpenWrite;
93676 aOp[1].p2 = pTab->tnum;
93677 aOp[1].p3 = iDb;
93678
93679 /* Configure the number of columns. Configure the cursor to
93680 ** think that the table has one more column than it really
93681 ** does. An OP_Column to retrieve this imaginary column will
93682 ** always return an SQL NULL. This is useful because it means
93683 ** we can invoke OP_Column to fill in the vdbe cursors type
93684 ** and offset cache without causing any IO.
93685 */
93686 aOp[1].p4type = P4_INT32;
93687 aOp[1].p4.i = pTab->nCol+1;
93688 aOp[3].p2 = pTab->nCol;
93689
93690 sParse.nVar = 0;
93691 sParse.nMem = 1;
93692 sParse.nTab = 1;
93693 sqlite3VdbeMakeReady(v, &sParse);
93694 }
93695 }
93696
93697 pBlob->iCol = iCol;
93698 pBlob->db = db;
93700 if( db->mallocFailed ){
93701 goto blob_open_out;
93702 }
93703 rc = blobSeekToRow(pBlob, iRow, &zErr);
93704 } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
93705
93706blob_open_out:
93707 if( rc==SQLITE_OK && db->mallocFailed==0 ){
93708 *ppBlob = (sqlite3_blob *)pBlob;
93709 }else{
93710 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
93711 sqlite3DbFree(db, pBlob);
93712 }
93713 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe *, Parse *)
Definition sqlite3.c:80075
struct sqlite3_blob sqlite3_blob
Definition sqlite3.c:8124
#define SQLITE_MAX_SCHEMA_RETRY
Definition sqlite3.c:20730
#define P4_TRANSIENT
Definition sqlite3.c:15505
#define OP_TableLock
Definition sqlite3.c:15727
SQLITE_PRIVATE Vdbe * sqlite3VdbeCreate(Parse *)
Definition sqlite3.c:77757
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *, int)
Definition sqlite3.c:79490
#define P4_INT32
Definition sqlite3.c:15508
static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr)
Definition sqlite3.c:93421
ynVar nVar
Definition sqlite3.c:18748
int iGeneration
Definition sqlite3.c:16632

◆ sqlite3_blob_read()

SQLITE_API int sqlite3_blob_read ( sqlite3_blob * pBlob,
void * Z,
int N,
int iOffset )

Definition at line 93813 of file sqlite3.c.

◆ sqlite3_blob_reopen()

SQLITE_API int sqlite3_blob_reopen ( sqlite3_blob * pBlob,
sqlite3_int64 iRow )

Definition at line 93845 of file sqlite3.c.

93851 {
93852 int rc;
93853 Incrblob *p = (Incrblob *)pBlob;
93854 sqlite3 *db;
93855
93856 if( p==0 ) return SQLITE_MISUSE_BKPT;
93857 db = p->db;
93859
93860 if( p->pStmt==0 ){
93861 /* If there is no statement handle, then the blob-handle has
93862 ** already been invalidated. Return SQLITE_ABORT in this case.
93863 */
93864 rc = SQLITE_ABORT;
93865 }else{
93866 char *zErr;
93867 rc = blobSeekToRow(p, iRow, &zErr);
93868 if( rc!=SQLITE_OK ){
93869 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
93870 sqlite3DbFree(db, zErr);
93871 }
93872 assert( rc!=SQLITE_SCHEMA );
93873 }

References blobSeekToRow(), Incrblob::db, sqlite3::mutex, Incrblob::pStmt, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3DbFree(), sqlite3ErrorWithMsg(), SQLITE_ABORT, SQLITE_MISUSE_BKPT, SQLITE_OK, and SQLITE_SCHEMA.

◆ sqlite3_blob_write()

SQLITE_API int sqlite3_blob_write ( sqlite3_blob * pBlob,
const void * z,
int n,
int iOffset )

Definition at line 93820 of file sqlite3.c.

◆ sqlite3_busy_handler()

SQLITE_API int sqlite3_busy_handler ( sqlite3 * db,
int(*)(void *, int) xBusy,
void * pArg )

Definition at line 162677 of file sqlite3.c.

162687 {
162688#ifdef SQLITE_ENABLE_API_ARMOR
162689 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
162690#endif
162692 db->busyHandler.xBusyHandler = xBusy;
int(* xBusyHandler)(void *, int)
Definition sqlite3.c:14565
BusyHandler busyHandler
Definition sqlite3.c:16925

Referenced by db_busy_handler(), and sqlite3_busy_timeout().

◆ sqlite3_busy_timeout()

SQLITE_API int sqlite3_busy_timeout ( sqlite3 * db,
int ms )

Definition at line 162731 of file sqlite3.c.

162737 {
162738#ifdef SQLITE_ENABLE_API_ARMOR
162739 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
162740#endif
162741 if( ms>0 ){
162742 sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
162743 (void*)db);
SQLITE_API int sqlite3_busy_handler(sqlite3 *, int(*)(void *, int), void *)
Definition sqlite3.c:162677
static int sqliteDefaultBusyCallback(void *ptr, int count)
Definition sqlite3.c:162609

References sqlite3_busy_handler(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, and sqliteDefaultBusyCallback().

Referenced by db_busy_timeout(), and sqlite3Pragma().

◆ sqlite3_cancel_auto_extension()

SQLITE_API int sqlite3_cancel_auto_extension ( void(*)(void) xEntryPoint)

Definition at line 125000 of file sqlite3.c.

125008 {
125009#if SQLITE_THREADSAFE
125011#endif
125012 int i;
125013 int n = 0;
125016 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
125017 if( wsdAutoext.aExt[i]==xInit ){
125018 wsdAutoext.nExt--;
125019 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
125020 n++;

References mutex, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_MAIN, wsdAutoext, and wsdAutoextInit.

◆ sqlite3_changes()

SQLITE_API int sqlite3_changes ( sqlite3 * db)

Definition at line 162082 of file sqlite3.c.

162088 {
162089#ifdef SQLITE_ENABLE_API_ARMOR
162090 if( !sqlite3SafetyCheckOk(db) ){

Referenced by changes(), and db_changes().

◆ sqlite3_clear_bindings()

SQLITE_API int sqlite3_clear_bindings ( sqlite3_stmt * pStmt)

Definition at line 83128 of file sqlite3.c.

83134 {
83135 int i;
83136 int rc = SQLITE_OK;
83137 Vdbe *p = (Vdbe*)pStmt;
83138#if SQLITE_THREADSAFE
83139 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
83140#endif
83142 for(i=0; i<p->nVar; i++){
83144 p->aVar[i].flags = MEM_Null;
83145 }
83146 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
#define SQLITE_PREPARE_SAVESQL
Definition sqlite3.c:15792
ynVar nVar
Definition sqlite3.c:21087
u32 expmask
Definition sqlite3.c:21146
u8 prepFlags
Definition sqlite3.c:21125

◆ sqlite3_close()

SQLITE_API int sqlite3_close ( sqlite3 * db)

Definition at line 162246 of file sqlite3.c.

Referenced by cleanupdb(), and openDatabase().

◆ sqlite3_close_v2()

SQLITE_API int sqlite3_close_v2 ( sqlite3 * db)

Definition at line 162247 of file sqlite3.c.

References sqlite3Close().

◆ sqlite3_collation_needed()

SQLITE_API int sqlite3_collation_needed ( sqlite3 * db,
void * pCollNeededArg,
void(*)(void *, sqlite3 *, int eTextRep, const char *) xCollNeeded )

Definition at line 164507 of file sqlite3.c.

164517 {
164518#ifdef SQLITE_ENABLE_API_ARMOR
164519 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
164520#endif

References sqlite3::mutex, sqlite3::pCollNeededArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_OK, sqlite3::xCollNeeded, and sqlite3::xCollNeeded16.

◆ sqlite3_collation_needed16()

SQLITE_API int sqlite3_collation_needed16 ( sqlite3 * db,
void * pCollNeededArg,
void(*)(void *, sqlite3 *, int eTextRep, const void *) xCollNeeded16 )

Definition at line 164528 of file sqlite3.c.

164538 {
164539#ifdef SQLITE_ENABLE_API_ARMOR
164540 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
164541#endif

References sqlite3::mutex, sqlite3::pCollNeededArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_OK, sqlite3::xCollNeeded, and sqlite3::xCollNeeded16.

◆ sqlite3_column_blob()

SQLITE_API const void * sqlite3_column_blob ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84091 of file sqlite3.c.

84097 {
84098 const void *val;
84099 val = sqlite3_value_blob( columnMem(pStmt,i) );
84100 /* Even though there is no encoding conversion, value_blob() might
static Mem * columnMem(sqlite3_stmt *pStmt, int i)
Definition sqlite3.c:84036

Referenced by vm_push_column().

◆ sqlite3_column_bytes()

SQLITE_API int sqlite3_column_bytes ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84101 of file sqlite3.c.

Referenced by vm_push_column().

◆ sqlite3_column_bytes16()

SQLITE_API int sqlite3_column_bytes16 ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84106 of file sqlite3.c.

84107 {
84108 int val = sqlite3_value_bytes( columnMem(pStmt,i) );
84109 columnMallocFailure(pStmt);
84110 return val;
static void columnMallocFailure(sqlite3_stmt *pStmt)
Definition sqlite3.c:84071

◆ sqlite3_column_count()

◆ sqlite3_column_database_name()

SQLITE_API const char * sqlite3_column_database_name ( sqlite3_stmt * ,
int  )

◆ sqlite3_column_database_name16()

SQLITE_API const void * sqlite3_column_database_name16 ( sqlite3_stmt * ,
int  )

◆ sqlite3_column_decltype()

SQLITE_API const char * sqlite3_column_decltype ( sqlite3_stmt * pStmt,
int N )

Definition at line 84241 of file sqlite3.c.

Referenced by dbvm_get_named_types(), dbvm_get_type(), dbvm_get_types(), and dbvm_get_utypes().

◆ sqlite3_column_decltype16()

SQLITE_API const void * sqlite3_column_decltype16 ( sqlite3_stmt * pStmt,
int N )

Definition at line 84245 of file sqlite3.c.

84247 {

References COLNAME_DECLTYPE, and columnName().

◆ sqlite3_column_double()

SQLITE_API double sqlite3_column_double ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84111 of file sqlite3.c.

84112 {
84113 int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
84114 columnMallocFailure(pStmt);
84115 return val;
SQLITE_API int sqlite3_value_bytes16(sqlite3_value *)
Definition sqlite3.c:83169

Referenced by vm_push_column().

◆ sqlite3_column_int()

SQLITE_API int sqlite3_column_int ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84116 of file sqlite3.c.

84117 {
84118 double val = sqlite3_value_double( columnMem(pStmt,i) );
84119 columnMallocFailure(pStmt);
84120 return val;

◆ sqlite3_column_int64()

SQLITE_API sqlite_int64 sqlite3_column_int64 ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84121 of file sqlite3.c.

84122 {
84123 int val = sqlite3_value_int( columnMem(pStmt,i) );
84124 columnMallocFailure(pStmt);
84125 return val;

Referenced by vm_push_column().

◆ sqlite3_column_name()

SQLITE_API const char * sqlite3_column_name ( sqlite3_stmt * pStmt,
int N )

◆ sqlite3_column_name16()

SQLITE_API const void * sqlite3_column_name16 ( sqlite3_stmt * pStmt,
int N )

Definition at line 84222 of file sqlite3.c.

84224 {

References COLNAME_NAME, and columnName().

◆ sqlite3_column_origin_name()

SQLITE_API const char * sqlite3_column_origin_name ( sqlite3_stmt * ,
int  )

◆ sqlite3_column_origin_name16()

SQLITE_API const void * sqlite3_column_origin_name16 ( sqlite3_stmt * ,
int  )

◆ sqlite3_column_table_name()

SQLITE_API const char * sqlite3_column_table_name ( sqlite3_stmt * ,
int  )

◆ sqlite3_column_table_name16()

SQLITE_API const void * sqlite3_column_table_name16 ( sqlite3_stmt * ,
int  )

◆ sqlite3_column_text()

SQLITE_API const unsigned char * sqlite3_column_text ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84126 of file sqlite3.c.

84127 {
84128 sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
84129 columnMallocFailure(pStmt);
84130 return val;

Referenced by execSql(), sqlite3_exec(), and vm_push_column().

◆ sqlite3_column_text16()

SQLITE_API const void * sqlite3_column_text16 ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84141 of file sqlite3.c.

◆ sqlite3_column_type()

SQLITE_API int sqlite3_column_type ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84147 of file sqlite3.c.

84147 {
84148 const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
84149 columnMallocFailure(pStmt);
84150 return val;
84151}

References columnMallocFailure(), columnMem(), and sqlite3_value_text16().

Referenced by sqlite3_exec(), and vm_push_column().

◆ sqlite3_column_value()

SQLITE_API sqlite3_value * sqlite3_column_value ( sqlite3_stmt * pStmt,
int iCol )

Definition at line 84131 of file sqlite3.c.

84132 {
84133 const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
84134 columnMallocFailure(pStmt);
84135 return val;
84136}
84138 Mem *pOut = columnMem(pStmt, i);
84139 if( pOut->flags&MEM_Static ){
#define MEM_Static
Definition sqlite3.c:20968
SQLITE_API sqlite3_value * sqlite3_column_value(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84131

◆ sqlite3_commit_hook()

SQLITE_API void * sqlite3_commit_hook ( sqlite3 * db,
int(*)(void *) xCallback,
void * pArg )

Definition at line 163156 of file sqlite3.c.

163166 {
163167 void *pOld;
163168
163169#ifdef SQLITE_ENABLE_API_ARMOR
163170 if( !sqlite3SafetyCheckOk(db) ){
163171 (void)SQLITE_MISUSE_BKPT;
163172 return 0;
163173 }
163174#endif

References sqlite3::mutex, sqlite3::pCommitArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, and sqlite3::xCommitCallback.

Referenced by db_commit_hook().

◆ sqlite3_compileoption_get()

SQLITE_API const char * sqlite3_compileoption_get ( int N)

Definition at line 165586 of file sqlite3.c.

165592 {
165593 int nOpt;
165594 const char **azCompileOpt;

Referenced by sqlite3Pragma().

◆ sqlite3_compileoption_used()

SQLITE_API int sqlite3_compileoption_used ( const char * zOptName)

Definition at line 165553 of file sqlite3.c.

165559 {
165560 int i, n;
165561 int nOpt;
165562 const char **azCompileOpt;
165563
165564#if SQLITE_ENABLE_API_ARMOR
165565 if( zOptName==0 ){
165566 (void)SQLITE_MISUSE_BKPT;
165567 return 0;
165568 }
165569#endif
165570
165571 azCompileOpt = sqlite3CompileOptions(&nOpt);
165572
165573 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
165574 n = sqlite3Strlen30(zOptName);
165575
165576 /* Since nOpt is normally in single digits, a linear search is
165577 ** adequate. No need for a binary search. */
165578 for(i=0; i<nOpt; i++){
165579 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
165580 && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
SQLITE_PRIVATE const char ** sqlite3CompileOptions(int *pnOpt)
Definition sqlite3.c:782

References sqlite3CompileOptions(), sqlite3IsIdChar(), sqlite3Strlen30(), sqlite3StrNICmp, and SQLITE_MISUSE_BKPT.

Referenced by compileoptionusedFunc().

◆ sqlite3_complete()

SQLITE_API int sqlite3_complete ( const char * sql)

Definition at line 160710 of file sqlite3.c.

160716 {
160717 u8 state = 0; /* Current state, using numbers defined in header comment */
160718 u8 token; /* Value of the next token */
160719
160720#ifndef SQLITE_OMIT_TRIGGER
160721 /* A complex statement machine used to detect the end of a CREATE TRIGGER
160722 ** statement. This is the normal case.
160723 */
160724 static const u8 trans[8][8] = {
160725 /* Token: */
160726 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
160727 /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
160728 /* 1 START: */ { 1, 1, 2, 3, 4, 2, 2, 2, },
160729 /* 2 NORMAL: */ { 1, 2, 2, 2, 2, 2, 2, 2, },
160730 /* 3 EXPLAIN: */ { 1, 3, 3, 2, 4, 2, 2, 2, },
160731 /* 4 CREATE: */ { 1, 4, 2, 2, 2, 4, 5, 2, },
160732 /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
160733 /* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, },
160734 /* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, },
160735 };
160736#else
160737 /* If triggers are not supported by this compile then the statement machine
160738 ** used to detect the end of a statement is much simpler
160739 */
160740 static const u8 trans[3][3] = {
160741 /* Token: */
160742 /* State: ** SEMI WS OTHER */
160743 /* 0 INVALID: */ { 1, 0, 2, },
160744 /* 1 START: */ { 1, 1, 2, },
160745 /* 2 NORMAL: */ { 1, 2, 2, },
160746 };
160747#endif /* SQLITE_OMIT_TRIGGER */
160748
160749#ifdef SQLITE_ENABLE_API_ARMOR
160750 if( zSql==0 ){
160751 (void)SQLITE_MISUSE_BKPT;
160752 return 0;
160753 }
160754#endif
160755
160756 while( *zSql ){
160757 switch( *zSql ){
160758 case ';': { /* A semicolon */
160759 token = tkSEMI;
160760 break;
160761 }
160762 case ' ':
160763 case '\r':
160764 case '\t':
160765 case '\n':
160766 case '\f': { /* White space is ignored */
160767 token = tkWS;
160768 break;
160769 }
160770 case '/': { /* C-style comments */
160771 if( zSql[1]!='*' ){
160772 token = tkOTHER;
160773 break;
160774 }
160775 zSql += 2;
160776 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
160777 if( zSql[0]==0 ) return 0;
160778 zSql++;
160779 token = tkWS;
160780 break;
160781 }
160782 case '-': { /* SQL-style comments from "--" to end of line */
160783 if( zSql[1]!='-' ){
160784 token = tkOTHER;
160785 break;
160786 }
160787 while( *zSql && *zSql!='\n' ){ zSql++; }
160788 if( *zSql==0 ) return state==1;
160789 token = tkWS;
160790 break;
160791 }
160792 case '[': { /* Microsoft-style identifiers in [...] */
160793 zSql++;
160794 while( *zSql && *zSql!=']' ){ zSql++; }
160795 if( *zSql==0 ) return 0;
160796 token = tkOTHER;
160797 break;
160798 }
160799 case '`': /* Grave-accent quoted symbols used by MySQL */
160800 case '"': /* single- and double-quoted strings */
160801 case '\'': {
160802 int c = *zSql;
160803 zSql++;
160804 while( *zSql && *zSql!=c ){ zSql++; }
160805 if( *zSql==0 ) return 0;
160806 token = tkOTHER;
160807 break;
160808 }
160809 default: {
160810#ifdef SQLITE_EBCDIC
160811 unsigned char c;
160812#endif
160813 if( IdChar((u8)*zSql) ){
160814 /* Keywords and unquoted identifiers */
160815 int nId;
160816 for(nId=1; IdChar(zSql[nId]); nId++){}
160817#ifdef SQLITE_OMIT_TRIGGER
160818 token = tkOTHER;
160819#else
160820 switch( *zSql ){
160821 case 'c': case 'C': {
160822 if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
160823 token = tkCREATE;
160824 }else{
160825 token = tkOTHER;
160826 }
160827 break;
160828 }
160829 case 't': case 'T': {
160830 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
160831 token = tkTRIGGER;
160832 }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
160833 token = tkTEMP;
160834 }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
160835 token = tkTEMP;
160836 }else{
160837 token = tkOTHER;
160838 }
160839 break;
160840 }
160841 case 'e': case 'E': {
160842 if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
160843 token = tkEND;
160844 }else
160845#ifndef SQLITE_OMIT_EXPLAIN
160846 if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
160847 token = tkEXPLAIN;
160848 }else
160849#endif
160850 {
160851 token = tkOTHER;
160852 }
160853 break;
160854 }
160855 default: {
160856 token = tkOTHER;
160857 break;
160858 }
160859 }
160860#endif /* SQLITE_OMIT_TRIGGER */
160861 zSql += nId-1;
160862 }else{
160863 /* Operators and special symbols */
160864 token = tkOTHER;
160865 }
160866 break;
160867 }
#define tkSEMI
Definition sqlite3.c:160646
#define IdChar(C)
Definition sqlite3.c:159903
#define tkEXPLAIN
Definition sqlite3.c:160650
#define tkOTHER
Definition sqlite3.c:160648
#define tkCREATE
Definition sqlite3.c:160651
#define tkWS
Definition sqlite3.c:160647
#define tkTEMP
Definition sqlite3.c:160652
#define tkEND
Definition sqlite3.c:160654
#define tkTRIGGER
Definition sqlite3.c:160653

References IdChar, sqlite3StrNICmp, SQLITE_MISUSE_BKPT, tkCREATE, tkEND, tkEXPLAIN, tkOTHER, tkSEMI, tkTEMP, tkTRIGGER, and tkWS.

Referenced by lsqlite_complete(), and sqlite3_complete16().

◆ sqlite3_complete16()

SQLITE_API int sqlite3_complete16 ( const void * sql)

Definition at line 160875 of file sqlite3.c.

160881 {
160882 sqlite3_value *pVal;
160883 char const *zSql8;
160884 int rc;
160885
160886#ifndef SQLITE_OMIT_AUTOINIT
160887 rc = sqlite3_initialize();
160888 if( rc ) return rc;
160889#endif
160890 pVal = sqlite3ValueNew(0);
160892 zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
160893 if( zSql8 ){
160894 rc = sqlite3_complete(zSql8);
SQLITE_API int sqlite3_complete(const char *sql)
Definition sqlite3.c:160710

References sqlite3_complete(), sqlite3_initialize(), sqlite3ValueFree(), sqlite3ValueNew(), sqlite3ValueSetStr(), sqlite3ValueText(), SQLITE_NOMEM_BKPT, SQLITE_STATIC, SQLITE_UTF16NATIVE, and SQLITE_UTF8.

◆ sqlite3_config()

SQLITE_API int sqlite3_config ( int op,
... )

Definition at line 161425 of file sqlite3.c.

161431 {
161432 va_list ap;
161433 int rc = SQLITE_OK;
161434
161435 /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while
161436 ** the SQLite library is in use. */
161437 if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE_BKPT;
161438
161439 va_start(ap, op);
161440 switch( op ){
161441
161442 /* Mutex configuration options are only available in a threadsafe
161443 ** compile.
161444 */
161445#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
161447 /* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
161448 ** Single-thread. */
161449 sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
161450 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
161451 break;
161452 }
161453#endif
161454#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
161456 /* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
161457 ** Multi-thread. */
161458 sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
161459 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
161460 break;
161461 }
161462#endif
161463#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
161465 /* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
161466 ** Serialized. */
161467 sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
161468 sqlite3GlobalConfig.bFullMutex = 1; /* Enable mutex on connections */
161469 break;
161470 }
161471#endif
161472#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
161473 case SQLITE_CONFIG_MUTEX: {
161474 /* Specify an alternative mutex implementation */
161475 sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
161476 break;
161477 }
161478#endif
161479#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
161480 case SQLITE_CONFIG_GETMUTEX: {
161481 /* Retrieve the current mutex implementation */
161482 *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
161483 break;
161484 }
161485#endif
161486
161487 case SQLITE_CONFIG_MALLOC: {
161488 /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
161489 ** single argument which is a pointer to an instance of the
161490 ** sqlite3_mem_methods structure. The argument specifies alternative
161491 ** low-level memory allocation routines to be used in place of the memory
161492 ** allocation routines built into SQLite. */
161493 sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
161494 break;
161495 }
161497 /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
161498 ** single argument which is a pointer to an instance of the
161499 ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
161500 ** filled with the currently defined memory allocation routines. */
161501 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
161502 *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
161503 break;
161504 }
161506 /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
161507 ** single argument of type int, interpreted as a boolean, which enables
161508 ** or disables the collection of memory allocation statistics. */
161509 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
161510 break;
161511 }
161513 sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int);
161514 break;
161515 }
161517 /* EVIDENCE-OF: R-18761-36601 There are three arguments to
161518 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
161519 ** the size of each page cache line (sz), and the number of cache lines
161520 ** (N). */
161521 sqlite3GlobalConfig.pPage = va_arg(ap, void*);
161522 sqlite3GlobalConfig.szPage = va_arg(ap, int);
161523 sqlite3GlobalConfig.nPage = va_arg(ap, int);
161524 break;
161525 }
161527 /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
161528 ** a single parameter which is a pointer to an integer and writes into
161529 ** that integer the number of extra bytes per page required for each page
161530 ** in SQLITE_CONFIG_PAGECACHE. */
161531 *va_arg(ap, int*) =
161535 break;
161536 }
161537
161538 case SQLITE_CONFIG_PCACHE: {
161539 /* no-op */
161540 break;
161541 }
161543 /* now an error */
161544 rc = SQLITE_ERROR;
161545 break;
161546 }
161547
161548 case SQLITE_CONFIG_PCACHE2: {
161549 /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
161550 ** single argument which is a pointer to an sqlite3_pcache_methods2
161551 ** object. This object specifies the interface to a custom page cache
161552 ** implementation. */
161553 sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
161554 break;
161555 }
161557 /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
161558 ** single argument which is a pointer to an sqlite3_pcache_methods2
161559 ** object. SQLite copies of the current page cache implementation into
161560 ** that object. */
161561 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
161563 }
161564 *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
161565 break;
161566 }
161567
161568/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
161569** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
161570** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
161571#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
161572 case SQLITE_CONFIG_HEAP: {
161573 /* EVIDENCE-OF: R-19854-42126 There are three arguments to
161574 ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
161575 ** number of bytes in the memory buffer, and the minimum allocation size.
161576 */
161577 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
161578 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
161579 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
161580
161581 if( sqlite3GlobalConfig.mnReq<1 ){
161582 sqlite3GlobalConfig.mnReq = 1;
161583 }else if( sqlite3GlobalConfig.mnReq>(1<<12) ){
161584 /* cap min request size at 2^12 */
161585 sqlite3GlobalConfig.mnReq = (1<<12);
161586 }
161587
161588 if( sqlite3GlobalConfig.pHeap==0 ){
161589 /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
161590 ** is NULL, then SQLite reverts to using its default memory allocator
161591 ** (the system malloc() implementation), undoing any prior invocation of
161592 ** SQLITE_CONFIG_MALLOC.
161593 **
161594 ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
161595 ** revert to its default implementation when sqlite3_initialize() is run
161596 */
161597 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
161598 }else{
161599 /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
161600 ** alternative memory allocator is engaged to handle all of SQLites
161601 ** memory allocation needs. */
161602#ifdef SQLITE_ENABLE_MEMSYS3
161603 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
161604#endif
161605#ifdef SQLITE_ENABLE_MEMSYS5
161606 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
161607#endif
161608 }
161609 break;
161610 }
161611#endif
161612
161614 sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
161615 sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
161616 break;
161617 }
161618
161619 /* Record a pointer to the logger function and its first argument.
161620 ** The default is NULL. Logging is disabled if the function pointer is
161621 ** NULL.
161622 */
161623 case SQLITE_CONFIG_LOG: {
161624 /* MSVC is picky about pulling func ptrs from va lists.
161625 ** http://support.microsoft.com/kb/47961
161626 ** sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*));
161627 */
161628 typedef void(*LOGFUNC_t)(void*,int,const char*);
161629 sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
161630 sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
161631 break;
161632 }
161633
161634 /* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
161635 ** can be changed at start-time using the
161636 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
161637 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
161638 */
161639 case SQLITE_CONFIG_URI: {
161640 /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
161641 ** argument of type int. If non-zero, then URI handling is globally
161642 ** enabled. If the parameter is zero, then URI handling is globally
161643 ** disabled. */
161644 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
161645 break;
161646 }
161647
161649 /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
161650 ** option takes a single integer argument which is interpreted as a
161651 ** boolean in order to enable or disable the use of covering indices for
161652 ** full table scans in the query optimizer. */
161653 sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
161654 break;
161655 }
161656
161657#ifdef SQLITE_ENABLE_SQLLOG
161658 case SQLITE_CONFIG_SQLLOG: {
161659 typedef void(*SQLLOGFUNC_t)(void*, sqlite3*, const char*, int);
161660 sqlite3GlobalConfig.xSqllog = va_arg(ap, SQLLOGFUNC_t);
161661 sqlite3GlobalConfig.pSqllogArg = va_arg(ap, void *);
161662 break;
161663 }
161664#endif
161665
161667 /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
161668 ** integer (sqlite3_int64) values that are the default mmap size limit
161669 ** (the default setting for PRAGMA mmap_size) and the maximum allowed
161670 ** mmap size limit. */
161671 sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
161672 sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
161673 /* EVIDENCE-OF: R-53367-43190 If either argument to this option is
161674 ** negative, then that argument is changed to its compile-time default.
161675 **
161676 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
161677 ** silently truncated if necessary so that it does not exceed the
161678 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
161679 ** compile-time option.
161680 */
161681 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
161682 mxMmap = SQLITE_MAX_MMAP_SIZE;
161683 }
161684 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
161685 if( szMmap>mxMmap) szMmap = mxMmap;
161686 sqlite3GlobalConfig.mxMmap = mxMmap;
161687 sqlite3GlobalConfig.szMmap = szMmap;
161688 break;
161689 }
161690
161691#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
161693 /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
161694 ** unsigned integer value that specifies the maximum size of the created
161695 ** heap. */
161696 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
161697 break;
161698 }
161699#endif
161700
161701 case SQLITE_CONFIG_PMASZ: {
161702 sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
161703 break;
161704 }
161705
161707 sqlite3GlobalConfig.nStmtSpill = va_arg(ap, int);
161708 break;
161709 }
161710
161711#ifdef SQLITE_ENABLE_SORTER_REFERENCES
161713 int iVal = va_arg(ap, int);
161714 if( iVal<0 ){
161716 }
161717 sqlite3GlobalConfig.szSorterRef = (u32)iVal;
161718 break;
161719 }
161720#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
161721
161722#ifdef SQLITE_ENABLE_DESERIALIZE
161724 sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
161725 break;
161726 }
161727#endif /* SQLITE_ENABLE_DESERIALIZE */
161728
161729 default: {
161730 rc = SQLITE_ERROR;
#define SQLITE_DEFAULT_SORTERREF_SIZE
Definition sqlite3.c:14239
#define SQLITE_CONFIG_MEMSTATUS
Definition sqlite3.c:3086
#define SQLITE_CONFIG_MUTEX
Definition sqlite3.c:3087
#define SQLITE_CONFIG_PMASZ
Definition sqlite3.c:3102
#define SQLITE_CONFIG_STMTJRNL_SPILL
Definition sqlite3.c:3103
SQLITE_PRIVATE void sqlite3MemSetDefault(void)
Definition sqlite3.c:23824
#define SQLITE_CONFIG_HEAP
Definition sqlite3.c:3085
#define SQLITE_CONFIG_MEMDB_MAXSIZE
Definition sqlite3.c:3106
#define SQLITE_CONFIG_PCACHE2
Definition sqlite3.c:3095
#define SQLITE_CONFIG_SMALL_MALLOC
Definition sqlite3.c:3104
SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void)
Definition sqlite3.c:75028
#define SQLITE_CONFIG_PAGECACHE
Definition sqlite3.c:3084
#define SQLITE_CONFIG_GETMALLOC
Definition sqlite3.c:3082
#define SQLITE_CONFIG_LOG
Definition sqlite3.c:3093
#define SQLITE_CONFIG_GETMUTEX
Definition sqlite3.c:3088
#define SQLITE_CONFIG_MULTITHREAD
Definition sqlite3.c:3079
#define SQLITE_CONFIG_COVERING_INDEX_SCAN
Definition sqlite3.c:3097
SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void)
Definition sqlite3.c:50968
#define SQLITE_CONFIG_MALLOC
Definition sqlite3.c:3081
#define SQLITE_CONFIG_WIN32_HEAPSIZE
Definition sqlite3.c:3100
#define SQLITE_CONFIG_LOOKASIDE
Definition sqlite3.c:3090
#define SQLITE_DEFAULT_MMAP_SIZE
Definition sqlite3.c:14527
SQLITE_PRIVATE void sqlite3PCacheSetDefault(void)
Definition sqlite3.c:50946
#define SQLITE_CONFIG_URI
Definition sqlite3.c:3094
#define SQLITE_CONFIG_SQLLOG
Definition sqlite3.c:3098
#define SQLITE_MAX_MMAP_SIZE
Definition sqlite3.c:14517
#define SQLITE_CONFIG_MMAP_SIZE
Definition sqlite3.c:3099
#define SQLITE_CONFIG_PCACHE
Definition sqlite3.c:3091
#define SQLITE_CONFIG_PCACHE_HDRSZ
Definition sqlite3.c:3101
#define SQLITE_CONFIG_SERIALIZED
Definition sqlite3.c:3080
#define SQLITE_CONFIG_GETPCACHE
Definition sqlite3.c:3092
#define SQLITE_CONFIG_SINGLETHREAD
Definition sqlite3.c:3078
#define SQLITE_CONFIG_SORTERREF_SIZE
Definition sqlite3.c:3105
SQLITE_PRIVATE int sqlite3HeaderSizePcache(void)
Definition sqlite3.c:49720
#define SQLITE_CONFIG_GETPCACHE2
Definition sqlite3.c:3096

References sqlite3GlobalConfig, sqlite3HeaderSizeBtree(), sqlite3HeaderSizePcache(), sqlite3HeaderSizePcache1(), sqlite3MemSetDefault(), sqlite3PCacheSetDefault(), SQLITE_CONFIG_COVERING_INDEX_SCAN, SQLITE_CONFIG_GETMALLOC, SQLITE_CONFIG_GETMUTEX, SQLITE_CONFIG_GETPCACHE, SQLITE_CONFIG_GETPCACHE2, SQLITE_CONFIG_HEAP, SQLITE_CONFIG_LOG, SQLITE_CONFIG_LOOKASIDE, SQLITE_CONFIG_MALLOC, SQLITE_CONFIG_MEMDB_MAXSIZE, SQLITE_CONFIG_MEMSTATUS, SQLITE_CONFIG_MMAP_SIZE, SQLITE_CONFIG_MULTITHREAD, SQLITE_CONFIG_MUTEX, SQLITE_CONFIG_PAGECACHE, SQLITE_CONFIG_PCACHE, SQLITE_CONFIG_PCACHE2, SQLITE_CONFIG_PCACHE_HDRSZ, SQLITE_CONFIG_PMASZ, SQLITE_CONFIG_SERIALIZED, SQLITE_CONFIG_SINGLETHREAD, SQLITE_CONFIG_SMALL_MALLOC, SQLITE_CONFIG_SORTERREF_SIZE, SQLITE_CONFIG_SQLLOG, SQLITE_CONFIG_STMTJRNL_SPILL, SQLITE_CONFIG_URI, SQLITE_CONFIG_WIN32_HEAPSIZE, SQLITE_DEFAULT_MMAP_SIZE, SQLITE_DEFAULT_SORTERREF_SIZE, SQLITE_ERROR, SQLITE_MAX_MMAP_SIZE, SQLITE_MISUSE_BKPT, and SQLITE_OK.

Referenced by sqlite3MemSetDefault().

◆ sqlite3_context_db_handle()

SQLITE_API sqlite3 * sqlite3_context_db_handle ( sqlite3_context * p)

Definition at line 83794 of file sqlite3.c.

83794 : R-46798-50301 The sqlite3_context_db_handle() interface
83795** returns a copy of the pointer to the database connection (the 1st
83796** parameter) of the sqlite3_create_function() and
83797** sqlite3_create_function16() routines that originally registered the
SQLITE_API int sqlite3_create_function16(sqlite3 *db, const void *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *))
Definition sqlite3.c:162980

References sqlite3_value::db, and sqlite3_context::pOut.

Referenced by attachFunc(), changes(), contextMalloc(), detachFunc(), likeFunc(), loadExt(), renameColumnFunc(), renameEditSql(), renameTableFunc(), renameTableTest(), replaceFunc(), statInit(), strftimeFunc(), and substrFunc().

◆ sqlite3_create_collation()

SQLITE_API int sqlite3_create_collation ( sqlite3 * db,
const char * zName,
int eTextRep,
void * pArg,
int(*)(void *, int, const void *, int, const void *) xCompare )

Definition at line 164439 of file sqlite3.c.

◆ sqlite3_create_collation16()

SQLITE_API int sqlite3_create_collation16 ( sqlite3 * db,
const void * zName,
int eTextRep,
void * pArg,
int(*)(void *, int, const void *, int, const void *) xCompare )

Definition at line 164477 of file sqlite3.c.

164489 {
164490 int rc = SQLITE_OK;
164491 char *zName8;
164492
164493#ifdef SQLITE_ENABLE_API_ARMOR
164494 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
164495#endif
164497 assert( !db->mallocFailed );
164498 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
164499 if( zName8 ){
164500 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
SQLITE_PRIVATE char * sqlite3Utf16to8(sqlite3 *, const void *, int, u8)
Definition sqlite3.c:31111

◆ sqlite3_create_collation_v2()

SQLITE_API int sqlite3_create_collation_v2 ( sqlite3 * db,
const char * zName,
int eTextRep,
void * pArg,
int(*)(void *, int, const void *, int, const void *) xCompare,
void(*)(void *) xDestroy )

Definition at line 164452 of file sqlite3.c.

164465 {
164466 int rc;
164467
164468#ifdef SQLITE_ENABLE_API_ARMOR
164469 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
164470#endif

Referenced by db_create_collation().

◆ sqlite3_create_filename()

SQLITE_API char * sqlite3_create_filename ( const char * zDatabase,
const char * zJournal,
const char * zWal,
int nParam,
const char ** azParam )

Definition at line 165241 of file sqlite3.c.

165253 {
165254 sqlite3_int64 nByte;
165255 int i;
165256 char *pResult, *p;
165257 nByte = strlen(zDatabase) + strlen(zJournal) + strlen(zWal) + 10;
165258 for(i=0; i<nParam*2; i++){
165259 nByte += strlen(azParam[i])+1;
165260 }
165261 pResult = p = sqlite3_malloc64( nByte );
165262 if( p==0 ) return 0;
165263 memset(p, 0, 4);
165264 p += 4;
165265 p = appendText(p, zDatabase);
165266 for(i=0; i<nParam*2; i++){
165267 p = appendText(p, azParam[i]);
165268 }
165269 *(p++) = 0;
165270 p = appendText(p, zJournal);
static char * appendText(char *p, const char *z)
Definition sqlite3.c:165226

References appendText(), and sqlite3_malloc64().

◆ sqlite3_create_function()

SQLITE_API int sqlite3_create_function ( sqlite3 * db,
const char * zFunctionName,
int nArg,
int eTextRep,
void * pApp,
void(*)(sqlite3_context *, int, sqlite3_value **) xFunc,
void(*)(sqlite3_context *, int, sqlite3_value **) xStep,
void(*)(sqlite3_context *) xFinal )

Definition at line 162936 of file sqlite3.c.

Referenced by db_register_function().

◆ sqlite3_create_function16()

SQLITE_API int sqlite3_create_function16 ( sqlite3 * db,
const void * zFunctionName,
int nArg,
int eTextRep,
void * pApp,
void(*)(sqlite3_context *, int, sqlite3_value **) xFunc,
void(*)(sqlite3_context *, int, sqlite3_value **) xStep,
void(*)(sqlite3_context *) xFinal )

Definition at line 162980 of file sqlite3.c.

162980 {
162981 return createFunctionApi(db, zFunc, nArg, enc, p, 0, xStep,
162982 xFinal, xValue, xInverse, xDestroy);
162983}
162984
162985#ifndef SQLITE_OMIT_UTF16
162987 sqlite3 *db,
162988 const void *zFunctionName,
162989 int nArg,
162990 int eTextRep,
162991 void *p,
162992 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**),
162993 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
162994 void (*xFinal)(sqlite3_context*)
162995){
162996 int rc;
162997 char *zFunc8;
162998
162999#ifdef SQLITE_ENABLE_API_ARMOR
163000 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
163001#endif
163003 assert( !db->mallocFailed );
163004 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);

References createFunctionApi().

◆ sqlite3_create_function_v2()

SQLITE_API int sqlite3_create_function_v2 ( sqlite3 * db,
const char * zFunctionName,
int nArg,
int eTextRep,
void * pApp,
void(*)(sqlite3_context *, int, sqlite3_value **) xFunc,
void(*)(sqlite3_context *, int, sqlite3_value **) xStep,
void(*)(sqlite3_context *) xFinal,
void(*)(void *) xDestroy )

Definition at line 162949 of file sqlite3.c.

162951 {
162952 return createFunctionApi(db, zFunc, nArg, enc, p, xSFunc, xStep,
162953 xFinal, 0, 0, 0);
162954}
162956 sqlite3 *db,
162957 const char *zFunc,
162958 int nArg,
162959 int enc,
162960 void *p,
162961 void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
162962 void (*xStep)(sqlite3_context*,int,sqlite3_value **),

References createFunctionApi().

Referenced by sqlite3_overload_function().

◆ sqlite3_create_module()

SQLITE_API int sqlite3_create_module ( sqlite3 * db,
const char * zName,
const sqlite3_module * p,
void * pClientData )

Definition at line 139679 of file sqlite3.c.

◆ sqlite3_create_module_v2()

SQLITE_API int sqlite3_create_module_v2 ( sqlite3 * db,
const char * zName,
const sqlite3_module * p,
void * pClientData,
void(*)(void *) xDestroy )

Definition at line 139694 of file sqlite3.c.

◆ sqlite3_create_window_function()

SQLITE_API int sqlite3_create_window_function ( sqlite3 * db,
const char * zFunctionName,
int nArg,
int eTextRep,
void * pApp,
void(*)(sqlite3_context *, int, sqlite3_value **) xStep,
void(*)(sqlite3_context *) xFinal,
void(*)(sqlite3_context *) xValue,
void(*)(sqlite3_context *, int, sqlite3_value **) xInverse,
void(*)(void *) xDestroy )

Definition at line 162963 of file sqlite3.c.

162965 {
162966 return createFunctionApi(db, zFunc, nArg, enc, p, xSFunc, xStep,
162967 xFinal, 0, 0, xDestroy);
162968}
162970 sqlite3 *db,
162971 const char *zFunc,
162972 int nArg,
162973 int enc,
162974 void *p,
162975 void (*xStep)(sqlite3_context*,int,sqlite3_value **),
162976 void (*xFinal)(sqlite3_context*),
162977 void (*xValue)(sqlite3_context*),

References createFunctionApi().

◆ sqlite3_data_count()

SQLITE_API int sqlite3_data_count ( sqlite3_stmt * pStmt)

Definition at line 83987 of file sqlite3.c.

Referenced by db_do_next_row(), and dbvm_step().

◆ sqlite3_database_file_object()

SQLITE_API sqlite3_file * sqlite3_database_file_object ( const char * zName)

Definition at line 56713 of file sqlite3.c.

56719 {
56720 Pager *pPager;

References Pager::fd, and zName.

◆ sqlite3_db_cacheflush()

SQLITE_API int sqlite3_db_cacheflush ( sqlite3 * db)

Definition at line 161881 of file sqlite3.c.

161887 {
161888 int i;
161889 int rc = SQLITE_OK;
161890 int bSeenBusy = 0;
161891
161892#ifdef SQLITE_ENABLE_API_ARMOR
161893 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
161894#endif
161897 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
161898 Btree *pBt = db->aDb[i].pBt;
161899 if( pBt && sqlite3BtreeIsInTrans(pBt) ){
161900 Pager *pPager = sqlite3BtreePager(pBt);
161901 rc = sqlite3PagerFlush(pPager);
161902 if( rc==SQLITE_BUSY ){
161903 bSeenBusy = 1;
161904 rc = SQLITE_OK;
161905 }
SQLITE_PRIVATE int sqlite3PagerFlush(Pager *)
Definition sqlite3.c:56293
SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *)
Definition sqlite3.c:74792

◆ sqlite3_db_config()

SQLITE_API int sqlite3_db_config ( sqlite3 * db,
int op,
... )

Definition at line 161910 of file sqlite3.c.

161910 : rc);
161911}
161912
161913/*
161914** Configuration settings for an individual database connection
161915*/
161916SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
161917 va_list ap;
161918 int rc;
161919 va_start(ap, op);
161920 switch( op ){
161922 /* IMP: R-06824-28531 */
161923 /* IMP: R-36257-52125 */
161924 db->aDb[0].zDbSName = va_arg(ap,char*);
161925 rc = SQLITE_OK;
161926 break;
161927 }
161929 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
161930 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
161931 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
161932 rc = setupLookaside(db, pBuf, sz, cnt);
161933 break;
161934 }
161935 default: {
161936 static const struct {
161937 int op; /* The opcode */
161938 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
161939 } aFlagOp[] = {
161957 };
161958 unsigned int i;
161959 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
161960 for(i=0; i<ArraySize(aFlagOp); i++){
161961 if( aFlagOp[i].op==op ){
161962 int onoff = va_arg(ap, int);
161963 int *pRes = va_arg(ap, int*);
161964 u64 oldFlags = db->flags;
161965 if( onoff>0 ){
161966 db->flags |= aFlagOp[i].mask;
161967 }else if( onoff==0 ){
161968 db->flags &= ~(u64)aFlagOp[i].mask;
161969 }
161970 if( oldFlags!=db->flags ){
161972 }
161973 if( pRes ){
161974 *pRes = (db->flags & aFlagOp[i].mask)!=0;
161975 }
161976 rc = SQLITE_OK;
161977 break;
161978 }
161979 }
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
Definition sqlite3.c:3382
#define SQLITE_DBCONFIG_DEFENSIVE
Definition sqlite3.c:3387
#define SQLITE_DBCONFIG_DQS_DDL
Definition sqlite3.c:3391
#define SQLITE_DBCONFIG_ENABLE_TRIGGER
Definition sqlite3.c:3380
SQLITE_API int sqlite3_db_config(sqlite3 *, int op,...)
Definition sqlite3.c:161910
#define SQLITE_DBCONFIG_ENABLE_FKEY
Definition sqlite3.c:3379
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
Definition sqlite3.c:3381
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA
Definition sqlite3.c:3394
#define SQLITE_DBCONFIG_RESET_DATABASE
Definition sqlite3.c:3386
#define SQLITE_DBCONFIG_DQS_DML
Definition sqlite3.c:3390
#define SQLITE_DBCONFIG_ENABLE_QPSG
Definition sqlite3.c:3384
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA
Definition sqlite3.c:3388
#define SQLITE_NoSchemaError
Definition sqlite3.c:17006
#define SQLITE_TriggerEQP
Definition sqlite3.c:17003
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
Definition sqlite3.c:3389
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
Definition sqlite3.c:3383
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
Definition sqlite3.c:3393
#define SQLITE_NoCkptOnClose
Definition sqlite3.c:16990
#define SQLITE_DBCONFIG_LOOKASIDE
Definition sqlite3.c:3378
#define SQLITE_DBCONFIG_ENABLE_VIEW
Definition sqlite3.c:3392
#define SQLITE_DBCONFIG_MAINDBNAME
Definition sqlite3.c:3377
#define SQLITE_DBCONFIG_TRIGGER_EQP
Definition sqlite3.c:3385

◆ sqlite3_db_filename()

SQLITE_API const char * sqlite3_db_filename ( sqlite3 * db,
const char * zDbName )

Definition at line 165384 of file sqlite3.c.

165390 {
165391 Btree *pBt;
165392#ifdef SQLITE_ENABLE_API_ARMOR
165393 if( !sqlite3SafetyCheckOk(db) ){
165394 (void)SQLITE_MISUSE_BKPT;

Referenced by db_db_filename().

◆ sqlite3_db_handle()

SQLITE_API sqlite3 * sqlite3_db_handle ( sqlite3_stmt * pStmt)

Definition at line 84646 of file sqlite3.c.

◆ sqlite3_db_mutex()

SQLITE_API sqlite3_mutex * sqlite3_db_mutex ( sqlite3 * db)

Definition at line 161843 of file sqlite3.c.

161849 {
161850#ifdef SQLITE_ENABLE_API_ARMOR
161851 if( !sqlite3SafetyCheckOk(db) ){

◆ sqlite3_db_readonly()

SQLITE_API int sqlite3_db_readonly ( sqlite3 * db,
const char * zDbName )

Definition at line 165400 of file sqlite3.c.

165406 {
165407 Btree *pBt;
165408#ifdef SQLITE_ENABLE_API_ARMOR
165409 if( !sqlite3SafetyCheckOk(db) ){
165410 (void)SQLITE_MISUSE_BKPT;

◆ sqlite3_db_release_memory()

SQLITE_API int sqlite3_db_release_memory ( sqlite3 * db)

Definition at line 161857 of file sqlite3.c.

161863 {
161864 int i;
161865
161866#ifdef SQLITE_ENABLE_API_ARMOR
161867 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
161868#endif
161871 for(i=0; i<db->nDb; i++){
161872 Btree *pBt = db->aDb[i].pBt;
161873 if( pBt ){
161874 Pager *pPager = sqlite3BtreePager(pBt);
161875 sqlite3PagerShrink(pPager);
SQLITE_PRIVATE void sqlite3PagerShrink(Pager *)
Definition sqlite3.c:55186

Referenced by sqlite3Pragma().

◆ sqlite3_db_status()

SQLITE_API int sqlite3_db_status ( sqlite3 * db,
int op,
int * pCur,
int * pHiwtr,
int resetFlg )

Definition at line 21515 of file sqlite3.c.

21526 {
21527 int rc = SQLITE_OK; /* Return code */
21528#ifdef SQLITE_ENABLE_API_ARMOR
21529 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
21530 return SQLITE_MISUSE_BKPT;
21531 }
21532#endif
21534 switch( op ){
21536 *pCurrent = sqlite3LookasideUsed(db, pHighwater);
21537 if( resetFlag ){
21538 LookasideSlot *p = db->lookaside.pFree;
21539 if( p ){
21540 while( p->pNext ) p = p->pNext;
21541 p->pNext = db->lookaside.pInit;
21542 db->lookaside.pInit = db->lookaside.pFree;
21543 db->lookaside.pFree = 0;
21544 }
21545#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21546 p = db->lookaside.pSmallFree;
21547 if( p ){
21548 while( p->pNext ) p = p->pNext;
21549 p->pNext = db->lookaside.pSmallInit;
21551 db->lookaside.pSmallFree = 0;
21552 }
21553#endif
21554 }
21555 break;
21556 }
21557
21564 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
21565 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
21566 *pCurrent = 0;
21567 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
21568 if( resetFlag ){
21570 }
21571 break;
21572 }
21573
21574 /*
21575 ** Return an approximation for the amount of memory currently used
21576 ** by all pagers associated with the given database connection. The
21577 ** highwater mark is meaningless and is returned as zero.
21578 */
21581 int totalUsed = 0;
21582 int i;
21584 for(i=0; i<db->nDb; i++){
21585 Btree *pBt = db->aDb[i].pBt;
21586 if( pBt ){
21587 Pager *pPager = sqlite3BtreePager(pBt);
21588 int nByte = sqlite3PagerMemUsed(pPager);
21590 nByte = nByte / sqlite3BtreeConnectionCount(pBt);
21591 }
21592 totalUsed += nByte;
21593 }
21594 }
21596 *pCurrent = totalUsed;
21597 *pHighwater = 0;
21598 break;
21599 }
21600
21601 /*
21602 ** *pCurrent gets an accurate estimate of the amount of memory used
21603 ** to store the schema for all databases (main, temp, and any ATTACHed
21604 ** databases. *pHighwater is set to zero.
21605 */
21607 int i; /* Used to iterate through schemas */
21608 int nByte = 0; /* Used to accumulate return value */
21609
21611 db->pnBytesFreed = &nByte;
21612 for(i=0; i<db->nDb; i++){
21613 Schema *pSchema = db->aDb[i].pSchema;
21614 if( ALWAYS(pSchema!=0) ){
21615 HashElem *p;
21616
21617 nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * (
21618 pSchema->tblHash.count
21619 + pSchema->trigHash.count
21620 + pSchema->idxHash.count
21621 + pSchema->fkeyHash.count
21622 );
21623 nByte += sqlite3_msize(pSchema->tblHash.ht);
21624 nByte += sqlite3_msize(pSchema->trigHash.ht);
21625 nByte += sqlite3_msize(pSchema->idxHash.ht);
21626 nByte += sqlite3_msize(pSchema->fkeyHash.ht);
21627
21628 for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
21630 }
21631 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
21633 }
21634 }
21635 }
21636 db->pnBytesFreed = 0;
21638
21639 *pHighwater = 0;
21640 *pCurrent = nByte;
21641 break;
21642 }
21643
21644 /*
21645 ** *pCurrent gets an accurate estimate of the amount of memory used
21646 ** to store all prepared statements.
21647 ** *pHighwater is set to zero.
21648 */
21650 struct Vdbe *pVdbe; /* Used to iterate through VMs */
21651 int nByte = 0; /* Used to accumulate return value */
21652
21653 db->pnBytesFreed = &nByte;
21654 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
21655 sqlite3VdbeClearObject(db, pVdbe);
21656 sqlite3DbFree(db, pVdbe);
21657 }
21658 db->pnBytesFreed = 0;
21659
21660 *pHighwater = 0; /* IMP: R-64479-57858 */
21661 *pCurrent = nByte;
21662
21663 break;
21664 }
21665
21666 /*
21667 ** Set *pCurrent to the total cache hits or misses encountered by all
21668 ** pagers the database handle is connected to. *pHighwater is always set
21669 ** to zero.
21670 */
21673 /* no break */ deliberate_fall_through
21677 int i;
21678 int nRet = 0;
21681
21682 for(i=0; i<db->nDb; i++){
21683 if( db->aDb[i].pBt ){
21684 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
21685 sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
21686 }
21687 }
21688 *pHighwater = 0; /* IMP: R-42420-56072 */
21689 /* IMP: R-54100-20147 */
21690 /* IMP: R-29431-39229 */
21691 *pCurrent = nRet;
21692 break;
21693 }
21694
21695 /* Set *pCurrent to non-zero if there are unresolved deferred foreign
21696 ** key constraints. Set *pCurrent to zero if all foreign key constraints
21697 ** have been satisfied. The *pHighwater is always set to zero.
21698 */
21700 *pHighwater = 0; /* IMP: R-11967-56545 */
21701 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
21702 break;
21703 }
21704
21705 default: {
21706 rc = SQLITE_ERROR;
#define SQLITE_DBSTATUS_CACHE_HIT
Definition sqlite3.c:9204
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
Definition sqlite3.c:9202
#define SQLITE_DBSTATUS_STMT_USED
Definition sqlite3.c:9200
SQLITE_API sqlite3_uint64 sqlite3_msize(void *)
Definition sqlite3.c:27683
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
Definition sqlite3.c:9203
SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *)
Definition sqlite3.c:58474
SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *, Trigger *)
Definition sqlite3.c:136938
#define SQLITE_DBSTATUS_CACHE_USED
Definition sqlite3.c:9198
#define SQLITE_DBSTATUS_LOOKASIDE_HIT
Definition sqlite3.c:9201
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *)
Definition sqlite3.c:58427
SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *, Vdbe *)
Definition sqlite3.c:81168
#define SQLITE_DBSTATUS_SCHEMA_USED
Definition sqlite3.c:9199
#define SQLITE_DBSTATUS_CACHE_USED_SHARED
Definition sqlite3.c:9208
SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *)
Definition sqlite3.c:75043
#define SQLITE_DBSTATUS_CACHE_WRITE
Definition sqlite3.c:9206
#define SQLITE_DBSTATUS_DEFERRED_FKS
Definition sqlite3.c:9207
#define SQLITE_DBSTATUS_CACHE_SPILL
Definition sqlite3.c:9209
#define SQLITE_DBSTATUS_LOOKASIDE_USED
Definition sqlite3.c:9197
#define SQLITE_DBSTATUS_CACHE_MISS
Definition sqlite3.c:9205
u32 anStat[3]
Definition sqlite3.c:16724
Hash idxHash
Definition sqlite3.c:16634
Hash fkeyHash
Definition sqlite3.c:16636
Vdbe * pNext
Definition sqlite3.c:21085
i64 nDeferredCons
Definition sqlite3.c:16932
i64 nDeferredImmCons
Definition sqlite3.c:16933

◆ sqlite3_declare_vtab()

SQLITE_API int sqlite3_declare_vtab ( sqlite3 * db,
const char * zSQL )

Definition at line 140366 of file sqlite3.c.

140372 {
140373 VtabCtx *pCtx;
140374 int rc = SQLITE_OK;
140375 Table *pTab;
140376 char *zErr = 0;
140377 Parse sParse;
140378
140379#ifdef SQLITE_ENABLE_API_ARMOR
140380 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
140381 return SQLITE_MISUSE_BKPT;
140382 }
140383#endif
140385 pCtx = db->pVtabCtx;
140386 if( !pCtx || pCtx->bDeclared ){
140389 return SQLITE_MISUSE_BKPT;
140390 }
140391 pTab = pCtx->pTab;
140392 assert( IsVirtual(pTab) );
140393
140394 memset(&sParse, 0, sizeof(sParse));
140396 sParse.db = db;
140397 sParse.nQueryLoop = 1;
140398 if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr)
140399 && sParse.pNewTable
140400 && !db->mallocFailed
140401 && !sParse.pNewTable->pSelect
140402 && !IsVirtual(sParse.pNewTable)
140403 ){
140404 if( !pTab->aCol ){
140405 Table *pNew = sParse.pNewTable;
140406 Index *pIdx;
140407 pTab->aCol = pNew->aCol;
140408 pTab->nCol = pNew->nCol;
140410 pNew->nCol = 0;
140411 pNew->aCol = 0;
140412 assert( pTab->pIndex==0 );
140413 assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
140414 if( !HasRowid(pNew)
140415 && pCtx->pVTable->pMod->pModule->xUpdate!=0
140416 && sqlite3PrimaryKeyIndex(pNew)->nKeyCol!=1
140417 ){
140418 /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
140419 ** or else must have a single-column PRIMARY KEY */
140420 rc = SQLITE_ERROR;
140421 }
140422 pIdx = pNew->pIndex;
140423 if( pIdx ){
140424 assert( pIdx->pNext==0 );
140425 pTab->pIndex = pIdx;
140426 pNew->pIndex = 0;
140427 pIdx->pTable = pTab;
140428 }
140429 }
140430 pCtx->bDeclared = 1;
140431 }else{
140432 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
140433 sqlite3DbFree(db, zErr);
140434 rc = SQLITE_ERROR;
140435 }
140436 sParse.eParseMode = PARSE_MODE_NORMAL;
140437
140438 if( sParse.pVdbe ){
140439 sqlite3VdbeFinalize(sParse.pVdbe);
140440 }
140441 sqlite3DeleteTable(db, sParse.pNewTable);
140442 sqlite3ParserReset(&sParse);
#define PARSE_MODE_NORMAL
Definition sqlite3.c:18781
#define TF_NoVisibleRowid
Definition sqlite3.c:17545
#define SQLITE_MISUSE
Definition sqlite3.c:1491
#define PARSE_MODE_DECLARE_VTAB
Definition sqlite3.c:18782
const sqlite3_module * pModule
Definition sqlite3.c:17306
Module * pMod
Definition sqlite3.c:17468
int bDeclared
Definition sqlite3.c:139599
Table * pTab
Definition sqlite3.c:139597
VTable * pVTable
Definition sqlite3.c:139596
int(* xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *)
Definition sqlite3.c:7777
VtabCtx * pVtabCtx
Definition sqlite3.c:16919

References Table::aCol, VtabCtx::bDeclared, Parse::db, Parse::eParseMode, HasRowid, IsVirtual, sqlite3::mallocFailed, sqlite3::mutex, Table::nCol, Parse::nQueryLoop, PARSE_MODE_DECLARE_VTAB, PARSE_MODE_NORMAL, Table::pIndex, VTable::pMod, Module::pModule, Parse::pNewTable, Index::pNext, Table::pSelect, VtabCtx::pTab, Index::pTable, Parse::pVdbe, sqlite3::pVtabCtx, VtabCtx::pVTable, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3DbFree(), sqlite3DeleteTable(), sqlite3Error(), sqlite3ErrorWithMsg(), sqlite3ParserReset(), sqlite3PrimaryKeyIndex(), sqlite3RunParser(), sqlite3SafetyCheckOk(), sqlite3VdbeFinalize(), SQLITE_ERROR, SQLITE_MISUSE, SQLITE_MISUSE_BKPT, SQLITE_OK, Table::tabFlags, TF_NoVisibleRowid, TF_WithoutRowid, and sqlite3_module::xUpdate.

◆ sqlite3_deserialize()

SQLITE_API int sqlite3_deserialize ( sqlite3 * db,
const char * zSchema,
unsigned char * pData,
sqlite3_int64 szDb,
sqlite3_int64 szBuf,
unsigned mFlags )

◆ sqlite3_drop_modules()

SQLITE_API int sqlite3_drop_modules ( sqlite3 * db,
const char ** azKeep )

Definition at line 139711 of file sqlite3.c.

139717 {
139718 HashElem *pThis, *pNext;
139719#ifdef SQLITE_ENABLE_API_ARMOR
139720 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
139721#endif
139722 for(pThis=sqliteHashFirst(&db->aModule); pThis; pThis=pNext){
139723 Module *pMod = (Module*)sqliteHashData(pThis);
139724 pNext = sqliteHashNext(pThis);
139725 if( azNames ){
139726 int ii;
139727 for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
const char * zName
Definition sqlite3.c:17307

◆ sqlite3_enable_load_extension()

SQLITE_API int sqlite3_enable_load_extension ( sqlite3 * db,
int onoff )

Definition at line 124907 of file sqlite3.c.

124913 {
124915 if( onoff ){

Referenced by db_load_extension().

◆ sqlite3_enable_shared_cache()

SQLITE_API int sqlite3_enable_shared_cache ( int enable)

Definition at line 64566 of file sqlite3.c.

References sqlite3GlobalConfig, and SQLITE_OK.

◆ sqlite3_errcode()

SQLITE_API int sqlite3_errcode ( sqlite3 * db)

Definition at line 163553 of file sqlite3.c.

163559 {
163560 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
163561 return SQLITE_MISUSE_BKPT;
SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *)
Definition sqlite3.c:32559

References sqlite3SafetyCheckSickOrOk(), and SQLITE_MISUSE_BKPT.

Referenced by db_errcode(), db_prepare(), dbvm_reset(), lsqlite_do_open(), and openDatabase().

◆ sqlite3_errmsg()

SQLITE_API const char * sqlite3_errmsg ( sqlite3 * db)

Definition at line 163483 of file sqlite3.c.

163489 {
163490 const char *z;
163491 if( !db ){
163493 }
163494 if( !sqlite3SafetyCheckSickOrOk(db) ){
163496 }
163498 if( db->mallocFailed ){
163500 }else{
163501 testcase( db->pErr==0 );
163502 z = db->errCode ? (char*)sqlite3_value_text(db->pErr) : 0;
163503 assert( !db->mallocFailed );
163504 if( z==0 ){
SQLITE_PRIVATE const char * sqlite3ErrStr(int)
Definition sqlite3.c:162539
int errCode
Definition sqlite3.c:16832
sqlite3_value * pErr
Definition sqlite3.c:16901

Referenced by blobSeekToRow(), db_do_next_row(), db_do_rows(), db_errmsg(), execSqlF(), lsqlite_do_open(), sqlite3_exec(), and sqlite3InitCallback().

◆ sqlite3_errmsg16()

SQLITE_API const void * sqlite3_errmsg16 ( sqlite3 * db)

Definition at line 163511 of file sqlite3.c.

163517 {
163518 static const u16 outOfMem[] = {
163519 'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
163520 };
163521 static const u16 misuse[] = {
163522 'b', 'a', 'd', ' ', 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r', ' ',
163523 'o', 'r', ' ', 'o', 't', 'h', 'e', 'r', ' ', 'A', 'P', 'I', ' ',
163524 'm', 'i', 's', 'u', 's', 'e', 0
163525 };
163526
163527 const void *z;
163528 if( !db ){
163529 return (void *)outOfMem;
163530 }
163531 if( !sqlite3SafetyCheckSickOrOk(db) ){
163532 return (void *)misuse;
163533 }
163535 if( db->mallocFailed ){
163536 z = (void *)outOfMem;
163537 }else{
163538 z = sqlite3_value_text16(db->pErr);
163539 if( z==0 ){
163541 z = sqlite3_value_text16(db->pErr);
163542 }
163543 /* A malloc() may have failed within the call to sqlite3_value_text16()
163544 ** above. If this is the case, then the db->mallocFailed flag needs to
163545 ** be cleared before returning. Do this directly, instead of via
163546 ** sqlite3ApiExit(), to avoid setting the database handle error message.

References sqlite3::errCode, sqlite3::mallocFailed, sqlite3::mutex, sqlite3::pErr, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_value_text16(), sqlite3ErrorWithMsg(), sqlite3ErrStr(), sqlite3OomClear(), and sqlite3SafetyCheckSickOrOk().

◆ sqlite3_errstr()

SQLITE_API const char * sqlite3_errstr ( int rc)

Definition at line 163580 of file sqlite3.c.

References sqlite3ErrStr().

◆ sqlite3_exec()

SQLITE_API int sqlite3_exec ( sqlite3 * db,
const char * sql,
int(*)(void *, int, char **, char **) callback,
void * pArg,
char ** errmsg )

Definition at line 123455 of file sqlite3.c.

123467 {
123468 int rc = SQLITE_OK; /* Return code */
123469 const char *zLeftover; /* Tail of unprocessed SQL */
123470 sqlite3_stmt *pStmt = 0; /* The current SQL statement */
123471 char **azCols = 0; /* Names of result columns */
123472 int callbackIsInit; /* True if callback data is initialized */
123473
123474 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
123475 if( zSql==0 ) zSql = "";
123476
123478 sqlite3Error(db, SQLITE_OK);
123479 while( rc==SQLITE_OK && zSql[0] ){
123480 int nCol = 0;
123481 char **azVals = 0;
123482
123483 pStmt = 0;
123484 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
123485 assert( rc==SQLITE_OK || pStmt==0 );
123486 if( rc!=SQLITE_OK ){
123487 continue;
123488 }
123489 if( !pStmt ){
123490 /* this happens for a comment or white-space */
123491 zSql = zLeftover;
123492 continue;
123493 }
123494 callbackIsInit = 0;
123495
123496 while( 1 ){
123497 int i;
123498 rc = sqlite3_step(pStmt);
123499
123500 /* Invoke the callback function if required */
123501 if( xCallback && (SQLITE_ROW==rc ||
123502 (SQLITE_DONE==rc && !callbackIsInit
123503 && db->flags&SQLITE_NullCallback)) ){
123504 if( !callbackIsInit ){
123505 nCol = sqlite3_column_count(pStmt);
123506 azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
123507 if( azCols==0 ){
123508 goto exec_out;
123509 }
123510 for(i=0; i<nCol; i++){
123511 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
123512 /* sqlite3VdbeSetColName() installs column names as UTF8
123513 ** strings so there is no way for sqlite3_column_name() to fail. */
123514 assert( azCols[i]!=0 );
123515 }
123516 callbackIsInit = 1;
123517 }
123518 if( rc==SQLITE_ROW ){
123519 azVals = &azCols[nCol];
123520 for(i=0; i<nCol; i++){
123521 azVals[i] = (char *)sqlite3_column_text(pStmt, i);
123522 if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){
123523 sqlite3OomFault(db);
123524 goto exec_out;
123525 }
123526 }
123527 azVals[i] = 0;
123528 }
123529 if( xCallback(pArg, nCol, azVals, azCols) ){
123530 /* EVIDENCE-OF: R-38229-40159 If the callback function to
123531 ** sqlite3_exec() returns non-zero, then sqlite3_exec() will
123532 ** return SQLITE_ABORT. */
123533 rc = SQLITE_ABORT;
123534 sqlite3VdbeFinalize((Vdbe *)pStmt);
123535 pStmt = 0;
123537 goto exec_out;
123538 }
123539 }
123540
123541 if( rc!=SQLITE_ROW ){
123542 rc = sqlite3VdbeFinalize((Vdbe *)pStmt);
123543 pStmt = 0;
123544 zSql = zLeftover;
123545 while( sqlite3Isspace(zSql[0]) ) zSql++;
123546 break;
123547 }
123548 }
123549
123550 sqlite3DbFree(db, azCols);
123551 azCols = 0;
123552 }
123553
123554exec_out:
123555 if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt);
123556 sqlite3DbFree(db, azCols);
123557
123558 rc = sqlite3ApiExit(db, rc);
123559 if( rc!=SQLITE_OK && pzErrMsg ){
123560 *pzErrMsg = sqlite3DbStrDup(0, sqlite3_errmsg(db));
123561 if( *pzErrMsg==0 ){
123562 rc = SQLITE_NOMEM_BKPT;
123564 }
123565 }else if( pzErrMsg ){
123566 *pzErrMsg = 0;
SQLITE_API int sqlite3_column_type(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84147
#define SQLITE_NullCallback
Definition sqlite3.c:16986
SQLITE_API const char * sqlite3_column_name(sqlite3_stmt *, int N)
Definition sqlite3.c:84218

References sqlite3::errMask, sqlite3::flags, sqlite3::mutex, sqlite3_column_count(), sqlite3_column_name(), sqlite3_column_text(), sqlite3_column_type(), sqlite3_errmsg(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_prepare_v2(), sqlite3_step(), sqlite3ApiExit(), sqlite3DbFree(), sqlite3DbMallocRaw(), sqlite3DbStrDup(), sqlite3Error(), sqlite3Isspace, sqlite3OomFault(), sqlite3SafetyCheckOk(), sqlite3VdbeFinalize(), SQLITE_ABORT, SQLITE_DONE, SQLITE_MISUSE_BKPT, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_NULL, SQLITE_NullCallback, SQLITE_OK, and SQLITE_ROW.

Referenced by db_exec(), lsqlite_open_ptr(), sqlite3_get_table(), sqlite3AnalysisLoad(), sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3_expanded_sql()

SQLITE_API char * sqlite3_expanded_sql ( sqlite3_stmt * pStmt)

Definition at line 84745 of file sqlite3.c.

84751 {
84752#ifdef SQLITE_OMIT_TRACE
84753 return 0;
84754#else
84755 char *z = 0;
84756 const char *zSql = sqlite3_sql(pStmt);
84757 if( zSql ){
84758 Vdbe *p = (Vdbe *)pStmt;
SQLITE_API const char * sqlite3_sql(sqlite3_stmt *pStmt)
Definition sqlite3.c:84731

References Vdbe::db, sqlite3::mutex, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_sql(), and sqlite3VdbeExpandSql().

◆ sqlite3_expired()

SQLITE_API int sqlite3_expired ( sqlite3_stmt * pStmt)

Definition at line 83009 of file sqlite3.c.

References Vdbe::expired.

◆ sqlite3_extended_errcode()

SQLITE_API int sqlite3_extended_errcode ( sqlite3 * db)

Definition at line 163562 of file sqlite3.c.

163563 {
163564 return SQLITE_NOMEM_BKPT;
163565 }
163566 return db->errCode & db->errMask;
163567}
163569 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
163570 return SQLITE_MISUSE_BKPT;
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db)
Definition sqlite3.c:163562

◆ sqlite3_extended_result_codes()

SQLITE_API int sqlite3_extended_result_codes ( sqlite3 * db,
int onoff )

Definition at line 164768 of file sqlite3.c.

164774 {
164775#ifdef SQLITE_ENABLE_API_ARMOR
164776 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;

◆ sqlite3_file_control()

SQLITE_API int sqlite3_file_control ( sqlite3 * db,
const char * zDbName,
int op,
void * pArg )

Definition at line 164781 of file sqlite3.c.

164787 {
164788 int rc = SQLITE_ERROR;
164789 Btree *pBtree;
164790
164791#ifdef SQLITE_ENABLE_API_ARMOR
164792 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
164793#endif
164795 pBtree = sqlite3DbNameToBtree(db, zDbName);
164796 if( pBtree ){
164797 Pager *pPager;
164798 sqlite3_file *fd;
164799 sqlite3BtreeEnter(pBtree);
164800 pPager = sqlite3BtreePager(pBtree);
164801 assert( pPager!=0 );
164802 fd = sqlite3PagerFile(pPager);
164803 assert( fd!=0 );
164804 if( op==SQLITE_FCNTL_FILE_POINTER ){
164805 *(sqlite3_file**)pArg = fd;
164806 rc = SQLITE_OK;
164807 }else if( op==SQLITE_FCNTL_VFS_POINTER ){
164808 *(sqlite3_vfs**)pArg = sqlite3PagerVfs(pPager);
164809 rc = SQLITE_OK;
164810 }else if( op==SQLITE_FCNTL_JOURNAL_POINTER ){
164811 *(sqlite3_file**)pArg = sqlite3PagerJrnlFile(pPager);
164812 rc = SQLITE_OK;
164813 }else if( op==SQLITE_FCNTL_DATA_VERSION ){
164814 *(unsigned int*)pArg = sqlite3PagerDataVersion(pPager);
164815 rc = SQLITE_OK;
164816 }else if( op==SQLITE_FCNTL_RESERVE_BYTES ){
164817 int iNew = *(int*)pArg;
164818 *(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree);
164819 if( iNew>=0 && iNew<=255 ){
164820 sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0);
164821 }
164822 rc = SQLITE_OK;
164823 }else{
164824 rc = sqlite3OsFileControl(fd, op, pArg);
#define SQLITE_FCNTL_DATA_VERSION
Definition sqlite3.c:2212
SQLITE_PRIVATE Btree * sqlite3DbNameToBtree(sqlite3 *, const char *)
Definition sqlite3.c:165375
#define SQLITE_FCNTL_FILE_POINTER
Definition sqlite3.c:2185
SQLITE_PRIVATE sqlite3_vfs * sqlite3PagerVfs(Pager *)
Definition sqlite3.c:58685
#define SQLITE_FCNTL_VFS_POINTER
Definition sqlite3.c:2204
SQLITE_PRIVATE sqlite3_file * sqlite3PagerJrnlFile(Pager *)
Definition sqlite3.c:58702
SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree *)
Definition sqlite3.c:67396
#define SQLITE_FCNTL_JOURNAL_POINTER
Definition sqlite3.c:2205
SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *)
Definition sqlite3.c:53456
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix)
Definition sqlite3.c:67334
#define SQLITE_FCNTL_RESERVE_BYTES
Definition sqlite3.c:2215

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ sqlite3_filename_database()

SQLITE_API const char * sqlite3_filename_database ( const char * zFilename)

Definition at line 165350 of file sqlite3.c.

◆ sqlite3_filename_journal()

SQLITE_API const char * sqlite3_filename_journal ( const char * zFilename)

Definition at line 165353 of file sqlite3.c.

165356 {
165357 return databaseName(zFilename);
165358}
165359SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){
165360 zFilename = databaseName(zFilename);
165361 zFilename += sqlite3Strlen30(zFilename) + 1;
static const char * databaseName(const char *zName)
Definition sqlite3.c:165215
SQLITE_API const char * sqlite3_filename_journal(const char *)
Definition sqlite3.c:165353

References databaseName().

◆ sqlite3_filename_wal()

SQLITE_API const char * sqlite3_filename_wal ( const char * zFilename)

Definition at line 165362 of file sqlite3.c.

165362 {
165363 zFilename += sqlite3Strlen30(zFilename) + 1;
165364 zFilename += sqlite3Strlen30(zFilename) + 1;
165365 }
165366 return zFilename + 1;
165367}
165368SQLITE_API const char *sqlite3_filename_wal(const char *zFilename){
165369#ifdef SQLITE_OMIT_WAL
165370 return 0;
SQLITE_API const char * sqlite3_filename_wal(const char *)
Definition sqlite3.c:165362

References sqlite3Strlen30().

◆ sqlite3_finalize()

SQLITE_API int sqlite3_finalize ( sqlite3_stmt * pStmt)

Definition at line 83080 of file sqlite3.c.

83086 {
83087 int rc;
83088 if( pStmt==0 ){
83089 /* IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL
83090 ** pointer is a harmless no-op. */
83091 rc = SQLITE_OK;
83092 }else{
83093 Vdbe *v = (Vdbe*)pStmt;
83094 sqlite3 *db = v->db;
83095 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
83097 checkProfileCallback(db, v);
#define checkProfileCallback(DB, P)
Definition sqlite3.c:83065
static int vdbeSafety(Vdbe *p)
Definition sqlite3.c:83020

References checkProfileCallback, Vdbe::db, sqlite3::mutex, sqlite3_mutex_enter(), sqlite3ApiExit(), sqlite3LeaveMutexAndCloseZombie(), sqlite3VdbeFinalize(), SQLITE_MISUSE_BKPT, SQLITE_OK, and vdbeSafety().

Referenced by blobSeekToRow(), cleanupvm(), db_close_vm(), db_do_next_row(), and sqlite3InitCallback().

◆ sqlite3_free()

SQLITE_API void sqlite3_free ( void * p)

Definition at line 27692 of file sqlite3.c.

27697 {
27698 if( p==0 ) return; /* IMP: R-49053-54554 */
27700 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
27701 if( sqlite3GlobalConfig.bMemstat ){
27705 sqlite3GlobalConfig.m.xFree(p);
#define SQLITE_STATUS_MALLOC_COUNT
Definition sqlite3.c:9059

Referenced by attachFunc(), btreeRestoreCursorPosition(), charFunc(), clearAllSharedCacheTableLocks(), closeUnixFile(), createFunctionApi(), db_load_extension(), findInodeInfo(), loadExt(), lsqlite_temp_directory(), openDatabase(), pager_delsuper(), pcache1Destroy(), pcache1ResizeHash(), pthreadMutexFree(), quoteFunc(), rehash(), releaseAllSavepoints(), releaseInodeInfo(), renameColumnParseError(), renameEditSql(), replaceFunc(), saveCursorKey(), setupLookaside(), sqlite3_backup_init(), sqlite3_free_filename(), sqlite3_get_table(), sqlite3_get_table_cb(), sqlite3_overload_function(), sqlite3AnalysisLoad(), sqlite3AutoLoadExtensions(), sqlite3BitvecBuiltinTest(), sqlite3BtreeIntegrityCheck(), sqlite3BtreeMovetoUnpacked(), sqlite3BtreeOpen(), sqlite3InvalidFunction(), sqlite3LeaveMutexAndCloseZombie(), sqlite3LoadExtension(), sqlite3NotPureFunc(), sqlite3OsInit(), sqlite3PagerClose(), sqlite3PagerOpen(), sqlite3Pragma(), sqlite3RunParser(), sqlite3VdbeExec(), sqlite3VdbeList(), sqlite3VdbeMemGrow(), sqlite3VtabImportErrmsg(), sqlite3WalOpen(), statGet(), unixFullPathname(), unixOpen(), unixOpenSharedMemory(), unixShmPurge(), unixShmUnmap(), vdbePmaWriterFinish(), vdbeSorterListToPMA(), vtabBestIndex(), vtabCallConstructor(), walBeginShmUnreliable(), walIndexRecover(), walIteratorInit(), walRewriteChecksums(), whereLoopAddVirtual(), and whereLoopAddVirtualOne().

◆ sqlite3_free_filename()

SQLITE_API void sqlite3_free_filename ( char * p)

Definition at line 165277 of file sqlite3.c.

References databaseName(), and sqlite3_free().

Referenced by attachFunc(), openDatabase(), and sqlite3ParseUri().

◆ sqlite3_free_table()

SQLITE_API void sqlite3_free_table ( char ** result)

Definition at line 136368 of file sqlite3.c.

136376 {
136377 if( azResult ){
136378 int i, n;
136379 azResult--;

Referenced by sqlite3_get_table().

◆ sqlite3_get_autocommit()

SQLITE_API int sqlite3_get_autocommit ( sqlite3 * db)

Definition at line 164561 of file sqlite3.c.

164567 {
164568#ifdef SQLITE_ENABLE_API_ARMOR
164569 if( !sqlite3SafetyCheckOk(db) ){

References sqlite3::autoCommit, sqlite3SafetyCheckOk(), and SQLITE_MISUSE_BKPT.

◆ sqlite3_get_auxdata()

SQLITE_API void * sqlite3_get_auxdata ( sqlite3_context * pCtx,
int N )

Definition at line 83888 of file sqlite3.c.

83890 : If iArg is negative then access a cache of
83891** auxiliary data pointers that is available to all functions within a
83892** single prepared statement. The iArg values must match.
83893*/
83894SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
83895 AuxData *pAuxData;
83896
83897 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83898#if SQLITE_ENABLE_STAT4
83899 if( pCtx->pVdbe==0 ) return 0;
83900#else
83901 assert( pCtx->pVdbe!=0 );
83902#endif
83903 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
static int statement(LexState *ls)
SQLITE_API void * sqlite3_get_auxdata(sqlite3_context *, int N)
Definition sqlite3.c:83888
AuxData * pNextAux
Definition sqlite3.c:21017
AuxData * pAuxData
Definition sqlite3.c:21148

References sqlite3_value::db, AuxData::iAuxArg, AuxData::iAuxOp, sqlite3_context::iOp, sqlite3::mutex, AuxData::pAux, Vdbe::pAuxData, AuxData::pNextAux, sqlite3_context::pOut, sqlite3_context::pVdbe, and sqlite3_mutex_held().

◆ sqlite3_get_table()

SQLITE_API int sqlite3_get_table ( sqlite3 * db,
const char * zSql,
char *** pazResult,
int * pnRow,
int * pnColumn,
char ** pzErrmsg )

Definition at line 136299 of file sqlite3.c.

136312 {
136313 int rc;
136314 TabResult res;
136315
136316#ifdef SQLITE_ENABLE_API_ARMOR
136317 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
136318#endif
136319 *pazResult = 0;
136320 if( pnColumn ) *pnColumn = 0;
136321 if( pnRow ) *pnRow = 0;
136322 if( pzErrMsg ) *pzErrMsg = 0;
136323 res.zErrMsg = 0;
136324 res.nRow = 0;
136325 res.nColumn = 0;
136326 res.nData = 1;
136327 res.nAlloc = 20;
136328 res.rc = SQLITE_OK;
136329 res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
136330 if( res.azResult==0 ){
136331 db->errCode = SQLITE_NOMEM;
136332 return SQLITE_NOMEM_BKPT;
136333 }
136334 res.azResult[0] = 0;
136335 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
136336 assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
136337 res.azResult[0] = SQLITE_INT_TO_PTR(res.nData);
136338 if( (rc&0xff)==SQLITE_ABORT ){
136339 sqlite3_free_table(&res.azResult[1]);
136340 if( res.zErrMsg ){
136341 if( pzErrMsg ){
136342 sqlite3_free(*pzErrMsg);
136343 *pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg);
136344 }
136345 sqlite3_free(res.zErrMsg);
136346 }
136347 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
136348 return res.rc;
136349 }
136350 sqlite3_free(res.zErrMsg);
136351 if( rc!=SQLITE_OK ){
136352 sqlite3_free_table(&res.azResult[1]);
136353 return rc;
136354 }
136355 if( res.nAlloc>res.nData ){
136356 char **azNew;
136357 azNew = sqlite3Realloc( res.azResult, sizeof(char*)*res.nData );
136358 if( azNew==0 ){
136359 sqlite3_free_table(&res.azResult[1]);
136360 db->errCode = SQLITE_NOMEM;
136361 return SQLITE_NOMEM_BKPT;
136362 }
136363 res.azResult = azNew;
static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv)
Definition sqlite3.c:136225
SQLITE_API int sqlite3_exec(sqlite3 *, const char *sql, int(*callback)(void *, int, char **, char **), void *, char **errmsg)
Definition sqlite3.c:123455
SQLITE_API void sqlite3_free_table(char **result)
Definition sqlite3.c:136368
char * zErrMsg
Definition sqlite3.c:136212
char ** azResult
Definition sqlite3.c:136211

References TabResult::azResult, sqlite3::errCode, TabResult::nAlloc, TabResult::nColumn, TabResult::nData, TabResult::nRow, TabResult::rc, sqlite3_exec(), sqlite3_free(), sqlite3_free_table(), sqlite3_get_table_cb(), sqlite3_malloc64(), sqlite3_mprintf(), sqlite3Realloc(), sqlite3SafetyCheckOk(), SQLITE_ABORT, SQLITE_INT_TO_PTR, SQLITE_MISUSE_BKPT, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, and TabResult::zErrMsg.

◆ sqlite3_get_table_cb()

static int sqlite3_get_table_cb ( void * pArg,
int nCol,
char ** argv,
char ** colv )
static

Definition at line 136225 of file sqlite3.c.

136231 {
136232 TabResult *p = (TabResult*)pArg; /* Result accumulator */
136233 int need; /* Slots needed in p->azResult[] */
136234 int i; /* Loop counter */
136235 char *z; /* A single column of result */
136236
136237 /* Make sure there is enough space in p->azResult to hold everything
136238 ** we need to remember from this invocation of the callback.
136239 */
136240 if( p->nRow==0 && argv!=0 ){
136241 need = nCol*2;
136242 }else{
136243 need = nCol;
136244 }
136245 if( p->nData + need > p->nAlloc ){
136246 char **azNew;
136247 p->nAlloc = p->nAlloc*2 + need;
136248 azNew = sqlite3Realloc( p->azResult, sizeof(char*)*p->nAlloc );
136249 if( azNew==0 ) goto malloc_failed;
136250 p->azResult = azNew;
136251 }
136252
136253 /* If this is the first row, then generate an extra row containing
136254 ** the names of all columns.
136255 */
136256 if( p->nRow==0 ){
136257 p->nColumn = nCol;
136258 for(i=0; i<nCol; i++){
136259 z = sqlite3_mprintf("%s", colv[i]);
136260 if( z==0 ) goto malloc_failed;
136261 p->azResult[p->nData++] = z;
136262 }
136263 }else if( (int)p->nColumn!=nCol ){
136264 sqlite3_free(p->zErrMsg);
136266 "sqlite3_get_table() called with two or more incompatible queries"
136267 );
136268 p->rc = SQLITE_ERROR;
136269 return 1;
136270 }
136271
136272 /* Copy over the row data
136273 */
136274 if( argv!=0 ){
136275 for(i=0; i<nCol; i++){
136276 if( argv[i]==0 ){
136277 z = 0;
136278 }else{
136279 int n = sqlite3Strlen30(argv[i])+1;
136280 z = sqlite3_malloc64( n );
136281 if( z==0 ) goto malloc_failed;
136282 memcpy(z, argv[i], n);
136283 }
136284 p->azResult[p->nData++] = z;
136285 }
136286 p->nRow++;
136287 }

References TabResult::azResult, TabResult::nAlloc, TabResult::nColumn, TabResult::nData, TabResult::nRow, TabResult::rc, sqlite3_free(), sqlite3_malloc64(), sqlite3_mprintf(), sqlite3Realloc(), sqlite3Strlen30(), SQLITE_ERROR, SQLITE_NOMEM_BKPT, and TabResult::zErrMsg.

Referenced by sqlite3_get_table().

◆ sqlite3_global_recover()

SQLITE_API int sqlite3_global_recover ( void )

Definition at line 164550 of file sqlite3.c.

References SQLITE_OK.

◆ sqlite3_hard_heap_limit64()

SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64 ( sqlite3_int64 N)

Definition at line 27449 of file sqlite3.c.

27454 {
27455 sqlite3_int64 priorLimit;
27456#ifndef SQLITE_OMIT_AUTOINIT
27457 int rc = sqlite3_initialize();
27458 if( rc ) return -1;
27459#endif
27461 priorLimit = mem0.hardLimit;
27462 if( n>=0 ){
27463 mem0.hardLimit = n;
27464 if( n<mem0.alarmThreshold || mem0.alarmThreshold==0 ){
27465 mem0.alarmThreshold = n;

References mem0, sqlite3_initialize(), sqlite3_mutex_enter(), and sqlite3_mutex_leave().

Referenced by sqlite3Pragma().

◆ sqlite3_initialize()

SQLITE_API int sqlite3_initialize ( void )

Definition at line 161196 of file sqlite3.c.

161202 {
161203 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
161204 int rc; /* Result code */
161205#ifdef SQLITE_EXTRA_INIT
161206 int bRunExtraInit = 0; /* Extra initialization needed */
161207#endif
161208
161209#ifdef SQLITE_OMIT_WSD
161210 rc = sqlite3_wsd_init(4096, 24);
161211 if( rc!=SQLITE_OK ){
161212 return rc;
161213 }
161214#endif
161215
161216 /* If the following assert() fails on some obscure processor/compiler
161217 ** combination, the work-around is to set the correct pointer
161218 ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
161219 assert( SQLITE_PTRSIZE==sizeof(char*) );
161220
161221 /* If SQLite is already completely initialized, then this call
161222 ** to sqlite3_initialize() should be a no-op. But the initialization
161223 ** must be complete. So isInit must not be set until the very end
161224 ** of this routine.
161225 */
161226 if( sqlite3GlobalConfig.isInit ){
161228 return SQLITE_OK;
161229 }
161230
161231 /* Make sure the mutex subsystem is initialized. If unable to
161232 ** initialize the mutex subsystem, return early with the error.
161233 ** If the system is so sick that we are unable to allocate a mutex,
161234 ** there is not much SQLite is going to be able to do.
161235 **
161236 ** The mutex subsystem must take care of serializing its own
161237 ** initialization.
161238 */
161239 rc = sqlite3MutexInit();
161240 if( rc ) return rc;
161241
161242 /* Initialize the malloc() system and the recursive pInitMutex mutex.
161243 ** This operation is protected by the STATIC_MAIN mutex. Note that
161244 ** MutexAlloc() is called for a static mutex prior to initializing the
161245 ** malloc subsystem - this implies that the allocation of a static
161246 ** mutex must not require support from the malloc subsystem.
161247 */
161249 sqlite3_mutex_enter(pMainMtx);
161250 sqlite3GlobalConfig.isMutexInit = 1;
161251 if( !sqlite3GlobalConfig.isMallocInit ){
161252 rc = sqlite3MallocInit();
161253 }
161254 if( rc==SQLITE_OK ){
161255 sqlite3GlobalConfig.isMallocInit = 1;
161256 if( !sqlite3GlobalConfig.pInitMutex ){
161257 sqlite3GlobalConfig.pInitMutex =
161259 if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
161260 rc = SQLITE_NOMEM_BKPT;
161261 }
161262 }
161263 }
161264 if( rc==SQLITE_OK ){
161265 sqlite3GlobalConfig.nRefInitMutex++;
161266 }
161267 sqlite3_mutex_leave(pMainMtx);
161268
161269 /* If rc is not SQLITE_OK at this point, then either the malloc
161270 ** subsystem could not be initialized or the system failed to allocate
161271 ** the pInitMutex mutex. Return an error in either case. */
161272 if( rc!=SQLITE_OK ){
161273 return rc;
161274 }
161275
161276 /* Do the rest of the initialization under the recursive mutex so
161277 ** that we will be able to handle recursive calls into
161278 ** sqlite3_initialize(). The recursive calls normally come through
161279 ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
161280 ** recursive calls might also be possible.
161281 **
161282 ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
161283 ** to the xInit method, so the xInit method need not be threadsafe.
161284 **
161285 ** The following mutex is what serializes access to the appdef pcache xInit
161286 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
161287 ** call to sqlite3PcacheInitialize().
161288 */
161290 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
161291 sqlite3GlobalConfig.inProgress = 1;
161292#ifdef SQLITE_ENABLE_SQLLOG
161293 {
161294 extern void sqlite3_init_sqllog(void);
161295 sqlite3_init_sqllog();
161296 }
161297#endif
161300 if( sqlite3GlobalConfig.isPCacheInit==0 ){
161302 }
161303 if( rc==SQLITE_OK ){
161304 sqlite3GlobalConfig.isPCacheInit = 1;
161305 rc = sqlite3OsInit();
161306 }
161307#ifdef SQLITE_ENABLE_DESERIALIZE
161308 if( rc==SQLITE_OK ){
161309 rc = sqlite3MemdbInit();
161310 }
161311#endif
161312 if( rc==SQLITE_OK ){
161316 sqlite3GlobalConfig.isInit = 1;
161317#ifdef SQLITE_EXTRA_INIT
161318 bRunExtraInit = 1;
161319#endif
161320 }
161321 sqlite3GlobalConfig.inProgress = 0;
161322 }
161324
161325 /* Go back under the static mutex and clean up the recursive
161326 ** mutex to prevent a resource leak.
161327 */
161328 sqlite3_mutex_enter(pMainMtx);
161329 sqlite3GlobalConfig.nRefInitMutex--;
161330 if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
161331 assert( sqlite3GlobalConfig.nRefInitMutex==0 );
161333 sqlite3GlobalConfig.pInitMutex = 0;
161334 }
161335 sqlite3_mutex_leave(pMainMtx);
161336
161337 /* The following is just a sanity check to make sure SQLite has
161338 ** been compiled correctly. It is important to run this code, but
161339 ** we don't want to run it too often and soak up CPU cycles for no
161340 ** reason. So we run it once during initialization.
161341 */
161342#ifndef NDEBUG
161343#ifndef SQLITE_OMIT_FLOATING_POINT
161344 /* This section of code's only "output" is via assert() statements. */
161345 if( rc==SQLITE_OK ){
161346 u64 x = (((u64)1)<<63)-1;
161347 double y;
161348 assert(sizeof(x)==8);
161349 assert(sizeof(x)==sizeof(y));
161350 memcpy(&y, &x, 8);
161351 assert( sqlite3IsNaN(y) );
161352 }
161353#endif
161354#endif
161355
161356 /* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
161357 ** compile-time option.
161358 */
161359#ifdef SQLITE_EXTRA_INIT
161360 if( bRunExtraInit ){
161361 int SQLITE_EXTRA_INIT(const char*);
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions
Definition sqlite3.c:20634
SQLITE_PRIVATE int sqlite3PcacheInitialize(void)
Definition sqlite3.c:49132
SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void)
Definition sqlite3.c:118958
SQLITE_PRIVATE void sqlite3MemoryBarrier(void)
Definition sqlite3.c:26314
SQLITE_PRIVATE int sqlite3MutexInit(void)
Definition sqlite3.c:25860
#define SQLITE_PTRSIZE
Definition sqlite3.c:14393
SQLITE_PRIVATE int sqlite3MallocInit(void)
Definition sqlite3.c:27471
SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *, int sz, int n)
Definition sqlite3.c:50022
SQLITE_PRIVATE int sqlite3IsNaN(double)
Definition sqlite3.c:31244
SQLITE_PRIVATE int sqlite3OsInit(void)
Definition sqlite3.c:23290

References MUTEX_LOGIC, sqlite3_mutex_enter(), sqlite3_mutex_free(), sqlite3_mutex_leave(), sqlite3BuiltinFunctions, sqlite3GlobalConfig, sqlite3IsNaN(), sqlite3MallocInit(), sqlite3MemoryBarrier(), sqlite3MutexAlloc(), sqlite3MutexInit(), sqlite3OsInit(), sqlite3PCacheBufferSetup(), sqlite3PcacheInitialize(), sqlite3RegisterBuiltinFunctions(), SQLITE_MUTEX_RECURSIVE, SQLITE_MUTEX_STATIC_MAIN, SQLITE_NOMEM_BKPT, SQLITE_OK, and SQLITE_PTRSIZE.

Referenced by openDatabase(), sqlite3_auto_extension(), sqlite3_complete16(), sqlite3_hard_heap_limit64(), sqlite3_soft_heap_limit64(), sqlite3_vfs_find(), and sqlite3_vfs_register().

◆ sqlite3_interrupt()

SQLITE_API void sqlite3_interrupt ( sqlite3 * db)

Definition at line 162748 of file sqlite3.c.

162754 {
162755#ifdef SQLITE_ENABLE_API_ARMOR
162756 if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){
#define SQLITE_MAGIC_ZOMBIE
Definition sqlite3.c:17082

Referenced by db_interrupt(), and sqlite3VdbeExec().

◆ sqlite3_keyword_check()

SQLITE_API int sqlite3_keyword_check ( const char * zName,
int nName )

Definition at line 159878 of file sqlite3.c.

◆ sqlite3_keyword_count()

SQLITE_API int sqlite3_keyword_count ( void )

Definition at line 159877 of file sqlite3.c.

159877{

◆ sqlite3_keyword_name()

SQLITE_API int sqlite3_keyword_name ( int i,
const char ** pzName,
int * pnName )

Definition at line 159871 of file sqlite3.c.

159871 {
159872 int id = TK_ID;
159873 keywordCode((char*)z, n, &id);
159874 return id;
159875}
159876#define SQLITE_N_KEYWORD 145

References keywordCode(), and TK_ID.

◆ sqlite3_last_insert_rowid()

SQLITE_API sqlite_int64 sqlite3_last_insert_rowid ( sqlite3 * db)

Definition at line 162054 of file sqlite3.c.

162060 {
162061#ifdef SQLITE_ENABLE_API_ARMOR
162062 if( !sqlite3SafetyCheckOk(db) ){

Referenced by db_last_insert_rowid(), and dbvm_last_insert_rowid().

◆ sqlite3_libversion()

SQLITE_API const char * sqlite3_libversion ( void )

Definition at line 161104 of file sqlite3.c.

References sqlite3_version.

Referenced by lsqlite_version().

◆ sqlite3_libversion_number()

SQLITE_API int sqlite3_libversion_number ( void )

Definition at line 161117 of file sqlite3.c.

◆ sqlite3_limit()

SQLITE_API int sqlite3_limit ( sqlite3 * db,
int id,
int newVal )

Definition at line 163728 of file sqlite3.c.

163734 {
163735 int oldLimit;
163736
163737#ifdef SQLITE_ENABLE_API_ARMOR
163738 if( !sqlite3SafetyCheckOk(db) ){
163739 (void)SQLITE_MISUSE_BKPT;
163740 return -1;
163741 }
163742#endif
163743
163744 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
163745 ** there is a hard upper bound set at compile-time by a C preprocessor
163746 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
163747 ** "_MAX_".)
163748 */
163763
163764
163765 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
163766 return -1;
163767 }
163768 oldLimit = db->aLimit[limitId];
163769 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
163770 if( newLimit>aHardLimit[limitId] ){
#define SQLITE_MAX_FUNCTION_ARG
Definition sqlite3.c:13334
#define SQLITE_MAX_COMPOUND_SELECT
Definition sqlite3.c:13319
#define SQLITE_MAX_LIKE_PATTERN_LENGTH
Definition sqlite3.c:13439
#define SQLITE_LIMIT_FUNCTION_ARG
Definition sqlite3.c:4950
#define SQLITE_MAX_COLUMN
Definition sqlite3.c:13282
#define SQLITE_MAX_EXPR_DEPTH
Definition sqlite3.c:13307
#define SQLITE_LIMIT_EXPR_DEPTH
Definition sqlite3.c:4947
#define SQLITE_MAX_WORKER_THREADS
Definition sqlite3.c:14212
#define SQLITE_MAX_VDBE_OP
Definition sqlite3.c:13327
#define SQLITE_LIMIT_TRIGGER_DEPTH
Definition sqlite3.c:4954
#define SQLITE_MAX_ATTACHED
Definition sqlite3.c:13365
#define SQLITE_MAX_SQL_LENGTH
Definition sqlite3.c:13293
#define SQLITE_LIMIT_VARIABLE_NUMBER
Definition sqlite3.c:4953
#define SQLITE_MAX_VARIABLE_NUMBER
Definition sqlite3.c:13376
#define SQLITE_MAX_TRIGGER_DEPTH
Definition sqlite3.c:13450
#define SQLITE_N_LIMIT
Definition sqlite3.c:16671

References aHardLimit, sqlite3::aLimit, sqlite3SafetyCheckOk(), SQLITE_LIMIT_ATTACHED, SQLITE_LIMIT_COLUMN, SQLITE_LIMIT_COMPOUND_SELECT, SQLITE_LIMIT_EXPR_DEPTH, SQLITE_LIMIT_FUNCTION_ARG, SQLITE_LIMIT_LENGTH, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, SQLITE_LIMIT_SQL_LENGTH, SQLITE_LIMIT_TRIGGER_DEPTH, SQLITE_LIMIT_VARIABLE_NUMBER, SQLITE_LIMIT_VDBE_OP, SQLITE_LIMIT_WORKER_THREADS, SQLITE_MAX_ATTACHED, SQLITE_MAX_COLUMN, SQLITE_MAX_COMPOUND_SELECT, SQLITE_MAX_EXPR_DEPTH, SQLITE_MAX_FUNCTION_ARG, SQLITE_MAX_LENGTH, SQLITE_MAX_LIKE_PATTERN_LENGTH, SQLITE_MAX_SQL_LENGTH, SQLITE_MAX_TRIGGER_DEPTH, SQLITE_MAX_VARIABLE_NUMBER, SQLITE_MAX_VDBE_OP, SQLITE_MAX_WORKER_THREADS, SQLITE_MISUSE_BKPT, and SQLITE_N_LIMIT.

Referenced by sqlite3Pragma().

◆ sqlite3_load_extension()

SQLITE_API int sqlite3_load_extension ( sqlite3 * db,
const char * zFile,
const char * zProc,
char ** pzErrMsg )

Definition at line 124876 of file sqlite3.c.

124887 {
124888 int rc;

Referenced by db_load_extension(), and loadExt().

◆ sqlite3_log()

◆ sqlite3_malloc()

SQLITE_API void * sqlite3_malloc ( int n)

Definition at line 27615 of file sqlite3.c.

27620 {

Referenced by sqlite3OsInit(), unixFullPathname(), and walRewriteChecksums().

◆ sqlite3_malloc64()

◆ sqlite3_memory_alarm() [1/2]

SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm ( void(*)(void *, sqlite3_int64, int) ,
void * ,
sqlite3_int64  )

◆ sqlite3_memory_alarm() [2/2]

SQLITE_API int sqlite3_memory_alarm ( void(*)(void *pArg, sqlite3_int64 used, int N) xCallback,
void * pArg,
sqlite3_int64 iThreshold )

Definition at line 27384 of file sqlite3.c.

27393 {

References SQLITE_OK.

◆ sqlite3_memory_highwater()

SQLITE_API sqlite3_int64 sqlite3_memory_highwater ( int resetFlag)

Definition at line 27521 of file sqlite3.c.

References sqlite3_status64(), and SQLITE_STATUS_MEMORY_USED.

◆ sqlite3_memory_used()

SQLITE_API sqlite3_int64 sqlite3_memory_used ( void )

Definition at line 27510 of file sqlite3.c.

◆ sqlite3_mprintf()

SQLITE_API char * sqlite3_mprintf ( const char * zFormat,
... )

◆ sqlite3_msize()

SQLITE_API sqlite3_uint64 sqlite3_msize ( void * p)

Definition at line 27683 of file sqlite3.c.

◆ sqlite3_mutex_alloc()

SQLITE_API sqlite3_mutex * sqlite3_mutex_alloc ( int id)

Definition at line 25922 of file sqlite3.c.

25927 {
25928#ifndef SQLITE_OMIT_AUTOINIT
25929 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;

Referenced by findInodeInfo(), and unixOpenSharedMemory().

◆ sqlite3_mutex_enter()

◆ sqlite3_mutex_free()

SQLITE_API void sqlite3_mutex_free ( sqlite3_mutex * p)

◆ sqlite3_mutex_held()

SQLITE_API int sqlite3_mutex_held ( sqlite3_mutex * )

Referenced by allocateBtreePage(), allocateSpace(), autoVacuumCommit(), backupUpdate(), balance_deeper(), balance_nonroot(), balance_quick(), btreeEnterAll(), btreeGetPage(), btreeInitPage(), btreePageLookup(), btreeParseCellPtrNoPayload(), columnMallocFailure(), decodeFlags(), defragmentPage(), dropCell(), fetchPayload(), fillInCell(), freePage2(), freeSpace(), getAndInitPage(), getOverflowPage(), incrVacuumStep(), insertCell(), invalidateAllOverflowCache(), lockBtree(), lockBtreeMutex(), mallocWithAlarm(), modifyPagePointer(), newDatabase(), pageReinit(), pcache1PinPage(), pcache1RemoveFromHash(), pcache1ResizeHash(), pcache1TruncateUnsafe(), ptrmapGet(), ptrmapPageno(), ptrmapPut(), relocatePage(), saveAllCursors(), schemaIsValid(), setChildPtrmaps(), sqlite3_aggregate_context(), sqlite3_get_auxdata(), sqlite3_result_blob64(), sqlite3_result_error16(), sqlite3_result_int(), sqlite3_result_text(), sqlite3_result_text16be(), sqlite3_result_text16le(), sqlite3_result_text64(), sqlite3_result_value(), sqlite3_set_auxdata(), sqlite3ApiExit(), sqlite3BackupRestart(), sqlite3BtreeEnter(), sqlite3BtreeGetReserveNoMutex(), sqlite3BtreeIsInBackup(), sqlite3BtreeMovetoUnpacked(), sqlite3BtreeOpen(), sqlite3BtreePutData(), sqlite3BtreeRowCountEst(), sqlite3BtreeSchemaLocked(), sqlite3BtreeSetCacheSize(), sqlite3BtreeSetPagerFlags(), sqlite3BtreeSetSpillSize(), sqlite3Checkpoint(), sqlite3CreateFunc(), sqlite3DbFreeNN(), sqlite3DbRealloc(), sqlite3Init(), sqlite3InitCallback(), sqlite3InitOne(), sqlite3Reprepare(), sqlite3ResultIntReal(), sqlite3RollbackAll(), sqlite3SchemaToIndex(), sqlite3StatusHighwater(), sqlite3StatusUp(), sqlite3StatusValue(), sqlite3ValueText(), sqlite3VdbeChangeEncoding(), sqlite3VdbeMemAggValue(), sqlite3VdbeMemExpandBlob(), sqlite3VdbeMemFinalize(), sqlite3VdbeMemMakeWriteable(), sqlite3VdbeMemMove(), sqlite3VdbeMemNumerify(), sqlite3VdbeMemSetStr(), sqlite3VdbeMemStringify(), sqlite3VdbeMemTranslate(), sqlite3VtabDisconnect(), sqlite3VtabUnlockList(), unixFileLock(), unixShmSystemLock(), unlockBtreeIfUnused(), valueToText(), and vdbeMemClearExternAndSetNull().

◆ sqlite3_mutex_leave()

◆ sqlite3_mutex_notheld()

◆ sqlite3_mutex_try()

SQLITE_API int sqlite3_mutex_try ( sqlite3_mutex * p)

Definition at line 25965 of file sqlite3.c.

25970 {
25971 int rc = SQLITE_OK;
25972 if( p ){

References sqlite3GlobalConfig, and SQLITE_OK.

Referenced by btreeLockCarefully().

◆ sqlite3_next_stmt()

SQLITE_API sqlite3_stmt * sqlite3_next_stmt ( sqlite3 * pDb,
sqlite3_stmt * pStmt )

Definition at line 84680 of file sqlite3.c.

84686 {
84687 sqlite3_stmt *pNext;
84688#ifdef SQLITE_ENABLE_API_ARMOR
84689 if( !sqlite3SafetyCheckOk(pDb) ){
84690 (void)SQLITE_MISUSE_BKPT;
84691 return 0;
84692 }
84693#endif
84695 if( pStmt==0 ){
84696 pNext = (sqlite3_stmt*)pDb->pVdbe;

References sqlite3::mutex, sqlite3::pVdbe, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), and SQLITE_MISUSE_BKPT.

◆ sqlite3_normalized_sql()

SQLITE_API const char * sqlite3_normalized_sql ( sqlite3_stmt * pStmt)

◆ sqlite3_open()

SQLITE_API int sqlite3_open ( const char * filename,
sqlite3 ** ppDb )

Definition at line 164380 of file sqlite3.c.

◆ sqlite3_open16()

SQLITE_API int sqlite3_open16 ( const void * filename,
sqlite3 ** ppDb )

Definition at line 164400 of file sqlite3.c.

164409 {
164410 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
164411 sqlite3_value *pVal;
164412 int rc;
164413
164414#ifdef SQLITE_ENABLE_API_ARMOR
164415 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
164416#endif
164417 *ppDb = 0;
164418#ifndef SQLITE_OMIT_AUTOINIT
164419 rc = sqlite3_initialize();
164420 if( rc ) return rc;
164421#endif
164422 if( zFilename==0 ) zFilename = "\000\000";
164423 pVal = sqlite3ValueNew(0);
164424 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
164425 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
164426 if( zFilename8 ){
164427 rc = openDatabase(zFilename8, ppDb,
164429 assert( *ppDb || rc==SQLITE_NOMEM );
164430 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
164431 SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
164432 }
164433 }else{
static int openDatabase(const char *zFilename, sqlite3 **ppDb, unsigned int flags, const char *zVfs)
Definition sqlite3.c:164053
#define DB_SchemaLoaded
Definition sqlite3.c:16663
#define DbHasProperty(D, I, P)
Definition sqlite3.c:16648

◆ sqlite3_open_v2()

SQLITE_API int sqlite3_open_v2 ( const char * filename,
sqlite3 ** ppDb,
int flags,
const char * zVfs )

Definition at line 164387 of file sqlite3.c.

164389 {
164390 return openDatabase(zFilename, ppDb,
164392}
164394 const char *filename, /* Database filename (UTF-8) */
SQLITE_API int sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs)
Definition sqlite3.c:164387

References openDatabase(), SQLITE_OPEN_CREATE, and SQLITE_OPEN_READWRITE.

◆ sqlite3_os_end()

SQLITE_API int sqlite3_os_end ( void )

Definition at line 41473 of file sqlite3.c.

References SQLITE_OK, and unixBigLock.

Referenced by sqlite3_shutdown().

◆ sqlite3_os_init()

SQLITE_API int sqlite3_os_init ( void )

Definition at line 41373 of file sqlite3.c.

41379 {
41380 /*
41381 ** The following macro defines an initializer for an sqlite3_vfs object.
41382 ** The name of the VFS is NAME. The pAppData is a pointer to a pointer
41383 ** to the "finder" function. (pAppData is a pointer to a pointer because
41384 ** silly C90 rules prohibit a void* from being cast to a function pointer
41385 ** and so we have to go through the intermediate pointer to avoid problems
41386 ** when compiling with -pedantic-errors on GCC.)
41387 **
41388 ** The FINDER parameter to this macro is the name of the pointer to the
41389 ** finder-function. The finder-function returns a pointer to the
41390 ** sqlite_io_methods object that implements the desired locking
41391 ** behaviors. See the division above that contains the IOMETHODS
41392 ** macro for addition information on finder-functions.
41393 **
41394 ** Most finders simply return a pointer to a fixed sqlite3_io_methods
41395 ** object. But the "autolockIoFinder" available on MacOSX does a little
41396 ** more than that; it looks at the filesystem type that hosts the
41397 ** database file and tries to choose an locking method appropriate for
41398 ** that filesystem time.
41399 */
41400 #define UNIXVFS(VFSNAME, FINDER) { \
41401 3, /* iVersion */ \
41402 sizeof(unixFile), /* szOsFile */ \
41403 MAX_PATHNAME, /* mxPathname */ \
41404 0, /* pNext */ \
41405 VFSNAME, /* zName */ \
41406 (void*)&FINDER, /* pAppData */ \
41407 unixOpen, /* xOpen */ \
41408 unixDelete, /* xDelete */ \
41409 unixAccess, /* xAccess */ \
41410 unixFullPathname, /* xFullPathname */ \
41411 unixDlOpen, /* xDlOpen */ \
41412 unixDlError, /* xDlError */ \
41413 unixDlSym, /* xDlSym */ \
41414 unixDlClose, /* xDlClose */ \
41415 unixRandomness, /* xRandomness */ \
41416 unixSleep, /* xSleep */ \
41417 unixCurrentTime, /* xCurrentTime */ \
41418 unixGetLastError, /* xGetLastError */ \
41419 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
41420 unixSetSystemCall, /* xSetSystemCall */ \
41421 unixGetSystemCall, /* xGetSystemCall */ \
41422 unixNextSystemCall, /* xNextSystemCall */ \
41423 }
41424
41425 /*
41426 ** All default VFSes for unix are contained in the following array.
41427 **
41428 ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
41429 ** by the SQLite core when the VFS is registered. So the following
41430 ** array cannot be const.
41431 */
41432 static sqlite3_vfs aVfs[] = {
41433#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
41434 UNIXVFS("unix", autolockIoFinder ),
41435#elif OS_VXWORKS
41436 UNIXVFS("unix", vxworksIoFinder ),
41437#else
41438 UNIXVFS("unix", posixIoFinder ),
41439#endif
41440 UNIXVFS("unix-none", nolockIoFinder ),
41441 UNIXVFS("unix-dotfile", dotlockIoFinder ),
41442 UNIXVFS("unix-excl", posixIoFinder ),
41443#if OS_VXWORKS
41444 UNIXVFS("unix-namedsem", semIoFinder ),
41445#endif
41446#if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS
41447 UNIXVFS("unix-posix", posixIoFinder ),
41448#endif
41449#if SQLITE_ENABLE_LOCKING_STYLE
41450 UNIXVFS("unix-flock", flockIoFinder ),
41451#endif
41452#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
41453 UNIXVFS("unix-afp", afpIoFinder ),
41454 UNIXVFS("unix-nfs", nfsIoFinder ),
41455 UNIXVFS("unix-proxy", proxyIoFinder ),
41456#endif
41457 };
41458 unsigned int i; /* Loop counter */
41459
41460 /* Double-check that the aSyscall[] array has been constructed
41461 ** correctly. See ticket [bb3a86e890c8e96ab] */
41462 assert( ArraySize(aSyscall)==29 );
41463
41464 /* Register all VFSes defined in the aVfs[] array */
#define UNIXVFS(VFSNAME, FINDER)

References ArraySize, aSyscall, sqlite3_vfs_register(), sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_VFS1, SQLITE_OK, unixBigLock, and UNIXVFS.

Referenced by sqlite3OsInit().

◆ sqlite3_overload_function()

SQLITE_API int sqlite3_overload_function ( sqlite3 * db,
const char * zFuncName,
int nArg )

Definition at line 163042 of file sqlite3.c.

163052 {
163053 int rc;
163054 char *zCopy;
163055
163056#ifdef SQLITE_ENABLE_API_ARMOR
163057 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
163058 return SQLITE_MISUSE_BKPT;
163059 }
163060#endif
163062 rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;

References sqlite3::mutex, sqlite3_create_function_v2(), sqlite3_free(), sqlite3_mprintf(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3FindFunction(), sqlite3InvalidFunction(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_NOMEM, SQLITE_OK, SQLITE_UTF8, and zName.

Referenced by sqlite3RegisterPerConnectionBuiltinFunctions().

◆ sqlite3_prepare()

SQLITE_API int sqlite3_prepare ( sqlite3 * db,
const char * zSql,
int nByte,
sqlite3_stmt ** ppStmt,
const char ** pzTail )

Definition at line 129134 of file sqlite3.c.

◆ sqlite3_prepare16()

SQLITE_API int sqlite3_prepare16 ( sqlite3 * db,
const void * zSql,
int nByte,
sqlite3_stmt ** ppStmt,
const void ** pzTail )

Definition at line 129250 of file sqlite3.c.

◆ sqlite3_prepare16_v2()

SQLITE_API int sqlite3_prepare16_v2 ( sqlite3 * db,
const void * zSql,
int nByte,
sqlite3_stmt ** ppStmt,
const void ** pzTail )

Definition at line 129262 of file sqlite3.c.

129262 {
129263 int rc;
129264 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
129265 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
129266 return rc;
129267}
129269 sqlite3 *db, /* Database handle. */
129270 const void *zSql, /* UTF-16 encoded SQL statement. */
129271 int nBytes, /* Length of zSql in bytes. */
129272 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
129273 const void **pzTail /* OUT: End of parsed string */
static int sqlite3Prepare16(sqlite3 *db, const void *zSql, int nBytes, u32 prepFlags, sqlite3_stmt **ppStmt, const void **pzTail)
Definition sqlite3.c:129192
SQLITE_API int sqlite3_prepare16_v2(sqlite3 *db, const void *zSql, int nByte, sqlite3_stmt **ppStmt, const void **pzTail)
Definition sqlite3.c:129262

References sqlite3Prepare16(), and SQLITE_OK.

◆ sqlite3_prepare16_v3()

SQLITE_API int sqlite3_prepare16_v3 ( sqlite3 * db,
const void * zSql,
int nByte,
unsigned int prepFlags,
sqlite3_stmt ** ppStmt,
const void ** pzTail )

Definition at line 129274 of file sqlite3.c.

129274 {
129275 int rc;
129276 rc = sqlite3Prepare16(db,zSql,nBytes,SQLITE_PREPARE_SAVESQL,ppStmt,pzTail);
129277 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
129278 return rc;
129279}
129281 sqlite3 *db, /* Database handle. */
129282 const void *zSql, /* UTF-16 encoded SQL statement. */
129283 int nBytes, /* Length of zSql in bytes. */
129284 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
129285 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
129286 const void **pzTail /* OUT: End of parsed string */
129287){
129288 int rc;
SQLITE_API int sqlite3_prepare16_v3(sqlite3 *db, const void *zSql, int nByte, unsigned int prepFlags, sqlite3_stmt **ppStmt, const void **pzTail)
Definition sqlite3.c:129274

References sqlite3Prepare16(), SQLITE_OK, and SQLITE_PREPARE_SAVESQL.

◆ sqlite3_prepare_v2()

SQLITE_API int sqlite3_prepare_v2 ( sqlite3 * db,
const char * zSql,
int nByte,
sqlite3_stmt ** ppStmt,
const char ** pzTail )

Definition at line 129146 of file sqlite3.c.

129146 {
129147 int rc;
129148 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
129149 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
129150 return rc;
129151}
129153 sqlite3 *db, /* Database handle. */
129154 const char *zSql, /* UTF-8 encoded SQL statement. */
129155 int nBytes, /* Length of zSql in bytes. */
129156 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
129157 const char **pzTail /* OUT: End of parsed string */
129158){
129159 int rc;
129160 /* EVIDENCE-OF: R-37923-12173 The sqlite3_prepare_v2() interface works
129161 ** exactly the same as sqlite3_prepare_v3() with a zero prepFlags
129162 ** parameter.
129163 **
static int sqlite3LockAndPrepare(sqlite3 *db, const char *zSql, int nBytes, u32 prepFlags, Vdbe *pOld, sqlite3_stmt **ppStmt, const char **pzTail)
Definition sqlite3.c:129050

References sqlite3LockAndPrepare(), and SQLITE_OK.

Referenced by db_do_rows(), db_prepare(), execSql(), and sqlite3_exec().

◆ sqlite3_prepare_v3()

SQLITE_API int sqlite3_prepare_v3 ( sqlite3 * db,
const char * zSql,
int nByte,
unsigned int prepFlags,
sqlite3_stmt ** ppStmt,
const char ** pzTail )

Definition at line 129164 of file sqlite3.c.

129177 {
129178 int rc;
129179 /* EVIDENCE-OF: R-56861-42673 sqlite3_prepare_v3() differs from
129180 ** sqlite3_prepare_v2() only in having the extra prepFlags parameter,
129181 ** which is a bit array consisting of zero or more of the
129182 ** SQLITE_PREPARE_* flags.
129183 **
129184 ** Proof by comparison to the implementation of sqlite3_prepare_v2()
129185 ** directly above. */

◆ sqlite3_profile()

SQLITE_API void * sqlite3_profile ( sqlite3 * db,
void(*)(void *, const char *, sqlite3_uint64) xProfile,
void * pArg )

Definition at line 163126 of file sqlite3.c.

163136 {
163137 void *pOld;
163138
163139#ifdef SQLITE_ENABLE_API_ARMOR
163140 if( !sqlite3SafetyCheckOk(db) ){
163141 (void)SQLITE_MISUSE_BKPT;
163142 return 0;
163143 }
163144#endif
163146 pOld = db->pProfileArg;
163147 db->xProfile = xProfile;

References sqlite3::mTrace, sqlite3::mutex, sqlite3::pProfileArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_TRACE_NONLEGACY_MASK, SQLITE_TRACE_XPROFILE, and sqlite3::xProfile.

◆ sqlite3_progress_handler()

SQLITE_API void sqlite3_progress_handler ( sqlite3 * db,
int nOps,
int(*)(void *) xProgress,
void * pArg )

Definition at line 162700 of file sqlite3.c.

162711 {
162712#ifdef SQLITE_ENABLE_API_ARMOR
162713 if( !sqlite3SafetyCheckOk(db) ){
162714 (void)SQLITE_MISUSE_BKPT;
162715 return;
162716 }
162717#endif
162719 if( nOps>0 ){
162720 db->xProgress = xProgress;
162721 db->nProgressOps = (unsigned)nOps;
162722 db->pProgressArg = pArg;
162723 }else{
void * pProgressArg
Definition sqlite3.c:16913
int(* xProgress)(void *)
Definition sqlite3.c:16912
unsigned nProgressOps
Definition sqlite3.c:16914

References sqlite3::mutex, sqlite3::nProgressOps, sqlite3::pProgressArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, and sqlite3::xProgress.

Referenced by db_progress_handler().

◆ sqlite3_randomness()

SQLITE_API void sqlite3_randomness ( int N,
void * P )

Definition at line 30261 of file sqlite3.c.

30267 {
30268 unsigned char t;
30269 unsigned char *zBuf = pBuf;
30270
30271 /* The "wsdPrng" macro will resolve to the pseudo-random number generator
30272 ** state vector. If writable static data is unsupported on the target,
30273 ** we have to locate the state vector at run-time. In the more common
30274 ** case where writable static data is supported, wsdPrng can refer directly
30275 ** to the "sqlite3Prng" state vector declared above.
30276 */
30277#ifdef SQLITE_OMIT_WSD
30278 struct sqlite3PrngType *p = &GLOBAL(struct sqlite3PrngType, sqlite3Prng);
30279# define wsdPrng p[0]
30280#else
30281# define wsdPrng sqlite3Prng
30282#endif
30283
30284#if SQLITE_THREADSAFE
30286#endif
30287
30288#ifndef SQLITE_OMIT_AUTOINIT
30289 if( sqlite3_initialize() ) return;
30290#endif
30291
30292#if SQLITE_THREADSAFE
30294#endif
30295
30297 if( N<=0 || pBuf==0 ){
30298 wsdPrng.isInit = 0;
30300 return;
30301 }
30302
30303 /* Initialize the state of the random number generator once,
30304 ** the first time this routine is called. The seed value does
30305 ** not need to contain a lot of randomness since we are not
30306 ** trying to do secure encryption or anything like that...
30307 **
30308 ** Nothing in this file or anywhere else in SQLite does any kind of
30309 ** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
30310 ** number generator) not as an encryption device.
30311 */
30312 if( !wsdPrng.isInit ){
30313 int i;
30314 char k[256];
30315 wsdPrng.j = 0;
30316 wsdPrng.i = 0;
30318 for(i=0; i<256; i++){
30319 wsdPrng.s[i] = (u8)i;
30320 }
30321 for(i=0; i<256; i++){
30322 wsdPrng.j += wsdPrng.s[i] + k[i];
30323 t = wsdPrng.s[wsdPrng.j];
30324 wsdPrng.s[wsdPrng.j] = wsdPrng.s[i];
30325 wsdPrng.s[i] = t;
30326 }
30327 wsdPrng.isInit = 1;
30328 }
30329
30330 assert( N>0 );
30331 do{
30332 wsdPrng.i++;
30333 t = wsdPrng.s[wsdPrng.i];
30334 wsdPrng.j += t;
30335 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
static SQLITE_WSD struct sqlite3PrngType sqlite3Prng
SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *)
Definition sqlite3.c:23221
#define SQLITE_MUTEX_STATIC_PRNG
Definition sqlite3.c:8635
#define wsdPrng
unsigned char i
Definition sqlite3.c:30254

Referenced by randomFunc(), sqlite3BitvecBuiltinTest(), sqlite3ColumnsFromExprList(), sqlite3VdbeExec(), unixGetTempname(), unixOpen(), vdbeCommit(), walCheckpoint(), walRestartLog(), and writeJournalHdr().

◆ sqlite3_realloc()

SQLITE_API void * sqlite3_realloc ( void * pOld,
int n )

Definition at line 27819 of file sqlite3.c.

27824 {
27825#ifndef SQLITE_OMIT_AUTOINIT

Referenced by unixShmMap().

◆ sqlite3_realloc64()

SQLITE_API void * sqlite3_realloc64 ( void * pOld,
sqlite3_uint64 n )

Definition at line 27826 of file sqlite3.c.

27831 {

Referenced by sqlite3_auto_extension().

◆ sqlite3_release_memory()

SQLITE_API int sqlite3_release_memory ( int n)

Definition at line 27335 of file sqlite3.c.

27340 {
27341#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
27342 return sqlite3PcacheReleaseMemory(n);
27343#else
27344 /* IMPLEMENTATION-OF: R-34391-24921 The sqlite3_release_memory() routine
27345 ** is a no-op returning zero if SQLite is not compiled with

References UNUSED_PARAMETER.

◆ sqlite3_reset()

SQLITE_API int sqlite3_reset ( sqlite3_stmt * pStmt)

Definition at line 83107 of file sqlite3.c.

83113 {
83114 int rc;
83115 if( pStmt==0 ){
83116 rc = SQLITE_OK;
83117 }else{
83118 Vdbe *v = (Vdbe*)pStmt;
83119 sqlite3 *db = v->db;
83121 checkProfileCallback(db, v);
83122 rc = sqlite3VdbeReset(v);
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *)
Definition sqlite3.c:81017
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *)
Definition sqlite3.c:80022

References checkProfileCallback, Vdbe::db, sqlite3::errMask, sqlite3::mutex, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3VdbeReset(), sqlite3VdbeRewind(), and SQLITE_OK.

Referenced by db_do_next_row(), dbvm_reset(), sqlite3_step(), and sqlite3Step().

◆ sqlite3_reset_auto_extension()

SQLITE_API void sqlite3_reset_auto_extension ( void )

Definition at line 125025 of file sqlite3.c.

125031 {
125032#ifndef SQLITE_OMIT_AUTOINIT
125034#endif
125035 {
125036#if SQLITE_THREADSAFE
125038#endif

Referenced by sqlite3_shutdown().

◆ sqlite3_result_blob()

SQLITE_API void sqlite3_result_blob ( sqlite3_context * pCtx,
const void * z,
int n,
void(*)(void *) xDel )

Definition at line 83379 of file sqlite3.c.

83379 {
83380 xDel((void*)p);
83381 }
83382 if( pCtx ) sqlite3_result_error_toobig(pCtx);
83383 return SQLITE_TOOBIG;
83384}
83386 sqlite3_context *pCtx,
83387 const void *z,
83388 int n,
SQLITE_API void sqlite3_result_blob(sqlite3_context *, const void *, int, void(*)(void *))
Definition sqlite3.c:83379

Referenced by lcontext_result_blob(), and statGet().

◆ sqlite3_result_blob64()

SQLITE_API void sqlite3_result_blob64 ( sqlite3_context * pCtx,
const void * z,
sqlite3_uint64 n,
void(*)(void *) xDel )

Definition at line 83389 of file sqlite3.c.

83390 {
83391 assert( n>=0 );
83392 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83393 setResultStrOrError(pCtx, z, n, 0, xDel);
83394}
83396 sqlite3_context *pCtx,
83397 const void *z,
83399 void (*xDel)(void *)
83400){
83401 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83402 assert( xDel!=SQLITE_DYNAMIC );
SQLITE_API void sqlite3_result_blob64(sqlite3_context *, const void *, sqlite3_uint64, void(*)(void *))
Definition sqlite3.c:83389
static void setResultStrOrError(sqlite3_context *pCtx, const char *z, int n, u8 enc, void(*xDel)(void *))
Definition sqlite3.c:83352

References sqlite3_value::db, sqlite3::mutex, sqlite3_context::pOut, setResultStrOrError(), and sqlite3_mutex_held().

Referenced by substrFunc().

◆ sqlite3_result_double()

SQLITE_API void sqlite3_result_double ( sqlite3_context * pCtx,
double rVal )

Definition at line 83403 of file sqlite3.c.

83403 {
83404 (void)invokeValueDestructor(z, xDel, pCtx);
83405 }else{
83406 setResultStrOrError(pCtx, z, (int)n, 0, xDel);

References invokeValueDestructor().

Referenced by absFunc(), juliandayFunc(), lcontext_result(), and lcontext_result_double().

◆ sqlite3_result_error()

◆ sqlite3_result_error16()

SQLITE_API void sqlite3_result_error16 ( sqlite3_context * pCtx,
const void * z,
int n )

◆ sqlite3_result_error_code()

SQLITE_API void sqlite3_result_error_code ( sqlite3_context * pCtx,
int errCode )

Definition at line 83520 of file sqlite3.c.

83520 {
83521 return SQLITE_TOOBIG;
83522 }
83523 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
83524 return SQLITE_OK;
83525}
83527 pCtx->isError = errCode ? errCode : -1;
83528#ifdef SQLITE_DEBUG
83529 if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;

References SQLITE_TOOBIG.

Referenced by attachFunc(), renameColumnFunc(), and renameTableFunc().

◆ sqlite3_result_error_nomem()

SQLITE_API void sqlite3_result_error_nomem ( sqlite3_context * pCtx)

◆ sqlite3_result_error_toobig()

SQLITE_API void sqlite3_result_error_toobig ( sqlite3_context * pCtx)

Definition at line 83532 of file sqlite3.c.

Referenced by contextMalloc(), invokeValueDestructor(), replaceFunc(), and strftimeFunc().

◆ sqlite3_result_int()

◆ sqlite3_result_int64()

SQLITE_API void sqlite3_result_int64 ( sqlite3_context * pCtx,
sqlite3_int64 iVal )

Definition at line 83423 of file sqlite3.c.

83425 {
83426 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );

Referenced by absFunc(), countInverse(), lcontext_result(), randomFunc(), and statGet().

◆ sqlite3_result_null()

SQLITE_API void sqlite3_result_null ( sqlite3_context * pCtx)

Definition at line 83427 of file sqlite3.c.

83429 {
83430 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );

Referenced by absFunc(), lcontext_result(), and lcontext_result_null().

◆ sqlite3_result_pointer()

SQLITE_API void sqlite3_result_pointer ( sqlite3_context * pCtx,
void * pPtr,
const char * zPType,
void(*)(void *) xDestructor )

Definition at line 83431 of file sqlite3.c.

83433 {
83434 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83436}
83438 sqlite3_context *pCtx,
83439 void *pPtr,
83440 const char *zPType,
83441 void (*xDestructor)(void*)
83442){
SQLITE_API void sqlite3_result_pointer(sqlite3_context *, void *, const char *, void(*)(void *))
Definition sqlite3.c:83431

◆ sqlite3_result_subtype()

SQLITE_API void sqlite3_result_subtype ( sqlite3_context * pCtx,
unsigned int eSubtype )

Definition at line 83443 of file sqlite3.c.

◆ sqlite3_result_text()

SQLITE_API void sqlite3_result_text ( sqlite3_context * pCtx,
const char * z,
int n,
void(*)(void *) xDel )

Definition at line 83449 of file sqlite3.c.

83449 {
83450 Mem *pOut = pCtx->pOut;
83451 assert( sqlite3_mutex_held(pOut->db->mutex) );
83452 pOut->eSubtype = eSubtype & 0xff;
83453 pOut->flags |= MEM_Subtype;
83454}
83456 sqlite3_context *pCtx,
83457 const char *z,
#define MEM_Subtype
Definition sqlite3.c:20972

References sqlite3_value::db, sqlite3_value::eSubtype, sqlite3_value::flags, MEM_Subtype, sqlite3::mutex, sqlite3_context::pOut, and sqlite3_mutex_held().

Referenced by dateFunc(), datetimeFunc(), lcontext_result(), lcontext_result_text(), quoteFunc(), renameEditSql(), replaceFunc(), sourceidFunc(), statGet(), strftimeFunc(), and timeFunc().

◆ sqlite3_result_text16()

SQLITE_API void sqlite3_result_text16 ( sqlite3_context * pCtx,
const void * z,
int n,
void(*)(void *) xDel )

Definition at line 83475 of file sqlite3.c.

83476 {
83477 setResultStrOrError(pCtx, z, (int)n, enc, xDel);
83478 }
83479}
83480#ifndef SQLITE_OMIT_UTF16
83482 sqlite3_context *pCtx,
83483 const void *z,
SQLITE_API void sqlite3_result_text16(sqlite3_context *, const void *, int, void(*)(void *))
Definition sqlite3.c:83475

◆ sqlite3_result_text16be()

SQLITE_API void sqlite3_result_text16be ( sqlite3_context * pCtx,
const void * z,
int n,
void(*)(void *) xDel )

Definition at line 83484 of file sqlite3.c.

83486 {
83487 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83488 setResultStrOrError(pCtx, z, n, SQLITE_UTF16NATIVE, xDel);
83489}
83491 sqlite3_context *pCtx,
83492 const void *z,
SQLITE_API void sqlite3_result_text16be(sqlite3_context *, const void *, int, void(*)(void *))
Definition sqlite3.c:83484

References sqlite3_value::db, sqlite3::mutex, sqlite3_context::pOut, setResultStrOrError(), sqlite3_mutex_held(), and SQLITE_UTF16NATIVE.

◆ sqlite3_result_text16le()

SQLITE_API void sqlite3_result_text16le ( sqlite3_context * pCtx,
const void * z,
int n,
void(*)(void *) xDel )

Definition at line 83493 of file sqlite3.c.

83495 {
83496 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83497 setResultStrOrError(pCtx, z, n, SQLITE_UTF16BE, xDel);
83498}
83500 sqlite3_context *pCtx,
83501 const void *z,
SQLITE_API void sqlite3_result_text16le(sqlite3_context *, const void *, int, void(*)(void *))
Definition sqlite3.c:83493

References sqlite3_value::db, sqlite3::mutex, sqlite3_context::pOut, setResultStrOrError(), sqlite3_mutex_held(), and SQLITE_UTF16BE.

◆ sqlite3_result_text64()

SQLITE_API void sqlite3_result_text64 ( sqlite3_context * pCtx,
const char * z,
sqlite3_uint64 n,
void(*)(void *) xDel,
unsigned char encoding )

Definition at line 83458 of file sqlite3.c.

83460 {
83461 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83462 setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel);
83463}
83465 sqlite3_context *pCtx,
83466 const char *z,
83468 void (*xDel)(void *),
83469 unsigned char enc
83470){
83471 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83472 assert( xDel!=SQLITE_DYNAMIC );
83473 if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
SQLITE_API void sqlite3_result_text64(sqlite3_context *, const char *, sqlite3_uint64, void(*)(void *), unsigned char encoding)
Definition sqlite3.c:83458

References sqlite3_value::db, sqlite3::mutex, sqlite3_context::pOut, setResultStrOrError(), sqlite3_mutex_held(), and SQLITE_UTF8.

Referenced by charFunc(), and substrFunc().

◆ sqlite3_result_value()

SQLITE_API void sqlite3_result_value ( sqlite3_context * pCtx,
sqlite3_value * pValue )

◆ sqlite3_result_zeroblob()

SQLITE_API void sqlite3_result_zeroblob ( sqlite3_context * pCtx,
int n )

Definition at line 83507 of file sqlite3.c.

83509 {
83510 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );

◆ sqlite3_result_zeroblob64()

SQLITE_API int sqlite3_result_zeroblob64 ( sqlite3_context * pCtx,
sqlite3_uint64 n )

Definition at line 83511 of file sqlite3.c.

83513 {
83514 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83516}
83518 Mem *pOut = pCtx->pOut;
83519 assert( sqlite3_mutex_held(pOut->db->mutex) );
SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *, sqlite3_uint64 n)
Definition sqlite3.c:83511

◆ sqlite3_rollback_hook()

SQLITE_API void * sqlite3_rollback_hook ( sqlite3 * db,
void(*)(void *) xCallback,
void * pArg )

Definition at line 163206 of file sqlite3.c.

163216 {
163217 void *pRet;
163218
163219#ifdef SQLITE_ENABLE_API_ARMOR
163220 if( !sqlite3SafetyCheckOk(db) ){
163221 (void)SQLITE_MISUSE_BKPT;
163222 return 0;
163223 }
163224#endif

Referenced by db_rollback_hook().

◆ sqlite3_rtree_geometry_callback()

SQLITE_API int sqlite3_rtree_geometry_callback ( sqlite3 * db,
const char * zGeom,
int(*)(sqlite3_rtree_geometry *, int, sqlite3_rtree_dbl *, int *) xGeom,
void * pContext )

◆ sqlite3_rtree_query_callback()

SQLITE_API int sqlite3_rtree_query_callback ( sqlite3 * db,
const char * zQueryFunc,
int(*)(sqlite3_rtree_query_info *) xQueryFunc,
void * pContext,
void(*)(void *) xDestructor )

◆ sqlite3_serialize()

SQLITE_API unsigned char * sqlite3_serialize ( sqlite3 * db,
const char * zSchema,
sqlite3_int64 * piSize,
unsigned int mFlags )

◆ sqlite3_set_authorizer()

SQLITE_API int sqlite3_set_authorizer ( sqlite3 * db,
int(*)(void *, int, const char *, const char *, const char *, const char *) xAuth,
void * pUserData )

Definition at line 110182 of file sqlite3.c.

110192 {
110193#ifdef SQLITE_ENABLE_API_ARMOR
110194 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
110195#endif

References sqlite3::mutex, sqlite3::pAuthArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ExpirePreparedStatements(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_OK, and sqlite3::xAuth.

◆ sqlite3_set_auxdata()

SQLITE_API void sqlite3_set_auxdata ( sqlite3_context * pCtx,
int N,
void * pAux,
void(*)(void *) xDelete )

Definition at line 83916 of file sqlite3.c.

83918 : If iArg is negative then make the data available
83919** to all functions within the current prepared statement using iArg as an
83920** access code.
83921*/
83923 sqlite3_context *pCtx,
83924 int iArg,
83925 void *pAux,
83926 void (*xDelete)(void*)
83927){
83928 AuxData *pAuxData;
83929 Vdbe *pVdbe = pCtx->pVdbe;
83930
83931 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
83932#ifdef SQLITE_ENABLE_STAT4
83933 if( pVdbe==0 ) goto failed;
83934#else
83935 assert( pVdbe!=0 );
83936#endif
83937
83938 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
83939 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
83940 break;
83941 }
83942 }
83943 if( pAuxData==0 ){
83944 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
83945 if( !pAuxData ) goto failed;
83946 pAuxData->iAuxOp = pCtx->iOp;
83947 pAuxData->iAuxArg = iArg;
83948 pAuxData->pNextAux = pVdbe->pAuxData;
83949 pVdbe->pAuxData = pAuxData;
83950 if( pCtx->isError==0 ) pCtx->isError = -1;
83951 }else if( pAuxData->xDeleteAux ){
83952 pAuxData->xDeleteAux(pAuxData->pAux);
83953 }
83954
83955 pAuxData->pAux = pAux;
83956 pAuxData->xDeleteAux = xDelete;
83957 return;
SQLITE_API void sqlite3_set_auxdata(sqlite3_context *, int N, void *, void(*)(void *))
Definition sqlite3.c:83916
void(* xDeleteAux)(void *)
Definition sqlite3.c:21016
void * pAux
Definition sqlite3.c:21015
int iAuxArg
Definition sqlite3.c:21014
int iAuxOp
Definition sqlite3.c:21013

References sqlite3_value::db, Vdbe::db, AuxData::iAuxArg, AuxData::iAuxOp, sqlite3_context::iOp, sqlite3_context::isError, sqlite3::mutex, AuxData::pAux, Vdbe::pAuxData, AuxData::pNextAux, sqlite3_context::pOut, sqlite3_context::pVdbe, sqlite3_mutex_held(), sqlite3DbMallocZero(), and AuxData::xDeleteAux.

◆ sqlite3_set_last_insert_rowid()

SQLITE_API void sqlite3_set_last_insert_rowid ( sqlite3 * db,
sqlite3_int64 iRowid )

Definition at line 162067 of file sqlite3.c.

162073 {
162074#ifdef SQLITE_ENABLE_API_ARMOR
162075 if( !sqlite3SafetyCheckOk(db) ){
162076 (void)SQLITE_MISUSE_BKPT;
162077 return;

◆ sqlite3_shutdown()

SQLITE_API int sqlite3_shutdown ( void )

Definition at line 161371 of file sqlite3.c.

161377 {
161378#ifdef SQLITE_OMIT_WSD
161379 int rc = sqlite3_wsd_init(4096, 24);
161380 if( rc!=SQLITE_OK ){
161381 return rc;
161382 }
161383#endif
161384
161385 if( sqlite3GlobalConfig.isInit ){
161386#ifdef SQLITE_EXTRA_SHUTDOWN
161387 void SQLITE_EXTRA_SHUTDOWN(void);
161388 SQLITE_EXTRA_SHUTDOWN();
161389#endif
161390 sqlite3_os_end();
161392 sqlite3GlobalConfig.isInit = 0;
161393 }
161394 if( sqlite3GlobalConfig.isPCacheInit ){
161396 sqlite3GlobalConfig.isPCacheInit = 0;
161397 }
161398 if( sqlite3GlobalConfig.isMallocInit ){
161400 sqlite3GlobalConfig.isMallocInit = 0;
161401
161402#ifndef SQLITE_OMIT_SHUTDOWN_DIRECTORIES
161403 /* The heap subsystem has now been shutdown and these values are supposed
161404 ** to be NULL or point to memory that was obtained from sqlite3_malloc(),
161405 ** which would rely on that heap subsystem; therefore, make sure these
161406 ** values cannot refer to heap memory that was just invalidated when the
161407 ** heap subsystem was shutdown. This is only done if the current call to
161408 ** this function resulted in the heap subsystem actually being shutdown.
161409 */
161412#endif
161413 }
161414 if( sqlite3GlobalConfig.isMutexInit ){
SQLITE_API int sqlite3_os_end(void)
Definition sqlite3.c:41473
SQLITE_PRIVATE void sqlite3MallocEnd(void)
Definition sqlite3.c:27500
SQLITE_API char * sqlite3_temp_directory
Definition sqlite3.c:7084
SQLITE_API void sqlite3_reset_auto_extension(void)
Definition sqlite3.c:125025
SQLITE_API char * sqlite3_data_directory
Definition sqlite3.c:7121
SQLITE_PRIVATE void sqlite3PcacheShutdown(void)
Definition sqlite3.c:49142

References sqlite3_data_directory, sqlite3_os_end(), sqlite3_reset_auto_extension(), sqlite3_temp_directory, sqlite3GlobalConfig, sqlite3MallocEnd(), sqlite3MutexEnd(), sqlite3PcacheShutdown(), and SQLITE_OK.

◆ sqlite3_sleep()

SQLITE_API int sqlite3_sleep ( int ms)

Definition at line 164752 of file sqlite3.c.

164758 {
164759 sqlite3_vfs *pVfs;
164760 int rc;
164761 pVfs = sqlite3_vfs_find(0);
164762 if( pVfs==0 ) return 0;
164763

◆ sqlite3_snapshot_cmp()

SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp ( sqlite3_snapshot * p1,
sqlite3_snapshot * p2 )

◆ sqlite3_snapshot_free()

SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free ( sqlite3_snapshot * )

◆ sqlite3_snapshot_get()

SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get ( sqlite3 * db,
const char * zSchema,
sqlite3_snapshot ** ppSnapshot )

◆ sqlite3_snapshot_open()

SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open ( sqlite3 * db,
const char * zSchema,
sqlite3_snapshot * pSnapshot )

◆ sqlite3_snapshot_recover()

SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover ( sqlite3 * db,
const char * zDb )

◆ sqlite3_snprintf()

SQLITE_API char * sqlite3_snprintf ( int n,
char * zBuf,
const char * zFormat,
... )

◆ sqlite3_soft_heap_limit()

SQLITE_API void sqlite3_soft_heap_limit ( int N)

Definition at line 27432 of file sqlite3.c.

◆ sqlite3_soft_heap_limit64()

SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64 ( sqlite3_int64 N)

Definition at line 27407 of file sqlite3.c.

27412 {
27413 sqlite3_int64 priorLimit;
27414 sqlite3_int64 excess;
27415 sqlite3_int64 nUsed;
27416#ifndef SQLITE_OMIT_AUTOINIT
27417 int rc = sqlite3_initialize();
27418 if( rc ) return -1;
27419#endif
27421 priorLimit = mem0.alarmThreshold;
27422 if( n<0 ){
27424 return priorLimit;
27425 }
27426 if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){
27427 n = mem0.hardLimit;
27428 }
27429 mem0.alarmThreshold = n;
27431 AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed);

References AtomicStore, mem0, sqlite3_initialize(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3StatusValue(), and SQLITE_STATUS_MEMORY_USED.

Referenced by sqlite3Pragma().

◆ sqlite3_sourceid()

SQLITE_API const char * sqlite3_sourceid ( void )

Definition at line 230510 of file sqlite3.c.

References SQLITE_SOURCE_ID.

Referenced by sourceidFunc(), and sqlite3CorruptError().

◆ sqlite3_sql()

SQLITE_API const char * sqlite3_sql ( sqlite3_stmt * pStmt)

Definition at line 84731 of file sqlite3.c.

Referenced by sqlite3_expanded_sql(), and sqlite3Reprepare().

◆ sqlite3_status()

SQLITE_API int sqlite3_status ( int op,
int * pCurrent,
int * pHighwater,
int resetFlag )

Definition at line 21472 of file sqlite3.c.

21477 {
21478 sqlite3_int64 iCur = 0, iHwtr = 0;
21479 int rc;
21480#ifdef SQLITE_ENABLE_API_ARMOR
21481 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
21482#endif
21483 rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag);
21484 if( rc==0 ){
SQLITE_API int sqlite3_status64(int op, sqlite3_int64 *pCurrent, sqlite3_int64 *pHighwater, int resetFlag)
Definition sqlite3.c:21447

◆ sqlite3_status64()

SQLITE_API int sqlite3_status64 ( int op,
sqlite3_int64 * pCurrent,
sqlite3_int64 * pHighwater,
int resetFlag )

Definition at line 21447 of file sqlite3.c.

21457 {
21458 sqlite3_mutex *pMutex;
21460 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
21461 return SQLITE_MISUSE_BKPT;
21462 }
21463#ifdef SQLITE_ENABLE_API_ARMOR
21464 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
21465#endif
21467 sqlite3_mutex_enter(pMutex);
21468 *pCurrent = wsdStat.nowValue[op];
21469 *pHighwater = wsdStat.mxValue[op];
21470 if( resetFlag ){
21471 wsdStat.mxValue[op] = wsdStat.nowValue[op];
static const char statMutex[]
Definition sqlite3.c:21350
SQLITE_PRIVATE sqlite3_mutex * sqlite3Pcache1Mutex(void)
Definition sqlite3.c:50974
#define wsdStat
Definition sqlite3.c:21375
#define wsdStatInit
Definition sqlite3.c:21374
SQLITE_PRIVATE sqlite3_mutex * sqlite3MallocMutex(void)
Definition sqlite3.c:27374

Referenced by sqlite3_memory_highwater().

◆ sqlite3_step()

SQLITE_API int sqlite3_step ( sqlite3_stmt * pStmt)

Definition at line 83730 of file sqlite3.c.

83736 {
83737 int rc = SQLITE_OK; /* Result from sqlite3Step() */
83738 Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */
83739 int cnt = 0; /* Counter to prevent infinite loop of reprepares */
83740 sqlite3 *db; /* The database connection */
83741
83742 if( vdbeSafetyNotNull(v) ){
83743 return SQLITE_MISUSE_BKPT;
83744 }
83745 db = v->db;
83747 v->doingRerun = 0;
83748 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
83749 && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){
83750 int savedPc = v->pc;
83751 rc = sqlite3Reprepare(v);
83752 if( rc!=SQLITE_OK ){
83753 /* This case occurs after failing to recompile an sql statement.
83754 ** The error message from the SQL compiler has already been loaded
83755 ** into the database handle. This block copies the error message
83756 ** from the database handle into the statement and sets the statement
83757 ** program counter to 0 to ensure that when the statement is
83758 ** finalized or reset the parser error message is available via
83759 ** sqlite3_errmsg() and sqlite3_errcode().
83760 */
83761 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
83762 sqlite3DbFree(db, v->zErrMsg);
83763 if( !db->mallocFailed ){
83764 v->zErrMsg = sqlite3DbStrDup(db, zErr);
83765 v->rc = rc = sqlite3ApiExit(db, rc);
83766 } else {
83767 v->zErrMsg = 0;
83768 v->rc = rc = SQLITE_NOMEM_BKPT;
83769 }
83770 break;
83771 }
83772 sqlite3_reset(pStmt);
static int vdbeSafetyNotNull(Vdbe *p)
Definition sqlite3.c:83028
static int sqlite3Step(Vdbe *p)
Definition sqlite3.c:83596
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt)
Definition sqlite3.c:83107
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe *)
Definition sqlite3.c:129095
u8 doingRerun
Definition sqlite3.c:21126
char * zErrMsg
Definition sqlite3.c:21113
int pc
Definition sqlite3.c:21092

References Vdbe::db, Vdbe::doingRerun, Vdbe::expired, sqlite3::mallocFailed, sqlite3::mutex, Vdbe::pc, sqlite3::pErr, Vdbe::rc, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_reset(), sqlite3_value_text(), sqlite3ApiExit(), sqlite3DbFree(), sqlite3DbStrDup(), sqlite3Reprepare(), sqlite3Step(), SQLITE_MAX_SCHEMA_RETRY, SQLITE_MISUSE_BKPT, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_SCHEMA, vdbeSafetyNotNull(), and Vdbe::zErrMsg.

Referenced by blobSeekToRow(), execSql(), sqlite3_exec(), and stepvm().

◆ sqlite3_stmt_busy()

SQLITE_API int sqlite3_stmt_busy ( sqlite3_stmt * pStmt)

Definition at line 84669 of file sqlite3.c.

84669 : 0;
84670}
84671
84672/*

◆ sqlite3_stmt_isexplain()

SQLITE_API int sqlite3_stmt_isexplain ( sqlite3_stmt * pStmt)

Definition at line 84662 of file sqlite3.c.

◆ sqlite3_stmt_readonly()

SQLITE_API int sqlite3_stmt_readonly ( sqlite3_stmt * pStmt)

Definition at line 84654 of file sqlite3.c.

◆ sqlite3_stmt_scanstatus()

SQLITE_API int sqlite3_stmt_scanstatus ( sqlite3_stmt * pStmt,
int idx,
int iScanStatusOp,
void * pOut )

◆ sqlite3_stmt_scanstatus_reset()

SQLITE_API void sqlite3_stmt_scanstatus_reset ( sqlite3_stmt * )

◆ sqlite3_stmt_status()

SQLITE_API int sqlite3_stmt_status ( sqlite3_stmt * pStmt,
int op,
int resetFlg )

Definition at line 84701 of file sqlite3.c.

84707 {
84708 Vdbe *pVdbe = (Vdbe*)pStmt;
84709 u32 v;
84710#ifdef SQLITE_ENABLE_API_ARMOR
84711 if( !pStmt
84712 || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter)))
84713 ){
84714 (void)SQLITE_MISUSE_BKPT;
84715 return 0;
84716 }
84717#endif
84718 if( op==SQLITE_STMTSTATUS_MEMUSED ){
84719 sqlite3 *db = pVdbe->db;
84721 v = 0;
84722 db->pnBytesFreed = (int*)&v;
84723 sqlite3VdbeClearObject(db, pVdbe);
84724 sqlite3DbFree(db, pVdbe);
84725 db->pnBytesFreed = 0;
#define SQLITE_STMTSTATUS_MEMUSED
Definition sqlite3.c:9300
u32 aCounter[7]
Definition sqlite3.c:21136

◆ sqlite3_str_append()

SQLITE_API void sqlite3_str_append ( sqlite3_str * p,
const char * zIn,
int N )

Definition at line 29123 of file sqlite3.c.

29129 {
29130 assert( z!=0 || N==0 );
29131 assert( p->zText!=0 || p->nChar==0 || p->accError );
29132 assert( N>=0 );
29133 assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
29134 if( p->nChar+N >= p->nAlloc ){
29135 enlargeAndAppend(p,z,N);
static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N)
Definition sqlite3.c:29111
char * zText
Definition sqlite3.c:18970

Referenced by explainAppendTerm(), explainIndexRange(), sqlite3_str_vappendf(), sqlite3RunParser(), sqlite3VdbeDisplayP4(), sqlite3VdbeExpandSql(), and sqlite3WhereExplainOneScan().

◆ sqlite3_str_appendall()

SQLITE_API void sqlite3_str_appendall ( sqlite3_str * p,
const char * zIn )

◆ sqlite3_str_appendchar()

SQLITE_API void sqlite3_str_appendchar ( sqlite3_str * p,
int N,
char C )

Definition at line 29095 of file sqlite3.c.

29101 {

Referenced by sqlite3_str_vappendf().

◆ sqlite3_str_appendf()

SQLITE_API void sqlite3_str_appendf ( sqlite3_str * p,
const char * zFormat,
... )

◆ sqlite3_str_errcode()

SQLITE_API int sqlite3_str_errcode ( sqlite3_str * p)

Definition at line 29197 of file sqlite3.c.

◆ sqlite3_str_finish()

SQLITE_API char * sqlite3_str_finish ( sqlite3_str * p)

Definition at line 29185 of file sqlite3.c.

29185 {
29186 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
29187};
29188
29189/* Finalize a string created using sqlite3_str_new().
29190*/
29192 char *z;
29193 if( p!=0 && p!=&sqlite3OomStr ){
29194 z = sqlite3StrAccumFinish(p);
static sqlite3_str sqlite3OomStr
Definition sqlite3.c:29179
SQLITE_API char * sqlite3_str_finish(sqlite3_str *)
Definition sqlite3.c:29185

References SQLITE_NOMEM.

Referenced by sqlite3RunParser().

◆ sqlite3_str_length()

SQLITE_API int sqlite3_str_length ( sqlite3_str * p)

Definition at line 29202 of file sqlite3.c.

29203 {
29204 return p ? p->accError : SQLITE_NOMEM;

References sqlite3_str::accError, and SQLITE_NOMEM.

◆ sqlite3_str_new()

SQLITE_API sqlite3_str * sqlite3_str_new ( sqlite3 * db)

Definition at line 29251 of file sqlite3.c.

29257 {
29258 sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
29259 if( p ){
29260 sqlite3StrAccumInit(p, 0, 0, 0,

Referenced by sqlite3RunParser().

◆ sqlite3_str_reset()

SQLITE_API void sqlite3_str_reset ( sqlite3_str * p)

Definition at line 29216 of file sqlite3.c.

29222 {
29223 if( isMalloced(p) ){
29224 sqlite3DbFree(p->db, p->zText);
#define isMalloced(X)
Definition sqlite3.c:18981
sqlite3 * db
Definition sqlite3.c:18969

Referenced by sqlite3BtreeIntegrityCheck(), sqlite3StrAccumEnlarge(), and sqlite3VdbeExpandSql().

◆ sqlite3_str_value()

SQLITE_API char * sqlite3_str_value ( sqlite3_str * p)

Definition at line 29207 of file sqlite3.c.

29208 {
29209 return p ? p->nChar : 0;
29210}
29211

References sqlite3_str::nChar.

◆ sqlite3_str_vappendf()

SQLITE_API void sqlite3_str_vappendf ( sqlite3_str * pAccum,
const char * zFormat,
va_list ap )

Definition at line 28341 of file sqlite3.c.

28351 {
28352 int c; /* Next character in the format string */
28353 char *bufpt; /* Pointer to the conversion buffer */
28354 int precision; /* Precision of the current field */
28355 int length; /* Length of the field */
28356 int idx; /* A general purpose loop counter */
28357 int width; /* Width of the current field */
28358 etByte flag_leftjustify; /* True if "-" flag is present */
28359 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */
28360 etByte flag_alternateform; /* True if "#" flag is present */
28361 etByte flag_altform2; /* True if "!" flag is present */
28362 etByte flag_zeropad; /* True if field width constant starts with zero */
28363 etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */
28364 etByte done; /* Loop termination flag */
28365 etByte cThousand; /* Thousands separator for %d and %u */
28366 etByte xtype = etINVALID; /* Conversion paradigm */
28367 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
28368 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
28369 sqlite_uint64 longvalue; /* Value for integer types */
28370 LONGDOUBLE_TYPE realvalue; /* Value for real types */
28371 const et_info *infop; /* Pointer to the appropriate info structure */
28372 char *zOut; /* Rendering buffer */
28373 int nOut; /* Size of the rendering buffer */
28374 char *zExtra = 0; /* Malloced memory used by some conversion */
28375#ifndef SQLITE_OMIT_FLOATING_POINT
28376 int exp, e2; /* exponent of real numbers */
28377 int nsd; /* Number of significant digits returned */
28378 double rounder; /* Used for rounding floating point values */
28379 etByte flag_dp; /* True if decimal point should be shown */
28380 etByte flag_rtz; /* True if trailing zeros should be removed */
28381#endif
28382 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
28383 char buf[etBUFSIZE]; /* Conversion buffer */
28384
28385 /* pAccum never starts out with an empty buffer that was obtained from
28386 ** malloc(). This precondition is required by the mprintf("%z...")
28387 ** optimization. */
28388 assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 );
28389
28390 bufpt = 0;
28391 if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
28392 pArgList = va_arg(ap, PrintfArguments*);
28393 bArgList = 1;
28394 }else{
28395 bArgList = 0;
28396 }
28397 for(; (c=(*fmt))!=0; ++fmt){
28398 if( c!='%' ){
28399 bufpt = (char *)fmt;
28400#if HAVE_STRCHRNUL
28401 fmt = strchrnul(fmt, '%');
28402#else
28403 do{ fmt++; }while( *fmt && *fmt != '%' );
28404#endif
28405 sqlite3_str_append(pAccum, bufpt, (int)(fmt - bufpt));
28406 if( *fmt==0 ) break;
28407 }
28408 if( (c=(*++fmt))==0 ){
28409 sqlite3_str_append(pAccum, "%", 1);
28410 break;
28411 }
28412 /* Find out what flags are present */
28413 flag_leftjustify = flag_prefix = cThousand =
28414 flag_alternateform = flag_altform2 = flag_zeropad = 0;
28415 done = 0;
28416 width = 0;
28417 flag_long = 0;
28418 precision = -1;
28419 do{
28420 switch( c ){
28421 case '-': flag_leftjustify = 1; break;
28422 case '+': flag_prefix = '+'; break;
28423 case ' ': flag_prefix = ' '; break;
28424 case '#': flag_alternateform = 1; break;
28425 case '!': flag_altform2 = 1; break;
28426 case '0': flag_zeropad = 1; break;
28427 case ',': cThousand = ','; break;
28428 default: done = 1; break;
28429 case 'l': {
28430 flag_long = 1;
28431 c = *++fmt;
28432 if( c=='l' ){
28433 c = *++fmt;
28434 flag_long = 2;
28435 }
28436 done = 1;
28437 break;
28438 }
28439 case '1': case '2': case '3': case '4': case '5':
28440 case '6': case '7': case '8': case '9': {
28441 unsigned wx = c - '0';
28442 while( (c = *++fmt)>='0' && c<='9' ){
28443 wx = wx*10 + c - '0';
28444 }
28445 testcase( wx>0x7fffffff );
28446 width = wx & 0x7fffffff;
28447#ifdef SQLITE_PRINTF_PRECISION_LIMIT
28448 if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
28449 width = SQLITE_PRINTF_PRECISION_LIMIT;
28450 }
28451#endif
28452 if( c!='.' && c!='l' ){
28453 done = 1;
28454 }else{
28455 fmt--;
28456 }
28457 break;
28458 }
28459 case '*': {
28460 if( bArgList ){
28461 width = (int)getIntArg(pArgList);
28462 }else{
28463 width = va_arg(ap,int);
28464 }
28465 if( width<0 ){
28466 flag_leftjustify = 1;
28467 width = width >= -2147483647 ? -width : 0;
28468 }
28469#ifdef SQLITE_PRINTF_PRECISION_LIMIT
28470 if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
28471 width = SQLITE_PRINTF_PRECISION_LIMIT;
28472 }
28473#endif
28474 if( (c = fmt[1])!='.' && c!='l' ){
28475 c = *++fmt;
28476 done = 1;
28477 }
28478 break;
28479 }
28480 case '.': {
28481 c = *++fmt;
28482 if( c=='*' ){
28483 if( bArgList ){
28484 precision = (int)getIntArg(pArgList);
28485 }else{
28486 precision = va_arg(ap,int);
28487 }
28488 if( precision<0 ){
28489 precision = precision >= -2147483647 ? -precision : -1;
28490 }
28491 c = *++fmt;
28492 }else{
28493 unsigned px = 0;
28494 while( c>='0' && c<='9' ){
28495 px = px*10 + c - '0';
28496 c = *++fmt;
28497 }
28498 testcase( px>0x7fffffff );
28499 precision = px & 0x7fffffff;
28500 }
28501#ifdef SQLITE_PRINTF_PRECISION_LIMIT
28502 if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){
28503 precision = SQLITE_PRINTF_PRECISION_LIMIT;
28504 }
28505#endif
28506 if( c=='l' ){
28507 --fmt;
28508 }else{
28509 done = 1;
28510 }
28511 break;
28512 }
28513 }
28514 }while( !done && (c=(*++fmt))!=0 );
28515
28516 /* Fetch the info entry for the field */
28517 infop = &fmtinfo[0];
28518 xtype = etINVALID;
28519 for(idx=0; idx<ArraySize(fmtinfo); idx++){
28520 if( c==fmtinfo[idx].fmttype ){
28521 infop = &fmtinfo[idx];
28522 xtype = infop->type;
28523 break;
28524 }
28525 }
28526
28527 /*
28528 ** At this point, variables are initialized as follows:
28529 **
28530 ** flag_alternateform TRUE if a '#' is present.
28531 ** flag_altform2 TRUE if a '!' is present.
28532 ** flag_prefix '+' or ' ' or zero
28533 ** flag_leftjustify TRUE if a '-' is present or if the
28534 ** field width was negative.
28535 ** flag_zeropad TRUE if the width began with 0.
28536 ** flag_long 1 for "l", 2 for "ll"
28537 ** width The specified field width. This is
28538 ** always non-negative. Zero is the default.
28539 ** precision The specified precision. The default
28540 ** is -1.
28541 ** xtype The class of the conversion.
28542 ** infop Pointer to the appropriate info struct.
28543 */
28544 assert( width>=0 );
28545 assert( precision>=(-1) );
28546 switch( xtype ){
28547 case etPOINTER:
28548 flag_long = sizeof(char*)==sizeof(i64) ? 2 :
28549 sizeof(char*)==sizeof(long int) ? 1 : 0;
28550 /* no break */ deliberate_fall_through
28551 case etORDINAL:
28552 case etRADIX:
28553 cThousand = 0;
28554 /* no break */ deliberate_fall_through
28555 case etDECIMAL:
28556 if( infop->flags & FLAG_SIGNED ){
28557 i64 v;
28558 if( bArgList ){
28559 v = getIntArg(pArgList);
28560 }else if( flag_long ){
28561 if( flag_long==2 ){
28562 v = va_arg(ap,i64) ;
28563 }else{
28564 v = va_arg(ap,long int);
28565 }
28566 }else{
28567 v = va_arg(ap,int);
28568 }
28569 if( v<0 ){
28570 if( v==SMALLEST_INT64 ){
28571 longvalue = ((u64)1)<<63;
28572 }else{
28573 longvalue = -v;
28574 }
28575 prefix = '-';
28576 }else{
28577 longvalue = v;
28578 prefix = flag_prefix;
28579 }
28580 }else{
28581 if( bArgList ){
28582 longvalue = (u64)getIntArg(pArgList);
28583 }else if( flag_long ){
28584 if( flag_long==2 ){
28585 longvalue = va_arg(ap,u64);
28586 }else{
28587 longvalue = va_arg(ap,unsigned long int);
28588 }
28589 }else{
28590 longvalue = va_arg(ap,unsigned int);
28591 }
28592 prefix = 0;
28593 }
28594 if( longvalue==0 ) flag_alternateform = 0;
28595 if( flag_zeropad && precision<width-(prefix!=0) ){
28596 precision = width-(prefix!=0);
28597 }
28598 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
28599 nOut = etBUFSIZE;
28600 zOut = buf;
28601 }else{
28602 u64 n;
28603 n = (u64)precision + 10;
28604 if( cThousand ) n += precision/3;
28605 zOut = zExtra = printfTempBuf(pAccum, n);
28606 if( zOut==0 ) return;
28607 nOut = (int)n;
28608 }
28609 bufpt = &zOut[nOut-1];
28610 if( xtype==etORDINAL ){
28611 static const char zOrd[] = "thstndrd";
28612 int x = (int)(longvalue % 10);
28613 if( x>=4 || (longvalue/10)%10==1 ){
28614 x = 0;
28615 }
28616 *(--bufpt) = zOrd[x*2+1];
28617 *(--bufpt) = zOrd[x*2];
28618 }
28619 {
28620 const char *cset = &aDigits[infop->charset];
28621 u8 base = infop->base;
28622 do{ /* Convert to ascii */
28623 *(--bufpt) = cset[longvalue%base];
28624 longvalue = longvalue/base;
28625 }while( longvalue>0 );
28626 }
28627 length = (int)(&zOut[nOut-1]-bufpt);
28628 while( precision>length ){
28629 *(--bufpt) = '0'; /* Zero pad */
28630 length++;
28631 }
28632 if( cThousand ){
28633 int nn = (length - 1)/3; /* Number of "," to insert */
28634 int ix = (length - 1)%3 + 1;
28635 bufpt -= nn;
28636 for(idx=0; nn>0; idx++){
28637 bufpt[idx] = bufpt[idx+nn];
28638 ix--;
28639 if( ix==0 ){
28640 bufpt[++idx] = cThousand;
28641 nn--;
28642 ix = 3;
28643 }
28644 }
28645 }
28646 if( prefix ) *(--bufpt) = prefix; /* Add sign */
28647 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
28648 const char *pre;
28649 char x;
28650 pre = &aPrefix[infop->prefix];
28651 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
28652 }
28653 length = (int)(&zOut[nOut-1]-bufpt);
28654 break;
28655 case etFLOAT:
28656 case etEXP:
28657 case etGENERIC:
28658 if( bArgList ){
28659 realvalue = getDoubleArg(pArgList);
28660 }else{
28661 realvalue = va_arg(ap,double);
28662 }
28663#ifdef SQLITE_OMIT_FLOATING_POINT
28664 length = 0;
28665#else
28666 if( precision<0 ) precision = 6; /* Set default precision */
28667#ifdef SQLITE_FP_PRECISION_LIMIT
28668 if( precision>SQLITE_FP_PRECISION_LIMIT ){
28669 precision = SQLITE_FP_PRECISION_LIMIT;
28670 }
28671#endif
28672 if( realvalue<0.0 ){
28673 realvalue = -realvalue;
28674 prefix = '-';
28675 }else{
28676 prefix = flag_prefix;
28677 }
28678 if( xtype==etGENERIC && precision>0 ) precision--;
28679 testcase( precision>0xfff );
28680 idx = precision & 0xfff;
28681 rounder = arRound[idx%10];
28682 while( idx>=10 ){ rounder *= 1.0e-10; idx -= 10; }
28683 if( xtype==etFLOAT ){
28684 double rx = (double)realvalue;
28686 int ex;
28687 memcpy(&u, &rx, sizeof(u));
28688 ex = -1023 + (int)((u>>52)&0x7ff);
28689 if( precision+(ex/3) < 15 ) rounder += realvalue*3e-16;
28690 realvalue += rounder;
28691 }
28692 /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
28693 exp = 0;
28694 if( sqlite3IsNaN((double)realvalue) ){
28695 bufpt = "NaN";
28696 length = 3;
28697 break;
28698 }
28699 if( realvalue>0.0 ){
28700 LONGDOUBLE_TYPE scale = 1.0;
28701 while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
28702 while( realvalue>=1e10*scale && exp<=350 ){ scale *= 1e10; exp+=10; }
28703 while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
28704 realvalue /= scale;
28705 while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
28706 while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
28707 if( exp>350 ){
28708 bufpt = buf;
28709 buf[0] = prefix;
28710 memcpy(buf+(prefix!=0),"Inf",4);
28711 length = 3+(prefix!=0);
28712 break;
28713 }
28714 }
28715 bufpt = buf;
28716 /*
28717 ** If the field type is etGENERIC, then convert to either etEXP
28718 ** or etFLOAT, as appropriate.
28719 */
28720 if( xtype!=etFLOAT ){
28721 realvalue += rounder;
28722 if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; }
28723 }
28724 if( xtype==etGENERIC ){
28725 flag_rtz = !flag_alternateform;
28726 if( exp<-4 || exp>precision ){
28727 xtype = etEXP;
28728 }else{
28729 precision = precision - exp;
28730 xtype = etFLOAT;
28731 }
28732 }else{
28733 flag_rtz = flag_altform2;
28734 }
28735 if( xtype==etEXP ){
28736 e2 = 0;
28737 }else{
28738 e2 = exp;
28739 }
28740 {
28741 i64 szBufNeeded; /* Size of a temporary buffer needed */
28742 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15;
28743 if( szBufNeeded > etBUFSIZE ){
28744 bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded);
28745 if( bufpt==0 ) return;
28746 }
28747 }
28748 zOut = bufpt;
28749 nsd = 16 + flag_altform2*10;
28750 flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2;
28751 /* The sign in front of the number */
28752 if( prefix ){
28753 *(bufpt++) = prefix;
28754 }
28755 /* Digits prior to the decimal point */
28756 if( e2<0 ){
28757 *(bufpt++) = '0';
28758 }else{
28759 for(; e2>=0; e2--){
28760 *(bufpt++) = et_getdigit(&realvalue,&nsd);
28761 }
28762 }
28763 /* The decimal point */
28764 if( flag_dp ){
28765 *(bufpt++) = '.';
28766 }
28767 /* "0" digits after the decimal point but before the first
28768 ** significant digit of the number */
28769 for(e2++; e2<0; precision--, e2++){
28770 assert( precision>0 );
28771 *(bufpt++) = '0';
28772 }
28773 /* Significant digits after the decimal point */
28774 while( (precision--)>0 ){
28775 *(bufpt++) = et_getdigit(&realvalue,&nsd);
28776 }
28777 /* Remove trailing zeros and the "." if no digits follow the "." */
28778 if( flag_rtz && flag_dp ){
28779 while( bufpt[-1]=='0' ) *(--bufpt) = 0;
28780 assert( bufpt>zOut );
28781 if( bufpt[-1]=='.' ){
28782 if( flag_altform2 ){
28783 *(bufpt++) = '0';
28784 }else{
28785 *(--bufpt) = 0;
28786 }
28787 }
28788 }
28789 /* Add the "eNNN" suffix */
28790 if( xtype==etEXP ){
28791 *(bufpt++) = aDigits[infop->charset];
28792 if( exp<0 ){
28793 *(bufpt++) = '-'; exp = -exp;
28794 }else{
28795 *(bufpt++) = '+';
28796 }
28797 if( exp>=100 ){
28798 *(bufpt++) = (char)((exp/100)+'0'); /* 100's digit */
28799 exp %= 100;
28800 }
28801 *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */
28802 *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */
28803 }
28804 *bufpt = 0;
28805
28806 /* The converted number is in buf[] and zero terminated. Output it.
28807 ** Note that the number is in the usual order, not reversed as with
28808 ** integer conversions. */
28809 length = (int)(bufpt-zOut);
28810 bufpt = zOut;
28811
28812 /* Special case: Add leading zeros if the flag_zeropad flag is
28813 ** set and we are not left justified */
28814 if( flag_zeropad && !flag_leftjustify && length < width){
28815 int i;
28816 int nPad = width - length;
28817 for(i=width; i>=nPad; i--){
28818 bufpt[i] = bufpt[i-nPad];
28819 }
28820 i = prefix!=0;
28821 while( nPad-- ) bufpt[i++] = '0';
28822 length = width;
28823 }
28824#endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
28825 break;
28826 case etSIZE:
28827 if( !bArgList ){
28828 *(va_arg(ap,int*)) = pAccum->nChar;
28829 }
28830 length = width = 0;
28831 break;
28832 case etPERCENT:
28833 buf[0] = '%';
28834 bufpt = buf;
28835 length = 1;
28836 break;
28837 case etCHARX:
28838 if( bArgList ){
28839 bufpt = getTextArg(pArgList);
28840 length = 1;
28841 if( bufpt ){
28842 buf[0] = c = *(bufpt++);
28843 if( (c&0xc0)==0xc0 ){
28844 while( length<4 && (bufpt[0]&0xc0)==0x80 ){
28845 buf[length++] = *(bufpt++);
28846 }
28847 }
28848 }else{
28849 buf[0] = 0;
28850 }
28851 }else{
28852 unsigned int ch = va_arg(ap,unsigned int);
28853 if( ch<0x00080 ){
28854 buf[0] = ch & 0xff;
28855 length = 1;
28856 }else if( ch<0x00800 ){
28857 buf[0] = 0xc0 + (u8)((ch>>6)&0x1f);
28858 buf[1] = 0x80 + (u8)(ch & 0x3f);
28859 length = 2;
28860 }else if( ch<0x10000 ){
28861 buf[0] = 0xe0 + (u8)((ch>>12)&0x0f);
28862 buf[1] = 0x80 + (u8)((ch>>6) & 0x3f);
28863 buf[2] = 0x80 + (u8)(ch & 0x3f);
28864 length = 3;
28865 }else{
28866 buf[0] = 0xf0 + (u8)((ch>>18) & 0x07);
28867 buf[1] = 0x80 + (u8)((ch>>12) & 0x3f);
28868 buf[2] = 0x80 + (u8)((ch>>6) & 0x3f);
28869 buf[3] = 0x80 + (u8)(ch & 0x3f);
28870 length = 4;
28871 }
28872 }
28873 if( precision>1 ){
28874 width -= precision-1;
28875 if( width>1 && !flag_leftjustify ){
28876 sqlite3_str_appendchar(pAccum, width-1, ' ');
28877 width = 0;
28878 }
28879 while( precision-- > 1 ){
28880 sqlite3_str_append(pAccum, buf, length);
28881 }
28882 }
28883 bufpt = buf;
28884 flag_altform2 = 1;
28885 goto adjust_width_for_utf8;
28886 case etSTRING:
28887 case etDYNSTRING:
28888 if( bArgList ){
28889 bufpt = getTextArg(pArgList);
28890 xtype = etSTRING;
28891 }else{
28892 bufpt = va_arg(ap,char*);
28893 }
28894 if( bufpt==0 ){
28895 bufpt = "";
28896 }else if( xtype==etDYNSTRING ){
28897 if( pAccum->nChar==0
28898 && pAccum->mxAlloc
28899 && width==0
28900 && precision<0
28901 && pAccum->accError==0
28902 ){
28903 /* Special optimization for sqlite3_mprintf("%z..."):
28904 ** Extend an existing memory allocation rather than creating
28905 ** a new one. */
28906 assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 );
28907 pAccum->zText = bufpt;
28908 pAccum->nAlloc = sqlite3DbMallocSize(pAccum->db, bufpt);
28909 pAccum->nChar = 0x7fffffff & (int)strlen(bufpt);
28911 length = 0;
28912 break;
28913 }
28914 zExtra = bufpt;
28915 }
28916 if( precision>=0 ){
28917 if( flag_altform2 ){
28918 /* Set length to the number of bytes needed in order to display
28919 ** precision characters */
28920 unsigned char *z = (unsigned char*)bufpt;
28921 while( precision-- > 0 && z[0] ){
28923 }
28924 length = (int)(z - (unsigned char*)bufpt);
28925 }else{
28926 for(length=0; length<precision && bufpt[length]; length++){}
28927 }
28928 }else{
28929 length = 0x7fffffff & (int)strlen(bufpt);
28930 }
28931 adjust_width_for_utf8:
28932 if( flag_altform2 && width>0 ){
28933 /* Adjust width to account for extra bytes in UTF-8 characters */
28934 int ii = length - 1;
28935 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
28936 }
28937 break;
28938 case etSQLESCAPE: /* %q: Escape ' characters */
28939 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
28940 case etSQLESCAPE3: { /* %w: Escape " characters */
28941 int i, j, k, n, isnull;
28942 int needQuote;
28943 char ch;
28944 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
28945 char *escarg;
28946
28947 if( bArgList ){
28948 escarg = getTextArg(pArgList);
28949 }else{
28950 escarg = va_arg(ap,char*);
28951 }
28952 isnull = escarg==0;
28953 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
28954 /* For %q, %Q, and %w, the precision is the number of bytes (or
28955 ** characters if the ! flags is present) to use from the input.
28956 ** Because of the extra quoting characters inserted, the number
28957 ** of output characters may be larger than the precision.
28958 */
28959 k = precision;
28960 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
28961 if( ch==q ) n++;
28962 if( flag_altform2 && (ch&0xc0)==0xc0 ){
28963 while( (escarg[i+1]&0xc0)==0x80 ){ i++; }
28964 }
28965 }
28966 needQuote = !isnull && xtype==etSQLESCAPE2;
28967 n += i + 3;
28968 if( n>etBUFSIZE ){
28969 bufpt = zExtra = printfTempBuf(pAccum, n);
28970 if( bufpt==0 ) return;
28971 }else{
28972 bufpt = buf;
28973 }
28974 j = 0;
28975 if( needQuote ) bufpt[j++] = q;
28976 k = i;
28977 for(i=0; i<k; i++){
28978 bufpt[j++] = ch = escarg[i];
28979 if( ch==q ) bufpt[j++] = ch;
28980 }
28981 if( needQuote ) bufpt[j++] = q;
28982 bufpt[j] = 0;
28983 length = j;
28984 goto adjust_width_for_utf8;
28985 }
28986 case etTOKEN: {
28987 Token *pToken;
28988 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
28989 pToken = va_arg(ap, Token*);
28990 assert( bArgList==0 );
28991 if( pToken && pToken->n ){
28992 sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
28993 }
28994 length = width = 0;
28995 break;
28996 }
28997 case etSRCLIST: {
28998 SrcList *pSrc;
28999 int k;
29000 struct SrcList_item *pItem;
29001 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
29002 pSrc = va_arg(ap, SrcList*);
29003 k = va_arg(ap, int);
29004 pItem = &pSrc->a[k];
29005 assert( bArgList==0 );
29006 assert( k>=0 && k<pSrc->nSrc );
29007 if( pItem->zDatabase ){
29008 sqlite3_str_appendall(pAccum, pItem->zDatabase);
29009 sqlite3_str_append(pAccum, ".", 1);
29010 }
29011 sqlite3_str_appendall(pAccum, pItem->zName);
29012 length = width = 0;
29013 break;
29014 }
29015 default: {
29016 assert( xtype==etINVALID );
29017 return;
29018 }
29019 }/* End switch over the format type */
29020 /*
29021 ** The text of the conversion is pointed to by "bufpt" and is
29022 ** "length" characters long. The field width is "width". Do
29023 ** the output. Both length and width are in bytes, not characters,
29024 ** at this point. If the "!" flag was present on string conversions
29025 ** indicating that width and precision should be expressed in characters,
29026 ** then the values have been translated prior to reaching this point.
29027 */
29028 width -= length;
29029 if( width>0 ){
29030 if( !flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
29031 sqlite3_str_append(pAccum, bufpt, length);
29032 if( flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
29033 }else{
29034 sqlite3_str_append(pAccum, bufpt, length);
29035 }
29036
static const char aDigits[]
Definition sqlite3.c:28204
#define etCHARX
Definition sqlite3.c:28161
#define etSIZE
Definition sqlite3.c:28157
#define SQLITE_PRINTF_MALLOCED
Definition sqlite3.c:18979
unsigned long long int sqlite_uint64
Definition sqlite3.c:1327
static const char aPrefix[]
Definition sqlite3.c:28205
static double getDoubleArg(PrintfArguments *p)
Definition sqlite3.c:28290
#define etPOINTER
Definition sqlite3.c:28167
static char * getTextArg(PrintfArguments *p)
Definition sqlite3.c:28294
#define FLAG_SIGNED
Definition sqlite3.c:28196
#define etGENERIC
Definition sqlite3.c:28156
#define SQLITE_FP_PRECISION_LIMIT
Definition sqlite3.c:28335
#define etPERCENT
Definition sqlite3.c:28160
#define etRADIX
Definition sqlite3.c:28153
#define etDECIMAL
Definition sqlite3.c:28170
#define etEXP
Definition sqlite3.c:28155
#define etSTRING
Definition sqlite3.c:28158
#define etORDINAL
Definition sqlite3.c:28169
SQLITE_API void sqlite3_str_appendchar(sqlite3_str *, int N, char C)
Definition sqlite3.c:29095
#define etDYNSTRING
Definition sqlite3.c:28159
unsigned char etByte
Definition sqlite3.c:28178
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *, void *)
Definition sqlite3.c:27654
static const et_info fmtinfo[]
Definition sqlite3.c:28206
static const double arRound[]
Definition sqlite3.c:28237
#define etBUFSIZE
Definition sqlite3.c:28329
#define etFLOAT
Definition sqlite3.c:28154
static sqlite3_int64 getIntArg(PrintfArguments *p)
Definition sqlite3.c:28286
#define etSRCLIST
Definition sqlite3.c:28166
#define etTOKEN
Definition sqlite3.c:28165
#define SQLITE_PRINTF_INTERNAL
Definition sqlite3.c:18977
#define etSQLESCAPE
Definition sqlite3.c:28163
#define etINVALID
Definition sqlite3.c:28172
#define etSQLESCAPE3
Definition sqlite3.c:28168
#define etSQLESCAPE2
Definition sqlite3.c:28164
static char * printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n)
Definition sqlite3.c:28308
etByte type
Definition sqlite3.c:28188
etByte base
Definition sqlite3.c:28186
etByte prefix
Definition sqlite3.c:28190
etByte charset
Definition sqlite3.c:28189
etByte flags
Definition sqlite3.c:28187

References SrcList::a, sqlite3_str::accError, aDigits, aPrefix, ArraySize, arRound, et_info::base, et_info::charset, sqlite3_str::db, deliberate_fall_through, et_getdigit(), etBUFSIZE, etCHARX, etDECIMAL, etDYNSTRING, etEXP, etFLOAT, etGENERIC, etINVALID, etORDINAL, etPERCENT, etPOINTER, etRADIX, etSIZE, etSQLESCAPE, etSQLESCAPE2, etSQLESCAPE3, etSRCLIST, etSTRING, etTOKEN, FLAG_SIGNED, et_info::flags, fmtinfo, getDoubleArg(), getIntArg(), getTextArg(), LONGDOUBLE_TYPE, MAX, sqlite3_str::mxAlloc, Token::n, sqlite3_str::nAlloc, sqlite3_str::nChar, et_info::prefix, sqlite3_str::printfFlags, printfTempBuf(), SMALLEST_INT64, sqlite3_str_append(), sqlite3_str_appendall(), sqlite3_str_appendchar(), sqlite3DbFree(), sqlite3DbMallocSize(), sqlite3IsNaN(), SQLITE_FP_PRECISION_LIMIT, SQLITE_PRINTF_INTERNAL, SQLITE_PRINTF_MALLOCED, SQLITE_PRINTF_SQLFUNC, SQLITE_SKIP_UTF8, testcase, et_info::type, Token::z, and sqlite3_str::zText.

Referenced by renderLogMsg(), and sqlite3_str_appendf().

◆ sqlite3_strglob()

SQLITE_API int sqlite3_strglob ( const char * zGlob,
const char * zStr )

Definition at line 117856 of file sqlite3.c.

Referenced by decodeIntArray().

◆ sqlite3_stricmp()

SQLITE_API int sqlite3_stricmp ( const char * zLeft,
const char * zRight )

Definition at line 31460 of file sqlite3.c.

31460 : R-30243-02494 The sqlite3_stricmp() and
31461** sqlite3_strnicmp() APIs allow applications and extensions to compare
31462** the contents of two buffers containing UTF-8 strings in a
31463** case-independent fashion, using the same definition of "case
31464** independence" that SQLite uses internally when comparing identifiers.
31465*/
31466SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
31467 if( zLeft==0 ){

Referenced by analysisLoader(), isSelfJoinView(), lookupName(), parseModifier(), renameColumnElistNames(), renameColumnFunc(), renameColumnIdlistNames(), renameTableFunc(), resolveAsName(), sqlite3AddColumn(), sqlite3CheckObjectName(), sqlite3ExprCompare(), sqlite3FindDbName(), sqlite3FkCheck(), sqlite3FkRequired(), sqlite3GenerateRowDelete(), sqlite3Pragma(), sqlite3Select(), xferCompatibleIndex(), and xferOptimization().

◆ sqlite3_strlike()

SQLITE_API int sqlite3_strlike ( const char * zGlob,
const char * zStr,
unsigned int cEsc )

Definition at line 117864 of file sqlite3.c.

Referenced by analyzeOneTable(), and sqlite3VdbeExec().

◆ sqlite3_strnicmp()

SQLITE_API int sqlite3_strnicmp ( const char * zLeft,
const char * zRight,
int N )

Definition at line 31487 of file sqlite3.c.

31493 {
31494 register unsigned char *a, *b;
31495 if( zLeft==0 ){
31496 return zRight ? -1 : 0;
31497 }else if( zRight==0 ){
31498 return 1;

Referenced by codeInteger(), execSql(), parseModifier(), sqlite3InitCallback(), sqlite3IsShadowTableOf(), sqlite3LoadExtension(), sqlite3LocateTable(), sqlite3PragmaVtabRegister(), and yy_reduce().

◆ sqlite3_system_errno()

SQLITE_API int sqlite3_system_errno ( sqlite3 * db)

Definition at line 163571 of file sqlite3.c.

163572 {
163573 return SQLITE_NOMEM_BKPT;

◆ sqlite3_table_column_metadata()

SQLITE_API int sqlite3_table_column_metadata ( sqlite3 * db,
const char * zDbName,
const char * zTableName,
const char * zColumnName,
char const ** pzDataType,
char const ** pzCollSeq,
int * pNotNull,
int * pPrimaryKey,
int * pAutoinc )

Definition at line 164634 of file sqlite3.c.

164650 {
164651 int rc;
164652 char *zErrMsg = 0;
164653 Table *pTab = 0;
164654 Column *pCol = 0;
164655 int iCol = 0;
164656 char const *zDataType = 0;
164657 char const *zCollSeq = 0;
164658 int notnull = 0;
164659 int primarykey = 0;
164660 int autoinc = 0;
164661
164662
164663#ifdef SQLITE_ENABLE_API_ARMOR
164664 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
164665 return SQLITE_MISUSE_BKPT;
164666 }
164667#endif
164668
164669 /* Ensure the database schema has been loaded */
164672 rc = sqlite3Init(db, &zErrMsg);
164673 if( SQLITE_OK!=rc ){
164674 goto error_out;
164675 }
164676
164677 /* Locate the table in question */
164678 pTab = sqlite3FindTable(db, zTableName, zDbName);
164679 if( !pTab || pTab->pSelect ){
164680 pTab = 0;
164681 goto error_out;
164682 }
164683
164684 /* Find the column for which info is requested */
164685 if( zColumnName==0 ){
164686 /* Query for existance of table only */
164687 }else{
164688 for(iCol=0; iCol<pTab->nCol; iCol++){
164689 pCol = &pTab->aCol[iCol];
164690 if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
164691 break;
164692 }
164693 }
164694 if( iCol==pTab->nCol ){
164695 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
164696 iCol = pTab->iPKey;
164697 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
164698 }else{
164699 pTab = 0;
164700 goto error_out;
164701 }
164702 }
164703 }
164704
164705 /* The following block stores the meta information that will be returned
164706 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
164707 ** and autoinc. At this point there are two possibilities:
164708 **
164709 ** 1. The specified column name was rowid", "oid" or "_rowid_"
164710 ** and there is no explicitly declared IPK column.
164711 **
164712 ** 2. The table is not a view and the column name identified an
164713 ** explicitly declared column. Copy meta information from *pCol.
164714 */
164715 if( pCol ){
164716 zDataType = sqlite3ColumnType(pCol,0);
164717 zCollSeq = pCol->zColl;
164718 notnull = pCol->notNull!=0;
164719 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
164720 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
164721 }else{
164722 zDataType = "INTEGER";
164723 primarykey = 1;
164724 }
164725 if( !zCollSeq ){
164726 zCollSeq = sqlite3StrBINARY;
164727 }
164728
164729error_out:
164731
164732 /* Whether the function call succeeded or failed, set the output parameters
164733 ** to whatever their local counterparts contain. If an error did occur,
164734 ** this has the effect of zeroing all output parameters.
164735 */
164736 if( pzDataType ) *pzDataType = zDataType;
164737 if( pzCollSeq ) *pzCollSeq = zCollSeq;
164738 if( pNotNull ) *pNotNull = notnull;
164739 if( pPrimaryKey ) *pPrimaryKey = primarykey;
164740 if( pAutoinc ) *pAutoinc = autoinc;
164741
164742 if( SQLITE_OK==rc && !pTab ){
164743 sqlite3DbFree(db, zErrMsg);
164744 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
164745 zColumnName);
164746 rc = SQLITE_ERROR;
164747 }

References Table::aCol, COLFLAG_PRIMKEY, Column::colFlags, HasRowid, Table::iPKey, sqlite3::mutex, Table::nCol, Column::notNull, Table::pSelect, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3BtreeEnterAll(), sqlite3BtreeLeaveAll(), sqlite3ColumnType(), sqlite3DbFree(), sqlite3ErrorWithMsg(), sqlite3FindTable(), sqlite3Init(), sqlite3IsRowid(), sqlite3MPrintf(), sqlite3SafetyCheckOk(), sqlite3StrBINARY, sqlite3StrICmp(), SQLITE_ERROR, SQLITE_MISUSE_BKPT, SQLITE_OK, Table::tabFlags, TF_Autoincrement, Column::zColl, and Column::zName.

◆ sqlite3_test_control()

SQLITE_API int sqlite3_test_control ( int op,
... )

Definition at line 164829 of file sqlite3.c.

164835 {
164836 int rc = 0;
164837#ifdef SQLITE_UNTESTABLE
164838 UNUSED_PARAMETER(op);
164839#else
164840 va_list ap;
164841 va_start(ap, op);
164842 switch( op ){
164843
164844 /*
164845 ** Save the current state of the PRNG.
164846 */
164849 break;
164850 }
164851
164852 /*
164853 ** Restore the state of the PRNG to the last state saved using
164854 ** PRNG_SAVE. If PRNG_SAVE has never before been called, then
164855 ** this verb acts like PRNG_RESET.
164856 */
164859 break;
164860 }
164861
164862 /* sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, int x, sqlite3 *db);
164863 **
164864 ** Control the seed for the pseudo-random number generator (PRNG) that
164865 ** is built into SQLite. Cases:
164866 **
164867 ** x!=0 && db!=0 Seed the PRNG to the current value of the
164868 ** schema cookie in the main database for db, or
164869 ** x if the schema cookie is zero. This case
164870 ** is convenient to use with database fuzzers
164871 ** as it allows the fuzzer some control over the
164872 ** the PRNG seed.
164873 **
164874 ** x!=0 && db==0 Seed the PRNG to the value of x.
164875 **
164876 ** x==0 && db==0 Revert to default behavior of using the
164877 ** xRandomness method on the primary VFS.
164878 **
164879 ** This test-control also resets the PRNG so that the new seed will
164880 ** be used for the next call to sqlite3_randomness().
164881 */
164882#ifndef SQLITE_OMIT_WSD
164884 int x = va_arg(ap, int);
164885 int y;
164886 sqlite3 *db = va_arg(ap, sqlite3*);
164887 assert( db==0 || db->aDb[0].pSchema!=0 );
164888 if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
164890 sqlite3_randomness(0,0);
164891 break;
164892 }
164893#endif
164894
164895 /*
164896 ** sqlite3_test_control(BITVEC_TEST, size, program)
164897 **
164898 ** Run a test against a Bitvec object of size. The program argument
164899 ** is an array of integers that defines the test. Return -1 on a
164900 ** memory allocation error, 0 on success, or non-zero for an error.
164901 ** See the sqlite3BitvecBuiltinTest() for additional information.
164902 */
164904 int sz = va_arg(ap, int);
164905 int *aProg = va_arg(ap, int*);
164906 rc = sqlite3BitvecBuiltinTest(sz, aProg);
164907 break;
164908 }
164909
164910 /*
164911 ** sqlite3_test_control(FAULT_INSTALL, xCallback)
164912 **
164913 ** Arrange to invoke xCallback() whenever sqlite3FaultSim() is called,
164914 ** if xCallback is not NULL.
164915 **
164916 ** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
164917 ** is called immediately after installing the new callback and the return
164918 ** value from sqlite3FaultSim(0) becomes the return from
164919 ** sqlite3_test_control().
164920 */
164922 /* MSVC is picky about pulling func ptrs from va lists.
164923 ** http://support.microsoft.com/kb/47961
164924 ** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
164925 */
164926 typedef int(*TESTCALLBACKFUNC_t)(int);
164927 sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
164928 rc = sqlite3FaultSim(0);
164929 break;
164930 }
164931
164932 /*
164933 ** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
164934 **
164935 ** Register hooks to call to indicate which malloc() failures
164936 ** are benign.
164937 */
164939 typedef void (*void_function)(void);
164940 void_function xBenignBegin;
164941 void_function xBenignEnd;
164942 xBenignBegin = va_arg(ap, void_function);
164943 xBenignEnd = va_arg(ap, void_function);
164944 sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd);
164945 break;
164946 }
164947
164948 /*
164949 ** sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, unsigned int X)
164950 **
164951 ** Set the PENDING byte to the value in the argument, if X>0.
164952 ** Make no changes if X==0. Return the value of the pending byte
164953 ** as it existing before this routine was called.
164954 **
164955 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
164956 ** an incompatible database file format. Changing the PENDING byte
164957 ** while any database connection is open results in undefined and
164958 ** deleterious behavior.
164959 */
164961 rc = PENDING_BYTE;
164962#ifndef SQLITE_OMIT_WSD
164963 {
164964 unsigned int newVal = va_arg(ap, unsigned int);
164965 if( newVal ) sqlite3PendingByte = newVal;
164966 }
164967#endif
164968 break;
164969 }
164970
164971 /*
164972 ** sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X)
164973 **
164974 ** This action provides a run-time test to see whether or not
164975 ** assert() was enabled at compile-time. If X is true and assert()
164976 ** is enabled, then the return value is true. If X is true and
164977 ** assert() is disabled, then the return value is zero. If X is
164978 ** false and assert() is enabled, then the assertion fires and the
164979 ** process aborts. If X is false and assert() is disabled, then the
164980 ** return value is zero.
164981 */
164982 case SQLITE_TESTCTRL_ASSERT: {
164983 volatile int x = 0;
164984 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
164985 rc = x;
164986 break;
164987 }
164988
164989
164990 /*
164991 ** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
164992 **
164993 ** This action provides a run-time test to see how the ALWAYS and
164994 ** NEVER macros were defined at compile-time.
164995 **
164996 ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
164997 **
164998 ** The recommended test is X==2. If the return value is 2, that means
164999 ** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
165000 ** default setting. If the return value is 1, then ALWAYS() is either
165001 ** hard-coded to true or else it asserts if its argument is false.
165002 ** The first behavior (hard-coded to true) is the case if
165003 ** SQLITE_TESTCTRL_ASSERT shows that assert() is disabled and the second
165004 ** behavior (assert if the argument to ALWAYS() is false) is the case if
165005 ** SQLITE_TESTCTRL_ASSERT shows that assert() is enabled.
165006 **
165007 ** The run-time test procedure might look something like this:
165008 **
165009 ** if( sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, 2)==2 ){
165010 ** // ALWAYS() and NEVER() are no-op pass-through macros
165011 ** }else if( sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, 1) ){
165012 ** // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
165013 ** }else{
165014 ** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
165015 ** }
165016 */
165017 case SQLITE_TESTCTRL_ALWAYS: {
165018 int x = va_arg(ap,int);
165019 rc = x ? ALWAYS(x) : 0;
165020 break;
165021 }
165022
165023 /*
165024 ** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
165025 **
165026 ** The integer returned reveals the byte-order of the computer on which
165027 ** SQLite is running:
165028 **
165029 ** 1 big-endian, determined at run-time
165030 ** 10 little-endian, determined at run-time
165031 ** 432101 big-endian, determined at compile-time
165032 ** 123410 little-endian, determined at compile-time
165033 */
165036 break;
165037 }
165038
165039 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
165040 **
165041 ** Enable or disable various optimizations for testing purposes. The
165042 ** argument N is a bitmask of optimizations to be disabled. For normal
165043 ** operation N should be 0. The idea is that a test program (like the
165044 ** SQL Logic Test or SLT test module) can run the same SQL multiple times
165045 ** with various optimizations disabled to verify that the same answer
165046 ** is obtained in every case.
165047 */
165049 sqlite3 *db = va_arg(ap, sqlite3*);
165050 db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
165051 break;
165052 }
165053
165054 /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
165055 **
165056 ** If parameter onoff is non-zero, subsequent calls to localtime()
165057 ** and its variants fail. If onoff is zero, undo this setting.
165058 */
165060 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
165061 break;
165062 }
165063
165064 /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
165065 **
165066 ** Toggle the ability to use internal functions on or off for
165067 ** the database connection given in the argument.
165068 */
165070 sqlite3 *db = va_arg(ap, sqlite3*);
165072 break;
165073 }
165074
165075 /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
165076 **
165077 ** Set or clear a flag that indicates that the database file is always well-
165078 ** formed and never corrupt. This flag is clear by default, indicating that
165079 ** database files might have arbitrary corruption. Setting the flag during
165080 ** testing causes certain assert() statements in the code to be activated
165081 ** that demonstrat invariants on well-formed database files.
165082 */
165084 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
165085 break;
165086 }
165087
165088 /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
165089 **
165090 ** Set or clear a flag that causes SQLite to verify that type, name,
165091 ** and tbl_name fields of the sqlite_schema table. This is normally
165092 ** on, but it is sometimes useful to turn it off for testing.
165093 **
165094 ** 2020-07-22: Disabling EXTRA_SCHEMA_CHECKS also disables the
165095 ** verification of rootpage numbers when parsing the schema. This
165096 ** is useful to make it easier to reach strange internal error states
165097 ** during testing. The EXTRA_SCHEMA_CHECKS setting is always enabled
165098 ** in production.
165099 */
165101 sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
165102 break;
165103 }
165104
165105 /* Set the threshold at which OP_Once counters reset back to zero.
165106 ** By default this is 0x7ffffffe (over 2 billion), but that value is
165107 ** too big to test in a reasonable amount of time, so this control is
165108 ** provided to set a small and easily reachable reset value.
165109 */
165111 sqlite3GlobalConfig.iOnceResetThreshold = va_arg(ap, int);
165112 break;
165113 }
165114
165115 /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
165116 **
165117 ** Set the VDBE coverage callback function to xCallback with context
165118 ** pointer ptr.
165119 */
165121#ifdef SQLITE_VDBE_COVERAGE
165122 typedef void (*branch_callback)(void*,unsigned int,
165123 unsigned char,unsigned char);
165124 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
165125 sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
165126#endif
165127 break;
165128 }
165129
165130 /* sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */
165132 sqlite3 *db = va_arg(ap, sqlite3*);
165133 db->nMaxSorterMmap = va_arg(ap, int);
165134 break;
165135 }
165136
165137 /* sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
165138 **
165139 ** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
165140 ** not.
165141 */
165142 case SQLITE_TESTCTRL_ISINIT: {
165143 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
165144 break;
165145 }
165146
165147 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
165148 **
165149 ** This test control is used to create imposter tables. "db" is a pointer
165150 ** to the database connection. dbName is the database name (ex: "main" or
165151 ** "temp") which will receive the imposter. "onOff" turns imposter mode on
165152 ** or off. "tnum" is the root page of the b-tree to which the imposter
165153 ** table should connect.
165154 **
165155 ** Enable imposter mode only when the schema has already been parsed. Then
165156 ** run a single CREATE TABLE statement to construct the imposter table in
165157 ** the parsed schema. Then turn imposter mode back off again.
165158 **
165159 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
165160 ** the schema to be reparsed the next time it is needed. This has the
165161 ** effect of erasing all imposter tables.
165162 */
165164 sqlite3 *db = va_arg(ap, sqlite3*);
165166 db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
165167 db->init.busy = db->init.imposterTable = va_arg(ap,int);
165168 db->init.newTnum = va_arg(ap,int);
165169 if( db->init.busy==0 && db->init.newTnum>0 ){
165171 }
165173 break;
165174 }
165175
165176#if defined(YYCOVERAGE)
165177 /* sqlite3_test_control(SQLITE_TESTCTRL_PARSER_COVERAGE, FILE *out)
165178 **
165179 ** This test control (only available when SQLite is compiled with
165180 ** -DYYCOVERAGE) writes a report onto "out" that shows all
165181 ** state/lookahead combinations in the parser state machine
165182 ** which are never exercised. If any state is missed, make the
165183 ** return code SQLITE_ERROR.
165184 */
165186 FILE *out = va_arg(ap, FILE*);
165187 if( sqlite3ParserCoverage(out) ) rc = SQLITE_ERROR;
165188 break;
165189 }
165190#endif /* defined(YYCOVERAGE) */
165191
165192 /* sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL, sqlite3_context*);
165193 **
165194 ** This test-control causes the most recent sqlite3_result_int64() value
165195 ** to be interpreted as a MEM_IntReal instead of as an MEM_Int. Normally,
165196 ** MEM_IntReal values only arise during an INSERT operation of integer
165197 ** values into a REAL column, so they can be challenging to test. This
165198 ** test-control enables us to write an intreal() SQL function that can
165199 ** inject an intreal() value at arbitrary places in an SQL statement,
165200 ** for testing purposes.
165201 */
165203 sqlite3_context *pCtx = va_arg(ap, sqlite3_context*);
165204 sqlite3ResultIntReal(pCtx);
165205 break;
#define SQLITE_TESTCTRL_PARSER_COVERAGE
Definition sqlite3.c:8759
#define SQLITE_TESTCTRL_ALWAYS
Definition sqlite3.c:8744
#define SQLITE_TESTCTRL_LOCALTIME_FAULT
Definition sqlite3.c:8750
#define SQLITE_TESTCTRL_IMPOSTER
Definition sqlite3.c:8758
#define SQLITE_LITTLEENDIAN
Definition sqlite3.c:14455
#define SQLITE_TESTCTRL_SORTER_MMAP
Definition sqlite3.c:8757
#define SQLITE_TESTCTRL_PRNG_SAVE
Definition sqlite3.c:8736
SQLITE_PRIVATE int sqlite3PendingByte
Definition sqlite3.c:20663
#define SQLITE_TESTCTRL_ISINIT
Definition sqlite3.c:8756
SQLITE_PRIVATE void sqlite3ResultIntReal(sqlite3_context *)
Definition sqlite3.c:83552
#define SQLITE_TESTCTRL_PENDING_BYTE
Definition sqlite3.c:8742
#define SQLITE_TESTCTRL_PRNG_SEED
Definition sqlite3.c:8761
SQLITE_PRIVATE void sqlite3BenignMallocHooks(void(*)(void), void(*)(void))
Definition sqlite3.c:23455
#define SQLITE_TESTCTRL_PRNG_RESTORE
Definition sqlite3.c:8737
#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS
Definition sqlite3.c:8762
#define SQLITE_TESTCTRL_NEVER_CORRUPT
Definition sqlite3.c:8753
#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS
Definition sqlite3.c:8741
#define SQLITE_TESTCTRL_ASSERT
Definition sqlite3.c:8743
#define SQLITE_TESTCTRL_OPTIMIZATIONS
Definition sqlite3.c:8746
SQLITE_PRIVATE void sqlite3PrngSaveState(void)
Definition sqlite3.c:30348
#define SQLITE_BYTEORDER
Definition sqlite3.c:14437
SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int, int *)
Definition sqlite3.c:48796
#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD
Definition sqlite3.c:8752
#define SQLITE_TESTCTRL_VDBE_COVERAGE
Definition sqlite3.c:8754
#define SQLITE_TESTCTRL_BITVEC_TEST
Definition sqlite3.c:8739
SQLITE_PRIVATE void sqlite3PrngRestoreState(void)
Definition sqlite3.c:30355
#define SQLITE_TESTCTRL_RESULT_INTREAL
Definition sqlite3.c:8760
#define SQLITE_TESTCTRL_FAULT_INSTALL
Definition sqlite3.c:8740
#define SQLITE_TESTCTRL_BYTEORDER
Definition sqlite3.c:8755
#define SQLITE_BIGENDIAN
Definition sqlite3.c:14454
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
Definition sqlite3.c:8749
unsigned int iPrngSeed
Definition sqlite3.c:19066
u16 dbOptFlags
Definition sqlite3.c:16835

◆ sqlite3_thread_cleanup()

SQLITE_API void sqlite3_thread_cleanup ( void )

Definition at line 164626 of file sqlite3.c.

◆ sqlite3_threadsafe()

SQLITE_API int sqlite3_threadsafe ( void )

Definition at line 161123 of file sqlite3.c.

161123{ return SQLITE_VERSION_NUMBER; }
#define SQLITE_VERSION_NUMBER
Definition sqlite3.c:1175

References SQLITE_VERSION_NUMBER.

◆ sqlite3_total_changes()

SQLITE_API int sqlite3_total_changes ( sqlite3 * db)

Definition at line 162095 of file sqlite3.c.

162101 {
162102#ifdef SQLITE_ENABLE_API_ARMOR
162103 if( !sqlite3SafetyCheckOk(db) ){

Referenced by db_total_changes().

◆ sqlite3_trace()

SQLITE_API void * sqlite3_trace ( sqlite3 * db,
void(*)(void *, const char *) xTrace,
void * pArg )

Definition at line 163075 of file sqlite3.c.

163081 {
163082 void *pOld;
163083
163084#ifdef SQLITE_ENABLE_API_ARMOR
163085 if( !sqlite3SafetyCheckOk(db) ){
163086 (void)SQLITE_MISUSE_BKPT;
163087 return 0;
163088 }
163089#endif
163091 pOld = db->pTraceArg;
void * pTraceArg
Definition sqlite3.c:16875

References sqlite3::mTrace, sqlite3::mutex, sqlite3::pTraceArg, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_TRACE_LEGACY, sqlite3::trace, and sqlite3::xLegacy.

Referenced by db_trace().

◆ sqlite3_trace_v2()

SQLITE_API int sqlite3_trace_v2 ( sqlite3 * db,
unsigned uMask,
int(*)(unsigned, void *, void *, void *) xCallback,
void * pCtx )

Definition at line 163096 of file sqlite3.c.

163107 {
163108#ifdef SQLITE_ENABLE_API_ARMOR
163109 if( !sqlite3SafetyCheckOk(db) ){
163110 return SQLITE_MISUSE_BKPT;
163111 }
163112#endif
163114 if( mTrace==0 ) xTrace = 0;
163115 if( xTrace==0 ) mTrace = 0;

◆ sqlite3_transfer_bindings()

SQLITE_API int sqlite3_transfer_bindings ( sqlite3_stmt * pFromStmt,
sqlite3_stmt * pToStmt )

Definition at line 84622 of file sqlite3.c.

84628 {
84629 Vdbe *pFrom = (Vdbe*)pFromStmt;
84630 Vdbe *pTo = (Vdbe*)pToStmt;
84631 if( pFrom->nVar!=pTo->nVar ){
84632 return SQLITE_ERROR;
84633 }
84634 assert( (pTo->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pTo->expmask==0 );
84635 if( pTo->expmask ){
84636 pTo->expired = 1;
84637 }
bft expired
Definition sqlite3.c:21127

References Vdbe::expired, Vdbe::expmask, Vdbe::nVar, Vdbe::prepFlags, sqlite3TransferBindings(), SQLITE_ERROR, and SQLITE_PREPARE_SAVESQL.

◆ sqlite3_unlock_notify()

SQLITE_API int sqlite3_unlock_notify ( sqlite3 * pBlocked,
void(*)(void **apArg, int nArg) xNotify,
void * pNotifyArg )

◆ sqlite3_update_hook()

SQLITE_API void * sqlite3_update_hook ( sqlite3 * db,
void(*)(void *, int,char const *, char const *, sqlite3_int64) xCallback,
void * pArg )

Definition at line 163181 of file sqlite3.c.

163191 {
163192 void *pRet;
163193
163194#ifdef SQLITE_ENABLE_API_ARMOR
163195 if( !sqlite3SafetyCheckOk(db) ){
163196 (void)SQLITE_MISUSE_BKPT;
163197 return 0;
163198 }
163199#endif

Referenced by db_update_hook().

◆ sqlite3_uri_boolean()

SQLITE_API int sqlite3_uri_boolean ( const char * zFile,
const char * zParam,
int bDefault )

Definition at line 165318 of file sqlite3.c.

165318 : 0;
165319}
165320
165321/*
165322** Return a boolean value for a query parameter.

Referenced by sqlite3PagerOpen(), and unixOpenSharedMemory().

◆ sqlite3_uri_int64()

SQLITE_API sqlite3_int64 sqlite3_uri_int64 ( const char * zFilename,
const char * zParam,
sqlite3_int64 bDflt )

Definition at line 165327 of file sqlite3.c.

165327 : bDflt;
165328}
165329
165330/*
165331** Return a 64-bit integer value for a query parameter.
165332*/
165334 const char *zFilename, /* Filename as passed to xOpen */
165335 const char *zParam, /* URI parameter sought */
165336 sqlite3_int64 bDflt /* return if parameter is missing */
165337){
165338 const char *z = sqlite3_uri_parameter(zFilename, zParam);
SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char *, const char *, sqlite3_int64)
Definition sqlite3.c:165327

◆ sqlite3_uri_key()

SQLITE_API const char * sqlite3_uri_key ( const char * zFilename,
int N )

Definition at line 165304 of file sqlite3.c.

165310 {
165311 if( zFilename==0 || N<0 ) return 0;
165312 zFilename = databaseName(zFilename);
165313 zFilename += sqlite3Strlen30(zFilename) + 1;

◆ sqlite3_uri_parameter()

SQLITE_API const char * sqlite3_uri_parameter ( const char * zFilename,
const char * zParam )

Definition at line 165295 of file sqlite3.c.

References databaseName().

Referenced by findCreateFileMode().

◆ sqlite3_user_data()

◆ sqlite3_value_blob()

SQLITE_API const void * sqlite3_value_blob ( sqlite3_value * pVal)

Definition at line 83153 of file sqlite3.c.

83159 {
83160 Mem *p = (Mem*)pVal;
83161 if( p->flags & (MEM_Blob|MEM_Str) ){
83162 if( ExpandBlob(p)!=SQLITE_OK ){
83163 assert( p->flags==MEM_Null && p->z==0 );
83164 return 0;
83165 }

References ExpandBlob, sqlite3_value::flags, MEM_Blob, MEM_Null, MEM_Str, SQLITE_OK, and sqlite3_value::z.

Referenced by db_push_value(), instrFunc(), quoteFunc(), statGet(), statPush(), and substrFunc().

◆ sqlite3_value_bytes()

SQLITE_API int sqlite3_value_bytes ( sqlite3_value * pVal)

Definition at line 83166 of file sqlite3.c.

83167 : 0;
83168 }else{

Referenced by db_push_value(), instrFunc(), isDate(), likeFunc(), quoteFunc(), replaceFunc(), statPush(), and substrFunc().

◆ sqlite3_value_bytes16()

SQLITE_API int sqlite3_value_bytes16 ( sqlite3_value * pVal)

Definition at line 83169 of file sqlite3.c.

◆ sqlite3_value_double()

SQLITE_API double sqlite3_value_double ( sqlite3_value * pVal)

Definition at line 83172 of file sqlite3.c.

83172 {
83173 return sqlite3ValueBytes(pVal, SQLITE_UTF8);
83174}
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value *, u8)
Definition sqlite3.c:77714

References sqlite3ValueBytes(), and SQLITE_UTF8.

Referenced by absFunc(), db_push_value(), isDate(), and quoteFunc().

◆ sqlite3_value_dup()

SQLITE_API sqlite3_value * sqlite3_value_dup ( const sqlite3_value * pOrig)

Definition at line 83313 of file sqlite3.c.

83313 {
83314 return (pVal->flags&MEM_FromBind)!=0;
83315}
83316
83317/* Make a copy of an sqlite3_value object
83318*/
83320 sqlite3_value *pNew;
83321 if( pOrig==0 ) return 0;
83322 pNew = sqlite3_malloc( sizeof(*pNew) );
83323 if( pNew==0 ) return 0;
83324 memset(pNew, 0, sizeof(*pNew));
83325 memcpy(pNew, pOrig, MEMCELLSIZE);
83326 pNew->flags &= ~MEM_Dyn;
83327 pNew->db = 0;
83328 if( pNew->flags&(MEM_Str|MEM_Blob) ){
83329 pNew->flags &= ~(MEM_Static|MEM_Dyn);
83330 pNew->flags |= MEM_Ephem;
#define MEMCELLSIZE
Definition sqlite3.c:20933
#define MEM_FromBind
Definition sqlite3.c:20955

References sqlite3_value::flags, and MEM_FromBind.

Referenced by instrFunc().

◆ sqlite3_value_free()

SQLITE_API void sqlite3_value_free ( sqlite3_value * pOld)

Definition at line 83336 of file sqlite3.c.

Referenced by instrFunc(), and last_valueValueFunc().

◆ sqlite3_value_frombind()

SQLITE_API int sqlite3_value_frombind ( sqlite3_value * pVal)

Definition at line 83307 of file sqlite3.c.

83308 {
83309 return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);

References sqlite3_value::flags, MEM_Null, and MEM_Zero.

◆ sqlite3_value_int()

◆ sqlite3_value_int64()

SQLITE_API sqlite_int64 sqlite3_value_int64 ( sqlite3_value * pVal)

Definition at line 83178 of file sqlite3.c.

83178 {
83179 return sqlite3VdbeRealValue((Mem*)pVal);
83180}
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *)
Definition sqlite3.c:76445

References sqlite3VdbeRealValue().

Referenced by absFunc(), charFunc(), db_push_value(), ntileStepFunc(), statInit(), statPush(), and sumStep().

◆ sqlite3_value_nochange()

SQLITE_API int sqlite3_value_nochange ( sqlite3_value * pVal)

Definition at line 83302 of file sqlite3.c.

Referenced by sqlite3_vtab_nochange(), and sqlite3VdbeMemExpandBlob().

◆ sqlite3_value_numeric_type()

SQLITE_API int sqlite3_value_numeric_type ( sqlite3_value * pVal)

Definition at line 85640 of file sqlite3.c.

85646 {
85647 int eType = sqlite3_value_type(pVal);
85648 if( eType==SQLITE_TEXT ){

References applyNumericAffinity(), eType, sqlite3_value_type(), and SQLITE_TEXT.

Referenced by sumStep().

◆ sqlite3_value_pointer()

SQLITE_API void * sqlite3_value_pointer ( sqlite3_value * pVal,
const char * zPType )

Definition at line 83185 of file sqlite3.c.

83187 {
83188 Mem *pMem = (Mem*)pVal;
83189 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
83190}
83191SQLITE_API void *sqlite3_value_pointer(sqlite3_value *pVal, const char *zPType){
83192 Mem *p = (Mem*)pVal;
83195 && zPType!=0
83196 && p->eSubtype=='p'
83197 && strcmp(p->u.zPType, zPType)==0
#define MEM_Term
Definition sqlite3.c:20966
SQLITE_API void * sqlite3_value_pointer(sqlite3_value *, const char *)
Definition sqlite3.c:83185

◆ sqlite3_value_subtype()

SQLITE_API unsigned int sqlite3_value_subtype ( sqlite3_value * pVal)

Definition at line 83181 of file sqlite3.c.

83181 {
83182 return (int)sqlite3VdbeIntValue((Mem*)pVal);
83183}
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *)
Definition sqlite3.c:76416

References sqlite3VdbeIntValue().

◆ sqlite3_value_text()

◆ sqlite3_value_text16()

SQLITE_API const void * sqlite3_value_text16 ( sqlite3_value * pVal)

Definition at line 83202 of file sqlite3.c.

83204 {

Referenced by columnName(), sqlite3_column_type(), and sqlite3_errmsg16().

◆ sqlite3_value_text16be()

SQLITE_API const void * sqlite3_value_text16be ( sqlite3_value * pVal)

Definition at line 83205 of file sqlite3.c.

◆ sqlite3_value_text16le()

SQLITE_API const void * sqlite3_value_text16le ( sqlite3_value * pVal)

Definition at line 83208 of file sqlite3.c.

83208 {
83210}

References sqlite3ValueText(), and SQLITE_UTF16NATIVE.

◆ sqlite3_value_type()

SQLITE_API int sqlite3_value_type ( sqlite3_value * pVal)

Definition at line 83216 of file sqlite3.c.

83222 {
83223 static const u8 aType[] = {
83224 SQLITE_BLOB, /* 0x00 (not possible) */
83225 SQLITE_NULL, /* 0x01 NULL */
83226 SQLITE_TEXT, /* 0x02 TEXT */
83227 SQLITE_NULL, /* 0x03 (not possible) */
83228 SQLITE_INTEGER, /* 0x04 INTEGER */
83229 SQLITE_NULL, /* 0x05 (not possible) */
83230 SQLITE_INTEGER, /* 0x06 INTEGER + TEXT */
83231 SQLITE_NULL, /* 0x07 (not possible) */
83232 SQLITE_FLOAT, /* 0x08 FLOAT */
83233 SQLITE_NULL, /* 0x09 (not possible) */
83234 SQLITE_FLOAT, /* 0x0a FLOAT + TEXT */
83235 SQLITE_NULL, /* 0x0b (not possible) */
83236 SQLITE_INTEGER, /* 0x0c (not possible) */
83237 SQLITE_NULL, /* 0x0d (not possible) */
83238 SQLITE_INTEGER, /* 0x0e (not possible) */
83239 SQLITE_NULL, /* 0x0f (not possible) */
83240 SQLITE_BLOB, /* 0x10 BLOB */
83241 SQLITE_NULL, /* 0x11 (not possible) */
83242 SQLITE_TEXT, /* 0x12 (not possible) */
83243 SQLITE_NULL, /* 0x13 (not possible) */
83244 SQLITE_INTEGER, /* 0x14 INTEGER + BLOB */
83245 SQLITE_NULL, /* 0x15 (not possible) */
83246 SQLITE_INTEGER, /* 0x16 (not possible) */
83247 SQLITE_NULL, /* 0x17 (not possible) */
83248 SQLITE_FLOAT, /* 0x18 FLOAT + BLOB */
83249 SQLITE_NULL, /* 0x19 (not possible) */
83250 SQLITE_FLOAT, /* 0x1a (not possible) */
83251 SQLITE_NULL, /* 0x1b (not possible) */
83252 SQLITE_INTEGER, /* 0x1c (not possible) */
83253 SQLITE_NULL, /* 0x1d (not possible) */
83254 SQLITE_INTEGER, /* 0x1e (not possible) */
83255 SQLITE_NULL, /* 0x1f (not possible) */
83256 SQLITE_FLOAT, /* 0x20 INTREAL */
83257 SQLITE_NULL, /* 0x21 (not possible) */
83258 SQLITE_TEXT, /* 0x22 INTREAL + TEXT */
83259 SQLITE_NULL, /* 0x23 (not possible) */
83260 SQLITE_FLOAT, /* 0x24 (not possible) */
83261 SQLITE_NULL, /* 0x25 (not possible) */
83262 SQLITE_FLOAT, /* 0x26 (not possible) */
83263 SQLITE_NULL, /* 0x27 (not possible) */
83264 SQLITE_FLOAT, /* 0x28 (not possible) */
83265 SQLITE_NULL, /* 0x29 (not possible) */
83266 SQLITE_FLOAT, /* 0x2a (not possible) */
83267 SQLITE_NULL, /* 0x2b (not possible) */
83268 SQLITE_FLOAT, /* 0x2c (not possible) */
83269 SQLITE_NULL, /* 0x2d (not possible) */
83270 SQLITE_FLOAT, /* 0x2e (not possible) */
83271 SQLITE_NULL, /* 0x2f (not possible) */
83272 SQLITE_BLOB, /* 0x30 (not possible) */
83273 SQLITE_NULL, /* 0x31 (not possible) */
83274 SQLITE_TEXT, /* 0x32 (not possible) */
83275 SQLITE_NULL, /* 0x33 (not possible) */
83276 SQLITE_FLOAT, /* 0x34 (not possible) */
83277 SQLITE_NULL, /* 0x35 (not possible) */
83278 SQLITE_FLOAT, /* 0x36 (not possible) */
83279 SQLITE_NULL, /* 0x37 (not possible) */
83280 SQLITE_FLOAT, /* 0x38 (not possible) */
83281 SQLITE_NULL, /* 0x39 (not possible) */
83282 SQLITE_FLOAT, /* 0x3a (not possible) */
83283 SQLITE_NULL, /* 0x3b (not possible) */
83284 SQLITE_FLOAT, /* 0x3c (not possible) */
83285 SQLITE_NULL, /* 0x3d (not possible) */
83286 SQLITE_FLOAT, /* 0x3e (not possible) */
83287 SQLITE_NULL, /* 0x3f (not possible) */
83288 };
83289#ifdef SQLITE_DEBUG
83290 {
83291 int eType = SQLITE_BLOB;
83292 if( pVal->flags & MEM_Null ){
83294 }else if( pVal->flags & (MEM_Real|MEM_IntReal) ){
83296 }else if( pVal->flags & MEM_Int ){
83298 }else if( pVal->flags & MEM_Str ){

Referenced by absFunc(), db_push_value(), exprCompareVariable(), instrFunc(), isDate(), isLikeOrGlob(), likeFunc(), minmaxStep(), quoteFunc(), replaceFunc(), sqlite3_value_numeric_type(), statPush(), and substrFunc().

◆ sqlite3_vfs_find()

SQLITE_API sqlite3_vfs * sqlite3_vfs_find ( const char * zVfsName)

Definition at line 23307 of file sqlite3.c.

23312 {
23313 sqlite3_vfs *pVfs = 0;
23314#if SQLITE_THREADSAFE
23316#endif
23317#ifndef SQLITE_OMIT_AUTOINIT
23318 int rc = sqlite3_initialize();
23319 if( rc ) return 0;
23320#endif
23321#if SQLITE_THREADSAFE
23323#endif
23325 for(pVfs = vfsList; pVfs; pVfs=pVfs->pNext){
23326 if( zVfs==0 ) break;
#define vfsList
Definition sqlite3.c:23301
sqlite3_vfs * pNext
Definition sqlite3.c:2421

References mutex, sqlite3_vfs::pNext, sqlite3_initialize(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_MAIN, vfsList, and sqlite3_vfs::zName.

Referenced by attachFunc(), and sqlite3ParseUri().

◆ sqlite3_vfs_register()

SQLITE_API int sqlite3_vfs_register ( sqlite3_vfs * pVfs,
int makeDflt )

Definition at line 23353 of file sqlite3.c.

23358 {
23360#ifndef SQLITE_OMIT_AUTOINIT
23361 int rc = sqlite3_initialize();
23362 if( rc ) return rc;
23363#endif
23364#ifdef SQLITE_ENABLE_API_ARMOR
23365 if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
23366#endif
23367
23370 vfsUnlink(pVfs);
23371 if( makeDflt || vfsList==0 ){
23372 pVfs->pNext = vfsList;
23373 vfsList = pVfs;
23374 }else{
23375 pVfs->pNext = vfsList->pNext;
23376 vfsList->pNext = pVfs;
static void vfsUnlink(sqlite3_vfs *pVfs)
Definition sqlite3.c:23331

References mutex, MUTEX_LOGIC, sqlite3_vfs::pNext, sqlite3_initialize(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3MutexAlloc(), SQLITE_MISUSE_BKPT, SQLITE_MUTEX_STATIC_MAIN, SQLITE_OK, vfsList, and vfsUnlink().

Referenced by sqlite3_os_init().

◆ sqlite3_vfs_unregister()

SQLITE_API int sqlite3_vfs_unregister ( sqlite3_vfs * pVfs)

Definition at line 23381 of file sqlite3.c.

23386 {
23388#ifndef SQLITE_OMIT_AUTOINIT
23389 int rc = sqlite3_initialize();
23390 if( rc ) return rc;
23391#endif

◆ sqlite3_vmprintf()

SQLITE_API char * sqlite3_vmprintf ( const char * zFormat,
va_list ap )

Definition at line 29299 of file sqlite3.c.

29305 {
29306 char *z;
29307 char zBase[SQLITE_PRINT_BUF_SIZE];
29308 StrAccum acc;
29309
29310#ifdef SQLITE_ENABLE_API_ARMOR
29311 if( zFormat==0 ){
29312 (void)SQLITE_MISUSE_BKPT;
29313 return 0;
29314 }
29315#endif
29316#ifndef SQLITE_OMIT_AUTOINIT
29317 if( sqlite3_initialize() ) return 0;

◆ sqlite3_vsnprintf()

SQLITE_API char * sqlite3_vsnprintf ( int n,
char * zBuf,
const char * zFormat,
va_list ap )

Definition at line 29348 of file sqlite3.c.

29354 {
29355 StrAccum acc;
29356 if( n<=0 ) return zBuf;
29357#ifdef SQLITE_ENABLE_API_ARMOR
29358 if( zBuf==0 || zFormat==0 ) {
29359 (void)SQLITE_MISUSE_BKPT;
29360 if( zBuf ) zBuf[0] = 0;
29361 return zBuf;
29362 }

References SQLITE_MISUSE_BKPT.

◆ sqlite3_vtab_collation()

SQLITE_API const char * sqlite3_vtab_collation ( sqlite3_index_info * pIdxInfo,
int iCons )

Definition at line 148920 of file sqlite3.c.

148926 {
148927 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
148928 const char *zRet = 0;
148929 if( iCons>=0 && iCons<pIdxInfo->nConstraint ){
148930 CollSeq *pC = 0;
148931 int iTerm = pIdxInfo->aConstraint[iCons].iTermOffset;
148932 Expr *pX = pHidden->pWC->a[iTerm].pExpr;
148933 if( pX->pLeft ){

References WhereClause::a, sqlite3_index_info::aConstraint, sqlite3_index_info::sqlite3_index_constraint::iTermOffset, WhereTerm::pExpr, Expr::pLeft, HiddenIndexInfo::pParse, HiddenIndexInfo::pWC, sqlite3ExprCompareCollSeq(), sqlite3StrBINARY, and CollSeq::zName.

◆ sqlite3_vtab_config()

SQLITE_API int sqlite3_vtab_config ( sqlite3 * db,
int op,
... )

Definition at line 140848 of file sqlite3.c.

140854 {
140855 va_list ap;
140856 int rc = SQLITE_OK;
140857 VtabCtx *p;
140858
140859#ifdef SQLITE_ENABLE_API_ARMOR
140860 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
140861#endif
140863 p = db->pVtabCtx;
140864 if( !p ){
140865 rc = SQLITE_MISUSE_BKPT;
140866 }else{
140867 assert( p->pTab==0 || IsVirtual(p->pTab) );
140868 va_start(ap, op);
140869 switch( op ){
140871 p->pVTable->bConstraint = (u8)va_arg(ap, int);
140872 break;
140873 }
140874 case SQLITE_VTAB_INNOCUOUS: {
140876 break;
140877 }
140878 case SQLITE_VTAB_DIRECTONLY: {
140880 break;
140881 }
140882 default: {
140883 rc = SQLITE_MISUSE_BKPT;
140884 break;
140885 }
140886 }
140887 va_end(ap);
#define SQLITE_VTABRISK_Low
Definition sqlite3.c:17479
#define SQLITE_VTAB_INNOCUOUS
Definition sqlite3.c:10224
#define SQLITE_VTAB_DIRECTONLY
Definition sqlite3.c:10225
#define SQLITE_VTAB_CONSTRAINT_SUPPORT
Definition sqlite3.c:10223
#define SQLITE_VTABRISK_High
Definition sqlite3.c:17481
u8 bConstraint
Definition sqlite3.c:17471

References VTable::bConstraint, VTable::eVtabRisk, IsVirtual, sqlite3::mutex, VtabCtx::pTab, sqlite3::pVtabCtx, VtabCtx::pVTable, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3Error(), sqlite3SafetyCheckOk(), SQLITE_MISUSE_BKPT, SQLITE_OK, SQLITE_VTAB_CONSTRAINT_SUPPORT, SQLITE_VTAB_DIRECTONLY, SQLITE_VTAB_INNOCUOUS, SQLITE_VTABRISK_High, and SQLITE_VTABRISK_Low.

◆ sqlite3_vtab_nochange()

SQLITE_API int sqlite3_vtab_nochange ( sqlite3_context * p)

Definition at line 83813 of file sqlite3.c.

References sqlite3_context::pOut, and sqlite3_value_nochange().

◆ sqlite3_vtab_on_conflict()

SQLITE_API int sqlite3_vtab_on_conflict ( sqlite3 * db)

Definition at line 140830 of file sqlite3.c.

140836 {
140837 static const unsigned char aMap[] = {
140839 };
140840#ifdef SQLITE_ENABLE_API_ARMOR
140841 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
#define SQLITE_IGNORE
Definition sqlite3.c:4098
#define SQLITE_FAIL
Definition sqlite3.c:10287
#define SQLITE_ROLLBACK
Definition sqlite3.c:10285
#define SQLITE_REPLACE
Definition sqlite3.c:10289

References OE_Abort, OE_Fail, OE_Ignore, OE_Replace, OE_Rollback, sqlite3SafetyCheckOk(), SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_MISUSE_BKPT, SQLITE_REPLACE, SQLITE_ROLLBACK, and sqlite3::vtabOnConflict.

◆ sqlite3_wal_autocheckpoint()

SQLITE_API int sqlite3_wal_autocheckpoint ( sqlite3 * db,
int N )

Definition at line 163281 of file sqlite3.c.

163287 {
163288#ifdef SQLITE_OMIT_WAL
163289 UNUSED_PARAMETER(db);
163290 UNUSED_PARAMETER(nFrame);
163291#else
163292#ifdef SQLITE_ENABLE_API_ARMOR
163293 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
163294#endif
163295 if( nFrame>0 ){
SQLITE_PRIVATE int sqlite3WalDefaultHook(void *, sqlite3 *, const char *, int)
Definition sqlite3.c:163255
SQLITE_API void * sqlite3_wal_hook(sqlite3 *, int(*)(void *, sqlite3 *, const char *, int), void *)
Definition sqlite3.c:163302

References sqlite3_wal_hook(), sqlite3SafetyCheckOk(), sqlite3WalDefaultHook(), SQLITE_INT_TO_PTR, SQLITE_MISUSE_BKPT, SQLITE_OK, and UNUSED_PARAMETER.

Referenced by openDatabase(), and sqlite3Pragma().

◆ sqlite3_wal_checkpoint()

SQLITE_API int sqlite3_wal_checkpoint ( sqlite3 * db,
const char * zDb )

Definition at line 163391 of file sqlite3.c.

References sqlite3_wal_checkpoint_v2(), and SQLITE_CHECKPOINT_PASSIVE.

Referenced by sqlite3WalDefaultHook().

◆ sqlite3_wal_checkpoint_v2()

SQLITE_API int sqlite3_wal_checkpoint_v2 ( sqlite3 * db,
const char * zDb,
int eMode,
int * pnLog,
int * pnCkpt )

Definition at line 163329 of file sqlite3.c.

163341 {
163342#ifdef SQLITE_OMIT_WAL
163343 return SQLITE_OK;
163344#else
163345 int rc; /* Return code */
163346 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
163347
163348#ifdef SQLITE_ENABLE_API_ARMOR
163349 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
163350#endif
163351
163352 /* Initialize the output variables to -1 in case an error occurs. */
163353 if( pnLog ) *pnLog = -1;
163354 if( pnCkpt ) *pnCkpt = -1;
163355
163356 assert( SQLITE_CHECKPOINT_PASSIVE==0 );
163357 assert( SQLITE_CHECKPOINT_FULL==1 );
163358 assert( SQLITE_CHECKPOINT_RESTART==2 );
163359 assert( SQLITE_CHECKPOINT_TRUNCATE==3 );
163360 if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){
163361 /* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
163362 ** mode: */
163363 return SQLITE_MISUSE;
163364 }
163365
163367 if( zDb && zDb[0] ){
163368 iDb = sqlite3FindDbName(db, zDb);
163369 }
163370 if( iDb<0 ){
163371 rc = SQLITE_ERROR;
163372 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb);
163373 }else{
163374 db->busyHandler.nBusy = 0;
163375 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
163376 sqlite3Error(db, rc);
163377 }
163378 rc = sqlite3ApiExit(db, rc);
163379
163380 /* If there are no active statements, clear the interrupt flag at this
163381 ** point. */
163382 if( db->nVdbeActive==0 ){
163383 AtomicStore(&db->u1.isInterrupted, 0);
SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *, int, int, int *, int *)
Definition sqlite3.c:163418
#define SQLITE_CHECKPOINT_TRUNCATE
Definition sqlite3.c:10139
#define SQLITE_CHECKPOINT_FULL
Definition sqlite3.c:10137
#define SQLITE_CHECKPOINT_RESTART
Definition sqlite3.c:10138
#define SQLITE_CHECKPOINT_PASSIVE
Definition sqlite3.c:10136
volatile int isInterrupted
Definition sqlite3.c:16903
union sqlite3::@105 u1

Referenced by sqlite3_wal_checkpoint().

◆ sqlite3_wal_hook()

SQLITE_API void * sqlite3_wal_hook ( sqlite3 * db,
int(*)(void *, sqlite3 *, const char *, int) xCallback,
void * pArg )

Definition at line 163302 of file sqlite3.c.

163312 {
163313#ifndef SQLITE_OMIT_WAL
163314 void *pRet;
163315#ifdef SQLITE_ENABLE_API_ARMOR
163316 if( !sqlite3SafetyCheckOk(db) ){
163317 (void)SQLITE_MISUSE_BKPT;
163318 return 0;
163319 }
163320#endif
163322 pRet = db->pWalArg;
163323 db->xWalCallback = xCallback;
163324 db->pWalArg = pArg;

Referenced by sqlite3_wal_autocheckpoint().

◆ sqlite3_win32_set_directory()

SQLITE_API int sqlite3_win32_set_directory ( unsigned long type,
void * zValue )

◆ sqlite3_win32_set_directory16()

SQLITE_API int sqlite3_win32_set_directory16 ( unsigned long type,
const void * zValue )

◆ sqlite3_win32_set_directory8()

SQLITE_API int sqlite3_win32_set_directory8 ( unsigned long type,
const char * zValue )

◆ sqlite3AbsInt32()

SQLITE_PRIVATE int sqlite3AbsInt32 ( int x)

Definition at line 32640 of file sqlite3.c.

Referenced by allocateBtreePage(), sqlite3InitOne(), and sqlite3Pragma().

◆ sqlite3AddCheckConstraint()

SQLITE_PRIVATE void sqlite3AddCheckConstraint ( Parse * pParse,
Expr * pCheckExpr )

Definition at line 112008 of file sqlite3.c.

112017 {
112018#ifndef SQLITE_OMIT_CHECK
112019 Table *pTab = pParse->pNewTable;
112020 sqlite3 *db = pParse->db;
112021 if( pTab && !IN_DECLARE_VTAB
112022 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
112023 ){
112024 pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr);
112025 if( pParse->constraintName.n ){
112026 sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1);
112027 }
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt)
Definition sqlite3.c:75021
#define IN_DECLARE_VTAB
Definition sqlite3.c:18800
Token constraintName
Definition sqlite3.c:18706

Referenced by yy_reduce().

◆ sqlite3AddCollateType()

SQLITE_PRIVATE void sqlite3AddCollateType ( Parse * pParse,
Token * pToken )

Definition at line 112033 of file sqlite3.c.

112039 {
112040 Table *p;
112041 int i;
112042 char *zColl; /* Dequoted name of collation sequence */
112043 sqlite3 *db;
112044
112045 if( (p = pParse->pNewTable)==0 ) return;
112046 i = p->nCol-1;
112047 db = pParse->db;
112048 zColl = sqlite3NameFromToken(db, pToken);
112049 if( !zColl ) return;
112050
112051 if( sqlite3LocateCollSeq(pParse, zColl) ){
112052 Index *pIdx;
112053 sqlite3DbFree(db, p->aCol[i].zColl);
112054 p->aCol[i].zColl = zColl;
112055
112056 /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
112057 ** then an index may have been created on this column before the
112058 ** collation type was added. Correct this if it is the case.
112059 */
112060 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
112061 assert( pIdx->nKeyCol==1 );
112062 if( pIdx->aiColumn[0]==i ){
112063 pIdx->azColl[0] = p->aCol[i].zColl;
SQLITE_PRIVATE char * sqlite3NameFromToken(sqlite3 *, Token *)
Definition sqlite3.c:111142

Referenced by yy_reduce().

◆ sqlite3AddColumn()

SQLITE_PRIVATE void sqlite3AddColumn ( Parse * pParse,
Token * pName,
Token * pType )

Definition at line 111640 of file sqlite3.c.

111646 {
111647 Table *p;
111648 int i;
111649 char *z;
111650 char *zType;
111651 Column *pCol;
111652 sqlite3 *db = pParse->db;
111653 if( (p = pParse->pNewTable)==0 ) return;
111654 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
111655 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
111656 return;
111657 }
111658 z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
111659 if( z==0 ) return;
111660 if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, pName);
111661 memcpy(z, pName->z, pName->n);
111662 z[pName->n] = 0;
111663 sqlite3Dequote(z);
111664 for(i=0; i<p->nCol; i++){
111665 if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){
111666 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
111667 sqlite3DbFree(db, z);
111668 return;
111669 }
111670 }
111671 if( (p->nCol & 0x7)==0 ){
111672 Column *aNew;
111673 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
111674 if( aNew==0 ){
111675 sqlite3DbFree(db, z);
111676 return;
111677 }
111678 p->aCol = aNew;
111679 }
111680 pCol = &p->aCol[p->nCol];
111681 memset(pCol, 0, sizeof(p->aCol[0]));
111682 pCol->zName = z;
111683 pCol->hName = sqlite3StrIHash(z);
111685
111686 if( pType->n==0 ){
111687 /* If there is no type specified, columns have the default affinity
111688 ** 'BLOB' with a default size of 4 bytes. */
111689 pCol->affinity = SQLITE_AFF_BLOB;
111690 pCol->szEst = 1;
111691#ifdef SQLITE_ENABLE_SORTER_REFERENCES
111692 if( 4>=sqlite3GlobalConfig.szSorterRef ){
111693 pCol->colFlags |= COLFLAG_SORTERREF;
111694 }
111695#endif
111696 }else{
111697 zType = z + sqlite3Strlen30(z) + 1;
111698 memcpy(zType, pType->z, pType->n);
111699 zType[pType->n] = 0;
111700 sqlite3Dequote(zType);
111701 pCol->affinity = sqlite3AffinityType(zType, pCol);
SQLITE_PRIVATE void * sqlite3RenameTokenMap(Parse *, void *, Token *)
Definition sqlite3.c:106507
SQLITE_PRIVATE void sqlite3Dequote(char *)
Definition sqlite3.c:31411
#define COLFLAG_SORTERREF
Definition sqlite3.c:17348
#define sqlite3ColumnPropertiesFromName(T, C)
Definition sqlite3.c:19540
u8 szEst
Definition sqlite3.c:17337

References Table::aCol, Column::affinity, sqlite3::aLimit, COLFLAG_HASTYPE, COLFLAG_SORTERREF, Column::colFlags, Parse::constraintName, Parse::db, Column::hName, IN_RENAME_OBJECT, Token::n, Table::nCol, Table::nNVCol, Parse::pNewTable, sqlite3_stricmp(), sqlite3AffinityType(), sqlite3ColumnPropertiesFromName, sqlite3DbFree(), sqlite3DbMallocRaw(), sqlite3DbRealloc(), sqlite3Dequote(), sqlite3ErrorMsg(), sqlite3GlobalConfig, sqlite3RenameTokenMap(), sqlite3StrIHash(), sqlite3Strlen30(), SQLITE_AFF_BLOB, SQLITE_LIMIT_COLUMN, Column::szEst, Token::z, Column::zName, and Table::zName.

Referenced by yy_reduce().

◆ sqlite3AddDefaultValue()

SQLITE_PRIVATE void sqlite3AddDefaultValue ( Parse * pParse,
Expr * pExpr,
const char * zStart,
const char * zEnd )

Definition at line 111833 of file sqlite3.c.

111844 {
111845 Table *p;
111846 Column *pCol;
111847 sqlite3 *db = pParse->db;
111848 p = pParse->pNewTable;
111849 if( p!=0 ){
111850 int isInit = db->init.busy && db->init.iDb!=1;
111851 pCol = &(p->aCol[p->nCol-1]);
111852 if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){
111853 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
111854 pCol->zName);
111855#ifndef SQLITE_OMIT_GENERATED_COLUMNS
111856 }else if( pCol->colFlags & COLFLAG_GENERATED ){
111857 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
111858 testcase( pCol->colFlags & COLFLAG_STORED );
111859 sqlite3ErrorMsg(pParse, "cannot use DEFAULT on a generated column");
111860#endif
111861 }else{
111862 /* A copy of pExpr is used instead of the original, as pExpr contains
111863 ** tokens that point to volatile memory.
111864 */
111865 Expr x;
111866 sqlite3ExprDelete(db, pCol->pDflt);
111867 memset(&x, 0, sizeof(x));
111868 x.op = TK_SPAN;
111869 x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd);
111870 x.pLeft = pExpr;
111871 x.flags = EP_Skip;
111872 pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
111873 sqlite3DbFree(db, x.u.zToken);
111874 }
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *, u8)
Definition sqlite3.c:101914
SQLITE_PRIVATE char * sqlite3DbSpanDup(sqlite3 *, const char *, const char *)
Definition sqlite3.c:28049

References Table::aCol, sqlite3::sqlite3InitInfo::busy, COLFLAG_GENERATED, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, EP_Skip, EXPRDUP_REDUCE, Expr::flags, sqlite3::sqlite3InitInfo::iDb, IN_RENAME_OBJECT, sqlite3::init, Table::nCol, Expr::op, Column::pDflt, Expr::pLeft, Parse::pNewTable, sqlite3DbFree(), sqlite3DbSpanDup(), sqlite3ErrorMsg(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprIsConstantOrFunction(), sqlite3RenameExprUnmap(), testcase, TK_SPAN, Expr::u, Column::zName, and Expr::zToken.

Referenced by yy_reduce().

◆ sqlite3AddGenerated()

SQLITE_PRIVATE void sqlite3AddGenerated ( Parse * pParse,
Expr * pExpr,
Token * pType )

Definition at line 112068 of file sqlite3.c.

112074 {
112075#ifndef SQLITE_OMIT_GENERATED_COLUMNS
112077 Table *pTab = pParse->pNewTable;
112078 Column *pCol;
112079 if( pTab==0 ){
112080 /* generated column in an CREATE TABLE IF NOT EXISTS that already exists */
112081 goto generated_done;
112082 }
112083 pCol = &(pTab->aCol[pTab->nCol-1]);
112084 if( IN_DECLARE_VTAB ){
112085 sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
112086 goto generated_done;
112087 }
112088 if( pCol->pDflt ) goto generated_error;
112089 if( pType ){
112090 if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
112091 /* no-op */
112092 }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
112094 }else{
112095 goto generated_error;
112096 }
112097 }
112098 if( eType==COLFLAG_VIRTUAL ) pTab->nNVCol--;
112099 pCol->colFlags |= eType;
112100 assert( TF_HasVirtual==COLFLAG_VIRTUAL );
112101 assert( TF_HasStored==COLFLAG_STORED );
112102 pTab->tabFlags |= eType;
112103 if( pCol->colFlags & COLFLAG_PRIMKEY ){
112104 makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
112105 }
112106 pCol->pDflt = pExpr;
112107 pExpr = 0;
112108 goto generated_done;
112109
112110generated_error:
112111 sqlite3ErrorMsg(pParse, "error in generated column \"%s\"",
112112 pCol->zName);
112113generated_done:
112114 sqlite3ExprDelete(pParse->db, pExpr);
112115#else
#define TF_HasStored
Definition sqlite3.c:17541
static void makeColumnPartOfPrimaryKey(Parse *pParse, Column *pCol)
Definition sqlite3.c:111903
#define TF_HasVirtual
Definition sqlite3.c:17540
i16 nNVCol
Definition sqlite3.c:17501

Referenced by yy_reduce().

◆ sqlite3AddInt64()

SQLITE_PRIVATE int sqlite3AddInt64 ( i64 * pA,
i64 iB )

Definition at line 32579 of file sqlite3.c.

32585 {
32586#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
32587 return __builtin_add_overflow(*pA, iB, pA);
32588#else
32589 i64 iA = *pA;
32590 testcase( iA==0 ); testcase( iA==1 );
32591 testcase( iB==-1 ); testcase( iB==0 );
32592 if( iB>=0 ){
32593 testcase( iA>0 && LARGEST_INT64 - iA == iB );
32594 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
32595 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
32596 }else{
32597 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
32598 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );

References LARGEST_INT64, and testcase.

Referenced by sqlite3VdbeExec(), and sumStep().

◆ sqlite3AddNotNull()

SQLITE_PRIVATE void sqlite3AddNotNull ( Parse * pParse,
int onError )

Definition at line 111709 of file sqlite3.c.

111715 {
111716 Table *p;
111717 Column *pCol;
111718 p = pParse->pNewTable;
111719 if( p==0 || NEVER(p->nCol<1) ) return;
111720 pCol = &p->aCol[p->nCol-1];
111721 pCol->notNull = (u8)onError;
111722 p->tabFlags |= TF_HasNotNull;
111723
111724 /* Set the uniqNotNull flag on any UNIQUE or PK indexes already created
111725 ** on this column. */
111726 if( pCol->colFlags & COLFLAG_UNIQUE ){
111727 Index *pIdx;
111728 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
111729 assert( pIdx->nKeyCol==1 && pIdx->onError!=OE_None );
#define COLFLAG_UNIQUE
Definition sqlite3.c:17347
u8 onError
Definition sqlite3.c:17792

References Table::aCol, Index::aiColumn, COLFLAG_UNIQUE, Column::colFlags, Table::nCol, NEVER, Index::nKeyCol, Column::notNull, OE_None, Index::onError, Table::pIndex, Parse::pNewTable, Index::pNext, Table::tabFlags, TF_HasNotNull, and Index::uniqNotNull.

Referenced by yy_reduce().

◆ sqlite3AddPrimaryKey()

SQLITE_PRIVATE void sqlite3AddPrimaryKey ( Parse * pParse,
ExprList * pList,
int onError,
int autoInc,
int sortOrder )

Definition at line 111933 of file sqlite3.c.

111945 {
111946 Table *pTab = pParse->pNewTable;
111947 Column *pCol = 0;
111948 int iCol = -1, i;
111949 int nTerm;
111950 if( pTab==0 ) goto primary_key_exit;
111951 if( pTab->tabFlags & TF_HasPrimaryKey ){
111952 sqlite3ErrorMsg(pParse,
111953 "table \"%s\" has more than one primary key", pTab->zName);
111954 goto primary_key_exit;
111955 }
111956 pTab->tabFlags |= TF_HasPrimaryKey;
111957 if( pList==0 ){
111958 iCol = pTab->nCol - 1;
111959 pCol = &pTab->aCol[iCol];
111960 makeColumnPartOfPrimaryKey(pParse, pCol);
111961 nTerm = 1;
111962 }else{
111963 nTerm = pList->nExpr;
111964 for(i=0; i<nTerm; i++){
111965 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
111966 assert( pCExpr!=0 );
111967 sqlite3StringToId(pCExpr);
111968 if( pCExpr->op==TK_ID ){
111969 const char *zCName = pCExpr->u.zToken;
111970 for(iCol=0; iCol<pTab->nCol; iCol++){
111971 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
111972 pCol = &pTab->aCol[iCol];
111973 makeColumnPartOfPrimaryKey(pParse, pCol);
111974 break;
111975 }
111976 }
111977 }
111978 }
111979 }
111980 if( nTerm==1
111981 && pCol
111982 && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
111983 && sortOrder!=SQLITE_SO_DESC
111984 ){
111985 if( IN_RENAME_OBJECT && pList ){
111986 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
111987 sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
111988 }
111989 pTab->iPKey = iCol;
111990 pTab->keyConf = (u8)onError;
111991 assert( autoInc==0 || autoInc==1 );
111992 pTab->tabFlags |= autoInc*TF_Autoincrement;
111993 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
111994 (void)sqlite3HasExplicitNulls(pParse, pList);
111995 }else if( autoInc ){
111996#ifndef SQLITE_OMIT_AUTOINCREMENT
111997 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
111998 "INTEGER PRIMARY KEY");
111999#endif
112000 }else{
112001 sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
112002 0, sortOrder, 0, SQLITE_IDXTYPE_PRIMARYKEY);
112003 pList = 0;
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *, ExprList *)
Definition sqlite3.c:113841
#define TF_HasPrimaryKey
Definition sqlite3.c:17537
static void sqlite3StringToId(Expr *p)
Definition sqlite3.c:111892
#define SQLITE_SO_DESC
Definition sqlite3.c:17377

References ExprList::a, Table::aCol, Parse::db, IN_RENAME_OBJECT, Table::iPKey, Parse::iPkSortOrder, Table::keyConf, makeColumnPartOfPrimaryKey(), Table::nCol, ExprList::nExpr, Expr::op, ExprList::ExprList_item::pExpr, Parse::pNewTable, ExprList::ExprList_item::sortFlags, sqlite3ColumnType(), sqlite3CreateIndex(), sqlite3ErrorMsg(), sqlite3ExprListDelete(), sqlite3ExprSkipCollate(), sqlite3HasExplicitNulls(), sqlite3RenameTokenRemap(), sqlite3StrICmp(), sqlite3StringToId(), SQLITE_IDXTYPE_PRIMARYKEY, SQLITE_SO_DESC, Table::tabFlags, TF_Autoincrement, TF_HasPrimaryKey, TK_ID, Expr::u, Column::zName, Table::zName, and Expr::zToken.

Referenced by yy_reduce().

◆ sqlite3AffinityType()

SQLITE_PRIVATE char sqlite3AffinityType ( const char * zIn,
Column * pCol )

Definition at line 111756 of file sqlite3.c.

111762 {
111763 u32 h = 0;
111764 char aff = SQLITE_AFF_NUMERIC;
111765 const char *zChar = 0;
111766
111767 assert( zIn!=0 );
111768 while( zIn[0] ){
111769 h = (h<<8) + sqlite3UpperToLower[(*zIn)&0xff];
111770 zIn++;
111771 if( h==(('c'<<24)+('h'<<16)+('a'<<8)+'r') ){ /* CHAR */
111772 aff = SQLITE_AFF_TEXT;
111773 zChar = zIn;
111774 }else if( h==(('c'<<24)+('l'<<16)+('o'<<8)+'b') ){ /* CLOB */
111775 aff = SQLITE_AFF_TEXT;
111776 }else if( h==(('t'<<24)+('e'<<16)+('x'<<8)+'t') ){ /* TEXT */
111777 aff = SQLITE_AFF_TEXT;
111778 }else if( h==(('b'<<24)+('l'<<16)+('o'<<8)+'b') /* BLOB */
111779 && (aff==SQLITE_AFF_NUMERIC || aff==SQLITE_AFF_REAL) ){
111780 aff = SQLITE_AFF_BLOB;
111781 if( zIn[0]=='(' ) zChar = zIn;
111782#ifndef SQLITE_OMIT_FLOATING_POINT
111783 }else if( h==(('r'<<24)+('e'<<16)+('a'<<8)+'l') /* REAL */
111784 && aff==SQLITE_AFF_NUMERIC ){
111785 aff = SQLITE_AFF_REAL;
111786 }else if( h==(('f'<<24)+('l'<<16)+('o'<<8)+'a') /* FLOA */
111787 && aff==SQLITE_AFF_NUMERIC ){
111788 aff = SQLITE_AFF_REAL;
111789 }else if( h==(('d'<<24)+('o'<<16)+('u'<<8)+'b') /* DOUB */
111790 && aff==SQLITE_AFF_NUMERIC ){
111791 aff = SQLITE_AFF_REAL;
111792#endif
111793 }else if( (h&0x00FFFFFF)==(('i'<<16)+('n'<<8)+'t') ){ /* INT */
111794 aff = SQLITE_AFF_INTEGER;
111795 break;
111796 }
111797 }
111798
111799 /* If pCol is not NULL, store an estimate of the field size. The
111800 ** estimate is scaled so that the size of an integer is 1. */
111801 if( pCol ){
111802 int v = 0; /* default size is approx 4 bytes */
111803 if( aff<SQLITE_AFF_NUMERIC ){
111804 if( zChar ){
111805 while( zChar[0] ){
111806 if( sqlite3Isdigit(zChar[0]) ){
111807 /* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */
111808 sqlite3GetInt32(zChar, &v);
111809 break;
111810 }
111811 zChar++;
111812 }
111813 }else{
111814 v = 16; /* BLOB, TEXT, CLOB -> r=5 (approx 20 bytes)*/
111815 }
111816 }
111817#ifdef SQLITE_ENABLE_SORTER_REFERENCES
111818 if( v>=sqlite3GlobalConfig.szSorterRef ){
111819 pCol->colFlags |= COLFLAG_SORTERREF;
111820 }
111821#endif
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int *)
Definition sqlite3.c:31981

References COLFLAG_SORTERREF, Column::colFlags, sqlite3GetInt32(), sqlite3GlobalConfig, sqlite3Isdigit, sqlite3UpperToLower, SQLITE_AFF_BLOB, SQLITE_AFF_INTEGER, SQLITE_AFF_NUMERIC, SQLITE_AFF_REAL, SQLITE_AFF_TEXT, and Column::szEst.

Referenced by createTableStmt(), sqlite3AddColumn(), sqlite3ExprAffinity(), sqlite3ExprCodeTarget(), and valueFromExpr().

◆ sqlite3AggInfoPersistWalkerInit()

SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit ( Walker * pWalker,
Parse * pParse )

Definition at line 105496 of file sqlite3.c.

Referenced by flattenSubquery(), and sqlite3WindowRewrite().

◆ sqlite3AllocateIndexObject()

SQLITE_PRIVATE Index * sqlite3AllocateIndexObject ( sqlite3 * db,
i16 nCol,
int nExtra,
char ** ppExtra )

Definition at line 113808 of file sqlite3.c.

113819 {
113820 Index *p; /* Allocated index object */
113821 int nByte; /* Bytes of space for Index object + arrays */
113822
113823 nByte = ROUND8(sizeof(Index)) + /* Index structure */
113824 ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
113825 ROUND8(sizeof(LogEst)*(nCol+1) + /* Index.aiRowLogEst */
113826 sizeof(i16)*nCol + /* Index.aiColumn */
113827 sizeof(u8)*nCol); /* Index.aSortOrder */
113828 p = sqlite3DbMallocZero(db, nByte + nExtra);
113829 if( p ){
113830 char *pExtra = ((char*)p)+ROUND8(sizeof(Index));
113831 p->azColl = (const char**)pExtra; pExtra += ROUND8(sizeof(char*)*nCol);
113832 p->aiRowLogEst = (LogEst*)pExtra; pExtra += sizeof(LogEst)*(nCol+1);
113833 p->aiColumn = (i16*)pExtra; pExtra += sizeof(i16)*nCol;
113834 p->aSortOrder = (u8*)pExtra;
INT16_TYPE LogEst
Definition sqlite3.c:14380

References Index::aiColumn, Index::aiRowLogEst, Index::aSortOrder, Index::azColl, Index::nColumn, Index::nKeyCol, ROUND8, and sqlite3DbMallocZero().

Referenced by constructAutomaticIndex(), and sqlite3CreateIndex().

◆ sqlite3AlterBeginAddColumn()

SQLITE_PRIVATE void sqlite3AlterBeginAddColumn ( Parse * pParse,
SrcList * pSrc )

Definition at line 106223 of file sqlite3.c.

106229 {
106230 Table *pNew;
106231 Table *pTab;
106232 int iDb;
106233 int i;
106234 int nAlloc;
106235 sqlite3 *db = pParse->db;
106236
106237 /* Look up the table being altered. */
106238 assert( pParse->pNewTable==0 );
106239 assert( sqlite3BtreeHoldsAllMutexes(db) );
106240 if( db->mallocFailed ) goto exit_begin_add_column;
106241 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
106242 if( !pTab ) goto exit_begin_add_column;
106243
106244#ifndef SQLITE_OMIT_VIRTUALTABLE
106245 if( IsVirtual(pTab) ){
106246 sqlite3ErrorMsg(pParse, "virtual tables may not be altered");
106247 goto exit_begin_add_column;
106248 }
106249#endif
106250
106251 /* Make sure this is not an attempt to ALTER a view. */
106252 if( pTab->pSelect ){
106253 sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
106254 goto exit_begin_add_column;
106255 }
106256 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
106257 goto exit_begin_add_column;
106258 }
106259
106260 sqlite3MayAbort(pParse);
106261 assert( pTab->addColOffset>0 );
106262 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
106263
106264 /* Put a copy of the Table struct in Parse.pNewTable for the
106265 ** sqlite3AddColumn() function and friends to modify. But modify
106266 ** the name by adding an "sqlite_altertab_" prefix. By adding this
106267 ** prefix, we insure that the name will not collide with an existing
106268 ** table because user table are not allowed to have the "sqlite_"
106269 ** prefix on their name.
106270 */
106271 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
106272 if( !pNew ) goto exit_begin_add_column;
106273 pParse->pNewTable = pNew;
106274 pNew->nTabRef = 1;
106275 pNew->nCol = pTab->nCol;
106276 assert( pNew->nCol>0 );
106277 nAlloc = (((pNew->nCol-1)/8)*8)+8;
106278 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
106279 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
106280 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
106281 if( !pNew->aCol || !pNew->zName ){
106282 assert( db->mallocFailed );
106283 goto exit_begin_add_column;
106284 }
106285 memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
106286 for(i=0; i<pNew->nCol; i++){
106287 Column *pCol = &pNew->aCol[i];
106288 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
106289 pCol->hName = sqlite3StrIHash(pCol->zName);
106290 pCol->zColl = 0;
106291 pCol->pDflt = 0;
106292 }
106293 pNew->pSchema = db->aDb[iDb].pSchema;
106294 pNew->addColOffset = pTab->addColOffset;
static int isAlterableTable(Parse *pParse, Table *pTab)
Definition sqlite3.c:105824
int addColOffset
Definition sqlite3.c:17509

References SrcList::a, Table::aCol, sqlite3::aDb, Table::addColOffset, Parse::db, Column::hName, isAlterableTable(), IsVirtual, sqlite3::mallocFailed, Table::nCol, Table::nTabRef, Column::pDflt, Parse::pNewTable, Db::pSchema, Table::pSchema, Table::pSelect, sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ErrorMsg(), sqlite3LocateTableItem(), sqlite3MayAbort(), sqlite3MPrintf(), sqlite3SchemaToIndex(), sqlite3SrcListDelete(), sqlite3StrIHash(), SQLITE_OK, Column::zColl, Column::zName, and Table::zName.

Referenced by yy_reduce().

◆ sqlite3AlterFinishAddColumn()

SQLITE_PRIVATE void sqlite3AlterFinishAddColumn ( Parse * pParse,
Token * pColDef )

Definition at line 106078 of file sqlite3.c.

106084 {
106085 Table *pNew; /* Copy of pParse->pNewTable */
106086 Table *pTab; /* Table being altered */
106087 int iDb; /* Database number */
106088 const char *zDb; /* Database name */
106089 const char *zTab; /* Table name */
106090 char *zCol; /* Null-terminated column definition */
106091 Column *pCol; /* The new column */
106092 Expr *pDflt; /* Default value for the new column */
106093 sqlite3 *db; /* The database connection; */
106094 Vdbe *v; /* The prepared statement under construction */
106095 int r1; /* Temporary registers */
106096
106097 db = pParse->db;
106098 if( pParse->nErr || db->mallocFailed ) return;
106099 pNew = pParse->pNewTable;
106100 assert( pNew );
106101
106102 assert( sqlite3BtreeHoldsAllMutexes(db) );
106103 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
106104 zDb = db->aDb[iDb].zDbSName;
106105 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
106106 pCol = &pNew->aCol[pNew->nCol-1];
106107 pDflt = pCol->pDflt;
106108 pTab = sqlite3FindTable(db, zTab, zDb);
106109 assert( pTab );
106110
106111#ifndef SQLITE_OMIT_AUTHORIZATION
106112 /* Invoke the authorization callback. */
106113 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
106114 return;
106115 }
106116#endif
106117
106118
106119 /* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
106120 ** If there is a NOT NULL constraint, then the default value for the
106121 ** column must not be NULL.
106122 */
106123 if( pCol->colFlags & COLFLAG_PRIMKEY ){
106124 sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
106125 return;
106126 }
106127 if( pNew->pIndex ){
106128 sqlite3ErrorMsg(pParse,
106129 "Cannot add a UNIQUE column");
106130 return;
106131 }
106132 if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
106133 /* If the default value for the new column was specified with a
106134 ** literal NULL, then set pDflt to 0. This simplifies checking
106135 ** for an SQL NULL default below.
106136 */
106137 assert( pDflt==0 || pDflt->op==TK_SPAN );
106138 if( pDflt && pDflt->pLeft->op==TK_NULL ){
106139 pDflt = 0;
106140 }
106141 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
106142 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
106143 "Cannot add a REFERENCES column with non-NULL default value");
106144 }
106145 if( pCol->notNull && !pDflt ){
106146 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
106147 "Cannot add a NOT NULL column with default value NULL");
106148 }
106149
106150
106151 /* Ensure the default expression is something that sqlite3ValueFromExpr()
106152 ** can handle (i.e. not CURRENT_TIME etc.)
106153 */
106154 if( pDflt ){
106155 sqlite3_value *pVal = 0;
106156 int rc;
106157 rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal);
106158 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
106159 if( rc!=SQLITE_OK ){
106160 assert( db->mallocFailed == 1 );
106161 return;
106162 }
106163 if( !pVal ){
106164 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
106165 "Cannot add a column with non-constant default");
106166 }
106167 sqlite3ValueFree(pVal);
106168 }
106169 }else if( pCol->colFlags & COLFLAG_STORED ){
106170 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "cannot add a STORED column");
106171 }
106172
106173
106174 /* Modify the CREATE TABLE statement. */
106175 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
106176 if( zCol ){
106177 char *zEnd = &zCol[pColDef->n-1];
106178 u32 savedDbFlags = db->mDbFlags;
106179 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
106180 *zEnd-- = '\0';
106181 }
106183 sqlite3NestedParse(pParse,
106184 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
106185 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
106186 "WHERE type = 'table' AND name = %Q",
106187 zDb, pNew->addColOffset, zCol, pNew->addColOffset+1,
106188 zTab
106189 );
106190 sqlite3DbFree(db, zCol);
106191 db->mDbFlags = savedDbFlags;
106192 }
106193
106194 /* Make sure the schema version is at least 3. But do not upgrade
106195 ** from less than 3 to 4, as that will corrupt any preexisting DESC
106196 ** index.
106197 */
106198 v = sqlite3GetVdbe(pParse);
106199 if( v ){
106200 r1 = sqlite3GetTempReg(pParse);
106202 sqlite3VdbeUsesBtree(v, iDb);
106203 sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2);
106205 VdbeCoverage(v);
#define OP_SetCookie
Definition sqlite3.c:15660
SQLITE_PRIVATE char * sqlite3DbStrNDup(sqlite3 *, const char *, u64)
Definition sqlite3.c:28031
#define SQLITE_ALTER_TABLE
Definition sqlite3.c:4145
#define OP_AddImm
Definition sqlite3.c:15648
#define OP_ReadCookie
Definition sqlite3.c:15659
#define BTREE_FILE_FORMAT
Definition sqlite3.c:15143
static void sqlite3ErrorIfNotEmpty(Parse *pParse, const char *zDb, const char *zTab, const char *zErr)
Definition sqlite3.c:106058
#define OP_IfPos
Definition sqlite3.c:15614
#define DBFLAG_PreferBuiltin
Definition sqlite3.c:17029

References Table::aCol, sqlite3::aDb, Table::addColOffset, BTREE_FILE_FORMAT, COLFLAG_GENERATED, COLFLAG_PRIMKEY, COLFLAG_STORED, Column::colFlags, Parse::db, DBFLAG_PreferBuiltin, DFLT_SCHEMA_TABLE, sqlite3::flags, sqlite3::mallocFailed, sqlite3::mDbFlags, Token::n, Table::nCol, Parse::nErr, Column::notNull, Expr::op, OP_AddImm, OP_IfPos, OP_ReadCookie, OP_SetCookie, Column::pDflt, Table::pFKey, Table::pIndex, Expr::pLeft, Parse::pNewTable, Table::pSchema, renameReloadSchema(), sqlite3AuthCheck(), sqlite3DbFree(), sqlite3DbStrNDup(), sqlite3ErrorIfNotEmpty(), sqlite3ErrorMsg(), sqlite3FindTable(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3Isspace, sqlite3NestedParse(), sqlite3ReleaseTempReg(), sqlite3SchemaToIndex(), sqlite3ValueFree(), sqlite3ValueFromExpr(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeCurrentAddr(), sqlite3VdbeUsesBtree(), SQLITE_AFF_BLOB, SQLITE_ALTER_TABLE, SQLITE_ForeignKeys, SQLITE_NOMEM, SQLITE_OK, SQLITE_UTF8, TK_NULL, TK_SPAN, VdbeCoverage, Token::z, Db::zDbSName, and Table::zName.

Referenced by yy_reduce().

◆ sqlite3AlterFunctions()

SQLITE_PRIVATE void sqlite3AlterFunctions ( void )

Definition at line 107532 of file sqlite3.c.

107538 {
107539 static FuncDef aAlterTableFuncs[] = {

Referenced by sqlite3RegisterBuiltinFunctions().

◆ sqlite3AlterRenameColumn()

SQLITE_PRIVATE void sqlite3AlterRenameColumn ( Parse * pParse,
SrcList * pSrc,
Token * pOld,
Token * pNew )

Definition at line 106334 of file sqlite3.c.

106345 {
106346 sqlite3 *db = pParse->db; /* Database connection */
106347 Table *pTab; /* Table being updated */
106348 int iCol; /* Index of column being renamed */
106349 char *zOld = 0; /* Old column name */
106350 char *zNew = 0; /* New column name */
106351 const char *zDb; /* Name of schema containing the table */
106352 int iSchema; /* Index of the schema */
106353 int bQuote; /* True to quote the new name */
106354
106355 /* Locate the table to be altered */
106356 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
106357 if( !pTab ) goto exit_rename_column;
106358
106359 /* Cannot alter a system table */
106360 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ) goto exit_rename_column;
106361 if( SQLITE_OK!=isRealTable(pParse, pTab) ) goto exit_rename_column;
106362
106363 /* Which schema holds the table to be altered */
106364 iSchema = sqlite3SchemaToIndex(db, pTab->pSchema);
106365 assert( iSchema>=0 );
106366 zDb = db->aDb[iSchema].zDbSName;
106367
106368#ifndef SQLITE_OMIT_AUTHORIZATION
106369 /* Invoke the authorization callback. */
106370 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
106371 goto exit_rename_column;
106372 }
106373#endif
106374
106375 /* Make sure the old name really is a column name in the table to be
106376 ** altered. Set iCol to be the index of the column being renamed */
106377 zOld = sqlite3NameFromToken(db, pOld);
106378 if( !zOld ) goto exit_rename_column;
106379 for(iCol=0; iCol<pTab->nCol; iCol++){
106380 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break;
106381 }
106382 if( iCol==pTab->nCol ){
106383 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
106384 goto exit_rename_column;
106385 }
106386
106387 /* Do the rename operation using a recursive UPDATE statement that
106388 ** uses the sqlite_rename_column() SQL function to compute the new
106389 ** CREATE statement text for the sqlite_schema table.
106390 */
106391 sqlite3MayAbort(pParse);
106392 zNew = sqlite3NameFromToken(db, pNew);
106393 if( !zNew ) goto exit_rename_column;
106394 assert( pNew->n>0 );
106395 bQuote = sqlite3Isquote(pNew->z[0]);
106396 sqlite3NestedParse(pParse,
106397 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
106398 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
106399 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
106400 " AND (type != 'index' OR tbl_name = %Q)"
106401 " AND sql NOT LIKE 'create virtual%%'",
106402 zDb,
106403 zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
106404 pTab->zName
106405 );
106406
106407 sqlite3NestedParse(pParse,
106408 "UPDATE temp." DFLT_SCHEMA_TABLE " SET "
106409 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) "
106410 "WHERE type IN ('trigger', 'view')",
106411 zDb, pTab->zName, iCol, zNew, bQuote
106412 );
106413
106414 /* Drop and reload the database schema. */
106415 renameReloadSchema(pParse, iSchema);
106416 renameTestSchema(pParse, zDb, iSchema==1);
106417
static void renameReloadSchema(Parse *pParse, int iDb)
Definition sqlite3.c:105872
static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp)
Definition sqlite3.c:105845
#define sqlite3Isquote(x)
Definition sqlite3.c:19325
static int isRealTable(Parse *pParse, Table *pTab)
Definition sqlite3.c:106305

References SrcList::a, Table::aCol, sqlite3::aDb, Parse::db, DFLT_SCHEMA_TABLE, isAlterableTable(), isRealTable(), Token::n, Table::nCol, Table::pSchema, renameReloadSchema(), renameTestSchema(), sqlite3AuthCheck(), sqlite3DbFree(), sqlite3ErrorMsg(), sqlite3Isquote, sqlite3LocateTableItem(), sqlite3MayAbort(), sqlite3NameFromToken(), sqlite3NestedParse(), sqlite3SchemaToIndex(), sqlite3SrcListDelete(), sqlite3StrICmp(), SQLITE_ALTER_TABLE, SQLITE_OK, Token::z, Db::zDbSName, Column::zName, and Table::zName.

Referenced by yy_reduce().

◆ sqlite3AlterRenameTable()

SQLITE_PRIVATE void sqlite3AlterRenameTable ( Parse * pParse,
SrcList * pSrc,
Token * pName )

Definition at line 105885 of file sqlite3.c.

105895 {
105896 int iDb; /* Database that contains the table */
105897 char *zDb; /* Name of database iDb */
105898 Table *pTab; /* Table being renamed */
105899 char *zName = 0; /* NULL-terminated version of pName */
105900 sqlite3 *db = pParse->db; /* Database connection */
105901 int nTabName; /* Number of UTF-8 characters in zTabName */
105902 const char *zTabName; /* Original name of the table */
105903 Vdbe *v;
105904 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
105905 u32 savedDbFlags; /* Saved value of db->mDbFlags */
105906
105907 savedDbFlags = db->mDbFlags;
105908 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
105909 assert( pSrc->nSrc==1 );
105910 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
105911
105912 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
105913 if( !pTab ) goto exit_rename_table;
105914 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
105915 zDb = db->aDb[iDb].zDbSName;
105917
105918 /* Get a NULL terminated version of the new table name. */
105919 zName = sqlite3NameFromToken(db, pName);
105920 if( !zName ) goto exit_rename_table;
105921
105922 /* Check that a table or index named 'zName' does not already exist
105923 ** in database iDb. If so, this is an error.
105924 */
105925 if( sqlite3FindTable(db, zName, zDb)
105926 || sqlite3FindIndex(db, zName, zDb)
105927 || sqlite3IsShadowTableOf(db, pTab, zName)
105928 ){
105929 sqlite3ErrorMsg(pParse,
105930 "there is already another table or index with this name: %s", zName);
105931 goto exit_rename_table;
105932 }
105933
105934 /* Make sure it is not a system table being altered, or a reserved name
105935 ** that the table is being renamed to.
105936 */
105937 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
105938 goto exit_rename_table;
105939 }
105940 if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){
105941 goto exit_rename_table;
105942 }
105943
105944#ifndef SQLITE_OMIT_VIEW
105945 if( pTab->pSelect ){
105946 sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
105947 goto exit_rename_table;
105948 }
105949#endif
105950
105951#ifndef SQLITE_OMIT_AUTHORIZATION
105952 /* Invoke the authorization callback. */
105953 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
105954 goto exit_rename_table;
105955 }
105956#endif
105957
105958#ifndef SQLITE_OMIT_VIRTUALTABLE
105959 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
105960 goto exit_rename_table;
105961 }
105962 if( IsVirtual(pTab) ){
105963 pVTab = sqlite3GetVTable(db, pTab);
105964 if( pVTab->pVtab->pModule->xRename==0 ){
105965 pVTab = 0;
105966 }
105967 }
105968#endif
105969
105970 /* Begin a transaction for database iDb. Then modify the schema cookie
105971 ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
105972 ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
105973 ** nested SQL may raise an exception. */
105974 v = sqlite3GetVdbe(pParse);
105975 if( v==0 ){
105976 goto exit_rename_table;
105977 }
105978 sqlite3MayAbort(pParse);
105979
105980 /* figure out how many UTF-8 characters are in zName */
105981 zTabName = pTab->zName;
105982 nTabName = sqlite3Utf8CharLen(zTabName, -1);
105983
105984 /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
105985 ** the schema to use the new table name. */
105986 sqlite3NestedParse(pParse,
105987 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
105988 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
105989 "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
105990 "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105991 , zDb, zDb, zTabName, zName, (iDb==1), zTabName
105992 );
105993
105994 /* Update the tbl_name and name columns of the sqlite_schema table
105995 ** as required. */
105996 sqlite3NestedParse(pParse,
105997 "UPDATE %Q." DFLT_SCHEMA_TABLE " SET "
105998 "tbl_name = %Q, "
105999 "name = CASE "
106000 "WHEN type='table' THEN %Q "
106001 "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' "
106002 " AND type='index' THEN "
106003 "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
106004 "ELSE name END "
106005 "WHERE tbl_name=%Q COLLATE nocase AND "
106006 "(type='table' OR type='index' OR type='trigger');",
106007 zDb,
106008 zName, zName, zName,
106009 nTabName, zTabName
106010 );
106011
106012#ifndef SQLITE_OMIT_AUTOINCREMENT
106013 /* If the sqlite_sequence table exists in this database, then update
106014 ** it with the new table name.
106015 */
106016 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
106017 sqlite3NestedParse(pParse,
106018 "UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q",
106019 zDb, zName, pTab->zName);
106020 }
106021#endif
106022
106023 /* If the table being renamed is not itself part of the temp database,
106024 ** edit view and trigger definitions within the temp database
106025 ** as required. */
106026 if( iDb!=1 ){
106027 sqlite3NestedParse(pParse,
106028 "UPDATE sqlite_temp_schema SET "
106029 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
106030 "tbl_name = "
106031 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
106032 " sqlite_rename_test(%Q, sql, type, name, 1) "
106033 "THEN %Q ELSE tbl_name END "
106034 "WHERE type IN ('view', 'trigger')"
106035 , zDb, zTabName, zName, zTabName, zDb, zName);
106036 }
106037
106038 /* If this is a virtual table, invoke the xRename() function if
106039 ** one is defined. The xRename() callback will modify the names
106040 ** of any resources used by the v-table implementation (including other
106041 ** SQLite tables) that are identified by the name of the virtual table.
106042 */
106043#ifndef SQLITE_OMIT_VIRTUALTABLE
106044 if( pVTab ){
106045 int i = ++pParse->nMem;
106047 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
106048 }
106049#endif
106050
106051 renameReloadSchema(pParse, iDb);
106052 renameTestSchema(pParse, zDb, iDb==1);
SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *, const char *, const char *)
Definition sqlite3.c:111272
#define OP_VRename
Definition sqlite3.c:15733
SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3 *, Table *, const char *)
Definition sqlite3.c:112575
int(* xRename)(sqlite3_vtab *pVtab, const char *zNew)
Definition sqlite3.c:7785

Referenced by yy_reduce().

◆ sqlite3AnalysisLoad()

SQLITE_PRIVATE int sqlite3AnalysisLoad ( sqlite3 * db,
int iDB )

Definition at line 109418 of file sqlite3.c.

109424 {
109425 analysisInfo sInfo;
109426 HashElem *i;
109427 char *zSql;
109428 int rc = SQLITE_OK;
109429 Schema *pSchema = db->aDb[iDb].pSchema;
109430
109431 assert( iDb>=0 && iDb<db->nDb );
109432 assert( db->aDb[iDb].pBt!=0 );
109433
109434 /* Clear any prior statistics */
109435 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
109436 for(i=sqliteHashFirst(&pSchema->tblHash); i; i=sqliteHashNext(i)){
109437 Table *pTab = sqliteHashData(i);
109438 pTab->tabFlags &= ~TF_HasStat1;
109439 }
109440 for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
109441 Index *pIdx = sqliteHashData(i);
109442 pIdx->hasStat1 = 0;
109443#ifdef SQLITE_ENABLE_STAT4
109444 sqlite3DeleteIndexSamples(db, pIdx);
109445 pIdx->aSample = 0;
109446#endif
109447 }
109448
109449 /* Load new statistics out of the sqlite_stat1 table */
109450 sInfo.db = db;
109451 sInfo.zDatabase = db->aDb[iDb].zDbSName;
109452 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
109453 zSql = sqlite3MPrintf(db,
109454 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
109455 if( zSql==0 ){
109456 rc = SQLITE_NOMEM_BKPT;
109457 }else{
109458 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
109459 sqlite3DbFree(db, zSql);
109460 }
109461 }
109462
109463 /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
109464 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
109465 for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
109466 Index *pIdx = sqliteHashData(i);
109467 if( !pIdx->hasStat1 ) sqlite3DefaultRowEst(pIdx);
109468 }
109469
109470 /* Load the statistics from the sqlite_stat4 table. */
109471#ifdef SQLITE_ENABLE_STAT4
109472 if( rc==SQLITE_OK ){
109474 rc = loadStat4(db, sInfo.zDatabase);
109476 }
109477 for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
109478 Index *pIdx = sqliteHashData(i);
109479 sqlite3_free(pIdx->aiRowEst);
109480 pIdx->aiRowEst = 0;
109481 }
109482#endif
SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *)
Definition sqlite3.c:114462
SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *, Index *)
Definition sqlite3.c:109154
static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed)
Definition sqlite3.c:109091

References sqlite3::aDb, analysisLoader(), analysisInfo::db, DisableLookaside, EnableLookaside, Index::hasStat1, Schema::idxHash, Db::pBt, Db::pSchema, sqlite3_exec(), sqlite3_free(), sqlite3DbFree(), sqlite3DefaultRowEst(), sqlite3DeleteIndexSamples(), sqlite3FindTable(), sqlite3MPrintf(), sqlite3OomFault(), SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, sqliteHashData, sqliteHashFirst, sqliteHashNext, Table::tabFlags, Schema::tblHash, analysisInfo::zDatabase, and Db::zDbSName.

Referenced by sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3Analyze()

SQLITE_PRIVATE void sqlite3Analyze ( Parse * pParse,
Token * pName1,
Token * pName2 )

Definition at line 108955 of file sqlite3.c.

108961 {
108962 sqlite3 *db = pParse->db;
108963 int iDb;
108964 int i;
108965 char *z, *zDb;
108966 Table *pTab;
108967 Index *pIdx;
108968 Token *pTableName;
108969 Vdbe *v;
108970
108971 /* Read the database schema. If an error occurs, leave an error message
108972 ** and code in pParse and return NULL. */
108973 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
108974 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
108975 return;
108976 }
108977
108978 assert( pName2!=0 || pName1==0 );
108979 if( pName1==0 ){
108980 /* Form 1: Analyze everything */
108981 for(i=0; i<db->nDb; i++){
108982 if( i==1 ) continue; /* Do not analyze the TEMP database */
108983 analyzeDatabase(pParse, i);
108984 }
108985 }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){
108986 /* Analyze the schema named as the argument */
108987 analyzeDatabase(pParse, iDb);
108988 }else{
108989 /* Form 3: Analyze the table or index named as an argument */
108990 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
108991 if( iDb>=0 ){
108992 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
108993 z = sqlite3NameFromToken(db, pTableName);
108994 if( z ){
108995 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
108996 analyzeTable(pParse, pIdx->pTable, pIdx);
108997 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
108998 analyzeTable(pParse, pTab, 0);
108999 }
109000 sqlite3DbFree(db, z);
109001 }
static void analyzeDatabase(Parse *pParse, int iDb)
Definition sqlite3.c:108897
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **)
Definition sqlite3.c:111217
static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx)
Definition sqlite3.c:108924
SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *, Token *)
Definition sqlite3.c:111192
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse)
Definition sqlite3.c:128781

References sqlite3::aDb, analyzeDatabase(), analyzeTable(), Parse::db, Token::n, sqlite3::nDb, sqlite3::nSqlExec, OP_Expire, Index::pTable, sqlite3DbFree(), sqlite3FindDb(), sqlite3FindIndex(), sqlite3GetVdbe(), sqlite3LocateTable(), sqlite3NameFromToken(), sqlite3ReadSchema(), sqlite3TwoPartName(), sqlite3VdbeAddOp0(), SQLITE_OK, and Db::zDbSName.

Referenced by yy_reduce().

◆ sqlite3ApiExit()

SQLITE_PRIVATE int sqlite3ApiExit ( sqlite3 * db,
int rc )

Definition at line 28121 of file sqlite3.c.

28126 {
28127 /* If the db handle must hold the connection handle mutex here.
28128 ** Otherwise the read (and possible write) of db->mallocFailed
28129 ** is unsafe, as is the call to sqlite3Error().
28130 */
28131 assert( db!=0 );
28132 assert( sqlite3_mutex_held(db->mutex) );

References apiOomError(), sqlite3::errMask, sqlite3::mallocFailed, sqlite3::mutex, sqlite3_mutex_held(), and SQLITE_IOERR_NOMEM.

Referenced by columnMallocFailure(), createFunctionApi(), createModule(), sqlite3_blob_reopen(), sqlite3_declare_vtab(), sqlite3_exec(), sqlite3_finalize(), sqlite3_reset(), sqlite3_step(), sqlite3_table_column_metadata(), sqlite3Prepare16(), and sqlite3Step().

◆ sqlite3ArrayAllocate()

SQLITE_PRIVATE void * sqlite3ArrayAllocate ( sqlite3 * db,
void * pArray,
int szEntry,
int * pnEntry,
int * pIdx )

Definition at line 114587 of file sqlite3.c.

114599 {
114600 char *z;
114601 sqlite3_int64 n = *pIdx = *pnEntry;
114602 if( (n & (n-1))==0 ){
114603 sqlite3_int64 sz = (n==0) ? 1 : 2*n;
114604 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
114605 if( pNew==0 ){
114606 *pIdx = -1;
114607 return pArray;
114608 }
114609 pArray = pNew;

References sqlite3DbRealloc().

Referenced by sqlite3IdListAppend().

◆ sqlite3AtoF()

SQLITE_PRIVATE int sqlite3AtoF ( const char * z,
double * pResult,
int length,
u8 enc )

Definition at line 31584 of file sqlite3.c.

31588 : 4756)
31589#endif
31590SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
31591#ifndef SQLITE_OMIT_FLOATING_POINT
31592 int incr;
31593 const char *zEnd;
31594 /* sign * significand * (10 ^ (esign * exponent)) */
31595 int sign = 1; /* sign of significand */
31596 i64 s = 0; /* significand */
31597 int d = 0; /* adjust exponent for shifting decimal point */
31598 int esign = 1; /* sign of exponent */
31599 int e = 0; /* exponent */
31600 int eValid = 1; /* True exponent is either not used or is well-formed */
31601 double result;
31602 int nDigit = 0; /* Number of digits processed */
31603 int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
31604
31605 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
31606 *pResult = 0.0; /* Default return value, in case of an error */
31607 if( length==0 ) return 0;
31608
31609 if( enc==SQLITE_UTF8 ){
31610 incr = 1;
31611 zEnd = z + length;
31612 }else{
31613 int i;
31614 incr = 2;
31615 length &= ~1;
31616 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
31617 testcase( enc==SQLITE_UTF16LE );
31618 testcase( enc==SQLITE_UTF16BE );
31619 for(i=3-enc; i<length && z[i]==0; i+=2){}
31620 if( i<length ) eType = -100;
31621 zEnd = &z[i^1];
31622 z += (enc&1);
31623 }
31624
31625 /* skip leading spaces */
31626 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
31627 if( z>=zEnd ) return 0;
31628
31629 /* get sign of significand */
31630 if( *z=='-' ){
31631 sign = -1;
31632 z+=incr;
31633 }else if( *z=='+' ){
31634 z+=incr;
31635 }
31636
31637 /* copy max significant digits to significand */
31638 while( z<zEnd && sqlite3Isdigit(*z) ){
31639 s = s*10 + (*z - '0');
31640 z+=incr; nDigit++;
31641 if( s>=((LARGEST_INT64-9)/10) ){
31642 /* skip non-significant significand digits
31643 ** (increase exponent by d to shift decimal left) */
31644 while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; d++; }
31645 }
31646 }
31647 if( z>=zEnd ) goto do_atof_calc;
31648
31649 /* if decimal point is present */
31650 if( *z=='.' ){
31651 z+=incr;
31652 eType++;
31653 /* copy digits from after decimal to significand
31654 ** (decrease exponent by d to shift decimal right) */
31655 while( z<zEnd && sqlite3Isdigit(*z) ){
31656 if( s<((LARGEST_INT64-9)/10) ){
31657 s = s*10 + (*z - '0');
31658 d--;
31659 nDigit++;
31660 }
31661 z+=incr;
31662 }
31663 }
31664 if( z>=zEnd ) goto do_atof_calc;
31665
31666 /* if exponent is present */
31667 if( *z=='e' || *z=='E' ){
31668 z+=incr;
31669 eValid = 0;
31670 eType++;
31671
31672 /* This branch is needed to avoid a (harmless) buffer overread. The
31673 ** special comment alerts the mutation tester that the correct answer
31674 ** is obtained even if the branch is omitted */
31675 if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
31676
31677 /* get sign of exponent */
31678 if( *z=='-' ){
31679 esign = -1;
31680 z+=incr;
31681 }else if( *z=='+' ){
31682 z+=incr;
31683 }
31684 /* copy digits to exponent */
31685 while( z<zEnd && sqlite3Isdigit(*z) ){
31686 e = e<10000 ? (e*10 + (*z - '0')) : 10000;
31687 z+=incr;
31688 eValid = 1;
31689 }
31690 }
31691
31692 /* skip trailing spaces */
31693 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
31694
31695do_atof_calc:
31696 /* adjust exponent by d, and update sign */
31697 e = (e*esign) + d;
31698 if( e<0 ) {
31699 esign = -1;
31700 e *= -1;
31701 } else {
31702 esign = 1;
31703 }
31704
31705 if( s==0 ) {
31706 /* In the IEEE 754 standard, zero is signed. */
31707 result = sign<0 ? -(double)0 : (double)0;
31708 } else {
31709 /* Attempt to reduce exponent.
31710 **
31711 ** Branches that are not required for the correct answer but which only
31712 ** help to obtain the correct answer faster are marked with special
31713 ** comments, as a hint to the mutation tester.
31714 */
31715 while( e>0 ){ /*OPTIMIZATION-IF-TRUE*/
31716 if( esign>0 ){
31717 if( s>=(LARGEST_INT64/10) ) break; /*OPTIMIZATION-IF-FALSE*/
31718 s *= 10;
31719 }else{
31720 if( s%10!=0 ) break; /*OPTIMIZATION-IF-FALSE*/
31721 s /= 10;
31722 }
31723 e--;
31724 }
31725
31726 /* adjust the sign of significand */
31727 s = sign<0 ? -s : s;
31728
31729 if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
31730 result = (double)s;
31731 }else{
31732 /* attempt to handle extremely small/large numbers better */
31733 if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
31734 if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
31735 LONGDOUBLE_TYPE scale = sqlite3Pow10(e-308);
31736 if( esign<0 ){
31737 result = s / scale;
31738 result /= 1.0e+308;
31739 }else{
31740 result = s * scale;
31741 result *= 1.0e+308;
31742 }
31743 }else{ assert( e>=342 );
31744 if( esign<0 ){
31745 result = 0.0*s;
31746 }else{
31747#ifdef INFINITY
31748 result = INFINITY*s;
31749#else
31750 result = 1e308*1e308*s; /* Infinity */
31751#endif
31752 }
31753 }
31754 }else{
31755 LONGDOUBLE_TYPE scale = sqlite3Pow10(e);
31756 if( esign<0 ){
31757 result = s / scale;
31758 }else{
31759 result = s * scale;
31760 }
31761 }
31762 }
31763 }
31764
31765 /* store the result */
31766 *pResult = result;
31767
31768 /* return true if number and no extra non-whitespace chracters after */
31769 if( z==zEnd && nDigit>0 && eValid && eType>0 ){
31770 return eType;
31771 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
31772 return -1;
31773 }else{
static LONGDOUBLE_TYPE sqlite3Pow10(int E)
Definition sqlite3.c:31519
#define SQLITE_PRIVATE
Definition sqlite3.c:23

References eType, LARGEST_INT64, LONGDOUBLE_TYPE, s, sqlite3Atoi64(), sqlite3Isdigit, sqlite3Isspace, sqlite3Pow10(), SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, and testcase.

Referenced by applyNumericAffinity(), codeReal(), computeNumericType(), exprProbability(), isLikeOrGlob(), parseDateOrTime(), parseModifier(), quoteFunc(), sqlite3VdbeMemNumerify(), and sqlite3VdbeRealValue().

◆ sqlite3Atoi()

SQLITE_PRIVATE int sqlite3Atoi ( const char * z)

Definition at line 32040 of file sqlite3.c.

Referenced by decodeIntArray(), getAutoVacuum(), getSafetyLevel(), and sqlite3Pragma().

◆ sqlite3Atoi64()

SQLITE_PRIVATE int sqlite3Atoi64 ( const char * zNum,
i64 * pNum,
int length,
u8 enc )

Definition at line 31849 of file sqlite3.c.

31855 {
31856 int incr;
31857 u64 u = 0;
31858 int neg = 0; /* assume positive */
31859 int i;
31860 int c = 0;
31861 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
31862 int rc; /* Baseline return code */
31863 const char *zStart;
31864 const char *zEnd = zNum + length;
31865 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
31866 if( enc==SQLITE_UTF8 ){
31867 incr = 1;
31868 }else{
31869 incr = 2;
31870 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
31871 for(i=3-enc; i<length && zNum[i]==0; i+=2){}
31872 nonNum = i<length;
31873 zEnd = &zNum[i^1];
31874 zNum += (enc&1);
31875 }
31876 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
31877 if( zNum<zEnd ){
31878 if( *zNum=='-' ){
31879 neg = 1;
31880 zNum+=incr;
31881 }else if( *zNum=='+' ){
31882 zNum+=incr;
31883 }
31884 }
31885 zStart = zNum;
31886 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
31887 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
31888 u = u*10 + c - '0';
31889 }
31890 testcase( i==18*incr );
31891 testcase( i==19*incr );
31892 testcase( i==20*incr );
31893 if( u>LARGEST_INT64 ){
31894 /* This test and assignment is needed only to suppress UB warnings
31895 ** from clang and -fsanitize=undefined. This test and assignment make
31896 ** the code a little larger and slower, and no harm comes from omitting
31897 ** them, but we must appaise the undefined-behavior pharisees. */
31898 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
31899 }else if( neg ){
31900 *pNum = -(i64)u;
31901 }else{
31902 *pNum = (i64)u;
31903 }
31904 rc = 0;
31905 if( i==0 && zStart==zNum ){ /* No digits */
31906 rc = -1;
31907 }else if( nonNum ){ /* UTF16 with high-order bytes non-zero */
31908 rc = 1;
31909 }else if( &zNum[i]<zEnd ){ /* Extra bytes at the end */
31910 int jj = i;
31911 do{
31912 if( !sqlite3Isspace(zNum[jj]) ){
31913 rc = 1; /* Extra non-space text after the integer */
31914 break;
31915 }
31916 jj += incr;
31917 }while( &zNum[jj]<zEnd );
31918 }
31919 if( i<19*incr ){
31920 /* Less than 19 digits, so we know that it fits in 64 bits */
31921 assert( u<=LARGEST_INT64 );
31922 return rc;
31923 }else{
31924 /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
31925 c = i>19*incr ? 1 : compare2pow63(zNum, incr);
31926 if( c<0 ){
31927 /* zNum is less than 9223372036854775808 so it fits */
31928 assert( u<=LARGEST_INT64 );
31929 return rc;
31930 }else{
31931 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
31932 if( c>0 ){
31933 /* zNum is greater than 9223372036854775808 so it overflows */
31934 return 2;
31935 }else{
31936 /* zNum is exactly 9223372036854775808. Fits if negative. The
31937 ** special case 2 overflow if positive */
static int compare2pow63(const char *zNum, int incr)
Definition sqlite3.c:31816

References compare2pow63(), LARGEST_INT64, SMALLEST_INT64, sqlite3Isspace, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, and testcase.

Referenced by alsoAnInt(), computeNumericType(), sqlite3AtoF(), sqlite3DecOrHexToI64(), sqlite3ExprAssignVarNumber(), sqlite3VdbeIntValue(), and sqlite3VdbeMemNumerify().

◆ sqlite3Attach()

SQLITE_PRIVATE void sqlite3Attach ( Parse * pParse,
Expr * p,
Expr * pDbname,
Expr * pKey )

Definition at line 109906 of file sqlite3.c.

109912 {
109913 static const FuncDef attach_func = {
109914 3, /* nArg */
109915 SQLITE_UTF8, /* funcFlags */
109916 0, /* pUserData */
109917 0, /* pNext */
109918 attachFunc, /* xSFunc */
109919 0, /* xFinalize */
static void attachFunc(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:109562

References attachFunc(), codeAttach(), SQLITE_ATTACH, and SQLITE_UTF8.

Referenced by yy_reduce().

◆ sqlite3AuthCheck()

SQLITE_PRIVATE int sqlite3AuthCheck ( Parse * pParse,
int code,
const char * zArg1,
const char * zArg2,
const char * zArg3 )

Definition at line 110310 of file sqlite3.c.

110322 {
110323 sqlite3 *db = pParse->db;
110324 int rc;
110325
110326 /* Don't do any authorization checks if the database is initialising
110327 ** or if the parser is being invoked from within sqlite3_declare_vtab.
110328 */
110329 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
110330 if( db->init.busy || IN_SPECIAL_PARSE ){
110331 return SQLITE_OK;
110332 }
110333
110334 if( db->xAuth==0 ){
110335 return SQLITE_OK;
110336 }
110337
110338 /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
110339 ** callback are either NULL pointers or zero-terminated strings that
110340 ** contain additional details about the action to be authorized.
110341 **
110342 ** The following testcase() macros show that any of the 3rd through 6th
110343 ** parameters can be either NULL or a string. */
110344 testcase( zArg1==0 );
110345 testcase( zArg2==0 );
110346 testcase( zArg3==0 );
110347 testcase( pParse->zAuthContext==0 );
110348
110349 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
110350#ifdef SQLITE_USER_AUTHENTICATION
110351 ,db->auth.zAuthUser
110352#endif
110353 );
110354 if( rc==SQLITE_DENY ){
110355 sqlite3ErrorMsg(pParse, "not authorized");
110356 pParse->rc = SQLITE_AUTH;
#define IN_SPECIAL_PARSE
Definition sqlite3.c:18812
#define SQLITE_AUTH
Definition sqlite3.c:1493
void * pAuthArg
Definition sqlite3.c:16909

References sqlite3::sqlite3InitInfo::busy, Parse::db, IN_RENAME_OBJECT, IN_SPECIAL_PARSE, sqlite3::init, sqlite3::pAuthArg, Parse::rc, sqlite3ErrorMsg(), SQLITE_AUTH, SQLITE_DENY, SQLITE_IGNORE, SQLITE_OK, sqliteAuthBadReturnCode(), testcase, sqlite3::xAuth, and Parse::zAuthContext.

Referenced by analyzeOneTable(), flattenSubquery(), generateWithRecursiveQuery(), resolveExprStep(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3BeginTrigger(), sqlite3CreateIndex(), sqlite3DeleteFrom(), sqlite3EndTransaction(), sqlite3Insert(), sqlite3Pragma(), sqlite3RefillIndex(), sqlite3Select(), sqlite3StartTable(), sqlite3Update(), and sqlite3VtabBeginParse().

◆ sqlite3AuthContextPop()

SQLITE_PRIVATE void sqlite3AuthContextPop ( AuthContext * pContext)

Definition at line 110378 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), and sqlite3Update().

◆ sqlite3AuthContextPush()

SQLITE_PRIVATE void sqlite3AuthContextPush ( Parse * pParse,
AuthContext * pContext,
const char * zContext )

◆ sqlite3AuthRead()

SQLITE_PRIVATE void sqlite3AuthRead ( Parse * pParse,
Expr * pExpr,
Schema * pSchema,
SrcList * pTabList )

Definition at line 110252 of file sqlite3.c.

110263 {
110264 sqlite3 *db = pParse->db;
110265 Table *pTab = 0; /* The table being read */
110266 const char *zCol; /* Name of the column of the table */
110267 int iSrc; /* Index in pTabList->a[] of table being read */
110268 int iDb; /* The index of the database the expression refers to */
110269 int iCol; /* Index of column in table */
110270
110271 assert( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER );
110272 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
110273 if( db->xAuth==0 ) return;
110274 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
110275 if( iDb<0 ){
110276 /* An attempt to read a column out of a subquery or other
110277 ** temporary table. */
110278 return;
110279 }
110280
110281 if( pExpr->op==TK_TRIGGER ){
110282 pTab = pParse->pTriggerTab;
110283 }else{
110284 assert( pTabList );
110285 for(iSrc=0; ALWAYS(iSrc<pTabList->nSrc); iSrc++){
110286 if( pExpr->iTable==pTabList->a[iSrc].iCursor ){
110287 pTab = pTabList->a[iSrc].pTab;
110288 break;
110289 }
110290 }
110291 }
110292 iCol = pExpr->iColumn;
110293 if( NEVER(pTab==0) ) return;
110294
110295 if( iCol>=0 ){
110296 assert( iCol<pTab->nCol );
110297 zCol = pTab->aCol[iCol].zName;
110298 }else if( pTab->iPKey>=0 ){
110299 assert( pTab->iPKey<pTab->nCol );
110300 zCol = pTab->aCol[pTab->iPKey].zName;
110301 }else{
110302 zCol = "ROWID";

References SrcList::a, Table::aCol, ALWAYS, Parse::db, Expr::iColumn, SrcList::SrcList_item::iCursor, IN_RENAME_OBJECT, Table::iPKey, Expr::iTable, Table::nCol, NEVER, Expr::op, SrcList::SrcList_item::pTab, Parse::pTriggerTab, sqlite3AuthReadCol(), sqlite3SchemaToIndex(), SQLITE_IGNORE, TK_COLUMN, TK_NULL, TK_TRIGGER, sqlite3::xAuth, Column::zName, and Table::zName.

Referenced by lookupName().

◆ sqlite3AuthReadCol()

SQLITE_PRIVATE int sqlite3AuthReadCol ( Parse * pParse,
const char * zTab,
const char * zCol,
int iDb )

Definition at line 110216 of file sqlite3.c.

110227 {
110228 sqlite3 *db = pParse->db; /* Database handle */
110229 char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
110230 int rc; /* Auth callback return code */
110231
110232 if( db->init.busy ) return SQLITE_OK;
110233 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
110234#ifdef SQLITE_USER_AUTHENTICATION
110235 ,db->auth.zAuthUser
110236#endif
110237 );
110238 if( rc==SQLITE_DENY ){
110239 char *z = sqlite3_mprintf("%s.%s", zTab, zCol);
110240 if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z);
110241 sqlite3ErrorMsg(pParse, "access to %z is prohibited", z);
#define SQLITE_READ
Definition sqlite3.c:4139

References sqlite3::aDb, sqlite3::sqlite3InitInfo::busy, Parse::db, sqlite3::init, sqlite3::nDb, sqlite3::pAuthArg, Parse::rc, sqlite3_mprintf(), sqlite3ErrorMsg(), SQLITE_AUTH, SQLITE_DENY, SQLITE_IGNORE, SQLITE_OK, SQLITE_READ, sqliteAuthBadReturnCode(), sqlite3::xAuth, Parse::zAuthContext, and Db::zDbSName.

Referenced by sqlite3AuthRead(), and sqlite3FkCheck().

◆ sqlite3AutoincrementBegin()

SQLITE_PRIVATE void sqlite3AutoincrementBegin ( Parse * pParse)

Definition at line 120937 of file sqlite3.c.

120943 {
120944 AutoincInfo *p; /* Information about an AUTOINCREMENT */
120945 sqlite3 *db = pParse->db; /* The database connection */
120946 Db *pDb; /* Database only autoinc table */
120947 int memId; /* Register holding max rowid */
120948 Vdbe *v = pParse->pVdbe; /* VDBE under construction */
120949
120950 /* This routine is never called during trigger-generation. It is
120951 ** only called from the top-level */
120952 assert( pParse->pTriggerTab==0 );
120953 assert( sqlite3IsToplevel(pParse) );
120954
120955 assert( v ); /* We failed long ago if this is not so */
120956 for(p = pParse->pAinc; p; p = p->pNext){
120957 static const int iLn = VDBE_OFFSET_LINENO(2);
120958 static const VdbeOpList autoInc[] = {
120959 /* 0 */ {OP_Null, 0, 0, 0},
120960 /* 1 */ {OP_Rewind, 0, 10, 0},
120961 /* 2 */ {OP_Column, 0, 0, 0},
120962 /* 3 */ {OP_Ne, 0, 9, 0},
120963 /* 4 */ {OP_Rowid, 0, 0, 0},
120964 /* 5 */ {OP_Column, 0, 1, 0},
120965 /* 6 */ {OP_AddImm, 0, 0, 0},
120966 /* 7 */ {OP_Copy, 0, 0, 0},
120967 /* 8 */ {OP_Goto, 0, 11, 0},
120968 /* 9 */ {OP_Next, 0, 2, 0},
120969 /* 10 */ {OP_Integer, 0, 0, 0},
120970 /* 11 */ {OP_Close, 0, 0, 0}
120971 };
120972 VdbeOp *aOp;
120973 pDb = &db->aDb[p->iDb];
120974 memId = p->regCtr;
120975 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
120976 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
120977 sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
120978 aOp = sqlite3VdbeAddOpList(v, ArraySize(autoInc), autoInc, iLn);
120979 if( aOp==0 ) break;
120980 aOp[0].p2 = memId;
120981 aOp[0].p3 = memId+2;
120982 aOp[2].p3 = memId;
120983 aOp[3].p1 = memId-1;
120984 aOp[3].p3 = memId;
120985 aOp[3].p5 = SQLITE_JUMPIFNULL;
120986 aOp[4].p2 = memId+1;
120987 aOp[5].p3 = memId;
120988 aOp[6].p1 = memId;
#define sqlite3IsToplevel(p)
Definition sqlite3.c:19788
u16 p5
Definition sqlite3.c:15437

Referenced by sqlite3FinishCoding().

◆ sqlite3AutoincrementEnd()

SQLITE_PRIVATE void sqlite3AutoincrementEnd ( Parse * pParse)

Definition at line 121048 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), sqlite3Insert(), sqlite3Update(), and xferOptimization().

◆ sqlite3AutoLoadExtensions()

SQLITE_PRIVATE void sqlite3AutoLoadExtensions ( sqlite3 * db)

Definition at line 125047 of file sqlite3.c.

125053 {
125054 u32 i;
125055 int go = 1;
125056 int rc;
125057 sqlite3_loadext_entry xInit;
125058
125060 if( wsdAutoext.nExt==0 ){
125061 /* Common case: early out without every having to acquire a mutex */
125062 return;
125063 }
125064 for(i=0; go; i++){
125065 char *zErrmsg;
125066#if SQLITE_THREADSAFE
125068#endif
125069#ifdef SQLITE_OMIT_LOAD_EXTENSION
125070 const sqlite3_api_routines *pThunk = 0;
125071#else
125072 const sqlite3_api_routines *pThunk = &sqlite3Apis;
125073#endif
125075 if( i>=wsdAutoext.nExt ){
125076 xInit = 0;
125077 go = 0;
125078 }else{
125079 xInit = (sqlite3_loadext_entry)wsdAutoext.aExt[i];
125080 }
125082 zErrmsg = 0;
125083 if( xInit && (rc = xInit(db, &zErrmsg, pThunk))!=0 ){
125084 sqlite3ErrorWithMsg(db, rc,
int(* sqlite3_loadext_entry)(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pThunk)
Definition sqlite3.c:123933
static const sqlite3_api_routines sqlite3Apis
Definition sqlite3.c:124365

References mutex, sqlite3_free(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3Apis, sqlite3ErrorWithMsg(), sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_MAIN, wsdAutoext, and wsdAutoextInit.

Referenced by openDatabase().

◆ sqlite3BackupRestart()

◆ sqlite3BackupUpdate()

SQLITE_PRIVATE void sqlite3BackupUpdate ( sqlite3_backup * pBackup,
Pgno iPage,
const u8 * aData )

Definition at line 75740 of file sqlite3.c.

75740 {
75741 p->rc = rc;
75742 }

References sqlite3_backup::rc.

Referenced by pager_playback_one_page(), pager_write_pagelist(), and pagerWalFrames().

◆ sqlite3BeginBenignMalloc()

◆ sqlite3BeginTransaction()

SQLITE_PRIVATE void sqlite3BeginTransaction ( Parse * pParse,
int type )

Definition at line 115022 of file sqlite3.c.

115028 {
115029 sqlite3 *db;
115030 Vdbe *v;
115031 int i;
115032
115033 assert( pParse!=0 );
115034 db = pParse->db;
115035 assert( db!=0 );
115036 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ){
115037 return;
115038 }
115039 v = sqlite3GetVdbe(pParse);
115040 if( !v ) return;
115041 if( type!=TK_DEFERRED ){
115042 for(i=0; i<db->nDb; i++){
#define TK_DEFERRED
Definition sqlite3.c:13949
#define SQLITE_TRANSACTION
Definition sqlite3.c:4141

Referenced by yy_reduce().

◆ sqlite3BeginTrigger()

SQLITE_PRIVATE void sqlite3BeginTrigger ( Parse * pParse,
Token * pName1,
Token * pName2,
int tr_tm,
int op,
IdList * pColumns,
SrcList * pTableName,
Expr * pWhen,
int isTemp,
int noErr )

Definition at line 136467 of file sqlite3.c.

136484 {
136485 Trigger *pTrigger = 0; /* The new trigger */
136486 Table *pTab; /* Table that the trigger fires off of */
136487 char *zName = 0; /* Name of the trigger */
136488 sqlite3 *db = pParse->db; /* The database connection */
136489 int iDb; /* The database to store the trigger in */
136490 Token *pName; /* The unqualified db name */
136491 DbFixer sFix; /* State vector for the DB fixer */
136492
136493 assert( pName1!=0 ); /* pName1->z might be NULL, but not pName1 itself */
136494 assert( pName2!=0 );
136495 assert( op==TK_INSERT || op==TK_UPDATE || op==TK_DELETE );
136496 assert( op>0 && op<0xff );
136497 if( isTemp ){
136498 /* If TEMP was specified, then the trigger name may not be qualified. */
136499 if( pName2->n>0 ){
136500 sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");
136501 goto trigger_cleanup;
136502 }
136503 iDb = 1;
136504 pName = pName1;
136505 }else{
136506 /* Figure out the db that the trigger will be created in */
136507 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
136508 if( iDb<0 ){
136509 goto trigger_cleanup;
136510 }
136511 }
136512 if( !pTableName || db->mallocFailed ){
136513 goto trigger_cleanup;
136514 }
136515
136516 /* A long-standing parser bug is that this syntax was allowed:
136517 **
136518 ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
136519 ** ^^^^^^^^
136520 **
136521 ** To maintain backwards compatibility, ignore the database
136522 ** name on pTableName if we are reparsing out of the schema table
136523 */
136524 if( db->init.busy && iDb!=1 ){
136525 sqlite3DbFree(db, pTableName->a[0].zDatabase);
136526 pTableName->a[0].zDatabase = 0;
136527 }
136528
136529 /* If the trigger name was unqualified, and the table is a temp table,
136530 ** then set iDb to 1 to create the trigger in the temporary database.
136531 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
136532 ** exist, the error is caught by the block below.
136533 */
136534 pTab = sqlite3SrcListLookup(pParse, pTableName);
136535 if( db->init.busy==0 && pName2->n==0 && pTab
136536 && pTab->pSchema==db->aDb[1].pSchema ){
136537 iDb = 1;
136538 }
136539
136540 /* Ensure the table name matches database name and that the table exists */
136541 if( db->mallocFailed ) goto trigger_cleanup;
136542 assert( pTableName->nSrc==1 );
136543 sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName);
136544 if( sqlite3FixSrcList(&sFix, pTableName) ){
136545 goto trigger_cleanup;
136546 }
136547 pTab = sqlite3SrcListLookup(pParse, pTableName);
136548 if( !pTab ){
136549 /* The table does not exist. */
136550 if( db->init.iDb==1 ){
136551 /* Ticket #3810.
136552 ** Normally, whenever a table is dropped, all associated triggers are
136553 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
136554 ** and the table is dropped by a different database connection, the
136555 ** trigger is not visible to the database connection that does the
136556 ** drop so the trigger cannot be dropped. This results in an
136557 ** "orphaned trigger" - a trigger whose associated table is missing.
136558 */
136559 db->init.orphanTrigger = 1;
136560 }
136561 goto trigger_cleanup;
136562 }
136563 if( IsVirtual(pTab) ){
136564 sqlite3ErrorMsg(pParse, "cannot create triggers on virtual tables");
136565 goto trigger_cleanup;
136566 }
136567
136568 /* Check that the trigger name is not reserved and that no trigger of the
136569 ** specified name exists */
136570 zName = sqlite3NameFromToken(db, pName);
136571 if( zName==0 ){
136572 assert( db->mallocFailed );
136573 goto trigger_cleanup;
136574 }
136575 if( sqlite3CheckObjectName(pParse, zName, "trigger", pTab->zName) ){
136576 goto trigger_cleanup;
136577 }
136578 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
136579 if( !IN_RENAME_OBJECT ){
136580 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
136581 if( !noErr ){
136582 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
136583 }else{
136584 assert( !db->init.busy );
136585 sqlite3CodeVerifySchema(pParse, iDb);
136586 }
136587 goto trigger_cleanup;
136588 }
136589 }
136590
136591 /* Do not create a trigger on a system table */
136592 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
136593 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
136594 goto trigger_cleanup;
136595 }
136596
136597 /* INSTEAD of triggers are only for views and views only support INSTEAD
136598 ** of triggers.
136599 */
136600 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
136601 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
136602 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
136603 goto trigger_cleanup;
136604 }
136605 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
136606 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
136607 " trigger on table: %S", pTableName, 0);
136608 goto trigger_cleanup;
136609 }
136610
136611#ifndef SQLITE_OMIT_AUTHORIZATION
136612 if( !IN_RENAME_OBJECT ){
136613 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
136614 int code = SQLITE_CREATE_TRIGGER;
136615 const char *zDb = db->aDb[iTabDb].zDbSName;
136616 const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
136617 if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
136618 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
136619 goto trigger_cleanup;
136620 }
136621 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
136622 goto trigger_cleanup;
136623 }
136624 }
136625#endif
136626
136627 /* INSTEAD OF triggers can only appear on views and BEFORE triggers
136628 ** cannot appear on views. So we might as well translate every
136629 ** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
136630 ** elsewhere.
136631 */
136632 if (tr_tm == TK_INSTEAD){
136633 tr_tm = TK_BEFORE;
136634 }
136635
136636 /* Build the Trigger object */
136637 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
136638 if( pTrigger==0 ) goto trigger_cleanup;
136639 pTrigger->zName = zName;
136640 zName = 0;
136641 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
136642 pTrigger->pSchema = db->aDb[iDb].pSchema;
136643 pTrigger->pTabSchema = pTab->pSchema;
136644 pTrigger->op = (u8)op;
136645 pTrigger->tr_tm = tr_tm==TK_BEFORE ? TRIGGER_BEFORE : TRIGGER_AFTER;
136646 if( IN_RENAME_OBJECT ){
136647 sqlite3RenameTokenRemap(pParse, pTrigger->table, pTableName->a[0].zName);
136648 pTrigger->pWhen = pWhen;
136649 pWhen = 0;
136650 }else{
136651 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
136652 }
136653 pTrigger->pColumns = pColumns;
136654 pColumns = 0;
136655 assert( pParse->pNewTrigger==0 );
136656 pParse->pNewTrigger = pTrigger;
136657
136658trigger_cleanup:
136659 sqlite3DbFree(db, zName);
136660 sqlite3SrcListDelete(db, pTableName);
136661 sqlite3IdListDelete(db, pColumns);
136662 sqlite3ExprDelete(db, pWhen);
#define SCHEMA_TABLE(x)
Definition sqlite3.c:14587
#define SQLITE_INSERT
Definition sqlite3.c:4137
SQLITE_PRIVATE Table * sqlite3SrcListLookup(Parse *, SrcList *)
Definition sqlite3.c:116106
#define SQLITE_CREATE_TRIGGER
Definition sqlite3.c:4126
#define SQLITE_CREATE_TEMP_TRIGGER
Definition sqlite3.c:4124
#define TK_BEFORE
Definition sqlite3.c:13975
#define TRIGGER_AFTER
Definition sqlite3.c:18893
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *, int)
Definition sqlite3.c:115126
SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer *, SrcList *)
Definition sqlite3.c:109959
#define TK_INSTEAD
Definition sqlite3.c:14007
SQLITE_PRIVATE void sqlite3FixInit(DbFixer *, Parse *, int, const char *, const Token *)
Definition sqlite3.c:109926

References SrcList::a, sqlite3::aDb, sqlite3::sqlite3InitInfo::busy, Parse::db, EXPRDUP_REDUCE, sqlite3::sqlite3InitInfo::iDb, IN_RENAME_OBJECT, sqlite3::init, IsVirtual, sqlite3::mallocFailed, Token::n, SrcList::nSrc, Trigger::op, sqlite3::sqlite3InitInfo::orphanTrigger, Trigger::pColumns, Parse::pNewTrigger, Db::pSchema, Table::pSchema, Trigger::pSchema, Table::pSelect, Trigger::pTabSchema, Trigger::pWhen, SCHEMA_TABLE, sqlite3AuthCheck(), sqlite3CheckObjectName(), sqlite3CodeVerifySchema(), sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3DeleteTrigger(), sqlite3ErrorMsg(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3FixInit(), sqlite3FixSrcList(), sqlite3HashFind(), sqlite3IdListDelete(), sqlite3NameFromToken(), sqlite3RenameTokenRemap(), sqlite3SchemaToIndex(), sqlite3SrcListDelete(), sqlite3SrcListLookup(), sqlite3StrNICmp, sqlite3TwoPartName(), SQLITE_CREATE_TEMP_TRIGGER, SQLITE_CREATE_TRIGGER, SQLITE_INSERT, Trigger::table, TK_BEFORE, TK_DELETE, TK_INSERT, TK_INSTEAD, TK_UPDATE, Trigger::tr_tm, TRIGGER_AFTER, TRIGGER_BEFORE, Schema::trigHash, SrcList::SrcList_item::zDatabase, Db::zDbSName, Table::zName, SrcList::SrcList_item::zName, Trigger::zName, and zName.

Referenced by yy_reduce().

◆ sqlite3BeginWriteOperation()

◆ sqlite3BenignMallocHooks()

SQLITE_PRIVATE void sqlite3BenignMallocHooks ( void(*)(void) xBenignBegin,
void(*)(void) xBenignEnd )

Definition at line 23455 of file sqlite3.c.

References wsdHooks, wsdHooksInit, and BenignMallocHooks::xBenignBegin.

◆ sqlite3BinaryCompareCollSeq()

SQLITE_PRIVATE CollSeq * sqlite3BinaryCompareCollSeq ( Parse * pParse,
const Expr * pLeft,
const Expr * pRight )

Definition at line 100041 of file sqlite3.c.

100051 {
100052 CollSeq *pColl;
100053 assert( pLeft );
100054 if( pLeft->flags & EP_Collate ){
100055 pColl = sqlite3ExprCollSeq(pParse, pLeft);
100056 }else if( pRight && (pRight->flags & EP_Collate)!=0 ){
100057 pColl = sqlite3ExprCollSeq(pParse, pRight);
100058 }else{
100059 pColl = sqlite3ExprCollSeq(pParse, pLeft);

References EP_Collate, Expr::flags, and sqlite3ExprCollSeq().

Referenced by sqlite3CodeRhsOfIN(), sqlite3ExprCompareCollSeq(), sqlite3FindInIndex(), and whereRangeVectorLen().

◆ sqlite3BitvecBuiltinTest()

SQLITE_PRIVATE int sqlite3BitvecBuiltinTest ( int sz,
int * aOp )

Definition at line 48796 of file sqlite3.c.

48802 {
48803 Bitvec *pBitvec = 0;
48804 unsigned char *pV = 0;
48805 int rc = -1;
48806 int i, nx, pc, op;
48807 void *pTmpSpace;
48808
48809 /* Allocate the Bitvec to be tested and a linear array of
48810 ** bits to act as the reference */
48811 pBitvec = sqlite3BitvecCreate( sz );
48812 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
48813 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
48814 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
48815
48816 /* NULL pBitvec tests */
48817 sqlite3BitvecSet(0, 1);
48818 sqlite3BitvecClear(0, 1, pTmpSpace);
48819
48820 /* Run the program */
48821 pc = 0;
48822 while( (op = aOp[pc])!=0 ){
48823 switch( op ){
48824 case 1:
48825 case 2:
48826 case 5: {
48827 nx = 4;
48828 i = aOp[pc+2] - 1;
48829 aOp[pc+2] += aOp[pc+3];
48830 break;
48831 }
48832 case 3:
48833 case 4:
48834 default: {
48835 nx = 2;
48836 sqlite3_randomness(sizeof(i), &i);
48837 break;
48838 }
48839 }
48840 if( (--aOp[pc+1]) > 0 ) nx = 0;
48841 pc += nx;
48842 i = (i & 0x7fffffff)%sz;
48843 if( (op & 1)!=0 ){
48844 SETBIT(pV, (i+1));
48845 if( op!=5 ){
48846 if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
48847 }
48848 }else{
48849 CLEARBIT(pV, (i+1));
48850 sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
48851 }
48852 }
48853
48854 /* Test to make sure the linear array exactly matches the
48855 ** Bitvec object. Start with the assumption that they do
48856 ** match (rc==0). Change rc to non-zero if a discrepancy
48857 ** is found.
48858 */
48859 rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
48860 + sqlite3BitvecTest(pBitvec, 0)
48861 + (sqlite3BitvecSize(pBitvec) - sz);
48862 for(i=1; i<=sz; i++){
48863 if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
48864 rc = i;
48865 break;
48866 }
48867 }
48868
48869 /* Free allocated structure */
#define CLEARBIT(V, I)
Definition sqlite3.c:48763
SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *)
Definition sqlite3.c:48751
SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec *, u32, void *)
Definition sqlite3.c:48699
#define SETBIT(V, I)
Definition sqlite3.c:48762
#define BITVEC_SZ
Definition sqlite3.c:48499
#define TESTBIT(V, I)
Definition sqlite3.c:48764

References BITVEC_SZ, CLEARBIT, SETBIT, sqlite3_free(), sqlite3_malloc64(), sqlite3_randomness(), sqlite3BitvecClear(), sqlite3BitvecCreate(), sqlite3BitvecDestroy(), sqlite3BitvecSet(), sqlite3BitvecSize(), sqlite3BitvecTest(), sqlite3MallocZero(), and TESTBIT.

◆ sqlite3BitvecClear()

SQLITE_PRIVATE void sqlite3BitvecClear ( Bitvec * p,
u32 i,
void * pBuf )

Definition at line 48699 of file sqlite3.c.

48705 {
48706 if( p==0 ) return;
48707 assert( i>0 );
48708 i--;
48709 while( p->iDivisor ){
48710 u32 bin = i/p->iDivisor;
48711 i = i%p->iDivisor;
48712 p = p->u.apSub[bin];
48713 if (!p) {
48714 return;
48715 }
48716 }
48717 if( p->iSize<=BITVEC_NBIT ){
48718 p->u.aBitmap[i/BITVEC_SZELEM] &= ~(1 << (i&(BITVEC_SZELEM-1)));
48719 }else{
48720 unsigned int j;
48721 u32 *aiValues = pBuf;
48722 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
48723 memset(p->u.aHash, 0, sizeof(p->u.aHash));
48724 p->nSet = 0;
48725 for(j=0; j<BITVEC_NINT; j++){
48726 if( aiValues[j] && aiValues[j]!=(i+1) ){
48727 u32 h = BITVEC_HASH(aiValues[j]-1);
48728 p->nSet++;
48729 while( p->u.aHash[h] ){
48730 h++;
48731 if( h>=BITVEC_NINT ) h = 0;
#define BITVEC_NINT
Definition sqlite3.c:48519
#define BITVEC_SZELEM
Definition sqlite3.c:48512
#define BITVEC_NBIT
Definition sqlite3.c:48516
#define BITVEC_HASH(X)
Definition sqlite3.c:48527
u32 iDivisor
Definition sqlite3.c:48558
u32 iSize
Definition sqlite3.c:48554
Bitvec * apSub[BITVEC_NPTR]
Definition sqlite3.c:48565
union Bitvec::@118 u
BITVEC_TELEM aBitmap[BITVEC_NELEM]
Definition sqlite3.c:48563
u32 nSet
Definition sqlite3.c:48555
u32 aHash[BITVEC_NINT]
Definition sqlite3.c:48564

References Bitvec::aBitmap, Bitvec::aHash, Bitvec::apSub, BITVEC_HASH, BITVEC_NBIT, BITVEC_NINT, BITVEC_SZELEM, Bitvec::iDivisor, Bitvec::iSize, Bitvec::nSet, and Bitvec::u.

Referenced by sqlite3BitvecBuiltinTest(), and sqlite3PagerMovepage().

◆ sqlite3BitvecCreate()

SQLITE_PRIVATE Bitvec * sqlite3BitvecCreate ( u32 iSize)

◆ sqlite3BitvecDestroy()

SQLITE_PRIVATE void sqlite3BitvecDestroy ( Bitvec * p)

Definition at line 48736 of file sqlite3.c.

48742 {
48743 if( p==0 ) return;
48744 if( p->iDivisor ){
48745 unsigned int i;

Referenced by pager_end_transaction(), pager_open_journal(), pager_unlock(), pagerPlaybackSavepoint(), releaseAllSavepoints(), sqlite3BitvecBuiltinTest(), and sqlite3PagerSavepoint().

◆ sqlite3BitvecSet()

SQLITE_PRIVATE int sqlite3BitvecSet ( Bitvec * p,
u32 i )

Definition at line 48628 of file sqlite3.c.

48634 {
48635 u32 h;
48636 if( p==0 ) return SQLITE_OK;
48637 assert( i>0 );
48638 assert( i<=p->iSize );
48639 i--;
48640 while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
48641 u32 bin = i/p->iDivisor;
48642 i = i%p->iDivisor;
48643 if( p->u.apSub[bin]==0 ){
48644 p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
48645 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM_BKPT;
48646 }
48647 p = p->u.apSub[bin];
48648 }
48649 if( p->iSize<=BITVEC_NBIT ){
48650 p->u.aBitmap[i/BITVEC_SZELEM] |= 1 << (i&(BITVEC_SZELEM-1));
48651 return SQLITE_OK;
48652 }
48653 h = BITVEC_HASH(i++);
48654 /* if there wasn't a hash collision, and this doesn't */
48655 /* completely fill the hash, then just add it without */
48656 /* worring about sub-dividing and re-hashing. */
48657 if( !p->u.aHash[h] ){
48658 if (p->nSet<(BITVEC_NINT-1)) {
48659 goto bitvec_set_end;
48660 } else {
48661 goto bitvec_set_rehash;
48662 }
48663 }
48664 /* there was a collision, check to see if it's already */
48665 /* in hash, if not, try to find a spot for it */
48666 do {
48667 if( p->u.aHash[h]==i ) return SQLITE_OK;
48668 h++;
48669 if( h>=BITVEC_NINT ) h = 0;
48670 } while( p->u.aHash[h] );
48671 /* we didn't find it in the hash. h points to the first */
48672 /* available free spot. check to see if this is going to */
48673 /* make our hash too "full". */
48674bitvec_set_rehash:
48675 if( p->nSet>=BITVEC_MXHASH ){
48676 unsigned int j;
48677 int rc;
48678 u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
48679 if( aiValues==0 ){
48680 return SQLITE_NOMEM_BKPT;
48681 }else{
48682 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
48683 memset(p->u.apSub, 0, sizeof(p->u.apSub));
48684 p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
48685 rc = sqlite3BitvecSet(p, i);
48686 for(j=0; j<BITVEC_NINT; j++){
48687 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
48688 }
48689 sqlite3StackFree(0, aiValues);
48690 return rc;
48691 }
#define BITVEC_MXHASH
Definition sqlite3.c:48522
#define BITVEC_NPTR
Definition sqlite3.c:48529

References Bitvec::aBitmap, Bitvec::aHash, Bitvec::apSub, BITVEC_HASH, BITVEC_MXHASH, BITVEC_NBIT, BITVEC_NINT, BITVEC_NPTR, BITVEC_SZELEM, Bitvec::iDivisor, Bitvec::iSize, Bitvec::nSet, sqlite3BitvecCreate(), sqlite3BitvecSet(), sqlite3StackAllocRaw, sqlite3StackFree, SQLITE_NOMEM_BKPT, SQLITE_OK, and Bitvec::u.

Referenced by addToSavepointBitvecs(), btreeSetHasContent(), getPageNormal(), pager_playback_one_page(), sqlite3BitvecBuiltinTest(), and sqlite3BitvecSet().

◆ sqlite3BitvecSize()

SQLITE_PRIVATE u32 sqlite3BitvecSize ( Bitvec * p)

Definition at line 48751 of file sqlite3.c.

Referenced by btreeGetHasContent(), btreeSetHasContent(), and sqlite3BitvecBuiltinTest().

◆ sqlite3BitvecTest()

SQLITE_PRIVATE int sqlite3BitvecTest ( Bitvec * p,
u32 i )

◆ sqlite3BitvecTestNotNull()

SQLITE_PRIVATE int sqlite3BitvecTestNotNull ( Bitvec * p,
u32 i )

Definition at line 48589 of file sqlite3.c.

48595 {
48596 assert( p!=0 );
48597 i--;
48598 if( i>=p->iSize ) return 0;
48599 while( p->iDivisor ){
48600 u32 bin = i/p->iDivisor;
48601 i = i%p->iDivisor;
48602 p = p->u.apSub[bin];
48603 if (!p) {
48604 return 0;
48605 }
48606 }
48607 if( p->iSize<=BITVEC_NBIT ){
48608 return (p->u.aBitmap[i/BITVEC_SZELEM] & (1<<(i&(BITVEC_SZELEM-1))))!=0;
48609 } else{
48610 u32 h = BITVEC_HASH(i++);
48611 while( p->u.aHash[h] ){

References Bitvec::aBitmap, Bitvec::aHash, Bitvec::apSub, BITVEC_HASH, BITVEC_NBIT, BITVEC_SZELEM, Bitvec::iDivisor, Bitvec::iSize, and Bitvec::u.

Referenced by btreeGetHasContent(), pager_write(), and subjRequiresPage().

◆ sqlite3BlobCompare()

SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3BlobCompare ( const Mem * pB1,
const Mem * pB2 )

Definition at line 81993 of file sqlite3.c.

81999 {
82000 int c;
82001 int n1 = pB1->n;
82002 int n2 = pB2->n;
82003
82004 /* It is possible to have a Blob value that has some non-zero content
82005 ** followed by zero content. But that only comes up for Blobs formed
82006 ** by the OP_MakeRecord opcode, and such Blobs never get passed into
82007 ** sqlite3MemCompare(). */
82008 assert( (pB1->flags & MEM_Zero)==0 || n1==0 );
82009 assert( (pB2->flags & MEM_Zero)==0 || n2==0 );
82010
82011 if( (pB1->flags|pB2->flags) & MEM_Zero ){
82012 if( pB1->flags & pB2->flags & MEM_Zero ){
82013 return pB1->u.nZero - pB2->u.nZero;
82014 }else if( pB1->flags & MEM_Zero ){
82015 if( !isAllZero(pB2->z, pB2->n) ) return -1;
82016 return pB1->u.nZero - n2;
82017 }else{
82018 if( !isAllZero(pB1->z, pB1->n) ) return +1;
82019 return n1 - pB2->u.nZero;
static int isAllZero(const char *z, int n)
Definition sqlite3.c:81980

References sqlite3_value::flags, isAllZero(), MEM_Zero, sqlite3_value::n, sqlite3_value::MemValue::nZero, sqlite3_value::u, and sqlite3_value::z.

Referenced by sqlite3MemCompare().

◆ sqlite3BtreeBeginStmt()

SQLITE_PRIVATE int sqlite3BtreeBeginStmt ( Btree * p,
int iStatement )

Definition at line 68747 of file sqlite3.c.

68753 {
68754 int rc;
68755 BtShared *pBt = p->pBt;
68757 assert( p->inTrans==TRANS_WRITE );
68758 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
68759 assert( iStatement>0 );
68760 assert( iStatement>p->db->nSavepoint );
68761 assert( pBt->inTransaction==TRANS_WRITE );
68762 /* At the pager level, a statement transaction is a savepoint with
68763 ** an index greater than all savepoints created explicitly using
68764 ** SQL statements. It is illegal to open, release or rollback any
int nSavepoint
Definition sqlite3.c:16930

References BTS_READ_ONLY, BtShared::btsFlags, Btree::db, Btree::inTrans, BtShared::inTransaction, sqlite3::nSavepoint, Btree::pBt, BtShared::pPager, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerOpenSavepoint(), and TRANS_WRITE.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeBeginTrans()

SQLITE_PRIVATE int sqlite3BtreeBeginTrans ( Btree * p,
int wrflag,
int * pSchemaVersion )

Definition at line 67850 of file sqlite3.c.

67856 {
67857 BtShared *pBt = p->pBt;
67858 Pager *pPager = pBt->pPager;
67859 int rc = SQLITE_OK;
67860
67862 btreeIntegrity(p);
67863
67864 /* If the btree is already in a write-transaction, or it
67865 ** is already in a read-transaction and a read-transaction
67866 ** is requested, this is a no-op.
67867 */
67868 if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){
67869 goto trans_begun;
67870 }
67871 assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
67872
67873 if( (p->db->flags & SQLITE_ResetDatabase)
67874 && sqlite3PagerIsreadonly(pPager)==0
67875 ){
67876 pBt->btsFlags &= ~BTS_READ_ONLY;
67877 }
67878
67879 /* Write transactions are not possible on a read-only database */
67880 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
67881 rc = SQLITE_READONLY;
67882 goto trans_begun;
67883 }
67884
67885#ifndef SQLITE_OMIT_SHARED_CACHE
67886 {
67887 sqlite3 *pBlock = 0;
67888 /* If another database handle has already opened a write transaction
67889 ** on this shared-btree structure and a second write transaction is
67890 ** requested, return SQLITE_LOCKED.
67891 */
67892 if( (wrflag && pBt->inTransaction==TRANS_WRITE)
67893 || (pBt->btsFlags & BTS_PENDING)!=0
67894 ){
67895 pBlock = pBt->pWriter->db;
67896 }else if( wrflag>1 ){
67897 BtLock *pIter;
67898 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
67899 if( pIter->pBtree!=p ){
67900 pBlock = pIter->pBtree->db;
67901 break;
67902 }
67903 }
67904 }
67905 if( pBlock ){
67906 sqlite3ConnectionBlocked(p->db, pBlock);
67908 goto trans_begun;
67909 }
67910 }
67911#endif
67912
67913 /* Any read-only or read-write transaction implies a read-lock on
67914 ** page 1. So if some other shared-cache client already has a write-lock
67915 ** on page 1, the transaction cannot be opened. */
67917 if( SQLITE_OK!=rc ) goto trans_begun;
67918
67919 pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
67920 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
67921 do {
67922 sqlite3PagerWalDb(pPager, p->db);
67923
67924#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
67925 /* If transitioning from no transaction directly to a write transaction,
67926 ** block for the WRITER lock first if possible. */
67927 if( pBt->pPage1==0 && wrflag ){
67928 assert( pBt->inTransaction==TRANS_NONE );
67929 rc = sqlite3PagerWalWriteLock(pPager, 1);
67930 if( rc!=SQLITE_BUSY && rc!=SQLITE_OK ) break;
67931 }
67932#endif
67933
67934 /* Call lockBtree() until either pBt->pPage1 is populated or
67935 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
67936 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
67937 ** reading page 1 it discovers that the page-size of the database
67938 ** file is not pBt->pageSize. In this case lockBtree() will update
67939 ** pBt->pageSize to the page-size of the file on disk.
67940 */
67941 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
67942
67943 if( rc==SQLITE_OK && wrflag ){
67944 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
67945 rc = SQLITE_READONLY;
67946 }else{
67947 rc = sqlite3PagerBegin(pPager, wrflag>1, sqlite3TempInMemory(p->db));
67948 if( rc==SQLITE_OK ){
67949 rc = newDatabase(pBt);
67950 }else if( rc==SQLITE_BUSY_SNAPSHOT && pBt->inTransaction==TRANS_NONE ){
67951 /* if there was no transaction opened when this function was
67952 ** called and SQLITE_BUSY_SNAPSHOT is returned, change the error
67953 ** code to SQLITE_BUSY. */
67954 rc = SQLITE_BUSY;
67955 }
67956 }
67957 }
67958
67959 if( rc!=SQLITE_OK ){
67960 (void)sqlite3PagerWalWriteLock(pPager, 0);
67962 }
67963 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
67965 sqlite3PagerWalDb(pPager, 0);
67966#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
67967 if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
67968#endif
67969
67970 if( rc==SQLITE_OK ){
67971 if( p->inTrans==TRANS_NONE ){
67972 pBt->nTransaction++;
67973#ifndef SQLITE_OMIT_SHARED_CACHE
67974 if( p->sharable ){
67975 assert( p->lock.pBtree==p && p->lock.iTable==1 );
67976 p->lock.eLock = READ_LOCK;
67977 p->lock.pNext = pBt->pLock;
67978 pBt->pLock = &p->lock;
67979 }
67980#endif
67981 }
67982 p->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
67983 if( p->inTrans>pBt->inTransaction ){
67984 pBt->inTransaction = p->inTrans;
67985 }
67986 if( wrflag ){
67987 MemPage *pPage1 = pBt->pPage1;
67988#ifndef SQLITE_OMIT_SHARED_CACHE
67989 assert( !pBt->pWriter );
67990 pBt->pWriter = p;
67991 pBt->btsFlags &= ~BTS_EXCLUSIVE;
67992 if( wrflag>1 ) pBt->btsFlags |= BTS_EXCLUSIVE;
67993#endif
67994
67995 /* If the db-size header field is incorrect (as it may be if an old
67996 ** client has been writing the database file), update it now. Doing
67997 ** this sooner rather than later means the database size can safely
67998 ** re-read the database size from page 1 if a savepoint or transaction
67999 ** rollback occurs within the transaction.
68000 */
68001 if( pBt->nPage!=get4byte(&pPage1->aData[28]) ){
68002 rc = sqlite3PagerWrite(pPage1->pDbPage);
68003 if( rc==SQLITE_OK ){
68004 put4byte(&pPage1->aData[28], pBt->nPage);
68005 }
68006 }
68007 }
68008 }
68009
68010trans_begun:
68011 if( rc==SQLITE_OK ){
68012 if( pSchemaVersion ){
68013 *pSchemaVersion = get4byte(&pBt->pPage1->aData[40]);
68014 }
68015 if( wrflag ){
68016 /* This call makes sure that the pager has the correct number of
68017 ** open savepoints. If the second parameter is greater than 0 and
68018 ** the sub-journal is not already open, then it will be opened here.
68019 */
68020 rc = sqlite3PagerOpenSavepoint(pPager, p->db->nSavepoint);
68021 }
static int btreeInvokeBusyHandler(void *pArg)
Definition sqlite3.c:66781
#define SCHEMA_ROOT
Definition sqlite3.c:14582
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *)
Definition sqlite3.c:163462
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n)
Definition sqlite3.c:58556
static int lockBtree(BtShared *pBt)
Definition sqlite3.c:67538
#define SQLITE_BUSY_TIMEOUT
Definition sqlite3.c:1559
#define BTS_INITIALLY_EMPTY
Definition sqlite3.c:63920
#define SQLITE_BUSY_SNAPSHOT
Definition sqlite3.c:1558
SQLITE_PRIVATE int sqlite3PagerBegin(Pager *, int exFlag, int)
Definition sqlite3.c:57521
#define sqlite3PagerWalDb(x, y)
Definition sqlite3.c:14943
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager *)
Definition sqlite3.c:58410
#define sqlite3PagerWalWriteLock(y, z)
Definition sqlite3.c:14942
static int newDatabase(BtShared *)
Definition sqlite3.c:67762
#define btreeIntegrity(p)
Definition sqlite3.c:64114
static void unlockBtreeIfUnused(BtShared *pBt)
Definition sqlite3.c:67745

References MemPage::aData, BtShared::bDoTruncate, btreeIntegrity, btreeInvokeBusyHandler(), BTS_EXCLUSIVE, BTS_INITIALLY_EMPTY, BTS_PENDING, BTS_READ_ONLY, BtShared::btsFlags, Btree::db, BtLock::eLock, sqlite3::flags, get4byte, IfNotOmitAV, Btree::inTrans, BtShared::inTransaction, BtLock::iTable, Btree::lock, lockBtree(), newDatabase(), BtShared::nPage, sqlite3::nSavepoint, BtShared::nTransaction, Btree::pBt, BtLock::pBtree, MemPage::pDbPage, BtShared::pLock, BtLock::pNext, BtShared::pPage1, BtShared::pPager, put4byte, BtShared::pWriter, querySharedCacheTableLock(), READ_LOCK, SCHEMA_ROOT, Btree::sharable, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3ConnectionBlocked, sqlite3PagerBegin(), sqlite3PagerIsreadonly(), sqlite3PagerOpenSavepoint(), sqlite3PagerWalDb, sqlite3PagerWalWriteLock, sqlite3PagerWrite(), sqlite3TempInMemory(), SQLITE_BUSY, SQLITE_BUSY_SNAPSHOT, SQLITE_BUSY_TIMEOUT, SQLITE_LOCKED_SHAREDCACHE, SQLITE_OK, SQLITE_READONLY, SQLITE_ResetDatabase, TRANS_NONE, TRANS_READ, TRANS_WRITE, and unlockBtreeIfUnused().

Referenced by schemaIsValid(), sqlite3BtreeSetVersion(), sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3BtreeCheckpoint()

SQLITE_PRIVATE int sqlite3BtreeCheckpoint ( Btree * p,
int eMode,
int * pnLog,
int * pnCkpt )

Definition at line 74806 of file sqlite3.c.

74812 {
74813 int rc = SQLITE_OK;
74814 if( p ){
74815 BtShared *pBt = p->pBt;
74817 if( pBt->inTransaction!=TRANS_NONE ){
74818 rc = SQLITE_LOCKED;
74819 }else{

References Btree::db, BtShared::inTransaction, Btree::pBt, BtShared::pPager, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerCheckpoint(), SQLITE_LOCKED, SQLITE_OK, and TRANS_NONE.

Referenced by sqlite3Checkpoint().

◆ sqlite3BtreeClearCursor()

SQLITE_PRIVATE void sqlite3BtreeClearCursor ( BtCursor * pCur)

Definition at line 65266 of file sqlite3.c.

Referenced by moveToRoot(), sqlite3BtreeTripAllCursors(), and sqlite3VdbeExec().

◆ sqlite3BtreeClearTable()

SQLITE_PRIVATE int sqlite3BtreeClearTable ( Btree * p,
int iTable,
int * pnChange )

Definition at line 73802 of file sqlite3.c.

73808 {
73809 int rc;
73810 BtShared *pBt = p->pBt;
73812 assert( p->inTrans==TRANS_WRITE );
73813
73814 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
73815
73816 if( SQLITE_OK==rc ){
73817 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
73818 ** is the root of a table b-tree - if it is not, the following call is
73819 ** a no-op). */

References clearDatabasePage(), Btree::inTrans, invalidateIncrblobCursors(), Btree::pBt, saveAllCursors(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), SQLITE_OK, and TRANS_WRITE.

Referenced by btreeDropTable(), sqlite3BtreeClearTableOfCursor(), and sqlite3VdbeExec().

◆ sqlite3BtreeClearTableOfCursor()

SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor ( BtCursor * pCur)

Definition at line 73826 of file sqlite3.c.

References BtCursor::pBtree, BtCursor::pgnoRoot, and sqlite3BtreeClearTable().

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeClose()

SQLITE_PRIVATE int sqlite3BtreeClose ( Btree * p)

Definition at line 67186 of file sqlite3.c.

67192 {
67193 BtShared *pBt = p->pBt;
67194 BtCursor *pCur;
67195
67196 /* Close all cursors opened via this handle. */
67197 assert( sqlite3_mutex_held(p->db->mutex) );
67199 pCur = pBt->pCursor;
67200 while( pCur ){
67201 BtCursor *pTmp = pCur;
67202 pCur = pCur->pNext;
67203 if( pTmp->pBtree==p ){
67205 }
67206 }
67207
67208 /* Rollback any active transaction and free the handle structure.
67209 ** The call to sqlite3BtreeRollback() drops any table-locks held by
67210 ** this handle.
67211 */
67214
67215 /* If there are still other outstanding references to the shared-btree
67216 ** structure, return now. The remainder of this procedure cleans
67217 ** up the shared-btree.
67218 */
67219 assert( p->wantToLock==0 && p->locked==0 );
67220 if( !p->sharable || removeFromSharingList(pBt) ){
67221 /* The pBt is no longer on the sharing list, so we can access
67222 ** it without having to hold the mutex.
67223 **
67224 ** Clean out and delete the BtShared object.
67225 */
67226 assert( !pBt->pCursor );
67227 sqlite3PagerClose(pBt->pPager, p->db);
67228 if( pBt->xFreeSchema && pBt->pSchema ){
67229 pBt->xFreeSchema(pBt->pSchema);
67230 }
67231 sqlite3DbFree(0, pBt->pSchema);
67232 freeTempSpace(pBt);
67233 sqlite3_free(pBt);
67234 }
67235
67236#ifndef SQLITE_OMIT_SHARED_CACHE
67237 assert( p->wantToLock==0 );
67238 assert( p->locked==0 );
67239 if( p->pPrev ) p->pPrev->pNext = p->pNext;
SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *)
Definition sqlite3.c:55785
static int removeFromSharingList(BtShared *pBt)
Definition sqlite3.c:67107
SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *)
Definition sqlite3.c:68969
void * pSchema
Definition sqlite3.c:63899
void(* xFreeSchema)(void *)
Definition sqlite3.c:63900
Btree * pPrev
Definition sqlite3.c:63824

Referenced by attachFunc(), detachFunc(), invalidateTempStorage(), and sqlite3LeaveMutexAndCloseZombie().

◆ sqlite3BtreeCloseCursor()

SQLITE_PRIVATE int sqlite3BtreeCloseCursor ( BtCursor * pCur)

Definition at line 68969 of file sqlite3.c.

68975 {
68976 Btree *pBtree = pCur->pBtree;
68977 if( pBtree ){
68978 BtShared *pBt = pCur->pBt;
68979 sqlite3BtreeEnter(pBtree);
68980 assert( pBt->pCursor!=0 );
68981 if( pBt->pCursor==pCur ){
68982 pBt->pCursor = pCur->pNext;
68983 }else{
68984 BtCursor *pPrev = pBt->pCursor;
68985 do{
68986 if( pPrev->pNext==pCur ){
68987 pPrev->pNext = pCur->pNext;
68988 break;
68989 }
68990 pPrev = pPrev->pNext;
68991 }while( ALWAYS(pPrev) );
68992 }
68995 sqlite3_free(pCur->aOverflow);

◆ sqlite3BtreeCommit()

SQLITE_PRIVATE int sqlite3BtreeCommit ( Btree * p)

Definition at line 68594 of file sqlite3.c.

68600 {
68601 int rc;
68603 rc = sqlite3BtreeCommitPhaseOne(p, 0);

Referenced by schemaIsValid(), and sqlite3InitOne().

◆ sqlite3BtreeCommitPhaseOne()

SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne ( Btree * p,
const char * zSuperJrnl )

Definition at line 68473 of file sqlite3.c.

68479 {
68480 int rc = SQLITE_OK;
68481 if( p->inTrans==TRANS_WRITE ){
68482 BtShared *pBt = p->pBt;
68484#ifndef SQLITE_OMIT_AUTOVACUUM
68485 if( pBt->autoVacuum ){
68486 rc = autoVacuumCommit(pBt);
68487 if( rc!=SQLITE_OK ){
68489 return rc;
68490 }
68491 }
68492 if( pBt->bDoTruncate ){
68494 }
static int autoVacuumCommit(BtShared *pBt)
Definition sqlite3.c:68394

References BtShared::autoVacuum, autoVacuumCommit(), BtShared::bDoTruncate, Btree::inTrans, BtShared::nPage, Btree::pBt, BtShared::pPager, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerCommitPhaseOne(), sqlite3PagerTruncateImage(), SQLITE_OK, and TRANS_WRITE.

Referenced by vdbeCommit().

◆ sqlite3BtreeCommitPhaseTwo()

SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo ( Btree * p,
int bCleanup )

Definition at line 68562 of file sqlite3.c.

68568 {
68569
68570 if( p->inTrans==TRANS_NONE ) return SQLITE_OK;
68572 btreeIntegrity(p);
68573
68574 /* If the handle has a write-transaction open, commit the shared-btrees
68575 ** transaction and set the shared state to TRANS_READ.
68576 */
68577 if( p->inTrans==TRANS_WRITE ){
68578 int rc;
68579 BtShared *pBt = p->pBt;
68580 assert( pBt->inTransaction==TRANS_WRITE );
68581 assert( pBt->nTransaction>0 );
68583 if( rc!=SQLITE_OK && bCleanup==0 ){
68585 return rc;
68586 }
68587 p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager *)
Definition sqlite3.c:58294
static void btreeClearHasContent(BtShared *pBt)
Definition sqlite3.c:65100
u32 iDataVersion
Definition sqlite3.c:63822

References btreeClearHasContent(), btreeEndTransaction(), btreeIntegrity, Btree::iDataVersion, Btree::inTrans, BtShared::inTransaction, BtShared::nTransaction, Btree::pBt, BtShared::pPager, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerCommitPhaseTwo(), SQLITE_OK, TRANS_NONE, TRANS_READ, and TRANS_WRITE.

Referenced by vdbeCommit().

◆ sqlite3BtreeConnectionCount()

SQLITE_PRIVATE int sqlite3BtreeConnectionCount ( Btree * p)

Definition at line 75043 of file sqlite3.c.

References BtShared::nRef, Btree::pBt, Btree::sharable, and testcase.

Referenced by sqlite3BtreeOpen().

◆ sqlite3BtreeCopyFile()

SQLITE_PRIVATE int sqlite3BtreeCopyFile ( Btree * pTo,
Btree * pFrom )

Definition at line 75772 of file sqlite3.c.

75778 {
75779 int rc;
75780 sqlite3_file *pFd; /* File descriptor for database pTo */
75782 sqlite3BtreeEnter(pTo);
75783 sqlite3BtreeEnter(pFrom);
75784
75785 assert( sqlite3BtreeIsInTrans(pTo) );
75787 if( pFd->pMethods ){
75788 i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
75790 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
75791 if( rc ) goto copy_finished;
75792 }
75793
75794 /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
75795 ** to 0. This is used by the implementations of sqlite3_backup_step()
75796 ** and sqlite3_backup_finish() to detect that they are being called
75797 ** from this function, not directly by the user.
75798 */
75799 memset(&b, 0, sizeof(b));
75800 b.pSrcDb = pFrom->db;
75801 b.pSrc = pFrom;
75802 b.pDest = pTo;
75803 b.iNext = 1;
75804
75805 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
75806 ** file. By passing this as the number of pages to copy to
75807 ** sqlite3_backup_step(), we can guarantee that the copy finishes
75808 ** within a single call (unless an error occurs). The assert() statement
75809 ** checks this assumption - (p->rc) should be set to either SQLITE_DONE
75810 ** or an error code. */
75811 sqlite3_backup_step(&b, 0x7FFFFFFF);
75812 assert( b.rc!=SQLITE_OK );
75813
75814 rc = sqlite3_backup_finish(&b);
75815 if( rc==SQLITE_OK ){
75816 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
75817 }else{
75819 }
75820
SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage)
Definition sqlite3.c:75371
SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p)
Definition sqlite3.c:75625
SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *)
Definition sqlite3.c:59081
#define SQLITE_FCNTL_OVERWRITE
Definition sqlite3.c:2189

References BtShared::btsFlags, Btree::db, sqlite3_backup::iNext, Btree::pBt, sqlite3_backup::pDest, sqlite3_file::pMethods, sqlite3_backup::pSrc, sqlite3_backup::pSrcDb, sqlite3_backup::rc, sqlite3_backup_finish(), sqlite3_backup_step(), sqlite3BtreeEnter(), sqlite3BtreeGetPageSize(), sqlite3BtreeIsInTrans(), sqlite3BtreeLastPage(), sqlite3BtreeLeave(), sqlite3BtreePager(), sqlite3OsFileControl(), sqlite3PagerClearCache(), sqlite3PagerFile(), SQLITE_FCNTL_OVERWRITE, SQLITE_NOTFOUND, and SQLITE_OK.

◆ sqlite3BtreeCount()

SQLITE_PRIVATE int sqlite3BtreeCount ( sqlite3 * db,
BtCursor * pCur,
i64 * pnEntry )

Definition at line 74026 of file sqlite3.c.

74032 {
74033 i64 nEntry = 0; /* Value to return in *pnEntry */
74034 int rc; /* Return code */
74035
74036 rc = moveToRoot(pCur);
74037 if( rc==SQLITE_EMPTY ){
74038 *pnEntry = 0;
74039 return SQLITE_OK;
74040 }
74041
74042 /* Unless an error occurs, the following loop runs one iteration for each
74043 ** page in the B-Tree structure (not including overflow pages).
74044 */
74045 while( rc==SQLITE_OK && !AtomicLoad(&db->u1.isInterrupted) ){
74046 int iIdx; /* Index of child node in parent */
74047 MemPage *pPage; /* Current page of the b-tree */
74048
74049 /* If this is a leaf page or the tree is not an int-key tree, then
74050 ** this page contains countable entries. Increment the entry counter
74051 ** accordingly.
74052 */
74053 pPage = pCur->pPage;
74054 if( pPage->leaf || !pPage->intKey ){
74055 nEntry += pPage->nCell;
74056 }
74057
74058 /* pPage is a leaf node. This loop navigates the cursor so that it
74059 ** points to the first interior cell that it points to the parent of
74060 ** the next page in the tree that has not yet been visited. The
74061 ** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
74062 ** of the page, or to the number of cells in the page if the next page
74063 ** to visit is the right-child of its parent.
74064 **
74065 ** If all pages in the tree have been visited, return SQLITE_OK to the
74066 ** caller.
74067 */
74068 if( pPage->leaf ){
74069 do {
74070 if( pCur->iPage==0 ){
74071 /* All pages of the b-tree have been visited. Return successfully. */
74072 *pnEntry = nEntry;
74073 return moveToRoot(pCur);
74074 }
74075 moveToParent(pCur);
74076 }while ( pCur->ix>=pCur->pPage->nCell );
74077
74078 pCur->ix++;
74079 pPage = pCur->pPage;
74080 }
74081
74082 /* Descend to the child node of the cell that the cursor currently
74083 ** points at. This is the right-child if (iIdx==pPage->nCell).
74084 */
74085 iIdx = pCur->ix;
74086 if( iIdx==pPage->nCell ){
74087 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
74088 }else{
74089 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
static int moveToRoot(BtCursor *pCur)
Definition sqlite3.c:69661
#define AtomicLoad(PTR)
Definition sqlite3.c:13476

References MemPage::aData, AtomicLoad, findCell, get4byte, MemPage::hdrOffset, MemPage::intKey, BtCursor::iPage, sqlite3::isInterrupted, BtCursor::ix, MemPage::leaf, moveToChild(), moveToParent(), moveToRoot(), MemPage::nCell, BtCursor::pPage, SQLITE_EMPTY, SQLITE_OK, and sqlite3::u1.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCreateTable()

SQLITE_PRIVATE int sqlite3BtreeCreateTable ( Btree * p,
Pgno * piTable,
int flags )

Definition at line 73723 of file sqlite3.c.

73729 {

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursor()

SQLITE_PRIVATE int sqlite3BtreeCursor ( Btree * p,
Pgno iTable,
int wrFlag,
struct KeyInfo * pKeyInfo,
BtCursor * pCursor )

Definition at line 68927 of file sqlite3.c.

68939 {

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursorHasHint()

SQLITE_PRIVATE int sqlite3BtreeCursorHasHint ( BtCursor * pCsr,
unsigned int mask )

Definition at line 75014 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursorHasMoved()

SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved ( BtCursor * pCur)

◆ sqlite3BtreeCursorHintFlags()

SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags ( BtCursor * pCur,
unsigned x )

Definition at line 65423 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursorIsValidNN()

SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN ( BtCursor * pCur)

Definition at line 69042 of file sqlite3.c.

69044 {
69045 return pCur && pCur->eState==CURSOR_VALID;

References CURSOR_VALID, and BtCursor::eState.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursorPin()

SQLITE_PRIVATE void sqlite3BtreeCursorPin ( BtCursor * pCur)

Definition at line 69064 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursorRestore()

SQLITE_PRIVATE int sqlite3BtreeCursorRestore ( BtCursor * pCur,
int * pDifferentRow )

Definition at line 65391 of file sqlite3.c.

65397 {
65398 int rc;
65399
65400 assert( pCur!=0 );
65401 assert( pCur->eState!=CURSOR_VALID );
65402 rc = restoreCursorPosition(pCur);
65403 if( rc ){
65404 *pDifferentRow = 1;
65405 return rc;
65406 }
65407 if( pCur->eState!=CURSOR_VALID ){

References CURSOR_VALID, BtCursor::eState, restoreCursorPosition, and SQLITE_OK.

Referenced by handleMovedCursor().

◆ sqlite3BtreeCursorSize()

SQLITE_PRIVATE int sqlite3BtreeCursorSize ( void )

Definition at line 68949 of file sqlite3.c.

References ROUND8.

Referenced by allocateCursor().

◆ sqlite3BtreeCursorUnpin()

SQLITE_PRIVATE void sqlite3BtreeCursorUnpin ( BtCursor * pCur)

Definition at line 69068 of file sqlite3.c.

69070 {
69071 assert( (pCur->curFlags & BTCF_Pinned)==0 );

References BTCF_Pinned, and BtCursor::curFlags.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeCursorZero()

SQLITE_PRIVATE void sqlite3BtreeCursorZero ( BtCursor * p)

Definition at line 68961 of file sqlite3.c.

References BTCURSOR_FIRST_UNINIT, and offsetof.

Referenced by allocateCursor().

◆ sqlite3BtreeDelete()

SQLITE_PRIVATE int sqlite3BtreeDelete ( BtCursor * pCur,
u8 flags )

Definition at line 73394 of file sqlite3.c.

73400 {
73401 Btree *p = pCur->pBtree;
73402 BtShared *pBt = p->pBt;
73403 int rc; /* Return code */
73404 MemPage *pPage; /* Page to delete cell from */
73405 unsigned char *pCell; /* Pointer to cell to delete */
73406 int iCellIdx; /* Index of cell to delete */
73407 int iCellDepth; /* Depth of node containing pCell */
73408 CellInfo info; /* Size of the cell being deleted */
73409 int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
73410 u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
73411
73412 assert( cursorOwnsBtShared(pCur) );
73413 assert( pBt->inTransaction==TRANS_WRITE );
73414 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
73415 assert( pCur->curFlags & BTCF_WriteFlag );
73416 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
73417 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
73418 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
73419 if( pCur->eState==CURSOR_REQUIRESEEK ){
73420 rc = btreeRestoreCursorPosition(pCur);
73421 if( rc ) return rc;
73422 }
73423 assert( pCur->eState==CURSOR_VALID );
73424
73425 iCellDepth = pCur->iPage;
73426 iCellIdx = pCur->ix;
73427 pPage = pCur->pPage;
73428 pCell = findCell(pPage, iCellIdx);
73429 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
73430
73431 /* If the bPreserve flag is set to true, then the cursor position must
73432 ** be preserved following this delete operation. If the current delete
73433 ** will cause a b-tree rebalance, then this is done by saving the cursor
73434 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
73435 ** returning.
73436 **
73437 ** Or, if the current delete will not cause a rebalance, then the cursor
73438 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
73439 ** before or after the deleted entry. In this case set bSkipnext to true. */
73440 if( bPreserve ){
73441 if( !pPage->leaf
73442 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
73443 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
73444 ){
73445 /* A b-tree rebalance will be required after deleting this entry.
73446 ** Save the cursor key. */
73447 rc = saveCursorKey(pCur);
73448 if( rc ) return rc;
73449 }else{
73450 bSkipnext = 1;
73451 }
73452 }
73453
73454 /* If the page containing the entry to delete is not a leaf page, move
73455 ** the cursor to the largest entry in the tree that is smaller than
73456 ** the entry being deleted. This cell will replace the cell being deleted
73457 ** from the internal node. The 'previous' entry is used for this instead
73458 ** of the 'next' entry, as the previous entry is always a part of the
73459 ** sub-tree headed by the child page of the cell being deleted. This makes
73460 ** balancing the tree following the delete operation easier. */
73461 if( !pPage->leaf ){
73462 rc = sqlite3BtreePrevious(pCur, 0);
73463 assert( rc!=SQLITE_DONE );
73464 if( rc ) return rc;
73465 }
73466
73467 /* Save the positions of any other cursors open on this table before
73468 ** making any modifications. */
73469 if( pCur->curFlags & BTCF_Multiple ){
73470 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
73471 if( rc ) return rc;
73472 }
73473
73474 /* If this is a delete operation to remove a row from a table b-tree,
73475 ** invalidate any incrblob cursors open on the row being deleted. */
73476 if( pCur->pKeyInfo==0 ){
73477 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
73478 }
73479
73480 /* Make the page containing the entry to be deleted writable. Then free any
73481 ** overflow pages associated with the entry and finally remove the cell
73482 ** itself from within the page. */
73483 rc = sqlite3PagerWrite(pPage->pDbPage);
73484 if( rc ) return rc;
73485 rc = clearCell(pPage, pCell, &info);
73486 dropCell(pPage, iCellIdx, info.nSize, &rc);
73487 if( rc ) return rc;
73488
73489 /* If the cell deleted was not located on a leaf page, then the cursor
73490 ** is currently pointing to the largest entry in the sub-tree headed
73491 ** by the child-page of the cell that was just deleted from an internal
73492 ** node. The cell from the leaf node needs to be moved to the internal
73493 ** node to replace the deleted cell. */
73494 if( !pPage->leaf ){
73495 MemPage *pLeaf = pCur->pPage;
73496 int nCell;
73497 Pgno n;
73498 unsigned char *pTmp;
73499
73500 if( pLeaf->nFree<0 ){
73501 rc = btreeComputeFreeSpace(pLeaf);
73502 if( rc ) return rc;
73503 }
73504 if( iCellDepth<pCur->iPage-1 ){
73505 n = pCur->apPage[iCellDepth+1]->pgno;
73506 }else{
73507 n = pCur->pPage->pgno;
73508 }
73509 pCell = findCell(pLeaf, pLeaf->nCell-1);
73510 if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
73511 nCell = pLeaf->xCellSize(pLeaf, pCell);
73512 assert( MX_CELL_SIZE(pBt) >= nCell );
73513 pTmp = pBt->pTmpSpace;
73514 assert( pTmp!=0 );
73515 rc = sqlite3PagerWrite(pLeaf->pDbPage);
73516 if( rc==SQLITE_OK ){
73517 insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
73518 }
73519 dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc);
73520 if( rc ) return rc;
73521 }
73522
73523 /* Balance the tree. If the entry deleted was located on a leaf page,
73524 ** then the cursor still points to that page. In this case the first
73525 ** call to balance() repairs the tree, and the if(...) condition is
73526 ** never true.
73527 **
73528 ** Otherwise, if the entry deleted was on an internal node page, then
73529 ** pCur is pointing to the leaf page from which a cell was removed to
73530 ** replace the cell deleted from the internal node. This is slightly
73531 ** tricky as the leaf node may be underfull, and the internal node may
73532 ** be either under or overfull. In this case run the balancing algorithm
73533 ** on the leaf node first. If the balance proceeds far enough up the
73534 ** tree that we can be sure that any problem in the internal node has
73535 ** been corrected, so be it. Otherwise, after balancing the leaf node,
73536 ** walk the cursor up the tree to the internal node and balance it as
73537 ** well. */
73538 rc = balance(pCur);
73539 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
73541 pCur->iPage--;
73542 while( pCur->iPage>iCellDepth ){
73543 releasePage(pCur->apPage[pCur->iPage--]);
73544 }
73545 pCur->pPage = pCur->apPage[pCur->iPage];
73546 rc = balance(pCur);
73547 }
73548
73549 if( rc==SQLITE_OK ){
73550 if( bSkipnext ){
73551 assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
73552 assert( pPage==pCur->pPage || CORRUPT_DB );
73553 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
73554 pCur->eState = CURSOR_SKIPNEXT;
73555 if( iCellIdx>=pPage->nCell ){
73556 pCur->skipNext = -1;
73557 pCur->ix = pPage->nCell-1;
73558 }else{
73559 pCur->skipNext = 1;
73560 }
73561 }else{
73562 rc = moveToRoot(pCur);
73563 if( bPreserve ){
73565 pCur->eState = CURSOR_REQUIRESEEK;
static void invalidateIncrblobCursors(Btree *pBtree, Pgno pgnoRoot, i64 iRow, int isClearTable)
Definition sqlite3.c:65009
#define BTREE_AUXDELETE
Definition sqlite3.c:15252
#define BTREE_SAVEPOSITION
Definition sqlite3.c:15251
static int btreeRestoreCursorPosition(BtCursor *pCur)
Definition sqlite3.c:65316

References BtCursor::apPage, balance(), BTCF_Multiple, BTCF_WriteFlag, BTREE_AUXDELETE, BTREE_SAVEPOSITION, btreeComputeFreeSpace(), btreeReleaseAllCursorPages(), btreeRestoreCursorPosition(), BTS_READ_ONLY, BtShared::btsFlags, cellSizePtr(), clearCell(), CORRUPT_DB, BtCursor::curFlags, CURSOR_REQUIRESEEK, CURSOR_SKIPNEXT, CURSOR_VALID, dropCell(), BtCursor::eState, findCell, BtCursor::info, insertCell(), BtShared::inTransaction, invalidateIncrblobCursors(), BtCursor::iPage, BtCursor::ix, MemPage::leaf, moveToRoot(), MX_CELL_SIZE, MemPage::nCell, MemPage::nFree, CellInfo::nKey, CellInfo::nSize, Btree::pBt, BtCursor::pBtree, MemPage::pDbPage, MemPage::pgno, BtCursor::pgnoRoot, BtCursor::pKeyInfo, BtCursor::pPage, BtShared::pTmpSpace, releasePage(), releasePageNotNull(), saveAllCursors(), saveCursorKey(), BtCursor::skipNext, sqlite3BtreePrevious(), sqlite3PagerWrite(), SQLITE_CORRUPT, SQLITE_CORRUPT_BKPT, SQLITE_DONE, SQLITE_EMPTY, SQLITE_OK, TRANS_WRITE, BtShared::usableSize, and MemPage::xCellSize.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeDropTable()

SQLITE_PRIVATE int sqlite3BtreeDropTable ( Btree * p,
int iTable,
int * piMoved )

Definition at line 73935 of file sqlite3.c.

73941 {

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeEnter()

SQLITE_PRIVATE void sqlite3BtreeEnter ( Btree * p)

Definition at line 64237 of file sqlite3.c.

64243 {
64244 /* Some basic sanity checking on the Btree. The list of Btrees
64245 ** connected by pNext and pPrev should be in sorted order by
64246 ** Btree.pBt value. All elements of the list should belong to
64247 ** the same connection. Only shared Btrees are on the list. */
64248 assert( p->pNext==0 || p->pNext->pBt>p->pBt );
64249 assert( p->pPrev==0 || p->pPrev->pBt<p->pBt );
64250 assert( p->pNext==0 || p->pNext->db==p->db );
64251 assert( p->pPrev==0 || p->pPrev->db==p->db );
64252 assert( p->sharable || (p->pNext==0 && p->pPrev==0) );
64253
64254 /* Check for locking consistency */
64255 assert( !p->locked || p->wantToLock>0 );
64256 assert( p->sharable || p->wantToLock==0 );
64257
64258 /* We should already hold a lock on the database connection */
64259 assert( sqlite3_mutex_held(p->db->mutex) );
64260
64261 /* Unless the database is sharable and unlocked, then BtShared.db
64262 ** should already be set correctly. */
64263 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );

References btreeLockCarefully(), Btree::db, BtShared::db, Btree::locked, sqlite3::mutex, Btree::pBt, Btree::pNext, Btree::pPrev, Btree::sharable, sqlite3_mutex_held(), and Btree::wantToLock.

Referenced by attachFunc(), doWalCallbacks(), openDatabase(), sqlite3BtreeBeginStmt(), sqlite3BtreeBeginTrans(), sqlite3BtreeCheckpoint(), sqlite3BtreeClearTable(), sqlite3BtreeCommitPhaseOne(), sqlite3BtreeCommitPhaseTwo(), sqlite3BtreeCopyFile(), sqlite3BtreeGetMeta(), sqlite3BtreeGetRequestedReserve(), sqlite3BtreeIncrVacuum(), sqlite3BtreeIntegrityCheck(), sqlite3BtreeLeaveCursor(), sqlite3BtreeLockTable(), sqlite3BtreeMaxPageCount(), sqlite3BtreeNewDb(), sqlite3BtreeRollback(), sqlite3BtreeSavepoint(), sqlite3BtreeSchema(), sqlite3BtreeSchemaLocked(), sqlite3BtreeSecureDelete(), sqlite3BtreeSetAutoVacuum(), sqlite3BtreeSetCacheSize(), sqlite3BtreeSetPagerFlags(), sqlite3BtreeSetPageSize(), sqlite3BtreeSetSpillSize(), sqlite3BtreeTripAllCursors(), sqlite3InitOne(), sqlite3VdbeEnter(), and vdbeCommit().

◆ sqlite3BtreeEnterAll()

SQLITE_PRIVATE void sqlite3BtreeEnterAll ( sqlite3 * db)

◆ sqlite3BtreeEnterCursor()

SQLITE_PRIVATE void sqlite3BtreeEnterCursor ( BtCursor * pCur)

Definition at line 64464 of file sqlite3.c.

◆ sqlite3BtreeEof()

SQLITE_PRIVATE int sqlite3BtreeEof ( BtCursor * pCur)

Definition at line 70139 of file sqlite3.c.

70145 {

References CURSOR_VALID, and BtCursor::eState.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeFakeValidCursor()

SQLITE_PRIVATE BtCursor * sqlite3BtreeFakeValidCursor ( void )

Definition at line 65372 of file sqlite3.c.

References CURSOR_VALID, and offsetof.

Referenced by sqlite3BtreeCursorHasMoved(), and sqlite3VdbeExec().

◆ sqlite3BtreeFirst()

SQLITE_PRIVATE int sqlite3BtreeFirst ( BtCursor * pCur,
int * pRes )

Definition at line 69796 of file sqlite3.c.

69802 {
69803 int rc;
69804
69805 assert( cursorOwnsBtShared(pCur) );
69806 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
69807 rc = moveToRoot(pCur);
69808 if( rc==SQLITE_OK ){
69809 assert( pCur->pPage->nCell>0 );
69810 *pRes = 0;
69811 rc = moveToLeftmost(pCur);
69812 }else if( rc==SQLITE_EMPTY ){

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeGetAutoVacuum()

SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum ( Btree * p)

Definition at line 67482 of file sqlite3.c.

67488 {
67489#ifdef SQLITE_OMIT_AUTOVACUUM
67490 return BTREE_AUTOVACUUM_NONE;
67491#else
67492 int rc;
67494 rc = (
67496 (!p->pBt->incrVacuum)?BTREE_AUTOVACUUM_FULL:
#define BTREE_AUTOVACUUM_FULL
Definition sqlite3.c:15030
#define BTREE_AUTOVACUUM_NONE
Definition sqlite3.c:15029

Referenced by sqlite3Pragma().

◆ sqlite3BtreeGetFilename()

SQLITE_PRIVATE const char * sqlite3BtreeGetFilename ( Btree * p)

Definition at line 74771 of file sqlite3.c.

References Btree::pBt, BtShared::pPager, and sqlite3PagerFilename().

Referenced by sqlite3Pragma(), and vdbeCommit().

◆ sqlite3BtreeGetJournalname()

SQLITE_PRIVATE const char * sqlite3BtreeGetJournalname ( Btree * p)

Definition at line 74784 of file sqlite3.c.

References Btree::pBt, and BtShared::pPager.

Referenced by vdbeCommit().

◆ sqlite3BtreeGetMeta()

SQLITE_PRIVATE void sqlite3BtreeGetMeta ( Btree * pBtree,
int idx,
u32 * pValue )

Definition at line 73964 of file sqlite3.c.

73970 {
73971 BtShared *pBt = p->pBt;
73972
73974 assert( p->inTrans>TRANS_NONE );
73976 assert( pBt->pPage1 );
73977 assert( idx>=0 && idx<=15 );
73978
73979 if( idx==BTREE_DATA_VERSION ){
73980 *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
73981 }else{
73982 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
73983 }
73984
73985 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
73986 ** database, mark the database as read-only. */
73987#ifdef SQLITE_OMIT_AUTOVACUUM
73988 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
#define BTREE_DATA_VERSION
Definition sqlite3.c:15150

References MemPage::aData, BTREE_DATA_VERSION, BTREE_LARGEST_ROOT_PAGE, BTS_READ_ONLY, BtShared::btsFlags, get4byte, Btree::iDataVersion, Btree::inTrans, Btree::pBt, BtShared::pPage1, BtShared::pPager, querySharedCacheTableLock(), READ_LOCK, SCHEMA_ROOT, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerDataVersion(), SQLITE_OK, and TRANS_NONE.

Referenced by btreeCreateTable(), btreeDropTable(), schemaIsValid(), sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3BtreeGetPageSize()

SQLITE_PRIVATE int sqlite3BtreeGetPageSize ( Btree * p)

◆ sqlite3BtreeGetRequestedReserve()

SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve ( Btree * p)

Definition at line 67396 of file sqlite3.c.

67402 {
67403 int n1, n2;

References BtShared::nReserveWanted, Btree::pBt, sqlite3BtreeEnter(), sqlite3BtreeGetReserveNoMutex(), and sqlite3BtreeLeave().

◆ sqlite3BtreeGetReserveNoMutex()

SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex ( Btree * p)

◆ sqlite3BtreeIncrblobCursor()

SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor ( BtCursor * pCur)

Definition at line 74968 of file sqlite3.c.

Referenced by blobSeekToRow().

◆ sqlite3BtreeIncrVacuum()

SQLITE_PRIVATE int sqlite3BtreeIncrVacuum ( Btree * p)

Definition at line 68352 of file sqlite3.c.

68358 {
68359 int rc;
68360 BtShared *pBt = p->pBt;
68361
68363 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
68364 if( !pBt->autoVacuum ){
68365 rc = SQLITE_DONE;
68366 }else{
68367 Pgno nOrig = btreePagecount(pBt);
68368 Pgno nFree = get4byte(&pBt->pPage1->aData[36]);
68369 Pgno nFin = finalDbSize(pBt, nOrig, nFree);
68370
68371 if( nOrig<nFin || nFree>=nOrig ){
68373 }else if( nFree>0 ){
68374 rc = saveAllCursors(pBt, 0, 0);
68375 if( rc==SQLITE_OK ){
68377 rc = incrVacuumStep(pBt, nFin, nOrig, 0);
68378 }
68379 if( rc==SQLITE_OK ){
68380 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
68381 put4byte(&pBt->pPage1->aData[28], pBt->nPage);
68382 }
68383 }else{

References MemPage::aData, BtShared::autoVacuum, btreePagecount(), finalDbSize(), get4byte, incrVacuumStep(), Btree::inTrans, BtShared::inTransaction, invalidateAllOverflowCache(), BtShared::nPage, Btree::pBt, MemPage::pDbPage, BtShared::pPage1, put4byte, saveAllCursors(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_DONE, SQLITE_OK, and TRANS_WRITE.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeInsert()

SQLITE_PRIVATE int sqlite3BtreeInsert ( BtCursor * pCur,
const BtreePayload * pPayload,
int flags,
int seekResult )

Definition at line 73109 of file sqlite3.c.

73120 {
73121 int rc;
73122 int loc = seekResult; /* -1: before desired location +1: after */
73123 int szNew = 0;
73124 int idx;
73125 MemPage *pPage;
73126 Btree *p = pCur->pBtree;
73127 BtShared *pBt = p->pBt;
73128 unsigned char *oldCell;
73129 unsigned char *newCell = 0;
73130
73131 assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND))==flags );
73132
73133 if( pCur->eState==CURSOR_FAULT ){
73134 assert( pCur->skipNext!=SQLITE_OK );
73135 return pCur->skipNext;
73136 }
73137
73138 assert( cursorOwnsBtShared(pCur) );
73139 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
73140 && pBt->inTransaction==TRANS_WRITE
73141 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
73142 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
73143
73144 /* Assert that the caller has been consistent. If this cursor was opened
73145 ** expecting an index b-tree, then the caller should be inserting blob
73146 ** keys with no associated data. If the cursor was opened expecting an
73147 ** intkey table, the caller should be inserting integer keys with a
73148 ** blob of associated data. */
73149 assert( (pX->pKey==0)==(pCur->pKeyInfo==0) );
73150
73151 /* Save the positions of any other cursors open on this table.
73152 **
73153 ** In some cases, the call to btreeMoveto() below is a no-op. For
73154 ** example, when inserting data into a table with auto-generated integer
73155 ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
73156 ** integer key to use. It then calls this function to actually insert the
73157 ** data into the intkey B-Tree. In this case btreeMoveto() recognizes
73158 ** that the cursor is already where it needs to be and returns without
73159 ** doing any work. To avoid thwarting these optimizations, it is important
73160 ** not to clear the cursor here.
73161 */
73162 if( pCur->curFlags & BTCF_Multiple ){
73163 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
73164 if( rc ) return rc;
73165 }
73166
73167 if( pCur->pKeyInfo==0 ){
73168 assert( pX->pKey==0 );
73169 /* If this is an insert into a table b-tree, invalidate any incrblob
73170 ** cursors open on the row being replaced */
73171 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
73172
73173 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
73174 ** to a row with the same key as the new entry being inserted.
73175 */
73176#ifdef SQLITE_DEBUG
73177 if( flags & BTREE_SAVEPOSITION ){
73178 assert( pCur->curFlags & BTCF_ValidNKey );
73179 assert( pX->nKey==pCur->info.nKey );
73180 assert( loc==0 );
73181 }
73182#endif
73183
73184 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
73185 ** that the cursor is not pointing to a row to be overwritten.
73186 ** So do a complete check.
73187 */
73188 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
73189 /* The cursor is pointing to the entry that is to be
73190 ** overwritten */
73191 assert( pX->nData>=0 && pX->nZero>=0 );
73192 if( pCur->info.nSize!=0
73193 && pCur->info.nPayload==(u32)pX->nData+pX->nZero
73194 ){
73195 /* New entry is the same size as the old. Do an overwrite */
73196 return btreeOverwriteCell(pCur, pX);
73197 }
73198 assert( loc==0 );
73199 }else if( loc==0 ){
73200 /* The cursor is *not* pointing to the cell to be overwritten, nor
73201 ** to an adjacent cell. Move the cursor so that it is pointing either
73202 ** to the cell to be overwritten or an adjacent cell.
73203 */
73204 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
73205 if( rc ) return rc;
73206 }
73207 }else{
73208 /* This is an index or a WITHOUT ROWID table */
73209
73210 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
73211 ** to a row with the same key as the new entry being inserted.
73212 */
73213 assert( (flags & BTREE_SAVEPOSITION)==0 || loc==0 );
73214
73215 /* If the cursor is not already pointing either to the cell to be
73216 ** overwritten, or if a new cell is being inserted, if the cursor is
73217 ** not pointing to an immediately adjacent cell, then move the cursor
73218 ** so that it does.
73219 */
73220 if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
73221 if( pX->nMem ){
73223 r.pKeyInfo = pCur->pKeyInfo;
73224 r.aMem = pX->aMem;
73225 r.nField = pX->nMem;
73226 r.default_rc = 0;
73227 r.errCode = 0;
73228 r.r1 = 0;
73229 r.r2 = 0;
73230 r.eqSeen = 0;
73231 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
73232 }else{
73233 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
73234 }
73235 if( rc ) return rc;
73236 }
73237
73238 /* If the cursor is currently pointing to an entry to be overwritten
73239 ** and the new content is the same as as the old, then use the
73240 ** overwrite optimization.
73241 */
73242 if( loc==0 ){
73243 getCellInfo(pCur);
73244 if( pCur->info.nKey==pX->nKey ){
73245 BtreePayload x2;
73246 x2.pData = pX->pKey;
73247 x2.nData = pX->nKey;
73248 x2.nZero = 0;
73249 return btreeOverwriteCell(pCur, &x2);
73250 }
73251 }
73252
73253 }
73254 assert( pCur->eState==CURSOR_VALID
73255 || (pCur->eState==CURSOR_INVALID && loc)
73256 || CORRUPT_DB );
73257
73258 pPage = pCur->pPage;
73259 assert( pPage->intKey || pX->nKey>=0 );
73260 assert( pPage->leaf || !pPage->intKey );
73261 if( pPage->nFree<0 ){
73262 if( pCur->eState>CURSOR_INVALID ){
73264 }else{
73265 rc = btreeComputeFreeSpace(pPage);
73266 }
73267 if( rc ) return rc;
73268 }
73269
73270 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
73271 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
73272 loc==0 ? "overwrite" : "new entry"));
73273 assert( pPage->isInit );
73274 newCell = pBt->pTmpSpace;
73275 assert( newCell!=0 );
73276 rc = fillInCell(pPage, newCell, pX, &szNew);
73277 if( rc ) goto end_insert;
73278 assert( szNew==pPage->xCellSize(pPage, newCell) );
73279 assert( szNew <= MX_CELL_SIZE(pBt) );
73280 idx = pCur->ix;
73281 if( loc==0 ){
73282 CellInfo info;
73283 assert( idx<pPage->nCell );
73284 rc = sqlite3PagerWrite(pPage->pDbPage);
73285 if( rc ){
73286 goto end_insert;
73287 }
73288 oldCell = findCell(pPage, idx);
73289 if( !pPage->leaf ){
73290 memcpy(newCell, oldCell, 4);
73291 }
73292 rc = clearCell(pPage, oldCell, &info);
73293 testcase( pCur->curFlags & BTCF_ValidOvfl );
73295 if( info.nSize==szNew && info.nLocal==info.nPayload
73296 && (!ISAUTOVACUUM || szNew<pPage->minLocal)
73297 ){
73298 /* Overwrite the old cell with the new if they are the same size.
73299 ** We could also try to do this if the old cell is smaller, then add
73300 ** the leftover space to the free list. But experiments show that
73301 ** doing that is no faster then skipping this optimization and just
73302 ** calling dropCell() and insertCell().
73303 **
73304 ** This optimization cannot be used on an autovacuum database if the
73305 ** new entry uses overflow pages, as the insertCell() call below is
73306 ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry. */
73307 assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
73308 if( oldCell < pPage->aData+pPage->hdrOffset+10 ){
73309 return SQLITE_CORRUPT_BKPT;
73310 }
73311 if( oldCell+szNew > pPage->aDataEnd ){
73312 return SQLITE_CORRUPT_BKPT;
73313 }
73314 memcpy(oldCell, newCell, szNew);
73315 return SQLITE_OK;
73316 }
73317 dropCell(pPage, idx, info.nSize, &rc);
73318 if( rc ) goto end_insert;
73319 }else if( loc<0 && pPage->nCell>0 ){
73320 assert( pPage->leaf );
73321 idx = ++pCur->ix;
73322 pCur->curFlags &= ~BTCF_ValidNKey;
73323 }else{
73324 assert( pPage->leaf );
73325 }
73326 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
73327 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
73328 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
73329
73330 /* If no error has occurred and pPage has an overflow cell, call balance()
73331 ** to redistribute the cells within the tree. Since balance() may move
73332 ** the cursor, zero the BtCursor.info.nSize and BTCF_ValidNKey
73333 ** variables.
73334 **
73335 ** Previous versions of SQLite called moveToRoot() to move the cursor
73336 ** back to the root page as balance() used to invalidate the contents
73337 ** of BtCursor.apPage[] and BtCursor.aiIdx[]. Instead of doing that,
73338 ** set the cursor state to "invalid". This makes common insert operations
73339 ** slightly faster.
73340 **
73341 ** There is a subtle but important optimization here too. When inserting
73342 ** multiple records into an intkey b-tree using a single cursor (as can
73343 ** happen while processing an "INSERT INTO ... SELECT" statement), it
73344 ** is advantageous to leave the cursor pointing to the last entry in
73345 ** the b-tree if possible. If the cursor is left pointing to the last
73346 ** entry in the table, and the next row inserted has an integer key
73347 ** larger than the largest existing key, it is possible to insert the
73348 ** row without seeking the cursor. This can be a big performance boost.
73349 */
73350 pCur->info.nSize = 0;
73351 if( pPage->nOverflow ){
73352 assert( rc==SQLITE_OK );
73353 pCur->curFlags &= ~(BTCF_ValidNKey);
73354 rc = balance(pCur);
73355
73356 /* Must make sure nOverflow is reset to zero even if the balance()
73357 ** fails. Internal data structure corruption will result otherwise.
73358 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
73359 ** from trying to save the current position of the cursor. */
73360 pCur->pPage->nOverflow = 0;
73361 pCur->eState = CURSOR_INVALID;
73362 if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
73364 if( pCur->pKeyInfo ){
73365 assert( pCur->pKey==0 );
73366 pCur->pKey = sqlite3Malloc( pX->nKey );
73367 if( pCur->pKey==0 ){
73368 rc = SQLITE_NOMEM;
73369 }else{
73370 memcpy(pCur->pKey, pX->pKey, pX->nKey);
73371 }
73372 }
73373 pCur->eState = CURSOR_REQUIRESEEK;
73374 pCur->nKey = pX->nKey;
73375 }
static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX)
Definition sqlite3.c:73030
#define invalidateOverflowCache(pCur)
Definition sqlite3.c:64981
#define BTREE_APPEND
Definition sqlite3.c:15253
static int fillInCell(MemPage *pPage, unsigned char *pCell, const BtreePayload *pX, int *pnSize)
Definition sqlite3.c:70938
KeyInfo * pKeyInfo
Definition sqlite3.c:17731

References MemPage::aDataEnd, BtreePayload::aMem, UnpackedRecord::aMem, balance(), BTCF_Multiple, BTCF_ValidNKey, BTCF_ValidOvfl, BTCF_WriteFlag, BTREE_APPEND, BTREE_SAVEPOSITION, btreeComputeFreeSpace(), btreeMoveto(), btreeOverwriteCell(), btreeReleaseAllCursorPages(), BTS_READ_ONLY, BtShared::btsFlags, clearCell(), CORRUPT_DB, BtCursor::curFlags, CURSOR_FAULT, CURSOR_INVALID, CURSOR_REQUIRESEEK, CURSOR_VALID, UnpackedRecord::default_rc, dropCell(), UnpackedRecord::eqSeen, UnpackedRecord::errCode, BtCursor::eState, fillInCell(), findCell, getCellInfo(), MemPage::hdrOffset, BtCursor::info, insertCell(), MemPage::intKey, BtShared::inTransaction, invalidateIncrblobCursors(), invalidateOverflowCache, BtCursor::iPage, ISAUTOVACUUM, MemPage::isInit, BtCursor::ix, MemPage::leaf, MX_CELL_SIZE, MemPage::nCell, BtreePayload::nData, UnpackedRecord::nField, MemPage::nFree, BtreePayload::nKey, CellInfo::nKey, BtCursor::nKey, CellInfo::nLocal, BtreePayload::nMem, MemPage::nOverflow, CellInfo::nPayload, CellInfo::nSize, BtreePayload::nZero, Btree::pBt, BtCursor::pBtree, BtreePayload::pData, MemPage::pDbPage, MemPage::pgno, BtCursor::pgnoRoot, BtreePayload::pKey, BtCursor::pKey, UnpackedRecord::pKeyInfo, BtCursor::pKeyInfo, BtCursor::pPage, BtShared::pTmpSpace, UnpackedRecord::r1, UnpackedRecord::r2, saveAllCursors(), BtCursor::skipNext, sqlite3BtreeMovetoUnpacked(), sqlite3Malloc(), sqlite3PagerWrite(), SQLITE_CORRUPT_BKPT, SQLITE_NOMEM, SQLITE_OK, testcase, TRACE, TRANS_WRITE, and MemPage::xCellSize.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeIntegerKey()

SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey ( BtCursor * pCur)

Definition at line 69053 of file sqlite3.c.

69059 {

References BtCursor::curIntKey, CURSOR_VALID, BtCursor::eState, and getCellInfo().

Referenced by saveCursorKey(), and sqlite3VdbeExec().

◆ sqlite3BtreeIntegrityCheck()

SQLITE_PRIVATE char * sqlite3BtreeIntegrityCheck ( sqlite3 * db,
Btree * p,
Pgno * aRoot,
int nRoot,
int mxErr,
int * pnErr )

Definition at line 74616 of file sqlite3.c.

74629 {
74630 Pgno i;
74631 IntegrityCk sCheck;
74632 BtShared *pBt = p->pBt;
74633 u64 savedDbFlags = pBt->db->flags;
74634 char zErr[100];
74635 int bPartial = 0; /* True if not checking all btrees */
74636 int bCkFreelist = 1; /* True to scan the freelist */
74637 VVA_ONLY( int nRef );
74638 assert( nRoot>0 );
74639
74640 /* aRoot[0]==0 means this is a partial check */
74641 if( aRoot[0]==0 ){
74642 assert( nRoot>1 );
74643 bPartial = 1;
74644 if( aRoot[1]!=1 ) bCkFreelist = 0;
74645 }
74646
74648 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
74649 VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
74650 assert( nRef>=0 );
74651 sCheck.db = db;
74652 sCheck.pBt = pBt;
74653 sCheck.pPager = pBt->pPager;
74654 sCheck.nPage = btreePagecount(sCheck.pBt);
74655 sCheck.mxErr = mxErr;
74656 sCheck.nErr = 0;
74657 sCheck.bOomFault = 0;
74658 sCheck.zPfx = 0;
74659 sCheck.v1 = 0;
74660 sCheck.v2 = 0;
74661 sCheck.aPgRef = 0;
74662 sCheck.heap = 0;
74663 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
74665 if( sCheck.nPage==0 ){
74666 goto integrity_ck_cleanup;
74667 }
74668
74669 sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
74670 if( !sCheck.aPgRef ){
74671 sCheck.bOomFault = 1;
74672 goto integrity_ck_cleanup;
74673 }
74674 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
74675 if( sCheck.heap==0 ){
74676 sCheck.bOomFault = 1;
74677 goto integrity_ck_cleanup;
74678 }
74679
74680 i = PENDING_BYTE_PAGE(pBt);
74681 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
74682
74683 /* Check the integrity of the freelist
74684 */
74685 if( bCkFreelist ){
74686 sCheck.zPfx = "Main freelist: ";
74687 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
74688 get4byte(&pBt->pPage1->aData[36]));
74689 sCheck.zPfx = 0;
74690 }
74691
74692 /* Check all the tables.
74693 */
74694#ifndef SQLITE_OMIT_AUTOVACUUM
74695 if( !bPartial ){
74696 if( pBt->autoVacuum ){
74697 Pgno mx = 0;
74698 Pgno mxInHdr;
74699 for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
74700 mxInHdr = get4byte(&pBt->pPage1->aData[52]);
74701 if( mx!=mxInHdr ){
74702 checkAppendMsg(&sCheck,
74703 "max rootpage (%d) disagrees with header (%d)",
74704 mx, mxInHdr
74705 );
74706 }
74707 }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
74708 checkAppendMsg(&sCheck,
74709 "incremental_vacuum enabled with a max rootpage of zero"
74710 );
74711 }
74712 }
74713#endif
74715 pBt->db->flags &= ~(u64)SQLITE_CellSizeCk;
74716 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
74717 i64 notUsed;
74718 if( aRoot[i]==0 ) continue;
74719#ifndef SQLITE_OMIT_AUTOVACUUM
74720 if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
74721 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
74722 }
74723#endif
74724 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
74725 }
74726 pBt->db->flags = savedDbFlags;
74727
74728 /* Make sure every page in the file is referenced
74729 */
74730 if( !bPartial ){
74731 for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
74732#ifdef SQLITE_OMIT_AUTOVACUUM
74733 if( getPageReferenced(&sCheck, i)==0 ){
74734 checkAppendMsg(&sCheck, "Page %d is never used", i);
74735 }
74736#else
74737 /* If the database supports auto-vacuum, make sure no tables contain
74738 ** references to pointer-map pages.
74739 */
74740 if( getPageReferenced(&sCheck, i)==0 &&
74741 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
74742 checkAppendMsg(&sCheck, "Page %d is never used", i);
74743 }
74744 if( getPageReferenced(&sCheck, i)!=0 &&
74745 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
74746 checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
74747 }
74748#endif
74749 }
74750 }
74751
74752 /* Clean up and report errors.
74753 */
74754integrity_ck_cleanup:
74755 sqlite3PageFree(sCheck.heap);
74756 sqlite3_free(sCheck.aPgRef);
74757 if( sCheck.bOomFault ){
74758 sqlite3_str_reset(&sCheck.errMsg);
74759 sCheck.nErr++;
74760 }
74761 *pnErr = sCheck.nErr;
static void setPageReferenced(IntegrityCk *pCheck, Pgno iPg)
Definition sqlite3.c:74141
SQLITE_API void sqlite3_str_reset(sqlite3_str *)
Definition sqlite3.c:29216
sqlite3 * db
Definition sqlite3.c:64157

References MemPage::aData, IntegrityCk::aPgRef, BtShared::autoVacuum, IntegrityCk::bOomFault, btreePagecount(), checkAppendMsg(), checkList(), checkPtrmap(), checkTreePage(), BtShared::db, IntegrityCk::db, IntegrityCk::errMsg, sqlite3::flags, get4byte, getPageReferenced(), IntegrityCk::heap, Btree::inTrans, BtShared::inTransaction, LARGEST_INT64, IntegrityCk::mxErr, IntegrityCk::nErr, IntegrityCk::nPage, BtShared::pageSize, Btree::pBt, IntegrityCk::pBt, PENDING_BYTE_PAGE, BtShared::pPage1, BtShared::pPager, IntegrityCk::pPager, sqlite3_str::printfFlags, PTRMAP_PAGENO, PTRMAP_ROOTPAGE, setPageReferenced(), sqlite3_free(), sqlite3_str_reset(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3MallocZero(), sqlite3PageFree(), sqlite3PageMalloc(), sqlite3StrAccumFinish(), sqlite3StrAccumInit(), SQLITE_CellSizeCk, SQLITE_MAX_LENGTH, SQLITE_PRINTF_INTERNAL, testcase, TRANS_NONE, IntegrityCk::v1, IntegrityCk::v2, VVA_ONLY, and IntegrityCk::zPfx.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeIsInBackup()

SQLITE_PRIVATE int sqlite3BtreeIsInBackup ( Btree * p)

Definition at line 74831 of file sqlite3.c.

74831 {
74832 assert( p );
74833 assert( sqlite3_mutex_held(p->db->mutex) );
74834 return p->inTrans!=TRANS_NONE;
74835}

References Btree::db, Btree::inTrans, sqlite3::mutex, sqlite3_mutex_held(), and TRANS_NONE.

Referenced by detachFunc().

◆ sqlite3BtreeIsInReadTrans()

SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans ( Btree * p)

◆ sqlite3BtreeIsInTrans()

SQLITE_PRIVATE int sqlite3BtreeIsInTrans ( Btree * p)

Definition at line 74792 of file sqlite3.c.

Referenced by sqlite3BtreeCopyFile(), sqlite3RollbackAll(), sqlite3VdbeExec(), and vdbeCommit().

◆ sqlite3BtreeIsReadonly()

SQLITE_PRIVATE int sqlite3BtreeIsReadonly ( Btree * pBt)

Definition at line 75021 of file sqlite3.c.

◆ sqlite3BtreeLast()

SQLITE_PRIVATE int sqlite3BtreeLast ( BtCursor * pCur,
int * pRes )

Definition at line 69818 of file sqlite3.c.

69824 {
69825 int rc;
69826
69827 assert( cursorOwnsBtShared(pCur) );
69828 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
69829
69830 /* If the cursor already points to the last entry, this is a no-op. */
69831 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){
69832#ifdef SQLITE_DEBUG
69833 /* This block serves to assert() that the cursor really does point
69834 ** to the last entry in the b-tree. */
69835 int ii;
69836 for(ii=0; ii<pCur->iPage; ii++){
69837 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
69838 }
69839 assert( pCur->ix==pCur->pPage->nCell-1 );
69840 assert( pCur->pPage->leaf );
69841#endif
69842 *pRes = 0;
69843 return SQLITE_OK;
69844 }
69845
69846 rc = moveToRoot(pCur);
69847 if( rc==SQLITE_OK ){
69848 assert( pCur->eState==CURSOR_VALID );
69849 *pRes = 0;
69850 rc = moveToRightmost(pCur);
69851 if( rc==SQLITE_OK ){
69852 pCur->curFlags |= BTCF_AtLast;
69853 }else{
69854 pCur->curFlags &= ~BTCF_AtLast;
69855 }
69856 }else if( rc==SQLITE_EMPTY ){

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeLastPage()

SQLITE_PRIVATE Pgno sqlite3BtreeLastPage ( Btree * p)

Definition at line 66621 of file sqlite3.c.

66624 {

References BtShared::nPage.

Referenced by backupOnePage(), sqlite3BtreeCopyFile(), sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3BtreeLeave()

◆ sqlite3BtreeLeaveAll()

SQLITE_PRIVATE void sqlite3BtreeLeaveAll ( sqlite3 * db)

Definition at line 64378 of file sqlite3.c.

64379 {
64380 p = db->aDb[i].pBt;

Referenced by attachFunc(), renameColumnFunc(), renameTableFunc(), sqlite3_table_column_metadata(), and sqlite3RollbackAll().

◆ sqlite3BtreeLeaveCursor()

SQLITE_PRIVATE void sqlite3BtreeLeaveCursor ( BtCursor * pCur)

Definition at line 64468 of file sqlite3.c.

64470 {

References BtCursor::pBtree, and sqlite3BtreeEnter().

◆ sqlite3BtreeLockTable()

SQLITE_PRIVATE int sqlite3BtreeLockTable ( Btree * pBtree,
int iTab,
u8 isWriteLock )

Definition at line 74890 of file sqlite3.c.

74896 {
74897 int rc = SQLITE_OK;
74898 assert( p->inTrans!=TRANS_NONE );
74899 if( p->sharable ){
74900 u8 lockType = READ_LOCK + isWriteLock;
74901 assert( READ_LOCK+1==WRITE_LOCK );
74902 assert( isWriteLock==0 || isWriteLock==1 );
74903
74905 rc = querySharedCacheTableLock(p, iTab, lockType);
74906 if( rc==SQLITE_OK ){

References Btree::inTrans, querySharedCacheTableLock(), READ_LOCK, setSharedCacheTableLock(), Btree::sharable, sqlite3BtreeEnter(), sqlite3BtreeLeave(), SQLITE_OK, TRANS_NONE, and WRITE_LOCK.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeMaxPageCount()

SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount ( Btree * p,
Pgno mxPage )

◆ sqlite3BtreeMaxRecordSize()

SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize ( BtCursor * pCur)

◆ sqlite3BtreeMovetoUnpacked()

SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked ( BtCursor * pCur,
UnpackedRecord * pUnKey,
i64 intKey,
int bias,
int * pRes )

Definition at line 69888 of file sqlite3.c.

69900 {
69901 int rc;
69902 RecordCompare xRecordCompare;
69903
69904 assert( cursorOwnsBtShared(pCur) );
69905 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
69906 assert( pRes );
69907 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
69908 assert( pCur->eState!=CURSOR_VALID || (pIdxKey==0)==(pCur->curIntKey!=0) );
69909
69910 /* If the cursor is already positioned at the point we are trying
69911 ** to move to, then just return without doing any work */
69912 if( pIdxKey==0
69913 && pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
69914 ){
69915 if( pCur->info.nKey==intKey ){
69916 *pRes = 0;
69917 return SQLITE_OK;
69918 }
69919 if( pCur->info.nKey<intKey ){
69920 if( (pCur->curFlags & BTCF_AtLast)!=0 ){
69921 *pRes = -1;
69922 return SQLITE_OK;
69923 }
69924 /* If the requested key is one more than the previous key, then
69925 ** try to get there using sqlite3BtreeNext() rather than a full
69926 ** binary search. This is an optimization only. The correct answer
69927 ** is still obtained without this case, only a little more slowely */
69928 if( pCur->info.nKey+1==intKey ){
69929 *pRes = 0;
69930 rc = sqlite3BtreeNext(pCur, 0);
69931 if( rc==SQLITE_OK ){
69932 getCellInfo(pCur);
69933 if( pCur->info.nKey==intKey ){
69934 return SQLITE_OK;
69935 }
69936 }else if( rc==SQLITE_DONE ){
69937 rc = SQLITE_OK;
69938 }else{
69939 return rc;
69940 }
69941 }
69942 }
69943 }
69944
69945 if( pIdxKey ){
69946 xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
69947 pIdxKey->errCode = 0;
69948 assert( pIdxKey->default_rc==1
69949 || pIdxKey->default_rc==0
69950 || pIdxKey->default_rc==-1
69951 );
69952 }else{
69953 xRecordCompare = 0; /* All keys are integers */
69954 }
69955
69956 rc = moveToRoot(pCur);
69957 if( rc ){
69958 if( rc==SQLITE_EMPTY ){
69959 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
69960 *pRes = -1;
69961 return SQLITE_OK;
69962 }
69963 return rc;
69964 }
69965 assert( pCur->pPage );
69966 assert( pCur->pPage->isInit );
69967 assert( pCur->eState==CURSOR_VALID );
69968 assert( pCur->pPage->nCell > 0 );
69969 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
69970 assert( pCur->curIntKey || pIdxKey );
69971 for(;;){
69972 int lwr, upr, idx, c;
69973 Pgno chldPg;
69974 MemPage *pPage = pCur->pPage;
69975 u8 *pCell; /* Pointer to current cell in pPage */
69976
69977 /* pPage->nCell must be greater than zero. If this is the root-page
69978 ** the cursor would have been INVALID above and this for(;;) loop
69979 ** not run. If this is not the root-page, then the moveToChild() routine
69980 ** would have already detected db corruption. Similarly, pPage must
69981 ** be the right kind (index or table) of b-tree page. Otherwise
69982 ** a moveToChild() or moveToRoot() call would have detected corruption. */
69983 assert( pPage->nCell>0 );
69984 assert( pPage->intKey==(pIdxKey==0) );
69985 lwr = 0;
69986 upr = pPage->nCell-1;
69987 assert( biasRight==0 || biasRight==1 );
69988 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
69989 pCur->ix = (u16)idx;
69990 if( xRecordCompare==0 ){
69991 for(;;){
69992 i64 nCellKey;
69993 pCell = findCellPastPtr(pPage, idx);
69994 if( pPage->intKeyLeaf ){
69995 while( 0x80 <= *(pCell++) ){
69996 if( pCell>=pPage->aDataEnd ){
69997 return SQLITE_CORRUPT_PAGE(pPage);
69998 }
69999 }
70000 }
70001 getVarint(pCell, (u64*)&nCellKey);
70002 if( nCellKey<intKey ){
70003 lwr = idx+1;
70004 if( lwr>upr ){ c = -1; break; }
70005 }else if( nCellKey>intKey ){
70006 upr = idx-1;
70007 if( lwr>upr ){ c = +1; break; }
70008 }else{
70009 assert( nCellKey==intKey );
70010 pCur->ix = (u16)idx;
70011 if( !pPage->leaf ){
70012 lwr = idx;
70013 goto moveto_next_layer;
70014 }else{
70015 pCur->curFlags |= BTCF_ValidNKey;
70016 pCur->info.nKey = nCellKey;
70017 pCur->info.nSize = 0;
70018 *pRes = 0;
70019 return SQLITE_OK;
70020 }
70021 }
70022 assert( lwr+upr>=0 );
70023 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
70024 }
70025 }else{
70026 for(;;){
70027 int nCell; /* Size of the pCell cell in bytes */
70028 pCell = findCellPastPtr(pPage, idx);
70029
70030 /* The maximum supported page-size is 65536 bytes. This means that
70031 ** the maximum number of record bytes stored on an index B-Tree
70032 ** page is less than 16384 bytes and may be stored as a 2-byte
70033 ** varint. This information is used to attempt to avoid parsing
70034 ** the entire cell by checking for the cases where the record is
70035 ** stored entirely within the b-tree page by inspecting the first
70036 ** 2 bytes of the cell.
70037 */
70038 nCell = pCell[0];
70039 if( nCell<=pPage->max1bytePayload ){
70040 /* This branch runs if the record-size field of the cell is a
70041 ** single byte varint and the record fits entirely on the main
70042 ** b-tree page. */
70043 testcase( pCell+nCell+1==pPage->aDataEnd );
70044 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
70045 }else if( !(pCell[1] & 0x80)
70046 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
70047 ){
70048 /* The record-size field is a 2 byte varint and the record
70049 ** fits entirely on the main b-tree page. */
70050 testcase( pCell+nCell+2==pPage->aDataEnd );
70051 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
70052 }else{
70053 /* The record flows over onto one or more overflow pages. In
70054 ** this case the whole cell needs to be parsed, a buffer allocated
70055 ** and accessPayload() used to retrieve the record into the
70056 ** buffer before VdbeRecordCompare() can be called.
70057 **
70058 ** If the record is corrupt, the xRecordCompare routine may read
70059 ** up to two varints past the end of the buffer. An extra 18
70060 ** bytes of padding is allocated at the end of the buffer in
70061 ** case this happens. */
70062 void *pCellKey;
70063 u8 * const pCellBody = pCell - pPage->childPtrSize;
70064 const int nOverrun = 18; /* Size of the overrun padding */
70065 pPage->xParseCell(pPage, pCellBody, &pCur->info);
70066 nCell = (int)pCur->info.nKey;
70067 testcase( nCell<0 ); /* True if key size is 2^32 or more */
70068 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
70069 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
70070 testcase( nCell==2 ); /* Minimum legal index key size */
70071 if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
70072 rc = SQLITE_CORRUPT_PAGE(pPage);
70073 goto moveto_finish;
70074 }
70075 pCellKey = sqlite3Malloc( nCell+nOverrun );
70076 if( pCellKey==0 ){
70077 rc = SQLITE_NOMEM_BKPT;
70078 goto moveto_finish;
70079 }
70080 pCur->ix = (u16)idx;
70081 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
70082 memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
70083 pCur->curFlags &= ~BTCF_ValidOvfl;
70084 if( rc ){
70085 sqlite3_free(pCellKey);
70086 goto moveto_finish;
70087 }
70088 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
70089 sqlite3_free(pCellKey);
70090 }
70091 assert(
70092 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
70093 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
70094 );
70095 if( c<0 ){
70096 lwr = idx+1;
70097 }else if( c>0 ){
70098 upr = idx-1;
70099 }else{
70100 assert( c==0 );
70101 *pRes = 0;
70102 rc = SQLITE_OK;
70103 pCur->ix = (u16)idx;
70104 if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT;
70105 goto moveto_finish;
70106 }
70107 if( lwr>upr ) break;
70108 assert( lwr+upr>=0 );
70109 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
70110 }
70111 }
70112 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
70113 assert( pPage->isInit );
70114 if( pPage->leaf ){
70115 assert( pCur->ix<pCur->pPage->nCell );
70116 pCur->ix = (u16)idx;
70117 *pRes = c;
70118 rc = SQLITE_OK;
70119 goto moveto_finish;
70120 }
70121moveto_next_layer:
70122 if( lwr>=pPage->nCell ){
70123 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
70124 }else{
70125 chldPg = get4byte(findCell(pPage, lwr));
70126 }
70127 pCur->ix = (u16)lwr;
70128 rc = moveToChild(pCur, chldPg);
70129 if( rc ) break;
#define getVarint
Definition sqlite3.c:19875
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int, const void *, UnpackedRecord *)
Definition sqlite3.c:82407
int(* RecordCompare)(int, const void *, UnpackedRecord *)
Definition sqlite3.c:15904
static int accessPayload(BtCursor *pCur, u32 offset, u32 amt, unsigned char *pBuf, int eOp)
Definition sqlite3.c:69259
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *)
Definition sqlite3.c:82582

References accessPayload(), MemPage::aData, MemPage::aDataEnd, BtCursor::apPage, BTCF_AtLast, BTCF_ValidNKey, BTCF_ValidOvfl, MemPage::childPtrSize, BtCursor::curFlags, BtCursor::curIntKey, CURSOR_VALID, Btree::db, UnpackedRecord::default_rc, UnpackedRecord::errCode, BtCursor::eState, findCell, findCellPastPtr, get4byte, getCellInfo(), getVarint, MemPage::hdrOffset, BtCursor::info, MemPage::intKey, MemPage::intKeyLeaf, BtCursor::iPage, MemPage::isInit, BtCursor::ix, MemPage::leaf, sqlite3::mallocFailed, MemPage::maxLocal, moveToChild(), moveToRoot(), sqlite3::mutex, MemPage::nCell, CellInfo::nKey, BtShared::nPage, CellInfo::nSize, BtCursor::pBt, BtCursor::pBtree, BtCursor::pgnoRoot, BtCursor::pKeyInfo, BtCursor::pPage, sqlite3_free(), sqlite3_mutex_held(), sqlite3BtreeNext(), sqlite3Malloc(), sqlite3VdbeFindCompare(), sqlite3VdbeRecordCompare(), SQLITE_CORRUPT, SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_PAGE, SQLITE_DONE, SQLITE_EMPTY, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, BtShared::usableSize, and MemPage::xParseCell.

Referenced by btreeMoveto(), sqlite3BtreeInsert(), sqlite3VdbeExec(), and sqlite3VdbeFinishMoveto().

◆ sqlite3BtreeNewDb()

SQLITE_PRIVATE int sqlite3BtreeNewDb ( Btree * p)

Definition at line 67806 of file sqlite3.c.

67812 {
67813 int rc;

References newDatabase(), BtShared::nPage, Btree::pBt, sqlite3BtreeEnter(), and sqlite3BtreeLeave().

◆ sqlite3BtreeNext()

SQLITE_PRIVATE int sqlite3BtreeNext ( BtCursor * pCur,
int flags )

Definition at line 70262 of file sqlite3.c.

70262 {
70263 return SQLITE_OK;
70264 }else{
70265 return moveToLeftmost(pCur);
70266 }
70267}
70268SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){
70269 MemPage *pPage;
70270 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
70271 assert( cursorOwnsBtShared(pCur) );
70272 assert( flags==0 || flags==1 );
70273 pCur->info.nSize = 0;
70275 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
70276 pPage = pCur->pPage;
70277 if( (++pCur->ix)>=pPage->nCell ){
70278 pCur->ix--;
70279 return btreeNext(pCur);
70280 }
static SQLITE_NOINLINE int btreeNext(BtCursor *pCur)
Definition sqlite3.c:70192

References SQLITE_OK.

Referenced by btreeNext(), resolveP2Values(), sqlite3BtreeMovetoUnpacked(), and sqlite3VdbeExec().

◆ sqlite3BtreeOpen()

SQLITE_PRIVATE int sqlite3BtreeOpen ( sqlite3_vfs * pVfs,
const char * zFilename,
sqlite3 * db,
Btree ** ppBtree,
int flags,
int vfsFlags )

Definition at line 66809 of file sqlite3.c.

66822 {
66823 BtShared *pBt = 0; /* Shared part of btree structure */
66824 Btree *p; /* Handle to return */
66825 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
66826 int rc = SQLITE_OK; /* Result code from this function */
66827 u8 nReserve; /* Byte of unused space on each page */
66828 unsigned char zDbHeader[100]; /* Database header content */
66829
66830 /* True if opening an ephemeral, temporary database */
66831 const int isTempDb = zFilename==0 || zFilename[0]==0;
66832
66833 /* Set the variable isMemdb to true for an in-memory database, or
66834 ** false for a file-based database.
66835 */
66836#ifdef SQLITE_OMIT_MEMORYDB
66837 const int isMemdb = 0;
66838#else
66839 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
66840 || (isTempDb && sqlite3TempInMemory(db))
66841 || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
66842#endif
66843
66844 assert( db!=0 );
66845 assert( pVfs!=0 );
66846 assert( sqlite3_mutex_held(db->mutex) );
66847 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
66848
66849 /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
66850 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
66851
66852 /* A BTREE_SINGLE database is always a temporary and/or ephemeral */
66853 assert( (flags & BTREE_SINGLE)==0 || isTempDb );
66854
66855 if( isMemdb ){
66856 flags |= BTREE_MEMORY;
66857 }
66858 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
66859 vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
66860 }
66861 p = sqlite3MallocZero(sizeof(Btree));
66862 if( !p ){
66863 return SQLITE_NOMEM_BKPT;
66864 }
66865 p->inTrans = TRANS_NONE;
66866 p->db = db;
66867#ifndef SQLITE_OMIT_SHARED_CACHE
66868 p->lock.pBtree = p;
66869 p->lock.iTable = 1;
66870#endif
66871
66872#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
66873 /*
66874 ** If this Btree is a candidate for shared cache, try to find an
66875 ** existing BtShared object that we can share with
66876 */
66877 if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
66878 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
66879 int nFilename = sqlite3Strlen30(zFilename)+1;
66880 int nFullPathname = pVfs->mxPathname+1;
66881 char *zFullPathname = sqlite3Malloc(MAX(nFullPathname,nFilename));
66882 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
66883
66884 p->sharable = 1;
66885 if( !zFullPathname ){
66886 sqlite3_free(p);
66887 return SQLITE_NOMEM_BKPT;
66888 }
66889 if( isMemdb ){
66890 memcpy(zFullPathname, zFilename, nFilename);
66891 }else{
66892 rc = sqlite3OsFullPathname(pVfs, zFilename,
66893 nFullPathname, zFullPathname);
66894 if( rc ){
66895 if( rc==SQLITE_OK_SYMLINK ){
66896 rc = SQLITE_OK;
66897 }else{
66898 sqlite3_free(zFullPathname);
66899 sqlite3_free(p);
66900 return rc;
66901 }
66902 }
66903 }
66904#if SQLITE_THREADSAFE
66906 sqlite3_mutex_enter(mutexOpen);
66908 sqlite3_mutex_enter(mutexShared);
66909#endif
66910 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
66911 assert( pBt->nRef>0 );
66912 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
66913 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
66914 int iDb;
66915 for(iDb=db->nDb-1; iDb>=0; iDb--){
66916 Btree *pExisting = db->aDb[iDb].pBt;
66917 if( pExisting && pExisting->pBt==pBt ){
66918 sqlite3_mutex_leave(mutexShared);
66919 sqlite3_mutex_leave(mutexOpen);
66920 sqlite3_free(zFullPathname);
66921 sqlite3_free(p);
66922 return SQLITE_CONSTRAINT;
66923 }
66924 }
66925 p->pBt = pBt;
66926 pBt->nRef++;
66927 break;
66928 }
66929 }
66930 sqlite3_mutex_leave(mutexShared);
66931 sqlite3_free(zFullPathname);
66932 }
66933#ifdef SQLITE_DEBUG
66934 else{
66935 /* In debug mode, we mark all persistent databases as sharable
66936 ** even when they are not. This exercises the locking code and
66937 ** gives more opportunity for asserts(sqlite3_mutex_held())
66938 ** statements to find locking problems.
66939 */
66940 p->sharable = 1;
66941 }
66942#endif
66943 }
66944#endif
66945 if( pBt==0 ){
66946 /*
66947 ** The following asserts make sure that structures used by the btree are
66948 ** the right size. This is to guard against size changes that result
66949 ** when compiling on a different architecture.
66950 */
66951 assert( sizeof(i64)==8 );
66952 assert( sizeof(u64)==8 );
66953 assert( sizeof(u32)==4 );
66954 assert( sizeof(u16)==2 );
66955 assert( sizeof(Pgno)==4 );
66956
66957 pBt = sqlite3MallocZero( sizeof(*pBt) );
66958 if( pBt==0 ){
66959 rc = SQLITE_NOMEM_BKPT;
66960 goto btree_open_out;
66961 }
66962 rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
66963 sizeof(MemPage), flags, vfsFlags, pageReinit);
66964 if( rc==SQLITE_OK ){
66966 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
66967 }
66968 if( rc!=SQLITE_OK ){
66969 goto btree_open_out;
66970 }
66971 pBt->openFlags = (u8)flags;
66972 pBt->db = db;
66974 p->pBt = pBt;
66975
66976 pBt->pCursor = 0;
66977 pBt->pPage1 = 0;
66979#if defined(SQLITE_SECURE_DELETE)
66981#elif defined(SQLITE_FAST_SECURE_DELETE)
66982 pBt->btsFlags |= BTS_OVERWRITE;
66983#endif
66984 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
66985 ** determined by the 2-byte integer located at an offset of 16 bytes from
66986 ** the beginning of the database file. */
66987 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
66988 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
66989 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
66990 pBt->pageSize = 0;
66991#ifndef SQLITE_OMIT_AUTOVACUUM
66992 /* If the magic name ":memory:" will create an in-memory database, then
66993 ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
66994 ** SQLITE_DEFAULT_AUTOVACUUM is true. On the other hand, if
66995 ** SQLITE_OMIT_MEMORYDB has been defined, then ":memory:" is just a
66996 ** regular file-name. In this case the auto-vacuum applies as per normal.
66997 */
66998 if( zFilename && !isMemdb ){
66999 pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
67000 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
67001 }
67002#endif
67003 nReserve = 0;
67004 }else{
67005 /* EVIDENCE-OF: R-37497-42412 The size of the reserved region is
67006 ** determined by the one-byte unsigned integer found at an offset of 20
67007 ** into the database file header. */
67008 nReserve = zDbHeader[20];
67010#ifndef SQLITE_OMIT_AUTOVACUUM
67011 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
67012 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
67013#endif
67014 }
67015 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
67016 if( rc ) goto btree_open_out;
67017 pBt->usableSize = pBt->pageSize - nReserve;
67018 assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
67019
67020#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
67021 /* Add the new BtShared object to the linked list sharable BtShareds.
67022 */
67023 pBt->nRef = 1;
67024 if( p->sharable ){
67025 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
67027 if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
67029 if( pBt->mutex==0 ){
67030 rc = SQLITE_NOMEM_BKPT;
67031 goto btree_open_out;
67032 }
67033 }
67034 sqlite3_mutex_enter(mutexShared);
67037 sqlite3_mutex_leave(mutexShared);
67038 }
67039#endif
67040 }
67041
67042#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
67043 /* If the new Btree uses a sharable pBtShared, then link the new
67044 ** Btree into the list of all sharable Btrees for the same connection.
67045 ** The list is kept in ascending order by pBt address.
67046 */
67047 if( p->sharable ){
67048 int i;
67049 Btree *pSib;
67050 for(i=0; i<db->nDb; i++){
67051 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
67052 while( pSib->pPrev ){ pSib = pSib->pPrev; }
67053 if( (uptr)p->pBt<(uptr)pSib->pBt ){
67054 p->pNext = pSib;
67055 p->pPrev = 0;
67056 pSib->pPrev = p;
67057 }else{
67058 while( pSib->pNext && (uptr)pSib->pNext->pBt<(uptr)p->pBt ){
67059 pSib = pSib->pNext;
67060 }
67061 p->pNext = pSib->pNext;
67062 p->pPrev = pSib;
67063 if( p->pNext ){
67064 p->pNext->pPrev = p;
67065 }
67066 pSib->pNext = p;
67067 }
67068 break;
67069 }
67070 }
67071 }
67072#endif
67073 *ppBtree = p;
67074
67075btree_open_out:
67076 if( rc!=SQLITE_OK ){
67077 if( pBt && pBt->pPager ){
67078 sqlite3PagerClose(pBt->pPager, 0);
67079 }
67080 sqlite3_free(pBt);
67081 sqlite3_free(p);
67082 *ppBtree = 0;
67083 }else{
67084 sqlite3_file *pFile;
67085
67086 /* If the B-Tree was successfully opened, set the pager-cache size to the
67087 ** default value. Except, when opening on an existing shared pager-cache,
67088 ** do not change the pager-cache size.
67089 */
67090 if( sqlite3BtreeSchema(p, 0, 0)==0 ){
67092 }
67093
67094 pFile = sqlite3PagerFile(pBt->pPager);
67095 if( pFile->pMethods ){
67096 sqlite3OsFileControlHint(pFile, SQLITE_FCNTL_PDB, (void*)&pBt->db);
67097 }
67098 }
67099 if( mutexOpen ){
SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *)
Definition sqlite3.c:23197
SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager *, int)
Definition sqlite3.c:55147
SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager *, int(*)(void *), void *)
Definition sqlite3.c:55341
#define BTREE_MEMORY
Definition sqlite3.c:15058
#define SQLITE_DEFAULT_AUTOVACUUM
Definition sqlite3.c:15026
#define SQLITE_OK_SYMLINK
Definition sqlite3.c:1592
#define SQLITE_DEFAULT_CACHE_SIZE
Definition sqlite3.c:13347
SQLITE_PRIVATE int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char *, int, int, int, void(*)(DbPage *))
Definition sqlite3.c:56342
#define BTREE_UNORDERED
Definition sqlite3.c:15060
SQLITE_PRIVATE const char * sqlite3PagerFilename(const Pager *, int)
Definition sqlite3.c:58677
SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager *, int, unsigned char *)
Definition sqlite3.c:55514
#define SQLITE_MUTEX_STATIC_OPEN
Definition sqlite3.c:8634
#define SQLITE_OPEN_MEMORY
Definition sqlite3.c:1608
static void pageReinit(DbPage *pData)
Definition sqlite3.c:66759
SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64)
Definition sqlite3.c:55178
#define BTREE_SINGLE
Definition sqlite3.c:15059
#define BTS_OVERWRITE
Definition sqlite3.c:63918
SQLITE_PRIVATE void * sqlite3BtreeSchema(Btree *, int, void(*)(void *))
Definition sqlite3.c:74857
#define SQLITE_FCNTL_PDB
Definition sqlite3.c:2207
u8 openFlags
Definition sqlite3.c:63881

References sqlite3::aDb, BtShared::autoVacuum, BTREE_MEMORY, BTREE_SINGLE, BTREE_UNORDERED, btreeInvokeBusyHandler(), BTS_OVERWRITE, BTS_PAGESIZE_FIXED, BTS_READ_ONLY, BTS_SECURE_DELETE, BtShared::btsFlags, Btree::db, BtShared::db, get4byte, GLOBAL, BtShared::incrVacuum, Btree::inTrans, BtLock::iTable, Btree::lock, MAX, sqlite3::mutex, BtShared::mutex, MUTEX_LOGIC, sqlite3_vfs::mxPathname, sqlite3::nDb, BtShared::nRef, BtShared::openFlags, pageReinit(), BtShared::pageSize, Db::pBt, Btree::pBt, BtLock::pBtree, BtShared::pCursor, sqlite3_file::pMethods, Btree::pNext, BtShared::pNext, BtShared::pPage1, BtShared::pPager, Btree::pPrev, Btree::sharable, sqlite3_free(), sqlite3_mutex_enter(), sqlite3_mutex_held(), sqlite3_mutex_leave(), sqlite3BtreeConnectionCount(), sqlite3BtreeSchema(), sqlite3GlobalConfig, sqlite3Malloc(), sqlite3MallocZero(), sqlite3MutexAlloc(), sqlite3OsFileControlHint(), sqlite3OsFullPathname(), sqlite3PagerClose(), sqlite3PagerFile(), sqlite3PagerFilename(), sqlite3PagerIsreadonly(), sqlite3PagerOpen(), sqlite3PagerReadFileheader(), sqlite3PagerSetBusyHandler(), sqlite3PagerSetCachesize(), sqlite3PagerSetMmapLimit(), sqlite3PagerSetPagesize(), sqlite3PagerVfs(), sqlite3SharedCacheList, sqlite3Strlen30(), sqlite3TempInMemory(), SQLITE_CONSTRAINT, SQLITE_DEFAULT_AUTOVACUUM, SQLITE_DEFAULT_CACHE_SIZE, SQLITE_FCNTL_PDB, SQLITE_MAX_PAGE_SIZE, SQLITE_MUTEX_FAST, SQLITE_MUTEX_STATIC_MAIN, SQLITE_MUTEX_STATIC_OPEN, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OK_SYMLINK, SQLITE_OPEN_MAIN_DB, SQLITE_OPEN_MEMORY, SQLITE_OPEN_SHAREDCACHE, SQLITE_OPEN_TEMP_DB, SQLITE_OPEN_URI, SQLITE_THREADSAFE, sqlite3::szMmap, TRANS_NONE, and BtShared::usableSize.

Referenced by attachFunc(), openDatabase(), and sqlite3VdbeExec().

◆ sqlite3BtreePager()

◆ sqlite3BtreePayload()

SQLITE_PRIVATE int sqlite3BtreePayload ( BtCursor * pCur,
u32 offset,
u32 amt,
void * pBuf )

◆ sqlite3BtreePayloadChecked()

SQLITE_PRIVATE int sqlite3BtreePayloadChecked ( BtCursor * pCur,
u32 offset,
u32 amt,
void * pBuf )

Definition at line 69489 of file sqlite3.c.

69493 : accessPayload(pCur, offset, amt, pBuf, 0);
69494}
69495SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
69496 if( pCur->eState==CURSOR_VALID ){
SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *, u32 offset, u32 amt, void *)
Definition sqlite3.c:69489

◆ sqlite3BtreePayloadFetch()

SQLITE_PRIVATE const void * sqlite3BtreePayloadFetch ( BtCursor * pCur,
u32 * pAmt )

Definition at line 69557 of file sqlite3.c.

References fetchPayload().

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreePayloadSize()

◆ sqlite3BtreePrevious()

SQLITE_PRIVATE int sqlite3BtreePrevious ( BtCursor * pCur,
int flags )

Definition at line 70351 of file sqlite3.c.

70351 {
70352 rc = SQLITE_OK;
70353 }
70354 }
70355 return rc;
70356}
70357SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){
70358 assert( cursorOwnsBtShared(pCur) );
70359 assert( flags==0 || flags==1 );
70360 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
70362 pCur->info.nSize = 0;
70363 if( pCur->eState!=CURSOR_VALID
70364 || pCur->ix==0
70365 || pCur->pPage->leaf==0

Referenced by btreePrevious(), resolveP2Values(), sqlite3BtreeDelete(), and sqlite3VdbeExec().

◆ sqlite3BtreePutData()

SQLITE_PRIVATE int sqlite3BtreePutData ( BtCursor * pCsr,
u32 offset,
u32 amt,
void * z )

Definition at line 74920 of file sqlite3.c.

74926 {
74927 int rc;
74928 assert( cursorOwnsBtShared(pCsr) );
74929 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
74930 assert( pCsr->curFlags & BTCF_Incrblob );
74931
74932 rc = restoreCursorPosition(pCsr);
74933 if( rc!=SQLITE_OK ){
74934 return rc;
74935 }
74936 assert( pCsr->eState!=CURSOR_REQUIRESEEK );
74937 if( pCsr->eState!=CURSOR_VALID ){
74938 return SQLITE_ABORT;
74939 }
74940
74941 /* Save the positions of all other cursors open on this table. This is
74942 ** required in case any of them are holding references to an xFetch
74943 ** version of the b-tree page modified by the accessPayload call below.
74944 **
74945 ** Note that pCsr must be open on a INTKEY table and saveCursorPosition()
74946 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
74947 ** saveAllCursors can only return SQLITE_OK.
74948 */
74949 VVA_ONLY(rc =) saveAllCursors(pCsr->pBt, pCsr->pgnoRoot, pCsr);
74950 assert( rc==SQLITE_OK );
74951
74952 /* Check some assumptions:
74953 ** (a) the cursor is open for writing,
74954 ** (b) there is a read/write transaction open,
74955 ** (c) the connection holds a write-lock on the table (if required),
74956 ** (d) there are no conflicting read-locks, and
74957 ** (e) the cursor points at a valid row of an intKey table.
74958 */
74959 if( (pCsr->curFlags & BTCF_WriteFlag)==0 ){
74960 return SQLITE_READONLY;
74961 }
74962 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
74963 && pCsr->pBt->inTransaction==TRANS_WRITE );

References BTCF_Incrblob, BTCF_WriteFlag, BTS_READ_ONLY, BtShared::btsFlags, BtCursor::curFlags, CURSOR_REQUIRESEEK, CURSOR_VALID, Btree::db, BtCursor::eState, MemPage::intKey, BtShared::inTransaction, sqlite3::mutex, BtCursor::pBt, BtCursor::pBtree, BtCursor::pgnoRoot, BtCursor::pPage, restoreCursorPosition, saveAllCursors(), sqlite3_mutex_held(), SQLITE_ABORT, SQLITE_OK, SQLITE_READONLY, TRANS_WRITE, and VVA_ONLY.

◆ sqlite3BtreeRollback()

SQLITE_PRIVATE int sqlite3BtreeRollback ( Btree * p,
int tripCode,
int writeOnly )

Definition at line 68682 of file sqlite3.c.

68688 {
68689 int rc;
68690 BtShared *pBt = p->pBt;
68691 MemPage *pPage1;
68692
68693 assert( writeOnly==1 || writeOnly==0 );
68694 assert( tripCode==SQLITE_ABORT_ROLLBACK || tripCode==SQLITE_OK );
68696 if( tripCode==SQLITE_OK ){
68697 rc = tripCode = saveAllCursors(pBt, 0, 0);
68698 if( rc ) writeOnly = 0;
68699 }else{
68700 rc = SQLITE_OK;
68701 }
68702 if( tripCode ){
68703 int rc2 = sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
68704 assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
68705 if( rc2!=SQLITE_OK ) rc = rc2;
68706 }
68707 btreeIntegrity(p);
68708
68709 if( p->inTrans==TRANS_WRITE ){
68710 int rc2;
68711
68712 assert( TRANS_WRITE==pBt->inTransaction );
68713 rc2 = sqlite3PagerRollback(pBt->pPager);
68714 if( rc2!=SQLITE_OK ){
68715 rc = rc2;
68716 }
68717
68718 /* The rollback may have destroyed the pPage1->aData value. So
68719 ** call btreeGetPage() on page 1 again to make
68720 ** sure pPage1->aData is set correctly. */
68721 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
68722 btreeSetNPage(pBt, pPage1);
68723 releasePageOne(pPage1);
68724 }
68725 assert( countValidCursors(pBt, 1)==0 );
#define SQLITE_ABORT_ROLLBACK
Definition sqlite3.c:1575
static void btreeSetNPage(BtShared *pBt, MemPage *pPage1)
Definition sqlite3.c:68663
SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree *, int, int)
Definition sqlite3.c:68631

References btreeClearHasContent(), btreeEndTransaction(), btreeGetPage(), btreeIntegrity, btreeSetNPage(), Btree::inTrans, BtShared::inTransaction, Btree::pBt, BtShared::pPager, releasePageOne(), saveAllCursors(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3BtreeTripAllCursors(), sqlite3PagerRollback(), SQLITE_ABORT_ROLLBACK, SQLITE_OK, TRANS_READ, and TRANS_WRITE.

Referenced by sqlite3RollbackAll().

◆ sqlite3BtreeRowCountEst()

SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst ( BtCursor * pCur)

Definition at line 70152 of file sqlite3.c.

70158 {
70159 i64 n;
70160 u8 i;
70161
70162 assert( cursorOwnsBtShared(pCur) );
70163 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
70164
70165 /* Currently this interface is only called by the OP_IfSmaller
70166 ** opcode, and it that case the cursor will always be valid and
70167 ** will always point to a leaf node. */
70168 if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
70169 if( NEVER(pCur->pPage->leaf==0) ) return -1;
70170

References BtCursor::apPage, CURSOR_VALID, Btree::db, BtCursor::eState, BtCursor::iPage, MemPage::leaf, sqlite3::mutex, MemPage::nCell, NEVER, BtCursor::pBtree, BtCursor::pPage, and sqlite3_mutex_held().

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeSavepoint()

SQLITE_PRIVATE int sqlite3BtreeSavepoint ( Btree * p,
int op,
int iSavepoint )

Definition at line 68778 of file sqlite3.c.

68784 {
68785 int rc = SQLITE_OK;
68786 if( p && p->inTrans==TRANS_WRITE ){
68787 BtShared *pBt = p->pBt;
68788 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
68789 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
68791 if( op==SAVEPOINT_ROLLBACK ){
68792 rc = saveAllCursors(pBt, 0, 0);
68793 }
68794 if( rc==SQLITE_OK ){
68795 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
68796 }
68797 if( rc==SQLITE_OK ){
68798 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
68799 pBt->nPage = 0;
68800 }
68801 rc = newDatabase(pBt);
68802 btreeSetNPage(pBt, pBt->pPage1);
68803
68804 /* pBt->nPage might be zero if the database was corrupt when
68805 ** the transaction was started. Otherwise, it must be at least 1. */
#define SAVEPOINT_RELEASE
Definition sqlite3.c:17296
SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint)
Definition sqlite3.c:58598
#define SAVEPOINT_ROLLBACK
Definition sqlite3.c:17297

References btreeSetNPage(), BTS_INITIALLY_EMPTY, BtShared::btsFlags, CORRUPT_DB, Btree::inTrans, newDatabase(), BtShared::nPage, Btree::pBt, BtShared::pPage1, BtShared::pPager, saveAllCursors(), SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerSavepoint(), SQLITE_OK, and TRANS_WRITE.

Referenced by sqlite3VdbeExec(), and vdbeCloseStatement().

◆ sqlite3BtreeSchema()

SQLITE_PRIVATE void * sqlite3BtreeSchema ( Btree * p,
int nBytes,
void(*)(void *) xFree )

Definition at line 74857 of file sqlite3.c.

74863 {
74864 BtShared *pBt = p->pBt;
74866 if( !pBt->pSchema && nBytes ){

References Btree::pBt, BtShared::pSchema, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3DbMallocZero(), and BtShared::xFreeSchema.

Referenced by sqlite3BtreeOpen().

◆ sqlite3BtreeSchemaLocked()

SQLITE_PRIVATE int sqlite3BtreeSchemaLocked ( Btree * pBtree)

◆ sqlite3BtreeSecureDelete()

SQLITE_PRIVATE int sqlite3BtreeSecureDelete ( Btree * p,
int newFlag )

Definition at line 67437 of file sqlite3.c.

67443 {
67444 int b;
67445 if( p==0 ) return 0;
67447 assert( BTS_OVERWRITE==BTS_SECURE_DELETE*2 );
67449 if( newFlag>=0 ){
67450 p->pBt->btsFlags &= ~BTS_FAST_SECURE;

References BTS_FAST_SECURE, BTS_OVERWRITE, BTS_SECURE_DELETE, BtShared::btsFlags, Btree::pBt, sqlite3BtreeEnter(), and sqlite3BtreeLeave().

Referenced by attachFunc(), and sqlite3Pragma().

◆ sqlite3BtreeSetAutoVacuum()

SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum ( Btree * p,
int autoVacuum )

Definition at line 67458 of file sqlite3.c.

67464 {
67465#ifdef SQLITE_OMIT_AUTOVACUUM
67466 return SQLITE_READONLY;
67467#else
67468 BtShared *pBt = p->pBt;
67469 int rc = SQLITE_OK;
67470 u8 av = (u8)autoVacuum;
67471
67473 if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
67474 rc = SQLITE_READONLY;
67475 }else{
67476 pBt->autoVacuum = av ?1:0;

References BtShared::autoVacuum, BTS_PAGESIZE_FIXED, BtShared::btsFlags, BtShared::incrVacuum, Btree::pBt, sqlite3BtreeEnter(), sqlite3BtreeLeave(), SQLITE_OK, and SQLITE_READONLY.

Referenced by sqlite3Pragma().

◆ sqlite3BtreeSetCacheSize()

SQLITE_PRIVATE int sqlite3BtreeSetCacheSize ( Btree * p,
int mxPage )

◆ sqlite3BtreeSetPagerFlags()

SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags ( Btree * p,
unsigned pgFlags )

◆ sqlite3BtreeSetPageSize()

SQLITE_PRIVATE int sqlite3BtreeSetPageSize ( Btree * p,
int nPagesize,
int nReserve,
int eFix )

Definition at line 67334 of file sqlite3.c.

67340 {
67341 int rc = SQLITE_OK;
67342 int x;
67343 BtShared *pBt = p->pBt;
67344 assert( nReserve>=0 && nReserve<=255 );
67346 pBt->nReserveWanted = nReserve;
67347 x = pBt->pageSize - pBt->usableSize;
67348 if( nReserve<x ) nReserve = x;
67349 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
67351 return SQLITE_READONLY;
67352 }
67353 assert( nReserve>=0 && nReserve<=255 );
67354 if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
67355 ((pageSize-1)&pageSize)==0 ){
67356 assert( (pageSize & 7)==0 );
67357 assert( !pBt->pCursor );
67358 pBt->pageSize = (u32)pageSize;
67359 freeTempSpace(pBt);
67360 }
u8 nReserveWanted
Definition sqlite3.c:63889

References BTS_PAGESIZE_FIXED, BtShared::btsFlags, freeTempSpace(), BtShared::nReserveWanted, BtShared::pageSize, Btree::pBt, BtShared::pCursor, BtShared::pPager, sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3PagerSetPagesize(), SQLITE_MAX_PAGE_SIZE, SQLITE_OK, SQLITE_READONLY, and BtShared::usableSize.

Referenced by sqlite3Pragma().

◆ sqlite3BtreeSetSpillSize()

SQLITE_PRIVATE int sqlite3BtreeSetSpillSize ( Btree * p,
int mxPage )

Definition at line 67267 of file sqlite3.c.

67273 {
67274 BtShared *pBt = p->pBt;
67275 int res;

References Btree::db, sqlite3::mutex, Btree::pBt, BtShared::pPager, sqlite3_mutex_held(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), and sqlite3PagerSetSpillsize().

Referenced by sqlite3Pragma().

◆ sqlite3BtreeSetVersion()

SQLITE_PRIVATE int sqlite3BtreeSetVersion ( Btree * pBt,
int iVersion )

Definition at line 74979 of file sqlite3.c.

74985 {
74986 BtShared *pBt = pBtree->pBt;
74987 int rc; /* Return code */
74988
74989 assert( iVersion==1 || iVersion==2 );
74990
74991 /* If setting the version fields to 1, do not automatically open the
74992 ** WAL connection, even if the version fields are currently set to 2.
74993 */
74994 pBt->btsFlags &= ~BTS_NO_WAL;
74995 if( iVersion==1 ) pBt->btsFlags |= BTS_NO_WAL;
74996
74997 rc = sqlite3BtreeBeginTrans(pBtree, 0, 0);
74998 if( rc==SQLITE_OK ){
74999 u8 *aData = pBt->pPage1->aData;
75000 if( aData[18]!=(u8)iVersion || aData[19]!=(u8)iVersion ){
75001 rc = sqlite3BtreeBeginTrans(pBtree, 2, 0);
75002 if( rc==SQLITE_OK ){
75003 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
75004 if( rc==SQLITE_OK ){
75005 aData[18] = (u8)iVersion;
75006 aData[19] = (u8)iVersion;
75007 }
75008 }

References MemPage::aData, BTS_NO_WAL, BtShared::btsFlags, Btree::pBt, MemPage::pDbPage, BtShared::pPage1, sqlite3BtreeBeginTrans(), sqlite3PagerWrite(), and SQLITE_OK.

Referenced by sqlite3VdbeExec().

◆ sqlite3BtreeSharable()

SQLITE_PRIVATE int sqlite3BtreeSharable ( Btree * p)

Definition at line 75034 of file sqlite3.c.

75034 { return ROUND8(sizeof(MemPage)); }
75035
75036#if !defined(SQLITE_OMIT_SHARED_CACHE)

References ROUND8.

Referenced by sqlite3TableLock(), and sqlite3VdbeUsesBtree().

◆ sqlite3BtreeTripAllCursors()

SQLITE_PRIVATE int sqlite3BtreeTripAllCursors ( Btree * pBtree,
int errCode,
int writeOnly )

Definition at line 68631 of file sqlite3.c.

68637 {
68638 BtCursor *p;
68639 int rc = SQLITE_OK;
68640
68641 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
68642 if( pBtree ){
68643 sqlite3BtreeEnter(pBtree);
68644 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
68645 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
68646 if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){
68647 rc = saveCursorPosition(p);
68648 if( rc!=SQLITE_OK ){
68649 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
68650 break;
68651 }
68652 }
68653 }else{
68655 p->eState = CURSOR_FAULT;
68656 p->skipNext = errCode;
68657 }

References BTCF_WriteFlag, btreeReleaseAllCursorPages(), BtCursor::curFlags, CURSOR_FAULT, CURSOR_SKIPNEXT, CURSOR_VALID, BtCursor::eState, Btree::pBt, BtShared::pCursor, BtCursor::pNext, saveCursorPosition(), BtCursor::skipNext, sqlite3BtreeClearCursor(), sqlite3BtreeEnter(), sqlite3BtreeLeave(), sqlite3BtreeTripAllCursors(), and SQLITE_OK.

Referenced by sqlite3BtreeRollback(), sqlite3BtreeTripAllCursors(), and sqlite3VdbeExec().

◆ sqlite3BtreeUpdateMeta()

SQLITE_PRIVATE int sqlite3BtreeUpdateMeta ( Btree * p,
int idx,
u32 value )

Definition at line 73994 of file sqlite3.c.

74000 {
74001 BtShared *pBt = p->pBt;
74002 unsigned char *pP1;
74003 int rc;
74004 assert( idx>=1 && idx<=15 );
74006 assert( p->inTrans==TRANS_WRITE );
74007 assert( pBt->pPage1!=0 );
74008 pP1 = pBt->pPage1->aData;
74009 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
74010 if( rc==SQLITE_OK ){
74011 put4byte(&pP1[36 + idx*4], iMeta);
74012#ifndef SQLITE_OMIT_AUTOVACUUM
74013 if( idx==BTREE_INCR_VACUUM ){
74014 assert( pBt->autoVacuum || iMeta==0 );
74015 assert( iMeta==0 || iMeta==1 );
74016 pBt->incrVacuum = (u8)iMeta;
#define BTREE_INCR_VACUUM
Definition sqlite3.c:15148

Referenced by btreeCreateTable(), btreeDropTable(), and sqlite3VdbeExec().

◆ sqlite3CantopenError()

SQLITE_PRIVATE int sqlite3CantopenError ( int lineno)

Definition at line 164595 of file sqlite3.c.

164597 {
164598 testcase( sqlite3GlobalConfig.xLog!=0 );

◆ sqlite3ChangeCookie()

SQLITE_PRIVATE void sqlite3ChangeCookie ( Parse * pParse,
int iDb )

Definition at line 112136 of file sqlite3.c.

112139 : R-34230-56049 SQLite automatically increments
112140** the schema-version whenever the schema changes.
112141*/
112142SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){
SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *, int)
Definition sqlite3.c:112136

References sqlite3::aDb, BTREE_SCHEMA_VERSION, Parse::db, OP_SetCookie, Db::pSchema, Parse::pVdbe, Schema::schema_cookie, and sqlite3VdbeAddOp3().

Referenced by sqlite3CreateIndex(), and sqlite3EndTable().

◆ sqlite3CheckCollSeq()

SQLITE_PRIVATE int sqlite3CheckCollSeq ( Parse * pParse,
CollSeq * pColl )

Definition at line 115615 of file sqlite3.c.

115621 {
115622 if( pColl && pColl->xCmp==0 ){
115623 const char *zName = pColl->zName;
115624 sqlite3 *db = pParse->db;
115625 CollSeq *p = sqlite3GetCollSeq(pParse, ENC(db), pColl, zName);
115626 if( !p ){
SQLITE_PRIVATE CollSeq * sqlite3GetCollSeq(Parse *, u8, CollSeq *, const char *)
Definition sqlite3.c:115740

References Parse::db, ENC, sqlite3GetCollSeq(), SQLITE_ERROR, SQLITE_OK, CollSeq::xCmp, CollSeq::zName, and zName.

Referenced by sqlite3ExprCollSeq().

◆ sqlite3CheckObjectName()

SQLITE_PRIVATE int sqlite3CheckObjectName ( Parse * pParse,
const char * zName,
const char * zType,
const char * zTblName )

Definition at line 111272 of file sqlite3.c.

111283 {
111284 sqlite3 *db = pParse->db;
111285 if( sqlite3WritableSchema(db)
111286 || db->init.imposterTable
111288 ){
111289 /* Skip these error checks for writable_schema=ON */
111290 return SQLITE_OK;
111291 }
111292 if( db->init.busy ){
111293 if( sqlite3_stricmp(zType, db->init.azInit[0])
111294 || sqlite3_stricmp(zName, db->init.azInit[1])
111295 || sqlite3_stricmp(zTblName, db->init.azInit[2])
111296 ){
111297 sqlite3ErrorMsg(pParse, ""); /* corruptSchema() will supply the error */
111298 return SQLITE_ERROR;
111299 }
111300 }else{
111301 if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
111303 ){
111304 sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s",
111305 zName);
SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName)
Definition sqlite3.c:112599
u8 bExtraSchemaChecks
Definition sqlite3.c:19015

References sqlite3::sqlite3InitInfo::azInit, Sqlite3Config::bExtraSchemaChecks, sqlite3::sqlite3InitInfo::busy, Parse::db, sqlite3::sqlite3InitInfo::imposterTable, sqlite3::init, Parse::nested, sqlite3_stricmp(), sqlite3Config, sqlite3ErrorMsg(), sqlite3ReadOnlyShadowTables(), sqlite3ShadowTableName(), sqlite3StrNICmp, sqlite3WritableSchema(), SQLITE_ERROR, SQLITE_OK, and zName.

Referenced by sqlite3BeginTrigger(), sqlite3CreateIndex(), and sqlite3StartTable().

◆ sqlite3Checkpoint()

SQLITE_PRIVATE int sqlite3Checkpoint ( sqlite3 * db,
int iDb,
int eMode,
int * pnLog,
int * pnCkpt )

Definition at line 163418 of file sqlite3.c.

163424 {
163425 int rc = SQLITE_OK; /* Return code */
163426 int i; /* Used to iterate through attached dbs */
163427 int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
163428
163429 assert( sqlite3_mutex_held(db->mutex) );
163430 assert( !pnLog || *pnLog==-1 );
163431 assert( !pnCkpt || *pnCkpt==-1 );
163432
163433 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
163434 if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
163435 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
163436 pnLog = 0;
163437 pnCkpt = 0;
163438 if( rc==SQLITE_BUSY ){
163439 bBusy = 1;
163440 rc = SQLITE_OK;
SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree *, int, int *, int *)
Definition sqlite3.c:74806

References sqlite3::aDb, sqlite3::mutex, sqlite3::nDb, Db::pBt, sqlite3_mutex_held(), sqlite3BtreeCheckpoint(), SQLITE_BUSY, SQLITE_MAX_ATTACHED, and SQLITE_OK.

Referenced by sqlite3VdbeExec().

◆ sqlite3ClearStatTables()

static void sqlite3ClearStatTables ( Parse * pParse,
int iDb,
const char * zType,
const char * zName )
static

Definition at line 113307 of file sqlite3.c.

113318 {
113319 int i;
113320 const char *zDbName = pParse->db->aDb[iDb].zDbSName;
113321 for(i=1; i<=4; i++){
113322 char zTab[24];
113323 sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
113324 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
113325 sqlite3NestedParse(pParse,

◆ sqlite3ClearTempRegCache()

SQLITE_PRIVATE void sqlite3ClearTempRegCache ( Parse * pParse)

◆ sqlite3Close()

static int sqlite3Close ( sqlite3 * db,
int forceZombie )
static

Definition at line 162187 of file sqlite3.c.

162193 {
162194 if( !db ){
162195 /* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
162196 ** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
162197 return SQLITE_OK;
162198 }
162199 if( !sqlite3SafetyCheckSickOrOk(db) ){
162200 return SQLITE_MISUSE_BKPT;
162201 }
162203 if( db->mTrace & SQLITE_TRACE_CLOSE ){
162204 db->trace.xV2(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0);
162205 }
162206
162207 /* Force xDisconnect calls on all virtual tables */
162208 disconnectAllVtab(db);
162209
162210 /* If a transaction is open, the disconnectAllVtab() call above
162211 ** will not have called the xDisconnect() method on any virtual
162212 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
162213 ** call will do so. We need to do this before the check for active
162214 ** SQL statements below, as the v-table implementation may be storing
162215 ** some prepared statements internally.
162216 */
162218
162219 /* Legacy behavior (sqlite3_close() behavior) is to return
162220 ** SQLITE_BUSY if the connection can not be closed immediately.
162221 */
162222 if( !forceZombie && connectionIsBusy(db) ){
162223 sqlite3ErrorWithMsg(db, SQLITE_BUSY, "unable to close due to unfinalized "
162224 "statements or unfinished backups");
162226 return SQLITE_BUSY;
162227 }
162228
162229#ifdef SQLITE_ENABLE_SQLLOG
162230 if( sqlite3GlobalConfig.xSqllog ){
162231 /* Closing the handle. Fourth parameter is passed the value 2. */
162232 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
162233 }
162234#endif
162235
static void disconnectAllVtab(sqlite3 *db)
Definition sqlite3.c:162142
static int connectionIsBusy(sqlite3 *db)
Definition sqlite3.c:162173
SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db)
Definition sqlite3.c:140542
#define SQLITE_TRACE_CLOSE
Definition sqlite3.c:4247
int(* xV2)(u32, void *, void *, void *)
Definition sqlite3.c:16873
union sqlite3::@104 trace

Referenced by sqlite3_close_v2().

◆ sqlite3CloseExtensions()

SQLITE_PRIVATE void sqlite3CloseExtensions ( sqlite3 * db)

Definition at line 124894 of file sqlite3.c.

124900 {
124901 int i;

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ sqlite3CloseSavepoints()

SQLITE_PRIVATE void sqlite3CloseSavepoints ( sqlite3 * db)

Definition at line 162110 of file sqlite3.c.

162116 {
162117 while( db->pSavepoint ){
162118 Savepoint *pTmp = db->pSavepoint;
162119 db->pSavepoint = pTmp->pNext;
Savepoint * pNext
Definition sqlite3.c:17288
Savepoint * pSavepoint
Definition sqlite3.c:16927

References sqlite3::isTransactionSavepoint, sqlite3::nSavepoint, sqlite3::nStatement, Savepoint::pNext, sqlite3::pSavepoint, and sqlite3DbFree().

Referenced by sqlite3LeaveMutexAndCloseZombie(), sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3CodeDropTable()

SQLITE_PRIVATE void sqlite3CodeDropTable ( Parse * pParse,
Table * pTab,
int iDb,
int isView )

Definition at line 113330 of file sqlite3.c.

113336 {
113337 Vdbe *v;
113338 sqlite3 *db = pParse->db;
113339 Trigger *pTrigger;
113340 Db *pDb = &db->aDb[iDb];
113341
113342 v = sqlite3GetVdbe(pParse);
113343 assert( v!=0 );
113344 sqlite3BeginWriteOperation(pParse, 1, iDb);
113345
113346#ifndef SQLITE_OMIT_VIRTUALTABLE
113347 if( IsVirtual(pTab) ){
113349 }
113350#endif
113351
113352 /* Drop all triggers associated with the table being dropped. Code
113353 ** is generated to remove entries from sqlite_schema and/or
113354 ** sqlite_temp_schema if required.
113355 */
113356 pTrigger = sqlite3TriggerList(pParse, pTab);
113357 while( pTrigger ){
113358 assert( pTrigger->pSchema==pTab->pSchema ||
113359 pTrigger->pSchema==db->aDb[1].pSchema );
113360 sqlite3DropTriggerPtr(pParse, pTrigger);
113361 pTrigger = pTrigger->pNext;
113362 }
113363
113364#ifndef SQLITE_OMIT_AUTOINCREMENT
113365 /* Remove any entries of the sqlite_sequence table associated with
113366 ** the table being dropped. This is done before the table is dropped
113367 ** at the btree level, in case the sqlite_sequence table needs to
113368 ** move as a result of the drop (can happen in auto-vacuum mode).
113369 */
113370 if( pTab->tabFlags & TF_Autoincrement ){
113371 sqlite3NestedParse(pParse,
113372 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
113373 pDb->zDbSName, pTab->zName
113374 );
113375 }
113376#endif
113377
113378 /* Drop all entries in the schema table that refer to the
113379 ** table. The program name loops through the schema table and deletes
113380 ** every row that refers to a table of the same name as the one being
113381 ** dropped. Triggers are handled separately because a trigger can be
113382 ** created in the temp database that refers to a table in another
113383 ** database.
113384 */
113385 sqlite3NestedParse(pParse,
113386 "DELETE FROM %Q." DFLT_SCHEMA_TABLE
113387 " WHERE tbl_name=%Q and type!='trigger'",
113388 pDb->zDbSName, pTab->zName);
113389 if( !isView && !IsVirtual(pTab) ){
113390 destroyTable(pParse, pTab);
113391 }
113392
113393 /* Remove the table entry from SQLite's internal schema and modify
113394 ** the schema cookie.
113395 */
113396 if( IsVirtual(pTab) ){
113397 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
SQLITE_PRIVATE Trigger * sqlite3TriggerList(Parse *, Table *)
Definition sqlite3.c:136434
#define OP_VBegin
Definition sqlite3.c:15728
SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse *, Trigger *)
Definition sqlite3.c:137006
#define OP_VDestroy
Definition sqlite3.c:15730
static void destroyTable(Parse *pParse, Table *pTab)
Definition sqlite3.c:113258
Trigger * pNext
Definition sqlite3.c:18882

◆ sqlite3CodeRhsOfIN()

SQLITE_PRIVATE void sqlite3CodeRhsOfIN ( Parse * pParse,
Expr * pExpr,
int iTab )

Definition at line 102537 of file sqlite3.c.

102547 {
102548 int addrOnce = 0; /* Address of the OP_Once instruction at top */
102549 int addr; /* Address of OP_OpenEphemeral instruction */
102550 Expr *pLeft; /* the LHS of the IN operator */
102551 KeyInfo *pKeyInfo = 0; /* Key information */
102552 int nVal; /* Size of vector pLeft */
102553 Vdbe *v; /* The prepared statement under construction */
102554
102555 v = pParse->pVdbe;
102556 assert( v!=0 );
102557
102558 /* The evaluation of the IN must be repeated every time it
102559 ** is encountered if any of the following is true:
102560 **
102561 ** * The right-hand side is a correlated subquery
102562 ** * The right-hand side is an expression list containing variables
102563 ** * We are inside a trigger
102564 **
102565 ** If all of the above are false, then we can compute the RHS just once
102566 ** and reuse it many names.
102567 */
102568 if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
102569 /* Reuse of the RHS is allowed */
102570 /* If this routine has already been coded, but the previous code
102571 ** might not have been invoked yet, so invoke it now as a subroutine.
102572 */
102573 if( ExprHasProperty(pExpr, EP_Subrtn) ){
102574 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
102575 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
102576 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
102577 pExpr->x.pSelect->selId));
102578 }
102580 pExpr->y.sub.iAddr);
102581 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
102582 sqlite3VdbeJumpHere(v, addrOnce);
102583 return;
102584 }
102585
102586 /* Begin coding the subroutine */
102587 ExprSetProperty(pExpr, EP_Subrtn);
102588 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
102589 pExpr->y.sub.regReturn = ++pParse->nMem;
102590 pExpr->y.sub.iAddr =
102591 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
102592 VdbeComment((v, "return address"));
102593
102594 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
102595 }
102596
102597 /* Check to see if this is a vector IN operator */
102598 pLeft = pExpr->pLeft;
102599 nVal = sqlite3ExprVectorSize(pLeft);
102600
102601 /* Construct the ephemeral table that will contain the content of
102602 ** RHS of the IN operator.
102603 */
102604 pExpr->iTable = iTab;
102605 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
102606#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
102607 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
102608 VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
102609 }else{
102610 VdbeComment((v, "RHS of IN operator"));
102611 }
102612#endif
102613 pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
102614
102615 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
102616 /* Case 1: expr IN (SELECT ...)
102617 **
102618 ** Generate code to write the results of the select into the temporary
102619 ** table allocated and opened above.
102620 */
102621 Select *pSelect = pExpr->x.pSelect;
102622 ExprList *pEList = pSelect->pEList;
102623
102624 ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
102625 addrOnce?"":"CORRELATED ", pSelect->selId
102626 ));
102627 /* If the LHS and RHS of the IN operator do not match, that
102628 ** error will have been caught long before we reach this point. */
102629 if( ALWAYS(pEList->nExpr==nVal) ){
102630 SelectDest dest;
102631 int i;
102632 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
102633 dest.zAffSdst = exprINAffinity(pParse, pExpr);
102634 pSelect->iLimit = 0;
102635 testcase( pSelect->selFlags & SF_Distinct );
102636 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
102637 if( sqlite3Select(pParse, pSelect, &dest) ){
102638 sqlite3DbFree(pParse->db, dest.zAffSdst);
102639 sqlite3KeyInfoUnref(pKeyInfo);
102640 return;
102641 }
102642 sqlite3DbFree(pParse->db, dest.zAffSdst);
102643 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
102644 assert( pEList!=0 );
102645 assert( pEList->nExpr>0 );
102646 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
102647 for(i=0; i<nVal; i++){
102648 Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
102649 pKeyInfo->aColl[i] = sqlite3BinaryCompareCollSeq(
102650 pParse, p, pEList->a[i].pExpr
102651 );
102652 }
102653 }
102654 }else if( ALWAYS(pExpr->x.pList!=0) ){
102655 /* Case 2: expr IN (exprlist)
102656 **
102657 ** For each expression, build an index key from the evaluation and
102658 ** store it in the temporary table. If <expr> is a column, then use
102659 ** that columns affinity when building index keys. If <expr> is not
102660 ** a column, use numeric affinity.
102661 */
102662 char affinity; /* Affinity of the LHS of the IN */
102663 int i;
102664 ExprList *pList = pExpr->x.pList;
102665 struct ExprList_item *pItem;
102666 int r1, r2;
102667 affinity = sqlite3ExprAffinity(pLeft);
102668 if( affinity<=SQLITE_AFF_NONE ){
102669 affinity = SQLITE_AFF_BLOB;
102670 }else if( affinity==SQLITE_AFF_REAL ){
102671 affinity = SQLITE_AFF_NUMERIC;
102672 }
102673 if( pKeyInfo ){
102674 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
102675 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
102676 }
102677
102678 /* Loop through each expression in <exprlist>. */
102679 r1 = sqlite3GetTempReg(pParse);
102680 r2 = sqlite3GetTempReg(pParse);
102681 for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
102682 Expr *pE2 = pItem->pExpr;
102683
102684 /* If the expression is not constant then we will need to
102685 ** disable the test that was generated above that makes sure
102686 ** this code only executes once. Because for a non-constant
102687 ** expression we need to rerun this code each time.
102688 */
102689 if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
102690 sqlite3VdbeChangeToNoop(v, addrOnce);
102692 addrOnce = 0;
102693 }
102694
102695 /* Evaluate the expression and insert it into the temp table */
102696 sqlite3ExprCode(pParse, pE2, r1);
102697 sqlite3VdbeAddOp4(v, OP_MakeRecord, r1, 1, r2, &affinity, 1);
102698 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r1, 1);
102699 }
102700 sqlite3ReleaseTempReg(pParse, r1);
102701 sqlite3ReleaseTempReg(pParse, r2);
102702 }
102703 if( pKeyInfo ){
102704 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
102705 }
102706 if( addrOnce ){
102707 sqlite3VdbeJumpHere(v, addrOnce);
static char * exprINAffinity(Parse *pParse, Expr *pExpr)
Definition sqlite3.c:102452
#define EP_Subrtn
Definition sqlite3.c:18085
#define OP_OpenDup
Definition sqlite3.c:15664
struct Expr::@109::@110 sub
int iAddr
Definition sqlite3.c:18047
int regReturn
Definition sqlite3.c:18048
int iSelfTab
Definition sqlite3.c:18700

References ExprList::a, KeyInfo::aColl, ALWAYS, Parse::db, EP_Reduced, EP_Subrtn, EP_TokenOnly, EP_VarSelect, EP_xIsSelect, ExplainQueryPlan, ExprClearProperty, ExprHasProperty, exprINAffinity(), ExprSetProperty, Expr::iAddr, Select::iLimit, Parse::iSelfTab, Expr::iTable, ExprList::nExpr, Parse::nMem, OP_Gosub, OP_IdxInsert, OP_Integer, OP_MakeRecord, OP_Once, OP_OpenDup, OP_OpenEphemeral, OP_Return, P4_KEYINFO, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pSelect, Parse::pVdbe, Expr::regReturn, Select::selFlags, Select::selId, SF_Distinct, sqlite3BinaryCompareCollSeq(), sqlite3ClearTempRegCache(), sqlite3DbFree(), sqlite3ExprAffinity(), sqlite3ExprCode(), sqlite3ExprCollSeq(), sqlite3ExprIsConstant(), sqlite3ExprVectorSize(), sqlite3GetTempReg(), sqlite3KeyInfoAlloc(), sqlite3KeyInfoUnref(), sqlite3ReleaseTempReg(), sqlite3Select(), sqlite3SelectDestInit(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP1(), sqlite3VdbeChangeP4(), sqlite3VdbeChangeToNoop(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), sqlite3VectorFieldSubexpr(), SQLITE_AFF_BLOB, SQLITE_AFF_NONE, SQLITE_AFF_NUMERIC, SQLITE_AFF_REAL, SRT_Set, Expr::sub, testcase, VdbeComment, VdbeCoverage, Expr::x, Expr::y, and SelectDest::zAffSdst.

Referenced by sqlite3FindInIndex().

◆ sqlite3CodeRowTrigger()

SQLITE_PRIVATE void sqlite3CodeRowTrigger ( Parse * pParse,
Trigger * pTrigger,
int op,
ExprList * pChanges,
int tr_tm,
Table * pTab,
int reg,
int orconf,
int ignoreJump )

Definition at line 137501 of file sqlite3.c.

137517 {
137518 Trigger *p; /* Used to iterate through pTrigger list */
137519
137520 assert( op==TK_UPDATE || op==TK_INSERT || op==TK_DELETE );
137521 assert( tr_tm==TRIGGER_BEFORE || tr_tm==TRIGGER_AFTER );
137522 assert( (op==TK_UPDATE)==(pChanges!=0) );
137523
137524 for(p=pTrigger; p; p=p->pNext){
137525
137526 /* Sanity checking: The schema for the trigger and for the table are
137527 ** always defined. The trigger must be in the same schema as the table
137528 ** or else it must be a TEMP trigger. */
137529 assert( p->pSchema!=0 );
137530 assert( p->pTabSchema!=0 );
137531 assert( p->pSchema==p->pTabSchema
137532 || p->pSchema==pParse->db->aDb[1].pSchema );
137533
137534 /* Determine whether we should code this trigger */
137535 if( p->op==op
137536 && p->tr_tm==tr_tm

References sqlite3::aDb, checkColumnOverlap(), Parse::db, Trigger::op, Trigger::pColumns, Trigger::pNext, Db::pSchema, Trigger::pSchema, Trigger::pTabSchema, sqlite3CodeRowTriggerDirect(), TK_DELETE, TK_INSERT, TK_UPDATE, Trigger::tr_tm, TRIGGER_AFTER, and TRIGGER_BEFORE.

Referenced by sqlite3GenerateRowDelete(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3CodeRowTriggerDirect()

SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect ( Parse * pParse,
Trigger * p,
Table * pTab,
int reg,
int orconf,
int ignoreJump )

Definition at line 137429 of file sqlite3.c.

137442 {
137443 Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
137444 TriggerPrg *pPrg;
137445 pPrg = getRowTrigger(pParse, p, pTab, orconf);
137446 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
137447
137448 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
137449 ** is a pointer to the sub-vdbe containing the trigger program. */
137450 if( pPrg ){
137451 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
137452
137453 sqlite3VdbeAddOp4(v, OP_Program, reg, ignoreJump, ++pParse->nMem,
137454 (const char *)pPrg->pProgram, P4_SUBPROGRAM);
137455 VdbeComment(
137456 (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf)));
137457
137458 /* Set the P5 operand of the OP_Program instruction to non-zero if
137459 ** recursive invocation of this trigger program is disallowed. Recursive
static TriggerPrg * getRowTrigger(Parse *pParse, Trigger *pTrigger, Table *pTab, int orconf)
Definition sqlite3.c:137395
#define OP_Program
Definition sqlite3.c:15612
#define P4_SUBPROGRAM
Definition sqlite3.c:15509

References Parse::db, sqlite3::flags, getRowTrigger(), sqlite3::mallocFailed, Parse::nErr, Parse::nMem, OP_Program, P4_SUBPROGRAM, TriggerPrg::pProgram, sqlite3GetVdbe(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), SQLITE_RecTriggers, VdbeComment, and Trigger::zName.

Referenced by sqlite3CodeRowTrigger().

◆ sqlite3CodeSubselect()

SQLITE_PRIVATE int sqlite3CodeSubselect ( Parse * pParse,
Expr * pExpr )

Definition at line 102725 of file sqlite3.c.

102731 {
102732 int addrOnce = 0; /* Address of OP_Once at top of subroutine */
102733 int rReg = 0; /* Register storing resulting */
102734 Select *pSel; /* SELECT statement to encode */
102735 SelectDest dest; /* How to deal with SELECT result */
102736 int nReg; /* Registers to allocate */
102737 Expr *pLimit; /* New limit expression */
102738
102739 Vdbe *v = pParse->pVdbe;
102740 assert( v!=0 );
102741 testcase( pExpr->op==TK_EXISTS );
102742 testcase( pExpr->op==TK_SELECT );
102743 assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
102744 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
102745 pSel = pExpr->x.pSelect;
102746
102747 /* The evaluation of the EXISTS/SELECT must be repeated every time it
102748 ** is encountered if any of the following is true:
102749 **
102750 ** * The right-hand side is a correlated subquery
102751 ** * The right-hand side is an expression list containing variables
102752 ** * We are inside a trigger
102753 **
102754 ** If all of the above are false, then we can run this code just once
102755 ** save the results, and reuse the same result on subsequent invocations.
102756 */
102757 if( !ExprHasProperty(pExpr, EP_VarSelect) ){
102758 /* If this routine has already been coded, then invoke it as a
102759 ** subroutine. */
102760 if( ExprHasProperty(pExpr, EP_Subrtn) ){
102761 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
102763 pExpr->y.sub.iAddr);
102764 return pExpr->iTable;
102765 }
102766
102767 /* Begin coding the subroutine */
102768 ExprSetProperty(pExpr, EP_Subrtn);
102769 pExpr->y.sub.regReturn = ++pParse->nMem;
102770 pExpr->y.sub.iAddr =
102771 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
102772 VdbeComment((v, "return address"));
102773
102774 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
102775 }
102776
102777 /* For a SELECT, generate code to put the values for all columns of
102778 ** the first row into an array of registers and return the index of
102779 ** the first register.
102780 **
102781 ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
102782 ** into a register and return that register number.
102783 **
102784 ** In both cases, the query is augmented with "LIMIT 1". Any
102785 ** preexisting limit is discarded in place of the new LIMIT 1.
102786 */
102787 ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
102788 addrOnce?"":"CORRELATED ", pSel->selId));
102789 nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
102790 sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
102791 pParse->nMem += nReg;
102792 if( pExpr->op==TK_SELECT ){
102793 dest.eDest = SRT_Mem;
102794 dest.iSdst = dest.iSDParm;
102795 dest.nSdst = nReg;
102796 sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
102797 VdbeComment((v, "Init subquery result"));
102798 }else{
102799 dest.eDest = SRT_Exists;
102800 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
102801 VdbeComment((v, "Init EXISTS result"));
102802 }
102803 if( pSel->pLimit ){
102804 /* The subquery already has a limit. If the pre-existing limit is X
102805 ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
102806 sqlite3 *db = pParse->db;
102807 pLimit = sqlite3Expr(db, TK_INTEGER, "0");
102808 if( pLimit ){
102809 pLimit->affExpr = SQLITE_AFF_NUMERIC;
102810 pLimit = sqlite3PExpr(pParse, TK_NE,
102811 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
102812 }
102813 sqlite3ExprDelete(db, pSel->pLimit->pLeft);
102814 pSel->pLimit->pLeft = pLimit;
102815 }else{
102816 /* If there is no pre-existing limit add a limit of 1 */
102817 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
102818 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
102819 }
102820 pSel->iLimit = 0;
102821 if( sqlite3Select(pParse, pSel, &dest) ){
102822 return 0;
102823 }
102824 pExpr->iTable = rReg = dest.iSDParm;
102826 if( addrOnce ){
102827 sqlite3VdbeJumpHere(v, addrOnce);
102828
102829 /* Subroutine return */
#define OP_Return
Definition sqlite3.c:15631

References Expr::affExpr, Parse::db, SelectDest::eDest, EP_NoReduce, EP_Subrtn, EP_VarSelect, EP_xIsSelect, ExplainQueryPlan, ExprHasProperty, ExprSetProperty, ExprSetVVAProperty, Expr::iAddr, Select::iLimit, SelectDest::iSDParm, SelectDest::iSdst, Expr::iTable, ExprList::nExpr, Parse::nMem, SelectDest::nSdst, Expr::op, OP_Gosub, OP_Integer, OP_Null, OP_Once, OP_Return, Select::pEList, Expr::pLeft, Select::pLimit, Expr::pSelect, Parse::pVdbe, Expr::regReturn, Select::selId, sqlite3ClearTempRegCache(), sqlite3Expr(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3PExpr(), sqlite3Select(), sqlite3SelectDestInit(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP1(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), SQLITE_AFF_NUMERIC, SRT_Exists, SRT_Mem, Expr::sub, testcase, TK_EXISTS, TK_INTEGER, TK_LIMIT, TK_NE, TK_SELECT, VdbeComment, VdbeCoverage, Expr::x, and Expr::y.

Referenced by codeExprOrVector(), exprCodeSubselect(), exprCodeVector(), and sqlite3ExprCodeTarget().

◆ sqlite3CodeVerifyNamedSchema()

SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema ( Parse * pParse,
const char * zDb )

Definition at line 115145 of file sqlite3.c.

115151 {
115152 sqlite3 *db = pParse->db;
115153 int i;
115154 for(i=0; i<db->nDb; i++){

Referenced by sqlite3DropTrigger(), and sqlite3Pragma().

◆ sqlite3CodeVerifySchema()

SQLITE_PRIVATE void sqlite3CodeVerifySchema ( Parse * pParse,
int iDb )

Definition at line 115126 of file sqlite3.c.

115132 {
115133 Parse *pToplevel = sqlite3ParseToplevel(pParse);
115134
115135 assert( iDb>=0 && iDb<pParse->db->nDb );
115136 assert( pParse->db->aDb[iDb].pBt!=0 || iDb==1 );
115137 assert( iDb<SQLITE_MAX_ATTACHED+2 );
115138 assert( sqlite3SchemaMutexHeld(pParse->db, iDb, 0) );
115139 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
#define DbMaskTest(M, I)
Definition sqlite3.c:18656
yDbMask cookieMask
Definition sqlite3.c:18708

References sqlite3::aDb, Parse::cookieMask, Parse::db, DbMaskSet, DbMaskTest, sqlite3::nDb, OMIT_TEMPDB, Db::pBt, sqlite3OpenTempDatabase(), sqlite3ParseToplevel, and SQLITE_MAX_ATTACHED.

Referenced by sqlite3BeginTrigger(), sqlite3BeginWriteOperation(), sqlite3CreateIndex(), sqlite3FindInIndex(), sqlite3Pragma(), sqlite3Select(), sqlite3StartTable(), sqlite3WhereBegin(), and xferOptimization().

◆ sqlite3CollapseDatabaseArray()

SQLITE_PRIVATE void sqlite3CollapseDatabaseArray ( sqlite3 * db)

Definition at line 110938 of file sqlite3.c.

110944 {
110945 int i, j;
110946 for(i=j=2; i<db->nDb; i++){
110947 struct Db *pDb = &db->aDb[i];
110948 if( pDb->pBt==0 ){
110949 sqlite3DbFree(db, pDb->zDbSName);
110950 pDb->zDbSName = 0;
110951 continue;
110952 }
110953 if( j<i ){
110954 db->aDb[j] = db->aDb[i];
110955 }
110956 j++;
110957 }
110958 db->nDb = j;

References sqlite3::aDb, sqlite3::aDbStatic, sqlite3::nDb, Db::pBt, sqlite3DbFree(), and Db::zDbSName.

Referenced by detachFunc(), and sqlite3LeaveMutexAndCloseZombie().

◆ sqlite3ColumnDefault()

SQLITE_PRIVATE void sqlite3ColumnDefault ( Vdbe * v,
Table * pTab,
int i,
int iReg )

Definition at line 137656 of file sqlite3.c.

137662 {
137663 assert( pTab!=0 );
137664 if( !pTab->pSelect ){
137665 sqlite3_value *pValue = 0;
137666 u8 enc = ENC(sqlite3VdbeDb(v));
137667 Column *pCol = &pTab->aCol[i];
137668 VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
137669 assert( i<pTab->nCol );
137671 pCol->affinity, &pValue);
137672 if( pValue ){
137673 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
137674 }
137675 }
SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe *, void *pP4, int p4type)
Definition sqlite3.c:79071

References Table::aCol, Column::affinity, ENC, IsVirtual, OP_RealAffinity, P4_MEM, Column::pDflt, Table::pSelect, sqlite3ValueFromExpr(), sqlite3VdbeAddOp1(), sqlite3VdbeAppendP4(), sqlite3VdbeDb(), SQLITE_AFF_REAL, VdbeComment, Column::zName, and Table::zName.

◆ sqlite3ColumnsFromExprList()

SQLITE_PRIVATE int sqlite3ColumnsFromExprList ( Parse * pParse,
ExprList * pEList,
i16 * pnCol,
Column ** paCol )

Definition at line 131254 of file sqlite3.c.

131259*/
131261 Parse *pParse, /* Parsing context */
131262 ExprList *pEList, /* Expr list from which to derive column names */
131263 i16 *pnCol, /* Write the number of columns here */
131264 Column **paCol /* Write the new column list here */
131265){
131266 sqlite3 *db = pParse->db; /* Database connection */
131267 int i, j; /* Loop counters */
131268 u32 cnt; /* Index added to make the name unique */
131269 Column *aCol, *pCol; /* For looping over result columns */
131270 int nCol; /* Number of columns in the result set */
131271 char *zName; /* Column name */
131272 int nName; /* Size of name in zName[] */
131273 Hash ht; /* Hash table of column names */
131274
131275 sqlite3HashInit(&ht);
131276 if( pEList ){
131277 nCol = pEList->nExpr;
131278 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
131279 testcase( aCol==0 );
131280 if( nCol>32767 ) nCol = 32767;
131281 }else{
131282 nCol = 0;
131283 aCol = 0;
131284 }
131285 assert( nCol==(i16)nCol );
131286 *pnCol = nCol;
131287 *paCol = aCol;
131288
131289 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
131290 /* Get an appropriate name for the column
131291 */
131292 if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){
131293 /* If the column contains an "AS <name>" phrase, use <name> as the name */
131294 }else{
131295 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
131296 while( pColExpr->op==TK_DOT ){
131297 pColExpr = pColExpr->pRight;
131298 assert( pColExpr!=0 );
131299 }
131300 if( pColExpr->op==TK_COLUMN ){
131301 /* For columns use the column name name */
131302 int iCol = pColExpr->iColumn;
131303 Table *pTab = pColExpr->y.pTab;
131304 assert( pTab!=0 );
131305 if( iCol<0 ) iCol = pTab->iPKey;
131306 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
131307 }else if( pColExpr->op==TK_ID ){
131308 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
131309 zName = pColExpr->u.zToken;
131310 }else{
131311 /* Use the original text of the column expression as its name */
131312 zName = pEList->a[i].zEName;
131313 }
131314 }
131315 if( zName && !sqlite3IsTrueOrFalse(zName) ){
131316 zName = sqlite3DbStrDup(db, zName);
131317 }else{
131318 zName = sqlite3MPrintf(db,"column%d",i+1);
131319 }
131320
131321 /* Make sure the column name is unique. If the name is not unique,
131322 ** append an integer to the name so that it becomes unique.
131323 */
131324 cnt = 0;
131325 while( zName && sqlite3HashFind(&ht, zName)!=0 ){
131327 if( nName>0 ){
131328 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
131329 if( zName[j]==':' ) nName = j;
131330 }
131331 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
131332 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
131333 }
131334 pCol->zName = zName;
131335 pCol->hName = sqlite3StrIHash(zName);
131337 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
131338 sqlite3OomFault(db);
131339 }
131340 }
131341 sqlite3HashClear(&ht);
131342 if( db->mallocFailed ){
131343 for(j=0; j<i; j++){
131344 sqlite3DbFree(db, aCol[j].zName);
131345 }
131346 sqlite3DbFree(db, aCol);
SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char *)
Definition sqlite3.c:101619
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse *, ExprList *, i16 *, Column **)
Definition sqlite3.c:131254
SQLITE_PRIVATE void sqlite3HashClear(Hash *)
Definition sqlite3.c:32912

References ExprList::a, Table::aCol, Parse::db, ExprList::ExprList_item::eEName, ENAME_NAME, EP_IntValue, ExprHasProperty, Column::hName, Expr::iColumn, Table::iPKey, sqlite3::mallocFailed, ExprList::nExpr, nName, Expr::op, ExprList::ExprList_item::pExpr, Expr::pRight, Expr::pTab, sqlite3_randomness(), sqlite3ColumnPropertiesFromName, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ExprSkipCollateAndLikely(), sqlite3HashClear(), sqlite3HashFind(), sqlite3HashInit(), sqlite3HashInsert(), sqlite3Isdigit, sqlite3IsTrueOrFalse(), sqlite3MPrintf(), sqlite3OomFault(), sqlite3StrIHash(), sqlite3Strlen30(), SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, TK_COLUMN, TK_DOT, TK_ID, Expr::u, Expr::y, ExprList::ExprList_item::zEName, Column::zName, zName, and Expr::zToken.

Referenced by sqlite3ExpandSubquery(), sqlite3ViewGetColumnNames(), and withExpand().

◆ sqlite3ColumnType()

SQLITE_PRIVATE char * sqlite3ColumnType ( Column * pCol,
char * zDflt )

◆ sqlite3CommitInternalChanges()

SQLITE_PRIVATE void sqlite3CommitInternalChanges ( sqlite3 * db)

Definition at line 111013 of file sqlite3.c.

Referenced by sqlite3Init(), and sqlite3VdbeHalt().

◆ sqlite3CompareAffinity()

SQLITE_PRIVATE char sqlite3CompareAffinity ( const Expr * pExpr,
char aff2 )

Definition at line 99959 of file sqlite3.c.

99965 {
99966 char aff1 = sqlite3ExprAffinity(pExpr);
99967 if( aff1>SQLITE_AFF_NONE && aff2>SQLITE_AFF_NONE ){
99968 /* Both sides of the comparison are columns. If one has numeric
99969 ** affinity, use that. Otherwise use no affinity.
99970 */
99972 return SQLITE_AFF_NUMERIC;
99973 }else{
99974 return SQLITE_AFF_BLOB;
99975 }
#define sqlite3IsNumericAffinity(X)
Definition sqlite3.c:17401

References sqlite3ExprAffinity(), sqlite3IsNumericAffinity, SQLITE_AFF_BLOB, SQLITE_AFF_NONE, and SQLITE_AFF_NUMERIC.

Referenced by codeAllEqualityTerms(), exprINAffinity(), sqlite3FindInIndex(), updateRangeAffinityStr(), and whereRangeVectorLen().

◆ sqlite3CompileOptions()

SQLITE_PRIVATE const char ** sqlite3CompileOptions ( int * pnOpt)

Definition at line 782 of file sqlite3.c.

782 {
783 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
784 return (const char**)sqlite3azCompileOpt;
785}
static const char *const sqlite3azCompileOpt[]
Definition sqlite3.c:72

References sqlite3azCompileOpt.

Referenced by sqlite3_compileoption_used().

◆ sqlite3CompleteInsertion()

SQLITE_PRIVATE void sqlite3CompleteInsertion ( Parse * pParse,
Table * pTab,
int iDataCur,
int iIdxCur,
int regNewData,
int * aRegIdx,
int update_flags,
int appendBias,
int useSeekResult )

Definition at line 122833 of file sqlite3.c.

122849 {
122850 Vdbe *v; /* Prepared statements under construction */
122851 Index *pIdx; /* An index being inserted or updated */
122852 u8 pik_flags; /* flag values passed to the btree insert */
122853 int i; /* Loop counter */
122854
122855 assert( update_flags==0
122856 || update_flags==OPFLAG_ISUPDATE
122857 || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
122858 );
122859
122860 v = sqlite3GetVdbe(pParse);
122861 assert( v!=0 );
122862 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122863 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122864 /* All REPLACE indexes are at the end of the list */
122865 assert( pIdx->onError!=OE_Replace
122866 || pIdx->pNext==0
122867 || pIdx->pNext->onError==OE_Replace );
122868 if( aRegIdx[i]==0 ) continue;
122869 if( pIdx->pPartIdxWhere ){
122870 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
122871 VdbeCoverage(v);
122872 }
122873 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
122874 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
122875 assert( pParse->nested==0 );
122876 pik_flags |= OPFLAG_NCHANGE;
122877 pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
122878#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
122879 if( update_flags==0 ){
122880 int r = sqlite3GetTempReg(pParse);
122881 sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
122883 iIdxCur+i, aRegIdx[i], r, (char*)pTab, P4_TABLE
122884 );
122886 sqlite3ReleaseTempReg(pParse, r);
122887 }
122888#endif
122889 }
122890 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
122891 aRegIdx[i]+1,
122892 pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
122893 sqlite3VdbeChangeP5(v, pik_flags);
122894 }
122895 if( !HasRowid(pTab) ) return;
122896 if( pParse->nested ){
122897 pik_flags = 0;
122898 }else{
122899 pik_flags = OPFLAG_NCHANGE;
122900 pik_flags |= (update_flags?update_flags:OPFLAG_LASTROWID);
122901 }
122902 if( appendBias ){
122903 pik_flags |= OPFLAG_APPEND;
122904 }
122905 if( useSeekResult ){
122906 pik_flags |= OPFLAG_USESEEKRESULT;
122907 }
#define OPFLAG_LASTROWID
Definition sqlite3.c:18840
#define OPFLAG_NCHANGE
Definition sqlite3.c:18836
#define OPFLAG_ISNOOP
Definition sqlite3.c:18844
#define OPFLAG_ISUPDATE
Definition sqlite3.c:18841
#define OPFLAG_SAVEPOSITION
Definition sqlite3.c:18852
#define OE_Replace
Definition sqlite3.c:17661

References HasRowid, IsPrimaryKeyIndex, Index::nColumn, Parse::nested, Index::nKeyCol, OE_Replace, Index::onError, OP_IdxInsert, OP_Insert, OP_Integer, OP_IsNull, OPFLAG_APPEND, OPFLAG_ISNOOP, OPFLAG_ISUPDATE, OPFLAG_LASTROWID, OPFLAG_NCHANGE, OPFLAG_SAVEPOSITION, OPFLAG_USESEEKRESULT, P4_TABLE, Table::pIndex, Index::pNext, Index::pPartIdxWhere, Table::pSelect, sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), Index::uniqNotNull, and VdbeCoverage.

Referenced by sqlite3Insert(), and sqlite3Update().

◆ sqlite3ComputeGeneratedColumns()

SQLITE_PRIVATE void sqlite3ComputeGeneratedColumns ( Parse * pParse,
int iRegStore,
Table * pTab )

Definition at line 120770 of file sqlite3.c.

120780 {
120781 int i;
120782 Walker w;
120783 Column *pRedo;
120784 int eProgress;
120785 VdbeOp *pOp;
120786
120787 assert( pTab->tabFlags & TF_HasGenerated );
120788 testcase( pTab->tabFlags & TF_HasVirtual );
120789 testcase( pTab->tabFlags & TF_HasStored );
120790
120791 /* Before computing generated columns, first go through and make sure
120792 ** that appropriate affinity has been applied to the regular columns
120793 */
120794 sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
120795 if( (pTab->tabFlags & TF_HasStored)!=0
120796 && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity
120797 ){
120798 /* Change the OP_Affinity argument to '@' (NONE) for all stored
120799 ** columns. '@' is the no-op affinity and those columns have not
120800 ** yet been computed. */
120801 int ii, jj;
120802 char *zP4 = pOp->p4.z;
120803 assert( zP4!=0 );
120804 assert( pOp->p4type==P4_DYNAMIC );
120805 for(ii=jj=0; zP4[jj]; ii++){
120806 if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
120807 continue;
120808 }
120809 if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
120810 zP4[jj] = SQLITE_AFF_NONE;
120811 }
120812 jj++;
120813 }
120814 }
120815
120816 /* Because there can be multiple generated columns that refer to one another,
120817 ** this is a two-pass algorithm. On the first pass, mark all generated
120818 ** columns as "not available".
120819 */
120820 for(i=0; i<pTab->nCol; i++){
120821 if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){
120822 testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL );
120823 testcase( pTab->aCol[i].colFlags & COLFLAG_STORED );
120824 pTab->aCol[i].colFlags |= COLFLAG_NOTAVAIL;
120825 }
120826 }
120827
120828 w.u.pTab = pTab;
120830 w.xSelectCallback = 0;
120831 w.xSelectCallback2 = 0;
120832
120833 /* On the second pass, compute the value of each NOT-AVAILABLE column.
120834 ** Companion code in the TK_COLUMN case of sqlite3ExprCodeTarget() will
120835 ** compute dependencies and mark remove the COLSPAN_NOTAVAIL mark, as
120836 ** they are needed.
120837 */
120838 pParse->iSelfTab = -iRegStore;
120839 do{
120840 eProgress = 0;
120841 pRedo = 0;
120842 for(i=0; i<pTab->nCol; i++){
120843 Column *pCol = pTab->aCol + i;
120844 if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
120845 int x;
120846 pCol->colFlags |= COLFLAG_BUSY;
120847 w.eCode = 0;
120848 sqlite3WalkExpr(&w, pCol->pDflt);
120849 pCol->colFlags &= ~COLFLAG_BUSY;
120850 if( w.eCode & COLFLAG_NOTAVAIL ){
120851 pRedo = pCol;
120852 continue;
120853 }
120854 eProgress = 1;
120855 assert( pCol->colFlags & COLFLAG_GENERATED );
120856 x = sqlite3TableColumnToStorage(pTab, i) + iRegStore;
120857 sqlite3ExprCodeGeneratedColumn(pParse, pCol, x);
120858 pCol->colFlags &= ~COLFLAG_NOTAVAIL;
120859 }
120860 }
#define TF_HasGenerated
Definition sqlite3.c:17542
#define OP_Affinity
Definition sqlite3.c:15656
#define COLFLAG_NOTAVAIL
Definition sqlite3.c:17351
#define COLFLAG_BUSY
Definition sqlite3.c:17352
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *, Table *, int)
Definition sqlite3.c:120678
static int exprColumnFlagUnion(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:120754
SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse *, Column *, int)
Definition sqlite3.c:103217
struct Table * pTab
Definition sqlite3.c:19112

References Table::aCol, COLFLAG_BUSY, COLFLAG_GENERATED, COLFLAG_NOTAVAIL, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, Walker::eCode, exprColumnFlagUnion(), Parse::iSelfTab, Table::nCol, OP_Affinity, VdbeOp::p4, P4_DYNAMIC, VdbeOp::p4type, Column::pDflt, Walker::pTab, Parse::pVdbe, sqlite3ErrorMsg(), sqlite3ExprCodeGeneratedColumn(), sqlite3TableAffinity(), sqlite3TableColumnToStorage(), sqlite3VdbeGetOp(), sqlite3WalkExpr(), SQLITE_AFF_NONE, Table::tabFlags, testcase, TF_HasGenerated, TF_HasStored, TF_HasVirtual, Walker::u, Walker::xExprCallback, Walker::xSelectCallback, Walker::xSelectCallback2, VdbeOp::p4union::z, and Column::zName.

Referenced by sqlite3GenerateConstraintChecks(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3CorruptError()

SQLITE_PRIVATE int sqlite3CorruptError ( int lineno)

Definition at line 164587 of file sqlite3.c.

164588 {
164589 sqlite3_log(iErr, "%s at line %d of [%.10s]",
164590 zType, lineno, 20+sqlite3_sourceid());
SQLITE_API const char * sqlite3_sourceid(void)
Definition sqlite3.c:230510

References sqlite3_log(), and sqlite3_sourceid().

◆ sqlite3CreateColumnExpr()

SQLITE_PRIVATE Expr * sqlite3CreateColumnExpr ( sqlite3 * db,
SrcList * pSrc,
int iSrc,
int iCol )

Definition at line 98400 of file sqlite3.c.

98406 {
98407 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
98408 if( p ){
98409 struct SrcList_item *pItem = &pSrc->a[iSrc];
98410 Table *pTab = p->y.pTab = pItem->pTab;
98411 p->iTable = pItem->iCursor;
98412 if( p->y.pTab->iPKey==iCol ){
98413 p->iColumn = -1;
98414 }else{
98415 p->iColumn = (ynVar)iCol;
98416 if( (pTab->tabFlags & TF_HasGenerated)!=0
98417 && (pTab->aCol[iCol].colFlags & COLFLAG_GENERATED)!=0
98418 ){
98419 testcase( pTab->nCol==63 );
98420 testcase( pTab->nCol==64 );
98421 pItem->colUsed = pTab->nCol>=64 ? ALLBITS : MASKBIT(pTab->nCol)-1;
98422 }else{
98423 testcase( iCol==BMS );
98424 testcase( iCol==BMS-1 );
i16 ynVar
Definition sqlite3.c:17925
#define ALLBITS
Definition sqlite3.c:14734

Referenced by addWhereTerm().

◆ sqlite3CreateForeignKey()

SQLITE_PRIVATE void sqlite3CreateForeignKey ( Parse * pParse,
ExprList * pFromCol,
Token * pTo,
ExprList * pToCol,
int flags )

Definition at line 113551 of file sqlite3.c.

113563 {
113564 sqlite3 *db = pParse->db;
113565#ifndef SQLITE_OMIT_FOREIGN_KEY
113566 FKey *pFKey = 0;
113567 FKey *pNextTo;
113568 Table *p = pParse->pNewTable;
113569 int nByte;
113570 int i;
113571 int nCol;
113572 char *z;
113573
113574 assert( pTo!=0 );
113575 if( p==0 || IN_DECLARE_VTAB ) goto fk_end;
113576 if( pFromCol==0 ){
113577 int iCol = p->nCol-1;
113578 if( NEVER(iCol<0) ) goto fk_end;
113579 if( pToCol && pToCol->nExpr!=1 ){
113580 sqlite3ErrorMsg(pParse, "foreign key on %s"
113581 " should reference only one column of table %T",
113582 p->aCol[iCol].zName, pTo);
113583 goto fk_end;
113584 }
113585 nCol = 1;
113586 }else if( pToCol && pToCol->nExpr!=pFromCol->nExpr ){
113587 sqlite3ErrorMsg(pParse,
113588 "number of columns in foreign key does not match the number of "
113589 "columns in the referenced table");
113590 goto fk_end;
113591 }else{
113592 nCol = pFromCol->nExpr;
113593 }
113594 nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1;
113595 if( pToCol ){
113596 for(i=0; i<pToCol->nExpr; i++){
113597 nByte += sqlite3Strlen30(pToCol->a[i].zEName) + 1;
113598 }
113599 }
113600 pFKey = sqlite3DbMallocZero(db, nByte );
113601 if( pFKey==0 ){
113602 goto fk_end;
113603 }
113604 pFKey->pFrom = p;
113605 pFKey->pNextFrom = p->pFKey;
113606 z = (char*)&pFKey->aCol[nCol];
113607 pFKey->zTo = z;
113608 if( IN_RENAME_OBJECT ){
113609 sqlite3RenameTokenMap(pParse, (void*)z, pTo);
113610 }
113611 memcpy(z, pTo->z, pTo->n);
113612 z[pTo->n] = 0;
113613 sqlite3Dequote(z);
113614 z += pTo->n+1;
113615 pFKey->nCol = nCol;
113616 if( pFromCol==0 ){
113617 pFKey->aCol[0].iFrom = p->nCol-1;
113618 }else{
113619 for(i=0; i<nCol; i++){
113620 int j;
113621 for(j=0; j<p->nCol; j++){
113622 if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){
113623 pFKey->aCol[i].iFrom = j;
113624 break;
113625 }
113626 }
113627 if( j>=p->nCol ){
113628 sqlite3ErrorMsg(pParse,
113629 "unknown column \"%s\" in foreign key definition",
113630 pFromCol->a[i].zEName);
113631 goto fk_end;
113632 }
113633 if( IN_RENAME_OBJECT ){
113634 sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zEName);
113635 }
113636 }
113637 }
113638 if( pToCol ){
113639 for(i=0; i<nCol; i++){
113640 int n = sqlite3Strlen30(pToCol->a[i].zEName);
113641 pFKey->aCol[i].zCol = z;
113642 if( IN_RENAME_OBJECT ){
113643 sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zEName);
113644 }
113645 memcpy(z, pToCol->a[i].zEName, n);
113646 z[n] = 0;
113647 z += n+1;
113648 }
113649 }
113650 pFKey->isDeferred = 0;
113651 pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
113652 pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
113653
113654 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
113655 pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
113656 pFKey->zTo, (void *)pFKey
113657 );
113658 if( pNextTo==pFKey ){
113659 sqlite3OomFault(db);
113660 goto fk_end;
113661 }
113662 if( pNextTo ){
113663 assert( pNextTo->pPrevTo==0 );
113664 pFKey->pNextTo = pNextTo;
113665 pNextTo->pPrevTo = pFKey;
113666 }
113667
113668 /* Link the foreign key to the table as the last step.
113669 */
113670 p->pFKey = pFKey;
113671 pFKey = 0;
113672
FKey * pPrevTo
Definition sqlite3.c:17619
FKey * pNextTo
Definition sqlite3.c:17618

References ExprList::a, FKey::aAction, Table::aCol, FKey::aCol, Parse::db, Schema::fkeyHash, FKey::sColMap::iFrom, IN_DECLARE_VTAB, IN_RENAME_OBJECT, FKey::isDeferred, Token::n, Table::nCol, FKey::nCol, NEVER, ExprList::nExpr, Table::pFKey, FKey::pFrom, Parse::pNewTable, FKey::pNextFrom, FKey::pNextTo, FKey::pPrevTo, Table::pSchema, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3Dequote(), sqlite3ErrorMsg(), sqlite3ExprListDelete(), sqlite3HashInsert(), sqlite3OomFault(), sqlite3RenameTokenMap(), sqlite3RenameTokenRemap(), sqlite3StrICmp(), sqlite3Strlen30(), Token::z, FKey::sColMap::zCol, ExprList::ExprList_item::zEName, Column::zName, and FKey::zTo.

Referenced by yy_reduce().

◆ sqlite3CreateFunc()

SQLITE_PRIVATE int sqlite3CreateFunc ( sqlite3 * db,
const char * zFunctionName,
int nArg,
int enc,
void * pUserData,
void(*)(sqlite3_context *, int, sqlite3_value **) xSFunc,
void(*)(sqlite3_context *, int, sqlite3_value **) xStep,
void(*)(sqlite3_context *) xFinal,
void(*)(sqlite3_context *) xValue,
void(*)(sqlite3_context *, int, sqlite3_value **) xInverse,
FuncDestructor * pDestructor )

Definition at line 162765 of file sqlite3.c.

162783 {
162784 FuncDef *p;
162785 int nName;
162786 int extraFlags;
162787
162788 assert( sqlite3_mutex_held(db->mutex) );
162789 assert( xValue==0 || xSFunc==0 );
162790 if( zFunctionName==0 /* Must have a valid name */
162791 || (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */
162792 || ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */
162793 || ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */
162794 || (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG)
162795 || (255<(nName = sqlite3Strlen30( zFunctionName)))
162796 ){
162797 return SQLITE_MISUSE_BKPT;
162798 }
162799
162802 extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|
162805
162806 /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
162807 ** the meaning is inverted. So flip the bit. */
162809 extraFlags ^= SQLITE_FUNC_UNSAFE;
162810
162811
162812#ifndef SQLITE_OMIT_UTF16
162813 /* If SQLITE_UTF16 is specified as the encoding type, transform this
162814 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
162815 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
162816 **
162817 ** If SQLITE_ANY is specified, add three versions of the function
162818 ** to the hash table.
162819 */
162820 if( enc==SQLITE_UTF16 ){
162821 enc = SQLITE_UTF16NATIVE;
162822 }else if( enc==SQLITE_ANY ){
162823 int rc;
162824 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
162825 (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
162826 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
162827 if( rc==SQLITE_OK ){
162828 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
162829 (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
162830 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
162831 }
162832 if( rc!=SQLITE_OK ){
162833 return rc;
162834 }
162835 enc = SQLITE_UTF16BE;
162836 }
162837#else
162838 enc = SQLITE_UTF8;
162839#endif
162840
162841 /* Check if an existing function is being overridden or deleted. If so,
162842 ** and there are active VMs, then return SQLITE_BUSY. If a function
162843 ** is being overridden/deleted but there are no active VMs, allow the
162844 ** operation to continue but invalidate all precompiled statements.
162845 */
162846 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
162847 if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)enc && p->nArg==nArg ){
162848 if( db->nVdbeActive ){
162850 "unable to delete/modify user-function due to active statements");
162851 assert( !db->mallocFailed );
162852 return SQLITE_BUSY;
162853 }else{
162855 }
162856 }
162857
162858 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 1);
162859 assert(p || db->mallocFailed);
162860 if( !p ){
162861 return SQLITE_NOMEM_BKPT;
162862 }
162863
162864 /* If an older version of the function with a configured destructor is
162865 ** being replaced invoke the destructor function here. */
162866 functionDestroy(db, p);
162867
162868 if( pDestructor ){
162869 pDestructor->nRef++;
162870 }
162871 p->u.pDestructor = pDestructor;
162872 p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
162875 p->xSFunc = xSFunc ? xSFunc : xStep;
162876 p->xFinalize = xFinal;
static void functionDestroy(sqlite3 *db, FuncDef *p)
Definition sqlite3.c:162127
#define SQLITE_ANY
Definition sqlite3.c:6256

References FuncDef::funcFlags, functionDestroy(), sqlite3::mallocFailed, sqlite3::mutex, FuncDef::nArg, nName, FuncDestructor::nRef, sqlite3::nVdbeActive, FuncDef::pDestructor, FuncDef::pUserData, sqlite3_mutex_held(), sqlite3CreateFunc(), sqlite3ErrorWithMsg(), sqlite3ExpirePreparedStatements(), sqlite3FindFunction(), sqlite3Strlen30(), SQLITE_ANY, SQLITE_BUSY, SQLITE_DETERMINISTIC, SQLITE_DIRECTONLY, SQLITE_FUNC_CONSTANT, SQLITE_FUNC_DIRECT, SQLITE_FUNC_ENCMASK, SQLITE_FUNC_UNSAFE, SQLITE_INNOCUOUS, SQLITE_MAX_FUNCTION_ARG, SQLITE_MISUSE_BKPT, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_SUBTYPE, SQLITE_UTF16, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF16NATIVE, SQLITE_UTF8, testcase, FuncDef::u, FuncDef::xFinalize, FuncDef::xInverse, FuncDef::xSFunc, and FuncDef::xValue.

Referenced by createFunctionApi(), sqlite3CreateFunc(), and sqlite3RegisterLikeFunctions().

◆ sqlite3CreateIndex()

SQLITE_PRIVATE void sqlite3CreateIndex ( Parse * pParse,
Token * pName1,
Token * pName2,
SrcList * pTblName,
ExprList * pList,
int onError,
Token * pStart,
Expr * pPIWhere,
int sortOrder,
int ifNotExist,
u8 idxType )

Definition at line 113869 of file sqlite3.c.

113887 {
113888 Table *pTab = 0; /* Table to be indexed */
113889 Index *pIndex = 0; /* The index to be created */
113890 char *zName = 0; /* Name of the index */
113891 int nName; /* Number of characters in zName */
113892 int i, j;
113893 DbFixer sFix; /* For assigning database names to pTable */
113894 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
113895 sqlite3 *db = pParse->db;
113896 Db *pDb; /* The specific table containing the indexed database */
113897 int iDb; /* Index of the database that is being written */
113898 Token *pName = 0; /* Unqualified name of the index to create */
113899 struct ExprList_item *pListItem; /* For looping over pList */
113900 int nExtra = 0; /* Space allocated for zExtra[] */
113901 int nExtraCol; /* Number of extra columns needed */
113902 char *zExtra = 0; /* Extra space after the Index object */
113903 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
113904
113905 if( db->mallocFailed || pParse->nErr>0 ){
113906 goto exit_create_index;
113907 }
113908 if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
113909 goto exit_create_index;
113910 }
113911 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
113912 goto exit_create_index;
113913 }
113914 if( sqlite3HasExplicitNulls(pParse, pList) ){
113915 goto exit_create_index;
113916 }
113917
113918 /*
113919 ** Find the table that is to be indexed. Return early if not found.
113920 */
113921 if( pTblName!=0 ){
113922
113923 /* Use the two-part index name to determine the database
113924 ** to search for the table. 'Fix' the table name to this db
113925 ** before looking up the table.
113926 */
113927 assert( pName1 && pName2 );
113928 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
113929 if( iDb<0 ) goto exit_create_index;
113930 assert( pName && pName->z );
113931
113932#ifndef SQLITE_OMIT_TEMPDB
113933 /* If the index name was unqualified, check if the table
113934 ** is a temp table. If so, set the database to 1. Do not do this
113935 ** if initialising a database schema.
113936 */
113937 if( !db->init.busy ){
113938 pTab = sqlite3SrcListLookup(pParse, pTblName);
113939 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
113940 iDb = 1;
113941 }
113942 }
113943#endif
113944
113945 sqlite3FixInit(&sFix, pParse, iDb, "index", pName);
113946 if( sqlite3FixSrcList(&sFix, pTblName) ){
113947 /* Because the parser constructs pTblName from a single identifier,
113948 ** sqlite3FixSrcList can never fail. */
113949 assert(0);
113950 }
113951 pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]);
113952 assert( db->mallocFailed==0 || pTab==0 );
113953 if( pTab==0 ) goto exit_create_index;
113954 if( iDb==1 && db->aDb[iDb].pSchema!=pTab->pSchema ){
113955 sqlite3ErrorMsg(pParse,
113956 "cannot create a TEMP index on non-TEMP table \"%s\"",
113957 pTab->zName);
113958 goto exit_create_index;
113959 }
113960 if( !HasRowid(pTab) ) pPk = sqlite3PrimaryKeyIndex(pTab);
113961 }else{
113962 assert( pName==0 );
113963 assert( pStart==0 );
113964 pTab = pParse->pNewTable;
113965 if( !pTab ) goto exit_create_index;
113966 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
113967 }
113968 pDb = &db->aDb[iDb];
113969
113970 assert( pTab!=0 );
113971 assert( pParse->nErr==0 );
113972 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
113973 && db->init.busy==0
113974 && pTblName!=0
113975#if SQLITE_USER_AUTHENTICATION
113976 && sqlite3UserAuthTable(pTab->zName)==0
113977#endif
113978 ){
113979 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
113980 goto exit_create_index;
113981 }
113982#ifndef SQLITE_OMIT_VIEW
113983 if( pTab->pSelect ){
113984 sqlite3ErrorMsg(pParse, "views may not be indexed");
113985 goto exit_create_index;
113986 }
113987#endif
113988#ifndef SQLITE_OMIT_VIRTUALTABLE
113989 if( IsVirtual(pTab) ){
113990 sqlite3ErrorMsg(pParse, "virtual tables may not be indexed");
113991 goto exit_create_index;
113992 }
113993#endif
113994
113995 /*
113996 ** Find the name of the index. Make sure there is not already another
113997 ** index or table with the same name.
113998 **
113999 ** Exception: If we are reading the names of permanent indices from the
114000 ** sqlite_schema table (because some other process changed the schema) and
114001 ** one of the index names collides with the name of a temporary table or
114002 ** index, then we will continue to process this index.
114003 **
114004 ** If pName==0 it means that we are
114005 ** dealing with a primary key or UNIQUE constraint. We have to invent our
114006 ** own name.
114007 */
114008 if( pName ){
114009 zName = sqlite3NameFromToken(db, pName);
114010 if( zName==0 ) goto exit_create_index;
114011 assert( pName->z!=0 );
114012 if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName,"index",pTab->zName) ){
114013 goto exit_create_index;
114014 }
114015 if( !IN_RENAME_OBJECT ){
114016 if( !db->init.busy ){
114017 if( sqlite3FindTable(db, zName, 0)!=0 ){
114018 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
114019 goto exit_create_index;
114020 }
114021 }
114022 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
114023 if( !ifNotExist ){
114024 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
114025 }else{
114026 assert( !db->init.busy );
114027 sqlite3CodeVerifySchema(pParse, iDb);
114028 }
114029 goto exit_create_index;
114030 }
114031 }
114032 }else{
114033 int n;
114034 Index *pLoop;
114035 for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){}
114036 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
114037 if( zName==0 ){
114038 goto exit_create_index;
114039 }
114040
114041 /* Automatic index names generated from within sqlite3_declare_vtab()
114042 ** must have names that are distinct from normal automatic index names.
114043 ** The following statement converts "sqlite3_autoindex..." into
114044 ** "sqlite3_butoindex..." in order to make the names distinct.
114045 ** The "vtab_err.test" test demonstrates the need of this statement. */
114046 if( IN_SPECIAL_PARSE ) zName[7]++;
114047 }
114048
114049 /* Check for authorization to create an index.
114050 */
114051#ifndef SQLITE_OMIT_AUTHORIZATION
114052 if( !IN_RENAME_OBJECT ){
114053 const char *zDb = pDb->zDbSName;
114054 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
114055 goto exit_create_index;
114056 }
114058 if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
114059 if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){
114060 goto exit_create_index;
114061 }
114062 }
114063#endif
114064
114065 /* If pList==0, it means this routine was called to make a primary
114066 ** key out of the last column added to the table under construction.
114067 ** So create a fake list to simulate this.
114068 */
114069 if( pList==0 ){
114070 Token prevCol;
114071 Column *pCol = &pTab->aCol[pTab->nCol-1];
114072 pCol->colFlags |= COLFLAG_UNIQUE;
114073 sqlite3TokenInit(&prevCol, pCol->zName);
114074 pList = sqlite3ExprListAppend(pParse, 0,
114075 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
114076 if( pList==0 ) goto exit_create_index;
114077 assert( pList->nExpr==1 );
114079 }else{
114080 sqlite3ExprListCheckLength(pParse, pList, "index");
114081 if( pParse->nErr ) goto exit_create_index;
114082 }
114083
114084 /* Figure out how many bytes of space are required to store explicitly
114085 ** specified collation sequence names.
114086 */
114087 for(i=0; i<pList->nExpr; i++){
114088 Expr *pExpr = pList->a[i].pExpr;
114089 assert( pExpr!=0 );
114090 if( pExpr->op==TK_COLLATE ){
114091 nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
114092 }
114093 }
114094
114095 /*
114096 ** Allocate the index structure.
114097 */
114099 nExtraCol = pPk ? pPk->nKeyCol : 1;
114100 assert( pList->nExpr + nExtraCol <= 32767 /* Fits in i16 */ );
114101 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
114102 nName + nExtra + 1, &zExtra);
114103 if( db->mallocFailed ){
114104 goto exit_create_index;
114105 }
114106 assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowLogEst) );
114107 assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
114108 pIndex->zName = zExtra;
114109 zExtra += nName + 1;
114110 memcpy(pIndex->zName, zName, nName+1);
114111 pIndex->pTable = pTab;
114112 pIndex->onError = (u8)onError;
114113 pIndex->uniqNotNull = onError!=OE_None;
114114 pIndex->idxType = idxType;
114115 pIndex->pSchema = db->aDb[iDb].pSchema;
114116 pIndex->nKeyCol = pList->nExpr;
114117 if( pPIWhere ){
114118 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
114119 pIndex->pPartIdxWhere = pPIWhere;
114120 pPIWhere = 0;
114121 }
114122 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114123
114124 /* Check to see if we should honor DESC requests on index columns
114125 */
114126 if( pDb->pSchema->file_format>=4 ){
114127 sortOrderMask = -1; /* Honor DESC */
114128 }else{
114129 sortOrderMask = 0; /* Ignore DESC */
114130 }
114131
114132 /* Analyze the list of expressions that form the terms of the index and
114133 ** report any errors. In the common case where the expression is exactly
114134 ** a table column, store that column in aiColumn[]. For general expressions,
114135 ** populate pIndex->aColExpr and store XN_EXPR (-2) in aiColumn[].
114136 **
114137 ** TODO: Issue a warning if two or more columns of the index are identical.
114138 ** TODO: Issue a warning if the table primary key is used as part of the
114139 ** index key.
114140 */
114141 pListItem = pList->a;
114142 if( IN_RENAME_OBJECT ){
114143 pIndex->aColExpr = pList;
114144 pList = 0;
114145 }
114146 for(i=0; i<pIndex->nKeyCol; i++, pListItem++){
114147 Expr *pCExpr; /* The i-th index expression */
114148 int requestedSortOrder; /* ASC or DESC on the i-th expression */
114149 const char *zColl; /* Collation sequence name */
114150
114151 sqlite3StringToId(pListItem->pExpr);
114152 sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
114153 if( pParse->nErr ) goto exit_create_index;
114154 pCExpr = sqlite3ExprSkipCollate(pListItem->pExpr);
114155 if( pCExpr->op!=TK_COLUMN ){
114156 if( pTab==pParse->pNewTable ){
114157 sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
114158 "UNIQUE constraints");
114159 goto exit_create_index;
114160 }
114161 if( pIndex->aColExpr==0 ){
114162 pIndex->aColExpr = pList;
114163 pList = 0;
114164 }
114165 j = XN_EXPR;
114166 pIndex->aiColumn[i] = XN_EXPR;
114167 pIndex->uniqNotNull = 0;
114168 }else{
114169 j = pCExpr->iColumn;
114170 assert( j<=0x7fff );
114171 if( j<0 ){
114172 j = pTab->iPKey;
114173 }else{
114174 if( pTab->aCol[j].notNull==0 ){
114175 pIndex->uniqNotNull = 0;
114176 }
114177 if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
114178 pIndex->bHasVCol = 1;
114179 }
114180 }
114181 pIndex->aiColumn[i] = (i16)j;
114182 }
114183 zColl = 0;
114184 if( pListItem->pExpr->op==TK_COLLATE ){
114185 int nColl;
114186 zColl = pListItem->pExpr->u.zToken;
114187 nColl = sqlite3Strlen30(zColl) + 1;
114188 assert( nExtra>=nColl );
114189 memcpy(zExtra, zColl, nColl);
114190 zColl = zExtra;
114191 zExtra += nColl;
114192 nExtra -= nColl;
114193 }else if( j>=0 ){
114194 zColl = pTab->aCol[j].zColl;
114195 }
114196 if( !zColl ) zColl = sqlite3StrBINARY;
114197 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
114198 goto exit_create_index;
114199 }
114200 pIndex->azColl[i] = zColl;
114201 requestedSortOrder = pListItem->sortFlags & sortOrderMask;
114202 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
114203 }
114204
114205 /* Append the table key to the end of the index. For WITHOUT ROWID
114206 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
114207 ** normal tables (when pPk==0) this will be the rowid.
114208 */
114209 if( pPk ){
114210 for(j=0; j<pPk->nKeyCol; j++){
114211 int x = pPk->aiColumn[j];
114212 assert( x>=0 );
114213 if( isDupColumn(pIndex, pIndex->nKeyCol, pPk, j) ){
114214 pIndex->nColumn--;
114215 }else{
114216 testcase( hasColumn(pIndex->aiColumn,pIndex->nKeyCol,x) );
114217 pIndex->aiColumn[i] = x;
114218 pIndex->azColl[i] = pPk->azColl[j];
114219 pIndex->aSortOrder[i] = pPk->aSortOrder[j];
114220 i++;
114221 }
114222 }
114223 assert( i==pIndex->nColumn );
114224 }else{
114225 pIndex->aiColumn[i] = XN_ROWID;
114226 pIndex->azColl[i] = sqlite3StrBINARY;
114227 }
114228 sqlite3DefaultRowEst(pIndex);
114229 if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
114230
114231 /* If this index contains every column of its table, then mark
114232 ** it as a covering index */
114233 assert( HasRowid(pTab)
114234 || pTab->iPKey<0 || sqlite3TableColumnToIndex(pIndex, pTab->iPKey)>=0 );
114236 if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
114237 pIndex->isCovering = 1;
114238 for(j=0; j<pTab->nCol; j++){
114239 if( j==pTab->iPKey ) continue;
114240 if( sqlite3TableColumnToIndex(pIndex,j)>=0 ) continue;
114241 pIndex->isCovering = 0;
114242 break;
114243 }
114244 }
114245
114246 if( pTab==pParse->pNewTable ){
114247 /* This routine has been called to create an automatic index as a
114248 ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or
114249 ** a PRIMARY KEY or UNIQUE clause following the column definitions.
114250 ** i.e. one of:
114251 **
114252 ** CREATE TABLE t(x PRIMARY KEY, y);
114253 ** CREATE TABLE t(x, y, UNIQUE(x, y));
114254 **
114255 ** Either way, check to see if the table already has such an index. If
114256 ** so, don't bother creating this one. This only applies to
114257 ** automatically created indices. Users can do as they wish with
114258 ** explicit indices.
114259 **
114260 ** Two UNIQUE or PRIMARY KEY constraints are considered equivalent
114261 ** (and thus suppressing the second one) even if they have different
114262 ** sort orders.
114263 **
114264 ** If there are different collating sequences or if the columns of
114265 ** the constraint occur in different orders, then the constraints are
114266 ** considered distinct and both result in separate indices.
114267 */
114268 Index *pIdx;
114269 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
114270 int k;
114271 assert( IsUniqueIndex(pIdx) );
114272 assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
114273 assert( IsUniqueIndex(pIndex) );
114274
114275 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
114276 for(k=0; k<pIdx->nKeyCol; k++){
114277 const char *z1;
114278 const char *z2;
114279 assert( pIdx->aiColumn[k]>=0 );
114280 if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
114281 z1 = pIdx->azColl[k];
114282 z2 = pIndex->azColl[k];
114283 if( sqlite3StrICmp(z1, z2) ) break;
114284 }
114285 if( k==pIdx->nKeyCol ){
114286 if( pIdx->onError!=pIndex->onError ){
114287 /* This constraint creates the same index as a previous
114288 ** constraint specified somewhere in the CREATE TABLE statement.
114289 ** However the ON CONFLICT clauses are different. If both this
114290 ** constraint and the previous equivalent constraint have explicit
114291 ** ON CONFLICT clauses this is an error. Otherwise, use the
114292 ** explicitly specified behavior for the index.
114293 */
114294 if( !(pIdx->onError==OE_Default || pIndex->onError==OE_Default) ){
114295 sqlite3ErrorMsg(pParse,
114296 "conflicting ON CONFLICT clauses specified", 0);
114297 }
114298 if( pIdx->onError==OE_Default ){
114299 pIdx->onError = pIndex->onError;
114300 }
114301 }
114302 if( idxType==SQLITE_IDXTYPE_PRIMARYKEY ) pIdx->idxType = idxType;
114303 if( IN_RENAME_OBJECT ){
114304 pIndex->pNext = pParse->pNewIndex;
114305 pParse->pNewIndex = pIndex;
114306 pIndex = 0;
114307 }
114308 goto exit_create_index;
114309 }
114310 }
114311 }
114312
114313 if( !IN_RENAME_OBJECT ){
114314
114315 /* Link the new Index structure to its table and to the other
114316 ** in-memory database structures.
114317 */
114318 assert( pParse->nErr==0 );
114319 if( db->init.busy ){
114320 Index *p;
114321 assert( !IN_SPECIAL_PARSE );
114322 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
114323 if( pTblName!=0 ){
114324 pIndex->tnum = db->init.newTnum;
114325 if( sqlite3IndexHasDuplicateRootPage(pIndex) ){
114326 sqlite3ErrorMsg(pParse, "invalid rootpage");
114327 pParse->rc = SQLITE_CORRUPT_BKPT;
114328 goto exit_create_index;
114329 }
114330 }
114331 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
114332 pIndex->zName, pIndex);
114333 if( p ){
114334 assert( p==pIndex ); /* Malloc must have failed */
114335 sqlite3OomFault(db);
114336 goto exit_create_index;
114337 }
114339 }
114340
114341 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
114342 ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
114343 ** emit code to allocate the index rootpage on disk and make an entry for
114344 ** the index in the sqlite_schema table and populate the index with
114345 ** content. But, do not do this if we are simply reading the sqlite_schema
114346 ** table to parse the schema, or if this index is the PRIMARY KEY index
114347 ** of a WITHOUT ROWID table.
114348 **
114349 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
114350 ** or UNIQUE index in a CREATE TABLE statement. Since the table
114351 ** has just been created, it contains no data and the index initialization
114352 ** step can be skipped.
114353 */
114354 else if( HasRowid(pTab) || pTblName!=0 ){
114355 Vdbe *v;
114356 char *zStmt;
114357 int iMem = ++pParse->nMem;
114358
114359 v = sqlite3GetVdbe(pParse);
114360 if( v==0 ) goto exit_create_index;
114361
114362 sqlite3BeginWriteOperation(pParse, 1, iDb);
114363
114364 /* Create the rootpage for the index using CreateIndex. But before
114365 ** doing so, code a Noop instruction and store its address in
114366 ** Index.tnum. This is required in case this index is actually a
114367 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
114368 ** that case the convertToWithoutRowidTable() routine will replace
114369 ** the Noop with a Goto to jump over the VDBE code generated below. */
114370 pIndex->tnum = (Pgno)sqlite3VdbeAddOp0(v, OP_Noop);
114372
114373 /* Gather the complete text of the CREATE INDEX statement into
114374 ** the zStmt variable
114375 */
114376 assert( pName!=0 || pStart==0 );
114377 if( pStart ){
114378 int n = (int)(pParse->sLastToken.z - pName->z) + pParse->sLastToken.n;
114379 if( pName->z[n-1]==';' ) n--;
114380 /* A named index with an explicit CREATE INDEX statement */
114381 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
114382 onError==OE_None ? "" : " UNIQUE", n, pName->z);
114383 }else{
114384 /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
114385 /* zStmt = sqlite3MPrintf(""); */
114386 zStmt = 0;
114387 }
114388
114389 /* Add an entry in sqlite_schema for this index
114390 */
114391 sqlite3NestedParse(pParse,
114392 "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);",
114393 db->aDb[iDb].zDbSName,
114394 pIndex->zName,
114395 pTab->zName,
114396 iMem,
114397 zStmt
114398 );
114399 sqlite3DbFree(db, zStmt);
114400
114401 /* Fill the index with data and reparse the schema. Code an OP_Expire
114402 ** to invalidate all pre-compiled statements.
114403 */
114404 if( pTblName ){
114405 sqlite3RefillIndex(pParse, pIndex, iMem);
114406 sqlite3ChangeCookie(pParse, iDb);
114408 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
114409 sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
114410 }
114411
114412 sqlite3VdbeJumpHere(v, (int)pIndex->tnum);
114413 }
114414 }
114415 if( db->init.busy || pTblName==0 ){
114416 pIndex->pNext = pTab->pIndex;
114417 pTab->pIndex = pIndex;
114418 pIndex = 0;
114419 }
114420 else if( IN_RENAME_OBJECT ){
114421 assert( pParse->pNewIndex==0 );
114422 pParse->pNewIndex = pIndex;
114423 pIndex = 0;
114424 }
114425
114426 /* Clean up before exiting */
114427exit_create_index:
114428 if( pIndex ) sqlite3FreeIndex(db, pIndex);
114429 if( pTab ){ /* Ensure all REPLACE indexes are at the end of the list */
114430 Index **ppFrom = &pTab->pIndex;
114431 Index *pThis;
114432 for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
114433 Index *pNext;
114434 if( pThis->onError!=OE_Replace ) continue;
114435 while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){
114436 *ppFrom = pNext;
114437 pThis->pNext = pNext->pNext;
114438 pNext->pNext = pThis;
114439 ppFrom = &pNext->pNext;
114440 }
114441 break;
114442 }
static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage)
Definition sqlite3.c:113702
static void recomputeColumnsNotIndexed(Index *pIdx)
Definition sqlite3.c:112385
#define OP_CreateBtree
Definition sqlite3.c:15705
SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse *, ExprList *, const char *)
Definition sqlite3.c:101551
static void estimateIndexWidth(Index *pIdx)
Definition sqlite3.c:112307
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *, int, char *)
Definition sqlite3.c:78206
#define OMIT_TEMPDB
Definition sqlite3.c:14172
SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse *, Table *, int, Expr *, ExprList *)
Definition sqlite3.c:99672
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList *, int, int)
Definition sqlite3.c:101456
#define DBFLAG_SchemaChange
Definition sqlite3.c:17028
SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index *)
Definition sqlite3.c:128385
#define SQLITE_CREATE_TEMP_INDEX
Definition sqlite3.c:4122
#define SQLITE_CREATE_INDEX
Definition sqlite3.c:4120
unsigned bHasVCol
Definition sqlite3.c:17802
Token sLastToken
Definition sqlite3.c:18747

References ExprList::a, SrcList::a, Table::aCol, Index::aColExpr, sqlite3::aDb, Index::aiColumn, Index::aiRowLogEst, Index::aSortOrder, Index::azColl, Index::bHasVCol, BTREE_BLOBKEY, sqlite3::sqlite3InitInfo::busy, COLFLAG_UNIQUE, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, DBFLAG_SchemaChange, DFLT_SCHEMA_TABLE, EIGHT_BYTE_ALIGNMENT, estimateIndexWidth(), Schema::file_format, hasColumn(), HasRowid, Expr::iColumn, Schema::idxHash, Index::idxType, IN_DECLARE_VTAB, IN_RENAME_OBJECT, IN_SPECIAL_PARSE, sqlite3::init, Table::iPKey, Index::isCovering, isDupColumn(), IsUniqueIndex, IsVirtual, sqlite3::mallocFailed, sqlite3::mDbFlags, Token::n, NC_IdxExpr, NC_PartIdx, Table::nCol, Index::nColumn, Parse::nErr, sqlite3::sqlite3InitInfo::newTnum, ExprList::nExpr, Index::nKeyCol, Parse::nMem, nName, Column::notNull, OE_Default, OE_None, OE_Replace, OMIT_TEMPDB, Index::onError, Expr::op, OP_CreateBtree, OP_Expire, OP_Noop, ExprList::ExprList_item::pExpr, Table::pIndex, Parse::pNewIndex, Parse::pNewTable, Index::pNext, Index::pPartIdxWhere, Db::pSchema, Table::pSchema, Index::pSchema, Table::pSelect, Index::pTable, Parse::rc, recomputeColumnsNotIndexed(), SCHEMA_TABLE, Parse::sLastToken, sqlite3AllocateIndexObject(), sqlite3AuthCheck(), sqlite3BeginWriteOperation(), sqlite3ChangeCookie(), sqlite3CheckObjectName(), sqlite3CodeVerifySchema(), sqlite3DbFree(), sqlite3DefaultRowEst(), sqlite3ErrorMsg(), sqlite3ExprAlloc(), sqlite3ExprDelete(), sqlite3ExprListAppend(), sqlite3ExprListCheckLength(), sqlite3ExprListDelete(), sqlite3ExprListSetSortOrder(), sqlite3ExprSkipCollate(), sqlite3FindIndex(), sqlite3FindTable(), sqlite3FixInit(), sqlite3FixSrcList(), sqlite3FreeIndex(), sqlite3GetVdbe(), sqlite3HasExplicitNulls(), sqlite3HashInsert(), sqlite3IndexHasDuplicateRootPage(), sqlite3LocateCollSeq(), sqlite3LocateTableItem(), sqlite3MPrintf(), sqlite3NameFromToken(), sqlite3NestedParse(), sqlite3OomFault(), sqlite3PrimaryKeyIndex(), sqlite3ReadSchema(), sqlite3RefillIndex(), sqlite3ResolveSelfReference(), sqlite3SchemaToIndex(), sqlite3SrcListDelete(), sqlite3SrcListLookup(), sqlite3StrBINARY, sqlite3StrICmp(), sqlite3StringToId(), sqlite3Strlen30(), sqlite3StrNICmp, sqlite3TableColumnToIndex(), sqlite3TokenInit(), sqlite3TwoPartName(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddParseSchemaOp(), sqlite3VdbeJumpHere(), SQLITE_CORRUPT_BKPT, SQLITE_CREATE_INDEX, SQLITE_CREATE_TEMP_INDEX, SQLITE_IDXTYPE_APPDEF, SQLITE_IDXTYPE_PRIMARYKEY, SQLITE_INSERT, SQLITE_OK, SQLITE_SO_UNDEFINED, testcase, TK_COLLATE, TK_COLUMN, TK_ID, Index::tnum, Expr::u, Index::uniqNotNull, XN_EXPR, XN_ROWID, Token::z, Column::zColl, Db::zDbSName, Column::zName, Table::zName, Index::zName, zName, and Expr::zToken.

Referenced by convertToWithoutRowidTable(), sqlite3AddPrimaryKey(), and yy_reduce().

◆ sqlite3CreateView()

SQLITE_PRIVATE void sqlite3CreateView ( Parse * pParse,
Token * pBegin,
Token * pName1,
Token * pName2,
ExprList * pCNames,
Select * pSelect,
int isTemp,
int noErr )

Definition at line 112951 of file sqlite3.c.

112966 {
112967 Table *p;
112968 int n;
112969 const char *z;
112970 Token sEnd;
112971 DbFixer sFix;
112972 Token *pName = 0;
112973 int iDb;
112974 sqlite3 *db = pParse->db;
112975
112976 if( pParse->nVar>0 ){
112977 sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
112978 goto create_view_fail;
112979 }
112980 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
112981 p = pParse->pNewTable;
112982 if( p==0 || pParse->nErr ) goto create_view_fail;
112983 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
112984 iDb = sqlite3SchemaToIndex(db, p->pSchema);
112985 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
112986 if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
112987
112988 /* Make a copy of the entire SELECT statement that defines the view.
112989 ** This will force all the Expr.token.z values to be dynamically
112990 ** allocated rather than point to the input string - which means that
112991 ** they will persist after the current sqlite3_exec() call returns.
112992 */
112993 pSelect->selFlags |= SF_View;
112994 if( IN_RENAME_OBJECT ){
112995 p->pSelect = pSelect;
112996 pSelect = 0;
112997 }else{
112998 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
112999 }
113000 p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
113001 if( db->mallocFailed ) goto create_view_fail;
113002
113003 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
113004 ** the end.
113005 */
113006 sEnd = pParse->sLastToken;
113007 assert( sEnd.z[0]!=0 || sEnd.n==0 );
113008 if( sEnd.z[0]!=';' ){
113009 sEnd.z += sEnd.n;
113010 }
113011 sEnd.n = 0;
113012 n = (int)(sEnd.z - pBegin->z);
113013 assert( n>0 );
113014 z = pBegin->z;
113015 while( sqlite3Isspace(z[n-1]) ){ n--; }
113016 sEnd.z = &z[n-1];
113017 sEnd.n = 1;
113018
113019 /* Use sqlite3EndTable() to add the view to the schema table */
113020 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
113021
113022create_view_fail:
113023 sqlite3SelectDelete(db, pSelect);
SQLITE_PRIVATE int sqlite3FixSelect(DbFixer *, Select *)
Definition sqlite3.c:109994
SQLITE_PRIVATE void sqlite3EndTable(Parse *, Token *, Token *, u8, Select *)
Definition sqlite3.c:112660
SQLITE_PRIVATE void sqlite3StartTable(Parse *, Token *, Token *, int, int, int, int)
Definition sqlite3.c:111424

Referenced by yy_reduce().

◆ sqlite3DbFree()

SQLITE_PRIVATE void sqlite3DbFree ( sqlite3 * db,
void * p )

Definition at line 27757 of file sqlite3.c.

Referenced by addModuleArgument(), analyzeOneTable(), attachFunc(), btreeMoveto(), callCollNeeded(), callFinaliser(), codeEqualityTerm(), deleteTable(), findBtree(), findCollSeqEntry(), fkActionTrigger(), fkTriggerDelete(), flattenSubquery(), freeP4FuncCtx(), functionDestroy(), propagateConstants(), renameEditSql(), resolveAlias(), resolveP2Values(), selectExpander(), sqlite3_blob_reopen(), sqlite3_declare_vtab(), sqlite3_exec(), sqlite3_step(), sqlite3_str_vappendf(), sqlite3_table_column_metadata(), sqlite3AddColumn(), sqlite3AddDefaultValue(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3AnalysisLoad(), sqlite3Analyze(), sqlite3BeginTrigger(), sqlite3CloseSavepoints(), sqlite3CodeRhsOfIN(), sqlite3CollapseDatabaseArray(), sqlite3ColumnsFromExprList(), sqlite3CreateForeignKey(), sqlite3CreateIndex(), sqlite3DbReallocOrFree(), sqlite3DeleteFrom(), sqlite3DeleteTriggerStep(), sqlite3EndTable(), sqlite3ErrorMsg(), sqlite3ExprCodeIN(), sqlite3FindDb(), sqlite3FindFunction(), sqlite3FixSrcList(), sqlite3FkCheck(), sqlite3FkDelete(), sqlite3FkLocateIndex(), sqlite3InitOne(), sqlite3Insert(), sqlite3LeaveMutexAndCloseZombie(), sqlite3NestedParse(), sqlite3PagerOpen(), sqlite3Pragma(), sqlite3Prepare16(), sqlite3Reindex(), sqlite3RowSetClear(), sqlite3RowSetDelete(), sqlite3RunParser(), sqlite3SrcListAppendList(), sqlite3StartTable(), sqlite3TriggerStepSrc(), sqlite3Update(), sqlite3UpsertDelete(), sqlite3VdbeClearObject(), sqlite3VdbeDeleteAuxData(), sqlite3VdbeExec(), sqlite3VdbeFrameDelete(), sqlite3VdbeHalt(), sqlite3VdbeReset(), sqlite3VdbeSetNumCols(), sqlite3VtabCallConnect(), sqlite3VtabClear(), sqlite3VtabCreateModule(), sqlite3VtabEponymousTableInit(), sqlite3VtabImportErrmsg(), sqlite3WhereBegin(), sqlite3WhereClauseClear(), sqlite3WhereEnd(), sqlite3WindowChain(), sqlite3WindowRewrite(), sqlite3WithAdd(), transferParseError(), valueFromExpr(), vdbeCommit(), vdbeFreeOpArray(), vtabCallConstructor(), whereClauseInsert(), and whereLoopAddVirtual().

◆ sqlite3DbFreeNN()

SQLITE_PRIVATE void sqlite3DbFreeNN ( sqlite3 * db,
void * p )

Definition at line 27720 of file sqlite3.c.

27725 {
27726 assert( db==0 || sqlite3_mutex_held(db->mutex) );
27727 assert( p!=0 );
27728 if( db ){
27729 if( db->pnBytesFreed ){
27730 measureAllocationSize(db, p);
27731 return;
27732 }
27733 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27734#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27735 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27736 LookasideSlot *pBuf = (LookasideSlot*)p;
27737#ifdef SQLITE_DEBUG
27738 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
27739#endif
27740 pBuf->pNext = db->lookaside.pSmallFree;
27741 db->lookaside.pSmallFree = pBuf;
27742 return;
27743 }
27744#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
27745 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27746 LookasideSlot *pBuf = (LookasideSlot*)p;
27747#ifdef SQLITE_DEBUG
27748 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
27749#endif
27750 pBuf->pNext = db->lookaside.pFree;
27751 db->lookaside.pFree = pBuf;
27752 return;
27753 }
27754 }
27755 }
static SQLITE_NOINLINE void measureAllocationSize(sqlite3 *db, void *p)
Definition sqlite3.c:27711

References sqlite3::lookaside, LOOKASIDE_SMALL, measureAllocationSize(), MEMTYPE_HEAP, MEMTYPE_LOOKASIDE, sqlite3::mutex, Lookaside::pEnd, Lookaside::pFree, Lookaside::pMiddle, sqlite3::pnBytesFreed, LookasideSlot::pNext, Lookaside::pSmallFree, Lookaside::pStart, sqlite3_mutex_held(), sqlite3MemdebugHasType, and Lookaside::szTrue.

Referenced by clearSelect(), freeEphemeralFunction(), sqlite3RunParser(), sqlite3VdbeExec(), sqlite3VdbeMemFinalize(), sqlite3VdbeMemGrow(), valueNew(), vdbeFreeOpArray(), vdbeMemClear(), whereLoopAddVirtual(), and wherePathSolver().

◆ sqlite3DbIsNamed()

SQLITE_PRIVATE int sqlite3DbIsNamed ( sqlite3 * db,
int iDb,
const char * zName )

Definition at line 109540 of file sqlite3.c.

Referenced by attachFunc(), detachFunc(), sqlite3DropTrigger(), and sqlite3FindIndex().

◆ sqlite3DbMallocRaw()

SQLITE_PRIVATE void * sqlite3DbMallocRaw ( sqlite3 * db,
u64 n )

Definition at line 27893 of file sqlite3.c.

27893 : "a") worked too.
27894**
27895** The sqlite3MallocRawNN() variant guarantees that the "db" parameter is
27896** not a NULL pointer.
27897*/
27899 void *p;

Referenced by createTableStmt(), exprINAffinity(), printfTempBuf(), sqlite3_exec(), sqlite3AddColumn(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3IndexAffinityStr(), sqlite3PagerOpen(), sqlite3TableAffinity(), sqlite3VdbeAllocUnpackedRecord(), sqlite3VdbeMemGrow(), sqlite3VdbeMemTranslate(), and strAccumFinishRealloc().

◆ sqlite3DbMallocRawNN()

SQLITE_PRIVATE void * sqlite3DbMallocRawNN ( sqlite3 * db,
u64 n )

Definition at line 27900 of file sqlite3.c.

27905 {
27906#ifndef SQLITE_OMIT_LOOKASIDE
27907 LookasideSlot *pBuf;
27908 assert( db!=0 );
27909 assert( sqlite3_mutex_held(db->mutex) );
27910 assert( db->pnBytesFreed==0 );
27911 if( n>db->lookaside.sz ){
27912 if( !db->lookaside.bDisable ){
27913 db->lookaside.anStat[1]++;
27914 }else if( db->mallocFailed ){
27915 return 0;
27916 }
27917 return dbMallocRawFinish(db, n);
27918 }
27919#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27920 if( n<=LOOKASIDE_SMALL ){
27921 if( (pBuf = db->lookaside.pSmallFree)!=0 ){
27922 db->lookaside.pSmallFree = pBuf->pNext;
27923 db->lookaside.anStat[0]++;
27924 return (void*)pBuf;
27925 }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){
27926 db->lookaside.pSmallInit = pBuf->pNext;
27927 db->lookaside.anStat[0]++;
27928 return (void*)pBuf;
27929 }
27930 }
27931#endif
27932 if( (pBuf = db->lookaside.pFree)!=0 ){
27933 db->lookaside.pFree = pBuf->pNext;
27934 db->lookaside.anStat[0]++;
27935 return (void*)pBuf;
27936 }else if( (pBuf = db->lookaside.pInit)!=0 ){
27937 db->lookaside.pInit = pBuf->pNext;
27938 db->lookaside.anStat[0]++;
27939 return (void*)pBuf;
27940 }else{
27941 db->lookaside.anStat[2]++;
27942 }
27943#else
27944 assert( db!=0 );
27945 assert( sqlite3_mutex_held(db->mutex) );
27946 assert( db->pnBytesFreed==0 );
27947 if( db->mallocFailed ){
static SQLITE_NOINLINE void * dbMallocRawFinish(sqlite3 *db, u64 n)
Definition sqlite3.c:27861

Referenced by analyzeOneTable(), attachFunc(), autoIncBegin(), exprAnalyzeOrTerm(), exprDup(), multiSelectOrderBy(), rowSetEntryAlloc(), sqlite3DbRealloc(), sqlite3DeleteFrom(), sqlite3ExprAlloc(), sqlite3ExprListAppend(), sqlite3FkLocateIndex(), sqlite3HexToBlob(), sqlite3Insert(), sqlite3PExpr(), sqlite3Pragma(), sqlite3RowSetInit(), sqlite3SelectNew(), sqlite3SrcListAppend(), sqlite3SrcListDup(), sqlite3Update(), sqlite3VdbeAddFunctionCall(), sqlite3VdbeExec(), sqlite3VdbeMakeReady(), sqlite3VdbeSetNumCols(), sqlite3WhereBegin(), strftimeFunc(), tokenExpr(), whereClauseInsert(), whereLoopInsert(), and wherePathSolver().

◆ sqlite3DbMallocSize()

SQLITE_PRIVATE int sqlite3DbMallocSize ( sqlite3 * db,
void * p )

Definition at line 27654 of file sqlite3.c.

27655#else
27656 return db->lookaside.szTrue;
27657#endif
27658}
27660 assert( p!=0 );
27661#ifdef SQLITE_DEBUG
27662 if( db==0 || !isLookaside(db,p) ){
27663 if( db==0 ){
27664 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
27666 }else{
27669 }
27670 }
27671#endif
27672 if( db ){
27673 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27674#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27675 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27676 assert( sqlite3_mutex_held(db->mutex) );
27677 return LOOKASIDE_SMALL;
27678 }
27679#endif
27680 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27681 assert( sqlite3_mutex_held(db->mutex) );
27682 return db->lookaside.szTrue;

Referenced by growOpArray(), measureAllocationSize(), sqlite3_str_vappendf(), sqlite3RowSetInit(), sqlite3StrAccumEnlarge(), sqlite3VdbeMemGrow(), sqlite3VdbeMemSetStr(), sqlite3VdbeMemTranslate(), and whereClauseInsert().

◆ sqlite3DbMallocZero()

◆ sqlite3DbNameToBtree()

SQLITE_PRIVATE Btree * sqlite3DbNameToBtree ( sqlite3 * db,
const char * zDbName )

Definition at line 165375 of file sqlite3.c.

◆ sqlite3DbRealloc()

SQLITE_PRIVATE void * sqlite3DbRealloc ( sqlite3 * db,
void * p,
u64 n )

Definition at line 27956 of file sqlite3.c.

27961 {
27962 assert( db!=0 );
27963 if( p==0 ) return sqlite3DbMallocRawNN(db, n);
27964 assert( sqlite3_mutex_held(db->mutex) );
27965 if( ((uptr)p)<(uptr)db->lookaside.pEnd ){
27966#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27967 if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){
27968 if( n<=LOOKASIDE_SMALL ) return p;
27969 }else
27970#endif
27971 if( ((uptr)p)>=(uptr)db->lookaside.pStart ){

References sqlite3::lookaside, LOOKASIDE_SMALL, sqlite3::mutex, Lookaside::pEnd, Lookaside::pMiddle, Lookaside::pStart, sqlite3_mutex_held(), and sqlite3DbMallocRawNN().

Referenced by addModuleArgument(), attachFunc(), growOpArray(), sqlite3AddColumn(), sqlite3ArrayAllocate(), sqlite3DbReallocOrFree(), sqlite3ExprListAppend(), sqlite3SrcListEnlarge(), sqlite3StrAccumEnlarge(), sqlite3VListAdd(), and sqlite3WithAdd().

◆ sqlite3DbReallocOrFree()

SQLITE_PRIVATE void * sqlite3DbReallocOrFree ( sqlite3 * db,
void * p,
u64 n )

Definition at line 28002 of file sqlite3.c.

28007 {
28008 void *pNew;
28009 pNew = sqlite3DbRealloc(db, p, n);

References sqlite3DbFree(), and sqlite3DbRealloc().

Referenced by codeEqualityTerm(), constInsert(), resizeResolveLabel(), sqlite3SelectAddColumnTypeAndCollation(), sqlite3TableLock(), and sqlite3VdbeMemGrow().

◆ sqlite3DbSpanDup()

SQLITE_PRIVATE char * sqlite3DbSpanDup ( sqlite3 * db,
const char * zStart,
const char * zEnd )

Definition at line 28049 of file sqlite3.c.

28054 {
28055 int n;

References ALWAYS, sqlite3DbStrNDup(), and sqlite3Isspace.

Referenced by sqlite3AddDefaultValue(), and sqlite3ExprListSetSpan().

◆ sqlite3DbStrDup()

◆ sqlite3DbStrNDup()

SQLITE_PRIVATE char * sqlite3DbStrNDup ( sqlite3 * db,
const char * z,
u64 n )

Definition at line 28031 of file sqlite3.c.

28031 {
28032 memcpy(zNew, z, n);
28033 }
28034 return zNew;
28035}
28036SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
28037 char *zNew;
28038 assert( db!=0 );
28039 assert( z!=0 || n==0 );
28040 assert( (n&0x7fffffff)==n );
28041 zNew = z ? sqlite3DbMallocRawNN(db, n+1) : 0;
28042 if( zNew ){

Referenced by addArgumentToVtab(), sqlite3AlterFinishAddColumn(), sqlite3DbSpanDup(), sqlite3ExprListSetName(), sqlite3NameFromToken(), sqlite3RunParser(), sqlite3WindowAssemble(), and yy_reduce().

◆ sqlite3DecOrHexToI64()

SQLITE_PRIVATE int sqlite3DecOrHexToI64 ( const char * z,
i64 * pOut )

Definition at line 31951 of file sqlite3.c.

31957 {
31958#ifndef SQLITE_OMIT_HEX_INTEGER
31959 if( z[0]=='0'
31960 && (z[1]=='x' || z[1]=='X')
31961 ){
31962 u64 u = 0;
31963 int i, k;
31964 for(i=2; z[i]=='0'; i++){}
31965 for(k=i; sqlite3Isxdigit(z[k]); k++){
31966 u = u*16 + sqlite3HexToInt(z[k]);
31967 }
31968 memcpy(pOut, &u, 8);
31969 return (z[k]==0 && k-i<=16) ? 0 : 2;
#define sqlite3Isxdigit(x)
Definition sqlite3.c:19323
SQLITE_PRIVATE u8 sqlite3HexToInt(int h)
Definition sqlite3.c:32482

References sqlite3Atoi64(), sqlite3HexToInt(), sqlite3Isxdigit, sqlite3Strlen30(), and SQLITE_UTF8.

Referenced by codeInteger(), and sqlite3Pragma().

◆ sqlite3DefaultMutex()

SQLITE_PRIVATE sqlite3_mutex_methods const * sqlite3DefaultMutex ( void )

Definition at line 26596 of file sqlite3.c.

26601 {
26602 static const sqlite3_mutex_methods sMutex = {
26610#ifdef SQLITE_DEBUG
26611 pthreadMutexHeld,
26612 pthreadMutexNotheld
26613#else
26614 0,
26615 0
static void pthreadMutexEnter(sqlite3_mutex *p)
Definition sqlite3.c:26474
static sqlite3_mutex * pthreadMutexAlloc(int iType)
Definition sqlite3.c:26376
static int pthreadMutexInit(void)
Definition sqlite3.c:26325
static void pthreadMutexFree(sqlite3_mutex *p)
Definition sqlite3.c:26447
static int pthreadMutexEnd(void)
Definition sqlite3.c:26326
static void pthreadMutexLeave(sqlite3_mutex *p)
Definition sqlite3.c:26573

Referenced by sqlite3MutexInit().

◆ sqlite3DefaultRowEst()

SQLITE_PRIVATE void sqlite3DefaultRowEst ( Index * pIdx)

Definition at line 114462 of file sqlite3.c.

114468 {
114469 /* 10, 9, 8, 7, 6 */
114470 static const LogEst aVal[] = { 33, 32, 30, 28, 26 };
114471 LogEst *a = pIdx->aiRowLogEst;
114472 LogEst x;
114473 int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol);
114474 int i;
114475
114476 /* Indexes with default row estimates should not have stat1 data */
114477 assert( !pIdx->hasStat1 );
114478
114479 /* Set the first entry (number of rows in the index) to the estimated
114480 ** number of rows in the table, or half the number of rows in the table
114481 ** for a partial index.
114482 **
114483 ** 2020-05-27: If some of the stat data is coming from the sqlite_stat1
114484 ** table but other parts we are having to guess at, then do not let the
114485 ** estimated number of rows in the table be less than 1000 (LogEst 99).
114486 ** Failure to do this can cause the indexes for which we do not have
114487 ** stat1 data to be ignored by the query planner.
114488 */
114489 x = pIdx->pTable->nRowLogEst;
114490 assert( 99==sqlite3LogEst(1000) );
114491 if( x<99 ){
114492 pIdx->pTable->nRowLogEst = x = 99;
114493 }
114494 if( pIdx->pPartIdxWhere!=0 ) x -= 10; assert( 10==sqlite3LogEst(2) );
114495 a[0] = x;
114496
114497 /* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
114498 ** 6 and each subsequent value (if any) is 5. */
114499 memcpy(&a[1], aVal, nCopy*sizeof(LogEst));
114500 for(i=nCopy+1; i<=pIdx->nKeyCol; i++){

References Index::aiRowLogEst, ArraySize, Index::hasStat1, IsUniqueIndex, MIN, Index::nKeyCol, Table::nRowLogEst, Index::pPartIdxWhere, Index::pTable, and sqlite3LogEst().

Referenced by sqlite3AnalysisLoad(), and sqlite3CreateIndex().

◆ sqlite3DeferForeignKey()

SQLITE_PRIVATE void sqlite3DeferForeignKey ( Parse * pParse,
int isDeferred )

Definition at line 113681 of file sqlite3.c.

113687 {
113688#ifndef SQLITE_OMIT_FOREIGN_KEY
113689 Table *pTab;

References FKey::isDeferred, Table::pFKey, and Parse::pNewTable.

Referenced by yy_reduce().

◆ sqlite3DeleteColumnNames()

SQLITE_PRIVATE void sqlite3DeleteColumnNames ( sqlite3 * db,
Table * pTable )

Definition at line 111021 of file sqlite3.c.

111027 {
111028 int i;
111029 Column *pCol;
111030 assert( pTable!=0 );
111031 if( (pCol = pTable->aCol)!=0 ){
111032 for(i=0; i<pTable->nCol; i++, pCol++){
111033 assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) );
111034 sqlite3DbFree(db, pCol->zName);

Referenced by deleteTable(), sqlite3ViewGetColumnNames(), and sqliteViewResetAll().

◆ sqlite3DeleteFrom()

SQLITE_PRIVATE void sqlite3DeleteFrom ( Parse * pParse,
SrcList * pTabList,
Expr * pWhere,
ExprList * pOrderBy,
Expr * pLimit )

Definition at line 116309 of file sqlite3.c.

116321 {
116322 Vdbe *v; /* The virtual database engine */
116323 Table *pTab; /* The table from which records will be deleted */
116324 int i; /* Loop counter */
116325 WhereInfo *pWInfo; /* Information about the WHERE clause */
116326 Index *pIdx; /* For looping over indices of the table */
116327 int iTabCur; /* Cursor number for the table */
116328 int iDataCur = 0; /* VDBE cursor for the canonical data source */
116329 int iIdxCur = 0; /* Cursor number of the first index */
116330 int nIdx; /* Number of indices */
116331 sqlite3 *db; /* Main database structure */
116332 AuthContext sContext; /* Authorization context */
116333 NameContext sNC; /* Name context to resolve expressions in */
116334 int iDb; /* Database number */
116335 int memCnt = 0; /* Memory cell used for change counting */
116336 int rcauth; /* Value returned by authorization callback */
116337 int eOnePass; /* ONEPASS_OFF or _SINGLE or _MULTI */
116338 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
116339 u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
116340 Index *pPk; /* The PRIMARY KEY index on the table */
116341 int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
116342 i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
116343 int iKey; /* Memory cell holding key of row to be deleted */
116344 i16 nKey; /* Number of memory cells in the row key */
116345 int iEphCur = 0; /* Ephemeral table holding all primary key values */
116346 int iRowSet = 0; /* Register for rowset of rows to delete */
116347 int addrBypass = 0; /* Address of jump over the delete logic */
116348 int addrLoop = 0; /* Top of the delete loop */
116349 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
116350 int bComplex; /* True if there are triggers or FKs or
116351 ** subqueries in the WHERE clause */
116352
116353#ifndef SQLITE_OMIT_TRIGGER
116354 int isView; /* True if attempting to delete from a view */
116355 Trigger *pTrigger; /* List of table triggers, if required */
116356#endif
116357
116358 memset(&sContext, 0, sizeof(sContext));
116359 db = pParse->db;
116360 if( pParse->nErr || db->mallocFailed ){
116361 goto delete_from_cleanup;
116362 }
116363 assert( pTabList->nSrc==1 );
116364
116365
116366 /* Locate the table which we want to delete. This table has to be
116367 ** put in an SrcList structure because some of the subroutines we
116368 ** will be calling are designed to work with multiple tables and expect
116369 ** an SrcList* parameter instead of just a Table* parameter.
116370 */
116371 pTab = sqlite3SrcListLookup(pParse, pTabList);
116372 if( pTab==0 ) goto delete_from_cleanup;
116373
116374 /* Figure out if we have any triggers and if the table being
116375 ** deleted from is a view
116376 */
116377#ifndef SQLITE_OMIT_TRIGGER
116378 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
116379 isView = pTab->pSelect!=0;
116380#else
116381# define pTrigger 0
116382# define isView 0
116383#endif
116384 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
116385#ifdef SQLITE_OMIT_VIEW
116386# undef isView
116387# define isView 0
116388#endif
116389
116390#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
116391 if( !isView ){
116392 pWhere = sqlite3LimitWhere(
116393 pParse, pTabList, pWhere, pOrderBy, pLimit, "DELETE"
116394 );
116395 pOrderBy = 0;
116396 pLimit = 0;
116397 }
116398#endif
116399
116400 /* If pTab is really a view, make sure it has been initialized.
116401 */
116402 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
116403 goto delete_from_cleanup;
116404 }
116405
116406 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
116407 goto delete_from_cleanup;
116408 }
116409 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
116410 assert( iDb<db->nDb );
116411 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
116412 db->aDb[iDb].zDbSName);
116413 assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
116414 if( rcauth==SQLITE_DENY ){
116415 goto delete_from_cleanup;
116416 }
116417 assert(!isView || pTrigger);
116418
116419 /* Assign cursor numbers to the table and all its indices.
116420 */
116421 assert( pTabList->nSrc==1 );
116422 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
116423 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
116424 pParse->nTab++;
116425 }
116426
116427 /* Start the view context
116428 */
116429 if( isView ){
116430 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
116431 }
116432
116433 /* Begin generating code.
116434 */
116435 v = sqlite3GetVdbe(pParse);
116436 if( v==0 ){
116437 goto delete_from_cleanup;
116438 }
116439 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
116440 sqlite3BeginWriteOperation(pParse, bComplex, iDb);
116441
116442 /* If we are trying to delete from a view, realize that view into
116443 ** an ephemeral table.
116444 */
116445#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
116446 if( isView ){
116447 sqlite3MaterializeView(pParse, pTab,
116448 pWhere, pOrderBy, pLimit, iTabCur
116449 );
116450 iDataCur = iIdxCur = iTabCur;
116451 pOrderBy = 0;
116452 pLimit = 0;
116453 }
116454#endif
116455
116456 /* Resolve the column names in the WHERE clause.
116457 */
116458 memset(&sNC, 0, sizeof(sNC));
116459 sNC.pParse = pParse;
116460 sNC.pSrcList = pTabList;
116461 if( sqlite3ResolveExprNames(&sNC, pWhere) ){
116462 goto delete_from_cleanup;
116463 }
116464
116465 /* Initialize the counter of the number of rows deleted, if
116466 ** we are counting rows.
116467 */
116468 if( (db->flags & SQLITE_CountRows)!=0
116469 && !pParse->nested
116470 && !pParse->pTriggerTab
116471 ){
116472 memCnt = ++pParse->nMem;
116473 sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
116474 }
116475
116476#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
116477 /* Special case: A DELETE without a WHERE clause deletes everything.
116478 ** It is easier just to erase the whole table. Prior to version 3.6.5,
116479 ** this optimization caused the row change count (the value returned by
116480 ** API function sqlite3_count_changes) to be set incorrectly.
116481 **
116482 ** The "rcauth==SQLITE_OK" terms is the
116483 ** IMPLEMENTATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
116484 ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
116485 ** the truncate optimization is disabled and all rows are deleted
116486 ** individually.
116487 */
116488 if( rcauth==SQLITE_OK
116489 && pWhere==0
116490 && !bComplex
116491 && !IsVirtual(pTab)
116492#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
116493 && db->xPreUpdateCallback==0
116494#endif
116495 ){
116496 assert( !isView );
116497 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
116498 if( HasRowid(pTab) ){
116499 sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt ? memCnt : -1,
116500 pTab->zName, P4_STATIC);
116501 }
116502 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
116503 assert( pIdx->pSchema==pTab->pSchema );
116504 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
116505 }
116506 }else
116507#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
116508 {
116510 if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
116511 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
116512 if( HasRowid(pTab) ){
116513 /* For a rowid table, initialize the RowSet to an empty set */
116514 pPk = 0;
116515 nPk = 1;
116516 iRowSet = ++pParse->nMem;
116517 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
116518 }else{
116519 /* For a WITHOUT ROWID table, create an ephemeral table used to
116520 ** hold all primary keys for rows to be deleted. */
116521 pPk = sqlite3PrimaryKeyIndex(pTab);
116522 assert( pPk!=0 );
116523 nPk = pPk->nKeyCol;
116524 iPk = pParse->nMem+1;
116525 pParse->nMem += nPk;
116526 iEphCur = pParse->nTab++;
116527 addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
116528 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
116529 }
116530
116531 /* Construct a query to find the rowid or primary key for every row
116532 ** to be deleted, based on the WHERE clause. Set variable eOnePass
116533 ** to indicate the strategy used to implement this delete:
116534 **
116535 ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values.
116536 ** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
116537 ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
116538 */
116539 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1);
116540 if( pWInfo==0 ) goto delete_from_cleanup;
116541 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
116542 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
116543 assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
116544 if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
116545
116546 /* Keep track of the number of rows to be deleted */
116547 if( memCnt ){
116548 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
116549 }
116550
116551 /* Extract the rowid or primary key for the current row */
116552 if( pPk ){
116553 for(i=0; i<nPk; i++){
116554 assert( pPk->aiColumn[i]>=0 );
116555 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
116556 pPk->aiColumn[i], iPk+i);
116557 }
116558 iKey = iPk;
116559 }else{
116560 iKey = ++pParse->nMem;
116561 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, -1, iKey);
116562 }
116563
116564 if( eOnePass!=ONEPASS_OFF ){
116565 /* For ONEPASS, no need to store the rowid/primary-key. There is only
116566 ** one, so just keep it in its register(s) and fall through to the
116567 ** delete code. */
116568 nKey = nPk; /* OP_Found will use an unpacked key */
116569 aToOpen = sqlite3DbMallocRawNN(db, nIdx+2);
116570 if( aToOpen==0 ){
116571 sqlite3WhereEnd(pWInfo);
116572 goto delete_from_cleanup;
116573 }
116574 memset(aToOpen, 1, nIdx+1);
116575 aToOpen[nIdx+1] = 0;
116576 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
116577 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
116578 if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
116579 }else{
116580 if( pPk ){
116581 /* Add the PK key for this row to the temporary table */
116582 iKey = ++pParse->nMem;
116583 nKey = 0; /* Zero tells OP_Found to use a composite key */
116584 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
116585 sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
116586 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEphCur, iKey, iPk, nPk);
116587 }else{
116588 /* Add the rowid of the row to be deleted to the RowSet */
116589 nKey = 1; /* OP_DeferredSeek always uses a single rowid */
116590 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
116591 }
116592 }
116593
116594 /* If this DELETE cannot use the ONEPASS strategy, this is the
116595 ** end of the WHERE loop */
116596 if( eOnePass!=ONEPASS_OFF ){
116597 addrBypass = sqlite3VdbeMakeLabel(pParse);
116598 }else{
116599 sqlite3WhereEnd(pWInfo);
116600 }
116601
116602 /* Unless this is a view, open cursors for the table we are
116603 ** deleting from and all its indices. If this is a view, then the
116604 ** only effect this statement has is to fire the INSTEAD OF
116605 ** triggers.
116606 */
116607 if( !isView ){
116608 int iAddrOnce = 0;
116609 if( eOnePass==ONEPASS_MULTI ){
116610 iAddrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
116611 }
116612 testcase( IsVirtual(pTab) );
116614 iTabCur, aToOpen, &iDataCur, &iIdxCur);
116615 assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur );
116616 assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 );
116617 if( eOnePass==ONEPASS_MULTI ){
116618 sqlite3VdbeJumpHereOrPopInst(v, iAddrOnce);
116619 }
116620 }
116621
116622 /* Set up a loop over the rowids/primary-keys that were found in the
116623 ** where-clause loop above.
116624 */
116625 if( eOnePass!=ONEPASS_OFF ){
116626 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
116627 if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){
116628 assert( pPk!=0 || pTab->pSelect!=0 );
116629 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
116630 VdbeCoverage(v);
116631 }
116632 }else if( pPk ){
116633 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
116634 if( IsVirtual(pTab) ){
116635 sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey);
116636 }else{
116637 sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
116638 }
116639 assert( nKey==0 ); /* OP_Found will use a composite key */
116640 }else{
116641 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
116642 VdbeCoverage(v);
116643 assert( nKey==1 );
116644 }
116645
116646 /* Delete the row */
116647#ifndef SQLITE_OMIT_VIRTUALTABLE
116648 if( IsVirtual(pTab) ){
116649 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
116650 sqlite3VtabMakeWritable(pParse, pTab);
116651 assert( eOnePass==ONEPASS_OFF || eOnePass==ONEPASS_SINGLE );
116652 sqlite3MayAbort(pParse);
116653 if( eOnePass==ONEPASS_SINGLE ){
116654 sqlite3VdbeAddOp1(v, OP_Close, iTabCur);
116655 if( sqlite3IsToplevel(pParse) ){
116656 pParse->isMultiWrite = 0;
116657 }
116658 }
116659 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
116661 }else
116662#endif
116663 {
116664 int count = (pParse->nested==0); /* True to count changes */
116665 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
116666 iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]);
116667 }
116668
116669 /* End of the loop over all rowids/primary-keys. */
116670 if( eOnePass!=ONEPASS_OFF ){
116671 sqlite3VdbeResolveLabel(v, addrBypass);
116672 sqlite3WhereEnd(pWInfo);
116673 }else if( pPk ){
116674 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
116675 sqlite3VdbeJumpHere(v, addrLoop);
116676 }else{
116677 sqlite3VdbeGoto(v, addrLoop);
116678 sqlite3VdbeJumpHere(v, addrLoop);
116679 }
116680 } /* End non-truncate path */
116681
116682 /* Update the sqlite_sequence table by storing the content of the
116683 ** maximum rowid counter values recorded while inserting into
116684 ** autoincrement tables.
116685 */
116686 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
116687 sqlite3AutoincrementEnd(pParse);
116688 }
116689
116690 /* Return the number of rows that were deleted. If this routine is
116691 ** generating code because of a call to sqlite3NestedParse(), do not
116692 ** invoke the callback function.
116693 */
116694 if( memCnt ){
116695 sqlite3VdbeAddOp2(v, OP_ResultRow, memCnt, 1);
116696 sqlite3VdbeSetNumCols(v, 1);
116697 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
116698 }
116699
116700delete_from_cleanup:
116701 sqlite3AuthContextPop(&sContext);
116702 sqlite3SrcListDelete(db, pTabList);
116703 sqlite3ExprDelete(db, pWhere);
116704#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *, Table *, int)
Definition sqlite3.c:116156
SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe *, int addr)
Definition sqlite3.c:78814
#define ONEPASS_OFF
Definition sqlite3.c:19647
#define ONEPASS_SINGLE
Definition sqlite3.c:19648
SQLITE_PRIVATE void sqlite3MultiWrite(Parse *)
Definition sqlite3.c:115183
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *, int *)
Definition sqlite3.c:145747
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *, Table *)
Definition sqlite3.c:140741
#define ONEPASS_MULTI
Definition sqlite3.c:19649
#define OPFLAG_FORDELETE
Definition sqlite3.c:18849
SQLITE_PRIVATE int sqlite3FkRequired(Parse *, Table *, int *, int)
Definition sqlite3.c:120216
#define WHERE_ONEPASS_DESIRED
Definition sqlite3.c:18306
SQLITE_PRIVATE void sqlite3AuthContextPush(Parse *, AuthContext *, const char *)
Definition sqlite3.c:110363
#define SQLITE_CountRows
Definition sqlite3.c:17011
SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse *, Table *, Trigger *, int, int, int, i16, u8, u8, u8, int)
Definition sqlite3.c:116756
SQLITE_PRIVATE void sqlite3MaterializeView(Parse *, Table *, Expr *, ExprList *, Expr *, int)
Definition sqlite3.c:116177
#define OP_RowSetAdd
Definition sqlite3.c:15713
#define OP_RowSetRead
Definition sqlite3.c:15608
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse)
Definition sqlite3.c:121048
#define WHERE_DUPLICATES_OK
Definition sqlite3.c:18308
SQLITE_PRIVATE void sqlite3AuthContextPop(AuthContext *)
Definition sqlite3.c:110378
SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse *, Table *, int, u8, int, u8 *, int *, int *)
Definition sqlite3.c:122930
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe *, Table *, int, int, int)
Definition sqlite3.c:103242
SQLITE_PRIVATE Trigger * sqlite3TriggersExist(Parse *, Table *, int, ExprList *, int *pMask)
Definition sqlite3.c:137093
#define WHERE_SEEK_TABLE
Definition sqlite3.c:18314
#define WHERE_ONEPASS_MULTIROW
Definition sqlite3.c:18307
SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe *)
Definition sqlite3.c:82757

References SrcList::a, sqlite3::aDb, Index::aiColumn, COLNAME_NAME, Parse::db, sqlite3::flags, HasRowid, SrcList::SrcList_item::iCursor, Parse::isMultiWrite, IsVirtual, sqlite3::mallocFailed, NC_VarSelect, NameContext::ncFlags, Parse::nErr, Parse::nested, Index::nKeyCol, Parse::nMem, SrcList::nSrc, Parse::nTab, OE_Abort, OE_Default, ONEPASS_MULTI, ONEPASS_OFF, ONEPASS_SINGLE, OP_AddImm, OP_Clear, OP_Close, OP_Column, OP_IdxInsert, OP_Integer, OP_MakeRecord, OP_Next, OP_NotFound, OP_Null, OP_Once, OP_OpenEphemeral, OP_OpenWrite, OP_ResultRow, OP_Rewind, OP_RowData, OP_RowSetAdd, OP_RowSetRead, OP_VUpdate, OPFLAG_FORDELETE, P4_STATIC, P4_VTAB, Table::pIndex, Index::pNext, NameContext::pParse, Table::pSchema, Index::pSchema, Table::pSelect, NameContext::pSrcList, Parse::pTriggerTab, sqlite3AuthCheck(), sqlite3AuthContextPop(), sqlite3AuthContextPush(), sqlite3AutoincrementEnd(), sqlite3BeginWriteOperation(), sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3ExprCodeGetColumnOfTable(), sqlite3ExprDelete(), sqlite3ExprListDelete(), sqlite3FkRequired(), sqlite3GenerateRowDelete(), sqlite3GetVdbe(), sqlite3GetVTable(), sqlite3IndexAffinityStr(), sqlite3IsReadOnly(), sqlite3IsToplevel, sqlite3MaterializeView(), sqlite3MayAbort(), sqlite3MultiWrite(), sqlite3OpenTableAndIndices(), sqlite3PrimaryKeyIndex(), sqlite3ResolveExprNames(), sqlite3SchemaToIndex(), sqlite3SrcListDelete(), sqlite3SrcListLookup(), sqlite3TableLock(), sqlite3TriggersExist(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeChangeToNoop(), sqlite3VdbeCountChanges(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeJumpHereOrPopInst(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VdbeSetColName(), sqlite3VdbeSetNumCols(), sqlite3VdbeSetP4KeyInfo(), sqlite3ViewGetColumnNames(), sqlite3VtabMakeWritable(), sqlite3WhereBegin(), sqlite3WhereEnd(), sqlite3WhereOkOnePass(), SQLITE_CountRows, SQLITE_DELETE, SQLITE_DENY, SQLITE_IGNORE, SQLITE_OK, SQLITE_STATIC, testcase, TK_DELETE, Table::tnum, Index::tnum, VdbeCoverage, WHERE_DUPLICATES_OK, WHERE_ONEPASS_DESIRED, WHERE_ONEPASS_MULTIROW, WHERE_SEEK_TABLE, Db::zDbSName, and Table::zName.

Referenced by sqlite3FkDropTable(), and yy_reduce().

◆ sqlite3DeleteIndexSamples()

SQLITE_PRIVATE void sqlite3DeleteIndexSamples ( sqlite3 * db,
Index * pIdx )

Definition at line 109154 of file sqlite3.c.

109160 {
109161#ifdef SQLITE_ENABLE_STAT4
109162 if( pIdx->aSample ){
109163 int j;
109164 for(j=0; j<pIdx->nSample; j++){
109165 IndexSample *p = &pIdx->aSample[j];
109166 sqlite3DbFree(db, p->p);
109167 }
109168 sqlite3DbFree(db, pIdx->aSample);
109169 }
109170 if( db && db->pnBytesFreed==0 ){
109171 pIdx->nSample = 0;
109172 pIdx->aSample = 0;

Referenced by sqlite3AnalysisLoad().

◆ sqlite3DeleteTable()

◆ sqlite3DeleteTrigger()

SQLITE_PRIVATE void sqlite3DeleteTrigger ( sqlite3 * db,
Trigger * pTrigger )

Definition at line 136938 of file sqlite3.c.

136944 {
136945 if( pTrigger==0 ) return;
136946 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *, TriggerStep *)
Definition sqlite3.c:136403

Referenced by sqlite3BeginTrigger(), sqlite3RunParser(), and sqlite3SchemaClear().

◆ sqlite3DeleteTriggerStep()

SQLITE_PRIVATE void sqlite3DeleteTriggerStep ( sqlite3 * db,
TriggerStep * pTriggerStep )

Definition at line 136403 of file sqlite3.c.

136409 {
136410 while( pTriggerStep ){
136411 TriggerStep * pTmp = pTriggerStep;
136412 pTriggerStep = pTriggerStep->pNext;
136413
136414 sqlite3ExprDelete(db, pTmp->pWhere);
136415 sqlite3ExprListDelete(db, pTmp->pExprList);
136416 sqlite3SelectDelete(db, pTmp->pSelect);
136417 sqlite3IdListDelete(db, pTmp->pIdList);
136418 sqlite3UpsertDelete(db, pTmp->pUpsert);
SQLITE_PRIVATE void sqlite3UpsertDelete(sqlite3 *, Upsert *)
Definition sqlite3.c:138923

References TriggerStep::pExprList, TriggerStep::pFrom, TriggerStep::pIdList, TriggerStep::pNext, TriggerStep::pSelect, TriggerStep::pUpsert, TriggerStep::pWhere, sqlite3DbFree(), sqlite3ExprDelete(), sqlite3ExprListDelete(), sqlite3IdListDelete(), sqlite3SelectDelete(), sqlite3SrcListDelete(), sqlite3UpsertDelete(), and TriggerStep::zSpan.

Referenced by yy_destructor().

◆ sqlite3Dequote()

SQLITE_PRIVATE void sqlite3Dequote ( char * z)

Definition at line 31411 of file sqlite3.c.

31413 : This routine is extended to remove MS-Access style
31414** brackets from around identifiers. For example: "[a-b-c]" becomes
31415** "a-b-c".
31416*/
31417SQLITE_PRIVATE void sqlite3Dequote(char *z){
31418 char quote;
31419 int i, j;
31420 if( z==0 ) return;
31421 quote = z[0];
31422 if( !sqlite3Isquote(quote) ) return;
31423 if( quote=='[' ) quote = ']';
31424 for(i=1, j=0;; i++){
31425 assert( z[i] );
31426 if( z[i]==quote ){
31427 if( z[i+1]==quote ){
31428 z[j++] = quote;
31429 i++;
31430 }else{
31431 break;
31432 }

References sqlite3Isquote.

Referenced by sqlite3AddColumn(), sqlite3CreateForeignKey(), sqlite3ExprListSetName(), sqlite3NameFromToken(), sqlite3RunParser(), and triggerStepAllocate().

◆ sqlite3DequoteExpr()

SQLITE_PRIVATE void sqlite3DequoteExpr ( Expr * p)

Definition at line 31433 of file sqlite3.c.

31433 {
31434 z[j++] = z[i];
31435 }
31436 }
31437 z[j] = 0;

Referenced by sqlite3ExprAlloc(), and tokenExpr().

◆ sqlite3Detach()

SQLITE_PRIVATE void sqlite3Detach ( Parse * pParse,
Expr * pDbname )

Definition at line 109886 of file sqlite3.c.

109892 {
109893 static const FuncDef detach_func = {
109894 1, /* nArg */
109895 SQLITE_UTF8, /* funcFlags */
109896 0, /* pUserData */
109897 0, /* pNext */
109898 detachFunc, /* xSFunc */
109899 0, /* xFinalize */

References codeAttach(), detachFunc(), SQLITE_DETACH, and SQLITE_UTF8.

Referenced by yy_reduce().

◆ sqlite3DropIndex()

SQLITE_PRIVATE void sqlite3DropIndex ( Parse * pParse,
SrcList * pName,
int ifExists )

Definition at line 114506 of file sqlite3.c.

114512 {
114513 Index *pIndex;
114514 Vdbe *v;
114515 sqlite3 *db = pParse->db;
114516 int iDb;
114517
114518 assert( pParse->nErr==0 ); /* Never called with prior errors */
114519 if( db->mallocFailed ){
114520 goto exit_drop_index;
114521 }
114522 assert( pName->nSrc==1 );
114523 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
114524 goto exit_drop_index;
114525 }
114526 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
114527 if( pIndex==0 ){
114528 if( !ifExists ){
114529 sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0);
114530 }else{
114531 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
114532 }
114533 pParse->checkSchema = 1;
114534 goto exit_drop_index;
114535 }
114536 if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
114537 sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
114538 "or PRIMARY KEY constraint cannot be dropped", 0);
114539 goto exit_drop_index;
114540 }
114541 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
114542#ifndef SQLITE_OMIT_AUTHORIZATION
114543 {
114544 int code = SQLITE_DROP_INDEX;
114545 Table *pTab = pIndex->pTable;
114546 const char *zDb = db->aDb[iDb].zDbSName;
114547 const char *zTab = SCHEMA_TABLE(iDb);
114548 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
114549 goto exit_drop_index;
114550 }
114551 if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
114552 if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
114553 goto exit_drop_index;
114554 }
114555 }
114556#endif
114557
114558 /* Generate code to remove the index and from the schema table */
114559 v = sqlite3GetVdbe(pParse);
114560 if( v ){
114561 sqlite3BeginWriteOperation(pParse, 1, iDb);
114562 sqlite3NestedParse(pParse,
114563 "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='index'",
114564 db->aDb[iDb].zDbSName, pIndex->zName
114565 );
114566 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
114567 sqlite3ChangeCookie(pParse, iDb);
114568 destroyRootPage(pParse, pIndex->tnum, iDb);
static void destroyRootPage(Parse *pParse, int iTable, int iDb)
Definition sqlite3.c:113228
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *, const char *zDb)
Definition sqlite3.c:115145
#define SQLITE_DROP_TEMP_INDEX
Definition sqlite3.c:4131
static void sqlite3ClearStatTables(Parse *pParse, int iDb, const char *zType, const char *zName)
Definition sqlite3.c:113307
#define SQLITE_DROP_INDEX
Definition sqlite3.c:4129

Referenced by yy_reduce().

◆ sqlite3DropTable()

SQLITE_PRIVATE void sqlite3DropTable ( Parse * pParse,
SrcList * pName,
int isView,
int noErr )

Definition at line 113434 of file sqlite3.c.

113440 {
113441 Table *pTab;
113442 Vdbe *v;
113443 sqlite3 *db = pParse->db;
113444 int iDb;
113445
113446 if( db->mallocFailed ){
113447 goto exit_drop_table;
113448 }
113449 assert( pParse->nErr==0 );
113450 assert( pName->nSrc==1 );
113451 if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
113452 if( noErr ) db->suppressErr++;
113453 assert( isView==0 || isView==LOCATE_VIEW );
113454 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
113455 if( noErr ) db->suppressErr--;
113456
113457 if( pTab==0 ){
113458 if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
113459 goto exit_drop_table;
113460 }
113461 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
113462 assert( iDb>=0 && iDb<db->nDb );
113463
113464 /* If pTab is a virtual table, call ViewGetColumnNames() to ensure
113465 ** it is initialized.
113466 */
113467 if( IsVirtual(pTab) && sqlite3ViewGetColumnNames(pParse, pTab) ){
113468 goto exit_drop_table;
113469 }
113470#ifndef SQLITE_OMIT_AUTHORIZATION
113471 {
113472 int code;
113473 const char *zTab = SCHEMA_TABLE(iDb);
113474 const char *zDb = db->aDb[iDb].zDbSName;
113475 const char *zArg2 = 0;
113476 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
113477 goto exit_drop_table;
113478 }
113479 if( isView ){
113480 if( !OMIT_TEMPDB && iDb==1 ){
113481 code = SQLITE_DROP_TEMP_VIEW;
113482 }else{
113483 code = SQLITE_DROP_VIEW;
113484 }
113485#ifndef SQLITE_OMIT_VIRTUALTABLE
113486 }else if( IsVirtual(pTab) ){
113487 code = SQLITE_DROP_VTABLE;
113488 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
113489#endif
113490 }else{
113491 if( !OMIT_TEMPDB && iDb==1 ){
113492 code = SQLITE_DROP_TEMP_TABLE;
113493 }else{
113494 code = SQLITE_DROP_TABLE;
113495 }
113496 }
113497 if( sqlite3AuthCheck(pParse, code, pTab->zName, zArg2, zDb) ){
113498 goto exit_drop_table;
113499 }
113500 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
113501 goto exit_drop_table;
113502 }
113503 }
113504#endif
113505 if( tableMayNotBeDropped(db, pTab) ){
113506 sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName);
113507 goto exit_drop_table;
113508 }
113509
113510#ifndef SQLITE_OMIT_VIEW
113511 /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
113512 ** on a table.
113513 */
113514 if( isView && pTab->pSelect==0 ){
113515 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
113516 goto exit_drop_table;
113517 }
113518 if( !isView && pTab->pSelect ){
113519 sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
113520 goto exit_drop_table;
113521 }
113522#endif
113523
113524 /* Generate code to remove the table from the schema table
113525 ** on disk.
113526 */
113527 v = sqlite3GetVdbe(pParse);
113528 if( v ){
113529 sqlite3BeginWriteOperation(pParse, 1, iDb);
113530 if( !isView ){
113531 sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName);
113532 sqlite3FkDropTable(pParse, pName, pTab);
113533 }
#define SQLITE_DROP_TEMP_VIEW
Definition sqlite3.c:4134
SQLITE_PRIVATE void sqlite3FkDropTable(Parse *, SrcList *, Table *)
Definition sqlite3.c:119814
#define SQLITE_DROP_TABLE
Definition sqlite3.c:4130
static int tableMayNotBeDropped(sqlite3 *db, Table *pTab)
Definition sqlite3.c:113418
#define SQLITE_DROP_TEMP_TABLE
Definition sqlite3.c:4132
#define SQLITE_DROP_VTABLE
Definition sqlite3.c:4149
#define LOCATE_VIEW
Definition sqlite3.c:19673
#define SQLITE_DROP_VIEW
Definition sqlite3.c:4136

Referenced by yy_reduce().

◆ sqlite3DropTrigger()

SQLITE_PRIVATE void sqlite3DropTrigger ( Parse * pParse,
SrcList * pName,
int noErr )

Definition at line 136956 of file sqlite3.c.

136962 {
136963 Trigger *pTrigger = 0;
136964 int i;
136965 const char *zDb;
136966 const char *zName;
136967 sqlite3 *db = pParse->db;
136968
136969 if( db->mallocFailed ) goto drop_trigger_cleanup;
136970 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
136971 goto drop_trigger_cleanup;
136972 }
136973
136974 assert( pName->nSrc==1 );
136975 zDb = pName->a[0].zDatabase;
136976 zName = pName->a[0].zName;
136977 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
136978 for(i=OMIT_TEMPDB; i<db->nDb; i++){
136979 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
136980 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
136981 assert( sqlite3SchemaMutexHeld(db, j, 0) );
136982 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
136983 if( pTrigger ) break;
136984 }
136985 if( !pTrigger ){
136986 if( !noErr ){
136987 sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
136988 }else{
136989 sqlite3CodeVerifyNamedSchema(pParse, zDb);
136990 }
136991 pParse->checkSchema = 1;
136992 goto drop_trigger_cleanup;

References SrcList::a, sqlite3::aDb, Parse::checkSchema, Parse::db, sqlite3::mallocFailed, sqlite3::nDb, SrcList::nSrc, OMIT_TEMPDB, Db::pSchema, sqlite3CodeVerifyNamedSchema(), sqlite3DbIsNamed(), sqlite3DropTriggerPtr(), sqlite3ErrorMsg(), sqlite3HashFind(), sqlite3ReadSchema(), sqlite3SrcListDelete(), SQLITE_OK, Schema::trigHash, SrcList::SrcList_item::zDatabase, SrcList::SrcList_item::zName, and zName.

Referenced by yy_reduce().

◆ sqlite3DropTriggerPtr()

SQLITE_PRIVATE void sqlite3DropTriggerPtr ( Parse * pParse,
Trigger * pTrigger )

Definition at line 137006 of file sqlite3.c.

137012 {
137013 Table *pTable;
137014 Vdbe *v;
137015 sqlite3 *db = pParse->db;
137016 int iDb;
137017
137018 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
137019 assert( iDb>=0 && iDb<db->nDb );
137020 pTable = tableOfTrigger(pTrigger);
137021 assert( (pTable && pTable->pSchema==pTrigger->pSchema) || iDb==1 );
137022#ifndef SQLITE_OMIT_AUTHORIZATION
137023 if( pTable ){
137024 int code = SQLITE_DROP_TRIGGER;
137025 const char *zDb = db->aDb[iDb].zDbSName;
137026 const char *zTab = SCHEMA_TABLE(iDb);
137027 if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
137028 if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
137029 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
137030 return;
137031 }
137032 }
137033#endif
137034
137035 /* Generate code to destroy the database record of the trigger.
137036 */
137037 if( (v = sqlite3GetVdbe(pParse))!=0 ){
137038 sqlite3NestedParse(pParse,
137039 "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'",
#define SQLITE_DROP_TEMP_TRIGGER
Definition sqlite3.c:4133
#define SQLITE_DROP_TRIGGER
Definition sqlite3.c:4135

Referenced by sqlite3DropTrigger().

◆ sqlite3EndBenignMalloc()

SQLITE_PRIVATE void sqlite3EndBenignMalloc ( void )

◆ sqlite3EndTable()

SQLITE_PRIVATE void sqlite3EndTable ( Parse * pParse,
Token * pCons,
Token * pEnd,
u8 tabOpts,
Select * pSelect )

Definition at line 112660 of file sqlite3.c.

112672 {
112673 Table *p; /* The new table */
112674 sqlite3 *db = pParse->db; /* The database connection */
112675 int iDb; /* Database in which the table lives */
112676 Index *pIdx; /* An implied index of the table */
112677
112678 if( pEnd==0 && pSelect==0 ){
112679 return;
112680 }
112681 assert( !db->mallocFailed );
112682 p = pParse->pNewTable;
112683 if( p==0 ) return;
112684
112685 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
112686 p->tabFlags |= TF_Shadow;
112687 }
112688
112689 /* If the db->init.busy is 1 it means we are reading the SQL off the
112690 ** "sqlite_schema" or "sqlite_temp_schema" table on the disk.
112691 ** So do not write to the disk again. Extract the root page number
112692 ** for the table from the db->init.newTnum field. (The page number
112693 ** should have been put there by the sqliteOpenCb routine.)
112694 **
112695 ** If the root page number is 1, that means this is the sqlite_schema
112696 ** table itself. So mark it read-only.
112697 */
112698 if( db->init.busy ){
112699 if( pSelect ){
112700 sqlite3ErrorMsg(pParse, "");
112701 return;
112702 }
112703 p->tnum = db->init.newTnum;
112704 if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
112705 }
112706
112707 assert( (p->tabFlags & TF_HasPrimaryKey)==0
112708 || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
112709 assert( (p->tabFlags & TF_HasPrimaryKey)!=0
112710 || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
112711
112712 /* Special processing for WITHOUT ROWID Tables */
112713 if( tabOpts & TF_WithoutRowid ){
112714 if( (p->tabFlags & TF_Autoincrement) ){
112715 sqlite3ErrorMsg(pParse,
112716 "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
112717 return;
112718 }
112719 if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
112720 sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
112721 return;
112722 }
112724 convertToWithoutRowidTable(pParse, p);
112725 }
112726 iDb = sqlite3SchemaToIndex(db, p->pSchema);
112727
112728#ifndef SQLITE_OMIT_CHECK
112729 /* Resolve names in all CHECK constraint expressions.
112730 */
112731 if( p->pCheck ){
112732 sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
112733 if( pParse->nErr ){
112734 /* If errors are seen, delete the CHECK constraints now, else they might
112735 ** actually be used if PRAGMA writable_schema=ON is set. */
112737 p->pCheck = 0;
112738 }else{
112740 }
112741 }
112742#endif /* !defined(SQLITE_OMIT_CHECK) */
112743#ifndef SQLITE_OMIT_GENERATED_COLUMNS
112744 if( p->tabFlags & TF_HasGenerated ){
112745 int ii, nNG = 0;
112748 for(ii=0; ii<p->nCol; ii++){
112749 u32 colFlags = p->aCol[ii].colFlags;
112750 if( (colFlags & COLFLAG_GENERATED)!=0 ){
112751 Expr *pX = p->aCol[ii].pDflt;
112752 testcase( colFlags & COLFLAG_VIRTUAL );
112753 testcase( colFlags & COLFLAG_STORED );
112754 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
112755 /* If there are errors in resolving the expression, change the
112756 ** expression to a NULL. This prevents code generators that operate
112757 ** on the expression from inserting extra parts into the expression
112758 ** tree that have been allocated from lookaside memory, which is
112759 ** illegal in a schema and will lead to errors or heap corruption
112760 ** when the database connection closes. */
112761 sqlite3ExprDelete(db, pX);
112762 p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
112763 }
112764 }else{
112765 nNG++;
112766 }
112767 }
112768 if( nNG==0 ){
112769 sqlite3ErrorMsg(pParse, "must have at least one non-generated column");
112770 return;
112771 }
112772 }
112773#endif
112774
112775 /* Estimate the average row size for the table and for all implied indices */
112777 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
112778 estimateIndexWidth(pIdx);
112779 }
112780
112781 /* If not initializing, then create a record for the new table
112782 ** in the schema table of the database.
112783 **
112784 ** If this is a TEMPORARY table, write the entry into the auxiliary
112785 ** file instead of into the main database file.
112786 */
112787 if( !db->init.busy ){
112788 int n;
112789 Vdbe *v;
112790 char *zType; /* "view" or "table" */
112791 char *zType2; /* "VIEW" or "TABLE" */
112792 char *zStmt; /* Text of the CREATE TABLE or CREATE VIEW statement */
112793
112794 v = sqlite3GetVdbe(pParse);
112795 if( NEVER(v==0) ) return;
112796
112798
112799 /*
112800 ** Initialize zType for the new view or table.
112801 */
112802 if( p->pSelect==0 ){
112803 /* A regular table */
112804 zType = "table";
112805 zType2 = "TABLE";
112806#ifndef SQLITE_OMIT_VIEW
112807 }else{
112808 /* A view */
112809 zType = "view";
112810 zType2 = "VIEW";
112811#endif
112812 }
112813
112814 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
112815 ** statement to populate the new table. The root-page number for the
112816 ** new table is in register pParse->regRoot.
112817 **
112818 ** Once the SELECT has been coded by sqlite3Select(), it is in a
112819 ** suitable state to query for the column names and types to be used
112820 ** by the new table.
112821 **
112822 ** A shared-cache write-lock is not required to write to the new table,
112823 ** as a schema-lock must have already been obtained to create it. Since
112824 ** a schema-lock excludes all other database users, the write-lock would
112825 ** be redundant.
112826 */
112827 if( pSelect ){
112828 SelectDest dest; /* Where the SELECT should store results */
112829 int regYield; /* Register holding co-routine entry-point */
112830 int addrTop; /* Top of the co-routine */
112831 int regRec; /* A record to be insert into the new table */
112832 int regRowid; /* Rowid of the next row to insert */
112833 int addrInsLoop; /* Top of the loop for inserting rows */
112834 Table *pSelTab; /* A table that describes the SELECT results */
112835
112836 regYield = ++pParse->nMem;
112837 regRec = ++pParse->nMem;
112838 regRowid = ++pParse->nMem;
112839 assert(pParse->nTab==1);
112840 sqlite3MayAbort(pParse);
112841 sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
112843 pParse->nTab = 2;
112844 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
112845 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
112846 if( pParse->nErr ) return;
112847 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
112848 if( pSelTab==0 ) return;
112849 assert( p->aCol==0 );
112850 p->nCol = p->nNVCol = pSelTab->nCol;
112851 p->aCol = pSelTab->aCol;
112852 pSelTab->nCol = 0;
112853 pSelTab->aCol = 0;
112854 sqlite3DeleteTable(db, pSelTab);
112855 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
112856 sqlite3Select(pParse, pSelect, &dest);
112857 if( pParse->nErr ) return;
112858 sqlite3VdbeEndCoroutine(v, regYield);
112859 sqlite3VdbeJumpHere(v, addrTop - 1);
112860 addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
112861 VdbeCoverage(v);
112862 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
112863 sqlite3TableAffinity(v, p, 0);
112864 sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
112865 sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
112866 sqlite3VdbeGoto(v, addrInsLoop);
112867 sqlite3VdbeJumpHere(v, addrInsLoop);
112869 }
112870
112871 /* Compute the complete text of the CREATE statement */
112872 if( pSelect ){
112873 zStmt = createTableStmt(db, p);
112874 }else{
112875 Token *pEnd2 = tabOpts ? &pParse->sLastToken : pEnd;
112876 n = (int)(pEnd2->z - pParse->sNameToken.z);
112877 if( pEnd2->z[0]!=';' ) n += pEnd2->n;
112878 zStmt = sqlite3MPrintf(db,
112879 "CREATE %s %.*s", zType2, n, pParse->sNameToken.z
112880 );
112881 }
112882
112883 /* A slot for the record has already been allocated in the
112884 ** schema table. We just need to update that slot with all
112885 ** the information we've collected.
112886 */
112887 sqlite3NestedParse(pParse,
112888 "UPDATE %Q." DFLT_SCHEMA_TABLE
112889 " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
112890 " WHERE rowid=#%d",
112891 db->aDb[iDb].zDbSName,
112892 zType,
112893 p->zName,
112894 p->zName,
112895 pParse->regRoot,
112896 zStmt,
112897 pParse->regRowid
112898 );
112899 sqlite3DbFree(db, zStmt);
112900 sqlite3ChangeCookie(pParse, iDb);
112901
112902#ifndef SQLITE_OMIT_AUTOINCREMENT
112903 /* Check to see if we need to create an sqlite_sequence table for
112904 ** keeping track of autoincrement keys.
112905 */
112906 if( (p->tabFlags & TF_Autoincrement)!=0 ){
112907 Db *pDb = &db->aDb[iDb];
112908 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112909 if( pDb->pSchema->pSeqTab==0 ){
112910 sqlite3NestedParse(pParse,
112911 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
112912 pDb->zDbSName
112913 );
112914 }
112915 }
112916#endif
112917
112918 /* Reparse everything to update our internal data structures */
112920 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
112921 }
112922
112923 /* Add the table to the in-memory representation of the database.
112924 */
112925 if( db->init.busy ){
112926 Table *pOld;
112927 Schema *pSchema = p->pSchema;
112928 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112929 pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
112930 if( pOld ){
112931 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
112932 sqlite3OomFault(db);
112933 return;
112934 }
112935 pParse->pNewTable = 0;
112937
112938#ifndef SQLITE_OMIT_ALTERTABLE
112939 if( !p->pSelect ){
112940 const char *zName = (const char *)pParse->sNameToken.z;
112941 int nName;
112942 assert( !pSelect && pCons && pEnd );
112943 if( pCons->z==0 ){
112944 pCons = pEnd;
112945 }
#define markExprListImmutable(X)
Definition sqlite3.c:112636
static void convertToWithoutRowidTable(Parse *pParse, Table *pTab)
Definition sqlite3.c:112425
static void estimateTableWidth(Table *pTab)
Definition sqlite3.c:112293
#define TF_Readonly
Definition sqlite3.c:17535
SQLITE_PRIVATE Table * sqlite3ResultSetOfSelect(Parse *, Select *, char)
Definition sqlite3.c:131409
static char * createTableStmt(sqlite3 *db, Table *p)
Definition sqlite3.c:112201
int regRowid
Definition sqlite3.c:18709
Token sNameToken
Definition sqlite3.c:18738

References Table::aCol, sqlite3::aDb, Table::addColOffset, sqlite3::sqlite3InitInfo::busy, COLFLAG_GENERATED, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, convertToWithoutRowidTable(), createTableStmt(), Parse::db, DBFLAG_SchemaChange, DFLT_SCHEMA_TABLE, estimateIndexWidth(), estimateTableWidth(), sqlite3::init, Table::iPKey, SelectDest::iSDParm, SelectDest::iSdst, sqlite3::mallocFailed, markExprListImmutable, sqlite3::mDbFlags, Token::n, NC_GenCol, NC_IsCheck, Table::nCol, Parse::nErr, NEVER, sqlite3::sqlite3InitInfo::newTnum, Parse::nMem, nName, Table::nNVCol, SelectDest::nSdst, Parse::nTab, OP_Close, OP_InitCoroutine, OP_Insert, OP_MakeRecord, OP_NewRowid, OP_OpenWrite, OP_Yield, OPFLAG_P2ISREG, Table::pCheck, Column::pDflt, Table::pIndex, Parse::pNewTable, Index::pNext, Db::pSchema, Table::pSchema, Table::pSelect, Schema::pSeqTab, Parse::regRoot, Parse::regRowid, Parse::sLastToken, Parse::sNameToken, sqlite3ChangeCookie(), sqlite3DbFree(), sqlite3DeleteTable(), sqlite3ErrorMsg(), sqlite3ExprAlloc(), sqlite3ExprDelete(), sqlite3ExprListDelete(), sqlite3GetVdbe(), sqlite3HashInsert(), sqlite3MayAbort(), sqlite3MPrintf(), sqlite3NestedParse(), sqlite3OomFault(), sqlite3PrimaryKeyIndex(), sqlite3ResolveSelfReference(), sqlite3ResultSetOfSelect(), sqlite3SchemaToIndex(), sqlite3Select(), sqlite3SelectDestInit(), sqlite3ShadowTableName(), sqlite3TableAffinity(), sqlite3Utf8CharLen(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddParseSchemaOp(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeEndCoroutine(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), SQLITE_AFF_BLOB, SRT_Coroutine, Table::tabFlags, Schema::tblHash, testcase, TF_Autoincrement, TF_HasGenerated, TF_HasPrimaryKey, TF_HasStored, TF_HasVirtual, TF_NoVisibleRowid, TF_Readonly, TF_Shadow, TF_WithoutRowid, TK_NULL, Table::tnum, VdbeCoverage, Token::z, Db::zDbSName, Table::zName, and zName.

Referenced by yy_reduce().

◆ sqlite3EndTransaction()

SQLITE_PRIVATE void sqlite3EndTransaction ( Parse * pParse,
int eType )

Definition at line 115049 of file sqlite3.c.

115055 {
115056 Vdbe *v;
115057 int isRollback;
115058
115059 assert( pParse!=0 );
115060 assert( pParse->db!=0 );
115061 assert( eType==TK_COMMIT || eType==TK_END || eType==TK_ROLLBACK );
115062 isRollback = eType==TK_ROLLBACK;
115064 isRollback ? "ROLLBACK" : "COMMIT", 0, 0) ){
115065 return;
#define TK_ROLLBACK
Definition sqlite3.c:13954
#define TK_END
Definition sqlite3.c:13953
#define TK_COMMIT
Definition sqlite3.c:13952

References Parse::db, eType, OP_AutoCommit, sqlite3AuthCheck(), sqlite3GetVdbe(), sqlite3VdbeAddOp2(), SQLITE_TRANSACTION, TK_COMMIT, TK_END, and TK_ROLLBACK.

Referenced by yy_reduce().

◆ sqlite3Error()

◆ sqlite3ErrorFinish()

static SQLITE_NOINLINE void sqlite3ErrorFinish ( sqlite3 * db,
int err_code )
static

Definition at line 31281 of file sqlite3.c.

References sqlite3::pErr, sqlite3SystemError(), and sqlite3ValueSetNull().

Referenced by sqlite3Error().

◆ sqlite3ErrorIfNotEmpty()

static void sqlite3ErrorIfNotEmpty ( Parse * pParse,
const char * zDb,
const char * zTab,
const char * zErr )
static

Definition at line 106058 of file sqlite3.c.

Referenced by sqlite3AlterFinishAddColumn().

◆ sqlite3ErrorMsg()

SQLITE_PRIVATE void sqlite3ErrorMsg ( Parse * pParse,
const char * zFormat,
... )

Definition at line 31363 of file sqlite3.c.

31369 {
31370 char *zMsg;
31371 va_list ap;
31372 sqlite3 *db = pParse->db;
31373 va_start(ap, zFormat);
31374 zMsg = sqlite3VMPrintf(db, zFormat, ap);
31375 va_end(ap);
31376 if( db->suppressErr ){
31377 sqlite3DbFree(db, zMsg);
31378 }else{
31379 pParse->nErr++;

References Parse::db, Parse::nErr, Parse::pWith, Parse::rc, sqlite3DbFree(), sqlite3VMPrintf(), SQLITE_ERROR, sqlite3::suppressErr, and Parse::zErrMsg.

Referenced by addModuleArgument(), allocateIndexInfo(), cannotBeFunction(), codeInteger(), codeVectorCompare(), destroyRootPage(), exprAnalyze(), generateWithRecursiveQuery(), invalidateTempStorage(), isAlterableTable(), isRealTable(), lookupName(), multiSelect(), parserAddExprIdListTerm(), parserDoubleLinkSelect(), resetAccumulator(), resolveCompoundOrderBy(), resolveExprStep(), selectExpander(), sqlite3AddColumn(), sqlite3AddDefaultValue(), sqlite3AddPrimaryKey(), sqlite3AlterBeginAddColumn(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3AuthCheck(), sqlite3AuthReadCol(), sqlite3BeginTrigger(), sqlite3CheckObjectName(), sqlite3ComputeGeneratedColumns(), sqlite3CreateForeignKey(), sqlite3CreateIndex(), sqlite3DropTrigger(), sqlite3EndTable(), sqlite3ExprAssignVarNumber(), sqlite3ExprCheckHeight(), sqlite3ExprCodeTarget(), sqlite3ExprFunctionUsable(), sqlite3ExprListAppendVector(), sqlite3FinishCoding(), sqlite3FixSrcList(), sqlite3FkLocateIndex(), sqlite3GetCollSeq(), sqlite3HasExplicitNulls(), sqlite3IndexedByLookup(), sqlite3Insert(), sqlite3IsReadOnly(), sqlite3JoinType(), sqlite3LocateTable(), sqlite3Pragma(), sqlite3Reindex(), sqlite3ResolveOrderGroupBy(), sqlite3RunParser(), sqlite3Select(), sqlite3SelectWrongNumTermsError(), sqlite3SrcListAppendFromTerm(), sqlite3SrcListEnlarge(), sqlite3StartTable(), sqlite3SubselectError(), sqlite3TwoPartName(), sqlite3Update(), sqlite3UpsertAnalyzeTarget(), sqlite3VectorErrorMsg(), sqlite3ViewGetColumnNames(), sqlite3VtabCallConnect(), sqlite3VtabEponymousTableInit(), sqlite3WhereBegin(), sqlite3WhereTabFuncArgs(), sqlite3WindowChain(), sqlite3WindowUpdate(), sqlite3WithAdd(), sqliteProcessJoin(), updateFromSelect(), vtabBestIndex(), whereLoopAddVirtualOne(), wherePathSolver(), withExpand(), and yy_reduce().

◆ sqlite3ErrorToParser()

SQLITE_PRIVATE int sqlite3ErrorToParser ( sqlite3 * db,
int errCode )

Definition at line 31386 of file sqlite3.c.

31392 {

References Parse::nErr, sqlite3::pParse, and Parse::rc.

Referenced by sqlite3VdbeMemSetStr(), and sqlite3WindowRewrite().

◆ sqlite3ErrorWithMsg()

SQLITE_PRIVATE void sqlite3ErrorWithMsg ( sqlite3 * db,
int err_code,
const char * zFormat,
... )

Definition at line 31330 of file sqlite3.c.

31336 {
31337 assert( db!=0 );
31338 db->errCode = err_code;
31339 sqlite3SystemError(db, err_code);
31340 if( zFormat==0 ){
31341 sqlite3Error(db, err_code);
31342 }else if( db->pErr || (db->pErr = sqlite3ValueNew(db))!=0 ){
31343 char *z;
31344 va_list ap;
SQLITE_PRIVATE void sqlite3SystemError(sqlite3 *, int)
Definition sqlite3.c:31301

References sqlite3::errCode, sqlite3::pErr, sqlite3Error(), sqlite3SystemError(), sqlite3ValueNew(), sqlite3ValueSetStr(), sqlite3VMPrintf(), SQLITE_DYNAMIC, and SQLITE_UTF8.

Referenced by checkReadTransaction(), findBtree(), openDatabase(), sqlite3_backup_init(), sqlite3_blob_reopen(), sqlite3_declare_vtab(), sqlite3_errmsg16(), sqlite3_table_column_metadata(), sqlite3AutoLoadExtensions(), sqlite3CreateFunc(), and sqlite3VdbeReset().

◆ sqlite3ErrStr()

SQLITE_PRIVATE const char * sqlite3ErrStr ( int rc)

Definition at line 162539 of file sqlite3.c.

162545 {
162546 static const char* const aMsg[] = {
162547 /* SQLITE_OK */ "not an error",
162548 /* SQLITE_ERROR */ "SQL logic error",
162549 /* SQLITE_INTERNAL */ 0,
162550 /* SQLITE_PERM */ "access permission denied",
162551 /* SQLITE_ABORT */ "query aborted",
162552 /* SQLITE_BUSY */ "database is locked",
162553 /* SQLITE_LOCKED */ "database table is locked",
162554 /* SQLITE_NOMEM */ "out of memory",
162555 /* SQLITE_READONLY */ "attempt to write a readonly database",
162556 /* SQLITE_INTERRUPT */ "interrupted",
162557 /* SQLITE_IOERR */ "disk I/O error",
162558 /* SQLITE_CORRUPT */ "database disk image is malformed",
162559 /* SQLITE_NOTFOUND */ "unknown operation",
162560 /* SQLITE_FULL */ "database or disk is full",
162561 /* SQLITE_CANTOPEN */ "unable to open database file",
162562 /* SQLITE_PROTOCOL */ "locking protocol",
162563 /* SQLITE_EMPTY */ 0,
162564 /* SQLITE_SCHEMA */ "database schema has changed",
162565 /* SQLITE_TOOBIG */ "string or blob too big",
162566 /* SQLITE_CONSTRAINT */ "constraint failed",
162567 /* SQLITE_MISMATCH */ "datatype mismatch",
162568 /* SQLITE_MISUSE */ "bad parameter or other API misuse",
162569#ifdef SQLITE_DISABLE_LFS
162570 /* SQLITE_NOLFS */ "large file support is disabled",
162571#else
162572 /* SQLITE_NOLFS */ 0,
162573#endif
162574 /* SQLITE_AUTH */ "authorization denied",
162575 /* SQLITE_FORMAT */ 0,
162576 /* SQLITE_RANGE */ "column index out of range",
162577 /* SQLITE_NOTADB */ "file is not a database",
162578 /* SQLITE_NOTICE */ "notification message",
162579 /* SQLITE_WARNING */ "warning message",
162580 };
162581 const char *zErr = "unknown error";
162582 switch( rc ){
162583 case SQLITE_ABORT_ROLLBACK: {
162584 zErr = "abort due to ROLLBACK";
162585 break;
162586 }
162587 case SQLITE_ROW: {
162588 zErr = "another row available";
162589 break;
162590 }
162591 case SQLITE_DONE: {
162592 zErr = "no more rows available";
162593 break;
162594 }
162595 default: {
162596 rc &= 0xff;
162597 if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
162598 zErr = aMsg[rc];

References ALWAYS, ArraySize, SQLITE_ABORT_ROLLBACK, SQLITE_DONE, and SQLITE_ROW.

Referenced by sqlite3_errmsg16(), sqlite3_errstr(), sqlite3InitOne(), sqlite3Pragma(), sqlite3RunParser(), sqlite3VdbeExec(), sqlite3VdbeList(), and vtabBestIndex().

◆ sqlite3ExpandSubquery()

SQLITE_PRIVATE int sqlite3ExpandSubquery ( Parse * pParse,
struct SrcList_item * pFrom )

Definition at line 134220 of file sqlite3.c.

134226 {
134227 Select *pSel = pFrom->pSelect;
134228 Table *pTab;
134229
134230 assert( pSel );
134231 pFrom->pTab = pTab = sqlite3DbMallocZero(pParse->db, sizeof(Table));
134232 if( pTab==0 ) return SQLITE_NOMEM;
134233 pTab->nTabRef = 1;
134234 if( pFrom->zAlias ){
134235 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
134236 }else{
134237 pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId);
134238 }
134239 while( pSel->pPrior ){ pSel = pSel->pPrior; }
134240 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);

References Table::aCol, Parse::db, Table::iPKey, Table::nCol, Parse::nErr, Table::nRowLogEst, Table::nTabRef, Select::pEList, Select::pPrior, Select::selId, sqlite3ColumnsFromExprList(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3LogEst(), sqlite3MPrintf(), SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, Table::tabFlags, TF_Ephemeral, and Table::zName.

Referenced by selectExpander().

◆ sqlite3ExpirePreparedStatements()

SQLITE_PRIVATE void sqlite3ExpirePreparedStatements ( sqlite3 * db,
int iCode )

◆ sqlite3Expr()

◆ sqlite3ExprAddCollateString()

SQLITE_PRIVATE Expr * sqlite3ExprAddCollateString ( Parse * pParse,
Expr * pExpr,
const char * zC )

◆ sqlite3ExprAddCollateToken()

SQLITE_PRIVATE Expr * sqlite3ExprAddCollateToken ( Parse * pParse,
Expr * pExpr,
const Token * pCollName,
int dequote )

Definition at line 99798 of file sqlite3.c.

99809 {
99810 if( pCollName->n>0 ){
99811 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
99812 if( pNew ){
99813 pNew->pLeft = pExpr;

References Parse::db, Token::n, Expr::pLeft, sqlite3ExprAlloc(), and TK_COLLATE.

Referenced by yy_reduce().

◆ sqlite3ExprAffinity()

SQLITE_PRIVATE char sqlite3ExprAffinity ( const Expr * pExpr)

Definition at line 99753 of file sqlite3.c.

99759 {
99760 int op;
99761 while( ExprHasProperty(pExpr, EP_Skip) ){
99762 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99763 pExpr = pExpr->pLeft;
99764 assert( pExpr!=0 );
99765 }
99766 op = pExpr->op;
99767 if( op==TK_SELECT ){
99768 assert( pExpr->flags&EP_xIsSelect );
99769 assert( pExpr->x.pSelect!=0 );
99770 assert( pExpr->x.pSelect->pEList!=0 );
99771 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
99772 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
99773 }
99774 if( op==TK_REGISTER ) op = pExpr->op2;
99775#ifndef SQLITE_OMIT_CAST
99776 if( op==TK_CAST ){
99777 assert( !ExprHasProperty(pExpr, EP_IntValue) );
99778 return sqlite3AffinityType(pExpr->u.zToken, 0);
99779 }
99780#endif
99781 if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){
99782 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
99783 }
99784 if( op==TK_SELECT_COLUMN ){
99785 assert( pExpr->pLeft->flags&EP_xIsSelect );
99786 return sqlite3ExprAffinity(
99787 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
99788 );
#define TK_CAST
Definition sqlite3.c:13978
SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table *, int)
Definition sqlite3.c:99732

References ExprList::a, Expr::affExpr, EP_IntValue, EP_Skip, EP_xIsSelect, ExprHasProperty, Expr::flags, Expr::iColumn, Expr::op, Expr::op2, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pSelect, Expr::pTab, sqlite3AffinityType(), sqlite3ExprAffinity(), sqlite3TableColumnAffinity(), TK_AGG_COLUMN, TK_CAST, TK_COLLATE, TK_COLUMN, TK_IF_NULL_ROW, TK_REGISTER, TK_SELECT, TK_SELECT_COLUMN, TK_VECTOR, Expr::u, Expr::x, Expr::y, and Expr::zToken.

Referenced by constInsert(), exprAnalyzeOrTerm(), exprINAffinity(), isLikeOrGlob(), sqlite3CodeRhsOfIN(), sqlite3CompareAffinity(), sqlite3ExprAffinity(), sqlite3IndexAffinityStr(), sqlite3SelectAddColumnTypeAndCollation(), termIsEquivalence(), whereIndexExprTransNode(), whereRangeVectorLen(), and whereScanInitIndexExpr().

◆ sqlite3ExprAlloc()

SQLITE_PRIVATE Expr * sqlite3ExprAlloc ( sqlite3 * db,
int op,
const Token * pToken,
int dequote )

Definition at line 100506 of file sqlite3.c.

100506 : If op==TK_INTEGER and pToken points to a string that
100507** can be translated into a 32-bit integer, then the token is not
100508** stored in u.zToken. Instead, the integer values is written
100509** into u.iValue and the EP_IntValue flag is set. No extra storage
100510** is allocated to hold the integer text and the dequote flag is ignored.
100511*/
100513 sqlite3 *db, /* Handle for sqlite3DbMallocRawNN() */
100514 int op, /* Expression opcode */
100515 const Token *pToken, /* Token argument. Might be NULL */
100516 int dequote /* True to dequote */
100517){
100518 Expr *pNew;
100519 int nExtra = 0;
100520 int iValue = 0;
100521
100522 assert( db!=0 );
100523 if( pToken ){
100524 if( op!=TK_INTEGER || pToken->z==0
100525 || sqlite3GetInt32(pToken->z, &iValue)==0 ){
100526 nExtra = pToken->n+1;
100527 assert( iValue>=0 );
100528 }
100529 }
100530 pNew = sqlite3DbMallocRawNN(db, sizeof(Expr)+nExtra);
100531 if( pNew ){
100532 memset(pNew, 0, sizeof(Expr));
100533 pNew->op = (u8)op;
100534 pNew->iAgg = -1;
100535 if( pToken ){
100536 if( nExtra==0 ){
100537 pNew->flags |= EP_IntValue|EP_Leaf|(iValue?EP_IsTrue:EP_IsFalse);
100538 pNew->u.iValue = iValue;
100539 }else{
100540 pNew->u.zToken = (char*)&pNew[1];
100541 assert( pToken->z!=0 || pToken->n==0 );
100542 if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
100543 pNew->u.zToken[pToken->n] = 0;
100544 if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
100545 sqlite3DequoteExpr(pNew);
100546 }
100547 }
100548 }
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *)
Definition sqlite3.c:31433

References EP_IntValue, EP_IsFalse, EP_IsTrue, EP_Leaf, Expr::flags, Expr::iAgg, Expr::iValue, Token::n, Expr::nHeight, Expr::op, sqlite3DbMallocRawNN(), sqlite3DequoteExpr(), sqlite3GetInt32(), sqlite3Isquote, TK_INTEGER, Expr::u, Token::z, and Expr::zToken.

Referenced by convertToWithoutRowidTable(), exprAnalyze(), fkActionTrigger(), sqlite3CreateIndex(), sqlite3EndTable(), sqlite3ExprAddCollateToken(), sqlite3WhereTabFuncArgs(), sqlite3WindowOffsetExpr(), and yy_reduce().

◆ sqlite3ExprAnalyzeAggList()

SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList ( NameContext * pNC,
ExprList * pList )

Definition at line 105694 of file sqlite3.c.

105700 {
105701 struct ExprList_item *pItem;
105702 int i;

References ExprList::a, ExprList::nExpr, and sqlite3ExprAnalyzeAggregates().

Referenced by sqlite3Select().

◆ sqlite3ExprAnalyzeAggregates()

SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates ( NameContext * pNC,
Expr * pExpr )

Definition at line 105676 of file sqlite3.c.

105682 {
105683 Walker w;
static int analyzeAggregate(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:105540
SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker *, Select *)
Definition sqlite3.c:97719
SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *, Select *)
Definition sqlite3.c:97714

References analyzeAggregate(), Walker::pNC, Walker::pParse, NameContext::pSrcList, sqlite3WalkerDepthDecrease(), sqlite3WalkerDepthIncrease(), sqlite3WalkExpr(), Walker::u, Walker::walkerDepth, Walker::xExprCallback, Walker::xSelectCallback, and Walker::xSelectCallback2.

Referenced by sqlite3ExprAnalyzeAggList(), and sqlite3Select().

◆ sqlite3ExprAnd()

SQLITE_PRIVATE Expr * sqlite3ExprAnd ( Parse * pParse,
Expr * pLeft,
Expr * pRight )

Definition at line 100646 of file sqlite3.c.

100652 {
100653 sqlite3 *db = pParse->db;
100654 if( pLeft==0 ){
100655 return pRight;
100656 }else if( pRight==0 ){
100657 return pLeft;
100658 }else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
100659 && !IN_RENAME_OBJECT
100660 ){
100661 sqlite3ExprDelete(db, pLeft);
#define ExprAlwaysFalse(E)
Definition sqlite3.c:18108

References Parse::db, ExprAlwaysFalse, IN_RENAME_OBJECT, sqlite3Expr(), sqlite3ExprDelete(), sqlite3PExpr(), TK_AND, and TK_INTEGER.

Referenced by addWhereTerm(), constructAutomaticIndex(), fkActionTrigger(), fkScanChildren(), havingToWhereExprCb(), pushDownWhereTerms(), sqliteProcessJoin(), and yy_reduce().

◆ sqlite3ExprAssignVarNumber()

SQLITE_PRIVATE void sqlite3ExprAssignVarNumber ( Parse * pParse,
Expr * pExpr,
u32 n )

Definition at line 100742 of file sqlite3.c.

100743 :aaa", "@aaa", or "$aaa" are assigned the same number
100744** as the previous instance of the same wildcard. Or if this is the first
100745** instance of the wildcard, the next sequential variable number is
100746** assigned.
100747*/
100748SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
100749 sqlite3 *db = pParse->db;
100750 const char *z;
100751 ynVar x;
100752
100753 if( pExpr==0 ) return;
100754 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
100755 z = pExpr->u.zToken;
100756 assert( z!=0 );
100757 assert( z[0]!=0 );
100758 assert( n==(u32)sqlite3Strlen30(z) );
100759 if( z[1]==0 ){
100760 /* Wildcard of the form "?". Assign the next variable number */
100761 assert( z[0]=='?' );
100762 x = (ynVar)(++pParse->nVar);
100763 }else{
100764 int doAdd = 0;
100765 if( z[0]=='?' ){
100766 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
100767 ** use it as the variable number */
100768 i64 i;
100769 int bOk;
100770 if( n==2 ){ /*OPTIMIZATION-IF-TRUE*/
100771 i = z[1]-'0'; /* The common case of ?N for a single digit N */
100772 bOk = 1;
100773 }else{
100774 bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
100775 }
100776 testcase( i==0 );
100777 testcase( i==1 );
100778 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
100779 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
100780 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
100781 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
100782 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
100783 return;
100784 }
100785 x = (ynVar)i;
100786 if( x>pParse->nVar ){
100787 pParse->nVar = (int)x;
100788 doAdd = 1;
100789 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
100790 doAdd = 1;
100791 }
100792 }else{
100793 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
100794 ** number as the prior appearance of the same name, or if the name
100795 ** has never appeared before, reuse the same variable number
100796 */
100797 x = (ynVar)sqlite3VListNameToNum(pParse->pVList, z, n);
100798 if( x==0 ){
100799 x = (ynVar)(++pParse->nVar);
100800 doAdd = 1;
100801 }
100802 }
100803 if( doAdd ){
100804 pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
100805 }

References sqlite3::aLimit, Parse::db, EP_IntValue, EP_Reduced, EP_TokenOnly, ExprHasProperty, Expr::iColumn, Parse::nVar, Parse::pVList, sqlite3Atoi64(), sqlite3ErrorMsg(), sqlite3Strlen30(), sqlite3VListAdd(), sqlite3VListNameToNum(), sqlite3VListNumToName(), SQLITE_LIMIT_VARIABLE_NUMBER, SQLITE_UTF8, testcase, Expr::u, and Expr::zToken.

Referenced by yy_reduce().

◆ sqlite3ExprAttachSubtrees()

SQLITE_PRIVATE void sqlite3ExprAttachSubtrees ( sqlite3 * db,
Expr * pRoot,
Expr * pLeft,
Expr * pRight )

Definition at line 100571 of file sqlite3.c.

100582 {
100583 if( pRoot==0 ){
100584 assert( db->mallocFailed );
100585 sqlite3ExprDelete(db, pLeft);
100586 sqlite3ExprDelete(db, pRight);
100587 }else{
100588 if( pRight ){
100589 pRoot->pRight = pRight;
100590 pRoot->flags |= EP_Propagate & pRight->flags;
100591 }
100592 if( pLeft ){
#define EP_Propagate
Definition sqlite3.c:18097

References EP_Propagate, exprSetHeight(), Expr::flags, sqlite3::mallocFailed, Expr::pLeft, Expr::pRight, and sqlite3ExprDelete().

Referenced by sqlite3PExpr(), and yy_reduce().

◆ sqlite3ExprCanBeNull()

SQLITE_PRIVATE int sqlite3ExprCanBeNull ( const Expr * p)

Definition at line 101989 of file sqlite3.c.

101995 {
101996 u8 op;
101997 while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
101998 p = p->pLeft;
101999 }
102000 op = p->op;
102001 if( op==TK_REGISTER ) op = p->op2;
102002 switch( op ){
102003 case TK_INTEGER:
102004 case TK_STRING:
102005 case TK_FLOAT:
102006 case TK_BLOB:
102007 return 0;
102008 case TK_COLUMN:
102009 return ExprHasProperty(p, EP_CanBeNull) ||
102010 p->y.pTab==0 || /* Reference to column of index on expression */
102011 (p->iColumn>=0
#define TK_FLOAT
Definition sqlite3.c:14092
#define TK_BLOB
Definition sqlite3.c:14093

References Table::aCol, ALWAYS, EP_CanBeNull, ExprHasProperty, Expr::iColumn, Column::notNull, Expr::op, Expr::op2, Expr::pLeft, Expr::pTab, TK_BLOB, TK_COLUMN, TK_FLOAT, TK_INTEGER, TK_REGISTER, TK_STRING, TK_UMINUS, TK_UPLUS, and Expr::y.

Referenced by codeAllEqualityTerms(), minMaxQuery(), sqlite3ExprCodeIN(), and sqlite3FindInIndex().

◆ sqlite3ExprCheckHeight()

SQLITE_PRIVATE int sqlite3ExprCheckHeight ( Parse * pParse,
int nHeight )

Definition at line 100379 of file sqlite3.c.

100385 {
100386 int rc = SQLITE_OK;
100387 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
100388 if( nHeight>mxHeight ){
100389 sqlite3ErrorMsg(pParse,

References sqlite3::aLimit, Parse::db, sqlite3ErrorMsg(), SQLITE_ERROR, SQLITE_LIMIT_EXPR_DEPTH, and SQLITE_OK.

Referenced by sqlite3ExprSetHeightAndFlags(), sqlite3PExpr(), sqlite3ResolveExprListNames(), and sqlite3ResolveExprNames().

◆ sqlite3ExprCheckIN()

SQLITE_PRIVATE int sqlite3ExprCheckIN ( Parse * pParse,
Expr * pIn )

Definition at line 102840 of file sqlite3.c.

102846 {
102847 int nVector = sqlite3ExprVectorSize(pIn->pLeft);
102848 if( (pIn->flags & EP_xIsSelect) ){
102849 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
102850 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
102851 return 1;
102852 }
SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect)
Definition sqlite3.c:102484

References EP_xIsSelect, Expr::flags, ExprList::nExpr, Select::pEList, Expr::pLeft, Expr::pSelect, sqlite3ExprVectorSize(), sqlite3SubselectError(), sqlite3VectorErrorMsg(), and Expr::x.

Referenced by exprAnalyze(), and sqlite3ExprCodeIN().

◆ sqlite3ExprCode()

SQLITE_PRIVATE void sqlite3ExprCode ( Parse * pParse,
Expr * pExpr,
int target )

Definition at line 104341 of file sqlite3.c.

104347 {
104348 int inReg;
104349
104350 assert( pExpr==0 || !ExprHasVVAProperty(pExpr,EP_Immutable) );
104351 assert( target>0 && target<=pParse->nMem );
104352 assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
104353 if( pParse->pVdbe==0 ) return;
104354 inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
104355 if( inReg!=target ){
104356 u8 op;
104357 if( ExprHasProperty(pExpr,EP_Subquery) ){
104358 op = OP_Copy;
#define EP_Subquery
Definition sqlite3.c:18081

References Parse::db, EP_Immutable, EP_Subquery, ExprHasProperty, ExprHasVVAProperty, sqlite3::mallocFailed, OP_Copy, OP_SCopy, Parse::pVdbe, sqlite3ExprCodeTarget(), and sqlite3VdbeAddOp2().

Referenced by codeExprOrVector(), computeLimitRegisters(), generateSortTail(), sqlite3CodeRhsOfIN(), sqlite3ExprCodeCopy(), sqlite3ExprCodeRunJustOnce(), sqlite3ExprCodeTarget(), sqlite3FinishCoding(), sqlite3Insert(), sqlite3Select(), sqlite3Update(), sqlite3Vacuum(), sqlite3WindowCodeStep(), updateAccumulator(), and updateVirtualTable().

◆ sqlite3ExprCodeCopy()

SQLITE_PRIVATE void sqlite3ExprCodeCopy ( Parse * pParse,
Expr * pExpr,
int target )

◆ sqlite3ExprCodeExprList()

SQLITE_PRIVATE int sqlite3ExprCodeExprList ( Parse * pParse,
ExprList * pList,
int target,
int srcReg,
u8 flags )

Definition at line 104406 of file sqlite3.c.

104418 {
104419 struct ExprList_item *pItem;
104420 int i, j, n;
104421 u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
104422 Vdbe *v = pParse->pVdbe;
104423 assert( pList!=0 );
104424 assert( target>0 );
104425 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
104426 n = pList->nExpr;
104427 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
104428 for(pItem=pList->a, i=0; i<n; i++, pItem++){
104429 Expr *pExpr = pItem->pExpr;
104430#ifdef SQLITE_ENABLE_SORTER_REFERENCES
104431 if( pItem->bSorterRef ){
104432 i--;
104433 n--;
104434 }else
104435#endif
104436 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
104437 if( flags & SQLITE_ECEL_OMITREF ){
104438 i--;
104439 n--;
104440 }else{
104441 sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
104442 }
104443 }else if( (flags & SQLITE_ECEL_FACTOR)!=0
104445 ){
104446 sqlite3ExprCodeRunJustOnce(pParse, pExpr, target+i);
104447 }else{
104448 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
104449 if( inReg!=target+i ){
104450 VdbeOp *pOp;
104451 if( copyOp==OP_Copy
104452 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
104453 && pOp->p1+pOp->p3+1==inReg
104454 && pOp->p2+pOp->p3+1==target+i
104455 && pOp->p5==0 /* The do-not-merge flag must be clear */
104456 ){
104457 pOp->p3++;
104458 }else{
104459 sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse *, Expr *, int)
Definition sqlite3.c:104257
#define ConstFactorOk(P)
Definition sqlite3.c:17070
#define SQLITE_ECEL_FACTOR
Definition sqlite3.c:19666
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *)
Definition sqlite3.c:101820

References ExprList::a, ConstFactorOk, ExprList::nExpr, OP_Copy, OP_SCopy, VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, VdbeOp::p5, Parse::pVdbe, sqlite3ExprCodeRunJustOnce(), sqlite3ExprCodeTarget(), sqlite3ExprIsConstantNotJoin(), sqlite3VdbeAddOp2(), sqlite3VdbeGetOp(), SQLITE_ECEL_DUP, SQLITE_ECEL_FACTOR, SQLITE_ECEL_OMITREF, and SQLITE_ECEL_REF.

Referenced by sqlite3ExprCodeTarget(), sqlite3Select(), updateAccumulator(), and windowAggStep().

◆ sqlite3ExprCodeFactorable()

SQLITE_PRIVATE void sqlite3ExprCodeFactorable ( Parse * pParse,
Expr * pExpr,
int target )

◆ sqlite3ExprCodeGeneratedColumn()

SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn ( Parse * pParse,
Column * pCol,
int regOut )

Definition at line 103217 of file sqlite3.c.

103227 {
103228 int iAddr;
103229 Vdbe *v = pParse->pVdbe;
103230 assert( v!=0 );
103231 assert( pParse->iSelfTab!=0 );
103232 if( pParse->iSelfTab>0 ){
103233 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
103234 }else{
103235 iAddr = 0;
103236 }
#define OP_IfNullRow
Definition sqlite3.c:15587

References Column::affinity, Parse::iSelfTab, OP_Affinity, OP_IfNullRow, Column::pDflt, Parse::pVdbe, sqlite3ExprCodeCopy(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeJumpHere(), and SQLITE_AFF_TEXT.

Referenced by sqlite3ComputeGeneratedColumns(), and sqlite3ExprCodeTarget().

◆ sqlite3ExprCodeGetColumn()

SQLITE_PRIVATE int sqlite3ExprCodeGetColumn ( Parse * pParse,
Table * pTab,
int iColumn,
int iTable,
int iReg,
u8 p5 )

Definition at line 103299 of file sqlite3.c.

103312 {
103313 assert( pParse->pVdbe!=0 );
103314 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);

References OP_Column, VdbeOp::opcode, VdbeOp::p5, Parse::pVdbe, sqlite3ExprCodeGetColumnOfTable(), and sqlite3VdbeGetOp().

Referenced by sqlite3ExprCodeTarget().

◆ sqlite3ExprCodeGetColumnOfTable()

SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable ( Vdbe * v,
Table * pTab,
int iTabCur,
int iCol,
int regOut )

Definition at line 103242 of file sqlite3.c.

103254 {
103255 Column *pCol;
103256 assert( v!=0 );
103257 if( pTab==0 ){
103258 sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
103259 return;
103260 }
103261 if( iCol<0 || iCol==pTab->iPKey ){
103262 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
103263 }else{
103264 int op;
103265 int x;
103266 if( IsVirtual(pTab) ){
103267 op = OP_VColumn;
103268 x = iCol;
103269#ifndef SQLITE_OMIT_GENERATED_COLUMNS
103270 }else if( (pCol = &pTab->aCol[iCol])->colFlags & COLFLAG_VIRTUAL ){
103271 Parse *pParse = sqlite3VdbeParser(v);
103272 if( pCol->colFlags & COLFLAG_BUSY ){
103273 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pCol->zName);
103274 }else{
103275 int savedSelfTab = pParse->iSelfTab;
103276 pCol->colFlags |= COLFLAG_BUSY;
103277 pParse->iSelfTab = iTabCur+1;
103278 sqlite3ExprCodeGeneratedColumn(pParse, pCol, regOut);
103279 pParse->iSelfTab = savedSelfTab;
103280 pCol->colFlags &= ~COLFLAG_BUSY;
103281 }
103282 return;
103283#endif
103284 }else if( !HasRowid(pTab) ){
103285 testcase( iCol!=sqlite3TableColumnToStorage(pTab, iCol) );
103287 op = OP_Column;
103288 }else{
103289 x = sqlite3TableColumnToStorage(pTab,iCol);
103290 testcase( x!=iCol );
SQLITE_PRIVATE Parse * sqlite3VdbeParser(Vdbe *)
Definition sqlite3.c:77784
#define OP_VColumn
Definition sqlite3.c:15732

Referenced by sqlite3DeleteFrom(), sqlite3ExprCodeGetColumn(), sqlite3GenerateRowDelete(), sqlite3Pragma(), sqlite3Select(), and sqlite3Update().

◆ sqlite3ExprCodeIN()

static void sqlite3ExprCodeIN ( Parse * pParse,
Expr * pExpr,
int destIfFalse,
int destIfNull )
static

Definition at line 102881 of file sqlite3.c.

102892 {
102893 int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
102894 int eType; /* Type of the RHS */
102895 int rLhs; /* Register(s) holding the LHS values */
102896 int rLhsOrig; /* LHS values prior to reordering by aiMap[] */
102897 Vdbe *v; /* Statement under construction */
102898 int *aiMap = 0; /* Map from vector field to index column */
102899 char *zAff = 0; /* Affinity string for comparisons */
102900 int nVector; /* Size of vectors for this IN operator */
102901 int iDummy; /* Dummy parameter to exprCodeVector() */
102902 Expr *pLeft; /* The LHS of the IN operator */
102903 int i; /* loop counter */
102904 int destStep2; /* Where to jump when NULLs seen in step 2 */
102905 int destStep6 = 0; /* Start of code for Step 6 */
102906 int addrTruthOp; /* Address of opcode that determines the IN is true */
102907 int destNotNull; /* Jump here if a comparison is not true in step 6 */
102908 int addrTop; /* Top of the step-6 loop */
102909 int iTab = 0; /* Index to use */
102910 u8 okConstFactor = pParse->okConstFactor;
102911
102912 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
102913 pLeft = pExpr->pLeft;
102914 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
102915 zAff = exprINAffinity(pParse, pExpr);
102916 nVector = sqlite3ExprVectorSize(pExpr->pLeft);
102917 aiMap = (int*)sqlite3DbMallocZero(
102918 pParse->db, nVector*(sizeof(int) + sizeof(char)) + 1
102919 );
102920 if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
102921
102922 /* Attempt to compute the RHS. After this step, if anything other than
102923 ** IN_INDEX_NOOP is returned, the table opened with cursor iTab
102924 ** contains the values that make up the RHS. If IN_INDEX_NOOP is returned,
102925 ** the RHS has not yet been coded. */
102926 v = pParse->pVdbe;
102927 assert( v!=0 ); /* OOM detected prior to this routine */
102928 VdbeNoopComment((v, "begin IN expr"));
102929 eType = sqlite3FindInIndex(pParse, pExpr,
102931 destIfFalse==destIfNull ? 0 : &rRhsHasNull,
102932 aiMap, &iTab);
102933
102934 assert( pParse->nErr || nVector==1 || eType==IN_INDEX_EPH
102936 );
102937#ifdef SQLITE_DEBUG
102938 /* Confirm that aiMap[] contains nVector integer values between 0 and
102939 ** nVector-1. */
102940 for(i=0; i<nVector; i++){
102941 int j, cnt;
102942 for(cnt=j=0; j<nVector; j++) if( aiMap[j]==i ) cnt++;
102943 assert( cnt==1 );
102944 }
102945#endif
102946
102947 /* Code the LHS, the <expr> from "<expr> IN (...)". If the LHS is a
102948 ** vector, then it is stored in an array of nVector registers starting
102949 ** at r1.
102950 **
102951 ** sqlite3FindInIndex() might have reordered the fields of the LHS vector
102952 ** so that the fields are in the same order as an existing index. The
102953 ** aiMap[] array contains a mapping from the original LHS field order to
102954 ** the field order that matches the RHS index.
102955 **
102956 ** Avoid factoring the LHS of the IN(...) expression out of the loop,
102957 ** even if it is constant, as OP_Affinity may be used on the register
102958 ** by code generated below. */
102959 assert( pParse->okConstFactor==okConstFactor );
102960 pParse->okConstFactor = 0;
102961 rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
102962 pParse->okConstFactor = okConstFactor;
102963 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
102964 if( i==nVector ){
102965 /* LHS fields are not reordered */
102966 rLhs = rLhsOrig;
102967 }else{
102968 /* Need to reorder the LHS fields according to aiMap */
102969 rLhs = sqlite3GetTempRange(pParse, nVector);
102970 for(i=0; i<nVector; i++){
102971 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
102972 }
102973 }
102974
102975 /* If sqlite3FindInIndex() did not find or create an index that is
102976 ** suitable for evaluating the IN operator, then evaluate using a
102977 ** sequence of comparisons.
102978 **
102979 ** This is step (1) in the in-operator.md optimized algorithm.
102980 */
102981 if( eType==IN_INDEX_NOOP ){
102982 ExprList *pList = pExpr->x.pList;
102983 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
102984 int labelOk = sqlite3VdbeMakeLabel(pParse);
102985 int r2, regToFree;
102986 int regCkNull = 0;
102987 int ii;
102988 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
102989 if( destIfNull!=destIfFalse ){
102990 regCkNull = sqlite3GetTempReg(pParse);
102991 sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
102992 }
102993 for(ii=0; ii<pList->nExpr; ii++){
102994 r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
102995 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
102996 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
102997 }
102998 sqlite3ReleaseTempReg(pParse, regToFree);
102999 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
103000 int op = rLhs!=r2 ? OP_Eq : OP_NotNull;
103001 sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2,
103002 (void*)pColl, P4_COLLSEQ);
103003 VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq);
103004 VdbeCoverageIf(v, ii==pList->nExpr-1 && op==OP_Eq);
103005 VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_NotNull);
103006 VdbeCoverageIf(v, ii==pList->nExpr-1 && op==OP_NotNull);
103007 sqlite3VdbeChangeP5(v, zAff[0]);
103008 }else{
103009 int op = rLhs!=r2 ? OP_Ne : OP_IsNull;
103010 assert( destIfNull==destIfFalse );
103011 sqlite3VdbeAddOp4(v, op, rLhs, destIfFalse, r2,
103012 (void*)pColl, P4_COLLSEQ);
103013 VdbeCoverageIf(v, op==OP_Ne);
103014 VdbeCoverageIf(v, op==OP_IsNull);
103016 }
103017 }
103018 if( regCkNull ){
103019 sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
103020 sqlite3VdbeGoto(v, destIfFalse);
103021 }
103022 sqlite3VdbeResolveLabel(v, labelOk);
103023 sqlite3ReleaseTempReg(pParse, regCkNull);
103024 goto sqlite3ExprCodeIN_finished;
103025 }
103026
103027 /* Step 2: Check to see if the LHS contains any NULL columns. If the
103028 ** LHS does contain NULLs then the result must be either FALSE or NULL.
103029 ** We will then skip the binary search of the RHS.
103030 */
103031 if( destIfNull==destIfFalse ){
103032 destStep2 = destIfFalse;
103033 }else{
103034 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
103035 }
103036 if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
103037 for(i=0; i<nVector; i++){
103038 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
103039 if( sqlite3ExprCanBeNull(p) ){
103040 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
103041 VdbeCoverage(v);
103042 }
103043 }
103044
103045 /* Step 3. The LHS is now known to be non-NULL. Do the binary search
103046 ** of the RHS using the LHS as a probe. If found, the result is
103047 ** true.
103048 */
103049 if( eType==IN_INDEX_ROWID ){
103050 /* In this case, the RHS is the ROWID of table b-tree and so we also
103051 ** know that the RHS is non-NULL. Hence, we combine steps 3 and 4
103052 ** into a single opcode. */
103053 sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs);
103054 VdbeCoverage(v);
103055 addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
103056 }else{
103057 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
103058 if( destIfFalse==destIfNull ){
103059 /* Combine Step 3 and Step 5 into a single opcode */
103060 sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
103061 rLhs, nVector); VdbeCoverage(v);
103062 goto sqlite3ExprCodeIN_finished;
103063 }
103064 /* Ordinary Step 3, for the case where FALSE and NULL are distinct */
103065 addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, iTab, 0,
103066 rLhs, nVector); VdbeCoverage(v);
103067 }
103068
103069 /* Step 4. If the RHS is known to be non-NULL and we did not find
103070 ** an match on the search above, then the result must be FALSE.
103071 */
103072 if( rRhsHasNull && nVector==1 ){
103073 sqlite3VdbeAddOp2(v, OP_NotNull, rRhsHasNull, destIfFalse);
103074 VdbeCoverage(v);
103075 }
103076
103077 /* Step 5. If we do not care about the difference between NULL and
103078 ** FALSE, then just return false.
103079 */
103080 if( destIfFalse==destIfNull ) sqlite3VdbeGoto(v, destIfFalse);
103081
103082 /* Step 6: Loop through rows of the RHS. Compare each row to the LHS.
103083 ** If any comparison is NULL, then the result is NULL. If all
103084 ** comparisons are FALSE then the final result is FALSE.
103085 **
103086 ** For a scalar LHS, it is sufficient to check just the first row
103087 ** of the RHS.
103088 */
103089 if( destStep6 ) sqlite3VdbeResolveLabel(v, destStep6);
103090 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, destIfFalse);
103091 VdbeCoverage(v);
103092 if( nVector>1 ){
103093 destNotNull = sqlite3VdbeMakeLabel(pParse);
103094 }else{
103095 /* For nVector==1, combine steps 6 and 7 by immediately returning
103096 ** FALSE if the first comparison is not NULL */
103097 destNotNull = destIfFalse;
103098 }
103099 for(i=0; i<nVector; i++){
103100 Expr *p;
103101 CollSeq *pColl;
103102 int r3 = sqlite3GetTempReg(pParse);
103103 p = sqlite3VectorFieldSubexpr(pLeft, i);
103104 pColl = sqlite3ExprCollSeq(pParse, p);
103105 sqlite3VdbeAddOp3(v, OP_Column, iTab, i, r3);
103106 sqlite3VdbeAddOp4(v, OP_Ne, rLhs+i, destNotNull, r3,
103107 (void*)pColl, P4_COLLSEQ);
103108 VdbeCoverage(v);
103109 sqlite3ReleaseTempReg(pParse, r3);
103110 }
103111 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
103112 if( nVector>1 ){
103113 sqlite3VdbeResolveLabel(v, destNotNull);
103114 sqlite3VdbeAddOp2(v, OP_Next, iTab, addrTop+1);
103115 VdbeCoverage(v);
103116
103117 /* Step 7: If we reach this point, we know that the result must
103118 ** be false. */
103119 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
103120 }
103121
103122 /* Jumps here in order to return true. */
103123 sqlite3VdbeJumpHere(v, addrTruthOp);
103124
103125sqlite3ExprCodeIN_finished:
#define OP_BitAnd
Definition sqlite3.c:15667
#define IN_INDEX_MEMBERSHIP
Definition sqlite3.c:20237
#define IN_INDEX_EPH
Definition sqlite3.c:20229
#define IN_INDEX_INDEX_ASC
Definition sqlite3.c:20230
#define IN_INDEX_NOOP_OK
Definition sqlite3.c:20236

References ExprList::a, Parse::db, EP_Immutable, EP_xIsSelect, eType, exprCodeVector(), ExprHasProperty, ExprHasVVAProperty, exprINAffinity(), IN_INDEX_EPH, IN_INDEX_INDEX_ASC, IN_INDEX_INDEX_DESC, IN_INDEX_MEMBERSHIP, IN_INDEX_NOOP, IN_INDEX_NOOP_OK, IN_INDEX_ROWID, sqlite3::mallocFailed, Parse::nErr, ExprList::nExpr, Parse::okConstFactor, OP_Affinity, OP_BitAnd, OP_Column, OP_Copy, OP_Eq, OP_Found, OP_Goto, OP_IsNull, OP_Ne, OP_Next, OP_NotFound, OP_NotNull, OP_Rewind, OP_SeekRowid, P4_COLLSEQ, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Parse::pVdbe, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3ExprCanBeNull(), sqlite3ExprCheckIN(), sqlite3ExprCodeTemp(), sqlite3ExprCollSeq(), sqlite3ExprVectorSize(), sqlite3FindInIndex(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VectorFieldSubexpr(), SQLITE_JUMPIFNULL, VdbeComment, VdbeCoverage, VdbeCoverageIf, VdbeNoopComment, and Expr::x.

Referenced by sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), and sqlite3ExprIfTrue().

◆ sqlite3ExprCodeLoadIndexColumn()

SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn ( Parse * pParse,
Index * pIdx,
int iTabCur,
int iIdxCol,
int regOut )

Definition at line 103192 of file sqlite3.c.

103204 {
103205 i16 iTabCol = pIdx->aiColumn[iIdxCol];
103206 if( iTabCol==XN_EXPR ){
103207 assert( pIdx->aColExpr );
103208 assert( pIdx->aColExpr->nExpr>iIdxCol );
103209 pParse->iSelfTab = iTabCur + 1;
103210 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse *, Expr *, int)
Definition sqlite3.c:104365

Referenced by analyzeOneTable(), and sqlite3GenerateIndexKey().

◆ sqlite3ExprCodeMove()

SQLITE_PRIVATE void sqlite3ExprCodeMove ( Parse * pParse,
int iFrom,
int iTo,
int nReg )

Definition at line 103320 of file sqlite3.c.

Referenced by generateOutputSubroutine(), and sqlite3Select().

◆ sqlite3ExprCodeRunJustOnce()

SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce ( Parse * pParse,
Expr * pExpr,
int regDest )

Definition at line 104257 of file sqlite3.c.

104267 {
104268 ExprList *p;
104269 assert( ConstFactorOk(pParse) );
104270 p = pParse->pConstExpr;
104271 if( regDest<0 && p ){
104272 struct ExprList_item *pItem;
104273 int i;
104274 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
104275 if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
104276 return pItem->u.iConstExprReg;
104277 }
104278 }
104279 }
104280 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
104281 if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){
104282 Vdbe *v = pParse->pVdbe;
104283 int addr;
104284 assert( v );
104285 addr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
104286 pParse->okConstFactor = 0;
104287 if( !pParse->db->mallocFailed ){
104288 if( regDest<0 ) regDest = ++pParse->nMem;
104289 sqlite3ExprCode(pParse, pExpr, regDest);
104290 }
104291 pParse->okConstFactor = 1;
104292 sqlite3ExprDelete(pParse->db, pExpr);
104293 sqlite3VdbeJumpHere(v, addr);
104294 }else{
104295 p = sqlite3ExprListAppend(pParse, p, pExpr);
104296 if( p ){
104297 struct ExprList_item *pItem = &p->a[p->nExpr-1];
104298 pItem->reusable = regDest<0;
104299 if( regDest<0 ) regDest = ++pParse->nMem;
#define EP_HasFunc
Definition sqlite3.c:18062

References ExprList::a, ConstFactorOk, Parse::db, EP_HasFunc, ExprHasProperty, sqlite3::mallocFailed, ExprList::nExpr, Parse::nMem, Parse::okConstFactor, OP_Once, Parse::pConstExpr, Parse::pVdbe, ExprList::ExprList_item::reusable, sqlite3ExprCode(), sqlite3ExprCompare(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3VdbeAddOp0(), sqlite3VdbeJumpHere(), and VdbeCoverage.

Referenced by sqlite3ExprCodeExprList(), sqlite3ExprCodeFactorable(), sqlite3ExprCodeTarget(), and sqlite3ExprCodeTemp().

◆ sqlite3ExprCodeTarget()

SQLITE_PRIVATE int sqlite3ExprCodeTarget ( Parse * pParse,
Expr * pExpr,
int target )

Definition at line 103502 of file sqlite3.c.

103508 {
103509 Vdbe *v = pParse->pVdbe; /* The VM under construction */
103510 int op; /* The opcode being coded */
103511 int inReg = target; /* Results stored in register inReg */
103512 int regFree1 = 0; /* If non-zero free this temporary register */
103513 int regFree2 = 0; /* If non-zero free this temporary register */
103514 int r1, r2; /* Various register numbers */
103515 Expr tempX; /* Temporary expression node */
103516 int p5 = 0;
103517
103518 assert( target>0 && target<=pParse->nMem );
103519 assert( v!=0 );
103520
103521expr_code_doover:
103522 if( pExpr==0 ){
103523 op = TK_NULL;
103524 }else{
103525 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
103526 op = pExpr->op;
103527 }
103528 switch( op ){
103529 case TK_AGG_COLUMN: {
103530 AggInfo *pAggInfo = pExpr->pAggInfo;
103531 struct AggInfo_col *pCol;
103532 assert( pAggInfo!=0 );
103533 assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
103534 pCol = &pAggInfo->aCol[pExpr->iAgg];
103535 if( !pAggInfo->directMode ){
103536 assert( pCol->iMem>0 );
103537 return pCol->iMem;
103538 }else if( pAggInfo->useSortingIdx ){
103539 Table *pTab = pCol->pTab;
103541 pCol->iSorterColumn, target);
103542 if( pCol->iColumn<0 ){
103543 VdbeComment((v,"%s.rowid",pTab->zName));
103544 }else{
103545 VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName));
103546 if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
103548 }
103549 }
103550 return target;
103551 }
103552 /* Otherwise, fall thru into the TK_COLUMN case */
103553 /* no break */ deliberate_fall_through
103554 }
103555 case TK_COLUMN: {
103556 int iTab = pExpr->iTable;
103557 int iReg;
103558 if( ExprHasProperty(pExpr, EP_FixedCol) ){
103559 /* This COLUMN expression is really a constant due to WHERE clause
103560 ** constraints, and that constant is coded by the pExpr->pLeft
103561 ** expresssion. However, make sure the constant has the correct
103562 ** datatype by applying the Affinity of the table column to the
103563 ** constant.
103564 */
103565 int aff;
103566 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
103567 if( pExpr->y.pTab ){
103568 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
103569 }else{
103570 aff = pExpr->affExpr;
103571 }
103572 if( aff>SQLITE_AFF_BLOB ){
103573 static const char zAff[] = "B\000C\000D\000E";
103574 assert( SQLITE_AFF_BLOB=='A' );
103575 assert( SQLITE_AFF_TEXT=='B' );
103576 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
103577 &zAff[(aff-'B')*2], P4_STATIC);
103578 }
103579 return iReg;
103580 }
103581 if( iTab<0 ){
103582 if( pParse->iSelfTab<0 ){
103583 /* Other columns in the same row for CHECK constraints or
103584 ** generated columns or for inserting into partial index.
103585 ** The row is unpacked into registers beginning at
103586 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
103587 ** immediately prior to the first column.
103588 */
103589 Column *pCol;
103590 Table *pTab = pExpr->y.pTab;
103591 int iSrc;
103592 int iCol = pExpr->iColumn;
103593 assert( pTab!=0 );
103594 assert( iCol>=XN_ROWID );
103595 assert( iCol<pTab->nCol );
103596 if( iCol<0 ){
103597 return -1-pParse->iSelfTab;
103598 }
103599 pCol = pTab->aCol + iCol;
103600 testcase( iCol!=sqlite3TableColumnToStorage(pTab,iCol) );
103601 iSrc = sqlite3TableColumnToStorage(pTab, iCol) - pParse->iSelfTab;
103602#ifndef SQLITE_OMIT_GENERATED_COLUMNS
103603 if( pCol->colFlags & COLFLAG_GENERATED ){
103604 if( pCol->colFlags & COLFLAG_BUSY ){
103605 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"",
103606 pCol->zName);
103607 return 0;
103608 }
103609 pCol->colFlags |= COLFLAG_BUSY;
103610 if( pCol->colFlags & COLFLAG_NOTAVAIL ){
103611 sqlite3ExprCodeGeneratedColumn(pParse, pCol, iSrc);
103612 }
103614 return iSrc;
103615 }else
103616#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
103617 if( pCol->affinity==SQLITE_AFF_REAL ){
103618 sqlite3VdbeAddOp2(v, OP_SCopy, iSrc, target);
103620 return target;
103621 }else{
103622 return iSrc;
103623 }
103624 }else{
103625 /* Coding an expression that is part of an index where column names
103626 ** in the index refer to the table to which the index belongs */
103627 iTab = pParse->iSelfTab - 1;
103628 }
103629 }
103630 iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
103631 pExpr->iColumn, iTab, target,
103632 pExpr->op2);
103633 if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
103635 }
103636 return iReg;
103637 }
103638 case TK_INTEGER: {
103639 codeInteger(pParse, pExpr, 0, target);
103640 return target;
103641 }
103642 case TK_TRUEFALSE: {
103644 return target;
103645 }
103646#ifndef SQLITE_OMIT_FLOATING_POINT
103647 case TK_FLOAT: {
103648 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103649 codeReal(v, pExpr->u.zToken, 0, target);
103650 return target;
103651 }
103652#endif
103653 case TK_STRING: {
103654 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103655 sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
103656 return target;
103657 }
103658 default: {
103659 /* Make NULL the default case so that if a bug causes an illegal
103660 ** Expr node to be passed into this function, it will be handled
103661 ** sanely and not crash. But keep the assert() to bring the problem
103662 ** to the attention of the developers. */
103663 assert( op==TK_NULL );
103664 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
103665 return target;
103666 }
103667#ifndef SQLITE_OMIT_BLOB_LITERAL
103668 case TK_BLOB: {
103669 int n;
103670 const char *z;
103671 char *zBlob;
103672 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103673 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
103674 assert( pExpr->u.zToken[1]=='\'' );
103675 z = &pExpr->u.zToken[2];
103676 n = sqlite3Strlen30(z) - 1;
103677 assert( z[n]=='\'' );
103678 zBlob = sqlite3HexToBlob(sqlite3VdbeDb(v), z, n);
103679 sqlite3VdbeAddOp4(v, OP_Blob, n/2, target, 0, zBlob, P4_DYNAMIC);
103680 return target;
103681 }
103682#endif
103683 case TK_VARIABLE: {
103684 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103685 assert( pExpr->u.zToken!=0 );
103686 assert( pExpr->u.zToken[0]!=0 );
103687 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
103688 if( pExpr->u.zToken[1]!=0 ){
103689 const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn);
103690 assert( pExpr->u.zToken[0]=='?' || (z && !strcmp(pExpr->u.zToken, z)) );
103691 pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */
103692 sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
103693 }
103694 return target;
103695 }
103696 case TK_REGISTER: {
103697 return pExpr->iTable;
103698 }
103699#ifndef SQLITE_OMIT_CAST
103700 case TK_CAST: {
103701 /* Expressions of the form: CAST(pLeft AS token) */
103702 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
103703 if( inReg!=target ){
103704 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
103705 inReg = target;
103706 }
103707 sqlite3VdbeAddOp2(v, OP_Cast, target,
103708 sqlite3AffinityType(pExpr->u.zToken, 0));
103709 return inReg;
103710 }
103711#endif /* SQLITE_OMIT_CAST */
103712 case TK_IS:
103713 case TK_ISNOT:
103714 op = (op==TK_IS) ? TK_EQ : TK_NE;
103715 p5 = SQLITE_NULLEQ;
103716 /* fall-through */
103717 case TK_LT:
103718 case TK_LE:
103719 case TK_GT:
103720 case TK_GE:
103721 case TK_NE:
103722 case TK_EQ: {
103723 Expr *pLeft = pExpr->pLeft;
103724 if( sqlite3ExprIsVector(pLeft) ){
103725 codeVectorCompare(pParse, pExpr, target, op, p5);
103726 }else{
103727 r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
103728 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
103729 codeCompare(pParse, pLeft, pExpr->pRight, op,
103730 r1, r2, inReg, SQLITE_STOREP2 | p5,
103732 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
103733 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
103734 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
103735 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
103736 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
103737 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
103738 testcase( regFree1==0 );
103739 testcase( regFree2==0 );
103740 }
103741 break;
103742 }
103743 case TK_AND:
103744 case TK_OR:
103745 case TK_PLUS:
103746 case TK_STAR:
103747 case TK_MINUS:
103748 case TK_REM:
103749 case TK_BITAND:
103750 case TK_BITOR:
103751 case TK_SLASH:
103752 case TK_LSHIFT:
103753 case TK_RSHIFT:
103754 case TK_CONCAT: {
103755 assert( TK_AND==OP_And ); testcase( op==TK_AND );
103756 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
103757 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
103758 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
103759 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
103760 assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
103761 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
103762 assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
103763 assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
103764 assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
103765 assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
103766 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
103767 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
103768 sqlite3VdbeAddOp3(v, op, r2, r1, target);
103769 testcase( regFree1==0 );
103770 testcase( regFree2==0 );
103771 break;
103772 }
103773 case TK_UMINUS: {
103774 Expr *pLeft = pExpr->pLeft;
103775 assert( pLeft );
103776 if( pLeft->op==TK_INTEGER ){
103777 codeInteger(pParse, pLeft, 1, target);
103778 return target;
103779#ifndef SQLITE_OMIT_FLOATING_POINT
103780 }else if( pLeft->op==TK_FLOAT ){
103781 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103782 codeReal(v, pLeft->u.zToken, 1, target);
103783 return target;
103784#endif
103785 }else{
103786 tempX.op = TK_INTEGER;
103788 tempX.u.iValue = 0;
103789 ExprClearVVAProperties(&tempX);
103790 r1 = sqlite3ExprCodeTemp(pParse, &tempX, &regFree1);
103791 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
103792 sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
103793 testcase( regFree2==0 );
103794 }
103795 break;
103796 }
103797 case TK_BITNOT:
103798 case TK_NOT: {
103799 assert( TK_BITNOT==OP_BitNot ); testcase( op==TK_BITNOT );
103800 assert( TK_NOT==OP_Not ); testcase( op==TK_NOT );
103801 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
103802 testcase( regFree1==0 );
103803 sqlite3VdbeAddOp2(v, op, r1, inReg);
103804 break;
103805 }
103806 case TK_TRUTH: {
103807 int isTrue; /* IS TRUE or IS NOT TRUE */
103808 int bNormal; /* IS TRUE or IS FALSE */
103809 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
103810 testcase( regFree1==0 );
103811 isTrue = sqlite3ExprTruthValue(pExpr->pRight);
103812 bNormal = pExpr->op2==TK_IS;
103813 testcase( isTrue && bNormal);
103814 testcase( !isTrue && bNormal);
103815 sqlite3VdbeAddOp4Int(v, OP_IsTrue, r1, inReg, !isTrue, isTrue ^ bNormal);
103816 break;
103817 }
103818 case TK_ISNULL:
103819 case TK_NOTNULL: {
103820 int addr;
103821 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
103822 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
103823 sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
103824 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
103825 testcase( regFree1==0 );
103826 addr = sqlite3VdbeAddOp1(v, op, r1);
103827 VdbeCoverageIf(v, op==TK_ISNULL);
103828 VdbeCoverageIf(v, op==TK_NOTNULL);
103829 sqlite3VdbeAddOp2(v, OP_Integer, 0, target);
103830 sqlite3VdbeJumpHere(v, addr);
103831 break;
103832 }
103833 case TK_AGG_FUNCTION: {
103834 AggInfo *pInfo = pExpr->pAggInfo;
103835 if( pInfo==0
103836 || NEVER(pExpr->iAgg<0)
103837 || NEVER(pExpr->iAgg>=pInfo->nFunc)
103838 ){
103839 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103840 sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
103841 }else{
103842 return pInfo->aFunc[pExpr->iAgg].iMem;
103843 }
103844 break;
103845 }
103846 case TK_FUNCTION: {
103847 ExprList *pFarg; /* List of function arguments */
103848 int nFarg; /* Number of function arguments */
103849 FuncDef *pDef; /* The function definition object */
103850 const char *zId; /* The function name */
103851 u32 constMask = 0; /* Mask of function arguments that are constant */
103852 int i; /* Loop counter */
103853 sqlite3 *db = pParse->db; /* The database connection */
103854 u8 enc = ENC(db); /* The text encoding used by this database */
103855 CollSeq *pColl = 0; /* A collating sequence */
103856
103857#ifndef SQLITE_OMIT_WINDOWFUNC
103858 if( ExprHasProperty(pExpr, EP_WinFunc) ){
103859 return pExpr->y.pWin->regResult;
103860 }
103861#endif
103862
103863 if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
103864 /* SQL functions can be expensive. So try to avoid running them
103865 ** multiple times if we know they always give the same result */
103866 return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
103867 }
103868 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
103869 assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
103870 pFarg = pExpr->x.pList;
103871 nFarg = pFarg ? pFarg->nExpr : 0;
103872 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103873 zId = pExpr->u.zToken;
103874 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
103875#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
103876 if( pDef==0 && pParse->explain ){
103877 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
103878 }
103879#endif
103880 if( pDef==0 || pDef->xFinalize!=0 ){
103881 sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
103882 break;
103883 }
103884 if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
103885 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
103886 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
103887 return exprCodeInlineFunction(pParse, pFarg,
103888 SQLITE_PTR_TO_INT(pDef->pUserData), target);
103889 }else if( pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE) ){
103890 sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
103891 }
103892
103893 for(i=0; i<nFarg; i++){
103894 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
103895 testcase( i==31 );
103896 constMask |= MASKBIT32(i);
103897 }
103898 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
103899 pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
103900 }
103901 }
103902 if( pFarg ){
103903 if( constMask ){
103904 r1 = pParse->nMem+1;
103905 pParse->nMem += nFarg;
103906 }else{
103907 r1 = sqlite3GetTempRange(pParse, nFarg);
103908 }
103909
103910 /* For length() and typeof() functions with a column argument,
103911 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
103912 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
103913 ** loading.
103914 */
103915 if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
103916 u8 exprOp;
103917 assert( nFarg==1 );
103918 assert( pFarg->a[0].pExpr!=0 );
103919 exprOp = pFarg->a[0].pExpr->op;
103920 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
103924 pFarg->a[0].pExpr->op2 =
103926 }
103927 }
103928
103929 sqlite3ExprCodeExprList(pParse, pFarg, r1, 0,
103931 }else{
103932 r1 = 0;
103933 }
103934#ifndef SQLITE_OMIT_VIRTUALTABLE
103935 /* Possibly overload the function if the first argument is
103936 ** a virtual table column.
103937 **
103938 ** For infix functions (LIKE, GLOB, REGEXP, and MATCH) use the
103939 ** second argument, not the first, as the argument to test to
103940 ** see if it is a column in a virtual table. This is done because
103941 ** the left operand of infix functions (the operand we want to
103942 ** control overloading) ends up as the second argument to the
103943 ** function. The expression "A glob B" is equivalent to
103944 ** "glob(B,A). We want to use the A in "A glob B" to test
103945 ** for function overloading. But we use the B term in "glob(B,A)".
103946 */
103947 if( nFarg>=2 && ExprHasProperty(pExpr, EP_InfixFunc) ){
103948 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
103949 }else if( nFarg>0 ){
103950 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
103951 }
103952#endif
103953 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
103954 if( !pColl ) pColl = db->pDfltColl;
103955 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
103956 }
103957#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
103958 if( pDef->funcFlags & SQLITE_FUNC_OFFSET ){
103959 Expr *pArg = pFarg->a[0].pExpr;
103960 if( pArg->op==TK_COLUMN ){
103961 sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
103962 }else{
103963 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
103964 }
103965 }else
103966#endif
103967 {
103968 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
103969 pDef, pExpr->op2);
103970 }
103971 if( nFarg ){
103972 if( constMask==0 ){
103973 sqlite3ReleaseTempRange(pParse, r1, nFarg);
103974 }else{
103975 sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1);
103976 }
103977 }
103978 return target;
103979 }
103980#ifndef SQLITE_OMIT_SUBQUERY
103981 case TK_EXISTS:
103982 case TK_SELECT: {
103983 int nCol;
103984 testcase( op==TK_EXISTS );
103985 testcase( op==TK_SELECT );
103986 if( pParse->db->mallocFailed ){
103987 return 0;
103988 }else if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){
103989 sqlite3SubselectError(pParse, nCol, 1);
103990 }else{
103991 return sqlite3CodeSubselect(pParse, pExpr);
103992 }
103993 break;
103994 }
103995 case TK_SELECT_COLUMN: {
103996 int n;
103997 if( pExpr->pLeft->iTable==0 ){
103998 pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft);
103999 }
104000 assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT );
104001 if( pExpr->iTable!=0
104002 && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft))
104003 ){
104004 sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
104005 pExpr->iTable, n);
104006 }
104007 return pExpr->pLeft->iTable + pExpr->iColumn;
104008 }
104009 case TK_IN: {
104010 int destIfFalse = sqlite3VdbeMakeLabel(pParse);
104011 int destIfNull = sqlite3VdbeMakeLabel(pParse);
104012 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
104013 sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
104014 sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
104015 sqlite3VdbeResolveLabel(v, destIfFalse);
104016 sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
104017 sqlite3VdbeResolveLabel(v, destIfNull);
104018 return target;
104019 }
104020#endif /* SQLITE_OMIT_SUBQUERY */
104021
104022
104023 /*
104024 ** x BETWEEN y AND z
104025 **
104026 ** This is equivalent to
104027 **
104028 ** x>=y AND x<=z
104029 **
104030 ** X is stored in pExpr->pLeft.
104031 ** Y is stored in pExpr->pList->a[0].pExpr.
104032 ** Z is stored in pExpr->pList->a[1].pExpr.
104033 */
104034 case TK_BETWEEN: {
104035 exprCodeBetween(pParse, pExpr, target, 0, 0);
104036 return target;
104037 }
104038 case TK_SPAN:
104039 case TK_COLLATE:
104040 case TK_UPLUS: {
104041 pExpr = pExpr->pLeft;
104042 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
104043 }
104044
104045 case TK_TRIGGER: {
104046 /* If the opcode is TK_TRIGGER, then the expression is a reference
104047 ** to a column in the new.* or old.* pseudo-tables available to
104048 ** trigger programs. In this case Expr.iTable is set to 1 for the
104049 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
104050 ** is set to the column of the pseudo-table to read, or to -1 to
104051 ** read the rowid field.
104052 **
104053 ** The expression is implemented using an OP_Param opcode. The p1
104054 ** parameter is set to 0 for an old.rowid reference, or to (i+1)
104055 ** to reference another column of the old.* pseudo-table, where
104056 ** i is the index of the column. For a new.rowid reference, p1 is
104057 ** set to (n+1), where n is the number of columns in each pseudo-table.
104058 ** For a reference to any other column in the new.* pseudo-table, p1
104059 ** is set to (n+2+i), where n and i are as defined previously. For
104060 ** example, if the table on which triggers are being fired is
104061 ** declared as:
104062 **
104063 ** CREATE TABLE t1(a, b);
104064 **
104065 ** Then p1 is interpreted as follows:
104066 **
104067 ** p1==0 -> old.rowid p1==3 -> new.rowid
104068 ** p1==1 -> old.a p1==4 -> new.a
104069 ** p1==2 -> old.b p1==5 -> new.b
104070 */
104071 Table *pTab = pExpr->y.pTab;
104072 int iCol = pExpr->iColumn;
104073 int p1 = pExpr->iTable * (pTab->nCol+1) + 1
104074 + sqlite3TableColumnToStorage(pTab, iCol);
104075
104076 assert( pExpr->iTable==0 || pExpr->iTable==1 );
104077 assert( iCol>=-1 && iCol<pTab->nCol );
104078 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
104079 assert( p1>=0 && p1<(pTab->nCol*2+2) );
104080
104081 sqlite3VdbeAddOp2(v, OP_Param, p1, target);
104082 VdbeComment((v, "r[%d]=%s.%s", target,
104083 (pExpr->iTable ? "new" : "old"),
104084 (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zName)
104085 ));
104086
104087#ifndef SQLITE_OMIT_FLOATING_POINT
104088 /* If the column has REAL affinity, it may currently be stored as an
104089 ** integer. Use OP_RealAffinity to make sure it is really real.
104090 **
104091 ** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
104092 ** floating point when extracting it from the record. */
104093 if( iCol>=0 && pTab->aCol[iCol].affinity==SQLITE_AFF_REAL ){
104095 }
104096#endif
104097 break;
104098 }
104099
104100 case TK_VECTOR: {
104101 sqlite3ErrorMsg(pParse, "row value misused");
104102 break;
104103 }
104104
104105 /* TK_IF_NULL_ROW Expr nodes are inserted ahead of expressions
104106 ** that derive from the right-hand table of a LEFT JOIN. The
104107 ** Expr.iTable value is the table number for the right-hand table.
104108 ** The expression is only evaluated if that table is not currently
104109 ** on a LEFT JOIN NULL row.
104110 */
104111 case TK_IF_NULL_ROW: {
104112 int addrINR;
104113 u8 okConstFactor = pParse->okConstFactor;
104114 addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
104115 /* Temporarily disable factoring of constant expressions, since
104116 ** even though expressions may appear to be constant, they are not
104117 ** really constant because they originate from the right-hand side
104118 ** of a LEFT JOIN. */
104119 pParse->okConstFactor = 0;
104120 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
104121 pParse->okConstFactor = okConstFactor;
104122 sqlite3VdbeJumpHere(v, addrINR);
104123 sqlite3VdbeChangeP3(v, addrINR, inReg);
104124 break;
104125 }
104126
104127 /*
104128 ** Form A:
104129 ** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
104130 **
104131 ** Form B:
104132 ** CASE WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
104133 **
104134 ** Form A is can be transformed into the equivalent form B as follows:
104135 ** CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
104136 ** WHEN x=eN THEN rN ELSE y END
104137 **
104138 ** X (if it exists) is in pExpr->pLeft.
104139 ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
104140 ** odd. The Y is also optional. If the number of elements in x.pList
104141 ** is even, then Y is omitted and the "otherwise" result is NULL.
104142 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
104143 **
104144 ** The result of the expression is the Ri for the first matching Ei,
104145 ** or if there is no matching Ei, the ELSE term Y, or if there is
104146 ** no ELSE term, NULL.
104147 */
104148 case TK_CASE: {
104149 int endLabel; /* GOTO label for end of CASE stmt */
104150 int nextCase; /* GOTO label for next WHEN clause */
104151 int nExpr; /* 2x number of WHEN terms */
104152 int i; /* Loop counter */
104153 ExprList *pEList; /* List of WHEN terms */
104154 struct ExprList_item *aListelem; /* Array of WHEN terms */
104155 Expr opCompare; /* The X==Ei expression */
104156 Expr *pX; /* The X expression */
104157 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
104158 Expr *pDel = 0;
104159 sqlite3 *db = pParse->db;
104160
104161 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
104162 assert(pExpr->x.pList->nExpr > 0);
104163 pEList = pExpr->x.pList;
104164 aListelem = pEList->a;
104165 nExpr = pEList->nExpr;
104166 endLabel = sqlite3VdbeMakeLabel(pParse);
104167 if( (pX = pExpr->pLeft)!=0 ){
104168 pDel = sqlite3ExprDup(db, pX, 0);
104169 if( db->mallocFailed ){
104170 sqlite3ExprDelete(db, pDel);
104171 break;
104172 }
104173 testcase( pX->op==TK_COLUMN );
104174 exprToRegister(pDel, exprCodeVector(pParse, pDel, &regFree1));
104175 testcase( regFree1==0 );
104176 memset(&opCompare, 0, sizeof(opCompare));
104177 opCompare.op = TK_EQ;
104178 opCompare.pLeft = pDel;
104179 pTest = &opCompare;
104180 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
104181 ** The value in regFree1 might get SCopy-ed into the file result.
104182 ** So make sure that the regFree1 register is not reused for other
104183 ** purposes and possibly overwritten. */
104184 regFree1 = 0;
104185 }
104186 for(i=0; i<nExpr-1; i=i+2){
104187 if( pX ){
104188 assert( pTest!=0 );
104189 opCompare.pRight = aListelem[i].pExpr;
104190 }else{
104191 pTest = aListelem[i].pExpr;
104192 }
104193 nextCase = sqlite3VdbeMakeLabel(pParse);
104194 testcase( pTest->op==TK_COLUMN );
104195 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
104196 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
104197 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
104198 sqlite3VdbeGoto(v, endLabel);
104199 sqlite3VdbeResolveLabel(v, nextCase);
104200 }
104201 if( (nExpr&1)!=0 ){
104202 sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target);
104203 }else{
104204 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
104205 }
104206 sqlite3ExprDelete(db, pDel);
104208 sqlite3VdbeResolveLabel(v, endLabel);
104209 break;
104210 }
104211#ifndef SQLITE_OMIT_TRIGGER
104212 case TK_RAISE: {
104213 assert( pExpr->affExpr==OE_Rollback
104214 || pExpr->affExpr==OE_Abort
104215 || pExpr->affExpr==OE_Fail
104216 || pExpr->affExpr==OE_Ignore
104217 );
104218 if( !pParse->pTriggerTab && !pParse->nested ){
104219 sqlite3ErrorMsg(pParse,
104220 "RAISE() may only be used within a trigger-program");
104221 return 0;
104222 }
104223 if( pExpr->affExpr==OE_Abort ){
104224 sqlite3MayAbort(pParse);
104225 }
104226 assert( !ExprHasProperty(pExpr, EP_IntValue) );
104227 if( pExpr->affExpr==OE_Ignore ){
104229 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
104230 VdbeCoverage(v);
104231 }else{
104232 sqlite3HaltConstraint(pParse,
104234 pExpr->affExpr, pExpr->u.zToken, 0, 0);
104235 }
104236
104237 break;
104238 }
SQLITE_PRIVATE FuncDef * sqlite3VtabOverloadFunction(sqlite3 *, FuncDef *, int nArg, Expr *)
Definition sqlite3.c:140672
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse *, Table *, int, int, int, u8)
Definition sqlite3.c:103299
#define OP_IsTrue
Definition sqlite3.c:15653
#define OPFLAG_TYPEOFARG
Definition sqlite3.c:18846
SQLITE_PRIVATE const char * sqlite3VListNumToName(VList *, int)
Definition sqlite3.c:32847
#define EP_InfixFunc
Definition sqlite3.c:18067
#define OP_Variable
Definition sqlite3.c:15641
#define OP_CollSeq
Definition sqlite3.c:15647
#define SQLITE_FUNC_TYPEOF
Definition sqlite3.c:17151
#define OP_Divide
Definition sqlite3.c:15674
#define OP_BitOr
Definition sqlite3.c:15668
#define sqlite3VdbeReleaseRegisters(P, A, N, M, F)
Definition sqlite3.c:15857
#define SQLITE_CONSTRAINT_TRIGGER
Definition sqlite3.c:1582
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *)
Definition sqlite3.c:101648
#define OP_Subtract
Definition sqlite3.c:15672
#define OP_Cast
Definition sqlite3.c:15650
SQLITE_PRIVATE void * sqlite3HexToBlob(sqlite3 *, const char *z, int n)
Definition sqlite3.c:32500
#define OP_Not
Definition sqlite3.c:15585
#define OP_Concat
Definition sqlite3.c:15676
#define OP_RealAffinity
Definition sqlite3.c:15649
static int exprCodeInlineFunction(Parse *pParse, ExprList *pFarg, int iFuncId, int target)
Definition sqlite3.c:103386
#define OP_Blob
Definition sqlite3.c:15640
#define OP_Offset
Definition sqlite3.c:15654
#define MASKBIT32(n)
Definition sqlite3.c:14733
#define SQLITE_FUNC_OFFSET
Definition sqlite3.c:17159
#define OP_ShiftRight
Definition sqlite3.c:15670
#define OP_And
Definition sqlite3.c:15610
#define OP_ShiftLeft
Definition sqlite3.c:15669
#define OP_Param
Definition sqlite3.c:15714
#define OE_Fail
Definition sqlite3.c:17659
#define OE_Rollback
Definition sqlite3.c:17657
static void sqlite3ExprCodeIN(Parse *pParse, Expr *pExpr, int destIfFalse, int destIfNull)
Definition sqlite3.c:102881
#define OP_Or
Definition sqlite3.c:15609
#define OPFLAG_LENGTHARG
Definition sqlite3.c:18845
#define OP_Remainder
Definition sqlite3.c:15675
#define OP_BitNot
Definition sqlite3.c:15678
#define OP_Add
Definition sqlite3.c:15671
static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem)
Definition sqlite3.c:103155
#define SQLITE_FUNC_LENGTH
Definition sqlite3.c:17150
int sortingIdxPTab
Definition sqlite3.c:17887
u8 useSortingIdx
Definition sqlite3.c:17884
u8 directMode
Definition sqlite3.c:17882
void * pUserData
Definition sqlite3.c:17097
VList * pVList
Definition sqlite3.c:18759
int regResult
Definition sqlite3.c:19208

References ExprList::a, Table::aCol, AggInfo::aCol, Expr::affExpr, Column::affinity, AggInfo::aFunc, codeCompare(), codeInteger(), codeReal(), codeVectorCompare(), COLFLAG_BUSY, COLFLAG_GENERATED, COLFLAG_NOTAVAIL, Column::colFlags, ConstFactorOk, Parse::db, deliberate_fall_through, AggInfo::directMode, ENC, EP_Commuted, EP_FixedCol, EP_Immutable, EP_InfixFunc, EP_IntValue, EP_TokenOnly, EP_WinFunc, EP_xIsSelect, Parse::explain, ExprClearVVAProperties, exprCodeBetween(), exprCodeInlineFunction(), exprCodeVector(), ExprHasProperty, ExprHasVVAProperty, exprToRegister(), Expr::flags, FuncDef::funcFlags, Expr::iAgg, Expr::iColumn, AggInfo::AggInfo_func::iMem, Table::iPKey, Parse::iSelfTab, Expr::iTable, Expr::iValue, sqlite3::mallocFailed, MASKBIT32, Table::nCol, AggInfo::nColumn, Parse::nested, NEVER, ExprList::nExpr, AggInfo::nFunc, Parse::nMem, OE_Abort, OE_Fail, OE_Ignore, OE_Rollback, Parse::okConstFactor, Expr::op, Expr::op2, OP_Add, OP_AddImm, OP_Affinity, OP_And, OP_BitAnd, OP_BitNot, OP_BitOr, OP_Blob, OP_Cast, OP_CollSeq, OP_Column, OP_Concat, OP_Divide, OP_Eq, OP_Ge, OP_Gt, OP_Halt, OP_IfNullRow, OP_Integer, OP_IsNull, OP_IsTrue, OP_Le, OP_Lt, OP_Ne, OP_Not, OP_NotNull, OP_Null, OP_Offset, OP_Or, OP_Param, OP_RealAffinity, OP_Remainder, OP_SCopy, OP_ShiftLeft, OP_ShiftRight, OP_Subtract, OP_Variable, OPFLAG_LENGTHARG, OPFLAG_TYPEOFARG, P4_COLLSEQ, P4_DYNAMIC, P4_STATIC, Expr::pAggInfo, sqlite3::pDfltColl, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pSelect, Expr::pTab, Parse::pTriggerTab, FuncDef::pUserData, Parse::pVdbe, Parse::pVList, Expr::pWin, Window::regResult, setDoNotMergeFlagOnCopy(), AggInfo::sortingIdxPTab, sqlite3AffinityType(), sqlite3CodeSubselect(), sqlite3ErrorMsg(), sqlite3ExprCode(), sqlite3ExprCodeExprList(), sqlite3ExprCodeGeneratedColumn(), sqlite3ExprCodeGetColumn(), sqlite3ExprCodeIN(), sqlite3ExprCodeRunJustOnce(), sqlite3ExprCodeTarget(), sqlite3ExprCodeTemp(), sqlite3ExprCollSeq(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprFunctionUsable(), sqlite3ExprIfFalse(), sqlite3ExprIsConstant(), sqlite3ExprIsConstantNotJoin(), sqlite3ExprIsVector(), sqlite3ExprTruthValue(), sqlite3ExprVectorSize(), sqlite3FindFunction(), sqlite3GetTempRange(), sqlite3HaltConstraint(), sqlite3HexToBlob(), sqlite3MayAbort(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3Strlen30(), sqlite3SubselectError(), sqlite3TableColumnAffinity(), sqlite3TableColumnToStorage(), sqlite3VdbeAddFunctionCall(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP3(), sqlite3VdbeDb(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeLoadString(), sqlite3VdbeMakeLabel(), sqlite3VdbeReleaseRegisters, sqlite3VdbeResolveLabel(), sqlite3VListNumToName(), sqlite3VtabOverloadFunction(), SQLITE_AFF_BLOB, SQLITE_AFF_REAL, SQLITE_AFF_TEXT, SQLITE_CONSTRAINT_TRIGGER, SQLITE_ECEL_DUP, SQLITE_ECEL_FACTOR, SQLITE_ERROR, SQLITE_FUNC_DIRECT, SQLITE_FUNC_INLINE, SQLITE_FUNC_LENGTH, SQLITE_FUNC_NEEDCOLL, SQLITE_FUNC_OFFSET, SQLITE_FUNC_TYPEOF, SQLITE_FUNC_UNSAFE, SQLITE_JUMPIFNULL, SQLITE_NULLEQ, SQLITE_OK, SQLITE_PTR_TO_INT, SQLITE_STOREP2, testcase, TK_AGG_COLUMN, TK_AGG_FUNCTION, TK_AND, TK_BETWEEN, TK_BITAND, TK_BITNOT, TK_BITOR, TK_BLOB, TK_CASE, TK_CAST, TK_COLLATE, TK_COLUMN, TK_CONCAT, TK_EQ, TK_EXISTS, TK_FLOAT, TK_FUNCTION, TK_GE, TK_GT, TK_IF_NULL_ROW, TK_IN, TK_INTEGER, TK_IS, TK_ISNOT, TK_ISNULL, TK_LE, TK_LSHIFT, TK_LT, TK_MINUS, TK_NE, TK_NOT, TK_NOTNULL, TK_NULL, TK_OR, TK_PLUS, TK_RAISE, TK_REGISTER, TK_REM, TK_RSHIFT, TK_SELECT, TK_SELECT_COLUMN, TK_SLASH, TK_SPAN, TK_STAR, TK_STRING, TK_TRIGGER, TK_TRUEFALSE, TK_TRUTH, TK_UMINUS, TK_UPLUS, TK_VARIABLE, TK_VECTOR, Expr::u, AggInfo::useSortingIdx, VdbeComment, VdbeCoverage, VdbeCoverageIf, Expr::x, FuncDef::xFinalize, XN_ROWID, Expr::y, Column::zName, Table::zName, and Expr::zToken.

Referenced by codeEqualityTerm(), exprCodeBetween(), isLikeOrGlob(), sqlite3ExprCode(), sqlite3ExprCodeExprList(), sqlite3ExprCodeTarget(), and sqlite3ExprCodeTemp().

◆ sqlite3ExprCodeTemp()

SQLITE_PRIVATE int sqlite3ExprCodeTemp ( Parse * pParse,
Expr * pExpr,
int * pReg )

Definition at line 104314 of file sqlite3.c.

104320 {
104321 int r2;
104322 pExpr = sqlite3ExprSkipCollateAndLikely(pExpr);
104323 if( ConstFactorOk(pParse)
104324 && pExpr->op!=TK_REGISTER
104326 ){
104327 *pReg = 0;
104328 r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
104329 }else{
104330 int r1 = sqlite3GetTempReg(pParse);
104331 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
104332 if( r2==r1 ){
104333 *pReg = r1;
104334 }else{

References ConstFactorOk, Expr::op, sqlite3ExprCodeRunJustOnce(), sqlite3ExprCodeTarget(), sqlite3ExprIsConstantNotJoin(), sqlite3ExprSkipCollateAndLikely(), sqlite3GetTempReg(), sqlite3ReleaseTempReg(), and TK_REGISTER.

Referenced by exprCodeVector(), exprVectorRegister(), sqlite3ExprCodeIN(), sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), and sqlite3ExprIfTrue().

◆ sqlite3ExprCollSeq()

SQLITE_PRIVATE CollSeq * sqlite3ExprCollSeq ( Parse * pParse,
const Expr * pExpr )

Definition at line 99866 of file sqlite3.c.

99872 {
99873 sqlite3 *db = pParse->db;
99874 CollSeq *pColl = 0;
99875 const Expr *p = pExpr;
99876 while( p ){
99877 int op = p->op;
99878 if( op==TK_REGISTER ) op = p->op2;
99879 if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER)
99880 && p->y.pTab!=0
99881 ){
99882 /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
99883 ** a TK_COLUMN but was previously evaluated and cached in a register */
99884 int j = p->iColumn;
99885 if( j>=0 ){
99886 const char *zColl = p->y.pTab->aCol[j].zColl;
99887 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
99888 }
99889 break;
99890 }
99891 if( op==TK_CAST || op==TK_UPLUS ){
99892 p = p->pLeft;
99893 continue;
99894 }
99895 if( op==TK_VECTOR ){
99896 p = p->x.pList->a[0].pExpr;
99897 continue;
99898 }
99899 if( op==TK_COLLATE ){
99900 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
99901 break;
99902 }
99903 if( p->flags & EP_Collate ){
99904 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
99905 p = p->pLeft;
99906 }else{
99907 Expr *pNext = p->pRight;
99908 /* The Expr.x union is never used at the same time as Expr.pRight */
99909 assert( p->x.pList==0 || p->pRight==0 );
99910 if( p->x.pList!=0
99911 && !db->mallocFailed
99913 ){
99914 int i;
99915 for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
99916 if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
99917 pNext = p->x.pList->a[i].pExpr;
99918 break;
99919 }
99920 }
99921 }
99922 p = pNext;
99923 }
99924 }else{
99925 break;
99926 }

References ExprList::a, Table::aCol, ALWAYS, Parse::db, ENC, EP_Collate, EP_xIsSelect, ExprHasProperty, Expr::flags, Expr::iColumn, sqlite3::mallocFailed, Expr::op, Expr::op2, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pTab, sqlite3CheckCollSeq(), sqlite3FindCollSeq(), sqlite3GetCollSeq(), TK_AGG_COLUMN, TK_CAST, TK_COLLATE, TK_COLUMN, TK_REGISTER, TK_TRIGGER, TK_UPLUS, TK_VECTOR, Expr::u, Expr::x, Expr::y, Column::zColl, and Expr::zToken.

Referenced by multiSelectCollSeq(), multiSelectOrderByKeyInfo(), selectInnerLoop(), sqlite3BinaryCompareCollSeq(), sqlite3CodeRhsOfIN(), sqlite3ExprCodeIN(), sqlite3ExprCodeTarget(), sqlite3ExprNNCollSeq(), sqlite3SelectAddColumnTypeAndCollation(), substExpr(), and updateAccumulator().

◆ sqlite3ExprCollSeqMatch()

SQLITE_PRIVATE int sqlite3ExprCollSeqMatch ( Parse * pParse,
const Expr * pE1,
const Expr * pE2 )

Definition at line 99948 of file sqlite3.c.

Referenced by termIsEquivalence().

◆ sqlite3ExprColUsed()

SQLITE_PRIVATE Bitmask sqlite3ExprColUsed ( Expr * pExpr)

Definition at line 97938 of file sqlite3.c.

97944 {
97945 int n;
97946 Table *pExTab;
97947
97948 n = pExpr->iColumn;
97949 pExTab = pExpr->y.pTab;
97950 assert( pExTab!=0 );
97951 if( (pExTab->tabFlags & TF_HasGenerated)!=0
97952 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
97953 ){
97954 testcase( pExTab->nCol==BMS-1 );
97955 testcase( pExTab->nCol==BMS );
97956 return pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1;
97957 }else{

Referenced by lookupName().

◆ sqlite3ExprCompare()

SQLITE_PRIVATE int sqlite3ExprCompare ( Parse * pParse,
Expr * pA,
Expr * pB,
int iTab )

Definition at line 104941 of file sqlite3.c.

104947 {
104948 u32 combinedFlags;
104949 if( pA==0 || pB==0 ){
104950 return pB==pA ? 0 : 2;
104951 }
104952 if( pParse && pA->op==TK_VARIABLE && exprCompareVariable(pParse, pA, pB) ){
104953 return 0;
104954 }
104955 combinedFlags = pA->flags | pB->flags;
104956 if( combinedFlags & EP_IntValue ){
104957 if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
104958 return 0;
104959 }
104960 return 2;
104961 }
104962 if( pA->op!=pB->op || pA->op==TK_RAISE ){
104963 if( pA->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA->pLeft,pB,iTab)<2 ){
104964 return 1;
104965 }
104966 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
104967 return 1;
104968 }
104969 return 2;
104970 }
104971 if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
104972 if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
104973 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
104974#ifndef SQLITE_OMIT_WINDOWFUNC
104975 assert( pA->op==pB->op );
104977 return 2;
104978 }
104979 if( ExprHasProperty(pA,EP_WinFunc) ){
104980 if( sqlite3WindowCompare(pParse, pA->y.pWin, pB->y.pWin, 1)!=0 ){
104981 return 2;
104982 }
104983 }
104984#endif
104985 }else if( pA->op==TK_NULL ){
104986 return 0;
104987 }else if( pA->op==TK_COLLATE ){
104988 if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
104989 }else if( ALWAYS(pB->u.zToken!=0) && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
104990 return 2;
104991 }
104992 }
104993 if( (pA->flags & (EP_Distinct|EP_Commuted))
104994 != (pB->flags & (EP_Distinct|EP_Commuted)) ) return 2;
104995 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
104996 if( combinedFlags & EP_xIsSelect ) return 2;
104997 if( (combinedFlags & EP_FixedCol)==0
104998 && sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2;
104999 if( sqlite3ExprCompare(pParse, pA->pRight, pB->pRight, iTab) ) return 2;
105000 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
105001 if( pA->op!=TK_STRING
105002 && pA->op!=TK_TRUEFALSE
105003 && ALWAYS((combinedFlags & EP_Reduced)==0)
105004 ){
105005 if( pA->iColumn!=pB->iColumn ) return 2;
105006 if( pA->op2!=pB->op2 && pA->op==TK_TRUTH ) return 2;
105007 if( pA->op!=TK_IN && pA->iTable!=pB->iTable && pA->iTable!=iTab ){
static int exprCompareVariable(Parse *pParse, Expr *pVar, Expr *pExpr)
Definition sqlite3.c:104889
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList *, ExprList *, int)
Definition sqlite3.c:105025
SQLITE_PRIVATE int sqlite3WindowCompare(Parse *, Window *, Window *, int)
Definition sqlite3.c:152483

References ALWAYS, EP_Commuted, EP_Distinct, EP_FixedCol, EP_IntValue, EP_Reduced, EP_TokenOnly, EP_WinFunc, EP_xIsSelect, exprCompareVariable(), ExprHasProperty, Expr::flags, Expr::iColumn, Expr::iTable, Expr::iValue, Expr::op, Expr::op2, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pWin, sqlite3_stricmp(), sqlite3ExprCompare(), sqlite3ExprListCompare(), sqlite3StrICmp(), sqlite3WindowCompare(), TK_AGG_COLUMN, TK_AGG_FUNCTION, TK_COLLATE, TK_COLUMN, TK_FUNCTION, TK_IN, TK_NULL, TK_RAISE, TK_STRING, TK_TRUEFALSE, TK_TRUTH, TK_VARIABLE, Expr::u, Expr::x, Expr::y, and Expr::zToken.

Referenced by analyzeAggregate(), exprAnalyzeOrTerm(), exprImpliesNotNull(), isSelfJoinView(), resolveOrderByTermToExprList(), resolveOrderGroupBy(), selectWindowRewriteExprCb(), sqlite3ExprCodeRunJustOnce(), sqlite3ExprCompare(), sqlite3ExprImpliesExpr(), sqlite3ExprListCompare(), sqlite3UpsertAnalyzeTarget(), sqlite3WindowCompare(), whereApplyPartialIndexConstraints(), whereCombineDisjuncts(), whereIndexExprTransNode(), xferCompatibleIndex(), and xferOptimization().

◆ sqlite3ExprCompareCollSeq()

◆ sqlite3ExprCompareSkip()

SQLITE_PRIVATE int sqlite3ExprCompareSkip ( Expr * pA,
Expr * pB,
int iTab )

◆ sqlite3ExprCoveredByIndex()

SQLITE_PRIVATE int sqlite3ExprCoveredByIndex ( Expr * pExpr,
int iCur,
Index * pIdx )

Definition at line 105344 of file sqlite3.c.

105354 {
105355 Walker w;
105356 struct IdxCover xcov;
105357 memset(&w, 0, sizeof(w));
105358 xcov.iCur = iCur;

References Walker::eCode, exprIdxCover(), IdxCover::iCur, IdxCover::pIdx, Walker::pIdxCover, sqlite3WalkExpr(), Walker::u, and Walker::xExprCallback.

Referenced by whereLoopAddBtree().

◆ sqlite3ExprDelete()

◆ sqlite3ExprDeleteNN()

static SQLITE_NOINLINE void sqlite3ExprDeleteNN ( sqlite3 * db,
Expr * p )
static

Definition at line 100810 of file sqlite3.c.

100816 {
100817 assert( p!=0 );
100818 /* Sanity check: Assert that the IntValue is non-negative if it exists */
100819 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
100820
100821 assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed );
100823 || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) );
100824#ifdef SQLITE_DEBUG
100826 assert( p->pLeft==0 );
100827 assert( p->pRight==0 );
100828 assert( p->x.pSelect==0 );
100829 }
100830#endif
100831 if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
100832 /* The Expr.x union is never used at the same time as Expr.pRight */
100833 assert( p->x.pList==0 || p->pRight==0 );
100834 if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
100835 if( p->pRight ){
100836 assert( !ExprHasProperty(p, EP_WinFunc) );
100837 sqlite3ExprDeleteNN(db, p->pRight);
100838 }else if( ExprHasProperty(p, EP_xIsSelect) ){
100839 assert( !ExprHasProperty(p, EP_WinFunc) );
100840 sqlite3SelectDelete(db, p->x.pSelect);
100841 }else{
100842 sqlite3ExprListDelete(db, p->x.pList);
100843#ifndef SQLITE_OMIT_WINDOWFUNC
100844 if( ExprHasProperty(p, EP_WinFunc) ){
100845 sqlite3WindowDelete(db, p->y.pWin);
100846 }
100847#endif
100848 }
static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p)
Definition sqlite3.c:100810
SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3 *, Window *)
Definition sqlite3.c:152265

◆ sqlite3ExprDup()

◆ sqlite3ExprForVectorField()

SQLITE_PRIVATE Expr * sqlite3ExprForVectorField ( Parse * pParse,
Expr * pVector,
int iField )

Definition at line 100187 of file sqlite3.c.

100197 {
100198 Expr *pRet;
100199 if( pVector->op==TK_SELECT ){
100200 assert( pVector->flags & EP_xIsSelect );
100201 /* The TK_SELECT_COLUMN Expr node:
100202 **
100203 ** pLeft: pVector containing TK_SELECT. Not deleted.
100204 ** pRight: not used. But recursively deleted.
100205 ** iColumn: Index of a column in pVector
100206 ** iTable: 0 or the number of columns on the LHS of an assignment
100207 ** pLeft->iTable: First in an array of register holding result, or 0
100208 ** if the result is not yet computed.
100209 **
100210 ** sqlite3ExprDelete() specifically skips the recursive delete of
100211 ** pLeft on TK_SELECT_COLUMN nodes. But pRight is followed, so pVector
100212 ** can be attached to pRight to cause this node to take ownership of
100213 ** pVector. Typically there will be multiple TK_SELECT_COLUMN nodes
100214 ** with the same pLeft pointer to the pVector, but only one of them
100215 ** will own the pVector.
100216 */
100217 pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
100218 if( pRet ){
100219 pRet->iColumn = iField;
100220 pRet->pLeft = pVector;
100221 }
100222 assert( pRet==0 || pRet->iTable==0 );
100223 }else{

References ExprList::a, Parse::db, EP_xIsSelect, Expr::flags, Expr::iColumn, Expr::iTable, Expr::op, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, sqlite3ExprDup(), sqlite3PExpr(), sqlite3RenameTokenRemap(), TK_SELECT, TK_SELECT_COLUMN, TK_VECTOR, and Expr::x.

Referenced by exprAnalyze(), and sqlite3ExprListAppendVector().

◆ sqlite3ExprFunction()

SQLITE_PRIVATE Expr * sqlite3ExprFunction ( Parse * pParse,
ExprList * pList,
Token * pToken,
int eDistinct )

Definition at line 100667 of file sqlite3.c.

100678 {
100679 Expr *pNew;
100680 sqlite3 *db = pParse->db;
100681 assert( pToken );
100682 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
100683 if( pNew==0 ){
100684 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
100685 return 0;
100686 }
100687 if( pList && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
100688 sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
100689 }
100690 pNew->x.pList = pList;

Referenced by yy_reduce().

◆ sqlite3ExprFunctionUsable()

SQLITE_PRIVATE void sqlite3ExprFunctionUsable ( Parse * pParse,
Expr * pExpr,
FuncDef * pDef )

Definition at line 100703 of file sqlite3.c.

100713 {
100714 assert( !IN_RENAME_OBJECT );
100715 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
100716 if( ExprHasProperty(pExpr, EP_FromDDL) ){
100717 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
100718 || (pParse->db->flags & SQLITE_TrustedSchema)==0
100719 ){
100720 /* Functions prohibited in triggers and views if:
100721 ** (1) tagged with SQLITE_DIRECTONLY
100722 ** (2) not tagged with SQLITE_INNOCUOUS (which means it
100723 ** is tagged with SQLITE_FUNC_UNSAFE) and
100724 ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning

References Parse::db, EP_FromDDL, ExprHasProperty, sqlite3::flags, FuncDef::funcFlags, IN_RENAME_OBJECT, sqlite3ErrorMsg(), SQLITE_FUNC_DIRECT, SQLITE_FUNC_UNSAFE, SQLITE_TrustedSchema, and FuncDef::zName.

Referenced by resolveExprStep(), and sqlite3ExprCodeTarget().

◆ sqlite3ExprIdToTrueFalse()

SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse ( Expr * pExpr)

Definition at line 101631 of file sqlite3.c.

101637 {
101638 u32 v;
101639 assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
101640 if( !ExprHasProperty(pExpr, EP_Quoted)
101641 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
101642 ){
#define EP_Quoted
Definition sqlite3.c:18086

References EP_Quoted, ExprHasProperty, ExprSetProperty, Expr::op, sqlite3IsTrueOrFalse(), TK_ID, TK_STRING, TK_TRUEFALSE, Expr::u, and Expr::zToken.

Referenced by exprNodeIsConstant(), lookupName(), and yy_reduce().

◆ sqlite3ExprIfFalse()

SQLITE_PRIVATE void sqlite3ExprIfFalse ( Parse * pParse,
Expr * pExpr,
int dest,
int jumpIfNull )

Definition at line 104695 of file sqlite3.c.

104701 {
104702 Vdbe *v = pParse->pVdbe;
104703 int op = 0;
104704 int regFree1 = 0;
104705 int regFree2 = 0;
104706 int r1, r2;
104707
104708 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
104709 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
104710 if( pExpr==0 ) return;
104711 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
104712
104713 /* The value of pExpr->op and op are related as follows:
104714 **
104715 ** pExpr->op op
104716 ** --------- ----------
104717 ** TK_ISNULL OP_NotNull
104718 ** TK_NOTNULL OP_IsNull
104719 ** TK_NE OP_Eq
104720 ** TK_EQ OP_Ne
104721 ** TK_GT OP_Le
104722 ** TK_LE OP_Gt
104723 ** TK_GE OP_Lt
104724 ** TK_LT OP_Ge
104725 **
104726 ** For other values of pExpr->op, op is undefined and unused.
104727 ** The value of TK_ and OP_ constants are arranged such that we
104728 ** can compute the mapping above using the following expression.
104729 ** Assert()s verify that the computation is correct.
104730 */
104731 op = ((pExpr->op+(TK_ISNULL&1))^1)-(TK_ISNULL&1);
104732
104733 /* Verify correct alignment of TK_ and OP_ constants
104734 */
104735 assert( pExpr->op!=TK_ISNULL || op==OP_NotNull );
104736 assert( pExpr->op!=TK_NOTNULL || op==OP_IsNull );
104737 assert( pExpr->op!=TK_NE || op==OP_Eq );
104738 assert( pExpr->op!=TK_EQ || op==OP_Ne );
104739 assert( pExpr->op!=TK_LT || op==OP_Ge );
104740 assert( pExpr->op!=TK_LE || op==OP_Gt );
104741 assert( pExpr->op!=TK_GT || op==OP_Le );
104742 assert( pExpr->op!=TK_GE || op==OP_Lt );
104743
104744 switch( pExpr->op ){
104745 case TK_AND:
104746 case TK_OR: {
104747 Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
104748 if( pAlt!=pExpr ){
104749 sqlite3ExprIfFalse(pParse, pAlt, dest, jumpIfNull);
104750 }else if( pExpr->op==TK_AND ){
104751 testcase( jumpIfNull==0 );
104752 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
104753 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
104754 }else{
104755 int d2 = sqlite3VdbeMakeLabel(pParse);
104756 testcase( jumpIfNull==0 );
104757 sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2,
104758 jumpIfNull^SQLITE_JUMPIFNULL);
104759 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
104761 }
104762 break;
104763 }
104764 case TK_NOT: {
104765 testcase( jumpIfNull==0 );
104766 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
104767 break;
104768 }
104769 case TK_TRUTH: {
104770 int isNot; /* IS NOT TRUE or IS NOT FALSE */
104771 int isTrue; /* IS TRUE or IS NOT TRUE */
104772 testcase( jumpIfNull==0 );
104773 isNot = pExpr->op2==TK_ISNOT;
104774 isTrue = sqlite3ExprTruthValue(pExpr->pRight);
104775 testcase( isTrue && isNot );
104776 testcase( !isTrue && isNot );
104777 if( isTrue ^ isNot ){
104778 /* IS TRUE and IS NOT FALSE */
104779 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest,
104780 isNot ? 0 : SQLITE_JUMPIFNULL);
104781
104782 }else{
104783 /* IS FALSE and IS NOT TRUE */
104784 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest,
104785 isNot ? 0 : SQLITE_JUMPIFNULL);
104786 }
104787 break;
104788 }
104789 case TK_IS:
104790 case TK_ISNOT:
104791 testcase( pExpr->op==TK_IS );
104792 testcase( pExpr->op==TK_ISNOT );
104793 op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
104794 jumpIfNull = SQLITE_NULLEQ;
104795 /* no break */ deliberate_fall_through
104796 case TK_LT:
104797 case TK_LE:
104798 case TK_GT:
104799 case TK_GE:
104800 case TK_NE:
104801 case TK_EQ: {
104802 if( sqlite3ExprIsVector(pExpr->pLeft) ) goto default_expr;
104803 testcase( jumpIfNull==0 );
104804 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
104805 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
104806 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
104807 r1, r2, dest, jumpIfNull,ExprHasProperty(pExpr,EP_Commuted));
104808 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
104809 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
104810 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
104811 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
104812 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq);
104813 VdbeCoverageIf(v, op==OP_Eq && jumpIfNull!=SQLITE_NULLEQ);
104814 VdbeCoverageIf(v, op==OP_Eq && jumpIfNull==SQLITE_NULLEQ);
104815 assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
104816 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
104817 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
104818 testcase( regFree1==0 );
104819 testcase( regFree2==0 );
104820 break;
104821 }
104822 case TK_ISNULL:
104823 case TK_NOTNULL: {
104824 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
104825 sqlite3VdbeAddOp2(v, op, r1, dest);
104826 testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
104828 testcase( regFree1==0 );
104829 break;
104830 }
104831 case TK_BETWEEN: {
104832 testcase( jumpIfNull==0 );
104833 exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfFalse, jumpIfNull);
104834 break;
104835 }
104836#ifndef SQLITE_OMIT_SUBQUERY
104837 case TK_IN: {
104838 if( jumpIfNull ){
104839 sqlite3ExprCodeIN(pParse, pExpr, dest, dest);
104840 }else{
104841 int destIfNull = sqlite3VdbeMakeLabel(pParse);
104842 sqlite3ExprCodeIN(pParse, pExpr, dest, destIfNull);
104843 sqlite3VdbeResolveLabel(v, destIfNull);
104844 }
104845 break;
104846 }
104847#endif
104848 default: {
104849 default_expr:
104850 if( ExprAlwaysFalse(pExpr) ){
104851 sqlite3VdbeGoto(v, dest);
104852 }else if( ExprAlwaysTrue(pExpr) ){
104853 /* no-op */
104854 }else{
104855 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
104856 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
104857 VdbeCoverage(v);
104858 testcase( regFree1==0 );
104859 testcase( jumpIfNull==0 );
104860 }
SQLITE_PRIVATE Expr * sqlite3ExprSimplifiedAndOr(Expr *)
Definition sqlite3.c:101669
#define ExprAlwaysTrue(E)
Definition sqlite3.c:18107

References codeCompare(), deliberate_fall_through, EP_Commuted, EP_Immutable, ExprAlwaysFalse, ExprAlwaysTrue, exprCodeBetween(), ExprHasProperty, ExprHasVVAProperty, NEVER, Expr::op, Expr::op2, OP_Eq, OP_Ge, OP_Gt, OP_IfNot, OP_IsNull, OP_Le, OP_Lt, OP_Ne, OP_NotNull, Expr::pLeft, Expr::pRight, Parse::pVdbe, sqlite3ExprCodeIN(), sqlite3ExprCodeTemp(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3ExprIsVector(), sqlite3ExprSimplifiedAndOr(), sqlite3ExprTruthValue(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeGoto(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_JUMPIFNULL, SQLITE_NULLEQ, testcase, TK_AND, TK_BETWEEN, TK_EQ, TK_GE, TK_GT, TK_IN, TK_IS, TK_ISNOT, TK_ISNULL, TK_LE, TK_LT, TK_NE, TK_NOT, TK_NOTNULL, TK_OR, TK_TRUTH, VdbeCoverage, and VdbeCoverageIf.

Referenced by constructAutomaticIndex(), exprCodeBetween(), sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), sqlite3ExprIfFalseDup(), sqlite3ExprIfTrue(), sqlite3Pragma(), sqlite3Select(), sqlite3Update(), sqlite3WhereBegin(), and updateAccumulator().

◆ sqlite3ExprIfFalseDup()

SQLITE_PRIVATE void sqlite3ExprIfFalseDup ( Parse * pParse,
Expr * pExpr,
int dest,
int jumpIfNull )

◆ sqlite3ExprIfTrue()

SQLITE_PRIVATE void sqlite3ExprIfTrue ( Parse * pParse,
Expr * pExpr,
int dest,
int jumpIfNull )

Definition at line 104553 of file sqlite3.c.

104553 : TK_EQ)
104554** are the same as opcode values (ex: OP_Eq) that implement the corresponding
104555** operation. Special comments in vdbe.c and the mkopcodeh.awk script in
104556** the make process cause these values to align. Assert()s in the code
104557** below verify that the numbers are aligned correctly.
104558*/
104559SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
104560 Vdbe *v = pParse->pVdbe;
104561 int op = 0;
104562 int regFree1 = 0;
104563 int regFree2 = 0;
104564 int r1, r2;
104565
104566 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
104567 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
104568 if( NEVER(pExpr==0) ) return; /* No way this can happen */
104569 assert( !ExprHasVVAProperty(pExpr, EP_Immutable) );
104570 op = pExpr->op;
104571 switch( op ){
104572 case TK_AND:
104573 case TK_OR: {
104574 Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
104575 if( pAlt!=pExpr ){
104576 sqlite3ExprIfTrue(pParse, pAlt, dest, jumpIfNull);
104577 }else if( op==TK_AND ){
104578 int d2 = sqlite3VdbeMakeLabel(pParse);
104579 testcase( jumpIfNull==0 );
104580 sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,
104581 jumpIfNull^SQLITE_JUMPIFNULL);
104582 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
104584 }else{
104585 testcase( jumpIfNull==0 );
104586 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
104587 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
104588 }
104589 break;
104590 }
104591 case TK_NOT: {
104592 testcase( jumpIfNull==0 );
104593 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
104594 break;
104595 }
104596 case TK_TRUTH: {
104597 int isNot; /* IS NOT TRUE or IS NOT FALSE */
104598 int isTrue; /* IS TRUE or IS NOT TRUE */
104599 testcase( jumpIfNull==0 );
104600 isNot = pExpr->op2==TK_ISNOT;
104601 isTrue = sqlite3ExprTruthValue(pExpr->pRight);
104602 testcase( isTrue && isNot );
104603 testcase( !isTrue && isNot );
104604 if( isTrue ^ isNot ){
104605 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest,
104606 isNot ? SQLITE_JUMPIFNULL : 0);
104607 }else{
104608 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest,
104609 isNot ? SQLITE_JUMPIFNULL : 0);
104610 }
104611 break;
104612 }
104613 case TK_IS:
104614 case TK_ISNOT:
104615 testcase( op==TK_IS );
104616 testcase( op==TK_ISNOT );
104617 op = (op==TK_IS) ? TK_EQ : TK_NE;
104618 jumpIfNull = SQLITE_NULLEQ;
104619 /* no break */ deliberate_fall_through
104620 case TK_LT:
104621 case TK_LE:
104622 case TK_GT:
104623 case TK_GE:
104624 case TK_NE:
104625 case TK_EQ: {
104626 if( sqlite3ExprIsVector(pExpr->pLeft) ) goto default_expr;
104627 testcase( jumpIfNull==0 );
104628 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
104629 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
104630 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
104631 r1, r2, dest, jumpIfNull, ExprHasProperty(pExpr,EP_Commuted));
104632 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
104633 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
104634 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
104635 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
104636 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq);
104637 VdbeCoverageIf(v, op==OP_Eq && jumpIfNull==SQLITE_NULLEQ);
104638 VdbeCoverageIf(v, op==OP_Eq && jumpIfNull!=SQLITE_NULLEQ);
104639 assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
104640 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
104641 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
104642 testcase( regFree1==0 );
104643 testcase( regFree2==0 );
104644 break;
104645 }
104646 case TK_ISNULL:
104647 case TK_NOTNULL: {
104648 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
104649 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
104650 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
104651 sqlite3VdbeAddOp2(v, op, r1, dest);
104652 VdbeCoverageIf(v, op==TK_ISNULL);
104653 VdbeCoverageIf(v, op==TK_NOTNULL);
104654 testcase( regFree1==0 );
104655 break;
104656 }
104657 case TK_BETWEEN: {
104658 testcase( jumpIfNull==0 );
104659 exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
104660 break;
104661 }
104662#ifndef SQLITE_OMIT_SUBQUERY
104663 case TK_IN: {
104664 int destIfFalse = sqlite3VdbeMakeLabel(pParse);
104665 int destIfNull = jumpIfNull ? dest : destIfFalse;
104666 sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
104667 sqlite3VdbeGoto(v, dest);
104668 sqlite3VdbeResolveLabel(v, destIfFalse);
104669 break;
104670 }
104671#endif
104672 default: {
104673 default_expr:
104674 if( ExprAlwaysTrue(pExpr) ){
104675 sqlite3VdbeGoto(v, dest);
104676 }else if( ExprAlwaysFalse(pExpr) ){
104677 /* No-op */
104678 }else{
104679 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
104680 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
104681 VdbeCoverage(v);
104682 testcase( regFree1==0 );
104683 testcase( jumpIfNull==0 );
104684 }

References codeCompare(), deliberate_fall_through, EP_Commuted, EP_Immutable, ExprAlwaysFalse, ExprAlwaysTrue, exprCodeBetween(), ExprHasProperty, ExprHasVVAProperty, NEVER, Expr::op, Expr::op2, OP_Eq, OP_Ge, OP_Gt, OP_If, OP_IsNull, OP_Le, OP_Lt, OP_Ne, OP_NotNull, Expr::pLeft, Expr::pRight, Parse::pVdbe, sqlite3ExprCodeIN(), sqlite3ExprCodeTemp(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3ExprIsVector(), sqlite3ExprSimplifiedAndOr(), sqlite3ExprTruthValue(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeGoto(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_JUMPIFNULL, SQLITE_NULLEQ, testcase, TK_AND, TK_BETWEEN, TK_EQ, TK_GE, TK_GT, TK_IN, TK_IS, TK_ISNOT, TK_ISNULL, TK_LE, TK_LT, TK_NE, TK_NOT, TK_NOTNULL, TK_OR, TK_TRUTH, VdbeCoverage, and VdbeCoverageIf.

Referenced by exprCodeBetween(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3GenerateConstraintChecks(), and sqlite3Pragma().

◆ sqlite3ExprImpliesExpr()

SQLITE_PRIVATE int sqlite3ExprImpliesExpr ( Parse * pParse,
Expr * pE1,
Expr * pE2,
int iTab )

Definition at line 105153 of file sqlite3.c.

105159 {
105160 if( sqlite3ExprCompare(pParse, pE1, pE2, iTab)==0 ){
105161 return 1;
105162 }
105163 if( pE2->op==TK_OR
105164 && (sqlite3ExprImpliesExpr(pParse, pE1, pE2->pLeft, iTab)
105165 || sqlite3ExprImpliesExpr(pParse, pE1, pE2->pRight, iTab) )
105166 ){
105167 return 1;
105168 }
105169 if( pE2->op==TK_NOTNULL

References exprImpliesNotNull(), Expr::op, Expr::pLeft, Expr::pRight, sqlite3ExprCompare(), sqlite3ExprImpliesExpr(), TK_NOTNULL, and TK_OR.

Referenced by sqlite3ExprImpliesExpr().

◆ sqlite3ExprImpliesNonNullRow()

SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow ( Expr * p,
int iTab )

Definition at line 105285 of file sqlite3.c.

105291 {
105292 Walker w;
105294 if( p==0 ) return 0;
105295 if( p->op==TK_NOTNULL ){
105296 p = p->pLeft;
105297 }else{
105298 while( p->op==TK_AND ){
105299 if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
105300 p = p->pRight;
105301 }
105302 }
105304 w.xSelectCallback = 0;
static int impliesNotNullRow(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:105180

References Walker::eCode, Walker::iCur, impliesNotNullRow(), Expr::op, Expr::pLeft, Expr::pRight, sqlite3ExprImpliesNonNullRow(), sqlite3ExprSkipCollateAndLikely(), sqlite3WalkExpr(), TK_AND, TK_NOTNULL, Walker::u, Walker::xExprCallback, Walker::xSelectCallback, and Walker::xSelectCallback2.

Referenced by sqlite3ExprImpliesNonNullRow(), and sqlite3Select().

◆ sqlite3ExprIsConstant()

◆ sqlite3ExprIsConstantNotJoin()

SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin ( Expr * p)

◆ sqlite3ExprIsConstantOrFunction()

SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction ( Expr * p,
u8 isInit )

Definition at line 101914 of file sqlite3.c.

101916 : "abc")
101917** is considered a variable but a single-quoted string (ex: 'abc') is

References exprIsConst().

Referenced by sqlite3AddDefaultValue().

◆ sqlite3ExprIsConstantOrGroupBy()

SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy ( Parse * pParse,
Expr * p,
ExprList * pGroupBy )

Definition at line 101882 of file sqlite3.c.

101888 {
101889 Walker w;
101890 w.eCode = 1;
static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:101838

References Walker::eCode, exprNodeIsConstantOrGroupBy(), Walker::pGroupBy, Walker::pParse, sqlite3WalkExpr(), Walker::u, Walker::xExprCallback, and Walker::xSelectCallback.

Referenced by havingToWhereExprCb().

◆ sqlite3ExprIsInteger()

SQLITE_PRIVATE int sqlite3ExprIsInteger ( Expr * p,
int * pValue )

Definition at line 101943 of file sqlite3.c.

101949 {
101950 int rc = 0;
101951 if( NEVER(p==0) ) return 0; /* Used to only happen following on OOM */
101952
101953 /* If an expression is an integer literal that fits in a signed 32-bit
101954 ** integer, then the EP_IntValue flag will have already been set */
101955 assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
101956 || sqlite3GetInt32(p->u.zToken, &rc)==0 );
101957
101958 if( p->flags & EP_IntValue ){
101959 *pValue = p->u.iValue;
101960 return 1;
101961 }
101962 switch( p->op ){
101963 case TK_UPLUS: {
101964 rc = sqlite3ExprIsInteger(p->pLeft, pValue);
101965 break;
101966 }
101967 case TK_UMINUS: {
101968 int v;
101969 if( sqlite3ExprIsInteger(p->pLeft, &v) ){
101970 assert( v!=(-2147483647-1) );
101971 *pValue = -v;
101972 rc = 1;
101973 }

References EP_IntValue, Expr::flags, Expr::iValue, NEVER, Expr::op, Expr::pLeft, sqlite3ExprIsInteger(), sqlite3GetInt32(), TK_INTEGER, TK_UMINUS, TK_UPLUS, Expr::u, and Expr::zToken.

Referenced by computeLimitRegisters(), multiSelect(), resolveCompoundOrderBy(), resolveOrderByTermToExprList(), resolveOrderGroupBy(), sqlite3ExprIsInteger(), and whereLoopOutputAdjust().

◆ sqlite3ExprIsTableConstant()

SQLITE_PRIVATE int sqlite3ExprIsTableConstant ( Expr * p,
int iCur )

Definition at line 101830 of file sqlite3.c.

References exprIsConst().

Referenced by constructAutomaticIndex(), and pushDownWhereTerms().

◆ sqlite3ExprIsVector()

◆ sqlite3ExprListAppend()

SQLITE_PRIVATE ExprList * sqlite3ExprListAppend ( Parse * pParse,
ExprList * pList,
Expr * pExpr )

Definition at line 101344 of file sqlite3.c.

101354 {
101355 struct ExprList_item *pItem;
101356 sqlite3 *db = pParse->db;
101357 assert( db!=0 );
101358 if( pList==0 ){
101359 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
101360 if( pList==0 ){
101361 goto no_mem;
101362 }
101363 pList->nExpr = 0;
101364 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
101365 ExprList *pNew;
101366 pNew = sqlite3DbRealloc(db, pList,
101367 sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
101368 if( pNew==0 ){
101369 goto no_mem;
101370 }
101371 pList = pNew;
101372 }
101373 pItem = &pList->a[pList->nExpr++];
101374 assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) );
101375 assert( offsetof(struct ExprList_item,pExpr)==0 );
101376 memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName));
101377 pItem->pExpr = pExpr;
101378 return pList;
101379

References ExprList::a, Parse::db, ExprList::nExpr, offsetof, sqlite3DbMallocRawNN(), sqlite3DbRealloc(), sqlite3ExprDelete(), and sqlite3ExprListDelete().

Referenced by agginfoPersistExprCb(), convertCompoundSelectToSubquery(), convertToWithoutRowidTable(), exprAnalyzeOrTerm(), fkActionTrigger(), multiSelectOrderBy(), parserAddExprIdListTerm(), removeUnindexableInClauseTerms(), selectExpander(), selectWindowRewriteExprCb(), sqlite3CreateIndex(), sqlite3ExprCodeRunJustOnce(), sqlite3ExprListAppendVector(), sqlite3SelectNew(), sqlite3WindowRewrite(), updateFromSelect(), updateVirtualTable(), and yy_reduce().

◆ sqlite3ExprListAppendVector()

SQLITE_PRIVATE ExprList * sqlite3ExprListAppendVector ( Parse * pParse,
ExprList * pList,
IdList * pColumns,
Expr * pExpr )

Definition at line 101392 of file sqlite3.c.

101392 : (a,b,c) = (SELECT x,y,z FROM ....)
101393**
101394** For each term of the vector assignment, append new entries to the
101395** expression list pList. In the case of a subquery on the RHS, append
101396** TK_SELECT_COLUMN expressions.
101397*/
101399 Parse *pParse, /* Parsing context */
101400 ExprList *pList, /* List to which to append. Might be NULL */
101401 IdList *pColumns, /* List of names of LHS of the assignment */
101402 Expr *pExpr /* Vector expression to be appended. Might be NULL */
101403){
101404 sqlite3 *db = pParse->db;
101405 int n;
101406 int i;
101407 int iFirst = pList ? pList->nExpr : 0;
101408 /* pColumns can only be NULL due to an OOM but an OOM will cause an
101409 ** exit prior to this routine being invoked */
101410 if( NEVER(pColumns==0) ) goto vector_append_error;
101411 if( pExpr==0 ) goto vector_append_error;
101412
101413 /* If the RHS is a vector, then we can immediately check to see that
101414 ** the size of the RHS and LHS match. But if the RHS is a SELECT,
101415 ** wildcards ("*") in the result set of the SELECT must be expanded before
101416 ** we can do the size check, so defer the size check until code generation.
101417 */
101418 if( pExpr->op!=TK_SELECT && pColumns->nId!=(n=sqlite3ExprVectorSize(pExpr)) ){
101419 sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
101420 pColumns->nId, n);
101421 goto vector_append_error;
101422 }
101423
101424 for(i=0; i<pColumns->nId; i++){
101425 Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i);
101426 assert( pSubExpr!=0 || db->mallocFailed );
101427 assert( pSubExpr==0 || pSubExpr->iTable==0 );
101428 if( pSubExpr==0 ) continue;
101429 pSubExpr->iTable = pColumns->nId;
101430 pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
101431 if( pList ){
101432 assert( pList->nExpr==iFirst+i+1 );
101433 pList->a[pList->nExpr-1].zEName = pColumns->a[i].zName;
101434 pColumns->a[i].zName = 0;
101435 }
101436 }
101437
101438 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
101439 Expr *pFirst = pList->a[iFirst].pExpr;
101440 assert( pFirst!=0 );
101441 assert( pFirst->op==TK_SELECT_COLUMN );
101442
101443 /* Store the SELECT statement in pRight so it will be deleted when
101444 ** sqlite3ExprListDelete() is called */
101445 pFirst->pRight = pExpr;
101446 pExpr = 0;
101447
101448 /* Remember the size of the LHS in iTable so that we can check that
101449 ** the RHS and LHS sizes match during code generation. */
101450 pFirst->iTable = pColumns->nId;
101451 }
CURL_EXTERN int void curl_formget_callback append
Definition curl.h:2623
static void assignment(LexState *ls, struct LHS_assign *lh, int nvars)
SQLITE_PRIVATE ExprList * sqlite3ExprListAppendVector(Parse *, ExprList *, IdList *, Expr *)
Definition sqlite3.c:101392

References ExprList::a, IdList::a, ALWAYS, Parse::db, Expr::iTable, sqlite3::mallocFailed, NEVER, ExprList::nExpr, IdList::nId, Expr::op, ExprList::ExprList_item::pExpr, Expr::pRight, sqlite3ErrorMsg(), sqlite3ExprForVectorField(), sqlite3ExprListAppend(), sqlite3ExprUnmapAndDelete(), sqlite3ExprVectorSize(), sqlite3IdListDelete(), TK_SELECT, TK_SELECT_COLUMN, ExprList::ExprList_item::zEName, and IdList::IdList_item::zName.

Referenced by yy_reduce().

◆ sqlite3ExprListCheckLength()

SQLITE_PRIVATE void sqlite3ExprListCheckLength ( Parse * pParse,
ExprList * pEList,
const char * zObject )

Definition at line 101551 of file sqlite3.c.

101561 {
101562 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];

Referenced by sqlite3CreateIndex(), and yy_reduce().

◆ sqlite3ExprListCompare()

SQLITE_PRIVATE int sqlite3ExprListCompare ( ExprList * pA,
ExprList * pB,
int iTab )

Definition at line 105025 of file sqlite3.c.

105031 {
105032 int i;
105033 if( pA==0 && pB==0 ) return 0;
105034 if( pA==0 || pB==0 ) return 1;
105035 if( pA->nExpr!=pB->nExpr ) return 1;
105036 for(i=0; i<pA->nExpr; i++){
105037 int res;
105038 Expr *pExprA = pA->a[i].pExpr;

References ExprList::a, ExprList::nExpr, ExprList::ExprList_item::pExpr, ExprList::ExprList_item::sortFlags, and sqlite3ExprCompare().

Referenced by sqlite3ExprCompare(), sqlite3Select(), sqlite3WindowCompare(), sqlite3WindowRewrite(), and xferOptimization().

◆ sqlite3ExprListDelete()

◆ sqlite3ExprListDup()

SQLITE_PRIVATE ExprList * sqlite3ExprListDup ( sqlite3 * db,
ExprList * p,
int flags )

Definition at line 101165 of file sqlite3.c.

101167 {
101168 assert( flags==0 || flags==EXPRDUP_REDUCE );
101169 return p ? exprDup(db, p, flags, 0) : 0;
101170}
101172 ExprList *pNew;
101173 struct ExprList_item *pItem, *pOldItem;
101174 int i;
101175 Expr *pPriorSelectCol = 0;
101176 assert( db!=0 );
101177 if( p==0 ) return 0;
101178 pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
101179 if( pNew==0 ) return 0;
101180 pNew->nExpr = p->nExpr;
101181 pItem = pNew->a;
101182 pOldItem = p->a;
101183 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
101184 Expr *pOldExpr = pOldItem->pExpr;
101185 Expr *pNewExpr;
101186 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
101187 if( pOldExpr
101188 && pOldExpr->op==TK_SELECT_COLUMN
101189 && (pNewExpr = pItem->pExpr)!=0
101190 ){
101191 assert( pNewExpr->iColumn==0 || i>0 );
101192 if( pNewExpr->iColumn==0 ){
101193 assert( pOldExpr->pLeft==pOldExpr->pRight );
101194 pPriorSelectCol = pNewExpr->pLeft = pNewExpr->pRight;
101195 }else{
101196 assert( i>0 );
101197 assert( pItem[-1].pExpr!=0 );
101198 assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
101199 assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
101200 pNewExpr->pLeft = pPriorSelectCol;
101201 }
101202 }
101203 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
101204 pItem->sortFlags = pOldItem->sortFlags;
101205 pItem->eEName = pOldItem->eEName;
101206 pItem->done = 0;

References exprDup(), and EXPRDUP_REDUCE.

Referenced by exprDup(), fkActionTrigger(), minMaxQuery(), multiSelectOrderBy(), sqlite3Pragma(), sqlite3Select(), sqlite3SrcListDup(), sqlite3TriggerUpdateStep(), sqlite3WindowChain(), sqlite3WindowDup(), sqlite3WindowUpdate(), updateFromSelect(), and withDup().

◆ sqlite3ExprListFlags()

SQLITE_PRIVATE u32 sqlite3ExprListFlags ( const ExprList * pList)

Definition at line 101586 of file sqlite3.c.

101592 {
101593 int i;
101594 u32 m = 0;
101595 assert( pList!=0 );
101596 for(i=0; i<pList->nExpr; i++){

Referenced by exprSetHeight().

◆ sqlite3ExprListSetName()

SQLITE_PRIVATE void sqlite3ExprListSetName ( Parse * pParse,
ExprList * pList,
Token * pName,
int dequote )

Definition at line 101494 of file sqlite3.c.

101505 {
101506 assert( pList!=0 || pParse->db->mallocFailed!=0 );
101507 assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
101508 if( pList ){
101509 struct ExprList_item *pItem;
101510 assert( pList->nExpr>0 );
101511 pItem = &pList->a[pList->nExpr-1];
101512 assert( pItem->zEName==0 );
101513 assert( pItem->eEName==ENAME_NAME );
101514 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
101515 if( dequote ){
101516 /* If dequote==0, then pName->z does not point to part of a DDL
101517 ** statement handled by the parser. And so no token need be added
101518 ** to the token-map. */
101519 sqlite3Dequote(pItem->zEName);
#define PARSE_MODE_UNMAP
Definition sqlite3.c:18784

References ExprList::a, Parse::db, ENAME_NAME, Parse::eParseMode, IN_RENAME_OBJECT, sqlite3::mallocFailed, Token::n, ExprList::nExpr, PARSE_MODE_UNMAP, sqlite3DbStrNDup(), sqlite3Dequote(), sqlite3RenameTokenMap(), and Token::z.

Referenced by fkActionTrigger(), parserAddExprIdListTerm(), selectExpander(), and yy_reduce().

◆ sqlite3ExprListSetSortOrder()

SQLITE_PRIVATE void sqlite3ExprListSetSortOrder ( ExprList * p,
int iSortOrder,
int eNulls )

Definition at line 101456 of file sqlite3.c.

101462 {
101463 struct ExprList_item *pItem;
101464 if( p==0 ) return;
101465 assert( p->nExpr>0 );
101466
101467 assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
101468 assert( iSortOrder==SQLITE_SO_UNDEFINED
101469 || iSortOrder==SQLITE_SO_ASC
101470 || iSortOrder==SQLITE_SO_DESC
101471 );
101472 assert( eNulls==SQLITE_SO_UNDEFINED
101473 || eNulls==SQLITE_SO_ASC
101474 || eNulls==SQLITE_SO_DESC
101475 );
101476
101477 pItem = &p->a[p->nExpr-1];
101478 assert( pItem->bNulls==0 );
101479 if( iSortOrder==SQLITE_SO_UNDEFINED ){
101480 iSortOrder = SQLITE_SO_ASC;
101481 }
101482 pItem->sortFlags = (u8)iSortOrder;
101483
101484 if( eNulls!=SQLITE_SO_UNDEFINED ){
#define SQLITE_SO_ASC
Definition sqlite3.c:17376

Referenced by sqlite3CreateIndex(), and yy_reduce().

◆ sqlite3ExprListSetSpan()

SQLITE_PRIVATE void sqlite3ExprListSetSpan ( Parse * pParse,
ExprList * pList,
const char * zStart,
const char * zEnd )

Definition at line 101529 of file sqlite3.c.

101540 {
101541 sqlite3 *db = pParse->db;
101542 assert( pList!=0 || db->mallocFailed!=0 );
101543 if( pList ){
101544 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
101545 assert( pList->nExpr>0 );

References ExprList::a, Parse::db, ENAME_SPAN, sqlite3::mallocFailed, ExprList::nExpr, and sqlite3DbSpanDup().

Referenced by yy_reduce().

◆ sqlite3ExprNeedsNoAffinityChange()

SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange ( const Expr * p,
char aff )

Definition at line 102023 of file sqlite3.c.

102029 {
102030 u8 op;
102031 int unaryMinus = 0;
102032 if( aff==SQLITE_AFF_BLOB ) return 1;
102033 while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
102034 if( p->op==TK_UMINUS ) unaryMinus = 1;
102035 p = p->pLeft;
102036 }
102037 op = p->op;
102038 if( op==TK_REGISTER ) op = p->op2;
102039 switch( op ){
102040 case TK_INTEGER: {
102041 return aff>=SQLITE_AFF_NUMERIC;
102042 }
102043 case TK_FLOAT: {
102044 return aff>=SQLITE_AFF_NUMERIC;
102045 }
102046 case TK_STRING: {
102047 return !unaryMinus && aff==SQLITE_AFF_TEXT;
102048 }
102049 case TK_BLOB: {
102050 return !unaryMinus;
102051 }
102052 case TK_COLUMN: {
102053 assert( p->iTable>=0 ); /* p cannot be part of a CHECK constraint */
102054 return aff>=SQLITE_AFF_NUMERIC && p->iColumn<0;

References Expr::iColumn, Expr::iTable, Expr::op, Expr::op2, Expr::pLeft, SQLITE_AFF_BLOB, SQLITE_AFF_NUMERIC, SQLITE_AFF_TEXT, TK_BLOB, TK_COLUMN, TK_FLOAT, TK_INTEGER, TK_REGISTER, TK_STRING, TK_UMINUS, and TK_UPLUS.

Referenced by codeAllEqualityTerms(), and updateRangeAffinityStr().

◆ sqlite3ExprNNCollSeq()

SQLITE_PRIVATE CollSeq * sqlite3ExprNNCollSeq ( Parse * pParse,
const Expr * pExpr )

Definition at line 99938 of file sqlite3.c.

99940**
99941** The sqlite3ExprCollSeq() routine works the same except that it
99942** returns NULL if there is no defined collation.
99943*/

References Parse::db, sqlite3::pDfltColl, and sqlite3ExprCollSeq().

Referenced by findIndexCol(), sqlite3KeyInfoFromExprList(), wherePathSatisfiesOrderBy(), and windowAggStep().

◆ sqlite3ExprReferencesUpdatedColumn()

SQLITE_PRIVATE int sqlite3ExprReferencesUpdatedColumn ( Expr * pExpr,
int * aiChng,
int chngRowid )

Definition at line 121926 of file sqlite3.c.

121927 : pExpr might also be an expression for an index-on-expressions.
121928** The operation of this routine is the same - return true if an only if
121929** the expression uses one or more of columns identified by the second and
121930** third arguments.
121931*/
121933 Expr *pExpr, /* The expression to be checked */
121934 int *aiChng, /* aiChng[x]>=0 if column x changed by the UPDATE */
121935 int chngRowid /* True if UPDATE changes the rowid */
121936){
121937 Walker w;
121938 memset(&w, 0, sizeof(w));
121939 w.eCode = 0;
121941 w.u.aiCol = aiChng;
121942 sqlite3WalkExpr(&w, pExpr);
121943 if( !chngRowid ){
121944 testcase( (w.eCode & CKCNSTRNT_ROWID)!=0 );
121945 w.eCode &= ~CKCNSTRNT_ROWID;
121946 }
static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:121897
SQLITE_PRIVATE int sqlite3ExprReferencesUpdatedColumn(Expr *, int *, int)
Definition sqlite3.c:121926
#define CKCNSTRNT_ROWID
Definition sqlite3.c:121890

References Walker::aiCol, checkConstraintExprNode(), CKCNSTRNT_COLUMN, CKCNSTRNT_ROWID, Walker::eCode, sqlite3WalkExpr(), testcase, Walker::u, and Walker::xExprCallback.

Referenced by indexColumnIsBeingUpdated(), indexWhereClauseMightChange(), sqlite3GenerateConstraintChecks(), and sqlite3Update().

◆ sqlite3ExprSetHeightAndFlags()

SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags ( Parse * pParse,
Expr * p )

Definition at line 100458 of file sqlite3.c.

References exprSetHeight(), Parse::nErr, Expr::nHeight, and sqlite3ExprCheckHeight().

Referenced by yy_reduce().

◆ sqlite3ExprSimplifiedAndOr()

SQLITE_PRIVATE Expr * sqlite3ExprSimplifiedAndOr ( Expr * pExpr)

Definition at line 101669 of file sqlite3.c.

101675 {
101676 assert( pExpr!=0 );
101677 if( pExpr->op==TK_AND || pExpr->op==TK_OR ){
101678 Expr *pRight = sqlite3ExprSimplifiedAndOr(pExpr->pRight);
101679 Expr *pLeft = sqlite3ExprSimplifiedAndOr(pExpr->pLeft);
101680 if( ExprAlwaysTrue(pLeft) || ExprAlwaysFalse(pRight) ){
101681 pExpr = pExpr->op==TK_AND ? pRight : pLeft;

References ExprAlwaysFalse, ExprAlwaysTrue, Expr::op, Expr::pLeft, Expr::pRight, sqlite3ExprSimplifiedAndOr(), TK_AND, and TK_OR.

Referenced by sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), and sqlite3ExprSimplifiedAndOr().

◆ sqlite3ExprSkipCollate()

SQLITE_PRIVATE Expr * sqlite3ExprSkipCollate ( Expr * pExpr)

Definition at line 99824 of file sqlite3.c.

99830 {

Referenced by exprAnalyze(), isLikeOrGlob(), sqlite3AddPrimaryKey(), and sqlite3CreateIndex().

◆ sqlite3ExprSkipCollateAndLikely()

◆ sqlite3ExprTruthValue()

SQLITE_PRIVATE int sqlite3ExprTruthValue ( const Expr * pExpr)

Definition at line 101648 of file sqlite3.c.

101654 {

Referenced by sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), and yy_reduce().

◆ sqlite3ExprUnmapAndDelete()

SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete ( Parse * pParse,
Expr * p )

Definition at line 100856 of file sqlite3.c.

100862 {
100863 if( p ){

Referenced by sqlite3ExprListAppendVector(), and yy_reduce().

◆ sqlite3ExprVectorSize()

◆ sqlite3ExprWalkNoop()

SQLITE_PRIVATE int sqlite3ExprWalkNoop ( Walker * NotUsed,
Expr * NotUsed2 )

Definition at line 97734 of file sqlite3.c.

References UNUSED_PARAMETER2, and WRC_Continue.

Referenced by sqlite3SelectAddTypeInfo(), and sqlite3SelectExpand().

◆ sqlite3FaultSim()

◆ sqlite3FindCollSeq()

SQLITE_PRIVATE CollSeq * sqlite3FindCollSeq ( sqlite3 * db,
u8 enc,
const char * zName,
int create )

Definition at line 115695 of file sqlite3.c.

115700*/
115702 sqlite3 *db, /* Database connection to search */
115703 u8 enc, /* Desired text encoding */
115704 const char *zName, /* Name of the collating sequence. Might be NULL */
115705 int create /* True to create CollSeq if doesn't already exist */
115706){
115707 CollSeq *pColl;
115708 assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
115709 assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
115710 if( zName ){
115711 pColl = findCollSeqEntry(db, zName, create);
static CollSeq * findCollSeqEntry(sqlite3 *db, const char *zName, int create)
Definition sqlite3.c:115643

References findCollSeqEntry(), sqlite3::pDfltColl, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, and zName.

Referenced by sqlite3ExprCollSeq(), sqlite3GetCollSeq(), sqlite3LocateCollSeq(), sqlite3Reindex(), and synthCollSeq().

◆ sqlite3FindDb()

SQLITE_PRIVATE int sqlite3FindDb ( sqlite3 * db,
Token * pName )

Definition at line 111192 of file sqlite3.c.

111198 {
111199 int i; /* Database number */

References sqlite3DbFree(), sqlite3FindDbName(), sqlite3NameFromToken(), and zName.

Referenced by sqlite3Analyze(), sqlite3TwoPartName(), and sqlite3Vacuum().

◆ sqlite3FindDbName()

SQLITE_PRIVATE int sqlite3FindDbName ( sqlite3 * db,
const char * zName )

Definition at line 111172 of file sqlite3.c.

111178 {
111179 int i = -1; /* Database number */
111180 if( zName ){
111181 Db *pDb;
111182 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
111183 if( 0==sqlite3_stricmp(pDb->zDbSName, zName) ) break;
111184 /* "main" is always an acceptable alias for the primary database

References sqlite3::aDb, sqlite3::nDb, sqlite3_stricmp(), Db::zDbSName, and zName.

Referenced by findBtree(), renameParseSql(), renameTableTest(), sqlite3FindDb(), and sqlite3FixSrcList().

◆ sqlite3FindFunction()

SQLITE_PRIVATE FuncDef * sqlite3FindFunction ( sqlite3 * db,
const char * zName,
int nArg,
u8 enc,
u8 createFlag )

Definition at line 115931 of file sqlite3.c.

115943 {
115944 FuncDef *p; /* Iterator variable */
115945 FuncDef *pBest = 0; /* Best match found so far */
115946 int bestScore = 0; /* Score of best match */
115947 int h; /* Hash value */
115948 int nName; /* Length of the name */
115949
115950 assert( nArg>=(-2) );
115951 assert( nArg>=(-1) || createFlag==0 );
115953
115954 /* First search for a match amongst the application-defined functions.
115955 */
115956 p = (FuncDef*)sqlite3HashFind(&db->aFunc, zName);
115957 while( p ){
115958 int score = matchQuality(p, nArg, enc);
115959 if( score>bestScore ){
115960 pBest = p;
115961 bestScore = score;
115962 }
115963 p = p->pNext;
115964 }
115965
115966 /* If no match is found, search the built-in functions.
115967 **
115968 ** If the DBFLAG_PreferBuiltin flag is set, then search the built-in
115969 ** functions even if a prior app-defined function was found. And give
115970 ** priority to built-in functions.
115971 **
115972 ** Except, if createFlag is true, that means that we are trying to
115973 ** install a new function. Whatever FuncDef structure is returned it will
115974 ** have fields overwritten with new information appropriate for the
115975 ** new function. But the FuncDefs for built-in functions are read-only.
115976 ** So we must not search for built-ins when creating a new function.
115977 */
115978 if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
115979 bestScore = 0;
115982 while( p ){
115983 int score = matchQuality(p, nArg, enc);
115984 if( score>bestScore ){
115985 pBest = p;
115986 bestScore = score;
115987 }
115988 p = p->pNext;
115989 }
115990 }
115991
115992 /* If the createFlag parameter is true and the search did not reveal an
115993 ** exact match for the name, number of arguments and encoding, then add a
115994 ** new entry to the hash table and return it.
115995 */
115996 if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
115997 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
115998 FuncDef *pOther;
115999 u8 *z;
116000 pBest->zName = (const char*)&pBest[1];
116001 pBest->nArg = (u16)nArg;
116002 pBest->funcFlags = enc;
116003 memcpy((char*)&pBest[1], zName, nName+1);
116004 for(z=(u8*)pBest->zName; *z; z++) *z = sqlite3UpperToLower[*z];
116005 pOther = (FuncDef*)sqlite3HashInsert(&db->aFunc, pBest->zName, pBest);
116006 if( pOther==pBest ){
116007 sqlite3DbFree(db, pBest);
116008 sqlite3OomFault(db);
116009 return 0;
116010 }else{
116011 pBest->pNext = pOther;
116012 }
116013 }
SQLITE_PRIVATE FuncDef * sqlite3FunctionSearch(int, const char *)
Definition sqlite3.c:115870
static int matchQuality(FuncDef *p, int nArg, u8 enc)
Definition sqlite3.c:115834
#define SQLITE_FUNC_HASH(C, L)
Definition sqlite3.c:16763
Hash aFunc
Definition sqlite3.c:16923

References sqlite3::aFunc, DBFLAG_PreferBuiltin, FUNC_PERFECT_MATCH, FuncDef::funcFlags, matchQuality(), sqlite3::mDbFlags, FuncDef::nArg, nName, FuncDef::pNext, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3FunctionSearch(), sqlite3HashFind(), sqlite3HashInsert(), sqlite3OomFault(), sqlite3Strlen30(), sqlite3UpperToLower, SQLITE_FUNC_HASH, FuncDef::xSFunc, FuncDef::zName, and zName.

Referenced by analyzeAggregate(), resolveExprStep(), sqlite3_overload_function(), sqlite3CreateFunc(), sqlite3ExprCodeTarget(), sqlite3IsLikeFunction(), and sqlite3RegisterLikeFunctions().

◆ sqlite3FindIndex()

SQLITE_PRIVATE Index * sqlite3FindIndex ( sqlite3 * db,
const char * zName,
const char * zDb )

Definition at line 110865 of file sqlite3.c.

110871 {
110872 Index *p = 0;
110873 int i;
110874 /* All mutexes are required for schema access. Make sure we hold them. */
110875 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
110876 for(i=OMIT_TEMPDB; i<db->nDb; i++){
110877 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
110878 Schema *pSchema = db->aDb[j].pSchema;
110879 assert( pSchema );
110880 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;

References sqlite3::aDb, Schema::idxHash, sqlite3::nDb, OMIT_TEMPDB, Db::pSchema, sqlite3DbIsNamed(), sqlite3HashFind(), and zName.

Referenced by analysisLoader(), sqlite3Analyze(), sqlite3CreateIndex(), sqlite3InitCallback(), sqlite3Pragma(), sqlite3Reindex(), and sqlite3StartTable().

◆ sqlite3FindInIndex()

SQLITE_PRIVATE int sqlite3FindInIndex ( Parse * pParse,
Expr * pX,
u32 inFlags,
int * prRhsHasNull,
int * aiMap,
int * piTab )

Definition at line 102229 of file sqlite3.c.

102232 {2, 0, 1}.
102233*/
102234#ifndef SQLITE_OMIT_SUBQUERY
102236 Parse *pParse, /* Parsing context */
102237 Expr *pX, /* The IN expression */
102238 u32 inFlags, /* IN_INDEX_LOOP, _MEMBERSHIP, and/or _NOOP_OK */
102239 int *prRhsHasNull, /* Register holding NULL status. See notes */
102240 int *aiMap, /* Mapping from Index fields to RHS fields */
102241 int *piTab /* OUT: index to use */
102242){
102243 Select *p; /* SELECT to the right of IN operator */
102244 int eType = 0; /* Type of RHS table. IN_INDEX_* */
102245 int iTab = pParse->nTab++; /* Cursor of the RHS table */
102246 int mustBeUnique; /* True if RHS must be unique */
102247 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
102248
102249 assert( pX->op==TK_IN );
102250 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
102251
102252 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
102253 ** whether or not the SELECT result contains NULL values, check whether
102254 ** or not NULL is actually possible (it may not be, for example, due
102255 ** to NOT NULL constraints in the schema). If no NULL values are possible,
102256 ** set prRhsHasNull to 0 before continuing. */
102257 if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){
102258 int i;
102259 ExprList *pEList = pX->x.pSelect->pEList;
102260 for(i=0; i<pEList->nExpr; i++){
102261 if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break;
102262 }
102263 if( i==pEList->nExpr ){
102264 prRhsHasNull = 0;
102265 }
102266 }
102267
102268 /* Check to see if an existing table or index can be used to
102269 ** satisfy the query. This is preferable to generating a new
102270 ** ephemeral table. */
102271 if( pParse->nErr==0 && (p = isCandidateForInOpt(pX))!=0 ){
102272 sqlite3 *db = pParse->db; /* Database connection */
102273 Table *pTab; /* Table <table>. */
102274 int iDb; /* Database idx for pTab */
102275 ExprList *pEList = p->pEList;
102276 int nExpr = pEList->nExpr;
102277
102278 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
102279 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
102280 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
102281 pTab = p->pSrc->a[0].pTab;
102282
102283 /* Code an OP_Transaction and OP_TableLock for <table>. */
102284 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102285 assert( iDb>=0 && iDb<SQLITE_MAX_ATTACHED );
102286 sqlite3CodeVerifySchema(pParse, iDb);
102287 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
102288
102289 assert(v); /* sqlite3GetVdbe() has always been previously called */
102290 if( nExpr==1 && pEList->a[0].pExpr->iColumn<0 ){
102291 /* The "x IN (SELECT rowid FROM table)" case */
102292 int iAddr = sqlite3VdbeAddOp0(v, OP_Once);
102293 VdbeCoverage(v);
102294
102295 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
102297 ExplainQueryPlan((pParse, 0,
102298 "USING ROWID SEARCH ON TABLE %s FOR IN-OPERATOR",pTab->zName));
102299 sqlite3VdbeJumpHere(v, iAddr);
102300 }else{
102301 Index *pIdx; /* Iterator variable */
102302 int affinity_ok = 1;
102303 int i;
102304
102305 /* Check that the affinity that will be used to perform each
102306 ** comparison is the same as the affinity of each column in table
102307 ** on the RHS of the IN operator. If it not, it is not possible to
102308 ** use any index of the RHS table. */
102309 for(i=0; i<nExpr && affinity_ok; i++){
102310 Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
102311 int iCol = pEList->a[i].pExpr->iColumn;
102312 char idxaff = sqlite3TableColumnAffinity(pTab,iCol); /* RHS table */
102313 char cmpaff = sqlite3CompareAffinity(pLhs, idxaff);
102314 testcase( cmpaff==SQLITE_AFF_BLOB );
102315 testcase( cmpaff==SQLITE_AFF_TEXT );
102316 switch( cmpaff ){
102317 case SQLITE_AFF_BLOB:
102318 break;
102319 case SQLITE_AFF_TEXT:
102320 /* sqlite3CompareAffinity() only returns TEXT if one side or the
102321 ** other has no affinity and the other side is TEXT. Hence,
102322 ** the only way for cmpaff to be TEXT is for idxaff to be TEXT
102323 ** and for the term on the LHS of the IN to have no affinity. */
102324 assert( idxaff==SQLITE_AFF_TEXT );
102325 break;
102326 default:
102327 affinity_ok = sqlite3IsNumericAffinity(idxaff);
102328 }
102329 }
102330
102331 if( affinity_ok ){
102332 /* Search for an existing index that will work for this IN operator */
102333 for(pIdx=pTab->pIndex; pIdx && eType==0; pIdx=pIdx->pNext){
102334 Bitmask colUsed; /* Columns of the index used */
102335 Bitmask mCol; /* Mask for the current column */
102336 if( pIdx->nColumn<nExpr ) continue;
102337 if( pIdx->pPartIdxWhere!=0 ) continue;
102338 /* Maximum nColumn is BMS-2, not BMS-1, so that we can compute
102339 ** BITMASK(nExpr) without overflowing */
102340 testcase( pIdx->nColumn==BMS-2 );
102341 testcase( pIdx->nColumn==BMS-1 );
102342 if( pIdx->nColumn>=BMS-1 ) continue;
102343 if( mustBeUnique ){
102344 if( pIdx->nKeyCol>nExpr
102345 ||(pIdx->nColumn>nExpr && !IsUniqueIndex(pIdx))
102346 ){
102347 continue; /* This index is not unique over the IN RHS columns */
102348 }
102349 }
102350
102351 colUsed = 0; /* Columns of index used so far */
102352 for(i=0; i<nExpr; i++){
102353 Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
102354 Expr *pRhs = pEList->a[i].pExpr;
102355 CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
102356 int j;
102357
102358 assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr );
102359 for(j=0; j<nExpr; j++){
102360 if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
102361 assert( pIdx->azColl[j] );
102362 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
102363 continue;
102364 }
102365 break;
102366 }
102367 if( j==nExpr ) break;
102368 mCol = MASKBIT(j);
102369 if( mCol & colUsed ) break; /* Each column used only once */
102370 colUsed |= mCol;
102371 if( aiMap ) aiMap[i] = j;
102372 }
102373
102374 assert( i==nExpr || colUsed!=(MASKBIT(nExpr)-1) );
102375 if( colUsed==(MASKBIT(nExpr)-1) ){
102376 /* If we reach this point, that means the index pIdx is usable */
102377 int iAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
102378 ExplainQueryPlan((pParse, 0,
102379 "USING INDEX %s FOR IN-OPERATOR",pIdx->zName));
102380 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
102381 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
102382 VdbeComment((v, "%s", pIdx->zName));
102384 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
102385
102386 if( prRhsHasNull ){
102387#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
102388 i64 mask = (1<<nExpr)-1;
102390 iTab, 0, 0, (u8*)&mask, P4_INT64);
102391#endif
102392 *prRhsHasNull = ++pParse->nMem;
102393 if( nExpr==1 ){
102394 sqlite3SetHasNullFlag(v, iTab, *prRhsHasNull);
102395 }
102396 }
102397 sqlite3VdbeJumpHere(v, iAddr);
102398 }
102399 } /* End loop over indexes */
102400 } /* End if( affinity_ok ) */
102401 } /* End if not an rowid index */
102402 } /* End attempt to optimize using an index */
102403
102404 /* If no preexisting index is available for the IN clause
102405 ** and IN_INDEX_NOOP is an allowed reply
102406 ** and the RHS of the IN operator is a list, not a subquery
102407 ** and the RHS is not constant or has two or fewer terms,
102408 ** then it is not worth creating an ephemeral table to evaluate
102409 ** the IN operator so return IN_INDEX_NOOP.
102410 */
102411 if( eType==0
102412 && (inFlags & IN_INDEX_NOOP_OK)
102414 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
102415 ){
102417 }
102418
102419 if( eType==0 ){
102420 /* Could not find an existing table or index to use as the RHS b-tree.
102421 ** We will have to generate an ephemeral table to do the job.
102422 */
102423 u32 savedNQueryLoop = pParse->nQueryLoop;
102424 int rMayHaveNull = 0;
102426 if( inFlags & IN_INDEX_LOOP ){
102427 pParse->nQueryLoop = 0;
102428 }else if( prRhsHasNull ){
102429 *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
102430 }
102431 assert( pX->op==TK_IN );
102432 sqlite3CodeRhsOfIN(pParse, pX, iTab);
102433 if( rMayHaveNull ){
102434 sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
102435 }
102436 pParse->nQueryLoop = savedNQueryLoop;
102437 }
102438
102440 int i, n;
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe *, int, int, int, int, const u8 *, int)
Definition sqlite3.c:78121
static Select * isCandidateForInOpt(Expr *pX)
Definition sqlite3.c:102074
static void sqlite3SetHasNullFlag(Vdbe *v, int iCur, int regHasNull)
Definition sqlite3.c:102119
static int sqlite3InRhsIsConstant(Expr *pIn)
Definition sqlite3.c:102136
#define OP_ColumnsUsed
Definition sqlite3.c:15683
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse *, Expr *, int)
Definition sqlite3.c:102537

References ExprList::a, SrcList::a, Index::aiColumn, Index::aSortOrder, Index::azColl, BMS, Parse::db, EP_xIsSelect, eType, ExplainQueryPlan, ExprHasProperty, Expr::flags, Expr::iColumn, IN_INDEX_EPH, IN_INDEX_INDEX_ASC, IN_INDEX_INDEX_DESC, IN_INDEX_LOOP, IN_INDEX_NOOP, IN_INDEX_NOOP_OK, IN_INDEX_ROWID, isCandidateForInOpt(), IsUniqueIndex, mask, MASKBIT, Index::nColumn, Parse::nErr, ExprList::nExpr, Index::nKeyCol, Parse::nMem, Parse::nQueryLoop, Parse::nTab, Expr::op, OP_ColumnsUsed, OP_Once, OP_OpenRead, P4_INT64, Select::pEList, ExprList::ExprList_item::pExpr, Table::pIndex, Expr::pLeft, Expr::pList, Index::pNext, Index::pPartIdxWhere, Table::pSchema, Expr::pSelect, Select::pSrc, SrcList::SrcList_item::pTab, sqlite3BinaryCompareCollSeq(), sqlite3CodeRhsOfIN(), sqlite3CodeVerifySchema(), sqlite3CompareAffinity(), sqlite3ExprCanBeNull(), sqlite3ExprVectorSize(), sqlite3GetVdbe(), sqlite3InRhsIsConstant(), sqlite3IsNumericAffinity, sqlite3OpenTable(), sqlite3SchemaToIndex(), sqlite3SetHasNullFlag(), sqlite3StrICmp(), sqlite3TableColumnAffinity(), sqlite3TableLock(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4Dup8(), sqlite3VdbeJumpHere(), sqlite3VdbeSetP4KeyInfo(), sqlite3VectorFieldSubexpr(), SQLITE_AFF_BLOB, SQLITE_AFF_TEXT, SQLITE_MAX_ATTACHED, testcase, TK_IN, Table::tnum, Index::tnum, VdbeComment, VdbeCoverage, Expr::x, XN_ROWID, CollSeq::zName, Table::zName, and Index::zName.

Referenced by codeEqualityTerm(), and sqlite3ExprCodeIN().

◆ sqlite3FindTable()

SQLITE_PRIVATE Table * sqlite3FindTable ( sqlite3 * db,
const char * zName,
const char * zDatabase )

Definition at line 110699 of file sqlite3.c.

110705 {
110706 Table *p = 0;
110707 int i;
110708
110709 /* All mutexes are required for schema access. Make sure we hold them. */
110710 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
110711#if SQLITE_USER_AUTHENTICATION
110712 /* Only the admin user is allowed to know that the sqlite_user table
110713 ** exists */
110714 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
110715 return 0;
110716 }
110717#endif
110718 if( zDatabase ){
110719 for(i=0; i<db->nDb; i++){
110720 if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break;
110721 }
110722 if( i>=db->nDb ){
110723 /* No match against the official names. But always match "main"
110724 ** to schema 0 as a legacy fallback. */
110725 if( sqlite3StrICmp(zDatabase,"main")==0 ){
110726 i = 0;
110727 }else{
110728 return 0;
110729 }
110730 }
110731 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110732 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
110733 if( i==1 ){
110737 ){
110738 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
110740 }
110741 }else{
110742 if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){
110743 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash,
110745 }
110746 }
110747 }
110748 }else{
110749 /* Match against TEMP first */
110750 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName);
110751 if( p ) return p;
110752 /* The main database is second */
110753 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName);
110754 if( p ) return p;
110755 /* Attached databases are in order of attachment */
110756 for(i=2; i<db->nDb; i++){
110757 assert( sqlite3SchemaMutexHeld(db, i, 0) );
110758 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110759 if( p ) break;
110760 }
110761 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
110762 if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){
110764 }else if( sqlite3StrICmp(zName+7, &ALT_TEMP_SCHEMA_TABLE[7])==0 ){
110765 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
#define DFLT_TEMP_SCHEMA_TABLE
Definition sqlite3.c:14574
#define ALT_SCHEMA_TABLE
Definition sqlite3.c:14575
#define ALT_TEMP_SCHEMA_TABLE
Definition sqlite3.c:14576

References sqlite3::aDb, ALT_SCHEMA_TABLE, ALT_TEMP_SCHEMA_TABLE, DFLT_SCHEMA_TABLE, DFLT_TEMP_SCHEMA_TABLE, sqlite3::nDb, Db::pSchema, sqlite3HashFind(), sqlite3StrICmp(), sqlite3StrNICmp, Schema::tblHash, Db::zDbSName, and zName.

Referenced by analysisLoader(), openStatTable(), renameColumnFunc(), renameResolveTrigger(), renameTableFunc(), sqlite3_table_column_metadata(), sqlite3AlterFinishAddColumn(), sqlite3AnalysisLoad(), sqlite3CreateIndex(), sqlite3FkCheck(), sqlite3LocateTable(), sqlite3Pragma(), sqlite3Reindex(), sqlite3ShadowTableName(), sqlite3StartTable(), sqlite3VtabCallCreate(), and sqlite3VtabCallDestroy().

◆ sqlite3FinishCoding()

SQLITE_PRIVATE void sqlite3FinishCoding ( Parse * pParse)

Definition at line 110520 of file sqlite3.c.

110526 {
110527 sqlite3 *db;
110528 Vdbe *v;
110529
110530 assert( pParse->pToplevel==0 );
110531 db = pParse->db;
110532 if( pParse->nested ) return;
110533 if( db->mallocFailed || pParse->nErr ){
110534 if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
110535 return;
110536 }
110537
110538 /* Begin by generating some termination code at the end of the
110539 ** vdbe program
110540 */
110541 v = sqlite3GetVdbe(pParse);
110542 assert( !pParse->isMultiWrite
110543 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
110544 if( v ){
110546
110547#if SQLITE_USER_AUTHENTICATION
110548 if( pParse->nTableLock>0 && db->init.busy==0 ){
110549 sqlite3UserAuthInit(db);
110550 if( db->auth.authLevel<UAUTH_User ){
110551 sqlite3ErrorMsg(pParse, "user not authenticated");
110552 pParse->rc = SQLITE_AUTH_USER;
110553 return;
110554 }
110555 }
110556#endif
110557
110558 /* The cookie mask contains one bit for each database file open.
110559 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
110560 ** set for each database that is used. Generate code to start a
110561 ** transaction on each used database and to verify the schema cookie
110562 ** on each used database.
110563 */
110564 if( db->mallocFailed==0
110565 && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
110566 ){
110567 int iDb, i;
110568 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
110569 sqlite3VdbeJumpHere(v, 0);
110570 for(iDb=0; iDb<db->nDb; iDb++){
110571 Schema *pSchema;
110572 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
110573 sqlite3VdbeUsesBtree(v, iDb);
110574 pSchema = db->aDb[iDb].pSchema;
110576 OP_Transaction, /* Opcode */
110577 iDb, /* P1 */
110578 DbMaskTest(pParse->writeMask,iDb), /* P2 */
110579 pSchema->schema_cookie, /* P3 */
110580 pSchema->iGeneration /* P4 */
110581 );
110582 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
110583 VdbeComment((v,
110584 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
110585 }
110586#ifndef SQLITE_OMIT_VIRTUALTABLE
110587 for(i=0; i<pParse->nVtabLock; i++){
110588 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
110589 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
110590 }
110591 pParse->nVtabLock = 0;
110592#endif
110593
110594 /* Once all the cookies have been verified and transactions opened,
110595 ** obtain the required table-locks. This is a no-op unless the
110596 ** shared-cache feature is enabled.
110597 */
110598 codeTableLocks(pParse);
110599
110600 /* Initialize any AUTOINCREMENT data structures required.
110601 */
110603
110604 /* Code constant expressions that where factored out of inner loops.
110605 **
110606 ** The pConstExpr list might also contain expressions that we simply
110607 ** want to keep around until the Parse object is deleted. Such
110608 ** expressions have iConstExprReg==0. Do not generate code for
110609 ** those expressions, of course.
110610 */
110611 if( pParse->pConstExpr ){
110612 ExprList *pEL = pParse->pConstExpr;
110613 pParse->okConstFactor = 0;
110614 for(i=0; i<pEL->nExpr; i++){
110615 int iReg = pEL->a[i].u.iConstExprReg;
110616 if( iReg>0 ){
110617 sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
110618 }
110619 }
110620 }
110621
110622 /* Finally, jump back to the beginning of the executable code. */
110623 sqlite3VdbeGoto(v, 1);
110624 }
110625 }
110626
110627
110628 /* Get the VDBE program ready for execution
110629 */
110630 if( v && pParse->nErr==0 && !db->mallocFailed ){
110631 /* A minimum of one cursor is required if autoincrement is used
110632 * See ticket [a696379c1f08866] */
110633 assert( pParse->pAinc==0 || pParse->nTab>0 );
static void codeTableLocks(Parse *pParse)
Definition sqlite3.c:110479
#define DbMaskNonZero(M)
Definition sqlite3.c:18660
SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse)
Definition sqlite3.c:120937
#define OP_Init
Definition sqlite3.c:15628
u8 mayAbort
Definition sqlite3.c:18689
yDbMask writeMask
Definition sqlite3.c:18707
int nVtabLock
Definition sqlite3.c:18753
Table ** apVtabLock
Definition sqlite3.c:18770

References ExprList::a, sqlite3::aDb, Parse::apVtabLock, sqlite3::sqlite3InitInfo::busy, codeTableLocks(), Parse::cookieMask, Parse::db, DbMaskNonZero, DbMaskTest, ExprList::ExprList_item::iConstExprReg, Schema::iGeneration, sqlite3::init, Parse::isMultiWrite, sqlite3::mallocFailed, Parse::mayAbort, sqlite3::nDb, Parse::nErr, Parse::nested, ExprList::nExpr, Parse::nTab, Parse::nTableLock, Parse::nVtabLock, Parse::okConstFactor, OP_Halt, OP_Init, OP_Transaction, OP_VBegin, P4_VTAB, Parse::pAinc, Parse::pConstExpr, ExprList::ExprList_item::pExpr, Db::pSchema, Parse::pToplevel, Parse::rc, Schema::schema_cookie, sqlite3AutoincrementBegin(), sqlite3ErrorMsg(), sqlite3ExprCode(), sqlite3GetVdbe(), sqlite3GetVTable(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeGetOp(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeReady(), sqlite3VdbeUsesBtree(), SQLITE_AUTH_USER, SQLITE_DONE, SQLITE_ERROR, SQLITE_OK, ExprList::ExprList_item::u, VdbeComment, and Parse::writeMask.

Referenced by yy_reduce().

◆ sqlite3FinishTrigger()

SQLITE_PRIVATE void sqlite3FinishTrigger ( Parse * pParse,
TriggerStep * pStepList,
Token * pAll )

Definition at line 136668 of file sqlite3.c.

136678 {
136679 Trigger *pTrig = pParse->pNewTrigger; /* Trigger being finished */
136680 char *zName; /* Name of trigger */
136681 sqlite3 *db = pParse->db; /* The database */
136682 DbFixer sFix; /* Fixer object */
136683 int iDb; /* Database containing the trigger */
136684 Token nameToken; /* Trigger name for error reporting */
136685
136686 pParse->pNewTrigger = 0;
136687 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
136688 zName = pTrig->zName;
136689 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
136690 pTrig->step_list = pStepList;
136691 while( pStepList ){
136692 pStepList->pTrig = pTrig;
136693 pStepList = pStepList->pNext;
136694 }
136695 sqlite3TokenInit(&nameToken, pTrig->zName);
136696 sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken);
136697 if( sqlite3FixTriggerStep(&sFix, pTrig->step_list)
136698 || sqlite3FixExpr(&sFix, pTrig->pWhen)
136699 ){
136700 goto triggerfinish_cleanup;
136701 }
136702
136703#ifndef SQLITE_OMIT_ALTERTABLE
136704 if( IN_RENAME_OBJECT ){
136705 assert( !db->init.busy );
136706 pParse->pNewTrigger = pTrig;
136707 pTrig = 0;
136708 }else
136709#endif
136710
136711 /* if we are not initializing,
136712 ** build the sqlite_schema entry
136713 */
136714 if( !db->init.busy ){
136715 Vdbe *v;
136716 char *z;
136717
136718 /* Make an entry in the sqlite_schema table */
136719 v = sqlite3GetVdbe(pParse);
136720 if( v==0 ) goto triggerfinish_cleanup;
136721 sqlite3BeginWriteOperation(pParse, 0, iDb);
136722 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
136723 testcase( z==0 );
136724 sqlite3NestedParse(pParse,
136725 "INSERT INTO %Q." DFLT_SCHEMA_TABLE
136726 " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
136727 db->aDb[iDb].zDbSName, zName,
136728 pTrig->table, z);
136729 sqlite3DbFree(db, z);
136730 sqlite3ChangeCookie(pParse, iDb);
136732 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
136733 }
136734
136735 if( db->init.busy ){
136736 Trigger *pLink = pTrig;
136737 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
136738 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
136739 assert( pLink!=0 );
136740 pTrig = sqlite3HashInsert(pHash, zName, pTrig);
136741 if( pTrig ){
136742 sqlite3OomFault(db);
136743 }else if( pLink->pSchema==pLink->pTabSchema ){
136744 Table *pTab;
136745 pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table);
136746 assert( pTab!=0 );
136747 pLink->pNext = pTab->pTrigger;
136748 pTab->pTrigger = pLink;
136749 }
136750 }
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer *, TriggerStep *)
Definition sqlite3.c:110076
SQLITE_PRIVATE int sqlite3FixExpr(DbFixer *, Expr *)
Definition sqlite3.c:110032
Trigger * pTrigger
Definition sqlite3.c:17516

Referenced by yy_reduce().

◆ sqlite3FixExpr()

SQLITE_PRIVATE int sqlite3FixExpr ( DbFixer * pFix,
Expr * pExpr )

Definition at line 110032 of file sqlite3.c.

110041 {
110042 while( pExpr ){
110043 if( !pFix->bTemp ) ExprSetProperty(pExpr, EP_FromDDL);
110044 if( pExpr->op==TK_VARIABLE ){
110045 if( pFix->pParse->db->init.busy ){
110046 pExpr->op = TK_NULL;
110047 }else{
110048 sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType);
110049 return 1;
110050 }
110051 }
110052 if( ExprHasProperty(pExpr, EP_TokenOnly|EP_Leaf) ) break;
110053 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
110054 if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1;
110055 }else{
110056 if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1;
110057 }
110058 if( sqlite3FixExpr(pFix, pExpr->pRight) ){
SQLITE_PRIVATE int sqlite3FixExprList(DbFixer *, ExprList *)
Definition sqlite3.c:110059
Parse * pParse
Definition sqlite3.c:18956
const char * zType
Definition sqlite3.c:18960

Referenced by sqlite3FixSrcList().

◆ sqlite3FixExprList()

SQLITE_PRIVATE int sqlite3FixExprList ( DbFixer * pFix,
ExprList * pList )

Definition at line 110059 of file sqlite3.c.

110068 {
110069 int i;
110070 struct ExprList_item *pItem;
110071 if( pList==0 ) return 0;
110072 for(i=0, pItem=pList->a; i<pList->nExpr; i++, pItem++){

Referenced by sqlite3FixSrcList().

◆ sqlite3FixInit()

SQLITE_PRIVATE void sqlite3FixInit ( DbFixer * pFix,
Parse * pParse,
int iDb,
const char * zType,
const Token * pName )

Definition at line 109926 of file sqlite3.c.

109938 {
109939 sqlite3 *db;
109940
109941 db = pParse->db;
109942 assert( db->nDb>iDb );
109943 pFix->pParse = pParse;

References sqlite3::aDb, DbFixer::bTemp, Parse::db, sqlite3::nDb, DbFixer::pName, DbFixer::pParse, Db::pSchema, DbFixer::pSchema, DbFixer::zDb, Db::zDbSName, and DbFixer::zType.

Referenced by sqlite3BeginTrigger(), and sqlite3CreateIndex().

◆ sqlite3FixSelect()

SQLITE_PRIVATE int sqlite3FixSelect ( DbFixer * pFix,
Select * pSelect )

Definition at line 109994 of file sqlite3.c.

110003 {
110004 while( pSelect ){
110005 if( sqlite3FixExprList(pFix, pSelect->pEList) ){
110006 return 1;
110007 }
110008 if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){
110009 return 1;
110010 }
110011 if( sqlite3FixExpr(pFix, pSelect->pWhere) ){
110012 return 1;
110013 }
110014 if( sqlite3FixExprList(pFix, pSelect->pGroupBy) ){
110015 return 1;
110016 }
110017 if( sqlite3FixExpr(pFix, pSelect->pHaving) ){
110018 return 1;
110019 }
110020 if( sqlite3FixExprList(pFix, pSelect->pOrderBy) ){
110021 return 1;
110022 }
110023 if( sqlite3FixExpr(pFix, pSelect->pLimit) ){
110024 return 1;
110025 }
110026 if( pSelect->pWith ){
110027 int i;
110028 for(i=0; i<pSelect->pWith->nCte; i++){
110029 if( sqlite3FixSelect(pFix, pSelect->pWith->a[i].pSelect) ){
110030 return 1;
110031 }

Referenced by sqlite3FixSrcList().

◆ sqlite3FixSrcList()

SQLITE_PRIVATE int sqlite3FixSrcList ( DbFixer * pFix,
SrcList * pList )

Definition at line 109959 of file sqlite3.c.

109959 : indices, triggers, and views in the TEMP database are
109960** allowed to refer to anything.) If a reference is explicitly made
109961** to an object in a different database, an error message is added to
109962** pParse->zErrMsg and these routines return non-zero. If everything
109963** checks out, these routines return 0.
109964*/
109966 DbFixer *pFix, /* Context of the fixation */
109967 SrcList *pList /* The Source list to check and modify */
109968){
109969 int i;
109970 struct SrcList_item *pItem;
109971 sqlite3 *db = pFix->pParse->db;
109972 int iDb = sqlite3FindDbName(db, pFix->zDb);
109973
109974 if( NEVER(pList==0) ) return 0;
109975
109976 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
109977 if( pFix->bTemp==0 ){
109978 if( pItem->zDatabase && iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){
109979 sqlite3ErrorMsg(pFix->pParse,
109980 "%s %T cannot reference objects in database %s",
109981 pFix->zType, pFix->pName, pItem->zDatabase);
109982 return 1;
109983 }
109984 sqlite3DbFree(db, pItem->zDatabase);
109985 pItem->zDatabase = 0;
109986 pItem->pSchema = pFix->pSchema;
109987 pItem->fg.fromDDL = 1;
109988 }
109989#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
109990 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
109991 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
109992#endif
Schema * pSchema
Definition sqlite3.c:18957
const char * zDb
Definition sqlite3.c:18959
const Token * pName
Definition sqlite3.c:18961

References SrcList::a, DbFixer::bTemp, Parse::db, NEVER, SrcList::nSrc, DbFixer::pName, DbFixer::pParse, DbFixer::pSchema, sqlite3DbFree(), sqlite3ErrorMsg(), sqlite3FindDbName(), sqlite3FixExpr(), sqlite3FixExprList(), sqlite3FixSelect(), DbFixer::zDb, and DbFixer::zType.

Referenced by sqlite3BeginTrigger(), and sqlite3CreateIndex().

◆ sqlite3FixTriggerStep()

SQLITE_PRIVATE int sqlite3FixTriggerStep ( DbFixer * pFix,
TriggerStep * pStep )

Definition at line 110076 of file sqlite3.c.

110085 {
110086 while( pStep ){
110087 if( sqlite3FixSelect(pFix, pStep->pSelect) ){
110088 return 1;
110089 }
110090 if( sqlite3FixExpr(pFix, pStep->pWhere) ){
110091 return 1;
110092 }
110093 if( sqlite3FixExprList(pFix, pStep->pExprList) ){
110094 return 1;
110095 }
110096 if( pStep->pFrom && sqlite3FixSrcList(pFix, pStep->pFrom) ){
110097 return 1;
110098 }
110099#ifndef SQLITE_OMIT_UPSERT
110100 if( pStep->pUpsert ){
110101 Upsert *pUp = pStep->pUpsert;
110102 if( sqlite3FixExprList(pFix, pUp->pUpsertTarget)
110103 || sqlite3FixExpr(pFix, pUp->pUpsertTargetWhere)
110104 || sqlite3FixExprList(pFix, pUp->pUpsertSet)
110105 || sqlite3FixExpr(pFix, pUp->pUpsertWhere)
110106 ){
110107 return 1;
110108 }
SrcList * pFrom
Definition sqlite3.c:18939

◆ sqlite3FkActions()

SQLITE_PRIVATE void sqlite3FkActions ( Parse * pParse,
Table * pTab,
ExprList * pChanges,
int regOld,
int * aChange,
int bChngRowid )

Definition at line 120475 of file sqlite3.c.

120488 {
120489 /* If foreign-key support is enabled, iterate through all FKs that
120490 ** refer to table pTab. If there is an action associated with the FK
120491 ** for this operation (either update or delete), invoke the associated
120492 ** trigger sub-program. */
120493 if( pParse->db->flags&SQLITE_ForeignKeys ){
120494 FKey *pFKey; /* Iterator variable */
120495 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
120496 if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
120497 Trigger *pAct = fkActionTrigger(pParse, pTab, pFKey, pChanges);
120498 if( pAct ){
SQLITE_PRIVATE FKey * sqlite3FkReferences(Table *)
Definition sqlite3.c:119774
static int fkParentIsModified(Table *pTab, FKey *p, int *aChange, int bChngRowid)
Definition sqlite3.c:119904
static Trigger * fkActionTrigger(Parse *pParse, Table *pTab, FKey *pFKey, ExprList *pChanges)
Definition sqlite3.c:120283

Referenced by sqlite3GenerateRowDelete(), and sqlite3Update().

◆ sqlite3FkCheck()

SQLITE_PRIVATE void sqlite3FkCheck ( Parse * pParse,
Table * pTab,
int regOld,
int regNew,
int * aChange,
int bChngRowid )

Definition at line 119966 of file sqlite3.c.

119979 {
119980 sqlite3 *db = pParse->db; /* Database handle */
119981 FKey *pFKey; /* Used to iterate through FKs */
119982 int iDb; /* Index of database containing pTab */
119983 const char *zDb; /* Name of database containing pTab */
119984 int isIgnoreErrors = pParse->disableTriggers;
119985
119986 /* Exactly one of regOld and regNew should be non-zero. */
119987 assert( (regOld==0)!=(regNew==0) );
119988
119989 /* If foreign-keys are disabled, this function is a no-op. */
119990 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
119991
119992 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119993 zDb = db->aDb[iDb].zDbSName;
119994
119995 /* Loop through all the foreign key constraints for which pTab is the
119996 ** child table (the table that the foreign key definition is part of). */
119997 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
119998 Table *pTo; /* Parent table of foreign key pFKey */
119999 Index *pIdx = 0; /* Index on key columns in pTo */
120000 int *aiFree = 0;
120001 int *aiCol;
120002 int iCol;
120003 int i;
120004 int bIgnore = 0;
120005
120006 if( aChange
120007 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
120008 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
120009 ){
120010 continue;
120011 }
120012
120013 /* Find the parent table of this foreign key. Also find a unique index
120014 ** on the parent key columns in the parent table. If either of these
120015 ** schema items cannot be located, set an error in pParse and return
120016 ** early. */
120017 if( pParse->disableTriggers ){
120018 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
120019 }else{
120020 pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb);
120021 }
120022 if( !pTo || sqlite3FkLocateIndex(pParse, pTo, pFKey, &pIdx, &aiFree) ){
120023 assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) );
120024 if( !isIgnoreErrors || db->mallocFailed ) return;
120025 if( pTo==0 ){
120026 /* If isIgnoreErrors is true, then a table is being dropped. In this
120027 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped
120028 ** before actually dropping it in order to check FK constraints.
120029 ** If the parent table of an FK constraint on the current table is
120030 ** missing, behave as if it is empty. i.e. decrement the relevant
120031 ** FK counter for each row of the current table with non-NULL keys.
120032 */
120033 Vdbe *v = sqlite3GetVdbe(pParse);
120034 int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
120035 for(i=0; i<pFKey->nCol; i++){
120036 int iFromCol, iReg;
120037 iFromCol = pFKey->aCol[i].iFrom;
120038 iReg = sqlite3TableColumnToStorage(pFKey->pFrom,iFromCol) + regOld+1;
120039 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v);
120040 }
120041 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
120042 }
120043 continue;
120044 }
120045 assert( pFKey->nCol==1 || (aiFree && pIdx) );
120046
120047 if( aiFree ){
120048 aiCol = aiFree;
120049 }else{
120050 iCol = pFKey->aCol[0].iFrom;
120051 aiCol = &iCol;
120052 }
120053 for(i=0; i<pFKey->nCol; i++){
120054 if( aiCol[i]==pTab->iPKey ){
120055 aiCol[i] = -1;
120056 }
120057 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
120058#ifndef SQLITE_OMIT_AUTHORIZATION
120059 /* Request permission to read the parent key columns. If the
120060 ** authorization callback returns SQLITE_IGNORE, behave as if any
120061 ** values read from the parent table are NULL. */
120062 if( db->xAuth ){
120063 int rcauth;
120064 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
120065 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
120066 bIgnore = (rcauth==SQLITE_IGNORE);
120067 }
120068#endif
120069 }
120070
120071 /* Take a shared-cache advisory read-lock on the parent table. Allocate
120072 ** a cursor to use to search the unique index on the parent key columns
120073 ** in the parent table. */
120074 sqlite3TableLock(pParse, iDb, pTo->tnum, 0, pTo->zName);
120075 pParse->nTab++;
120076
120077 if( regOld!=0 ){
120078 /* A row is being removed from the child table. Search for the parent.
120079 ** If the parent does not exist, removing the child row resolves an
120080 ** outstanding foreign key constraint violation. */
120081 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
120082 }
120083 if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
120084 /* A row is being added to the child table. If a parent row cannot
120085 ** be found, adding the child row has violated the FK constraint.
120086 **
120087 ** If this operation is being performed as part of a trigger program
120088 ** that is actually a "SET NULL" action belonging to this very
120089 ** foreign key, then omit this scan altogether. As all child key
120090 ** values are guaranteed to be NULL, it is not possible for adding
120091 ** this row to cause an FK violation. */
120092 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
120093 }
120094
120095 sqlite3DbFree(db, aiFree);
120096 }
120097
120098 /* Loop through all the foreign key constraints that refer to this table.
120099 ** (the "child" constraints) */
120100 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
120101 Index *pIdx = 0; /* Foreign key index for pFKey */
120102 SrcList *pSrc;
120103 int *aiCol = 0;
120104
120105 if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
120106 continue;
120107 }
120108
120109 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
120110 && !pParse->pToplevel && !pParse->isMultiWrite
120111 ){
120112 assert( regOld==0 && regNew!=0 );
120113 /* Inserting a single row into a parent table cannot cause (or fix)
120114 ** an immediate foreign key violation. So do nothing in this case. */
120115 continue;
120116 }
120117
120118 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
120119 if( !isIgnoreErrors || db->mallocFailed ) return;
120120 continue;
120121 }
120122 assert( aiCol || pFKey->nCol==1 );
120123
120124 /* Create a SrcList structure containing the child table. We need the
120125 ** child table as a SrcList for sqlite3WhereBegin() */
120126 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
120127 if( pSrc ){
120128 struct SrcList_item *pItem = pSrc->a;
120129 pItem->pTab = pFKey->pFrom;
120130 pItem->zName = pFKey->pFrom->zName;
120131 pItem->pTab->nTabRef++;
120132 pItem->iCursor = pParse->nTab++;
120133
120134 if( regNew!=0 ){
120135 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
120136 }
120137 if( regOld!=0 ){
120138 int eAction = pFKey->aAction[aChange!=0];
120139 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
120140 /* If this is a deferred FK constraint, or a CASCADE or SET NULL
120141 ** action applies, then any foreign key violations caused by
120142 ** removing the parent key will be rectified by the action trigger.
120143 ** So do not set the "may-abort" flag in this case.
120144 **
120145 ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
120146 ** may-abort flag will eventually be set on this statement anyway
120147 ** (when this function is called as part of processing the UPDATE
120148 ** within the action trigger).
120149 **
120150 ** Note 2: At first glance it may seem like SQLite could simply omit
120151 ** all OP_FkCounter related scans when either CASCADE or SET NULL
120152 ** applies. The trouble starts if the CASCADE or SET NULL action
120153 ** trigger causes other triggers or action rules attached to the
120154 ** child table to fire. In these cases the fk constraint counters
120155 ** might be set incorrectly if any OP_FkCounter related scans are
120156 ** omitted. */
120157 if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
120158 sqlite3MayAbort(pParse);
120159 }
120160 }
static void fkScanChildren(Parse *pParse, SrcList *pSrc, Table *pTab, Index *pIdx, FKey *pFKey, int *aiCol, int regData, int nIncr)
Definition sqlite3.c:119645
static int isSetNullAction(Parse *pParse, FKey *pFKey)
Definition sqlite3.c:119933
static void fkLookupParent(Parse *pParse, int iDb, Table *pTab, Index *pIdx, FKey *pFKey, int *aiCol, int regData, int nIncr, int isIgnore)
Definition sqlite3.c:119413
SQLITE_PRIVATE int sqlite3AuthReadCol(Parse *, const char *, const char *, int)
Definition sqlite3.c:110216
static int fkChildIsModified(Table *pTab, FKey *p, int *aChange, int bChngRowid)
Definition sqlite3.c:119877
u8 disableTriggers
Definition sqlite3.c:18728

References SrcList::a, FKey::aAction, Table::aCol, FKey::aCol, sqlite3::aDb, Index::aiColumn, Parse::db, Parse::disableTriggers, fkChildIsModified(), fkLookupParent(), fkParentIsModified(), fkScanChildren(), sqlite3::flags, FKey::sColMap::iFrom, Table::iPKey, FKey::isDeferred, Parse::isMultiWrite, isSetNullAction(), sqlite3::mallocFailed, FKey::nCol, Parse::nTab, OE_Cascade, OE_SetNull, OP_FkCounter, OP_IsNull, Table::pFKey, FKey::pFrom, FKey::pNextFrom, FKey::pNextTo, Table::pSchema, Parse::pToplevel, sqlite3_stricmp(), sqlite3AuthReadCol(), sqlite3DbFree(), sqlite3FindTable(), sqlite3FkLocateIndex(), sqlite3FkReferences(), sqlite3GetVdbe(), sqlite3LocateTable(), sqlite3MayAbort(), sqlite3SchemaToIndex(), sqlite3SrcListAppend(), sqlite3TableColumnToStorage(), sqlite3TableLock(), sqlite3VdbeAddOp2(), sqlite3VdbeCurrentAddr(), SQLITE_DeferFKs, SQLITE_ForeignKeys, SQLITE_IGNORE, Table::tnum, VdbeCoverage, sqlite3::xAuth, Db::zDbSName, Column::zName, Table::zName, and FKey::zTo.

Referenced by sqlite3GenerateRowDelete(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3FkDelete()

SQLITE_PRIVATE void sqlite3FkDelete ( sqlite3 * db,
Table * pTab )

Definition at line 120507 of file sqlite3.c.

120513 {
120514 FKey *pFKey; /* Iterator variable */
120515 FKey *pNext; /* Copy of pFKey->pNextFrom */
120516
120517 assert( db==0 || IsVirtual(pTab)
120518 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
120519 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
120520
120521 /* Remove the FK from the fkeyHash hash table. */
120522 if( !db || db->pnBytesFreed==0 ){
120523 if( pFKey->pPrevTo ){
120524 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
120525 }else{
120526 void *p = (void *)pFKey->pNextTo;
120527 const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
120528 sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, p);
120529 }
120530 if( pFKey->pNextTo ){
120531 pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
120532 }
120533 }
120534
120535 /* EV: R-30323-21917 Each foreign key constraint in SQLite is
120536 ** classified as either immediate or deferred.
120537 */
120538 assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
120539
120540 /* Delete any triggers created to implement actions for this FK. */
120541#ifndef SQLITE_OMIT_TRIGGER
120542 fkTriggerDelete(db, pFKey->apTrigger[0]);
120543 fkTriggerDelete(db, pFKey->apTrigger[1]);

References FKey::apTrigger, Schema::fkeyHash, fkTriggerDelete(), FKey::isDeferred, IsVirtual, Table::pFKey, sqlite3::pnBytesFreed, FKey::pNextFrom, FKey::pNextTo, FKey::pPrevTo, Table::pSchema, sqlite3DbFree(), sqlite3HashInsert(), and FKey::zTo.

Referenced by deleteTable().

◆ sqlite3FkDropTable()

SQLITE_PRIVATE void sqlite3FkDropTable ( Parse * pParse,
SrcList * pName,
Table * pTab )

Definition at line 119814 of file sqlite3.c.

119820 {
119821 sqlite3 *db = pParse->db;
119822 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
119823 int iSkip = 0;
119824 Vdbe *v = sqlite3GetVdbe(pParse);
119825
119826 assert( v ); /* VDBE has already been allocated */
119827 assert( pTab->pSelect==0 ); /* Not a view */
119828 if( sqlite3FkReferences(pTab)==0 ){
119829 /* Search for a deferred foreign key constraint for which this table
119830 ** is the child table. If one cannot be found, return without
119831 ** generating any VDBE code. If one can be found, then jump over
119832 ** the entire DELETE if there are no outstanding deferred constraints
119833 ** when this statement is run. */
119834 FKey *p;
119835 for(p=pTab->pFKey; p; p=p->pNextFrom){
119836 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
119837 }
119838 if( !p ) return;
119839 iSkip = sqlite3VdbeMakeLabel(pParse);
119840 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
119841 }
119842
119843 pParse->disableTriggers = 1;
119844 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
119845 pParse->disableTriggers = 0;
119846
119847 /* If the DELETE has generated immediate foreign key constraint
119848 ** violations, halt the VDBE and return an error at this point, before
119849 ** any modifications to the schema are made. This is because statement
119850 ** transactions are not able to rollback schema changes.
119851 **
119852 ** If the SQLITE_DeferFKs flag is set, then this is not required, as
119853 ** the statement transaction will not be rolled back even if FK
119854 ** constraints are violated.
119855 */
119856 if( (db->flags & SQLITE_DeferFKs)==0 ){
119859 VdbeCoverage(v);
119862 }
SQLITE_PRIVATE SrcList * sqlite3SrcListDup(sqlite3 *, SrcList *, int)
Definition sqlite3.c:101216

References Parse::db, Parse::disableTriggers, sqlite3::flags, FKey::isDeferred, IsVirtual, OE_Abort, OP_FkIfZero, P4_STATIC, P5_ConstraintFK, Table::pFKey, FKey::pNextFrom, Table::pSelect, sqlite3DeleteFrom(), sqlite3FkReferences(), sqlite3GetVdbe(), sqlite3HaltConstraint(), sqlite3SrcListDup(), sqlite3VdbeAddOp2(), sqlite3VdbeCurrentAddr(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VdbeVerifyAbortable, SQLITE_CONSTRAINT_FOREIGNKEY, SQLITE_DeferFKs, SQLITE_ForeignKeys, and VdbeCoverage.

◆ sqlite3FkLocateIndex()

SQLITE_PRIVATE int sqlite3FkLocateIndex ( Parse * pParse,
Table * pParent,
FKey * pFKey,
Index ** ppIdx,
int ** paiCol )

Definition at line 119278 of file sqlite3.c.

119290 {
119291 Index *pIdx = 0; /* Value to return via *ppIdx */
119292 int *aiCol = 0; /* Value to return via *paiCol */
119293 int nCol = pFKey->nCol; /* Number of columns in parent key */
119294 char *zKey = pFKey->aCol[0].zCol; /* Name of left-most parent key column */
119295
119296 /* The caller is responsible for zeroing output parameters. */
119297 assert( ppIdx && *ppIdx==0 );
119298 assert( !paiCol || *paiCol==0 );
119299 assert( pParse );
119300
119301 /* If this is a non-composite (single column) foreign key, check if it
119302 ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
119303 ** and *paiCol set to zero and return early.
119304 **
119305 ** Otherwise, for a composite foreign key (more than one column), allocate
119306 ** space for the aiCol array (returned via output parameter *paiCol).
119307 ** Non-composite foreign keys do not require the aiCol array.
119308 */
119309 if( nCol==1 ){
119310 /* The FK maps to the IPK if any of the following are true:
119311 **
119312 ** 1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
119313 ** mapped to the primary key of table pParent, or
119314 ** 2) The FK is explicitly mapped to a column declared as INTEGER
119315 ** PRIMARY KEY.
119316 */
119317 if( pParent->iPKey>=0 ){
119318 if( !zKey ) return 0;
119319 if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0;
119320 }
119321 }else if( paiCol ){
119322 assert( nCol>1 );
119323 aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int));
119324 if( !aiCol ) return 1;
119325 *paiCol = aiCol;
119326 }
119327
119328 for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
119329 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
119330 /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
119331 ** of columns. If each indexed column corresponds to a foreign key
119332 ** column of pFKey, then this index is a winner. */
119333
119334 if( zKey==0 ){
119335 /* If zKey is NULL, then this foreign key is implicitly mapped to
119336 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
119337 ** identified by the test. */
119338 if( IsPrimaryKeyIndex(pIdx) ){
119339 if( aiCol ){
119340 int i;
119341 for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
119342 }
119343 break;
119344 }
119345 }else{
119346 /* If zKey is non-NULL, then this foreign key was declared to
119347 ** map to an explicit list of columns in table pParent. Check if this
119348 ** index matches those columns. Also, check that the index uses
119349 ** the default collation sequences for each column. */
119350 int i, j;
119351 for(i=0; i<nCol; i++){
119352 i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
119353 const char *zDfltColl; /* Def. collation for column */
119354 char *zIdxCol; /* Name of indexed column */
119355
119356 if( iCol<0 ) break; /* No foreign keys against expression indexes */
119357
119358 /* If the index uses a collation sequence that is different from
119359 ** the default collation sequence for the column, this index is
119360 ** unusable. Bail out early in this case. */
119361 zDfltColl = pParent->aCol[iCol].zColl;
119362 if( !zDfltColl ) zDfltColl = sqlite3StrBINARY;
119363 if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;
119364
119365 zIdxCol = pParent->aCol[iCol].zName;
119366 for(j=0; j<nCol; j++){
119367 if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
119368 if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom;
119369 break;
119370 }
119371 }
119372 if( j==nCol ) break;
119373 }
119374 if( i==nCol ) break; /* pIdx is usable */
119375 }
119376 }
119377 }
119378
119379 if( !pIdx ){
119380 if( !pParse->disableTriggers ){
119381 sqlite3ErrorMsg(pParse,
119382 "foreign key mismatch - \"%w\" referencing \"%w\"",
119383 pFKey->pFrom->zName, pFKey->zTo);
119384 }
119385 sqlite3DbFree(pParse->db, aiCol);

References Table::aCol, FKey::aCol, Index::aiColumn, Index::azColl, Parse::db, Parse::disableTriggers, FKey::sColMap::iFrom, Table::iPKey, IsPrimaryKeyIndex, IsUniqueIndex, FKey::nCol, Index::nKeyCol, FKey::pFrom, Table::pIndex, Index::pNext, Index::pPartIdxWhere, sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3ErrorMsg(), sqlite3StrBINARY, sqlite3StrICmp(), FKey::sColMap::zCol, Column::zColl, Column::zName, Table::zName, and FKey::zTo.

Referenced by fkActionTrigger(), sqlite3FkCheck(), sqlite3FkOldmask(), and sqlite3Pragma().

◆ sqlite3FkOldmask()

SQLITE_PRIVATE u32 sqlite3FkOldmask ( Parse * pParse,
Table * pTab )

Definition at line 120168 of file sqlite3.c.

120168 : ((u32)1<<(x)))
120169
120170/*
120171** This function is called before generating code to update or delete a
120172** row contained in table pTab.
120173*/
120175 Parse *pParse, /* Parse context */
120176 Table *pTab /* Table being modified */
120177){
120178 u32 mask = 0;
120179 if( pParse->db->flags&SQLITE_ForeignKeys ){
120180 FKey *p;
120181 int i;
120182 for(p=pTab->pFKey; p; p=p->pNextFrom){
120183 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
120184 }
120185 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
120186 Index *pIdx = 0;
120187 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
120188 if( pIdx ){
120189 for(i=0; i<pIdx->nKeyCol; i++){
120190 assert( pIdx->aiColumn[i]>=0 );
120191 mask |= COLUMN_MASK(pIdx->aiColumn[i]);
#define COLUMN_MASK(x)
Definition sqlite3.c:120162
SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse *, Table *)
Definition sqlite3.c:120168

References FKey::aCol, Index::aiColumn, COLUMN_MASK, Parse::db, sqlite3::flags, FKey::sColMap::iFrom, mask, FKey::nCol, Index::nKeyCol, Table::pFKey, FKey::pNextFrom, FKey::pNextTo, sqlite3FkLocateIndex(), sqlite3FkReferences(), and SQLITE_ForeignKeys.

Referenced by sqlite3GenerateRowDelete(), and sqlite3Update().

◆ sqlite3FkReferences()

◆ sqlite3FkRequired()

SQLITE_PRIVATE int sqlite3FkRequired ( Parse * pParse,
Table * pTab,
int * aChange,
int chngRowid )

Definition at line 120216 of file sqlite3.c.

120227 {
120228 int eRet = 0;
120229 if( pParse->db->flags&SQLITE_ForeignKeys ){
120230 if( !aChange ){
120231 /* A DELETE operation. Foreign key processing is required if the
120232 ** table in question is either the child or parent table for any
120233 ** foreign key constraint. */
120234 eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
120235 }else{
120236 /* This is an UPDATE. Foreign key processing is only required if the
120237 ** operation modifies one or more child or parent key columns. */
120238 FKey *p;
120239
120240 /* Check if any child key columns are being modified. */
120241 for(p=pTab->pFKey; p; p=p->pNextFrom){
120242 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
120243 if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
120244 eRet = 1;
120245 }
120246 }
120247
120248 /* Check if any parent key columns are being modified. */
120249 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
120250 if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
120251 if( p->aAction[1]!=OE_None ) return 2;
120252 eRet = 1;

References FKey::aAction, Parse::db, fkChildIsModified(), fkParentIsModified(), sqlite3::flags, OE_None, Table::pFKey, FKey::pNextFrom, FKey::pNextTo, sqlite3_stricmp(), sqlite3FkReferences(), SQLITE_ForeignKeys, Table::zName, and FKey::zTo.

Referenced by sqlite3DeleteFrom(), sqlite3GenerateConstraintChecks(), sqlite3GenerateRowDelete(), and sqlite3Update().

◆ sqlite3FreeIndex()

SQLITE_PRIVATE void sqlite3FreeIndex ( sqlite3 * db,
Index * p )

Definition at line 110885 of file sqlite3.c.

110891 {
110892#ifndef SQLITE_OMIT_ANALYZE
110894#endif
110897 sqlite3DbFree(db, p->zColAff);
char * zColAff
Definition sqlite3.c:17781

Referenced by deleteTable(), sqlite3CreateIndex(), and sqlite3UnlinkAndDeleteIndex().

◆ sqlite3FunctionSearch()

SQLITE_PRIVATE FuncDef * sqlite3FunctionSearch ( int h,
const char * zFunc )

Definition at line 115870 of file sqlite3.c.

115879 {
115880 FuncDef *p;
115881 for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
FuncDef * a[SQLITE_FUNC_HASH_SZ]
Definition sqlite3.c:16761
FuncDef * pHash
Definition sqlite3.c:17105

Referenced by sqlite3FindFunction().

◆ sqlite3FunctionUsesThisSrc()

SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc ( Expr * pExpr,
SrcList * pSrcList )

Definition at line 105424 of file sqlite3.c.

105430 {
105431 Walker w;
105432 struct SrcCount cnt;
105433 assert( pExpr->op==TK_AGG_FUNCTION );
105434 memset(&w, 0, sizeof(w));
105437 w.u.pSrcCount = &cnt;
105438 cnt.pSrc = pSrcList;
105439 cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
105440 cnt.nThis = 0;
105441 cnt.nOther = 0;
105442 sqlite3WalkExprList(&w, pExpr->x.pList);
105443#ifndef SQLITE_OMIT_WINDOWFUNC
static int selectSrcCount(Walker *pWalker, Select *pSel)
Definition sqlite3.c:105380
static int exprSrcCount(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:105391

References SrcList::a, EP_WinFunc, ExprHasProperty, exprSrcCount(), SrcList::SrcList_item::iCursor, SrcCount::iSrcInner, SrcCount::nOther, SrcList::nSrc, SrcCount::nThis, Expr::op, Window::pFilter, Expr::pList, SrcCount::pSrc, Walker::pSrcCount, Expr::pWin, selectSrcCount(), sqlite3WalkExpr(), sqlite3WalkExprList(), TK_AGG_FUNCTION, Walker::u, Expr::x, Walker::xExprCallback, Walker::xSelectCallback, and Expr::y.

Referenced by resolveExprStep().

◆ sqlite3GenerateConstraintChecks()

SQLITE_PRIVATE void sqlite3GenerateConstraintChecks ( Parse * pParse,
Table * pTab,
int * aRegIdx,
int iDataCur,
int iIdxCur,
int regNewData,
int regOldData,
u8 pkChng,
u8 overrideError,
int ignoreDest,
int * pbMayReplace,
int * aiChng,
Upsert * pUpsert )

Definition at line 122039 of file sqlite3.c.

122059 {
122060 Vdbe *v; /* VDBE under constrution */
122061 Index *pIdx; /* Pointer to one of the indices */
122062 Index *pPk = 0; /* The PRIMARY KEY index */
122063 sqlite3 *db; /* Database connection */
122064 int i; /* loop counter */
122065 int ix; /* Index loop counter */
122066 int nCol; /* Number of columns */
122067 int onError; /* Conflict resolution strategy */
122068 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
122069 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
122070 Index *pUpIdx = 0; /* Index to which to apply the upsert */
122071 u8 isUpdate; /* True if this is an UPDATE operation */
122072 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
122073 int upsertBypass = 0; /* Address of Goto to bypass upsert subroutine */
122074 int upsertJump = 0; /* Address of Goto that jumps into upsert subroutine */
122075 int ipkTop = 0; /* Top of the IPK uniqueness check */
122076 int ipkBottom = 0; /* OP_Goto at the end of the IPK uniqueness check */
122077 /* Variables associated with retesting uniqueness constraints after
122078 ** replace triggers fire have run */
122079 int regTrigCnt; /* Register used to count replace trigger invocations */
122080 int addrRecheck = 0; /* Jump here to recheck all uniqueness constraints */
122081 int lblRecheckOk = 0; /* Each recheck jumps to this label if it passes */
122082 Trigger *pTrigger; /* List of DELETE triggers on the table pTab */
122083 int nReplaceTrig = 0; /* Number of replace triggers coded */
122084
122085 isUpdate = regOldData!=0;
122086 db = pParse->db;
122087 v = sqlite3GetVdbe(pParse);
122088 assert( v!=0 );
122089 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122090 nCol = pTab->nCol;
122091
122092 /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
122093 ** normal rowid tables. nPkField is the number of key fields in the
122094 ** pPk index or 1 for a rowid table. In other words, nPkField is the
122095 ** number of fields in the true primary key of the table. */
122096 if( HasRowid(pTab) ){
122097 pPk = 0;
122098 nPkField = 1;
122099 }else{
122100 pPk = sqlite3PrimaryKeyIndex(pTab);
122101 nPkField = pPk->nKeyCol;
122102 }
122103
122104 /* Record that this module has started */
122105 VdbeModuleComment((v, "BEGIN: GenCnstCks(%d,%d,%d,%d,%d)",
122106 iDataCur, iIdxCur, regNewData, regOldData, pkChng));
122107
122108 /* Test all NOT NULL constraints.
122109 */
122110 if( pTab->tabFlags & TF_HasNotNull ){
122111 int b2ndPass = 0; /* True if currently running 2nd pass */
122112 int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */
122113 int nGenerated = 0; /* Number of generated columns with NOT NULL */
122114 while(1){ /* Make 2 passes over columns. Exit loop via "break" */
122115 for(i=0; i<nCol; i++){
122116 int iReg; /* Register holding column value */
122117 Column *pCol = &pTab->aCol[i]; /* The column to check for NOT NULL */
122118 int isGenerated; /* non-zero if column is generated */
122119 onError = pCol->notNull;
122120 if( onError==OE_None ) continue; /* No NOT NULL on this column */
122121 if( i==pTab->iPKey ){
122122 continue; /* ROWID is never NULL */
122123 }
122124 isGenerated = pCol->colFlags & COLFLAG_GENERATED;
122125 if( isGenerated && !b2ndPass ){
122126 nGenerated++;
122127 continue; /* Generated columns processed on 2nd pass */
122128 }
122129 if( aiChng && aiChng[i]<0 && !isGenerated ){
122130 /* Do not check NOT NULL on columns that do not change */
122131 continue;
122132 }
122133 if( overrideError!=OE_Default ){
122134 onError = overrideError;
122135 }else if( onError==OE_Default ){
122136 onError = OE_Abort;
122137 }
122138 if( onError==OE_Replace ){
122139 if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
122140 || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */
122141 ){
122142 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
122143 testcase( pCol->colFlags & COLFLAG_STORED );
122145 onError = OE_Abort;
122146 }else{
122147 assert( !isGenerated );
122148 }
122149 }else if( b2ndPass && !isGenerated ){
122150 continue;
122151 }
122152 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
122153 || onError==OE_Ignore || onError==OE_Replace );
122154 testcase( i!=sqlite3TableColumnToStorage(pTab, i) );
122155 iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
122156 switch( onError ){
122157 case OE_Replace: {
122158 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg);
122159 VdbeCoverage(v);
122160 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
122161 nSeenReplace++;
122162 sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg);
122163 sqlite3VdbeJumpHere(v, addr1);
122164 break;
122165 }
122166 case OE_Abort:
122167 sqlite3MayAbort(pParse);
122168 /* no break */ deliberate_fall_through
122169 case OE_Rollback:
122170 case OE_Fail: {
122171 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
122172 pCol->zName);
122174 onError, iReg);
122177 VdbeCoverage(v);
122178 break;
122179 }
122180 default: {
122181 assert( onError==OE_Ignore );
122182 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest);
122183 VdbeCoverage(v);
122184 break;
122185 }
122186 } /* end switch(onError) */
122187 } /* end loop i over columns */
122188 if( nGenerated==0 && nSeenReplace==0 ){
122189 /* If there are no generated columns with NOT NULL constraints
122190 ** and no NOT NULL ON CONFLICT REPLACE constraints, then a single
122191 ** pass is sufficient */
122192 break;
122193 }
122194 if( b2ndPass ) break; /* Never need more than 2 passes */
122195 b2ndPass = 1;
122196#ifndef SQLITE_OMIT_GENERATED_COLUMNS
122197 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
122198 /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
122199 ** first pass, recomputed values for all generated columns, as
122200 ** those values might depend on columns affected by the REPLACE.
122201 */
122202 sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab);
122203 }
122204#endif
122205 } /* end of 2-pass loop */
122206 } /* end if( has-not-null-constraints ) */
122207
122208 /* Test all CHECK constraints
122209 */
122210#ifndef SQLITE_OMIT_CHECK
122211 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
122212 ExprList *pCheck = pTab->pCheck;
122213 pParse->iSelfTab = -(regNewData+1);
122214 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
122215 for(i=0; i<pCheck->nExpr; i++){
122216 int allOk;
122217 Expr *pCopy;
122218 Expr *pExpr = pCheck->a[i].pExpr;
122219 if( aiChng
122220 && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng)
122221 ){
122222 /* The check constraints do not reference any of the columns being
122223 ** updated so there is no point it verifying the check constraint */
122224 continue;
122225 }
122226 if( bAffinityDone==0 ){
122227 sqlite3TableAffinity(v, pTab, regNewData+1);
122228 bAffinityDone = 1;
122229 }
122230 allOk = sqlite3VdbeMakeLabel(pParse);
122231 sqlite3VdbeVerifyAbortable(v, onError);
122232 pCopy = sqlite3ExprDup(db, pExpr, 0);
122233 if( !db->mallocFailed ){
122234 sqlite3ExprIfTrue(pParse, pCopy, allOk, SQLITE_JUMPIFNULL);
122235 }
122236 sqlite3ExprDelete(db, pCopy);
122237 if( onError==OE_Ignore ){
122238 sqlite3VdbeGoto(v, ignoreDest);
122239 }else{
122240 char *zName = pCheck->a[i].zEName;
122241 if( zName==0 ) zName = pTab->zName;
122242 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */
122244 onError, zName, P4_TRANSIENT,
122246 }
122247 sqlite3VdbeResolveLabel(v, allOk);
122248 }
122249 pParse->iSelfTab = 0;
122250 }
122251#endif /* !defined(SQLITE_OMIT_CHECK) */
122252
122253 /* UNIQUE and PRIMARY KEY constraints should be handled in the following
122254 ** order:
122255 **
122256 ** (1) OE_Update
122257 ** (2) OE_Abort, OE_Fail, OE_Rollback, OE_Ignore
122258 ** (3) OE_Replace
122259 **
122260 ** OE_Fail and OE_Ignore must happen before any changes are made.
122261 ** OE_Update guarantees that only a single row will change, so it
122262 ** must happen before OE_Replace. Technically, OE_Abort and OE_Rollback
122263 ** could happen in any order, but they are grouped up front for
122264 ** convenience.
122265 **
122266 ** 2018-08-14: Ticket https://www.sqlite.org/src/info/908f001483982c43
122267 ** The order of constraints used to have OE_Update as (2) and OE_Abort
122268 ** and so forth as (1). But apparently PostgreSQL checks the OE_Update
122269 ** constraint before any others, so it had to be moved.
122270 **
122271 ** Constraint checking code is generated in this order:
122272 ** (A) The rowid constraint
122273 ** (B) Unique index constraints that do not have OE_Replace as their
122274 ** default conflict resolution strategy
122275 ** (C) Unique index that do use OE_Replace by default.
122276 **
122277 ** The ordering of (2) and (3) is accomplished by making sure the linked
122278 ** list of indexes attached to a table puts all OE_Replace indexes last
122279 ** in the list. See sqlite3CreateIndex() for where that happens.
122280 */
122281
122282 if( pUpsert ){
122283 if( pUpsert->pUpsertTarget==0 ){
122284 /* An ON CONFLICT DO NOTHING clause, without a constraint-target.
122285 ** Make all unique constraint resolution be OE_Ignore */
122286 assert( pUpsert->pUpsertSet==0 );
122287 overrideError = OE_Ignore;
122288 pUpsert = 0;
122289 }else if( (pUpIdx = pUpsert->pUpsertIdx)!=0 ){
122290 /* If the constraint-target uniqueness check must be run first.
122291 ** Jump to that uniqueness check now */
122292 upsertJump = sqlite3VdbeAddOp0(v, OP_Goto);
122293 VdbeComment((v, "UPSERT constraint goes first"));
122294 }
122295 }
122296
122297 /* Determine if it is possible that triggers (either explicitly coded
122298 ** triggers or FK resolution actions) might run as a result of deletes
122299 ** that happen when OE_Replace conflict resolution occurs. (Call these
122300 ** "replace triggers".) If any replace triggers run, we will need to
122301 ** recheck all of the uniqueness constraints after they have all run.
122302 ** But on the recheck, the resolution is OE_Abort instead of OE_Replace.
122303 **
122304 ** If replace triggers are a possibility, then
122305 **
122306 ** (1) Allocate register regTrigCnt and initialize it to zero.
122307 ** That register will count the number of replace triggers that
122308 ** fire. Constraint recheck only occurs if the number is positive.
122309 ** (2) Initialize pTrigger to the list of all DELETE triggers on pTab.
122310 ** (3) Initialize addrRecheck and lblRecheckOk
122311 **
122312 ** The uniqueness rechecking code will create a series of tests to run
122313 ** in a second pass. The addrRecheck and lblRecheckOk variables are
122314 ** used to link together these tests which are separated from each other
122315 ** in the generate bytecode.
122316 */
122317 if( (db->flags & (SQLITE_RecTriggers|SQLITE_ForeignKeys))==0 ){
122318 /* There are not DELETE triggers nor FK constraints. No constraint
122319 ** rechecks are needed. */
122320 pTrigger = 0;
122321 regTrigCnt = 0;
122322 }else{
122323 if( db->flags&SQLITE_RecTriggers ){
122324 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
122325 regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
122326 }else{
122327 pTrigger = 0;
122328 regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
122329 }
122330 if( regTrigCnt ){
122331 /* Replace triggers might exist. Allocate the counter and
122332 ** initialize it to zero. */
122333 regTrigCnt = ++pParse->nMem;
122334 sqlite3VdbeAddOp2(v, OP_Integer, 0, regTrigCnt);
122335 VdbeComment((v, "trigger count"));
122336 lblRecheckOk = sqlite3VdbeMakeLabel(pParse);
122337 addrRecheck = lblRecheckOk;
122338 }
122339 }
122340
122341 /* If rowid is changing, make sure the new rowid does not previously
122342 ** exist in the table.
122343 */
122344 if( pkChng && pPk==0 ){
122345 int addrRowidOk = sqlite3VdbeMakeLabel(pParse);
122346
122347 /* Figure out what action to take in case of a rowid collision */
122348 onError = pTab->keyConf;
122349 if( overrideError!=OE_Default ){
122350 onError = overrideError;
122351 }else if( onError==OE_Default ){
122352 onError = OE_Abort;
122353 }
122354
122355 /* figure out whether or not upsert applies in this case */
122356 if( pUpsert && pUpsert->pUpsertIdx==0 ){
122357 if( pUpsert->pUpsertSet==0 ){
122358 onError = OE_Ignore; /* DO NOTHING is the same as INSERT OR IGNORE */
122359 }else{
122360 onError = OE_Update; /* DO UPDATE */
122361 }
122362 }
122363
122364 /* If the response to a rowid conflict is REPLACE but the response
122365 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
122366 ** to defer the running of the rowid conflict checking until after
122367 ** the UNIQUE constraints have run.
122368 */
122369 if( onError==OE_Replace /* IPK rule is REPLACE */
122370 && onError!=overrideError /* Rules for other contraints are different */
122371 && pTab->pIndex /* There exist other constraints */
122372 ){
122373 ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
122374 VdbeComment((v, "defer IPK REPLACE until last"));
122375 }
122376
122377 if( isUpdate ){
122378 /* pkChng!=0 does not mean that the rowid has changed, only that
122379 ** it might have changed. Skip the conflict logic below if the rowid
122380 ** is unchanged. */
122381 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
122383 VdbeCoverage(v);
122384 }
122385
122386 /* Check to see if the new rowid already exists in the table. Skip
122387 ** the following conflict logic if it does not. */
122388 VdbeNoopComment((v, "uniqueness check for ROWID"));
122389 sqlite3VdbeVerifyAbortable(v, onError);
122390 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
122391 VdbeCoverage(v);
122392
122393 switch( onError ){
122394 default: {
122395 onError = OE_Abort;
122396 /* no break */ deliberate_fall_through
122397 }
122398 case OE_Rollback:
122399 case OE_Abort:
122400 case OE_Fail: {
122401 testcase( onError==OE_Rollback );
122402 testcase( onError==OE_Abort );
122403 testcase( onError==OE_Fail );
122404 sqlite3RowidConstraint(pParse, onError, pTab);
122405 break;
122406 }
122407 case OE_Replace: {
122408 /* If there are DELETE triggers on this table and the
122409 ** recursive-triggers flag is set, call GenerateRowDelete() to
122410 ** remove the conflicting row from the table. This will fire
122411 ** the triggers and remove both the table and index b-tree entries.
122412 **
122413 ** Otherwise, if there are no triggers or the recursive-triggers
122414 ** flag is not set, but the table has one or more indexes, call
122415 ** GenerateRowIndexDelete(). This removes the index b-tree entries
122416 ** only. The table b-tree entry will be replaced by the new entry
122417 ** when it is inserted.
122418 **
122419 ** If either GenerateRowDelete() or GenerateRowIndexDelete() is called,
122420 ** also invoke MultiWrite() to indicate that this VDBE may require
122421 ** statement rollback (if the statement is aborted after the delete
122422 ** takes place). Earlier versions called sqlite3MultiWrite() regardless,
122423 ** but being more selective here allows statements like:
122424 **
122425 ** REPLACE INTO t(rowid) VALUES($newrowid)
122426 **
122427 ** to run without a statement journal if there are no indexes on the
122428 ** table.
122429 */
122430 if( regTrigCnt ){
122431 sqlite3MultiWrite(pParse);
122432 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
122433 regNewData, 1, 0, OE_Replace, 1, -1);
122434 sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
122435 nReplaceTrig++;
122436 }else{
122437#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
122438 assert( HasRowid(pTab) );
122439 /* This OP_Delete opcode fires the pre-update-hook only. It does
122440 ** not modify the b-tree. It is more efficient to let the coming
122441 ** OP_Insert replace the existing entry than it is to delete the
122442 ** existing entry and then insert a new one. */
122444 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
122445#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
122446 if( pTab->pIndex ){
122447 sqlite3MultiWrite(pParse);
122448 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
122449 }
122450 }
122451 seenReplace = 1;
122452 break;
122453 }
122454#ifndef SQLITE_OMIT_UPSERT
122455 case OE_Update: {
122456 sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur);
122457 /* no break */ deliberate_fall_through
122458 }
122459#endif
122460 case OE_Ignore: {
122461 testcase( onError==OE_Ignore );
122462 sqlite3VdbeGoto(v, ignoreDest);
122463 break;
122464 }
122465 }
122466 sqlite3VdbeResolveLabel(v, addrRowidOk);
122467 if( ipkTop ){
122468 ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
122469 sqlite3VdbeJumpHere(v, ipkTop-1);
122470 }
122471 }
122472
122473 /* Test all UNIQUE constraints by creating entries for each UNIQUE
122474 ** index and making sure that duplicate entries do not already exist.
122475 ** Compute the revised record entries for indices as we go.
122476 **
122477 ** This loop also handles the case of the PRIMARY KEY index for a
122478 ** WITHOUT ROWID table.
122479 */
122480 for(ix=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, ix++){
122481 int regIdx; /* Range of registers hold conent for pIdx */
122482 int regR; /* Range of registers holding conflicting PK */
122483 int iThisCur; /* Cursor for this UNIQUE index */
122484 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
122485 int addrConflictCk; /* First opcode in the conflict check logic */
122486
122487 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
122488 if( pUpIdx==pIdx ){
122489 addrUniqueOk = upsertJump+1;
122490 upsertBypass = sqlite3VdbeGoto(v, 0);
122491 VdbeComment((v, "Skip upsert subroutine"));
122492 sqlite3VdbeJumpHere(v, upsertJump);
122493 }else{
122494 addrUniqueOk = sqlite3VdbeMakeLabel(pParse);
122495 }
122496 if( bAffinityDone==0 && (pUpIdx==0 || pUpIdx==pIdx) ){
122497 sqlite3TableAffinity(v, pTab, regNewData+1);
122498 bAffinityDone = 1;
122499 }
122500 VdbeNoopComment((v, "prep index %s", pIdx->zName));
122501 iThisCur = iIdxCur+ix;
122502
122503
122504 /* Skip partial indices for which the WHERE clause is not true */
122505 if( pIdx->pPartIdxWhere ){
122506 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
122507 pParse->iSelfTab = -(regNewData+1);
122508 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
122510 pParse->iSelfTab = 0;
122511 }
122512
122513 /* Create a record for this index entry as it should appear after
122514 ** the insert or update. Store that record in the aRegIdx[ix] register
122515 */
122516 regIdx = aRegIdx[ix]+1;
122517 for(i=0; i<pIdx->nColumn; i++){
122518 int iField = pIdx->aiColumn[i];
122519 int x;
122520 if( iField==XN_EXPR ){
122521 pParse->iSelfTab = -(regNewData+1);
122522 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
122523 pParse->iSelfTab = 0;
122524 VdbeComment((v, "%s column %d", pIdx->zName, i));
122525 }else if( iField==XN_ROWID || iField==pTab->iPKey ){
122526 x = regNewData;
122527 sqlite3VdbeAddOp2(v, OP_IntCopy, x, regIdx+i);
122528 VdbeComment((v, "rowid"));
122529 }else{
122530 testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField );
122531 x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1;
122532 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
122533 VdbeComment((v, "%s", pTab->aCol[iField].zName));
122534 }
122535 }
122536 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
122537 VdbeComment((v, "for %s", pIdx->zName));
122538#ifdef SQLITE_ENABLE_NULL_TRIM
122539 if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
122540 sqlite3SetMakeRecordP5(v, pIdx->pTable);
122541 }
122542#endif
122543 sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
122544
122545 /* In an UPDATE operation, if this index is the PRIMARY KEY index
122546 ** of a WITHOUT ROWID table and there has been no change the
122547 ** primary key, then no collision is possible. The collision detection
122548 ** logic below can all be skipped. */
122549 if( isUpdate && pPk==pIdx && pkChng==0 ){
122550 sqlite3VdbeResolveLabel(v, addrUniqueOk);
122551 continue;
122552 }
122553
122554 /* Find out what action to take in case there is a uniqueness conflict */
122555 onError = pIdx->onError;
122556 if( onError==OE_None ){
122557 sqlite3VdbeResolveLabel(v, addrUniqueOk);
122558 continue; /* pIdx is not a UNIQUE index */
122559 }
122560 if( overrideError!=OE_Default ){
122561 onError = overrideError;
122562 }else if( onError==OE_Default ){
122563 onError = OE_Abort;
122564 }
122565
122566 /* Figure out if the upsert clause applies to this index */
122567 if( pUpIdx==pIdx ){
122568 if( pUpsert->pUpsertSet==0 ){
122569 onError = OE_Ignore; /* DO NOTHING is the same as INSERT OR IGNORE */
122570 }else{
122571 onError = OE_Update; /* DO UPDATE */
122572 }
122573 }
122574
122575 /* Collision detection may be omitted if all of the following are true:
122576 ** (1) The conflict resolution algorithm is REPLACE
122577 ** (2) The table is a WITHOUT ROWID table
122578 ** (3) There are no secondary indexes on the table
122579 ** (4) No delete triggers need to be fired if there is a conflict
122580 ** (5) No FK constraint counters need to be updated if a conflict occurs.
122581 **
122582 ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
122583 ** must be explicitly deleted in order to ensure any pre-update hook
122584 ** is invoked. */
122585#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
122586 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
122587 && pPk==pIdx /* Condition 2 */
122588 && onError==OE_Replace /* Condition 1 */
122589 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
122590 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
122591 && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
122592 (0==pTab->pFKey && 0==sqlite3FkReferences(pTab)))
122593 ){
122594 sqlite3VdbeResolveLabel(v, addrUniqueOk);
122595 continue;
122596 }
122597#endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */
122598
122599 /* Check to see if the new index entry will be unique */
122600 sqlite3VdbeVerifyAbortable(v, onError);
122601 addrConflictCk =
122602 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
122603 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
122604
122605 /* Generate code to handle collisions */
122606 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
122607 if( isUpdate || onError==OE_Replace ){
122608 if( HasRowid(pTab) ){
122609 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
122610 /* Conflict only if the rowid of the existing index entry
122611 ** is different from old-rowid */
122612 if( isUpdate ){
122613 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
122615 VdbeCoverage(v);
122616 }
122617 }else{
122618 int x;
122619 /* Extract the PRIMARY KEY from the end of the index entry and
122620 ** store it in registers regR..regR+nPk-1 */
122621 if( pIdx!=pPk ){
122622 for(i=0; i<pPk->nKeyCol; i++){
122623 assert( pPk->aiColumn[i]>=0 );
122624 x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
122625 sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
122626 VdbeComment((v, "%s.%s", pTab->zName,
122627 pTab->aCol[pPk->aiColumn[i]].zName));
122628 }
122629 }
122630 if( isUpdate ){
122631 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
122632 ** table, only conflict if the new PRIMARY KEY values are actually
122633 ** different from the old.
122634 **
122635 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
122636 ** of the matched index row are different from the original PRIMARY
122637 ** KEY values of this row before the update. */
122638 int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
122639 int op = OP_Ne;
122640 int regCmp = (IsPrimaryKeyIndex(pIdx) ? regIdx : regR);
122641
122642 for(i=0; i<pPk->nKeyCol; i++){
122643 char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
122644 x = pPk->aiColumn[i];
122645 assert( x>=0 );
122646 if( i==(pPk->nKeyCol-1) ){
122647 addrJump = addrUniqueOk;
122648 op = OP_Eq;
122649 }
122650 x = sqlite3TableColumnToStorage(pTab, x);
122651 sqlite3VdbeAddOp4(v, op,
122652 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
122653 );
122655 VdbeCoverageIf(v, op==OP_Eq);
122656 VdbeCoverageIf(v, op==OP_Ne);
122657 }
122658 }
122659 }
122660 }
122661
122662 /* Generate code that executes if the new index entry is not unique */
122663 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
122664 || onError==OE_Ignore || onError==OE_Replace || onError==OE_Update );
122665 switch( onError ){
122666 case OE_Rollback:
122667 case OE_Abort:
122668 case OE_Fail: {
122669 testcase( onError==OE_Rollback );
122670 testcase( onError==OE_Abort );
122671 testcase( onError==OE_Fail );
122672 sqlite3UniqueConstraint(pParse, onError, pIdx);
122673 break;
122674 }
122675#ifndef SQLITE_OMIT_UPSERT
122676 case OE_Update: {
122677 sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, pIdx, iIdxCur+ix);
122678 /* no break */ deliberate_fall_through
122679 }
122680#endif
122681 case OE_Ignore: {
122682 testcase( onError==OE_Ignore );
122683 sqlite3VdbeGoto(v, ignoreDest);
122684 break;
122685 }
122686 default: {
122687 int nConflictCk; /* Number of opcodes in conflict check logic */
122688
122689 assert( onError==OE_Replace );
122690 nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
122691 assert( nConflictCk>0 );
122692 testcase( nConflictCk>1 );
122693 if( regTrigCnt ){
122694 sqlite3MultiWrite(pParse);
122695 nReplaceTrig++;
122696 }
122697 if( pTrigger && isUpdate ){
122698 sqlite3VdbeAddOp1(v, OP_CursorLock, iDataCur);
122699 }
122700 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
122701 regR, nPkField, 0, OE_Replace,
122702 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
122703 if( pTrigger && isUpdate ){
122704 sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur);
122705 }
122706 if( regTrigCnt ){
122707 int addrBypass; /* Jump destination to bypass recheck logic */
122708
122709 sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
122710 addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
122711 VdbeComment((v, "bypass recheck"));
122712
122713 /* Here we insert code that will be invoked after all constraint
122714 ** checks have run, if and only if one or more replace triggers
122715 ** fired. */
122716 sqlite3VdbeResolveLabel(v, lblRecheckOk);
122717 lblRecheckOk = sqlite3VdbeMakeLabel(pParse);
122718 if( pIdx->pPartIdxWhere ){
122719 /* Bypass the recheck if this partial index is not defined
122720 ** for the current row */
122721 sqlite3VdbeAddOp2(v, OP_IsNull, regIdx-1, lblRecheckOk);
122722 VdbeCoverage(v);
122723 }
122724 /* Copy the constraint check code from above, except change
122725 ** the constraint-ok jump destination to be the address of
122726 ** the next retest block */
122727 while( nConflictCk>0 ){
122728 VdbeOp x; /* Conflict check opcode to copy */
122729 /* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
122730 ** Hence, make a complete copy of the opcode, rather than using
122731 ** a pointer to the opcode. */
122732 x = *sqlite3VdbeGetOp(v, addrConflictCk);
122733 if( x.opcode!=OP_IdxRowid ){
122734 int p2; /* New P2 value for copied conflict check opcode */
122735 const char *zP4;
122737 p2 = lblRecheckOk;
122738 }else{
122739 p2 = x.p2;
122740 }
122741 zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
122742 sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
122743 sqlite3VdbeChangeP5(v, x.p5);
122744 VdbeCoverageIf(v, p2!=x.p2);
122745 }
122746 nConflictCk--;
122747 addrConflictCk++;
122748 }
122749 /* If the retest fails, issue an abort */
122750 sqlite3UniqueConstraint(pParse, OE_Abort, pIdx);
122751
122752 sqlite3VdbeJumpHere(v, addrBypass); /* Terminate the recheck bypass */
122753 }
122754 seenReplace = 1;
122755 break;
122756 }
122757 }
122758 if( pUpIdx==pIdx ){
122759 sqlite3VdbeGoto(v, upsertJump+1);
122760 sqlite3VdbeJumpHere(v, upsertBypass);
122761 }else{
122762 sqlite3VdbeResolveLabel(v, addrUniqueOk);
122763 }
122764 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
122765 }
122766
122767 /* If the IPK constraint is a REPLACE, run it last */
122768 if( ipkTop ){
122769 sqlite3VdbeGoto(v, ipkTop);
122770 VdbeComment((v, "Do IPK REPLACE"));
122771 sqlite3VdbeJumpHere(v, ipkBottom);
122772 }
122773
122774 /* Recheck all uniqueness constraints after replace triggers have run */
122775 testcase( regTrigCnt!=0 && nReplaceTrig==0 );
122776 assert( regTrigCnt!=0 || nReplaceTrig==0 );
122777 if( nReplaceTrig ){
122778 sqlite3VdbeAddOp2(v, OP_IfNot, regTrigCnt, lblRecheckOk);VdbeCoverage(v);
122779 if( !pPk ){
122780 if( isUpdate ){
122781 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRecheck, regOldData);
122783 VdbeCoverage(v);
122784 }
122785 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRecheck, regNewData);
122786 VdbeCoverage(v);
122787 sqlite3RowidConstraint(pParse, OE_Abort, pTab);
122788 }else{
122789 sqlite3VdbeGoto(v, addrRecheck);
122790 }
122791 sqlite3VdbeResolveLabel(v, lblRecheckOk);
122792 }
122793
122794 /* Generate the table record */
122795 if( HasRowid(pTab) ){
122796 int regRec = aRegIdx[ix];
122797 sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, pTab->nNVCol, regRec);
122798 sqlite3SetMakeRecordP5(v, pTab);
122799 if( !bAffinityDone ){
122800 sqlite3TableAffinity(v, pTab, 0);
#define OP_IntCopy
Definition sqlite3.c:15645
#define OP_NoConflict
Definition sqlite3.c:15594
#define sqlite3SetMakeRecordP5(A, B)
Definition sqlite3.c:19732
#define OP_CursorLock
Definition sqlite3.c:15725
SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse *, int, Index *)
Definition sqlite3.c:115234
#define SQLITE_CONSTRAINT_NOTNULL
Definition sqlite3.c:1580
#define OE_Update
Definition sqlite3.c:17662
#define VdbeModuleComment(X)
Definition sqlite3.c:15935
SQLITE_PRIVATE void sqlite3UpsertDoUpdate(Parse *, Upsert *, Table *, Index *, int)
Definition sqlite3.c:139099
#define SQLITE_IgnoreChecks
Definition sqlite3.c:16988
#define OP_CursorUnlock
Definition sqlite3.c:15726
#define P5_ConstraintCheck
Definition sqlite3.c:15529
#define P5_ConstraintNotNull
Definition sqlite3.c:15527
SQLITE_PRIVATE void sqlite3RowidConstraint(Parse *, int, Table *)
Definition sqlite3.c:115270
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse *, Table *, int, int, int *, int)
Definition sqlite3.c:116908
#define OP_HaltIfNull
Definition sqlite3.c:15633
SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse *, Expr *, int, int)
Definition sqlite3.c:104867
SQLITE_PRIVATE void sqlite3ComputeGeneratedColumns(Parse *, int, Table *)
Definition sqlite3.c:120770
#define SQLITE_CONSTRAINT_CHECK
Definition sqlite3.c:1576
Index * pUpsertIdx
Definition sqlite3.c:18415

References ExprList::a, Table::aCol, Index::aColExpr, Index::aiColumn, Index::azColl, COLFLAG_GENERATED, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, deliberate_fall_through, sqlite3::flags, HasRowid, VdbeOp::p4union::i, Index::idxType, Table::iPKey, Parse::iSelfTab, IsPrimaryKeyIndex, Table::keyConf, sqlite3::mallocFailed, Table::nCol, Index::nColumn, ExprList::nExpr, Index::nKeyCol, Parse::nMem, Table::nNVCol, Column::notNull, OE_Abort, OE_Default, OE_Fail, OE_Ignore, OE_None, OE_Replace, OE_Rollback, OE_Update, ONEPASS_OFF, ONEPASS_SINGLE, Index::onError, OP_AddImm, OP_Column, OP_CursorLock, OP_CursorUnlock, OP_Delete, OP_Eq, OP_Goto, OP_HaltIfNull, OP_IdxRowid, OP_IfNot, OP_IntCopy, OP_Integer, OP_IsNull, OP_MakeRecord, OP_Ne, OP_NoConflict, OP_NotExists, OP_NotNull, OP_Null, OP_SCopy, VdbeOp::opcode, OPFLAG_ISNOOP, OPFLG_JUMP, VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, VdbeOp::p4, P4_COLLSEQ, P4_DYNAMIC, P4_INT32, P4_TABLE, P4_TRANSIENT, VdbeOp::p4type, VdbeOp::p5, P5_ConstraintCheck, P5_ConstraintNotNull, Table::pCheck, Column::pDflt, ExprList::ExprList_item::pExpr, Table::pFKey, Table::pIndex, Index::pNext, Index::pPartIdxWhere, Table::pSelect, Index::pTable, Upsert::pUpsertIdx, Upsert::pUpsertSet, Upsert::pUpsertTarget, sqlite3ComputeGeneratedColumns(), sqlite3ExprCodeCopy(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprIfFalseDup(), sqlite3ExprIfTrue(), sqlite3ExprReferencesUpdatedColumn(), sqlite3FkReferences(), sqlite3FkRequired(), sqlite3GenerateRowDelete(), sqlite3GenerateRowIndexDelete(), sqlite3GetTempRange(), sqlite3GetVdbe(), sqlite3HaltConstraint(), sqlite3LocateCollSeq(), sqlite3MayAbort(), sqlite3MPrintf(), sqlite3MultiWrite(), sqlite3OpcodeProperty, sqlite3PrimaryKeyIndex(), sqlite3ReleaseTempRange(), sqlite3RowidConstraint(), sqlite3SetMakeRecordP5, sqlite3TableAffinity(), sqlite3TableColumnToIndex(), sqlite3TableColumnToStorage(), sqlite3TriggersExist(), sqlite3UniqueConstraint(), sqlite3UpsertDoUpdate(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetOp(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeReleaseRegisters, sqlite3VdbeResolveLabel(), sqlite3VdbeVerifyAbortable, SQLITE_CONSTRAINT_CHECK, SQLITE_CONSTRAINT_NOTNULL, SQLITE_ForeignKeys, SQLITE_IDXTYPE_PRIMARYKEY, SQLITE_IgnoreChecks, SQLITE_INT_TO_PTR, SQLITE_JUMPIFNULL, SQLITE_NOTNULL, SQLITE_RecTriggers, Table::tabFlags, testcase, TF_HasGenerated, TF_HasNotNull, TK_DELETE, VdbeComment, VdbeCoverage, VdbeCoverageIf, VdbeModuleComment, VdbeNoopComment, XN_EXPR, XN_ROWID, VdbeOp::p4union::z, ExprList::ExprList_item::zEName, Column::zName, Table::zName, Index::zName, and zName.

Referenced by sqlite3Insert(), and sqlite3Update().

◆ sqlite3GenerateIndexKey()

SQLITE_PRIVATE int sqlite3GenerateIndexKey ( Parse * pParse,
Index * pIdx,
int iDataCur,
int regOut,
int prefixOnly,
int * piPartIdxLabel,
Index * pPrior,
int regPrior )

Definition at line 116973 of file sqlite3.c.

116988 {
116989 Vdbe *v = pParse->pVdbe;
116990 int j;
116991 int regBase;
116992 int nCol;
116993
116994 if( piPartIdxLabel ){
116995 if( pIdx->pPartIdxWhere ){
116996 *piPartIdxLabel = sqlite3VdbeMakeLabel(pParse);
116997 pParse->iSelfTab = iDataCur + 1;
116998 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
117000 pParse->iSelfTab = 0;
117001 pPrior = 0; /* Ticket a9efb42811fa41ee 2019-11-02;
117002 ** pPartIdxWhere may have corrupted regPrior registers */
117003 }else{
117004 *piPartIdxLabel = 0;
117005 }
117006 }
117007 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
117008 regBase = sqlite3GetTempRange(pParse, nCol);
117009 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
117010 for(j=0; j<nCol; j++){
117011 if( pPrior
117012 && pPrior->aiColumn[j]==pIdx->aiColumn[j]
117013 && pPrior->aiColumn[j]!=XN_EXPR
117014 ){
117015 /* This column was already computed by the previous index */
117016 continue;
117017 }
117018 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
117019 /* If the column affinity is REAL but the number is an integer, then it
117020 ** might be stored in the table as an integer (using a compact
117021 ** representation) then converted to REAL by an OP_RealAffinity opcode.
117022 ** But we are getting ready to store this value back into an index, where
117023 ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
117024 ** opcode if it is present */
117026 }
117027 if( regOut ){
117028 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
117029 if( pIdx->pTable->pSelect ){
117030 const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx);
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *, u8 op)
Definition sqlite3.c:78949

References Index::aiColumn, Parse::db, Parse::iSelfTab, Index::nColumn, Index::nKeyCol, OP_MakeRecord, OP_RealAffinity, P4_TRANSIENT, Index::pPartIdxWhere, Table::pSelect, Index::pTable, Parse::pVdbe, sqlite3ExprCodeLoadIndexColumn(), sqlite3ExprIfFalseDup(), sqlite3GetTempRange(), sqlite3IndexAffinityStr(), sqlite3ReleaseTempRange(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP4(), sqlite3VdbeDeletePriorOpcode(), sqlite3VdbeMakeLabel(), SQLITE_JUMPIFNULL, Index::uniqNotNull, and XN_EXPR.

Referenced by constructAutomaticIndex(), sqlite3GenerateRowIndexDelete(), sqlite3Pragma(), and sqlite3RefillIndex().

◆ sqlite3GenerateRowDelete()

SQLITE_PRIVATE void sqlite3GenerateRowDelete ( Parse * pParse,
Table * pTab,
Trigger * pTrigger,
int iDataCur,
int iIdxCur,
int iPk,
i16 nPk,
u8 count,
u8 onconf,
u8 eMode,
int iIdxNoSeek )

Definition at line 116756 of file sqlite3.c.

116774 {
116775 Vdbe *v = pParse->pVdbe; /* Vdbe */
116776 int iOld = 0; /* First register in OLD.* array */
116777 int iLabel; /* Label resolved to end of generated code */
116778 u8 opSeek; /* Seek opcode */
116779
116780 /* Vdbe is guaranteed to have been allocated by this stage. */
116781 assert( v );
116782 VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
116783 iDataCur, iIdxCur, iPk, (int)nPk));
116784
116785 /* Seek cursor iCur to the row to delete. If this row no longer exists
116786 ** (this can happen if a trigger program has already deleted it), do
116787 ** not attempt to delete it or fire any DELETE triggers. */
116788 iLabel = sqlite3VdbeMakeLabel(pParse);
116789 opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
116790 if( eMode==ONEPASS_OFF ){
116791 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
116792 VdbeCoverageIf(v, opSeek==OP_NotExists);
116793 VdbeCoverageIf(v, opSeek==OP_NotFound);
116794 }
116795
116796 /* If there are any triggers to fire, allocate a range of registers to
116797 ** use for the old.* references in the triggers. */
116798 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
116799 u32 mask; /* Mask of OLD.* columns in use */
116800 int iCol; /* Iterator used while populating OLD.* */
116801 int addrStart; /* Start of BEFORE trigger programs */
116802
116803 /* TODO: Could use temporary registers here. Also could attempt to
116804 ** avoid copying the contents of the rowid register. */
116806 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
116807 );
116808 mask |= sqlite3FkOldmask(pParse, pTab);
116809 iOld = pParse->nMem+1;
116810 pParse->nMem += (1 + pTab->nCol);
116811
116812 /* Populate the OLD.* pseudo-table register array. These values will be
116813 ** used by any BEFORE and AFTER triggers that exist. */
116814 sqlite3VdbeAddOp2(v, OP_Copy, iPk, iOld);
116815 for(iCol=0; iCol<pTab->nCol; iCol++){
116816 testcase( mask!=0xffffffff && iCol==31 );
116817 testcase( mask!=0xffffffff && iCol==32 );
116818 if( mask==0xffffffff || (iCol<=31 && (mask & MASKBIT32(iCol))!=0) ){
116819 int kk = sqlite3TableColumnToStorage(pTab, iCol);
116820 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+kk+1);
116821 }
116822 }
116823
116824 /* Invoke BEFORE DELETE trigger programs. */
116825 addrStart = sqlite3VdbeCurrentAddr(v);
116826 sqlite3CodeRowTrigger(pParse, pTrigger,
116827 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
116828 );
116829
116830 /* If any BEFORE triggers were coded, then seek the cursor to the
116831 ** row to be deleted again. It may be that the BEFORE triggers moved
116832 ** the cursor or already deleted the row that the cursor was
116833 ** pointing to.
116834 **
116835 ** Also disable the iIdxNoSeek optimization since the BEFORE trigger
116836 ** may have moved that cursor.
116837 */
116838 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
116839 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
116840 VdbeCoverageIf(v, opSeek==OP_NotExists);
116841 VdbeCoverageIf(v, opSeek==OP_NotFound);
116842 testcase( iIdxNoSeek>=0 );
116843 iIdxNoSeek = -1;
116844 }
116845
116846 /* Do FK processing. This call checks that any FK constraints that
116847 ** refer to this table (i.e. constraints attached to other tables)
116848 ** are not violated by deleting this row. */
116849 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
116850 }
116851
116852 /* Delete the index and table entries. Skip this step if pTab is really
116853 ** a view (in which case the only effect of the DELETE statement is to
116854 ** fire the INSTEAD OF triggers).
116855 **
116856 ** If variable 'count' is non-zero, then this OP_Delete instruction should
116857 ** invoke the update-hook. The pre-update-hook, on the other hand should
116858 ** be invoked unless table pTab is a system table. The difference is that
116859 ** the update-hook is not invoked for rows removed by REPLACE, but the
116860 ** pre-update-hook is.
116861 */
116862 if( pTab->pSelect==0 ){
116863 u8 p5 = 0;
116864 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
116865 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
116866 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
116867 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
116868 }
116869 if( eMode!=ONEPASS_OFF ){
116871 }
116872 if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
116873 sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
116874 }
116875 if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
116876 sqlite3VdbeChangeP5(v, p5);
116877 }
116878
116879 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
116880 ** handle rows (possibly in other tables) that refer via a foreign key
116881 ** to the row just deleted. */
116882 sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
116883
116884 /* Invoke AFTER DELETE trigger programs. */
116885 sqlite3CodeRowTrigger(pParse, pTrigger,
116886 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
116887 );
116888
#define OPFLAG_AUXDELETE
Definition sqlite3.c:18853
SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse *, Trigger *, int, ExprList *, int, Table *, int, int, int)
Definition sqlite3.c:137501
SQLITE_PRIVATE void sqlite3FkActions(Parse *, Table *, ExprList *, int, int *, int)
Definition sqlite3.c:120475
SQLITE_PRIVATE void sqlite3FkCheck(Parse *, Table *, int, int, int *, int)
Definition sqlite3.c:119966
SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse *, Trigger *, ExprList *, int, int, Table *, int)
Definition sqlite3.c:137563

References HasRowid, mask, MASKBIT32, Table::nCol, Parse::nested, Parse::nMem, ONEPASS_MULTI, ONEPASS_OFF, OP_Copy, OP_Delete, OP_NotExists, OP_NotFound, OPFLAG_AUXDELETE, OPFLAG_NCHANGE, OPFLAG_SAVEPOSITION, P4_TABLE, Table::pSelect, Parse::pVdbe, sqlite3_stricmp(), sqlite3CodeRowTrigger(), sqlite3ExprCodeGetColumnOfTable(), sqlite3FkActions(), sqlite3FkCheck(), sqlite3FkOldmask(), sqlite3FkRequired(), sqlite3GenerateRowIndexDelete(), sqlite3TableColumnToStorage(), sqlite3TriggerColmask(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), testcase, TK_DELETE, TRIGGER_AFTER, TRIGGER_BEFORE, VdbeCoverageIf, VdbeModuleComment, and Table::zName.

Referenced by sqlite3DeleteFrom(), and sqlite3GenerateConstraintChecks().

◆ sqlite3GenerateRowIndexDelete()

SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete ( Parse * pParse,
Table * pTab,
int iDataCur,
int iIdxCur,
int * aRegIdx,
int iIdxNoSeek )

Definition at line 116908 of file sqlite3.c.

116921 {
116922 int i; /* Index loop counter */
116923 int r1 = -1; /* Register holding an index key */
116924 int iPartIdxLabel; /* Jump destination for skipping partial index entries */
116925 Index *pIdx; /* Current index */
116926 Index *pPrior = 0; /* Prior index */
116927 Vdbe *v; /* The prepared statement under construction */
116928 Index *pPk; /* PRIMARY KEY index, or NULL for rowid tables */
116929
116930 v = pParse->pVdbe;
116931 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
116932 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
116933 assert( iIdxCur+i!=iDataCur || pPk==pIdx );
116934 if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
116935 if( pIdx==pPk ) continue;
116936 if( iIdxCur+i==iIdxNoSeek ) continue;
116937 VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
116938 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
116939 &iPartIdxLabel, pPrior, r1);
116940 sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1,

References HasRowid, Index::nColumn, Index::nKeyCol, OP_IdxDelete, Table::pIndex, Index::pNext, Parse::pVdbe, sqlite3GenerateIndexKey(), sqlite3PrimaryKeyIndex(), sqlite3ResolvePartIdxLabel(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP5(), Index::uniqNotNull, VdbeModuleComment, and Index::zName.

Referenced by sqlite3GenerateConstraintChecks(), sqlite3GenerateRowDelete(), and sqlite3Update().

◆ sqlite3Get4byte()

SQLITE_PRIVATE u32 sqlite3Get4byte ( const u8 * p)

Definition at line 32440 of file sqlite3.c.

32446 {
32447#if SQLITE_BYTEORDER==4321
32448 u32 x;
32449 memcpy(&x,p,4);
32450 return x;
32451#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
32452 u32 x;
32453 memcpy(&x,p,4);
32454 return __builtin_bswap32(x);
32455#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
32456 u32 x;
32457 memcpy(&x,p,4);

Referenced by pager_write_changecounter(), read32bits(), walDecodeFrame(), walIndexRecover(), walRestartHdr(), and walRewriteChecksums().

◆ sqlite3GetBoolean()

SQLITE_PRIVATE u8 sqlite3GetBoolean ( const char * z,
u8 dflt )

Definition at line 125808 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ sqlite3GetCollSeq()

SQLITE_PRIVATE CollSeq * sqlite3GetCollSeq ( Parse * pParse,
u8 enc,
CollSeq * pColl,
const char * zName )

Definition at line 115740 of file sqlite3.c.

115745*/
115747 Parse *pParse, /* Parsing context */
115748 u8 enc, /* The desired encoding for the collating sequence */
115749 CollSeq *pColl, /* Collating sequence with native encoding, or NULL */
115750 const char *zName /* Collating sequence name */
115751){
115752 CollSeq *p;
115753 sqlite3 *db = pParse->db;
115754
115755 p = pColl;
115756 if( !p ){
115757 p = sqlite3FindCollSeq(db, enc, zName, 0);
115758 }
115759 if( !p || !p->xCmp ){
115760 /* No collation sequence of this type for this encoding is registered.
115761 ** Call the collation factory to see if it can supply us with one.
115762 */
115763 callCollNeeded(db, enc, zName);
115764 p = sqlite3FindCollSeq(db, enc, zName, 0);
115765 }
115766 if( p && !p->xCmp && synthCollSeq(db, p) ){
115767 p = 0;
115768 }
115769 assert( !p || p->xCmp );
static void callCollNeeded(sqlite3 *db, int enc, const char *zName)
Definition sqlite3.c:115559
static int synthCollSeq(sqlite3 *db, CollSeq *pColl)
Definition sqlite3.c:115588

References callCollNeeded(), Parse::db, Parse::rc, sqlite3ErrorMsg(), sqlite3FindCollSeq(), SQLITE_ERROR_MISSING_COLLSEQ, synthCollSeq(), CollSeq::xCmp, and zName.

Referenced by sqlite3CheckCollSeq(), sqlite3ExprCollSeq(), and sqlite3LocateCollSeq().

◆ sqlite3GetFuncCollSeq()

static CollSeq * sqlite3GetFuncCollSeq ( sqlite3_context * context)
static

◆ sqlite3GetInt32()

SQLITE_PRIVATE int sqlite3GetInt32 ( const char * zNum,
int * pValue )

Definition at line 31981 of file sqlite3.c.

31987 {
31988 sqlite_int64 v = 0;
31989 int i, c;
31990 int neg = 0;
31991 if( zNum[0]=='-' ){
31992 neg = 1;
31993 zNum++;
31994 }else if( zNum[0]=='+' ){
31995 zNum++;
31996 }
31997#ifndef SQLITE_OMIT_HEX_INTEGER
31998 else if( zNum[0]=='0'
31999 && (zNum[1]=='x' || zNum[1]=='X')
32000 && sqlite3Isxdigit(zNum[2])
32001 ){
32002 u32 u = 0;
32003 zNum += 2;
32004 while( zNum[0]=='0' ) zNum++;
32005 for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){
32006 u = u*16 + sqlite3HexToInt(zNum[i]);
32007 }
32008 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
32009 memcpy(pValue, &u, 4);
32010 return 1;
32011 }else{
32012 return 0;
32013 }
32014 }
32015#endif
32016 if( !sqlite3Isdigit(zNum[0]) ) return 0;
32017 while( zNum[0]=='0' ) zNum++;
32018 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
32019 v = v*10 + c;
32020 }
32021
32022 /* The longest decimal representation of a 32 bit integer is 10 digits:
32023 **
32024 ** 1234567890
32025 ** 2^31 -> 2147483648
32026 */
32027 testcase( i==10 );
32028 if( i>10 ){
32029 return 0;
32030 }
32031 testcase( v-neg==2147483647 );
32032 if( v-neg>2147483647 ){
32033 return 0;
32034 }

References sqlite3HexToInt(), sqlite3Isdigit, sqlite3Isxdigit, and testcase.

Referenced by sqlite3AffinityType(), sqlite3ExprAlloc(), sqlite3ExprIsInteger(), sqlite3Pragma(), sqlite3VdbeExpandSql(), and yy_reduce().

◆ sqlite3GetTempRange()

SQLITE_PRIVATE int sqlite3GetTempRange ( Parse * pParse,
int nReg )

Definition at line 105730 of file sqlite3.c.

105736 {
105737 int i, n;
105738 if( nReg==1 ) return sqlite3GetTempReg(pParse);
105739 i = pParse->iRangeReg;
105740 n = pParse->nRangeReg;
105741 if( nReg<=n ){
105742 pParse->iRangeReg += nReg;
105743 pParse->nRangeReg -= nReg;
int iRangeReg
Definition sqlite3.c:18695
int nRangeReg
Definition sqlite3.c:18694

Referenced by analyzeOneTable(), fkLookupParent(), generateOutputSubroutine(), generateSortTail(), selectInnerLoop(), sqlite3ExprCodeIN(), sqlite3ExprCodeTarget(), sqlite3GenerateConstraintChecks(), sqlite3GenerateIndexKey(), sqlite3Insert(), sqlite3Select(), updateAccumulator(), windowAggStep(), windowCodeOp(), and windowFullScan().

◆ sqlite3GetTempReg()

◆ sqlite3GetToken()

SQLITE_PRIVATE int sqlite3GetToken ( const unsigned char * z,
int * tokenType )

Definition at line 160008 of file sqlite3.c.

160014 {
160015 int i, c;
160016 switch( aiClass[*z] ){ /* Switch on the character-class of the first byte
160017 ** of the token. See the comment on the CC_ defines
160018 ** above. */
160019 case CC_SPACE: {
160020 testcase( z[0]==' ' );
160021 testcase( z[0]=='\t' );
160022 testcase( z[0]=='\n' );
160023 testcase( z[0]=='\f' );
160024 testcase( z[0]=='\r' );
160025 for(i=1; sqlite3Isspace(z[i]); i++){}
160026 *tokenType = TK_SPACE;
160027 return i;
160028 }
160029 case CC_MINUS: {
160030 if( z[1]=='-' ){
160031 for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
160032 *tokenType = TK_SPACE; /* IMP: R-22934-25134 */
160033 return i;
160034 }
160035 *tokenType = TK_MINUS;
160036 return 1;
160037 }
160038 case CC_LP: {
160039 *tokenType = TK_LP;
160040 return 1;
160041 }
160042 case CC_RP: {
160043 *tokenType = TK_RP;
160044 return 1;
160045 }
160046 case CC_SEMI: {
160047 *tokenType = TK_SEMI;
160048 return 1;
160049 }
160050 case CC_PLUS: {
160051 *tokenType = TK_PLUS;
160052 return 1;
160053 }
160054 case CC_STAR: {
160055 *tokenType = TK_STAR;
160056 return 1;
160057 }
160058 case CC_SLASH: {
160059 if( z[1]!='*' || z[2]==0 ){
160060 *tokenType = TK_SLASH;
160061 return 1;
160062 }
160063 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
160064 if( c ) i++;
160065 *tokenType = TK_SPACE; /* IMP: R-22934-25134 */
160066 return i;
160067 }
160068 case CC_PERCENT: {
160069 *tokenType = TK_REM;
160070 return 1;
160071 }
160072 case CC_EQ: {
160073 *tokenType = TK_EQ;
160074 return 1 + (z[1]=='=');
160075 }
160076 case CC_LT: {
160077 if( (c=z[1])=='=' ){
160078 *tokenType = TK_LE;
160079 return 2;
160080 }else if( c=='>' ){
160081 *tokenType = TK_NE;
160082 return 2;
160083 }else if( c=='<' ){
160084 *tokenType = TK_LSHIFT;
160085 return 2;
160086 }else{
160087 *tokenType = TK_LT;
160088 return 1;
160089 }
160090 }
160091 case CC_GT: {
160092 if( (c=z[1])=='=' ){
160093 *tokenType = TK_GE;
160094 return 2;
160095 }else if( c=='>' ){
160096 *tokenType = TK_RSHIFT;
160097 return 2;
160098 }else{
160099 *tokenType = TK_GT;
160100 return 1;
160101 }
160102 }
160103 case CC_BANG: {
160104 if( z[1]!='=' ){
160105 *tokenType = TK_ILLEGAL;
160106 return 1;
160107 }else{
160108 *tokenType = TK_NE;
160109 return 2;
160110 }
160111 }
160112 case CC_PIPE: {
160113 if( z[1]!='|' ){
160114 *tokenType = TK_BITOR;
160115 return 1;
160116 }else{
160117 *tokenType = TK_CONCAT;
160118 return 2;
160119 }
160120 }
160121 case CC_COMMA: {
160122 *tokenType = TK_COMMA;
160123 return 1;
160124 }
160125 case CC_AND: {
160126 *tokenType = TK_BITAND;
160127 return 1;
160128 }
160129 case CC_TILDA: {
160130 *tokenType = TK_BITNOT;
160131 return 1;
160132 }
160133 case CC_QUOTE: {
160134 int delim = z[0];
160135 testcase( delim=='`' );
160136 testcase( delim=='\'' );
160137 testcase( delim=='"' );
160138 for(i=1; (c=z[i])!=0; i++){
160139 if( c==delim ){
160140 if( z[i+1]==delim ){
160141 i++;
160142 }else{
160143 break;
160144 }
160145 }
160146 }
160147 if( c=='\'' ){
160148 *tokenType = TK_STRING;
160149 return i+1;
160150 }else if( c!=0 ){
160151 *tokenType = TK_ID;
160152 return i+1;
160153 }else{
160154 *tokenType = TK_ILLEGAL;
160155 return i;
160156 }
160157 }
160158 case CC_DOT: {
160159#ifndef SQLITE_OMIT_FLOATING_POINT
160160 if( !sqlite3Isdigit(z[1]) )
160161#endif
160162 {
160163 *tokenType = TK_DOT;
160164 return 1;
160165 }
160166 /* If the next character is a digit, this is a floating point
160167 ** number that begins with ".". Fall thru into the next case */
160168 /* no break */ deliberate_fall_through
160169 }
160170 case CC_DIGIT: {
160171 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
160172 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
160173 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
160174 testcase( z[0]=='9' );
160175 *tokenType = TK_INTEGER;
160176#ifndef SQLITE_OMIT_HEX_INTEGER
160177 if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
160178 for(i=3; sqlite3Isxdigit(z[i]); i++){}
160179 return i;
160180 }
160181#endif
160182 for(i=0; sqlite3Isdigit(z[i]); i++){}
160183#ifndef SQLITE_OMIT_FLOATING_POINT
160184 if( z[i]=='.' ){
160185 i++;
160186 while( sqlite3Isdigit(z[i]) ){ i++; }
160187 *tokenType = TK_FLOAT;
160188 }
160189 if( (z[i]=='e' || z[i]=='E') &&
160190 ( sqlite3Isdigit(z[i+1])
160191 || ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2]))
160192 )
160193 ){
160194 i += 2;
160195 while( sqlite3Isdigit(z[i]) ){ i++; }
160196 *tokenType = TK_FLOAT;
160197 }
160198#endif
160199 while( IdChar(z[i]) ){
160200 *tokenType = TK_ILLEGAL;
160201 i++;
160202 }
160203 return i;
160204 }
160205 case CC_QUOTE2: {
160206 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
160207 *tokenType = c==']' ? TK_ID : TK_ILLEGAL;
160208 return i;
160209 }
160210 case CC_VARNUM: {
160211 *tokenType = TK_VARIABLE;
160212 for(i=1; sqlite3Isdigit(z[i]); i++){}
160213 return i;
160214 }
160215 case CC_DOLLAR:
160216 case CC_VARALPHA: {
160217 int n = 0;
160218 testcase( z[0]=='$' ); testcase( z[0]=='@' );
160219 testcase( z[0]==':' ); testcase( z[0]=='#' );
160220 *tokenType = TK_VARIABLE;
160221 for(i=1; (c=z[i])!=0; i++){
160222 if( IdChar(c) ){
160223 n++;
160224#ifndef SQLITE_OMIT_TCL_VARIABLE
160225 }else if( c=='(' && n>0 ){
160226 do{
160227 i++;
160228 }while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' );
160229 if( c==')' ){
160230 i++;
160231 }else{
160232 *tokenType = TK_ILLEGAL;
160233 }
160234 break;
160235 }else if( c==':' && z[i+1]==':' ){
160236 i++;
160237#endif
160238 }else{
160239 break;
160240 }
160241 }
160242 if( n==0 ) *tokenType = TK_ILLEGAL;
160243 return i;
160244 }
160245 case CC_KYWD: {
160246 for(i=1; aiClass[z[i]]<=CC_KYWD; i++){}
160247 if( IdChar(z[i]) ){
160248 /* This token started out using characters that can appear in keywords,
160249 ** but z[i] is a character not allowed within keywords, so this must
160250 ** be an identifier instead */
160251 i++;
160252 break;
160253 }
160254 *tokenType = TK_ID;
160255 return keywordCode((char*)z, i, tokenType);
160256 }
160257 case CC_X: {
160258#ifndef SQLITE_OMIT_BLOB_LITERAL
160259 testcase( z[0]=='x' ); testcase( z[0]=='X' );
160260 if( z[1]=='\'' ){
160261 *tokenType = TK_BLOB;
160262 for(i=2; sqlite3Isxdigit(z[i]); i++){}
160263 if( z[i]!='\'' || i%2 ){
160264 *tokenType = TK_ILLEGAL;
160265 while( z[i] && z[i]!='\'' ){ i++; }
160266 }
160267 if( z[i] ) i++;
160268 return i;
160269 }
160270#endif
160271 /* If it is not a BLOB literal, then it must be an ID, since no
160272 ** SQL keywords start with the letter 'x'. Fall through */
160273 /* no break */ deliberate_fall_through
160274 }
160275 case CC_ID: {
160276 i = 1;
160277 break;
160278 }
160279 case CC_NUL: {
160280 *tokenType = TK_ILLEGAL;
160281 return 0;
160282 }
160283 default: {
160284 *tokenType = TK_ILLEGAL;
160285 return 1;
#define CC_SEMI
Definition sqlite3.c:159304
#define CC_PERCENT
Definition sqlite3.c:159307
#define CC_STAR
Definition sqlite3.c:159306
#define CC_COMMA
Definition sqlite3.c:159308
#define CC_EQ
Definition sqlite3.c:159299
#define CC_AND
Definition sqlite3.c:159309
#define CC_VARNUM
Definition sqlite3.c:159291
#define CC_BANG
Definition sqlite3.c:159300
#define CC_PIPE
Definition sqlite3.c:159295
#define CC_X
Definition sqlite3.c:159285
#define CC_NUL
Definition sqlite3.c:159313
#define CC_DOLLAR
Definition sqlite3.c:159289
#define CC_DIGIT
Definition sqlite3.c:159288
static const unsigned char aiClass[]
Definition sqlite3.c:159315
#define CC_KYWD
Definition sqlite3.c:159286
#define CC_DOT
Definition sqlite3.c:159311
#define CC_MINUS
Definition sqlite3.c:159296
#define TK_COMMA
Definition sqlite3.c:13968
#define CC_SPACE
Definition sqlite3.c:159292
#define CC_QUOTE2
Definition sqlite3.c:159294
#define CC_GT
Definition sqlite3.c:159298
#define CC_RP
Definition sqlite3.c:159303
#define CC_LT
Definition sqlite3.c:159297
#define CC_SLASH
Definition sqlite3.c:159301
#define CC_QUOTE
Definition sqlite3.c:159293
#define CC_LP
Definition sqlite3.c:159302
#define CC_VARALPHA
Definition sqlite3.c:159290
#define CC_TILDA
Definition sqlite3.c:159310
#define CC_ID
Definition sqlite3.c:159287
#define TK_SEMI
Definition sqlite3.c:13943
#define CC_PLUS
Definition sqlite3.c:159305

References aiClass, CC_AND, CC_BANG, CC_COMMA, CC_DIGIT, CC_DOLLAR, CC_DOT, CC_EQ, CC_GT, CC_ID, CC_KYWD, CC_LP, CC_LT, CC_MINUS, CC_NUL, CC_PERCENT, CC_PIPE, CC_PLUS, CC_QUOTE, CC_QUOTE2, CC_RP, CC_SEMI, CC_SLASH, CC_SPACE, CC_STAR, CC_TILDA, CC_VARALPHA, CC_VARNUM, CC_X, deliberate_fall_through, IdChar, keywordCode(), sqlite3Isdigit, sqlite3Isspace, sqlite3Isxdigit, testcase, TK_BITAND, TK_BITNOT, TK_BITOR, TK_BLOB, TK_COMMA, TK_CONCAT, TK_DOT, TK_EQ, TK_FLOAT, TK_GE, TK_GT, TK_ID, TK_ILLEGAL, TK_INTEGER, TK_LE, TK_LP, TK_LSHIFT, TK_LT, TK_MINUS, TK_NE, TK_PLUS, TK_REM, TK_RP, TK_RSHIFT, TK_SEMI, TK_SLASH, TK_SPACE, TK_STAR, TK_STRING, and TK_VARIABLE.

Referenced by findNextHostParameter(), getToken(), and sqlite3RunParser().

◆ sqlite3GetUInt32()

SQLITE_PRIVATE int sqlite3GetUInt32 ( const char * z,
u32 * pI )

Definition at line 32052 of file sqlite3.c.

32058 {
32059 u64 v = 0;
32060 int i;
32061 for(i=0; sqlite3Isdigit(z[i]); i++){
32062 v = v*10 + z[i] - '0';

References sqlite3Isdigit.

Referenced by sqlite3InitCallback().

◆ sqlite3GetVarint()

SQLITE_PRIVATE u8 sqlite3GetVarint ( const unsigned char * p,
u64 * v )

Definition at line 32147 of file sqlite3.c.

32153 {
32154 u32 a,b,s;
32155
32156 if( ((signed char*)p)[0]>=0 ){
32157 *v = *p;
32158 return 1;
32159 }
32160 if( ((signed char*)p)[1]>=0 ){
32161 *v = ((u32)(p[0]&0x7f)<<7) | p[1];
32162 return 2;
32163 }
32164
32165 /* Verify that constants are precomputed correctly */
32166 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) );
32167 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) );
32168
32169 a = ((u32)p[0])<<14;
32170 b = p[1];
32171 p += 2;
32172 a |= *p;
32173 /* a: p0<<14 | p2 (unmasked) */
32174 if (!(a&0x80))
32175 {
32176 a &= SLOT_2_0;
32177 b &= 0x7f;
32178 b = b<<7;
32179 a |= b;
32180 *v = a;
32181 return 3;
32182 }
32183
32184 /* CSE1 from below */
32185 a &= SLOT_2_0;
32186 p++;
32187 b = b<<14;
32188 b |= *p;
32189 /* b: p1<<14 | p3 (unmasked) */
32190 if (!(b&0x80))
32191 {
32192 b &= SLOT_2_0;
32193 /* moved CSE1 up */
32194 /* a &= (0x7f<<14)|(0x7f); */
32195 a = a<<7;
32196 a |= b;
32197 *v = a;
32198 return 4;
32199 }
32200
32201 /* a: p0<<14 | p2 (masked) */
32202 /* b: p1<<14 | p3 (unmasked) */
32203 /* 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
32204 /* moved CSE1 up */
32205 /* a &= (0x7f<<14)|(0x7f); */
32206 b &= SLOT_2_0;
32207 s = a;
32208 /* s: p0<<14 | p2 (masked) */
32209
32210 p++;
32211 a = a<<14;
32212 a |= *p;
32213 /* a: p0<<28 | p2<<14 | p4 (unmasked) */
32214 if (!(a&0x80))
32215 {
32216 /* we can skip these cause they were (effectively) done above
32217 ** while calculating s */
32218 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
32219 /* b &= (0x7f<<14)|(0x7f); */
32220 b = b<<7;
32221 a |= b;
32222 s = s>>18;
32223 *v = ((u64)s)<<32 | a;
32224 return 5;
32225 }
32226
32227 /* 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
32228 s = s<<7;
32229 s |= b;
32230 /* s: p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
32231
32232 p++;
32233 b = b<<14;
32234 b |= *p;
32235 /* b: p1<<28 | p3<<14 | p5 (unmasked) */
32236 if (!(b&0x80))
32237 {
32238 /* we can skip this cause it was (effectively) done above in calc'ing s */
32239 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
32240 a &= SLOT_2_0;
32241 a = a<<7;
32242 a |= b;
32243 s = s>>18;
32244 *v = ((u64)s)<<32 | a;
32245 return 6;
32246 }
32247
32248 p++;
32249 a = a<<14;
32250 a |= *p;
32251 /* a: p2<<28 | p4<<14 | p6 (unmasked) */
32252 if (!(a&0x80))
32253 {
32254 a &= SLOT_4_2_0;
32255 b &= SLOT_2_0;
32256 b = b<<7;
32257 a |= b;
32258 s = s>>11;
32259 *v = ((u64)s)<<32 | a;
32260 return 7;
32261 }
32262
32263 /* CSE2 from below */
32264 a &= SLOT_2_0;
32265 p++;
32266 b = b<<14;
32267 b |= *p;
32268 /* b: p3<<28 | p5<<14 | p7 (unmasked) */
32269 if (!(b&0x80))
32270 {
32271 b &= SLOT_4_2_0;
32272 /* moved CSE2 up */
32273 /* a &= (0x7f<<14)|(0x7f); */
32274 a = a<<7;
32275 a |= b;
32276 s = s>>4;
32277 *v = ((u64)s)<<32 | a;
32278 return 8;
32279 }
32280
32281 p++;
32282 a = a<<15;
32283 a |= *p;
32284 /* a: p4<<29 | p6<<15 | p8 (unmasked) */
32285
32286 /* moved CSE2 up */
32287 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
32288 b &= SLOT_2_0;
32289 b = b<<8;
32290 a |= b;
32291
32292 s = s<<4;
32293 b = p[-4];
32294 b &= 0x7f;
32295 b = b>>3;
#define SLOT_2_0
Definition sqlite3.c:32139
#define SLOT_4_2_0
Definition sqlite3.c:32140

References s, SLOT_2_0, and SLOT_4_2_0.

Referenced by sqlite3GetVarint32().

◆ sqlite3GetVarint32()

SQLITE_PRIVATE u8 sqlite3GetVarint32 ( const unsigned char * p,
u32 * v )

Definition at line 32308 of file sqlite3.c.

32314 {
32315 u32 a,b;
32316
32317 /* The 1-byte case. Overwhelmingly the most common. Handled inline
32318 ** by the getVarin32() macro */
32319 a = *p;
32320 /* a: p0 (unmasked) */
32321#ifndef getVarint32
32322 if (!(a&0x80))
32323 {
32324 /* Values between 0 and 127 */
32325 *v = a;
32326 return 1;
32327 }
32328#endif
32329
32330 /* The 2-byte case */
32331 p++;
32332 b = *p;
32333 /* b: p1 (unmasked) */
32334 if (!(b&0x80))
32335 {
32336 /* Values between 128 and 16383 */
32337 a &= 0x7f;
32338 a = a<<7;
32339 *v = a | b;
32340 return 2;
32341 }
32342
32343 /* The 3-byte case */
32344 p++;
32345 a = a<<14;
32346 a |= *p;
32347 /* a: p0<<14 | p2 (unmasked) */
32348 if (!(a&0x80))
32349 {
32350 /* Values between 16384 and 2097151 */
32351 a &= (0x7f<<14)|(0x7f);
32352 b &= 0x7f;
32353 b = b<<7;
32354 *v = a | b;
32355 return 3;
32356 }
32357
32358 /* A 32-bit varint is used to store size information in btrees.
32359 ** Objects are rarely larger than 2MiB limit of a 3-byte varint.
32360 ** A 3-byte varint is sufficient, for example, to record the size
32361 ** of a 1048569-byte BLOB or string.
32362 **
32363 ** We only unroll the first 1-, 2-, and 3- byte cases. The very
32364 ** rare larger cases can be handled by the slower 64-bit varint
32365 ** routine.
32366 */
32367#if 1
32368 {
32369 u64 v64;
32370 u8 n;
32371
32372 n = sqlite3GetVarint(p-2, &v64);
32373 assert( n>3 && n<=9 );
32374 if( (v64 & SQLITE_MAX_U32)!=v64 ){
32375 *v = 0xffffffff;
32376 }else{
32377 *v = (u32)v64;
32378 }
32379 return n;
32380 }
32381
32382#else
32383 /* For following code (kept for historical record only) shows an
32384 ** unrolling for the 3- and 4-byte varint cases. This code is
32385 ** slightly faster, but it is also larger and much harder to test.
32386 */
32387 p++;
32388 b = b<<14;
32389 b |= *p;
32390 /* b: p1<<14 | p3 (unmasked) */
32391 if (!(b&0x80))
32392 {
32393 /* Values between 2097152 and 268435455 */
32394 b &= (0x7f<<14)|(0x7f);
32395 a &= (0x7f<<14)|(0x7f);
32396 a = a<<7;
32397 *v = a | b;
32398 return 4;
32399 }
32400
32401 p++;
32402 a = a<<14;
32403 a |= *p;
32404 /* a: p0<<28 | p2<<14 | p4 (unmasked) */
32405 if (!(a&0x80))
32406 {
32407 /* Values between 268435456 and 34359738367 */
32408 a &= SLOT_4_2_0;
32409 b &= SLOT_4_2_0;
32410 b = b<<7;
32411 *v = a | b;
32412 return 5;
32413 }
32414
32415 /* We can only reach this point when reading a corrupt database
32416 ** file. In that case we are not in any hurry. Use the (relatively
32417 ** slow) general-purpose sqlite3GetVarint() routine to extract the
32418 ** value. */
32419 {
32420 u64 v64;
32421 u8 n;
32422
32423 p -= 4;
32424 n = sqlite3GetVarint(p, &v64);
#define SQLITE_MAX_U32
Definition sqlite3.c:14343
SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *, u64 *)
Definition sqlite3.c:32147

References SLOT_4_2_0, sqlite3GetVarint(), and SQLITE_MAX_U32.

Referenced by sqlite3VdbeExec(), and vdbeRecordCompareString().

◆ sqlite3GetVdbe()

◆ sqlite3GetVTable()

◆ sqlite3HaltConstraint()

SQLITE_PRIVATE void sqlite3HaltConstraint ( Parse * pParse,
int errCode,
int onError,
char * p4,
i8 p4type,
u8 p5Errmsg )

Definition at line 115214 of file sqlite3.c.

115227 {
115228 Vdbe *v = sqlite3GetVdbe(pParse);
115229 assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );

References Parse::nested, OE_Abort, OP_Halt, sqlite3GetVdbe(), sqlite3MayAbort(), sqlite3VdbeAddOp4(), and SQLITE_CONSTRAINT.

Referenced by fkLookupParent(), sqlite3ExprCodeTarget(), sqlite3FkDropTable(), and sqlite3GenerateConstraintChecks().

◆ sqlite3HasExplicitNulls()

SQLITE_PRIVATE int sqlite3HasExplicitNulls ( Parse * pParse,
ExprList * pList )

Definition at line 113841 of file sqlite3.c.

113847 {
113848 if( pList ){
113849 int i;
113850 for(i=0; i<pList->nExpr; i++){
113851 if( pList->a[i].bNulls ){
113852 u8 sf = pList->a[i].sortFlags;
113853 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
113854 (sf==0 || sf==3) ? "FIRST" : "LAST"
113855 );

References ExprList::a, ExprList::ExprList_item::bNulls, ExprList::nExpr, ExprList::ExprList_item::sortFlags, and sqlite3ErrorMsg().

Referenced by sqlite3AddPrimaryKey(), sqlite3CreateIndex(), sqlite3Insert(), and sqlite3TriggerInsertStep().

◆ sqlite3HashClear()

SQLITE_PRIVATE void sqlite3HashClear ( Hash * pH)

Definition at line 32912 of file sqlite3.c.

32918 {
32919 HashElem *elem; /* For looping over all elements of the table */
32920
32921 assert( pH!=0 );
32922 elem = pH->first;
32923 pH->first = 0;
32924 sqlite3_free(pH->ht);
32925 pH->ht = 0;
32926 pH->htsize = 0;
32927 while( elem ){

Referenced by sqlite3ColumnsFromExprList(), sqlite3LeaveMutexAndCloseZombie(), and sqlite3SchemaClear().

◆ sqlite3HashFind()

◆ sqlite3HashInit()

SQLITE_PRIVATE void sqlite3HashInit ( Hash * pNew)

Definition at line 32900 of file sqlite3.c.

32906 {

References Hash::count, Hash::first, Hash::ht, and Hash::htsize.

Referenced by openDatabase(), sqlite3ColumnsFromExprList(), and sqlite3SchemaClear().

◆ sqlite3HashInsert()

SQLITE_PRIVATE void * sqlite3HashInsert ( Hash * pH,
const char * pKey,
void * pData )

Definition at line 33114 of file sqlite3.c.

33120 {
33121 unsigned int h; /* the hash of the key modulo hash table size */
33122 HashElem *elem; /* Used to loop thru the element list */
33123 HashElem *new_elem; /* New element added to the pH */
33124
33125 assert( pH!=0 );
33126 assert( pKey!=0 );
33127 elem = findElementWithHash(pH,pKey,&h);
33128 if( elem->data ){
33129 void *old_data = elem->data;
33130 if( data==0 ){
33131 removeElementGivenHash(pH,elem,h);
33132 }else{
33133 elem->data = data;
33134 elem->pKey = pKey;
33135 }
33136 return old_data;
33137 }
33138 if( data==0 ) return 0;
33139 new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
33140 if( new_elem==0 ) return data;
33141 new_elem->pKey = pKey;
33142 new_elem->data = data;
33143 pH->count++;
33144 if( pH->count>=10 && pH->count > 2*pH->htsize ){
33145 if( rehash(pH, pH->count*2) ){
33146 assert( pH->htsize>0 );
static HashElem * findElementWithHash(const Hash *pH, const char *pKey, unsigned int *pHash)
Definition sqlite3.c:33024
static int rehash(Hash *pH, unsigned int new_size)
Definition sqlite3.c:32983
static void removeElementGivenHash(Hash *pH, HashElem *elem, unsigned int h)
Definition sqlite3.c:33059
void * data
Definition sqlite3.c:13902

References Hash::count, HashElem::data, findElementWithHash(), Hash::ht, Hash::htsize, insertElement(), HashElem::pKey, rehash(), removeElementGivenHash(), sqlite3Malloc(), and strHash().

Referenced by deleteTable(), findCollSeqEntry(), sqlite3ColumnsFromExprList(), sqlite3CreateForeignKey(), sqlite3CreateIndex(), sqlite3EndTable(), sqlite3FindFunction(), sqlite3FkDelete(), sqlite3UnlinkAndDeleteIndex(), sqlite3UnlinkAndDeleteTable(), and sqlite3VtabCreateModule().

◆ sqlite3HeaderSizeBtree()

SQLITE_PRIVATE int sqlite3HeaderSizeBtree ( void )

Definition at line 75028 of file sqlite3.c.

Referenced by sqlite3_config().

◆ sqlite3HeaderSizePcache()

SQLITE_PRIVATE int sqlite3HeaderSizePcache ( void )

Definition at line 49720 of file sqlite3.c.

Referenced by sqlite3_config().

◆ sqlite3HeaderSizePcache1()

SQLITE_PRIVATE int sqlite3HeaderSizePcache1 ( void )

Definition at line 50968 of file sqlite3.c.

Referenced by sqlite3_config().

◆ sqlite3HeapNearlyFull()

SQLITE_PRIVATE int sqlite3HeapNearlyFull ( void )

Definition at line 27493 of file sqlite3.c.

References AtomicLoad, and mem0.

Referenced by pcache1UnderMemoryPressure().

◆ sqlite3HexToBlob()

SQLITE_PRIVATE void * sqlite3HexToBlob ( sqlite3 * db,
const char * z,
int n )

Definition at line 32500 of file sqlite3.c.

32506 {
32507 char *zBlob;
32508 int i;
32509
32510 zBlob = (char *)sqlite3DbMallocRawNN(db, n/2 + 1);
32511 n--;
32512 if( zBlob ){
32513 for(i=0; i<n; i+=2){

References sqlite3DbMallocRawNN(), and sqlite3HexToInt().

Referenced by sqlite3ExprCodeTarget(), and valueFromExpr().

◆ sqlite3HexToInt()

SQLITE_PRIVATE u8 sqlite3HexToInt ( int h)

Definition at line 32482 of file sqlite3.c.

32488 {
32489 assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') );
32490#ifdef SQLITE_ASCII
32491 h += 9*(1&(h>>6));

Referenced by sqlite3DecOrHexToI64(), sqlite3GetInt32(), sqlite3HexToBlob(), and sqlite3ParseUri().

◆ sqlite3IdListAppend()

SQLITE_PRIVATE IdList * sqlite3IdListAppend ( Parse * pParse,
IdList * pList,
Token * pToken )

Definition at line 114617 of file sqlite3.c.

114623 {
114624 sqlite3 *db = pParse->db;
114625 int i;
114626 if( pList==0 ){
114627 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
114628 if( pList==0 ) return 0;
114629 }
114630 pList->a = sqlite3ArrayAllocate(
114631 db,
114632 pList->a,
114633 sizeof(pList->a[0]),
114634 &pList->nId,
114635 &i
114636 );
114637 if( i<0 ){
114638 sqlite3IdListDelete(db, pList);
114639 return 0;
114640 }

References IdList::a, Parse::db, IN_RENAME_OBJECT, IdList::nId, sqlite3ArrayAllocate(), sqlite3DbMallocZero(), sqlite3IdListDelete(), sqlite3NameFromToken(), sqlite3RenameTokenMap(), and IdList::IdList_item::zName.

Referenced by yy_reduce().

◆ sqlite3IdListDelete()

SQLITE_PRIVATE void sqlite3IdListDelete ( sqlite3 * db,
IdList * pList )

◆ sqlite3IdListDup()

SQLITE_PRIVATE IdList * sqlite3IdListDup ( sqlite3 * db,
IdList * p )

Definition at line 101257 of file sqlite3.c.

101263 {
101264 IdList *pNew;
101265 int i;
101266 assert( db!=0 );
101267 if( p==0 ) return 0;
101268 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
101269 if( pNew==0 ) return 0;
101270 pNew->nId = p->nId;
101271 pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
101272 if( pNew->a==0 ){
101273 sqlite3DbFreeNN(db, pNew);
101274 return 0;
101275 }
101276 /* Note that because the size of the allocation for p->a[] is not
101277 ** necessarily a power of two, sqlite3IdListAppend() may not be called
101278 ** on the duplicate created by this function. */
101279 for(i=0; i<p->nId; i++){
101280 struct IdList_item *pNewItem = &pNew->a[i];

◆ sqlite3IdListIndex()

SQLITE_PRIVATE int sqlite3IdListIndex ( IdList * pList,
const char * zName )

Definition at line 114659 of file sqlite3.c.

114665 {
114666 int i;

Referenced by checkColumnOverlap(), and selectExpander().

◆ sqlite3IndexAffinityOk()

SQLITE_PRIVATE int sqlite3IndexAffinityOk ( const Expr * pExpr,
char idx_affinity )

Definition at line 100004 of file sqlite3.c.

100010 {
100011 char aff = comparisonAffinity(pExpr);
100012 if( aff<SQLITE_AFF_TEXT ){
100013 return 1;
static char comparisonAffinity(const Expr *pExpr)
Definition sqlite3.c:99981

References comparisonAffinity(), sqlite3IsNumericAffinity, and SQLITE_AFF_TEXT.

Referenced by termCanDriveIndex(), and whereScanNext().

◆ sqlite3IndexAffinityStr()

SQLITE_PRIVATE const char * sqlite3IndexAffinityStr ( sqlite3 * db,
Index * pIdx )

Definition at line 120619 of file sqlite3.c.

120625 {
120626 if( !pIdx->zColAff ){
120627 /* The first time a column affinity string for a particular index is
120628 ** required, it is allocated and populated here. It is then stored as
120629 ** a member of the Index structure for subsequent use.
120630 **
120631 ** The column affinity string will eventually be deleted by
120632 ** sqliteDeleteIndex() when the Index structure itself is cleaned
120633 ** up.
120634 */
120635 int n;
120636 Table *pTab = pIdx->pTable;
120637 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
120638 if( !pIdx->zColAff ){
120639 sqlite3OomFault(db);
120640 return 0;
120641 }
120642 for(n=0; n<pIdx->nColumn; n++){
120643 i16 x = pIdx->aiColumn[n];
120644 char aff;
120645 if( x>=0 ){
120646 aff = pTab->aCol[x].affinity;
120647 }else if( x==XN_ROWID ){
120648 aff = SQLITE_AFF_INTEGER;
120649 }else{
120650 assert( x==XN_EXPR );
120651 assert( pIdx->aColExpr!=0 );
120652 aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
120653 }
120654 if( aff<SQLITE_AFF_BLOB ) aff = SQLITE_AFF_BLOB;
120655 if( aff>SQLITE_AFF_NUMERIC) aff = SQLITE_AFF_NUMERIC;
120656 pIdx->zColAff[n] = aff;

References ExprList::a, Table::aCol, Index::aColExpr, Column::affinity, Index::aiColumn, Index::nColumn, ExprList::ExprList_item::pExpr, Index::pTable, sqlite3DbMallocRaw(), sqlite3ExprAffinity(), sqlite3OomFault(), SQLITE_AFF_BLOB, SQLITE_AFF_INTEGER, SQLITE_AFF_NUMERIC, XN_EXPR, XN_ROWID, and Index::zColAff.

Referenced by codeAllEqualityTerms(), fkLookupParent(), sqlite3DeleteFrom(), sqlite3GenerateIndexKey(), sqlite3Pragma(), and sqlite3Update().

◆ sqlite3IndexedByLookup()

SQLITE_PRIVATE int sqlite3IndexedByLookup ( Parse * pParse,
struct SrcList_item * pFrom )

Definition at line 133892 of file sqlite3.c.

133898 {
133899 if( pFrom->pTab && pFrom->fg.isIndexedBy ){
133900 Table *pTab = pFrom->pTab;
133901 char *zIndexedBy = pFrom->u1.zIndexedBy;
133902 Index *pIdx;
133903 for(pIdx=pTab->pIndex;
133904 pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy);
133905 pIdx=pIdx->pNext
133906 );
133907 if( !pIdx ){
133908 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
133909 pParse->checkSchema = 1;

References Parse::checkSchema, Table::pIndex, Index::pNext, sqlite3ErrorMsg(), sqlite3StrICmp(), SQLITE_ERROR, SQLITE_OK, and Index::zName.

Referenced by selectExpander(), and sqlite3SrcListLookup().

◆ sqlite3IndexHasDuplicateRootPage()

SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage ( Index * pIndex)

Definition at line 128385 of file sqlite3.c.

128391 {

References Table::pIndex, Index::pNext, Index::pTable, and Index::tnum.

Referenced by sqlite3CreateIndex(), and sqlite3InitCallback().

◆ sqlite3Init()

SQLITE_PRIVATE int sqlite3Init ( sqlite3 * db,
char ** pzErrMsg )

Definition at line 128749 of file sqlite3.c.

128755 {
128756 int i, rc;
128757 int commit_internal = !(db->mDbFlags&DBFLAG_SchemaChange);
128758
128759 assert( sqlite3_mutex_held(db->mutex) );
128760 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
128761 assert( db->init.busy==0 );
128762 ENC(db) = SCHEMA_ENC(db);
128763 assert( db->nDb>0 );
128764 /* Do the main schema first */
128765 if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){
128766 rc = sqlite3InitOne(db, 0, pzErrMsg, 0);
128767 if( rc ) return rc;
128768 }
128769 /* All other schemas after the main schema. The "temp" schema must be last */
128770 for(i=db->nDb-1; i>0; i--){
128771 assert( i==1 || sqlite3BtreeHoldsMutex(db->aDb[i].pBt) );
128772 if( !DbHasProperty(db, i, DB_SchemaLoaded) ){
128773 rc = sqlite3InitOne(db, i, pzErrMsg, 0);
128774 if( rc ) return rc;
128775 }
SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *, int, char **, u32)
Definition sqlite3.c:128514

References sqlite3::aDb, sqlite3::sqlite3InitInfo::busy, DB_SchemaLoaded, DBFLAG_SchemaChange, DbHasProperty, ENC, sqlite3::init, sqlite3::mDbFlags, sqlite3::mutex, sqlite3::nDb, Db::pBt, SCHEMA_ENC, sqlite3_mutex_held(), sqlite3CommitInternalChanges(), sqlite3InitOne(), and SQLITE_OK.

Referenced by attachFunc(), and sqlite3_table_column_metadata().

◆ sqlite3InitCallback()

SQLITE_PRIVATE int sqlite3InitCallback ( void * pInit,
int argc,
char ** argv,
char ** NotUsed )

Definition at line 128419 of file sqlite3.c.

128425 {
128426 InitData *pData = (InitData*)pInit;
128427 sqlite3 *db = pData->db;
128428 int iDb = pData->iDb;
128429
128430 assert( argc==5 );
128431 UNUSED_PARAMETER2(NotUsed, argc);
128432 assert( sqlite3_mutex_held(db->mutex) );
128434 pData->nInitRow++;
128435 if( db->mallocFailed ){
128436 corruptSchema(pData, argv[1], 0);
128437 return 1;
128438 }
128439
128440 assert( iDb>=0 && iDb<db->nDb );
128441 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
128442 if( argv[3]==0 ){
128443 corruptSchema(pData, argv[1], 0);
128444 }else if( sqlite3_strnicmp(argv[4],"create ",7)==0 ){
128445 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
128446 ** But because db->init.busy is set to 1, no VDBE code is generated
128447 ** or executed. All the parser does is build the internal data
128448 ** structures that describe the table, index, or view.
128449 */
128450 int rc;
128451 u8 saved_iDb = db->init.iDb;
128452 sqlite3_stmt *pStmt;
128453 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
128454
128455 assert( db->init.busy );
128456 db->init.iDb = iDb;
128457 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
128458 || (db->init.newTnum>pData->mxPage && pData->mxPage>0)
128459 ){
128461 corruptSchema(pData, argv[1], "invalid rootpage");
128462 }
128463 }
128464 db->init.orphanTrigger = 0;
128465 db->init.azInit = argv;
128466 pStmt = 0;
128467 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
128468 rc = db->errCode;
128469 assert( (rc&0xFF)==(rcp&0xFF) );
128470 db->init.iDb = saved_iDb;
128471 /* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
128472 if( SQLITE_OK!=rc ){
128473 if( db->init.orphanTrigger ){
128474 assert( iDb==1 );
128475 }else{
128476 if( rc > pData->rc ) pData->rc = rc;
128477 if( rc==SQLITE_NOMEM ){
128478 sqlite3OomFault(db);
128479 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
128480 corruptSchema(pData, argv[1], sqlite3_errmsg(db));
128481 }
128482 }
128483 }
128484 sqlite3_finalize(pStmt);
128485 }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
128486 corruptSchema(pData, argv[1], 0);
128487 }else{
128488 /* If the SQL column is blank it means this is an index that
128489 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
128490 ** constraint for a CREATE TABLE. The index should have already
128491 ** been created when we processed the CREATE TABLE. All we have
128492 ** to do here is record the root page number for that index.
128493 */
128494 Index *pIndex;
128495 pIndex = sqlite3FindIndex(db, argv[1], db->aDb[iDb].zDbSName);
128496 if( pIndex==0 ){
128497 corruptSchema(pData, argv[1], "orphan index");
128498 }else
128499 if( sqlite3GetUInt32(argv[3],&pIndex->tnum)==0
128500 || pIndex->tnum<2
128501 || pIndex->tnum>pData->mxPage
128503 ){
#define SQLITE_INTERRUPT
Definition sqlite3.c:1479
static void corruptSchema(InitData *pData, const char *zObj, const char *zExtra)
Definition sqlite3.c:128355
#define DBFLAG_EncodingFixed
Definition sqlite3.c:17034
SQLITE_PRIVATE int sqlite3GetUInt32(const char *, u32 *)
Definition sqlite3.c:32052
static int sqlite3Prepare(sqlite3 *db, const char *zSql, int nBytes, u32 prepFlags, Vdbe *pReprepare, sqlite3_stmt **ppStmt, const char **pzTail)
Definition sqlite3.c:128912
u32 nInitRow
Definition sqlite3.c:18994
Pgno mxPage
Definition sqlite3.c:18995

References sqlite3::aDb, sqlite3::sqlite3InitInfo::azInit, Sqlite3Config::bExtraSchemaChecks, sqlite3::sqlite3InitInfo::busy, corruptSchema(), InitData::db, DBFLAG_EncodingFixed, sqlite3::errCode, sqlite3::sqlite3InitInfo::iDb, InitData::iDb, sqlite3::init, sqlite3::mallocFailed, sqlite3::mDbFlags, sqlite3::mutex, InitData::mxPage, sqlite3::sqlite3InitInfo::newTnum, InitData::nInitRow, sqlite3::sqlite3InitInfo::orphanTrigger, InitData::rc, sqlite3_errmsg(), sqlite3_finalize(), sqlite3_mutex_held(), sqlite3_strnicmp(), sqlite3Config, sqlite3FindIndex(), sqlite3GetUInt32(), sqlite3IndexHasDuplicateRootPage(), sqlite3OomFault(), sqlite3Prepare(), SQLITE_INTERRUPT, SQLITE_LOCKED, SQLITE_NOMEM, SQLITE_OK, TESTONLY, Index::tnum, UNUSED_PARAMETER2, and Db::zDbSName.

Referenced by sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3InitOne()

SQLITE_PRIVATE int sqlite3InitOne ( sqlite3 * db,
int iDb,
char ** pzErrMsg,
u32 mFlags )

Definition at line 128514 of file sqlite3.c.

128520 {
128521 int rc;
128522 int i;
128523#ifndef SQLITE_OMIT_DEPRECATED
128524 int size;
128525#endif
128526 Db *pDb;
128527 char const *azArg[6];
128528 int meta[5];
128529 InitData initData;
128530 const char *zSchemaTabName;
128531 int openedTransaction = 0;
128533
128534 assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
128535 assert( iDb>=0 && iDb<db->nDb );
128536 assert( db->aDb[iDb].pSchema );
128537 assert( sqlite3_mutex_held(db->mutex) );
128538 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
128539
128540 db->init.busy = 1;
128541
128542 /* Construct the in-memory representation schema tables (sqlite_schema or
128543 ** sqlite_temp_schema) by invoking the parser directly. The appropriate
128544 ** table name will be inserted automatically by the parser so we can just
128545 ** use the abbreviation "x" here. The parser will also automatically tag
128546 ** the schema table as read-only. */
128547 azArg[0] = "table";
128548 azArg[1] = zSchemaTabName = SCHEMA_TABLE(iDb);
128549 azArg[2] = azArg[1];
128550 azArg[3] = "1";
128551 azArg[4] = "CREATE TABLE x(type text,name text,tbl_name text,"
128552 "rootpage int,sql text)";
128553 azArg[5] = 0;
128554 initData.db = db;
128555 initData.iDb = iDb;
128556 initData.rc = SQLITE_OK;
128557 initData.pzErrMsg = pzErrMsg;
128558 initData.mInitFlags = mFlags;
128559 initData.nInitRow = 0;
128560 initData.mxPage = 0;
128561 sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
128562 db->mDbFlags &= mask;
128563 if( initData.rc ){
128564 rc = initData.rc;
128565 goto error_out;
128566 }
128567
128568 /* Create a cursor to hold the database open
128569 */
128570 pDb = &db->aDb[iDb];
128571 if( pDb->pBt==0 ){
128572 assert( iDb==1 );
128574 rc = SQLITE_OK;
128575 goto error_out;
128576 }
128577
128578 /* If there is not already a read-only (or read-write) transaction opened
128579 ** on the b-tree database, open one now. If a transaction is opened, it
128580 ** will be closed before this function returns. */
128581 sqlite3BtreeEnter(pDb->pBt);
128582 if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){
128583 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
128584 if( rc!=SQLITE_OK ){
128585 sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc));
128586 goto initone_error_out;
128587 }
128588 openedTransaction = 1;
128589 }
128590
128591 /* Get the database meta information.
128592 **
128593 ** Meta values are as follows:
128594 ** meta[0] Schema cookie. Changes with each schema change.
128595 ** meta[1] File format of schema layer.
128596 ** meta[2] Size of the page cache.
128597 ** meta[3] Largest rootpage (auto/incr_vacuum mode)
128598 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
128599 ** meta[5] User version
128600 ** meta[6] Incremental vacuum mode
128601 ** meta[7] unused
128602 ** meta[8] unused
128603 ** meta[9] unused
128604 **
128605 ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
128606 ** the possible values of meta[4].
128607 */
128608 for(i=0; i<ArraySize(meta); i++){
128609 sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
128610 }
128611 if( (db->flags & SQLITE_ResetDatabase)!=0 ){
128612 memset(meta, 0, sizeof(meta));
128613 }
128615
128616 /* If opening a non-empty database, check the text encoding. For the
128617 ** main database, set sqlite3.enc to the encoding of the main database.
128618 ** For an attached db, it is an error if the encoding is not the same
128619 ** as sqlite3.enc.
128620 */
128621 if( meta[BTREE_TEXT_ENCODING-1] ){ /* text encoding */
128622 if( iDb==0 && (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
128623 u8 encoding;
128624#ifndef SQLITE_OMIT_UTF16
128625 /* If opening the main database, set ENC(db). */
128626 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
128627 if( encoding==0 ) encoding = SQLITE_UTF8;
128628#else
128629 encoding = SQLITE_UTF8;
128630#endif
128631 sqlite3SetTextEncoding(db, encoding);
128632 }else{
128633 /* If opening an attached database, the encoding much match ENC(db) */
128634 if( (meta[BTREE_TEXT_ENCODING-1] & 3)!=ENC(db) ){
128635 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
128636 " text encoding as main database");
128637 rc = SQLITE_ERROR;
128638 goto initone_error_out;
128639 }
128640 }
128641 }
128642 pDb->pSchema->enc = ENC(db);
128643
128644 if( pDb->pSchema->cache_size==0 ){
128645#ifndef SQLITE_OMIT_DEPRECATED
128647 if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
128648 pDb->pSchema->cache_size = size;
128649#else
128651#endif
128653 }
128654
128655 /*
128656 ** file_format==1 Version 3.0.0.
128657 ** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
128658 ** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
128659 ** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
128660 */
128661 pDb->pSchema->file_format = (u8)meta[BTREE_FILE_FORMAT-1];
128662 if( pDb->pSchema->file_format==0 ){
128663 pDb->pSchema->file_format = 1;
128664 }
128666 sqlite3SetString(pzErrMsg, db, "unsupported file format");
128667 rc = SQLITE_ERROR;
128668 goto initone_error_out;
128669 }
128670
128671 /* Ticket #2804: When we open a database in the newer file format,
128672 ** clear the legacy_file_format pragma flag so that a VACUUM will
128673 ** not downgrade the database and thus invalidate any descending
128674 ** indices that the user might have created.
128675 */
128676 if( iDb==0 && meta[BTREE_FILE_FORMAT-1]>=4 ){
128677 db->flags &= ~(u64)SQLITE_LegacyFileFmt;
128678 }
128679
128680 /* Read the schema information out of the schema tables
128681 */
128682 assert( db->init.busy );
128683 initData.mxPage = sqlite3BtreeLastPage(pDb->pBt);
128684 {
128685 char *zSql;
128686 zSql = sqlite3MPrintf(db,
128687 "SELECT*FROM\"%w\".%s ORDER BY rowid",
128688 db->aDb[iDb].zDbSName, zSchemaTabName);
128689#ifndef SQLITE_OMIT_AUTHORIZATION
128690 {
128691 sqlite3_xauth xAuth;
128692 xAuth = db->xAuth;
128693 db->xAuth = 0;
128694#endif
128695 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
128696#ifndef SQLITE_OMIT_AUTHORIZATION
128697 db->xAuth = xAuth;
128698 }
128699#endif
128700 if( rc==SQLITE_OK ) rc = initData.rc;
128701 sqlite3DbFree(db, zSql);
128702#ifndef SQLITE_OMIT_ANALYZE
128703 if( rc==SQLITE_OK ){
128704 sqlite3AnalysisLoad(db, iDb);
128705 }
128706#endif
128707 }
128708 if( db->mallocFailed ){
128709 rc = SQLITE_NOMEM_BKPT;
128711 }
128712 if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
128713 /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
128714 ** the schema loaded, even if errors occurred. In this situation the
128715 ** current sqlite3_prepare() operation will fail, but the following one
128716 ** will attempt to compile the supplied statement against whatever subset
128717 ** of the schema was loaded before the error occurred. The primary
128718 ** purpose of this is to allow access to the sqlite_schema table
128719 ** even when its contents have been corrupted.
128720 */
128721 DbSetProperty(db, iDb, DB_SchemaLoaded);
128722 rc = SQLITE_OK;
128723 }
128724
128725 /* Jump here for an error that occurs after successfully allocating
128726 ** curMain and calling sqlite3BtreeEnter(). For an error that occurs
128727 ** before that point, jump to error_out.
128728 */
128729initone_error_out:
128730 if( openedTransaction ){
128731 sqlite3BtreeCommit(pDb->pBt);
128732 }
128733 sqlite3BtreeLeave(pDb->pBt);
128734
128735error_out:
128736 if( rc ){
128737 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
128738 sqlite3OomFault(db);
#define BTREE_TEXT_ENCODING
Definition sqlite3.c:15146
#define SQLITE_MAX_FILE_FORMAT
Definition sqlite3.c:14181
SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *, int iDB)
Definition sqlite3.c:109418
SQLITE_PRIVATE int sqlite3InitCallback(void *, int, char **, char **)
Definition sqlite3.c:128419
#define DbSetProperty(D, I, P)
Definition sqlite3.c:16650
#define BTREE_DEFAULT_CACHE_SIZE
Definition sqlite3.c:15144
SQLITE_PRIVATE int sqlite3BtreeCommit(Btree *)
Definition sqlite3.c:68594
SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree *, int)
Definition sqlite3.c:67248
int cache_size
Definition sqlite3.c:16641

References sqlite3::aDb, ArraySize, BTREE_DEFAULT_CACHE_SIZE, BTREE_FILE_FORMAT, BTREE_SCHEMA_VERSION, BTREE_TEXT_ENCODING, sqlite3::sqlite3InitInfo::busy, Schema::cache_size, InitData::db, DB_SchemaLoaded, DBFLAG_EncodingFixed, DBFLAG_SchemaKnownOk, DbSetProperty, Schema::enc, ENC, Schema::file_format, sqlite3::flags, InitData::iDb, sqlite3::init, sqlite3::mallocFailed, mask, sqlite3::mDbFlags, InitData::mInitFlags, sqlite3::mutex, InitData::mxPage, InitData::nInitRow, Db::pBt, Db::pSchema, InitData::pzErrMsg, InitData::rc, Schema::schema_cookie, SCHEMA_TABLE, sqlite3_exec(), sqlite3_mutex_held(), sqlite3AbsInt32(), sqlite3AnalysisLoad(), sqlite3BtreeBeginTrans(), sqlite3BtreeCommit(), sqlite3BtreeEnter(), sqlite3BtreeGetMeta(), sqlite3BtreeIsInReadTrans(), sqlite3BtreeLastPage(), sqlite3BtreeLeave(), sqlite3BtreeSetCacheSize(), sqlite3DbFree(), sqlite3ErrStr(), sqlite3InitCallback(), sqlite3MPrintf(), sqlite3OomFault(), sqlite3ResetAllSchemasOfConnection(), sqlite3ResetOneSchema(), sqlite3SetString(), sqlite3SetTextEncoding(), SQLITE_DEFAULT_CACHE_SIZE, SQLITE_ERROR, SQLITE_IOERR_NOMEM, SQLITE_LegacyFileFmt, SQLITE_MAX_FILE_FORMAT, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_NoSchemaError, SQLITE_OK, SQLITE_ResetDatabase, SQLITE_UTF8, sqlite3::xAuth, and Db::zDbSName.

Referenced by sqlite3Init(), and sqlite3VdbeExec().

◆ sqlite3InRhsIsConstant()

static int sqlite3InRhsIsConstant ( Expr * pIn)
static

Definition at line 102136 of file sqlite3.c.

102142 {
102143 Expr *pLHS;
102144 int res;
102145 assert( !ExprHasProperty(pIn, EP_xIsSelect) );

References EP_xIsSelect, ExprHasProperty, Expr::pLeft, and sqlite3ExprIsConstant().

Referenced by sqlite3FindInIndex().

◆ sqlite3Insert()

SQLITE_PRIVATE void sqlite3Insert ( Parse * pParse,
SrcList * pTabList,
Select * pSelect,
IdList * pColumn,
int onError,
Upsert * pUpsert )

Definition at line 121167 of file sqlite3.c.

121168 : loop over rows of intermediate table
121169** transfer values form intermediate table into <table>
121170** end loop
121171** D: cleanup
121172*/
121174 Parse *pParse, /* Parser context */
121175 SrcList *pTabList, /* Name of table into which we are inserting */
121176 Select *pSelect, /* A SELECT statement to use as the data source */
121177 IdList *pColumn, /* Column names corresponding to IDLIST, or NULL. */
121178 int onError, /* How to handle constraint errors */
121179 Upsert *pUpsert /* ON CONFLICT clauses for upsert, or NULL */
121180){
121181 sqlite3 *db; /* The main database structure */
121182 Table *pTab; /* The table to insert into. aka TABLE */
121183 int i, j; /* Loop counters */
121184 Vdbe *v; /* Generate code into this virtual machine */
121185 Index *pIdx; /* For looping over indices of the table */
121186 int nColumn; /* Number of columns in the data */
121187 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
121188 int iDataCur = 0; /* VDBE cursor that is the main data repository */
121189 int iIdxCur = 0; /* First index cursor */
121190 int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
121191 int endOfLoop; /* Label for the end of the insertion loop */
121192 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
121193 int addrInsTop = 0; /* Jump to label "D" */
121194 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
121195 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
121196 int iDb; /* Index of database holding TABLE */
121197 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
121198 u8 appendFlag = 0; /* True if the insert is likely to be an append */
121199 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
121200 u8 bIdListInOrder; /* True if IDLIST is in table order */
121201 ExprList *pList = 0; /* List of VALUES() to be inserted */
121202 int iRegStore; /* Register in which to store next column */
121203
121204 /* Register allocations */
121205 int regFromSelect = 0;/* Base register for data coming from SELECT */
121206 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
121207 int regRowCount = 0; /* Memory cell used for the row counter */
121208 int regIns; /* Block of regs holding rowid+data being inserted */
121209 int regRowid; /* registers holding insert rowid */
121210 int regData; /* register holding first column to insert */
121211 int *aRegIdx = 0; /* One register allocated to each index */
121212
121213#ifndef SQLITE_OMIT_TRIGGER
121214 int isView; /* True if attempting to insert into a view */
121215 Trigger *pTrigger; /* List of triggers on pTab, if required */
121216 int tmask; /* Mask of trigger times */
121217#endif
121218
121219 db = pParse->db;
121220 if( pParse->nErr || db->mallocFailed ){
121221 goto insert_cleanup;
121222 }
121223 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
121224
121225 /* If the Select object is really just a simple VALUES() list with a
121226 ** single row (the common case) then keep that one row of values
121227 ** and discard the other (unused) parts of the pSelect object
121228 */
121229 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
121230 pList = pSelect->pEList;
121231 pSelect->pEList = 0;
121232 sqlite3SelectDelete(db, pSelect);
121233 pSelect = 0;
121234 }
121235
121236 /* Locate the table into which we will be inserting new information.
121237 */
121238 assert( pTabList->nSrc==1 );
121239 pTab = sqlite3SrcListLookup(pParse, pTabList);
121240 if( pTab==0 ){
121241 goto insert_cleanup;
121242 }
121243 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
121244 assert( iDb<db->nDb );
121245 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0,
121246 db->aDb[iDb].zDbSName) ){
121247 goto insert_cleanup;
121248 }
121249 withoutRowid = !HasRowid(pTab);
121250
121251 /* Figure out if we have any triggers and if the table being
121252 ** inserted into is a view
121253 */
121254#ifndef SQLITE_OMIT_TRIGGER
121255 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
121256 isView = pTab->pSelect!=0;
121257#else
121258# define pTrigger 0
121259# define tmask 0
121260# define isView 0
121261#endif
121262#ifdef SQLITE_OMIT_VIEW
121263# undef isView
121264# define isView 0
121265#endif
121266 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
121267
121268 /* If pTab is really a view, make sure it has been initialized.
121269 ** ViewGetColumnNames() is a no-op if pTab is not a view.
121270 */
121271 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
121272 goto insert_cleanup;
121273 }
121274
121275 /* Cannot insert into a read-only table.
121276 */
121277 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
121278 goto insert_cleanup;
121279 }
121280
121281 /* Allocate a VDBE
121282 */
121283 v = sqlite3GetVdbe(pParse);
121284 if( v==0 ) goto insert_cleanup;
121285 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
121286 sqlite3BeginWriteOperation(pParse, pSelect || pTrigger, iDb);
121287
121288#ifndef SQLITE_OMIT_XFER_OPT
121289 /* If the statement is of the form
121290 **
121291 ** INSERT INTO <table1> SELECT * FROM <table2>;
121292 **
121293 ** Then special optimizations can be applied that make the transfer
121294 ** very fast and which reduce fragmentation of indices.
121295 **
121296 ** This is the 2nd template.
121297 */
121298 if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){
121299 assert( !pTrigger );
121300 assert( pList==0 );
121301 goto insert_end;
121302 }
121303#endif /* SQLITE_OMIT_XFER_OPT */
121304
121305 /* If this is an AUTOINCREMENT table, look up the sequence number in the
121306 ** sqlite_sequence table and store it in memory cell regAutoinc.
121307 */
121308 regAutoinc = autoIncBegin(pParse, iDb, pTab);
121309
121310 /* Allocate a block registers to hold the rowid and the values
121311 ** for all columns of the new row.
121312 */
121313 regRowid = regIns = pParse->nMem+1;
121314 pParse->nMem += pTab->nCol + 1;
121315 if( IsVirtual(pTab) ){
121316 regRowid++;
121317 pParse->nMem++;
121318 }
121319 regData = regRowid+1;
121320
121321 /* If the INSERT statement included an IDLIST term, then make sure
121322 ** all elements of the IDLIST really are columns of the table and
121323 ** remember the column indices.
121324 **
121325 ** If the table has an INTEGER PRIMARY KEY column and that column
121326 ** is named in the IDLIST, then record in the ipkColumn variable
121327 ** the index into IDLIST of the primary key column. ipkColumn is
121328 ** the index of the primary key as it appears in IDLIST, not as
121329 ** is appears in the original table. (The index of the INTEGER
121330 ** PRIMARY KEY in the original table is pTab->iPKey.) After this
121331 ** loop, if ipkColumn==(-1), that means that integer primary key
121332 ** is unspecified, and hence the table is either WITHOUT ROWID or
121333 ** it will automatically generated an integer primary key.
121334 **
121335 ** bIdListInOrder is true if the columns in IDLIST are in storage
121336 ** order. This enables an optimization that avoids shuffling the
121337 ** columns into storage order. False negatives are harmless,
121338 ** but false positives will cause database corruption.
121339 */
121340 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
121341 if( pColumn ){
121342 for(i=0; i<pColumn->nId; i++){
121343 pColumn->a[i].idx = -1;
121344 }
121345 for(i=0; i<pColumn->nId; i++){
121346 for(j=0; j<pTab->nCol; j++){
121347 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
121348 pColumn->a[i].idx = j;
121349 if( i!=j ) bIdListInOrder = 0;
121350 if( j==pTab->iPKey ){
121351 ipkColumn = i; assert( !withoutRowid );
121352 }
121353#ifndef SQLITE_OMIT_GENERATED_COLUMNS
121354 if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
121355 sqlite3ErrorMsg(pParse,
121356 "cannot INSERT into generated column \"%s\"",
121357 pTab->aCol[j].zName);
121358 goto insert_cleanup;
121359 }
121360#endif
121361 break;
121362 }
121363 }
121364 if( j>=pTab->nCol ){
121365 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
121366 ipkColumn = i;
121367 bIdListInOrder = 0;
121368 }else{
121369 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
121370 pTabList, 0, pColumn->a[i].zName);
121371 pParse->checkSchema = 1;
121372 goto insert_cleanup;
121373 }
121374 }
121375 }
121376 }
121377
121378 /* Figure out how many columns of data are supplied. If the data
121379 ** is coming from a SELECT statement, then generate a co-routine that
121380 ** produces a single row of the SELECT on each invocation. The
121381 ** co-routine is the common header to the 3rd and 4th templates.
121382 */
121383 if( pSelect ){
121384 /* Data is coming from a SELECT or from a multi-row VALUES clause.
121385 ** Generate a co-routine to run the SELECT. */
121386 int regYield; /* Register holding co-routine entry-point */
121387 int addrTop; /* Top of the co-routine */
121388 int rc; /* Result code */
121389
121390 regYield = ++pParse->nMem;
121391 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
121392 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
121393 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
121394 dest.iSdst = bIdListInOrder ? regData : 0;
121395 dest.nSdst = pTab->nCol;
121396 rc = sqlite3Select(pParse, pSelect, &dest);
121397 regFromSelect = dest.iSdst;
121398 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
121399 sqlite3VdbeEndCoroutine(v, regYield);
121400 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
121401 assert( pSelect->pEList );
121402 nColumn = pSelect->pEList->nExpr;
121403
121404 /* Set useTempTable to TRUE if the result of the SELECT statement
121405 ** should be written into a temporary table (template 4). Set to
121406 ** FALSE if each output row of the SELECT can be written directly into
121407 ** the destination table (template 3).
121408 **
121409 ** A temp table must be used if the table being updated is also one
121410 ** of the tables being read by the SELECT statement. Also use a
121411 ** temp table in the case of row triggers.
121412 */
121413 if( pTrigger || readsTable(pParse, iDb, pTab) ){
121414 useTempTable = 1;
121415 }
121416
121417 if( useTempTable ){
121418 /* Invoke the coroutine to extract information from the SELECT
121419 ** and add it to a transient table srcTab. The code generated
121420 ** here is from the 4th template:
121421 **
121422 ** B: open temp table
121423 ** L: yield X, goto M at EOF
121424 ** insert row from R..R+n into temp table
121425 ** goto L
121426 ** M: ...
121427 */
121428 int regRec; /* Register to hold packed record */
121429 int regTempRowid; /* Register to hold temp table ROWID */
121430 int addrL; /* Label "L" */
121431
121432 srcTab = pParse->nTab++;
121433 regRec = sqlite3GetTempReg(pParse);
121434 regTempRowid = sqlite3GetTempReg(pParse);
121435 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
121436 addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
121437 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
121438 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
121439 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
121440 sqlite3VdbeGoto(v, addrL);
121441 sqlite3VdbeJumpHere(v, addrL);
121442 sqlite3ReleaseTempReg(pParse, regRec);
121443 sqlite3ReleaseTempReg(pParse, regTempRowid);
121444 }
121445 }else{
121446 /* This is the case if the data for the INSERT is coming from a
121447 ** single-row VALUES clause
121448 */
121449 NameContext sNC;
121450 memset(&sNC, 0, sizeof(sNC));
121451 sNC.pParse = pParse;
121452 srcTab = -1;
121453 assert( useTempTable==0 );
121454 if( pList ){
121455 nColumn = pList->nExpr;
121456 if( sqlite3ResolveExprListNames(&sNC, pList) ){
121457 goto insert_cleanup;
121458 }
121459 }else{
121460 nColumn = 0;
121461 }
121462 }
121463
121464 /* If there is no IDLIST term but the table has an integer primary
121465 ** key, the set the ipkColumn variable to the integer primary key
121466 ** column index in the original table definition.
121467 */
121468 if( pColumn==0 && nColumn>0 ){
121469 ipkColumn = pTab->iPKey;
121470#ifndef SQLITE_OMIT_GENERATED_COLUMNS
121471 if( ipkColumn>=0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
121472 testcase( pTab->tabFlags & TF_HasVirtual );
121473 testcase( pTab->tabFlags & TF_HasStored );
121474 for(i=ipkColumn-1; i>=0; i--){
121475 if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){
121476 testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL );
121477 testcase( pTab->aCol[i].colFlags & COLFLAG_STORED );
121478 ipkColumn--;
121479 }
121480 }
121481 }
121482#endif
121483 }
121484
121485 /* Make sure the number of columns in the source data matches the number
121486 ** of columns to be inserted into the table.
121487 */
121488 for(i=0; i<pTab->nCol; i++){
121489 if( pTab->aCol[i].colFlags & COLFLAG_NOINSERT ) nHidden++;
121490 }
121491 if( pColumn==0 && nColumn && nColumn!=(pTab->nCol-nHidden) ){
121492 sqlite3ErrorMsg(pParse,
121493 "table %S has %d columns but %d values were supplied",
121494 pTabList, 0, pTab->nCol-nHidden, nColumn);
121495 goto insert_cleanup;
121496 }
121497 if( pColumn!=0 && nColumn!=pColumn->nId ){
121498 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
121499 goto insert_cleanup;
121500 }
121501
121502 /* Initialize the count of rows to be inserted
121503 */
121504 if( (db->flags & SQLITE_CountRows)!=0
121505 && !pParse->nested
121506 && !pParse->pTriggerTab
121507 ){
121508 regRowCount = ++pParse->nMem;
121509 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
121510 }
121511
121512 /* If this is not a view, open the table and and all indices */
121513 if( !isView ){
121514 int nIdx;
121515 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, -1, 0,
121516 &iDataCur, &iIdxCur);
121517 aRegIdx = sqlite3DbMallocRawNN(db, sizeof(int)*(nIdx+2));
121518 if( aRegIdx==0 ){
121519 goto insert_cleanup;
121520 }
121521 for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
121522 assert( pIdx );
121523 aRegIdx[i] = ++pParse->nMem;
121524 pParse->nMem += pIdx->nColumn;
121525 }
121526 aRegIdx[i] = ++pParse->nMem; /* Register to store the table record */
121527 }
121528#ifndef SQLITE_OMIT_UPSERT
121529 if( pUpsert ){
121530 if( IsVirtual(pTab) ){
121531 sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
121532 pTab->zName);
121533 goto insert_cleanup;
121534 }
121535 if( pTab->pSelect ){
121536 sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
121537 goto insert_cleanup;
121538 }
121539 if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
121540 goto insert_cleanup;
121541 }
121542 pTabList->a[0].iCursor = iDataCur;
121543 pUpsert->pUpsertSrc = pTabList;
121544 pUpsert->regData = regData;
121545 pUpsert->iDataCur = iDataCur;
121546 pUpsert->iIdxCur = iIdxCur;
121547 if( pUpsert->pUpsertTarget ){
121548 sqlite3UpsertAnalyzeTarget(pParse, pTabList, pUpsert);
121549 }
121550 }
121551#endif
121552
121553
121554 /* This is the top of the main insertion loop */
121555 if( useTempTable ){
121556 /* This block codes the top of loop only. The complete loop is the
121557 ** following pseudocode (template 4):
121558 **
121559 ** rewind temp table, if empty goto D
121560 ** C: loop over rows of intermediate table
121561 ** transfer values form intermediate table into <table>
121562 ** end loop
121563 ** D: ...
121564 */
121565 addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v);
121566 addrCont = sqlite3VdbeCurrentAddr(v);
121567 }else if( pSelect ){
121568 /* This block codes the top of loop only. The complete loop is the
121569 ** following pseudocode (template 3):
121570 **
121571 ** C: yield X, at EOF goto D
121572 ** insert the select result into <table> from R..R+n
121573 ** goto C
121574 ** D: ...
121575 */
121576 sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0);
121577 addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
121578 VdbeCoverage(v);
121579 if( ipkColumn>=0 ){
121580 /* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the
121581 ** SELECT, go ahead and copy the value into the rowid slot now, so that
121582 ** the value does not get overwritten by a NULL at tag-20191021-002. */
121583 sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
121584 }
121585 }
121586
121587 /* Compute data for ordinary columns of the new entry. Values
121588 ** are written in storage order into registers starting with regData.
121589 ** Only ordinary columns are computed in this loop. The rowid
121590 ** (if there is one) is computed later and generated columns are
121591 ** computed after the rowid since they might depend on the value
121592 ** of the rowid.
121593 */
121594 nHidden = 0;
121595 iRegStore = regData; assert( regData==regRowid+1 );
121596 for(i=0; i<pTab->nCol; i++, iRegStore++){
121597 int k;
121598 u32 colFlags;
121599 assert( i>=nHidden );
121600 if( i==pTab->iPKey ){
121601 /* tag-20191021-002: References to the INTEGER PRIMARY KEY are filled
121602 ** using the rowid. So put a NULL in the IPK slot of the record to avoid
121603 ** using excess space. The file format definition requires this extra
121604 ** NULL - we cannot optimize further by skipping the column completely */
121605 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
121606 continue;
121607 }
121608 if( ((colFlags = pTab->aCol[i].colFlags) & COLFLAG_NOINSERT)!=0 ){
121609 nHidden++;
121610 if( (colFlags & COLFLAG_VIRTUAL)!=0 ){
121611 /* Virtual columns do not participate in OP_MakeRecord. So back up
121612 ** iRegStore by one slot to compensate for the iRegStore++ in the
121613 ** outer for() loop */
121614 iRegStore--;
121615 continue;
121616 }else if( (colFlags & COLFLAG_STORED)!=0 ){
121617 /* Stored columns are computed later. But if there are BEFORE
121618 ** triggers, the slots used for stored columns will be OP_Copy-ed
121619 ** to a second block of registers, so the register needs to be
121620 ** initialized to NULL to avoid an uninitialized register read */
121621 if( tmask & TRIGGER_BEFORE ){
121622 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
121623 }
121624 continue;
121625 }else if( pColumn==0 ){
121626 /* Hidden columns that are not explicitly named in the INSERT
121627 ** get there default value */
121628 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
121629 continue;
121630 }
121631 }
121632 if( pColumn ){
121633 for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){}
121634 if( j>=pColumn->nId ){
121635 /* A column not named in the insert column list gets its
121636 ** default value */
121637 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
121638 continue;
121639 }
121640 k = j;
121641 }else if( nColumn==0 ){
121642 /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
121643 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
121644 continue;
121645 }else{
121646 k = i - nHidden;
121647 }
121648
121649 if( useTempTable ){
121650 sqlite3VdbeAddOp3(v, OP_Column, srcTab, k, iRegStore);
121651 }else if( pSelect ){
121652 if( regFromSelect!=regData ){
121653 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
121654 }
121655 }else{
121656 sqlite3ExprCode(pParse, pList->a[k].pExpr, iRegStore);
121657 }
121658 }
121659
121660
121661 /* Run the BEFORE and INSTEAD OF triggers, if there are any
121662 */
121663 endOfLoop = sqlite3VdbeMakeLabel(pParse);
121664 if( tmask & TRIGGER_BEFORE ){
121665 int regCols = sqlite3GetTempRange(pParse, pTab->nCol+1);
121666
121667 /* build the NEW.* reference row. Note that if there is an INTEGER
121668 ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
121669 ** translated into a unique ID for the row. But on a BEFORE trigger,
121670 ** we do not know what the unique ID will be (because the insert has
121671 ** not happened yet) so we substitute a rowid of -1
121672 */
121673 if( ipkColumn<0 ){
121674 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
121675 }else{
121676 int addr1;
121677 assert( !withoutRowid );
121678 if( useTempTable ){
121679 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
121680 }else{
121681 assert( pSelect==0 ); /* Otherwise useTempTable is true */
121682 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
121683 }
121684 addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
121685 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
121686 sqlite3VdbeJumpHere(v, addr1);
121688 }
121689
121690 /* Cannot have triggers on a virtual table. If it were possible,
121691 ** this block would have to account for hidden column.
121692 */
121693 assert( !IsVirtual(pTab) );
121694
121695 /* Copy the new data already generated. */
121696 assert( pTab->nNVCol>0 );
121697 sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1);
121698
121699#ifndef SQLITE_OMIT_GENERATED_COLUMNS
121700 /* Compute the new value for generated columns after all other
121701 ** columns have already been computed. This must be done after
121702 ** computing the ROWID in case one of the generated columns
121703 ** refers to the ROWID. */
121704 if( pTab->tabFlags & TF_HasGenerated ){
121705 testcase( pTab->tabFlags & TF_HasVirtual );
121706 testcase( pTab->tabFlags & TF_HasStored );
121707 sqlite3ComputeGeneratedColumns(pParse, regCols+1, pTab);
121708 }
121709#endif
121710
121711 /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
121712 ** do not attempt any conversions before assembling the record.
121713 ** If this is a real table, attempt conversions as required by the
121714 ** table column affinities.
121715 */
121716 if( !isView ){
121717 sqlite3TableAffinity(v, pTab, regCols+1);
121718 }
121719
121720 /* Fire BEFORE or INSTEAD OF triggers */
121721 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
121722 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
121723
121724 sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
121725 }
121726
121727 if( !isView ){
121728 if( IsVirtual(pTab) ){
121729 /* The row that the VUpdate opcode will delete: none */
121730 sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
121731 }
121732 if( ipkColumn>=0 ){
121733 /* Compute the new rowid */
121734 if( useTempTable ){
121735 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
121736 }else if( pSelect ){
121737 /* Rowid already initialized at tag-20191021-001 */
121738 }else{
121739 Expr *pIpk = pList->a[ipkColumn].pExpr;
121740 if( pIpk->op==TK_NULL && !IsVirtual(pTab) ){
121741 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
121742 appendFlag = 1;
121743 }else{
121744 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
121745 }
121746 }
121747 /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
121748 ** to generate a unique primary key value.
121749 */
121750 if( !appendFlag ){
121751 int addr1;
121752 if( !IsVirtual(pTab) ){
121753 addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v);
121754 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
121755 sqlite3VdbeJumpHere(v, addr1);
121756 }else{
121757 addr1 = sqlite3VdbeCurrentAddr(v);
121758 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, addr1+2); VdbeCoverage(v);
121759 }
121760 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
121761 }
121762 }else if( IsVirtual(pTab) || withoutRowid ){
121763 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
121764 }else{
121765 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
121766 appendFlag = 1;
121767 }
121768 autoIncStep(pParse, regAutoinc, regRowid);
121769
121770#ifndef SQLITE_OMIT_GENERATED_COLUMNS
121771 /* Compute the new value for generated columns after all other
121772 ** columns have already been computed. This must be done after
121773 ** computing the ROWID in case one of the generated columns
121774 ** is derived from the INTEGER PRIMARY KEY. */
121775 if( pTab->tabFlags & TF_HasGenerated ){
121776 sqlite3ComputeGeneratedColumns(pParse, regRowid+1, pTab);
121777 }
121778#endif
121779
121780 /* Generate code to check constraints and generate index keys and
121781 ** do the insertion.
121782 */
121783#ifndef SQLITE_OMIT_VIRTUALTABLE
121784 if( IsVirtual(pTab) ){
121785 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
121786 sqlite3VtabMakeWritable(pParse, pTab);
121787 sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB);
121788 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
121789 sqlite3MayAbort(pParse);
121790 }else
121791#endif
121792 {
121793 int isReplace; /* Set to true if constraints may cause a replace */
121794 int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
121795 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
121796 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
121797 );
121798 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
121799
121800 /* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
121801 ** constraints or (b) there are no triggers and this table is not a
121802 ** parent table in a foreign key constraint. It is safe to set the
121803 ** flag in the second case as if any REPLACE constraint is hit, an
121804 ** OP_Delete or OP_IdxDelete instruction will be executed on each
121805 ** cursor that is disturbed. And these instructions both clear the
121806 ** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
121807 ** functionality. */
121808 bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
121809 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
121810 regIns, aRegIdx, 0, appendFlag, bUseSeek
121811 );
121812 }
121813 }
121814
121815 /* Update the count of rows that are inserted
121816 */
121817 if( regRowCount ){
121818 sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
121819 }
121820
121821 if( pTrigger ){
121822 /* Code AFTER triggers */
121823 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_AFTER,
121824 pTab, regData-2-pTab->nCol, onError, endOfLoop);
121825 }
121826
121827 /* The bottom of the main insertion loop, if the data source
121828 ** is a SELECT statement.
121829 */
121830 sqlite3VdbeResolveLabel(v, endOfLoop);
121831 if( useTempTable ){
121832 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
121833 sqlite3VdbeJumpHere(v, addrInsTop);
121834 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
121835 }else if( pSelect ){
121836 sqlite3VdbeGoto(v, addrCont);
121837#ifdef SQLITE_DEBUG
121838 /* If we are jumping back to an OP_Yield that is preceded by an
121839 ** OP_ReleaseReg, set the p5 flag on the OP_Goto so that the
121840 ** OP_ReleaseReg will be included in the loop. */
121841 if( sqlite3VdbeGetOp(v, addrCont-1)->opcode==OP_ReleaseReg ){
121842 assert( sqlite3VdbeGetOp(v, addrCont)->opcode==OP_Yield );
121843 sqlite3VdbeChangeP5(v, 1);
121844 }
121845#endif
121846 sqlite3VdbeJumpHere(v, addrInsTop);
121847 }
121848
121849insert_end:
121850 /* Update the sqlite_sequence table by storing the content of the
121851 ** maximum rowid counter values recorded while inserting into
121852 ** autoincrement tables.
121853 */
121854 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
121855 sqlite3AutoincrementEnd(pParse);
121856 }
121857
121858 /*
121859 ** Return the number of rows inserted. If this routine is
121860 ** generating code because of a call to sqlite3NestedParse(), do not
121861 ** invoke the callback function.
121862 */
121863 if( regRowCount ){
121864 sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
121865 sqlite3VdbeSetNumCols(v, 1);
121866 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC);
121867 }
121868
121869insert_cleanup:
121870 sqlite3SrcListDelete(db, pTabList);
#define COLFLAG_NOINSERT
Definition sqlite3.c:17354
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse *, Table *, int *, int, int, int, int, u8, u8, int, int *, int *, Upsert *)
Definition sqlite3.c:122039
SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(Parse *, SrcList *, Upsert *)
Definition sqlite3.c:138981
SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse *, Table *, int, int, int, int *, int, int, int)
Definition sqlite3.c:122833
static int readsTable(Parse *p, int iDb, Table *pTab)
Definition sqlite3.c:120717
SQLITE_PRIVATE int sqlite3VdbeHasSubProgram(Vdbe *)
Definition sqlite3.c:78926
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *, Expr *, int)
Definition sqlite3.c:104378
#define OP_SoftNull
Definition sqlite3.c:15639
#define OP_ReleaseReg
Definition sqlite3.c:15738
static int autoIncBegin(Parse *pParse, int iDb, Table *pTab)
Definition sqlite3.c:120888
static int xferOptimization(Parse *pParse, Table *pDest, Select *pSelect, int onError, int iDbDest)
Definition sqlite3.c:123069
#define TF_OOOHidden
Definition sqlite3.c:17546
static void autoIncStep(Parse *pParse, int memId, int regRowid)
Definition sqlite3.c:120998
int iDataCur
Definition sqlite3.c:18418
int iIdxCur
Definition sqlite3.c:18419

References ExprList::a, IdList::a, SrcList::a, Table::aCol, sqlite3::aDb, autoIncBegin(), autoIncStep(), Parse::checkSchema, COLFLAG_GENERATED, COLFLAG_NOINSERT, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, COLNAME_NAME, Parse::db, sqlite3::flags, HasRowid, SrcList::SrcList_item::iCursor, Upsert::iDataCur, IdList::IdList_item::idx, Upsert::iIdxCur, Table::iPKey, SelectDest::iSDParm, SelectDest::iSdst, IsVirtual, sqlite3::mallocFailed, Table::nCol, Index::nColumn, Parse::nErr, Parse::nested, ExprList::nExpr, IdList::nId, Parse::nMem, Table::nNVCol, SelectDest::nSdst, SrcList::nSrc, Parse::nTab, OE_Abort, OE_Default, Expr::op, OP_AddImm, OP_Close, OP_Column, OP_Copy, OP_InitCoroutine, OP_Insert, OP_Integer, OP_IsNull, OP_MakeRecord, OP_MustBeInt, OP_NewRowid, OP_Next, OP_NotNull, OP_Null, OP_OpenEphemeral, OP_OpenWrite, OP_ReleaseReg, OP_ResultRow, OP_Rewind, OP_SCopy, OP_SoftNull, OP_VUpdate, OP_Yield, P4_VTAB, Column::pDflt, Select::pEList, ExprList::ExprList_item::pExpr, Table::pIndex, Index::pNext, NameContext::pParse, Select::pPrior, Table::pSchema, Table::pSelect, Parse::pTriggerTab, Upsert::pUpsertSrc, Upsert::pUpsertTarget, readsTable(), Upsert::regData, Select::selFlags, SF_Values, sqlite3AuthCheck(), sqlite3AutoincrementEnd(), sqlite3BeginWriteOperation(), sqlite3CodeRowTrigger(), sqlite3CompleteInsertion(), sqlite3ComputeGeneratedColumns(), sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3ErrorMsg(), sqlite3ExprCode(), sqlite3ExprCodeFactorable(), sqlite3ExprListDelete(), sqlite3FkCheck(), sqlite3GenerateConstraintChecks(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3GetVTable(), sqlite3HasExplicitNulls(), sqlite3IdListDelete(), sqlite3IsReadOnly(), sqlite3IsRowid(), sqlite3MayAbort(), sqlite3OpenTableAndIndices(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3ResolveExprListNames(), sqlite3SchemaToIndex(), sqlite3Select(), sqlite3SelectDelete(), sqlite3SelectDestInit(), sqlite3SrcListDelete(), sqlite3SrcListLookup(), sqlite3StrICmp(), sqlite3TableAffinity(), sqlite3TriggersExist(), sqlite3UpsertAnalyzeTarget(), sqlite3UpsertDelete(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), sqlite3VdbeCountChanges(), sqlite3VdbeCurrentAddr(), sqlite3VdbeEndCoroutine(), sqlite3VdbeGetOp(), sqlite3VdbeGoto(), sqlite3VdbeHasSubProgram(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeReleaseRegisters, sqlite3VdbeResolveLabel(), sqlite3VdbeSetColName(), sqlite3VdbeSetNumCols(), sqlite3ViewGetColumnNames(), sqlite3VtabMakeWritable(), SQLITE_CountRows, SQLITE_INSERT, SQLITE_STATIC, SRT_Coroutine, Table::tabFlags, testcase, TF_HasGenerated, TF_HasStored, TF_HasVirtual, TF_OOOHidden, TK_INSERT, TK_NULL, TRIGGER_AFTER, TRIGGER_BEFORE, VdbeCoverage, xferOptimization(), Db::zDbSName, Column::zName, Table::zName, and IdList::IdList_item::zName.

Referenced by yy_reduce().

◆ sqlite3InsertBuiltinFuncs()

SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs ( FuncDef * aDef,
int nDef )

Definition at line 115886 of file sqlite3.c.

115895 {
115896 int i;
115897 for(i=0; i<nDef; i++){
115898 FuncDef *pOther;
115899 const char *zName = aDef[i].zName;
115900 int nName = sqlite3Strlen30(zName);
115901 int h = SQLITE_FUNC_HASH(zName[0], nName);
115902 assert( zName[0]>='a' && zName[0]<='z' );
115903 pOther = sqlite3FunctionSearch(h, zName);
115904 if( pOther ){
115905 assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
115906 aDef[i].pNext = pOther->pNext;
115907 pOther->pNext = &aDef[i];
115908 }else{

Referenced by sqlite3RegisterBuiltinFunctions(), and sqlite3RegisterDateTimeFunctions().

◆ sqlite3Int64ToText()

SQLITE_PRIVATE void sqlite3Int64ToText ( i64 v,
char * zOut )

Definition at line 31783 of file sqlite3.c.

31789 {
31790 int i;
31791 u64 x;
31792 char zTemp[22];
31793 if( v<0 ){
31794 x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
31795 }else{
31796 x = v;
31797 }
31798 i = sizeof(zTemp)-2;
31799 zTemp[sizeof(zTemp)-1] = 0;
31800 do{

References SMALLEST_INT64.

Referenced by strftimeFunc(), and vdbeMemRenderNum().

◆ sqlite3IntFloatCompare()

static int sqlite3IntFloatCompare ( i64 i,
double r )
static

Definition at line 82026 of file sqlite3.c.

82032 {
82033 if( sizeof(LONGDOUBLE_TYPE)>8 ){
82035 if( x<r ) return -1;
82036 if( x>r ) return +1;
82037 return 0;
82038 }else{
82039 i64 y;
82040 double s;
82041 if( r<-9223372036854775808.0 ) return +1;
82042 if( r>=9223372036854775808.0 ) return -1;
82043 y = (i64)r;
82044 if( i<y ) return -1;
82045 if( i>y ) return +1;

References LONGDOUBLE_TYPE, and s.

Referenced by sqlite3MemCompare(), and sqlite3VdbeRecordCompareWithSkip().

◆ sqlite3InvalidFunction()

static void sqlite3InvalidFunction ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 163016 of file sqlite3.c.

163026 {
163027 const char *zName = (const char*)sqlite3_user_data(context);
163028 char *zErr;

References sqlite3_free(), sqlite3_mprintf(), sqlite3_result_error(), sqlite3_user_data(), UNUSED_PARAMETER2, and zName.

Referenced by sqlite3_overload_function().

◆ sqlite3InvokeBusyHandler()

SQLITE_PRIVATE int sqlite3InvokeBusyHandler ( BusyHandler * p)

Definition at line 162661 of file sqlite3.c.

162667 {
162668 int rc;
162669 if( p->xBusyHandler==0 || p->nBusy<0 ) return 0;
162670 rc = p->xBusyHandler(p->pBusyArg, p->nBusy);
162671 if( rc==0 ){
void * pBusyArg
Definition sqlite3.c:14566

References BusyHandler::nBusy, BusyHandler::pBusyArg, and BusyHandler::xBusyHandler.

◆ sqlite3IsBinary()

SQLITE_PRIVATE int sqlite3IsBinary ( const CollSeq * p)

Definition at line 162023 of file sqlite3.c.

Referenced by constInsert(), and termIsEquivalence().

◆ sqlite3IsIdChar()

SQLITE_PRIVATE int sqlite3IsIdChar ( u8 c)

Definition at line 159925 of file sqlite3.c.

Referenced by renameEditSql(), sqlite3_compileoption_used(), and sqlite3RunParser().

◆ sqlite3IsLikeFunction()

SQLITE_PRIVATE int sqlite3IsLikeFunction ( sqlite3 * db,
Expr * pExpr,
int * pIsNocase,
char * aWc )

Definition at line 118909 of file sqlite3.c.

118915 {
118916 FuncDef *pDef;
118917 int nExpr;
118918 if( pExpr->op!=TK_FUNCTION || !pExpr->x.pList ){
118919 return 0;
118920 }
118921 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
118922 nExpr = pExpr->x.pList->nExpr;
118923 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
118924#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
118925 if( pDef==0 ) return 0;
118926#endif
118927 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
118928 return 0;
118929 }
118930
118931 /* The memcpy() statement assumes that the wildcard characters are
118932 ** the first three statements in the compareInfo structure. The
118933 ** asserts() that follow verify that assumption
118934 */
118935 memcpy(aWc, pDef->pUserData, 3);
118936 assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
118937 assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
118938 assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
118939
118940 if( nExpr<3 ){
118941 aWc[3] = 0;
118942 }else{
118943 Expr *pEscape = pExpr->x.pList->a[2].pExpr;
118944 char *zEscape;
118945 if( pEscape->op!=TK_STRING ) return 0;
118946 zEscape = pEscape->u.zToken;
118947 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
118948 if( zEscape[0]==aWc[0] ) return 0;
118949 if( zEscape[0]==aWc[1] ) return 0;
static const struct compareInfo likeInfoAlt
Definition sqlite3.c:117677
#define SQLITE_FUNC_LIKE
Definition sqlite3.c:17146

References ExprList::a, EP_xIsSelect, ExprHasProperty, FuncDef::funcFlags, likeInfoAlt, compareInfo::matchAll, compareInfo::matchOne, compareInfo::matchSet, NEVER, ExprList::nExpr, Expr::op, ExprList::ExprList_item::pExpr, Expr::pList, FuncDef::pUserData, sqlite3FindFunction(), SQLITE_FUNC_CASE, SQLITE_FUNC_LIKE, SQLITE_UTF8, TK_FUNCTION, TK_STRING, Expr::u, Expr::x, and Expr::zToken.

Referenced by isLikeOrGlob().

◆ sqlite3IsNaN()

SQLITE_PRIVATE int sqlite3IsNaN ( double x)

◆ sqlite3IsReadOnly()

SQLITE_PRIVATE int sqlite3IsReadOnly ( Parse * pParse,
Table * pTab,
int viewOk )

Definition at line 116156 of file sqlite3.c.

116162 {
116163 if( tabIsReadOnly(pParse, pTab) ){
116164 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
116165 return 1;
116166 }
116167#ifndef SQLITE_OMIT_VIEW
116168 if( !viewOk && pTab->pSelect ){
static int tabIsReadOnly(Parse *pParse, Table *pTab)
Definition sqlite3.c:116137

References Table::pSelect, sqlite3ErrorMsg(), tabIsReadOnly(), and Table::zName.

Referenced by sqlite3DeleteFrom(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3IsRowid()

SQLITE_PRIVATE int sqlite3IsRowid ( const char * z)

◆ sqlite3IsShadowTableOf()

SQLITE_PRIVATE int sqlite3IsShadowTableOf ( sqlite3 * db,
Table * pTab,
const char * zName )

Definition at line 112575 of file sqlite3.c.

112581 {
112582 int nName; /* Length of zName */
112583 Module *pMod; /* Module for the virtual table */
112584
112585 if( !IsVirtual(pTab) ) return 0;
112586 nName = sqlite3Strlen30(pTab->zName);
112587 if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
112588 if( zName[nName]!='_' ) return 0;

References sqlite3::aModule, Table::azModuleArg, IsVirtual, sqlite3_module::iVersion, nName, Module::pModule, sqlite3_strnicmp(), sqlite3HashFind(), sqlite3Strlen30(), sqlite3_module::xShadowName, Table::zName, and zName.

Referenced by sqlite3ShadowTableName().

◆ sqlite3IsTrueOrFalse()

SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse ( const char * zIn)

Definition at line 101619 of file sqlite3.c.

References EP_IsFalse, EP_IsTrue, and sqlite3StrICmp().

Referenced by sqlite3ColumnsFromExprList(), and sqlite3ExprIdToTrueFalse().

◆ sqlite3JoinType()

SQLITE_PRIVATE int sqlite3JoinType ( Parse * pParse,
Token * pA,
Token * pB,
Token * pC )

Definition at line 129497 of file sqlite3.c.

129503 {
129504 int jointype = 0;
129505 Token *apAll[3];
129506 Token *p;
129507 /* 0123456789 123456789 123456789 123 */
129508 static const char zKeyText[] = "naturaleftouterightfullinnercross";
129509 static const struct {
129510 u8 i; /* Beginning of keyword text in zKeyText[] */
129511 u8 nChar; /* Length of the keyword in characters */
129512 u8 code; /* Join type mask */
129513 } aKeyword[] = {
129514 /* natural */ { 0, 7, JT_NATURAL },
129515 /* left */ { 6, 4, JT_LEFT|JT_OUTER },
129516 /* outer */ { 10, 5, JT_OUTER },
129517 /* right */ { 14, 5, JT_RIGHT|JT_OUTER },
129518 /* full */ { 19, 4, JT_LEFT|JT_RIGHT|JT_OUTER },
129519 /* inner */ { 23, 5, JT_INNER },
129520 /* cross */ { 28, 5, JT_INNER|JT_CROSS },
129521 };
129522 int i, j;
129523 apAll[0] = pA;
129524 apAll[1] = pB;
129525 apAll[2] = pC;
129526 for(i=0; i<3 && apAll[i]; i++){
129527 p = apAll[i];
129528 for(j=0; j<ArraySize(aKeyword); j++){
129529 if( p->n==aKeyword[j].nChar
129530 && sqlite3StrNICmp((char*)p->z, &zKeyText[aKeyword[j].i], p->n)==0 ){
129531 jointype |= aKeyword[j].code;
129532 break;
129533 }
129534 }
129535 testcase( j==0 || j==1 || j==2 || j==3 || j==4 || j==5 || j==6 );
129536 if( j>=ArraySize(aKeyword) ){
129537 jointype |= JT_ERROR;
129538 break;
129539 }
129540 }
129541 if(
129542 (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) ||
129543 (jointype & JT_ERROR)!=0
129544 ){
129545 const char *zSp = " ";
129546 assert( pB!=0 );
129547 if( pC==0 ){ zSp++; }
129548 sqlite3ErrorMsg(pParse, "unknown or unsupported join type: "
129549 "%T %T%s%T", pA, pB, zSp, pC);
129550 jointype = JT_INNER;
129551 }else if( (jointype & JT_OUTER)!=0
129552 && (jointype & (JT_LEFT|JT_RIGHT))!=JT_LEFT ){
#define JT_ERROR
Definition sqlite3.c:18293
#define JT_INNER
Definition sqlite3.c:18287
#define JT_CROSS
Definition sqlite3.c:18288

References ArraySize, JT_CROSS, JT_ERROR, JT_INNER, JT_LEFT, JT_NATURAL, JT_OUTER, JT_RIGHT, Token::n, sqlite3ErrorMsg(), sqlite3StrNICmp, testcase, and Token::z.

Referenced by yy_reduce().

◆ sqlite3JournalIsInMemory()

◆ sqlite3JournalModename()

SQLITE_PRIVATE const char * sqlite3JournalModename ( int eMode)

Definition at line 125998 of file sqlite3.c.

126004 {
126005 static char * const azModeName[] = {
126006 "delete", "persist", "off", "truncate", "memory"
126007#ifndef SQLITE_OMIT_WAL
126008 , "wal"
126009#endif
126010 };
126011 assert( PAGER_JOURNALMODE_DELETE==0 );
126012 assert( PAGER_JOURNALMODE_PERSIST==1 );
126013 assert( PAGER_JOURNALMODE_OFF==2 );
126014 assert( PAGER_JOURNALMODE_TRUNCATE==3 );
126015 assert( PAGER_JOURNALMODE_MEMORY==4 );

References ArraySize, PAGER_JOURNALMODE_DELETE, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_OFF, PAGER_JOURNALMODE_PERSIST, PAGER_JOURNALMODE_TRUNCATE, and PAGER_JOURNALMODE_WAL.

Referenced by sqlite3Pragma(), and sqlite3VdbeExec().

◆ sqlite3JournalOpen()

SQLITE_PRIVATE int sqlite3JournalOpen ( sqlite3_vfs * pVfs,
const char * zName,
sqlite3_file * pJfd,
int flags,
int nSpill )

Definition at line 97412 of file sqlite3.c.

97424 {
97425 MemJournal *p = (MemJournal*)pJfd;
97426
97427 /* Zero the file-handle object. If nSpill was passed zero, initialize
97428 ** it using the sqlite3OsOpen() function of the underlying VFS. In this
97429 ** case none of the code in this module is executed as a result of calls
97430 ** made on the journal file-handle. */
97431 memset(p, 0, sizeof(MemJournal));
97432 if( nSpill==0 ){
97433 return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0);
97434 }
97435
97436 if( nSpill>0 ){
97437 p->nChunkSize = nSpill;
97438 }else{
97441 }
97442
struct FileChunk FileChunk
Definition sqlite3.c:97099
#define MEMJOURNAL_DFLT_FILECHUNKSIZE
Definition sqlite3.c:97115
static const struct sqlite3_io_methods MemJournalMethods
Definition sqlite3.c:97378

References fileChunkSize, MemJournal::flags, MEMJOURNAL_DFLT_FILECHUNKSIZE, MemJournalMethods, MemJournal::nChunkSize, MemJournal::nSpill, sqlite3_file::pMethods, MemJournal::pVfs, sqlite3OsOpen(), MemJournal::zJournal, and zName.

Referenced by openSubJournal(), and pager_open_journal().

◆ sqlite3JournalSize()

SQLITE_PRIVATE int sqlite3JournalSize ( sqlite3_vfs * pVfs)

Definition at line 97495 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ sqlite3KeyInfoAlloc()

SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoAlloc ( sqlite3 * db,
int N,
int X )

Definition at line 130589 of file sqlite3.c.

130595 {
130596 int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
130597 KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
130598 if( p ){
130599 p->aSortFlags = (u8*)&p->aColl[N+X];
130600 p->nKeyField = (u16)N;
130601 p->nAllField = (u16)(N+X);
130602 p->enc = ENC(db);
130603 p->db = db;
130604 p->nRef = 1;
u32 nRef
Definition sqlite3.c:17680
sqlite3 * db
Definition sqlite3.c:17684

Referenced by multiSelect(), multiSelectOrderBy(), multiSelectOrderByKeyInfo(), sqlite3CodeRhsOfIN(), sqlite3KeyInfoFromExprList(), and sqlite3KeyInfoOfIndex().

◆ sqlite3KeyInfoFromExprList()

SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoFromExprList ( Parse * pParse,
ExprList * pList,
int iStart,
int nExtra )

Definition at line 130652 of file sqlite3.c.

130663 {
130664 int nExpr;
130665 KeyInfo *pInfo;
130666 struct ExprList_item *pItem;
130667 sqlite3 *db = pParse->db;
130668 int i;
130669
130670 nExpr = pList->nExpr;
130671 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
130672 if( pInfo ){
130673 assert( sqlite3KeyInfoIsWriteable(pInfo) );
130674 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){

References ExprList::a, KeyInfo::aColl, KeyInfo::aSortFlags, Parse::db, ExprList::nExpr, sqlite3ExprNNCollSeq(), and sqlite3KeyInfoAlloc().

Referenced by resetAccumulator(), sqlite3Select(), sqlite3WindowCodeInit(), sqlite3WindowCodeStep(), windowFullScan(), and windowIfNewPeer().

◆ sqlite3KeyInfoOfIndex()

SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoOfIndex ( Parse * pParse,
Index * pIdx )

Definition at line 115426 of file sqlite3.c.

115432 {
115433 int i;
115434 int nCol = pIdx->nColumn;
115435 int nKey = pIdx->nKeyCol;
115436 KeyInfo *pKey;
115437 if( pParse->nErr ) return 0;
115438 if( pIdx->uniqNotNull ){
115439 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
115440 }else{
115441 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
115442 }
115443 if( pKey ){
115444 assert( sqlite3KeyInfoIsWriteable(pKey) );
115445 for(i=0; i<nCol; i++){
115446 const char *zColl = pIdx->azColl[i];
115447 pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
115448 sqlite3LocateCollSeq(pParse, zColl);
115449 pKey->aSortFlags[i] = pIdx->aSortOrder[i];
115450 assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
115451 }
115452 if( pParse->nErr ){
115453 assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
115454 if( pIdx->bNoQuery==0 ){
115455 /* Deactivate the index because it contains an unknown collating
115456 ** sequence. The only way to reactive the index is to reload the
115457 ** schema. Adding the missing collating sequence later does not
115458 ** reactive the index. The application had the chance to register
115459 ** the missing index using the collation-needed callback. For
115460 ** simplicity, SQLite will not give the application a second chance.
115461 */
115462 pIdx->bNoQuery = 1;
115463 pParse->rc = SQLITE_ERROR_RETRY;
115464 }
#define SQLITE_ERROR_MISSING_COLLSEQ
Definition sqlite3.c:1520
#define SQLITE_ERROR_RETRY
Definition sqlite3.c:1521
unsigned bNoQuery
Definition sqlite3.c:17800

References KeyInfo::aColl, KeyInfo::aSortFlags, Index::aSortOrder, Index::azColl, Index::bNoQuery, Parse::db, KEYINFO_ORDER_BIGNULL, Index::nColumn, Parse::nErr, Index::nKeyCol, Parse::rc, sqlite3KeyInfoAlloc(), sqlite3KeyInfoUnref(), sqlite3LocateCollSeq(), sqlite3StrBINARY, SQLITE_ERROR_MISSING_COLLSEQ, SQLITE_ERROR_RETRY, and Index::uniqNotNull.

Referenced by sqlite3RefillIndex(), sqlite3Select(), sqlite3Update(), and valueNew().

◆ sqlite3KeyInfoRef()

SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoRef ( KeyInfo * p)

Definition at line 130620 of file sqlite3.c.

130626 {

Referenced by generateOutputSubroutine(), multiSelect(), sqlite3RefillIndex(), and sqlite3Select().

◆ sqlite3KeyInfoUnref()

SQLITE_PRIVATE void sqlite3KeyInfoUnref ( KeyInfo * p)

Definition at line 130609 of file sqlite3.c.

130615 {

Referenced by multiSelect(), multiSelectOrderBy(), sqlite3CodeRhsOfIN(), and sqlite3KeyInfoOfIndex().

◆ sqlite3KeywordCode()

SQLITE_PRIVATE int sqlite3KeywordCode ( const unsigned char * z,
int n )

Definition at line 159865 of file sqlite3.c.

Referenced by identPut().

◆ sqlite3LeaveMutexAndCloseZombie()

SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie ( sqlite3 * db)

Definition at line 162258 of file sqlite3.c.

162264 {
162265 HashElem *i; /* Hash table iterator */
162266 int j;
162267
162268 /* If there are outstanding sqlite3_stmt or sqlite3_backup objects
162269 ** or if the connection has not yet been closed by sqlite3_close_v2(),
162270 ** then just leave the mutex and return.
162271 */
162272 if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
162274 return;
162275 }
162276
162277 /* If we reach this point, it means that the database connection has
162278 ** closed all sqlite3_stmt and sqlite3_backup objects and has been
162279 ** passed to sqlite3_close (meaning that it is a zombie). Therefore,
162280 ** go ahead and free all resources.
162281 */
162282
162283 /* If a transaction is open, roll it back. This also ensures that if
162284 ** any database schemas have been modified by an uncommitted transaction
162285 ** they are reset. And that the required b-tree mutex is held to make
162286 ** the pager rollback and schema reset an atomic operation. */
162288
162289 /* Free any outstanding Savepoint structures. */
162291
162292 /* Close all database connections */
162293 for(j=0; j<db->nDb; j++){
162294 struct Db *pDb = &db->aDb[j];
162295 if( pDb->pBt ){
162296 sqlite3BtreeClose(pDb->pBt);
162297 pDb->pBt = 0;
162298 if( j!=1 ){
162299 pDb->pSchema = 0;
162300 }
162301 }
162302 }
162303 /* Clear the TEMP schema separately and last */
162304 if( db->aDb[1].pSchema ){
162306 }
162308
162309 /* Free up the array of auxiliary databases */
162311 assert( db->nDb<=2 );
162312 assert( db->aDb==db->aDbStatic );
162313
162314 /* Tell the code in notify.c that the connection no longer holds any
162315 ** locks and does not require any further unlock-notify callbacks.
162316 */
162318
162319 for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){
162320 FuncDef *pNext, *p;
162321 p = sqliteHashData(i);
162322 do{
162323 functionDestroy(db, p);
162324 pNext = p->pNext;
162325 sqlite3DbFree(db, p);
162326 p = pNext;
162327 }while( p );
162328 }
162329 sqlite3HashClear(&db->aFunc);
162330 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
162331 CollSeq *pColl = (CollSeq *)sqliteHashData(i);
162332 /* Invoke any destructors registered for collation sequence user data. */
162333 for(j=0; j<3; j++){
162334 if( pColl[j].xDel ){
162335 pColl[j].xDel(pColl[j].pUser);
162336 }
162337 }
162338 sqlite3DbFree(db, pColl);
162339 }
162341#ifndef SQLITE_OMIT_VIRTUALTABLE
162342 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
162343 Module *pMod = (Module *)sqliteHashData(i);
162345 sqlite3VtabModuleUnref(db, pMod);
162346 }
162348#endif
162349
162350 sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
162351 sqlite3ValueFree(db->pErr);
162353#if SQLITE_USER_AUTHENTICATION
162354 sqlite3_free(db->auth.zAuthUser);
162355 sqlite3_free(db->auth.zAuthPW);
162356#endif
162357
162359
162360 /* The temp-database schema is allocated differently from the other schema
162361 ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
162362 ** So it needs to be freed here. Todo: Why not roll the temp schema into
162363 ** the same sqliteMalloc() as the one that allocates the database
162364 ** structure?
162365 */
162366 sqlite3DbFree(db, db->aDb[1].pSchema);
#define SQLITE_MAGIC_ERROR
Definition sqlite3.c:17081
SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *)
Definition sqlite3.c:139877
#define SQLITE_MAGIC_CLOSED
Definition sqlite3.c:17078
SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *)
Definition sqlite3.c:124894
SQLITE_PRIVATE void sqlite3SchemaClear(void *)
Definition sqlite3.c:116023
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *)
Definition sqlite3.c:110938
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *)
Definition sqlite3.c:162110
SQLITE_PRIVATE void sqlite3VtabModuleUnref(sqlite3 *, Module *)
Definition sqlite3.c:139733
#define sqlite3ConnectionClosed(x)
Definition sqlite3.c:20270
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *, int)
Definition sqlite3.c:162378
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *, Module *)
Definition sqlite3.c:140811

References sqlite3::aCollSeq, sqlite3::aDb, sqlite3::aDbStatic, sqlite3::aFunc, sqlite3::aModule, Lookaside::bMalloced, connectionIsBusy(), functionDestroy(), sqlite3::lookaside, sqlite3::magic, sqlite3::mutex, sqlite3::nDb, Db::pBt, sqlite3::pErr, FuncDef::pNext, Db::pSchema, Lookaside::pStart, sqlite3_free(), sqlite3_mutex_free(), sqlite3_mutex_leave(), sqlite3BtreeClose(), sqlite3CloseExtensions(), sqlite3CloseSavepoints(), sqlite3CollapseDatabaseArray(), sqlite3ConnectionClosed, sqlite3DbFree(), sqlite3Error(), sqlite3HashClear(), sqlite3LookasideUsed(), sqlite3RollbackAll(), sqlite3SchemaClear(), sqlite3ValueFree(), sqlite3VtabEponymousTableClear(), sqlite3VtabModuleUnref(), sqlite3VtabUnlockList(), SQLITE_MAGIC_CLOSED, SQLITE_MAGIC_ERROR, SQLITE_MAGIC_ZOMBIE, SQLITE_OK, sqliteHashData, sqliteHashFirst, sqliteHashNext, and CollSeq::xDel.

Referenced by sqlite3_finalize().

◆ sqlite3LoadExtension()

static int sqlite3LoadExtension ( sqlite3 * db,
const char * zFile,
const char * zProc,
char ** pzErrMsg )
static

Definition at line 124735 of file sqlite3.c.

124746 {
124747 sqlite3_vfs *pVfs = db->pVfs;
124748 void *handle;
124749 sqlite3_loadext_entry xInit;
124750 char *zErrmsg = 0;
124751 const char *zEntry;
124752 char *zAltEntry = 0;
124753 void **aHandle;
124754 u64 nMsg = 300 + sqlite3Strlen30(zFile);
124755 int ii;
124756 int rc;
124757
124758 /* Shared library endings to try if zFile cannot be loaded as written */
124759 static const char *azEndings[] = {
124760#if SQLITE_OS_WIN
124761 "dll"
124762#elif defined(__APPLE__)
124763 "dylib"
124764#else
124765 "so"
124766#endif
124767 };
124768
124769
124770 if( pzErrMsg ) *pzErrMsg = 0;
124771
124772 /* Ticket #1863. To avoid a creating security problems for older
124773 ** applications that relink against newer versions of SQLite, the
124774 ** ability to run load_extension is turned off by default. One
124775 ** must call either sqlite3_enable_load_extension(db) or
124776 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
124777 ** to turn on extension loading.
124778 */
124779 if( (db->flags & SQLITE_LoadExtension)==0 ){
124780 if( pzErrMsg ){
124781 *pzErrMsg = sqlite3_mprintf("not authorized");
124782 }
124783 return SQLITE_ERROR;
124784 }
124785
124786 zEntry = zProc ? zProc : "sqlite3_extension_init";
124787
124788 handle = sqlite3OsDlOpen(pVfs, zFile);
124789#if SQLITE_OS_UNIX || SQLITE_OS_WIN
124790 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
124791 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
124792 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
124793 handle = sqlite3OsDlOpen(pVfs, zAltFile);
124794 sqlite3_free(zAltFile);
124795 }
124796#endif
124797 if( handle==0 ){
124798 if( pzErrMsg ){
124799 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
124800 if( zErrmsg ){
124801 sqlite3_snprintf(nMsg, zErrmsg,
124802 "unable to open shared library [%s]", zFile);
124803 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
124804 }
124805 }
124806 return SQLITE_ERROR;
124807 }
124808 xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
124809
124810 /* If no entry point was specified and the default legacy
124811 ** entry point name "sqlite3_extension_init" was not found, then
124812 ** construct an entry point name "sqlite3_X_init" where the X is
124813 ** replaced by the lowercase value of every ASCII alphabetic
124814 ** character in the filename after the last "/" upto the first ".",
124815 ** and eliding the first three characters if they are "lib".
124816 ** Examples:
124817 **
124818 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
124819 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
124820 */
124821 if( xInit==0 && zProc==0 ){
124822 int iFile, iEntry, c;
124823 int ncFile = sqlite3Strlen30(zFile);
124824 zAltEntry = sqlite3_malloc64(ncFile+30);
124825 if( zAltEntry==0 ){
124826 sqlite3OsDlClose(pVfs, handle);
124827 return SQLITE_NOMEM_BKPT;
124828 }
124829 memcpy(zAltEntry, "sqlite3_", 8);
124830 for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
124831 iFile++;
124832 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
124833 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
124834 if( sqlite3Isalpha(c) ){
124835 zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
124836 }
124837 }
124838 memcpy(zAltEntry+iEntry, "_init", 6);
124839 zEntry = zAltEntry;
124840 xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
124841 }
124842 if( xInit==0 ){
124843 if( pzErrMsg ){
124844 nMsg += sqlite3Strlen30(zEntry);
124845 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
124846 if( zErrmsg ){
124847 sqlite3_snprintf(nMsg, zErrmsg,
124848 "no entry point [%s] in shared library [%s]", zEntry, zFile);
124849 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
124850 }
124851 }
124852 sqlite3OsDlClose(pVfs, handle);
124853 sqlite3_free(zAltEntry);
124854 return SQLITE_ERROR;
124855 }
124856 sqlite3_free(zAltEntry);
124857 rc = xInit(db, &zErrmsg, &sqlite3Apis);
124858 if( rc ){
124859 if( rc==SQLITE_OK_LOAD_PERMANENTLY ) return SQLITE_OK;
124860 if( pzErrMsg ){
124861 *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
124862 }
124863 sqlite3_free(zErrmsg);
124864 sqlite3OsDlClose(pVfs, handle);
124865 return SQLITE_ERROR;
124866 }
124867
124868 /* Append the new shared library handle to the db->aExtension array. */
124869 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
124870 if( aHandle==0 ){
124871 return SQLITE_NOMEM_BKPT;
124872 }
124873 if( db->nExtension>0 ){
124874 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
124875 }
#define SQLITE_OK_LOAD_PERMANENTLY
Definition sqlite3.c:1591
#define sqlite3Isalpha(x)
Definition sqlite3.c:19321
SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *)
Definition sqlite3.c:23217
SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *)
Definition sqlite3.c:23211
SQLITE_PRIVATE void * sqlite3OsDlOpen(sqlite3_vfs *, const char *)
Definition sqlite3.c:23208
#define DirSep(X)
Definition sqlite3.c:124720
SQLITE_PRIVATE void(*)(void) sqlite3OsDlSym(sqlite3_vfs *, void *, const char *)
Definition sqlite3.c:16471
int nExtension
Definition sqlite3.c:16869
void ** aExtension
Definition sqlite3.c:16870

References sqlite3::aExtension, ArraySize, DirSep, sqlite3::flags, sqlite3::nExtension, sqlite3::pVfs, sqlite3_free(), sqlite3_malloc64(), sqlite3_mprintf(), sqlite3_snprintf(), sqlite3_strnicmp(), sqlite3Apis, sqlite3DbMallocZero(), sqlite3Isalpha, sqlite3OsDlClose(), sqlite3OsDlError(), sqlite3OsDlOpen(), sqlite3OsDlSym, sqlite3Strlen30(), sqlite3UpperToLower, SQLITE_ERROR, SQLITE_LoadExtension, SQLITE_NOMEM_BKPT, SQLITE_OK, and SQLITE_OK_LOAD_PERMANENTLY.

◆ sqlite3LocateCollSeq()

SQLITE_PRIVATE CollSeq * sqlite3LocateCollSeq ( Parse * pParse,
const char * zName )

Definition at line 115791 of file sqlite3.c.

115796*/
115797SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName){
115798 sqlite3 *db = pParse->db;
115799 u8 enc = ENC(db);
115800 u8 initbusy = db->init.busy;
115801 CollSeq *pColl;
115802
115803 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);

References sqlite3::sqlite3InitInfo::busy, Parse::db, ENC, sqlite3::init, sqlite3FindCollSeq(), sqlite3GetCollSeq(), CollSeq::xCmp, and zName.

Referenced by analyzeOneTable(), sqlite3CreateIndex(), sqlite3GenerateConstraintChecks(), and sqlite3KeyInfoOfIndex().

◆ sqlite3LocateTable()

SQLITE_PRIVATE Table * sqlite3LocateTable ( Parse * pParse,
u32 flags,
const char * zName,
const char * zDbase )

Definition at line 110777 of file sqlite3.c.

110788 {
110789 Table *p;
110790 sqlite3 *db = pParse->db;
110791
110792 /* Read the database schema. If an error occurs, leave an error message
110793 ** and code in pParse and return NULL. */
110794 if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0
110795 && SQLITE_OK!=sqlite3ReadSchema(pParse)
110796 ){
110797 return 0;
110798 }
110799
110800 p = sqlite3FindTable(db, zName, zDbase);
110801 if( p==0 ){
110802#ifndef SQLITE_OMIT_VIRTUALTABLE
110803 /* If zName is the not the name of a table in the schema created using
110804 ** CREATE, then check to see if it is the name of an virtual table that
110805 ** can be an eponymous virtual table. */
110806 if( pParse->disableVtab==0 ){
110807 Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
110808 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
110809 pMod = sqlite3PragmaVtabRegister(db, zName);
110810 }
110811 if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
110812 return pMod->pEpoTab;
110813 }
110814 }
110815#endif
110816 if( flags & LOCATE_NOERR ) return 0;
110817 pParse->checkSchema = 1;
110818 }else if( IsVirtual(p) && pParse->disableVtab ){
110819 p = 0;
110820 }
110821
110822 if( p==0 ){
110823 const char *zMsg = flags & LOCATE_VIEW ? "no such view" : "no such table";
110824 if( zDbase ){
110825 sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
110826 }else{
#define LOCATE_NOERR
Definition sqlite3.c:19674
SQLITE_PRIVATE Module * sqlite3PragmaVtabRegister(sqlite3 *, const char *zName)
Definition sqlite3.c:128318
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse *, Module *)
Definition sqlite3.c:140774

References sqlite3::aModule, Parse::checkSchema, Parse::db, DBFLAG_SchemaKnownOk, Parse::disableVtab, IsVirtual, LOCATE_NOERR, LOCATE_VIEW, sqlite3::mDbFlags, Module::pEpoTab, sqlite3_strnicmp(), sqlite3ErrorMsg(), sqlite3FindTable(), sqlite3HashFind(), sqlite3PragmaVtabRegister(), sqlite3ReadSchema(), sqlite3VtabEponymousTableInit(), SQLITE_OK, and zName.

Referenced by renameColumnFunc(), sqlite3Analyze(), sqlite3FkCheck(), sqlite3LocateTableItem(), and sqlite3Pragma().

◆ sqlite3LocateTableItem()

SQLITE_PRIVATE Table * sqlite3LocateTableItem ( Parse * pParse,
u32 flags,
struct SrcList_item * p )

Definition at line 110837 of file sqlite3.c.

110847 {
110848 const char *zDb;
110849 assert( p->pSchema==0 || p->zDatabase==0 );
110850 if( p->pSchema ){
110851 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);

References sqlite3::aDb, Parse::db, sqlite3LocateTable(), sqlite3SchemaToIndex(), and Db::zDbSName.

Referenced by renameResolveTrigger(), selectExpander(), sqlite3AlterBeginAddColumn(), sqlite3AlterRenameColumn(), sqlite3CreateIndex(), sqlite3SrcListLookup(), and xferOptimization().

◆ sqlite3LockAndPrepare()

static int sqlite3LockAndPrepare ( sqlite3 * db,
const char * zSql,
int nBytes,
u32 prepFlags,
Vdbe * pOld,
sqlite3_stmt ** ppStmt,
const char ** pzTail )
static

Definition at line 129050 of file sqlite3.c.

129051 :
129052
129053 sqlite3ParserReset(&sParse);
129054 return rc;
129055}
129056static int sqlite3LockAndPrepare(
129057 sqlite3 *db, /* Database handle. */
129058 const char *zSql, /* UTF-8 encoded SQL statement. */
129059 int nBytes, /* Length of zSql in bytes. */
129060 u32 prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
129061 Vdbe *pOld, /* VM being reprepared */
129062 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
129063 const char **pzTail /* OUT: End of parsed string */
129064){
129065 int rc;
129066 int cnt = 0;
129067
129068#ifdef SQLITE_ENABLE_API_ARMOR
129069 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
129070#endif
129071 *ppStmt = 0;
129072 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
129073 return SQLITE_MISUSE_BKPT;
129074 }
129077 do{
129078 /* Make multiple attempts to compile the SQL, until it either succeeds
129079 ** or encounters a permanent error. A schema problem after one schema
129080 ** reset is considered a permanent error. */
129081 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
129082 assert( rc==SQLITE_OK || *ppStmt==0 );
129083 }while( rc==SQLITE_ERROR_RETRY
129084 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );

Referenced by sqlite3_prepare_v2(), sqlite3Prepare16(), and sqlite3Reprepare().

◆ sqlite3LogEst()

SQLITE_PRIVATE LogEst sqlite3LogEst ( u64 x)

Definition at line 32710 of file sqlite3.c.

32716 {
32717 static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 };
32718 LogEst y = 40;
32719 if( x<8 ){
32720 if( x<2 ) return 0;
32721 while( x<8 ){ y -= 10; x <<= 1; }
32722 }else{
32723#if GCC_VERSION>=5004000
32724 int i = 60 - __builtin_clzll(x);
32725 y += i*10;
32726 x >>= i;
32727#else

Referenced by computeLimitRegisters(), decodeIntArray(), multiSelect(), sqlite3DefaultRowEst(), sqlite3ExpandSubquery(), sqlite3LogEstFromDouble(), sqlite3Pragma(), sqlite3Select(), sqlite3StartTable(), sqlite3VdbeExec(), whereClauseInsert(), whereLoopAddBtree(), whereLoopAddBtreeIndex(), whereLoopAddVirtualOne(), wherePathSolver(), whereRangeAdjust(), whereRangeScanEst(), whereSortingCost(), and withExpand().

◆ sqlite3LogEstAdd()

SQLITE_PRIVATE LogEst sqlite3LogEstAdd ( LogEst a,
LogEst b )

Definition at line 32683 of file sqlite3.c.

32689 {
32690 static const unsigned char x[] = {
32691 10, 10, /* 0,1 */
32692 9, 9, /* 2,3 */
32693 8, 8, /* 4,5 */
32694 7, 7, 7, /* 6,7,8 */
32695 6, 6, 6, /* 9,10,11 */
32696 5, 5, 5, /* 12-14 */
32697 4, 4, 4, 4, /* 15-18 */
32698 3, 3, 3, 3, 3, 3, /* 19-24 */
32699 2, 2, 2, 2, 2, 2, 2, /* 25-31 */
32700 };
32701 if( a>=b ){
32702 if( a>b+49 ) return a;
32703 if( a>b+31 ) return a+1;
32704 return a+x[a-b];

Referenced by multiSelect(), multiSelectOrderBy(), whereLoopAddBtree(), whereLoopAddBtreeIndex(), whereLoopAddOr(), and wherePathSolver().

◆ sqlite3LogEstFromDouble()

SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble ( double x)

Definition at line 32734 of file sqlite3.c.

32740 {
32741 u64 a;
32742 LogEst e;
32743 assert( sizeof(x)==8 && sizeof(a)==8 );

References sqlite3LogEst().

Referenced by whereLoopAddVirtualOne().

◆ sqlite3LookasideUsed()

SQLITE_PRIVATE int sqlite3LookasideUsed ( sqlite3 * db,
int * pHighwater )

Definition at line 21501 of file sqlite3.c.

21506 {
21509#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
static u32 countLookasideSlots(LookasideSlot *p)
Definition sqlite3.c:21489

Referenced by deleteTable(), setupLookaside(), and sqlite3LeaveMutexAndCloseZombie().

◆ sqlite3Malloc()

SQLITE_PRIVATE void * sqlite3Malloc ( u64 n)

Definition at line 27590 of file sqlite3.c.

27595 {
27596 void *p;
27597 if( n==0 || n>=0x7fffff00 ){
27598 /* A memory allocation of a number of bytes which is near the maximum
27599 ** signed integer value might cause an integer overflow inside of the
27600 ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
27601 ** 255 bytes of overhead. SQLite itself will never use anything near
27602 ** this amount. The only way to reach the limit is with sqlite3_malloc() */
27603 p = 0;
27604 }else if( sqlite3GlobalConfig.bMemstat ){
27606 mallocWithAlarm((int)n, &p);
27608 }else{
static void mallocWithAlarm(int n, void **pp)
Definition sqlite3.c:27541

References EIGHT_BYTE_ALIGNMENT, mallocWithAlarm(), mem0, sqlite3_mutex_enter(), sqlite3_mutex_leave(), and sqlite3GlobalConfig.

Referenced by contextMalloc(), createFunctionApi(), dbMallocRawFinish(), pager_delsuper(), pcache1Alloc(), rehash(), saveCursorKey(), setupLookaside(), sqlite3BtreeInsert(), sqlite3BtreeMovetoUnpacked(), sqlite3BtreeOpen(), sqlite3HashInsert(), sqlite3MallocZero(), sqlite3RunParser(), sqlite3VdbeSorterInit(), sqlite3VtabCreateModule(), vdbePmaReaderSeek(), and vdbeSorterFlushPMA().

◆ sqlite3MallocAlarm()

static void sqlite3MallocAlarm ( int nByte)
static

Definition at line 27530 of file sqlite3.c.

27535 {

Referenced by mallocWithAlarm().

◆ sqlite3MallocEnd()

SQLITE_PRIVATE void sqlite3MallocEnd ( void )

Definition at line 27500 of file sqlite3.c.

27505 {

Referenced by sqlite3_shutdown().

◆ sqlite3MallocInit()

SQLITE_PRIVATE int sqlite3MallocInit ( void )

Definition at line 27471 of file sqlite3.c.

27476 {
27477 int rc;
27478 if( sqlite3GlobalConfig.m.xMalloc==0 ){
27480 }
27481 memset(&mem0, 0, sizeof(mem0));
27483 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
27484 || sqlite3GlobalConfig.nPage<=0 ){
27485 sqlite3GlobalConfig.pPage = 0;
27486 sqlite3GlobalConfig.szPage = 0;
#define SQLITE_MUTEX_STATIC_MEM
Definition sqlite3.c:8632

References mem0, sqlite3GlobalConfig, sqlite3MemSetDefault(), sqlite3MutexAlloc(), SQLITE_MUTEX_STATIC_MEM, and SQLITE_OK.

Referenced by sqlite3_initialize().

◆ sqlite3MallocMutex()

SQLITE_PRIVATE sqlite3_mutex * sqlite3MallocMutex ( void )

◆ sqlite3MallocSize()

◆ sqlite3MallocZero()

◆ sqlite3MatchEName()

SQLITE_PRIVATE int sqlite3MatchEName ( const struct ExprList_item * pItem,
const char * zCol,
const char * zTab,
const char * zDb )

Definition at line 97891 of file sqlite3.c.

97902 {
97903 int n;
97904 const char *zSpan;
97905 if( pItem->eEName!=ENAME_TAB ) return 0;
97906 zSpan = pItem->zEName;
97907 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
97908 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
97909 return 0;
97910 }
97911 zSpan += n+1;
97912 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
97913 if( zTab && (sqlite3StrNICmp(zSpan, zTab, n)!=0 || zTab[n]!=0) ){
97914 return 0;
97915 }

References ALWAYS, ENAME_TAB, sqlite3StrICmp(), and sqlite3StrNICmp.

Referenced by lookupName(), and selectExpander().

◆ sqlite3MaterializeView()

SQLITE_PRIVATE void sqlite3MaterializeView ( Parse * pParse,
Table * pView,
Expr * pWhere,
ExprList * pOrderBy,
Expr * pLimit,
int iCur )

Definition at line 116177 of file sqlite3.c.

116190 {
116191 SelectDest dest;
116192 Select *pSel;
116193 SrcList *pFrom;
116194 sqlite3 *db = pParse->db;
116195 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
116196 pWhere = sqlite3ExprDup(db, pWhere, 0);
116197 pFrom = sqlite3SrcListAppend(pParse, 0, 0, 0);
116198 if( pFrom ){
116199 assert( pFrom->nSrc==1 );
116200 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
116201 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
116202 assert( pFrom->a[0].pOn==0 );
116203 assert( pFrom->a[0].pUsing==0 );
116204 }

References SrcList::a, sqlite3::aDb, Parse::db, SrcList::nSrc, SrcList::SrcList_item::pOn, Table::pSchema, SrcList::SrcList_item::pUsing, SF_IncludeHidden, sqlite3DbStrDup(), sqlite3ExprDup(), sqlite3SchemaToIndex(), sqlite3Select(), sqlite3SelectDelete(), sqlite3SelectDestInit(), sqlite3SelectNew(), sqlite3SrcListAppend(), SRT_EphemTab, SrcList::SrcList_item::zDatabase, Db::zDbSName, Table::zName, and SrcList::SrcList_item::zName.

Referenced by sqlite3DeleteFrom(), and sqlite3Update().

◆ sqlite3MayAbort()

◆ sqlite3MemCompare()

SQLITE_PRIVATE int sqlite3MemCompare ( const Mem * pMem1,
const Mem * pMem2,
const CollSeq * pColl )

Definition at line 82056 of file sqlite3.c.

82062 {
82063 int f1, f2;
82064 int combined_flags;
82065
82066 f1 = pMem1->flags;
82067 f2 = pMem2->flags;
82068 combined_flags = f1|f2;
82069 assert( !sqlite3VdbeMemIsRowSet(pMem1) && !sqlite3VdbeMemIsRowSet(pMem2) );
82070
82071 /* If one value is NULL, it is less than the other. If both values
82072 ** are NULL, return 0.
82073 */
82074 if( combined_flags&MEM_Null ){
82075 return (f2&MEM_Null) - (f1&MEM_Null);
82076 }
82077
82078 /* At least one of the two values is a number
82079 */
82080 if( combined_flags&(MEM_Int|MEM_Real|MEM_IntReal) ){
82081 testcase( combined_flags & MEM_Int );
82082 testcase( combined_flags & MEM_Real );
82083 testcase( combined_flags & MEM_IntReal );
82084 if( (f1 & f2 & (MEM_Int|MEM_IntReal))!=0 ){
82085 testcase( f1 & f2 & MEM_Int );
82086 testcase( f1 & f2 & MEM_IntReal );
82087 if( pMem1->u.i < pMem2->u.i ) return -1;
82088 if( pMem1->u.i > pMem2->u.i ) return +1;
82089 return 0;
82090 }
82091 if( (f1 & f2 & MEM_Real)!=0 ){
82092 if( pMem1->u.r < pMem2->u.r ) return -1;
82093 if( pMem1->u.r > pMem2->u.r ) return +1;
82094 return 0;
82095 }
82096 if( (f1&(MEM_Int|MEM_IntReal))!=0 ){
82097 testcase( f1 & MEM_Int );
82098 testcase( f1 & MEM_IntReal );
82099 if( (f2&MEM_Real)!=0 ){
82100 return sqlite3IntFloatCompare(pMem1->u.i, pMem2->u.r);
82101 }else if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
82102 if( pMem1->u.i < pMem2->u.i ) return -1;
82103 if( pMem1->u.i > pMem2->u.i ) return +1;
82104 return 0;
82105 }else{
82106 return -1;
82107 }
82108 }
82109 if( (f1&MEM_Real)!=0 ){
82110 if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
82111 testcase( f2 & MEM_Int );
82112 testcase( f2 & MEM_IntReal );
82113 return -sqlite3IntFloatCompare(pMem2->u.i, pMem1->u.r);
82114 }else{
82115 return -1;
82116 }
82117 }
82118 return +1;
82119 }
82120
82121 /* If one value is a string and the other is a blob, the string is less.
82122 ** If both are strings, compare using the collating functions.
82123 */
82124 if( combined_flags&MEM_Str ){
82125 if( (f1 & MEM_Str)==0 ){
82126 return 1;
82127 }
82128 if( (f2 & MEM_Str)==0 ){
82129 return -1;
82130 }
82131
82132 assert( pMem1->enc==pMem2->enc || pMem1->db->mallocFailed );
82133 assert( pMem1->enc==SQLITE_UTF8 ||
82134 pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
82135
82136 /* The collation sequence must be defined at this point, even if
82137 ** the user deletes the collation sequence after the vdbe program is
82138 ** compiled (this was not always the case).
82139 */
82140 assert( !pColl || pColl->xCmp );
82141
82142 if( pColl ){
82143 return vdbeCompareMemString(pMem1, pMem2, pColl, 0);
82144 }
82145 /* If a NULL pointer was passed as the collate function, fall through
static int sqlite3IntFloatCompare(i64 i, double r)
Definition sqlite3.c:82026
static int vdbeCompareMemString(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl, u8 *prcErr)
Definition sqlite3.c:81943

References sqlite3_value::db, sqlite3_value::enc, sqlite3_value::flags, sqlite3_value::MemValue::i, sqlite3::mallocFailed, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, sqlite3_value::MemValue::r, sqlite3BlobCompare(), sqlite3IntFloatCompare(), SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, testcase, sqlite3_value::u, vdbeCompareMemString(), and CollSeq::xCmp.

Referenced by exprCompareVariable(), minmaxStep(), nullifFunc(), and sqlite3VdbeExec().

◆ sqlite3MemFree()

static void sqlite3MemFree ( void * pPrior)
static

Definition at line 23709 of file sqlite3.c.

23714 {
23715#ifdef SQLITE_MALLOCSIZE
23716 SQLITE_FREE(pPrior);
23717#else
23718 sqlite3_int64 *p = (sqlite3_int64*)pPrior;
#define SQLITE_FREE(x)
Definition sqlite3.c:23624

References SQLITE_FREE.

Referenced by sqlite3MemSetDefault().

◆ sqlite3MemInit()

static int sqlite3MemInit ( void * NotUsed)
static

Definition at line 23786 of file sqlite3.c.

23791 {
23792#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
23793 int cpuCount;
23794 size_t len;
23795 if( _sqliteZone_ ){
23796 return SQLITE_OK;
23797 }
23798 len = sizeof(cpuCount);
23799 /* One usually wants to use hw.acctivecpu for MT decisions, but not here */
23800 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0);
23801 if( cpuCount>1 ){
23802 /* defer MT decisions to system malloc */
23803 _sqliteZone_ = malloc_default_zone();
23804 }else{
23805 /* only 1 core, use our own zone to contention over global locks,
23806 ** e.g. we have our own dedicated locks */
23807 _sqliteZone_ = malloc_create_zone(4096, 0);
23808 malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");

Referenced by sqlite3MemSetDefault().

◆ sqlite3MemJournalOpen()

SQLITE_PRIVATE void sqlite3MemJournalOpen ( sqlite3_file * pJfd)

Definition at line 97448 of file sqlite3.c.

Referenced by pager_open_journal().

◆ sqlite3MemMalloc()

static void * sqlite3MemMalloc ( int nByte)
static

Definition at line 23675 of file sqlite3.c.

23680 {
23681#ifdef SQLITE_MALLOCSIZE
23682 void *p;
23683 testcase( ROUND8(nByte)==nByte );
23684 p = SQLITE_MALLOC( nByte );
23685 if( p==0 ){
23686 testcase( sqlite3GlobalConfig.xLog!=0 );
23687 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
23688 }
23689 return p;
23690#else
23691 sqlite3_int64 *p;
23692 assert( nByte>0 );
23693 testcase( ROUND8(nByte)!=nByte );
23694 p = SQLITE_MALLOC( nByte+8 );
23695 if( p ){
23696 p[0] = nByte;
23697 p++;
23698 }else{
23699 testcase( sqlite3GlobalConfig.xLog!=0 );
#define SQLITE_MALLOC(x)
Definition sqlite3.c:23623

References ROUND8, sqlite3_log(), sqlite3GlobalConfig, SQLITE_MALLOC, SQLITE_NOMEM, and testcase.

Referenced by sqlite3MemSetDefault().

◆ sqlite3MemoryBarrier()

SQLITE_PRIVATE void sqlite3MemoryBarrier ( void )

Definition at line 26314 of file sqlite3.c.

26319 {
26320#if defined(SQLITE_MEMORY_BARRIER)

Referenced by sqlite3_initialize(), sqlite3MutexInit(), and unixShmBarrier().

◆ sqlite3MemRealloc()

static void * sqlite3MemRealloc ( void * pPrior,
int nByte )
static

Definition at line 23747 of file sqlite3.c.

23752 {
23753#ifdef SQLITE_MALLOCSIZE
23754 void *p = SQLITE_REALLOC(pPrior, nByte);
23755 if( p==0 ){
23756 testcase( sqlite3GlobalConfig.xLog!=0 );
23758 "failed memory resize %u to %u bytes",
23759 SQLITE_MALLOCSIZE(pPrior), nByte);
23760 }
23761 return p;
23762#else
23763 sqlite3_int64 *p = (sqlite3_int64*)pPrior;
23764 assert( pPrior!=0 && nByte>0 );
23765 assert( nByte==ROUND8(nByte) ); /* EV: R-46199-30249 */
23766 p--;
23767 p = SQLITE_REALLOC(p, nByte+8 );
23768 if( p ){
23769 p[0] = nByte;
23770 p++;
23771 }else{
23772 testcase( sqlite3GlobalConfig.xLog!=0 );
23774 "failed memory resize %u to %u bytes",
#define SQLITE_REALLOC(x, y)
Definition sqlite3.c:23625

References ROUND8, sqlite3_log(), sqlite3GlobalConfig, sqlite3MemSize(), SQLITE_NOMEM, SQLITE_REALLOC, and testcase.

Referenced by sqlite3MemSetDefault().

◆ sqlite3MemRoundup()

static int sqlite3MemRoundup ( int n)
static

Definition at line 23779 of file sqlite3.c.

Referenced by sqlite3MemSetDefault().

◆ sqlite3MemSetDefault()

SQLITE_PRIVATE void sqlite3MemSetDefault ( void )

Definition at line 23824 of file sqlite3.c.

23829 {
23830 static const sqlite3_mem_methods defaultMethods = {
static int sqlite3MemInit(void *NotUsed)
Definition sqlite3.c:23786
static void sqlite3MemFree(void *pPrior)
Definition sqlite3.c:23709
static int sqlite3MemSize(void *pPrior)
Definition sqlite3.c:23724
static void * sqlite3MemRealloc(void *pPrior, int nByte)
Definition sqlite3.c:23747
static void * sqlite3MemMalloc(int nByte)
Definition sqlite3.c:23675
static int sqlite3MemRoundup(int n)
Definition sqlite3.c:23779

References sqlite3_config(), sqlite3MemFree(), sqlite3MemInit(), sqlite3MemMalloc(), sqlite3MemRealloc(), sqlite3MemRoundup(), sqlite3MemShutdown(), sqlite3MemSize(), and SQLITE_CONFIG_MALLOC.

Referenced by sqlite3_config(), and sqlite3MallocInit().

◆ sqlite3MemShutdown()

static void sqlite3MemShutdown ( void * NotUsed)
static

Definition at line 23813 of file sqlite3.c.

Referenced by sqlite3MemSetDefault().

◆ sqlite3MemSize()

static int sqlite3MemSize ( void * pPrior)
static

Definition at line 23724 of file sqlite3.c.

23729 {
23730#ifdef SQLITE_MALLOCSIZE
23731 assert( pPrior!=0 );
23732 return (int)SQLITE_MALLOCSIZE(pPrior);
23733#else
23734 sqlite3_int64 *p;
23735 assert( pPrior!=0 );

Referenced by sqlite3MemRealloc(), and sqlite3MemSetDefault().

◆ sqlite3MisuseError()

SQLITE_PRIVATE int sqlite3MisuseError ( int lineno)

Definition at line 164591 of file sqlite3.c.

164593 {
164594 testcase( sqlite3GlobalConfig.xLog!=0 );

◆ sqlite3MPrintf()

◆ sqlite3MulInt64()

SQLITE_PRIVATE int sqlite3MulInt64 ( i64 * pA,
i64 iB )

Definition at line 32614 of file sqlite3.c.

32615 {
32616 return sqlite3AddInt64(pA, -iB);
32617 }
32618#endif
32619}
32621#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
32622 return __builtin_mul_overflow(*pA, iB, pA);
32623#else
32624 i64 iA = *pA;
32625 if( iB>0 ){
32626 if( iA>LARGEST_INT64/iB ) return 1;
32627 if( iA<SMALLEST_INT64/iB ) return 1;
32628 }else if( iB<0 ){
32629 if( iA>0 ){
32630 if( iB<SMALLEST_INT64/iA ) return 1;
32631 }else if( iA<0 ){
32632 if( iB==SMALLEST_INT64 ) return 1;
32633 if( iA==SMALLEST_INT64 ) return 1;
32634 if( -iA>LARGEST_INT64/-iB ) return 1;
SQLITE_PRIVATE int sqlite3AddInt64(i64 *, i64)
Definition sqlite3.c:32579
SQLITE_PRIVATE int sqlite3MulInt64(i64 *, i64)
Definition sqlite3.c:32614

Referenced by sqlite3VdbeExec().

◆ sqlite3MultiWrite()

SQLITE_PRIVATE void sqlite3MultiWrite ( Parse * pParse)

Definition at line 115183 of file sqlite3.c.

115184 : deleting one row then inserting another,
115185** inserting multiple rows in a table, or inserting a row and index entries.)
115186** If an abort occurs after some of these writes have completed, then it will

References Parse::isMultiWrite, and sqlite3ParseToplevel.

Referenced by sqlite3DeleteFrom(), sqlite3GenerateConstraintChecks(), sqlite3RefillIndex(), sqlite3Update(), and updateVirtualTable().

◆ sqlite3MutexAlloc()

◆ sqlite3MutexEnd()

SQLITE_PRIVATE int sqlite3MutexEnd ( void )

Definition at line 25906 of file sqlite3.c.

25911 {
25912 int rc = SQLITE_OK;
25913 if( sqlite3GlobalConfig.mutex.xMutexEnd ){
25914 rc = sqlite3GlobalConfig.mutex.xMutexEnd();
25915 }
25916
25917#ifdef SQLITE_DEBUG

References GLOBAL, sqlite3GlobalConfig, and SQLITE_OK.

Referenced by sqlite3_shutdown().

◆ sqlite3MutexInit()

SQLITE_PRIVATE int sqlite3MutexInit ( void )

Definition at line 25860 of file sqlite3.c.

25865 {
25866 int rc = SQLITE_OK;
25867 if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
25868 /* If the xMutexAlloc method has not been set, then the user did not
25869 ** install a mutex implementation via sqlite3_config() prior to
25870 ** sqlite3_initialize() being called. This block copies pointers to
25871 ** the default implementation into the sqlite3GlobalConfig structure.
25872 */
25873 sqlite3_mutex_methods const *pFrom;
25875
25876 if( sqlite3GlobalConfig.bCoreMutex ){
25877#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
25878 pFrom = multiThreadedCheckMutex();
25879#else
25880 pFrom = sqlite3DefaultMutex();
25881#endif
25882 }else{
25883 pFrom = sqlite3NoopMutex();
25884 }
25885 pTo->xMutexInit = pFrom->xMutexInit;
25886 pTo->xMutexEnd = pFrom->xMutexEnd;
25887 pTo->xMutexFree = pFrom->xMutexFree;
25888 pTo->xMutexEnter = pFrom->xMutexEnter;
25889 pTo->xMutexTry = pFrom->xMutexTry;
25890 pTo->xMutexLeave = pFrom->xMutexLeave;
25891 pTo->xMutexHeld = pFrom->xMutexHeld;
25892 pTo->xMutexNotheld = pFrom->xMutexNotheld;
25894 pTo->xMutexAlloc = pFrom->xMutexAlloc;
25895 }
25896 assert( sqlite3GlobalConfig.mutex.xMutexInit );
25897 rc = sqlite3GlobalConfig.mutex.xMutexInit();
25898
25899#ifdef SQLITE_DEBUG
25900 GLOBAL(int, mutexIsInit) = 1;
SQLITE_PRIVATE sqlite3_mutex_methods const * sqlite3NoopMutex(void)
Definition sqlite3.c:26057
SQLITE_PRIVATE sqlite3_mutex_methods const * sqlite3DefaultMutex(void)
Definition sqlite3.c:26596
sqlite3_mutex *(* xMutexAlloc)(int)
Definition sqlite3.c:8576
int(* xMutexTry)(sqlite3_mutex *)
Definition sqlite3.c:8579
int(* xMutexEnd)(void)
Definition sqlite3.c:8575
void(* xMutexFree)(sqlite3_mutex *)
Definition sqlite3.c:8577
int(* xMutexHeld)(sqlite3_mutex *)
Definition sqlite3.c:8581
int(* xMutexNotheld)(sqlite3_mutex *)
Definition sqlite3.c:8582
void(* xMutexEnter)(sqlite3_mutex *)
Definition sqlite3.c:8578
void(* xMutexLeave)(sqlite3_mutex *)
Definition sqlite3.c:8580
int(* xMutexInit)(void)
Definition sqlite3.c:8574

References GLOBAL, sqlite3DefaultMutex(), sqlite3GlobalConfig, sqlite3MemoryBarrier(), sqlite3NoopMutex(), SQLITE_OK, sqlite3_mutex_methods::xMutexAlloc, sqlite3_mutex_methods::xMutexEnd, sqlite3_mutex_methods::xMutexEnter, sqlite3_mutex_methods::xMutexFree, sqlite3_mutex_methods::xMutexHeld, sqlite3_mutex_methods::xMutexInit, sqlite3_mutex_methods::xMutexLeave, sqlite3_mutex_methods::xMutexNotheld, and sqlite3_mutex_methods::xMutexTry.

Referenced by sqlite3_initialize().

◆ sqlite3NameFromToken()

◆ sqlite3NestedParse()

SQLITE_PRIVATE void sqlite3NestedParse ( Parse * pParse,
const char * zFormat,
... )

Definition at line 110647 of file sqlite3.c.

110653 {
110654 va_list ap;
110655 char *zSql;
110656 char *zErrMsg = 0;
110657 sqlite3 *db = pParse->db;
110658 char saveBuf[PARSE_TAIL_SZ];
110659
110660 if( pParse->nErr ) return;
110661 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
110662 va_start(ap, zFormat);
110663 zSql = sqlite3VMPrintf(db, zFormat, ap);
110664 va_end(ap);
110665 if( zSql==0 ){
110666 /* This can result either from an OOM or because the formatted string
110667 ** exceeds SQLITE_LIMIT_LENGTH. In the latter case, we need to set
110668 ** an error */
110669 if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
110670 pParse->nErr++;
110671 return;
110672 }
110673 pParse->nested++;
110674 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
110675 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
#define PARSE_TAIL_SZ
Definition sqlite3.c:18791
#define PARSE_TAIL(X)
Definition sqlite3.c:18792

References Parse::db, sqlite3::mallocFailed, Parse::nErr, Parse::nested, PARSE_TAIL, PARSE_TAIL_SZ, Parse::rc, sqlite3DbFree(), sqlite3RunParser(), sqlite3VMPrintf(), and SQLITE_TOOBIG.

Referenced by destroyRootPage(), openStatTable(), renameTestSchema(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3CreateIndex(), and sqlite3EndTable().

◆ sqlite3NoopDestructor()

SQLITE_PRIVATE void sqlite3NoopDestructor ( void * p)

Definition at line 76696 of file sqlite3.c.

◆ sqlite3NoopMutex()

SQLITE_PRIVATE sqlite3_mutex_methods const * sqlite3NoopMutex ( void )

Definition at line 26057 of file sqlite3.c.

26060 { UNUSED_PARAMETER(p); return; }
26061
26063 static const sqlite3_mutex_methods sMutex = {
26071
26072 0,
static sqlite3_mutex * noopMutexAlloc(int id)
Definition sqlite3.c:26045
static int noopMutexEnd(void)
Definition sqlite3.c:26044
static int noopMutexInit(void)
Definition sqlite3.c:26043
static int noopMutexTry(sqlite3_mutex *p)
Definition sqlite3.c:26051
static void noopMutexLeave(sqlite3_mutex *p)
Definition sqlite3.c:26055
static void noopMutexFree(sqlite3_mutex *p)
Definition sqlite3.c:26049
static void noopMutexEnter(sqlite3_mutex *p)
Definition sqlite3.c:26050

Referenced by sqlite3MutexInit().

◆ sqlite3NotPureFunc()

SQLITE_PRIVATE int sqlite3NotPureFunc ( sqlite3_context * pCtx)

Definition at line 82849 of file sqlite3.c.

82855 {
82856 const VdbeOp *pOp;
82857#ifdef SQLITE_ENABLE_STAT4
82858 if( pCtx->pVdbe==0 ) return 1;
82859#endif
82860 pOp = pCtx->pVdbe->aOp + pCtx->iOp;
82861 if( pOp->opcode==OP_PureFunc ){
82862 const char *zContext;
82863 char *zMsg;
82864 if( pOp->p5 & NC_IsCheck ){
82865 zContext = "a CHECK constraint";
82866 }else if( pOp->p5 & NC_GenCol ){
82867 zContext = "a generated column";
82868 }else{
82869 zContext = "an index";
82870 }
82871 zMsg = sqlite3_mprintf("non-deterministic use of %s() in %s",
82872 pCtx->pFunc->zName, zContext);
#define OP_PureFunc
Definition sqlite3.c:15629

References Vdbe::aOp, sqlite3_context::iOp, NC_GenCol, NC_IsCheck, OP_PureFunc, VdbeOp::opcode, VdbeOp::p5, sqlite3_context::pFunc, sqlite3_context::pVdbe, sqlite3_free(), sqlite3_mprintf(), sqlite3_result_error(), and FuncDef::zName.

Referenced by parseDateOrTime(), and parseModifier().

◆ sqlite3OomClear()

SQLITE_PRIVATE void sqlite3OomClear ( sqlite3 * db)

◆ sqlite3OomFault()

◆ sqlite3OpcodeName()

SQLITE_PRIVATE const char * sqlite3OpcodeName ( int i)

Definition at line 33160 of file sqlite3.c.

33166 {
33167 static const char *const azName[] = {
33168 /* 0 */ "Savepoint" OpHelp(""),
33169 /* 1 */ "AutoCommit" OpHelp(""),
33170 /* 2 */ "Transaction" OpHelp(""),
33171 /* 3 */ "SorterNext" OpHelp(""),
33172 /* 4 */ "Prev" OpHelp(""),
33173 /* 5 */ "Next" OpHelp(""),
33174 /* 6 */ "Checkpoint" OpHelp(""),
33175 /* 7 */ "JournalMode" OpHelp(""),
33176 /* 8 */ "Vacuum" OpHelp(""),
33177 /* 9 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
33178 /* 10 */ "VUpdate" OpHelp("data=r[P3@P2]"),
33179 /* 11 */ "Goto" OpHelp(""),
33180 /* 12 */ "Gosub" OpHelp(""),
33181 /* 13 */ "InitCoroutine" OpHelp(""),
33182 /* 14 */ "Yield" OpHelp(""),
33183 /* 15 */ "MustBeInt" OpHelp(""),
33184 /* 16 */ "Jump" OpHelp(""),
33185 /* 17 */ "Once" OpHelp(""),
33186 /* 18 */ "If" OpHelp(""),
33187 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
33188 /* 20 */ "IfNot" OpHelp(""),
33189 /* 21 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
33190 /* 22 */ "SeekLT" OpHelp("key=r[P3@P4]"),
33191 /* 23 */ "SeekLE" OpHelp("key=r[P3@P4]"),
33192 /* 24 */ "SeekGE" OpHelp("key=r[P3@P4]"),
33193 /* 25 */ "SeekGT" OpHelp("key=r[P3@P4]"),
33194 /* 26 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
33195 /* 27 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
33196 /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
33197 /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
33198 /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
33199 /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
33200 /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
33201 /* 33 */ "Last" OpHelp(""),
33202 /* 34 */ "IfSmaller" OpHelp(""),
33203 /* 35 */ "SorterSort" OpHelp(""),
33204 /* 36 */ "Sort" OpHelp(""),
33205 /* 37 */ "Rewind" OpHelp(""),
33206 /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
33207 /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
33208 /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
33209 /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
33210 /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
33211 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
33212 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
33213 /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
33214 /* 46 */ "Program" OpHelp(""),
33215 /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
33216 /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
33217 /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
33218 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
33219 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
33220 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
33221 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
33222 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
33223 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
33224 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
33225 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
33226 /* 58 */ "ElseNotEq" OpHelp(""),
33227 /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
33228 /* 60 */ "IncrVacuum" OpHelp(""),
33229 /* 61 */ "VNext" OpHelp(""),
33230 /* 62 */ "Init" OpHelp("Start at P2"),
33231 /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
33232 /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
33233 /* 65 */ "Return" OpHelp(""),
33234 /* 66 */ "EndCoroutine" OpHelp(""),
33235 /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
33236 /* 68 */ "Halt" OpHelp(""),
33237 /* 69 */ "Integer" OpHelp("r[P2]=P1"),
33238 /* 70 */ "Int64" OpHelp("r[P2]=P4"),
33239 /* 71 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
33240 /* 72 */ "Null" OpHelp("r[P2..P3]=NULL"),
33241 /* 73 */ "SoftNull" OpHelp("r[P1]=NULL"),
33242 /* 74 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
33243 /* 75 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
33244 /* 76 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
33245 /* 77 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
33246 /* 78 */ "SCopy" OpHelp("r[P2]=r[P1]"),
33247 /* 79 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
33248 /* 80 */ "ResultRow" OpHelp("output=r[P1@P2]"),
33249 /* 81 */ "CollSeq" OpHelp(""),
33250 /* 82 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
33251 /* 83 */ "RealAffinity" OpHelp(""),
33252 /* 84 */ "Cast" OpHelp("affinity(r[P1])"),
33253 /* 85 */ "Permutation" OpHelp(""),
33254 /* 86 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
33255 /* 87 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
33256 /* 88 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33257 /* 89 */ "Column" OpHelp("r[P3]=PX"),
33258 /* 90 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33259 /* 91 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33260 /* 92 */ "Count" OpHelp("r[P2]=count()"),
33261 /* 93 */ "ReadCookie" OpHelp(""),
33262 /* 94 */ "SetCookie" OpHelp(""),
33263 /* 95 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33264 /* 96 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33265 /* 97 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33266 /* 98 */ "OpenDup" OpHelp(""),
33267 /* 99 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33268 /* 100 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33269 /* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
33270 /* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
33271 /* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
33272 /* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
33273 /* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
33274 /* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
33275 /* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
33276 /* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
33277 /* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
33278 /* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33279 /* 111 */ "SorterOpen" OpHelp(""),
33280 /* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33281 /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33282 /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33283 /* 115 */ "String8" OpHelp("r[P2]='P4'"),
33284 /* 116 */ "Close" OpHelp(""),
33285 /* 117 */ "ColumnsUsed" OpHelp(""),
33286 /* 118 */ "SeekHit" OpHelp("seekHit=P2"),
33287 /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33288 /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"),
33289 /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33290 /* 122 */ "Delete" OpHelp(""),
33291 /* 123 */ "ResetCount" OpHelp(""),
33292 /* 124 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33293 /* 125 */ "SorterData" OpHelp("r[P2]=data"),
33294 /* 126 */ "RowData" OpHelp("r[P2]=data"),
33295 /* 127 */ "Rowid" OpHelp("r[P2]=rowid"),
33296 /* 128 */ "NullRow" OpHelp(""),
33297 /* 129 */ "SeekEnd" OpHelp(""),
33298 /* 130 */ "IdxInsert" OpHelp("key=r[P2]"),
33299 /* 131 */ "SorterInsert" OpHelp("key=r[P2]"),
33300 /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33301 /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33302 /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33303 /* 135 */ "FinishSeek" OpHelp(""),
33304 /* 136 */ "Destroy" OpHelp(""),
33305 /* 137 */ "Clear" OpHelp(""),
33306 /* 138 */ "ResetSorter" OpHelp(""),
33307 /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33308 /* 140 */ "SqlExec" OpHelp(""),
33309 /* 141 */ "ParseSchema" OpHelp(""),
33310 /* 142 */ "LoadAnalysis" OpHelp(""),
33311 /* 143 */ "DropTable" OpHelp(""),
33312 /* 144 */ "DropIndex" OpHelp(""),
33313 /* 145 */ "DropTrigger" OpHelp(""),
33314 /* 146 */ "IntegrityCk" OpHelp(""),
33315 /* 147 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
33316 /* 148 */ "Param" OpHelp(""),
33317 /* 149 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33318 /* 150 */ "Real" OpHelp("r[P2]=P4"),
33319 /* 151 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33320 /* 152 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33321 /* 153 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33322 /* 154 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33323 /* 155 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33324 /* 156 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33325 /* 157 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33326 /* 158 */ "Expire" OpHelp(""),
33327 /* 159 */ "CursorLock" OpHelp(""),
33328 /* 160 */ "CursorUnlock" OpHelp(""),
33329 /* 161 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33330 /* 162 */ "VBegin" OpHelp(""),
33331 /* 163 */ "VCreate" OpHelp(""),
33332 /* 164 */ "VDestroy" OpHelp(""),
33333 /* 165 */ "VOpen" OpHelp(""),
33334 /* 166 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33335 /* 167 */ "VRename" OpHelp(""),
33336 /* 168 */ "Pagecount" OpHelp(""),
33337 /* 169 */ "MaxPgcnt" OpHelp(""),
33338 /* 170 */ "Trace" OpHelp(""),
33339 /* 171 */ "CursorHint" OpHelp(""),
33340 /* 172 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
#define OpHelp(X)
Definition sqlite3.c:33158

References OpHelp.

Referenced by sqlite3VdbeList().

◆ sqlite3OpenSchemaTable()

SQLITE_PRIVATE void sqlite3OpenSchemaTable ( Parse * p,
int iDb )

Definition at line 111157 of file sqlite3.c.

111163 {
111164 Vdbe *v = sqlite3GetVdbe(p);

Referenced by sqlite3StartTable().

◆ sqlite3OpenTable()

SQLITE_PRIVATE void sqlite3OpenTable ( Parse * pParse,
int iCur,
int iDb,
Table * pTab,
int opcode )

Definition at line 120573 of file sqlite3.c.

120585 {
120586 Vdbe *v;
120587 assert( !IsVirtual(pTab) );
120588 v = sqlite3GetVdbe(pParse);
120589 assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
120590 sqlite3TableLock(pParse, iDb, pTab->tnum,
120591 (opcode==OP_OpenWrite)?1:0, pTab->zName);
120592 if( HasRowid(pTab) ){
120593 sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
120594 VdbeComment((v, "%s", pTab->zName));
120595 }else{
120596 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
120597 assert( pPk!=0 );

References HasRowid, IsVirtual, Table::nNVCol, OP_OpenRead, OP_OpenWrite, sqlite3GetVdbe(), sqlite3PrimaryKeyIndex(), sqlite3TableLock(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4Int(), sqlite3VdbeSetP4KeyInfo(), Table::tnum, Index::tnum, VdbeComment, and Table::zName.

Referenced by analyzeOneTable(), autoIncrementEnd(), fkLookupParent(), generateSortTail(), sqlite3FindInIndex(), sqlite3OpenTableAndIndices(), sqlite3Pragma(), sqlite3RefillIndex(), sqlite3WhereBegin(), and xferOptimization().

◆ sqlite3OpenTableAndIndices()

SQLITE_PRIVATE int sqlite3OpenTableAndIndices ( Parse * pParse,
Table * pTab,
int op,
u8 p5,
int iBase,
u8 * aToOpen,
int * piDataCur,
int * piIdxCur )

Definition at line 122930 of file sqlite3.c.

122945 {
122946 int i;
122947 int iDb;
122948 int iDataCur;
122949 Index *pIdx;
122950 Vdbe *v;
122951
122952 assert( op==OP_OpenRead || op==OP_OpenWrite );
122953 assert( op==OP_OpenWrite || p5==0 );
122954 if( IsVirtual(pTab) ){
122955 /* This routine is a no-op for virtual tables. Leave the output
122956 ** variables *piDataCur and *piIdxCur uninitialized so that valgrind
122957 ** can detect if they are used by mistake in the caller. */
122958 return 0;
122959 }
122960 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
122961 v = sqlite3GetVdbe(pParse);
122962 assert( v!=0 );
122963 if( iBase<0 ) iBase = pParse->nTab;
122964 iDataCur = iBase++;
122965 if( piDataCur ) *piDataCur = iDataCur;
122966 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
122967 sqlite3OpenTable(pParse, iDataCur, iDb, pTab, op);
122968 }else{
122969 sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
122970 }
122971 if( piIdxCur ) *piIdxCur = iBase;
122972 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122973 int iIdxCur = iBase++;
122974 assert( pIdx->pSchema==pTab->pSchema );
122975 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
122976 if( piDataCur ) *piDataCur = iIdxCur;
122977 p5 = 0;
122978 }
122979 if( aToOpen==0 || aToOpen[i+1] ){
122980 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
122981 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
122982 sqlite3VdbeChangeP5(v, p5);

References Parse::db, HasRowid, IsPrimaryKeyIndex, IsVirtual, Parse::nTab, OP_OpenRead, OP_OpenWrite, Table::pIndex, Index::pNext, Table::pSchema, Index::pSchema, sqlite3GetVdbe(), sqlite3OpenTable(), sqlite3SchemaToIndex(), sqlite3TableLock(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP5(), sqlite3VdbeSetP4KeyInfo(), Table::tnum, Index::tnum, VdbeComment, Table::zName, and Index::zName.

Referenced by sqlite3DeleteFrom(), sqlite3Insert(), sqlite3Pragma(), and sqlite3Update().

◆ sqlite3OpenTempDatabase()

SQLITE_PRIVATE int sqlite3OpenTempDatabase ( Parse * pParse)

Definition at line 115091 of file sqlite3.c.

115097 {
115098 sqlite3 *db = pParse->db;
115099 if( db->aDb[1].pBt==0 && !pParse->explain ){
115100 int rc;
115101 Btree *pBt;
115102 static const int flags =
115108
115109 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
115110 if( rc!=SQLITE_OK ){
115111 sqlite3ErrorMsg(pParse, "unable to open a temporary database "
115112 "file for storing temporary tables");
115113 pParse->rc = rc;
115114 return 1;
115115 }
115116 db->aDb[1].pBt = pBt;
115117 assert( db->aDb[1].pSchema );
115118 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){

Referenced by findBtree(), sqlite3CodeVerifySchema(), and sqlite3Pragma().

◆ sqlite3OsAccess()

SQLITE_PRIVATE int sqlite3OsAccess ( sqlite3_vfs * pVfs,
const char * zPath,
int flags,
int * pResOut )

Definition at line 23188 of file sqlite3.c.

23188 {
23190 assert( dirSync==0 || dirSync==1 );
23191 return pVfs->xDelete(pVfs, zPath, dirSync);
23192}
23194 sqlite3_vfs *pVfs,
23195 const char *zPath,
23196 int flags,
#define DO_OS_MALLOC_TEST(x)
Definition sqlite3.c:23034
int(* xDelete)(sqlite3_vfs *, const char *zName, int syncDir)
Definition sqlite3.c:2426

References DO_OS_MALLOC_TEST, and sqlite3_vfs::xDelete.

Referenced by hasHotJournal(), pager_delsuper(), pager_playback(), pagerOpenWalIfPresent(), sqlite3PagerCloseWal(), sqlite3PagerSharedLock(), sqlite3Pragma(), and vdbeCommit().

◆ sqlite3OsCheckReservedLock()

SQLITE_PRIVATE int sqlite3OsCheckReservedLock ( sqlite3_file * id,
int * pResOut )

Definition at line 23075 of file sqlite3.c.

23077 {
23078 return id->pMethods->xUnlock(id, lockType);

Referenced by hasHotJournal().

◆ sqlite3OsClose()

◆ sqlite3OsCloseFree()

SQLITE_PRIVATE void sqlite3OsCloseFree ( sqlite3_file * pFile)

Definition at line 23278 of file sqlite3.c.

23278 {
23279 rc = SQLITE_NOMEM_BKPT;
23280 }
23281 return rc;
23282}

Referenced by vdbeCommit().

◆ sqlite3OsCurrentTimeInt64()

SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64 ( sqlite3_vfs * pVfs,
sqlite3_int64 * pTimeOut )

Definition at line 23238 of file sqlite3.c.

23240 {
23241 return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0;
23242}
23244 int rc;
23245 /* IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64()
23246 ** method to get the current date and time if that method is available
23247 ** (if iVersion is 2 or greater and the function pointer is not NULL) and
23248 ** will fall back to xCurrentTime() if xCurrentTimeInt64() is
23249 ** unavailable.
23250 */
23251 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
23252 rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
23253 }else{
23254 double r;
int(* xGetLastError)(sqlite3_vfs *, int, char *)
Definition sqlite3.c:2436
int(* xCurrentTimeInt64)(sqlite3_vfs *, sqlite3_int64 *)
Definition sqlite3.c:2441

Referenced by invokeProfileCallback(), sqlite3Step(), and sqlite3StmtCurrentTime().

◆ sqlite3OsDelete()

SQLITE_PRIVATE int sqlite3OsDelete ( sqlite3_vfs * pVfs,
const char * zPath,
int dirSync )

◆ sqlite3OsDeviceCharacteristics()

◆ sqlite3OsDlClose()

SQLITE_PRIVATE void sqlite3OsDlClose ( sqlite3_vfs * pVfs,
void * pHandle )

Definition at line 23217 of file sqlite3.c.

23219 {

Referenced by sqlite3LoadExtension().

◆ sqlite3OsDlError()

SQLITE_PRIVATE void sqlite3OsDlError ( sqlite3_vfs * pVfs,
int nByte,
char * zBufOut )

Definition at line 23211 of file sqlite3.c.

23213 {

Referenced by sqlite3LoadExtension().

◆ sqlite3OsDlOpen()

SQLITE_PRIVATE void * sqlite3OsDlOpen ( sqlite3_vfs * pVfs,
const char * zPath )

Definition at line 23208 of file sqlite3.c.

Referenced by sqlite3LoadExtension().

◆ sqlite3OsFetch()

SQLITE_PRIVATE int sqlite3OsFetch ( sqlite3_file * id,
i64 iOff,
int iAmt,
void ** pp )

Definition at line 23153 of file sqlite3.c.

23153 {
23154 return id->pMethods->xUnfetch(id, iOff, p);
23155}
23156#else

Referenced by vdbeSorterMapFile().

◆ sqlite3OsFileControl()

SQLITE_PRIVATE int sqlite3OsFileControl ( sqlite3_file * id,
int op,
void * pArg )

Definition at line 23088 of file sqlite3.c.

23093 {
23094 if( id->pMethods==0 ) return SQLITE_NOTFOUND;
23095#ifdef SQLITE_TEST
23098 ){
23099 /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
23100 ** is using a regular VFS, it is called after the corresponding
23101 ** transaction has been committed. Injecting a fault at this point
23102 ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
23103 ** but the transaction is committed anyway.
23104 **
23105 ** The core must call OsFileControl() though, not OsFileControlHint(),
23106 ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
23107 ** means the commit really has failed and an error should be returned
23108 ** to the user. */
#define SQLITE_FCNTL_LOCK_TIMEOUT
Definition sqlite3.c:2211

References sqlite3_file::pMethods, SQLITE_FCNTL_COMMIT_PHASETWO, SQLITE_FCNTL_LOCK_TIMEOUT, and SQLITE_NOTFOUND.

Referenced by databaseIsUnmoved(), pager_end_transaction(), sqlite3BtreeCopyFile(), sqlite3PagerCommitPhaseOne(), sqlite3PagerSync(), sqlite3Pragma(), and walCheckpoint().

◆ sqlite3OsFileControlHint()

◆ sqlite3OsFileSize()

◆ sqlite3OsFullPathname()

SQLITE_PRIVATE int sqlite3OsFullPathname ( sqlite3_vfs * pVfs,
const char * zPath,
int nPathOut,
char * zPathOut )

Definition at line 23197 of file sqlite3.c.

23198 {
23200 return pVfs->xAccess(pVfs, zPath, flags, pResOut);
23201}
23203 sqlite3_vfs *pVfs,
23204 const char *zPath,
23205 int nPathOut,
23206 char *zPathOut
int(* xAccess)(sqlite3_vfs *, const char *zName, int flags, int *pResOut)
Definition sqlite3.c:2427

References DO_OS_MALLOC_TEST, and sqlite3_vfs::xAccess.

Referenced by sqlite3BtreeOpen(), and sqlite3PagerOpen().

◆ sqlite3OsGetLastError()

SQLITE_PRIVATE int sqlite3OsGetLastError ( sqlite3_vfs * pVfs)

Definition at line 23235 of file sqlite3.c.

23237 {

◆ sqlite3OsInit()

SQLITE_PRIVATE int sqlite3OsInit ( void )

Definition at line 23290 of file sqlite3.c.

23295 {

References sqlite3_free(), sqlite3_malloc(), sqlite3_os_init(), and SQLITE_NOMEM_BKPT.

Referenced by sqlite3_initialize().

◆ sqlite3OsLock()

SQLITE_PRIVATE int sqlite3OsLock ( sqlite3_file * id,
int lockType )

Definition at line 23068 of file sqlite3.c.

23069 {
23071 return id->pMethods->xFileSize(id, pSize);

Referenced by pagerLockDb().

◆ sqlite3OsOpen()

SQLITE_PRIVATE int sqlite3OsOpen ( sqlite3_vfs * pVfs,
const char * zPath,
sqlite3_file * pFile,
int flags,
int * pFlagsOut )

Definition at line 23166 of file sqlite3.c.

23177 {
23178 int rc;
23180 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
23181 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
23182 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before

References DO_OS_MALLOC_TEST.

Referenced by hasHotJournal(), pager_delsuper(), pagerOpentemp(), sqlite3JournalOpen(), sqlite3PagerOpen(), sqlite3PagerSharedLock(), and sqlite3WalOpen().

◆ sqlite3OsOpenMalloc()

SQLITE_PRIVATE int sqlite3OsOpenMalloc ( sqlite3_vfs * pVfs,
const char * zFile,
sqlite3_file ** ppFile,
int flags,
int * pOutFlags )

Definition at line 23256 of file sqlite3.c.

23267 {
23268 int rc;
23269 sqlite3_file *pFile;
23270 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
23271 if( pFile ){
23272 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
23273 if( rc!=SQLITE_OK ){
23274 sqlite3_free(pFile);
23275 }else{
23276 *ppFile = pFile;
23277 }

Referenced by vdbeCommit(), and vdbeSorterOpenTempFile().

◆ sqlite3OsRandomness()

SQLITE_PRIVATE int sqlite3OsRandomness ( sqlite3_vfs * pVfs,
int nByte,
char * zBufOut )

Definition at line 23221 of file sqlite3.c.

23222 {
23223 pVfs->xDlClose(pVfs, pHandle);
23224}
23225#endif /* SQLITE_OMIT_LOAD_EXTENSION */
23226SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
23228 memset(zBufOut, 0, nByte);
23229 if( ALWAYS(nByte>(signed)sizeof(unsigned)) ) nByte = sizeof(unsigned int);
23230 memcpy(zBufOut, &sqlite3Config.iPrngSeed, nByte);
23231 return SQLITE_OK;
void(* xDlClose)(sqlite3_vfs *, void *)
Definition sqlite3.c:2432

◆ sqlite3OsRead()

◆ sqlite3OsSectorSize()

SQLITE_PRIVATE int sqlite3OsSectorSize ( sqlite3_file * id)

Definition at line 23113 of file sqlite3.c.

23114 {
23115 if( id->pMethods ) (void)id->pMethods->xFileControl(id, op, pArg);
23116}
int(* xFileControl)(sqlite3_file *, int op, void *pArg)
Definition sqlite3.c:1842

◆ sqlite3OsShmBarrier()

SQLITE_PRIVATE void sqlite3OsShmBarrier ( sqlite3_file * id)

Definition at line 23124 of file sqlite3.c.

23126 {

◆ sqlite3OsShmLock()

SQLITE_PRIVATE int sqlite3OsShmLock ( sqlite3_file * id,
int offset,
int n,
int flags )

Definition at line 23121 of file sqlite3.c.

23122 {
23123 return id->pMethods->xDeviceCharacteristics(id);

Referenced by walLockExclusive(), and walLockShared().

◆ sqlite3OsShmMap()

SQLITE_PRIVATE int sqlite3OsShmMap ( sqlite3_file * id,
int iPage,
int pgsz,
int bExtend,
void volatile ** pp )

Definition at line 23130 of file sqlite3.c.

23132 {
23133 return id->pMethods->xShmUnmap(id, deleteFlag);
23134}
23136 sqlite3_file *id, /* Database file handle */
23137 int iPage,
23138 int pgsz,
23139 int bExtend, /* True to extend file if necessary */
SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *, int, int, int, void volatile **)
Definition sqlite3.c:23130

Referenced by walBeginShmUnreliable(), and walIndexPageRealloc().

◆ sqlite3OsShmUnmap()

SQLITE_PRIVATE int sqlite3OsShmUnmap ( sqlite3_file * id,
int deleteFlag )

Definition at line 23127 of file sqlite3.c.

23129 {

◆ sqlite3OsSleep()

SQLITE_PRIVATE int sqlite3OsSleep ( sqlite3_vfs * pVfs,
int nMicro )

Definition at line 23232 of file sqlite3.c.

23232 {
23233 return pVfs->xRandomness(pVfs, nByte, zBufOut);
23234 }
int(* xRandomness)(sqlite3_vfs *, int nByte, char *zOut)
Definition sqlite3.c:2433

Referenced by sqliteDefaultBusyCallback(), and walTryBeginRead().

◆ sqlite3OsSync()

SQLITE_PRIVATE int sqlite3OsSync ( sqlite3_file * id,
int flags )

Definition at line 23060 of file sqlite3.c.

23062 {
23063 return id->pMethods->xTruncate(id, size);

Referenced by pager_end_transaction(), pagerSyncHotJournal(), sqlite3PagerSync(), syncJournal(), vdbeCommit(), walCheckpoint(), walWriteToLog(), and zeroJournalHdr().

◆ sqlite3OsTruncate()

◆ sqlite3OsUnfetch()

SQLITE_PRIVATE int sqlite3OsUnfetch ( sqlite3_file * id,
i64 iOff,
void * p )

Definition at line 23157 of file sqlite3.c.

23158 {
23159 *pp = 0;

References SQLITE_OK.

Referenced by pager_unlock(), pagerBeginReadTransaction(), sqlite3PagerSharedLock(), sqlite3WalCheckpoint(), and vdbePmaReaderSeek().

◆ sqlite3OsUnlock()

SQLITE_PRIVATE int sqlite3OsUnlock ( sqlite3_file * id,
int lockType )

Definition at line 23072 of file sqlite3.c.

23073 {

Referenced by pagerUnlockDb().

◆ sqlite3OsWrite()

SQLITE_PRIVATE int sqlite3OsWrite ( sqlite3_file * id,
const void * pBuf,
int amt,
i64 offset )

◆ sqlite3PageFree()

SQLITE_PRIVATE void sqlite3PageFree ( void * p)

◆ sqlite3PageMalloc()

SQLITE_PRIVATE void * sqlite3PageMalloc ( int sz)

◆ sqlite3PagerBackupPtr()

SQLITE_PRIVATE sqlite3_backup ** sqlite3PagerBackupPtr ( Pager * pPager)

Definition at line 59073 of file sqlite3.c.

References Pager::pBackup.

◆ sqlite3PagerBegin()

SQLITE_PRIVATE int sqlite3PagerBegin ( Pager * pPager,
int exFlag,
int subjInMemory )

Definition at line 57521 of file sqlite3.c.

57527 {
57528 int rc = SQLITE_OK;
57529
57530 if( pPager->errCode ) return pPager->errCode;
57531 assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
57532 pPager->subjInMemory = (u8)subjInMemory;
57533
57534 if( ALWAYS(pPager->eState==PAGER_READER) ){
57535 assert( pPager->pInJournal==0 );
57536
57537 if( pagerUseWal(pPager) ){
57538 /* If the pager is configured to use locking_mode=exclusive, and an
57539 ** exclusive lock on the database is not already held, obtain it now.
57540 */
57541 if( pPager->exclusiveMode && sqlite3WalExclusiveMode(pPager->pWal, -1) ){
57542 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
57543 if( rc!=SQLITE_OK ){
57544 return rc;
57545 }
57546 (void)sqlite3WalExclusiveMode(pPager->pWal, 1);
57547 }
57548
57549 /* Grab the write lock on the log file. If successful, upgrade to
57550 ** PAGER_RESERVED state. Otherwise, return an error code to the caller.
57551 ** The busy-handler is not invoked if another connection already
57552 ** holds the write-lock. If possible, the upper layer will call it.
57553 */
57555 }else{
57556 /* Obtain a RESERVED lock on the database file. If the exFlag parameter
57557 ** is true, then immediately upgrade this to an EXCLUSIVE lock. The
57558 ** busy-handler callback can be used when upgrading to the EXCLUSIVE
57559 ** lock, but not when obtaining the RESERVED lock.
57560 */
57561 rc = pagerLockDb(pPager, RESERVED_LOCK);
57562 if( rc==SQLITE_OK && exFlag ){
57563 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
57564 }
57565 }
57566
57567 if( rc==SQLITE_OK ){
57568 /* Change to WRITER_LOCKED state.
57569 **
57570 ** WAL mode sets Pager.eState to PAGER_WRITER_LOCKED or CACHEMOD
57571 ** when it has an open transaction, but never to DBMOD or FINISHED.
57572 ** This is because in those states the code to roll back savepoint
57573 ** transactions may copy data from the sub-journal into the database
57574 ** file as well as into the page cache. Which would be incorrect in
57575 ** WAL mode.
57576 */
57577 pPager->eState = PAGER_WRITER_LOCKED;
57578 pPager->dbHintSize = pPager->dbSize;
57579 pPager->dbFileSize = pPager->dbSize;
57580 pPager->dbOrigSize = pPager->dbSize;
57581 pPager->journalOff = 0;
57582 }
57583
57584 assert( rc==SQLITE_OK || pPager->eState==PAGER_READER );
57585 assert( rc!=SQLITE_OK || pPager->eState==PAGER_WRITER_LOCKED );
static int pager_wait_on_lock(Pager *pPager, int locktype)
Definition sqlite3.c:55563
SQLITE_PRIVATE int sqlite3WalBeginWriteTransaction(Wal *pWal)
Definition sqlite3.c:62572

References ALWAYS, Pager::dbFileSize, Pager::dbHintSize, Pager::dbOrigSize, Pager::dbSize, Pager::errCode, Pager::eState, EXCLUSIVE_LOCK, Pager::exclusiveMode, Pager::journalOff, PAGER_ERROR, PAGER_READER, pager_wait_on_lock(), PAGER_WRITER_LOCKED, PAGERID, pagerLockDb(), PAGERTRACE, pagerUseWal, Pager::pInJournal, Pager::pWal, RESERVED_LOCK, sqlite3WalBeginWriteTransaction(), sqlite3WalExclusiveMode(), SQLITE_OK, and Pager::subjInMemory.

Referenced by sqlite3BtreeBeginTrans().

◆ sqlite3PagerCacheStat()

SQLITE_PRIVATE void sqlite3PagerCacheStat ( Pager * pPager,
int eStat,
int reset,
int * pnVal )

◆ sqlite3PagerCheckpoint()

SQLITE_PRIVATE int sqlite3PagerCheckpoint ( Pager * pPager,
sqlite3 * db,
int eMode,
int * pnLog,
int * pnCkpt )

Definition at line 59096 of file sqlite3.c.

59108 {
59109 int rc = SQLITE_OK;
59110 if( pPager->pWal ){
59111 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
59112 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
59113 pPager->pBusyHandlerArg,
SQLITE_PRIVATE int sqlite3WalCheckpoint(Wal *pWal, sqlite3 *db, int eMode, int(*xBusy)(void *), void *pBusyArg, int sync_flags, int nBuf, u8 *zBuf, int *pnLog, int *pnCkpt)
Definition sqlite3.c:63134

References Pager::pageSize, Pager::pBusyHandlerArg, Pager::pTmpSpace, Pager::pWal, sqlite3WalCheckpoint(), SQLITE_CHECKPOINT_PASSIVE, SQLITE_OK, Pager::walSyncFlags, and Pager::xBusyHandler.

Referenced by sqlite3BtreeCheckpoint().

◆ sqlite3PagerClearCache()

SQLITE_PRIVATE void sqlite3PagerClearCache ( Pager * pPager)

Definition at line 59081 of file sqlite3.c.

Referenced by sqlite3BtreeCopyFile().

◆ sqlite3PagerClose()

SQLITE_PRIVATE int sqlite3PagerClose ( Pager * pPager,
sqlite3 * db )

Definition at line 55785 of file sqlite3.c.

55791 {
55792 u8 *pTmp = (u8*)pPager->pTmpSpace;
55793 assert( db || pagerUseWal(pPager)==0 );
55794 assert( assert_pager_state(pPager) );
55797 pagerFreeMapHdrs(pPager);
55798 /* pPager->errCode = 0; */
55799 pPager->exclusiveMode = 0;
55800#ifndef SQLITE_OMIT_WAL
55801 {
55802 u8 *a = 0;
55803 assert( db || pPager->pWal==0 );
55804 if( db && 0==(db->flags & SQLITE_NoCkptOnClose)
55805 && SQLITE_OK==databaseIsUnmoved(pPager)
55806 ){
55807 a = pTmp;
55808 }
55809 sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize,a);
55810 pPager->pWal = 0;
55811 }
55812#endif
55813 pager_reset(pPager);
55814 if( MEMDB ){
55815 pager_unlock(pPager);
55816 }else{
55817 /* If it is open, sync the journal file before calling UnlockAndRollback.
55818 ** If this is not done, then an unsynced portion of the open journal
55819 ** file may be played back into the database. If a power failure occurs
55820 ** while this is happening, the database could become corrupt.
55821 **
55822 ** If an error occurs while trying to sync the journal, shift the pager
55823 ** into the ERROR state. This causes UnlockAndRollback to unlock the
55824 ** database and close the journal file without attempting to roll it
55825 ** back or finalize it. The next database user will have to do hot-journal
55826 ** rollback before accessing the database file.
55827 */
55828 if( isOpen(pPager->jfd) ){
55829 pager_error(pPager, pagerSyncHotJournal(pPager));
55830 }
55831 pagerUnlockAndRollback(pPager);
55832 }
55835 PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
55836 IOTRACE(("CLOSE %p\n", pPager))
55837 sqlite3OsClose(pPager->jfd);
55838 sqlite3OsClose(pPager->fd);
55839 sqlite3PageFree(pTmp);
55840 sqlite3PcacheClose(pPager->pPCache);
SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, sqlite3 *, int sync_flags, int, u8 *)
Definition sqlite3.c:61533
static void pagerUnlockAndRollback(Pager *pPager)
Definition sqlite3.c:53854
static int pagerSyncHotJournal(Pager *pPager)
Definition sqlite3.c:55658
static void pager_unlock(Pager *pPager)
Definition sqlite3.c:53516
#define enable_simulated_io_errors()
Definition sqlite3.c:14989
static void pagerFreeMapHdrs(Pager *pPager)
Definition sqlite3.c:55737
SQLITE_PRIVATE void sqlite3PcacheClose(PCache *)
Definition sqlite3.c:49548
#define disable_simulated_io_errors()
Definition sqlite3.c:14988

References Pager::aSavepoint, databaseIsUnmoved(), disable_simulated_io_errors, enable_simulated_io_errors, Pager::exclusiveMode, Pager::fd, sqlite3::flags, IOTRACE, isOpen, Pager::jfd, MEMDB, pager_error(), pager_reset(), pager_unlock(), pagerFreeMapHdrs(), PAGERID, pagerSyncHotJournal(), PAGERTRACE, pagerUnlockAndRollback(), pagerUseWal, Pager::pageSize, Pager::pInJournal, Pager::pPCache, Pager::pTmpSpace, Pager::pWal, Pager::sjfd, sqlite3_free(), sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), sqlite3OsClose(), sqlite3PageFree(), sqlite3PcacheClose(), sqlite3WalClose(), SQLITE_NoCkptOnClose, SQLITE_OK, and Pager::walSyncFlags.

Referenced by sqlite3BtreeOpen().

◆ sqlite3PagerCloseWal()

SQLITE_PRIVATE int sqlite3PagerCloseWal ( Pager * pPager,
sqlite3 * db )

Definition at line 59237 of file sqlite3.c.

59243 {
59244 int rc = SQLITE_OK;
59245
59246 assert( pPager->journalMode==PAGER_JOURNALMODE_WAL );
59247
59248 /* If the log file is not already open, but does exist in the file-system,
59249 ** it may need to be checkpointed before the connection can switch to
59250 ** rollback mode. Open it now so this can happen.
59251 */
59252 if( !pPager->pWal ){
59253 int logexists = 0;
59254 rc = pagerLockDb(pPager, SHARED_LOCK);
59255 if( rc==SQLITE_OK ){
59256 rc = sqlite3OsAccess(
59257 pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &logexists
59258 );
59259 }
59260 if( rc==SQLITE_OK && logexists ){
59261 rc = pagerOpenWal(pPager);
59262 }
59263 }
59264
59265 /* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
59266 ** the database file, the log and log-summary files will be deleted.
59267 */
59268 if( rc==SQLITE_OK && pPager->pWal ){
59269 rc = pagerExclusiveLock(pPager);
59270 if( rc==SQLITE_OK ){
59271 rc = sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags,
59272 pPager->pageSize, (u8*)pPager->pTmpSpace);
59273 pPager->pWal = 0;
static int pagerOpenWal(Pager *pPager)
Definition sqlite3.c:59153

References Pager::exclusiveMode, Pager::journalMode, PAGER_JOURNALMODE_WAL, pagerExclusiveLock(), pagerFixMaplimit(), pagerLockDb(), pagerOpenWal(), pagerUnlockDb(), Pager::pageSize, Pager::pTmpSpace, Pager::pVfs, Pager::pWal, SHARED_LOCK, sqlite3OsAccess(), sqlite3WalClose(), SQLITE_ACCESS_EXISTS, SQLITE_OK, Pager::walSyncFlags, and Pager::zWal.

Referenced by sqlite3VdbeExec().

◆ sqlite3PagerCommitPhaseOne()

SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne ( Pager * pPager,
const char * zSuper,
int noSync )

Definition at line 58064 of file sqlite3.c.

58074 {
58075 int rc = SQLITE_OK; /* Return code */
58076
58077 assert( pPager->eState==PAGER_WRITER_LOCKED
58078 || pPager->eState==PAGER_WRITER_CACHEMOD
58079 || pPager->eState==PAGER_WRITER_DBMOD
58080 || pPager->eState==PAGER_ERROR
58081 );
58082 assert( assert_pager_state(pPager) );
58083
58084 /* If a prior error occurred, report that error again. */
58085 if( NEVER(pPager->errCode) ) return pPager->errCode;
58086
58087 /* Provide the ability to easily simulate an I/O error during testing */
58088 if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
58089
58090 PAGERTRACE(("DATABASE SYNC: File=%s zSuper=%s nSize=%d\n",
58091 pPager->zFilename, zSuper, pPager->dbSize));
58092
58093 /* If no database changes have been made, return early. */
58094 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
58095
58096 assert( MEMDB==0 || pPager->tempFile );
58097 assert( isOpen(pPager->fd) || pPager->tempFile );
58098 if( 0==pagerFlushOnCommit(pPager, 1) ){
58099 /* If this is an in-memory db, or no pages have been written to, or this
58100 ** function has already been called, it is mostly a no-op. However, any
58101 ** backup in progress needs to be restarted. */
58103 }else{
58104 PgHdr *pList;
58105 if( pagerUseWal(pPager) ){
58106 PgHdr *pPageOne = 0;
58107 pList = sqlite3PcacheDirtyList(pPager->pPCache);
58108 if( pList==0 ){
58109 /* Must have at least one page for the WAL commit flag.
58110 ** Ticket [2d1a5c67dfc2363e44f29d9bbd57f] 2011-05-18 */
58111 rc = sqlite3PagerGet(pPager, 1, &pPageOne, 0);
58112 pList = pPageOne;
58113 pList->pDirty = 0;
58114 }
58115 assert( rc==SQLITE_OK );
58116 if( ALWAYS(pList) ){
58117 rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1);
58118 }
58119 sqlite3PagerUnref(pPageOne);
58120 if( rc==SQLITE_OK ){
58122 }
58123 }else{
58124 /* The bBatch boolean is true if the batch-atomic-write commit method
58125 ** should be used. No rollback journal is created if batch-atomic-write
58126 ** is enabled.
58127 */
58128#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58129 sqlite3_file *fd = pPager->fd;
58130 int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
58132 && !pPager->noSync
58133 && sqlite3JournalIsInMemory(pPager->jfd);
58134#else
58135# define bBatch 0
58136#endif
58137
58138#ifdef SQLITE_ENABLE_ATOMIC_WRITE
58139 /* The following block updates the change-counter. Exactly how it
58140 ** does this depends on whether or not the atomic-update optimization
58141 ** was enabled at compile time, and if this transaction meets the
58142 ** runtime criteria to use the operation:
58143 **
58144 ** * The file-system supports the atomic-write property for
58145 ** blocks of size page-size, and
58146 ** * This commit is not part of a multi-file transaction, and
58147 ** * Exactly one page has been modified and store in the journal file.
58148 **
58149 ** If the optimization was not enabled at compile time, then the
58150 ** pager_incr_changecounter() function is called to update the change
58151 ** counter in 'indirect-mode'. If the optimization is compiled in but
58152 ** is not applicable to this transaction, call sqlite3JournalCreate()
58153 ** to make sure the journal file has actually been created, then call
58154 ** pager_incr_changecounter() to update the change-counter in indirect
58155 ** mode.
58156 **
58157 ** Otherwise, if the optimization is both enabled and applicable,
58158 ** then call pager_incr_changecounter() to update the change-counter
58159 ** in 'direct' mode. In this case the journal file will never be
58160 ** created for this transaction.
58161 */
58162 if( bBatch==0 ){
58163 PgHdr *pPg;
58164 assert( isOpen(pPager->jfd)
58167 );
58168 if( !zSuper && isOpen(pPager->jfd)
58169 && pPager->journalOff==jrnlBufferSize(pPager)
58170 && pPager->dbSize>=pPager->dbOrigSize
58171 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
58172 ){
58173 /* Update the db file change counter via the direct-write method. The
58174 ** following call will modify the in-memory representation of page 1
58175 ** to include the updated change counter and then write page 1
58176 ** directly to the database file. Because of the atomic-write
58177 ** property of the host file-system, this is safe.
58178 */
58179 rc = pager_incr_changecounter(pPager, 1);
58180 }else{
58181 rc = sqlite3JournalCreate(pPager->jfd);
58182 if( rc==SQLITE_OK ){
58183 rc = pager_incr_changecounter(pPager, 0);
58184 }
58185 }
58186 }
58187#else /* SQLITE_ENABLE_ATOMIC_WRITE */
58188#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58189 if( zSuper ){
58190 rc = sqlite3JournalCreate(pPager->jfd);
58191 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58192 assert( bBatch==0 );
58193 }
58194#endif
58195 rc = pager_incr_changecounter(pPager, 0);
58196#endif /* !SQLITE_ENABLE_ATOMIC_WRITE */
58197 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58198
58199 /* Write the super-journal name into the journal file. If a
58200 ** super-journal file name has already been written to the journal file,
58201 ** or if zSuper is NULL (no super-journal), then this call is a no-op.
58202 */
58203 rc = writeSuperJournal(pPager, zSuper);
58204 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58205
58206 /* Sync the journal file and write all dirty pages to the database.
58207 ** If the atomic-update optimization is being used, this sync will not
58208 ** create the journal file or perform any real IO.
58209 **
58210 ** Because the change-counter page was just modified, unless the
58211 ** atomic-update optimization is used it is almost certain that the
58212 ** journal requires a sync here. However, in locking_mode=exclusive
58213 ** on a system under memory pressure it is just possible that this is
58214 ** not the case. In this case it is likely enough that the redundant
58215 ** xSync() call will be changed to a no-op by the OS anyhow.
58216 */
58217 rc = syncJournal(pPager, 0);
58218 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58219
58220 pList = sqlite3PcacheDirtyList(pPager->pPCache);
58221#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58222 if( bBatch ){
58224 if( rc==SQLITE_OK ){
58225 rc = pager_write_pagelist(pPager, pList);
58226 if( rc==SQLITE_OK ){
58228 }
58229 if( rc!=SQLITE_OK ){
58231 }
58232 }
58233
58234 if( (rc&0xFF)==SQLITE_IOERR && rc!=SQLITE_IOERR_NOMEM ){
58235 rc = sqlite3JournalCreate(pPager->jfd);
58236 if( rc!=SQLITE_OK ){
58237 sqlite3OsClose(pPager->jfd);
58238 goto commit_phase_one_exit;
58239 }
58240 bBatch = 0;
58241 }else{
58242 sqlite3OsClose(pPager->jfd);
58243 }
58244 }
58245#endif /* SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
58246
58247 if( bBatch==0 ){
58248 rc = pager_write_pagelist(pPager, pList);
58249 }
58250 if( rc!=SQLITE_OK ){
58251 assert( rc!=SQLITE_IOERR_BLOCKED );
58252 goto commit_phase_one_exit;
58253 }
58255
58256 /* If the file on disk is smaller than the database image, use
58257 ** pager_truncate to grow the file here. This can happen if the database
58258 ** image was extended as part of the current transaction and then the
58259 ** last page in the db image moved to the free-list. In this case the
58260 ** last page is never written out to disk, leaving the database file
58261 ** undersized. Fix this now if it is the case. */
58262 if( pPager->dbSize>pPager->dbFileSize ){
58263 Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager));
58264 assert( pPager->eState==PAGER_WRITER_DBMOD );
58265 rc = pager_truncate(pPager, nNew);
58266 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58267 }
58268
58269 /* Finally, sync the database file. */
58270 if( !noSync ){
58271 rc = sqlite3PagerSync(pPager, zSuper);
58272 }
58273 IOTRACE(("DBSYNC %p\n", pPager))
58274 }
58275 }
58276
static int writeSuperJournal(Pager *pPager, const char *zSuper)
Definition sqlite3.c:53379
SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *)
Definition sqlite3.c:75755
#define bBatch
#define SQLITE_IOERR_BLOCKED
Definition sqlite3.c:1533
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE
Definition sqlite3.c:2208
static int pager_incr_changecounter(Pager *pPager, int isDirectMode)
Definition sqlite3.c:57916
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE
Definition sqlite3.c:2210
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE
Definition sqlite3.c:2209

References ALWAYS, bBatch, Pager::dbFileSize, Pager::dbOrigSize, Pager::dbSize, Pager::errCode, Pager::eState, Pager::fd, IOTRACE, isOpen, Pager::jfd, Pager::journalMode, Pager::journalOff, jrnlBufferSize(), MEMDB, NEVER, Pager::noSync, PAGER_ERROR, pager_incr_changecounter(), PAGER_JOURNALMODE_OFF, PAGER_JOURNALMODE_WAL, PAGER_MJ_PGNO, pager_truncate(), pager_write_pagelist(), PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, PAGER_WRITER_FINISHED, PAGER_WRITER_LOCKED, pagerFlushOnCommit(), PAGERTRACE, pagerUseWal, pagerWalFrames(), Pager::pBackup, PgHdr::pDirty, Pager::pPCache, sqlite3BackupRestart(), sqlite3FaultSim(), sqlite3JournalIsInMemory(), sqlite3OsClose(), sqlite3OsDeviceCharacteristics(), sqlite3OsFileControl(), sqlite3OsFileControlHint(), sqlite3PagerGet(), sqlite3PagerSync(), sqlite3PagerUnref(), sqlite3PcacheCleanAll(), sqlite3PcacheDirtyList(), SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, SQLITE_IOCAP_BATCH_ATOMIC, SQLITE_IOERR, SQLITE_IOERR_BLOCKED, SQLITE_IOERR_NOMEM, SQLITE_OK, syncJournal(), Pager::tempFile, writeSuperJournal(), and Pager::zFilename.

Referenced by sqlite3BtreeCommitPhaseOne().

◆ sqlite3PagerCommitPhaseTwo()

SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo ( Pager * pPager)

Definition at line 58294 of file sqlite3.c.

58300 {
58301 int rc = SQLITE_OK; /* Return code */
58302
58303 /* This routine should not be called if a prior error has occurred.
58304 ** But if (due to a coding error elsewhere in the system) it does get
58305 ** called, just return the same error code without doing anything. */
58306 if( NEVER(pPager->errCode) ) return pPager->errCode;
58307 pPager->iDataVersion++;
58308
58309 assert( pPager->eState==PAGER_WRITER_LOCKED
58310 || pPager->eState==PAGER_WRITER_FINISHED
58311 || (pagerUseWal(pPager) && pPager->eState==PAGER_WRITER_CACHEMOD)
58312 );
58313 assert( assert_pager_state(pPager) );
58314
58315 /* An optimization. If the database was not actually modified during
58316 ** this transaction, the pager is running in exclusive-mode and is
58317 ** using persistent journals, then this function is a no-op.
58318 **
58319 ** The start of the journal file currently contains a single journal
58320 ** header with the nRec field set to 0. If such a journal is used as
58321 ** a hot-journal during hot-journal rollback, 0 changes will be made
58322 ** to the database file. So there is no need to zero the journal
58323 ** header. Since the pager is in exclusive mode, there is no need
58324 ** to drop any locks either.
58325 */
58326 if( pPager->eState==PAGER_WRITER_LOCKED
58327 && pPager->exclusiveMode
58329 ){
58330 assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) || !pPager->journalOff );
58331 pPager->eState = PAGER_READER;
58332 return SQLITE_OK;
#define PAGER_WRITER_FINISHED
Definition sqlite3.c:52058
u32 iDataVersion
Definition sqlite3.c:52369

References Pager::errCode, Pager::eState, Pager::exclusiveMode, Pager::iDataVersion, JOURNAL_HDR_SZ, Pager::journalMode, Pager::journalOff, NEVER, pager_end_transaction(), pager_error(), PAGER_JOURNALMODE_PERSIST, PAGER_READER, PAGER_WRITER_CACHEMOD, PAGER_WRITER_FINISHED, PAGER_WRITER_LOCKED, PAGERID, PAGERTRACE, pagerUseWal, Pager::setSuper, and SQLITE_OK.

Referenced by sqlite3BtreeCommitPhaseTwo().

◆ sqlite3PagerDataVersion()

SQLITE_PRIVATE u32 sqlite3PagerDataVersion ( Pager * pPager)

Definition at line 53456 of file sqlite3.c.

Referenced by sqlite3BtreeGetMeta().

◆ sqlite3PagerDontWrite()

SQLITE_PRIVATE void sqlite3PagerDontWrite ( DbPage * pPg)

Definition at line 57882 of file sqlite3.c.

57888 {
57889 Pager *pPager = pPg->pPager;
57890 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
57891 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
57892 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))

References PgHdr::flags, IOTRACE, Pager::nSavepoint, pager_set_pagehash, PAGERID, PAGERTRACE, PGHDR_DIRTY, PGHDR_DONT_WRITE, PGHDR_NEED_SYNC, PgHdr::pgno, PgHdr::pPager, Pager::tempFile, and testcase.

Referenced by freePage2().

◆ sqlite3PagerExclusiveLock()

SQLITE_PRIVATE int sqlite3PagerExclusiveLock ( Pager * pPager)

Definition at line 58022 of file sqlite3.c.

58028 {
58029 int rc = pPager->errCode;
58030 assert( assert_pager_state(pPager) );
58031 if( rc==SQLITE_OK ){
58032 assert( pPager->eState==PAGER_WRITER_CACHEMOD
58033 || pPager->eState==PAGER_WRITER_DBMOD
58034 || pPager->eState==PAGER_WRITER_LOCKED
58035 );
58036 assert( assert_pager_state(pPager) );

References Pager::errCode, Pager::eState, EXCLUSIVE_LOCK, pager_wait_on_lock(), PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, PAGER_WRITER_LOCKED, pagerUseWal, and SQLITE_OK.

Referenced by syncJournal(), and vdbeCommit().

◆ sqlite3PagerFile()

SQLITE_PRIVATE sqlite3_file * sqlite3PagerFile ( Pager * pPager)

Definition at line 58694 of file sqlite3.c.

References Pager::fd.

Referenced by accessPayload(), sqlite3BtreeCopyFile(), sqlite3BtreeOpen(), and sqlite3Pragma().

◆ sqlite3PagerFilename()

SQLITE_PRIVATE const char * sqlite3PagerFilename ( const Pager * pPager,
int nullIfMemDb )

Definition at line 58677 of file sqlite3.c.

Referenced by sqlite3BtreeGetFilename(), sqlite3BtreeOpen(), and sqlite3VdbeExec().

◆ sqlite3PagerFlush()

SQLITE_PRIVATE int sqlite3PagerFlush ( Pager * pPager)

Definition at line 56293 of file sqlite3.c.

56299 {
56300 int rc = pPager->errCode;
56301 if( !MEMDB ){
56302 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
56303 assert( assert_pager_state(pPager) );
56304 while( rc==SQLITE_OK && pList ){
56305 PgHdr *pNext = pList->pDirty;
56306 if( pList->nRef==0 ){
56307 rc = pagerStress((void*)pPager, pList);
56308 }
static int pagerStress(void *p, PgHdr *pPg)
Definition sqlite3.c:56216
i16 nRef
Definition sqlite3.c:16062

◆ sqlite3PagerGet()

◆ sqlite3PagerGetData()

SQLITE_PRIVATE void * sqlite3PagerGetData ( DbPage * pPg)

◆ sqlite3PagerGetExtra()

SQLITE_PRIVATE void * sqlite3PagerGetExtra ( DbPage * pPg)

◆ sqlite3PagerGetJournalMode()

SQLITE_PRIVATE int sqlite3PagerGetJournalMode ( Pager * pPager)

Definition at line 59037 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and vdbeCommit().

◆ sqlite3PagerIsMemdb()

SQLITE_PRIVATE int sqlite3PagerIsMemdb ( Pager * pPager)

Definition at line 58497 of file sqlite3.c.

Referenced by backupOnePage(), and vdbeCommit().

◆ sqlite3PagerIsreadonly()

SQLITE_PRIVATE u8 sqlite3PagerIsreadonly ( Pager * pPager)

Definition at line 58410 of file sqlite3.c.

Referenced by sqlite3BtreeBeginTrans(), and sqlite3BtreeOpen().

◆ sqlite3PagerJournalname()

SQLITE_PRIVATE const char * sqlite3PagerJournalname ( Pager * pPager)

Definition at line 58713 of file sqlite3.c.

◆ sqlite3PagerJournalSizeLimit()

SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit ( Pager * pPager,
i64 iLimit )

Definition at line 59059 of file sqlite3.c.

59065 {

References Pager::journalSizeLimit, Pager::pWal, and sqlite3WalLimit().

Referenced by sqlite3Pragma().

◆ sqlite3PagerJrnlFile()

SQLITE_PRIVATE sqlite3_file * sqlite3PagerJrnlFile ( Pager * pPager)

Definition at line 58702 of file sqlite3.c.

58708 {

◆ sqlite3PagerLockingMode()

SQLITE_PRIVATE int sqlite3PagerLockingMode ( Pager * pPager,
int eMode )

Definition at line 58913 of file sqlite3.c.

58919 {
58920 assert( eMode==PAGER_LOCKINGMODE_QUERY
58921 || eMode==PAGER_LOCKINGMODE_NORMAL
58922 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
58923 assert( PAGER_LOCKINGMODE_QUERY<0 );
#define PAGER_LOCKINGMODE_NORMAL
Definition sqlite3.c:14817
#define PAGER_LOCKINGMODE_QUERY
Definition sqlite3.c:14816
#define PAGER_LOCKINGMODE_EXCLUSIVE
Definition sqlite3.c:14818

References Pager::exclusiveMode, PAGER_LOCKINGMODE_EXCLUSIVE, PAGER_LOCKINGMODE_NORMAL, PAGER_LOCKINGMODE_QUERY, Pager::pWal, sqlite3WalHeapMemory(), and Pager::tempFile.

Referenced by attachFunc(), openDatabase(), and sqlite3Pragma().

◆ sqlite3PagerLookup()

SQLITE_PRIVATE DbPage * sqlite3PagerLookup ( Pager * pPager,
Pgno pgno )

◆ sqlite3PagerMaxPageCount()

SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount ( Pager * pPager,
Pgno mxPage )

Definition at line 55464 of file sqlite3.c.

55470 {
55471 if( mxPage>0 ){
55472 pPager->mxPgno = mxPage;
55473 }
55474 assert( pPager->eState!=PAGER_OPEN ); /* Called only by OP_MaxPgcnt */

References Pager::eState, Pager::mxPgno, and PAGER_OPEN.

Referenced by sqlite3BtreeMaxPageCount().

◆ sqlite3PagerMemUsed()

SQLITE_PRIVATE int sqlite3PagerMemUsed ( Pager * pPager)

◆ sqlite3PagerMovepage()

SQLITE_PRIVATE int sqlite3PagerMovepage ( Pager * pPager,
DbPage * pPg,
Pgno pgno,
int isCommit )

Definition at line 58743 of file sqlite3.c.

58749 {
58750 PgHdr *pPgOld; /* The page being overwritten. */
58751 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
58752 int rc; /* Return code */
58753 Pgno origPgno; /* The original page number */
58754
58755 assert( pPg->nRef>0 );
58756 assert( pPager->eState==PAGER_WRITER_CACHEMOD
58757 || pPager->eState==PAGER_WRITER_DBMOD
58758 );
58759 assert( assert_pager_state(pPager) );
58760
58761 /* In order to be able to rollback, an in-memory database must journal
58762 ** the page we are moving from.
58763 */
58764 assert( pPager->tempFile || !MEMDB );
58765 if( pPager->tempFile ){
58766 rc = sqlite3PagerWrite(pPg);
58767 if( rc ) return rc;
58768 }
58769
58770 /* If the page being moved is dirty and has not been saved by the latest
58771 ** savepoint, then save the current contents of the page into the
58772 ** sub-journal now. This is required to handle the following scenario:
58773 **
58774 ** BEGIN;
58775 ** <journal page X, then modify it in memory>
58776 ** SAVEPOINT one;
58777 ** <Move page X to location Y>
58778 ** ROLLBACK TO one;
58779 **
58780 ** If page X were not written to the sub-journal here, it would not
58781 ** be possible to restore its contents when the "ROLLBACK TO one"
58782 ** statement were is processed.
58783 **
58784 ** subjournalPage() may need to allocate space to store pPg->pgno into
58785 ** one or more savepoint bitvecs. This is the reason this function
58786 ** may return SQLITE_NOMEM.
58787 */
58788 if( (pPg->flags & PGHDR_DIRTY)!=0
58789 && SQLITE_OK!=(rc = subjournalPageIfRequired(pPg))
58790 ){
58791 return rc;
58792 }
58793
58794 PAGERTRACE(("MOVE %d page %d (needSync=%d) moves to %d\n",
58795 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
58796 IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
58797
58798 /* If the journal needs to be sync()ed before page pPg->pgno can
58799 ** be written to, store pPg->pgno in local variable needSyncPgno.
58800 **
58801 ** If the isCommit flag is set, there is no need to remember that
58802 ** the journal needs to be sync()ed before database page pPg->pgno
58803 ** can be written to. The caller has already promised not to write to it.
58804 */
58805 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
58806 needSyncPgno = pPg->pgno;
58807 assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
58808 pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
58809 assert( pPg->flags&PGHDR_DIRTY );
58810 }
58811
58812 /* If the cache contains a page with page-number pgno, remove it
58813 ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
58814 ** page pgno before the 'move' operation, it needs to be retained
58815 ** for the page moved there.
58816 */
58817 pPg->flags &= ~PGHDR_NEED_SYNC;
58818 pPgOld = sqlite3PagerLookup(pPager, pgno);
58819 assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
58820 if( pPgOld ){
58821 if( pPgOld->nRef>1 ){
58823 return SQLITE_CORRUPT_BKPT;
58824 }
58825 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
58826 if( pPager->tempFile ){
58827 /* Do not discard pages from an in-memory database since we might
58828 ** need to rollback later. Just move the page out of the way. */
58829 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
58830 }else{
58831 sqlite3PcacheDrop(pPgOld);
58832 }
58833 }
58834
58835 origPgno = pPg->pgno;
58836 sqlite3PcacheMove(pPg, pgno);
58838
58839 /* For an in-memory database, make sure the original page continues
58840 ** to exist, in case the transaction needs to roll back. Use pPgOld
58841 ** as the original page since it has already been allocated.
58842 */
58843 if( pPager->tempFile && pPgOld ){
58844 sqlite3PcacheMove(pPgOld, origPgno);
58846 }
58847
58848 if( needSyncPgno ){
58849 /* If needSyncPgno is non-zero, then the journal file needs to be
58850 ** sync()ed before any data is written to database file page needSyncPgno.
58851 ** Currently, no such page exists in the page-cache and the
58852 ** "is journaled" bitvec flag has been set. This needs to be remedied by
58853 ** loading the page into the pager-cache and setting the PGHDR_NEED_SYNC
58854 ** flag.
58855 **
58856 ** If the attempt to load the page into the page-cache fails, (due
58857 ** to a malloc() or IO failure), clear the bit in the pInJournal[]
58858 ** array. Otherwise, if the page is loaded and written again in
58859 ** this transaction, it may be written to the database file before
58860 ** it is synced into the journal file. This way, it may end up in
58861 ** the journal file twice, but that is not a problem.
58862 */
58863 PgHdr *pPgHdr;
58864 rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr, 0);
58865 if( rc!=SQLITE_OK ){
58866 if( needSyncPgno<=pPager->dbOrigSize ){
58867 assert( pPager->pTmpSpace!=0 );
58868 sqlite3BitvecClear(pPager->pInJournal, needSyncPgno, pPager->pTmpSpace);
58869 }
58870 return rc;
58871 }
58872 pPgHdr->flags |= PGHDR_NEED_SYNC;
SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *, Pgno)
Definition sqlite3.c:49493

References CORRUPT_DB, Pager::dbOrigSize, Pager::dbSize, Pager::eState, PgHdr::flags, IOTRACE, Pager::journalMode, MEMDB, PgHdr::nRef, PAGER_JOURNALMODE_OFF, PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, PAGERID, PAGERTRACE, PGHDR_DIRTY, PGHDR_NEED_SYNC, PgHdr::pgno, Pager::pInJournal, Pager::pTmpSpace, sqlite3BitvecClear(), sqlite3PagerGet(), sqlite3PagerLookup(), sqlite3PagerUnrefNotNull(), sqlite3PagerWrite(), sqlite3PcacheDrop(), sqlite3PcacheMakeDirty(), sqlite3PcacheMove(), SQLITE_CORRUPT_BKPT, SQLITE_OK, subjournalPageIfRequired(), and Pager::tempFile.

Referenced by relocatePage().

◆ sqlite3PagerOkToChangeJournalMode()

SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode ( Pager * pPager)

Definition at line 59046 of file sqlite3.c.

References Pager::eState, isOpen, Pager::jfd, Pager::journalOff, NEVER, and PAGER_WRITER_CACHEMOD.

Referenced by sqlite3VdbeExec().

◆ sqlite3PagerOpen()

SQLITE_PRIVATE int sqlite3PagerOpen ( sqlite3_vfs * pVfs,
Pager ** ppPager,
const char * zFilename,
int nExtra,
int flags,
int vfsFlags,
void(*)(DbPage *) xReinit )

Definition at line 56342 of file sqlite3.c.

56356 {
56357 u8 *pPtr;
56358 Pager *pPager = 0; /* Pager object to allocate and return */
56359 int rc = SQLITE_OK; /* Return code */
56360 int tempFile = 0; /* True for temp files (incl. in-memory files) */
56361 int memDb = 0; /* True if this is an in-memory file */
56362#ifdef SQLITE_ENABLE_DESERIALIZE
56363 int memJM = 0; /* Memory journal mode */
56364#else
56365# define memJM 0
56366#endif
56367 int readOnly = 0; /* True if this is a read-only file */
56368 int journalFileSize; /* Bytes to allocate for each journal fd */
56369 char *zPathname = 0; /* Full path to database file */
56370 int nPathname = 0; /* Number of bytes in zPathname */
56371 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
56372 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
56373 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
56374 const char *zUri = 0; /* URI args to copy */
56375 int nUriByte = 1; /* Number of bytes of URI args at *zUri */
56376 int nUri = 0; /* Number of URI parameters */
56377
56378 /* Figure out how much space is required for each journal file-handle
56379 ** (there are two of them, the main journal and the sub-journal). */
56380 journalFileSize = ROUND8(sqlite3JournalSize(pVfs));
56381
56382 /* Set the output variable to NULL in case an error occurs. */
56383 *ppPager = 0;
56384
56385#ifndef SQLITE_OMIT_MEMORYDB
56386 if( flags & PAGER_MEMORY ){
56387 memDb = 1;
56388 if( zFilename && zFilename[0] ){
56389 zPathname = sqlite3DbStrDup(0, zFilename);
56390 if( zPathname==0 ) return SQLITE_NOMEM_BKPT;
56391 nPathname = sqlite3Strlen30(zPathname);
56392 zFilename = 0;
56393 }
56394 }
56395#endif
56396
56397 /* Compute and store the full pathname in an allocated buffer pointed
56398 ** to by zPathname, length nPathname. Or, if this is a temporary file,
56399 ** leave both nPathname and zPathname set to 0.
56400 */
56401 if( zFilename && zFilename[0] ){
56402 const char *z;
56403 nPathname = pVfs->mxPathname+1;
56404 zPathname = sqlite3DbMallocRaw(0, nPathname*2);
56405 if( zPathname==0 ){
56406 return SQLITE_NOMEM_BKPT;
56407 }
56408 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
56409 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
56410 if( rc!=SQLITE_OK ){
56411 if( rc==SQLITE_OK_SYMLINK ){
56412 if( vfsFlags & SQLITE_OPEN_NOFOLLOW ){
56414 }else{
56415 rc = SQLITE_OK;
56416 }
56417 }
56418 }
56419 nPathname = sqlite3Strlen30(zPathname);
56420 z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
56421 while( *z ){
56422 z += strlen(z)+1;
56423 z += strlen(z)+1;
56424 nUri++;
56425 }
56426 nUriByte = (int)(&z[1] - zUri);
56427 assert( nUriByte>=1 );
56428 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
56429 /* This branch is taken when the journal path required by
56430 ** the database being opened will be more than pVfs->mxPathname
56431 ** bytes in length. This means the database cannot be opened,
56432 ** as it will not be possible to open the journal file or even
56433 ** check for a hot-journal before reading.
56434 */
56436 }
56437 if( rc!=SQLITE_OK ){
56438 sqlite3DbFree(0, zPathname);
56439 return rc;
56440 }
56441 }
56442
56443 /* Allocate memory for the Pager structure, PCache object, the
56444 ** three file descriptors, the database file name and the journal
56445 ** file name. The layout in memory is as follows:
56446 **
56447 ** Pager object (sizeof(Pager) bytes)
56448 ** PCache object (sqlite3PcacheSize() bytes)
56449 ** Database file handle (pVfs->szOsFile bytes)
56450 ** Sub-journal file handle (journalFileSize bytes)
56451 ** Main journal file handle (journalFileSize bytes)
56452 ** Ptr back to the Pager (sizeof(Pager*) bytes)
56453 ** \0\0\0\0 database prefix (4 bytes)
56454 ** Database file name (nPathname+1 bytes)
56455 ** URI query parameters (nUriByte bytes)
56456 ** Journal filename (nPathname+8+1 bytes)
56457 ** WAL filename (nPathname+4+1 bytes)
56458 ** \0\0\0 terminator (3 bytes)
56459 **
56460 ** Some 3rd-party software, over which we have no control, depends on
56461 ** the specific order of the filenames and the \0 separators between them
56462 ** so that it can (for example) find the database filename given the WAL
56463 ** filename without using the sqlite3_filename_database() API. This is a
56464 ** misuse of SQLite and a bug in the 3rd-party software, but the 3rd-party
56465 ** software is in widespread use, so we try to avoid changing the filename
56466 ** order and formatting if possible. In particular, the details of the
56467 ** filename format expected by 3rd-party software should be as follows:
56468 **
56469 ** - Main Database Path
56470 ** - \0
56471 ** - Multiple URI components consisting of:
56472 ** - Key
56473 ** - \0
56474 ** - Value
56475 ** - \0
56476 ** - \0
56477 ** - Journal Path
56478 ** - \0
56479 ** - WAL Path (zWALName)
56480 ** - \0
56481 **
56482 ** The sqlite3_create_filename() interface and the databaseFilename() utility
56483 ** that is used by sqlite3_filename_database() and kin also depend on the
56484 ** specific formatting and order of the various filenames, so if the format
56485 ** changes here, be sure to change it there as well.
56486 */
56487 pPtr = (u8 *)sqlite3MallocZero(
56488 ROUND8(sizeof(*pPager)) + /* Pager structure */
56489 ROUND8(pcacheSize) + /* PCache object */
56490 ROUND8(pVfs->szOsFile) + /* The main db file */
56491 journalFileSize * 2 + /* The two journal files */
56492 sizeof(pPager) + /* Space to hold a pointer */
56493 4 + /* Database prefix */
56494 nPathname + 1 + /* database filename */
56495 nUriByte + /* query parameters */
56496 nPathname + 8 + 1 + /* Journal filename */
56497#ifndef SQLITE_OMIT_WAL
56498 nPathname + 4 + 1 + /* WAL filename */
56499#endif
56500 3 /* Terminator */
56501 );
56502 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
56503 if( !pPtr ){
56504 sqlite3DbFree(0, zPathname);
56505 return SQLITE_NOMEM_BKPT;
56506 }
56507 pPager = (Pager*)pPtr; pPtr += ROUND8(sizeof(*pPager));
56508 pPager->pPCache = (PCache*)pPtr; pPtr += ROUND8(pcacheSize);
56509 pPager->fd = (sqlite3_file*)pPtr; pPtr += ROUND8(pVfs->szOsFile);
56510 pPager->sjfd = (sqlite3_file*)pPtr; pPtr += journalFileSize;
56511 pPager->jfd = (sqlite3_file*)pPtr; pPtr += journalFileSize;
56512 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
56513 memcpy(pPtr, &pPager, sizeof(pPager)); pPtr += sizeof(pPager);
56514
56515 /* Fill in the Pager.zFilename and pPager.zQueryParam fields */
56516 pPtr += 4; /* Skip zero prefix */
56517 pPager->zFilename = (char*)pPtr;
56518 if( nPathname>0 ){
56519 memcpy(pPtr, zPathname, nPathname); pPtr += nPathname + 1;
56520 if( zUri ){
56521 memcpy(pPtr, zUri, nUriByte); pPtr += nUriByte;
56522 }else{
56523 pPtr++;
56524 }
56525 }
56526
56527
56528 /* Fill in Pager.zJournal */
56529 if( nPathname>0 ){
56530 pPager->zJournal = (char*)pPtr;
56531 memcpy(pPtr, zPathname, nPathname); pPtr += nPathname;
56532 memcpy(pPtr, "-journal",8); pPtr += 8 + 1;
56533#ifdef SQLITE_ENABLE_8_3_NAMES
56534 sqlite3FileSuffix3(zFilename,pPager->zJournal);
56535 pPtr = (u8*)(pPager->zJournal + sqlite3Strlen30(pPager->zJournal)+1);
56536#endif
56537 }else{
56538 pPager->zJournal = 0;
56539 }
56540
56541#ifndef SQLITE_OMIT_WAL
56542 /* Fill in Pager.zWal */
56543 if( nPathname>0 ){
56544 pPager->zWal = (char*)pPtr;
56545 memcpy(pPtr, zPathname, nPathname); pPtr += nPathname;
56546 memcpy(pPtr, "-wal", 4); pPtr += 4 + 1;
56547#ifdef SQLITE_ENABLE_8_3_NAMES
56548 sqlite3FileSuffix3(zFilename, pPager->zWal);
56549 pPtr = (u8*)(pPager->zWal + sqlite3Strlen30(pPager->zWal)+1);
56550#endif
56551 }else{
56552 pPager->zWal = 0;
56553 }
56554#endif
56555
56556 if( nPathname ) sqlite3DbFree(0, zPathname);
56557 pPager->pVfs = pVfs;
56558 pPager->vfsFlags = vfsFlags;
56559
56560 /* Open the pager file.
56561 */
56562 if( zFilename && zFilename[0] ){
56563 int fout = 0; /* VFS flags returned by xOpen() */
56564 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
56565 assert( !memDb );
56566#ifdef SQLITE_ENABLE_DESERIALIZE
56567 memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
56568#endif
56569 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
56570
56571 /* If the file was successfully opened for read/write access,
56572 ** choose a default page size in case we have to create the
56573 ** database file. The default page size is the maximum of:
56574 **
56575 ** + SQLITE_DEFAULT_PAGE_SIZE,
56576 ** + The value returned by sqlite3OsSectorSize()
56577 ** + The largest page size that can be written atomically.
56578 */
56579 if( rc==SQLITE_OK ){
56580 int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
56581 if( !readOnly ){
56582 setSectorSize(pPager);
56584 if( szPageDflt<pPager->sectorSize ){
56586 szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
56587 }else{
56588 szPageDflt = (u32)pPager->sectorSize;
56589 }
56590 }
56591#ifdef SQLITE_ENABLE_ATOMIC_WRITE
56592 {
56593 int ii;
56594 assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
56595 assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
56596 assert(SQLITE_MAX_DEFAULT_PAGE_SIZE<=65536);
56597 for(ii=szPageDflt; ii<=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
56598 if( iDc&(SQLITE_IOCAP_ATOMIC|(ii>>8)) ){
56599 szPageDflt = ii;
56600 }
56601 }
56602 }
56603#endif
56604 }
56605 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
56606 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
56607 || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
56608 vfsFlags |= SQLITE_OPEN_READONLY;
56609 goto act_like_temp_file;
56610 }
56611 }
56612 }else{
56613 /* If a temporary file is requested, it is not opened immediately.
56614 ** In this case we accept the default page size and delay actually
56615 ** opening the file until the first call to OsWrite().
56616 **
56617 ** This branch is also run for an in-memory database. An in-memory
56618 ** database is the same as a temp-file that is never written out to
56619 ** disk and uses an in-memory rollback journal.
56620 **
56621 ** This branch also runs for files marked as immutable.
56622 */
56623act_like_temp_file:
56624 tempFile = 1;
56625 pPager->eState = PAGER_READER; /* Pretend we already have a lock */
56626 pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE mode */
56627 pPager->noLock = 1; /* Do no locking */
56628 readOnly = (vfsFlags&SQLITE_OPEN_READONLY);
56629 }
56630
56631 /* The following call to PagerSetPagesize() serves to set the value of
56632 ** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
56633 */
56634 if( rc==SQLITE_OK ){
56635 assert( pPager->memDb==0 );
56636 rc = sqlite3PagerSetPagesize(pPager, &szPageDflt, -1);
56637 testcase( rc!=SQLITE_OK );
56638 }
56639
56640 /* Initialize the PCache object. */
56641 if( rc==SQLITE_OK ){
56642 nExtra = ROUND8(nExtra);
56643 assert( nExtra>=8 && nExtra<1000 );
56644 rc = sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
56645 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
56646 }
56647
56648 /* If an error occurred above, free the Pager structure and close the file.
56649 */
56650 if( rc!=SQLITE_OK ){
56651 sqlite3OsClose(pPager->fd);
56652 sqlite3PageFree(pPager->pTmpSpace);
56653 sqlite3_free(pPager);
56654 return rc;
56655 }
56656
56657 PAGERTRACE(("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename));
56658 IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
56659
56660 pPager->useJournal = (u8)useJournal;
56661 /* pPager->stmtOpen = 0; */
56662 /* pPager->stmtInUse = 0; */
56663 /* pPager->nRef = 0; */
56664 /* pPager->stmtSize = 0; */
56665 /* pPager->stmtJSize = 0; */
56666 /* pPager->nPage = 0; */
56667 pPager->mxPgno = SQLITE_MAX_PAGE_COUNT;
56668 /* pPager->state = PAGER_UNLOCK; */
56669 /* pPager->errMask = 0; */
56670 pPager->tempFile = (u8)tempFile;
56671 assert( tempFile==PAGER_LOCKINGMODE_NORMAL
56672 || tempFile==PAGER_LOCKINGMODE_EXCLUSIVE );
56673 assert( PAGER_LOCKINGMODE_EXCLUSIVE==1 );
56674 pPager->exclusiveMode = (u8)tempFile;
56675 pPager->changeCountDone = pPager->tempFile;
56676 pPager->memDb = (u8)memDb;
56677 pPager->readOnly = (u8)readOnly;
56678 assert( useJournal || pPager->tempFile );
56679 pPager->noSync = pPager->tempFile;
56680 if( pPager->noSync ){
56681 assert( pPager->fullSync==0 );
56682 assert( pPager->extraSync==0 );
56683 assert( pPager->syncFlags==0 );
56684 assert( pPager->walSyncFlags==0 );
56685 }else{
56686 pPager->fullSync = 1;
56687 pPager->extraSync = 0;
56688 pPager->syncFlags = SQLITE_SYNC_NORMAL;
56690 }
56691 /* pPager->pFirst = 0; */
56692 /* pPager->pFirstSynced = 0; */
56693 /* pPager->pLast = 0; */
56694 pPager->nExtra = (u16)nExtra;
56696 assert( isOpen(pPager->fd) || tempFile );
56697 setSectorSize(pPager);
56698 if( !useJournal ){
56700 }else if( memDb || memJM ){
56702 }
56703 /* pPager->xBusyHandler = 0; */
56704 /* pPager->pBusyHandlerArg = 0; */
56705 pPager->xReiniter = xReinit;
56706 setGetterMethod(pPager);
#define SQLITE_CANTOPEN_SYMLINK
Definition sqlite3.c:1565
#define SQLITE_DEFAULT_PAGE_SIZE
Definition sqlite3.c:13400
#define memJM
#define SQLITE_MAX_DEFAULT_PAGE_SIZE
Definition sqlite3.c:13415
SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *)
Definition sqlite3.c:97495
#define SQLITE_IOCAP_IMMUTABLE
Definition sqlite3.c:1674
#define PAGER_MEMORY
Definition sqlite3.c:14811
#define FILEHANDLEID(fd)
Definition sqlite3.c:51834
#define SQLITE_MAX_PAGE_COUNT
Definition sqlite3.c:13431
#define sqlite3FileSuffix3(X, Y)
Definition sqlite3.c:19926
SQLITE_PRIVATE int sqlite3PcacheSize(void)
Definition sqlite3.c:49152
SQLITE_PRIVATE int sqlite3PcacheOpen(int szPage, int szExtra, int bPurgeable, int(*xStress)(void *, PgHdr *), void *pStress, PCache *pToInit)
Definition sqlite3.c:49166
#define SQLITE_OPEN_NOFOLLOW
Definition sqlite3.c:1621
#define PAGER_OMIT_JOURNAL
Definition sqlite3.c:14810
#define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
Definition sqlite3.c:14776
static void setSectorSize(Pager *pPager)
Definition sqlite3.c:54367
u16 nExtra
Definition sqlite3.c:52379
u8 memDb
Definition sqlite3.c:52333

References Pager::changeCountDone, EIGHT_BYTE_ALIGNMENT, Pager::eLock, Pager::eState, EXCLUSIVE_LOCK, Pager::exclusiveMode, Pager::extraSync, Pager::fd, FILEHANDLEID, Pager::fullSync, IOTRACE, isOpen, Pager::jfd, Pager::journalMode, Pager::journalSizeLimit, Pager::memDb, memJM, sqlite3_vfs::mxPathname, Pager::mxPgno, Pager::nExtra, Pager::noLock, Pager::noSync, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_OFF, PAGER_LOCKINGMODE_EXCLUSIVE, PAGER_LOCKINGMODE_NORMAL, PAGER_MEMORY, PAGER_OMIT_JOURNAL, PAGER_READER, pagerStress(), PAGERTRACE, Pager::pPCache, Pager::pTmpSpace, Pager::pVfs, Pager::readOnly, ROUND8, Pager::sectorSize, setGetterMethod(), setSectorSize(), Pager::sjfd, sqlite3_free(), sqlite3_uri_boolean(), sqlite3DbFree(), sqlite3DbMallocRaw(), sqlite3DbStrDup(), sqlite3FileSuffix3, sqlite3JournalSize(), sqlite3MallocZero(), sqlite3OsClose(), sqlite3OsDeviceCharacteristics(), sqlite3OsFullPathname(), sqlite3OsOpen(), sqlite3PageFree(), sqlite3PagerSetPagesize(), sqlite3PcacheOpen(), sqlite3PcacheSize(), sqlite3Strlen30(), SQLITE_CANTOPEN_BKPT, SQLITE_CANTOPEN_SYMLINK, SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT, SQLITE_DEFAULT_PAGE_SIZE, SQLITE_INT_TO_PTR, SQLITE_IOCAP_ATOMIC, SQLITE_IOCAP_ATOMIC512, SQLITE_IOCAP_ATOMIC64K, SQLITE_IOCAP_IMMUTABLE, SQLITE_MAX_DEFAULT_PAGE_SIZE, SQLITE_MAX_PAGE_COUNT, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OK_SYMLINK, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOFOLLOW, SQLITE_OPEN_READONLY, SQLITE_SYNC_NORMAL, Pager::syncFlags, sqlite3_vfs::szOsFile, Pager::tempFile, testcase, Pager::useJournal, Pager::vfsFlags, Pager::walSyncFlags, Pager::xReiniter, Pager::zFilename, Pager::zJournal, and Pager::zWal.

Referenced by sqlite3BtreeOpen().

◆ sqlite3PagerOpenSavepoint()

SQLITE_PRIVATE int sqlite3PagerOpenSavepoint ( Pager * pPager,
int n )

Definition at line 58556 of file sqlite3.c.

58562 {
58563 assert( pPager->eState>=PAGER_WRITER_LOCKED );
58564 assert( assert_pager_state(pPager) );
58565

Referenced by sqlite3BtreeBeginStmt(), and sqlite3BtreeBeginTrans().

◆ sqlite3PagerOpenWal()

SQLITE_PRIVATE int sqlite3PagerOpenWal ( Pager * pPager,
int * pisOpen )

Definition at line 59198 of file sqlite3.c.

59207 {
59208 int rc = SQLITE_OK; /* Return code */
59209
59210 assert( assert_pager_state(pPager) );
59211 assert( pPager->eState==PAGER_OPEN || pbOpen );
59212 assert( pPager->eState==PAGER_READER || !pbOpen );
59213 assert( pbOpen==0 || *pbOpen==0 );
59214 assert( pbOpen!=0 || (!pPager->tempFile && !pPager->pWal) );
59215
59216 if( !pPager->tempFile && !pPager->pWal ){
59217 if( !sqlite3PagerWalSupported(pPager) ) return SQLITE_CANTOPEN;
59218
59219 /* Close any rollback journal previously open */
59220 sqlite3OsClose(pPager->jfd);
59221
59222 rc = pagerOpenWal(pPager);
59223 if( rc==SQLITE_OK ){
59225 pPager->eState = PAGER_OPEN;
59226 }
SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager)
Definition sqlite3.c:59123

References Pager::eState, Pager::jfd, Pager::journalMode, PAGER_JOURNALMODE_WAL, PAGER_OPEN, PAGER_READER, pagerOpenWal(), Pager::pWal, sqlite3OsClose(), sqlite3PagerWalSupported(), SQLITE_CANTOPEN, SQLITE_OK, and Pager::tempFile.

Referenced by lockBtree(), and pagerOpenWalIfPresent().

◆ sqlite3PagerPagecount()

SQLITE_PRIVATE void sqlite3PagerPagecount ( Pager * pPager,
int * pnPage )

Definition at line 55542 of file sqlite3.c.

References Pager::dbSize, Pager::eState, PAGER_READER, and PAGER_WRITER_FINISHED.

Referenced by lockBtree().

◆ sqlite3PagerPageRefcount()

SQLITE_PRIVATE int sqlite3PagerPageRefcount ( DbPage * pPage)

Definition at line 58438 of file sqlite3.c.

Referenced by allocateBtreePage(), btreeGetUnusedPage(), and pageReinit().

◆ sqlite3PagerReadFileheader()

SQLITE_PRIVATE int sqlite3PagerReadFileheader ( Pager * pPager,
int N,
unsigned char * pDest )

Definition at line 55514 of file sqlite3.c.

55520 {
55521 int rc = SQLITE_OK;
55522 memset(pDest, 0, N);
55523 assert( isOpen(pPager->fd) || pPager->tempFile );
55524
55525 /* This routine is only called by btree immediately after creating
55526 ** the Pager object. There has not been an opportunity to transition
55527 ** to WAL mode yet.
55528 */
55529 assert( !pagerUseWal(pPager) );
55530
55531 if( isOpen(pPager->fd) ){
55532 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
55533 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);

References Pager::fd, IOTRACE, isOpen, pagerUseWal, sqlite3OsRead(), SQLITE_IOERR_SHORT_READ, SQLITE_OK, and Pager::tempFile.

Referenced by sqlite3BtreeOpen().

◆ sqlite3PagerRef()

SQLITE_PRIVATE void sqlite3PagerRef ( DbPage * pPg)

Definition at line 55854 of file sqlite3.c.

Referenced by freePage2().

◆ sqlite3PagerRekey()

SQLITE_PRIVATE void sqlite3PagerRekey ( DbPage * pPg,
Pgno iNew,
u16 flags )

Definition at line 58881 of file sqlite3.c.

References PgHdr::flags, and PgHdr::pgno.

Referenced by balance_nonroot().

◆ sqlite3PagerRollback()

SQLITE_PRIVATE int sqlite3PagerRollback ( Pager * pPager)

Definition at line 58360 of file sqlite3.c.

58366 {
58367 int rc = SQLITE_OK; /* Return code */
58368 PAGERTRACE(("ROLLBACK %d\n", PAGERID(pPager)));
58369
58370 /* PagerRollback() is a no-op if called in READER or OPEN state. If
58371 ** the pager is already in the ERROR state, the rollback is not
58372 ** attempted here. Instead, the error code is returned to the caller.
58373 */
58374 assert( assert_pager_state(pPager) );
58375 if( pPager->eState==PAGER_ERROR ) return pPager->errCode;
58376 if( pPager->eState<=PAGER_READER ) return SQLITE_OK;
58377
58378 if( pagerUseWal(pPager) ){
58379 int rc2;
58380 rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
58381 rc2 = pager_end_transaction(pPager, pPager->setSuper, 0);
58382 if( rc==SQLITE_OK ) rc = rc2;
58383 }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
58384 int eState = pPager->eState;
58385 rc = pager_end_transaction(pPager, 0, 0);
58386 if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
58387 /* This can happen using journal_mode=off. Move the pager to the error
58388 ** state to indicate that the contents of the cache may not be trusted.
58389 ** Any active readers will get SQLITE_ABORT.
58390 */
58391 pPager->errCode = SQLITE_ABORT;
58392 pPager->eState = PAGER_ERROR;
58393 setGetterMethod(pPager);
58394 return rc;
58395 }
58396 }else{
58397 rc = pager_playback(pPager, 0);
58398 }
58399
58400 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
58401 assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
58402 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
58403 || rc==SQLITE_CANTOPEN
58404 );
static int pager_playback(Pager *pPager, int isHot)
Definition sqlite3.c:54440

References Pager::errCode, Pager::eState, isOpen, Pager::jfd, MEMDB, pager_end_transaction(), PAGER_ERROR, pager_error(), pager_playback(), PAGER_READER, PAGER_WRITER_LOCKED, PAGERID, PAGERTRACE, pagerUseWal, SAVEPOINT_ROLLBACK, setGetterMethod(), Pager::setSuper, sqlite3PagerSavepoint(), SQLITE_ABORT, SQLITE_CANTOPEN, SQLITE_CORRUPT, SQLITE_FULL, SQLITE_IOERR, SQLITE_NOMEM, and SQLITE_OK.

Referenced by autoVacuumCommit(), pagerUnlockAndRollback(), and sqlite3BtreeRollback().

◆ sqlite3PagerSavepoint()

SQLITE_PRIVATE int sqlite3PagerSavepoint ( Pager * pPager,
int op,
int iSavepoint )

Definition at line 58598 of file sqlite3.c.

58604 {
58605 int rc = pPager->errCode;
58606
58607#ifdef SQLITE_ENABLE_ZIPVFS
58608 if( op==SAVEPOINT_RELEASE ) rc = SQLITE_OK;
58609#endif
58610
58611 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
58612 assert( iSavepoint>=0 || op==SAVEPOINT_ROLLBACK );
58613
58614 if( rc==SQLITE_OK && iSavepoint<pPager->nSavepoint ){
58615 int ii; /* Iterator variable */
58616 int nNew; /* Number of remaining savepoints after this op. */
58617
58618 /* Figure out how many savepoints will still be active after this
58619 ** operation. Store this value in nNew. Then free resources associated
58620 ** with any savepoints that are destroyed by this operation.
58621 */
58622 nNew = iSavepoint + (( op==SAVEPOINT_RELEASE ) ? 0 : 1);
58623 for(ii=nNew; ii<pPager->nSavepoint; ii++){
58625 }
58626 pPager->nSavepoint = nNew;
58627
58628 /* If this is a release of the outermost savepoint, truncate
58629 ** the sub-journal to zero bytes in size. */
58630 if( op==SAVEPOINT_RELEASE ){
58631 if( nNew==0 && isOpen(pPager->sjfd) ){
58632 /* Only truncate if it is an in-memory sub-journal. */
58633 if( sqlite3JournalIsInMemory(pPager->sjfd) ){
58634 rc = sqlite3OsTruncate(pPager->sjfd, 0);
58635 assert( rc==SQLITE_OK );
58636 }
58637 pPager->nSubRec = 0;
58638 }
58639 }
58640 /* Else this is a rollback operation, playback the specified savepoint.
58641 ** If this is a temp-file, it is possible that the journal file has
58642 ** not yet been opened. In this case there have been no changes to
58643 ** the database file, so the playback operation can be skipped.
58644 */
58645 else if( pagerUseWal(pPager) || isOpen(pPager->jfd) ){
58646 PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
58647 rc = pagerPlaybackSavepoint(pPager, pSavepoint);
58648 assert(rc!=SQLITE_DONE);
58649 }
58650
58651#ifdef SQLITE_ENABLE_ZIPVFS
58652 /* If the cache has been modified but the savepoint cannot be rolled
58653 ** back journal_mode=off, put the pager in the error state. This way,
58654 ** if the VFS used by this pager includes ZipVFS, the entire transaction
58655 ** can be rolled back at the ZipVFS level. */
58656 else if(
58658 && pPager->eState>=PAGER_WRITER_CACHEMOD
58659 ){
58660 pPager->errCode = SQLITE_ABORT;
58661 pPager->eState = PAGER_ERROR;
58662 setGetterMethod(pPager);
static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint)
Definition sqlite3.c:55035

References Pager::aSavepoint, Pager::errCode, Pager::eState, isOpen, Pager::jfd, Pager::journalMode, Pager::nSavepoint, Pager::nSubRec, PAGER_ERROR, PAGER_JOURNALMODE_OFF, PAGER_WRITER_CACHEMOD, pagerPlaybackSavepoint(), pagerUseWal, PagerSavepoint::pInSavepoint, SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, setGetterMethod(), Pager::sjfd, sqlite3BitvecDestroy(), sqlite3JournalIsInMemory(), sqlite3OsTruncate(), SQLITE_ABORT, SQLITE_DONE, and SQLITE_OK.

Referenced by sqlite3BtreeSavepoint(), and sqlite3PagerRollback().

◆ sqlite3PagerSetBusyHandler()

SQLITE_PRIVATE void sqlite3PagerSetBusyHandler ( Pager * pPager,
int(*)(void *) xBusyHandler,
void * pBusyHandlerArg )

Definition at line 55341 of file sqlite3.c.

55351 {
55352 void **ap;
55353 pPager->xBusyHandler = xBusyHandler;
int(* xBusyHandler)(void *)
Definition sqlite3.c:52388

References Pager::fd, Pager::pBusyHandlerArg, sqlite3OsFileControlHint(), SQLITE_FCNTL_BUSYHANDLER, and Pager::xBusyHandler.

Referenced by sqlite3BtreeOpen().

◆ sqlite3PagerSetCachesize()

SQLITE_PRIVATE void sqlite3PagerSetCachesize ( Pager * pPager,
int mxPage )

Definition at line 55147 of file sqlite3.c.

Referenced by sqlite3BtreeOpen(), and sqlite3BtreeSetCacheSize().

◆ sqlite3PagerSetFlags()

SQLITE_PRIVATE void sqlite3PagerSetFlags ( Pager * pPager,
unsigned pgFlags )

Definition at line 55242 of file sqlite3.c.

55251 {
55252 unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK;
55253 if( pPager->tempFile ){
55254 pPager->noSync = 1;
55255 pPager->fullSync = 0;
55256 pPager->extraSync = 0;
55257 }else{
55258 pPager->noSync = level==PAGER_SYNCHRONOUS_OFF ?1:0;
55259 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
55260 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
55261 }
55262 if( pPager->noSync ){
55263 pPager->syncFlags = 0;
55264 }else if( pgFlags & PAGER_FULLFSYNC ){
55265 pPager->syncFlags = SQLITE_SYNC_FULL;
55266 }else{
55267 pPager->syncFlags = SQLITE_SYNC_NORMAL;
55268 }
55269 pPager->walSyncFlags = (pPager->syncFlags<<2);
55270 if( pPager->fullSync ){
55271 pPager->walSyncFlags |= pPager->syncFlags;
55272 }
55273 if( (pgFlags & PAGER_CKPT_FULLFSYNC) && !pPager->noSync ){
55274 pPager->walSyncFlags |= (SQLITE_SYNC_FULL<<2);
55275 }
#define SQLITE_SYNC_FULL
Definition sqlite3.c:1717
#define PAGER_SYNCHRONOUS_EXTRA
Definition sqlite3.c:14852

References Pager::doNotSpill, Pager::extraSync, Pager::fullSync, Pager::noSync, PAGER_CACHESPILL, PAGER_CKPT_FULLFSYNC, PAGER_FULLFSYNC, PAGER_SYNCHRONOUS_EXTRA, PAGER_SYNCHRONOUS_FULL, PAGER_SYNCHRONOUS_MASK, PAGER_SYNCHRONOUS_OFF, SPILLFLAG_OFF, SQLITE_SYNC_FULL, SQLITE_SYNC_NORMAL, Pager::syncFlags, Pager::tempFile, and Pager::walSyncFlags.

Referenced by sqlite3BtreeSetPagerFlags().

◆ sqlite3PagerSetJournalMode()

SQLITE_PRIVATE int sqlite3PagerSetJournalMode ( Pager * pPager,
int eMode )

Definition at line 58946 of file sqlite3.c.

58952 {
58953 u8 eOld = pPager->journalMode; /* Prior journalmode */
58954
58955 /* The eMode parameter is always valid */
58956 assert( eMode==PAGER_JOURNALMODE_DELETE
58959 || eMode==PAGER_JOURNALMODE_OFF
58960 || eMode==PAGER_JOURNALMODE_WAL
58961 || eMode==PAGER_JOURNALMODE_MEMORY );
58962
58963 /* This routine is only called from the OP_JournalMode opcode, and
58964 ** the logic there will never allow a temporary file to be changed
58965 ** to WAL mode.
58966 */
58967 assert( pPager->tempFile==0 || eMode!=PAGER_JOURNALMODE_WAL );
58968
58969 /* Do allow the journalmode of an in-memory database to be set to
58970 ** anything other than MEMORY or OFF
58971 */
58972 if( MEMDB ){
58973 assert( eOld==PAGER_JOURNALMODE_MEMORY || eOld==PAGER_JOURNALMODE_OFF );
58974 if( eMode!=PAGER_JOURNALMODE_MEMORY && eMode!=PAGER_JOURNALMODE_OFF ){
58975 eMode = eOld;
58976 }
58977 }
58978
58979 if( eMode!=eOld ){
58980
58981 /* Change the journal mode. */
58982 assert( pPager->eState!=PAGER_ERROR );
58983 pPager->journalMode = (u8)eMode;
58984
58985 /* When transistioning from TRUNCATE or PERSIST to any other journal
58986 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
58987 ** delete the journal file.
58988 */
58989 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
58990 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
58991 assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
58992 assert( (PAGER_JOURNALMODE_MEMORY & 5)==4 );
58993 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
58994 assert( (PAGER_JOURNALMODE_WAL & 5)==5 );
58995
58996 assert( isOpen(pPager->fd) || pPager->exclusiveMode );
58997 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
58998
58999 /* In this case we would like to delete the journal file. If it is
59000 ** not possible, then that is not a problem. Deleting the journal file
59001 ** here is an optimization only.
59002 **
59003 ** Before deleting the journal file, obtain a RESERVED lock on the
59004 ** database file. This ensures that the journal file is not deleted
59005 ** while it is in use by some other client.
59006 */
59007 sqlite3OsClose(pPager->jfd);
59008 if( pPager->eLock>=RESERVED_LOCK ){
59009 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
59010 }else{
59011 int rc = SQLITE_OK;
59012 int state = pPager->eState;
59013 assert( state==PAGER_OPEN || state==PAGER_READER );
59014 if( state==PAGER_OPEN ){
59015 rc = sqlite3PagerSharedLock(pPager);
59016 }
59017 if( pPager->eState==PAGER_READER ){
59018 assert( rc==SQLITE_OK );
59019 rc = pagerLockDb(pPager, RESERVED_LOCK);
59020 }
59021 if( rc==SQLITE_OK ){
59022 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
59023 }
59024 if( rc==SQLITE_OK && state==PAGER_READER ){
59025 pagerUnlockDb(pPager, SHARED_LOCK);
59026 }else if( state==PAGER_OPEN ){
59027 pager_unlock(pPager);
59028 }
59029 assert( state==pPager->eState );
59030 }
59031 }else if( eMode==PAGER_JOURNALMODE_OFF ){
59032 sqlite3OsClose(pPager->jfd);

References Pager::eLock, Pager::eState, Pager::exclusiveMode, Pager::fd, isOpen, Pager::jfd, Pager::journalMode, MEMDB, PAGER_ERROR, PAGER_JOURNALMODE_DELETE, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_OFF, PAGER_JOURNALMODE_PERSIST, PAGER_JOURNALMODE_TRUNCATE, PAGER_JOURNALMODE_WAL, PAGER_OPEN, PAGER_READER, pager_unlock(), pagerLockDb(), pagerUnlockDb(), Pager::pVfs, RESERVED_LOCK, SHARED_LOCK, sqlite3OsClose(), sqlite3OsDelete(), sqlite3PagerSharedLock(), SQLITE_OK, Pager::tempFile, and Pager::zJournal.

Referenced by sqlite3VdbeExec().

◆ sqlite3PagerSetMmapLimit()

SQLITE_PRIVATE void sqlite3PagerSetMmapLimit ( Pager * pPager,
sqlite3_int64 szMmap )

Definition at line 55178 of file sqlite3.c.

Referenced by sqlite3BtreeOpen().

◆ sqlite3PagerSetPagesize()

SQLITE_PRIVATE int sqlite3PagerSetPagesize ( Pager * pPager,
u32 * pPageSize,
int nReserve )

Definition at line 55385 of file sqlite3.c.

55391 {
55392 int rc = SQLITE_OK;
55393
55394 /* It is not possible to do a full assert_pager_state() here, as this
55395 ** function may be called from within PagerOpen(), before the state
55396 ** of the Pager object is internally consistent.
55397 **
55398 ** At one point this function returned an error if the pager was in
55399 ** PAGER_ERROR state. But since PAGER_ERROR state guarantees that
55400 ** there is at least one outstanding page reference, this function
55401 ** is a no-op for that case anyhow.
55402 */
55403
55404 u32 pageSize = *pPageSize;
55405 assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
55406 if( (pPager->memDb==0 || pPager->dbSize==0)
55407 && sqlite3PcacheRefCount(pPager->pPCache)==0
55408 && pageSize && pageSize!=(u32)pPager->pageSize
55409 ){
55410 char *pNew = NULL; /* New temp space */
55411 i64 nByte = 0;
55412
55413 if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
55414 rc = sqlite3OsFileSize(pPager->fd, &nByte);
55415 }
55416 if( rc==SQLITE_OK ){
55417 /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
55418 * cell header parser will never run off the end of the allocation */
55419 pNew = (char *)sqlite3PageMalloc(pageSize+8);
55420 if( !pNew ){
55421 rc = SQLITE_NOMEM_BKPT;
55422 }else{
55423 memset(pNew+pageSize, 0, 8);
55424 }
55425 }
55426
55427 if( rc==SQLITE_OK ){
55428 pager_reset(pPager);
55429 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
55430 }
55431 if( rc==SQLITE_OK ){
55432 sqlite3PageFree(pPager->pTmpSpace);
55433 pPager->pTmpSpace = pNew;
55434 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
55435 pPager->pageSize = pageSize;
55436 }else{
55437 sqlite3PageFree(pNew);
55438 }
55439 }
55440
55441 *pPageSize = pPager->pageSize;
55442 if( rc==SQLITE_OK ){
55443 if( nReserve<0 ) nReserve = pPager->nReserve;
SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *, int)
Definition sqlite3.c:49192

References Pager::dbSize, Pager::eState, Pager::fd, isOpen, Pager::memDb, Pager::nReserve, NULL, PAGER_OPEN, pager_reset(), pagerFixMaplimit(), Pager::pageSize, Pager::pPCache, Pager::pTmpSpace, sqlite3OsFileSize(), sqlite3PageFree(), sqlite3PageMalloc(), sqlite3PcacheRefCount(), sqlite3PcacheSetPageSize(), SQLITE_MAX_PAGE_SIZE, SQLITE_NOMEM_BKPT, and SQLITE_OK.

Referenced by lockBtree(), pager_playback(), readJournalHdr(), sqlite3BtreeOpen(), sqlite3BtreeSetPageSize(), and sqlite3PagerOpen().

◆ sqlite3PagerSetSpillsize()

SQLITE_PRIVATE int sqlite3PagerSetSpillsize ( Pager * pPager,
int mxPage )

Definition at line 55155 of file sqlite3.c.

Referenced by sqlite3BtreeSetSpillSize().

◆ sqlite3PagerSharedLock()

SQLITE_PRIVATE int sqlite3PagerSharedLock ( Pager * pPager)

Definition at line 56874 of file sqlite3.c.

56880 {
56881 int rc = SQLITE_OK; /* Return code */
56882
56883 /* This routine is only called from b-tree and only when there are no
56884 ** outstanding pages. This implies that the pager state should either
56885 ** be OPEN or READER. READER is only possible if the pager is or was in
56886 ** exclusive access mode. */
56887 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
56888 assert( assert_pager_state(pPager) );
56889 assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
56890 assert( pPager->errCode==SQLITE_OK );
56891
56892 if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
56893 int bHotJournal = 1; /* True if there exists a hot journal-file */
56894
56895 assert( !MEMDB );
56896 assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
56897
56898 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
56899 if( rc!=SQLITE_OK ){
56900 assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
56901 goto failed;
56902 }
56903
56904 /* If a journal file exists, and there is no RESERVED lock on the
56905 ** database file, then it either needs to be played back or deleted.
56906 */
56907 if( pPager->eLock<=SHARED_LOCK ){
56908 rc = hasHotJournal(pPager, &bHotJournal);
56909 }
56910 if( rc!=SQLITE_OK ){
56911 goto failed;
56912 }
56913 if( bHotJournal ){
56914 if( pPager->readOnly ){
56916 goto failed;
56917 }
56918
56919 /* Get an EXCLUSIVE lock on the database file. At this point it is
56920 ** important that a RESERVED lock is not obtained on the way to the
56921 ** EXCLUSIVE lock. If it were, another process might open the
56922 ** database file, detect the RESERVED lock, and conclude that the
56923 ** database is safe to read while this process is still rolling the
56924 ** hot-journal back.
56925 **
56926 ** Because the intermediate RESERVED lock is not requested, any
56927 ** other process attempting to access the database file will get to
56928 ** this point in the code and fail to obtain its own EXCLUSIVE lock
56929 ** on the database file.
56930 **
56931 ** Unless the pager is in locking_mode=exclusive mode, the lock is
56932 ** downgraded to SHARED_LOCK before this function returns.
56933 */
56934 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
56935 if( rc!=SQLITE_OK ){
56936 goto failed;
56937 }
56938
56939 /* If it is not already open and the file exists on disk, open the
56940 ** journal for read/write access. Write access is required because
56941 ** in exclusive-access mode the file descriptor will be kept open
56942 ** and possibly used for a transaction later on. Also, write-access
56943 ** is usually required to finalize the journal in journal_mode=persist
56944 ** mode (and also for journal_mode=truncate on some systems).
56945 **
56946 ** If the journal does not exist, it usually means that some
56947 ** other connection managed to get in and roll it back before
56948 ** this connection obtained the exclusive lock above. Or, it
56949 ** may mean that the pager was in the error-state when this
56950 ** function was called and the journal file does not exist.
56951 */
56952 if( !isOpen(pPager->jfd) ){
56953 sqlite3_vfs * const pVfs = pPager->pVfs;
56954 int bExists; /* True if journal file exists */
56955 rc = sqlite3OsAccess(
56956 pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &bExists);
56957 if( rc==SQLITE_OK && bExists ){
56958 int fout = 0;
56960 assert( !pPager->tempFile );
56961 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &fout);
56962 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
56963 if( rc==SQLITE_OK && fout&SQLITE_OPEN_READONLY ){
56965 sqlite3OsClose(pPager->jfd);
56966 }
56967 }
56968 }
56969
56970 /* Playback and delete the journal. Drop the database write
56971 ** lock and reacquire the read lock. Purge the cache before
56972 ** playing back the hot-journal so that we don't end up with
56973 ** an inconsistent cache. Sync the hot journal before playing
56974 ** it back since the process that crashed and left the hot journal
56975 ** probably did not sync it and we are required to always sync
56976 ** the journal before playing it back.
56977 */
56978 if( isOpen(pPager->jfd) ){
56979 assert( rc==SQLITE_OK );
56980 rc = pagerSyncHotJournal(pPager);
56981 if( rc==SQLITE_OK ){
56982 rc = pager_playback(pPager, !pPager->tempFile);
56983 pPager->eState = PAGER_OPEN;
56984 }
56985 }else if( !pPager->exclusiveMode ){
56986 pagerUnlockDb(pPager, SHARED_LOCK);
56987 }
56988
56989 if( rc!=SQLITE_OK ){
56990 /* This branch is taken if an error occurs while trying to open
56991 ** or roll back a hot-journal while holding an EXCLUSIVE lock. The
56992 ** pager_unlock() routine will be called before returning to unlock
56993 ** the file. If the unlock attempt fails, then Pager.eLock must be
56994 ** set to UNKNOWN_LOCK (see the comment above the #define for
56995 ** UNKNOWN_LOCK above for an explanation).
56996 **
56997 ** In order to get pager_unlock() to do this, set Pager.eState to
56998 ** PAGER_ERROR now. This is not actually counted as a transition
56999 ** to ERROR state in the state diagram at the top of this file,
57000 ** since we know that the same call to pager_unlock() will very
57001 ** shortly transition the pager object to the OPEN state. Calling
57002 ** assert_pager_state() would fail now, as it should not be possible
57003 ** to be in ERROR state when there are zero outstanding page
57004 ** references.
57005 */
57006 pager_error(pPager, rc);
57007 goto failed;
57008 }
57009
57010 assert( pPager->eState==PAGER_OPEN );
57011 assert( (pPager->eLock==SHARED_LOCK)
57012 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
57013 );
57014 }
57015
57016 if( !pPager->tempFile && pPager->hasHeldSharedLock ){
57017 /* The shared-lock has just been acquired then check to
57018 ** see if the database has been modified. If the database has changed,
57019 ** flush the cache. The hasHeldSharedLock flag prevents this from
57020 ** occurring on the very first access to a file, in order to save a
57021 ** single unnecessary sqlite3OsRead() call at the start-up.
57022 **
57023 ** Database changes are detected by looking at 15 bytes beginning
57024 ** at offset 24 into the file. The first 4 of these 16 bytes are
57025 ** a 32-bit counter that is incremented with each change. The
57026 ** other bytes change randomly with each file change when
57027 ** a codec is in use.
57028 **
57029 ** There is a vanishingly small chance that a change will not be
57030 ** detected. The chance of an undetected change is so small that
57031 ** it can be neglected.
57032 */
57033 char dbFileVers[sizeof(pPager->dbFileVers)];
57034
57035 IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
57036 rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
57037 if( rc!=SQLITE_OK ){
57038 if( rc!=SQLITE_IOERR_SHORT_READ ){
57039 goto failed;
57040 }
57041 memset(dbFileVers, 0, sizeof(dbFileVers));
57042 }
57043
57044 if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
57045 pager_reset(pPager);
57046
57047 /* Unmap the database file. It is possible that external processes
57048 ** may have truncated the database file and then extended it back
57049 ** to its original size while this process was not holding a lock.
57050 ** In this case there may exist a Pager.pMap mapping that appears
57051 ** to be the right size but is not actually valid. Avoid this
57052 ** possibility by unmapping the db here. */
57053 if( USEFETCH(pPager) ){
57054 sqlite3OsUnfetch(pPager->fd, 0, 0);
57055 }
57056 }
57057 }
57058
57059 /* If there is a WAL file in the file-system, open this database in WAL
57060 ** mode. Otherwise, the following function call is a no-op.
57061 */
57062 rc = pagerOpenWalIfPresent(pPager);
57063#ifndef SQLITE_OMIT_WAL
57064 assert( pPager->pWal==0 || rc==SQLITE_OK );
57065#endif
57066 }
57067
57068 if( pagerUseWal(pPager) ){
57069 assert( rc==SQLITE_OK );
57070 rc = pagerBeginReadTransaction(pPager);
57071 }
57072
57073 if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
57074 rc = pagerPagecount(pPager, &pPager->dbSize);
57075 }
57076
57077 failed:
57078 if( rc!=SQLITE_OK ){
57079 assert( !MEMDB );
57080 pager_unlock(pPager);
57081 assert( pPager->eState==PAGER_OPEN );
static int pagerBeginReadTransaction(Pager *pPager)
Definition sqlite3.c:54875
static int pagerOpenWalIfPresent(Pager *pPager)
Definition sqlite3.c:54968
static int hasHotJournal(Pager *pPager, int *pExists)
Definition sqlite3.c:56754
#define SQLITE_READONLY_ROLLBACK
Definition sqlite3.c:1571

References Pager::dbFileVers, Pager::dbSize, Pager::eLock, Pager::errCode, Pager::eState, EXCLUSIVE_LOCK, Pager::exclusiveMode, Pager::fd, Pager::hasHeldSharedLock, hasHotJournal(), IOTRACE, isOpen, Pager::jfd, MEMDB, NO_LOCK, pager_error(), PAGER_OPEN, pager_playback(), PAGER_READER, pager_reset(), pager_unlock(), pager_wait_on_lock(), pagerBeginReadTransaction(), pagerLockDb(), pagerOpenWalIfPresent(), pagerPagecount(), pagerSyncHotJournal(), pagerUnlockDb(), pagerUseWal, Pager::pPCache, Pager::pVfs, Pager::pWal, Pager::readOnly, SHARED_LOCK, sqlite3OsAccess(), sqlite3OsClose(), sqlite3OsOpen(), sqlite3OsRead(), sqlite3OsUnfetch(), sqlite3PcacheRefCount(), SQLITE_ACCESS_EXISTS, SQLITE_CANTOPEN_BKPT, SQLITE_IOERR_SHORT_READ, SQLITE_OK, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_READONLY_ROLLBACK, Pager::tempFile, UNKNOWN_LOCK, USEFETCH, and Pager::zJournal.

Referenced by lockBtree(), and sqlite3PagerSetJournalMode().

◆ sqlite3PagerShrink()

SQLITE_PRIVATE void sqlite3PagerShrink ( Pager * pPager)

Definition at line 55186 of file sqlite3.c.

◆ sqlite3PagerSync()

SQLITE_PRIVATE int sqlite3PagerSync ( Pager * pPager,
const char * zSuper )

Definition at line 57999 of file sqlite3.c.

58005 {
58006 int rc = SQLITE_OK;
58007 void *pArg = (void*)zSuper;
58008 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
58009 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
#define SQLITE_FCNTL_SYNC
Definition sqlite3.c:2198

References Pager::fd, MEMDB, Pager::noSync, sqlite3OsFileControl(), sqlite3OsSync(), SQLITE_FCNTL_SYNC, SQLITE_NOTFOUND, SQLITE_OK, and Pager::syncFlags.

Referenced by pager_playback(), and sqlite3PagerCommitPhaseOne().

◆ sqlite3PagerTempSpace()

SQLITE_PRIVATE void * sqlite3PagerTempSpace ( Pager * pPager)

Definition at line 55453 of file sqlite3.c.

References Pager::pTmpSpace.

Referenced by defragmentPage(), editPage(), and rebuildPage().

◆ sqlite3PagerTruncateImage()

SQLITE_PRIVATE void sqlite3PagerTruncateImage ( Pager * pPager,
Pgno nPage )

Definition at line 55627 of file sqlite3.c.

55633 {
55634 assert( pPager->dbSize>=nPage );
55635 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
55636 pPager->dbSize = nPage;
55637
55638 /* At one point the code here called assertTruncateConstraint() to
55639 ** ensure that all pages being truncated away by this operation are,
55640 ** if one or more savepoints are open, present in the savepoint
55641 ** journal so that they can be restored if the savepoint is rolled

References Pager::dbSize, Pager::eState, and PAGER_WRITER_CACHEMOD.

Referenced by sqlite3BtreeCommitPhaseOne().

◆ sqlite3PagerUnref()

SQLITE_PRIVATE void sqlite3PagerUnref ( DbPage * pPg)

Definition at line 57397 of file sqlite3.c.

57397 {
57399 }
SQLITE_PRIVATE void sqlite3PcacheRelease(PgHdr *)
Definition sqlite3.c:49382

Referenced by accessPayload(), backupOnePage(), checkList(), pager_incr_changecounter(), ptrmapGet(), ptrmapPut(), and sqlite3PagerCommitPhaseOne().

◆ sqlite3PagerUnrefNotNull()

SQLITE_PRIVATE void sqlite3PagerUnrefNotNull ( DbPage * pPg)

Definition at line 57385 of file sqlite3.c.

57391 {
57392 TESTONLY( Pager *pPager = pPg->pPager; )
57393 assert( pPg!=0 );
57394 if( pPg->flags & PGHDR_MMAP ){
57395 assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */
#define PGHDR_MMAP
Definition sqlite3.c:16075
static void pagerReleaseMapPage(PgHdr *pPg)
Definition sqlite3.c:55724

References PgHdr::flags, pagerReleaseMapPage(), PGHDR_MMAP, PgHdr::pgno, PgHdr::pPager, and TESTONLY.

Referenced by pager_end_transaction(), pagerUndoCallback(), pagerWriteLargeSector(), and sqlite3PagerMovepage().

◆ sqlite3PagerUnrefPageOne()

SQLITE_PRIVATE void sqlite3PagerUnrefPageOne ( DbPage * pPg)

Definition at line 57400 of file sqlite3.c.

57403 {
57404 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
57405}
57407 Pager *pPager;
57408 assert( pPg!=0 );
SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *)
Definition sqlite3.c:57400

◆ sqlite3PagerVfs()

SQLITE_PRIVATE sqlite3_vfs * sqlite3PagerVfs ( Pager * pPager)

Definition at line 58685 of file sqlite3.c.

58685 : pPager->zFilename;
58686}
58687

Referenced by sqlite3BtreeOpen().

◆ sqlite3PagerWalCallback()

SQLITE_PRIVATE int sqlite3PagerWalCallback ( Pager * pPager)

Definition at line 59115 of file sqlite3.c.

Referenced by doWalCallbacks().

◆ sqlite3PagerWalSupported()

SQLITE_PRIVATE int sqlite3PagerWalSupported ( Pager * pPager)

Definition at line 59123 of file sqlite3.c.

Referenced by sqlite3PagerOpenWal(), and sqlite3VdbeExec().

◆ sqlite3PagerWrite()

◆ sqlite3Parser() [1/2]

SQLITE_PRIVATE void sqlite3Parser ( void * ,
int ,
Token  )

Referenced by sqlite3RunParser().

◆ sqlite3Parser() [2/2]

SQLITE_PRIVATE void sqlite3Parser ( void * yyp,
int yymajor,
sqlite3ParserTOKENTYPE yyminor sqlite3ParserARG_PDECL )

Definition at line 159071 of file sqlite3.c.

159074 :
159075** None.
159076*/
159078 void *yyp, /* The parser */
159079 int yymajor, /* The major token code number */
159080 sqlite3ParserTOKENTYPE yyminor /* The value for the token */
159081 sqlite3ParserARG_PDECL /* Optional %extra_argument parameter */
159082){
159083 YYMINORTYPE yyminorunion;
159084 YYACTIONTYPE yyact; /* The parser action. */
159085#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
159086 int yyendofinput; /* True if we are at the end of input */
159087#endif
159088#ifdef YYERRORSYMBOL
159089 int yyerrorhit = 0; /* True if yymajor has invoked an error */
159090#endif
159091 yyParser *yypParser = (yyParser*)yyp; /* The parser */
159094
159095 assert( yypParser->yytos!=0 );
159096#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
159097 yyendofinput = (yymajor==0);
159098#endif
159099
159100 yyact = yypParser->yytos->stateno;
159101#ifndef NDEBUG
159102 if( yyTraceFILE ){
159103 if( yyact < YY_MIN_REDUCE ){
159104 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
159105 yyTracePrompt,yyTokenName[yymajor],yyact);
159106 }else{
159107 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
159108 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
159109 }
159110 }
159111#endif
159112
159113 do{
159114 assert( yyact==yypParser->yytos->stateno );
159115 yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
159116 if( yyact >= YY_MIN_REDUCE ){
159117 yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,
159118 yyminor sqlite3ParserCTX_PARAM);
159119 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
159120 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
159121#ifndef YYNOERRORRECOVERY
159122 yypParser->yyerrcnt--;
159123#endif
159124 break;
159125 }else if( yyact==YY_ACCEPT_ACTION ){
159126 yypParser->yytos--;
159127 yy_accept(yypParser);
159128 return;
159129 }else{
159130 assert( yyact == YY_ERROR_ACTION );
159131 yyminorunion.yy0 = yyminor;
159132#ifdef YYERRORSYMBOL
159133 int yymx;
159134#endif
159135#ifndef NDEBUG
159136 if( yyTraceFILE ){
159137 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
159138 }
159139#endif
159140#ifdef YYERRORSYMBOL
159141 /* A syntax error has occurred.
159142 ** The response to an error depends upon whether or not the
159143 ** grammar defines an error token "ERROR".
159144 **
159145 ** This is what we do if the grammar does define ERROR:
159146 **
159147 ** * Call the %syntax_error function.
159148 **
159149 ** * Begin popping the stack until we enter a state where
159150 ** it is legal to shift the error symbol, then shift
159151 ** the error symbol.
159152 **
159153 ** * Set the error count to three.
159154 **
159155 ** * Begin accepting and shifting new tokens. No new error
159156 ** processing will occur until three tokens have been
159157 ** shifted successfully.
159158 **
159159 */
159160 if( yypParser->yyerrcnt<0 ){
159161 yy_syntax_error(yypParser,yymajor,yyminor);
159162 }
159163 yymx = yypParser->yytos->major;
159164 if( yymx==YYERRORSYMBOL || yyerrorhit ){
159165#ifndef NDEBUG
159166 if( yyTraceFILE ){
159167 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
159168 yyTracePrompt,yyTokenName[yymajor]);
159169 }
159170#endif
159171 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
159172 yymajor = YYNOCODE;
159173 }else{
159174 while( yypParser->yytos >= yypParser->yystack
159175 && (yyact = yy_find_reduce_action(
159176 yypParser->yytos->stateno,
159177 YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE
159178 ){
159179 yy_pop_parser_stack(yypParser);
159180 }
159181 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
159182 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
159183 yy_parse_failed(yypParser);
159184#ifndef YYNOERRORRECOVERY
159185 yypParser->yyerrcnt = -1;
159186#endif
159187 yymajor = YYNOCODE;
159188 }else if( yymx!=YYERRORSYMBOL ){
159189 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
159190 }
159191 }
159192 yypParser->yyerrcnt = 3;
159193 yyerrorhit = 1;
159194 if( yymajor==YYNOCODE ) break;
159195 yyact = yypParser->yytos->stateno;
159196#elif defined(YYNOERRORRECOVERY)
159197 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
159198 ** do any kind of error recovery. Instead, simply invoke the syntax
159199 ** error routine and continue going as if nothing had happened.
159200 **
159201 ** Applications can set this macro (for example inside %include) if
159202 ** they intend to abandon the parse upon the first syntax error seen.
159203 */
159204 yy_syntax_error(yypParser,yymajor, yyminor);
159205 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
159206 break;
159207#else /* YYERRORSYMBOL is not defined */
159208 /* This is what we do if the grammar does not define ERROR:
159209 **
159210 ** * Report an error message, and throw away the input token.
159211 **
159212 ** * If the input token is $, then fail the parse.
159213 **
159214 ** As before, subsequent error messages are suppressed until
159215 ** three input tokens have been successfully shifted.
159216 */
159217 if( yypParser->yyerrcnt<=0 ){
159218 yy_syntax_error(yypParser,yymajor, yyminor);
159219 }
159220 yypParser->yyerrcnt = 3;
159221 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
159222 if( yyendofinput ){
159223 yy_parse_failed(yypParser);
159224#ifndef YYNOERRORRECOVERY
159225 yypParser->yyerrcnt = -1;
159226#endif
159227 }
159228 break;
159229#endif
159230 }
159231 }while( yypParser->yytos>yypParser->yystack );
159232#ifndef NDEBUG
159233 if( yyTraceFILE ){
159234 yyStackEntry *i;
159235 char cDiv = '[';
159236 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
159237 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
159238 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
159239 cDiv = ' ';
static void yy_pop_parser_stack(yyParser *pParser)
Definition sqlite3.c:156391
static YYACTIONTYPE yy_find_shift_action(YYCODETYPE iLookAhead, YYACTIONTYPE stateno)
Definition sqlite3.c:156489
static YYACTIONTYPE yy_find_reduce_action(YYACTIONTYPE stateno, YYCODETYPE iLookAhead)
Definition sqlite3.c:156554
#define YYCODETYPE
Definition sqlite3.c:154476
#define sqlite3ParserCTX_FETCH
Definition sqlite3.c:154511
#define sqlite3ParserTOKENTYPE
Definition sqlite3.c:154480
#define sqlite3ParserARG_PDECL
Definition sqlite3.c:154504
#define sqlite3ParserARG_STORE
Definition sqlite3.c:154507
SQLITE_PRIVATE void sqlite3Parser(void *, int, Token)
static void yy_shift(yyParser *yypParser, YYACTIONTYPE yyNewState, YYCODETYPE yyMajor, sqlite3ParserTOKENTYPE yyMinor)
Definition sqlite3.c:156626
#define YYACTIONTYPE
Definition sqlite3.c:154478
#define YYNOCODE
Definition sqlite3.c:154477
#define YY_ERROR_ACTION
Definition sqlite3.c:154521
#define YY_MIN_REDUCE
Definition sqlite3.c:154524
static void yy_accept(yyParser *)
Definition sqlite3.c:159030
#define YY_ACCEPT_ACTION
Definition sqlite3.c:154522
#define sqlite3ParserCTX_PARAM
Definition sqlite3.c:154510
#define YY_MAX_SHIFTREDUCE
Definition sqlite3.c:154520
static void yy_syntax_error(yyParser *yypParser, int yymajor, sqlite3ParserTOKENTYPE yyminor)
Definition sqlite3.c:159006
static YYACTIONTYPE yy_reduce(yyParser *yypParser, unsigned int yyruleno, int yyLookahead, sqlite3ParserTOKENTYPE yyLookaheadToken sqlite3ParserCTX_PDECL)
Definition sqlite3.c:157457
static void yy_destructor(yyParser *yypParser, YYCODETYPE yymajor, YYMINORTYPE *yypminor)
Definition sqlite3.c:156267
sqlite3ParserARG_SDECL sqlite3ParserCTX_SDECL yyStackEntry yystack[YYSTACKDEPTH]
Definition sqlite3.c:155417
yyStackEntry * yytos
Definition sqlite3.c:155403
YYACTIONTYPE stateno
Definition sqlite3.c:155392
YYCODETYPE major
Definition sqlite3.c:155393
sqlite3ParserTOKENTYPE yy0
Definition sqlite3.c:154483

References yyStackEntry::major, sqlite3ParserARG_STORE, sqlite3ParserCTX_FETCH, sqlite3ParserCTX_PARAM, yyStackEntry::stateno, YYMINORTYPE::yy0, yy_accept(), YY_ACCEPT_ACTION, yy_destructor(), YY_ERROR_ACTION, yy_find_reduce_action(), yy_find_shift_action(), YY_MAX_SHIFTREDUCE, YY_MIN_REDUCE, yy_pop_parser_stack(), yy_reduce(), yy_shift(), yy_syntax_error(), YYACTIONTYPE, YYCODETYPE, YYNOCODE, yyParser::yystack, and yyParser::yytos.

◆ sqlite3ParserFallback()

SQLITE_PRIVATE int sqlite3ParserFallback ( int iToken)

Definition at line 159245 of file sqlite3.c.

159251 {
159252#ifdef YYFALLBACK
159253 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
static const YYCODETYPE yyFallback[]
Definition sqlite3.c:155190

Referenced by getToken().

◆ sqlite3ParserFinalize()

SQLITE_PRIVATE void sqlite3ParserFinalize ( void * p)

Definition at line 156409 of file sqlite3.c.

156415 {

Referenced by sqlite3RunParser().

◆ sqlite3ParserInit()

SQLITE_PRIVATE void sqlite3ParserInit ( void *yypRawParser sqlite3ParserCTX_PDECL)

Definition at line 156209 of file sqlite3.c.

156215 {
156216 yyParser *yypParser = (yyParser*)yypRawParser;
156218#ifdef YYTRACKMAXSTACKDEPTH
156219 yypParser->yyhwm = 0;
156220#endif
156221#if YYSTACKDEPTH<=0
156222 yypParser->yytos = NULL;
156223 yypParser->yystack = NULL;
156224 yypParser->yystksz = 0;
156225 if( yyGrowStack(yypParser) ){
156226 yypParser->yystack = &yypParser->yystk0;
156227 yypParser->yystksz = 1;
156228 }
156229#endif
156230#ifndef YYNOERRORRECOVERY
156231 yypParser->yyerrcnt = -1;
156232#endif
156233 yypParser->yytos = yypParser->yystack;
#define sqlite3ParserCTX_STORE
Definition sqlite3.c:154512

References yyStackEntry::major, NULL, sqlite3ParserCTX_STORE, yyStackEntry::stateno, yyParser::yystack, YYSTACKDEPTH, yyParser::yystackEnd, and yyParser::yytos.

Referenced by sqlite3RunParser().

◆ sqlite3ParserReset()

SQLITE_PRIVATE void sqlite3ParserReset ( Parse * pParse)

Definition at line 128891 of file sqlite3.c.

128897 {
128898 sqlite3 *db = pParse->db;
128899 AggInfo *pThis = pParse->pAggList;
128900 while( pThis ){
128901 AggInfo *pNext = pThis->pNext;
128902 agginfoFree(db, pThis);
128903 pThis = pNext;
128904 }
128905 sqlite3DbFree(db, pParse->aLabel);
128906 sqlite3ExprListDelete(db, pParse->pConstExpr);
128907 if( db ){
static void agginfoFree(sqlite3 *db, AggInfo *p)
Definition sqlite3.c:128882
AggInfo * pNext
Definition sqlite3.c:17911
AggInfo * pAggList
Definition sqlite3.c:18721

Referenced by findBtree(), and sqlite3_declare_vtab().

◆ sqlite3ParseUri()

SQLITE_PRIVATE int sqlite3ParseUri ( const char * zDefaultVfs,
const char * zUri,
unsigned int * pFlags,
sqlite3_vfs ** ppVfs,
char ** pzFile,
char ** pzErrMsg )

Definition at line 163798 of file sqlite3.c.

163811 {
163812 int rc = SQLITE_OK;
163813 unsigned int flags = *pFlags;
163814 const char *zVfs = zDefaultVfs;
163815 char *zFile;
163816 char c;
163817 int nUri = sqlite3Strlen30(zUri);
163818
163819 assert( *pzErrMsg==0 );
163820
163821 if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
163822 || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
163823 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
163824 ){
163825 char *zOpt;
163826 int eState; /* Parser state when parsing URI */
163827 int iIn; /* Input character index */
163828 int iOut = 0; /* Output character index */
163829 u64 nByte = nUri+8; /* Bytes of space to allocate */
163830
163831 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
163832 ** method that there may be extra parameters following the file-name. */
163833 flags |= SQLITE_OPEN_URI;
163834
163835 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
163836 zFile = sqlite3_malloc64(nByte);
163837 if( !zFile ) return SQLITE_NOMEM_BKPT;
163838
163839 memset(zFile, 0, 4); /* 4-byte of 0x00 is the start of DB name marker */
163840 zFile += 4;
163841
163842 iIn = 5;
163843#ifdef SQLITE_ALLOW_URI_AUTHORITY
163844 if( strncmp(zUri+5, "///", 3)==0 ){
163845 iIn = 7;
163846 /* The following condition causes URIs with five leading / characters
163847 ** like file://///host/path to be converted into UNCs like //host/path.
163848 ** The correct URI for that UNC has only two or four leading / characters
163849 ** file://host/path or file:////host/path. But 5 leading slashes is a
163850 ** common error, we are told, so we handle it as a special case. */
163851 if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
163852 }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
163853 iIn = 16;
163854 }
163855#else
163856 /* Discard the scheme and authority segments of the URI. */
163857 if( zUri[5]=='/' && zUri[6]=='/' ){
163858 iIn = 7;
163859 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
163860 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
163861 *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
163862 iIn-7, &zUri[7]);
163863 rc = SQLITE_ERROR;
163864 goto parse_uri_out;
163865 }
163866 }
163867#endif
163868
163869 /* Copy the filename and any query parameters into the zFile buffer.
163870 ** Decode %HH escape codes along the way.
163871 **
163872 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
163873 ** on the parsing context. As follows:
163874 **
163875 ** 0: Parsing file-name.
163876 ** 1: Parsing name section of a name=value query parameter.
163877 ** 2: Parsing value section of a name=value query parameter.
163878 */
163879 eState = 0;
163880 while( (c = zUri[iIn])!=0 && c!='#' ){
163881 iIn++;
163882 if( c=='%'
163883 && sqlite3Isxdigit(zUri[iIn])
163884 && sqlite3Isxdigit(zUri[iIn+1])
163885 ){
163886 int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
163887 octet += sqlite3HexToInt(zUri[iIn++]);
163888
163889 assert( octet>=0 && octet<256 );
163890 if( octet==0 ){
163891#ifndef SQLITE_ENABLE_URI_00_ERROR
163892 /* This branch is taken when "%00" appears within the URI. In this
163893 ** case we ignore all text in the remainder of the path, name or
163894 ** value currently being parsed. So ignore the current character
163895 ** and skip to the next "?", "=" or "&", as appropriate. */
163896 while( (c = zUri[iIn])!=0 && c!='#'
163897 && (eState!=0 || c!='?')
163898 && (eState!=1 || (c!='=' && c!='&'))
163899 && (eState!=2 || c!='&')
163900 ){
163901 iIn++;
163902 }
163903 continue;
163904#else
163905 /* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */
163906 *pzErrMsg = sqlite3_mprintf("unexpected %%00 in uri");
163907 rc = SQLITE_ERROR;
163908 goto parse_uri_out;
163909#endif
163910 }
163911 c = octet;
163912 }else if( eState==1 && (c=='&' || c=='=') ){
163913 if( zFile[iOut-1]==0 ){
163914 /* An empty option name. Ignore this option altogether. */
163915 while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++;
163916 continue;
163917 }
163918 if( c=='&' ){
163919 zFile[iOut++] = '\0';
163920 }else{
163921 eState = 2;
163922 }
163923 c = 0;
163924 }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
163925 c = 0;
163926 eState = 1;
163927 }
163928 zFile[iOut++] = c;
163929 }
163930 if( eState==1 ) zFile[iOut++] = '\0';
163931 memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */
163932
163933 /* Check if there were any options specified that should be interpreted
163934 ** here. Options that are interpreted here include "vfs" and those that
163935 ** correspond to flags that may be passed to the sqlite3_open_v2()
163936 ** method. */
163937 zOpt = &zFile[sqlite3Strlen30(zFile)+1];
163938 while( zOpt[0] ){
163939 int nOpt = sqlite3Strlen30(zOpt);
163940 char *zVal = &zOpt[nOpt+1];
163941 int nVal = sqlite3Strlen30(zVal);
163942
163943 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
163944 zVfs = zVal;
163945 }else{
163946 struct OpenMode {
163947 const char *z;
163948 int mode;
163949 } *aMode = 0;
163950 char *zModeType = 0;
163951 int mask = 0;
163952 int limit = 0;
163953
163954 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
163955 static struct OpenMode aCacheMode[] = {
163956 { "shared", SQLITE_OPEN_SHAREDCACHE },
163957 { "private", SQLITE_OPEN_PRIVATECACHE },
163958 { 0, 0 }
163959 };
163960
163962 aMode = aCacheMode;
163963 limit = mask;
163964 zModeType = "cache";
163965 }
163966 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
163967 static struct OpenMode aOpenMode[] = {
163968 { "ro", SQLITE_OPEN_READONLY },
163969 { "rw", SQLITE_OPEN_READWRITE },
163971 { "memory", SQLITE_OPEN_MEMORY },
163972 { 0, 0 }
163973 };
163974
163977 aMode = aOpenMode;
163978 limit = mask & flags;
163979 zModeType = "access";
163980 }
163981
163982 if( aMode ){
163983 int i;
163984 int mode = 0;
163985 for(i=0; aMode[i].z; i++){
163986 const char *z = aMode[i].z;
163987 if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
163988 mode = aMode[i].mode;
163989 break;
163990 }
163991 }
163992 if( mode==0 ){
163993 *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
163994 rc = SQLITE_ERROR;
163995 goto parse_uri_out;
163996 }
163997 if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
163998 *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
163999 zModeType, zVal);
164000 rc = SQLITE_PERM;
164001 goto parse_uri_out;
164002 }
164003 flags = (flags & ~mask) | mode;
164004 }
164005 }
164006
164007 zOpt = &zVal[nVal+1];
164008 }
164009
164010 }else{
164011 zFile = sqlite3_malloc64(nUri+8);
164012 if( !zFile ) return SQLITE_NOMEM_BKPT;
164013 memset(zFile, 0, 4);
164014 zFile += 4;
164015 if( nUri ){
164016 memcpy(zFile, zUri, nUri);
164017 }
164018 memset(zFile+nUri, 0, 4);
164019 flags &= ~SQLITE_OPEN_URI;
164020 }
164021
164022 *ppVfs = sqlite3_vfs_find(zVfs);
164023 if( *ppVfs==0 ){
164024 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
164025 rc = SQLITE_ERROR;
164026 }
164027 parse_uri_out:
164028 if( rc!=SQLITE_OK ){
164029 sqlite3_free_filename(zFile);
#define SQLITE_PERM
Definition sqlite3.c:1473

References mask, sqlite3_free_filename(), sqlite3_malloc64(), sqlite3_mprintf(), sqlite3_vfs_find(), sqlite3GlobalConfig, sqlite3HexToInt(), sqlite3Isxdigit, sqlite3Strlen30(), SQLITE_ERROR, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_MEMORY, SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE, SQLITE_OPEN_URI, and SQLITE_PERM.

Referenced by attachFunc(), and openDatabase().

◆ sqlite3Pcache1Mutex()

SQLITE_PRIVATE sqlite3_mutex * sqlite3Pcache1Mutex ( void )

Definition at line 50974 of file sqlite3.c.

50974 { return ROUND8(sizeof(PgHdr1)); }
50975
50976/*

References ROUND8.

Referenced by sqlite3StatusHighwater(), sqlite3StatusUp(), and sqlite3StatusValue().

◆ sqlite3PCacheBufferSetup()

SQLITE_PRIVATE void sqlite3PCacheBufferSetup ( void * pBuf,
int sz,
int n )

Definition at line 50022 of file sqlite3.c.

50028 {
50029 if( pcache1.isInit ){
50030 PgFreeslot *p;
50031 if( pBuf==0 ) sz = n = 0;
50032 if( n==0 ) sz = 0;
50033 sz = ROUNDDOWN8(sz);
50034 pcache1.szSlot = sz;
50035 pcache1.nSlot = pcache1.nFreeSlot = n;
50036 pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
50037 pcache1.pStart = pBuf;
50038 pcache1.pFree = 0;
50039 pcache1.bUnderPressure = 0;
50040 while( n-- ){
50041 p = (PgFreeslot*)pBuf;
50042 p->pNext = pcache1.pFree;

References pcache1, PgFreeslot::pNext, and ROUNDDOWN8.

Referenced by sqlite3_initialize().

◆ sqlite3PcacheCleanAll()

SQLITE_PRIVATE void sqlite3PcacheCleanAll ( PCache * pCache)

Definition at line 49459 of file sqlite3.c.

49465 {

Referenced by pager_end_transaction(), and sqlite3PagerCommitPhaseOne().

◆ sqlite3PcacheClear()

SQLITE_PRIVATE void sqlite3PcacheClear ( PCache * pCache)

Definition at line 49557 of file sqlite3.c.

◆ sqlite3PcacheClearSyncFlags()

SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags ( PCache * pCache)

Definition at line 49482 of file sqlite3.c.

49488 {

Referenced by syncJournal().

◆ sqlite3PcacheClearWritable()

SQLITE_PRIVATE void sqlite3PcacheClearWritable ( PCache * pCache)

Definition at line 49470 of file sqlite3.c.

49476 {
49477 PgHdr *p;

Referenced by pager_end_transaction().

◆ sqlite3PcacheClose()

SQLITE_PRIVATE void sqlite3PcacheClose ( PCache * pCache)

Definition at line 49548 of file sqlite3.c.

Referenced by sqlite3PagerClose().

◆ sqlite3PcacheDirtyList()

SQLITE_PRIVATE PgHdr * sqlite3PcacheDirtyList ( PCache * pCache)

Definition at line 49637 of file sqlite3.c.

49643 {

Referenced by pagerWalFrames(), and sqlite3PagerCommitPhaseOne().

◆ sqlite3PcacheDrop()

SQLITE_PRIVATE void sqlite3PcacheDrop ( PgHdr * p)

Definition at line 49409 of file sqlite3.c.

49415 {
49416 assert( p->nRef==1 );
49417 assert( sqlite3PcachePageSanity(p) );

References PgHdr::flags, PgHdr::nRef, PCache::nRefSum, PgHdr::pCache, PCache::pCache, PCACHE_DIRTYLIST_REMOVE, pcacheManageDirtyList(), PGHDR_DIRTY, PgHdr::pPage, and sqlite3GlobalConfig.

Referenced by getPageNormal(), pagerUndoCallback(), and sqlite3PagerMovepage().

◆ sqlite3PcacheFetch()

SQLITE_PRIVATE sqlite3_pcache_page * sqlite3PcacheFetch ( PCache * pCache,
Pgno pgno,
int createFlag )

Definition at line 49236 of file sqlite3.c.

49246 {
49247 int eCreate;
49248 sqlite3_pcache_page *pRes;
49249
49250 assert( pCache!=0 );
49251 assert( pCache->pCache!=0 );
49252 assert( createFlag==3 || createFlag==0 );
49253 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
49254
49255 /* eCreate defines what to do if the page does not exist.
49256 ** 0 Do not allocate a new page. (createFlag==0)
49257 ** 1 Allocate a new page if doing so is inexpensive.
49258 ** (createFlag==1 AND bPurgeable AND pDirty)
49259 ** 2 Allocate a new page even it doing so is difficult.
49260 ** (createFlag==1 AND !(bPurgeable AND pDirty)
49261 */
49262 eCreate = createFlag & pCache->eCreate;
49263 assert( eCreate==0 || eCreate==1 || eCreate==2 );
49264 assert( createFlag==0 || pCache->eCreate==eCreate );
sqlite3_pcache * pCache
Definition sqlite3.c:48926

References PCache::bPurgeable, PCache::eCreate, PCache::pCache, pcacheTrace, PCache::pDirty, and sqlite3GlobalConfig.

Referenced by getPageNormal(), and sqlite3PagerLookup().

◆ sqlite3PcacheFetchFinish()

SQLITE_PRIVATE PgHdr * sqlite3PcacheFetchFinish ( PCache * pCache,
Pgno pgno,
sqlite3_pcache_page * pPage )

Definition at line 49359 of file sqlite3.c.

49369 {
49370 PgHdr *pPgHdr;
49371
49372 assert( pPage!=0 );
49373 pPgHdr = (PgHdr *)pPage->pExtra;
49374
49375 if( !pPgHdr->pPage ){
49376 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
static SQLITE_NOINLINE PgHdr * pcacheFetchFinishWithInit(PCache *pCache, Pgno pgno, sqlite3_pcache_page *pPage)
Definition sqlite3.c:49333

References PgHdr::nRef, PCache::nRefSum, pcacheFetchFinishWithInit(), sqlite3_pcache_page::pExtra, and PgHdr::pPage.

Referenced by getPageNormal(), pcacheFetchFinishWithInit(), and sqlite3PagerLookup().

◆ sqlite3PcacheFetchStress()

SQLITE_PRIVATE int sqlite3PcacheFetchStress ( PCache * pCache,
Pgno pgno,
sqlite3_pcache_page ** ppPage )

Definition at line 49277 of file sqlite3.c.

49287 {
49288 PgHdr *pPg;
49289 if( pCache->eCreate==2 ) return 0;
49290
49291 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
49292 /* Find a dirty page to write-out and recycle. First try to find a
49293 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
49294 ** cleared), but if that is not possible settle for any other
49295 ** unreferenced dirty page.
49296 **
49297 ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
49298 ** flag is currently referenced, then the following may leave pSynced
49299 ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
49300 ** cleared). This is Ok, as pSynced is just an optimization. */
49301 for(pPg=pCache->pSynced;
49302 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
49303 pPg=pPg->pDirtyPrev
49304 );
49305 pCache->pSynced = pPg;
49306 if( !pPg ){
49307 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
49308 }
49309 if( pPg ){
49310 int rc;
49311#ifdef SQLITE_LOG_CACHE_SPILL
49313 "spill page %d making room for %d - cache used: %d/%d",
49314 pPg->pgno, pgno,
49315 sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
49316 numberOfCachePages(pCache));
49317#endif
49318 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
49319 rc = pCache->xStress(pCache->pStress, pPg);
49320 pcacheDump(pCache);
49321 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
49322 return rc;
static int numberOfCachePages(PCache *p)
Definition sqlite3.c:49113
#define pcacheDump(X)
Definition sqlite3.c:48968
int(* xStress)(void *, PgHdr *)
Definition sqlite3.c:48924
int szSpill
Definition sqlite3.c:48919
void * pStress
Definition sqlite3.c:48925

References PCache::eCreate, PgHdr::flags, PgHdr::nRef, numberOfCachePages(), PCache::pCache, pcacheDump, pcacheTrace, PgHdr::pDirtyPrev, PCache::pDirtyTail, PGHDR_NEED_SYNC, PgHdr::pgno, PCache::pStress, PCache::pSynced, sqlite3_log(), sqlite3GlobalConfig, sqlite3PcachePagecount(), SQLITE_BUSY, SQLITE_FULL, SQLITE_NOMEM_BKPT, SQLITE_OK, PCache::szSpill, and PCache::xStress.

Referenced by getPageNormal().

◆ sqlite3PcacheInitialize()

SQLITE_PRIVATE int sqlite3PcacheInitialize ( void )

Definition at line 49132 of file sqlite3.c.

49138 {
49139 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
49140 /* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
49141 ** built-in default page cache is used instead of the application defined

References sqlite3GlobalConfig.

Referenced by sqlite3_initialize().

◆ sqlite3PcacheMakeClean()

SQLITE_PRIVATE void sqlite3PcacheMakeClean ( PgHdr * p)

Definition at line 49442 of file sqlite3.c.

49448 {
49449 assert( sqlite3PcachePageSanity(p) );
49450 assert( (p->flags & PGHDR_DIRTY)!=0 );
49451 assert( (p->flags & PGHDR_CLEAN)==0 );
49454 p->flags |= PGHDR_CLEAN;
static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove)
Definition sqlite3.c:49031
#define PGHDR_CLEAN
Definition sqlite3.c:16070

Referenced by pagerStress(), and sqlite3PcacheTruncate().

◆ sqlite3PcacheMakeDirty()

SQLITE_PRIVATE void sqlite3PcacheMakeDirty ( PgHdr * p)

Definition at line 49423 of file sqlite3.c.

49429 {
49430 assert( p->nRef>0 );
49431 assert( sqlite3PcachePageSanity(p) );
49432 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
49433 p->flags &= ~PGHDR_DONT_WRITE;
49434 if( p->flags & PGHDR_CLEAN ){
49436 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));

Referenced by pager_playback_one_page(), pager_write(), and sqlite3PagerMovepage().

◆ sqlite3PcacheMove()

SQLITE_PRIVATE void sqlite3PcacheMove ( PgHdr * p,
Pgno newPgno )

Definition at line 49493 of file sqlite3.c.

49499 {
49500 PCache *pCache = p->pCache;
49501 assert( p->nRef>0 );
49502 assert( newPgno>0 );
49503 assert( sqlite3PcachePageSanity(p) );
49504 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));

Referenced by sqlite3PagerMovepage().

◆ sqlite3PcacheOpen()

SQLITE_PRIVATE int sqlite3PcacheOpen ( int szPage,
int szExtra,
int bPurgeable,
int(*)(void *, PgHdr *) xStress,
void * pStress,
PCache * pToInit )

Definition at line 49166 of file sqlite3.c.

49179 {
49180 memset(p, 0, sizeof(PCache));
49181 p->szPage = 1;
49182 p->szExtra = szExtra;
49183 assert( szExtra>=8 ); /* First 8 bytes will be zeroed */
49184 p->bPurgeable = bPurgeable;
49185 p->eCreate = 2;
49186 p->xStress = xStress;

References PCache::bPurgeable, PCache::eCreate, pcacheTrace, PCache::pStress, sqlite3PcacheSetPageSize(), PCache::szCache, PCache::szExtra, PCache::szPage, PCache::szSpill, and PCache::xStress.

Referenced by sqlite3PagerOpen().

◆ sqlite3PcachePagecount()

SQLITE_PRIVATE int sqlite3PcachePagecount ( PCache * pCache)

◆ sqlite3PcachePageRefcount()

SQLITE_PRIVATE int sqlite3PcachePageRefcount ( PgHdr * p)

Definition at line 49658 of file sqlite3.c.

Referenced by pagerUndoCallback().

◆ sqlite3PCachePercentDirty()

SQLITE_PRIVATE int sqlite3PCachePercentDirty ( PCache * pCache)

Definition at line 49726 of file sqlite3.c.

49726 { return ROUND8(sizeof(PgHdr)); }
49727
49728/*
49729** Return the number of dirty pages currently in the cache, as a percentage
49730** of the configured cache size.
49731*/
SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *)
Definition sqlite3.c:49726

References ROUND8.

Referenced by pagerFlushOnCommit().

◆ sqlite3PcacheRef()

SQLITE_PRIVATE void sqlite3PcacheRef ( PgHdr * p)

Definition at line 49397 of file sqlite3.c.

◆ sqlite3PcacheRefCount()

SQLITE_PRIVATE int sqlite3PcacheRefCount ( PCache * pCache)

◆ sqlite3PcacheRelease()

SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease ( PgHdr * p)

Definition at line 49382 of file sqlite3.c.

49388 {
49389 assert( p->nRef>0 );
49390 p->pCache->nRefSum--;
49391 if( (--p->nRef)==0 ){
49392 if( p->flags&PGHDR_CLEAN ){
int nRefSum
Definition sqlite3.c:48917

Referenced by pager_playback_one_page().

◆ sqlite3PcacheSetCachesize()

SQLITE_PRIVATE void sqlite3PcacheSetCachesize ( PCache * pCache,
int mxPage )

Definition at line 49682 of file sqlite3.c.

◆ sqlite3PCacheSetDefault()

SQLITE_PRIVATE void sqlite3PCacheSetDefault ( void )

Definition at line 50946 of file sqlite3.c.

50952 {
50953 static const sqlite3_pcache_methods2 defaultMethods = {
50954 1, /* iVersion */
50955 0, /* pArg */
50956 pcache1Init, /* xInit */
50957 pcache1Shutdown, /* xShutdown */
50958 pcache1Create, /* xCreate */
50959 pcache1Cachesize, /* xCachesize */
50960 pcache1Pagecount, /* xPagecount */
50961 pcache1Fetch, /* xFetch */
50962 pcache1Unpin, /* xUnpin */
50963 pcache1Rekey, /* xRekey */
static int pcache1Init(void *NotUsed)
Definition sqlite3.c:50458
static void pcache1Cachesize(sqlite3_pcache *p, int nMax)
Definition sqlite3.c:50575
static void pcache1Unpin(sqlite3_pcache *p, sqlite3_pcache_page *pPg, int reuseUnlikely)
Definition sqlite3.c:50833
static void pcache1Shutdown(void *NotUsed)
Definition sqlite3.c:50511
static sqlite3_pcache_page * pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag)
Definition sqlite3.c:50802
static sqlite3_pcache * pcache1Create(int szPage, int szExtra, int bPurgeable)
Definition sqlite3.c:50525
static int pcache1Pagecount(sqlite3_pcache *p)
Definition sqlite3.c:50611
static void pcache1Rekey(sqlite3_pcache *p, sqlite3_pcache_page *pPg, unsigned int iOld, unsigned int iNew)
Definition sqlite3.c:50868

References pcache1Cachesize(), pcache1Create(), pcache1Destroy(), pcache1Fetch(), pcache1Init(), pcache1Pagecount(), pcache1Rekey(), pcache1Shrink(), pcache1Shutdown(), pcache1Truncate(), and pcache1Unpin().

Referenced by sqlite3_config().

◆ sqlite3PcacheSetPageSize()

SQLITE_PRIVATE int sqlite3PcacheSetPageSize ( PCache * pCache,
int szPage )

Definition at line 49192 of file sqlite3.c.

49198 {
49199 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
49200 if( pCache->szPage ){
49201 sqlite3_pcache *pNew;
49202 pNew = sqlite3GlobalConfig.pcache2.xCreate(
49203 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
49204 pCache->bPurgeable
49205 );
49206 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
49207 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
49208 if( pCache->pCache ){
49209 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
49210 }
struct sqlite3_pcache sqlite3_pcache
Definition sqlite3.c:9313
int szPage
Definition sqlite3.c:48920
int szExtra
Definition sqlite3.c:48921

Referenced by sqlite3PagerSetPagesize(), and sqlite3PcacheOpen().

◆ sqlite3PcacheSetSpillsize()

SQLITE_PRIVATE int sqlite3PcacheSetSpillsize ( PCache * p,
int mxPage )

Definition at line 49694 of file sqlite3.c.

49700 {
49701 int res;
49702 assert( p->pCache!=0 );
49703 if( mxPage ){
49704 if( mxPage<0 ){
49705 mxPage = (int)((-1024*(i64)mxPage)/(p->szPage+p->szExtra));
49706 }

References numberOfCachePages(), PCache::pCache, PCache::szExtra, PCache::szPage, and PCache::szSpill.

◆ sqlite3PcacheShrink()

SQLITE_PRIVATE void sqlite3PcacheShrink ( PCache * pCache)

Definition at line 49711 of file sqlite3.c.

◆ sqlite3PcacheShutdown()

SQLITE_PRIVATE void sqlite3PcacheShutdown ( void )

Definition at line 49142 of file sqlite3.c.

Referenced by sqlite3_shutdown().

◆ sqlite3PcacheSize()

SQLITE_PRIVATE int sqlite3PcacheSize ( void )

Definition at line 49152 of file sqlite3.c.

Referenced by sqlite3PagerOpen().

◆ sqlite3PcacheTruncate()

SQLITE_PRIVATE void sqlite3PcacheTruncate ( PCache * pCache,
Pgno x )

Definition at line 49515 of file sqlite3.c.

49521 {
49522 if( pCache->pCache ){
49523 PgHdr *p;
49524 PgHdr *pNext;
49525 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
49526 for(p=pCache->pDirty; p; p=pNext){
49527 pNext = p->pDirtyNext;
49528 /* This routine never gets call with a positive pgno except right
49529 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
49530 ** it must be that pgno==0.
49531 */
49532 assert( p->pgno>0 );
49533 if( p->pgno>pgno ){
49534 assert( p->flags&PGHDR_DIRTY );
49536 }
49537 }
49538 if( pgno==0 && pCache->nRefSum ){
49539 sqlite3_pcache_page *pPage1;
49540 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
49541 if( ALWAYS(pPage1) ){ /* Page 1 is always available in cache, because
49542 ** pCache->nRefSum>0 */
49543 memset(pPage1->pBuf, 0, pCache->szPage);
SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *)
Definition sqlite3.c:49442

References ALWAYS, PgHdr::flags, PCache::nRefSum, sqlite3_pcache_page::pBuf, PCache::pCache, pcacheTrace, PCache::pDirty, PgHdr::pDirtyNext, PGHDR_DIRTY, PgHdr::pgno, sqlite3GlobalConfig, sqlite3PcacheMakeClean(), and PCache::szPage.

Referenced by pager_end_transaction().

◆ sqlite3PExpr()

SQLITE_PRIVATE Expr * sqlite3PExpr ( Parse * pParse,
int op,
Expr * pLeft,
Expr * pRight )

Definition at line 100601 of file sqlite3.c.

100612 {
100613 Expr *p;
100614 p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
100615 if( p ){
100616 memset(p, 0, sizeof(Expr));
100617 p->op = op & 0xff;
100618 p->iAgg = -1;
100619 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
100620 sqlite3ExprCheckHeight(pParse, p->nHeight);
SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3 *, Expr *, Expr *, Expr *)
Definition sqlite3.c:100571
SQLITE_PRIVATE int sqlite3ExprCheckHeight(Parse *, int)
Definition sqlite3.c:100379
int nHeight
Definition sqlite3.c:18027

References Parse::db, Expr::iAgg, Expr::nHeight, Expr::op, sqlite3DbMallocRawNN(), sqlite3ExprAttachSubtrees(), sqlite3ExprCheckHeight(), and sqlite3ExprDelete().

Referenced by addWhereTerm(), exprAnalyze(), exprAnalyzeOrTerm(), exprRowColumn(), fkActionTrigger(), fkScanChildren(), flattenSubquery(), selectExpander(), sqlite3CodeSubselect(), sqlite3ExprAnd(), sqlite3ExprForVectorField(), sqlite3WhereTabFuncArgs(), updateFromSelect(), updateVirtualTable(), and yy_reduce().

◆ sqlite3PExprAddSelect()

SQLITE_PRIVATE void sqlite3PExprAddSelect ( Parse * pParse,
Expr * pExpr,
Select * pSelect )

Definition at line 100626 of file sqlite3.c.

100632 {
100633 if( pExpr ){
100634 pExpr->x.pSelect = pSelect;

Referenced by yy_reduce().

◆ sqlite3Pow10()

static LONGDOUBLE_TYPE sqlite3Pow10 ( int E)
static

Definition at line 31519 of file sqlite3.c.

31525 {
31526#if defined(_MSC_VER)
31527 static const LONGDOUBLE_TYPE x[] = {
31528 1.0e+001L,
31529 1.0e+002L,
31530 1.0e+004L,
31531 1.0e+008L,
31532 1.0e+016L,
31533 1.0e+032L,
31534 1.0e+064L,
31535 1.0e+128L,
31536 1.0e+256L
31537 };
31538 LONGDOUBLE_TYPE r = 1.0;
31539 int i;
31540 assert( E>=0 && E<=307 );
31541 for(i=0; E!=0; i++, E >>=1){
31542 if( E & 1 ) r *= x[i];
31543 }
31544 return r;
31545#else
31546 LONGDOUBLE_TYPE x = 10.0;
31547 LONGDOUBLE_TYPE r = 1.0;
31548 while(1){
31549 if( E & 1 ) r *= x;
31550 E >>= 1;

References LONGDOUBLE_TYPE.

Referenced by sqlite3AtoF().

◆ sqlite3Pragma()

SQLITE_PRIVATE void sqlite3Pragma ( Parse * pParse,
Token * pId1,
Token * pId2,
Token * pValue,
int minusFlag )

Definition at line 126117 of file sqlite3.c.

126129 {
126130 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
126131 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
126132 const char *zDb = 0; /* The database name */
126133 Token *pId; /* Pointer to <id> token */
126134 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
126135 int iDb; /* Database index for <database> */
126136 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
126137 sqlite3 *db = pParse->db; /* The database connection */
126138 Db *pDb; /* The specific database being pragmaed */
126139 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
126140 const PragmaName *pPragma; /* The pragma */
126141
126142 if( v==0 ) return;
126144 pParse->nMem = 2;
126145
126146 /* Interpret the [schema.] part of the pragma statement. iDb is the
126147 ** index of the database this pragma is being applied to in db.aDb[]. */
126148 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
126149 if( iDb<0 ) return;
126150 pDb = &db->aDb[iDb];
126151
126152 /* If the temp database has been explicitly named as part of the
126153 ** pragma, make sure it is open.
126154 */
126155 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
126156 return;
126157 }
126158
126159 zLeft = sqlite3NameFromToken(db, pId);
126160 if( !zLeft ) return;
126161 if( minusFlag ){
126162 zRight = sqlite3MPrintf(db, "-%T", pValue);
126163 }else{
126164 zRight = sqlite3NameFromToken(db, pValue);
126165 }
126166
126167 assert( pId2 );
126168 zDb = pId2->n>0 ? pDb->zDbSName : 0;
126169 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
126170 goto pragma_out;
126171 }
126172
126173 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
126174 ** connection. If it returns SQLITE_OK, then assume that the VFS
126175 ** handled the pragma and generate a no-op prepared statement.
126176 **
126177 ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
126178 ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
126179 ** object corresponding to the database file to which the pragma
126180 ** statement refers.
126181 **
126182 ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
126183 ** file control is an array of pointers to strings (char**) in which the
126184 ** second element of the array is the name of the pragma and the third
126185 ** element is the argument to the pragma or NULL if the pragma has no
126186 ** argument.
126187 */
126188 aFcntl[0] = 0;
126189 aFcntl[1] = zLeft;
126190 aFcntl[2] = zRight;
126191 aFcntl[3] = 0;
126192 db->busyHandler.nBusy = 0;
126193 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
126194 if( rc==SQLITE_OK ){
126195 sqlite3VdbeSetNumCols(v, 1);
126197 returnSingleText(v, aFcntl[0]);
126198 sqlite3_free(aFcntl[0]);
126199 goto pragma_out;
126200 }
126201 if( rc!=SQLITE_NOTFOUND ){
126202 if( aFcntl[0] ){
126203 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
126204 sqlite3_free(aFcntl[0]);
126205 }
126206 pParse->nErr++;
126207 pParse->rc = rc;
126208 goto pragma_out;
126209 }
126210
126211 /* Locate the pragma in the lookup table */
126212 pPragma = pragmaLocate(zLeft);
126213 if( pPragma==0 ) goto pragma_out;
126214
126215 /* Make sure the database schema is loaded if the pragma requires that */
126216 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
126217 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
126218 }
126219
126220 /* Register the result column names for pragmas that return results */
126221 if( (pPragma->mPragFlg & PragFlg_NoColumns)==0
126222 && ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0)
126223 ){
126224 setPragmaResultColumnNames(v, pPragma);
126225 }
126226
126227 /* Jump to the appropriate pragma handler */
126228 switch( pPragma->ePragTyp ){
126229
126230#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
126231 /*
126232 ** PRAGMA [schema.]default_cache_size
126233 ** PRAGMA [schema.]default_cache_size=N
126234 **
126235 ** The first form reports the current persistent setting for the
126236 ** page cache size. The value returned is the maximum number of
126237 ** pages in the page cache. The second form sets both the current
126238 ** page cache size value and the persistent page cache size value
126239 ** stored in the database file.
126240 **
126241 ** Older versions of SQLite would set the default cache size to a
126242 ** negative number to indicate synchronous=OFF. These days, synchronous
126243 ** is always on by default regardless of the sign of the default cache
126244 ** size. But continue to take the absolute value of the default cache
126245 ** size of historical compatibility.
126246 */
126248 static const int iLn = VDBE_OFFSET_LINENO(2);
126249 static const VdbeOpList getCacheSize[] = {
126250 { OP_Transaction, 0, 0, 0}, /* 0 */
126251 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
126252 { OP_IfPos, 1, 8, 0},
126253 { OP_Integer, 0, 2, 0},
126254 { OP_Subtract, 1, 2, 1},
126255 { OP_IfPos, 1, 8, 0},
126256 { OP_Integer, 0, 1, 0}, /* 6 */
126257 { OP_Noop, 0, 0, 0},
126258 { OP_ResultRow, 1, 1, 0},
126259 };
126260 VdbeOp *aOp;
126261 sqlite3VdbeUsesBtree(v, iDb);
126262 if( !zRight ){
126263 pParse->nMem += 2;
126265 aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn);
126266 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
126267 aOp[0].p1 = iDb;
126268 aOp[1].p1 = iDb;
126269 aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE;
126270 }else{
126271 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
126272 sqlite3BeginWriteOperation(pParse, 0, iDb);
126274 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
126275 pDb->pSchema->cache_size = size;
126277 }
126278 break;
126279 }
126280#endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
126281
126282#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
126283 /*
126284 ** PRAGMA [schema.]page_size
126285 ** PRAGMA [schema.]page_size=N
126286 **
126287 ** The first form reports the current setting for the
126288 ** database page size in bytes. The second form sets the
126289 ** database page size value. The value can only be set if
126290 ** the database has not yet been created.
126291 */
126292 case PragTyp_PAGE_SIZE: {
126293 Btree *pBt = pDb->pBt;
126294 assert( pBt!=0 );
126295 if( !zRight ){
126296 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
126297 returnSingleInt(v, size);
126298 }else{
126299 /* Malloc may fail when setting the page-size, as there is an internal
126300 ** buffer that the pager module resizes using sqlite3_realloc().
126301 */
126302 db->nextPagesize = sqlite3Atoi(zRight);
126304 sqlite3OomFault(db);
126305 }
126306 }
126307 break;
126308 }
126309
126310 /*
126311 ** PRAGMA [schema.]secure_delete
126312 ** PRAGMA [schema.]secure_delete=ON/OFF/FAST
126313 **
126314 ** The first form reports the current setting for the
126315 ** secure_delete flag. The second form changes the secure_delete
126316 ** flag setting and reports the new value.
126317 */
126318 case PragTyp_SECURE_DELETE: {
126319 Btree *pBt = pDb->pBt;
126320 int b = -1;
126321 assert( pBt!=0 );
126322 if( zRight ){
126323 if( sqlite3_stricmp(zRight, "fast")==0 ){
126324 b = 2;
126325 }else{
126326 b = sqlite3GetBoolean(zRight, 0);
126327 }
126328 }
126329 if( pId2->n==0 && b>=0 ){
126330 int ii;
126331 for(ii=0; ii<db->nDb; ii++){
126332 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
126333 }
126334 }
126335 b = sqlite3BtreeSecureDelete(pBt, b);
126336 returnSingleInt(v, b);
126337 break;
126338 }
126339
126340 /*
126341 ** PRAGMA [schema.]max_page_count
126342 ** PRAGMA [schema.]max_page_count=N
126343 **
126344 ** The first form reports the current setting for the
126345 ** maximum number of pages in the database file. The
126346 ** second form attempts to change this setting. Both
126347 ** forms return the current setting.
126348 **
126349 ** The absolute value of N is used. This is undocumented and might
126350 ** change. The only purpose is to provide an easy way to test
126351 ** the sqlite3AbsInt32() function.
126352 **
126353 ** PRAGMA [schema.]page_count
126354 **
126355 ** Return the number of pages in the specified database.
126356 */
126357 case PragTyp_PAGE_COUNT: {
126358 int iReg;
126359 i64 x = 0;
126360 sqlite3CodeVerifySchema(pParse, iDb);
126361 iReg = ++pParse->nMem;
126362 if( sqlite3Tolower(zLeft[0])=='p' ){
126363 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
126364 }else{
126365 if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){
126366 if( x<0 ) x = 0;
126367 else if( x>0xfffffffe ) x = 0xfffffffe;
126368 }else{
126369 x = 0;
126370 }
126371 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, (int)x);
126372 }
126373 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
126374 break;
126375 }
126376
126377 /*
126378 ** PRAGMA [schema.]locking_mode
126379 ** PRAGMA [schema.]locking_mode = (normal|exclusive)
126380 */
126381 case PragTyp_LOCKING_MODE: {
126382 const char *zRet = "normal";
126383 int eMode = getLockingMode(zRight);
126384
126385 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
126386 /* Simple "PRAGMA locking_mode;" statement. This is a query for
126387 ** the current default locking mode (which may be different to
126388 ** the locking-mode of the main database).
126389 */
126390 eMode = db->dfltLockMode;
126391 }else{
126392 Pager *pPager;
126393 if( pId2->n==0 ){
126394 /* This indicates that no database name was specified as part
126395 ** of the PRAGMA command. In this case the locking-mode must be
126396 ** set on all attached databases, as well as the main db file.
126397 **
126398 ** Also, the sqlite3.dfltLockMode variable is set so that
126399 ** any subsequently attached databases also use the specified
126400 ** locking mode.
126401 */
126402 int ii;
126403 assert(pDb==&db->aDb[0]);
126404 for(ii=2; ii<db->nDb; ii++){
126405 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
126406 sqlite3PagerLockingMode(pPager, eMode);
126407 }
126408 db->dfltLockMode = (u8)eMode;
126409 }
126410 pPager = sqlite3BtreePager(pDb->pBt);
126411 eMode = sqlite3PagerLockingMode(pPager, eMode);
126412 }
126413
126414 assert( eMode==PAGER_LOCKINGMODE_NORMAL
126415 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
126416 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
126417 zRet = "exclusive";
126418 }
126419 returnSingleText(v, zRet);
126420 break;
126421 }
126422
126423 /*
126424 ** PRAGMA [schema.]journal_mode
126425 ** PRAGMA [schema.]journal_mode =
126426 ** (delete|persist|off|truncate|memory|wal|off)
126427 */
126428 case PragTyp_JOURNAL_MODE: {
126429 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
126430 int ii; /* Loop counter */
126431
126432 if( zRight==0 ){
126433 /* If there is no "=MODE" part of the pragma, do a query for the
126434 ** current mode */
126435 eMode = PAGER_JOURNALMODE_QUERY;
126436 }else{
126437 const char *zMode;
126438 int n = sqlite3Strlen30(zRight);
126439 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
126440 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
126441 }
126442 if( !zMode ){
126443 /* If the "=MODE" part does not match any known journal mode,
126444 ** then do a query */
126445 eMode = PAGER_JOURNALMODE_QUERY;
126446 }
126447 if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
126448 /* Do not allow journal-mode "OFF" in defensive since the database
126449 ** can become corrupted using ordinary SQL when the journal is off */
126450 eMode = PAGER_JOURNALMODE_QUERY;
126451 }
126452 }
126453 if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
126454 /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
126455 iDb = 0;
126456 pId2->n = 1;
126457 }
126458 for(ii=db->nDb-1; ii>=0; ii--){
126459 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
126460 sqlite3VdbeUsesBtree(v, ii);
126461 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
126462 }
126463 }
126465 break;
126466 }
126467
126468 /*
126469 ** PRAGMA [schema.]journal_size_limit
126470 ** PRAGMA [schema.]journal_size_limit=N
126471 **
126472 ** Get or set the size limit on rollback journal files.
126473 */
126475 Pager *pPager = sqlite3BtreePager(pDb->pBt);
126476 i64 iLimit = -2;
126477 if( zRight ){
126478 sqlite3DecOrHexToI64(zRight, &iLimit);
126479 if( iLimit<-1 ) iLimit = -1;
126480 }
126481 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
126482 returnSingleInt(v, iLimit);
126483 break;
126484 }
126485
126486#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
126487
126488 /*
126489 ** PRAGMA [schema.]auto_vacuum
126490 ** PRAGMA [schema.]auto_vacuum=N
126491 **
126492 ** Get or set the value of the database 'auto-vacuum' parameter.
126493 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
126494 */
126495#ifndef SQLITE_OMIT_AUTOVACUUM
126496 case PragTyp_AUTO_VACUUM: {
126497 Btree *pBt = pDb->pBt;
126498 assert( pBt!=0 );
126499 if( !zRight ){
126501 }else{
126502 int eAuto = getAutoVacuum(zRight);
126503 assert( eAuto>=0 && eAuto<=2 );
126504 db->nextAutovac = (u8)eAuto;
126505 /* Call SetAutoVacuum() to set initialize the internal auto and
126506 ** incr-vacuum flags. This is required in case this connection
126507 ** creates the database file. It is important that it is created
126508 ** as an auto-vacuum capable db.
126509 */
126510 rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
126511 if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
126512 /* When setting the auto_vacuum mode to either "full" or
126513 ** "incremental", write the value of meta[6] in the database
126514 ** file. Before writing to meta[6], check that meta[3] indicates
126515 ** that this really is an auto-vacuum capable database.
126516 */
126517 static const int iLn = VDBE_OFFSET_LINENO(2);
126518 static const VdbeOpList setMeta6[] = {
126519 { OP_Transaction, 0, 1, 0}, /* 0 */
126521 { OP_If, 1, 0, 0}, /* 2 */
126522 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
126523 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */
126524 };
126525 VdbeOp *aOp;
126526 int iAddr = sqlite3VdbeCurrentAddr(v);
126528 aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
126529 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
126530 aOp[0].p1 = iDb;
126531 aOp[1].p1 = iDb;
126532 aOp[2].p2 = iAddr+4;
126533 aOp[4].p1 = iDb;
126534 aOp[4].p3 = eAuto - 1;
126535 sqlite3VdbeUsesBtree(v, iDb);
126536 }
126537 }
126538 break;
126539 }
126540#endif
126541
126542 /*
126543 ** PRAGMA [schema.]incremental_vacuum(N)
126544 **
126545 ** Do N steps of incremental vacuuming on a database.
126546 */
126547#ifndef SQLITE_OMIT_AUTOVACUUM
126549 int iLimit, addr;
126550 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
126551 iLimit = 0x7fffffff;
126552 }
126553 sqlite3BeginWriteOperation(pParse, 0, iDb);
126554 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
126555 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
126557 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
126558 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
126559 sqlite3VdbeJumpHere(v, addr);
126560 break;
126561 }
126562#endif
126563
126564#ifndef SQLITE_OMIT_PAGER_PRAGMAS
126565 /*
126566 ** PRAGMA [schema.]cache_size
126567 ** PRAGMA [schema.]cache_size=N
126568 **
126569 ** The first form reports the current local setting for the
126570 ** page cache size. The second form sets the local
126571 ** page cache size value. If N is positive then that is the
126572 ** number of pages in the cache. If N is negative, then the
126573 ** number of pages is adjusted so that the cache uses -N kibibytes
126574 ** of memory.
126575 */
126576 case PragTyp_CACHE_SIZE: {
126577 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
126578 if( !zRight ){
126580 }else{
126581 int size = sqlite3Atoi(zRight);
126582 pDb->pSchema->cache_size = size;
126584 }
126585 break;
126586 }
126587
126588 /*
126589 ** PRAGMA [schema.]cache_spill
126590 ** PRAGMA cache_spill=BOOLEAN
126591 ** PRAGMA [schema.]cache_spill=N
126592 **
126593 ** The first form reports the current local setting for the
126594 ** page cache spill size. The second form turns cache spill on
126595 ** or off. When turnning cache spill on, the size is set to the
126596 ** current cache_size. The third form sets a spill size that
126597 ** may be different form the cache size.
126598 ** If N is positive then that is the
126599 ** number of pages in the cache. If N is negative, then the
126600 ** number of pages is adjusted so that the cache uses -N kibibytes
126601 ** of memory.
126602 **
126603 ** If the number of cache_spill pages is less then the number of
126604 ** cache_size pages, no spilling occurs until the page count exceeds
126605 ** the number of cache_size pages.
126606 **
126607 ** The cache_spill=BOOLEAN setting applies to all attached schemas,
126608 ** not just the schema specified.
126609 */
126610 case PragTyp_CACHE_SPILL: {
126611 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
126612 if( !zRight ){
126613 returnSingleInt(v,
126614 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
126615 sqlite3BtreeSetSpillSize(pDb->pBt,0));
126616 }else{
126617 int size = 1;
126618 if( sqlite3GetInt32(zRight, &size) ){
126619 sqlite3BtreeSetSpillSize(pDb->pBt, size);
126620 }
126621 if( sqlite3GetBoolean(zRight, size!=0) ){
126622 db->flags |= SQLITE_CacheSpill;
126623 }else{
126624 db->flags &= ~(u64)SQLITE_CacheSpill;
126625 }
126626 setAllPagerFlags(db);
126627 }
126628 break;
126629 }
126630
126631 /*
126632 ** PRAGMA [schema.]mmap_size(N)
126633 **
126634 ** Used to set mapping size limit. The mapping size limit is
126635 ** used to limit the aggregate size of all memory mapped regions of the
126636 ** database file. If this parameter is set to zero, then memory mapping
126637 ** is not used at all. If N is negative, then the default memory map
126638 ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
126639 ** The parameter N is measured in bytes.
126640 **
126641 ** This value is advisory. The underlying VFS is free to memory map
126642 ** as little or as much as it wants. Except, if N is set to 0 then the
126643 ** upper layers will never invoke the xFetch interfaces to the VFS.
126644 */
126645 case PragTyp_MMAP_SIZE: {
126646 sqlite3_int64 sz;
126647#if SQLITE_MAX_MMAP_SIZE>0
126648 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
126649 if( zRight ){
126650 int ii;
126651 sqlite3DecOrHexToI64(zRight, &sz);
126652 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
126653 if( pId2->n==0 ) db->szMmap = sz;
126654 for(ii=db->nDb-1; ii>=0; ii--){
126655 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
126656 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
126657 }
126658 }
126659 }
126660 sz = -1;
126661 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
126662#else
126663 sz = 0;
126664 rc = SQLITE_OK;
126665#endif
126666 if( rc==SQLITE_OK ){
126667 returnSingleInt(v, sz);
126668 }else if( rc!=SQLITE_NOTFOUND ){
126669 pParse->nErr++;
126670 pParse->rc = rc;
126671 }
126672 break;
126673 }
126674
126675 /*
126676 ** PRAGMA temp_store
126677 ** PRAGMA temp_store = "default"|"memory"|"file"
126678 **
126679 ** Return or set the local value of the temp_store flag. Changing
126680 ** the local value does not make changes to the disk file and the default
126681 ** value will be restored the next time the database is opened.
126682 **
126683 ** Note that it is possible for the library compile-time options to
126684 ** override this setting
126685 */
126686 case PragTyp_TEMP_STORE: {
126687 if( !zRight ){
126688 returnSingleInt(v, db->temp_store);
126689 }else{
126690 changeTempStorage(pParse, zRight);
126691 }
126692 break;
126693 }
126694
126695 /*
126696 ** PRAGMA temp_store_directory
126697 ** PRAGMA temp_store_directory = ""|"directory_name"
126698 **
126699 ** Return or set the local value of the temp_store_directory flag. Changing
126700 ** the value sets a specific directory to be used for temporary files.
126701 ** Setting to a null string reverts to the default temporary directory search.
126702 ** If temporary directory is changed, then invalidateTempStorage.
126703 **
126704 */
126706 if( !zRight ){
126708 }else{
126709#ifndef SQLITE_OMIT_WSD
126710 if( zRight[0] ){
126711 int res;
126712 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
126713 if( rc!=SQLITE_OK || res==0 ){
126714 sqlite3ErrorMsg(pParse, "not a writable directory");
126715 goto pragma_out;
126716 }
126717 }
126718 if( SQLITE_TEMP_STORE==0
126719 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
126720 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
126721 ){
126722 invalidateTempStorage(pParse);
126723 }
126725 if( zRight[0] ){
126726 sqlite3_temp_directory = sqlite3_mprintf("%s", zRight);
126727 }else{
126729 }
126730#endif /* SQLITE_OMIT_WSD */
126731 }
126732 break;
126733 }
126734
126735#if SQLITE_OS_WIN
126736 /*
126737 ** PRAGMA data_store_directory
126738 ** PRAGMA data_store_directory = ""|"directory_name"
126739 **
126740 ** Return or set the local value of the data_store_directory flag. Changing
126741 ** the value sets a specific directory to be used for database files that
126742 ** were specified with a relative pathname. Setting to a null string reverts
126743 ** to the default database directory, which for database files specified with
126744 ** a relative path will probably be based on the current directory for the
126745 ** process. Database file specified with an absolute path are not impacted
126746 ** by this setting, regardless of its value.
126747 **
126748 */
126750 if( !zRight ){
126752 }else{
126753#ifndef SQLITE_OMIT_WSD
126754 if( zRight[0] ){
126755 int res;
126756 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
126757 if( rc!=SQLITE_OK || res==0 ){
126758 sqlite3ErrorMsg(pParse, "not a writable directory");
126759 goto pragma_out;
126760 }
126761 }
126763 if( zRight[0] ){
126764 sqlite3_data_directory = sqlite3_mprintf("%s", zRight);
126765 }else{
126767 }
126768#endif /* SQLITE_OMIT_WSD */
126769 }
126770 break;
126771 }
126772#endif
126773
126774#if SQLITE_ENABLE_LOCKING_STYLE
126775 /*
126776 ** PRAGMA [schema.]lock_proxy_file
126777 ** PRAGMA [schema.]lock_proxy_file = ":auto:"|"lock_file_path"
126778 **
126779 ** Return or set the value of the lock_proxy_file flag. Changing
126780 ** the value sets a specific file to be used for database access locks.
126781 **
126782 */
126784 if( !zRight ){
126785 Pager *pPager = sqlite3BtreePager(pDb->pBt);
126786 char *proxy_file_path = NULL;
126787 sqlite3_file *pFile = sqlite3PagerFile(pPager);
126789 &proxy_file_path);
126790 returnSingleText(v, proxy_file_path);
126791 }else{
126792 Pager *pPager = sqlite3BtreePager(pDb->pBt);
126793 sqlite3_file *pFile = sqlite3PagerFile(pPager);
126794 int res;
126795 if( zRight[0] ){
126797 zRight);
126798 } else {
126800 NULL);
126801 }
126802 if( res!=SQLITE_OK ){
126803 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
126804 goto pragma_out;
126805 }
126806 }
126807 break;
126808 }
126809#endif /* SQLITE_ENABLE_LOCKING_STYLE */
126810
126811 /*
126812 ** PRAGMA [schema.]synchronous
126813 ** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA
126814 **
126815 ** Return or set the local value of the synchronous flag. Changing
126816 ** the local value does not make changes to the disk file and the
126817 ** default value will be restored the next time the database is
126818 ** opened.
126819 */
126820 case PragTyp_SYNCHRONOUS: {
126821 if( !zRight ){
126822 returnSingleInt(v, pDb->safety_level-1);
126823 }else{
126824 if( !db->autoCommit ){
126825 sqlite3ErrorMsg(pParse,
126826 "Safety level may not be changed inside a transaction");
126827 }else if( iDb!=1 ){
126828 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
126829 if( iLevel==0 ) iLevel = 1;
126830 pDb->safety_level = iLevel;
126831 pDb->bSyncSet = 1;
126832 setAllPagerFlags(db);
126833 }
126834 }
126835 break;
126836 }
126837#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
126838
126839#ifndef SQLITE_OMIT_FLAG_PRAGMAS
126840 case PragTyp_FLAG: {
126841 if( zRight==0 ){
126842 setPragmaResultColumnNames(v, pPragma);
126843 returnSingleInt(v, (db->flags & pPragma->iArg)!=0 );
126844 }else{
126845 u64 mask = pPragma->iArg; /* Mask of bits to set or clear. */
126846 if( db->autoCommit==0 ){
126847 /* Foreign key support may not be enabled or disabled while not
126848 ** in auto-commit mode. */
126849 mask &= ~(SQLITE_ForeignKeys);
126850 }
126851#if SQLITE_USER_AUTHENTICATION
126852 if( db->auth.authLevel==UAUTH_User ){
126853 /* Do not allow non-admin users to modify the schema arbitrarily */
126854 mask &= ~(SQLITE_WriteSchema);
126855 }
126856#endif
126857
126858 if( sqlite3GetBoolean(zRight, 0) ){
126859 db->flags |= mask;
126860 }else{
126861 db->flags &= ~mask;
126862 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
126863 }
126864
126865 /* Many of the flag-pragmas modify the code generated by the SQL
126866 ** compiler (eg. count_changes). So add an opcode to expire all
126867 ** compiled SQL statements after modifying a pragma value.
126868 */
126870 setAllPagerFlags(db);
126871 }
126872 break;
126873 }
126874#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
126875
126876#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
126877 /*
126878 ** PRAGMA table_info(<table>)
126879 **
126880 ** Return a single row for each column of the named table. The columns of
126881 ** the returned data set are:
126882 **
126883 ** cid: Column id (numbered from left to right, starting at 0)
126884 ** name: Column name
126885 ** type: Column declaration type.
126886 ** notnull: True if 'NOT NULL' is part of column declaration
126887 ** dflt_value: The default value for the column, if any.
126888 ** pk: Non-zero for PK fields.
126889 */
126890 case PragTyp_TABLE_INFO: if( zRight ){
126891 Table *pTab;
126892 sqlite3CodeVerifyNamedSchema(pParse, zDb);
126893 pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
126894 if( pTab ){
126895 int i, k;
126896 int nHidden = 0;
126897 Column *pCol;
126898 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
126899 pParse->nMem = 7;
126900 sqlite3ViewGetColumnNames(pParse, pTab);
126901 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
126902 int isHidden = 0;
126903 if( pCol->colFlags & COLFLAG_NOINSERT ){
126904 if( pPragma->iArg==0 ){
126905 nHidden++;
126906 continue;
126907 }
126908 if( pCol->colFlags & COLFLAG_VIRTUAL ){
126909 isHidden = 2; /* GENERATED ALWAYS AS ... VIRTUAL */
126910 }else if( pCol->colFlags & COLFLAG_STORED ){
126911 isHidden = 3; /* GENERATED ALWAYS AS ... STORED */
126912 }else{ assert( pCol->colFlags & COLFLAG_HIDDEN );
126913 isHidden = 1; /* HIDDEN */
126914 }
126915 }
126916 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
126917 k = 0;
126918 }else if( pPk==0 ){
126919 k = 1;
126920 }else{
126921 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
126922 }
126923 assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN || isHidden>=2 );
126924 sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
126925 i-nHidden,
126926 pCol->zName,
126927 sqlite3ColumnType(pCol,""),
126928 pCol->notNull ? 1 : 0,
126929 pCol->pDflt && isHidden<2 ? pCol->pDflt->u.zToken : 0,
126930 k,
126931 isHidden);
126932 }
126933 }
126934 }
126935 break;
126936
126937#ifdef SQLITE_DEBUG
126938 case PragTyp_STATS: {
126939 Index *pIdx;
126940 HashElem *i;
126941 pParse->nMem = 5;
126942 sqlite3CodeVerifySchema(pParse, iDb);
126943 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
126944 Table *pTab = sqliteHashData(i);
126945 sqlite3VdbeMultiLoad(v, 1, "ssiii",
126946 pTab->zName,
126947 0,
126948 pTab->szTabRow,
126949 pTab->nRowLogEst,
126950 pTab->tabFlags);
126951 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
126952 sqlite3VdbeMultiLoad(v, 2, "siiiX",
126953 pIdx->zName,
126954 pIdx->szIdxRow,
126955 pIdx->aiRowLogEst[0],
126956 pIdx->hasStat1);
126958 }
126959 }
126960 }
126961 break;
126962#endif
126963
126964 case PragTyp_INDEX_INFO: if( zRight ){
126965 Index *pIdx;
126966 Table *pTab;
126967 pIdx = sqlite3FindIndex(db, zRight, zDb);
126968 if( pIdx==0 ){
126969 /* If there is no index named zRight, check to see if there is a
126970 ** WITHOUT ROWID table named zRight, and if there is, show the
126971 ** structure of the PRIMARY KEY index for that table. */
126972 pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
126973 if( pTab && !HasRowid(pTab) ){
126974 pIdx = sqlite3PrimaryKeyIndex(pTab);
126975 }
126976 }
126977 if( pIdx ){
126978 int iIdxDb = sqlite3SchemaToIndex(db, pIdx->pSchema);
126979 int i;
126980 int mx;
126981 if( pPragma->iArg ){
126982 /* PRAGMA index_xinfo (newer version with more rows and columns) */
126983 mx = pIdx->nColumn;
126984 pParse->nMem = 6;
126985 }else{
126986 /* PRAGMA index_info (legacy version) */
126987 mx = pIdx->nKeyCol;
126988 pParse->nMem = 3;
126989 }
126990 pTab = pIdx->pTable;
126991 sqlite3CodeVerifySchema(pParse, iIdxDb);
126992 assert( pParse->nMem<=pPragma->nPragCName );
126993 for(i=0; i<mx; i++){
126994 i16 cnum = pIdx->aiColumn[i];
126995 sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum,
126996 cnum<0 ? 0 : pTab->aCol[cnum].zName);
126997 if( pPragma->iArg ){
126998 sqlite3VdbeMultiLoad(v, 4, "isiX",
126999 pIdx->aSortOrder[i],
127000 pIdx->azColl[i],
127001 i<pIdx->nKeyCol);
127002 }
127003 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
127004 }
127005 }
127006 }
127007 break;
127008
127009 case PragTyp_INDEX_LIST: if( zRight ){
127010 Index *pIdx;
127011 Table *pTab;
127012 int i;
127013 pTab = sqlite3FindTable(db, zRight, zDb);
127014 if( pTab ){
127015 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
127016 pParse->nMem = 5;
127017 sqlite3CodeVerifySchema(pParse, iTabDb);
127018 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
127019 const char *azOrigin[] = { "c", "u", "pk" };
127020 sqlite3VdbeMultiLoad(v, 1, "isisi",
127021 i,
127022 pIdx->zName,
127023 IsUniqueIndex(pIdx),
127024 azOrigin[pIdx->idxType],
127025 pIdx->pPartIdxWhere!=0);
127026 }
127027 }
127028 }
127029 break;
127030
127031 case PragTyp_DATABASE_LIST: {
127032 int i;
127033 pParse->nMem = 3;
127034 for(i=0; i<db->nDb; i++){
127035 if( db->aDb[i].pBt==0 ) continue;
127036 assert( db->aDb[i].zDbSName!=0 );
127037 sqlite3VdbeMultiLoad(v, 1, "iss",
127038 i,
127039 db->aDb[i].zDbSName,
127041 }
127042 }
127043 break;
127044
127045 case PragTyp_COLLATION_LIST: {
127046 int i = 0;
127047 HashElem *p;
127048 pParse->nMem = 2;
127049 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
127050 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
127051 sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
127052 }
127053 }
127054 break;
127055
127056#ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
127057 case PragTyp_FUNCTION_LIST: {
127058 int i;
127059 HashElem *j;
127060 FuncDef *p;
127061 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
127062 pParse->nMem = 6;
127063 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
127064 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
127065 pragmaFunclistLine(v, p, 1, showInternFunc);
127066 }
127067 }
127068 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
127069 p = (FuncDef*)sqliteHashData(j);
127070 pragmaFunclistLine(v, p, 0, showInternFunc);
127071 }
127072 }
127073 break;
127074
127075#ifndef SQLITE_OMIT_VIRTUALTABLE
127076 case PragTyp_MODULE_LIST: {
127077 HashElem *j;
127078 pParse->nMem = 1;
127079 for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
127080 Module *pMod = (Module*)sqliteHashData(j);
127081 sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
127082 }
127083 }
127084 break;
127085#endif /* SQLITE_OMIT_VIRTUALTABLE */
127086
127087 case PragTyp_PRAGMA_LIST: {
127088 int i;
127089 for(i=0; i<ArraySize(aPragmaName); i++){
127090 sqlite3VdbeMultiLoad(v, 1, "s", aPragmaName[i].zName);
127091 }
127092 }
127093 break;
127094#endif /* SQLITE_INTROSPECTION_PRAGMAS */
127095
127096#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
127097
127098#ifndef SQLITE_OMIT_FOREIGN_KEY
127099 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
127100 FKey *pFK;
127101 Table *pTab;
127102 pTab = sqlite3FindTable(db, zRight, zDb);
127103 if( pTab ){
127104 pFK = pTab->pFKey;
127105 if( pFK ){
127106 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
127107 int i = 0;
127108 pParse->nMem = 8;
127109 sqlite3CodeVerifySchema(pParse, iTabDb);
127110 while(pFK){
127111 int j;
127112 for(j=0; j<pFK->nCol; j++){
127113 sqlite3VdbeMultiLoad(v, 1, "iissssss",
127114 i,
127115 j,
127116 pFK->zTo,
127117 pTab->aCol[pFK->aCol[j].iFrom].zName,
127118 pFK->aCol[j].zCol,
127119 actionName(pFK->aAction[1]), /* ON UPDATE */
127120 actionName(pFK->aAction[0]), /* ON DELETE */
127121 "NONE");
127122 }
127123 ++i;
127124 pFK = pFK->pNextFrom;
127125 }
127126 }
127127 }
127128 }
127129 break;
127130#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
127131
127132#ifndef SQLITE_OMIT_FOREIGN_KEY
127133#ifndef SQLITE_OMIT_TRIGGER
127135 FKey *pFK; /* A foreign key constraint */
127136 Table *pTab; /* Child table contain "REFERENCES" keyword */
127137 Table *pParent; /* Parent table that child points to */
127138 Index *pIdx; /* Index in the parent table */
127139 int i; /* Loop counter: Foreign key number for pTab */
127140 int j; /* Loop counter: Field of the foreign key */
127141 HashElem *k; /* Loop counter: Next table in schema */
127142 int x; /* result variable */
127143 int regResult; /* 3 registers to hold a result row */
127144 int regKey; /* Register to hold key for checking the FK */
127145 int regRow; /* Registers to hold a row from pTab */
127146 int addrTop; /* Top of a loop checking foreign keys */
127147 int addrOk; /* Jump here if the key is OK */
127148 int *aiCols; /* child to parent column mapping */
127149
127150 regResult = pParse->nMem+1;
127151 pParse->nMem += 4;
127152 regKey = ++pParse->nMem;
127153 regRow = ++pParse->nMem;
127154 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
127155 while( k ){
127156 if( zRight ){
127157 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
127158 k = 0;
127159 }else{
127160 pTab = (Table*)sqliteHashData(k);
127161 k = sqliteHashNext(k);
127162 }
127163 if( pTab==0 || pTab->pFKey==0 ) continue;
127164 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
127165 zDb = db->aDb[iDb].zDbSName;
127166 sqlite3CodeVerifySchema(pParse, iDb);
127167 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
127168 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
127169 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
127170 sqlite3VdbeLoadString(v, regResult, pTab->zName);
127171 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
127172 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
127173 if( pParent==0 ) continue;
127174 pIdx = 0;
127175 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
127176 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
127177 if( x==0 ){
127178 if( pIdx==0 ){
127179 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
127180 }else{
127181 sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb);
127182 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
127183 }
127184 }else{
127185 k = 0;
127186 break;
127187 }
127188 }
127189 assert( pParse->nErr>0 || pFK==0 );
127190 if( pFK ) break;
127191 if( pParse->nTab<i ) pParse->nTab = i;
127192 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
127193 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
127194 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
127195 pIdx = 0;
127196 aiCols = 0;
127197 if( pParent ){
127198 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
127199 assert( x==0 );
127200 }
127201 addrOk = sqlite3VdbeMakeLabel(pParse);
127202
127203 /* Generate code to read the child key values into registers
127204 ** regRow..regRow+n. If any of the child key values are NULL, this
127205 ** row cannot cause an FK violation. Jump directly to addrOk in
127206 ** this case. */
127207 for(j=0; j<pFK->nCol; j++){
127208 int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
127209 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
127210 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
127211 }
127212
127213 /* Generate code to query the parent index for a matching parent
127214 ** key. If a match is found, jump to addrOk. */
127215 if( pIdx ){
127216 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
127217 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
127218 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
127219 VdbeCoverage(v);
127220 }else if( pParent ){
127221 int jmp = sqlite3VdbeCurrentAddr(v)+2;
127222 sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
127223 sqlite3VdbeGoto(v, addrOk);
127224 assert( pFK->nCol==1 );
127225 }
127226
127227 /* Generate code to report an FK violation to the caller. */
127228 if( HasRowid(pTab) ){
127229 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
127230 }else{
127231 sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
127232 }
127233 sqlite3VdbeMultiLoad(v, regResult+2, "siX", pFK->zTo, i-1);
127234 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
127235 sqlite3VdbeResolveLabel(v, addrOk);
127236 sqlite3DbFree(db, aiCols);
127237 }
127238 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
127239 sqlite3VdbeJumpHere(v, addrTop);
127240 }
127241 }
127242 break;
127243#endif /* !defined(SQLITE_OMIT_TRIGGER) */
127244#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
127245
127246#ifndef SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA
127247 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
127248 ** used will be case sensitive or not depending on the RHS.
127249 */
127251 if( zRight ){
127253 }
127254 }
127255 break;
127256#endif /* SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA */
127257
127258#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
127259# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
127260#endif
127261
127262#ifndef SQLITE_OMIT_INTEGRITY_CHECK
127263 /* PRAGMA integrity_check
127264 ** PRAGMA integrity_check(N)
127265 ** PRAGMA quick_check
127266 ** PRAGMA quick_check(N)
127267 **
127268 ** Verify the integrity of the database.
127269 **
127270 ** The "quick_check" is reduced version of
127271 ** integrity_check designed to detect most database corruption
127272 ** without the overhead of cross-checking indexes. Quick_check
127273 ** is linear time wherease integrity_check is O(NlogN).
127274 **
127275 ** The maximum nubmer of errors is 100 by default. A different default
127276 ** can be specified using a numeric parameter N.
127277 **
127278 ** Or, the parameter N can be the name of a table. In that case, only
127279 ** the one table named is verified. The freelist is only verified if
127280 ** the named table is "sqlite_schema" (or one of its aliases).
127281 **
127282 ** All schemas are checked by default. To check just a single
127283 ** schema, use the form:
127284 **
127285 ** PRAGMA schema.integrity_check;
127286 */
127288 int i, j, addr, mxErr;
127289 Table *pObjTab = 0; /* Check only this one table, if not NULL */
127290
127291 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
127292
127293 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
127294 ** then iDb is set to the index of the database identified by <db>.
127295 ** In this case, the integrity of database iDb only is verified by
127296 ** the VDBE created below.
127297 **
127298 ** Otherwise, if the command was simply "PRAGMA integrity_check" (or
127299 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
127300 ** to -1 here, to indicate that the VDBE should verify the integrity
127301 ** of all attached databases. */
127302 assert( iDb>=0 );
127303 assert( iDb==0 || pId2->z );
127304 if( pId2->z==0 ) iDb = -1;
127305
127306 /* Initialize the VDBE program */
127307 pParse->nMem = 6;
127308
127309 /* Set the maximum error count */
127311 if( zRight ){
127312 if( sqlite3GetInt32(zRight, &mxErr) ){
127313 if( mxErr<=0 ){
127315 }
127316 }else{
127317 pObjTab = sqlite3LocateTable(pParse, 0, zRight,
127318 iDb>=0 ? db->aDb[iDb].zDbSName : 0);
127319 }
127320 }
127321 sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
127322
127323 /* Do an integrity check on each database file */
127324 for(i=0; i<db->nDb; i++){
127325 HashElem *x; /* For looping over tables in the schema */
127326 Hash *pTbls; /* Set of all tables in the schema */
127327 int *aRoot; /* Array of root page numbers of all btrees */
127328 int cnt = 0; /* Number of entries in aRoot[] */
127329 int mxIdx = 0; /* Maximum number of indexes for any table */
127330
127331 if( OMIT_TEMPDB && i==1 ) continue;
127332 if( iDb>=0 && i!=iDb ) continue;
127333
127334 sqlite3CodeVerifySchema(pParse, i);
127335
127336 /* Do an integrity check of the B-Tree
127337 **
127338 ** Begin by finding the root pages numbers
127339 ** for all tables and indices in the database.
127340 */
127341 assert( sqlite3SchemaMutexHeld(db, i, 0) );
127342 pTbls = &db->aDb[i].pSchema->tblHash;
127343 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127344 Table *pTab = sqliteHashData(x); /* Current table */
127345 Index *pIdx; /* An index on pTab */
127346 int nIdx; /* Number of indexes on pTab */
127347 if( pObjTab && pObjTab!=pTab ) continue;
127348 if( HasRowid(pTab) ) cnt++;
127349 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
127350 if( nIdx>mxIdx ) mxIdx = nIdx;
127351 }
127352 if( cnt==0 ) continue;
127353 if( pObjTab ) cnt++;
127354 aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
127355 if( aRoot==0 ) break;
127356 cnt = 0;
127357 if( pObjTab ) aRoot[++cnt] = 0;
127358 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127359 Table *pTab = sqliteHashData(x);
127360 Index *pIdx;
127361 if( pObjTab && pObjTab!=pTab ) continue;
127362 if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
127363 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
127364 aRoot[++cnt] = pIdx->tnum;
127365 }
127366 }
127367 aRoot[0] = cnt;
127368
127369 /* Make sure sufficient number of registers have been allocated */
127370 pParse->nMem = MAX( pParse->nMem, 8+mxIdx );
127371 sqlite3ClearTempRegCache(pParse);
127372
127373 /* Do the b-tree integrity checks */
127374 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
127375 sqlite3VdbeChangeP5(v, (u8)i);
127376 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
127377 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
127378 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
127379 P4_DYNAMIC);
127380 sqlite3VdbeAddOp3(v, OP_Concat, 2, 3, 3);
127382 sqlite3VdbeJumpHere(v, addr);
127383
127384 /* Make sure all the indices are constructed correctly.
127385 */
127386 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127387 Table *pTab = sqliteHashData(x);
127388 Index *pIdx, *pPk;
127389 Index *pPrior = 0;
127390 int loopTop;
127391 int iDataCur, iIdxCur;
127392 int r1 = -1;
127393
127394 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
127395 if( pObjTab && pObjTab!=pTab ) continue;
127396 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
127397 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
127398 1, 0, &iDataCur, &iIdxCur);
127399 /* reg[7] counts the number of entries in the table.
127400 ** reg[8+i] counts the number of entries in the i-th index
127401 */
127402 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
127403 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
127404 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
127405 }
127406 assert( pParse->nMem>=8+j );
127407 assert( sqlite3NoTempsInRange(pParse,1,7+j) );
127408 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
127409 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
127410 if( !isQuick ){
127411 /* Sanity check on record header decoding */
127412 sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3);
127414 }
127415 /* Verify that all NOT NULL columns really are NOT NULL */
127416 for(j=0; j<pTab->nCol; j++){
127417 char *zErr;
127418 int jmp2;
127419 if( j==pTab->iPKey ) continue;
127420 if( pTab->aCol[j].notNull==0 ) continue;
127421 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
127422 if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
127424 }
127425 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
127426 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
127427 pTab->aCol[j].zName);
127428 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
127430 sqlite3VdbeJumpHere(v, jmp2);
127431 }
127432 /* Verify CHECK constraints */
127433 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
127434 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
127435 if( db->mallocFailed==0 ){
127436 int addrCkFault = sqlite3VdbeMakeLabel(pParse);
127437 int addrCkOk = sqlite3VdbeMakeLabel(pParse);
127438 char *zErr;
127439 int k;
127440 pParse->iSelfTab = iDataCur + 1;
127441 for(k=pCheck->nExpr-1; k>0; k--){
127442 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
127443 }
127444 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
127446 sqlite3VdbeResolveLabel(v, addrCkFault);
127447 pParse->iSelfTab = 0;
127448 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
127449 pTab->zName);
127450 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
127452 sqlite3VdbeResolveLabel(v, addrCkOk);
127453 }
127454 sqlite3ExprListDelete(db, pCheck);
127455 }
127456 if( !isQuick ){ /* Omit the remaining tests for quick_check */
127457 /* Validate index entries for the current row */
127458 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
127459 int jmp2, jmp3, jmp4, jmp5;
127460 int ckUniq = sqlite3VdbeMakeLabel(pParse);
127461 if( pPk==pIdx ) continue;
127462 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
127463 pPrior, r1);
127464 pPrior = pIdx;
127465 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
127466 /* Verify that an index entry exists for the current table row */
127467 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
127468 pIdx->nColumn); VdbeCoverage(v);
127469 sqlite3VdbeLoadString(v, 3, "row ");
127470 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
127471 sqlite3VdbeLoadString(v, 4, " missing from index ");
127472 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
127473 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
127474 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
127475 jmp4 = integrityCheckResultRow(v);
127476 sqlite3VdbeJumpHere(v, jmp2);
127477 /* For UNIQUE indexes, verify that only one entry exists with the
127478 ** current key. The entry is unique if (1) any column is NULL
127479 ** or (2) the next entry has a different key */
127480 if( IsUniqueIndex(pIdx) ){
127481 int uniqOk = sqlite3VdbeMakeLabel(pParse);
127482 int jmp6;
127483 int kk;
127484 for(kk=0; kk<pIdx->nKeyCol; kk++){
127485 int iCol = pIdx->aiColumn[kk];
127486 assert( iCol!=XN_ROWID && iCol<pTab->nCol );
127487 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
127488 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
127489 VdbeCoverage(v);
127490 }
127491 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
127492 sqlite3VdbeGoto(v, uniqOk);
127493 sqlite3VdbeJumpHere(v, jmp6);
127494 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
127495 pIdx->nKeyCol); VdbeCoverage(v);
127496 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
127497 sqlite3VdbeGoto(v, jmp5);
127498 sqlite3VdbeResolveLabel(v, uniqOk);
127499 }
127500 sqlite3VdbeJumpHere(v, jmp4);
127501 sqlite3ResolvePartIdxLabel(pParse, jmp3);
127502 }
127503 }
127504 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
127505 sqlite3VdbeJumpHere(v, loopTop-1);
127506 if( !isQuick ){
127507 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
127508 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
127509 if( pPk==pIdx ) continue;
127510 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
127511 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
127513 sqlite3VdbeLoadString(v, 4, pIdx->zName);
127514 sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
127516 sqlite3VdbeJumpHere(v, addr);
127517 }
127518 }
127519 }
127520 }
127521 {
127522 static const int iLn = VDBE_OFFSET_LINENO(2);
127523 static const VdbeOpList endCode[] = {
127524 { OP_AddImm, 1, 0, 0}, /* 0 */
127525 { OP_IfNotZero, 1, 4, 0}, /* 1 */
127526 { OP_String8, 0, 3, 0}, /* 2 */
127527 { OP_ResultRow, 3, 1, 0}, /* 3 */
127528 { OP_Halt, 0, 0, 0}, /* 4 */
127529 { OP_String8, 0, 3, 0}, /* 5 */
127530 { OP_Goto, 0, 3, 0}, /* 6 */
127531 };
127532 VdbeOp *aOp;
127533
127534 aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
127535 if( aOp ){
127536 aOp[0].p2 = 1-mxErr;
127537 aOp[2].p4type = P4_STATIC;
127538 aOp[2].p4.z = "ok";
127539 aOp[5].p4type = P4_STATIC;
127540 aOp[5].p4.z = (char*)sqlite3ErrStr(SQLITE_CORRUPT);
127541 }
127543 }
127544 }
127545 break;
127546#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
127547
127548#ifndef SQLITE_OMIT_UTF16
127549 /*
127550 ** PRAGMA encoding
127551 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
127552 **
127553 ** In its first form, this pragma returns the encoding of the main
127554 ** database. If the database is not initialized, it is initialized now.
127555 **
127556 ** The second form of this pragma is a no-op if the main database file
127557 ** has not already been initialized. In this case it sets the default
127558 ** encoding that will be used for the main database file if a new file
127559 ** is created. If an existing main database file is opened, then the
127560 ** default text encoding for the existing database is used.
127561 **
127562 ** In all cases new databases created using the ATTACH command are
127563 ** created to use the same default text encoding as the main database. If
127564 ** the main database has not been initialized and/or created when ATTACH
127565 ** is executed, this is done before the ATTACH operation.
127566 **
127567 ** In the second form this pragma sets the text encoding to be used in
127568 ** new database files created using this database handle. It is only
127569 ** useful if invoked immediately after the main database i
127570 */
127571 case PragTyp_ENCODING: {
127572 static const struct EncName {
127573 char *zName;
127574 u8 enc;
127575 } encnames[] = {
127576 { "UTF8", SQLITE_UTF8 },
127577 { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
127578 { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
127579 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
127580 { "UTF16le", SQLITE_UTF16LE },
127581 { "UTF16be", SQLITE_UTF16BE },
127582 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
127583 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
127584 { 0, 0 }
127585 };
127586 const struct EncName *pEnc;
127587 if( !zRight ){ /* "PRAGMA encoding" */
127588 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
127589 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
127590 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
127591 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
127592 returnSingleText(v, encnames[ENC(pParse->db)].zName);
127593 }else{ /* "PRAGMA encoding = XXX" */
127594 /* Only change the value of sqlite.enc if the database handle is not
127595 ** initialized. If the main database exists, the new sqlite.enc value
127596 ** will be overwritten when the schema is next loaded. If it does not
127597 ** already exists, it will be created to use the new encoding value.
127598 */
127599 if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
127600 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
127601 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
127602 u8 enc = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
127603 SCHEMA_ENC(db) = enc;
127604 sqlite3SetTextEncoding(db, enc);
127605 break;
127606 }
127607 }
127608 if( !pEnc->zName ){
127609 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
127610 }
127611 }
127612 }
127613 }
127614 break;
127615#endif /* SQLITE_OMIT_UTF16 */
127616
127617#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
127618 /*
127619 ** PRAGMA [schema.]schema_version
127620 ** PRAGMA [schema.]schema_version = <integer>
127621 **
127622 ** PRAGMA [schema.]user_version
127623 ** PRAGMA [schema.]user_version = <integer>
127624 **
127625 ** PRAGMA [schema.]freelist_count
127626 **
127627 ** PRAGMA [schema.]data_version
127628 **
127629 ** PRAGMA [schema.]application_id
127630 ** PRAGMA [schema.]application_id = <integer>
127631 **
127632 ** The pragma's schema_version and user_version are used to set or get
127633 ** the value of the schema-version and user-version, respectively. Both
127634 ** the schema-version and the user-version are 32-bit signed integers
127635 ** stored in the database header.
127636 **
127637 ** The schema-cookie is usually only manipulated internally by SQLite. It
127638 ** is incremented by SQLite whenever the database schema is modified (by
127639 ** creating or dropping a table or index). The schema version is used by
127640 ** SQLite each time a query is executed to ensure that the internal cache
127641 ** of the schema used when compiling the SQL query matches the schema of
127642 ** the database against which the compiled query is actually executed.
127643 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
127644 ** the schema-version is potentially dangerous and may lead to program
127645 ** crashes or database corruption. Use with caution!
127646 **
127647 ** The user-version is not used internally by SQLite. It may be used by
127648 ** applications for any purpose.
127649 */
127650 case PragTyp_HEADER_VALUE: {
127651 int iCookie = pPragma->iArg; /* Which cookie to read or write */
127652 sqlite3VdbeUsesBtree(v, iDb);
127653 if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
127654 /* Write the specified cookie value */
127655 static const VdbeOpList setCookie[] = {
127656 { OP_Transaction, 0, 1, 0}, /* 0 */
127657 { OP_SetCookie, 0, 0, 0}, /* 1 */
127658 };
127659 VdbeOp *aOp;
127661 aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
127662 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
127663 aOp[0].p1 = iDb;
127664 aOp[1].p1 = iDb;
127665 aOp[1].p2 = iCookie;
127666 aOp[1].p3 = sqlite3Atoi(zRight);
127667 aOp[1].p5 = 1;
127668 }else{
127669 /* Read the specified cookie value */
127670 static const VdbeOpList readCookie[] = {
127671 { OP_Transaction, 0, 0, 0}, /* 0 */
127672 { OP_ReadCookie, 0, 1, 0}, /* 1 */
127673 { OP_ResultRow, 1, 1, 0}
127674 };
127675 VdbeOp *aOp;
127677 aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
127678 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
127679 aOp[0].p1 = iDb;
127680 aOp[1].p1 = iDb;
127681 aOp[1].p3 = iCookie;
127683 }
127684 }
127685 break;
127686#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
127687
127688#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
127689 /*
127690 ** PRAGMA compile_options
127691 **
127692 ** Return the names of all compile-time options used in this build,
127693 ** one option per row.
127694 */
127696 int i = 0;
127697 const char *zOpt;
127698 pParse->nMem = 1;
127699 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
127700 sqlite3VdbeLoadString(v, 1, zOpt);
127702 }
127704 }
127705 break;
127706#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
127707
127708#ifndef SQLITE_OMIT_WAL
127709 /*
127710 ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
127711 **
127712 ** Checkpoint the database.
127713 */
127714 case PragTyp_WAL_CHECKPOINT: {
127715 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
127716 int eMode = SQLITE_CHECKPOINT_PASSIVE;
127717 if( zRight ){
127718 if( sqlite3StrICmp(zRight, "full")==0 ){
127719 eMode = SQLITE_CHECKPOINT_FULL;
127720 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
127722 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
127724 }
127725 }
127726 pParse->nMem = 3;
127727 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
127729 }
127730 break;
127731
127732 /*
127733 ** PRAGMA wal_autocheckpoint
127734 ** PRAGMA wal_autocheckpoint = N
127735 **
127736 ** Configure a database connection to automatically checkpoint a database
127737 ** after accumulating N frames in the log. Or query for the current value
127738 ** of N.
127739 */
127741 if( zRight ){
127743 }
127744 returnSingleInt(v,
127746 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
127747 }
127748 break;
127749#endif
127750
127751 /*
127752 ** PRAGMA shrink_memory
127753 **
127754 ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
127755 ** connection on which it is invoked to free up as much memory as it
127756 ** can, by calling sqlite3_db_release_memory().
127757 */
127758 case PragTyp_SHRINK_MEMORY: {
127760 break;
127761 }
127762
127763 /*
127764 ** PRAGMA optimize
127765 ** PRAGMA optimize(MASK)
127766 ** PRAGMA schema.optimize
127767 ** PRAGMA schema.optimize(MASK)
127768 **
127769 ** Attempt to optimize the database. All schemas are optimized in the first
127770 ** two forms, and only the specified schema is optimized in the latter two.
127771 **
127772 ** The details of optimizations performed by this pragma are expected
127773 ** to change and improve over time. Applications should anticipate that
127774 ** this pragma will perform new optimizations in future releases.
127775 **
127776 ** The optional argument is a bitmask of optimizations to perform:
127777 **
127778 ** 0x0001 Debugging mode. Do not actually perform any optimizations
127779 ** but instead return one line of text for each optimization
127780 ** that would have been done. Off by default.
127781 **
127782 ** 0x0002 Run ANALYZE on tables that might benefit. On by default.
127783 ** See below for additional information.
127784 **
127785 ** 0x0004 (Not yet implemented) Record usage and performance
127786 ** information from the current session in the
127787 ** database file so that it will be available to "optimize"
127788 ** pragmas run by future database connections.
127789 **
127790 ** 0x0008 (Not yet implemented) Create indexes that might have
127791 ** been helpful to recent queries
127792 **
127793 ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
127794 ** of the optimizations listed above except Debug Mode, including new
127795 ** optimizations that have not yet been invented. If new optimizations are
127796 ** ever added that should be off by default, those off-by-default
127797 ** optimizations will have bitmasks of 0x10000 or larger.
127798 **
127799 ** DETERMINATION OF WHEN TO RUN ANALYZE
127800 **
127801 ** In the current implementation, a table is analyzed if only if all of
127802 ** the following are true:
127803 **
127804 ** (1) MASK bit 0x02 is set.
127805 **
127806 ** (2) The query planner used sqlite_stat1-style statistics for one or
127807 ** more indexes of the table at some point during the lifetime of
127808 ** the current connection.
127809 **
127810 ** (3) One or more indexes of the table are currently unanalyzed OR
127811 ** the number of rows in the table has increased by 25 times or more
127812 ** since the last time ANALYZE was run.
127813 **
127814 ** The rules for when tables are analyzed are likely to change in
127815 ** future releases.
127816 */
127817 case PragTyp_OPTIMIZE: {
127818 int iDbLast; /* Loop termination point for the schema loop */
127819 int iTabCur; /* Cursor for a table whose size needs checking */
127820 HashElem *k; /* Loop over tables of a schema */
127821 Schema *pSchema; /* The current schema */
127822 Table *pTab; /* A table in the schema */
127823 Index *pIdx; /* An index of the table */
127824 LogEst szThreshold; /* Size threshold above which reanalysis is needd */
127825 char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
127826 u32 opMask; /* Mask of operations to perform */
127827
127828 if( zRight ){
127829 opMask = (u32)sqlite3Atoi(zRight);
127830 if( (opMask & 0x02)==0 ) break;
127831 }else{
127832 opMask = 0xfffe;
127833 }
127834 iTabCur = pParse->nTab++;
127835 for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
127836 if( iDb==1 ) continue;
127837 sqlite3CodeVerifySchema(pParse, iDb);
127838 pSchema = db->aDb[iDb].pSchema;
127839 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
127840 pTab = (Table*)sqliteHashData(k);
127841
127842 /* If table pTab has not been used in a way that would benefit from
127843 ** having analysis statistics during the current session, then skip it.
127844 ** This also has the effect of skipping virtual tables and views */
127845 if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue;
127846
127847 /* Reanalyze if the table is 25 times larger than the last analysis */
127848 szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 );
127849 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
127850 if( !pIdx->hasStat1 ){
127851 szThreshold = 0; /* Always analyze if any index lacks statistics */
127852 break;
127853 }
127854 }
127855 if( szThreshold ){
127856 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
127857 sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
127858 sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
127859 VdbeCoverage(v);
127860 }
127861 zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
127862 db->aDb[iDb].zDbSName, pTab->zName);
127863 if( opMask & 0x01 ){
127864 int r1 = sqlite3GetTempReg(pParse);
127865 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
127866 sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
127867 }else{
127868 sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
127869 }
127870 }
127871 }
127873 break;
127874 }
127875
127876 /*
127877 ** PRAGMA busy_timeout
127878 ** PRAGMA busy_timeout = N
127879 **
127880 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
127881 ** if one is set. If no busy handler or a different busy handler is set
127882 ** then 0 is returned. Setting the busy_timeout to 0 or negative
127883 ** disables the timeout.
127884 */
127885 /*case PragTyp_BUSY_TIMEOUT*/ default: {
127886 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
127887 if( zRight ){
127888 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
127889 }
127891 break;
127892 }
127893
127894 /*
127895 ** PRAGMA soft_heap_limit
127896 ** PRAGMA soft_heap_limit = N
127897 **
127898 ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
127899 ** sqlite3_soft_heap_limit64() interface with the argument N, if N is
127900 ** specified and is a non-negative integer.
127901 ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
127902 ** returns the same integer that would be returned by the
127903 ** sqlite3_soft_heap_limit64(-1) C-language function.
127904 */
127906 sqlite3_int64 N;
127907 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
127909 }
127911 break;
127912 }
127913
127914 /*
127915 ** PRAGMA hard_heap_limit
127916 ** PRAGMA hard_heap_limit = N
127917 **
127918 ** Invoke sqlite3_hard_heap_limit64() to query or set the hard heap
127919 ** limit. The hard heap limit can be activated or lowered by this
127920 ** pragma, but not raised or deactivated. Only the
127921 ** sqlite3_hard_heap_limit64() C-language API can raise or deactivate
127922 ** the hard heap limit. This allows an application to set a heap limit
127923 ** constraint that cannot be relaxed by an untrusted SQL script.
127924 */
127926 sqlite3_int64 N;
127927 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
127929 if( N>0 && (iPrior==0 || iPrior>N) ) sqlite3_hard_heap_limit64(N);
127930 }
127932 break;
127933 }
127934
127935 /*
127936 ** PRAGMA threads
127937 ** PRAGMA threads = N
127938 **
127939 ** Configure the maximum number of worker threads. Return the new
127940 ** maximum, which might be less than requested.
127941 */
127942 case PragTyp_THREADS: {
127943 sqlite3_int64 N;
127944 if( zRight
127945 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
127946 && N>=0
127947 ){
127948 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
127949 }
127951 break;
127952 }
127953
127954 /*
127955 ** PRAGMA analysis_limit
127956 ** PRAGMA analysis_limit = N
127957 **
127958 ** Configure the maximum number of rows that ANALYZE will examine
127959 ** in each index that it looks at. Return the new limit.
127960 */
127961 case PragTyp_ANALYSIS_LIMIT: {
127962 sqlite3_int64 N;
127963 if( zRight
127964 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
127965 && N>=0
127966 ){
127967 db->nAnalysisLimit = (int)(N&0x7fffffff);
127968 }
127970 break;
127971 }
127972
127973#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
127974 /*
127975 ** Report the current state of file logs for all databases
127976 */
127977 case PragTyp_LOCK_STATUS: {
127978 static const char *const azLockName[] = {
127979 "unlocked", "shared", "reserved", "pending", "exclusive"
127980 };
127981 int i;
127982 pParse->nMem = 2;
127983 for(i=0; i<db->nDb; i++){
127984 Btree *pBt;
127985 const char *zState = "unknown";
127986 int j;
127987 if( db->aDb[i].zDbSName==0 ) continue;
127988 pBt = db->aDb[i].pBt;
127989 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
127990 zState = "closed";
127991 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
127993 zState = azLockName[j];
127994 }
127995 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
127996 }
127997 break;
127998 }
127999#endif
128000
128001#if defined(SQLITE_ENABLE_CEROD)
128002 case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){
128003 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
128004 sqlite3_activate_cerod(&zRight[6]);
128005 }
128006 }
128007 break;
128008#endif
128009
128010 } /* End of the PRAGMA switch */
128011
128012 /* The following block is a no-op unless SQLITE_DEBUG is defined. Its only
128013 ** purpose is to execute assert() statements to verify that if the
128014 ** PragFlg_NoColumns1 flag is set and the caller specified an argument
128015 ** to the PRAGMA, the implementation has not added any OP_ResultRow
128016 ** instructions to the VM. */
128017 if( (pPragma->mPragFlg & PragFlg_NoColumns1) && zRight ){
#define PAGER_JOURNALMODE_QUERY
Definition sqlite3.c:14827
#define PragTyp_TABLE_INFO
Definition sqlite3.c:125164
#define PragTyp_JOURNAL_MODE
Definition sqlite3.c:125150
#define PragTyp_MMAP_SIZE
Definition sqlite3.c:125155
static void returnSingleInt(Vdbe *v, i64 value)
Definition sqlite3.c:125926
#define OP_String8
Definition sqlite3.c:15681
#define PragTyp_SECURE_DELETE
Definition sqlite3.c:125160
SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe *)
Definition sqlite3.c:78325
SQLITE_API int sqlite3_limit(sqlite3 *, int id, int newVal)
Definition sqlite3.c:163728
#define PragTyp_TEMP_STORE
Definition sqlite3.c:125165
#define SQLITE_TEMP_STORE
Definition sqlite3.c:14199
#define PragTyp_SYNCHRONOUS
Definition sqlite3.c:125163
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe *)
Definition sqlite3.c:78318
#define PragTyp_ENCODING
Definition sqlite3.c:125141
#define PragFlg_ReadOnly
Definition sqlite3.c:125177
#define OP_IncrVacuum
Definition sqlite3.c:15626
static void returnSingleText(Vdbe *v, const char *zValue)
Definition sqlite3.c:125934
#define PragFlg_NeedSchema
Definition sqlite3.c:125174
#define PragTyp_LOCK_STATUS
Definition sqlite3.c:125170
#define PragTyp_PAGE_COUNT
Definition sqlite3.c:125154
#define PragTyp_SOFT_HEAP_LIMIT
Definition sqlite3.c:125162
static void setAllPagerFlags(sqlite3 *db)
Definition sqlite3.c:125950
SQLITE_API const char * sqlite3_compileoption_get(int N)
Definition sqlite3.c:165586
SQLITE_API int sqlite3_file_control(sqlite3 *, const char *zDbName, int op, void *)
Definition sqlite3.c:164781
#define PragTyp_CACHE_SIZE
Definition sqlite3.c:125133
#define SQLITE_PRAGMA
Definition sqlite3.c:4138
static const PragmaName * pragmaLocate(const char *zName)
Definition sqlite3.c:126020
#define sqlite3VdbeVerifyNoMallocRequired(A, B)
Definition sqlite3.c:15817
#define PragTyp_CASE_SENSITIVE_LIKE
Definition sqlite3.c:125135
#define SQLITE_SET_LOCKPROXYFILE
Definition sqlite3.c:2220
#define sqlite3VdbeVerifyNoResultRow(A)
Definition sqlite3.c:15818
#define OP_Pagecount
Definition sqlite3.c:15734
#define SQLITE_FCNTL_MMAP_SIZE
Definition sqlite3.c:2195
#define PragFlg_NoColumns
Definition sqlite3.c:125175
static int getAutoVacuum(const char *z)
Definition sqlite3.c:125836
#define PragTyp_ACTIVATE_EXTENSIONS
Definition sqlite3.c:125127
#define PragTyp_HEADER_VALUE
Definition sqlite3.c:125129
SQLITE_PRIVATE int sqlite3BtreeSetSpillSize(Btree *, int)
Definition sqlite3.c:67267
static void setPragmaResultColumnNames(Vdbe *v, const PragmaName *pPragma)
Definition sqlite3.c:125907
#define PragTyp_FUNCTION_LIST
Definition sqlite3.c:125144
#define PragTyp_DATABASE_LIST
Definition sqlite3.c:125139
#define PragTyp_CACHE_SPILL
Definition sqlite3.c:125134
#define PragTyp_OPTIMIZE
Definition sqlite3.c:125157
#define PragTyp_LOCKING_MODE
Definition sqlite3.c:125153
static int getLockingMode(const char *z)
Definition sqlite3.c:125821
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int)
Definition sqlite3.c:67458
#define ONLY_IF_REALLOC_STRESS(X)
Definition sqlite3.c:13787
#define PragTyp_INTEGRITY_CHECK
Definition sqlite3.c:125149
#define OP_IfSmaller
Definition sqlite3.c:15600
static int invalidateTempStorage(Parse *pParse)
Definition sqlite3.c:125870
#define SQLITE_GET_LOCKPROXYFILE
Definition sqlite3.c:2219
#define PragFlg_NoColumns1
Definition sqlite3.c:125176
#define OP_IdxGT
Definition sqlite3.c:15605
#define PragTyp_TEMP_STORE_DIRECTORY
Definition sqlite3.c:125166
#define SQLITE_FUNC_HASH_SZ
Definition sqlite3.c:16759
#define OP_MaxPgcnt
Definition sqlite3.c:15735
static const char * actionName(u8 action)
Definition sqlite3.c:125978
SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64)
Definition sqlite3.c:59059
#define PragTyp_THREADS
Definition sqlite3.c:125167
#define PragTyp_COMPILE_OPTIONS
Definition sqlite3.c:125137
SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *, int)
Definition sqlite3.c:118876
#define PragTyp_INCREMENTAL_VACUUM
Definition sqlite3.c:125146
SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N)
Definition sqlite3.c:27449
#define PragTyp_WAL_CHECKPOINT
Definition sqlite3.c:125169
#define PragTyp_INDEX_LIST
Definition sqlite3.c:125148
#define PragTyp_MODULE_LIST
Definition sqlite3.c:125156
#define PragTyp_ANALYSIS_LIMIT
Definition sqlite3.c:125128
#define PragTyp_FOREIGN_KEY_LIST
Definition sqlite3.c:125143
#define PragTyp_FLAG
Definition sqlite3.c:125131
SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, u8)
Definition sqlite3.c:125808
SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N)
Definition sqlite3.c:27407
#define PragTyp_WAL_AUTOCHECKPOINT
Definition sqlite3.c:125168
#define OP_IntegrityCk
Definition sqlite3.c:15712
#define PragTyp_BUSY_TIMEOUT
Definition sqlite3.c:125132
#define PragTyp_DATA_STORE_DIRECTORY
Definition sqlite3.c:125138
static int changeTempStorage(Parse *pParse, const char *zStorageType)
Definition sqlite3.c:125892
#define PragTyp_COLLATION_LIST
Definition sqlite3.c:125136
SQLITE_PRIVATE const char * sqlite3JournalModename(int)
Definition sqlite3.c:125998
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *)
Definition sqlite3.c:67482
#define TF_StatsUsed
Definition sqlite3.c:17544
#define SQLITE_INTEGRITY_CHECK_ERROR_MAX
#define PragTyp_HARD_HEAP_LIMIT
Definition sqlite3.c:125145
#define PragTyp_PAGE_SIZE
Definition sqlite3.c:125158
SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse *, int)
Definition sqlite3.c:117037
#define PragTyp_FOREIGN_KEY_CHECK
Definition sqlite3.c:125142
#define PragTyp_AUTO_VACUUM
Definition sqlite3.c:125130
#define SQLITE_ACCESS_READWRITE
Definition sqlite3.c:2477
#define COLFLAG_HIDDEN
Definition sqlite3.c:17345
#define OP_SqlExec
Definition sqlite3.c:15706
#define PragTyp_LOCK_PROXY_FILE
Definition sqlite3.c:125152
#define PragTyp_JOURNAL_SIZE_LIMIT
Definition sqlite3.c:125151
#define SQLITE_FCNTL_LOCKSTATE
Definition sqlite3.c:2179
#define PragTyp_INDEX_INFO
Definition sqlite3.c:125147
#define PragTyp_DEFAULT_CACHE_SIZE
Definition sqlite3.c:125140
SQLITE_PRIVATE void sqlite3ClearTempRegCache(Parse *)
Definition sqlite3.c:105764
#define PragTyp_SHRINK_MEMORY
Definition sqlite3.c:125161
#define PragTyp_STATS
Definition sqlite3.c:125171
#define PragTyp_PRAGMA_LIST
Definition sqlite3.c:125159
SQLITE_API int sqlite3_db_release_memory(sqlite3 *)
Definition sqlite3.c:161857
static u8 getSafetyLevel(const char *z, int omitFull, u8 dflt)
Definition sqlite3.c:125783
SQLITE_API int sqlite3_busy_timeout(sqlite3 *, int ms)
Definition sqlite3.c:162731
#define SQLITE_FCNTL_PRAGMA
Definition sqlite3.c:2192
static void pragmaFunclistLine(Vdbe *v, FuncDef *p, int isBuiltin, int showInternFuncs)
Definition sqlite3.c:126041
SQLITE_PRIVATE const char * sqlite3BtreeGetFilename(Btree *)
Definition sqlite3.c:74771
u8 bSyncSet
Definition sqlite3.c:16609
int busyTimeout
Definition sqlite3.c:16929

References ExprList::a, FuncDefHash::a, FKey::aAction, Table::aCol, FKey::aCol, sqlite3::aCollSeq, actionName(), sqlite3::aDb, sqlite3::aFunc, Index::aiColumn, Index::aiRowLogEst, ALWAYS, sqlite3::aModule, aPragmaName, ArraySize, Index::aSortOrder, sqlite3::autoCommit, Index::azColl, Db::bSyncSet, BTREE_DEFAULT_CACHE_SIZE, BTREE_INCR_VACUUM, BTREE_LARGEST_ROOT_PAGE, sqlite3::busyHandler, sqlite3::busyTimeout, Schema::cache_size, changeTempStorage(), COLFLAG_HIDDEN, COLFLAG_NOINSERT, COLFLAG_PRIMKEY, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, COLNAME_NAME, Parse::db, DBFLAG_EncodingFixed, DBFLAG_InternalFunc, sqlite3::dfltLockMode, ENC, PragmaName::ePragTyp, sqlite3::flags, getAutoVacuum(), getLockingMode(), getSafetyLevel(), HasRowid, Index::hasStat1, PragmaName::iArg, Index::idxType, FKey::sColMap::iFrom, integrityCheckResultRow(), invalidateTempStorage(), Table::iPKey, Parse::iSelfTab, IsUniqueIndex, LOCATE_NOERR, sqlite3::mallocFailed, mask, MAX, sqlite3::mDbFlags, PragmaName::mPragFlg, Token::n, sqlite3::nAnalysisLimit, BusyHandler::nBusy, Table::nCol, FKey::nCol, Index::nColumn, sqlite3::nDb, sqlite3::nDeferredImmCons, Parse::nErr, ExprList::nExpr, sqlite3::nextAutovac, sqlite3::nextPagesize, Index::nKeyCol, Parse::nMem, Table::nNVCol, Column::notNull, PragmaName::nPragCName, Table::nRowLogEst, Parse::nTab, NULL, OE_Abort, OMIT_TEMPDB, ONLY_IF_REALLOC_STRESS, Expr::op, OP_AddImm, OP_Checkpoint, OP_Column, OP_Concat, OP_Count, OP_Eq, OP_Expire, OP_Found, OP_Goto, OP_Halt, OP_IdxGT, OP_If, OP_IfNotZero, OP_IfPos, OP_IfSmaller, OP_IncrVacuum, OP_Integer, OP_IntegrityCk, OP_IsNull, OP_JournalMode, OP_MakeRecord, OP_MaxPgcnt, OP_Next, OP_Noop, OP_NotNull, OP_Null, OP_OpenRead, OP_Pagecount, OP_ReadCookie, OP_ResultRow, OP_Rewind, OP_Rowid, OP_SeekRowid, OP_SetCookie, OP_SqlExec, OP_String8, OP_Subtract, OP_Transaction, OPFLAG_TYPEOFARG, VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, VdbeOp::p4, P4_DYNAMIC, P4_INTARRAY, P4_STATIC, VdbeOp::p4type, VdbeOp::p5, PAGER_JOURNALMODE_OFF, PAGER_JOURNALMODE_QUERY, PAGER_LOCKINGMODE_EXCLUSIVE, PAGER_LOCKINGMODE_NORMAL, PAGER_LOCKINGMODE_QUERY, PAGER_SYNCHRONOUS_MASK, Db::pBt, Table::pCheck, Column::pDflt, ExprList::ExprList_item::pExpr, Table::pFKey, FuncDef::pHash, Table::pIndex, Index::pNext, FKey::pNextFrom, Index::pPartIdxWhere, PragFlg_NeedSchema, PragFlg_NoColumns, PragFlg_NoColumns1, PragFlg_ReadOnly, pragmaFunclistLine(), pragmaLocate(), PragTyp_ACTIVATE_EXTENSIONS, PragTyp_ANALYSIS_LIMIT, PragTyp_AUTO_VACUUM, PragTyp_BUSY_TIMEOUT, PragTyp_CACHE_SIZE, PragTyp_CACHE_SPILL, PragTyp_CASE_SENSITIVE_LIKE, PragTyp_COLLATION_LIST, PragTyp_COMPILE_OPTIONS, PragTyp_DATA_STORE_DIRECTORY, PragTyp_DATABASE_LIST, PragTyp_DEFAULT_CACHE_SIZE, PragTyp_ENCODING, PragTyp_FLAG, PragTyp_FOREIGN_KEY_CHECK, PragTyp_FOREIGN_KEY_LIST, PragTyp_FUNCTION_LIST, PragTyp_HARD_HEAP_LIMIT, PragTyp_HEADER_VALUE, PragTyp_INCREMENTAL_VACUUM, PragTyp_INDEX_INFO, PragTyp_INDEX_LIST, PragTyp_INTEGRITY_CHECK, PragTyp_JOURNAL_MODE, PragTyp_JOURNAL_SIZE_LIMIT, PragTyp_LOCK_PROXY_FILE, PragTyp_LOCK_STATUS, PragTyp_LOCKING_MODE, PragTyp_MMAP_SIZE, PragTyp_MODULE_LIST, PragTyp_OPTIMIZE, PragTyp_PAGE_COUNT, PragTyp_PAGE_SIZE, PragTyp_PRAGMA_LIST, PragTyp_SECURE_DELETE, PragTyp_SHRINK_MEMORY, PragTyp_SOFT_HEAP_LIMIT, PragTyp_STATS, PragTyp_SYNCHRONOUS, PragTyp_TABLE_INFO, PragTyp_TEMP_STORE, PragTyp_TEMP_STORE_DIRECTORY, PragTyp_THREADS, PragTyp_WAL_AUTOCHECKPOINT, PragTyp_WAL_CHECKPOINT, Db::pSchema, Table::pSchema, Index::pSchema, Index::pTable, sqlite3::pVfs, sqlite3::pWalArg, Parse::rc, returnSingleInt(), returnSingleText(), Db::safety_level, SCHEMA_ENC, setAllPagerFlags(), setPragmaResultColumnNames(), sqlite3_busy_timeout(), sqlite3_compileoption_get(), sqlite3_data_directory, sqlite3_db_release_memory(), sqlite3_file_control(), sqlite3_free(), sqlite3_hard_heap_limit64(), sqlite3_limit(), sqlite3_mprintf(), sqlite3_soft_heap_limit64(), sqlite3_stricmp(), sqlite3_temp_directory, sqlite3_wal_autocheckpoint(), sqlite3AbsInt32(), sqlite3Atoi(), sqlite3AuthCheck(), sqlite3BeginWriteOperation(), sqlite3BtreeGetAutoVacuum(), sqlite3BtreeGetFilename(), sqlite3BtreeGetPageSize(), sqlite3BtreePager(), sqlite3BtreeSecureDelete(), sqlite3BtreeSetAutoVacuum(), sqlite3BtreeSetCacheSize(), sqlite3BtreeSetPageSize(), sqlite3BtreeSetSpillSize(), sqlite3BuiltinFunctions, sqlite3ClearTempRegCache(), sqlite3CodeVerifyNamedSchema(), sqlite3CodeVerifySchema(), sqlite3ColumnType(), sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3DecOrHexToI64(), sqlite3ErrorMsg(), sqlite3ErrStr(), sqlite3ExprCodeGetColumnOfTable(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3ExprListDelete(), sqlite3ExprListDup(), sqlite3FindIndex(), sqlite3FindTable(), sqlite3FkLocateIndex(), sqlite3GenerateIndexKey(), sqlite3GetBoolean(), sqlite3GetInt32(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3GlobalConfig, sqlite3IndexAffinityStr(), sqlite3JournalModename(), sqlite3LocateTable(), sqlite3LogEst(), sqlite3MPrintf(), sqlite3NameFromToken(), sqlite3OomFault(), sqlite3OpenTable(), sqlite3OpenTableAndIndices(), sqlite3OpenTempDatabase(), sqlite3OsAccess(), sqlite3OsFileControl(), sqlite3OsFileControlHint(), sqlite3PagerFile(), sqlite3PagerJournalSizeLimit(), sqlite3PagerLockingMode(), sqlite3PrimaryKeyIndex(), sqlite3ReadSchema(), sqlite3RegisterLikeFunctions(), sqlite3ResolvePartIdxLabel(), sqlite3SchemaToIndex(), sqlite3SetTextEncoding(), sqlite3StrICmp(), sqlite3Strlen30(), sqlite3StrNICmp, sqlite3TableLock(), sqlite3Tolower, sqlite3TwoPartName(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAddOpList(), sqlite3VdbeChangeP3(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetOp(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeLoadString(), sqlite3VdbeMakeLabel(), sqlite3VdbeMultiLoad(), sqlite3VdbeResolveLabel(), sqlite3VdbeReusable(), sqlite3VdbeRunOnlyOnce(), sqlite3VdbeSetColName(), sqlite3VdbeSetNumCols(), sqlite3VdbeSetP4KeyInfo(), sqlite3VdbeUsesBtree(), sqlite3VdbeVerifyNoMallocRequired, sqlite3VdbeVerifyNoResultRow, sqlite3ViewGetColumnNames(), sqlite3WalDefaultHook(), SQLITE_ACCESS_READWRITE, SQLITE_CacheSpill, SQLITE_CHECKPOINT_FULL, SQLITE_CHECKPOINT_PASSIVE, SQLITE_CHECKPOINT_RESTART, SQLITE_CHECKPOINT_TRUNCATE, SQLITE_CORRUPT, SQLITE_DEFAULT_CACHE_SIZE, SQLITE_Defensive, SQLITE_DeferFKs, SQLITE_FCNTL_LOCKSTATE, SQLITE_FCNTL_MMAP_SIZE, SQLITE_FCNTL_PRAGMA, SQLITE_ForeignKeys, SQLITE_FUNC_HASH_SZ, SQLITE_GET_LOCKPROXYFILE, SQLITE_IgnoreChecks, SQLITE_INTEGRITY_CHECK_ERROR_MAX, SQLITE_JUMPIFNULL, SQLITE_LIMIT_WORKER_THREADS, SQLITE_MAX_ATTACHED, SQLITE_NOMEM, SQLITE_NOTFOUND, SQLITE_NOTNULL, SQLITE_OK, SQLITE_PRAGMA, SQLITE_PTR_TO_INT, SQLITE_SET_LOCKPROXYFILE, SQLITE_TEMP_STORE, SQLITE_TRANSIENT, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF16NATIVE, SQLITE_UTF8, SQLITE_WriteSchema, sqliteHashData, sqliteHashFirst, sqliteHashNext, Index::szIdxRow, sqlite3::szMmap, Table::szTabRow, Table::tabFlags, Schema::tblHash, sqlite3::temp_store, TF_StatsUsed, TK_SPAN, Table::tnum, Index::tnum, FuncDef::u, Expr::u, VDBE_OFFSET_LINENO, VdbeCoverage, XN_ROWID, sqlite3::xWalCallback, VdbeOp::p4union::z, Token::z, FKey::sColMap::zCol, Db::zDbSName, Module::zName, Column::zName, CollSeq::zName, Table::zName, Index::zName, zName, FKey::zTo, and Expr::zToken.

Referenced by yy_reduce().

◆ sqlite3PragmaVtabRegister()

SQLITE_PRIVATE Module * sqlite3PragmaVtabRegister ( sqlite3 * db,
const char * zName )

◆ sqlite3Prepare()

static int sqlite3Prepare ( sqlite3 * db,
const char * zSql,
int nBytes,
u32 prepFlags,
Vdbe * pReprepare,
sqlite3_stmt ** ppStmt,
const char ** pzTail )
static

Definition at line 128912 of file sqlite3.c.

128926 {
128927 char *zErrMsg = 0; /* Error message */
128928 int rc = SQLITE_OK; /* Result code */
128929 int i; /* Loop counter */
128930 Parse sParse; /* Parsing context */
128931
128932 memset(&sParse, 0, PARSE_HDR_SZ);
128933 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
128934 sParse.pReprepare = pReprepare;
128935 assert( ppStmt && *ppStmt==0 );
128936 /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
128937 assert( sqlite3_mutex_held(db->mutex) );
128938
128939 /* For a long-term use prepared statement avoid the use of
128940 ** lookaside memory.
128941 */
128942 if( prepFlags & SQLITE_PREPARE_PERSISTENT ){
128943 sParse.disableLookaside++;
128945 }
128946 sParse.disableVtab = (prepFlags & SQLITE_PREPARE_NO_VTAB)!=0;
128947
128948 /* Check to verify that it is possible to get a read lock on all
128949 ** database schemas. The inability to get a read lock indicates that
128950 ** some other database connection is holding a write-lock, which in
128951 ** turn means that the other connection has made uncommitted changes
128952 ** to the schema.
128953 **
128954 ** Were we to proceed and prepare the statement against the uncommitted
128955 ** schema changes and if those schema changes are subsequently rolled
128956 ** back and different changes are made in their place, then when this
128957 ** prepared statement goes to run the schema cookie would fail to detect
128958 ** the schema change. Disaster would follow.
128959 **
128960 ** This thread is currently holding mutexes on all Btrees (because
128961 ** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
128962 ** is not possible for another thread to start a new schema change
128963 ** while this routine is running. Hence, we do not need to hold
128964 ** locks on the schema, we just need to make sure nobody else is
128965 ** holding them.
128966 **
128967 ** Note that setting READ_UNCOMMITTED overrides most lock detection,
128968 ** but it does *not* override schema lock detection, so this all still
128969 ** works even if READ_UNCOMMITTED is set.
128970 */
128971 if( !db->noSharedCache ){
128972 for(i=0; i<db->nDb; i++) {
128973 Btree *pBt = db->aDb[i].pBt;
128974 if( pBt ){
128975 assert( sqlite3BtreeHoldsMutex(pBt) );
128976 rc = sqlite3BtreeSchemaLocked(pBt);
128977 if( rc ){
128978 const char *zDb = db->aDb[i].zDbSName;
128979 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
128981 goto end_prepare;
128982 }
128983 }
128984 }
128985 }
128986
128988
128989 sParse.db = db;
128990 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
128991 char *zSqlCopy;
128992 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
128993 testcase( nBytes==mxLen );
128994 testcase( nBytes==mxLen+1 );
128995 if( nBytes>mxLen ){
128996 sqlite3ErrorWithMsg(db, SQLITE_TOOBIG, "statement too long");
128997 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
128998 goto end_prepare;
128999 }
129000 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
129001 if( zSqlCopy ){
129002 sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg);
129003 sParse.zTail = &zSql[sParse.zTail-zSqlCopy];
129004 sqlite3DbFree(db, zSqlCopy);
129005 }else{
129006 sParse.zTail = &zSql[nBytes];
129007 }
129008 }else{
129009 sqlite3RunParser(&sParse, zSql, &zErrMsg);
129010 }
129011 assert( 0==sParse.nQueryLoop );
129012
129013 if( sParse.rc==SQLITE_DONE ){
129014 sParse.rc = SQLITE_OK;
129015 }
129016 if( sParse.checkSchema ){
129017 schemaIsValid(&sParse);
129018 }
129019 if( pzTail ){
129020 *pzTail = sParse.zTail;
129021 }
129022
129023 if( db->init.busy==0 ){
129024 sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags);
129025 }
129026 if( db->mallocFailed ){
129027 sParse.rc = SQLITE_NOMEM_BKPT;
129028 }
129029 rc = sParse.rc;
129030 if( rc!=SQLITE_OK ){
129031 if( sParse.pVdbe ) sqlite3VdbeFinalize(sParse.pVdbe);
129032 assert(!(*ppStmt));
129033 }else{
129034 *ppStmt = (sqlite3_stmt*)sParse.pVdbe;
129035 }
129036
129037 if( zErrMsg ){
129038 sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg);
129039 sqlite3DbFree(db, zErrMsg);
129040 }else{
129041 sqlite3Error(db, rc);
129042 }
129043
129044 /* Delete any TriggerPrg structures allocated while parsing this statement. */
129045 while( sParse.pTriggerPrg ){
129046 TriggerPrg *pT = sParse.pTriggerPrg;
129047 sParse.pTriggerPrg = pT->pNext;
129048 sqlite3DbFree(db, pT);
129049 }
#define SQLITE_PREPARE_PERSISTENT
Definition sqlite3.c:4992
#define SQLITE_PREPARE_NO_VTAB
Definition sqlite3.c:4994
#define PARSE_HDR_SZ
Definition sqlite3.c:18789
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree)
Definition sqlite3.c:74873
static void schemaIsValid(Parse *pParse)
Definition sqlite3.c:128803
SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *, const char *z, int n, u8)
Definition sqlite3.c:77802
const char * zTail
Definition sqlite3.c:18761
u8 disableLookaside
Definition sqlite3.c:18692

Referenced by sqlite3InitCallback().

◆ sqlite3Prepare16()

static int sqlite3Prepare16 ( sqlite3 * db,
const void * zSql,
int nBytes,
u32 prepFlags,
sqlite3_stmt ** ppStmt,
const void ** pzTail )
static

Definition at line 129192 of file sqlite3.c.

129205 {
129206 /* This function currently works by first transforming the UTF-16
129207 ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
129208 ** tricky bit is figuring out the pointer to return in *pzTail.
129209 */
129210 char *zSql8;
129211 const char *zTail8 = 0;
129212 int rc = SQLITE_OK;
129213
129214#ifdef SQLITE_ENABLE_API_ARMOR
129215 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
129216#endif
129217 *ppStmt = 0;
129218 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
129219 return SQLITE_MISUSE_BKPT;
129220 }
129221 if( nBytes>=0 ){
129222 int sz;
129223 const char *z = (const char*)zSql;
129224 for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
129225 nBytes = sz;
129226 }
129228 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
129229 if( zSql8 ){
129230 rc = sqlite3LockAndPrepare(db, zSql8, -1, prepFlags, 0, ppStmt, &zTail8);
129231 }
129232
129233 if( zTail8 && pzTail ){
129234 /* If sqlite3_prepare returns a tail pointer, we calculate the
129235 ** equivalent pointer into the UTF-16 string by counting the unicode
129236 ** characters between zSql8 and zTail8, and then returning a pointer
129237 ** the same number of characters into the UTF-16 string.
129238 */
129239 int chars_parsed = sqlite3Utf8CharLen(zSql8, (int)(zTail8-zSql8));
129240 *pzTail = (u8 *)zSql + sqlite3Utf16ByteLen(zSql, chars_parsed);
SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar)
Definition sqlite3.c:31132

References sqlite3::mutex, sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3ApiExit(), sqlite3DbFree(), sqlite3LockAndPrepare(), sqlite3SafetyCheckOk(), sqlite3Utf16ByteLen(), sqlite3Utf16to8(), sqlite3Utf8CharLen(), SQLITE_MISUSE_BKPT, SQLITE_OK, and SQLITE_UTF16NATIVE.

Referenced by sqlite3_prepare16_v2(), and sqlite3_prepare16_v3().

◆ sqlite3PrimaryKeyIndex()

◆ sqlite3PrngRestoreState()

SQLITE_PRIVATE void sqlite3PrngRestoreState ( void )

Definition at line 30355 of file sqlite3.c.

30361 {

◆ sqlite3PrngSaveState()

SQLITE_PRIVATE void sqlite3PrngSaveState ( void )

Definition at line 30348 of file sqlite3.c.

30354 {

◆ sqlite3Put4byte() [1/2]

SQLITE_PRIVATE void sqlite3Put4byte ( u8 * ,
u32  )

◆ sqlite3Put4byte() [2/2]

SQLITE_PRIVATE void sqlite3Put4byte ( unsigned char * p,
u32 v )

Definition at line 32458 of file sqlite3.c.

32464 {
32465#if SQLITE_BYTEORDER==4321
32466 memcpy(p,&v,4);
32467#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
32468 u32 x = __builtin_bswap32(v);
32469 memcpy(p,&x,4);
32470#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
32471 u32 x = _byteswap_ulong(v);
32472 memcpy(p,&x,4);
32473#else

◆ sqlite3PutVarint()

SQLITE_PRIVATE int sqlite3PutVarint ( unsigned char * p,
u64 v )

Definition at line 32117 of file sqlite3.c.

32118 {
32119 p[i] = buf[j];
32120 }
32121 return n;
32122}
32123SQLITE_PRIVATE int sqlite3PutVarint(unsigned char *p, u64 v){
32124 if( v<=0x7f ){
32125 p[0] = v&0x7f;
32126 return 1;
32127 }
32128 if( v<=0x3fff ){
SQLITE_PRIVATE int sqlite3PutVarint(unsigned char *, u64)
Definition sqlite3.c:32117

◆ sqlite3ReadOnlyShadowTables()

SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables ( sqlite3 * db)

Definition at line 113403 of file sqlite3.c.

113409 {
113410#ifndef SQLITE_OMIT_VIRTUALTABLE
113411 if( (db->flags & SQLITE_Defensive)!=0
113412 && db->pVtabCtx==0
113413 && db->nVdbeExec==0

Referenced by isAlterableTable(), sqlite3CheckObjectName(), and tabIsReadOnly().

◆ sqlite3ReadSchema()

SQLITE_PRIVATE int sqlite3ReadSchema ( Parse * pParse)

Definition at line 128781 of file sqlite3.c.

128787 {
128788 int rc = SQLITE_OK;
128789 sqlite3 *db = pParse->db;
128790 assert( sqlite3_mutex_held(db->mutex) );
128791 if( !db->init.busy ){
128792 rc = sqlite3Init(db, &pParse->zErrMsg);
128793 if( rc!=SQLITE_OK ){
128794 pParse->rc = rc;
128795 pParse->nErr++;

Referenced by sqlite3Analyze(), sqlite3CreateIndex(), sqlite3DropTrigger(), sqlite3LocateTable(), sqlite3Pragma(), sqlite3Reindex(), and sqlite3StartTable().

◆ sqlite3Realloc()

SQLITE_PRIVATE void * sqlite3Realloc ( void * pOld,
u64 nBytes )

Definition at line 27765 of file sqlite3.c.

27770 {
27771 int nOld, nNew, nDiff;
27772 void *pNew;
27773 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
27774 assert( sqlite3MemdebugNoType(pOld, (u8)~MEMTYPE_HEAP) );
27775 if( pOld==0 ){
27776 return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
27777 }
27778 if( nBytes==0 ){
27779 sqlite3_free(pOld); /* IMP: R-26507-47431 */
27780 return 0;
27781 }
27782 if( nBytes>=0x7fffff00 ){
27783 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
27784 return 0;
27785 }
27786 nOld = sqlite3MallocSize(pOld);
27787 /* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
27788 ** argument to xRealloc is always a value returned by a prior call to
27789 ** xRoundup. */
27790 nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
27791 if( nOld==nNew ){
27792 pNew = pOld;
27793 }else if( sqlite3GlobalConfig.bMemstat ){
27796 nDiff = nNew - nOld;
27798 mem0.alarmThreshold-nDiff ){
27799 sqlite3MallocAlarm(nDiff);
27800 }
27801 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
27802#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
27803 if( pNew==0 && mem0.alarmThreshold>0 ){
27804 sqlite3MallocAlarm((int)nBytes);
27805 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
27806 }
27807#endif
27808 if( pNew ){
27809 nNew = sqlite3MallocSize(pNew);
27811 }
27813 }else{

Referenced by accessPayload(), pagerOpenSavepoint(), replaceFunc(), sqlite3_get_table(), sqlite3_get_table_cb(), sqlite3StrAccumEnlarge(), sqlite3VdbeMemGrow(), sqlite3VtabMakeWritable(), vdbePmaReadBlob(), and walIndexPageRealloc().

◆ sqlite3RealSameAsInt()

SQLITE_PRIVATE int sqlite3RealSameAsInt ( double r1,
sqlite3_int64 i )

Definition at line 76536 of file sqlite3.c.

Referenced by alsoAnInt(), and sqlite3VdbeMemNumerify().

◆ sqlite3RefillIndex()

static void sqlite3RefillIndex ( Parse * pParse,
Index * pIndex,
int memRootPage )
static

Definition at line 113702 of file sqlite3.c.

113708 {
113709 Table *pTab = pIndex->pTable; /* The table that is indexed */
113710 int iTab = pParse->nTab++; /* Btree cursor used for pTab */
113711 int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
113712 int iSorter; /* Cursor opened by OpenSorter (if in use) */
113713 int addr1; /* Address of top of loop */
113714 int addr2; /* Address to jump to for next iteration */
113715 Pgno tnum; /* Root page of index */
113716 int iPartIdxLabel; /* Jump to this label to skip a row */
113717 Vdbe *v; /* Generate code into this virtual machine */
113718 KeyInfo *pKey; /* KeyInfo for index */
113719 int regRecord; /* Register holding assembled index record */
113720 sqlite3 *db = pParse->db; /* The database connection */
113721 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
113722
113723#ifndef SQLITE_OMIT_AUTHORIZATION
113724 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
113725 db->aDb[iDb].zDbSName ) ){
113726 return;
113727 }
113728#endif
113729
113730 /* Require a write-lock on the table to perform this operation */
113731 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
113732
113733 v = sqlite3GetVdbe(pParse);
113734 if( v==0 ) return;
113735 if( memRootPage>=0 ){
113736 tnum = (Pgno)memRootPage;
113737 }else{
113738 tnum = pIndex->tnum;
113739 }
113740 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
113741 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
113742
113743 /* Open the sorter cursor if we are to use one. */
113744 iSorter = pParse->nTab++;
113745 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
113747
113748 /* Open the table. Loop through all rows of the table, inserting index
113749 ** records into the sorter. */
113750 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
113751 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
113752 regRecord = sqlite3GetTempReg(pParse);
113753 sqlite3MultiWrite(pParse);
113754
113755 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
113756 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
113757 sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
113758 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
113759 sqlite3VdbeJumpHere(v, addr1);
113760 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
113761 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, (int)tnum, iDb,
113762 (char *)pKey, P4_KEYINFO);
113763 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
113764
113765 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
113766 if( IsUniqueIndex(pIndex) ){
113767 int j2 = sqlite3VdbeGoto(v, 1);
113768 addr2 = sqlite3VdbeCurrentAddr(v);
113770 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
113771 pIndex->nKeyCol); VdbeCoverage(v);
113772 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
113773 sqlite3VdbeJumpHere(v, j2);
113774 }else{
113775 /* Most CREATE INDEX and REINDEX statements that are not UNIQUE can not
113776 ** abort. The exception is if one of the indexed expressions contains a
113777 ** user function that throws an exception when it is evaluated. But the
113778 ** overhead of adding a statement journal to a CREATE INDEX statement is
113779 ** very small (since most of the pages written do not contain content that
113780 ** needs to be restored if the statement aborts), so we call
113781 ** sqlite3MayAbort() for all CREATE INDEX statements. */
113782 sqlite3MayAbort(pParse);
113783 addr2 = sqlite3VdbeCurrentAddr(v);
113784 }
113785 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
113786 if( !pIndex->bAscKeyBug ){
113787 /* This OP_SeekEnd opcode makes index insert for a REINDEX go much
113788 ** faster by avoiding unnecessary seeks. But the optimization does
113789 ** not work for UNIQUE constraint indexes on WITHOUT ROWID tables
113790 ** with DESC primary keys, since those indexes have there keys in
113791 ** a different order from the main table.
113792 ** See ticket: https://www.sqlite.org/src/info/bba7b69f9849b5bf
113793 */
113794 sqlite3VdbeAddOp1(v, OP_SeekEnd, iIdx);
113795 }
113796 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
113798 sqlite3ReleaseTempReg(pParse, regRecord);
113799 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
#define OPFLAG_BULKCSR
Definition sqlite3.c:18847
SQLITE_PRIVATE KeyInfo * sqlite3KeyInfoOfIndex(Parse *, Index *)
Definition sqlite3.c:115426
#define OP_SorterOpen
Definition sqlite3.c:15677
#define OP_SeekEnd
Definition sqlite3.c:15695
#define SQLITE_REINDEX
Definition sqlite3.c:4146
#define OP_SorterCompare
Definition sqlite3.c:15690

References sqlite3::aDb, Index::bAscKeyBug, Parse::db, IsUniqueIndex, sqlite3::mallocFailed, Parse::nErr, Index::nKeyCol, Parse::nTab, OE_Abort, OP_Clear, OP_Close, OP_IdxInsert, OP_Next, OP_OpenRead, OP_OpenWrite, OP_Rewind, OP_SeekEnd, OP_SorterCompare, OP_SorterData, OP_SorterInsert, OP_SorterNext, OP_SorterOpen, OP_SorterSort, OPFLAG_BULKCSR, OPFLAG_P2ISREG, OPFLAG_USESEEKRESULT, P4_KEYINFO, Index::pSchema, Index::pTable, sqlite3AuthCheck(), sqlite3GenerateIndexKey(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3KeyInfoOfIndex(), sqlite3KeyInfoRef(), sqlite3MayAbort(), sqlite3MultiWrite(), sqlite3OpenTable(), sqlite3ReleaseTempReg(), sqlite3ResolvePartIdxLabel(), sqlite3SchemaToIndex(), sqlite3TableLock(), sqlite3UniqueConstraint(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeVerifyAbortable, SQLITE_REINDEX, Table::tnum, Index::tnum, VdbeCoverage, Db::zDbSName, Table::zName, and Index::zName.

Referenced by reindexTable(), sqlite3CreateIndex(), and sqlite3Reindex().

◆ sqlite3RegisterBuiltinFunctions()

SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions ( void )

Definition at line 118958 of file sqlite3.c.

118964 {
118965 /*
118966 ** The following array holds FuncDef structures for all of the functions
118967 ** defined in this file.
118968 **
118969 ** The array cannot be constant since changes are made to the
118970 ** FuncDef.pHash elements at start-time. The elements of this array
118971 ** are read-only after initialization is complete.
118972 **
118973 ** For peak efficiency, put the most frequently used function last.
118974 */
118975 static FuncDef aBuiltinFunc[] = {
118976/***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
118977 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
118978 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
118979 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
118980#ifdef SQLITE_DEBUG
118981 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
118982#endif
118983/***** Regular functions *****/
118984#ifdef SQLITE_SOUNDEX
118985 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
118986#endif
118987#ifndef SQLITE_OMIT_LOAD_EXTENSION
118988 SFUNCTION(load_extension, 1, 0, 0, loadExt ),
118989 SFUNCTION(load_extension, 2, 0, 0, loadExt ),
118990#endif
118991#if SQLITE_USER_AUTHENTICATION
118992 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
118993#endif
118994#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
118995 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
118996 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
118997#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
119001#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
119002 FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
119004#endif
119005 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
119006 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
119007 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
119008 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
119009 FUNCTION(trim, 1, 3, 0, trimFunc ),
119010 FUNCTION(trim, 2, 3, 0, trimFunc ),
119011 FUNCTION(min, -1, 0, 1, minmaxFunc ),
119012 FUNCTION(min, 0, 0, 1, 0 ),
119013 WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
119015 FUNCTION(max, -1, 1, 1, minmaxFunc ),
119016 FUNCTION(max, 0, 1, 1, 0 ),
119017 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
119019 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
119020 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
119021 FUNCTION(instr, 2, 0, 0, instrFunc ),
119022 FUNCTION(printf, -1, 0, 0, printfFunc ),
119023 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
119024 FUNCTION(char, -1, 0, 0, charFunc ),
119025 FUNCTION(abs, 1, 0, 0, absFunc ),
119026#ifndef SQLITE_OMIT_FLOATING_POINT
119027 FUNCTION(round, 1, 0, 0, roundFunc ),
119028 FUNCTION(round, 2, 0, 0, roundFunc ),
119029#endif
119030 FUNCTION(upper, 1, 0, 0, upperFunc ),
119031 FUNCTION(lower, 1, 0, 0, lowerFunc ),
119032 FUNCTION(hex, 1, 0, 0, hexFunc ),
119033 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
119034 VFUNCTION(random, 0, 0, 0, randomFunc ),
119035 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
119036 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
119037 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
119038 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
119039 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
119040 FUNCTION(quote, 1, 0, 0, quoteFunc ),
119042 VFUNCTION(changes, 0, 0, 0, changes ),
119044 FUNCTION(replace, 3, 0, 0, replaceFunc ),
119045 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
119046 FUNCTION(substr, 2, 0, 0, substrFunc ),
119047 FUNCTION(substr, 3, 0, 0, substrFunc ),
119051 WAGGREGATE(count, 0,0,0, countStep,
119053 WAGGREGATE(count, 1,0,0, countStep,
119055 WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
119057 WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
119059
119061#ifdef SQLITE_CASE_SENSITIVE_LIKE
119064#else
119067#endif
119068#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
119069 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
119070#endif
119071 FUNCTION(coalesce, 1, 0, 0, 0 ),
119072 FUNCTION(coalesce, 0, 0, 0, 0 ),
119073 INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
119074 INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
119075 };
119076#ifndef SQLITE_OMIT_ALTERTABLE
119078#endif
119081 sqlite3InsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc));
119082
119083#if 0 /* Enable to print out how the built-in functions are hashed */
119084 {
119085 int i;
119086 FuncDef *p;
119087 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
119088 printf("FUNC-HASH %02d:", i);
119089 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
119090 int n = sqlite3Strlen30(p->zName);
119091 int h = p->zName[0] + n;
119092 printf(" %s(%d)", p->zName, h);
#define trim(x)
static void minMaxFinalize(sqlite3_context *context)
Definition sqlite3.c:118754
static void sumFinalize(sqlite3_context *context)
Definition sqlite3.c:118617
static void unicodeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118155
#define FUNCTION(zName, nArg, iArg, bNC, xFunc)
Definition sqlite3.c:17239
static void versionFunc(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117977
#define INLINE_FUNC(zName, nArg, iArg, mFlags)
Definition sqlite3.c:17248
static void randomBlob(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117578
SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs(FuncDef *, int)
Definition sqlite3.c:115886
static void hexFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118211
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118570
static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117519
static void zeroblobFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118239
#define SQLITE_FUNC_COUNT
Definition sqlite3.c:17152
static void sourceidFunc(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117993
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f)
Definition sqlite3.c:17270
SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void)
Definition sqlite3.c:22940
static void groupConcatInverse(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118794
SQLITE_PRIVATE void sqlite3AlterFunctions(void)
Definition sqlite3.c:107532
static void minmaxFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117093
static void groupConcatStep(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118761
static void countFinalize(sqlite3_context *context)
Definition sqlite3.c:118675
static void errlogFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118009
static void last_insert_rowid(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117602
static void minmaxStep(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:118699
#define SFUNCTION(zName, nArg, iArg, bNC, xFunc)
Definition sqlite3.c:17245
static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118659
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc)
Definition sqlite3.c:17242
static void replaceFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118262
static void randomFunc(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117552
#define likely(X)
Definition sqlite3.c:13837
#define INLINEFUNC_unlikely
Definition sqlite3.c:17174
static const struct compareInfo globInfo
Definition sqlite3.c:117671
static void printfFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117307
static void substrFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117343
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117438
static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118079
static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117500
static void instrFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117239
static void compileoptiongetFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118049
SQLITE_PRIVATE void sqlite3WindowFunctions(void)
Definition sqlite3.c:151769
static void minMaxValue(sqlite3_context *context)
Definition sqlite3.c:118748
static const struct compareInfo likeInfoNorm
Definition sqlite3.c:117674
static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118520
static void nullifFunc(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:117961
static void compileoptionusedFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118025
static void charFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118170
static void typeofFunc(sqlite3_context *context, int NotUsed, sqlite3_value **argv)
Definition sqlite3.c:117123
static void sumInverse(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118592
#define unlikely(X)
Definition sqlite3.c:13838
static void totalFinalize(sqlite3_context *context)
Definition sqlite3.c:118637
#define LIKEFUNC(zName, nArg, arg, flags)
Definition sqlite3.c:17267
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags)
Definition sqlite3.c:17261
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc)
Definition sqlite3.c:17255
#define SQLITE_FUNC_CASE
Definition sqlite3.c:17147
static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117190
static void groupConcatValue(sqlite3_context *context)
Definition sqlite3.c:118840
#define TEST_FUNC(zName, nArg, iArg, mFlags)
Definition sqlite3.c:17251
static void total_changes(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117636
static void trimFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:118355
static void groupConcatFinalize(sqlite3_context *context)
Definition sqlite3.c:118825
static void lengthFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:117148

References FuncDefHash::a, absFunc(), ArraySize, avgFinalize(), changes(), charFunc(), compileoptiongetFunc(), compileoptionusedFunc(), countFinalize(), countInverse(), countStep(), DFUNCTION, errlogFunc(), FUNCTION, FUNCTION2, globInfo, groupConcatFinalize(), groupConcatInverse(), groupConcatStep(), groupConcatValue(), hexFunc(), INLINE_FUNC, INLINEFUNC_affinity, INLINEFUNC_coalesce, INLINEFUNC_expr_compare, INLINEFUNC_expr_implies_expr, INLINEFUNC_iif, INLINEFUNC_implies_nonnull_row, INLINEFUNC_unlikely, instrFunc(), last_insert_rowid(), lengthFunc(), LIKEFUNC, likeInfoAlt, likeInfoNorm, likely, loadExt(), lowerFunc(), minMaxFinalize(), minmaxFunc(), minmaxStep(), minMaxValue(), noopFunc, nullifFunc(), FuncDef::pHash, printf, printfFunc(), quoteFunc(), randomBlob(), randomFunc(), replaceFunc(), roundFunc(), SFUNCTION, sourceidFunc(), sqlite3AlterFunctions(), sqlite3BuiltinFunctions, sqlite3InsertBuiltinFuncs(), sqlite3RegisterDateTimeFunctions(), sqlite3Strlen30(), sqlite3WindowFunctions(), SQLITE_FUNC_CASE, SQLITE_FUNC_COUNT, SQLITE_FUNC_HASH_SZ, SQLITE_FUNC_LENGTH, SQLITE_FUNC_LIKE, SQLITE_FUNC_MINMAX, SQLITE_FUNC_OFFSET, SQLITE_FUNC_TYPEOF, SQLITE_FUNC_UNLIKELY, substrFunc(), sumFinalize(), sumInverse(), sumStep(), TEST_FUNC, total_changes(), totalFinalize(), trim, trimFunc(), typeofFunc(), FuncDef::u, unicodeFunc(), unlikely, upperFunc(), versionFunc(), VFUNCTION, WAGGREGATE, zeroblobFunc(), and FuncDef::zName.

Referenced by sqlite3_initialize().

◆ sqlite3RegisterDateTimeFunctions()

SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions ( void )

Definition at line 22940 of file sqlite3.c.

22945 {
22946 static FuncDef aDateTimeFuncs[] = {
22947#ifndef SQLITE_OMIT_DATETIME_FUNCS
22948 PURE_DATE(julianday, -1, 0, 0, juliandayFunc ),
22949 PURE_DATE(date, -1, 0, 0, dateFunc ),
22950 PURE_DATE(time, -1, 0, 0, timeFunc ),
22951 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
22952 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ),
22953 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
22954 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
22955 DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
22956#else
22957 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
22958 STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc),
static void dateFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:22681
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc)
Definition sqlite3.c:17264
static void datetimeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:22642
static void juliandayFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:22625
static void timeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:22662
static void ctimeFunc(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:22852
static void cdateFunc(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:22866
static void strftimeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:22714
#define PURE_DATE(zName, nArg, iArg, bNC, xFunc)
Definition sqlite3.c:17258
static void ctimestampFunc(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:22880

References ArraySize, cdateFunc(), ctimeFunc(), ctimestampFunc(), dateFunc(), datetimeFunc(), DFUNCTION, juliandayFunc(), PURE_DATE, sqlite3InsertBuiltinFuncs(), STR_FUNCTION, strftimeFunc(), and timeFunc().

Referenced by sqlite3RegisterBuiltinFunctions().

◆ sqlite3RegisterLikeFunctions()

SQLITE_PRIVATE void sqlite3RegisterLikeFunctions ( sqlite3 * db,
int caseSensitive )

Definition at line 118876 of file sqlite3.c.

118882 {
118883 struct compareInfo *pInfo;
118884 int flags;
118885 if( caseSensitive ){
118886 pInfo = (struct compareInfo*)&likeInfoAlt;
118888 }else{
118889 pInfo = (struct compareInfo*)&likeInfoNorm;
118890 flags = SQLITE_FUNC_LIKE;

References FuncDef::funcFlags, likeFunc(), likeInfoAlt, likeInfoNorm, sqlite3CreateFunc(), sqlite3FindFunction(), SQLITE_FUNC_CASE, SQLITE_FUNC_LIKE, and SQLITE_UTF8.

Referenced by sqlite3Pragma().

◆ sqlite3RegisterPerConnectionBuiltinFunctions()

SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions ( sqlite3 * db)

Definition at line 118863 of file sqlite3.c.

118869 {

References sqlite3_overload_function(), sqlite3OomFault(), SQLITE_NOMEM, and SQLITE_OK.

Referenced by openDatabase().

◆ sqlite3Reindex()

SQLITE_PRIVATE void sqlite3Reindex ( Parse * pParse,
Token * pName1,
Token * pName2 )

Definition at line 115366 of file sqlite3.c.

115372 {
115373 CollSeq *pColl; /* Collating sequence to be reindexed, or NULL */
115374 char *z; /* Name of a table or index */
115375 const char *zDb; /* Name of the database */
115376 Table *pTab; /* A table in the database */
115377 Index *pIndex; /* An index associated with pTab */
115378 int iDb; /* The database index number */
115379 sqlite3 *db = pParse->db; /* The database connection */
115380 Token *pObjName; /* Name of the table or index to be reindexed */
115381
115382 /* Read the database schema. If an error occurs, leave an error message
115383 ** and code in pParse and return NULL. */
115384 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
115385 return;
115386 }
115387
115388 if( pName1==0 ){
115389 reindexDatabases(pParse, 0);
115390 return;
115391 }else if( NEVER(pName2==0) || pName2->z==0 ){
115392 char *zColl;
115393 assert( pName1->z );
115394 zColl = sqlite3NameFromToken(pParse->db, pName1);
115395 if( !zColl ) return;
115396 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
115397 if( pColl ){
115398 reindexDatabases(pParse, zColl);
115399 sqlite3DbFree(db, zColl);
115400 return;
115401 }
115402 sqlite3DbFree(db, zColl);
115403 }
115404 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
115405 if( iDb<0 ) return;
115406 z = sqlite3NameFromToken(db, pObjName);
115407 if( z==0 ) return;
115408 zDb = db->aDb[iDb].zDbSName;
115409 pTab = sqlite3FindTable(db, z, zDb);
115410 if( pTab ){
115411 reindexTable(pParse, pTab, 0);
115412 sqlite3DbFree(db, z);
115413 return;
115414 }
115415 pIndex = sqlite3FindIndex(db, z, zDb);
115416 sqlite3DbFree(db, z);
115417 if( pIndex ){
static void reindexDatabases(Parse *pParse, char const *zColl)
Definition sqlite3.c:115334
static void reindexTable(Parse *pParse, Table *pTab, char const *zColl)
Definition sqlite3.c:115313

References sqlite3::aDb, Parse::db, ENC, NEVER, reindexDatabases(), reindexTable(), sqlite3BeginWriteOperation(), sqlite3DbFree(), sqlite3ErrorMsg(), sqlite3FindCollSeq(), sqlite3FindIndex(), sqlite3FindTable(), sqlite3NameFromToken(), sqlite3ReadSchema(), sqlite3RefillIndex(), sqlite3TwoPartName(), SQLITE_OK, Token::z, and Db::zDbSName.

Referenced by yy_reduce().

◆ sqlite3ReleaseTempRange()

SQLITE_PRIVATE void sqlite3ReleaseTempRange ( Parse * pParse,
int iReg,
int nReg )

Definition at line 105744 of file sqlite3.c.

105744 {
105745 i = pParse->nMem+1;
105746 pParse->nMem += nReg;
105747 }
105748 return i;
105749}
105750SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
105751 if( nReg==1 ){
105752 sqlite3ReleaseTempReg(pParse, iReg);
105753 return;
105754 }

Referenced by analyzeOneTable(), fkLookupParent(), generateSortTail(), selectInnerLoop(), sqlite3ExprCodeTarget(), sqlite3GenerateConstraintChecks(), sqlite3GenerateIndexKey(), sqlite3Insert(), sqlite3Select(), updateAccumulator(), windowAggStep(), windowCodeOp(), and windowFullScan().

◆ sqlite3ReleaseTempReg()

◆ sqlite3RenameExprlistUnmap()

SQLITE_PRIVATE void sqlite3RenameExprlistUnmap ( Parse * pParse,
ExprList * pEList )

Definition at line 106632 of file sqlite3.c.

106638 {
106639 if( pEList ){
106640 int i;
106641 Walker sWalker;
106642 memset(&sWalker, 0, sizeof(Walker));
106643 sWalker.pParse = pParse;
106645 sqlite3WalkExprList(&sWalker, pEList);
106646 for(i=0; i<pEList->nExpr; i++){
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:106543

◆ sqlite3RenameExprUnmap()

SQLITE_PRIVATE void sqlite3RenameExprUnmap ( Parse * pParse,
Expr * pExpr )

Definition at line 106616 of file sqlite3.c.

106622 {
106623 u8 eMode = pParse->eParseMode;
106624 Walker sWalker;
106625 memset(&sWalker, 0, sizeof(Walker));
106626 sWalker.pParse = pParse;

Referenced by sqlite3AddDefaultValue(), and sqlite3WindowOffsetExpr().

◆ sqlite3RenameTokenMap()

SQLITE_PRIVATE void * sqlite3RenameTokenMap ( Parse * pParse,
void * pPtr,
Token * pToken )

Definition at line 106507 of file sqlite3.c.

106513 {
106514 RenameToken *pNew;
106515 assert( pPtr || pParse->db->mallocFailed );
106516 renameTokenCheckAll(pParse, pPtr);
106517 if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){
106518 pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
106519 if( pNew ){
106520 pNew->p = pPtr;
106521 pNew->t = *pToken;
106522 pNew->pNext = pParse->pRename;
#define renameTokenCheckAll(x, y)
Definition sqlite3.c:106492

References ALWAYS, Parse::db, Parse::eParseMode, sqlite3::mallocFailed, RenameToken::p, PARSE_MODE_UNMAP, RenameToken::pNext, Parse::pRename, renameTokenCheckAll, sqlite3DbMallocZero(), and RenameToken::t.

Referenced by sqlite3AddColumn(), sqlite3CreateForeignKey(), sqlite3ExprListSetName(), sqlite3IdListAppend(), sqlite3SrcListAppendFromTerm(), sqlite3StartTable(), tokenExpr(), triggerStepAllocate(), and yy_reduce().

◆ sqlite3RenameTokenRemap()

SQLITE_PRIVATE void sqlite3RenameTokenRemap ( Parse * pParse,
void * pTo,
void * pFrom )

◆ sqlite3ReportError()

SQLITE_PRIVATE int sqlite3ReportError ( int iErr,
int lineno,
const char * zType )

Definition at line 164582 of file sqlite3.c.

◆ sqlite3Reprepare()

SQLITE_PRIVATE int sqlite3Reprepare ( Vdbe * p)

Definition at line 129095 of file sqlite3.c.

129101 {
129102 int rc;
129103 sqlite3_stmt *pNew;
129104 const char *zSql;
129105 sqlite3 *db;
129106 u8 prepFlags;
129107
129108 assert( sqlite3_mutex_held(sqlite3VdbeDb(p)->mutex) );
129109 zSql = sqlite3_sql((sqlite3_stmt *)p);
129110 assert( zSql!=0 ); /* Reprepare only called for prepare_v2() statements */
129111 db = sqlite3VdbeDb(p);
129112 assert( sqlite3_mutex_held(db->mutex) );
129113 prepFlags = sqlite3VdbePrepareFlags(p);
129114 rc = sqlite3LockAndPrepare(db, zSql, -1, prepFlags, p, &pNew, 0);
129115 if( rc ){
129116 if( rc==SQLITE_NOMEM ){
129117 sqlite3OomFault(db);
129118 }
129119 assert( pNew==0 );
129120 return rc;
129121 }else{
129122 assert( pNew!=0 );
129123 }
SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags(Vdbe *)
Definition sqlite3.c:82796

References sqlite3::mutex, mutex, sqlite3_mutex_held(), sqlite3_sql(), sqlite3LockAndPrepare(), sqlite3OomFault(), sqlite3TransferBindings(), sqlite3VdbeDb(), sqlite3VdbeFinalize(), sqlite3VdbePrepareFlags(), sqlite3VdbeResetStepResult(), sqlite3VdbeSwap(), SQLITE_NOMEM, and SQLITE_OK.

Referenced by sqlite3_step().

◆ sqlite3ResetAllSchemasOfConnection()

SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection ( sqlite3 * db)

Definition at line 110989 of file sqlite3.c.

110995 {
110996 int i;
110998 for(i=0; i<db->nDb; i++){
110999 Db *pDb = &db->aDb[i];
111000 if( pDb->pSchema ){
111001 if( db->nSchemaLock==0 ){
111003 }else{
111005 }
111006 }
111007 }
#define DB_ResetWanted
Definition sqlite3.c:16665
u32 nSchemaLock
Definition sqlite3.c:16830

Referenced by attachFunc(), invalidateTempStorage(), sqlite3InitOne(), sqlite3RollbackAll(), and sqlite3VdbeExec().

◆ sqlite3ResetOneSchema()

SQLITE_PRIVATE void sqlite3ResetOneSchema ( sqlite3 * db,
int iDb )

Definition at line 110965 of file sqlite3.c.

110971 {
110972 int i;
110973 assert( iDb<db->nDb );
110974
110975 if( iDb>=0 ){
110976 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
110977 DbSetProperty(db, iDb, DB_ResetWanted);
110979 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
110980 }
110981
110982 if( db->nSchemaLock==0 ){
110983 for(i=0; i<db->nDb; i++){

References sqlite3::aDb, DB_ResetWanted, DbHasProperty, DbSetProperty, sqlite3::mDbFlags, sqlite3::nDb, sqlite3::nSchemaLock, Db::pSchema, and sqlite3SchemaClear().

Referenced by schemaIsValid(), sqlite3InitOne(), and sqlite3VdbeExec().

◆ sqlite3ResolveExprListNames()

SQLITE_PRIVATE int sqlite3ResolveExprListNames ( NameContext * pNC,
ExprList * pList )

Definition at line 99583 of file sqlite3.c.

99592 {
99593 int i;
99594 int savedHasAgg = 0;
99595 Walker w;
99596 if( pList==0 ) return WRC_Continue;
99597 w.pParse = pNC->pParse;
99600 w.xSelectCallback2 = 0;
99601 w.u.pNC = pNC;
99602 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
99604 for(i=0; i<pList->nExpr; i++){
99605 Expr *pExpr = pList->a[i].pExpr;
99606 if( pExpr==0 ) continue;
99607#if SQLITE_MAX_EXPR_DEPTH>0
99608 w.pParse->nHeight += pExpr->nHeight;
99610 return WRC_Abort;
99611 }
99612#endif
99613 sqlite3WalkExpr(&w, pExpr);
99614#if SQLITE_MAX_EXPR_DEPTH>0
99615 w.pParse->nHeight -= pExpr->nHeight;
99616#endif
99617 assert( EP_Agg==NC_HasAgg );
99618 assert( EP_Win==NC_HasWin );
99619 testcase( pNC->ncFlags & NC_HasAgg );
99620 testcase( pNC->ncFlags & NC_HasWin );
99621 if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
99622 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
99623 savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
static int resolveSelectStep(Walker *pWalker, Select *p)
Definition sqlite3.c:99259
int nHeight
Definition sqlite3.c:18755

References ExprList::a, EP_Agg, EP_Win, ExprSetProperty, NC_HasAgg, NC_HasWin, NC_MinMaxAgg, NameContext::ncFlags, NameContext::nErr, Parse::nErr, ExprList::nExpr, Expr::nHeight, Parse::nHeight, ExprList::ExprList_item::pExpr, Walker::pNC, NameContext::pParse, Walker::pParse, resolveExprStep(), resolveSelectStep(), sqlite3ExprCheckHeight(), sqlite3WalkExpr(), testcase, Walker::u, WRC_Abort, WRC_Continue, Walker::xExprCallback, Walker::xSelectCallback, and Walker::xSelectCallback2.

Referenced by renameResolveTrigger(), sqlite3Insert(), sqlite3ResolveSelfReference(), and sqlite3UpsertAnalyzeTarget().

◆ sqlite3ResolveExprNames()

SQLITE_PRIVATE int sqlite3ResolveExprNames ( NameContext * pNC,
Expr * pExpr )

◆ sqlite3ResolveOrderGroupBy()

SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy ( Parse * pParse,
Select * pSelect,
ExprList * pOrderBy,
const char * zType )

Definition at line 99118 of file sqlite3.c.

99129 {
99130 int i;
99131 sqlite3 *db = pParse->db;
99132 ExprList *pEList;
99133 struct ExprList_item *pItem;
99134
99135 if( pOrderBy==0 || pParse->db->mallocFailed || IN_RENAME_OBJECT ) return 0;
99136 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
99137 sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
99138 return 1;
99139 }
99140 pEList = pSelect->pEList;
99141 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
99142 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99143 if( pItem->u.x.iOrderByCol ){
99144 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
99145 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
99146 return 1;
99147 }

References ExprList::a, sqlite3::aLimit, Parse::db, IN_RENAME_OBJECT, sqlite3::mallocFailed, ExprList::nExpr, Select::pEList, resolveAlias(), resolveOutOfRangeError(), sqlite3ErrorMsg(), and SQLITE_LIMIT_COLUMN.

Referenced by multiSelectOrderBy().

◆ sqlite3ResolvePartIdxLabel()

SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel ( Parse * pParse,
int iLabel )

◆ sqlite3ResolveSelectNames()

SQLITE_PRIVATE void sqlite3ResolveSelectNames ( Parse * pParse,
Select * p,
NameContext * pOuterNC )

◆ sqlite3ResolveSelfReference()

SQLITE_PRIVATE int sqlite3ResolveSelfReference ( Parse * pParse,
Table * pTab,
int type,
Expr * pExpr,
ExprList * pList )

Definition at line 99672 of file sqlite3.c.

99684 {
99685 SrcList sSrc; /* Fake SrcList for pParse->pNewTable */
99686 NameContext sNC; /* Name context for pParse->pNewTable */
99687 int rc;
99688
99689 assert( type==0 || pTab!=0 );
99690 assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr
99691 || type==NC_GenCol || pTab==0 );
99692 memset(&sNC, 0, sizeof(sNC));
99693 memset(&sSrc, 0, sizeof(sSrc));
99694 if( pTab ){
99695 sSrc.nSrc = 1;
99696 sSrc.a[0].zName = pTab->zName;
99697 sSrc.a[0].pTab = pTab;
99698 sSrc.a[0].iCursor = -1;
99699 if( pTab->pSchema!=pParse->db->aDb[1].pSchema ){
99700 /* Cause EP_FromDDL to be set on TK_FUNCTION nodes of non-TEMP
99701 ** schema elements */
99702 type |= NC_FromDDL;
99703 }
99704 }
99705 sNC.pParse = pParse;

References SrcList::a, sqlite3::aDb, Parse::db, SrcList::SrcList_item::iCursor, NC_FromDDL, NC_GenCol, NC_IdxExpr, NC_IsCheck, NC_IsDDL, NC_PartIdx, NameContext::ncFlags, SrcList::nSrc, NameContext::pParse, Db::pSchema, Table::pSchema, NameContext::pSrcList, SrcList::SrcList_item::pTab, sqlite3ResolveExprListNames(), sqlite3ResolveExprNames(), SQLITE_OK, Table::zName, and SrcList::SrcList_item::zName.

Referenced by sqlite3CreateIndex(), sqlite3EndTable(), and sqlite3Vacuum().

◆ sqlite3ResultIntReal()

SQLITE_PRIVATE void sqlite3ResultIntReal ( sqlite3_context * pCtx)

◆ sqlite3ResultSetOfSelect()

SQLITE_PRIVATE Table * sqlite3ResultSetOfSelect ( Parse * pParse,
Select * pSelect,
char aff )

Definition at line 131409 of file sqlite3.c.

131415 {
131416 Table *pTab;
131417 sqlite3 *db = pParse->db;
131418 u64 savedFlags;
131419
131420 savedFlags = db->flags;
131421 db->flags &= ~(u64)SQLITE_FullColNames;
131423 sqlite3SelectPrep(pParse, pSelect, 0);
131424 db->flags = savedFlags;
131425 if( pParse->nErr ) return 0;
131426 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
131427 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
131428 if( pTab==0 ){
131429 return 0;
131430 }
131431 pTab->nTabRef = 1;
131432 pTab->zName = 0;
131433 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
131434 sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
131435 sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect, aff);
131436 pTab->iPKey = -1;
SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse *, Table *, Select *, char)
Definition sqlite3.c:131359

Referenced by sqlite3EndTable(), sqlite3ViewGetColumnNames(), and sqlite3WindowRewrite().

◆ sqlite3RollbackAll()

SQLITE_PRIVATE void sqlite3RollbackAll ( sqlite3 * db,
int tripCode )

Definition at line 162378 of file sqlite3.c.

162384 {
162385 int i;
162386 int inTrans = 0;
162387 int schemaChange;
162388 assert( sqlite3_mutex_held(db->mutex) );
162390
162391 /* Obtain all b-tree mutexes before making any calls to BtreeRollback().
162392 ** This is important in case the transaction being rolled back has
162393 ** modified the database schema. If the b-tree mutexes are not taken
162394 ** here, then another shared-cache connection might sneak in between
162395 ** the database rollback and schema reset, which can cause false
162396 ** corruption reports in some cases. */
162398 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
162399
162400 for(i=0; i<db->nDb; i++){
162401 Btree *p = db->aDb[i].pBt;
162402 if( p ){
162403 if( sqlite3BtreeIsInTrans(p) ){
162404 inTrans = 1;
162405 }
162406 sqlite3BtreeRollback(p, tripCode, !schemaChange);
162407 }
162408 }
162411
162412 if( schemaChange ){
162415 }
162417
162418 /* Any deferred constraint violations have now been resolved. */
162419 db->nDeferredCons = 0;
162420 db->nDeferredImmCons = 0;
162421 db->flags &= ~(u64)SQLITE_DeferFKs;

References sqlite3::aDb, sqlite3::autoCommit, sqlite3::sqlite3InitInfo::busy, DBFLAG_SchemaChange, sqlite3::flags, sqlite3::init, sqlite3::mDbFlags, sqlite3::mutex, sqlite3::nDb, sqlite3::nDeferredCons, sqlite3::nDeferredImmCons, Db::pBt, sqlite3::pRollbackArg, sqlite3_mutex_held(), sqlite3BeginBenignMalloc(), sqlite3BtreeEnterAll(), sqlite3BtreeIsInTrans(), sqlite3BtreeLeaveAll(), sqlite3BtreeRollback(), sqlite3EndBenignMalloc(), sqlite3ExpirePreparedStatements(), sqlite3ResetAllSchemasOfConnection(), sqlite3VtabRollback(), SQLITE_DeferFKs, and sqlite3::xRollbackCallback.

Referenced by sqlite3LeaveMutexAndCloseZombie(), sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3RootPageMoved()

SQLITE_PRIVATE void sqlite3RootPageMoved ( sqlite3 * db,
int iDb,
Pgno iFrom,
Pgno iTo )

Definition at line 113198 of file sqlite3.c.

113204 {
113205 HashElem *pElem;
113206 Hash *pHash;
113207 Db *pDb;
113208
113209 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
113210 pDb = &db->aDb[iDb];
113211 pHash = &pDb->pSchema->tblHash;
113212 for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){
113213 Table *pTab = sqliteHashData(pElem);
113214 if( pTab->tnum==iFrom ){
113215 pTab->tnum = iTo;
113216 }
113217 }
113218 pHash = &pDb->pSchema->idxHash;
113219 for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){

References sqlite3::aDb, Schema::idxHash, Db::pSchema, sqliteHashData, sqliteHashFirst, sqliteHashNext, Schema::tblHash, Table::tnum, and Index::tnum.

Referenced by sqlite3VdbeExec().

◆ sqlite3RowidConstraint()

SQLITE_PRIVATE void sqlite3RowidConstraint ( Parse * pParse,
int onError,
Table * pTab )

Definition at line 115270 of file sqlite3.c.

115280 {
115281 char *zMsg;
115282 int rc;
115283 if( pTab->iPKey>=0 ){
115284 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
115285 pTab->aCol[pTab->iPKey].zName);
115287 }else{
#define SQLITE_CONSTRAINT_PRIMARYKEY
Definition sqlite3.c:1581

Referenced by sqlite3GenerateConstraintChecks(), and xferOptimization().

◆ sqlite3RowSetClear()

SQLITE_PRIVATE void sqlite3RowSetClear ( void * pArg)

Definition at line 51190 of file sqlite3.c.

51196 {
51197 RowSet *p = (RowSet*)pArg;
51198 struct RowSetChunk *pChunk, *pNextChunk;
51199 for(pChunk=p->pChunk; pChunk; pChunk = pNextChunk){
51200 pNextChunk = pChunk->pNextChunk;
51201 sqlite3DbFree(p->db, pChunk);
51202 }
51203 p->pChunk = 0;

References RowSet::db, RowSet::nFresh, RowSet::pChunk, RowSet::pEntry, RowSet::pForest, RowSet::pLast, RowSetChunk::pNextChunk, ROWSET_SORTED, RowSet::rsFlags, and sqlite3DbFree().

Referenced by sqlite3RowSetDelete(), and sqlite3RowSetNext().

◆ sqlite3RowSetDelete()

SQLITE_PRIVATE void sqlite3RowSetDelete ( void * pArg)

Definition at line 51210 of file sqlite3.c.

References sqlite3DbFree(), and sqlite3RowSetClear().

Referenced by sqlite3VdbeMemSetRowSet().

◆ sqlite3RowSetInit()

SQLITE_PRIVATE RowSet * sqlite3RowSetInit ( sqlite3 * db)

Definition at line 51168 of file sqlite3.c.

51174 {
51175 RowSet *p = sqlite3DbMallocRawNN(db, sizeof(*p));
51176 if( p ){
51177 int N = sqlite3DbMallocSize(db, p);
51178 p->pChunk = 0;
51179 p->db = db;
51180 p->pEntry = 0;
51181 p->pLast = 0;
51182 p->pForest = 0;
51183 p->pFresh = (struct RowSetEntry*)(ROUND8(sizeof(*p)) + (char*)p);
struct RowSetEntry * pLast
Definition sqlite3.c:51150
struct RowSetEntry * pEntry
Definition sqlite3.c:51149
struct RowSetEntry * pFresh
Definition sqlite3.c:51151
struct RowSetEntry * pForest
Definition sqlite3.c:51152

References RowSet::db, RowSet::iBatch, RowSet::nFresh, RowSet::pChunk, RowSet::pEntry, RowSet::pForest, RowSet::pFresh, RowSet::pLast, ROUND8, ROWSET_SORTED, RowSet::rsFlags, sqlite3DbMallocRawNN(), and sqlite3DbMallocSize().

Referenced by sqlite3VdbeMemSetRowSet().

◆ sqlite3RowSetInsert()

SQLITE_PRIVATE void sqlite3RowSetInsert ( RowSet * p,
i64 rowid )

Definition at line 51248 of file sqlite3.c.

51254 {
51255 struct RowSetEntry *pEntry; /* The new entry */
51256 struct RowSetEntry *pLast; /* The last prior entry */
51257
51258 /* This routine is never called after sqlite3RowSetNext() */
51259 assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
51260
51261 pEntry = rowSetEntryAlloc(p);
51262 if( pEntry==0 ) return;
51263 pEntry->v = rowid;
51264 pEntry->pRight = 0;
51265 pLast = p->pLast;
51266 if( pLast ){
51267 if( rowid<=pLast->v ){ /*OPTIMIZATION-IF-FALSE*/
51268 /* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
51269 ** where possible */
51270 p->rsFlags &= ~ROWSET_SORTED;
51271 }
#define ROWSET_NEXT
Definition sqlite3.c:51162
static struct RowSetEntry * rowSetEntryAlloc(RowSet *p)
Definition sqlite3.c:51223
u16 rsFlags
Definition sqlite3.c:51154

References RowSet::pEntry, RowSet::pLast, RowSetEntry::pRight, ROWSET_NEXT, rowSetEntryAlloc(), RowSet::rsFlags, and RowSetEntry::v.

Referenced by sqlite3VdbeExec().

◆ sqlite3RowSetNext()

SQLITE_PRIVATE int sqlite3RowSetNext ( RowSet * p,
i64 * pRowid )

Definition at line 51446 of file sqlite3.c.

51452 {
51453 assert( p!=0 );
51454 assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
51455
51456 /* Merge the forest into a single sorted list on first call */
51457 if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
51458 if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
51459 p->pEntry = rowSetEntrySort(p->pEntry);
51460 }
51462 }
51463
51464 /* Return the next entry on the list */
51465 if( p->pEntry ){
51466 *pRowid = p->pEntry->v;
51467 p->pEntry = p->pEntry->pRight;
51468 if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
51469 /* Free memory immediately, rather than waiting on sqlite3_finalize() */
#define ROWSET_SORTED
Definition sqlite3.c:51161
SQLITE_PRIVATE void sqlite3RowSetClear(void *)
Definition sqlite3.c:51190
static struct RowSetEntry * rowSetEntrySort(struct RowSetEntry *pIn)
Definition sqlite3.c:51314

References RowSet::pEntry, RowSet::pForest, RowSetEntry::pRight, ROWSET_NEXT, ROWSET_SORTED, rowSetEntrySort(), RowSet::rsFlags, sqlite3RowSetClear(), and RowSetEntry::v.

Referenced by sqlite3VdbeExec().

◆ sqlite3RowSetTest()

SQLITE_PRIVATE int sqlite3RowSetTest ( RowSet * pRowSet,
int iBatch,
i64 iRowid )

Definition at line 51480 of file sqlite3.c.

51486 {
51487 struct RowSetEntry *p, *pTree;
51488
51489 /* This routine is never called after sqlite3RowSetNext() */
51490 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
51491
51492 /* Sort entries into the forest on the first test of a new batch.
51493 ** To save unnecessary work, only do this when the batch number changes.
51494 */
51495 if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/
51496 p = pRowSet->pEntry;
51497 if( p ){
51498 struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
51499 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
51500 /* Only sort the current set of entries if they need it */
51501 p = rowSetEntrySort(p);
51502 }
51503 for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
51504 ppPrevTree = &pTree->pRight;
51505 if( pTree->pLeft==0 ){
51506 pTree->pLeft = rowSetListToTree(p);
51507 break;
51508 }else{
51509 struct RowSetEntry *pAux, *pTail;
51510 rowSetTreeToList(pTree->pLeft, &pAux, &pTail);
51511 pTree->pLeft = 0;
51512 p = rowSetEntryMerge(pAux, p);
51513 }
51514 }
51515 if( pTree==0 ){
51516 *ppPrevTree = pTree = rowSetEntryAlloc(pRowSet);
51517 if( pTree ){
51518 pTree->v = 0;
51519 pTree->pRight = 0;
51520 pTree->pLeft = rowSetListToTree(p);
51521 }
51522 }
51523 pRowSet->pEntry = 0;
51524 pRowSet->pLast = 0;
51525 pRowSet->rsFlags |= ROWSET_SORTED;
51526 }
51527 pRowSet->iBatch = iBatch;
51528 }
51529
51530 /* Test to see if the iRowid value appears anywhere in the forest.
51531 ** Return 1 if it does and 0 if not.
51532 */
51533 for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
51534 p = pTree->pLeft;
51535 while( p ){
51536 if( p->v<iRowid ){
51537 p = p->pRight;
51538 }else if( p->v>iRowid ){
51539 p = p->pLeft;
51540 }else{
static struct RowSetEntry * rowSetListToTree(struct RowSetEntry *pList)
Definition sqlite3.c:51414
int iBatch
Definition sqlite3.c:51155

References RowSet::iBatch, RowSet::pEntry, RowSet::pForest, RowSet::pLast, RowSetEntry::pLeft, RowSetEntry::pRight, ROWSET_NEXT, ROWSET_SORTED, rowSetEntryAlloc(), rowSetEntryMerge(), rowSetEntrySort(), rowSetListToTree(), rowSetTreeToList(), RowSet::rsFlags, and RowSetEntry::v.

Referenced by sqlite3VdbeExec().

◆ sqlite3RunParser()

SQLITE_PRIVATE int sqlite3RunParser ( Parse * pParse,
const char * zSql,
char ** pzErrMsg )

Definition at line 160294 of file sqlite3.c.

160300 {
160301 int nErr = 0; /* Number of errors encountered */
160302 void *pEngine; /* The LEMON-generated LALR(1) parser */
160303 int n = 0; /* Length of the next token token */
160304 int tokenType; /* type of the next token */
160305 int lastTokenParsed = -1; /* type of the previous token */
160306 sqlite3 *db = pParse->db; /* The database connection */
160307 int mxSqlLen; /* Max length of an SQL string */
160308#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
160309 yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
160310#endif
160311 VVA_ONLY( u8 startedWithOom = db->mallocFailed );
160312
160313 assert( zSql!=0 );
160314 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
160315 if( db->nVdbeActive==0 ){
160316 AtomicStore(&db->u1.isInterrupted, 0);
160317 }
160318 pParse->rc = SQLITE_OK;
160319 pParse->zTail = zSql;
160320 assert( pzErrMsg!=0 );
160321#ifdef SQLITE_DEBUG
160322 if( db->flags & SQLITE_ParserTrace ){
160323 printf("parser: [[[%s]]]\n", zSql);
160324 sqlite3ParserTrace(stdout, "parser: ");
160325 }else{
160326 sqlite3ParserTrace(0, 0);
160327 }
160328#endif
160329#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
160330 pEngine = &sEngine;
160331 sqlite3ParserInit(pEngine, pParse);
160332#else
160333 pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse);
160334 if( pEngine==0 ){
160335 sqlite3OomFault(db);
160336 return SQLITE_NOMEM_BKPT;
160337 }
160338#endif
160339 assert( pParse->pNewTable==0 );
160340 assert( pParse->pNewTrigger==0 );
160341 assert( pParse->nVar==0 );
160342 assert( pParse->pVList==0 );
160343 pParse->pParentParse = db->pParse;
160344 db->pParse = pParse;
160345 while( 1 ){
160346 n = sqlite3GetToken((u8*)zSql, &tokenType);
160347 mxSqlLen -= n;
160348 if( mxSqlLen<0 ){
160349 pParse->rc = SQLITE_TOOBIG;
160350 break;
160351 }
160352#ifndef SQLITE_OMIT_WINDOWFUNC
160353 if( tokenType>=TK_WINDOW ){
160354 assert( tokenType==TK_SPACE || tokenType==TK_OVER || tokenType==TK_FILTER
160355 || tokenType==TK_ILLEGAL || tokenType==TK_WINDOW
160356 );
160357#else
160358 if( tokenType>=TK_SPACE ){
160359 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
160360#endif /* SQLITE_OMIT_WINDOWFUNC */
160361 if( AtomicLoad(&db->u1.isInterrupted) ){
160362 pParse->rc = SQLITE_INTERRUPT;
160363 break;
160364 }
160365 if( tokenType==TK_SPACE ){
160366 zSql += n;
160367 continue;
160368 }
160369 if( zSql[0]==0 ){
160370 /* Upon reaching the end of input, call the parser two more times
160371 ** with tokens TK_SEMI and 0, in that order. */
160372 if( lastTokenParsed==TK_SEMI ){
160373 tokenType = 0;
160374 }else if( lastTokenParsed==0 ){
160375 break;
160376 }else{
160377 tokenType = TK_SEMI;
160378 }
160379 n = 0;
160380#ifndef SQLITE_OMIT_WINDOWFUNC
160381 }else if( tokenType==TK_WINDOW ){
160382 assert( n==6 );
160383 tokenType = analyzeWindowKeyword((const u8*)&zSql[6]);
160384 }else if( tokenType==TK_OVER ){
160385 assert( n==4 );
160386 tokenType = analyzeOverKeyword((const u8*)&zSql[4], lastTokenParsed);
160387 }else if( tokenType==TK_FILTER ){
160388 assert( n==6 );
160389 tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed);
160390#endif /* SQLITE_OMIT_WINDOWFUNC */
160391 }else{
160392 sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql);
160393 break;
160394 }
160395 }
160396 pParse->sLastToken.z = zSql;
160397 pParse->sLastToken.n = n;
160398 sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
160399 lastTokenParsed = tokenType;
160400 zSql += n;
160401 assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
160402 if( pParse->rc!=SQLITE_OK ) break;
160403 }
160404 assert( nErr==0 );
160405#ifdef YYTRACKMAXSTACKDEPTH
160408 sqlite3ParserStackPeak(pEngine)
160409 );
160411#endif /* YYDEBUG */
160412#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
160413 sqlite3ParserFinalize(pEngine);
160414#else
160415 sqlite3ParserFree(pEngine, sqlite3_free);
160416#endif
160417 if( db->mallocFailed ){
160418 pParse->rc = SQLITE_NOMEM_BKPT;
160419 }
160420 if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
160421 pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
160422 }
160423 assert( pzErrMsg!=0 );
160424 if( pParse->zErrMsg ){
160425 *pzErrMsg = pParse->zErrMsg;
160426 sqlite3_log(pParse->rc, "%s in \"%s\"",
160427 *pzErrMsg, pParse->zTail);
160428 pParse->zErrMsg = 0;
160429 nErr++;
160430 }
160431 pParse->zTail = zSql;
160432 if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){
160433 sqlite3VdbeDelete(pParse->pVdbe);
160434 pParse->pVdbe = 0;
160435 }
160436#ifndef SQLITE_OMIT_SHARED_CACHE
160437 if( pParse->nested==0 ){
160438 sqlite3DbFree(db, pParse->aTableLock);
160439 pParse->aTableLock = 0;
160440 pParse->nTableLock = 0;
160441 }
160442#endif
160443#ifndef SQLITE_OMIT_VIRTUALTABLE
160444 sqlite3_free(pParse->apVtabLock);
160445#endif
160446
160447 if( !IN_SPECIAL_PARSE ){
160448 /* If the pParse->declareVtab flag is set, do not delete any table
160449 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
160450 ** will take responsibility for freeing the Table structure.
160451 */
160452 sqlite3DeleteTable(db, pParse->pNewTable);
160453 }
160454 if( !IN_RENAME_OBJECT ){
160455 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
160456 }
160457
160458 if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
160459 sqlite3DbFree(db, pParse->pVList);
160460 while( pParse->pAinc ){
160461 AutoincInfo *p = pParse->pAinc;
160462 pParse->pAinc = p->pNext;
160463 sqlite3DbFreeNN(db, p);
160464 }
160465 while( pParse->pZombieTab ){
160466 Table *p = pParse->pZombieTab;
160467 pParse->pZombieTab = p->pNextZombie;
160468 sqlite3DeleteTable(db, p);
SQLITE_PRIVATE void sqlite3WithDelete(sqlite3 *, With *)
Definition sqlite3.c:115521
SQLITE_PRIVATE void sqlite3ParserFinalize(void *p)
Definition sqlite3.c:156409
SQLITE_PRIVATE void sqlite3ParserInit(void *yypRawParser sqlite3ParserCTX_PDECL)
Definition sqlite3.c:156209
static int analyzeOverKeyword(const unsigned char *z, int lastToken)
Definition sqlite3.c:159989
static int analyzeFilterKeyword(const unsigned char *z, int lastToken)
Definition sqlite3.c:159996
#define SQLITE_STATUS_PARSER_STACK
Definition sqlite3.c:9056
Parse * pParentParse
Definition sqlite3.c:18720
With * pWithToFree
Definition sqlite3.c:18775
TableLock * aTableLock
Definition sqlite3.c:18715
Parse * pParse
Definition sqlite3.c:16886

References sqlite3_str::accError, sqlite3::aLimit, analyzeFilterKeyword(), analyzeOverKeyword(), analyzeWindowKeyword(), Parse::apVtabLock, Parse::aTableLock, AtomicLoad, AtomicStore, Parse::db, eType, sqlite3::flags, IN_RENAME_OBJECT, IN_SPECIAL_PARSE, sqlite3::isInterrupted, sqlite3::mallocFailed, Token::n, sqlite3_str::nChar, Parse::nErr, Parse::nested, NEVER, Parse::nTableLock, Parse::nVar, sqlite3::nVdbeActive, Parse::pAinc, Parse::pNewTable, Parse::pNewTrigger, AutoincInfo::pNext, Table::pNextZombie, Parse::pParentParse, sqlite3::pParse, printf, Parse::pVdbe, Parse::pVList, Parse::pWithToFree, Parse::pZombieTab, Parse::rc, Parse::sLastToken, sqlite3_free(), sqlite3_log(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_str_append(), sqlite3_str_appendf(), sqlite3_str_finish(), sqlite3_str_new(), sqlite3DbFree(), sqlite3DbFreeNN(), sqlite3DbStrNDup(), sqlite3DeleteTable(), sqlite3DeleteTrigger(), sqlite3Dequote(), sqlite3ErrorMsg(), sqlite3ErrStr(), sqlite3GetToken(), sqlite3IsIdChar(), sqlite3Isquote, sqlite3Malloc(), sqlite3MallocMutex(), sqlite3MPrintf(), sqlite3OomFault(), sqlite3Parser(), sqlite3ParserFinalize(), sqlite3ParserInit(), sqlite3StatusHighwater(), sqlite3Strlen30(), sqlite3Tolower, sqlite3Toupper, sqlite3VdbeDb(), sqlite3VdbeDelete(), sqlite3WithDelete(), SQLITE_DONE, SQLITE_INTERRUPT, SQLITE_LIMIT_SQL_LENGTH, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_PRIVATE, SQLITE_STATUS_PARSER_STACK, SQLITE_TOOBIG, TK_BLOB, TK_FILTER, TK_FLOAT, TK_ID, TK_ILLEGAL, TK_IN, TK_INTEGER, TK_IS, TK_LP, TK_NOT, TK_NULL, TK_OVER, TK_RP, TK_SELECT, TK_SEMI, TK_SPACE, TK_STRING, TK_VARIABLE, TK_WINDOW, sqlite3::u1, VVA_ONLY, Token::z, Parse::zErrMsg, Parse::zTail, and sqlite3_str::zText.

Referenced by renameParseSql(), sqlite3_declare_vtab(), and sqlite3NestedParse().

◆ sqlite3RunVacuum()

SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum ( char ** pzErrMsg,
sqlite3 * db,
int iDb,
sqlite3_value * pOut )

Definition at line 139307 of file sqlite3.c.

139318 {
139319 int rc = SQLITE_OK; /* Return code from service routines */
139320 Btree *pMain; /* The database being vacuumed */
139321 Btree *pTemp; /* The temporary database we vacuum into */
139322 u32 saved_mDbFlags; /* Saved value of db->mDbFlags */
139323 u64 saved_flags; /* Saved value of db->flags */
139324 int saved_nChange; /* Saved value of db->nChange */
139325 int saved_nTotalChange; /* Saved value of db->nTotalChange */
139326 u32 saved_openFlags; /* Saved value of db->openFlags */
139327 u8 saved_mTrace; /* Saved trace settings */
139328 Db *pDb = 0; /* Database to detach at end of vacuum */
139329 int isMemDb; /* True if vacuuming a :memory: database */
139330 int nRes; /* Bytes of reserved space at the end of each page */
139331 int nDb; /* Number of attached databases */
139332 const char *zDbMain; /* Schema name of database to vacuum */
139333 const char *zOut; /* Name of output file */
139334
139335 if( !db->autoCommit ){
139336 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
139337 return SQLITE_ERROR; /* IMP: R-12218-18073 */
139338 }
139339 if( db->nVdbeActive>1 ){
139340 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
139341 return SQLITE_ERROR; /* IMP: R-15610-35227 */
139342 }
139343 saved_openFlags = db->openFlags;
139344 if( pOut ){
139345 if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
139346 sqlite3SetString(pzErrMsg, db, "non-text filename");
139347 return SQLITE_ERROR;
139348 }
139349 zOut = (const char*)sqlite3_value_text(pOut);
139350 db->openFlags &= ~SQLITE_OPEN_READONLY;
139352 }else{
139353 zOut = "";
139354 }
139355
139356 /* Save the current value of the database flags so that it can be
139357 ** restored before returning. Then set the writable-schema flag, and
139358 ** disable CHECK and foreign key constraints. */
139359 saved_flags = db->flags;
139360 saved_mDbFlags = db->mDbFlags;
139361 saved_nChange = db->nChange;
139362 saved_nTotalChange = db->nTotalChange;
139363 saved_mTrace = db->mTrace;
139368 db->mTrace = 0;
139369
139370 zDbMain = db->aDb[iDb].zDbSName;
139371 pMain = db->aDb[iDb].pBt;
139372 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
139373
139374 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
139375 ** can be set to 'off' for this file, as it is not recovered if a crash
139376 ** occurs anyway. The integrity of the database is maintained by a
139377 ** (possibly synchronous) transaction opened on the main database before
139378 ** sqlite3BtreeCopyFile() is called.
139379 **
139380 ** An optimisation would be to use a non-journaled pager.
139381 ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but
139382 ** that actually made the VACUUM run slower. Very little journalling
139383 ** actually occurs when doing a vacuum since the vacuum_db is initially
139384 ** empty. Only the journal header is written. Apparently it takes more
139385 ** time to parse and run the PRAGMA to turn journalling off than it does
139386 ** to write the journal header file.
139387 */
139388 nDb = db->nDb;
139389 rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
139390 db->openFlags = saved_openFlags;
139391 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139392 assert( (db->nDb-1)==nDb );
139393 pDb = &db->aDb[nDb];
139394 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
139395 pTemp = pDb->pBt;
139396 if( pOut ){
139398 i64 sz = 0;
139399 if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
139400 rc = SQLITE_ERROR;
139401 sqlite3SetString(pzErrMsg, db, "output file already exists");
139402 goto end_of_vacuum;
139403 }
139405 }
139406 nRes = sqlite3BtreeGetRequestedReserve(pMain);
139407
139411
139412 /* Begin a transaction and take an exclusive lock on the main database
139413 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
139414 ** to ensure that we do not try to change the page-size on a WAL database.
139415 */
139416 rc = execSql(db, pzErrMsg, "BEGIN");
139417 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139418 rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
139419 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139420
139421 /* Do not attempt to change the page size for a WAL database */
139424 db->nextPagesize = 0;
139425 }
139426
139427 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
139428 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
139429 || NEVER(db->mallocFailed)
139430 ){
139431 rc = SQLITE_NOMEM_BKPT;
139432 goto end_of_vacuum;
139433 }
139434
139435#ifndef SQLITE_OMIT_AUTOVACUUM
139438#endif
139439
139440 /* Query the schema of the main database. Create a mirror schema
139441 ** in the temporary database.
139442 */
139443 db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
139444 rc = execSqlF(db, pzErrMsg,
139445 "SELECT sql FROM \"%w\".sqlite_schema"
139446 " WHERE type='table'AND name<>'sqlite_sequence'"
139447 " AND coalesce(rootpage,1)>0",
139448 zDbMain
139449 );
139450 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139451 rc = execSqlF(db, pzErrMsg,
139452 "SELECT sql FROM \"%w\".sqlite_schema"
139453 " WHERE type='index'",
139454 zDbMain
139455 );
139456 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139457 db->init.iDb = 0;
139458
139459 /* Loop through the tables in the main database. For each, do
139460 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
139461 ** the contents to the temporary database.
139462 */
139463 rc = execSqlF(db, pzErrMsg,
139464 "SELECT'INSERT INTO vacuum_db.'||quote(name)"
139465 "||' SELECT*FROM\"%w\".'||quote(name)"
139466 "FROM vacuum_db.sqlite_schema "
139467 "WHERE type='table'AND coalesce(rootpage,1)>0",
139468 zDbMain
139469 );
139470 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
139471 db->mDbFlags &= ~DBFLAG_Vacuum;
139472 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139473
139474 /* Copy the triggers, views, and virtual tables from the main database
139475 ** over to the temporary database. None of these objects has any
139476 ** associated storage, so all we have to do is copy their entries
139477 ** from the schema table.
139478 */
139479 rc = execSqlF(db, pzErrMsg,
139480 "INSERT INTO vacuum_db.sqlite_schema"
139481 " SELECT*FROM \"%w\".sqlite_schema"
139482 " WHERE type IN('view','trigger')"
139483 " OR(type='table'AND rootpage=0)",
139484 zDbMain
139485 );
139486 if( rc ) goto end_of_vacuum;
139487
139488 /* At this point, there is a write transaction open on both the
139489 ** vacuum database and the main database. Assuming no error occurs,
139490 ** both transactions are closed by this block - the main database
139491 ** transaction by sqlite3BtreeCopyFile() and the other by an explicit
139492 ** call to sqlite3BtreeCommit().
139493 */
139494 {
139495 u32 meta;
139496 int i;
139497
139498 /* This array determines which meta meta values are preserved in the
139499 ** vacuum. Even entries are the meta value number and odd entries
139500 ** are an increment to apply to the meta value after the vacuum.
139501 ** The increment is used to increase the schema cookie so that other
139502 ** connections to the same database will know to reread the schema.
139503 */
139504 static const unsigned char aCopy[] = {
139505 BTREE_SCHEMA_VERSION, 1, /* Add one to the old schema cookie */
139506 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
139507 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
139508 BTREE_USER_VERSION, 0, /* Preserve the user version */
139509 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
139510 };
139511
139512 assert( 1==sqlite3BtreeIsInTrans(pTemp) );
139513 assert( pOut!=0 || 1==sqlite3BtreeIsInTrans(pMain) );
139514
139515 /* Copy Btree meta values */
139516 for(i=0; i<ArraySize(aCopy); i+=2){
139517 /* GetMeta() and UpdateMeta() cannot fail in this context because
139518 ** we already have page 1 loaded into cache and marked dirty. */
139519 sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
139520 rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
139521 if( NEVER(rc!=SQLITE_OK) ) goto end_of_vacuum;
139522 }
139523
139524 if( pOut==0 ){
139525 rc = sqlite3BtreeCopyFile(pMain, pTemp);
139526 }
139527 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139528 rc = sqlite3BtreeCommit(pTemp);
139529 if( rc!=SQLITE_OK ) goto end_of_vacuum;
139530#ifndef SQLITE_OMIT_AUTOVACUUM
139531 if( pOut==0 ){
139533 }
139534#endif
139535 }
139536
139537 assert( rc==SQLITE_OK );
139538 if( pOut==0 ){
139539 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
139540 }
139541
139542end_of_vacuum:
139543 /* Restore the original value of db->flags */
139544 db->init.iDb = 0;
139545 db->mDbFlags = saved_mDbFlags;
139546 db->flags = saved_flags;
139547 db->nChange = saved_nChange;
139548 db->nTotalChange = saved_nTotalChange;
139549 db->mTrace = saved_mTrace;
139550 sqlite3BtreeSetPageSize(pMain, -1, 0, 1);
139551
139552 /* Currently there is an SQL level transaction open on the vacuum
139553 ** database. No locks are held on any other files (since the main file
139554 ** was committed at the btree level). So it safe to end the transaction
139555 ** by manually setting the autoCommit flag to true and detaching the
139556 ** vacuum database. The vacuum_db journal file is deleted when the pager
139557 ** is closed by the DETACH.
139558 */
139559 db->autoCommit = 1;
139560
139561 if( pDb ){
139562 sqlite3BtreeClose(pDb->pBt);
139563 pDb->pBt = 0;
139564 pDb->pSchema = 0;
139565 }
139566
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *)
Definition sqlite3.c:75772
#define DBFLAG_VacuumInto
Definition sqlite3.c:17031
#define BTREE_APPLICATION_ID
Definition sqlite3.c:15149
#define BTREE_USER_VERSION
Definition sqlite3.c:15147
int nChange
Definition sqlite3.c:16851
int nTotalChange
Definition sqlite3.c:16852

Referenced by sqlite3VdbeExec().

◆ sqlite3SafetyCheckOk()

◆ sqlite3SafetyCheckSickOrOk()

SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk ( sqlite3 * db)

Definition at line 32559 of file sqlite3.c.

32561 {
32562 return 1;
32563 }
32564}
32566 u32 magic;
32567 magic = db->magic;
32568 if( magic!=SQLITE_MAGIC_SICK &&
32569 magic!=SQLITE_MAGIC_OPEN &&
32570 magic!=SQLITE_MAGIC_BUSY ){
32571 testcase( sqlite3GlobalConfig.xLog!=0 );

Referenced by sqlite3_errcode(), sqlite3_errmsg16(), and sqlite3SafetyCheckOk().

◆ sqlite3Savepoint()

SQLITE_PRIVATE void sqlite3Savepoint ( Parse * pParse,
int op,
Token * pName )

Definition at line 115071 of file sqlite3.c.

115077 {
115078 char *zName = sqlite3NameFromToken(pParse->db, pName);
115079 if( zName ){
115080 Vdbe *v = sqlite3GetVdbe(pParse);
115081#ifndef SQLITE_OMIT_AUTHORIZATION
115082 static const char * const az[] = { "BEGIN", "RELEASE", "ROLLBACK" };
115084#endif
115085 if( !v || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName, 0) ){
#define SQLITE_SAVEPOINT
Definition sqlite3.c:4151
#define SAVEPOINT_BEGIN
Definition sqlite3.c:17295

Referenced by yy_reduce().

◆ sqlite3SchemaClear()

SQLITE_PRIVATE void sqlite3SchemaClear ( void * p)

Definition at line 116023 of file sqlite3.c.

116029 {
116030 Hash temp1;
116031 Hash temp2;
116032 HashElem *pElem;
116033 Schema *pSchema = (Schema *)p;
116034
116035 temp1 = pSchema->tblHash;
116036 temp2 = pSchema->trigHash;
116037 sqlite3HashInit(&pSchema->trigHash);
116038 sqlite3HashClear(&pSchema->idxHash);
116039 for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
116041 }
116042 sqlite3HashClear(&temp2);
116043 sqlite3HashInit(&pSchema->tblHash);
116044 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
116045 Table *pTab = sqliteHashData(pElem);
116046 sqlite3DeleteTable(0, pTab);
116047 }
116048 sqlite3HashClear(&temp1);
116049 sqlite3HashClear(&pSchema->fkeyHash);

References DB_ResetWanted, DB_SchemaLoaded, Schema::fkeyHash, Schema::idxHash, Schema::iGeneration, Schema::pSeqTab, Schema::schemaFlags, sqlite3DeleteTable(), sqlite3DeleteTrigger(), sqlite3HashClear(), sqlite3HashInit(), sqliteHashData, sqliteHashFirst, sqliteHashNext, Schema::tblHash, and Schema::trigHash.

Referenced by sqlite3LeaveMutexAndCloseZombie(), sqlite3ResetOneSchema(), and sqlite3VdbeExec().

◆ sqlite3SchemaGet()

SQLITE_PRIVATE Schema * sqlite3SchemaGet ( sqlite3 * db,
Btree * pBt )

Definition at line 116055 of file sqlite3.c.

116061 {
116062 Schema * p;
116063 if( pBt ){
116064 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear);
116065 }else{
116066 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
116067 }
116068 if( !p ){
116069 sqlite3OomFault(db);
116070 }else if ( 0==p->file_format ){

Referenced by attachFunc(), and openDatabase().

◆ sqlite3SchemaToIndex()

SQLITE_PRIVATE int sqlite3SchemaToIndex ( sqlite3 * db,
Schema * pSchema )

Definition at line 128852 of file sqlite3.c.

128858 {
128859 int i = -32768;
128860
128861 /* If pSchema is NULL, then return -32768. This happens when code in
128862 ** expr.c is trying to resolve a reference to a transient table (i.e. one
128863 ** created by a sub-select). In this case the return value of this
128864 ** function should never be used.
128865 **
128866 ** We return -32768 instead of the more usual -1 simply because using
128867 ** -32768 as the incorrect index into db->aDb[] is much
128868 ** more likely to cause a segfault than -1 (of course there are assert()
128869 ** statements too, but it never hurts to play the odds) and
128870 ** -32768 will still fit into a 16-bit signed integer.
128871 */
128872 assert( sqlite3_mutex_held(db->mutex) );
128873 if( pSchema ){
128874 for(i=0; 1; i++){
128875 assert( i<db->nDb );
128876 if( db->aDb[i].pSchema==pSchema ){
128877 break;

References sqlite3::aDb, sqlite3::mutex, Db::pSchema, and sqlite3_mutex_held().

Referenced by analyzeOneTable(), analyzeTable(), columnTypeImpl(), destroyTable(), generateSortTail(), reindexTable(), renameResolveTrigger(), renameTableTest(), selectExpander(), sqlite3AlterBeginAddColumn(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3AuthRead(), sqlite3BeginTrigger(), sqlite3CreateIndex(), sqlite3DeleteFrom(), sqlite3EndTable(), sqlite3FindInIndex(), sqlite3FkCheck(), sqlite3Insert(), sqlite3LocateTableItem(), sqlite3MaterializeView(), sqlite3OpenTableAndIndices(), sqlite3Pragma(), sqlite3RefillIndex(), sqlite3Select(), sqlite3Update(), sqlite3VtabBeginParse(), sqlite3WhereBegin(), vtabCallConstructor(), and xferOptimization().

◆ sqlite3SectorSize()

SQLITE_PRIVATE int sqlite3SectorSize ( sqlite3_file * pFile)

Definition at line 54333 of file sqlite3.c.

54339 {
54340 int iRet = sqlite3OsSectorSize(pFile);
54341 if( iRet<32 ){
54342 iRet = 512;
SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id)
Definition sqlite3.c:23113

Referenced by setSectorSize().

◆ sqlite3Select()

SQLITE_PRIVATE int sqlite3Select ( Parse * pParse,
Select * p,
SelectDest * pDest )

Definition at line 135064 of file sqlite3.c.

135074 {
135075 int i, j; /* Loop counters */
135076 WhereInfo *pWInfo; /* Return from sqlite3WhereBegin() */
135077 Vdbe *v; /* The virtual machine under construction */
135078 int isAgg; /* True for select lists like "count(*)" */
135079 ExprList *pEList = 0; /* List of columns to extract. */
135080 SrcList *pTabList; /* List of tables to select from */
135081 Expr *pWhere; /* The WHERE clause. May be NULL */
135082 ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */
135083 Expr *pHaving; /* The HAVING clause. May be NULL */
135084 AggInfo *pAggInfo = 0; /* Aggregate information */
135085 int rc = 1; /* Value to return from this function */
135086 DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */
135087 SortCtx sSort; /* Info on how to code the ORDER BY clause */
135088 int iEnd; /* Address of the end of the query */
135089 sqlite3 *db; /* The database connection */
135090 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
135091 u8 minMaxFlag; /* Flag for min/max queries */
135092
135093 db = pParse->db;
135094 v = sqlite3GetVdbe(pParse);
135095 if( p==0 || db->mallocFailed || pParse->nErr ){
135096 return 1;
135097 }
135098 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
135099#if SELECTTRACE_ENABLED
135100 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
135101 if( sqlite3_unsupported_selecttrace & 0x100 ){
135102 sqlite3TreeViewSelect(0, p, 0);
135103 }
135104#endif
135105
135106 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
135107 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
135108 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
135109 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
135110 if( IgnorableOrderby(pDest) ){
135111 assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union ||
135112 pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard ||
135113 pDest->eDest==SRT_Queue || pDest->eDest==SRT_DistFifo ||
135114 pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_Fifo);
135115 /* If ORDER BY makes no difference in the output then neither does
135116 ** DISTINCT so it can be removed too. */
135118 p->pOrderBy = 0;
135119 p->selFlags &= ~SF_Distinct;
135120 p->selFlags |= SF_NoopOrderBy;
135121 }
135122 sqlite3SelectPrep(pParse, p, 0);
135123 if( pParse->nErr || db->mallocFailed ){
135124 goto select_end;
135125 }
135126 assert( p->pEList!=0 );
135127#if SELECTTRACE_ENABLED
135128 if( sqlite3_unsupported_selecttrace & 0x104 ){
135129 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
135130 sqlite3TreeViewSelect(0, p, 0);
135131 }
135132#endif
135133
135134 /* If the SF_UpdateFrom flag is set, then this function is being called
135135 ** as part of populating the temp table for an UPDATE...FROM statement.
135136 ** In this case, it is an error if the target object (pSrc->a[0]) name
135137 ** or alias is duplicated within FROM clause (pSrc->a[1..n]). */
135138 if( p->selFlags & SF_UpdateFrom ){
135139 struct SrcList_item *p0 = &p->pSrc->a[0];
135140 for(i=1; i<p->pSrc->nSrc; i++){
135141 struct SrcList_item *p1 = &p->pSrc->a[i];
135142 if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
135143 sqlite3ErrorMsg(pParse,
135144 "target object/alias may not appear in FROM clause: %s",
135145 p0->zAlias ? p0->zAlias : p0->pTab->zName
135146 );
135147 goto select_end;
135148 }
135149 }
135150 }
135151
135152 if( pDest->eDest==SRT_Output ){
135153 generateColumnNames(pParse, p);
135154 }
135155
135156#ifndef SQLITE_OMIT_WINDOWFUNC
135157 rc = sqlite3WindowRewrite(pParse, p);
135158 if( rc ){
135159 assert( db->mallocFailed || pParse->nErr>0 );
135160 goto select_end;
135161 }
135162#if SELECTTRACE_ENABLED
135163 if( p->pWin && (sqlite3_unsupported_selecttrace & 0x108)!=0 ){
135164 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
135165 sqlite3TreeViewSelect(0, p, 0);
135166 }
135167#endif
135168#endif /* SQLITE_OMIT_WINDOWFUNC */
135169 pTabList = p->pSrc;
135170 isAgg = (p->selFlags & SF_Aggregate)!=0;
135171 memset(&sSort, 0, sizeof(sSort));
135172 sSort.pOrderBy = p->pOrderBy;
135173
135174 /* Try to do various optimizations (flattening subqueries, and strength
135175 ** reduction of join operators) in the FROM clause up into the main query
135176 */
135177#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
135178 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
135179 struct SrcList_item *pItem = &pTabList->a[i];
135180 Select *pSub = pItem->pSelect;
135181 Table *pTab = pItem->pTab;
135182
135183 /* The expander should have already created transient Table objects
135184 ** even for FROM clause elements such as subqueries that do not correspond
135185 ** to a real table */
135186 assert( pTab!=0 );
135187
135188 /* Convert LEFT JOIN into JOIN if there are terms of the right table
135189 ** of the LEFT JOIN used in the WHERE clause.
135190 */
135191 if( (pItem->fg.jointype & JT_LEFT)!=0
135192 && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor)
135194 ){
135195 SELECTTRACE(0x100,pParse,p,
135196 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
135197 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
135198 unsetJoinExpr(p->pWhere, pItem->iCursor);
135199 }
135200
135201 /* No futher action if this term of the FROM clause is no a subquery */
135202 if( pSub==0 ) continue;
135203
135204 /* Catch mismatch in the declared columns of a view and the number of
135205 ** columns in the SELECT on the RHS */
135206 if( pTab->nCol!=pSub->pEList->nExpr ){
135207 sqlite3ErrorMsg(pParse, "expected %d columns for '%s' but got %d",
135208 pTab->nCol, pTab->zName, pSub->pEList->nExpr);
135209 goto select_end;
135210 }
135211
135212 /* Do not try to flatten an aggregate subquery.
135213 **
135214 ** Flattening an aggregate subquery is only possible if the outer query
135215 ** is not a join. But if the outer query is not a join, then the subquery
135216 ** will be implemented as a co-routine and there is no advantage to
135217 ** flattening in that case.
135218 */
135219 if( (pSub->selFlags & SF_Aggregate)!=0 ) continue;
135220 assert( pSub->pGroupBy==0 );
135221
135222 /* If the outer query contains a "complex" result set (that is,
135223 ** if the result set of the outer query uses functions or subqueries)
135224 ** and if the subquery contains an ORDER BY clause and if
135225 ** it will be implemented as a co-routine, then do not flatten. This
135226 ** restriction allows SQL constructs like this:
135227 **
135228 ** SELECT expensive_function(x)
135229 ** FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
135230 **
135231 ** The expensive_function() is only computed on the 10 rows that
135232 ** are output, rather than every row of the table.
135233 **
135234 ** The requirement that the outer query have a complex result set
135235 ** means that flattening does occur on simpler SQL constraints without
135236 ** the expensive_function() like:
135237 **
135238 ** SELECT x FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
135239 */
135240 if( pSub->pOrderBy!=0
135241 && i==0
135242 && (p->selFlags & SF_ComplexResult)!=0
135243 && (pTabList->nSrc==1
135244 || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0)
135245 ){
135246 continue;
135247 }
135248
135249 if( flattenSubquery(pParse, p, i, isAgg) ){
135250 if( pParse->nErr ) goto select_end;
135251 /* This subquery can be absorbed into its parent. */
135252 i = -1;
135253 }
135254 pTabList = p->pSrc;
135255 if( db->mallocFailed ) goto select_end;
135256 if( !IgnorableOrderby(pDest) ){
135257 sSort.pOrderBy = p->pOrderBy;
135258 }
135259 }
135260#endif
135261
135262#ifndef SQLITE_OMIT_COMPOUND_SELECT
135263 /* Handle compound SELECT statements using the separate multiSelect()
135264 ** procedure.
135265 */
135266 if( p->pPrior ){
135267 rc = multiSelect(pParse, p, pDest);
135268#if SELECTTRACE_ENABLED
135269 SELECTTRACE(0x1,pParse,p,("end compound-select processing\n"));
135270 if( (sqlite3_unsupported_selecttrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
135271 sqlite3TreeViewSelect(0, p, 0);
135272 }
135273#endif
135274 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
135275 return rc;
135276 }
135277#endif
135278
135279 /* Do the WHERE-clause constant propagation optimization if this is
135280 ** a join. No need to speed time on this operation for non-join queries
135281 ** as the equivalent optimization will be handled by query planner in
135282 ** sqlite3WhereBegin().
135283 */
135284 if( pTabList->nSrc>1
135286 && propagateConstants(pParse, p)
135287 ){
135288#if SELECTTRACE_ENABLED
135289 if( sqlite3_unsupported_selecttrace & 0x100 ){
135290 SELECTTRACE(0x100,pParse,p,("After constant propagation:\n"));
135291 sqlite3TreeViewSelect(0, p, 0);
135292 }
135293#endif
135294 }else{
135295 SELECTTRACE(0x100,pParse,p,("Constant propagation not helpful\n"));
135296 }
135297
135298#ifdef SQLITE_COUNTOFVIEW_OPTIMIZATION
135300 && countOfViewOptimization(pParse, p)
135301 ){
135302 if( db->mallocFailed ) goto select_end;
135303 pEList = p->pEList;
135304 pTabList = p->pSrc;
135305 }
135306#endif
135307
135308 /* For each term in the FROM clause, do two things:
135309 ** (1) Authorized unreferenced tables
135310 ** (2) Generate code for all sub-queries
135311 */
135312 for(i=0; i<pTabList->nSrc; i++){
135313 struct SrcList_item *pItem = &pTabList->a[i];
135314 SelectDest dest;
135315 Select *pSub;
135316#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
135317 const char *zSavedAuthContext;
135318#endif
135319
135320 /* Issue SQLITE_READ authorizations with a fake column name for any
135321 ** tables that are referenced but from which no values are extracted.
135322 ** Examples of where these kinds of null SQLITE_READ authorizations
135323 ** would occur:
135324 **
135325 ** SELECT count(*) FROM t1; -- SQLITE_READ t1.""
135326 ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2.""
135327 **
135328 ** The fake column name is an empty string. It is possible for a table to
135329 ** have a column named by the empty string, in which case there is no way to
135330 ** distinguish between an unreferenced table and an actual reference to the
135331 ** "" column. The original design was for the fake column name to be a NULL,
135332 ** which would be unambiguous. But legacy authorization callbacks might
135333 ** assume the column name is non-NULL and segfault. The use of an empty
135334 ** string for the fake column name seems safer.
135335 */
135336 if( pItem->colUsed==0 && pItem->zName!=0 ){
135337 sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase);
135338 }
135339
135340#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
135341 /* Generate code for all sub-queries in the FROM clause
135342 */
135343 pSub = pItem->pSelect;
135344 if( pSub==0 ) continue;
135345
135346 /* The code for a subquery should only be generated once, though it is
135347 ** technically harmless for it to be generated multiple times. The
135348 ** following assert() will detect if something changes to cause
135349 ** the same subquery to be coded multiple times, as a signal to the
135350 ** developers to try to optimize the situation.
135351 **
135352 ** Update 2019-07-24:
135353 ** See ticket https://sqlite.org/src/tktview/c52b09c7f38903b1311cec40.
135354 ** The dbsqlfuzz fuzzer found a case where the same subquery gets
135355 ** coded twice. So this assert() now becomes a testcase(). It should
135356 ** be very rare, though.
135357 */
135358 testcase( pItem->addrFillSub!=0 );
135359
135360 /* Increment Parse.nHeight by the height of the largest expression
135361 ** tree referred to by this, the parent select. The child select
135362 ** may contain expression trees of at most
135363 ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
135364 ** more conservative than necessary, but much easier than enforcing
135365 ** an exact limit.
135366 */
135367 pParse->nHeight += sqlite3SelectExprHeight(p);
135368
135369 /* Make copies of constant WHERE-clause terms in the outer query down
135370 ** inside the subquery. This can help the subquery to run more efficiently.
135371 */
135373 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
135374 (pItem->fg.jointype & JT_OUTER)!=0)
135375 ){
135376#if SELECTTRACE_ENABLED
135377 if( sqlite3_unsupported_selecttrace & 0x100 ){
135378 SELECTTRACE(0x100,pParse,p,
135379 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
135380 sqlite3TreeViewSelect(0, p, 0);
135381 }
135382#endif
135383 }else{
135384 SELECTTRACE(0x100,pParse,p,("Push-down not possible\n"));
135385 }
135386
135387 zSavedAuthContext = pParse->zAuthContext;
135388 pParse->zAuthContext = pItem->zName;
135389
135390 /* Generate code to implement the subquery
135391 **
135392 ** The subquery is implemented as a co-routine if the subquery is
135393 ** guaranteed to be the outer loop (so that it does not need to be
135394 ** computed more than once)
135395 **
135396 ** TODO: Are there other reasons beside (1) to use a co-routine
135397 ** implementation?
135398 */
135399 if( i==0
135400 && (pTabList->nSrc==1
135401 || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0) /* (1) */
135402 ){
135403 /* Implement a co-routine that will return a single row of the result
135404 ** set on each invocation.
135405 */
135406 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
135407
135408 pItem->regReturn = ++pParse->nMem;
135409 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
135410 VdbeComment((v, "%s", pItem->pTab->zName));
135411 pItem->addrFillSub = addrTop;
135412 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
135413 ExplainQueryPlan((pParse, 1, "CO-ROUTINE %u", pSub->selId));
135414 sqlite3Select(pParse, pSub, &dest);
135415 pItem->pTab->nRowLogEst = pSub->nSelectRow;
135416 pItem->fg.viaCoroutine = 1;
135417 pItem->regResult = dest.iSdst;
135418 sqlite3VdbeEndCoroutine(v, pItem->regReturn);
135419 sqlite3VdbeJumpHere(v, addrTop-1);
135420 sqlite3ClearTempRegCache(pParse);
135421 }else{
135422 /* Generate a subroutine that will fill an ephemeral table with
135423 ** the content of this subquery. pItem->addrFillSub will point
135424 ** to the address of the generated subroutine. pItem->regReturn
135425 ** is a register allocated to hold the subroutine return address
135426 */
135427 int topAddr;
135428 int onceAddr = 0;
135429 int retAddr;
135430 struct SrcList_item *pPrior;
135431
135432 testcase( pItem->addrFillSub==0 ); /* Ticket c52b09c7f38903b1311 */
135433 pItem->regReturn = ++pParse->nMem;
135434 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
135435 pItem->addrFillSub = topAddr+1;
135436 if( pItem->fg.isCorrelated==0 ){
135437 /* If the subquery is not correlated and if we are not inside of
135438 ** a trigger, then we only need to compute the value of the subquery
135439 ** once. */
135440 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
135441 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
135442 }else{
135443 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
135444 }
135445 pPrior = isSelfJoinView(pTabList, pItem);
135446 if( pPrior ){
135447 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
135448 assert( pPrior->pSelect!=0 );
135449 pSub->nSelectRow = pPrior->pSelect->nSelectRow;
135450 }else{
135451 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
135452 ExplainQueryPlan((pParse, 1, "MATERIALIZE %u", pSub->selId));
135453 sqlite3Select(pParse, pSub, &dest);
135454 }
135455 pItem->pTab->nRowLogEst = pSub->nSelectRow;
135456 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
135457 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
135458 VdbeComment((v, "end %s", pItem->pTab->zName));
135459 sqlite3VdbeChangeP1(v, topAddr, retAddr);
135460 sqlite3ClearTempRegCache(pParse);
135461 }
135462 if( db->mallocFailed ) goto select_end;
135463 pParse->nHeight -= sqlite3SelectExprHeight(p);
135464 pParse->zAuthContext = zSavedAuthContext;
135465#endif
135466 }
135467
135468 /* Various elements of the SELECT copied into local variables for
135469 ** convenience */
135470 pEList = p->pEList;
135471 pWhere = p->pWhere;
135472 pGroupBy = p->pGroupBy;
135473 pHaving = p->pHaving;
135474 sDistinct.isTnct = (p->selFlags & SF_Distinct)!=0;
135475
135476#if SELECTTRACE_ENABLED
135477 if( sqlite3_unsupported_selecttrace & 0x400 ){
135478 SELECTTRACE(0x400,pParse,p,("After all FROM-clause analysis:\n"));
135479 sqlite3TreeViewSelect(0, p, 0);
135480 }
135481#endif
135482
135483 /* If the query is DISTINCT with an ORDER BY but is not an aggregate, and
135484 ** if the select-list is the same as the ORDER BY list, then this query
135485 ** can be rewritten as a GROUP BY. In other words, this:
135486 **
135487 ** SELECT DISTINCT xyz FROM ... ORDER BY xyz
135488 **
135489 ** is transformed to:
135490 **
135491 ** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
135492 **
135493 ** The second form is preferred as a single index (or temp-table) may be
135494 ** used for both the ORDER BY and DISTINCT processing. As originally
135495 ** written the query must use a temp-table for at least one of the ORDER
135496 ** BY and DISTINCT, and an index or separate temp-table for the other.
135497 */
135499 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
135500#ifndef SQLITE_OMIT_WINDOWFUNC
135501 && p->pWin==0
135502#endif
135503 ){
135504 p->selFlags &= ~SF_Distinct;
135505 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
135506 p->selFlags |= SF_Aggregate;
135507 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
135508 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
135509 ** original setting of the SF_Distinct flag, not the current setting */
135510 assert( sDistinct.isTnct );
135511
135512#if SELECTTRACE_ENABLED
135513 if( sqlite3_unsupported_selecttrace & 0x400 ){
135514 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
135515 sqlite3TreeViewSelect(0, p, 0);
135516 }
135517#endif
135518 }
135519
135520 /* If there is an ORDER BY clause, then create an ephemeral index to
135521 ** do the sorting. But this sorting ephemeral index might end up
135522 ** being unused if the data can be extracted in pre-sorted order.
135523 ** If that is the case, then the OP_OpenEphemeral instruction will be
135524 ** changed to an OP_Noop once we figure out that the sorting index is
135525 ** not needed. The sSort.addrSortIndex variable is used to facilitate
135526 ** that change.
135527 */
135528 if( sSort.pOrderBy ){
135529 KeyInfo *pKeyInfo;
135530 pKeyInfo = sqlite3KeyInfoFromExprList(
135531 pParse, sSort.pOrderBy, 0, pEList->nExpr);
135532 sSort.iECursor = pParse->nTab++;
135533 sSort.addrSortIndex =
135535 sSort.iECursor, sSort.pOrderBy->nExpr+1+pEList->nExpr, 0,
135536 (char*)pKeyInfo, P4_KEYINFO
135537 );
135538 }else{
135539 sSort.addrSortIndex = -1;
135540 }
135541
135542 /* If the output is destined for a temporary table, open that table.
135543 */
135544 if( pDest->eDest==SRT_EphemTab ){
135545 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
135546 }
135547
135548 /* Set the limiter.
135549 */
135550 iEnd = sqlite3VdbeMakeLabel(pParse);
135551 if( (p->selFlags & SF_FixedLimit)==0 ){
135552 p->nSelectRow = 320; /* 4 billion rows */
135553 }
135554 computeLimitRegisters(pParse, p, iEnd);
135555 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
135557 sSort.sortFlags |= SORTFLAG_UseSorter;
135558 }
135559
135560 /* Open an ephemeral index to use for the distinct set.
135561 */
135562 if( p->selFlags & SF_Distinct ){
135563 sDistinct.tabTnct = pParse->nTab++;
135565 sDistinct.tabTnct, 0, 0,
135566 (char*)sqlite3KeyInfoFromExprList(pParse, p->pEList,0,0),
135567 P4_KEYINFO);
135570 }else{
135571 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
135572 }
135573
135574 if( !isAgg && pGroupBy==0 ){
135575 /* No aggregate functions and no GROUP BY clause */
135576 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
135577 | (p->selFlags & SF_FixedLimit);
135578#ifndef SQLITE_OMIT_WINDOWFUNC
135579 Window *pWin = p->pWin; /* Main window object (or NULL) */
135580 if( pWin ){
135581 sqlite3WindowCodeInit(pParse, p);
135582 }
135583#endif
135584 assert( WHERE_USE_LIMIT==SF_FixedLimit );
135585
135586
135587 /* Begin the database scan. */
135588 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
135589 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
135590 p->pEList, wctrlFlags, p->nSelectRow);
135591 if( pWInfo==0 ) goto select_end;
135592 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
135594 }
135595 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
135596 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
135597 }
135598 if( sSort.pOrderBy ){
135599 sSort.nOBSat = sqlite3WhereIsOrdered(pWInfo);
135601 if( sSort.nOBSat==sSort.pOrderBy->nExpr ){
135602 sSort.pOrderBy = 0;
135603 }
135604 }
135605
135606 /* If sorting index that was created by a prior OP_OpenEphemeral
135607 ** instruction ended up not being needed, then change the OP_OpenEphemeral
135608 ** into an OP_Noop.
135609 */
135610 if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
135612 }
135613
135614 assert( p->pEList==pEList );
135615#ifndef SQLITE_OMIT_WINDOWFUNC
135616 if( pWin ){
135617 int addrGosub = sqlite3VdbeMakeLabel(pParse);
135618 int iCont = sqlite3VdbeMakeLabel(pParse);
135619 int iBreak = sqlite3VdbeMakeLabel(pParse);
135620 int regGosub = ++pParse->nMem;
135621
135622 sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub);
135623
135624 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
135625 sqlite3VdbeResolveLabel(v, addrGosub);
135626 VdbeNoopComment((v, "inner-loop subroutine"));
135627 sSort.labelOBLopt = 0;
135628 selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest, iCont, iBreak);
135629 sqlite3VdbeResolveLabel(v, iCont);
135630 sqlite3VdbeAddOp1(v, OP_Return, regGosub);
135631 VdbeComment((v, "end inner-loop subroutine"));
135632 sqlite3VdbeResolveLabel(v, iBreak);
135633 }else
135634#endif /* SQLITE_OMIT_WINDOWFUNC */
135635 {
135636 /* Use the standard inner loop. */
135637 selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest,
135639 sqlite3WhereBreakLabel(pWInfo));
135640
135641 /* End the database scan loop.
135642 */
135643 sqlite3WhereEnd(pWInfo);
135644 }
135645 }else{
135646 /* This case when there exist aggregate functions or a GROUP BY clause
135647 ** or both */
135648 NameContext sNC; /* Name context for processing aggregate information */
135649 int iAMem; /* First Mem address for storing current GROUP BY */
135650 int iBMem; /* First Mem address for previous GROUP BY */
135651 int iUseFlag; /* Mem address holding flag indicating that at least
135652 ** one row of the input to the aggregator has been
135653 ** processed */
135654 int iAbortFlag; /* Mem address which causes query abort if positive */
135655 int groupBySort; /* Rows come from source in GROUP BY order */
135656 int addrEnd; /* End of processing for this SELECT */
135657 int sortPTab = 0; /* Pseudotable used to decode sorting results */
135658 int sortOut = 0; /* Output register from the sorter */
135659 int orderByGrp = 0; /* True if the GROUP BY and ORDER BY are the same */
135660
135661 /* Remove any and all aliases between the result set and the
135662 ** GROUP BY clause.
135663 */
135664 if( pGroupBy ){
135665 int k; /* Loop counter */
135666 struct ExprList_item *pItem; /* For looping over expression in a list */
135667
135668 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
135669 pItem->u.x.iAlias = 0;
135670 }
135671 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
135672 pItem->u.x.iAlias = 0;
135673 }
135674 assert( 66==sqlite3LogEst(100) );
135675 if( p->nSelectRow>66 ) p->nSelectRow = 66;
135676
135677 /* If there is both a GROUP BY and an ORDER BY clause and they are
135678 ** identical, then it may be possible to disable the ORDER BY clause
135679 ** on the grounds that the GROUP BY will cause elements to come out
135680 ** in the correct order. It also may not - the GROUP BY might use a
135681 ** database index that causes rows to be grouped together as required
135682 ** but not actually sorted. Either way, record the fact that the
135683 ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
135684 ** variable. */
135685 if( sSort.pOrderBy && pGroupBy->nExpr==sSort.pOrderBy->nExpr ){
135686 int ii;
135687 /* The GROUP BY processing doesn't care whether rows are delivered in
135688 ** ASC or DESC order - only that each group is returned contiguously.
135689 ** So set the ASC/DESC flags in the GROUP BY to match those in the
135690 ** ORDER BY to maximize the chances of rows being delivered in an
135691 ** order that makes the ORDER BY redundant. */
135692 for(ii=0; ii<pGroupBy->nExpr; ii++){
135693 u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
135694 pGroupBy->a[ii].sortFlags = sortFlags;
135695 }
135696 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
135697 orderByGrp = 1;
135698 }
135699 }
135700 }else{
135701 assert( 0==sqlite3LogEst(1) );
135702 p->nSelectRow = 0;
135703 }
135704
135705 /* Create a label to jump to when we want to abort the query */
135706 addrEnd = sqlite3VdbeMakeLabel(pParse);
135707
135708 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
135709 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
135710 ** SELECT statement.
135711 */
135712 pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
135713 if( pAggInfo==0 ){
135714 goto select_end;
135715 }
135716 pAggInfo->pNext = pParse->pAggList;
135717 pParse->pAggList = pAggInfo;
135718 pAggInfo->selId = p->selId;
135719 memset(&sNC, 0, sizeof(sNC));
135720 sNC.pParse = pParse;
135721 sNC.pSrcList = pTabList;
135722 sNC.uNC.pAggInfo = pAggInfo;
135723 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
135724 pAggInfo->mnReg = pParse->nMem+1;
135725 pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
135726 pAggInfo->pGroupBy = pGroupBy;
135727 sqlite3ExprAnalyzeAggList(&sNC, pEList);
135728 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
135729 if( pHaving ){
135730 if( pGroupBy ){
135731 assert( pWhere==p->pWhere );
135732 assert( pHaving==p->pHaving );
135733 assert( pGroupBy==p->pGroupBy );
135734 havingToWhere(pParse, p);
135735 pWhere = p->pWhere;
135736 }
135737 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135738 }
135739 pAggInfo->nAccumulator = pAggInfo->nColumn;
135740 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
135741 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy);
135742 }else{
135743 minMaxFlag = WHERE_ORDERBY_NORMAL;
135744 }
135745 for(i=0; i<pAggInfo->nFunc; i++){
135746 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
135747 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135748 sNC.ncFlags |= NC_InAggFunc;
135749 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135750#ifndef SQLITE_OMIT_WINDOWFUNC
135751 assert( !IsWindowFunc(pExpr) );
135752 if( ExprHasProperty(pExpr, EP_WinFunc) ){
135754 }
135755#endif
135756 sNC.ncFlags &= ~NC_InAggFunc;
135757 }
135758 pAggInfo->mxReg = pParse->nMem;
135759 if( db->mallocFailed ) goto select_end;
135760#if SELECTTRACE_ENABLED
135761 if( sqlite3_unsupported_selecttrace & 0x400 ){
135762 int ii;
135763 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
135764 sqlite3TreeViewSelect(0, p, 0);
135765 for(ii=0; ii<pAggInfo->nColumn; ii++){
135766 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135767 ii, pAggInfo->aCol[ii].iMem);
135768 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
135769 }
135770 for(ii=0; ii<pAggInfo->nFunc; ii++){
135771 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135772 ii, pAggInfo->aFunc[ii].iMem);
135773 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
135774 }
135775 }
135776#endif
135777
135778
135779 /* Processing for aggregates with GROUP BY is very different and
135780 ** much more complex than aggregates without a GROUP BY.
135781 */
135782 if( pGroupBy ){
135783 KeyInfo *pKeyInfo; /* Keying information for the group by clause */
135784 int addr1; /* A-vs-B comparision jump */
135785 int addrOutputRow; /* Start of subroutine that outputs a result row */
135786 int regOutputRow; /* Return address register for output subroutine */
135787 int addrSetAbort; /* Set the abort flag and return */
135788 int addrTopOfLoop; /* Top of the input loop */
135789 int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
135790 int addrReset; /* Subroutine for resetting the accumulator */
135791 int regReset; /* Return address register for reset subroutine */
135792
135793 /* If there is a GROUP BY clause we might need a sorting index to
135794 ** implement it. Allocate that sorting index now. If it turns out
135795 ** that we do not need it after all, the OP_SorterOpen instruction
135796 ** will be converted into a Noop.
135797 */
135798 pAggInfo->sortingIdx = pParse->nTab++;
135799 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pGroupBy,
135800 0, pAggInfo->nColumn);
135801 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
135802 pAggInfo->sortingIdx, pAggInfo->nSortingColumn,
135803 0, (char*)pKeyInfo, P4_KEYINFO);
135804
135805 /* Initialize memory locations used by GROUP BY aggregate processing
135806 */
135807 iUseFlag = ++pParse->nMem;
135808 iAbortFlag = ++pParse->nMem;
135809 regOutputRow = ++pParse->nMem;
135810 addrOutputRow = sqlite3VdbeMakeLabel(pParse);
135811 regReset = ++pParse->nMem;
135812 addrReset = sqlite3VdbeMakeLabel(pParse);
135813 iAMem = pParse->nMem + 1;
135814 pParse->nMem += pGroupBy->nExpr;
135815 iBMem = pParse->nMem + 1;
135816 pParse->nMem += pGroupBy->nExpr;
135817 sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
135818 VdbeComment((v, "clear abort flag"));
135819 sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);
135820
135821 /* Begin a loop that will extract all source rows in GROUP BY order.
135822 ** This might involve two separate loops with an OP_Sort in between, or
135823 ** it might be a single loop that uses an index to extract information
135824 ** in the right order to begin with.
135825 */
135826 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
135827 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
135828 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0,
135829 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0
135830 );
135831 if( pWInfo==0 ) goto select_end;
135832 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
135833 /* The optimizer is able to deliver rows in group by order so
135834 ** we do not have to sort. The OP_OpenEphemeral table will be
135835 ** cancelled later because we still need to use the pKeyInfo
135836 */
135837 groupBySort = 0;
135838 }else{
135839 /* Rows are coming out in undetermined order. We have to push
135840 ** each row into a sorting index, terminate the first loop,
135841 ** then loop over the sorting index in order to get the output
135842 ** in sorted order
135843 */
135844 int regBase;
135845 int regRecord;
135846 int nCol;
135847 int nGroupBy;
135848
135849 explainTempTable(pParse,
135850 (sDistinct.isTnct && (p->selFlags&SF_Distinct)==0) ?
135851 "DISTINCT" : "GROUP BY");
135852
135853 groupBySort = 1;
135854 nGroupBy = pGroupBy->nExpr;
135855 nCol = nGroupBy;
135856 j = nGroupBy;
135857 for(i=0; i<pAggInfo->nColumn; i++){
135858 if( pAggInfo->aCol[i].iSorterColumn>=j ){
135859 nCol++;
135860 j++;
135861 }
135862 }
135863 regBase = sqlite3GetTempRange(pParse, nCol);
135864 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
135865 j = nGroupBy;
135866 for(i=0; i<pAggInfo->nColumn; i++){
135867 struct AggInfo_col *pCol = &pAggInfo->aCol[i];
135868 if( pCol->iSorterColumn>=j ){
135869 int r1 = j + regBase;
135871 pCol->pTab, pCol->iTable, pCol->iColumn, r1);
135872 j++;
135873 }
135874 }
135875 regRecord = sqlite3GetTempReg(pParse);
135876 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
135877 sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
135878 sqlite3ReleaseTempReg(pParse, regRecord);
135879 sqlite3ReleaseTempRange(pParse, regBase, nCol);
135880 sqlite3WhereEnd(pWInfo);
135881 pAggInfo->sortingIdxPTab = sortPTab = pParse->nTab++;
135882 sortOut = sqlite3GetTempReg(pParse);
135883 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
135884 sqlite3VdbeAddOp2(v, OP_SorterSort, pAggInfo->sortingIdx, addrEnd);
135885 VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
135886 pAggInfo->useSortingIdx = 1;
135887 }
135888
135889 /* If the index or temporary table used by the GROUP BY sort
135890 ** will naturally deliver rows in the order required by the ORDER BY
135891 ** clause, cancel the ephemeral table open coded earlier.
135892 **
135893 ** This is an optimization - the correct answer should result regardless.
135894 ** Use the SQLITE_GroupByOrder flag with SQLITE_TESTCTRL_OPTIMIZER to
135895 ** disable this optimization for testing purposes. */
135896 if( orderByGrp && OptimizationEnabled(db, SQLITE_GroupByOrder)
135897 && (groupBySort || sqlite3WhereIsSorted(pWInfo))
135898 ){
135899 sSort.pOrderBy = 0;
135901 }
135902
135903 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
135904 ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
135905 ** Then compare the current GROUP BY terms against the GROUP BY terms
135906 ** from the previous row currently stored in a0, a1, a2...
135907 */
135908 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
135909 if( groupBySort ){
135911 sortOut, sortPTab);
135912 }
135913 for(j=0; j<pGroupBy->nExpr; j++){
135914 if( groupBySort ){
135915 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
135916 }else{
135917 pAggInfo->directMode = 1;
135918 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
135919 }
135920 }
135921 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
135922 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
135923 addr1 = sqlite3VdbeCurrentAddr(v);
135924 sqlite3VdbeAddOp3(v, OP_Jump, addr1+1, 0, addr1+1); VdbeCoverage(v);
135925
135926 /* Generate code that runs whenever the GROUP BY changes.
135927 ** Changes in the GROUP BY are detected by the previous code
135928 ** block. If there were no changes, this block is skipped.
135929 **
135930 ** This code copies current group by terms in b0,b1,b2,...
135931 ** over to a0,a1,a2. It then calls the output subroutine
135932 ** and resets the aggregate accumulator registers in preparation
135933 ** for the next GROUP BY batch.
135934 */
135935 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
135936 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
135937 VdbeComment((v, "output one row"));
135938 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
135939 VdbeComment((v, "check abort flag"));
135940 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
135941 VdbeComment((v, "reset accumulator"));
135942
135943 /* Update the aggregate accumulators based on the content of
135944 ** the current row
135945 */
135946 sqlite3VdbeJumpHere(v, addr1);
135947 updateAccumulator(pParse, iUseFlag, pAggInfo);
135948 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
135949 VdbeComment((v, "indicate data in accumulator"));
135950
135951 /* End of the loop
135952 */
135953 if( groupBySort ){
135954 sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx, addrTopOfLoop);
135955 VdbeCoverage(v);
135956 }else{
135957 sqlite3WhereEnd(pWInfo);
135958 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
135959 }
135960
135961 /* Output the final row of result
135962 */
135963 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
135964 VdbeComment((v, "output final row"));
135965
135966 /* Jump over the subroutines
135967 */
135968 sqlite3VdbeGoto(v, addrEnd);
135969
135970 /* Generate a subroutine that outputs a single row of the result
135971 ** set. This subroutine first looks at the iUseFlag. If iUseFlag
135972 ** is less than or equal to zero, the subroutine is a no-op. If
135973 ** the processing calls for the query to abort, this subroutine
135974 ** increments the iAbortFlag memory location before returning in
135975 ** order to signal the caller to abort.
135976 */
135977 addrSetAbort = sqlite3VdbeCurrentAddr(v);
135978 sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
135979 VdbeComment((v, "set abort flag"));
135980 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
135981 sqlite3VdbeResolveLabel(v, addrOutputRow);
135982 addrOutputRow = sqlite3VdbeCurrentAddr(v);
135983 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
135984 VdbeCoverage(v);
135985 VdbeComment((v, "Groupby result generator entry point"));
135986 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
135987 finalizeAggFunctions(pParse, pAggInfo);
135988 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
135989 selectInnerLoop(pParse, p, -1, &sSort,
135990 &sDistinct, pDest,
135991 addrOutputRow+1, addrSetAbort);
135992 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
135993 VdbeComment((v, "end groupby result generator"));
135994
135995 /* Generate a subroutine that will reset the group-by accumulator
135996 */
135997 sqlite3VdbeResolveLabel(v, addrReset);
135998 resetAccumulator(pParse, pAggInfo);
135999 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
136000 VdbeComment((v, "indicate accumulator empty"));
136001 sqlite3VdbeAddOp1(v, OP_Return, regReset);
136002
136003 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
136004 else {
136005 Table *pTab;
136006 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
136007 /* If isSimpleCount() returns a pointer to a Table structure, then
136008 ** the SQL statement is of the form:
136009 **
136010 ** SELECT count(*) FROM <tbl>
136011 **
136012 ** where the Table structure returned represents table <tbl>.
136013 **
136014 ** This statement is so common that it is optimized specially. The
136015 ** OP_Count instruction is executed either on the intkey table that
136016 ** contains the data for table <tbl> or on one of its indexes. It
136017 ** is better to execute the op on an index, as indexes are almost
136018 ** always spread across less pages than their corresponding tables.
136019 */
136020 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
136021 const int iCsr = pParse->nTab++; /* Cursor to scan b-tree */
136022 Index *pIdx; /* Iterator variable */
136023 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
136024 Index *pBest = 0; /* Best index found so far */
136025 Pgno iRoot = pTab->tnum; /* Root page of scanned b-tree */
136026
136027 sqlite3CodeVerifySchema(pParse, iDb);
136028 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
136029
136030 /* Search for the index that has the lowest scan cost.
136031 **
136032 ** (2011-04-15) Do not do a full scan of an unordered index.
136033 **
136034 ** (2013-10-03) Do not count the entries in a partial index.
136035 **
136036 ** In practice the KeyInfo structure will not be used. It is only
136037 ** passed to keep OP_OpenRead happy.
136038 */
136039 if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab);
136040 if( !p->pSrc->a[0].fg.notIndexed ){
136041 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
136042 if( pIdx->bUnordered==0
136043 && pIdx->szIdxRow<pTab->szTabRow
136044 && pIdx->pPartIdxWhere==0
136045 && (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
136046 ){
136047 pBest = pIdx;
136048 }
136049 }
136050 }
136051 if( pBest ){
136052 iRoot = pBest->tnum;
136053 pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest);
136054 }
136055
136056 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
136057 sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, (int)iRoot, iDb, 1);
136058 if( pKeyInfo ){
136059 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
136060 }
136061 sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
136062 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
136063 explainSimpleCount(pParse, pTab, pBest);
136064 }else{
136065 int regAcc = 0; /* "populate accumulators" flag */
136066 int addrSkip;
136067
136068 /* If there are accumulator registers but no min() or max() functions
136069 ** without FILTER clauses, allocate register regAcc. Register regAcc
136070 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
136071 ** The code generated by updateAccumulator() uses this to ensure
136072 ** that the accumulator registers are (a) updated only once if
136073 ** there are no min() or max functions or (b) always updated for the
136074 ** first row visited by the aggregate, so that they are updated at
136075 ** least once even if the FILTER clause means the min() or max()
136076 ** function visits zero rows. */
136077 if( pAggInfo->nAccumulator ){
136078 for(i=0; i<pAggInfo->nFunc; i++){
136079 if( ExprHasProperty(pAggInfo->aFunc[i].pFExpr, EP_WinFunc) ){
136080 continue;
136081 }
136082 if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
136083 break;
136084 }
136085 }
136086 if( i==pAggInfo->nFunc ){
136087 regAcc = ++pParse->nMem;
136088 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
136089 }
136090 }
136091
136092 /* This case runs if the aggregate has no GROUP BY clause. The
136093 ** processing is much simpler since there is only a single row
136094 ** of output.
136095 */
136096 assert( p->pGroupBy==0 );
136097 resetAccumulator(pParse, pAggInfo);
136098
136099 /* If this query is a candidate for the min/max optimization, then
136100 ** minMaxFlag will have been previously set to either
136101 ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
136102 ** be an appropriate ORDER BY expression for the optimization.
136103 */
136104 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
136105 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
136106
136107 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
136108 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
136109 0, minMaxFlag, 0);
136110 if( pWInfo==0 ){
136111 goto select_end;
136112 }
136113 updateAccumulator(pParse, regAcc, pAggInfo);
136114 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
136115 addrSkip = sqlite3WhereOrderByLimitOptLabel(pWInfo);
136116 if( addrSkip!=sqlite3WhereContinueLabel(pWInfo) ){
136117 sqlite3VdbeGoto(v, addrSkip);
136118 }
136119 sqlite3WhereEnd(pWInfo);
136120 finalizeAggFunctions(pParse, pAggInfo);
136121 }
136122
136123 sSort.pOrderBy = 0;
136124 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
136125 selectInnerLoop(pParse, p, -1, 0, 0,
136126 pDest, addrEnd, addrEnd);
136127 }
136128 sqlite3VdbeResolveLabel(v, addrEnd);
136129
136130 } /* endif aggregate query */
136131
136132 if( sDistinct.eTnctType==WHERE_DISTINCT_UNORDERED ){
136133 explainTempTable(pParse, "DISTINCT");
136134 }
136135
136136 /* If there is an ORDER BY clause, then we need to sort the results
136137 ** and send them to the callback one by one.
136138 */
136139 if( sSort.pOrderBy ){
136140 explainTempTable(pParse,
136141 sSort.nOBSat>0 ? "RIGHT PART OF ORDER BY":"ORDER BY");
136142 assert( p->pEList==pEList );
136143 generateSortTail(pParse, p, &sSort, pEList->nExpr, pDest);
136144 }
136145
136146 /* Jump here to skip this query
136147 */
136148 sqlite3VdbeResolveLabel(v, iEnd);
136149
136150 /* The SELECT has been coded. If there is an error in the Parse structure,
136151 ** set the return code to 1. Otherwise 0. */
136152 rc = (pParse->nErr>0);
136153
136154 /* Control jumps to here if an error is encountered above, or upon
136155 ** successful coding of the SELECT.
136156 */
136157select_end:
136158 sqlite3ExprListDelete(db, pMinMaxOrderBy);
136159#ifdef SQLITE_DEBUG
136160 if( pAggInfo && !db->mallocFailed ){
136161 for(i=0; i<pAggInfo->nColumn; i++){
136162 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
136163 assert( pExpr!=0 || db->mallocFailed );
136164 if( pExpr==0 ) continue;
136165 assert( pExpr->pAggInfo==pAggInfo );
136166 assert( pExpr->iAgg==i );
136167 }
136168 for(i=0; i<pAggInfo->nFunc; i++){
136169 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
136170 assert( pExpr!=0 || db->mallocFailed );
136171 if( pExpr==0 ) continue;
136172 assert( pExpr->pAggInfo==pAggInfo );
136173 assert( pExpr->iAgg==i );
136174 }
136175 }
136176#endif
136177
136178#if SELECTTRACE_ENABLED
136179 SELECTTRACE(0x1,pParse,p,("end processing\n"));
136180 if( (sqlite3_unsupported_selecttrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
static int flattenSubquery(Parse *pParse, Select *p, int iFrom, int isAgg)
Definition sqlite3.c:133077
SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse *, Select *, WhereInfo *, int, int)
Definition sqlite3.c:153875
static struct SrcList_item * isSelfJoinView(SrcList *pTabList, struct SrcList_item *pThis)
Definition sqlite3.c:134932
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *, Expr *)
Definition sqlite3.c:105676
static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo)
Definition sqlite3.c:134752
static void explainTempTable(Parse *pParse, const char *zUsage)
Definition sqlite3.c:130701
#define SQLITE_SimplifyJoin
Definition sqlite3.c:17055
#define WHERE_WANT_DISTINCT
Definition sqlite3.c:18312
SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo *)
Definition sqlite3.c:145701
#define SF_ComplexResult
Definition sqlite3.c:18489
static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax)
Definition sqlite3.c:133819
static int multiSelect(Parse *pParse, Select *p, SelectDest *pDest)
Definition sqlite3.c:131852
SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *)
Definition sqlite3.c:100468
#define ExplainQueryPlanParent(P)
Definition sqlite3.c:15832
static Table * isSimpleCount(Select *p, AggInfo *pAggInfo)
Definition sqlite3.c:133861
static void generateSortTail(Parse *pParse, Select *p, SortCtx *pSort, int nColumn, SelectDest *pDest)
Definition sqlite3.c:130727
#define IgnorableOrderby(X)
Definition sqlite3.c:18578
#define SQLITE_CountOfView
Definition sqlite3.c:17050
SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo *)
Definition sqlite3.c:145654
#define WHERE_USE_LIMIT
Definition sqlite3.c:18318
SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo *)
Definition sqlite3.c:145717
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *, int addr, int P1)
Definition sqlite3.c:78779
SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *)
Definition sqlite3.c:149620
static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo)
Definition sqlite3.c:134688
#define SQLITE_GroupByOrder
Definition sqlite3.c:17043
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *, Select *)
Definition sqlite3.c:152104
#define WHERE_SORTBYGROUP
Definition sqlite3.c:18313
#define SQLITE_PropagateConst
Definition sqlite3.c:17057
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo *)
Definition sqlite3.c:145674
static void havingToWhere(Parse *pParse, Select *p)
Definition sqlite3.c:134912
SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo *)
Definition sqlite3.c:145662
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *, Select *)
Definition sqlite3.c:152512
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext *, ExprList *)
Definition sqlite3.c:105694
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo *)
Definition sqlite3.c:145726
static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo)
Definition sqlite3.c:134730
#define SQLITE_PushDown
Definition sqlite3.c:17054
#define WHERE_GROUPBY
Definition sqlite3.c:18310
static void explainSimpleCount(Parse *pParse, Table *pTab, Index *pIdx)
Definition sqlite3.c:134849
#define SF_UpdateFrom
Definition sqlite3.c:18494
static int propagateConstants(Parse *pParse, Select *p)
Definition sqlite3.c:133647
int sortingIdx
Definition sqlite3.c:17886
int nAccumulator
Definition sqlite3.c:17900
u32 selId
Definition sqlite3.c:17910
int addrExplain
Definition sqlite3.c:18757
int labelOBLopt
Definition sqlite3.c:129350

References ExprList::a, SrcList::a, AggInfo::aCol, Parse::addrExplain, SortCtx::addrSortIndex, DistinctCtx::addrTnct, AggInfo::aFunc, BTREE_UNORDERED, Index::bUnordered, computeLimitRegisters(), Parse::db, AggInfo::directMode, SelectDest::eDest, EP_WinFunc, EP_xIsSelect, DistinctCtx::eTnctType, ExplainQueryPlan, ExplainQueryPlanParent, ExplainQueryPlanPop, explainSimpleCount(), explainTempTable(), ExprHasProperty, SrcList::SrcList_item::fg, finalizeAggFunctions(), flattenSubquery(), FuncDef::funcFlags, generateColumnNames(), generateSortTail(), HasRowid, havingToWhere(), Expr::iAgg, SortCtx::iECursor, IgnorableOrderby, Select::iLimit, AggInfo::AggInfo_col::iMem, AggInfo::AggInfo_func::iMem, SelectDest::iSDParm, SelectDest::iSdst, AggInfo::AggInfo_col::iSorterColumn, isSelfJoinView(), isSimpleCount(), DistinctCtx::isTnct, IsWindowFunc, SrcList::SrcList_item::jointype, JT_CROSS, JT_LEFT, JT_OUTER, KEYINFO_ORDER_DESC, SortCtx::labelOBLopt, sqlite3::mallocFailed, minMaxQuery(), AggInfo::mnReg, multiSelect(), AggInfo::mxReg, AggInfo::nAccumulator, NC_InAggFunc, NC_UAggInfo, NameContext::ncFlags, Table::nCol, AggInfo::nColumn, Parse::nErr, ExprList::nExpr, AggInfo::nFunc, Parse::nHeight, Parse::nMem, SortCtx::nOBSat, SrcList::SrcList_item::notIndexed, Select::nSelectRow, AggInfo::nSortingColumn, SrcList::nSrc, Parse::nTab, OP_Close, OP_Column, OP_Compare, OP_Count, OP_Gosub, OP_Goto, OP_IfPos, OP_InitCoroutine, OP_Integer, OP_Jump, OP_MakeRecord, OP_Null, OP_Once, OP_OpenDup, OP_OpenEphemeral, OP_OpenPseudo, OP_OpenRead, OP_Return, OP_SorterData, OP_SorterInsert, OP_SorterNext, OP_SorterOpen, OP_SorterSort, OptimizationEnabled, P4_KEYINFO, Expr::pAggInfo, NameContext::pAggInfo, Parse::pAggList, AggInfo::AggInfo_col::pCExpr, Select::pEList, ExprList::ExprList_item::pExpr, AggInfo::AggInfo_func::pFExpr, Window::pFilter, AggInfo::AggInfo_func::pFunc, AggInfo::pGroupBy, Select::pGroupBy, Select::pHaving, Table::pIndex, Expr::pList, Index::pNext, AggInfo::pNext, Select::pNext, Select::pOrderBy, SortCtx::pOrderBy, NameContext::pParse, Index::pPartIdxWhere, Select::pPrior, propagateConstants(), Table::pSchema, Select::pSrc, NameContext::pSrcList, pushDownWhereTerms(), Select::pWhere, Expr::pWin, Select::pWin, resetAccumulator(), selectInnerLoop(), SELECTTRACE, Select::selFlags, AggInfo::selId, Select::selId, SF_Aggregate, SF_ComplexResult, SF_Distinct, SF_FixedLimit, SF_NoopOrderBy, SF_UpdateFrom, SORTFLAG_UseSorter, ExprList::ExprList_item::sortFlags, SortCtx::sortFlags, AggInfo::sortingIdx, AggInfo::sortingIdxPTab, sqlite3_stricmp(), sqlite3_unsupported_selecttrace, sqlite3AuthCheck(), sqlite3ClearTempRegCache(), sqlite3CodeVerifySchema(), sqlite3DbMallocZero(), sqlite3ErrorMsg(), sqlite3ExprAnalyzeAggList(), sqlite3ExprAnalyzeAggregates(), sqlite3ExprCode(), sqlite3ExprCodeExprList(), sqlite3ExprCodeGetColumnOfTable(), sqlite3ExprCodeMove(), sqlite3ExprIfFalse(), sqlite3ExprImpliesNonNullRow(), sqlite3ExprListCompare(), sqlite3ExprListDelete(), sqlite3ExprListDup(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3KeyInfoFromExprList(), sqlite3KeyInfoOfIndex(), sqlite3KeyInfoRef(), sqlite3LogEst(), sqlite3PrimaryKeyIndex(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3SchemaToIndex(), sqlite3Select(), sqlite3SelectDestInit(), sqlite3SelectExprHeight(), sqlite3SelectPrep(), sqlite3TableLock(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeOpcode(), sqlite3VdbeChangeP1(), sqlite3VdbeChangeP4(), sqlite3VdbeChangeP5(), sqlite3VdbeChangeToNoop(), sqlite3VdbeCurrentAddr(), sqlite3VdbeEndCoroutine(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3WhereBegin(), sqlite3WhereBreakLabel(), sqlite3WhereContinueLabel(), sqlite3WhereEnd(), sqlite3WhereIsDistinct(), sqlite3WhereIsOrdered(), sqlite3WhereIsSorted(), sqlite3WhereOrderByLimitOptLabel(), sqlite3WhereOutputRowCount(), sqlite3WindowCodeInit(), sqlite3WindowCodeStep(), sqlite3WindowRewrite(), SQLITE_CountOfView, SQLITE_FUNC_NEEDCOLL, SQLITE_GroupByOrder, SQLITE_JUMPIFNULL, SQLITE_PropagateConst, SQLITE_PushDown, SQLITE_QueryFlattener, SQLITE_READ, SQLITE_SELECT, SQLITE_SimplifyJoin, SRT_Coroutine, SRT_Discard, SRT_DistFifo, SRT_DistQueue, SRT_EphemTab, SRT_Except, SRT_Exists, SRT_Fifo, SRT_Output, SRT_Queue, SRT_Union, Index::szIdxRow, Table::szTabRow, DistinctCtx::tabTnct, testcase, Table::tnum, Index::tnum, NameContext::uNC, unsetJoinExpr(), updateAccumulator(), AggInfo::useSortingIdx, VdbeComment, VdbeCoverage, VdbeNoopComment, VVA_ONLY, WHERE_DISTINCT_NOOP, WHERE_DISTINCT_UNORDERED, WHERE_GROUPBY, WHERE_ORDERBY_NORMAL, WHERE_SORTBYGROUP, WHERE_USE_LIMIT, WHERE_WANT_DISTINCT, Expr::x, Expr::y, Parse::zAuthContext, and Table::zName.

Referenced by generateWithRecursiveQuery(), multiSelect(), multiSelectOrderBy(), sqlite3CodeRhsOfIN(), sqlite3CodeSubselect(), sqlite3EndTable(), sqlite3Insert(), sqlite3MaterializeView(), sqlite3Select(), updateFromSelect(), and yy_reduce().

◆ sqlite3SelectAddColumnTypeAndCollation()

SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation ( Parse * pParse,
Table * pTab,
Select * pSelect,
char aff )

Definition at line 131359 of file sqlite3.c.

131370 {
131371 sqlite3 *db = pParse->db;
131372 NameContext sNC;
131373 Column *pCol;
131374 CollSeq *pColl;
131375 int i;
131376 Expr *p;
131377 struct ExprList_item *a;
131378
131379 assert( pSelect!=0 );
131380 assert( (pSelect->selFlags & SF_Resolved)!=0 );
131381 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
131382 if( db->mallocFailed ) return;
131383 memset(&sNC, 0, sizeof(sNC));
131384 sNC.pSrcList = pSelect->pSrc;
131385 a = pSelect->pEList->a;
131386 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
131387 const char *zType;
131388 int n, m;
131389 p = a[i].pExpr;
131390 zType = columnType(&sNC, p, 0, 0, 0);
131391 /* pCol->szEst = ... // Column size est for SELECT tables never used */
131392 pCol->affinity = sqlite3ExprAffinity(p);
131393 if( zType ){
131394 m = sqlite3Strlen30(zType);
131395 n = sqlite3Strlen30(pCol->zName);
131396 pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
131397 if( pCol->zName ){
131398 memcpy(&pCol->zName[n+1], zType, m+1);
131399 pCol->colFlags |= COLFLAG_HASTYPE;
131400 }
131401 }
131402 if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
131403 pColl = sqlite3ExprCollSeq(pParse, p);
#define COLFLAG_HASTYPE
Definition sqlite3.c:17346

References ExprList::a, Table::aCol, Column::affinity, COLFLAG_HASTYPE, Column::colFlags, columnType, Parse::db, sqlite3::mallocFailed, Table::nCol, ExprList::nExpr, Select::pEList, Select::pSrc, NameContext::pSrcList, Select::selFlags, SF_Resolved, sqlite3DbReallocOrFree(), sqlite3DbStrDup(), sqlite3ExprAffinity(), sqlite3ExprCollSeq(), sqlite3Strlen30(), SQLITE_AFF_NONE, Table::szTabRow, Column::zColl, Column::zName, and CollSeq::zName.

Referenced by selectAddSubqueryTypeInfo(), and sqlite3ViewGetColumnNames().

◆ sqlite3SelectAddTypeInfo()

static void sqlite3SelectAddTypeInfo ( Parse * pParse,
Select * pSelect )
static

◆ sqlite3SelectDelete()

◆ sqlite3SelectDestInit()

SQLITE_PRIVATE void sqlite3SelectDestInit ( SelectDest * pDest,
int eDest,
int iParm )

◆ sqlite3SelectDup()

SQLITE_PRIVATE Select * sqlite3SelectDup ( sqlite3 * db,
Select * pDup,
int flags )

Definition at line 101281 of file sqlite3.c.

101287 {
101288 Select *pRet = 0;
101289 Select *pNext = 0;
101290 Select **pp = &pRet;
101291 Select *p;
101292
101293 assert( db!=0 );
101294 for(p=pDup; p; p=p->pPrior){
101295 Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
101296 if( pNew==0 ) break;
101297 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
101298 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
101299 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
101300 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
101301 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
101302 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
101303 pNew->op = p->op;
101304 pNew->pNext = pNext;
101305 pNew->pPrior = 0;
101306 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
101307 pNew->iLimit = 0;
101308 pNew->iOffset = 0;
101309 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
101310 pNew->addrOpenEphm[0] = -1;
101311 pNew->addrOpenEphm[1] = -1;
101312 pNew->nSelectRow = p->nSelectRow;
101313 pNew->pWith = withDup(db, p->pWith);
101314#ifndef SQLITE_OMIT_WINDOWFUNC
101315 pNew->pWin = 0;
101316 pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn);
101317 if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
101318#endif
101319 pNew->selId = p->selId;
101320 *pp = pNew;
static With * withDup(sqlite3 *db, With *p)
Definition sqlite3.c:101090
SQLITE_PRIVATE Window * sqlite3WindowListDup(sqlite3 *db, Window *p)
Definition sqlite3.c:153506

Referenced by exprDup(), fkActionTrigger(), flattenSubquery(), selectExpander(), sqlite3SrcListDup(), sqlite3TriggerInsertStep(), sqlite3ViewGetColumnNames(), withDup(), and withExpand().

◆ sqlite3SelectExpand()

static void sqlite3SelectExpand ( Parse * pParse,
Select * pSelect )
static

◆ sqlite3SelectExprHeight()

SQLITE_PRIVATE int sqlite3SelectExprHeight ( Select * p)

Definition at line 100468 of file sqlite3.c.

Referenced by sqlite3Select().

◆ sqlite3SelectNew()

SQLITE_PRIVATE Select * sqlite3SelectNew ( Parse * pParse,
ExprList * pEList,
SrcList * pSrc,
Expr * pWhere,
ExprList * pGroupBy,
Expr * pHaving,
ExprList * pOrderBy,
u32 selFlags,
Expr * pLimit )

Definition at line 129410 of file sqlite3.c.

129426 {
129427 Select *pNew, *pAllocated;
129428 Select standin;
129429 pAllocated = pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
129430 if( pNew==0 ){
129431 assert( pParse->db->mallocFailed );
129432 pNew = &standin;
129433 }
129434 if( pEList==0 ){
129435 pEList = sqlite3ExprListAppend(pParse, 0,
129436 sqlite3Expr(pParse->db,TK_ASTERISK,0));
129437 }
129438 pNew->pEList = pEList;
129439 pNew->op = TK_SELECT;
129440 pNew->selFlags = selFlags;
129441 pNew->iLimit = 0;
129442 pNew->iOffset = 0;
129443 pNew->selId = ++pParse->nSelect;
129444 pNew->addrOpenEphm[0] = -1;
129445 pNew->addrOpenEphm[1] = -1;
129446 pNew->nSelectRow = 0;
129447 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
129448 pNew->pSrc = pSrc;
129449 pNew->pWhere = pWhere;
129450 pNew->pGroupBy = pGroupBy;
129451 pNew->pHaving = pHaving;
129452 pNew->pOrderBy = pOrderBy;
129453 pNew->pPrior = 0;
129454 pNew->pNext = 0;
129455 pNew->pLimit = pLimit;
129456 pNew->pWith = 0;
129457#ifndef SQLITE_OMIT_WINDOWFUNC
129458 pNew->pWin = 0;
129459 pNew->pWinDefn = 0;
129460#endif
129461 if( pParse->db->mallocFailed ) {
129462 clearSelect(pParse->db, pNew, pNew!=&standin);
static void clearSelect(sqlite3 *db, Select *p, int bFree)
Definition sqlite3.c:129371

References Select::addrOpenEphm, clearSelect(), Parse::db, Select::iLimit, Select::iOffset, sqlite3::mallocFailed, Parse::nErr, Parse::nSelect, Select::nSelectRow, Select::op, Select::pEList, Select::pGroupBy, Select::pHaving, Select::pLimit, Select::pNext, Select::pOrderBy, Select::pPrior, Select::pSrc, Select::pWhere, Select::pWin, Select::pWinDefn, Select::pWith, Select::selFlags, Select::selId, sqlite3DbMallocRawNN(), sqlite3DbMallocZero(), sqlite3Expr(), sqlite3ExprListAppend(), TK_ASTERISK, and TK_SELECT.

Referenced by fkActionTrigger(), sqlite3MaterializeView(), sqlite3WindowRewrite(), updateFromSelect(), and yy_reduce().

◆ sqlite3SelectPrep()

SQLITE_PRIVATE void sqlite3SelectPrep ( Parse * pParse,
Select * p,
NameContext * pOuterNC )

◆ sqlite3SelectWalkFail()

SQLITE_PRIVATE int sqlite3SelectWalkFail ( Walker * pWalker,
Select * NotUsed )

Definition at line 101605 of file sqlite3.c.

References Walker::eCode, UNUSED_PARAMETER, and WRC_Abort.

Referenced by exprIsDeterministic().

◆ sqlite3SelectWalkNoop()

SQLITE_PRIVATE int sqlite3SelectWalkNoop ( Walker * NotUsed,
Select * NotUsed2 )

Definition at line 97743 of file sqlite3.c.

Referenced by propagateConstants(), and sqlite3SelectAddTypeInfo().

◆ sqlite3SelectWrongNumTermsError()

SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError ( Parse * pParse,
Select * p )

Definition at line 132200 of file sqlite3.c.

132206 {
132207 if( p->selFlags & SF_Values ){

References Select::op, selectOpName(), Select::selFlags, SF_Values, and sqlite3ErrorMsg().

◆ sqlite3SetHasNullFlag()

static void sqlite3SetHasNullFlag ( Vdbe * v,
int iCur,
int regHasNull )
static

◆ sqlite3SetJoinExpr()

SQLITE_PRIVATE void sqlite3SetJoinExpr ( Expr * p,
int iTable )

◆ sqlite3SetString()

SQLITE_PRIVATE void sqlite3SetString ( char ** pz,
sqlite3 * db,
const char * zNew )

Definition at line 28060 of file sqlite3.c.

Referenced by execSqlF(), and sqlite3InitOne().

◆ sqlite3SetTextEncoding()

SQLITE_PRIVATE void sqlite3SetTextEncoding ( sqlite3 * db,
u8 enc )

Definition at line 115717 of file sqlite3.c.

115723 {
115724 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );

Referenced by openDatabase(), sqlite3InitOne(), and sqlite3Pragma().

◆ sqlite3ShadowTableName()

SQLITE_PRIVATE int sqlite3ShadowTableName ( sqlite3 * db,
const char * zName )

Definition at line 112599 of file sqlite3.c.

112605 {
112606 char *zTail; /* Pointer to the last "_" in zName */
112607 Table *pTab; /* Table that zName is a shadow of */
112608 zTail = strrchr(zName, '_');
112609 if( zTail==0 ) return 0;
112610 *zTail = 0;

References IsVirtual, sqlite3FindTable(), sqlite3IsShadowTableOf(), and zName.

Referenced by sqlite3CheckObjectName(), and sqlite3EndTable().

◆ sqlite3SkipAccumulatorLoad()

static void sqlite3SkipAccumulatorLoad ( sqlite3_context * context)
static

Definition at line 117084 of file sqlite3.c.

Referenced by minmaxStep().

◆ sqlite3SrcListAppend()

SQLITE_PRIVATE SrcList * sqlite3SrcListAppend ( Parse * pParse,
SrcList * pList,
Token * pTable,
Token * pDatabase )

Definition at line 114789 of file sqlite3.c.

114800 {
114801 struct SrcList_item *pItem;
114802 sqlite3 *db;
114803 assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */
114804 assert( pParse!=0 );
114805 assert( pParse->db!=0 );
114806 db = pParse->db;
114807 if( pList==0 ){
114808 pList = sqlite3DbMallocRawNN(pParse->db, sizeof(SrcList) );
114809 if( pList==0 ) return 0;
114810 pList->nAlloc = 1;
114811 pList->nSrc = 1;
114812 memset(&pList->a[0], 0, sizeof(pList->a[0]));
114813 pList->a[0].iCursor = -1;
114814 }else{
114815 SrcList *pNew = sqlite3SrcListEnlarge(pParse, pList, 1, pList->nSrc);
114816 if( pNew==0 ){
114817 sqlite3SrcListDelete(db, pList);
114818 return 0;
114819 }else{
114820 pList = pNew;
114821 }
114822 }
114823 pItem = &pList->a[pList->nSrc-1];
114824 if( pDatabase && pDatabase->z==0 ){
114825 pDatabase = 0;
114826 }
114827 if( pDatabase ){
114828 pItem->zName = sqlite3NameFromToken(db, pDatabase);
114829 pItem->zDatabase = sqlite3NameFromToken(db, pTable);

References SrcList::a, Parse::db, SrcList::SrcList_item::iCursor, SrcList::nAlloc, SrcList::nSrc, sqlite3DbMallocRawNN(), sqlite3NameFromToken(), sqlite3SrcListDelete(), sqlite3SrcListEnlarge(), and Token::z.

Referenced by fkActionTrigger(), flattenSubquery(), sqlite3FkCheck(), sqlite3MaterializeView(), sqlite3SrcListAppendFromTerm(), sqlite3TriggerStepSrc(), sqlite3WindowRewrite(), and yy_reduce().

◆ sqlite3SrcListAppendFromTerm()

SQLITE_PRIVATE SrcList * sqlite3SrcListAppendFromTerm ( Parse * pParse,
SrcList * p,
Token * pTable,
Token * pDatabase,
Token * pAlias,
Select * pSubquery,
Expr * pOn,
IdList * pUsing )

Definition at line 114886 of file sqlite3.c.

114901 {
114902 struct SrcList_item *pItem;
114903 sqlite3 *db = pParse->db;
114904 if( !p && (pOn || pUsing) ){
114905 sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s",
114906 (pOn ? "ON" : "USING")
114907 );
114908 goto append_from_error;
114909 }
114910 p = sqlite3SrcListAppend(pParse, p, pTable, pDatabase);
114911 if( p==0 ){
114912 goto append_from_error;
114913 }
114914 assert( p->nSrc>0 );
114915 pItem = &p->a[p->nSrc-1];
114916 assert( (pTable==0)==(pDatabase==0) );
114917 assert( pItem->zName==0 || pDatabase!=0 );
114918 if( IN_RENAME_OBJECT && pItem->zName ){
114919 Token *pToken = (ALWAYS(pDatabase) && pDatabase->z) ? pDatabase : pTable;
114920 sqlite3RenameTokenMap(pParse, pItem->zName, pToken);
114921 }
114922 assert( pAlias!=0 );
114923 if( pAlias->n ){
114924 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
114925 }
114926 pItem->pSelect = pSubquery;
114927 pItem->pOn = pOn;
114928 pItem->pUsing = pUsing;
114929 return p;
114930
114931 append_from_error:

References SrcList::a, ALWAYS, Parse::db, IN_RENAME_OBJECT, Token::n, SrcList::nSrc, sqlite3ErrorMsg(), sqlite3ExprDelete(), sqlite3IdListDelete(), sqlite3NameFromToken(), sqlite3RenameTokenMap(), sqlite3SelectDelete(), sqlite3SrcListAppend(), and Token::z.

Referenced by convertCompoundSelectToSubquery(), and yy_reduce().

◆ sqlite3SrcListAppendList()

SQLITE_PRIVATE SrcList * sqlite3SrcListAppendList ( Parse * pParse,
SrcList * p1,
SrcList * p2 )

Definition at line 114962 of file sqlite3.c.

114968 {
114969 assert( p1 && p1->nSrc==1 );
114970 if( p2 ){
114971 SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, 1);
114972 if( pNew==0 ){
114973 sqlite3SrcListDelete(pParse->db, p2);
114974 }else{
114975 p1 = pNew;

References SrcList::a, Parse::db, SrcList::nSrc, sqlite3DbFree(), sqlite3SrcListDelete(), and sqlite3SrcListEnlarge().

Referenced by sqlite3TriggerStepSrc(), and yy_reduce().

◆ sqlite3SrcListAssignCursors()

SQLITE_PRIVATE void sqlite3SrcListAssignCursors ( Parse * pParse,
SrcList * pList )

Definition at line 114834 of file sqlite3.c.

114840 {
114841 int i;
114842 struct SrcList_item *pItem;
114843 assert(pList || pParse->db->mallocFailed );
114844 if( pList ){
114845 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
114846 if( pItem->iCursor>=0 ) break;
114847 pItem->iCursor = pParse->nTab++;

Referenced by selectExpander(), sqlite3ViewGetColumnNames(), and sqlite3WindowRewrite().

◆ sqlite3SrcListDelete()

SQLITE_PRIVATE void sqlite3SrcListDelete ( sqlite3 * db,
SrcList * pList )

Definition at line 114852 of file sqlite3.c.

114858 {
114859 int i;
114860 struct SrcList_item *pItem;
114861 if( pList==0 ) return;
114862 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
114863 sqlite3DbFree(db, pItem->zDatabase);
114864 sqlite3DbFree(db, pItem->zName);
114865 sqlite3DbFree(db, pItem->zAlias);
114866 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
114867 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
114868 sqlite3DeleteTable(db, pItem->pTab);

Referenced by clearSelect(), renameResolveTrigger(), sqlite3AlterBeginAddColumn(), sqlite3AlterRenameColumn(), sqlite3BeginTrigger(), sqlite3CreateIndex(), sqlite3DeleteFrom(), sqlite3DeleteTriggerStep(), sqlite3DropTrigger(), sqlite3Insert(), sqlite3SrcListAppend(), sqlite3SrcListAppendList(), sqlite3TriggerUpdateStep(), sqlite3Update(), yy_destructor(), and yy_reduce().

◆ sqlite3SrcListDup()

SQLITE_PRIVATE SrcList * sqlite3SrcListDup ( sqlite3 * db,
SrcList * p,
int flags )

Definition at line 101216 of file sqlite3.c.

101222 {
101223 SrcList *pNew;
101224 int i;
101225 int nByte;
101226 assert( db!=0 );
101227 if( p==0 ) return 0;
101228 nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0);
101229 pNew = sqlite3DbMallocRawNN(db, nByte );
101230 if( pNew==0 ) return 0;
101231 pNew->nSrc = pNew->nAlloc = p->nSrc;
101232 for(i=0; i<p->nSrc; i++){
101233 struct SrcList_item *pNewItem = &pNew->a[i];
101234 struct SrcList_item *pOldItem = &p->a[i];
101235 Table *pTab;
101236 pNewItem->pSchema = pOldItem->pSchema;
101237 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
101238 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
101239 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
101240 pNewItem->fg = pOldItem->fg;
101241 pNewItem->iCursor = pOldItem->iCursor;
101242 pNewItem->addrFillSub = pOldItem->addrFillSub;
101243 pNewItem->regReturn = pOldItem->regReturn;
101244 if( pNewItem->fg.isIndexedBy ){
101245 pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
101246 }
101247 pNewItem->pIBIndex = pOldItem->pIBIndex;
101248 if( pNewItem->fg.isTabFunc ){
101249 pNewItem->u1.pFuncArg =
101250 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
101251 }
101252 pTab = pNewItem->pTab = pOldItem->pTab;
101253 if( pTab ){
101254 pTab->nTabRef++;
101255 }
101256 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);

References SrcList::a, SrcList::nAlloc, SrcList::nSrc, Table::nTabRef, Table::pSchema, sqlite3DbMallocRawNN(), sqlite3DbStrDup(), sqlite3ExprListDup(), sqlite3SelectDup(), and sqlite3::u1.

Referenced by sqlite3FkDropTable(), sqlite3TriggerStepSrc(), sqlite3TriggerUpdateStep(), sqlite3UpsertDoUpdate(), and updateFromSelect().

◆ sqlite3SrcListEnlarge()

SQLITE_PRIVATE SrcList * sqlite3SrcListEnlarge ( Parse * pParse,
SrcList * pSrc,
int nExtra,
int iStart )

Definition at line 114700 of file sqlite3.c.

114700 : nil, nil, nil, A, B.
114701**
114702** If a memory allocation fails or the SrcList becomes too large, leave
114703** the original SrcList unchanged, return NULL, and leave an error message
114704** in pParse.
114705*/
114707 Parse *pParse, /* Parsing context into which errors are reported */
114708 SrcList *pSrc, /* The SrcList to be enlarged */
114709 int nExtra, /* Number of new slots to add to pSrc->a[] */
114710 int iStart /* Index in pSrc->a[] of first new slot */
114711){
114712 int i;
114713
114714 /* Sanity checking on calling parameters */
114715 assert( iStart>=0 );
114716 assert( nExtra>=1 );
114717 assert( pSrc!=0 );
114718 assert( iStart<=pSrc->nSrc );
114719
114720 /* Allocate additional space if needed */
114721 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
114722 SrcList *pNew;
114723 sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra;
114724 sqlite3 *db = pParse->db;
114725
114726 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
114727 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
114729 return 0;
114730 }
114731 if( nAlloc>SQLITE_MAX_SRCLIST ) nAlloc = SQLITE_MAX_SRCLIST;
114732 pNew = sqlite3DbRealloc(db, pSrc,
114733 sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
114734 if( pNew==0 ){
114735 assert( db->mallocFailed );
114736 return 0;
114737 }
114738 pSrc = pNew;
114739 pSrc->nAlloc = nAlloc;
114740 }
114741
114742 /* Move existing slots that come after the newly inserted slots
114743 ** out of the way */
114744 for(i=pSrc->nSrc-1; i>=iStart; i--){
114745 pSrc->a[i+nExtra] = pSrc->a[i];
114746 }
114747 pSrc->nSrc += nExtra;
114748
114749 /* Zero the newly allocated slots */
114750 memset(&pSrc->a[iStart], 0, sizeof(pSrc->a[0])*nExtra);
114751 for(i=iStart; i<iStart+nExtra; i++){
#define SQLITE_MAX_SRCLIST
Definition sqlite3.c:114677

References SrcList::a, Parse::db, SrcList::SrcList_item::iCursor, sqlite3::mallocFailed, SrcList::nAlloc, SrcList::nSrc, sqlite3DbRealloc(), sqlite3ErrorMsg(), and SQLITE_MAX_SRCLIST.

Referenced by flattenSubquery(), sqlite3SrcListAppend(), and sqlite3SrcListAppendList().

◆ sqlite3SrcListFuncArgs()

SQLITE_PRIVATE void sqlite3SrcListFuncArgs ( Parse * pParse,
SrcList * p,
ExprList * pList )

Definition at line 114981 of file sqlite3.c.

114987 {
114988 if( p ){
114989 struct SrcList_item *pItem = &p->a[p->nSrc-1];
114990 assert( pItem->fg.notIndexed==0 );
114991 assert( pItem->fg.isIndexedBy==0 );
114992 assert( pItem->fg.isTabFunc==0 );

Referenced by yy_reduce().

◆ sqlite3SrcListIndexedBy()

SQLITE_PRIVATE void sqlite3SrcListIndexedBy ( Parse * pParse,
SrcList * p,
Token * pIndexedBy )

Definition at line 114937 of file sqlite3.c.

114943 {
114944 assert( pIndexedBy!=0 );
114945 if( p && pIndexedBy->n>0 ){
114946 struct SrcList_item *pItem;
114947 assert( p->nSrc>0 );
114948 pItem = &p->a[p->nSrc-1];
114949 assert( pItem->fg.notIndexed==0 );
114950 assert( pItem->fg.isIndexedBy==0 );
114951 assert( pItem->fg.isTabFunc==0 );
114952 if( pIndexedBy->n==1 && !pIndexedBy->z ){
114953 /* A "NOT INDEXED" clause was supplied. See parse.y
114954 ** construct "indexed_opt" for details. */
114955 pItem->fg.notIndexed = 1;

Referenced by yy_reduce().

◆ sqlite3SrcListLookup()

SQLITE_PRIVATE Table * sqlite3SrcListLookup ( Parse * pParse,
SrcList * pSrc )

Definition at line 116106 of file sqlite3.c.

116106 :
116107**
116108** pSrc->a[0].pTab Pointer to the Table object
116109** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one
116110**
116111*/
116113 struct SrcList_item *pItem = pSrc->a;
116114 Table *pTab;
116115 assert( pItem && pSrc->nSrc>=1 );
116116 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
116117 sqlite3DeleteTable(pParse->db, pItem->pTab);
116118 pItem->pTab = pTab;
116119 if( pTab ){
116120 pTab->nTabRef++;

References SrcList::a, Parse::db, SrcList::nSrc, Table::nTabRef, sqlite3DeleteTable(), sqlite3IndexedByLookup(), and sqlite3LocateTableItem().

Referenced by sqlite3BeginTrigger(), sqlite3CreateIndex(), sqlite3DeleteFrom(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3SrcListShiftJoinType()

SQLITE_PRIVATE void sqlite3SrcListShiftJoinType ( SrcList * p)

Definition at line 115009 of file sqlite3.c.

115015 {
115016 if( p ){
115017 int i;

References SrcList::a, SrcList::SrcList_item::fg, SrcList::SrcList_item::jointype, and SrcList::nSrc.

Referenced by yy_reduce().

◆ sqlite3StartTable()

SQLITE_PRIVATE void sqlite3StartTable ( Parse * pParse,
Token * pName1,
Token * pName2,
int isTemp,
int isView,
int isVirtual,
int noErr )

Definition at line 111424 of file sqlite3.c.

111438 {
111439 Table *pTable;
111440 char *zName = 0; /* The name of the new table */
111441 sqlite3 *db = pParse->db;
111442 Vdbe *v;
111443 int iDb; /* Database number to create the table in */
111444 Token *pName; /* Unqualified name of the table to create */
111445
111446 if( db->init.busy && db->init.newTnum==1 ){
111447 /* Special case: Parsing the sqlite_schema or sqlite_temp_schema schema */
111448 iDb = db->init.iDb;
111449 zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb));
111450 pName = pName1;
111451 }else{
111452 /* The common case */
111453 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
111454 if( iDb<0 ) return;
111455 if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
111456 /* If creating a temp table, the name may not be qualified. Unless
111457 ** the database name is "temp" anyway. */
111458 sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
111459 return;
111460 }
111461 if( !OMIT_TEMPDB && isTemp ) iDb = 1;
111462 zName = sqlite3NameFromToken(db, pName);
111463 if( IN_RENAME_OBJECT ){
111464 sqlite3RenameTokenMap(pParse, (void*)zName, pName);
111465 }
111466 }
111467 pParse->sNameToken = *pName;
111468 if( zName==0 ) return;
111469 if( sqlite3CheckObjectName(pParse, zName, isView?"view":"table", zName) ){
111470 goto begin_table_error;
111471 }
111472 if( db->init.iDb==1 ) isTemp = 1;
111473#ifndef SQLITE_OMIT_AUTHORIZATION
111474 assert( isTemp==0 || isTemp==1 );
111475 assert( isView==0 || isView==1 );
111476 {
111477 static const u8 aCode[] = {
111482 };
111483 char *zDb = db->aDb[iDb].zDbSName;
111484 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
111485 goto begin_table_error;
111486 }
111487 if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
111488 zName, 0, zDb) ){
111489 goto begin_table_error;
111490 }
111491 }
111492#endif
111493
111494 /* Make sure the new table name does not collide with an existing
111495 ** index or table name in the same database. Issue an error message if
111496 ** it does. The exception is if the statement being parsed was passed
111497 ** to an sqlite3_declare_vtab() call. In that case only the column names
111498 ** and types will be used, so there is no need to test for namespace
111499 ** collisions.
111500 */
111501 if( !IN_SPECIAL_PARSE ){
111502 char *zDb = db->aDb[iDb].zDbSName;
111503 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
111504 goto begin_table_error;
111505 }
111506 pTable = sqlite3FindTable(db, zName, zDb);
111507 if( pTable ){
111508 if( !noErr ){
111509 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
111510 }else{
111511 assert( !db->init.busy || CORRUPT_DB );
111512 sqlite3CodeVerifySchema(pParse, iDb);
111513 }
111514 goto begin_table_error;
111515 }
111516 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
111517 sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
111518 goto begin_table_error;
111519 }
111520 }
111521
111522 pTable = sqlite3DbMallocZero(db, sizeof(Table));
111523 if( pTable==0 ){
111524 assert( db->mallocFailed );
111525 pParse->rc = SQLITE_NOMEM_BKPT;
111526 pParse->nErr++;
111527 goto begin_table_error;
111528 }
111529 pTable->zName = zName;
111530 pTable->iPKey = -1;
111531 pTable->pSchema = db->aDb[iDb].pSchema;
111532 pTable->nTabRef = 1;
111533#ifdef SQLITE_DEFAULT_ROWEST
111534 pTable->nRowLogEst = sqlite3LogEst(SQLITE_DEFAULT_ROWEST);
111535#else
111536 pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
111537#endif
111538 assert( pParse->pNewTable==0 );
111539 pParse->pNewTable = pTable;
111540
111541 /* If this is the magic sqlite_sequence table used by autoincrement,
111542 ** then record a pointer to this table in the main database structure
111543 ** so that INSERT can find the table easily.
111544 */
111545#ifndef SQLITE_OMIT_AUTOINCREMENT
111546 if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
111547 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
111548 pTable->pSchema->pSeqTab = pTable;
111549 }
111550#endif
111551
111552 /* Begin generating the code that will insert the table record into
111553 ** the schema table. Note in particular that we must go ahead
111554 ** and allocate the record number for the table entry now. Before any
111555 ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
111556 ** indices to be created and the table record must come before the
111557 ** indices. Hence, the record number for the table must be allocated
111558 ** now.
111559 */
111560 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
111561 int addr1;
111562 int fileFormat;
111563 int reg1, reg2, reg3;
111564 /* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
111565 static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
111566 sqlite3BeginWriteOperation(pParse, 1, iDb);
111567
111568#ifndef SQLITE_OMIT_VIRTUALTABLE
111569 if( isVirtual ){
111571 }
111572#endif
111573
111574 /* If the file format and encoding in the database have not been set,
111575 ** set them now.
111576 */
111577 reg1 = pParse->regRowid = ++pParse->nMem;
111578 reg2 = pParse->regRoot = ++pParse->nMem;
111579 reg3 = ++pParse->nMem;
111581 sqlite3VdbeUsesBtree(v, iDb);
111582 addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
111583 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
111585 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat);
111587 sqlite3VdbeJumpHere(v, addr1);
111588
111589 /* This just creates a place-holder record in the sqlite_schema table.
111590 ** The record created does not contain anything yet. It will be replaced
111591 ** by the real entry in code generated at sqlite3EndTable().
111592 **
111593 ** The rowid for the new entry is left in register pParse->regRowid.
111594 ** The root page number of the new table is left in reg pParse->regRoot.
111595 ** The rowid and root page number values are needed by the code that
111596 ** sqlite3EndTable will generate.
111597 */
111598#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
111599 if( isView || isVirtual ){
111600 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
111601 }else
111602#endif
111603 {
111604 pParse->addrCrTab =
111606 }
111607 sqlite3OpenSchemaTable(pParse, iDb);
111608 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
111609 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
111610 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
111613 }
111614
111615 /* Normal (non-error) return. */
111616 return;
#define SQLITE_CREATE_TEMP_VIEW
Definition sqlite3.c:4125
#define SQLITE_CREATE_TABLE
Definition sqlite3.c:4121
SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int)
Definition sqlite3.c:111157
#define SQLITE_CREATE_VIEW
Definition sqlite3.c:4127
#define SQLITE_CREATE_TEMP_TABLE
Definition sqlite3.c:4123

References sqlite3::aDb, Parse::addrCrTab, BTREE_FILE_FORMAT, BTREE_INTKEY, BTREE_TEXT_ENCODING, sqlite3::sqlite3InitInfo::busy, CORRUPT_DB, Parse::db, ENC, sqlite3::flags, sqlite3::sqlite3InitInfo::iDb, IN_RENAME_OBJECT, IN_SPECIAL_PARSE, sqlite3::init, Table::iPKey, sqlite3::mallocFailed, Token::n, Parse::nErr, Parse::nested, sqlite3::sqlite3InitInfo::newTnum, Parse::nMem, Table::nRowLogEst, Table::nTabRef, OMIT_TEMPDB, OP_Blob, OP_Close, OP_CreateBtree, OP_If, OP_Insert, OP_Integer, OP_NewRowid, OP_ReadCookie, OP_SetCookie, OP_VBegin, OPFLAG_APPEND, P4_STATIC, Parse::pNewTable, Db::pSchema, Table::pSchema, Schema::pSeqTab, Parse::rc, Parse::regRoot, Parse::regRowid, SCHEMA_TABLE, Parse::sNameToken, sqlite3AuthCheck(), sqlite3BeginWriteOperation(), sqlite3CheckObjectName(), sqlite3CodeVerifySchema(), sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ErrorMsg(), sqlite3FindIndex(), sqlite3FindTable(), sqlite3GetVdbe(), sqlite3LogEst(), sqlite3NameFromToken(), sqlite3OpenSchemaTable(), sqlite3ReadSchema(), sqlite3RenameTokenMap(), sqlite3TwoPartName(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), sqlite3VdbeJumpHere(), sqlite3VdbeUsesBtree(), SQLITE_CREATE_TABLE, SQLITE_CREATE_TEMP_TABLE, SQLITE_CREATE_TEMP_VIEW, SQLITE_CREATE_VIEW, SQLITE_INSERT, SQLITE_LegacyFileFmt, SQLITE_MAX_FILE_FORMAT, SQLITE_NOMEM_BKPT, SQLITE_OK, VdbeCoverage, Db::zDbSName, Table::zName, and zName.

Referenced by sqlite3VtabBeginParse(), and yy_reduce().

◆ sqlite3StatusDown()

SQLITE_PRIVATE void sqlite3StatusDown ( int op,
int N )

Definition at line 21413 of file sqlite3.c.

21414 {
21415 wsdStat.mxValue[op] = wsdStat.nowValue[op];
21416 }
21417}
21418SQLITE_PRIVATE void sqlite3StatusDown(int op, int N){
21420 assert( N>=0 );
21421 assert( op>=0 && op<ArraySize(statMutex) );

References wsdStat.

◆ sqlite3StatusHighwater()

SQLITE_PRIVATE void sqlite3StatusHighwater ( int op,
int X )

Definition at line 21427 of file sqlite3.c.

21432 {
21433 sqlite3StatValueType newValue;
21435 assert( X>=0 );
21436 newValue = (sqlite3StatValueType)X;
21437 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
21438 assert( op>=0 && op<ArraySize(statMutex) );
21440 : sqlite3MallocMutex()) );
21441 assert( op==SQLITE_STATUS_MALLOC_SIZE
sqlite3_int64 sqlite3StatValueType
Definition sqlite3.c:21336

References ArraySize, sqlite3_mutex_held(), sqlite3MallocMutex(), sqlite3Pcache1Mutex(), SQLITE_STATUS_MALLOC_SIZE, SQLITE_STATUS_PAGECACHE_SIZE, SQLITE_STATUS_PARSER_STACK, statMutex, wsdStat, and wsdStatInit.

Referenced by mallocWithAlarm(), pcache1Alloc(), and sqlite3RunParser().

◆ sqlite3StatusUp()

SQLITE_PRIVATE void sqlite3StatusUp ( int op,
int N )

Definition at line 21402 of file sqlite3.c.

21407 {
21409 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
21410 assert( op>=0 && op<ArraySize(statMutex) );
21412 : sqlite3MallocMutex()) );

References ArraySize, sqlite3_mutex_held(), sqlite3MallocMutex(), sqlite3Pcache1Mutex(), statMutex, wsdStat, and wsdStatInit.

Referenced by mallocWithAlarm(), and pcache1Alloc().

◆ sqlite3StatusValue()

SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue ( int op)

Definition at line 21382 of file sqlite3.c.

21387 {
21389 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );

References ArraySize, sqlite3_mutex_held(), sqlite3MallocMutex(), sqlite3Pcache1Mutex(), statMutex, wsdStat, and wsdStatInit.

Referenced by mallocWithAlarm(), and sqlite3_soft_heap_limit64().

◆ sqlite3Step()

static int sqlite3Step ( Vdbe * p)
static

Definition at line 83596 of file sqlite3.c.

83602 {
83603 sqlite3 *db;
83604 int rc;
83605
83606 assert(p);
83607 if( p->magic!=VDBE_MAGIC_RUN ){
83608 /* We used to require that sqlite3_reset() be called before retrying
83609 ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
83610 ** with version 3.7.0, we changed this so that sqlite3_reset() would
83611 ** be called automatically instead of throwing the SQLITE_MISUSE error.
83612 ** This "automatic-reset" change is not technically an incompatibility,
83613 ** since any application that receives an SQLITE_MISUSE is broken by
83614 ** definition.
83615 **
83616 ** Nevertheless, some published applications that were originally written
83617 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
83618 ** returns, and those were broken by the automatic-reset change. As a
83619 ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
83620 ** legacy behavior of returning SQLITE_MISUSE for cases where the
83621 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
83622 ** or SQLITE_BUSY error.
83623 */
83624#ifdef SQLITE_OMIT_AUTORESET
83625 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
83627 }else{
83628 return SQLITE_MISUSE_BKPT;
83629 }
83630#else
83632#endif
83633 }
83634
83635 /* Check that malloc() has not failed. If it has, return early. */
83636 db = p->db;
83637 if( db->mallocFailed ){
83638 p->rc = SQLITE_NOMEM;
83639 return SQLITE_NOMEM_BKPT;
83640 }
83641
83642 if( p->pc<0 && p->expired ){
83643 p->rc = SQLITE_SCHEMA;
83644 rc = SQLITE_ERROR;
83645 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
83646 /* If this statement was prepared using saved SQL and an
83647 ** error has occurred, then return the error code in p->rc to the
83648 ** caller. Set the error code in the database handle to the same value.
83649 */
83651 }
83652 goto end_of_step;
83653 }
83654 if( p->pc<0 ){
83655 /* If there are no other statements currently running, then
83656 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
83657 ** from interrupting a statement that has not yet started.
83658 */
83659 if( db->nVdbeActive==0 ){
83660 AtomicStore(&db->u1.isInterrupted, 0);
83661 }
83662
83663 assert( db->nVdbeWrite>0 || db->autoCommit==0
83664 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
83665 );
83666
83667#ifndef SQLITE_OMIT_TRACE
83669 && !db->init.busy && p->zSql ){
83671 }else{
83672 assert( p->startTime==0 );
83673 }
83674#endif
83675
83676 db->nVdbeActive++;
83677 if( p->readOnly==0 ) db->nVdbeWrite++;
83678 if( p->bIsReader ) db->nVdbeRead++;
83679 p->pc = 0;
83680 }
83681#ifdef SQLITE_DEBUG
83682 p->rcApp = SQLITE_OK;
83683#endif
83684#ifndef SQLITE_OMIT_EXPLAIN
83685 if( p->explain ){
83686 rc = sqlite3VdbeList(p);
83687 }else
83688#endif /* SQLITE_OMIT_EXPLAIN */
83689 {
83690 db->nVdbeExec++;
83691 rc = sqlite3VdbeExec(p);
83692 db->nVdbeExec--;
83693 }
83694
83695 if( rc!=SQLITE_ROW ){
83696#ifndef SQLITE_OMIT_TRACE
83697 /* If the statement completed successfully, invoke the profile callback */
83698 checkProfileCallback(db, p);
83699#endif
83700
83701 if( rc==SQLITE_DONE && db->autoCommit ){
83702 assert( p->rc==SQLITE_OK );
83703 p->rc = doWalCallbacks(db);
83704 if( p->rc!=SQLITE_OK ){
83705 rc = SQLITE_ERROR;
83706 }
83707 }else if( rc!=SQLITE_DONE && (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
83708 /* If this statement was prepared using saved SQL and an
83709 ** error has occurred, then return the error code in p->rc to the
83710 ** caller. Set the error code in the database handle to the same value.
83711 */
83713 }
83714 }
83715
83716 db->errCode = rc;
83717 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
83718 p->rc = SQLITE_NOMEM_BKPT;
83719 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ) rc = p->rc;
83720 }
83721end_of_step:
83722 /* There are only a limited number of result codes allowed from the
83723 ** statements prepared using the legacy sqlite3_prepare() interface */
static int doWalCallbacks(sqlite3 *db)
Definition sqlite3.c:83566
SQLITE_PRIVATE int sqlite3VdbeList(Vdbe *)
Definition sqlite3.c:79834
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p)
Definition sqlite3.c:80968
#define VDBE_MAGIC_RUN
Definition sqlite3.c:21160
u32 magic
Definition sqlite3.c:21088
bft explain
Definition sqlite3.c:21128
int nVdbeWrite
Definition sqlite3.c:16866

References AtomicStore, sqlite3::autoCommit, Vdbe::bIsReader, sqlite3::sqlite3InitInfo::busy, checkProfileCallback, Vdbe::db, doWalCallbacks(), sqlite3::errCode, sqlite3::errMask, Vdbe::expired, Vdbe::explain, sqlite3::init, sqlite3::isInterrupted, Vdbe::magic, sqlite3::mallocFailed, sqlite3::mTrace, sqlite3::nDeferredCons, sqlite3::nDeferredImmCons, sqlite3::nVdbeActive, sqlite3::nVdbeExec, sqlite3::nVdbeRead, sqlite3::nVdbeWrite, Vdbe::pc, Vdbe::prepFlags, sqlite3::pVfs, Vdbe::rc, Vdbe::readOnly, sqlite3_reset(), sqlite3ApiExit(), sqlite3OsCurrentTimeInt64(), sqlite3VdbeExec(), sqlite3VdbeList(), sqlite3VdbeTransferError(), SQLITE_BUSY, SQLITE_DONE, SQLITE_ERROR, SQLITE_LOCKED, SQLITE_MISUSE, SQLITE_MISUSE_BKPT, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_PREPARE_SAVESQL, SQLITE_ROW, SQLITE_SCHEMA, SQLITE_TRACE_PROFILE, SQLITE_TRACE_XPROFILE, Vdbe::startTime, sqlite3::u1, VDBE_MAGIC_RUN, and Vdbe::zSql.

Referenced by sqlite3_step().

◆ sqlite3StmtCurrentTime()

SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime ( sqlite3_context * p)

Definition at line 83825 of file sqlite3.c.

83831 {
83832 int rc;
83833#ifndef SQLITE_ENABLE_STAT4
83834 sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime;
83835 assert( p->pVdbe!=0 );
83836#else
83837 sqlite3_int64 iTime = 0;
83838 sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
83839#endif
i64 iCurrentTime
Definition sqlite3.c:21096

References sqlite3_value::db, Vdbe::iCurrentTime, sqlite3_context::pOut, sqlite3_context::pVdbe, sqlite3::pVfs, and sqlite3OsCurrentTimeInt64().

Referenced by setDateTimeToCurrent().

◆ sqlite3StorageColumnToTable()

SQLITE_PRIVATE i16 sqlite3StorageColumnToTable ( Table * pTab,
i16 iCol )

Definition at line 111342 of file sqlite3.c.

111348 {
111349 if( pTab->tabFlags & TF_HasVirtual ){
111350 int i;

References Table::aCol, COLFLAG_VIRTUAL, Column::colFlags, Table::tabFlags, and TF_HasVirtual.

Referenced by sqlite3WhereEnd().

◆ sqlite3StrAccumEnlarge()

static int sqlite3StrAccumEnlarge ( StrAccum * p,
int N )
static

Definition at line 29045 of file sqlite3.c.

29051 {
29052 char *zNew;
29053 assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
29054 if( p->accError ){
29057 return 0;
29058 }
29059 if( p->mxAlloc==0 ){
29061 return p->nAlloc - p->nChar - 1;
29062 }else{
29063 char *zOld = isMalloced(p) ? p->zText : 0;
29064 i64 szNew = p->nChar;
29065 szNew += N + 1;
29066 if( szNew+p->nChar<=p->mxAlloc ){
29067 /* Force exponential buffer size growth as long as it does not overflow,
29068 ** to avoid having to call this routine too often */
29069 szNew += p->nChar;
29070 }
29071 if( szNew > p->mxAlloc ){
29074 return 0;
29075 }else{
29076 p->nAlloc = (int)szNew;
29077 }
29078 if( p->db ){
29079 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
29080 }else{
29081 zNew = sqlite3Realloc(zOld, p->nAlloc);
29082 }
29083 if( zNew ){
29084 assert( p->zText!=0 || p->nChar==0 );
29085 if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
29086 p->zText = zNew;
29087 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
29089 }else{

References sqlite3_str::accError, sqlite3_str::db, isMalloced, sqlite3_str::mxAlloc, sqlite3_str::nAlloc, sqlite3_str::nChar, sqlite3_str::printfFlags, setStrAccumError(), sqlite3_str_reset(), sqlite3DbMallocSize(), sqlite3DbRealloc(), sqlite3Realloc(), SQLITE_NOMEM, SQLITE_PRINTF_MALLOCED, SQLITE_TOOBIG, testcase, and sqlite3_str::zText.

Referenced by enlargeAndAppend().

◆ sqlite3StrAccumFinish()

SQLITE_PRIVATE char * sqlite3StrAccumFinish ( StrAccum * p)

Definition at line 29163 of file sqlite3.c.

29163 {
29165 }
29166 p->zText = zText;
29167 return zText;
29168}
29170 if( p->zText ){
29171 p->zText[p->nChar] = 0;

Referenced by sqlite3BtreeIntegrityCheck(), sqlite3VdbeDisplayP4(), sqlite3VdbeExpandSql(), sqlite3VdbeMemTranslate(), and sqlite3WhereExplainOneScan().

◆ sqlite3StrAccumInit()

SQLITE_PRIVATE void sqlite3StrAccumInit ( StrAccum * p,
sqlite3 * db,
char * zBase,
int n,
int mx )

Definition at line 29240 of file sqlite3.c.

29241 : Size of zBase in bytes. If total space requirements never exceed
29242** n then no memory allocations ever occur.
29243** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
29244** allocations will ever occur.
29245*/
29246SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
29247 p->zText = zBase;
29248 p->db = db;

References sqlite3_str::db, sqlite3_str::mxAlloc, sqlite3_str::nAlloc, and sqlite3_str::zText.

Referenced by renderLogMsg(), sqlite3BtreeIntegrityCheck(), sqlite3VdbeDisplayP4(), sqlite3VdbeExpandSql(), sqlite3VdbeMemTranslate(), sqlite3WhereExplainOneScan(), and vdbeMemRenderNum().

◆ sqlite3StrICmp()

SQLITE_PRIVATE int sqlite3StrICmp ( const char * zLeft,
const char * zRight )

Definition at line 31468 of file sqlite3.c.

31468 : 0;
31469 }else if( zRight==0 ){
31470 return 1;
31471 }
31472 return sqlite3StrICmp(zLeft, zRight);
31473}
31474SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){
31475 unsigned char *a, *b;
31476 int c, x;
31477 a = (unsigned char *)zLeft;
31478 b = (unsigned char *)zRight;
31479 for(;;){
31480 c = *a;
31481 x = *b;
31482 if( c==x ){
31483 if( c==0 ) break;
31484 }else{
31485 c = (int)UpperToLower[c] - (int)UpperToLower[x];
31486 if( c ) break;
#define UpperToLower
Definition sqlite3.c:31448

Referenced by collationMatch(), findElementWithHash(), findIndexCol(), fkParentIsModified(), getAutoVacuum(), getLockingMode(), getTempStore(), isAuxiliaryVtabOperator(), isDupColumn(), lookupName(), minMaxQuery(), nameInUsingClause(), parseDateOrTime(), searchWith(), selectExpander(), sqlite3_table_column_metadata(), sqlite3AddPrimaryKey(), sqlite3AlterRenameColumn(), sqlite3CreateForeignKey(), sqlite3CreateIndex(), sqlite3ExprCompare(), sqlite3FindInIndex(), sqlite3FindTable(), sqlite3FkLocateIndex(), sqlite3IndexedByLookup(), sqlite3Insert(), sqlite3IsTrueOrFalse(), sqlite3MatchEName(), sqlite3Pragma(), sqlite3TriggerList(), sqlite3Update(), sqlite3VdbeExec(), sqlite3WithAdd(), whereIndexExprTrans(), wherePathSatisfiesOrderBy(), whereRangeVectorLen(), whereScanNext(), and withExpand().

◆ sqlite3StrIHash()

SQLITE_PRIVATE u8 sqlite3StrIHash ( const char * z)

Definition at line 31503 of file sqlite3.c.

31503 : UpperToLower[*a] - UpperToLower[*b];
31504}
31505
31506/*
31507** Compute an 8-bit hash on a string that is insensitive to case differences
31508*/
31509SQLITE_PRIVATE u8 sqlite3StrIHash(const char *z){
31510 u8 h = 0;
31511 if( z==0 ) return 0;

Referenced by lookupName(), sqlite3AddColumn(), sqlite3AlterBeginAddColumn(), and sqlite3ColumnsFromExprList().

◆ sqlite3StringToId()

static void sqlite3StringToId ( Expr * p)
static

Definition at line 111892 of file sqlite3.c.

111898 {

References Expr::op, Expr::pLeft, TK_COLLATE, TK_ID, and TK_STRING.

Referenced by sqlite3AddPrimaryKey(), and sqlite3CreateIndex().

◆ sqlite3Strlen30()

◆ sqlite3SubInt64()

SQLITE_PRIVATE int sqlite3SubInt64 ( i64 * pA,
i64 iB )

Definition at line 32599 of file sqlite3.c.

32605 {
32606#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
32607 return __builtin_sub_overflow(*pA, iB, pA);
32608#else
32609 testcase( iB==SMALLEST_INT64+1 );
32610 if( iB==SMALLEST_INT64 ){
32611 testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
32612 if( (*pA)>=0 ) return 1;
32613 *pA -= iB;

Referenced by sqlite3VdbeExec().

◆ sqlite3SubselectError()

SQLITE_PRIVATE void sqlite3SubselectError ( Parse * pParse,
int nActual,
int nExpect )

Definition at line 102484 of file sqlite3.c.

References Parse::nErr, and sqlite3ErrorMsg().

Referenced by sqlite3ExprCheckIN(), sqlite3ExprCodeTarget(), and sqlite3VectorErrorMsg().

◆ sqlite3SystemError()

SQLITE_PRIVATE void sqlite3SystemError ( sqlite3 * db,
int rc )

Definition at line 31301 of file sqlite3.c.

31307 {

Referenced by sqlite3ErrorFinish(), sqlite3ErrorWithMsg(), and sqlite3VdbeExec().

◆ sqlite3TableAffinity()

SQLITE_PRIVATE void sqlite3TableAffinity ( Vdbe * v,
Table * pTab,
int iReg )

Definition at line 120678 of file sqlite3.c.

120684 {
120685 int i, j;
120686 char *zColAff = pTab->zColAff;
120687 if( zColAff==0 ){
120688 sqlite3 *db = sqlite3VdbeDb(v);
120689 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
120690 if( !zColAff ){
120691 sqlite3OomFault(db);
120692 return;
120693 }
120694
120695 for(i=j=0; i<pTab->nCol; i++){
120696 assert( pTab->aCol[i].affinity!=0 );
120697 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
120698 zColAff[j++] = pTab->aCol[i].affinity;
120699 }
120700 }
120701 do{
120702 zColAff[j--] = 0;
120703 }while( j>=0 && zColAff[j]<=SQLITE_AFF_BLOB );
120704 pTab->zColAff = zColAff;
120705 }
120706 assert( zColAff!=0 );
120707 i = sqlite3Strlen30NN(zColAff);
120708 if( i ){
120709 if( iReg ){
#define sqlite3Strlen30NN(C)
Definition sqlite3.c:19343
char * zColAff
Definition sqlite3.c:17493

References Table::aCol, Column::affinity, COLFLAG_VIRTUAL, Column::colFlags, Table::nCol, OP_Affinity, sqlite3DbMallocRaw(), sqlite3OomFault(), sqlite3Strlen30NN, sqlite3VdbeAddOp4(), sqlite3VdbeChangeP4(), sqlite3VdbeDb(), SQLITE_AFF_BLOB, and Table::zColAff.

Referenced by sqlite3ComputeGeneratedColumns(), sqlite3EndTable(), sqlite3GenerateConstraintChecks(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3TableColumnAffinity()

SQLITE_PRIVATE char sqlite3TableColumnAffinity ( Table * pTab,
int iCol )

◆ sqlite3TableColumnToIndex()

SQLITE_PRIVATE i16 sqlite3TableColumnToIndex ( Index * pIdx,
i16 iCol )

◆ sqlite3TableColumnToStorage()

SQLITE_PRIVATE i16 sqlite3TableColumnToStorage ( Table * pTab,
i16 iCol )

Definition at line 111390 of file sqlite3.c.

111396 {
111397 int i;
111398 i16 n;
111399 assert( iCol<pTab->nCol );
111400 if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
111401 for(i=0, n=0; i<iCol; i++){
111402 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
111403 }
111404 if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ){
111405 /* iCol is a virtual column itself */

References Table::aCol, COLFLAG_VIRTUAL, Column::colFlags, Table::nNVCol, Table::tabFlags, and TF_HasVirtual.

Referenced by codeDeferredSeek(), exprTableRegister(), fkLookupParent(), lookupName(), sqlite3ComputeGeneratedColumns(), sqlite3ExprCodeTarget(), sqlite3FkCheck(), sqlite3GenerateConstraintChecks(), sqlite3GenerateRowDelete(), and sqlite3Update().

◆ sqlite3TableLock()

SQLITE_PRIVATE void sqlite3TableLock ( Parse * pParse,
int iDb,
Pgno iTab,
u8 isWriteLock,
const char * zName )

Definition at line 110437 of file sqlite3.c.

110449 {
110450 Parse *pToplevel = sqlite3ParseToplevel(pParse);
110451 int i;
110452 int nBytes;
110453 TableLock *p;
110454 assert( iDb>=0 );
110455
110456 if( iDb==1 ) return;
110457 if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
110458 for(i=0; i<pToplevel->nTableLock; i++){
110459 p = &pToplevel->aTableLock[i];
110460 if( p->iDb==iDb && p->iTab==iTab ){
110461 p->isWriteLock = (p->isWriteLock || isWriteLock);
110462 return;
110463 }
110464 }
110465
110466 nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
110467 pToplevel->aTableLock =
110468 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
110469 if( pToplevel->aTableLock ){
110470 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
110471 p->iDb = iDb;
110472 p->iTab = iTab;
110473 p->isWriteLock = isWriteLock;
SQLITE_PRIVATE int sqlite3BtreeSharable(Btree *)
Definition sqlite3.c:75034
struct TableLock TableLock
Definition sqlite3.c:14694

References sqlite3::aDb, Parse::aTableLock, Parse::db, TableLock::iDb, TableLock::isWriteLock, TableLock::iTab, Parse::nTableLock, Db::pBt, sqlite3BtreeSharable(), sqlite3DbReallocOrFree(), sqlite3OomFault(), sqlite3ParseToplevel, TableLock::zLockName, and zName.

Referenced by analyzeOneTable(), openStatTable(), sqlite3DeleteFrom(), sqlite3FindInIndex(), sqlite3FkCheck(), sqlite3OpenTable(), sqlite3OpenTableAndIndices(), sqlite3Pragma(), sqlite3RefillIndex(), sqlite3Select(), sqlite3WhereBegin(), and xferOptimization().

◆ sqlite3TempInMemory()

SQLITE_PRIVATE int sqlite3TempInMemory ( const sqlite3 * db)

Definition at line 163462 of file sqlite3.c.

163468 {
163469#if SQLITE_TEMP_STORE==1
163470 return ( db->temp_store==2 );
163471#endif
163472#if SQLITE_TEMP_STORE==2
163473 return ( db->temp_store!=1 );
163474#endif
163475#if SQLITE_TEMP_STORE==3
163476 UNUSED_PARAMETER(db);
163477 return 1;

References sqlite3::temp_store, and UNUSED_PARAMETER.

Referenced by sqlite3BtreeBeginTrans(), sqlite3BtreeOpen(), and sqlite3VdbeSorterInit().

◆ sqlite3TestExtInit()

static int sqlite3TestExtInit ( sqlite3 * db)
static

Definition at line 161027 of file sqlite3.c.

References sqlite3FaultSim().

◆ sqlite3ThreadCreate() [1/2]

SQLITE_PRIVATE int sqlite3ThreadCreate ( SQLiteThread ** ,
void * *)(void *,
void *  )

◆ sqlite3ThreadCreate() [2/2]

SQLITE_PRIVATE int sqlite3ThreadCreate ( SQLiteThread ** ppThread,
void *(*)(void *) xTask,
void * pIn )

Definition at line 30416 of file sqlite3.c.

30426 {
30427 SQLiteThread *p;
30428 int rc;
30429
30430 assert( ppThread!=0 );
30431 assert( xTask!=0 );
30432 /* This routine is never used in single-threaded mode */
30433 assert( sqlite3GlobalConfig.bCoreMutex!=0 );
30434
30435 *ppThread = 0;
30436 p = sqlite3Malloc(sizeof(*p));
30437 if( p==0 ) return SQLITE_NOMEM_BKPT;
30438 memset(p, 0, sizeof(*p));
30439 p->xTask = xTask;
30440 p->pIn = pIn;
30441 /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a
30442 ** function that returns SQLITE_ERROR when passed the argument 200, that
30443 ** forces worker threads to run sequentially and deterministically
30444 ** for testing purposes. */
30445 if( sqlite3FaultSim(200) ){
30446 rc = 1;
30447 }else{
30448 rc = pthread_create(&p->tid, 0, xTask, pIn);
30449 }
30450 if( rc ){
pthread_t tid
Definition sqlite3.c:30408
void *(* xTask)(void *)
Definition sqlite3.c:30411

◆ sqlite3ThreadJoin()

SQLITE_PRIVATE int sqlite3ThreadJoin ( SQLiteThread * p,
void ** ppOut )

Definition at line 30453 of file sqlite3.c.

30459 {
30460 int rc;
30461
30462 assert( ppOut!=0 );
30463 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT;
30464 if( p->done ){
30465 *ppOut = p->pOut;
30466 rc = SQLITE_OK;
void * pOut
Definition sqlite3.c:30410

Referenced by vdbeSorterJoinThread().

◆ sqlite3TokenInit()

SQLITE_PRIVATE void sqlite3TokenInit ( Token * p,
char * z )

◆ sqlite3TransferBindings()

SQLITE_PRIVATE int sqlite3TransferBindings ( sqlite3_stmt * pFromStmt,
sqlite3_stmt * pToStmt )

Definition at line 84595 of file sqlite3.c.

84601 {
84602 Vdbe *pFrom = (Vdbe*)pFromStmt;
84603 Vdbe *pTo = (Vdbe*)pToStmt;
84604 int i;
84605 assert( pTo->db==pFrom->db );
84606 assert( pTo->nVar==pFrom->nVar );

Referenced by sqlite3_transfer_bindings(), and sqlite3Reprepare().

◆ sqlite3TriggerColmask()

SQLITE_PRIVATE u32 sqlite3TriggerColmask ( Parse * pParse,
Trigger * pTrigger,
ExprList * pChanges,
int isNew,
int tr_tm,
Table * pTab,
int orconf )

Definition at line 137563 of file sqlite3.c.

137577 {
137578 const int op = pChanges ? TK_UPDATE : TK_DELETE;
137579 u32 mask = 0;
137580 Trigger *p;
137581
137582 assert( isNew==1 || isNew==0 );
137583 for(p=pTrigger; p; p=p->pNext){
137584 if( p->op==op && (tr_tm&p->tr_tm)
137585 && checkColumnOverlap(p->pColumns,pChanges)
137586 ){
137587 TriggerPrg *pPrg;
137588 pPrg = getRowTrigger(pParse, p, pTab, orconf);
137589 if( pPrg ){
137590 mask |= pPrg->aColmask[isNew];
static int checkColumnOverlap(IdList *pIdList, ExprList *pEList)
Definition sqlite3.c:137078

References TriggerPrg::aColmask, checkColumnOverlap(), getRowTrigger(), mask, Trigger::op, Trigger::pColumns, Trigger::pNext, TK_DELETE, TK_UPDATE, and Trigger::tr_tm.

Referenced by sqlite3GenerateRowDelete(), and sqlite3Update().

◆ sqlite3TriggerDeleteStep()

SQLITE_PRIVATE TriggerStep * sqlite3TriggerDeleteStep ( Parse * pParse,
Token * pTableName,
Expr * pWhere,
const char * zStart,
const char * zEnd )

Definition at line 136911 of file sqlite3.c.

136923 {
136924 sqlite3 *db = pParse->db;
136925 TriggerStep *pTriggerStep;
136926
136927 pTriggerStep = triggerStepAllocate(pParse, TK_DELETE, pTableName,zStart,zEnd);
136928 if( pTriggerStep ){
136929 if( IN_RENAME_OBJECT ){
136930 pTriggerStep->pWhere = pWhere;
136931 pWhere = 0;
136932 }else{
136933 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
static TriggerStep * triggerStepAllocate(Parse *pParse, u8 op, Token *pName, const char *zStart, const char *zEnd)
Definition sqlite3.c:136794

References Parse::db, EXPRDUP_REDUCE, IN_RENAME_OBJECT, OE_Default, TriggerStep::orconf, TriggerStep::pWhere, sqlite3ExprDelete(), sqlite3ExprDup(), TK_DELETE, and triggerStepAllocate().

Referenced by yy_reduce().

◆ sqlite3TriggerInsertStep()

SQLITE_PRIVATE TriggerStep * sqlite3TriggerInsertStep ( Parse * pParse,
Token * pTableName,
IdList * pColumn,
Select * pSelect,
u8 orconf,
Upsert * pUpsert,
const char * zStart,
const char * zEnd )

Definition at line 136826 of file sqlite3.c.

136841 {
136842 sqlite3 *db = pParse->db;
136843 TriggerStep *pTriggerStep;
136844
136845 assert(pSelect != 0 || db->mallocFailed);
136846
136847 pTriggerStep = triggerStepAllocate(pParse, TK_INSERT, pTableName,zStart,zEnd);
136848 if( pTriggerStep ){
136849 if( IN_RENAME_OBJECT ){
136850 pTriggerStep->pSelect = pSelect;
136851 pSelect = 0;
136852 }else{
136853 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
136854 }
136855 pTriggerStep->pIdList = pColumn;
136856 pTriggerStep->pUpsert = pUpsert;
136857 pTriggerStep->orconf = orconf;
136858 if( pUpsert ){
136859 sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget);
136860 }
136861 }else{
136862 testcase( pColumn );
136863 sqlite3IdListDelete(db, pColumn);
136864 testcase( pUpsert );

References Parse::db, EXPRDUP_REDUCE, IN_RENAME_OBJECT, sqlite3::mallocFailed, TriggerStep::orconf, TriggerStep::pIdList, TriggerStep::pSelect, TriggerStep::pUpsert, Upsert::pUpsertTarget, sqlite3HasExplicitNulls(), sqlite3IdListDelete(), sqlite3SelectDelete(), sqlite3SelectDup(), sqlite3UpsertDelete(), testcase, TK_INSERT, and triggerStepAllocate().

Referenced by yy_reduce().

◆ sqlite3TriggerList()

SQLITE_PRIVATE Trigger * sqlite3TriggerList ( Parse * pParse,
Table * pTab )

Definition at line 136434 of file sqlite3.c.

136436 : This routine returns a list of all triggers
136437** that fire off of pTab. The list will include any TEMP triggers on
136438** pTab as well as the triggers lised in pTab->pTrigger.
136439*/
136441 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
136442 Trigger *pList = 0; /* List of triggers to return */
136443
136444 if( pParse->disableTriggers ){
136445 return 0;
136446 }
136447
136448 if( pTmpSchema!=pTab->pSchema ){
136449 HashElem *p;
136450 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
136451 for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){
136452 Trigger *pTrig = (Trigger *)sqliteHashData(p);
136453 if( pTrig->pTabSchema==pTab->pSchema
136454 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
136455 ){
136456 pTrig->pNext = (pList ? pList : pTab->pTrigger);
136457 pList = pTrig;

References sqlite3::aDb, Parse::db, Parse::disableTriggers, Trigger::pNext, Db::pSchema, Table::pSchema, Trigger::pTabSchema, Table::pTrigger, sqlite3StrICmp(), sqliteHashData, sqliteHashFirst, sqliteHashNext, Trigger::table, Schema::trigHash, and Table::zName.

Referenced by sqlite3TriggersExist(), and xferOptimization().

◆ sqlite3TriggerSelectStep()

SQLITE_PRIVATE TriggerStep * sqlite3TriggerSelectStep ( sqlite3 * db,
Select * pSelect,
const char * zStart,
const char * zEnd )

Definition at line 136770 of file sqlite3.c.

136781 {
136782 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
136783 if( pTriggerStep==0 ) {
136784 sqlite3SelectDelete(db, pSelect);
136785 return 0;
136786 }

References OE_Default, TriggerStep::op, TriggerStep::orconf, TriggerStep::pSelect, sqlite3DbMallocZero(), sqlite3SelectDelete(), TK_SELECT, triggerSpanDup(), and TriggerStep::zSpan.

Referenced by yy_reduce().

◆ sqlite3TriggersExist()

SQLITE_PRIVATE Trigger * sqlite3TriggersExist ( Parse * pParse,
Table * pTab,
int op,
ExprList * pChanges,
int * pMask )

Definition at line 137093 of file sqlite3.c.

137105 {
137106 int mask = 0;
137107 Trigger *pList = 0;
137108 Trigger *p;
137109
137110 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
137111 pList = sqlite3TriggerList(pParse, pTab);
137112 }
137113 assert( pList==0 || IsVirtual(pTab)==0 );
137114 for(p=pList; p; p=p->pNext){
137115 if( p->op==op && checkColumnOverlap(p->pColumns, pChanges) ){
137116 mask |= p->tr_tm;
137117 }

References checkColumnOverlap(), Parse::db, sqlite3::flags, IsVirtual, mask, Trigger::op, Trigger::pColumns, Trigger::pNext, sqlite3TriggerList(), SQLITE_EnableTrigger, and Trigger::tr_tm.

Referenced by sqlite3DeleteFrom(), sqlite3GenerateConstraintChecks(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3TriggerStepSrc()

SQLITE_PRIVATE SrcList * sqlite3TriggerStepSrc ( Parse * pParse,
TriggerStep * pStep )

Definition at line 137129 of file sqlite3.c.

137138 {
137139 sqlite3 *db = pParse->db;
137140 SrcList *pSrc; /* SrcList to be returned */
137141 char *zName = sqlite3DbStrDup(db, pStep->zTarget);
137142 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
137143 assert( pSrc==0 || pSrc->nSrc==1 );
137144 assert( zName || pSrc==0 );
137145 if( pSrc ){
137146 Schema *pSchema = pStep->pTrig->pSchema;
137147 pSrc->a[0].zName = zName;
137148 if( pSchema!=db->aDb[1].pSchema ){
137149 pSrc->a[0].pSchema = pSchema;
137150 }
137151 if( pStep->pFrom ){
137152 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
137153 pSrc = sqlite3SrcListAppendList(pParse, pSrc, pDup);
SQLITE_PRIVATE SrcList * sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2)
Definition sqlite3.c:114962

References SrcList::a, sqlite3::aDb, Parse::db, SrcList::nSrc, TriggerStep::pFrom, Db::pSchema, SrcList::SrcList_item::pSchema, Trigger::pSchema, TriggerStep::pTrig, sqlite3DbFree(), sqlite3DbStrDup(), sqlite3SrcListAppend(), sqlite3SrcListAppendList(), sqlite3SrcListDup(), SrcList::SrcList_item::zName, zName, and TriggerStep::zTarget.

Referenced by renameResolveTrigger().

◆ sqlite3TriggerUpdateStep()

SQLITE_PRIVATE TriggerStep * sqlite3TriggerUpdateStep ( Parse * pParse,
Token * pTableName,
SrcList * pFrom,
ExprList * pEList,
Expr * pWhere,
u8 orconf,
const char * zStart,
const char * zEnd )

Definition at line 136871 of file sqlite3.c.

136886 {
136887 sqlite3 *db = pParse->db;
136888 TriggerStep *pTriggerStep;
136889
136890 pTriggerStep = triggerStepAllocate(pParse, TK_UPDATE, pTableName,zStart,zEnd);
136891 if( pTriggerStep ){
136892 if( IN_RENAME_OBJECT ){
136893 pTriggerStep->pExprList = pEList;
136894 pTriggerStep->pWhere = pWhere;
136895 pTriggerStep->pFrom = pFrom;
136896 pEList = 0;
136897 pWhere = 0;
136898 pFrom = 0;
136899 }else{
136900 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
136901 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
136902 pTriggerStep->pFrom = sqlite3SrcListDup(db, pFrom, EXPRDUP_REDUCE);
136903 }
136904 pTriggerStep->orconf = orconf;

References Parse::db, EXPRDUP_REDUCE, IN_RENAME_OBJECT, TriggerStep::orconf, TriggerStep::pExprList, TriggerStep::pFrom, TriggerStep::pWhere, sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprListDelete(), sqlite3ExprListDup(), sqlite3SrcListDelete(), sqlite3SrcListDup(), TK_UPDATE, and triggerStepAllocate().

Referenced by yy_reduce().

◆ sqlite3TwoPartName()

SQLITE_PRIVATE int sqlite3TwoPartName ( Parse * pParse,
Token * pName1,
Token * pName2,
Token ** pUnqual )

Definition at line 111217 of file sqlite3.c.

111228 {
111229 int iDb; /* Database holding the object */
111230 sqlite3 *db = pParse->db;
111231
111232 assert( pName2!=0 );
111233 if( pName2->n>0 ){
111234 if( db->init.busy ) {
111235 sqlite3ErrorMsg(pParse, "corrupt database");
111236 return -1;
111237 }
111238 *pUnqual = pName2;
111239 iDb = sqlite3FindDb(db, pName1);
111240 if( iDb<0 ){
111241 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
111242 return -1;
111243 }
111244 }else{
111245 assert( db->init.iDb==0 || db->init.busy || IN_RENAME_OBJECT

References sqlite3::sqlite3InitInfo::busy, Parse::db, DBFLAG_Vacuum, sqlite3::sqlite3InitInfo::iDb, IN_RENAME_OBJECT, sqlite3::init, sqlite3::mDbFlags, Token::n, sqlite3ErrorMsg(), and sqlite3FindDb().

Referenced by sqlite3Analyze(), sqlite3BeginTrigger(), sqlite3CreateIndex(), sqlite3Pragma(), sqlite3Reindex(), sqlite3StartTable(), and sqlite3Vacuum().

◆ sqlite3UniqueConstraint()

SQLITE_PRIVATE void sqlite3UniqueConstraint ( Parse * pParse,
int onError,
Index * pIdx )

Definition at line 115234 of file sqlite3.c.

115244 {
115245 char *zErr;
115246 int j;
115247 StrAccum errMsg;
115248 Table *pTab = pIdx->pTable;
115249
115250 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
115251 pParse->db->aLimit[SQLITE_LIMIT_LENGTH]);
115252 if( pIdx->aColExpr ){
115253 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
115254 }else{
115255 for(j=0; j<pIdx->nKeyCol; j++){
115256 char *zCol;
115257 assert( pIdx->aiColumn[j]>=0 );
115258 zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
115259 if( j ) sqlite3_str_append(&errMsg, ", ", 2);
115260 sqlite3_str_appendall(&errMsg, pTab->zName);
115261 sqlite3_str_append(&errMsg, ".", 1);
115262 sqlite3_str_appendall(&errMsg, zCol);
115263 }
115264 }

Referenced by sqlite3GenerateConstraintChecks(), and sqlite3RefillIndex().

◆ sqlite3UnlinkAndDeleteIndex()

SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex ( sqlite3 * db,
int iDb,
const char * zIdxName )

Definition at line 110905 of file sqlite3.c.

110911 {
110912 Index *pIndex;
110913 Hash *pHash;
110914
110915 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
110916 pHash = &db->aDb[iDb].pSchema->idxHash;
110917 pIndex = sqlite3HashInsert(pHash, zIdxName, 0);
110918 if( ALWAYS(pIndex) ){
110919 if( pIndex->pTable->pIndex==pIndex ){
110920 pIndex->pTable->pIndex = pIndex->pNext;
110921 }else{
110922 Index *p;
110923 /* Justification of ALWAYS(); The index must be on the list of
110924 ** indices. */
110925 p = pIndex->pTable->pIndex;
110926 while( ALWAYS(p) && p->pNext!=pIndex ){ p = p->pNext; }
110927 if( ALWAYS(p && p->pNext==pIndex) ){
110928 p->pNext = pIndex->pNext;

References sqlite3::aDb, ALWAYS, DBFLAG_SchemaChange, Schema::idxHash, sqlite3::mDbFlags, Table::pIndex, Index::pNext, Db::pSchema, Index::pTable, sqlite3FreeIndex(), and sqlite3HashInsert().

Referenced by sqlite3VdbeExec().

◆ sqlite3UnlinkAndDeleteTable()

SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable ( sqlite3 * db,
int iDb,
const char * zTabName )

Definition at line 111114 of file sqlite3.c.

111120 {
111121 Table *p;
111122 Db *pDb;
111123
111124 assert( db!=0 );
111125 assert( iDb>=0 && iDb<db->nDb );
111126 assert( zTabName );
111127 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );

References sqlite3::aDb, DBFLAG_SchemaChange, sqlite3::mDbFlags, Db::pSchema, sqlite3DeleteTable(), sqlite3HashInsert(), Schema::tblHash, and testcase.

Referenced by sqlite3VdbeExec().

◆ sqlite3UnlinkAndDeleteTrigger()

SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger ( sqlite3 * db,
int iDb,
const char * zName )

Definition at line 137044 of file sqlite3.c.

137050 {
137051 Trigger *pTrigger;
137052 Hash *pHash;
137053
137054 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
137055 pHash = &(db->aDb[iDb].pSchema->trigHash);
137056 pTrigger = sqlite3HashInsert(pHash, zName, 0);
137057 if( ALWAYS(pTrigger) ){
137058 if( pTrigger->pSchema==pTrigger->pTabSchema ){
137059 Table *pTab = tableOfTrigger(pTrigger);
137060 if( pTab ){
137061 Trigger **pp;
137062 for(pp=&pTab->pTrigger; *pp; pp=&((*pp)->pNext)){
137063 if( *pp==pTrigger ){
137064 *pp = (*pp)->pNext;
137065 break;
137066 }
137067 }

Referenced by sqlite3VdbeExec().

◆ sqlite3Update()

SQLITE_PRIVATE void sqlite3Update ( Parse * pParse,
SrcList * pTabList,
ExprList * pChanges,
Expr * pWhere,
int onError,
ExprList * pOrderBy,
Expr * pLimit,
Upsert * pUpsert )

Definition at line 137872 of file sqlite3.c.

137887 {
137888 int i, j, k; /* Loop counters */
137889 Table *pTab; /* The table to be updated */
137890 int addrTop = 0; /* VDBE instruction address of the start of the loop */
137891 WhereInfo *pWInfo = 0; /* Information about the WHERE clause */
137892 Vdbe *v; /* The virtual database engine */
137893 Index *pIdx; /* For looping over indices */
137894 Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
137895 int nIdx; /* Number of indices that need updating */
137896 int nAllIdx; /* Total number of indexes */
137897 int iBaseCur; /* Base cursor number */
137898 int iDataCur; /* Cursor for the canonical data btree */
137899 int iIdxCur; /* Cursor for the first index */
137900 sqlite3 *db; /* The database structure */
137901 int *aRegIdx = 0; /* Registers for to each index and the main table */
137902 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
137903 ** an expression for the i-th column of the table.
137904 ** aXRef[i]==-1 if the i-th column is not changed. */
137905 u8 *aToOpen; /* 1 for tables and indices to be opened */
137906 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
137907 u8 chngRowid; /* Rowid changed in a normal table */
137908 u8 chngKey; /* Either chngPk or chngRowid */
137909 Expr *pRowidExpr = 0; /* Expression defining the new record number */
137910 int iRowidExpr = -1; /* Index of "rowid=" (or IPK) assignment in pChanges */
137911 AuthContext sContext; /* The authorization context */
137912 NameContext sNC; /* The name-context to resolve expressions in */
137913 int iDb; /* Database containing the table being updated */
137914 int eOnePass; /* ONEPASS_XXX value from where.c */
137915 int hasFK; /* True if foreign key processing is required */
137916 int labelBreak; /* Jump here to break out of UPDATE loop */
137917 int labelContinue; /* Jump here to continue next step of UPDATE loop */
137918 int flags; /* Flags for sqlite3WhereBegin() */
137919
137920#ifndef SQLITE_OMIT_TRIGGER
137921 int isView; /* True when updating a view (INSTEAD OF trigger) */
137922 Trigger *pTrigger; /* List of triggers on pTab, if required */
137923 int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
137924#endif
137925 int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
137926 int iEph = 0; /* Ephemeral table holding all primary key values */
137927 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
137928 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
137929 int addrOpen = 0; /* Address of OP_OpenEphemeral */
137930 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
137931 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
137932 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
137933 int bFinishSeek = 1; /* The OP_FinishSeek opcode is needed */
137934 int nChangeFrom = 0; /* If there is a FROM, pChanges->nExpr, else 0 */
137935
137936 /* Register Allocations */
137937 int regRowCount = 0; /* A count of rows changed */
137938 int regOldRowid = 0; /* The old rowid */
137939 int regNewRowid = 0; /* The new rowid */
137940 int regNew = 0; /* Content of the NEW.* table in triggers */
137941 int regOld = 0; /* Content of OLD.* table in triggers */
137942 int regRowSet = 0; /* Rowset of rows to be updated */
137943 int regKey = 0; /* composite PRIMARY KEY value */
137944
137945 memset(&sContext, 0, sizeof(sContext));
137946 db = pParse->db;
137947 if( pParse->nErr || db->mallocFailed ){
137948 goto update_cleanup;
137949 }
137950
137951 /* Locate the table which we want to update.
137952 */
137953 pTab = sqlite3SrcListLookup(pParse, pTabList);
137954 if( pTab==0 ) goto update_cleanup;
137955 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
137956
137957 /* Figure out if we have any triggers and if the table being
137958 ** updated is a view.
137959 */
137960#ifndef SQLITE_OMIT_TRIGGER
137961 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask);
137962 isView = pTab->pSelect!=0;
137963 assert( pTrigger || tmask==0 );
137964#else
137965# define pTrigger 0
137966# define isView 0
137967# define tmask 0
137968#endif
137969#ifdef SQLITE_OMIT_VIEW
137970# undef isView
137971# define isView 0
137972#endif
137973
137974 /* If there was a FROM clause, set nChangeFrom to the number of expressions
137975 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
137976 ** clause if this function is being called to generate code for part of
137977 ** an UPSERT statement. */
137978 nChangeFrom = (pTabList->nSrc>1) ? pChanges->nExpr : 0;
137979 assert( nChangeFrom==0 || pUpsert==0 );
137980
137981#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
137982 if( !isView && nChangeFrom==0 ){
137983 pWhere = sqlite3LimitWhere(
137984 pParse, pTabList, pWhere, pOrderBy, pLimit, "UPDATE"
137985 );
137986 pOrderBy = 0;
137987 pLimit = 0;
137988 }
137989#endif
137990
137991 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
137992 goto update_cleanup;
137993 }
137994 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
137995 goto update_cleanup;
137996 }
137997
137998 /* Allocate a cursors for the main database table and for all indices.
137999 ** The index cursors might not be used, but if they are used they
138000 ** need to occur right after the database cursor. So go ahead and
138001 ** allocate enough space, just in case.
138002 */
138003 iBaseCur = iDataCur = pParse->nTab++;
138004 iIdxCur = iDataCur+1;
138005 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
138006 testcase( pPk!=0 && pPk!=pTab->pIndex );
138007 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
138008 if( pPk==pIdx ){
138009 iDataCur = pParse->nTab;
138010 }
138011 pParse->nTab++;
138012 }
138013 if( pUpsert ){
138014 /* On an UPSERT, reuse the same cursors already opened by INSERT */
138015 iDataCur = pUpsert->iDataCur;
138016 iIdxCur = pUpsert->iIdxCur;
138017 pParse->nTab = iBaseCur;
138018 }
138019 pTabList->a[0].iCursor = iDataCur;
138020
138021 /* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
138022 ** Initialize aXRef[] and aToOpen[] to their default values.
138023 */
138024 aXRef = sqlite3DbMallocRawNN(db, sizeof(int) * (pTab->nCol+nIdx+1) + nIdx+2 );
138025 if( aXRef==0 ) goto update_cleanup;
138026 aRegIdx = aXRef+pTab->nCol;
138027 aToOpen = (u8*)(aRegIdx+nIdx+1);
138028 memset(aToOpen, 1, nIdx+1);
138029 aToOpen[nIdx+1] = 0;
138030 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
138031
138032 /* Initialize the name-context */
138033 memset(&sNC, 0, sizeof(sNC));
138034 sNC.pParse = pParse;
138035 sNC.pSrcList = pTabList;
138036 sNC.uNC.pUpsert = pUpsert;
138037 sNC.ncFlags = NC_UUpsert;
138038
138039 /* Begin generating code. */
138040 v = sqlite3GetVdbe(pParse);
138041 if( v==0 ) goto update_cleanup;
138042
138043 /* Resolve the column names in all the expressions of the
138044 ** of the UPDATE statement. Also find the column index
138045 ** for each column to be updated in the pChanges array. For each
138046 ** column to be updated, make sure we have authorization to change
138047 ** that column.
138048 */
138049 chngRowid = chngPk = 0;
138050 for(i=0; i<pChanges->nExpr; i++){
138051 /* If this is an UPDATE with a FROM clause, do not resolve expressions
138052 ** here. The call to sqlite3Select() below will do that. */
138053 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
138054 goto update_cleanup;
138055 }
138056 for(j=0; j<pTab->nCol; j++){
138057 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){
138058 if( j==pTab->iPKey ){
138059 chngRowid = 1;
138060 pRowidExpr = pChanges->a[i].pExpr;
138061 iRowidExpr = i;
138062 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
138063 chngPk = 1;
138064 }
138065#ifndef SQLITE_OMIT_GENERATED_COLUMNS
138066 else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
138067 testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
138068 testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
138069 sqlite3ErrorMsg(pParse,
138070 "cannot UPDATE generated column \"%s\"",
138071 pTab->aCol[j].zName);
138072 goto update_cleanup;
138073 }
138074#endif
138075 aXRef[j] = i;
138076 break;
138077 }
138078 }
138079 if( j>=pTab->nCol ){
138080 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
138081 j = -1;
138082 chngRowid = 1;
138083 pRowidExpr = pChanges->a[i].pExpr;
138084 iRowidExpr = i;
138085 }else{
138086 sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zEName);
138087 pParse->checkSchema = 1;
138088 goto update_cleanup;
138089 }
138090 }
138091#ifndef SQLITE_OMIT_AUTHORIZATION
138092 {
138093 int rc;
138094 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
138095 j<0 ? "ROWID" : pTab->aCol[j].zName,
138096 db->aDb[iDb].zDbSName);
138097 if( rc==SQLITE_DENY ){
138098 goto update_cleanup;
138099 }else if( rc==SQLITE_IGNORE ){
138100 aXRef[j] = -1;
138101 }
138102 }
138103#endif
138104 }
138105 assert( (chngRowid & chngPk)==0 );
138106 assert( chngRowid==0 || chngRowid==1 );
138107 assert( chngPk==0 || chngPk==1 );
138108 chngKey = chngRowid + chngPk;
138109
138110#ifndef SQLITE_OMIT_GENERATED_COLUMNS
138111 /* Mark generated columns as changing if their generator expressions
138112 ** reference any changing column. The actual aXRef[] value for
138113 ** generated expressions is not used, other than to check to see that it
138114 ** is non-negative, so the value of aXRef[] for generated columns can be
138115 ** set to any non-negative number. We use 99999 so that the value is
138116 ** obvious when looking at aXRef[] in a symbolic debugger.
138117 */
138118 if( pTab->tabFlags & TF_HasGenerated ){
138119 int bProgress;
138120 testcase( pTab->tabFlags & TF_HasVirtual );
138121 testcase( pTab->tabFlags & TF_HasStored );
138122 do{
138123 bProgress = 0;
138124 for(i=0; i<pTab->nCol; i++){
138125 if( aXRef[i]>=0 ) continue;
138126 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
138128 aXRef, chngRowid) ){
138129 aXRef[i] = 99999;
138130 bProgress = 1;
138131 }
138132 }
138133 }while( bProgress );
138134 }
138135#endif
138136
138137 /* The SET expressions are not actually used inside the WHERE loop.
138138 ** So reset the colUsed mask. Unless this is a virtual table. In that
138139 ** case, set all bits of the colUsed mask (to ensure that the virtual
138140 ** table implementation makes all columns available).
138141 */
138142 pTabList->a[0].colUsed = IsVirtual(pTab) ? ALLBITS : 0;
138143
138144 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
138145
138146 /* There is one entry in the aRegIdx[] array for each index on the table
138147 ** being updated. Fill in aRegIdx[] with a register number that will hold
138148 ** the key for accessing each index.
138149 */
138150 if( onError==OE_Replace ) bReplace = 1;
138151 for(nAllIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nAllIdx++){
138152 int reg;
138153 if( chngKey || hasFK>1 || pIdx==pPk
138154 || indexWhereClauseMightChange(pIdx,aXRef,chngRowid)
138155 ){
138156 reg = ++pParse->nMem;
138157 pParse->nMem += pIdx->nColumn;
138158 }else{
138159 reg = 0;
138160 for(i=0; i<pIdx->nKeyCol; i++){
138161 if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){
138162 reg = ++pParse->nMem;
138163 pParse->nMem += pIdx->nColumn;
138164 if( onError==OE_Default && pIdx->onError==OE_Replace ){
138165 bReplace = 1;
138166 }
138167 break;
138168 }
138169 }
138170 }
138171 if( reg==0 ) aToOpen[nAllIdx+1] = 0;
138172 aRegIdx[nAllIdx] = reg;
138173 }
138174 aRegIdx[nAllIdx] = ++pParse->nMem; /* Register storing the table record */
138175 if( bReplace ){
138176 /* If REPLACE conflict resolution might be invoked, open cursors on all
138177 ** indexes in case they are needed to delete records. */
138178 memset(aToOpen, 1, nIdx+1);
138179 }
138180
138181 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
138182 sqlite3BeginWriteOperation(pParse, pTrigger || hasFK, iDb);
138183
138184 /* Allocate required registers. */
138185 if( !IsVirtual(pTab) ){
138186 /* For now, regRowSet and aRegIdx[nAllIdx] share the same register.
138187 ** If regRowSet turns out to be needed, then aRegIdx[nAllIdx] will be
138188 ** reallocated. aRegIdx[nAllIdx] is the register in which the main
138189 ** table record is written. regRowSet holds the RowSet for the
138190 ** two-pass update algorithm. */
138191 assert( aRegIdx[nAllIdx]==pParse->nMem );
138192 regRowSet = aRegIdx[nAllIdx];
138193 regOldRowid = regNewRowid = ++pParse->nMem;
138194 if( chngPk || pTrigger || hasFK ){
138195 regOld = pParse->nMem + 1;
138196 pParse->nMem += pTab->nCol;
138197 }
138198 if( chngKey || pTrigger || hasFK ){
138199 regNewRowid = ++pParse->nMem;
138200 }
138201 regNew = pParse->nMem + 1;
138202 pParse->nMem += pTab->nCol;
138203 }
138204
138205 /* Start the view context. */
138206 if( isView ){
138207 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
138208 }
138209
138210 /* If we are trying to update a view, realize that view into
138211 ** an ephemeral table.
138212 */
138213#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
138214 if( nChangeFrom==0 && isView ){
138215 sqlite3MaterializeView(pParse, pTab,
138216 pWhere, pOrderBy, pLimit, iDataCur
138217 );
138218 pOrderBy = 0;
138219 pLimit = 0;
138220 }
138221#endif
138222
138223 /* Resolve the column names in all the expressions in the
138224 ** WHERE clause.
138225 */
138226 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pWhere) ){
138227 goto update_cleanup;
138228 }
138229
138230#ifndef SQLITE_OMIT_VIRTUALTABLE
138231 /* Virtual tables must be handled separately */
138232 if( IsVirtual(pTab) ){
138233 updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
138234 pWhere, onError);
138235 goto update_cleanup;
138236 }
138237#endif
138238
138239 /* Jump to labelBreak to abandon further processing of this UPDATE */
138240 labelContinue = labelBreak = sqlite3VdbeMakeLabel(pParse);
138241
138242 /* Not an UPSERT. Normal processing. Begin by
138243 ** initialize the count of updated rows */
138244 if( (db->flags&SQLITE_CountRows)!=0
138245 && !pParse->pTriggerTab
138246 && !pParse->nested
138247 && pUpsert==0
138248 ){
138249 regRowCount = ++pParse->nMem;
138250 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
138251 }
138252
138253 if( nChangeFrom==0 && HasRowid(pTab) ){
138254 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
138255 }else{
138256 assert( pPk!=0 || HasRowid(pTab) );
138257 nPk = pPk ? pPk->nKeyCol : 0;
138258 iPk = pParse->nMem+1;
138259 pParse->nMem += nPk;
138260 pParse->nMem += nChangeFrom;
138261 regKey = ++pParse->nMem;
138262 if( pUpsert==0 ){
138263 int nEphCol = nPk + nChangeFrom + (isView ? pTab->nCol : 0);
138264 iEph = pParse->nTab++;
138265 if( pPk ) sqlite3VdbeAddOp3(v, OP_Null, 0, iPk, iPk+nPk-1);
138266 addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nEphCol);
138267 if( pPk ){
138268 KeyInfo *pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pPk);
138269 if( pKeyInfo ){
138270 pKeyInfo->nAllField = nEphCol;
138271 sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
138272 }
138273 }
138274 if( nChangeFrom ){
138276 pParse, iEph, pPk, pChanges, pTabList, pWhere, pOrderBy, pLimit
138277 );
138278#ifndef SQLITE_OMIT_SUBQUERY
138279 if( isView ) iDataCur = iEph;
138280#endif
138281 }
138282 }
138283 }
138284
138285 if( nChangeFrom ){
138286 sqlite3MultiWrite(pParse);
138287 eOnePass = ONEPASS_OFF;
138288 nKey = nPk;
138289 regKey = iPk;
138290 }else{
138291 if( pUpsert ){
138292 /* If this is an UPSERT, then all cursors have already been opened by
138293 ** the outer INSERT and the data cursor should be pointing at the row
138294 ** that is to be updated. So bypass the code that searches for the
138295 ** row(s) to be updated.
138296 */
138297 pWInfo = 0;
138298 eOnePass = ONEPASS_SINGLE;
138299 sqlite3ExprIfFalse(pParse, pWhere, labelBreak, SQLITE_JUMPIFNULL);
138300 bFinishSeek = 0;
138301 }else{
138302 /* Begin the database scan.
138303 **
138304 ** Do not consider a single-pass strategy for a multi-row update if
138305 ** there are any triggers or foreign keys to process, or rows may
138306 ** be deleted as a result of REPLACE conflict handling. Any of these
138307 ** things might disturb a cursor being used to scan through the table
138308 ** or index, causing a single-pass approach to malfunction. */
138310 if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
138311 flags |= WHERE_ONEPASS_MULTIROW;
138312 }
138313 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
138314 if( pWInfo==0 ) goto update_cleanup;
138315
138316 /* A one-pass strategy that might update more than one row may not
138317 ** be used if any column of the index used for the scan is being
138318 ** updated. Otherwise, if there is an index on "b", statements like
138319 ** the following could create an infinite loop:
138320 **
138321 ** UPDATE t1 SET b=b+1 WHERE b>?
138322 **
138323 ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
138324 ** strategy that uses an index for which one or more columns are being
138325 ** updated. */
138326 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
138327 bFinishSeek = sqlite3WhereUsesDeferredSeek(pWInfo);
138328 if( eOnePass!=ONEPASS_SINGLE ){
138329 sqlite3MultiWrite(pParse);
138330 if( eOnePass==ONEPASS_MULTI ){
138331 int iCur = aiCurOnePass[1];
138332 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
138333 eOnePass = ONEPASS_OFF;
138334 }
138335 assert( iCur!=iDataCur || !HasRowid(pTab) );
138336 }
138337 }
138338 }
138339
138340 if( HasRowid(pTab) ){
138341 /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
138342 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
138343 ** leave it in register regOldRowid. */
138344 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
138345 if( eOnePass==ONEPASS_OFF ){
138346 /* We need to use regRowSet, so reallocate aRegIdx[nAllIdx] */
138347 aRegIdx[nAllIdx] = ++pParse->nMem;
138348 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
138349 }
138350 }else{
138351 /* Read the PK of the current row into an array of registers. In
138352 ** ONEPASS_OFF mode, serialize the array into a record and store it in
138353 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
138354 ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table
138355 ** is not required) and leave the PK fields in the array of registers. */
138356 for(i=0; i<nPk; i++){
138357 assert( pPk->aiColumn[i]>=0 );
138358 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur,
138359 pPk->aiColumn[i], iPk+i);
138360 }
138361 if( eOnePass ){
138362 if( addrOpen ) sqlite3VdbeChangeToNoop(v, addrOpen);
138363 nKey = nPk;
138364 regKey = iPk;
138365 }else{
138366 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
138367 sqlite3IndexAffinityStr(db, pPk), nPk);
138368 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk);
138369 }
138370 }
138371 }
138372
138373 if( pUpsert==0 ){
138374 if( nChangeFrom==0 && eOnePass!=ONEPASS_MULTI ){
138375 sqlite3WhereEnd(pWInfo);
138376 }
138377
138378 if( !isView ){
138379 int addrOnce = 0;
138380
138381 /* Open every index that needs updating. */
138382 if( eOnePass!=ONEPASS_OFF ){
138383 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
138384 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
138385 }
138386
138387 if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){
138388 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
138389 }
138390 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur,
138391 aToOpen, 0, 0);
138392 if( addrOnce ){
138393 sqlite3VdbeJumpHereOrPopInst(v, addrOnce);
138394 }
138395 }
138396
138397 /* Top of the update loop */
138398 if( eOnePass!=ONEPASS_OFF ){
138399 if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
138400 assert( pPk );
138401 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
138402 VdbeCoverage(v);
138403 }
138404 if( eOnePass!=ONEPASS_SINGLE ){
138405 labelContinue = sqlite3VdbeMakeLabel(pParse);
138406 }
138407 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
138408 VdbeCoverageIf(v, pPk==0);
138409 VdbeCoverageIf(v, pPk!=0);
138410 }else if( pPk || nChangeFrom ){
138411 labelContinue = sqlite3VdbeMakeLabel(pParse);
138412 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
138413 addrTop = sqlite3VdbeCurrentAddr(v);
138414 if( nChangeFrom ){
138415 if( !isView ){
138416 if( pPk ){
138417 for(i=0; i<nPk; i++){
138418 sqlite3VdbeAddOp3(v, OP_Column, iEph, i, iPk+i);
138419 }
138421 v, OP_NotFound, iDataCur, labelContinue, iPk, nPk
138422 ); VdbeCoverage(v);
138423 }else{
138424 sqlite3VdbeAddOp2(v, OP_Rowid, iEph, regOldRowid);
138426 v, OP_NotExists, iDataCur, labelContinue, regOldRowid
138427 ); VdbeCoverage(v);
138428 }
138429 }
138430 }else{
138431 sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
138432 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
138433 VdbeCoverage(v);
138434 }
138435 }else{
138436 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet,labelBreak,
138437 regOldRowid);
138438 VdbeCoverage(v);
138439 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
138440 VdbeCoverage(v);
138441 }
138442 }
138443
138444 /* If the rowid value will change, set register regNewRowid to
138445 ** contain the new value. If the rowid is not being modified,
138446 ** then regNewRowid is the same register as regOldRowid, which is
138447 ** already populated. */
138448 assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
138449 if( chngRowid ){
138450 assert( iRowidExpr>=0 );
138451 if( nChangeFrom==0 ){
138452 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
138453 }else{
138454 sqlite3VdbeAddOp3(v, OP_Column, iEph, iRowidExpr, regNewRowid);
138455 }
138456 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
138457 }
138458
138459 /* Compute the old pre-UPDATE content of the row being changed, if that
138460 ** information is needed */
138461 if( chngPk || hasFK || pTrigger ){
138462 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
138463 oldmask |= sqlite3TriggerColmask(pParse,
138464 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
138465 );
138466 for(i=0; i<pTab->nCol; i++){
138467 u32 colFlags = pTab->aCol[i].colFlags;
138468 k = sqlite3TableColumnToStorage(pTab, i) + regOld;
138469 if( oldmask==0xffffffff
138470 || (i<32 && (oldmask & MASKBIT32(i))!=0)
138471 || (colFlags & COLFLAG_PRIMKEY)!=0
138472 ){
138473 testcase( oldmask!=0xffffffff && i==31 );
138474 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k);
138475 }else{
138476 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
138477 }
138478 }
138479 if( chngRowid==0 && pPk==0 ){
138480 sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
138481 }
138482 }
138483
138484 /* Populate the array of registers beginning at regNew with the new
138485 ** row data. This array is used to check constants, create the new
138486 ** table and index records, and as the values for any new.* references
138487 ** made by triggers.
138488 **
138489 ** If there are one or more BEFORE triggers, then do not populate the
138490 ** registers associated with columns that are (a) not modified by
138491 ** this UPDATE statement and (b) not accessed by new.* references. The
138492 ** values for registers not modified by the UPDATE must be reloaded from
138493 ** the database after the BEFORE triggers are fired anyway (as the trigger
138494 ** may have modified them). So not loading those that are not going to
138495 ** be used eliminates some redundant opcodes.
138496 */
138497 newmask = sqlite3TriggerColmask(
138498 pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError
138499 );
138500 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
138501 if( i==pTab->iPKey ){
138502 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
138503 }else if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)!=0 ){
138504 if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ) k--;
138505 }else{
138506 j = aXRef[i];
138507 if( j>=0 ){
138508 if( nChangeFrom ){
138509 int nOff = (isView ? pTab->nCol : nPk);
138510 assert( eOnePass==ONEPASS_OFF );
138511 sqlite3VdbeAddOp3(v, OP_Column, iEph, nOff+j, k);
138512 }else{
138513 sqlite3ExprCode(pParse, pChanges->a[j].pExpr, k);
138514 }
138515 }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask & MASKBIT32(i)) ){
138516 /* This branch loads the value of a column that will not be changed
138517 ** into a register. This is done if there are no BEFORE triggers, or
138518 ** if there are one or more BEFORE triggers that use this value via
138519 ** a new.* reference in a trigger program.
138520 */
138521 testcase( i==31 );
138522 testcase( i==32 );
138523 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k);
138524 bFinishSeek = 0;
138525 }else{
138526 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
138527 }
138528 }
138529 }
138530#ifndef SQLITE_OMIT_GENERATED_COLUMNS
138531 if( pTab->tabFlags & TF_HasGenerated ){
138532 testcase( pTab->tabFlags & TF_HasVirtual );
138533 testcase( pTab->tabFlags & TF_HasStored );
138534 sqlite3ComputeGeneratedColumns(pParse, regNew, pTab);
138535 }
138536#endif
138537
138538 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
138539 ** verified. One could argue that this is wrong.
138540 */
138541 if( tmask&TRIGGER_BEFORE ){
138542 sqlite3TableAffinity(v, pTab, regNew);
138543 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
138544 TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
138545
138546 if( !isView ){
138547 /* The row-trigger may have deleted the row being updated. In this
138548 ** case, jump to the next row. No updates or AFTER triggers are
138549 ** required. This behavior - what happens when the row being updated
138550 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
138551 ** documentation.
138552 */
138553 if( pPk ){
138554 sqlite3VdbeAddOp4Int(v, OP_NotFound,iDataCur,labelContinue,regKey,nKey);
138555 VdbeCoverage(v);
138556 }else{
138557 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid);
138558 VdbeCoverage(v);
138559 }
138560
138561 /* After-BEFORE-trigger-reload-loop:
138562 ** If it did not delete it, the BEFORE trigger may still have modified
138563 ** some of the columns of the row being updated. Load the values for
138564 ** all columns not modified by the update statement into their registers
138565 ** in case this has happened. Only unmodified columns are reloaded.
138566 ** The values computed for modified columns use the values before the
138567 ** BEFORE trigger runs. See test case trigger1-18.0 (added 2018-04-26)
138568 ** for an example.
138569 */
138570 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
138571 if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){
138572 if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ) k--;
138573 }else if( aXRef[i]<0 && i!=pTab->iPKey ){
138574 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k);
138575 }
138576 }
138577#ifndef SQLITE_OMIT_GENERATED_COLUMNS
138578 if( pTab->tabFlags & TF_HasGenerated ){
138579 testcase( pTab->tabFlags & TF_HasVirtual );
138580 testcase( pTab->tabFlags & TF_HasStored );
138581 sqlite3ComputeGeneratedColumns(pParse, regNew, pTab);
138582 }
138583#endif
138584 }
138585 }
138586
138587 if( !isView ){
138588 /* Do constraint checks. */
138589 assert( regOldRowid>0 );
138590 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
138591 regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace,
138592 aXRef, 0);
138593
138594 /* If REPLACE conflict handling may have been used, or if the PK of the
138595 ** row is changing, then the GenerateConstraintChecks() above may have
138596 ** moved cursor iDataCur. Reseek it. */
138597 if( bReplace || chngKey ){
138598 if( pPk ){
138599 sqlite3VdbeAddOp4Int(v, OP_NotFound,iDataCur,labelContinue,regKey,nKey);
138600 }else{
138601 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid);
138602 }
138604 }
138605
138606 /* Do FK constraint checks. */
138607 if( hasFK ){
138608 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
138609 }
138610
138611 /* Delete the index entries associated with the current record. */
138612 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1);
138613
138614 /* We must run the OP_FinishSeek opcode to resolve a prior
138615 ** OP_DeferredSeek if there is any possibility that there have been
138616 ** no OP_Column opcodes since the OP_DeferredSeek was issued. But
138617 ** we want to avoid the OP_FinishSeek if possible, as running it
138618 ** costs CPU cycles. */
138619 if( bFinishSeek ){
138620 sqlite3VdbeAddOp1(v, OP_FinishSeek, iDataCur);
138621 }
138622
138623 /* If changing the rowid value, or if there are foreign key constraints
138624 ** to process, delete the old record. Otherwise, add a noop OP_Delete
138625 ** to invoke the pre-update hook.
138626 **
138627 ** That (regNew==regnewRowid+1) is true is also important for the
138628 ** pre-update hook. If the caller invokes preupdate_new(), the returned
138629 ** value is copied from memory cell (regNewRowid+1+iCol), where iCol
138630 ** is the column index supplied by the user.
138631 */
138632 assert( regNew==regNewRowid+1 );
138633#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
138634 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
138635 OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
138636 regNewRowid
138637 );
138638 if( eOnePass==ONEPASS_MULTI ){
138639 assert( hasFK==0 && chngKey==0 );
138641 }
138642 if( !pParse->nested ){
138643 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
138644 }
138645#else
138646 if( hasFK>1 || chngKey ){
138647 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
138648 }
138649#endif
138650
138651 if( hasFK ){
138652 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
138653 }
138654
138655 /* Insert the new index entries and the new record. */
138657 pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx,
138659 0, 0
138660 );
138661
138662 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
138663 ** handle rows (possibly in other tables) that refer via a foreign key
138664 ** to the row just updated. */
138665 if( hasFK ){
138666 sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngKey);
138667 }
138668 }
138669
138670 /* Increment the row counter
138671 */
138672 if( regRowCount ){
138673 sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
138674 }
138675
138676 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
138677 TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue);
138678
138679 /* Repeat the above with the next record to be updated, until
138680 ** all record selected by the WHERE clause have been updated.
138681 */
138682 if( eOnePass==ONEPASS_SINGLE ){
138683 /* Nothing to do at end-of-loop for a single-pass */
138684 }else if( eOnePass==ONEPASS_MULTI ){
138685 sqlite3VdbeResolveLabel(v, labelContinue);
138686 sqlite3WhereEnd(pWInfo);
138687 }else if( pPk || nChangeFrom ){
138688 sqlite3VdbeResolveLabel(v, labelContinue);
138689 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
138690 }else{
138691 sqlite3VdbeGoto(v, labelContinue);
138692 }
138693 sqlite3VdbeResolveLabel(v, labelBreak);
138694
138695 /* Update the sqlite_sequence table by storing the content of the
138696 ** maximum rowid counter values recorded while inserting into
138697 ** autoincrement tables.
138698 */
138699 if( pParse->nested==0 && pParse->pTriggerTab==0 && pUpsert==0 ){
138700 sqlite3AutoincrementEnd(pParse);
138701 }
138702
138703 /*
138704 ** Return the number of rows that were changed, if we are tracking
138705 ** that information.
138706 */
138707 if( regRowCount ){
138708 sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
138709 sqlite3VdbeSetNumCols(v, 1);
138710 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
138711 }
138712
138713update_cleanup:
138714 sqlite3AuthContextPop(&sContext);
138715 sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
138716 sqlite3SrcListDelete(db, pTabList);
138717 sqlite3ExprListDelete(db, pChanges);
138718 sqlite3ExprDelete(db, pWhere);
#define WHERE_SEEK_UNIQ_TABLE
Definition sqlite3.c:18316
static int indexColumnIsBeingUpdated(Index *pIdx, int iCol, int *aXRef, int chngRowid)
Definition sqlite3.c:137688
SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo *)
Definition sqlite3.c:145763
#define VdbeCoverageNeverTaken(v)
Definition sqlite3.c:15997
static void updateVirtualTable(Parse *pParse, SrcList *pSrc, Table *pTab, ExprList *pChanges, Expr *pRowidExpr, int *aXRef, Expr *pWhere, int onError)
Definition sqlite3.c:138751
static void updateFromSelect(Parse *pParse, int iEph, Index *pPk, ExprList *pChanges, SrcList *pTabList, Expr *pWhere, ExprList *pOrderBy, Expr *pLimit)
Definition sqlite3.c:137778
#define SQLITE_UPDATE
Definition sqlite3.c:4142
#define OP_FinishSeek
Definition sqlite3.c:15701
static int indexWhereClauseMightChange(Index *pIdx, int *aXRef, int chngRowid)
Definition sqlite3.c:137718

References ExprList::a, SrcList::a, Table::aCol, sqlite3::aDb, Index::aiColumn, ALLBITS, Parse::checkSchema, COLFLAG_GENERATED, COLFLAG_PRIMKEY, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, COLNAME_NAME, SrcList::SrcList_item::colUsed, Parse::db, sqlite3::flags, HasRowid, SrcList::SrcList_item::iCursor, Upsert::iDataCur, Upsert::iIdxCur, indexColumnIsBeingUpdated(), indexWhereClauseMightChange(), Table::iPKey, IsVirtual, sqlite3::mallocFailed, MASKBIT32, KeyInfo::nAllField, NC_UUpsert, NameContext::ncFlags, Table::nCol, Index::nColumn, Parse::nErr, Parse::nested, ExprList::nExpr, Index::nKeyCol, Parse::nMem, SrcList::nSrc, Parse::nTab, OE_Default, OE_Replace, ONEPASS_MULTI, ONEPASS_OFF, ONEPASS_SINGLE, Index::onError, OP_AddImm, OP_Column, OP_Copy, OP_Delete, OP_FinishSeek, OP_IdxInsert, OP_Integer, OP_IsNull, OP_MakeRecord, OP_MustBeInt, OP_Next, OP_NotExists, OP_NotFound, OP_Null, OP_Once, OP_OpenEphemeral, OP_OpenWrite, OP_ResultRow, OP_Rewind, OP_RowData, OP_Rowid, OP_RowSetAdd, OP_RowSetRead, OPFLAG_ISNOOP, OPFLAG_ISUPDATE, OPFLAG_SAVEPOSITION, P4_KEYINFO, P4_TABLE, Column::pDflt, ExprList::ExprList_item::pExpr, Table::pIndex, Index::pNext, NameContext::pParse, Table::pSchema, Table::pSelect, NameContext::pSrcList, Parse::pTriggerTab, NameContext::pUpsert, sqlite3AuthCheck(), sqlite3AuthContextPop(), sqlite3AuthContextPush(), sqlite3AutoincrementEnd(), sqlite3BeginWriteOperation(), sqlite3CodeRowTrigger(), sqlite3CompleteInsertion(), sqlite3ComputeGeneratedColumns(), sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3ErrorMsg(), sqlite3ExprCode(), sqlite3ExprCodeGetColumnOfTable(), sqlite3ExprDelete(), sqlite3ExprIfFalse(), sqlite3ExprListDelete(), sqlite3ExprReferencesUpdatedColumn(), sqlite3FkActions(), sqlite3FkCheck(), sqlite3FkOldmask(), sqlite3FkRequired(), sqlite3GenerateConstraintChecks(), sqlite3GenerateRowIndexDelete(), sqlite3GetVdbe(), sqlite3IndexAffinityStr(), sqlite3IsReadOnly(), sqlite3IsRowid(), sqlite3KeyInfoOfIndex(), sqlite3MaterializeView(), sqlite3MultiWrite(), sqlite3OpenTableAndIndices(), sqlite3PrimaryKeyIndex(), sqlite3ResolveExprNames(), sqlite3SchemaToIndex(), sqlite3SrcListDelete(), sqlite3SrcListLookup(), sqlite3StrICmp(), sqlite3TableAffinity(), sqlite3TableColumnToStorage(), sqlite3TriggerColmask(), sqlite3TriggersExist(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeChangeToNoop(), sqlite3VdbeCountChanges(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGoto(), sqlite3VdbeJumpHereOrPopInst(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3VdbeSetColName(), sqlite3VdbeSetNumCols(), sqlite3ViewGetColumnNames(), sqlite3WhereBegin(), sqlite3WhereEnd(), sqlite3WhereOkOnePass(), sqlite3WhereUsesDeferredSeek(), SQLITE_CountRows, SQLITE_DENY, SQLITE_IGNORE, SQLITE_JUMPIFNULL, SQLITE_STATIC, SQLITE_UPDATE, Table::tabFlags, testcase, TF_HasGenerated, TF_HasStored, TF_HasVirtual, TK_UPDATE, TRIGGER_AFTER, TRIGGER_BEFORE, NameContext::uNC, updateFromSelect(), updateVirtualTable(), VdbeCoverage, VdbeCoverageIf, VdbeCoverageNeverTaken, WHERE_ONEPASS_DESIRED, WHERE_ONEPASS_MULTIROW, WHERE_SEEK_UNIQ_TABLE, Db::zDbSName, ExprList::ExprList_item::zEName, Column::zName, and Table::zName.

Referenced by sqlite3UpsertDoUpdate(), and yy_reduce().

◆ sqlite3UpsertAnalyzeTarget()

SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget ( Parse * pParse,
SrcList * pTabList,
Upsert * pUpsert )

Definition at line 138981 of file sqlite3.c.

138991 {
138992 Table *pTab; /* That table into which we are inserting */
138993 int rc; /* Result code */
138994 int iCursor; /* Cursor used by pTab */
138995 Index *pIdx; /* One of the indexes of pTab */
138996 ExprList *pTarget; /* The conflict-target clause */
138997 Expr *pTerm; /* One term of the conflict-target clause */
138998 NameContext sNC; /* Context for resolving symbolic names */
138999 Expr sCol[2]; /* Index column converted into an Expr */
139000
139001 assert( pTabList->nSrc==1 );
139002 assert( pTabList->a[0].pTab!=0 );
139003 assert( pUpsert!=0 );
139004 assert( pUpsert->pUpsertTarget!=0 );
139005
139006 /* Resolve all symbolic names in the conflict-target clause, which
139007 ** includes both the list of columns and the optional partial-index
139008 ** WHERE clause.
139009 */
139010 memset(&sNC, 0, sizeof(sNC));
139011 sNC.pParse = pParse;
139012 sNC.pSrcList = pTabList;
139013 rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget);
139014 if( rc ) return rc;
139015 rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertTargetWhere);
139016 if( rc ) return rc;
139017
139018 /* Check to see if the conflict target matches the rowid. */
139019 pTab = pTabList->a[0].pTab;
139020 pTarget = pUpsert->pUpsertTarget;
139021 iCursor = pTabList->a[0].iCursor;
139022 if( HasRowid(pTab)
139023 && pTarget->nExpr==1
139024 && (pTerm = pTarget->a[0].pExpr)->op==TK_COLUMN
139025 && pTerm->iColumn==XN_ROWID
139026 ){
139027 /* The conflict-target is the rowid of the primary table */
139028 assert( pUpsert->pUpsertIdx==0 );
139029 return SQLITE_OK;
139030 }
139031
139032 /* Initialize sCol[0..1] to be an expression parse tree for a
139033 ** single column of an index. The sCol[0] node will be the TK_COLLATE
139034 ** operator and sCol[1] will be the TK_COLUMN operator. Code below
139035 ** will populate the specific collation and column number values
139036 ** prior to comparing against the conflict-target expression.
139037 */
139038 memset(sCol, 0, sizeof(sCol));
139039 sCol[0].op = TK_COLLATE;
139040 sCol[0].pLeft = &sCol[1];
139041 sCol[1].op = TK_COLUMN;
139042 sCol[1].iTable = pTabList->a[0].iCursor;
139043
139044 /* Check for matches against other indexes */
139045 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
139046 int ii, jj, nn;
139047 if( !IsUniqueIndex(pIdx) ) continue;
139048 if( pTarget->nExpr!=pIdx->nKeyCol ) continue;
139049 if( pIdx->pPartIdxWhere ){
139050 if( pUpsert->pUpsertTargetWhere==0 ) continue;
139051 if( sqlite3ExprCompare(pParse, pUpsert->pUpsertTargetWhere,
139052 pIdx->pPartIdxWhere, iCursor)!=0 ){
139053 continue;
139054 }
139055 }
139056 nn = pIdx->nKeyCol;
139057 for(ii=0; ii<nn; ii++){
139058 Expr *pExpr;
139059 sCol[0].u.zToken = (char*)pIdx->azColl[ii];
139060 if( pIdx->aiColumn[ii]==XN_EXPR ){
139061 assert( pIdx->aColExpr!=0 );
139062 assert( pIdx->aColExpr->nExpr>ii );
139063 pExpr = pIdx->aColExpr->a[ii].pExpr;
139064 if( pExpr->op!=TK_COLLATE ){
139065 sCol[0].pLeft = pExpr;
139066 pExpr = &sCol[0];
139067 }
139068 }else{
139069 sCol[0].pLeft = &sCol[1];
139070 sCol[1].iColumn = pIdx->aiColumn[ii];
139071 pExpr = &sCol[0];
139072 }
139073 for(jj=0; jj<nn; jj++){
139074 if( sqlite3ExprCompare(pParse, pTarget->a[jj].pExpr, pExpr,iCursor)<2 ){
139075 break; /* Column ii of the index matches column jj of target */
139076 }
139077 }
139078 if( jj>=nn ){
139079 /* The target contains no match for column jj of the index */
139080 break;
139081 }
139082 }
139083 if( ii<nn ){
139084 /* Column ii of the index did not match any term of the conflict target.
139085 ** Continue the search with the next index. */
139086 continue;
139087 }
139088 pUpsert->pUpsertIdx = pIdx;

References ExprList::a, SrcList::a, Index::aColExpr, Index::aiColumn, Index::azColl, HasRowid, Expr::iColumn, SrcList::SrcList_item::iCursor, IsUniqueIndex, Expr::iTable, ExprList::nExpr, Index::nKeyCol, SrcList::nSrc, Expr::op, ExprList::ExprList_item::pExpr, Table::pIndex, Expr::pLeft, Index::pNext, NameContext::pParse, Index::pPartIdxWhere, NameContext::pSrcList, SrcList::SrcList_item::pTab, Upsert::pUpsertIdx, Upsert::pUpsertTarget, Upsert::pUpsertTargetWhere, sqlite3ErrorMsg(), sqlite3ExprCompare(), sqlite3ResolveExprListNames(), sqlite3ResolveExprNames(), SQLITE_ERROR, SQLITE_OK, TK_COLLATE, TK_COLUMN, Expr::u, XN_EXPR, XN_ROWID, and Expr::zToken.

Referenced by sqlite3Insert().

◆ sqlite3UpsertDelete()

◆ sqlite3UpsertDoUpdate()

SQLITE_PRIVATE void sqlite3UpsertDoUpdate ( Parse * pParse,
Upsert * pUpsert,
Table * pTab,
Index * pIdx,
int iCur )

Definition at line 139099 of file sqlite3.c.

139111 {
139112 Vdbe *v = pParse->pVdbe;
139113 sqlite3 *db = pParse->db;
139114 SrcList *pSrc; /* FROM clause for the UPDATE */
139115 int iDataCur;
139116 int i;
139117
139118 assert( v!=0 );
139119 assert( pUpsert!=0 );
139120 VdbeNoopComment((v, "Begin DO UPDATE of UPSERT"));
139121 iDataCur = pUpsert->iDataCur;
139122 if( pIdx && iCur!=iDataCur ){
139123 if( HasRowid(pTab) ){
139124 int regRowid = sqlite3GetTempReg(pParse);
139125 sqlite3VdbeAddOp2(v, OP_IdxRowid, iCur, regRowid);
139126 sqlite3VdbeAddOp3(v, OP_SeekRowid, iDataCur, 0, regRowid);
139127 VdbeCoverage(v);
139128 sqlite3ReleaseTempReg(pParse, regRowid);
139129 }else{
139130 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
139131 int nPk = pPk->nKeyCol;
139132 int iPk = pParse->nMem+1;
139133 pParse->nMem += nPk;
139134 for(i=0; i<nPk; i++){
139135 int k;
139136 assert( pPk->aiColumn[i]>=0 );
139137 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
139138 sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i);
139139 VdbeComment((v, "%s.%s", pIdx->zName,
139140 pTab->aCol[pPk->aiColumn[i]].zName));
139141 }
139143 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
139144 VdbeCoverage(v);
139146 "corrupt database", P4_STATIC);
139147 sqlite3MayAbort(pParse);
139148 sqlite3VdbeJumpHere(v, i);
139149 }
139150 }
139151 /* pUpsert does not own pUpsertSrc - the outer INSERT statement does. So
139152 ** we have to make a copy before passing it down into sqlite3Update() */
139153 pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0);
139154 /* excluded.* columns of type REAL need to be converted to a hard real */
139155 for(i=0; i<pTab->nCol; i++){
139156 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
139157 sqlite3VdbeAddOp1(v, OP_RealAffinity, pUpsert->regData+i);
139158 }
139159 }

References Table::aCol, Column::affinity, Index::aiColumn, Parse::db, HasRowid, Upsert::iDataCur, Table::nCol, Index::nKeyCol, Parse::nMem, OE_Abort, OP_Column, OP_Found, OP_Halt, OP_IdxRowid, OP_RealAffinity, OP_SeekRowid, P4_STATIC, Upsert::pUpsertSet, Upsert::pUpsertSrc, Upsert::pUpsertWhere, Parse::pVdbe, Upsert::regData, sqlite3GetTempReg(), sqlite3MayAbort(), sqlite3PrimaryKeyIndex(), sqlite3ReleaseTempReg(), sqlite3SrcListDup(), sqlite3TableColumnToIndex(), sqlite3Update(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeJumpHere(), sqlite3VdbeVerifyAbortable, SQLITE_AFF_REAL, SQLITE_CORRUPT, VdbeComment, VdbeCoverage, VdbeNoopComment, Column::zName, and Index::zName.

Referenced by sqlite3GenerateConstraintChecks().

◆ sqlite3UpsertDup()

SQLITE_PRIVATE Upsert * sqlite3UpsertDup ( sqlite3 * db,
Upsert * p )

Definition at line 138936 of file sqlite3.c.

138942 {
138943 if( p==0 ) return 0;
138944 return sqlite3UpsertNew(db,
SQLITE_PRIVATE Upsert * sqlite3UpsertNew(sqlite3 *, ExprList *, Expr *, ExprList *, Expr *)
Definition sqlite3.c:138949

◆ sqlite3UpsertNew()

SQLITE_PRIVATE Upsert * sqlite3UpsertNew ( sqlite3 * db,
ExprList * pTarget,
Expr * pTargetWhere,
ExprList * pSet,
Expr * pWhere )

Definition at line 138949 of file sqlite3.c.

138961 {
138962 Upsert *pNew;
138963 pNew = sqlite3DbMallocRaw(db, sizeof(Upsert));
138964 if( pNew==0 ){
138965 sqlite3ExprListDelete(db, pTarget);
138966 sqlite3ExprDelete(db, pTargetWhere);
138967 sqlite3ExprListDelete(db, pSet);
138968 sqlite3ExprDelete(db, pWhere);
138969 return 0;
138970 }else{
138971 pNew->pUpsertTarget = pTarget;
138972 pNew->pUpsertTargetWhere = pTargetWhere;

Referenced by yy_reduce().

◆ sqlite3Utf16ByteLen()

SQLITE_PRIVATE int sqlite3Utf16ByteLen ( const void * pData,
int nChar )

Definition at line 31132 of file sqlite3.c.

31138 {
31139 int c;
31140 unsigned char const *z = zIn;
31141 int n = 0;
31142
31144 while( n<nChar ){
31145 c = z[0];
31146 z += 2;

References SQLITE_UTF16LE, and SQLITE_UTF16NATIVE.

Referenced by sqlite3Prepare16().

◆ sqlite3Utf16to8()

SQLITE_PRIVATE char * sqlite3Utf16to8 ( sqlite3 * db,
const void * z,
int nByte,
u8 enc )

Definition at line 31111 of file sqlite3.c.

31117 {
31118 Mem m;
31119 memset(&m, 0, sizeof(m));
31120 m.db = db;
31121 sqlite3VdbeMemSetStr(&m, z, nByte, enc, SQLITE_STATIC);
31123 if( db->mallocFailed ){
31125 m.z = 0;

References sqlite3_value::db, sqlite3_value::flags, sqlite3::mallocFailed, MEM_Str, MEM_Term, sqlite3VdbeChangeEncoding(), sqlite3VdbeMemRelease(), sqlite3VdbeMemSetStr(), SQLITE_STATIC, SQLITE_UTF8, and sqlite3_value::z.

Referenced by sqlite3Prepare16().

◆ sqlite3Utf8CharLen()

SQLITE_PRIVATE int sqlite3Utf8CharLen ( const char * pData,
int nByte )

Definition at line 31057 of file sqlite3.c.

31063 {
31064 int r = 0;
31065 const u8 *z = (const u8*)zIn;
31066 const u8 *zTerm;
31067 if( nByte>=0 ){
31068 zTerm = &z[nByte];
31069 }else{
31070 zTerm = (const u8*)(-1);
31071 }
31072 assert( z<=zTerm );

References SQLITE_SKIP_UTF8.

Referenced by likeFunc(), sqlite3EndTable(), and sqlite3Prepare16().

◆ sqlite3Utf8Read() [1/2]

SQLITE_PRIVATE u32 sqlite3Utf8Read ( const u8 ** )

Referenced by likeFunc(), and patternCompare().

◆ sqlite3Utf8Read() [2/2]

SQLITE_PRIVATE u32 sqlite3Utf8Read ( const unsigned char ** pz)

Definition at line 30788 of file sqlite3.c.

30792 { c = 0xFFFD; } \
30793 }
30795 const unsigned char **pz /* Pointer to string from which to read char */
30796){
30797 unsigned int c;
30798
30799 /* Same as READ_UTF8() above but without the zTerm parameter.
30800 ** For this routine, we assume the UTF8 string is always zero-terminated.
30801 */
30802 c = *((*pz)++);
30803 if( c>=0xc0 ){
30804 c = sqlite3Utf8Trans1[c-0xc0];
30805 while( (*(*pz) & 0xc0)==0x80 ){
30806 c = (c<<6) + (0x3f & *((*pz)++));
30807 }

References sqlite3Utf8Trans1.

◆ sqlite3Vacuum()

SQLITE_PRIVATE void sqlite3Vacuum ( Parse * pParse,
Token * pNm,
Expr * pInto )

Definition at line 139269 of file sqlite3.c.

139275 {
139276 Vdbe *v = sqlite3GetVdbe(pParse);
139277 int iDb = 0;
139278 if( v==0 ) goto build_vacuum_end;
139279 if( pParse->nErr ) goto build_vacuum_end;
139280 if( pNm ){
139281#ifndef SQLITE_BUG_COMPATIBLE_20160819
139282 /* Default behavior: Report an error if the argument to VACUUM is
139283 ** not recognized */
139284 iDb = sqlite3TwoPartName(pParse, pNm, pNm, &pNm);
139285 if( iDb<0 ) goto build_vacuum_end;
139286#else
139287 /* When SQLITE_BUG_COMPATIBLE_20160819 is defined, unrecognized arguments
139288 ** to VACUUM are silently ignored. This is a back-out of a bug fix that
139289 ** occurred on 2016-08-19 (https://www.sqlite.org/src/info/083f9e6270).
139290 ** The buggy behavior is required for binary compatibility with some
139291 ** legacy applications. */
139292 iDb = sqlite3FindDb(pParse->db, pNm);
139293 if( iDb<0 ) iDb = 0;
139294#endif
139295 }
139296 if( iDb!=1 ){
139297 int iIntoReg = 0;
139298 if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
139299 iIntoReg = ++pParse->nMem;
139300 sqlite3ExprCode(pParse, pInto, iIntoReg);
139301 }
139302 sqlite3VdbeAddOp2(v, OP_Vacuum, iDb, iIntoReg);

References Parse::db, Parse::nErr, Parse::nMem, OP_Vacuum, sqlite3ExprCode(), sqlite3ExprDelete(), sqlite3FindDb(), sqlite3GetVdbe(), sqlite3ResolveSelfReference(), sqlite3TwoPartName(), sqlite3VdbeAddOp2(), and sqlite3VdbeUsesBtree().

Referenced by yy_reduce().

◆ sqlite3ValueApplyAffinity()

SQLITE_PRIVATE void sqlite3ValueApplyAffinity ( sqlite3_value * pVal,
u8 affinity,
u8 enc )

Definition at line 85654 of file sqlite3.c.

Referenced by sqlite3VdbeGetBoundValue(), sqlite3VdbeMemCast(), and valueFromExpr().

◆ sqlite3ValueBytes()

SQLITE_PRIVATE int sqlite3ValueBytes ( sqlite3_value * pVal,
u8 enc )

Definition at line 77714 of file sqlite3.c.

77717 {
77718 return valueToText(pVal, enc)!=0 ? pVal->n : 0;
77719}
77721 Mem *p = (Mem*)pVal;
77722 assert( (p->flags & MEM_Null)==0 || (p->flags & (MEM_Str|MEM_Blob))==0 );
77723 if( (p->flags & MEM_Str)!=0 && pVal->enc==enc ){
77724 return p->n;
77725 }
77726 if( (p->flags & MEM_Blob)!=0 ){
77727 if( p->flags & MEM_Zero ){
77728 return p->n + p->u.nZero;
77729 }else{
static SQLITE_NOINLINE const void * valueToText(sqlite3_value *pVal, u8 enc)
Definition sqlite3.c:77055

References sqlite3_value::n, and valueToText().

Referenced by sqlite3_value_double(), and sqlite3_value_int().

◆ sqlite3ValueFree()

◆ sqlite3ValueFromExpr()

SQLITE_PRIVATE int sqlite3ValueFromExpr ( sqlite3 * db,
Expr * pExpr,
u8 enc,
u8 affinity,
sqlite3_value ** ppVal )

◆ sqlite3ValueNew()

SQLITE_PRIVATE sqlite3_value * sqlite3ValueNew ( sqlite3 * db)

◆ sqlite3ValueSetNull()

SQLITE_PRIVATE void sqlite3ValueSetNull ( sqlite3_value * p)

Definition at line 76653 of file sqlite3.c.

76653 {
76655 }else{
static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull(Mem *p)
Definition sqlite3.c:76319

References vdbeMemClearExternAndSetNull().

Referenced by sqlite3ErrorFinish(), and sqlite3VdbeTransferError().

◆ sqlite3ValueSetStr()

SQLITE_PRIVATE void sqlite3ValueSetStr ( sqlite3_value * v,
int n,
const void * z,
u8 enc,
void(*)(void *) xDel )

◆ sqlite3ValueText()

SQLITE_PRIVATE const void * sqlite3ValueText ( sqlite3_value * pVal,
u8 enc )

Definition at line 77098 of file sqlite3.c.

77100 :) The enc value can be or-ed with SQLITE_UTF16_ALIGNED.
77101** If that is the case, then the result must be aligned on an even byte
77102** boundary.
77103*/
77104SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
77105 if( !pVal ) return 0;
77106 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
77107 assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
77108 assert( !sqlite3VdbeMemIsRowSet(pVal) );
77109 if( (pVal->flags&(MEM_Str|MEM_Term))==(MEM_Str|MEM_Term) && pVal->enc==enc ){
77110 assert( sqlite3VdbeMemValidStrRep(pVal) );
77111 return pVal->z;

References sqlite3_value::db, sqlite3_value::enc, sqlite3_value::flags, MEM_Null, MEM_Str, MEM_Term, sqlite3::mutex, sqlite3_mutex_held(), SQLITE_UTF16_ALIGNED, and sqlite3_value::z.

Referenced by callCollNeeded(), sqlite3_complete16(), sqlite3_value_text16le(), and vdbeCompareMemString().

◆ sqlite3VarintLen()

SQLITE_PRIVATE int sqlite3VarintLen ( u64 v)

◆ sqlite3VdbeAddFunctionCall()

SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall ( Parse * pParse,
int p1,
int p2,
int p3,
int nArg,
const FuncDef * pFunc,
int eCallCtx )

Definition at line 78084 of file sqlite3.c.

78098 {
78099 Vdbe *v = pParse->pVdbe;
78100 int nByte;
78101 int addr;
78102 sqlite3_context *pCtx;
78103 assert( v );
78104 nByte = sizeof(*pCtx) + (nArg-1)*sizeof(sqlite3_value*);
78105 pCtx = sqlite3DbMallocRawNN(pParse->db, nByte);
78106 if( pCtx==0 ){
78107 assert( pParse->db->mallocFailed );
78108 freeEphemeralFunction(pParse->db, (FuncDef*)pFunc);
78109 return 0;
78110 }
78111 pCtx->pOut = 0;
78112 pCtx->pFunc = (FuncDef*)pFunc;
78113 pCtx->pVdbe = 0;
78114 pCtx->isError = 0;
78115 pCtx->argc = nArg;

References sqlite3_context::argc, Parse::db, freeEphemeralFunction(), sqlite3_context::iOp, sqlite3_context::isError, sqlite3::mallocFailed, NC_SelfRef, OP_Function, OP_PureFunc, P4_FUNCCTX, sqlite3_context::pFunc, sqlite3_context::pOut, ValueNewStat4Ctx::pParse, Parse::pVdbe, sqlite3_context::pVdbe, sqlite3DbMallocRawNN(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), and sqlite3VdbeCurrentAddr().

Referenced by analyzeOneTable(), and sqlite3ExprCodeTarget().

◆ sqlite3VdbeAddOp0()

◆ sqlite3VdbeAddOp1()

◆ sqlite3VdbeAddOp2()

SQLITE_PRIVATE int sqlite3VdbeAddOp2 ( Vdbe * p,
int op,
int p1,
int p2 )

◆ sqlite3VdbeAddOp3()

SQLITE_PRIVATE int sqlite3VdbeAddOp3 ( Vdbe * p,
int op,
int p1,
int p2,
int p3 )

Definition at line 77966 of file sqlite3.c.

77966 {
77967 assert( p->nOpAlloc<=p->nOp );
77968 if( growOpArray(p, 1) ) return 1;
77969 assert( p->nOpAlloc>p->nOp );
77970 return sqlite3VdbeAddOp3(p, op, p1, p2, p3);
77971}
77972SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
77973 int i;
77974 VdbeOp *pOp;
77975
77976 i = p->nOp;
77977 assert( p->magic==VDBE_MAGIC_INIT );
77978 assert( op>=0 && op<0xff );
77979 if( p->nOpAlloc<=i ){
77980 return growOp3(p, op, p1, p2, p3);
77981 }
77982 p->nOp++;
77983 pOp = &p->aOp[i];
77984 pOp->opcode = (u8)op;
77985 pOp->p5 = 0;
77986 pOp->p1 = p1;
77987 pOp->p2 = p2;
77988 pOp->p3 = p3;
77989 pOp->p4.p = 0;
77990 pOp->p4type = P4_NOTUSED;
77991#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
77992 pOp->zComment = 0;
77993#endif
77994#ifdef SQLITE_DEBUG
77995 if( p->db->flags & SQLITE_VdbeAddopTrace ){
77996 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
77997 test_addop_breakpoint(i, &p->aOp[i]);
77998 }
77999#endif
78000#ifdef VDBE_PROFILE
78001 pOp->cycles = 0;
78002 pOp->cnt = 0;
static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3)
Definition sqlite3.c:77960
#define VDBE_MAGIC_INIT
Definition sqlite3.c:21159
#define P4_NOTUSED
Definition sqlite3.c:15504
static int growOpArray(Vdbe *v, int nOp)
Definition sqlite3.c:77889

References growOpArray(), Vdbe::nOp, Vdbe::nOpAlloc, and sqlite3VdbeAddOp3().

Referenced by analyzeOneTable(), autoIncrementEnd(), codeAllEqualityTerms(), codeDeferredSeek(), codeDistinct(), codeEqualityTerm(), codeExprOrVector(), computeLimitRegisters(), constructAutomaticIndex(), destroyRootPage(), fkLookupParent(), generateOutputSubroutine(), generateSortTail(), generateWithRecursiveQuery(), integrityCheckResultRow(), makeSorterRecord(), multiSelect(), multiSelectOrderBy(), resetAccumulator(), selectInnerLoop(), sqlite3AlterFinishAddColumn(), sqlite3ChangeCookie(), sqlite3CodeSubselect(), sqlite3CompleteInsertion(), sqlite3CreateIndex(), sqlite3DeleteFrom(), sqlite3EndTable(), sqlite3ExprCodeGeneratedColumn(), sqlite3ExprCodeIN(), sqlite3ExprCodeTarget(), sqlite3ExprIfFalse(), sqlite3ExprIfTrue(), sqlite3FindInIndex(), sqlite3GenerateConstraintChecks(), sqlite3GenerateIndexKey(), sqlite3GenerateRowIndexDelete(), sqlite3Insert(), sqlite3OpenTable(), sqlite3OpenTableAndIndices(), sqlite3Pragma(), sqlite3RefillIndex(), sqlite3Select(), sqlite3SetHasNullFlag(), sqlite3StartTable(), sqlite3Update(), sqlite3UpsertDoUpdate(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeGoto(), sqlite3WhereBegin(), sqlite3WhereEnd(), sqlite3WindowCodeInit(), sqlite3WindowCodeStep(), updateAccumulator(), updateVirtualTable(), windowAggFinal(), windowAggStep(), windowCheckValue(), windowCodeOp(), windowCodeRangeTest(), windowFullScan(), windowIfNewPeer(), windowReturnOneRow(), and xferOptimization().

◆ sqlite3VdbeAddOp4()

◆ sqlite3VdbeAddOp4Dup8()

SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8 ( Vdbe * p,
int op,
int p1,
int p2,
int p3,
const u8 * zP4,
int p4type )

Definition at line 78121 of file sqlite3.c.

Referenced by codeInteger(), codeReal(), sqlite3FindInIndex(), and sqlite3WhereBegin().

◆ sqlite3VdbeAddOp4Int()

◆ sqlite3VdbeAddOpList()

SQLITE_PRIVATE VdbeOp * sqlite3VdbeAddOpList ( Vdbe * p,
int nOp,
VdbeOpList const * aOp,
int iLineno )

Definition at line 78700 of file sqlite3.c.

78711 {
78712 int i;
78713 VdbeOp *pOut, *pFirst;
78714 assert( nOp>0 );
78715 assert( p->magic==VDBE_MAGIC_INIT );
78716 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
78717 return 0;
78718 }
78719 pFirst = pOut = &p->aOp[p->nOp];
78720 for(i=0; i<nOp; i++, aOp++, pOut++){
78721 pOut->opcode = aOp->opcode;
78722 pOut->p1 = aOp->p1;
78723 pOut->p2 = aOp->p2;
78724 assert( aOp->p2>=0 );
78725 if( (sqlite3OpcodeProperty[aOp->opcode] & OPFLG_JUMP)!=0 && aOp->p2>0 ){
78726 pOut->p2 += p->nOp;
78727 }
78728 pOut->p3 = aOp->p3;
78729 pOut->p4type = P4_NOTUSED;
78730 pOut->p4.p = 0;
78731 pOut->p5 = 0;
78732#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
78733 pOut->zComment = 0;
78734#endif
78735#ifdef SQLITE_VDBE_COVERAGE
78736 pOut->iSrcLine = iLineno+i;
78737#else
78738 (void)iLineno;
78739#endif
78740#ifdef SQLITE_DEBUG
78741 if( p->db->flags & SQLITE_VdbeAddopTrace ){
78742 sqlite3VdbePrintOp(0, i+p->nOp, &p->aOp[i+p->nOp]);

References Vdbe::aOp, Vdbe::db, sqlite3::flags, growOpArray(), Vdbe::magic, Vdbe::nOp, Vdbe::nOpAlloc, VdbeOp::opcode, VdbeOpList::opcode, OPFLG_JUMP, VdbeOp::p4union::p, VdbeOp::p1, VdbeOpList::p1, VdbeOp::p2, VdbeOpList::p2, VdbeOp::p3, VdbeOpList::p3, VdbeOp::p4, P4_NOTUSED, VdbeOp::p4type, VdbeOp::p5, sqlite3OpcodeProperty, and VDBE_MAGIC_INIT.

Referenced by autoIncrementEnd(), and sqlite3Pragma().

◆ sqlite3VdbeAddParseSchemaOp()

SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp ( Vdbe * p,
int iDb,
char * zWhere )

Definition at line 78206 of file sqlite3.c.

References OP_ParseSchema, P4_DYNAMIC, and sqlite3VdbeAddOp4().

Referenced by sqlite3CreateIndex(), and sqlite3EndTable().

◆ sqlite3VdbeAllocUnpackedRecord()

SQLITE_PRIVATE UnpackedRecord * sqlite3VdbeAllocUnpackedRecord ( KeyInfo * pKeyInfo)

Definition at line 81728 of file sqlite3.c.

81736 {
81737 UnpackedRecord *p; /* Unpacked record to return */
81738 int nByte; /* Number of bytes required for *p */
81739 nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
81740 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
81741 if( !p ) return 0;
struct sqlite3_value Mem
Definition sqlite3.c:15426

References UnpackedRecord::aMem, KeyInfo::aSortFlags, KeyInfo::db, UnpackedRecord::nField, KeyInfo::nKeyField, UnpackedRecord::pKeyInfo, ROUND8, and sqlite3DbMallocRaw().

Referenced by btreeMoveto(), sqlite3VdbeExec(), sqlite3VdbeSorterCompare(), and vdbeSortAllocUnpacked().

◆ sqlite3VdbeAppendP4()

SQLITE_PRIVATE void sqlite3VdbeAppendP4 ( Vdbe * p,
void * pP4,
int p4type )

◆ sqlite3VdbeBooleanValue()

SQLITE_PRIVATE int sqlite3VdbeBooleanValue ( Mem * pMem,
int ifNull )

Definition at line 76465 of file sqlite3.c.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeChangeEncoding()

SQLITE_PRIVATE int sqlite3VdbeChangeEncoding ( Mem * pMem,
int desiredEnc )

Definition at line 76021 of file sqlite3.c.

76027 {
76028#ifndef SQLITE_OMIT_UTF16
76029 int rc;
76030#endif
76031 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76032 assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
76033 || desiredEnc==SQLITE_UTF16BE );
76034 if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
76035 return SQLITE_OK;
76036 }
76037 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76038#ifdef SQLITE_OMIT_UTF16
76039 return SQLITE_ERROR;
76040#else
76041
76042 /* MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned,
76043 ** then the encoding of the value may not have changed.
76044 */
76045 rc = sqlite3VdbeMemTranslate(pMem, (u8)desiredEnc);
SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem *, u8)
Definition sqlite3.c:30824

References sqlite3_value::db, sqlite3_value::enc, sqlite3_value::flags, MEM_Str, sqlite3::mutex, sqlite3_mutex_held(), sqlite3VdbeMemTranslate(), SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, SQLITE_UTF16BE, SQLITE_UTF16LE, and SQLITE_UTF8.

Referenced by sqlite3Utf16to8(), sqlite3VdbeExec(), sqlite3VdbeExpandSql(), sqlite3VdbeMemCast(), sqlite3VdbeMemStringify(), valueFromExpr(), and valueToText().

◆ sqlite3VdbeChangeOpcode()

SQLITE_PRIVATE void sqlite3VdbeChangeOpcode ( Vdbe * p,
int addr,
u8 iNewOpcode )

Definition at line 78776 of file sqlite3.c.

Referenced by convertToWithoutRowidTable(), and sqlite3Select().

◆ sqlite3VdbeChangeP1()

SQLITE_PRIVATE void sqlite3VdbeChangeP1 ( Vdbe * p,
int addr,
int P1 )

◆ sqlite3VdbeChangeP2()

SQLITE_PRIVATE void sqlite3VdbeChangeP2 ( Vdbe * p,
int addr,
int P2 )

Definition at line 78782 of file sqlite3.c.

78782 {
78783 sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
78784}

References VdbeOp::opcode, and sqlite3VdbeGetOp().

Referenced by constructAutomaticIndex(), multiSelect(), sqlite3VdbeJumpHereOrPopInst(), and windowCodeRangeTest().

◆ sqlite3VdbeChangeP3()

SQLITE_PRIVATE void sqlite3VdbeChangeP3 ( Vdbe * p,
int addr,
int P3 )

Definition at line 78785 of file sqlite3.c.

78785 {
78786 sqlite3VdbeGetOp(p,addr)->p1 = val;
78787}

References VdbeOp::p1, and sqlite3VdbeGetOp().

Referenced by convertToWithoutRowidTable(), isLikeOrGlob(), sqlite3ExprCodeTarget(), and sqlite3Pragma().

◆ sqlite3VdbeChangeP4()

SQLITE_PRIVATE void sqlite3VdbeChangeP4 ( Vdbe * p,
int addr,
const char * zP4,
int N )

Definition at line 79028 of file sqlite3.c.

79028 {
79029 if( n==0 ) n = sqlite3Strlen30(zP4);
79030 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
79031 pOp->p4type = P4_DYNAMIC;
79032 }
79033}
79034SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
79035 Op *pOp;
79036 sqlite3 *db;
79037 assert( p!=0 );
79038 db = p->db;
79039 assert( p->magic==VDBE_MAGIC_INIT );
79040 assert( p->aOp!=0 || db->mallocFailed );
79041 if( db->mallocFailed ){
79042 if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
79043 return;
79044 }
79045 assert( p->nOp>0 );
79046 assert( addr<p->nOp );
79047 if( addr<0 ){
79048 addr = p->nOp - 1;
79049 }
79050 pOp = &p->aOp[addr];
79051 if( n>=0 || pOp->p4type ){
79052 vdbeChangeP4Full(p, pOp, zP4, n);
79053 return;
79054 }
79055 if( n==P4_INT32 ){
79056 /* Note: this cast is safe, because the origin data point was an int
79057 ** that was cast to a (const char *). */
79058 pOp->p4.i = SQLITE_PTR_TO_INT(zP4);
79059 pOp->p4type = P4_INT32;
79060 }else if( zP4!=0 ){
static void SQLITE_NOINLINE vdbeChangeP4Full(Vdbe *p, Op *pOp, const char *zP4, int n)
Definition sqlite3.c:79009

Referenced by analyzeOneTable(), codeDeferredSeek(), multiSelect(), selectInnerLoop(), sqlite3CodeRhsOfIN(), sqlite3GenerateIndexKey(), sqlite3Select(), sqlite3TableAffinity(), sqlite3WhereBegin(), and vdbeChangeP4Full().

◆ sqlite3VdbeChangeP5()

◆ sqlite3VdbeChangeToNoop()

SQLITE_PRIVATE int sqlite3VdbeChangeToNoop ( Vdbe * p,
int addr )

Definition at line 78933 of file sqlite3.c.

78939 {
78940 VdbeOp *pOp;
78941 if( p->db->mallocFailed ) return 0;
78942 assert( addr>=0 && addr<p->nOp );
78943 pOp = &p->aOp[addr];

Referenced by selectInnerLoop(), sqlite3CodeRhsOfIN(), sqlite3DeleteFrom(), sqlite3Select(), sqlite3Update(), and updateVirtualTable().

◆ sqlite3VdbeCheckFk()

SQLITE_PRIVATE int sqlite3VdbeCheckFk ( Vdbe * p,
int deferred )

Definition at line 80728 of file sqlite3.c.

80734 {
80735 sqlite3 *db = p->db;
80736 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
80737 || (!deferred && p->nFkConstraint>0)
80738 ){
i64 nFkConstraint
Definition sqlite3.c:21097

References Vdbe::db, Vdbe::errorAction, sqlite3::nDeferredCons, sqlite3::nDeferredImmCons, Vdbe::nFkConstraint, OE_Abort, Vdbe::rc, sqlite3VdbeError(), SQLITE_CONSTRAINT_FOREIGNKEY, SQLITE_ERROR, and SQLITE_OK.

Referenced by sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3VdbeClearObject()

SQLITE_PRIVATE void sqlite3VdbeClearObject ( sqlite3 * db,
Vdbe * p )

Definition at line 81168 of file sqlite3.c.

81174 {
81175 SubProgram *pSub, *pNext;
81176 assert( p->db==0 || p->db==db );
81178 for(pSub=p->pProgram; pSub; pSub=pNext){
81179 pNext = pSub->pNext;
81180 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
81181 sqlite3DbFree(db, pSub);
81182 }
81183 if( p->magic!=VDBE_MAGIC_INIT ){
81184 releaseMemArray(p->aVar, p->nVar);
81185 sqlite3DbFree(db, p->pVList);
81186 sqlite3DbFree(db, p->pFree);
81187 }
81188 vdbeFreeOpArray(db, p->aOp, p->nOp);
81189 sqlite3DbFree(db, p->aColName);
81190 sqlite3DbFree(db, p->zSql);
81191#ifdef SQLITE_ENABLE_NORMALIZE
81192 sqlite3DbFree(db, p->zNormSql);
81193 {
81194 DblquoteStr *pThis, *pNext;
81195 for(pThis=p->pDblStr; pThis; pThis=pNext){
81196 pNext = pThis->pNextStr;
81197 sqlite3DbFree(db, pThis);
81198 }
81199 }
81200#endif
81201#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
81202 {
81203 int i;
81204 for(i=0; i<p->nScan; i++){
#define COLNAME_N
Definition sqlite3.c:15547
static void vdbeFreeOpArray(sqlite3 *, Op *, int)
Definition sqlite3.c:78900
DblquoteStr * pNextStr
Definition sqlite3.c:21072
SubProgram * pNext
Definition sqlite3.c:15486
VList * pVList
Definition sqlite3.c:21114
u16 nResColumn
Definition sqlite3.c:21122
void * pFree
Definition sqlite3.c:21142
SubProgram * pProgram
Definition sqlite3.c:21147

References Vdbe::aColName, SubProgram::aOp, Vdbe::aOp, Vdbe::aVar, COLNAME_N, Vdbe::db, Vdbe::magic, SubProgram::nOp, Vdbe::nOp, Vdbe::nResColumn, Vdbe::nVar, Vdbe::pFree, SubProgram::pNext, DblquoteStr::pNextStr, Vdbe::pProgram, Vdbe::pVList, releaseMemArray(), sqlite3DbFree(), VDBE_MAGIC_INIT, vdbeFreeOpArray(), and Vdbe::zSql.

◆ sqlite3VdbeCloseStatement()

SQLITE_PRIVATE int sqlite3VdbeCloseStatement ( Vdbe * p,
int eOp )

Definition at line 80709 of file sqlite3.c.

80709 {
80710 db->nDeferredCons = p->nStmtDefCons;
80711 db->nDeferredImmCons = p->nStmtDefImmCons;
80712 }
80713 return rc;
80714}
i64 nStmtDefCons
Definition sqlite3.c:21098
i64 nStmtDefImmCons
Definition sqlite3.c:21099

References sqlite3::nDeferredCons, sqlite3::nDeferredImmCons, Vdbe::nStmtDefCons, and Vdbe::nStmtDefImmCons.

Referenced by sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3VdbeCountChanges()

SQLITE_PRIVATE void sqlite3VdbeCountChanges ( Vdbe * v)

Definition at line 82757 of file sqlite3.c.

Referenced by sqlite3DeleteFrom(), sqlite3Insert(), and sqlite3Update().

◆ sqlite3VdbeCreate()

SQLITE_PRIVATE Vdbe * sqlite3VdbeCreate ( Parse * pParse)

Definition at line 77757 of file sqlite3.c.

77763 {
77764 sqlite3 *db = pParse->db;
77765 Vdbe *p;
77766 p = sqlite3DbMallocRawNN(db, sizeof(Vdbe) );
77767 if( p==0 ) return 0;
77768 memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
77769 p->db = db;
77770 if( db->pVdbe ){
77771 db->pVdbe->pPrev = p;
77772 }
77773 p->pNext = db->pVdbe;
77774 p->pPrev = 0;
77775 db->pVdbe = p;
77777 p->pParse = pParse;
77778 pParse->pVdbe = p;
77779 assert( pParse->aLabel==0 );
Vdbe * pPrev
Definition sqlite3.c:21085

◆ sqlite3VdbeCurrentAddr()

◆ sqlite3VdbeCursorMoveto()

SQLITE_PRIVATE int sqlite3VdbeCursorMoveto ( VdbeCursor ** pp,
u32 * piCol )

Definition at line 81297 of file sqlite3.c.

81303 {
81304 VdbeCursor *p = *pp;
81305 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
81306 if( p->deferredMoveto ){
81307 u32 iMap;
81308 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
81309 *pp = p->pAltCursor;
81310 *piCol = iMap - 1;
81311 return SQLITE_OK;
81312 }
81313 return sqlite3VdbeFinishMoveto(p);
SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *)
Definition sqlite3.c:81235
#define CURTYPE_PSEUDO
Definition sqlite3.c:20767
u32 * aAltMap
Definition sqlite3.c:20796
VdbeCursor * pAltCursor
Definition sqlite3.c:20812
u8 deferredMoveto
Definition sqlite3.c:20784

References VdbeCursor::aAltMap, CURTYPE_BTREE, CURTYPE_PSEUDO, VdbeCursor::deferredMoveto, VdbeCursor::eCurType, handleMovedCursor(), VdbeCursor::nullRow, VdbeCursor::pAltCursor, VdbeCursor::pCursor, sqlite3BtreeCursorHasMoved(), sqlite3VdbeFinishMoveto(), SQLITE_OK, and VdbeCursor::uc.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeCursorRestore()

SQLITE_PRIVATE int sqlite3VdbeCursorRestore ( VdbeCursor * p)

Definition at line 81276 of file sqlite3.c.

81282 {

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeDb()

◆ sqlite3VdbeDelete()

SQLITE_PRIVATE void sqlite3VdbeDelete ( Vdbe * p)

Definition at line 81209 of file sqlite3.c.

81215 {
81216 sqlite3 *db;
81217
81218 assert( p!=0 );
81219 db = p->db;
81220 assert( sqlite3_mutex_held(db->mutex) );
81222 if( p->pPrev ){
81223 p->pPrev->pNext = p->pNext;
81224 }else{
81225 assert( db->pVdbe==p );
81226 db->pVdbe = p->pNext;
81227 }
81228 if( p->pNext ){

Referenced by sqlite3RunParser().

◆ sqlite3VdbeDeleteAuxData()

SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData ( sqlite3 * db,
AuxData ** pp,
int iOp,
int mask )

Definition at line 81140 of file sqlite3.c.

81146 {
81147 while( *pp ){
81148 AuxData *pAux = *pp;
81149 if( (iOp<0)
81150 || (pAux->iAuxOp==iOp
81151 && pAux->iAuxArg>=0
81152 && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg))))
81153 ){
81154 testcase( pAux->iAuxArg==31 );
81155 if( pAux->xDeleteAux ){
81156 pAux->xDeleteAux(pAux->pAux);
81157 }
81158 *pp = pAux->pNextAux;

References AuxData::iAuxArg, AuxData::iAuxOp, mask, MASKBIT32, AuxData::pAux, AuxData::pNextAux, sqlite3DbFree(), testcase, and AuxData::xDeleteAux.

Referenced by closeAllCursors(), sqlite3VdbeExec(), sqlite3VdbeFrameDelete(), and sqlite3VdbeFrameRestore().

◆ sqlite3VdbeDeletePriorOpcode()

SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode ( Vdbe * p,
u8 op )

Definition at line 78949 of file sqlite3.c.

78955 {

Referenced by sqlite3GenerateIndexKey().

◆ sqlite3VdbeDisplayP4()

SQLITE_PRIVATE char * sqlite3VdbeDisplayP4 ( sqlite3 * db,
Op * pOp )

Definition at line 79365 of file sqlite3.c.

79371 {
79372 char *zP4 = 0;
79373 StrAccum x;
79374
79376 switch( pOp->p4type ){
79377 case P4_KEYINFO: {
79378 int j;
79379 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
79380 assert( pKeyInfo->aSortFlags!=0 );
79381 sqlite3_str_appendf(&x, "k(%d", pKeyInfo->nKeyField);
79382 for(j=0; j<pKeyInfo->nKeyField; j++){
79383 CollSeq *pColl = pKeyInfo->aColl[j];
79384 const char *zColl = pColl ? pColl->zName : "";
79385 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
79386 sqlite3_str_appendf(&x, ",%s%s%s",
79387 (pKeyInfo->aSortFlags[j] & KEYINFO_ORDER_DESC) ? "-" : "",
79388 (pKeyInfo->aSortFlags[j] & KEYINFO_ORDER_BIGNULL)? "N." : "",
79389 zColl);
79390 }
79391 sqlite3_str_append(&x, ")", 1);
79392 break;
79393 }
79394#ifdef SQLITE_ENABLE_CURSOR_HINTS
79395 case P4_EXPR: {
79396 displayP4Expr(&x, pOp->p4.pExpr);
79397 break;
79398 }
79399#endif
79400 case P4_COLLSEQ: {
79401 static const char *const encnames[] = {"?", "8", "16LE", "16BE"};
79402 CollSeq *pColl = pOp->p4.pColl;
79403 assert( pColl->enc>=0 && pColl->enc<4 );
79404 sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName,
79405 encnames[pColl->enc]);
79406 break;
79407 }
79408 case P4_FUNCDEF: {
79409 FuncDef *pDef = pOp->p4.pFunc;
79410 sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
79411 break;
79412 }
79413 case P4_FUNCCTX: {
79414 FuncDef *pDef = pOp->p4.pCtx->pFunc;
79415 sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
79416 break;
79417 }
79418 case P4_INT64: {
79419 sqlite3_str_appendf(&x, "%lld", *pOp->p4.pI64);
79420 break;
79421 }
79422 case P4_INT32: {
79423 sqlite3_str_appendf(&x, "%d", pOp->p4.i);
79424 break;
79425 }
79426 case P4_REAL: {
79427 sqlite3_str_appendf(&x, "%.16g", *pOp->p4.pReal);
79428 break;
79429 }
79430 case P4_MEM: {
79431 Mem *pMem = pOp->p4.pMem;
79432 if( pMem->flags & MEM_Str ){
79433 zP4 = pMem->z;
79434 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
79435 sqlite3_str_appendf(&x, "%lld", pMem->u.i);
79436 }else if( pMem->flags & MEM_Real ){
79437 sqlite3_str_appendf(&x, "%.16g", pMem->u.r);
79438 }else if( pMem->flags & MEM_Null ){
79439 zP4 = "NULL";
79440 }else{
79441 assert( pMem->flags & MEM_Blob );
79442 zP4 = "(blob)";
79443 }
79444 break;
79445 }
79446#ifndef SQLITE_OMIT_VIRTUALTABLE
79447 case P4_VTAB: {
79448 sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
79449 sqlite3_str_appendf(&x, "vtab:%p", pVtab);
79450 break;
79451 }
79452#endif
79453 case P4_INTARRAY: {
79454 u32 i;
79455 u32 *ai = pOp->p4.ai;
79456 u32 n = ai[0]; /* The first element of an INTARRAY is always the
79457 ** count of the number of elements to follow */
79458 for(i=1; i<=n; i++){
79459 sqlite3_str_appendf(&x, "%c%u", (i==1 ? '[' : ','), ai[i]);
79460 }
79461 sqlite3_str_append(&x, "]", 1);
79462 break;
79463 }
79464 case P4_SUBPROGRAM: {
79465 zP4 = "program";
79466 break;
79467 }
79468 case P4_DYNBLOB:
79469 case P4_ADVANCE: {
79470 break;
79471 }
79472 case P4_TABLE: {
79473 zP4 = pOp->p4.pTab->zName;
79474 break;
79475 }
79476 default: {
79477 zP4 = pOp->p4.z;
79478 }
79479 }
double * pReal
Definition sqlite3.c:15446
FuncDef * pFunc
Definition sqlite3.c:15447
sqlite3_context * pCtx
Definition sqlite3.c:15448
CollSeq * pColl
Definition sqlite3.c:15449

References sqlite3_str::accError, KeyInfo::aColl, VdbeOp::p4union::ai, KeyInfo::aSortFlags, CollSeq::enc, sqlite3_value::flags, VdbeOp::p4union::i, sqlite3_value::MemValue::i, KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, FuncDef::nArg, KeyInfo::nKeyField, VdbeOp::p4, P4_ADVANCE, P4_COLLSEQ, P4_DYNBLOB, P4_EXPR, P4_FUNCCTX, P4_FUNCDEF, P4_INT32, P4_INT64, P4_INTARRAY, P4_KEYINFO, P4_MEM, P4_REAL, P4_SUBPROGRAM, P4_TABLE, P4_VTAB, VdbeOp::p4type, VdbeOp::p4union::pColl, VdbeOp::p4union::pCtx, VdbeOp::p4union::pFunc, sqlite3_context::pFunc, VdbeOp::p4union::pI64, VdbeOp::p4union::pKeyInfo, VdbeOp::p4union::pMem, VdbeOp::p4union::pReal, VdbeOp::p4union::pTab, VdbeOp::p4union::pVtab, VTable::pVtab, sqlite3_value::MemValue::r, sqlite3_str_append(), sqlite3_str_appendall(), sqlite3_str_appendf(), sqlite3OomFault(), sqlite3StrAccumFinish(), sqlite3StrAccumInit(), SQLITE_MAX_LENGTH, SQLITE_NOMEM, sqlite3_value::u, VdbeOp::p4union::z, sqlite3_value::z, FuncDef::zName, CollSeq::zName, and Table::zName.

Referenced by sqlite3VdbeList().

◆ sqlite3VdbeEndCoroutine()

SQLITE_PRIVATE void sqlite3VdbeEndCoroutine ( Vdbe * v,
int regYield )

Definition at line 78234 of file sqlite3.c.

78240 {
78241 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
78242
78243 /* Clear the temporary register cache, thereby ensuring that each
78244 ** co-routine has its own independent set of registers, because co-routines
78245 ** might expect their registers to be preserved across an OP_Yield, and
#define OP_EndCoroutine
Definition sqlite3.c:15632

Referenced by multiSelectOrderBy(), sqlite3EndTable(), sqlite3Insert(), and sqlite3Select().

◆ sqlite3VdbeEnter()

SQLITE_PRIVATE void sqlite3VdbeEnter ( Vdbe * p)

Definition at line 79521 of file sqlite3.c.

79527 {
79528 int i;
79529 sqlite3 *db;
79530 Db *aDb;
79531 int nDb;
79532 if( DbMaskAllZero(p->lockMask) ) return; /* The common case */
79533 db = p->db;
79534 aDb = db->aDb;
79535 nDb = db->nDb;
yDbMask lockMask
Definition sqlite3.c:21135

References sqlite3::aDb, ALWAYS, Vdbe::db, DbMaskAllZero, DbMaskTest, Vdbe::lockMask, sqlite3::nDb, and sqlite3BtreeEnter().

Referenced by sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3VdbeError()

SQLITE_PRIVATE void sqlite3VdbeError ( Vdbe * p,
const char * zFormat,
... )

Definition at line 77791 of file sqlite3.c.

77797 {

Referenced by sqlite3VdbeCheckFk(), sqlite3VdbeExec(), and sqlite3VdbeList().

◆ sqlite3VdbeExec()

SQLITE_PRIVATE int sqlite3VdbeExec ( Vdbe * p)

Definition at line 85979 of file sqlite3.c.

85987 {
85988 Op *aOp = p->aOp; /* Copy of p->aOp */
85989 Op *pOp = aOp; /* Current operation */
85990#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
85991 Op *pOrigOp; /* Value of pOp at the top of the loop */
85992#endif
85993#ifdef SQLITE_DEBUG
85994 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
85995#endif
85996 int rc = SQLITE_OK; /* Value to return */
85997 sqlite3 *db = p->db; /* The database */
85998 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
85999 u8 encoding = ENC(db); /* The database encoding */
86000 int iCompare = 0; /* Result of last comparison */
86001 u64 nVmStep = 0; /* Number of virtual machine steps */
86002#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
86003 u64 nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */
86004#endif
86005 Mem *aMem = p->aMem; /* Copy of p->aMem */
86006 Mem *pIn1 = 0; /* 1st input operand */
86007 Mem *pIn2 = 0; /* 2nd input operand */
86008 Mem *pIn3 = 0; /* 3rd input operand */
86009 Mem *pOut = 0; /* Output operand */
86010#ifdef VDBE_PROFILE
86011 u64 start; /* CPU clock count at start of opcode */
86012#endif
86013 /*** INSERT STACK UNION HERE ***/
86014
86015 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
86017#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
86018 if( db->xProgress ){
86020 assert( 0 < db->nProgressOps );
86021 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
86022 }else{
86023 nProgressLimit = LARGEST_UINT64;
86024 }
86025#endif
86026 if( p->rc==SQLITE_NOMEM ){
86027 /* This happens if a malloc() inside a call to sqlite3_column_text() or
86028 ** sqlite3_column_text16() failed. */
86029 goto no_mem;
86030 }
86031 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
86032 testcase( p->rc!=SQLITE_OK );
86033 p->rc = SQLITE_OK;
86034 assert( p->bIsReader || p->readOnly!=0 );
86035 p->iCurrentTime = 0;
86036 assert( p->explain==0 );
86037 p->pResultSet = 0;
86038 db->busyHandler.nBusy = 0;
86039 if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
86041#ifdef SQLITE_DEBUG
86043 if( p->pc==0
86044 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
86045 ){
86046 int i;
86047 int once = 1;
86048 sqlite3VdbePrintSql(p);
86049 if( p->db->flags & SQLITE_VdbeListing ){
86050 printf("VDBE Program Listing:\n");
86051 for(i=0; i<p->nOp; i++){
86052 sqlite3VdbePrintOp(stdout, i, &aOp[i]);
86053 }
86054 }
86055 if( p->db->flags & SQLITE_VdbeEQP ){
86056 for(i=0; i<p->nOp; i++){
86057 if( aOp[i].opcode==OP_Explain ){
86058 if( once ) printf("VDBE Query Plan:\n");
86059 printf("%s\n", aOp[i].p4.z);
86060 once = 0;
86061 }
86062 }
86063 }
86064 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
86065 }
86067#endif
86068 for(pOp=&aOp[p->pc]; 1; pOp++){
86069 /* Errors are detected by individual opcodes, with an immediate
86070 ** jumps to abort_due_to_error. */
86071 assert( rc==SQLITE_OK );
86072
86073 assert( pOp>=aOp && pOp<&aOp[p->nOp]);
86074#ifdef VDBE_PROFILE
86075 start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
86076#endif
86077 nVmStep++;
86078#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
86079 if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
86080#endif
86081
86082 /* Only allow tracing if SQLITE_DEBUG is defined.
86083 */
86084#ifdef SQLITE_DEBUG
86085 if( db->flags & SQLITE_VdbeTrace ){
86086 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
86087 test_trace_breakpoint((int)(pOp - aOp),pOp,p);
86088 }
86089#endif
86090
86091
86092 /* Check to see if we need to simulate an interrupt. This only happens
86093 ** if we have a special test build.
86094 */
86095#ifdef SQLITE_TEST
86096 if( sqlite3_interrupt_count>0 ){
86097 sqlite3_interrupt_count--;
86098 if( sqlite3_interrupt_count==0 ){
86100 }
86101 }
86102#endif
86103
86104 /* Sanity checking on other operands */
86105#ifdef SQLITE_DEBUG
86106 {
86107 u8 opProperty = sqlite3OpcodeProperty[pOp->opcode];
86108 if( (opProperty & OPFLG_IN1)!=0 ){
86109 assert( pOp->p1>0 );
86110 assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
86111 assert( memIsValid(&aMem[pOp->p1]) );
86112 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
86113 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
86114 }
86115 if( (opProperty & OPFLG_IN2)!=0 ){
86116 assert( pOp->p2>0 );
86117 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
86118 assert( memIsValid(&aMem[pOp->p2]) );
86119 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
86120 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
86121 }
86122 if( (opProperty & OPFLG_IN3)!=0 ){
86123 assert( pOp->p3>0 );
86124 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
86125 assert( memIsValid(&aMem[pOp->p3]) );
86126 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
86127 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
86128 }
86129 if( (opProperty & OPFLG_OUT2)!=0 ){
86130 assert( pOp->p2>0 );
86131 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
86132 memAboutToChange(p, &aMem[pOp->p2]);
86133 }
86134 if( (opProperty & OPFLG_OUT3)!=0 ){
86135 assert( pOp->p3>0 );
86136 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
86137 memAboutToChange(p, &aMem[pOp->p3]);
86138 }
86139 }
86140#endif
86141#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
86142 pOrigOp = pOp;
86143#endif
86144
86145 switch( pOp->opcode ){
86146
86147/*****************************************************************************
86148** What follows is a massive switch statement where each case implements a
86149** separate instruction in the virtual machine. If we follow the usual
86150** indentation conventions, each case should be indented by 6 spaces. But
86151** that is a lot of wasted space on the left margin. So the code within
86152** the switch statement will break with convention and be flush-left. Another
86153** big comment (similar to this one) will mark the point in the code where
86154** we transition back to normal indentation.
86155**
86156** The formatting of each case is important. The makefile for SQLite
86157** generates two C files "opcodes.h" and "opcodes.c" by scanning this
86158** file looking for lines that begin with "case OP_". The opcodes.h files
86159** will be filled with #defines that give unique integer values to each
86160** opcode and the opcodes.c file is filled with an array of strings where
86161** each string is the symbolic name for the corresponding opcode. If the
86162** case statement is followed by a comment of the form "/# same as ... #/"
86163** that comment is used to determine the particular value of the opcode.
86164**
86165** Other keywords in the comment that follows each case are used to
86166** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
86167** Keywords include: in1, in2, in3, out2, out3. See
86168** the mkopcodeh.awk script for additional information.
86169**
86170** Documentation about VDBE opcodes is generated by scanning this file
86171** for lines of that contain "Opcode:". That line and all subsequent
86172** comment lines are used in the generation of the opcode.html documentation
86173** file.
86174**
86175** SUMMARY:
86176**
86177** Formatting is important to scripts that scan this file.
86178** Do not deviate from the formatting style currently in use.
86179**
86180*****************************************************************************/
86181
86182/* Opcode: Goto * P2 * * *
86183**
86184** An unconditional jump to address P2.
86185** The next instruction executed will be
86186** the one at index P2 from the beginning of
86187** the program.
86188**
86189** The P1 parameter is not actually used by this opcode. However, it
86190** is sometimes set to 1 instead of 0 as a hint to the command-line shell
86191** that this Goto is the bottom of a loop and that the lines from P2 down
86192** to the current line should be indented for EXPLAIN output.
86193*/
86194case OP_Goto: { /* jump */
86195
86196#ifdef SQLITE_DEBUG
86197 /* In debuggging mode, when the p5 flags is set on an OP_Goto, that
86198 ** means we should really jump back to the preceeding OP_ReleaseReg
86199 ** instruction. */
86200 if( pOp->p5 ){
86201 assert( pOp->p2 < (int)(pOp - aOp) );
86202 assert( pOp->p2 > 1 );
86203 pOp = &aOp[pOp->p2 - 2];
86204 assert( pOp[1].opcode==OP_ReleaseReg );
86205 goto check_for_interrupt;
86206 }
86207#endif
86208
86209jump_to_p2_and_check_for_interrupt:
86210 pOp = &aOp[pOp->p2 - 1];
86211
86212 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
86213 ** OP_VNext, or OP_SorterNext) all jump here upon
86214 ** completion. Check to see if sqlite3_interrupt() has been called
86215 ** or if the progress callback needs to be invoked.
86216 **
86217 ** This code uses unstructured "goto" statements and does not look clean.
86218 ** But that is not due to sloppy coding habits. The code is written this
86219 ** way for performance, to avoid having to run the interrupt and progress
86220 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
86221 ** faster according to "valgrind --tool=cachegrind" */
86222check_for_interrupt:
86223 if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
86224#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
86225 /* Call the progress callback if it is configured and the required number
86226 ** of VDBE ops have been executed (either since this invocation of
86227 ** sqlite3VdbeExec() or since last time the progress callback was called).
86228 ** If the progress callback returns non-zero, exit the virtual machine with
86229 ** a return code SQLITE_ABORT.
86230 */
86231 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
86232 assert( db->nProgressOps!=0 );
86233 nProgressLimit += db->nProgressOps;
86234 if( db->xProgress(db->pProgressArg) ){
86235 nProgressLimit = LARGEST_UINT64;
86236 rc = SQLITE_INTERRUPT;
86237 goto abort_due_to_error;
86238 }
86239 }
86240#endif
86241
86242 break;
86243}
86244
86245/* Opcode: Gosub P1 P2 * * *
86246**
86247** Write the current address onto register P1
86248** and then jump to address P2.
86249*/
86250case OP_Gosub: { /* jump */
86251 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
86252 pIn1 = &aMem[pOp->p1];
86253 assert( VdbeMemDynamic(pIn1)==0 );
86254 memAboutToChange(p, pIn1);
86255 pIn1->flags = MEM_Int;
86256 pIn1->u.i = (int)(pOp-aOp);
86257 REGISTER_TRACE(pOp->p1, pIn1);
86258
86259 /* Most jump operations do a goto to this spot in order to update
86260 ** the pOp pointer. */
86261jump_to_p2:
86262 pOp = &aOp[pOp->p2 - 1];
86263 break;
86264}
86265
86266/* Opcode: Return P1 * * * *
86267**
86268** Jump to the next instruction after the address in register P1. After
86269** the jump, register P1 becomes undefined.
86270*/
86271case OP_Return: { /* in1 */
86272 pIn1 = &aMem[pOp->p1];
86273 assert( pIn1->flags==MEM_Int );
86274 pOp = &aOp[pIn1->u.i];
86275 pIn1->flags = MEM_Undefined;
86276 break;
86277}
86278
86279/* Opcode: InitCoroutine P1 P2 P3 * *
86280**
86281** Set up register P1 so that it will Yield to the coroutine
86282** located at address P3.
86283**
86284** If P2!=0 then the coroutine implementation immediately follows
86285** this opcode. So jump over the coroutine implementation to
86286** address P2.
86287**
86288** See also: EndCoroutine
86289*/
86290case OP_InitCoroutine: { /* jump */
86291 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
86292 assert( pOp->p2>=0 && pOp->p2<p->nOp );
86293 assert( pOp->p3>=0 && pOp->p3<p->nOp );
86294 pOut = &aMem[pOp->p1];
86295 assert( !VdbeMemDynamic(pOut) );
86296 pOut->u.i = pOp->p3 - 1;
86297 pOut->flags = MEM_Int;
86298 if( pOp->p2 ) goto jump_to_p2;
86299 break;
86300}
86301
86302/* Opcode: EndCoroutine P1 * * * *
86303**
86304** The instruction at the address in register P1 is a Yield.
86305** Jump to the P2 parameter of that Yield.
86306** After the jump, register P1 becomes undefined.
86307**
86308** See also: InitCoroutine
86309*/
86310case OP_EndCoroutine: { /* in1 */
86311 VdbeOp *pCaller;
86312 pIn1 = &aMem[pOp->p1];
86313 assert( pIn1->flags==MEM_Int );
86314 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
86315 pCaller = &aOp[pIn1->u.i];
86316 assert( pCaller->opcode==OP_Yield );
86317 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
86318 pOp = &aOp[pCaller->p2 - 1];
86319 pIn1->flags = MEM_Undefined;
86320 break;
86321}
86322
86323/* Opcode: Yield P1 P2 * * *
86324**
86325** Swap the program counter with the value in register P1. This
86326** has the effect of yielding to a coroutine.
86327**
86328** If the coroutine that is launched by this instruction ends with
86329** Yield or Return then continue to the next instruction. But if
86330** the coroutine launched by this instruction ends with
86331** EndCoroutine, then jump to P2 rather than continuing with the
86332** next instruction.
86333**
86334** See also: InitCoroutine
86335*/
86336case OP_Yield: { /* in1, jump */
86337 int pcDest;
86338 pIn1 = &aMem[pOp->p1];
86339 assert( VdbeMemDynamic(pIn1)==0 );
86340 pIn1->flags = MEM_Int;
86341 pcDest = (int)pIn1->u.i;
86342 pIn1->u.i = (int)(pOp - aOp);
86343 REGISTER_TRACE(pOp->p1, pIn1);
86344 pOp = &aOp[pcDest];
86345 break;
86346}
86347
86348/* Opcode: HaltIfNull P1 P2 P3 P4 P5
86349** Synopsis: if r[P3]=null halt
86350**
86351** Check the value in register P3. If it is NULL then Halt using
86352** parameter P1, P2, and P4 as if this were a Halt instruction. If the
86353** value in register P3 is not NULL, then this routine is a no-op.
86354** The P5 parameter should be 1.
86355*/
86356case OP_HaltIfNull: { /* in3 */
86357 pIn3 = &aMem[pOp->p3];
86358#ifdef SQLITE_DEBUG
86359 if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
86360#endif
86361 if( (pIn3->flags & MEM_Null)==0 ) break;
86362 /* Fall through into OP_Halt */
86363 /* no break */ deliberate_fall_through
86364}
86365
86366/* Opcode: Halt P1 P2 * P4 P5
86367**
86368** Exit immediately. All open cursors, etc are closed
86369** automatically.
86370**
86371** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
86372** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
86373** For errors, it can be some other value. If P1!=0 then P2 will determine
86374** whether or not to rollback the current transaction. Do not rollback
86375** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
86376** then back out all changes that have occurred during this execution of the
86377** VDBE, but do not rollback the transaction.
86378**
86379** If P4 is not null then it is an error message string.
86380**
86381** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
86382**
86383** 0: (no change)
86384** 1: NOT NULL contraint failed: P4
86385** 2: UNIQUE constraint failed: P4
86386** 3: CHECK constraint failed: P4
86387** 4: FOREIGN KEY constraint failed: P4
86388**
86389** If P5 is not zero and P4 is NULL, then everything after the ":" is
86390** omitted.
86391**
86392** There is an implied "Halt 0 0 0" instruction inserted at the very end of
86393** every program. So a jump past the last instruction of the program
86394** is the same as executing Halt.
86395*/
86396case OP_Halt: {
86397 VdbeFrame *pFrame;
86398 int pcx;
86399
86400 pcx = (int)(pOp - aOp);
86401#ifdef SQLITE_DEBUG
86402 if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
86403#endif
86404 if( pOp->p1==SQLITE_OK && p->pFrame ){
86405 /* Halt the sub-program. Return control to the parent frame. */
86406 pFrame = p->pFrame;
86407 p->pFrame = pFrame->pParent;
86408 p->nFrame--;
86410 pcx = sqlite3VdbeFrameRestore(pFrame);
86411 if( pOp->p2==OE_Ignore ){
86412 /* Instruction pcx is the OP_Program that invoked the sub-program
86413 ** currently being halted. If the p2 instruction of this OP_Halt
86414 ** instruction is set to OE_Ignore, then the sub-program is throwing
86415 ** an IGNORE exception. In this case jump to the address specified
86416 ** as the p2 of the calling OP_Program. */
86417 pcx = p->aOp[pcx].p2-1;
86418 }
86419 aOp = p->aOp;
86420 aMem = p->aMem;
86421 pOp = &aOp[pcx];
86422 break;
86423 }
86424 p->rc = pOp->p1;
86425 p->errorAction = (u8)pOp->p2;
86426 p->pc = pcx;
86427 assert( pOp->p5<=4 );
86428 if( p->rc ){
86429 if( pOp->p5 ){
86430 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
86431 "FOREIGN KEY" };
86432 testcase( pOp->p5==1 );
86433 testcase( pOp->p5==2 );
86434 testcase( pOp->p5==3 );
86435 testcase( pOp->p5==4 );
86436 sqlite3VdbeError(p, "%s constraint failed", azType[pOp->p5-1]);
86437 if( pOp->p4.z ){
86438 p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
86439 }
86440 }else{
86441 sqlite3VdbeError(p, "%s", pOp->p4.z);
86442 }
86443 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
86444 }
86445 rc = sqlite3VdbeHalt(p);
86446 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
86447 if( rc==SQLITE_BUSY ){
86448 p->rc = SQLITE_BUSY;
86449 }else{
86450 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
86451 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
86452 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
86453 }
86454 goto vdbe_return;
86455}
86456
86457/* Opcode: Integer P1 P2 * * *
86458** Synopsis: r[P2]=P1
86459**
86460** The 32-bit integer value P1 is written into register P2.
86461*/
86462case OP_Integer: { /* out2 */
86463 pOut = out2Prerelease(p, pOp);
86464 pOut->u.i = pOp->p1;
86465 break;
86466}
86467
86468/* Opcode: Int64 * P2 * P4 *
86469** Synopsis: r[P2]=P4
86470**
86471** P4 is a pointer to a 64-bit integer value.
86472** Write that value into register P2.
86473*/
86474case OP_Int64: { /* out2 */
86475 pOut = out2Prerelease(p, pOp);
86476 assert( pOp->p4.pI64!=0 );
86477 pOut->u.i = *pOp->p4.pI64;
86478 break;
86479}
86480
86481#ifndef SQLITE_OMIT_FLOATING_POINT
86482/* Opcode: Real * P2 * P4 *
86483** Synopsis: r[P2]=P4
86484**
86485** P4 is a pointer to a 64-bit floating point value.
86486** Write that value into register P2.
86487*/
86488case OP_Real: { /* same as TK_FLOAT, out2 */
86489 pOut = out2Prerelease(p, pOp);
86490 pOut->flags = MEM_Real;
86491 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
86492 pOut->u.r = *pOp->p4.pReal;
86493 break;
86494}
86495#endif
86496
86497/* Opcode: String8 * P2 * P4 *
86498** Synopsis: r[P2]='P4'
86499**
86500** P4 points to a nul terminated UTF-8 string. This opcode is transformed
86501** into a String opcode before it is executed for the first time. During
86502** this transformation, the length of string P4 is computed and stored
86503** as the P1 parameter.
86504*/
86505case OP_String8: { /* same as TK_STRING, out2 */
86506 assert( pOp->p4.z!=0 );
86507 pOut = out2Prerelease(p, pOp);
86508 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
86509
86510#ifndef SQLITE_OMIT_UTF16
86511 if( encoding!=SQLITE_UTF8 ){
86512 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
86513 assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
86514 if( rc ) goto too_big;
86515 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
86516 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
86517 assert( VdbeMemDynamic(pOut)==0 );
86518 pOut->szMalloc = 0;
86519 pOut->flags |= MEM_Static;
86520 if( pOp->p4type==P4_DYNAMIC ){
86521 sqlite3DbFree(db, pOp->p4.z);
86522 }
86523 pOp->p4type = P4_DYNAMIC;
86524 pOp->p4.z = pOut->z;
86525 pOp->p1 = pOut->n;
86526 }
86527#endif
86528 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
86529 goto too_big;
86530 }
86531 pOp->opcode = OP_String;
86532 assert( rc==SQLITE_OK );
86533 /* Fall through to the next case, OP_String */
86534 /* no break */ deliberate_fall_through
86535}
86536
86537/* Opcode: String P1 P2 P3 P4 P5
86538** Synopsis: r[P2]='P4' (len=P1)
86539**
86540** The string value P4 of length P1 (bytes) is stored in register P2.
86541**
86542** If P3 is not zero and the content of register P3 is equal to P5, then
86543** the datatype of the register P2 is converted to BLOB. The content is
86544** the same sequence of bytes, it is merely interpreted as a BLOB instead
86545** of a string, as if it had been CAST. In other words:
86546**
86547** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
86548*/
86549case OP_String: { /* out2 */
86550 assert( pOp->p4.z!=0 );
86551 pOut = out2Prerelease(p, pOp);
86553 pOut->z = pOp->p4.z;
86554 pOut->n = pOp->p1;
86555 pOut->enc = encoding;
86556 UPDATE_MAX_BLOBSIZE(pOut);
86557#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
86558 if( pOp->p3>0 ){
86559 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
86560 pIn3 = &aMem[pOp->p3];
86561 assert( pIn3->flags & MEM_Int );
86562 if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
86563 }
86564#endif
86565 break;
86566}
86567
86568/* Opcode: Null P1 P2 P3 * *
86569** Synopsis: r[P2..P3]=NULL
86570**
86571** Write a NULL into registers P2. If P3 greater than P2, then also write
86572** NULL into register P3 and every register in between P2 and P3. If P3
86573** is less than P2 (typically P3 is zero) then only register P2 is
86574** set to NULL.
86575**
86576** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
86577** NULL values will not compare equal even if SQLITE_NULLEQ is set on
86578** OP_Ne or OP_Eq.
86579*/
86580case OP_Null: { /* out2 */
86581 int cnt;
86582 u16 nullFlag;
86583 pOut = out2Prerelease(p, pOp);
86584 cnt = pOp->p3-pOp->p2;
86585 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
86586 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
86587 pOut->n = 0;
86588#ifdef SQLITE_DEBUG
86589 pOut->uTemp = 0;
86590#endif
86591 while( cnt>0 ){
86592 pOut++;
86593 memAboutToChange(p, pOut);
86595 pOut->flags = nullFlag;
86596 pOut->n = 0;
86597 cnt--;
86598 }
86599 break;
86600}
86601
86602/* Opcode: SoftNull P1 * * * *
86603** Synopsis: r[P1]=NULL
86604**
86605** Set register P1 to have the value NULL as seen by the OP_MakeRecord
86606** instruction, but do not free any string or blob memory associated with
86607** the register, so that if the value was a string or blob that was
86608** previously copied using OP_SCopy, the copies will continue to be valid.
86609*/
86610case OP_SoftNull: {
86611 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
86612 pOut = &aMem[pOp->p1];
86613 pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
86614 break;
86615}
86616
86617/* Opcode: Blob P1 P2 * P4 *
86618** Synopsis: r[P2]=P4 (len=P1)
86619**
86620** P4 points to a blob of data P1 bytes long. Store this
86621** blob in register P2.
86622*/
86623case OP_Blob: { /* out2 */
86624 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
86625 pOut = out2Prerelease(p, pOp);
86626 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
86627 pOut->enc = encoding;
86628 UPDATE_MAX_BLOBSIZE(pOut);
86629 break;
86630}
86631
86632/* Opcode: Variable P1 P2 * P4 *
86633** Synopsis: r[P2]=parameter(P1,P4)
86634**
86635** Transfer the values of bound parameter P1 into register P2
86636**
86637** If the parameter is named, then its name appears in P4.
86638** The P4 value is used by sqlite3_bind_parameter_name().
86639*/
86640case OP_Variable: { /* out2 */
86641 Mem *pVar; /* Value being transferred */
86642
86643 assert( pOp->p1>0 && pOp->p1<=p->nVar );
86644 assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
86645 pVar = &p->aVar[pOp->p1 - 1];
86646 if( sqlite3VdbeMemTooBig(pVar) ){
86647 goto too_big;
86648 }
86649 pOut = &aMem[pOp->p2];
86650 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
86651 memcpy(pOut, pVar, MEMCELLSIZE);
86652 pOut->flags &= ~(MEM_Dyn|MEM_Ephem);
86653 pOut->flags |= MEM_Static|MEM_FromBind;
86654 UPDATE_MAX_BLOBSIZE(pOut);
86655 break;
86656}
86657
86658/* Opcode: Move P1 P2 P3 * *
86659** Synopsis: r[P2@P3]=r[P1@P3]
86660**
86661** Move the P3 values in register P1..P1+P3-1 over into
86662** registers P2..P2+P3-1. Registers P1..P1+P3-1 are
86663** left holding a NULL. It is an error for register ranges
86664** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
86665** for P3 to be less than 1.
86666*/
86667case OP_Move: {
86668 int n; /* Number of registers left to copy */
86669 int p1; /* Register to copy from */
86670 int p2; /* Register to copy to */
86671
86672 n = pOp->p3;
86673 p1 = pOp->p1;
86674 p2 = pOp->p2;
86675 assert( n>0 && p1>0 && p2>0 );
86676 assert( p1+n<=p2 || p2+n<=p1 );
86677
86678 pIn1 = &aMem[p1];
86679 pOut = &aMem[p2];
86680 do{
86681 assert( pOut<=&aMem[(p->nMem+1 - p->nCursor)] );
86682 assert( pIn1<=&aMem[(p->nMem+1 - p->nCursor)] );
86683 assert( memIsValid(pIn1) );
86684 memAboutToChange(p, pOut);
86685 sqlite3VdbeMemMove(pOut, pIn1);
86686#ifdef SQLITE_DEBUG
86687 pIn1->pScopyFrom = 0;
86688 { int i;
86689 for(i=1; i<p->nMem; i++){
86690 if( aMem[i].pScopyFrom==pIn1 ){
86691 aMem[i].pScopyFrom = pOut;
86692 }
86693 }
86694 }
86695#endif
86696 Deephemeralize(pOut);
86697 REGISTER_TRACE(p2++, pOut);
86698 pIn1++;
86699 pOut++;
86700 }while( --n );
86701 break;
86702}
86703
86704/* Opcode: Copy P1 P2 P3 * *
86705** Synopsis: r[P2@P3+1]=r[P1@P3+1]
86706**
86707** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
86708**
86709** This instruction makes a deep copy of the value. A duplicate
86710** is made of any string or blob constant. See also OP_SCopy.
86711*/
86712case OP_Copy: {
86713 int n;
86714
86715 n = pOp->p3;
86716 pIn1 = &aMem[pOp->p1];
86717 pOut = &aMem[pOp->p2];
86718 assert( pOut!=pIn1 );
86719 while( 1 ){
86720 memAboutToChange(p, pOut);
86722 Deephemeralize(pOut);
86723#ifdef SQLITE_DEBUG
86724 pOut->pScopyFrom = 0;
86725#endif
86726 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
86727 if( (n--)==0 ) break;
86728 pOut++;
86729 pIn1++;
86730 }
86731 break;
86732}
86733
86734/* Opcode: SCopy P1 P2 * * *
86735** Synopsis: r[P2]=r[P1]
86736**
86737** Make a shallow copy of register P1 into register P2.
86738**
86739** This instruction makes a shallow copy of the value. If the value
86740** is a string or blob, then the copy is only a pointer to the
86741** original and hence if the original changes so will the copy.
86742** Worse, if the original is deallocated, the copy becomes invalid.
86743** Thus the program must guarantee that the original will not change
86744** during the lifetime of the copy. Use OP_Copy to make a complete
86745** copy.
86746*/
86747case OP_SCopy: { /* out2 */
86748 pIn1 = &aMem[pOp->p1];
86749 pOut = &aMem[pOp->p2];
86750 assert( pOut!=pIn1 );
86752#ifdef SQLITE_DEBUG
86753 pOut->pScopyFrom = pIn1;
86754 pOut->mScopyFlags = pIn1->flags;
86755#endif
86756 break;
86757}
86758
86759/* Opcode: IntCopy P1 P2 * * *
86760** Synopsis: r[P2]=r[P1]
86761**
86762** Transfer the integer value held in register P1 into register P2.
86763**
86764** This is an optimized version of SCopy that works only for integer
86765** values.
86766*/
86767case OP_IntCopy: { /* out2 */
86768 pIn1 = &aMem[pOp->p1];
86769 assert( (pIn1->flags & MEM_Int)!=0 );
86770 pOut = &aMem[pOp->p2];
86771 sqlite3VdbeMemSetInt64(pOut, pIn1->u.i);
86772 break;
86773}
86774
86775/* Opcode: ResultRow P1 P2 * * *
86776** Synopsis: output=r[P1@P2]
86777**
86778** The registers P1 through P1+P2-1 contain a single row of
86779** results. This opcode causes the sqlite3_step() call to terminate
86780** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
86781** structure to provide access to the r(P1)..r(P1+P2-1) values as
86782** the result row.
86783*/
86784case OP_ResultRow: {
86785 Mem *pMem;
86786 int i;
86787 assert( p->nResColumn==pOp->p2 );
86788 assert( pOp->p1>0 );
86789 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
86790
86791 /* If this statement has violated immediate foreign key constraints, do
86792 ** not return the number of rows modified. And do not RELEASE the statement
86793 ** transaction. It needs to be rolled back. */
86794 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
86795 assert( db->flags&SQLITE_CountRows );
86796 assert( p->usesStmtJournal );
86797 goto abort_due_to_error;
86798 }
86799
86800 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
86801 ** DML statements invoke this opcode to return the number of rows
86802 ** modified to the user. This is the only way that a VM that
86803 ** opens a statement transaction may invoke this opcode.
86804 **
86805 ** In case this is such a statement, close any statement transaction
86806 ** opened by this VM before returning control to the user. This is to
86807 ** ensure that statement-transactions are always nested, not overlapping.
86808 ** If the open statement-transaction is not closed here, then the user
86809 ** may step another VM that opens its own statement transaction. This
86810 ** may lead to overlapping statement transactions.
86811 **
86812 ** The statement transaction is never a top-level transaction. Hence
86813 ** the RELEASE call below can never fail.
86814 */
86815 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
86817 assert( rc==SQLITE_OK );
86818
86819 /* Invalidate all ephemeral cursor row caches */
86820 p->cacheCtr = (p->cacheCtr + 2)|1;
86821
86822 /* Make sure the results of the current row are \000 terminated
86823 ** and have an assigned type. The results are de-ephemeralized as
86824 ** a side effect.
86825 */
86826 pMem = p->pResultSet = &aMem[pOp->p1];
86827 for(i=0; i<pOp->p2; i++){
86828 assert( memIsValid(&pMem[i]) );
86829 Deephemeralize(&pMem[i]);
86830 assert( (pMem[i].flags & MEM_Ephem)==0
86831 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
86833 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
86834#ifdef SQLITE_DEBUG
86835 /* The registers in the result will not be used again when the
86836 ** prepared statement restarts. This is because sqlite3_column()
86837 ** APIs might have caused type conversions of made other changes to
86838 ** the register values. Therefore, we can go ahead and break any
86839 ** OP_SCopy dependencies. */
86840 pMem[i].pScopyFrom = 0;
86841#endif
86842 }
86843 if( db->mallocFailed ) goto no_mem;
86844
86845 if( db->mTrace & SQLITE_TRACE_ROW ){
86846 db->trace.xV2(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
86847 }
86848
86849
86850 /* Return SQLITE_ROW
86851 */
86852 p->pc = (int)(pOp - aOp) + 1;
86853 rc = SQLITE_ROW;
86854 goto vdbe_return;
86855}
86856
86857/* Opcode: Concat P1 P2 P3 * *
86858** Synopsis: r[P3]=r[P2]+r[P1]
86859**
86860** Add the text in register P1 onto the end of the text in
86861** register P2 and store the result in register P3.
86862** If either the P1 or P2 text are NULL then store NULL in P3.
86863**
86864** P3 = P2 || P1
86865**
86866** It is illegal for P1 and P3 to be the same register. Sometimes,
86867** if P3 is the same register as P2, the implementation is able
86868** to avoid a memcpy().
86869*/
86870case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
86871 i64 nByte; /* Total size of the output string or blob */
86872 u16 flags1; /* Initial flags for P1 */
86873 u16 flags2; /* Initial flags for P2 */
86874
86875 pIn1 = &aMem[pOp->p1];
86876 pIn2 = &aMem[pOp->p2];
86877 pOut = &aMem[pOp->p3];
86878 testcase( pOut==pIn2 );
86879 assert( pIn1!=pOut );
86880 flags1 = pIn1->flags;
86881 testcase( flags1 & MEM_Null );
86882 testcase( pIn2->flags & MEM_Null );
86883 if( (flags1 | pIn2->flags) & MEM_Null ){
86885 break;
86886 }
86887 if( (flags1 & (MEM_Str|MEM_Blob))==0 ){
86888 if( sqlite3VdbeMemStringify(pIn1,encoding,0) ) goto no_mem;
86889 flags1 = pIn1->flags & ~MEM_Str;
86890 }else if( (flags1 & MEM_Zero)!=0 ){
86891 if( sqlite3VdbeMemExpandBlob(pIn1) ) goto no_mem;
86892 flags1 = pIn1->flags & ~MEM_Str;
86893 }
86894 flags2 = pIn2->flags;
86895 if( (flags2 & (MEM_Str|MEM_Blob))==0 ){
86896 if( sqlite3VdbeMemStringify(pIn2,encoding,0) ) goto no_mem;
86897 flags2 = pIn2->flags & ~MEM_Str;
86898 }else if( (flags2 & MEM_Zero)!=0 ){
86899 if( sqlite3VdbeMemExpandBlob(pIn2) ) goto no_mem;
86900 flags2 = pIn2->flags & ~MEM_Str;
86901 }
86902 nByte = pIn1->n + pIn2->n;
86903 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
86904 goto too_big;
86905 }
86906 if( sqlite3VdbeMemGrow(pOut, (int)nByte+3, pOut==pIn2) ){
86907 goto no_mem;
86908 }
86909 MemSetTypeFlag(pOut, MEM_Str);
86910 if( pOut!=pIn2 ){
86911 memcpy(pOut->z, pIn2->z, pIn2->n);
86912 assert( (pIn2->flags & MEM_Dyn) == (flags2 & MEM_Dyn) );
86913 pIn2->flags = flags2;
86914 }
86915 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
86916 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
86917 pIn1->flags = flags1;
86918 pOut->z[nByte]=0;
86919 pOut->z[nByte+1] = 0;
86920 pOut->z[nByte+2] = 0;
86921 pOut->flags |= MEM_Term;
86922 pOut->n = (int)nByte;
86923 pOut->enc = encoding;
86924 UPDATE_MAX_BLOBSIZE(pOut);
86925 break;
86926}
86927
86928/* Opcode: Add P1 P2 P3 * *
86929** Synopsis: r[P3]=r[P1]+r[P2]
86930**
86931** Add the value in register P1 to the value in register P2
86932** and store the result in register P3.
86933** If either input is NULL, the result is NULL.
86934*/
86935/* Opcode: Multiply P1 P2 P3 * *
86936** Synopsis: r[P3]=r[P1]*r[P2]
86937**
86938**
86939** Multiply the value in register P1 by the value in register P2
86940** and store the result in register P3.
86941** If either input is NULL, the result is NULL.
86942*/
86943/* Opcode: Subtract P1 P2 P3 * *
86944** Synopsis: r[P3]=r[P2]-r[P1]
86945**
86946** Subtract the value in register P1 from the value in register P2
86947** and store the result in register P3.
86948** If either input is NULL, the result is NULL.
86949*/
86950/* Opcode: Divide P1 P2 P3 * *
86951** Synopsis: r[P3]=r[P2]/r[P1]
86952**
86953** Divide the value in register P1 by the value in register P2
86954** and store the result in register P3 (P3=P2/P1). If the value in
86955** register P1 is zero, then the result is NULL. If either input is
86956** NULL, the result is NULL.
86957*/
86958/* Opcode: Remainder P1 P2 P3 * *
86959** Synopsis: r[P3]=r[P2]%r[P1]
86960**
86961** Compute the remainder after integer register P2 is divided by
86962** register P1 and store the result in register P3.
86963** If the value in register P1 is zero the result is NULL.
86964** If either operand is NULL, the result is NULL.
86965*/
86966case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
86967case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
86968case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
86969case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
86970case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
86971 u16 flags; /* Combined MEM_* flags from both inputs */
86972 u16 type1; /* Numeric type of left operand */
86973 u16 type2; /* Numeric type of right operand */
86974 i64 iA; /* Integer value of left operand */
86975 i64 iB; /* Integer value of right operand */
86976 double rA; /* Real value of left operand */
86977 double rB; /* Real value of right operand */
86978
86979 pIn1 = &aMem[pOp->p1];
86980 type1 = numericType(pIn1);
86981 pIn2 = &aMem[pOp->p2];
86982 type2 = numericType(pIn2);
86983 pOut = &aMem[pOp->p3];
86984 flags = pIn1->flags | pIn2->flags;
86985 if( (type1 & type2 & MEM_Int)!=0 ){
86986 iA = pIn1->u.i;
86987 iB = pIn2->u.i;
86988 switch( pOp->opcode ){
86989 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
86990 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
86991 case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break;
86992 case OP_Divide: {
86993 if( iA==0 ) goto arithmetic_result_is_null;
86994 if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
86995 iB /= iA;
86996 break;
86997 }
86998 default: {
86999 if( iA==0 ) goto arithmetic_result_is_null;
87000 if( iA==-1 ) iA = 1;
87001 iB %= iA;
87002 break;
87003 }
87004 }
87005 pOut->u.i = iB;
87006 MemSetTypeFlag(pOut, MEM_Int);
87007 }else if( (flags & MEM_Null)!=0 ){
87008 goto arithmetic_result_is_null;
87009 }else{
87010fp_math:
87011 rA = sqlite3VdbeRealValue(pIn1);
87012 rB = sqlite3VdbeRealValue(pIn2);
87013 switch( pOp->opcode ){
87014 case OP_Add: rB += rA; break;
87015 case OP_Subtract: rB -= rA; break;
87016 case OP_Multiply: rB *= rA; break;
87017 case OP_Divide: {
87018 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
87019 if( rA==(double)0 ) goto arithmetic_result_is_null;
87020 rB /= rA;
87021 break;
87022 }
87023 default: {
87024 iA = sqlite3VdbeIntValue(pIn1);
87025 iB = sqlite3VdbeIntValue(pIn2);
87026 if( iA==0 ) goto arithmetic_result_is_null;
87027 if( iA==-1 ) iA = 1;
87028 rB = (double)(iB % iA);
87029 break;
87030 }
87031 }
87032#ifdef SQLITE_OMIT_FLOATING_POINT
87033 pOut->u.i = rB;
87034 MemSetTypeFlag(pOut, MEM_Int);
87035#else
87036 if( sqlite3IsNaN(rB) ){
87037 goto arithmetic_result_is_null;
87038 }
87039 pOut->u.r = rB;
87040 MemSetTypeFlag(pOut, MEM_Real);
87041#endif
87042 }
87043 break;
87044
87045arithmetic_result_is_null:
87047 break;
87048}
87049
87050/* Opcode: CollSeq P1 * * P4
87051**
87052** P4 is a pointer to a CollSeq object. If the next call to a user function
87053** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
87054** be returned. This is used by the built-in min(), max() and nullif()
87055** functions.
87056**
87057** If P1 is not zero, then it is a register that a subsequent min() or
87058** max() aggregate will set to 1 if the current row is not the minimum or
87059** maximum. The P1 register is initialized to 0 by this instruction.
87060**
87061** The interface used by the implementation of the aforementioned functions
87062** to retrieve the collation sequence set by this opcode is not available
87063** publicly. Only built-in functions have access to this feature.
87064*/
87065case OP_CollSeq: {
87066 assert( pOp->p4type==P4_COLLSEQ );
87067 if( pOp->p1 ){
87068 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
87069 }
87070 break;
87071}
87072
87073/* Opcode: BitAnd P1 P2 P3 * *
87074** Synopsis: r[P3]=r[P1]&r[P2]
87075**
87076** Take the bit-wise AND of the values in register P1 and P2 and
87077** store the result in register P3.
87078** If either input is NULL, the result is NULL.
87079*/
87080/* Opcode: BitOr P1 P2 P3 * *
87081** Synopsis: r[P3]=r[P1]|r[P2]
87082**
87083** Take the bit-wise OR of the values in register P1 and P2 and
87084** store the result in register P3.
87085** If either input is NULL, the result is NULL.
87086*/
87087/* Opcode: ShiftLeft P1 P2 P3 * *
87088** Synopsis: r[P3]=r[P2]<<r[P1]
87089**
87090** Shift the integer value in register P2 to the left by the
87091** number of bits specified by the integer in register P1.
87092** Store the result in register P3.
87093** If either input is NULL, the result is NULL.
87094*/
87095/* Opcode: ShiftRight P1 P2 P3 * *
87096** Synopsis: r[P3]=r[P2]>>r[P1]
87097**
87098** Shift the integer value in register P2 to the right by the
87099** number of bits specified by the integer in register P1.
87100** Store the result in register P3.
87101** If either input is NULL, the result is NULL.
87102*/
87103case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
87104case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
87105case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
87106case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
87107 i64 iA;
87108 u64 uA;
87109 i64 iB;
87110 u8 op;
87111
87112 pIn1 = &aMem[pOp->p1];
87113 pIn2 = &aMem[pOp->p2];
87114 pOut = &aMem[pOp->p3];
87115 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
87117 break;
87118 }
87119 iA = sqlite3VdbeIntValue(pIn2);
87120 iB = sqlite3VdbeIntValue(pIn1);
87121 op = pOp->opcode;
87122 if( op==OP_BitAnd ){
87123 iA &= iB;
87124 }else if( op==OP_BitOr ){
87125 iA |= iB;
87126 }else if( iB!=0 ){
87127 assert( op==OP_ShiftRight || op==OP_ShiftLeft );
87128
87129 /* If shifting by a negative amount, shift in the other direction */
87130 if( iB<0 ){
87131 assert( OP_ShiftRight==OP_ShiftLeft+1 );
87132 op = 2*OP_ShiftLeft + 1 - op;
87133 iB = iB>(-64) ? -iB : 64;
87134 }
87135
87136 if( iB>=64 ){
87137 iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
87138 }else{
87139 memcpy(&uA, &iA, sizeof(uA));
87140 if( op==OP_ShiftLeft ){
87141 uA <<= iB;
87142 }else{
87143 uA >>= iB;
87144 /* Sign-extend on a right shift of a negative number */
87145 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
87146 }
87147 memcpy(&iA, &uA, sizeof(iA));
87148 }
87149 }
87150 pOut->u.i = iA;
87151 MemSetTypeFlag(pOut, MEM_Int);
87152 break;
87153}
87154
87155/* Opcode: AddImm P1 P2 * * *
87156** Synopsis: r[P1]=r[P1]+P2
87157**
87158** Add the constant P2 to the value in register P1.
87159** The result is always an integer.
87160**
87161** To force any register to be an integer, just add 0.
87162*/
87163case OP_AddImm: { /* in1 */
87164 pIn1 = &aMem[pOp->p1];
87165 memAboutToChange(p, pIn1);
87167 pIn1->u.i += pOp->p2;
87168 break;
87169}
87170
87171/* Opcode: MustBeInt P1 P2 * * *
87172**
87173** Force the value in register P1 to be an integer. If the value
87174** in P1 is not an integer and cannot be converted into an integer
87175** without data loss, then jump immediately to P2, or if P2==0
87176** raise an SQLITE_MISMATCH exception.
87177*/
87178case OP_MustBeInt: { /* jump, in1 */
87179 pIn1 = &aMem[pOp->p1];
87180 if( (pIn1->flags & MEM_Int)==0 ){
87181 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
87182 if( (pIn1->flags & MEM_Int)==0 ){
87183 VdbeBranchTaken(1, 2);
87184 if( pOp->p2==0 ){
87185 rc = SQLITE_MISMATCH;
87186 goto abort_due_to_error;
87187 }else{
87188 goto jump_to_p2;
87189 }
87190 }
87191 }
87192 VdbeBranchTaken(0, 2);
87193 MemSetTypeFlag(pIn1, MEM_Int);
87194 break;
87195}
87196
87197#ifndef SQLITE_OMIT_FLOATING_POINT
87198/* Opcode: RealAffinity P1 * * * *
87199**
87200** If register P1 holds an integer convert it to a real value.
87201**
87202** This opcode is used when extracting information from a column that
87203** has REAL affinity. Such column values may still be stored as
87204** integers, for space efficiency, but after extraction we want them
87205** to have only a real value.
87206*/
87207case OP_RealAffinity: { /* in1 */
87208 pIn1 = &aMem[pOp->p1];
87209 if( pIn1->flags & (MEM_Int|MEM_IntReal) ){
87210 testcase( pIn1->flags & MEM_Int );
87211 testcase( pIn1->flags & MEM_IntReal );
87213 REGISTER_TRACE(pOp->p1, pIn1);
87214 }
87215 break;
87216}
87217#endif
87218
87219#ifndef SQLITE_OMIT_CAST
87220/* Opcode: Cast P1 P2 * * *
87221** Synopsis: affinity(r[P1])
87222**
87223** Force the value in register P1 to be the type defined by P2.
87224**
87225** <ul>
87226** <li> P2=='A' &rarr; BLOB
87227** <li> P2=='B' &rarr; TEXT
87228** <li> P2=='C' &rarr; NUMERIC
87229** <li> P2=='D' &rarr; INTEGER
87230** <li> P2=='E' &rarr; REAL
87231** </ul>
87232**
87233** A NULL value is not changed by this routine. It remains NULL.
87234*/
87235case OP_Cast: { /* in1 */
87236 assert( pOp->p2>=SQLITE_AFF_BLOB && pOp->p2<=SQLITE_AFF_REAL );
87237 testcase( pOp->p2==SQLITE_AFF_TEXT );
87238 testcase( pOp->p2==SQLITE_AFF_BLOB );
87241 testcase( pOp->p2==SQLITE_AFF_REAL );
87242 pIn1 = &aMem[pOp->p1];
87243 memAboutToChange(p, pIn1);
87244 rc = ExpandBlob(pIn1);
87245 if( rc ) goto abort_due_to_error;
87246 rc = sqlite3VdbeMemCast(pIn1, pOp->p2, encoding);
87247 if( rc ) goto abort_due_to_error;
87248 UPDATE_MAX_BLOBSIZE(pIn1);
87249 REGISTER_TRACE(pOp->p1, pIn1);
87250 break;
87251}
87252#endif /* SQLITE_OMIT_CAST */
87253
87254/* Opcode: Eq P1 P2 P3 P4 P5
87255** Synopsis: IF r[P3]==r[P1]
87256**
87257** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
87258** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5, then
87259** store the result of comparison in register P2.
87260**
87261** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
87262** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
87263** to coerce both inputs according to this affinity before the
87264** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
87265** affinity is used. Note that the affinity conversions are stored
87266** back into the input registers P1 and P3. So this opcode can cause
87267** persistent changes to registers P1 and P3.
87268**
87269** Once any conversions have taken place, and neither value is NULL,
87270** the values are compared. If both values are blobs then memcmp() is
87271** used to determine the results of the comparison. If both values
87272** are text, then the appropriate collating function specified in
87273** P4 is used to do the comparison. If P4 is not specified then
87274** memcmp() is used to compare text string. If both values are
87275** numeric, then a numeric comparison is used. If the two values
87276** are of different types, then numbers are considered less than
87277** strings and strings are considered less than blobs.
87278**
87279** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
87280** true or false and is never NULL. If both operands are NULL then the result
87281** of comparison is true. If either operand is NULL then the result is false.
87282** If neither operand is NULL the result is the same as it would be if
87283** the SQLITE_NULLEQ flag were omitted from P5.
87284**
87285** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
87286** content of r[P2] is only changed if the new value is NULL or 0 (false).
87287** In other words, a prior r[P2] value will not be overwritten by 1 (true).
87288*/
87289/* Opcode: Ne P1 P2 P3 P4 P5
87290** Synopsis: IF r[P3]!=r[P1]
87291**
87292** This works just like the Eq opcode except that the jump is taken if
87293** the operands in registers P1 and P3 are not equal. See the Eq opcode for
87294** additional information.
87295**
87296** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
87297** content of r[P2] is only changed if the new value is NULL or 1 (true).
87298** In other words, a prior r[P2] value will not be overwritten by 0 (false).
87299*/
87300/* Opcode: Lt P1 P2 P3 P4 P5
87301** Synopsis: IF r[P3]<r[P1]
87302**
87303** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
87304** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5 store
87305** the result of comparison (0 or 1 or NULL) into register P2.
87306**
87307** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
87308** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
87309** bit is clear then fall through if either operand is NULL.
87310**
87311** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
87312** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
87313** to coerce both inputs according to this affinity before the
87314** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
87315** affinity is used. Note that the affinity conversions are stored
87316** back into the input registers P1 and P3. So this opcode can cause
87317** persistent changes to registers P1 and P3.
87318**
87319** Once any conversions have taken place, and neither value is NULL,
87320** the values are compared. If both values are blobs then memcmp() is
87321** used to determine the results of the comparison. If both values
87322** are text, then the appropriate collating function specified in
87323** P4 is used to do the comparison. If P4 is not specified then
87324** memcmp() is used to compare text string. If both values are
87325** numeric, then a numeric comparison is used. If the two values
87326** are of different types, then numbers are considered less than
87327** strings and strings are considered less than blobs.
87328*/
87329/* Opcode: Le P1 P2 P3 P4 P5
87330** Synopsis: IF r[P3]<=r[P1]
87331**
87332** This works just like the Lt opcode except that the jump is taken if
87333** the content of register P3 is less than or equal to the content of
87334** register P1. See the Lt opcode for additional information.
87335*/
87336/* Opcode: Gt P1 P2 P3 P4 P5
87337** Synopsis: IF r[P3]>r[P1]
87338**
87339** This works just like the Lt opcode except that the jump is taken if
87340** the content of register P3 is greater than the content of
87341** register P1. See the Lt opcode for additional information.
87342*/
87343/* Opcode: Ge P1 P2 P3 P4 P5
87344** Synopsis: IF r[P3]>=r[P1]
87345**
87346** This works just like the Lt opcode except that the jump is taken if
87347** the content of register P3 is greater than or equal to the content of
87348** register P1. See the Lt opcode for additional information.
87349*/
87350case OP_Eq: /* same as TK_EQ, jump, in1, in3 */
87351case OP_Ne: /* same as TK_NE, jump, in1, in3 */
87352case OP_Lt: /* same as TK_LT, jump, in1, in3 */
87353case OP_Le: /* same as TK_LE, jump, in1, in3 */
87354case OP_Gt: /* same as TK_GT, jump, in1, in3 */
87355case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
87356 int res, res2; /* Result of the comparison of pIn1 against pIn3 */
87357 char affinity; /* Affinity to use for comparison */
87358 u16 flags1; /* Copy of initial value of pIn1->flags */
87359 u16 flags3; /* Copy of initial value of pIn3->flags */
87360
87361 pIn1 = &aMem[pOp->p1];
87362 pIn3 = &aMem[pOp->p3];
87363 flags1 = pIn1->flags;
87364 flags3 = pIn3->flags;
87365 if( (flags1 | flags3)&MEM_Null ){
87366 /* One or both operands are NULL */
87367 if( pOp->p5 & SQLITE_NULLEQ ){
87368 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
87369 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
87370 ** or not both operands are null.
87371 */
87372 assert( (flags1 & MEM_Cleared)==0 );
87373 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
87374 testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
87375 if( (flags1&flags3&MEM_Null)!=0
87376 && (flags3&MEM_Cleared)==0
87377 ){
87378 res = 0; /* Operands are equal */
87379 }else{
87380 res = ((flags3 & MEM_Null) ? -1 : +1); /* Operands are not equal */
87381 }
87382 }else{
87383 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
87384 ** then the result is always NULL.
87385 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
87386 */
87387 if( pOp->p5 & SQLITE_STOREP2 ){
87388 pOut = &aMem[pOp->p2];
87389 iCompare = 1; /* Operands are not equal */
87390 memAboutToChange(p, pOut);
87391 MemSetTypeFlag(pOut, MEM_Null);
87392 REGISTER_TRACE(pOp->p2, pOut);
87393 }else{
87394 VdbeBranchTaken(2,3);
87395 if( pOp->p5 & SQLITE_JUMPIFNULL ){
87396 goto jump_to_p2;
87397 }
87398 }
87399 break;
87400 }
87401 }else{
87402 /* Neither operand is NULL. Do a comparison. */
87403 affinity = pOp->p5 & SQLITE_AFF_MASK;
87404 if( affinity>=SQLITE_AFF_NUMERIC ){
87405 if( (flags1 | flags3)&MEM_Str ){
87406 if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
87407 applyNumericAffinity(pIn1,0);
87408 testcase( flags3==pIn3->flags );
87409 flags3 = pIn3->flags;
87410 }
87411 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
87412 applyNumericAffinity(pIn3,0);
87413 }
87414 }
87415 /* Handle the common case of integer comparison here, as an
87416 ** optimization, to avoid a call to sqlite3MemCompare() */
87417 if( (pIn1->flags & pIn3->flags & MEM_Int)!=0 ){
87418 if( pIn3->u.i > pIn1->u.i ){ res = +1; goto compare_op; }
87419 if( pIn3->u.i < pIn1->u.i ){ res = -1; goto compare_op; }
87420 res = 0;
87421 goto compare_op;
87422 }
87423 }else if( affinity==SQLITE_AFF_TEXT ){
87424 if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
87425 testcase( pIn1->flags & MEM_Int );
87426 testcase( pIn1->flags & MEM_Real );
87427 testcase( pIn1->flags & MEM_IntReal );
87428 sqlite3VdbeMemStringify(pIn1, encoding, 1);
87429 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
87430 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
87431 if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
87432 }
87433 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
87434 testcase( pIn3->flags & MEM_Int );
87435 testcase( pIn3->flags & MEM_Real );
87436 testcase( pIn3->flags & MEM_IntReal );
87437 sqlite3VdbeMemStringify(pIn3, encoding, 1);
87438 testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) );
87439 flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask);
87440 }
87441 }
87442 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
87443 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
87444 }
87445compare_op:
87446 /* At this point, res is negative, zero, or positive if reg[P1] is
87447 ** less than, equal to, or greater than reg[P3], respectively. Compute
87448 ** the answer to this operator in res2, depending on what the comparison
87449 ** operator actually is. The next block of code depends on the fact
87450 ** that the 6 comparison operators are consecutive integers in this
87451 ** order: NE, EQ, GT, LE, LT, GE */
87452 assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
87453 assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
87454 if( res<0 ){ /* ne, eq, gt, le, lt, ge */
87455 static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 };
87456 res2 = aLTb[pOp->opcode - OP_Ne];
87457 }else if( res==0 ){
87458 static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 };
87459 res2 = aEQb[pOp->opcode - OP_Ne];
87460 }else{
87461 static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
87462 res2 = aGTb[pOp->opcode - OP_Ne];
87463 }
87464
87465 /* Undo any changes made by applyAffinity() to the input registers. */
87466 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
87467 pIn3->flags = flags3;
87468 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
87469 pIn1->flags = flags1;
87470
87471 if( pOp->p5 & SQLITE_STOREP2 ){
87472 pOut = &aMem[pOp->p2];
87473 iCompare = res;
87474 if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
87475 /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
87476 ** and prevents OP_Ne from overwriting NULL with 0. This flag
87477 ** is only used in contexts where either:
87478 ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
87479 ** (2) op==OP_Ne && (r[P2]==NULL || r[P2]==1)
87480 ** Therefore it is not necessary to check the content of r[P2] for
87481 ** NULL. */
87482 assert( pOp->opcode==OP_Ne || pOp->opcode==OP_Eq );
87483 assert( res2==0 || res2==1 );
87484 testcase( res2==0 && pOp->opcode==OP_Eq );
87485 testcase( res2==1 && pOp->opcode==OP_Eq );
87486 testcase( res2==0 && pOp->opcode==OP_Ne );
87487 testcase( res2==1 && pOp->opcode==OP_Ne );
87488 if( (pOp->opcode==OP_Eq)==res2 ) break;
87489 }
87490 memAboutToChange(p, pOut);
87491 MemSetTypeFlag(pOut, MEM_Int);
87492 pOut->u.i = res2;
87493 REGISTER_TRACE(pOp->p2, pOut);
87494 }else{
87495 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
87496 if( res2 ){
87497 goto jump_to_p2;
87498 }
87499 }
87500 break;
87501}
87502
87503/* Opcode: ElseNotEq * P2 * * *
87504**
87505** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
87506** can be zero or more OP_ReleaseReg opcodes intervening, but no other
87507** opcodes are allowed to occur between this instruction and the previous
87508** OP_Lt or OP_Gt. Furthermore, the prior OP_Lt or OP_Gt must have the
87509** SQLITE_STOREP2 bit set in the P5 field.
87510**
87511** If result of an OP_Eq comparison on the same two operands as the
87512** prior OP_Lt or OP_Gt would have been NULL or false (0), then then
87513** jump to P2. If the result of an OP_Eq comparison on the two previous
87514** operands would have been true (1), then fall through.
87515*/
87516case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */
87517
87518#ifdef SQLITE_DEBUG
87519 /* Verify the preconditions of this opcode - that it follows an OP_Lt or
87520 ** OP_Gt with the SQLITE_STOREP2 flag set, with zero or more intervening
87521 ** OP_ReleaseReg opcodes */
87522 int iAddr;
87523 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
87524 if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
87525 assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
87526 assert( aOp[iAddr].p5 & SQLITE_STOREP2 );
87527 break;
87528 }
87529#endif /* SQLITE_DEBUG */
87530 VdbeBranchTaken(iCompare!=0, 2);
87531 if( iCompare!=0 ) goto jump_to_p2;
87532 break;
87533}
87534
87535
87536/* Opcode: Permutation * * * P4 *
87537**
87538** Set the permutation used by the OP_Compare operator in the next
87539** instruction. The permutation is stored in the P4 operand.
87540**
87541** The permutation is only valid until the next OP_Compare that has
87542** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
87543** occur immediately prior to the OP_Compare.
87544**
87545** The first integer in the P4 integer array is the length of the array
87546** and does not become part of the permutation.
87547*/
87548case OP_Permutation: {
87549 assert( pOp->p4type==P4_INTARRAY );
87550 assert( pOp->p4.ai );
87551 assert( pOp[1].opcode==OP_Compare );
87552 assert( pOp[1].p5 & OPFLAG_PERMUTE );
87553 break;
87554}
87555
87556/* Opcode: Compare P1 P2 P3 P4 P5
87557** Synopsis: r[P1@P3] <-> r[P2@P3]
87558**
87559** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
87560** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
87561** the comparison for use by the next OP_Jump instruct.
87562**
87563** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is
87564** determined by the most recent OP_Permutation operator. If the
87565** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
87566** order.
87567**
87568** P4 is a KeyInfo structure that defines collating sequences and sort
87569** orders for the comparison. The permutation applies to registers
87570** only. The KeyInfo elements are used sequentially.
87571**
87572** The comparison is a sort comparison, so NULLs compare equal,
87573** NULLs are less than numbers, numbers are less than strings,
87574** and strings are less than blobs.
87575*/
87576case OP_Compare: {
87577 int n;
87578 int i;
87579 int p1;
87580 int p2;
87581 const KeyInfo *pKeyInfo;
87582 u32 idx;
87583 CollSeq *pColl; /* Collating sequence to use on this term */
87584 int bRev; /* True for DESCENDING sort order */
87585 u32 *aPermute; /* The permutation */
87586
87587 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
87588 aPermute = 0;
87589 }else{
87590 assert( pOp>aOp );
87591 assert( pOp[-1].opcode==OP_Permutation );
87592 assert( pOp[-1].p4type==P4_INTARRAY );
87593 aPermute = pOp[-1].p4.ai + 1;
87594 assert( aPermute!=0 );
87595 }
87596 n = pOp->p3;
87597 pKeyInfo = pOp->p4.pKeyInfo;
87598 assert( n>0 );
87599 assert( pKeyInfo!=0 );
87600 p1 = pOp->p1;
87601 p2 = pOp->p2;
87602#ifdef SQLITE_DEBUG
87603 if( aPermute ){
87604 int k, mx = 0;
87605 for(k=0; k<n; k++) if( aPermute[k]>(u32)mx ) mx = aPermute[k];
87606 assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
87607 assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
87608 }else{
87609 assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
87610 assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
87611 }
87612#endif /* SQLITE_DEBUG */
87613 for(i=0; i<n; i++){
87614 idx = aPermute ? aPermute[i] : (u32)i;
87615 assert( memIsValid(&aMem[p1+idx]) );
87616 assert( memIsValid(&aMem[p2+idx]) );
87617 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
87618 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
87619 assert( i<pKeyInfo->nKeyField );
87620 pColl = pKeyInfo->aColl[i];
87621 bRev = (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC);
87622 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
87623 if( iCompare ){
87624 if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
87625 && ((aMem[p1+idx].flags & MEM_Null) || (aMem[p2+idx].flags & MEM_Null))
87626 ){
87627 iCompare = -iCompare;
87628 }
87629 if( bRev ) iCompare = -iCompare;
87630 break;
87631 }
87632 }
87633 break;
87634}
87635
87636/* Opcode: Jump P1 P2 P3 * *
87637**
87638** Jump to the instruction at address P1, P2, or P3 depending on whether
87639** in the most recent OP_Compare instruction the P1 vector was less than
87640** equal to, or greater than the P2 vector, respectively.
87641*/
87642case OP_Jump: { /* jump */
87643 if( iCompare<0 ){
87644 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
87645 }else if( iCompare==0 ){
87646 VdbeBranchTaken(1,4); pOp = &aOp[pOp->p2 - 1];
87647 }else{
87648 VdbeBranchTaken(2,4); pOp = &aOp[pOp->p3 - 1];
87649 }
87650 break;
87651}
87652
87653/* Opcode: And P1 P2 P3 * *
87654** Synopsis: r[P3]=(r[P1] && r[P2])
87655**
87656** Take the logical AND of the values in registers P1 and P2 and
87657** write the result into register P3.
87658**
87659** If either P1 or P2 is 0 (false) then the result is 0 even if
87660** the other input is NULL. A NULL and true or two NULLs give
87661** a NULL output.
87662*/
87663/* Opcode: Or P1 P2 P3 * *
87664** Synopsis: r[P3]=(r[P1] || r[P2])
87665**
87666** Take the logical OR of the values in register P1 and P2 and
87667** store the answer in register P3.
87668**
87669** If either P1 or P2 is nonzero (true) then the result is 1 (true)
87670** even if the other input is NULL. A NULL and false or two NULLs
87671** give a NULL output.
87672*/
87673case OP_And: /* same as TK_AND, in1, in2, out3 */
87674case OP_Or: { /* same as TK_OR, in1, in2, out3 */
87675 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
87676 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
87677
87678 v1 = sqlite3VdbeBooleanValue(&aMem[pOp->p1], 2);
87679 v2 = sqlite3VdbeBooleanValue(&aMem[pOp->p2], 2);
87680 if( pOp->opcode==OP_And ){
87681 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
87682 v1 = and_logic[v1*3+v2];
87683 }else{
87684 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
87685 v1 = or_logic[v1*3+v2];
87686 }
87687 pOut = &aMem[pOp->p3];
87688 if( v1==2 ){
87689 MemSetTypeFlag(pOut, MEM_Null);
87690 }else{
87691 pOut->u.i = v1;
87692 MemSetTypeFlag(pOut, MEM_Int);
87693 }
87694 break;
87695}
87696
87697/* Opcode: IsTrue P1 P2 P3 P4 *
87698** Synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4
87699**
87700** This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and
87701** IS NOT FALSE operators.
87702**
87703** Interpret the value in register P1 as a boolean value. Store that
87704** boolean (a 0 or 1) in register P2. Or if the value in register P1 is
87705** NULL, then the P3 is stored in register P2. Invert the answer if P4
87706** is 1.
87707**
87708** The logic is summarized like this:
87709**
87710** <ul>
87711** <li> If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE
87712** <li> If P3==1 and P4==1 then r[P2] := r[P1] IS FALSE
87713** <li> If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE
87714** <li> If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE
87715** </ul>
87716*/
87717case OP_IsTrue: { /* in1, out2 */
87718 assert( pOp->p4type==P4_INT32 );
87719 assert( pOp->p4.i==0 || pOp->p4.i==1 );
87720 assert( pOp->p3==0 || pOp->p3==1 );
87721 sqlite3VdbeMemSetInt64(&aMem[pOp->p2],
87722 sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3) ^ pOp->p4.i);
87723 break;
87724}
87725
87726/* Opcode: Not P1 P2 * * *
87727** Synopsis: r[P2]= !r[P1]
87728**
87729** Interpret the value in register P1 as a boolean value. Store the
87730** boolean complement in register P2. If the value in register P1 is
87731** NULL, then a NULL is stored in P2.
87732*/
87733case OP_Not: { /* same as TK_NOT, in1, out2 */
87734 pIn1 = &aMem[pOp->p1];
87735 pOut = &aMem[pOp->p2];
87736 if( (pIn1->flags & MEM_Null)==0 ){
87738 }else{
87740 }
87741 break;
87742}
87743
87744/* Opcode: BitNot P1 P2 * * *
87745** Synopsis: r[P2]= ~r[P1]
87746**
87747** Interpret the content of register P1 as an integer. Store the
87748** ones-complement of the P1 value into register P2. If P1 holds
87749** a NULL then store a NULL in P2.
87750*/
87751case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */
87752 pIn1 = &aMem[pOp->p1];
87753 pOut = &aMem[pOp->p2];
87755 if( (pIn1->flags & MEM_Null)==0 ){
87756 pOut->flags = MEM_Int;
87757 pOut->u.i = ~sqlite3VdbeIntValue(pIn1);
87758 }
87759 break;
87760}
87761
87762/* Opcode: Once P1 P2 * * *
87763**
87764** Fall through to the next instruction the first time this opcode is
87765** encountered on each invocation of the byte-code program. Jump to P2
87766** on the second and all subsequent encounters during the same invocation.
87767**
87768** Top-level programs determine first invocation by comparing the P1
87769** operand against the P1 operand on the OP_Init opcode at the beginning
87770** of the program. If the P1 values differ, then fall through and make
87771** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are
87772** the same then take the jump.
87773**
87774** For subprograms, there is a bitmask in the VdbeFrame that determines
87775** whether or not the jump should be taken. The bitmask is necessary
87776** because the self-altering code trick does not work for recursive
87777** triggers.
87778*/
87779case OP_Once: { /* jump */
87780 u32 iAddr; /* Address of this instruction */
87781 assert( p->aOp[0].opcode==OP_Init );
87782 if( p->pFrame ){
87783 iAddr = (int)(pOp - p->aOp);
87784 if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){
87785 VdbeBranchTaken(1, 2);
87786 goto jump_to_p2;
87787 }
87788 p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7);
87789 }else{
87790 if( p->aOp[0].p1==pOp->p1 ){
87791 VdbeBranchTaken(1, 2);
87792 goto jump_to_p2;
87793 }
87794 }
87795 VdbeBranchTaken(0, 2);
87796 pOp->p1 = p->aOp[0].p1;
87797 break;
87798}
87799
87800/* Opcode: If P1 P2 P3 * *
87801**
87802** Jump to P2 if the value in register P1 is true. The value
87803** is considered true if it is numeric and non-zero. If the value
87804** in P1 is NULL then take the jump if and only if P3 is non-zero.
87805*/
87806case OP_If: { /* jump, in1 */
87807 int c;
87808 c = sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3);
87809 VdbeBranchTaken(c!=0, 2);
87810 if( c ) goto jump_to_p2;
87811 break;
87812}
87813
87814/* Opcode: IfNot P1 P2 P3 * *
87815**
87816** Jump to P2 if the value in register P1 is False. The value
87817** is considered false if it has a numeric value of zero. If the value
87818** in P1 is NULL then take the jump if and only if P3 is non-zero.
87819*/
87820case OP_IfNot: { /* jump, in1 */
87821 int c;
87822 c = !sqlite3VdbeBooleanValue(&aMem[pOp->p1], !pOp->p3);
87823 VdbeBranchTaken(c!=0, 2);
87824 if( c ) goto jump_to_p2;
87825 break;
87826}
87827
87828/* Opcode: IsNull P1 P2 * * *
87829** Synopsis: if r[P1]==NULL goto P2
87830**
87831** Jump to P2 if the value in register P1 is NULL.
87832*/
87833case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
87834 pIn1 = &aMem[pOp->p1];
87835 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
87836 if( (pIn1->flags & MEM_Null)!=0 ){
87837 goto jump_to_p2;
87838 }
87839 break;
87840}
87841
87842/* Opcode: NotNull P1 P2 * * *
87843** Synopsis: if r[P1]!=NULL goto P2
87844**
87845** Jump to P2 if the value in register P1 is not NULL.
87846*/
87847case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
87848 pIn1 = &aMem[pOp->p1];
87849 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
87850 if( (pIn1->flags & MEM_Null)==0 ){
87851 goto jump_to_p2;
87852 }
87853 break;
87854}
87855
87856/* Opcode: IfNullRow P1 P2 P3 * *
87857** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
87858**
87859** Check the cursor P1 to see if it is currently pointing at a NULL row.
87860** If it is, then set register P3 to NULL and jump immediately to P2.
87861** If P1 is not on a NULL row, then fall through without making any
87862** changes.
87863*/
87864case OP_IfNullRow: { /* jump */
87865 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
87866 assert( p->apCsr[pOp->p1]!=0 );
87867 if( p->apCsr[pOp->p1]->nullRow ){
87868 sqlite3VdbeMemSetNull(aMem + pOp->p3);
87869 goto jump_to_p2;
87870 }
87871 break;
87872}
87873
87874#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
87875/* Opcode: Offset P1 P2 P3 * *
87876** Synopsis: r[P3] = sqlite_offset(P1)
87877**
87878** Store in register r[P3] the byte offset into the database file that is the
87879** start of the payload for the record at which that cursor P1 is currently
87880** pointing.
87881**
87882** P2 is the column number for the argument to the sqlite_offset() function.
87883** This opcode does not use P2 itself, but the P2 value is used by the
87884** code generator. The P1, P2, and P3 operands to this opcode are the
87885** same as for OP_Column.
87886**
87887** This opcode is only available if SQLite is compiled with the
87888** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option.
87889*/
87890case OP_Offset: { /* out3 */
87891 VdbeCursor *pC; /* The VDBE cursor */
87892 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
87893 pC = p->apCsr[pOp->p1];
87894 pOut = &p->aMem[pOp->p3];
87895 if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){
87897 }else{
87898 sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor));
87899 }
87900 break;
87901}
87902#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */
87903
87904/* Opcode: Column P1 P2 P3 P4 P5
87905** Synopsis: r[P3]=PX
87906**
87907** Interpret the data that cursor P1 points to as a structure built using
87908** the MakeRecord instruction. (See the MakeRecord opcode for additional
87909** information about the format of the data.) Extract the P2-th column
87910** from this record. If there are less that (P2+1)
87911** values in the record, extract a NULL.
87912**
87913** The value extracted is stored in register P3.
87914**
87915** If the record contains fewer than P2 fields, then extract a NULL. Or,
87916** if the P4 argument is a P4_MEM use the value of the P4 argument as
87917** the result.
87918**
87919** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
87920** the result is guaranteed to only be used as the argument of a length()
87921** or typeof() function, respectively. The loading of large blobs can be
87922** skipped for length() and all content loading can be skipped for typeof().
87923*/
87924case OP_Column: {
87925 u32 p2; /* column number to retrieve */
87926 VdbeCursor *pC; /* The VDBE cursor */
87927 BtCursor *pCrsr; /* The BTree cursor */
87928 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
87929 int len; /* The length of the serialized data for the column */
87930 int i; /* Loop counter */
87931 Mem *pDest; /* Where to write the extracted value */
87932 Mem sMem; /* For storing the record being decoded */
87933 const u8 *zData; /* Part of the record being decoded */
87934 const u8 *zHdr; /* Next unparsed byte of the header */
87935 const u8 *zEndHdr; /* Pointer to first byte after the header */
87936 u64 offset64; /* 64-bit offset */
87937 u32 t; /* A type code from the record header */
87938 Mem *pReg; /* PseudoTable input register */
87939
87940 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
87941 pC = p->apCsr[pOp->p1];
87942 assert( pC!=0 );
87943 p2 = (u32)pOp->p2;
87944
87945 /* If the cursor cache is stale (meaning it is not currently point at
87946 ** the correct row) then bring it up-to-date by doing the necessary
87947 ** B-Tree seek. */
87948 rc = sqlite3VdbeCursorMoveto(&pC, &p2);
87949 if( rc ) goto abort_due_to_error;
87950
87951 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
87952 pDest = &aMem[pOp->p3];
87953 memAboutToChange(p, pDest);
87954 assert( pC!=0 );
87955 assert( p2<(u32)pC->nField );
87956 aOffset = pC->aOffset;
87957 assert( pC->eCurType!=CURTYPE_VTAB );
87958 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
87959 assert( pC->eCurType!=CURTYPE_SORTER );
87960
87961 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
87962 if( pC->nullRow ){
87963 if( pC->eCurType==CURTYPE_PSEUDO ){
87964 /* For the special case of as pseudo-cursor, the seekResult field
87965 ** identifies the register that holds the record */
87966 assert( pC->seekResult>0 );
87967 pReg = &aMem[pC->seekResult];
87968 assert( pReg->flags & MEM_Blob );
87969 assert( memIsValid(pReg) );
87970 pC->payloadSize = pC->szRow = pReg->n;
87971 pC->aRow = (u8*)pReg->z;
87972 }else{
87973 sqlite3VdbeMemSetNull(pDest);
87974 goto op_column_out;
87975 }
87976 }else{
87977 pCrsr = pC->uc.pCursor;
87978 assert( pC->eCurType==CURTYPE_BTREE );
87979 assert( pCrsr );
87980 assert( sqlite3BtreeCursorIsValid(pCrsr) );
87982 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow);
87983 assert( pC->szRow<=pC->payloadSize );
87984 assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */
87985 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
87986 goto too_big;
87987 }
87988 }
87989 pC->cacheStatus = p->cacheCtr;
87990 pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]);
87991 pC->nHdrParsed = 0;
87992
87993
87994 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
87995 /* pC->aRow does not have to hold the entire row, but it does at least
87996 ** need to cover the header of the record. If pC->aRow does not contain
87997 ** the complete header, then set it to zero, forcing the header to be
87998 ** dynamically allocated. */
87999 pC->aRow = 0;
88000 pC->szRow = 0;
88001
88002 /* Make sure a corrupt database has not given us an oversize header.
88003 ** Do this now to avoid an oversize memory allocation.
88004 **
88005 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
88006 ** types use so much data space that there can only be 4096 and 32 of
88007 ** them, respectively. So the maximum header length results from a
88008 ** 3-byte type for each of the maximum of 32768 columns plus three
88009 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
88010 */
88011 if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
88012 goto op_column_corrupt;
88013 }
88014 }else{
88015 /* This is an optimization. By skipping over the first few tests
88016 ** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
88017 ** measurable performance gain.
88018 **
88019 ** This branch is taken even if aOffset[0]==0. Such a record is never
88020 ** generated by SQLite, and could be considered corruption, but we
88021 ** accept it for historical reasons. When aOffset[0]==0, the code this
88022 ** branch jumps to reads past the end of the record, but never more
88023 ** than a few bytes. Even if the record occurs at the end of the page
88024 ** content area, the "page header" comes after the page content and so
88025 ** this overread is harmless. Similar overreads can occur for a corrupt
88026 ** database file.
88027 */
88028 zData = pC->aRow;
88029 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
88030 testcase( aOffset[0]==0 );
88031 goto op_column_read_header;
88032 }
88033 }
88034
88035 /* Make sure at least the first p2+1 entries of the header have been
88036 ** parsed and valid information is in aOffset[] and pC->aType[].
88037 */
88038 if( pC->nHdrParsed<=p2 ){
88039 /* If there is more header available for parsing in the record, try
88040 ** to extract additional fields up through the p2+1-th field
88041 */
88042 if( pC->iHdrOffset<aOffset[0] ){
88043 /* Make sure zData points to enough of the record to cover the header. */
88044 if( pC->aRow==0 ){
88045 memset(&sMem, 0, sizeof(sMem));
88046 rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem);
88047 if( rc!=SQLITE_OK ) goto abort_due_to_error;
88048 zData = (u8*)sMem.z;
88049 }else{
88050 zData = pC->aRow;
88051 }
88052
88053 /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
88054 op_column_read_header:
88055 i = pC->nHdrParsed;
88056 offset64 = aOffset[i];
88057 zHdr = zData + pC->iHdrOffset;
88058 zEndHdr = zData + aOffset[0];
88059 testcase( zHdr>=zEndHdr );
88060 do{
88061 if( (pC->aType[i] = t = zHdr[0])<0x80 ){
88062 zHdr++;
88063 offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
88064 }else{
88065 zHdr += sqlite3GetVarint32(zHdr, &t);
88066 pC->aType[i] = t;
88067 offset64 += sqlite3VdbeSerialTypeLen(t);
88068 }
88069 aOffset[++i] = (u32)(offset64 & 0xffffffff);
88070 }while( (u32)i<=p2 && zHdr<zEndHdr );
88071
88072 /* The record is corrupt if any of the following are true:
88073 ** (1) the bytes of the header extend past the declared header size
88074 ** (2) the entire header was used but not all data was used
88075 ** (3) the end of the data extends beyond the end of the record.
88076 */
88077 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
88078 || (offset64 > pC->payloadSize)
88079 ){
88080 if( aOffset[0]==0 ){
88081 i = 0;
88082 zHdr = zEndHdr;
88083 }else{
88084 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
88085 goto op_column_corrupt;
88086 }
88087 }
88088
88089 pC->nHdrParsed = i;
88090 pC->iHdrOffset = (u32)(zHdr - zData);
88091 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
88092 }else{
88093 t = 0;
88094 }
88095
88096 /* If after trying to extract new entries from the header, nHdrParsed is
88097 ** still not up to p2, that means that the record has fewer than p2
88098 ** columns. So the result will be either the default value or a NULL.
88099 */
88100 if( pC->nHdrParsed<=p2 ){
88101 if( pOp->p4type==P4_MEM ){
88103 }else{
88104 sqlite3VdbeMemSetNull(pDest);
88105 }
88106 goto op_column_out;
88107 }
88108 }else{
88109 t = pC->aType[p2];
88110 }
88111
88112 /* Extract the content for the p2+1-th column. Control can only
88113 ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
88114 ** all valid.
88115 */
88116 assert( p2<pC->nHdrParsed );
88117 assert( rc==SQLITE_OK );
88118 assert( sqlite3VdbeCheckMemInvariants(pDest) );
88119 if( VdbeMemDynamic(pDest) ){
88120 sqlite3VdbeMemSetNull(pDest);
88121 }
88122 assert( t==pC->aType[p2] );
88123 if( pC->szRow>=aOffset[p2+1] ){
88124 /* This is the common case where the desired content fits on the original
88125 ** page - where the content is not on an overflow page */
88126 zData = pC->aRow + aOffset[p2];
88127 if( t<12 ){
88128 sqlite3VdbeSerialGet(zData, t, pDest);
88129 }else{
88130 /* If the column value is a string, we need a persistent value, not
88131 ** a MEM_Ephem value. This branch is a fast short-cut that is equivalent
88132 ** to calling sqlite3VdbeSerialGet() and sqlite3VdbeDeephemeralize().
88133 */
88134 static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term };
88135 pDest->n = len = (t-12)/2;
88136 pDest->enc = encoding;
88137 if( pDest->szMalloc < len+2 ){
88138 pDest->flags = MEM_Null;
88139 if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
88140 }else{
88141 pDest->z = pDest->zMalloc;
88142 }
88143 memcpy(pDest->z, zData, len);
88144 pDest->z[len] = 0;
88145 pDest->z[len+1] = 0;
88146 pDest->flags = aFlag[t&1];
88147 }
88148 }else{
88149 pDest->enc = encoding;
88150 /* This branch happens only when content is on overflow pages */
88151 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
88152 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
88153 || (len = sqlite3VdbeSerialTypeLen(t))==0
88154 ){
88155 /* Content is irrelevant for
88156 ** 1. the typeof() function,
88157 ** 2. the length(X) function if X is a blob, and
88158 ** 3. if the content length is zero.
88159 ** So we might as well use bogus content rather than reading
88160 ** content from disk.
88161 **
88162 ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
88163 ** buffer passed to it, debugging function VdbeMemPrettyPrint() may
88164 ** read more. Use the global constant sqlite3CtypeMap[] as the array,
88165 ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint())
88166 ** and it begins with a bunch of zeros.
88167 */
88169 }else{
88170 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
88171 if( rc!=SQLITE_OK ) goto abort_due_to_error;
88172 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
88173 pDest->flags &= ~MEM_Ephem;
88174 }
88175 }
88176
88177op_column_out:
88178 UPDATE_MAX_BLOBSIZE(pDest);
88179 REGISTER_TRACE(pOp->p3, pDest);
88180 break;
88181
88182op_column_corrupt:
88183 if( aOp[0].p3>0 ){
88184 pOp = &aOp[aOp[0].p3-1];
88185 break;
88186 }else{
88188 goto abort_due_to_error;
88189 }
88190}
88191
88192/* Opcode: Affinity P1 P2 * P4 *
88193** Synopsis: affinity(r[P1@P2])
88194**
88195** Apply affinities to a range of P2 registers starting with P1.
88196**
88197** P4 is a string that is P2 characters long. The N-th character of the
88198** string indicates the column affinity that should be used for the N-th
88199** memory cell in the range.
88200*/
88201case OP_Affinity: {
88202 const char *zAffinity; /* The affinity to be applied */
88203
88204 zAffinity = pOp->p4.z;
88205 assert( zAffinity!=0 );
88206 assert( pOp->p2>0 );
88207 assert( zAffinity[pOp->p2]==0 );
88208 pIn1 = &aMem[pOp->p1];
88209 while( 1 /*exit-by-break*/ ){
88210 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
88211 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
88212 applyAffinity(pIn1, zAffinity[0], encoding);
88213 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
88214 /* When applying REAL affinity, if the result is still an MEM_Int
88215 ** that will fit in 6 bytes, then change the type to MEM_IntReal
88216 ** so that we keep the high-resolution integer value but know that
88217 ** the type really wants to be REAL. */
88218 testcase( pIn1->u.i==140737488355328LL );
88219 testcase( pIn1->u.i==140737488355327LL );
88220 testcase( pIn1->u.i==-140737488355328LL );
88221 testcase( pIn1->u.i==-140737488355329LL );
88222 if( pIn1->u.i<=140737488355327LL && pIn1->u.i>=-140737488355328LL ){
88223 pIn1->flags |= MEM_IntReal;
88224 pIn1->flags &= ~MEM_Int;
88225 }else{
88226 pIn1->u.r = (double)pIn1->u.i;
88227 pIn1->flags |= MEM_Real;
88228 pIn1->flags &= ~MEM_Int;
88229 }
88230 }
88231 REGISTER_TRACE((int)(pIn1-aMem), pIn1);
88232 zAffinity++;
88233 if( zAffinity[0]==0 ) break;
88234 pIn1++;
88235 }
88236 break;
88237}
88238
88239/* Opcode: MakeRecord P1 P2 P3 P4 *
88240** Synopsis: r[P3]=mkrec(r[P1@P2])
88241**
88242** Convert P2 registers beginning with P1 into the [record format]
88243** use as a data record in a database table or as a key
88244** in an index. The OP_Column opcode can decode the record later.
88245**
88246** P4 may be a string that is P2 characters long. The N-th character of the
88247** string indicates the column affinity that should be used for the N-th
88248** field of the index key.
88249**
88250** The mapping from character to affinity is given by the SQLITE_AFF_
88251** macros defined in sqliteInt.h.
88252**
88253** If P4 is NULL then all index fields have the affinity BLOB.
88254**
88255** The meaning of P5 depends on whether or not the SQLITE_ENABLE_NULL_TRIM
88256** compile-time option is enabled:
88257**
88258** * If SQLITE_ENABLE_NULL_TRIM is enabled, then the P5 is the index
88259** of the right-most table that can be null-trimmed.
88260**
88261** * If SQLITE_ENABLE_NULL_TRIM is omitted, then P5 has the value
88262** OPFLAG_NOCHNG_MAGIC if the OP_MakeRecord opcode is allowed to
88263** accept no-change records with serial_type 10. This value is
88264** only used inside an assert() and does not affect the end result.
88265*/
88266case OP_MakeRecord: {
88267 Mem *pRec; /* The new record */
88268 u64 nData; /* Number of bytes of data space */
88269 int nHdr; /* Number of bytes of header space */
88270 i64 nByte; /* Data space required for this record */
88271 i64 nZero; /* Number of zero bytes at the end of the record */
88272 int nVarint; /* Number of bytes in a varint */
88273 u32 serial_type; /* Type field */
88274 Mem *pData0; /* First field to be combined into the record */
88275 Mem *pLast; /* Last field of the record */
88276 int nField; /* Number of fields in the record */
88277 char *zAffinity; /* The affinity string for the record */
88278 int file_format; /* File format to use for encoding */
88279 u32 len; /* Length of a field */
88280 u8 *zHdr; /* Where to write next byte of the header */
88281 u8 *zPayload; /* Where to write next byte of the payload */
88282
88283 /* Assuming the record contains N fields, the record format looks
88284 ** like this:
88285 **
88286 ** ------------------------------------------------------------------------
88287 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
88288 ** ------------------------------------------------------------------------
88289 **
88290 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
88291 ** and so forth.
88292 **
88293 ** Each type field is a varint representing the serial type of the
88294 ** corresponding data element (see sqlite3VdbeSerialType()). The
88295 ** hdr-size field is also a varint which is the offset from the beginning
88296 ** of the record to data0.
88297 */
88298 nData = 0; /* Number of bytes of data space */
88299 nHdr = 0; /* Number of bytes of header space */
88300 nZero = 0; /* Number of zero bytes at the end of the record */
88301 nField = pOp->p1;
88302 zAffinity = pOp->p4.z;
88303 assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 );
88304 pData0 = &aMem[nField];
88305 nField = pOp->p2;
88306 pLast = &pData0[nField-1];
88307 file_format = p->minWriteFileFormat;
88308
88309 /* Identify the output register */
88310 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
88311 pOut = &aMem[pOp->p3];
88312 memAboutToChange(p, pOut);
88313
88314 /* Apply the requested affinity to all inputs
88315 */
88316 assert( pData0<=pLast );
88317 if( zAffinity ){
88318 pRec = pData0;
88319 do{
88320 applyAffinity(pRec, zAffinity[0], encoding);
88321 if( zAffinity[0]==SQLITE_AFF_REAL && (pRec->flags & MEM_Int) ){
88322 pRec->flags |= MEM_IntReal;
88323 pRec->flags &= ~(MEM_Int);
88324 }
88325 REGISTER_TRACE((int)(pRec-aMem), pRec);
88326 zAffinity++;
88327 pRec++;
88328 assert( zAffinity[0]==0 || pRec<=pLast );
88329 }while( zAffinity[0] );
88330 }
88331
88332#ifdef SQLITE_ENABLE_NULL_TRIM
88333 /* NULLs can be safely trimmed from the end of the record, as long as
88334 ** as the schema format is 2 or more and none of the omitted columns
88335 ** have a non-NULL default value. Also, the record must be left with
88336 ** at least one field. If P5>0 then it will be one more than the
88337 ** index of the right-most column with a non-NULL default value */
88338 if( pOp->p5 ){
88339 while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){
88340 pLast--;
88341 nField--;
88342 }
88343 }
88344#endif
88345
88346 /* Loop through the elements that will make up the record to figure
88347 ** out how much space is required for the new record. After this loop,
88348 ** the Mem.uTemp field of each term should hold the serial-type that will
88349 ** be used for that term in the generated record:
88350 **
88351 ** Mem.uTemp value type
88352 ** --------------- ---------------
88353 ** 0 NULL
88354 ** 1 1-byte signed integer
88355 ** 2 2-byte signed integer
88356 ** 3 3-byte signed integer
88357 ** 4 4-byte signed integer
88358 ** 5 6-byte signed integer
88359 ** 6 8-byte signed integer
88360 ** 7 IEEE float
88361 ** 8 Integer constant 0
88362 ** 9 Integer constant 1
88363 ** 10,11 reserved for expansion
88364 ** N>=12 and even BLOB
88365 ** N>=13 and odd text
88366 **
88367 ** The following additional values are computed:
88368 ** nHdr Number of bytes needed for the record header
88369 ** nData Number of bytes of data space needed for the record
88370 ** nZero Zero bytes at the end of the record
88371 */
88372 pRec = pLast;
88373 do{
88374 assert( memIsValid(pRec) );
88375 if( pRec->flags & MEM_Null ){
88376 if( pRec->flags & MEM_Zero ){
88377 /* Values with MEM_Null and MEM_Zero are created by xColumn virtual
88378 ** table methods that never invoke sqlite3_result_xxxxx() while
88379 ** computing an unchanging column value in an UPDATE statement.
88380 ** Give such values a special internal-use-only serial-type of 10
88381 ** so that they can be passed through to xUpdate and have
88382 ** a true sqlite3_value_nochange(). */
88383#ifndef SQLITE_ENABLE_NULL_TRIM
88384 assert( pOp->p5==OPFLAG_NOCHNG_MAGIC || CORRUPT_DB );
88385#endif
88386 pRec->uTemp = 10;
88387 }else{
88388 pRec->uTemp = 0;
88389 }
88390 nHdr++;
88391 }else if( pRec->flags & (MEM_Int|MEM_IntReal) ){
88392 /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
88393 i64 i = pRec->u.i;
88394 u64 uu;
88395 testcase( pRec->flags & MEM_Int );
88396 testcase( pRec->flags & MEM_IntReal );
88397 if( i<0 ){
88398 uu = ~i;
88399 }else{
88400 uu = i;
88401 }
88402 nHdr++;
88403 testcase( uu==127 ); testcase( uu==128 );
88404 testcase( uu==32767 ); testcase( uu==32768 );
88405 testcase( uu==8388607 ); testcase( uu==8388608 );
88406 testcase( uu==2147483647 ); testcase( uu==2147483648 );
88407 testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL );
88408 if( uu<=127 ){
88409 if( (i&1)==i && file_format>=4 ){
88410 pRec->uTemp = 8+(u32)uu;
88411 }else{
88412 nData++;
88413 pRec->uTemp = 1;
88414 }
88415 }else if( uu<=32767 ){
88416 nData += 2;
88417 pRec->uTemp = 2;
88418 }else if( uu<=8388607 ){
88419 nData += 3;
88420 pRec->uTemp = 3;
88421 }else if( uu<=2147483647 ){
88422 nData += 4;
88423 pRec->uTemp = 4;
88424 }else if( uu<=140737488355327LL ){
88425 nData += 6;
88426 pRec->uTemp = 5;
88427 }else{
88428 nData += 8;
88429 if( pRec->flags & MEM_IntReal ){
88430 /* If the value is IntReal and is going to take up 8 bytes to store
88431 ** as an integer, then we might as well make it an 8-byte floating
88432 ** point value */
88433 pRec->u.r = (double)pRec->u.i;
88434 pRec->flags &= ~MEM_IntReal;
88435 pRec->flags |= MEM_Real;
88436 pRec->uTemp = 7;
88437 }else{
88438 pRec->uTemp = 6;
88439 }
88440 }
88441 }else if( pRec->flags & MEM_Real ){
88442 nHdr++;
88443 nData += 8;
88444 pRec->uTemp = 7;
88445 }else{
88446 assert( db->mallocFailed || pRec->flags&(MEM_Str|MEM_Blob) );
88447 assert( pRec->n>=0 );
88448 len = (u32)pRec->n;
88449 serial_type = (len*2) + 12 + ((pRec->flags & MEM_Str)!=0);
88450 if( pRec->flags & MEM_Zero ){
88451 serial_type += pRec->u.nZero*2;
88452 if( nData ){
88453 if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem;
88454 len += pRec->u.nZero;
88455 }else{
88456 nZero += pRec->u.nZero;
88457 }
88458 }
88459 nData += len;
88460 nHdr += sqlite3VarintLen(serial_type);
88461 pRec->uTemp = serial_type;
88462 }
88463 if( pRec==pData0 ) break;
88464 pRec--;
88465 }while(1);
88466
88467 /* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
88468 ** which determines the total number of bytes in the header. The varint
88469 ** value is the size of the header in bytes including the size varint
88470 ** itself. */
88471 testcase( nHdr==126 );
88472 testcase( nHdr==127 );
88473 if( nHdr<=126 ){
88474 /* The common case */
88475 nHdr += 1;
88476 }else{
88477 /* Rare case of a really large header */
88478 nVarint = sqlite3VarintLen(nHdr);
88479 nHdr += nVarint;
88480 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
88481 }
88482 nByte = nHdr+nData;
88483
88484 /* Make sure the output register has a buffer large enough to store
88485 ** the new record. The output register (pOp->p3) is not allowed to
88486 ** be one of the input registers (because the following call to
88487 ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used).
88488 */
88489 if( nByte+nZero<=pOut->szMalloc ){
88490 /* The output register is already large enough to hold the record.
88491 ** No error checks or buffer enlargement is required */
88492 pOut->z = pOut->zMalloc;
88493 }else{
88494 /* Need to make sure that the output is not too big and then enlarge
88495 ** the output register to hold the full result */
88496 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
88497 goto too_big;
88498 }
88499 if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){
88500 goto no_mem;
88501 }
88502 }
88503 pOut->n = (int)nByte;
88504 pOut->flags = MEM_Blob;
88505 if( nZero ){
88506 pOut->u.nZero = nZero;
88507 pOut->flags |= MEM_Zero;
88508 }
88509 UPDATE_MAX_BLOBSIZE(pOut);
88510 zHdr = (u8 *)pOut->z;
88511 zPayload = zHdr + nHdr;
88512
88513 /* Write the record */
88514 zHdr += putVarint32(zHdr, nHdr);
88515 assert( pData0<=pLast );
88516 pRec = pData0;
88517 do{
88518 serial_type = pRec->uTemp;
88519 /* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
88520 ** additional varints, one per column. */
88521 zHdr += putVarint32(zHdr, serial_type); /* serial type */
88522 /* EVIDENCE-OF: R-64536-51728 The values for each column in the record
88523 ** immediately follow the header. */
88524 zPayload += sqlite3VdbeSerialPut(zPayload, pRec, serial_type); /* content */
88525 }while( (++pRec)<=pLast );
88526 assert( nHdr==(int)(zHdr - (u8*)pOut->z) );
88527 assert( nByte==(int)(zPayload - (u8*)pOut->z) );
88528
88529 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
88530 REGISTER_TRACE(pOp->p3, pOut);
88531 break;
88532}
88533
88534/* Opcode: Count P1 P2 p3 * *
88535** Synopsis: r[P2]=count()
88536**
88537** Store the number of entries (an integer value) in the table or index
88538** opened by cursor P1 in register P2.
88539**
88540** If P3==0, then an exact count is obtained, which involves visiting
88541** every btree page of the table. But if P3 is non-zero, an estimate
88542** is returned based on the current cursor position.
88543*/
88544case OP_Count: { /* out2 */
88545 i64 nEntry;
88546 BtCursor *pCrsr;
88547
88548 assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE );
88549 pCrsr = p->apCsr[pOp->p1]->uc.pCursor;
88550 assert( pCrsr );
88551 if( pOp->p3 ){
88552 nEntry = sqlite3BtreeRowCountEst(pCrsr);
88553 }else{
88554 nEntry = 0; /* Not needed. Only used to silence a warning. */
88555 rc = sqlite3BtreeCount(db, pCrsr, &nEntry);
88556 if( rc ) goto abort_due_to_error;
88557 }
88558 pOut = out2Prerelease(p, pOp);
88559 pOut->u.i = nEntry;
88560 goto check_for_interrupt;
88561}
88562
88563/* Opcode: Savepoint P1 * * P4 *
88564**
88565** Open, release or rollback the savepoint named by parameter P4, depending
88566** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
88567** To release (commit) an existing savepoint set P1==1 (SAVEPOINT_RELEASE).
88568** To rollback an existing savepoint set P1==2 (SAVEPOINT_ROLLBACK).
88569*/
88570case OP_Savepoint: {
88571 int p1; /* Value of P1 operand */
88572 char *zName; /* Name of savepoint */
88573 int nName;
88574 Savepoint *pNew;
88575 Savepoint *pSavepoint;
88576 Savepoint *pTmp;
88577 int iSavepoint;
88578 int ii;
88579
88580 p1 = pOp->p1;
88581 zName = pOp->p4.z;
88582
88583 /* Assert that the p1 parameter is valid. Also that if there is no open
88584 ** transaction, then there cannot be any savepoints.
88585 */
88586 assert( db->pSavepoint==0 || db->autoCommit==0 );
88588 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
88589 assert( checkSavepointCount(db) );
88590 assert( p->bIsReader );
88591
88592 if( p1==SAVEPOINT_BEGIN ){
88593 if( db->nVdbeWrite>0 ){
88594 /* A new savepoint cannot be created if there are active write
88595 ** statements (i.e. open read/write incremental blob handles).
88596 */
88597 sqlite3VdbeError(p, "cannot open savepoint - SQL statements in progress");
88598 rc = SQLITE_BUSY;
88599 }else{
88601
88602#ifndef SQLITE_OMIT_VIRTUALTABLE
88603 /* This call is Ok even if this savepoint is actually a transaction
88604 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
88605 ** If this is a transaction savepoint being opened, it is guaranteed
88606 ** that the db->aVTrans[] array is empty. */
88607 assert( db->autoCommit==0 || db->nVTrans==0 );
88609 db->nStatement+db->nSavepoint);
88610 if( rc!=SQLITE_OK ) goto abort_due_to_error;
88611#endif
88612
88613 /* Create a new savepoint structure. */
88614 pNew = sqlite3DbMallocRawNN(db, sizeof(Savepoint)+nName+1);
88615 if( pNew ){
88616 pNew->zName = (char *)&pNew[1];
88617 memcpy(pNew->zName, zName, nName+1);
88618
88619 /* If there is no open transaction, then mark this as a special
88620 ** "transaction savepoint". */
88621 if( db->autoCommit ){
88622 db->autoCommit = 0;
88623 db->isTransactionSavepoint = 1;
88624 }else{
88625 db->nSavepoint++;
88626 }
88627
88628 /* Link the new savepoint into the database handle's list. */
88629 pNew->pNext = db->pSavepoint;
88630 db->pSavepoint = pNew;
88631 pNew->nDeferredCons = db->nDeferredCons;
88633 }
88634 }
88635 }else{
88636 assert( p1==SAVEPOINT_RELEASE || p1==SAVEPOINT_ROLLBACK );
88637 iSavepoint = 0;
88638
88639 /* Find the named savepoint. If there is no such savepoint, then an
88640 ** an error is returned to the user. */
88641 for(
88642 pSavepoint = db->pSavepoint;
88643 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
88644 pSavepoint = pSavepoint->pNext
88645 ){
88646 iSavepoint++;
88647 }
88648 if( !pSavepoint ){
88649 sqlite3VdbeError(p, "no such savepoint: %s", zName);
88650 rc = SQLITE_ERROR;
88651 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
88652 /* It is not possible to release (commit) a savepoint if there are
88653 ** active write statements.
88654 */
88655 sqlite3VdbeError(p, "cannot release savepoint - "
88656 "SQL statements in progress");
88657 rc = SQLITE_BUSY;
88658 }else{
88659
88660 /* Determine whether or not this is a transaction savepoint. If so,
88661 ** and this is a RELEASE command, then the current transaction
88662 ** is committed.
88663 */
88664 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
88665 if( isTransaction && p1==SAVEPOINT_RELEASE ){
88666 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
88667 goto vdbe_return;
88668 }
88669 db->autoCommit = 1;
88670 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
88671 p->pc = (int)(pOp - aOp);
88672 db->autoCommit = 0;
88673 p->rc = rc = SQLITE_BUSY;
88674 goto vdbe_return;
88675 }
88676 rc = p->rc;
88677 if( rc ){
88678 db->autoCommit = 0;
88679 }else{
88680 db->isTransactionSavepoint = 0;
88681 }
88682 }else{
88683 int isSchemaChange;
88684 iSavepoint = db->nSavepoint - iSavepoint - 1;
88685 if( p1==SAVEPOINT_ROLLBACK ){
88686 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
88687 for(ii=0; ii<db->nDb; ii++){
88688 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
88690 isSchemaChange==0);
88691 if( rc!=SQLITE_OK ) goto abort_due_to_error;
88692 }
88693 }else{
88694 assert( p1==SAVEPOINT_RELEASE );
88695 isSchemaChange = 0;
88696 }
88697 for(ii=0; ii<db->nDb; ii++){
88698 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
88699 if( rc!=SQLITE_OK ){
88700 goto abort_due_to_error;
88701 }
88702 }
88703 if( isSchemaChange ){
88707 }
88708 }
88709 if( rc ) goto abort_due_to_error;
88710
88711 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
88712 ** savepoints nested inside of the savepoint being operated on. */
88713 while( db->pSavepoint!=pSavepoint ){
88714 pTmp = db->pSavepoint;
88715 db->pSavepoint = pTmp->pNext;
88716 sqlite3DbFree(db, pTmp);
88717 db->nSavepoint--;
88718 }
88719
88720 /* If it is a RELEASE, then destroy the savepoint being operated on
88721 ** too. If it is a ROLLBACK TO, then set the number of deferred
88722 ** constraint violations present in the database to the value stored
88723 ** when the savepoint was created. */
88724 if( p1==SAVEPOINT_RELEASE ){
88725 assert( pSavepoint==db->pSavepoint );
88726 db->pSavepoint = pSavepoint->pNext;
88727 sqlite3DbFree(db, pSavepoint);
88728 if( !isTransaction ){
88729 db->nSavepoint--;
88730 }
88731 }else{
88732 assert( p1==SAVEPOINT_ROLLBACK );
88733 db->nDeferredCons = pSavepoint->nDeferredCons;
88734 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
88735 }
88736
88737 if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
88738 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
88739 if( rc!=SQLITE_OK ) goto abort_due_to_error;
88740 }
88741 }
88742 }
88743 if( rc ) goto abort_due_to_error;
88744
88745 break;
88746}
88747
88748/* Opcode: AutoCommit P1 P2 * * *
88749**
88750** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
88751** back any currently active btree transactions. If there are any active
88752** VMs (apart from this one), then a ROLLBACK fails. A COMMIT fails if
88753** there are active writing VMs or active VMs that use shared cache.
88754**
88755** This instruction causes the VM to halt.
88756*/
88757case OP_AutoCommit: {
88758 int desiredAutoCommit;
88759 int iRollback;
88760
88761 desiredAutoCommit = pOp->p1;
88762 iRollback = pOp->p2;
88763 assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
88764 assert( desiredAutoCommit==1 || iRollback==0 );
88765 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
88766 assert( p->bIsReader );
88767
88768 if( desiredAutoCommit!=db->autoCommit ){
88769 if( iRollback ){
88770 assert( desiredAutoCommit==1 );
88772 db->autoCommit = 1;
88773 }else if( desiredAutoCommit && db->nVdbeWrite>0 ){
88774 /* If this instruction implements a COMMIT and other VMs are writing
88775 ** return an error indicating that the other VMs must complete first.
88776 */
88777 sqlite3VdbeError(p, "cannot commit transaction - "
88778 "SQL statements in progress");
88779 rc = SQLITE_BUSY;
88780 goto abort_due_to_error;
88781 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
88782 goto vdbe_return;
88783 }else{
88784 db->autoCommit = (u8)desiredAutoCommit;
88785 }
88786 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
88787 p->pc = (int)(pOp - aOp);
88788 db->autoCommit = (u8)(1-desiredAutoCommit);
88789 p->rc = rc = SQLITE_BUSY;
88790 goto vdbe_return;
88791 }
88793 if( p->rc==SQLITE_OK ){
88794 rc = SQLITE_DONE;
88795 }else{
88796 rc = SQLITE_ERROR;
88797 }
88798 goto vdbe_return;
88799 }else{
88801 (!desiredAutoCommit)?"cannot start a transaction within a transaction":(
88802 (iRollback)?"cannot rollback - no transaction is active":
88803 "cannot commit - no transaction is active"));
88804
88805 rc = SQLITE_ERROR;
88806 goto abort_due_to_error;
88807 }
88808 /*NOTREACHED*/ assert(0);
88809}
88810
88811/* Opcode: Transaction P1 P2 P3 P4 P5
88812**
88813** Begin a transaction on database P1 if a transaction is not already
88814** active.
88815** If P2 is non-zero, then a write-transaction is started, or if a
88816** read-transaction is already active, it is upgraded to a write-transaction.
88817** If P2 is zero, then a read-transaction is started.
88818**
88819** P1 is the index of the database file on which the transaction is
88820** started. Index 0 is the main database file and index 1 is the
88821** file used for temporary tables. Indices of 2 or more are used for
88822** attached databases.
88823**
88824** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
88825** true (this flag is set if the Vdbe may modify more than one row and may
88826** throw an ABORT exception), a statement transaction may also be opened.
88827** More specifically, a statement transaction is opened iff the database
88828** connection is currently not in autocommit mode, or if there are other
88829** active statements. A statement transaction allows the changes made by this
88830** VDBE to be rolled back after an error without having to roll back the
88831** entire transaction. If no error is encountered, the statement transaction
88832** will automatically commit when the VDBE halts.
88833**
88834** If P5!=0 then this opcode also checks the schema cookie against P3
88835** and the schema generation counter against P4.
88836** The cookie changes its value whenever the database schema changes.
88837** This operation is used to detect when that the cookie has changed
88838** and that the current process needs to reread the schema. If the schema
88839** cookie in P3 differs from the schema cookie in the database header or
88840** if the schema generation counter in P4 differs from the current
88841** generation counter, then an SQLITE_SCHEMA error is raised and execution
88842** halts. The sqlite3_step() wrapper function might then reprepare the
88843** statement and rerun it from the beginning.
88844*/
88845case OP_Transaction: {
88846 Btree *pBt;
88847 int iMeta = 0;
88848
88849 assert( p->bIsReader );
88850 assert( p->readOnly==0 || pOp->p2==0 );
88851 assert( pOp->p1>=0 && pOp->p1<db->nDb );
88852 assert( DbMaskTest(p->btreeMask, pOp->p1) );
88853 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
88854 rc = SQLITE_READONLY;
88855 goto abort_due_to_error;
88856 }
88857 pBt = db->aDb[pOp->p1].pBt;
88858
88859 if( pBt ){
88860 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2, &iMeta);
88863 if( rc!=SQLITE_OK ){
88864 if( (rc&0xff)==SQLITE_BUSY ){
88865 p->pc = (int)(pOp - aOp);
88866 p->rc = rc;
88867 goto vdbe_return;
88868 }
88869 goto abort_due_to_error;
88870 }
88871
88872 if( p->usesStmtJournal
88873 && pOp->p2
88874 && (db->autoCommit==0 || db->nVdbeRead>1)
88875 ){
88876 assert( sqlite3BtreeIsInTrans(pBt) );
88877 if( p->iStatement==0 ){
88878 assert( db->nStatement>=0 && db->nSavepoint>=0 );
88879 db->nStatement++;
88880 p->iStatement = db->nSavepoint + db->nStatement;
88881 }
88882
88884 if( rc==SQLITE_OK ){
88885 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
88886 }
88887
88888 /* Store the current value of the database handles deferred constraint
88889 ** counter. If the statement transaction needs to be rolled back,
88890 ** the value of this counter needs to be restored too. */
88891 p->nStmtDefCons = db->nDeferredCons;
88893 }
88894 }
88895 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
88896 if( pOp->p5
88897 && (iMeta!=pOp->p3
88898 || db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i)
88899 ){
88900 /*
88901 ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
88902 ** version is checked to ensure that the schema has not changed since the
88903 ** SQL statement was prepared.
88904 */
88905 sqlite3DbFree(db, p->zErrMsg);
88906 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
88907 /* If the schema-cookie from the database file matches the cookie
88908 ** stored with the in-memory representation of the schema, do
88909 ** not reload the schema from the database file.
88910 **
88911 ** If virtual-tables are in use, this is not just an optimization.
88912 ** Often, v-tables store their data in other SQLite tables, which
88913 ** are queried from within xNext() and other v-table methods using
88914 ** prepared queries. If such a query is out-of-date, we do not want to
88915 ** discard the database schema, as the user code implementing the
88916 ** v-table would have to be ready for the sqlite3_vtab structure itself
88917 ** to be invalidated whenever sqlite3_step() is called from within
88918 ** a v-table method.
88919 */
88920 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
88921 sqlite3ResetOneSchema(db, pOp->p1);
88922 }
88923 p->expired = 1;
88924 rc = SQLITE_SCHEMA;
88925 }
88926 if( rc ) goto abort_due_to_error;
88927 break;
88928}
88929
88930/* Opcode: ReadCookie P1 P2 P3 * *
88931**
88932** Read cookie number P3 from database P1 and write it into register P2.
88933** P3==1 is the schema version. P3==2 is the database format.
88934** P3==3 is the recommended pager cache size, and so forth. P1==0 is
88935** the main database file and P1==1 is the database file used to store
88936** temporary tables.
88937**
88938** There must be a read-lock on the database (either a transaction
88939** must be started or there must be an open cursor) before
88940** executing this instruction.
88941*/
88942case OP_ReadCookie: { /* out2 */
88943 int iMeta;
88944 int iDb;
88945 int iCookie;
88946
88947 assert( p->bIsReader );
88948 iDb = pOp->p1;
88949 iCookie = pOp->p3;
88950 assert( pOp->p3<SQLITE_N_BTREE_META );
88951 assert( iDb>=0 && iDb<db->nDb );
88952 assert( db->aDb[iDb].pBt!=0 );
88953 assert( DbMaskTest(p->btreeMask, iDb) );
88954
88955 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
88956 pOut = out2Prerelease(p, pOp);
88957 pOut->u.i = iMeta;
88958 break;
88959}
88960
88961/* Opcode: SetCookie P1 P2 P3 * P5
88962**
88963** Write the integer value P3 into cookie number P2 of database P1.
88964** P2==1 is the schema version. P2==2 is the database format.
88965** P2==3 is the recommended pager cache
88966** size, and so forth. P1==0 is the main database file and P1==1 is the
88967** database file used to store temporary tables.
88968**
88969** A transaction must be started before executing this opcode.
88970**
88971** If P2 is the SCHEMA_VERSION cookie (cookie number 1) then the internal
88972** schema version is set to P3-P5. The "PRAGMA schema_version=N" statement
88973** has P5 set to 1, so that the internal schema version will be different
88974** from the database schema version, resulting in a schema reset.
88975*/
88976case OP_SetCookie: {
88977 Db *pDb;
88978
88980 assert( pOp->p2<SQLITE_N_BTREE_META );
88981 assert( pOp->p1>=0 && pOp->p1<db->nDb );
88982 assert( DbMaskTest(p->btreeMask, pOp->p1) );
88983 assert( p->readOnly==0 );
88984 pDb = &db->aDb[pOp->p1];
88985 assert( pDb->pBt!=0 );
88986 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
88987 /* See note about index shifting on OP_ReadCookie */
88988 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
88989 if( pOp->p2==BTREE_SCHEMA_VERSION ){
88990 /* When the schema cookie changes, record the new cookie internally */
88991 pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5;
88993 }else if( pOp->p2==BTREE_FILE_FORMAT ){
88994 /* Record changes in the file format */
88995 pDb->pSchema->file_format = pOp->p3;
88996 }
88997 if( pOp->p1==1 ){
88998 /* Invalidate all prepared statements whenever the TEMP database
88999 ** schema is changed. Ticket #1644 */
89001 p->expired = 0;
89002 }
89003 if( rc ) goto abort_due_to_error;
89004 break;
89005}
89006
89007/* Opcode: OpenRead P1 P2 P3 P4 P5
89008** Synopsis: root=P2 iDb=P3
89009**
89010** Open a read-only cursor for the database table whose root page is
89011** P2 in a database file. The database file is determined by P3.
89012** P3==0 means the main database, P3==1 means the database used for
89013** temporary tables, and P3>1 means used the corresponding attached
89014** database. Give the new cursor an identifier of P1. The P1
89015** values need not be contiguous but all P1 values should be small integers.
89016** It is an error for P1 to be negative.
89017**
89018** Allowed P5 bits:
89019** <ul>
89020** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
89021** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
89022** of OP_SeekLE/OP_IdxLT)
89023** </ul>
89024**
89025** The P4 value may be either an integer (P4_INT32) or a pointer to
89026** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
89027** object, then table being opened must be an [index b-tree] where the
89028** KeyInfo object defines the content and collating
89029** sequence of that index b-tree. Otherwise, if P4 is an integer
89030** value, then the table being opened must be a [table b-tree] with a
89031** number of columns no less than the value of P4.
89032**
89033** See also: OpenWrite, ReopenIdx
89034*/
89035/* Opcode: ReopenIdx P1 P2 P3 P4 P5
89036** Synopsis: root=P2 iDb=P3
89037**
89038** The ReopenIdx opcode works like OP_OpenRead except that it first
89039** checks to see if the cursor on P1 is already open on the same
89040** b-tree and if it is this opcode becomes a no-op. In other words,
89041** if the cursor is already open, do not reopen it.
89042**
89043** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
89044** and with P4 being a P4_KEYINFO object. Furthermore, the P3 value must
89045** be the same as every other ReopenIdx or OpenRead for the same cursor
89046** number.
89047**
89048** Allowed P5 bits:
89049** <ul>
89050** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
89051** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
89052** of OP_SeekLE/OP_IdxLT)
89053** </ul>
89054**
89055** See also: OP_OpenRead, OP_OpenWrite
89056*/
89057/* Opcode: OpenWrite P1 P2 P3 P4 P5
89058** Synopsis: root=P2 iDb=P3
89059**
89060** Open a read/write cursor named P1 on the table or index whose root
89061** page is P2 (or whose root page is held in register P2 if the
89062** OPFLAG_P2ISREG bit is set in P5 - see below).
89063**
89064** The P4 value may be either an integer (P4_INT32) or a pointer to
89065** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
89066** object, then table being opened must be an [index b-tree] where the
89067** KeyInfo object defines the content and collating
89068** sequence of that index b-tree. Otherwise, if P4 is an integer
89069** value, then the table being opened must be a [table b-tree] with a
89070** number of columns no less than the value of P4.
89071**
89072** Allowed P5 bits:
89073** <ul>
89074** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
89075** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
89076** of OP_SeekLE/OP_IdxLT)
89077** <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
89078** and subsequently delete entries in an index btree. This is a
89079** hint to the storage engine that the storage engine is allowed to
89080** ignore. The hint is not used by the official SQLite b*tree storage
89081** engine, but is used by COMDB2.
89082** <li> <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
89083** as the root page, not the value of P2 itself.
89084** </ul>
89085**
89086** This instruction works like OpenRead except that it opens the cursor
89087** in read/write mode.
89088**
89089** See also: OP_OpenRead, OP_ReopenIdx
89090*/
89091case OP_ReopenIdx: {
89092 int nField;
89093 KeyInfo *pKeyInfo;
89094 u32 p2;
89095 int iDb;
89096 int wrFlag;
89097 Btree *pX;
89098 VdbeCursor *pCur;
89099 Db *pDb;
89100
89101 assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
89102 assert( pOp->p4type==P4_KEYINFO );
89103 pCur = p->apCsr[pOp->p1];
89104 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
89105 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
89106 goto open_cursor_set_hints;
89107 }
89108 /* If the cursor is not currently open or is open on a different
89109 ** index, then fall through into OP_OpenRead to force a reopen */
89110case OP_OpenRead:
89111case OP_OpenWrite:
89112
89113 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
89114 assert( p->bIsReader );
89115 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
89116 || p->readOnly==0 );
89117
89118 if( p->expired==1 ){
89120 goto abort_due_to_error;
89121 }
89122
89123 nField = 0;
89124 pKeyInfo = 0;
89125 p2 = (u32)pOp->p2;
89126 iDb = pOp->p3;
89127 assert( iDb>=0 && iDb<db->nDb );
89128 assert( DbMaskTest(p->btreeMask, iDb) );
89129 pDb = &db->aDb[iDb];
89130 pX = pDb->pBt;
89131 assert( pX!=0 );
89132 if( pOp->opcode==OP_OpenWrite ){
89134 wrFlag = BTREE_WRCSR | (pOp->p5 & OPFLAG_FORDELETE);
89135 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
89136 if( pDb->pSchema->file_format < p->minWriteFileFormat ){
89138 }
89139 }else{
89140 wrFlag = 0;
89141 }
89142 if( pOp->p5 & OPFLAG_P2ISREG ){
89143 assert( p2>0 );
89144 assert( p2<=(u32)(p->nMem+1 - p->nCursor) );
89145 assert( pOp->opcode==OP_OpenWrite );
89146 pIn2 = &aMem[p2];
89147 assert( memIsValid(pIn2) );
89148 assert( (pIn2->flags & MEM_Int)!=0 );
89150 p2 = (int)pIn2->u.i;
89151 /* The p2 value always comes from a prior OP_CreateBtree opcode and
89152 ** that opcode will always set the p2 value to 2 or more or else fail.
89153 ** If there were a failure, the prepared statement would have halted
89154 ** before reaching this instruction. */
89155 assert( p2>=2 );
89156 }
89157 if( pOp->p4type==P4_KEYINFO ){
89158 pKeyInfo = pOp->p4.pKeyInfo;
89159 assert( pKeyInfo->enc==ENC(db) );
89160 assert( pKeyInfo->db==db );
89161 nField = pKeyInfo->nAllField;
89162 }else if( pOp->p4type==P4_INT32 ){
89163 nField = pOp->p4.i;
89164 }
89165 assert( pOp->p1>=0 );
89166 assert( nField>=0 );
89167 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
89168 pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE);
89169 if( pCur==0 ) goto no_mem;
89170 pCur->nullRow = 1;
89171 pCur->isOrdered = 1;
89172 pCur->pgnoRoot = p2;
89173#ifdef SQLITE_DEBUG
89174 pCur->wrFlag = wrFlag;
89175#endif
89176 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->uc.pCursor);
89177 pCur->pKeyInfo = pKeyInfo;
89178 /* Set the VdbeCursor.isTable variable. Previous versions of
89179 ** SQLite used to check if the root-page flags were sane at this point
89180 ** and report database corruption if they were not, but this check has
89181 ** since moved into the btree layer. */
89182 pCur->isTable = pOp->p4type!=P4_KEYINFO;
89183
89184open_cursor_set_hints:
89185 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
89186 assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ );
89187 testcase( pOp->p5 & OPFLAG_BULKCSR );
89188 testcase( pOp->p2 & OPFLAG_SEEKEQ );
89190 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
89191 if( rc ) goto abort_due_to_error;
89192 break;
89193}
89194
89195/* Opcode: OpenDup P1 P2 * * *
89196**
89197** Open a new cursor P1 that points to the same ephemeral table as
89198** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
89199** opcode. Only ephemeral cursors may be duplicated.
89200**
89201** Duplicate ephemeral cursors are used for self-joins of materialized views.
89202*/
89203case OP_OpenDup: {
89204 VdbeCursor *pOrig; /* The original cursor to be duplicated */
89205 VdbeCursor *pCx; /* The new cursor */
89206
89207 pOrig = p->apCsr[pOp->p2];
89208 assert( pOrig );
89209 assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
89210
89211 pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
89212 if( pCx==0 ) goto no_mem;
89213 pCx->nullRow = 1;
89214 pCx->isEphemeral = 1;
89215 pCx->pKeyInfo = pOrig->pKeyInfo;
89216 pCx->isTable = pOrig->isTable;
89217 pCx->pgnoRoot = pOrig->pgnoRoot;
89218 pCx->isOrdered = pOrig->isOrdered;
89219 rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
89220 pCx->pKeyInfo, pCx->uc.pCursor);
89221 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
89222 ** opened for a database. Since there is already an open cursor when this
89223 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
89224 assert( rc==SQLITE_OK );
89225 break;
89226}
89227
89228
89229/* Opcode: OpenEphemeral P1 P2 * P4 P5
89230** Synopsis: nColumn=P2
89231**
89232** Open a new cursor P1 to a transient table.
89233** The cursor is always opened read/write even if
89234** the main database is read-only. The ephemeral
89235** table is deleted automatically when the cursor is closed.
89236**
89237** If the cursor P1 is already opened on an ephemeral table, the table
89238** is cleared (all content is erased).
89239**
89240** P2 is the number of columns in the ephemeral table.
89241** The cursor points to a BTree table if P4==0 and to a BTree index
89242** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
89243** that defines the format of keys in the index.
89244**
89245** The P5 parameter can be a mask of the BTREE_* flags defined
89246** in btree.h. These flags control aspects of the operation of
89247** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
89248** added automatically.
89249*/
89250/* Opcode: OpenAutoindex P1 P2 * P4 *
89251** Synopsis: nColumn=P2
89252**
89253** This opcode works the same as OP_OpenEphemeral. It has a
89254** different name to distinguish its use. Tables created using
89255** by this opcode will be used for automatically created transient
89256** indices in joins.
89257*/
89258case OP_OpenAutoindex:
89259case OP_OpenEphemeral: {
89260 VdbeCursor *pCx;
89261 KeyInfo *pKeyInfo;
89262
89263 static const int vfsFlags =
89269 assert( pOp->p1>=0 );
89270 assert( pOp->p2>=0 );
89271 pCx = p->apCsr[pOp->p1];
89272 if( pCx && pCx->pBtx ){
89273 /* If the ephermeral table is already open, erase all existing content
89274 ** so that the table is empty again, rather than creating a new table. */
89275 assert( pCx->isEphemeral );
89276 pCx->seqCount = 0;
89277 pCx->cacheStatus = CACHE_STALE;
89278 rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
89279 }else{
89280 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
89281 if( pCx==0 ) goto no_mem;
89282 pCx->isEphemeral = 1;
89283 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
89285 vfsFlags);
89286 if( rc==SQLITE_OK ){
89287 rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
89288 }
89289 if( rc==SQLITE_OK ){
89290 /* If a transient index is required, create it by calling
89291 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
89292 ** opening it. If a transient table is required, just use the
89293 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
89294 */
89295 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
89296 assert( pOp->p4type==P4_KEYINFO );
89297 rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot,
89298 BTREE_BLOBKEY | pOp->p5);
89299 if( rc==SQLITE_OK ){
89300 assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
89301 assert( pKeyInfo->db==db );
89302 assert( pKeyInfo->enc==ENC(db) );
89304 pKeyInfo, pCx->uc.pCursor);
89305 }
89306 pCx->isTable = 0;
89307 }else{
89308 pCx->pgnoRoot = SCHEMA_ROOT;
89310 0, pCx->uc.pCursor);
89311 pCx->isTable = 1;
89312 }
89313 }
89314 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
89315 }
89316 if( rc ) goto abort_due_to_error;
89317 pCx->nullRow = 1;
89318 break;
89319}
89320
89321/* Opcode: SorterOpen P1 P2 P3 P4 *
89322**
89323** This opcode works like OP_OpenEphemeral except that it opens
89324** a transient index that is specifically designed to sort large
89325** tables using an external merge-sort algorithm.
89326**
89327** If argument P3 is non-zero, then it indicates that the sorter may
89328** assume that a stable sort considering the first P3 fields of each
89329** key is sufficient to produce the required results.
89330*/
89331case OP_SorterOpen: {
89332 VdbeCursor *pCx;
89333
89334 assert( pOp->p1>=0 );
89335 assert( pOp->p2>=0 );
89336 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER);
89337 if( pCx==0 ) goto no_mem;
89338 pCx->pKeyInfo = pOp->p4.pKeyInfo;
89339 assert( pCx->pKeyInfo->db==db );
89340 assert( pCx->pKeyInfo->enc==ENC(db) );
89341 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx);
89342 if( rc ) goto abort_due_to_error;
89343 break;
89344}
89345
89346/* Opcode: SequenceTest P1 P2 * * *
89347** Synopsis: if( cursor[P1].ctr++ ) pc = P2
89348**
89349** P1 is a sorter cursor. If the sequence counter is currently zero, jump
89350** to P2. Regardless of whether or not the jump is taken, increment the
89351** the sequence value.
89352*/
89353case OP_SequenceTest: {
89354 VdbeCursor *pC;
89355 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89356 pC = p->apCsr[pOp->p1];
89357 assert( isSorter(pC) );
89358 if( (pC->seqCount++)==0 ){
89359 goto jump_to_p2;
89360 }
89361 break;
89362}
89363
89364/* Opcode: OpenPseudo P1 P2 P3 * *
89365** Synopsis: P3 columns in r[P2]
89366**
89367** Open a new cursor that points to a fake table that contains a single
89368** row of data. The content of that one row is the content of memory
89369** register P2. In other words, cursor P1 becomes an alias for the
89370** MEM_Blob content contained in register P2.
89371**
89372** A pseudo-table created by this opcode is used to hold a single
89373** row output from the sorter so that the row can be decomposed into
89374** individual columns using the OP_Column opcode. The OP_Column opcode
89375** is the only cursor opcode that works with a pseudo-table.
89376**
89377** P3 is the number of fields in the records that will be stored by
89378** the pseudo-table.
89379*/
89380case OP_OpenPseudo: {
89381 VdbeCursor *pCx;
89382
89383 assert( pOp->p1>=0 );
89384 assert( pOp->p3>=0 );
89385 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
89386 if( pCx==0 ) goto no_mem;
89387 pCx->nullRow = 1;
89388 pCx->seekResult = pOp->p2;
89389 pCx->isTable = 1;
89390 /* Give this pseudo-cursor a fake BtCursor pointer so that pCx
89391 ** can be safely passed to sqlite3VdbeCursorMoveto(). This avoids a test
89392 ** for pCx->eCurType==CURTYPE_BTREE inside of sqlite3VdbeCursorMoveto()
89393 ** which is a performance optimization */
89395 assert( pOp->p5==0 );
89396 break;
89397}
89398
89399/* Opcode: Close P1 * * * *
89400**
89401** Close a cursor previously opened as P1. If P1 is not
89402** currently open, this instruction is a no-op.
89403*/
89404case OP_Close: {
89405 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89406 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
89407 p->apCsr[pOp->p1] = 0;
89408 break;
89409}
89410
89411#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
89412/* Opcode: ColumnsUsed P1 * * P4 *
89413**
89414** This opcode (which only exists if SQLite was compiled with
89415** SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the
89416** table or index for cursor P1 are used. P4 is a 64-bit integer
89417** (P4_INT64) in which the first 63 bits are one for each of the
89418** first 63 columns of the table or index that are actually used
89419** by the cursor. The high-order bit is set if any column after
89420** the 64th is used.
89421*/
89422case OP_ColumnsUsed: {
89423 VdbeCursor *pC;
89424 pC = p->apCsr[pOp->p1];
89425 assert( pC->eCurType==CURTYPE_BTREE );
89426 pC->maskUsed = *(u64*)pOp->p4.pI64;
89427 break;
89428}
89429#endif
89430
89431/* Opcode: SeekGE P1 P2 P3 P4 *
89432** Synopsis: key=r[P3@P4]
89433**
89434** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
89435** use the value in register P3 as the key. If cursor P1 refers
89436** to an SQL index, then P3 is the first in an array of P4 registers
89437** that are used as an unpacked index key.
89438**
89439** Reposition cursor P1 so that it points to the smallest entry that
89440** is greater than or equal to the key value. If there are no records
89441** greater than or equal to the key and P2 is not zero, then jump to P2.
89442**
89443** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
89444** opcode will either land on a record that exactly matches the key, or
89445** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
89446** this opcode must be followed by an IdxLE opcode with the same arguments.
89447** The IdxGT opcode will be skipped if this opcode succeeds, but the
89448** IdxGT opcode will be used on subsequent loop iterations. The
89449** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
89450** is an equality search.
89451**
89452** This opcode leaves the cursor configured to move in forward order,
89453** from the beginning toward the end. In other words, the cursor is
89454** configured to use Next, not Prev.
89455**
89456** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
89457*/
89458/* Opcode: SeekGT P1 P2 P3 P4 *
89459** Synopsis: key=r[P3@P4]
89460**
89461** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
89462** use the value in register P3 as a key. If cursor P1 refers
89463** to an SQL index, then P3 is the first in an array of P4 registers
89464** that are used as an unpacked index key.
89465**
89466** Reposition cursor P1 so that it points to the smallest entry that
89467** is greater than the key value. If there are no records greater than
89468** the key and P2 is not zero, then jump to P2.
89469**
89470** This opcode leaves the cursor configured to move in forward order,
89471** from the beginning toward the end. In other words, the cursor is
89472** configured to use Next, not Prev.
89473**
89474** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
89475*/
89476/* Opcode: SeekLT P1 P2 P3 P4 *
89477** Synopsis: key=r[P3@P4]
89478**
89479** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
89480** use the value in register P3 as a key. If cursor P1 refers
89481** to an SQL index, then P3 is the first in an array of P4 registers
89482** that are used as an unpacked index key.
89483**
89484** Reposition cursor P1 so that it points to the largest entry that
89485** is less than the key value. If there are no records less than
89486** the key and P2 is not zero, then jump to P2.
89487**
89488** This opcode leaves the cursor configured to move in reverse order,
89489** from the end toward the beginning. In other words, the cursor is
89490** configured to use Prev, not Next.
89491**
89492** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
89493*/
89494/* Opcode: SeekLE P1 P2 P3 P4 *
89495** Synopsis: key=r[P3@P4]
89496**
89497** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
89498** use the value in register P3 as a key. If cursor P1 refers
89499** to an SQL index, then P3 is the first in an array of P4 registers
89500** that are used as an unpacked index key.
89501**
89502** Reposition cursor P1 so that it points to the largest entry that
89503** is less than or equal to the key value. If there are no records
89504** less than or equal to the key and P2 is not zero, then jump to P2.
89505**
89506** This opcode leaves the cursor configured to move in reverse order,
89507** from the end toward the beginning. In other words, the cursor is
89508** configured to use Prev, not Next.
89509**
89510** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
89511** opcode will either land on a record that exactly matches the key, or
89512** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
89513** this opcode must be followed by an IdxLE opcode with the same arguments.
89514** The IdxGE opcode will be skipped if this opcode succeeds, but the
89515** IdxGE opcode will be used on subsequent loop iterations. The
89516** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
89517** is an equality search.
89518**
89519** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
89520*/
89521case OP_SeekLT: /* jump, in3, group */
89522case OP_SeekLE: /* jump, in3, group */
89523case OP_SeekGE: /* jump, in3, group */
89524case OP_SeekGT: { /* jump, in3, group */
89525 int res; /* Comparison result */
89526 int oc; /* Opcode */
89527 VdbeCursor *pC; /* The cursor to seek */
89528 UnpackedRecord r; /* The key to seek for */
89529 int nField; /* Number of columns or fields in the key */
89530 i64 iKey; /* The rowid we are to seek to */
89531 int eqOnly; /* Only interested in == results */
89532
89533 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89534 assert( pOp->p2!=0 );
89535 pC = p->apCsr[pOp->p1];
89536 assert( pC!=0 );
89537 assert( pC->eCurType==CURTYPE_BTREE );
89538 assert( OP_SeekLE == OP_SeekLT+1 );
89539 assert( OP_SeekGE == OP_SeekLT+2 );
89540 assert( OP_SeekGT == OP_SeekLT+3 );
89541 assert( pC->isOrdered );
89542 assert( pC->uc.pCursor!=0 );
89543 oc = pOp->opcode;
89544 eqOnly = 0;
89545 pC->nullRow = 0;
89546#ifdef SQLITE_DEBUG
89547 pC->seekOp = pOp->opcode;
89548#endif
89549
89550 pC->deferredMoveto = 0;
89552 if( pC->isTable ){
89553 u16 flags3, newType;
89554 /* The OPFLAG_SEEKEQ/BTREE_SEEK_EQ flag is only set on index cursors */
89556 || CORRUPT_DB );
89557
89558 /* The input value in P3 might be of any type: integer, real, string,
89559 ** blob, or NULL. But it needs to be an integer before we can do
89560 ** the seek, so convert it. */
89561 pIn3 = &aMem[pOp->p3];
89562 flags3 = pIn3->flags;
89563 if( (flags3 & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Str))==MEM_Str ){
89564 applyNumericAffinity(pIn3, 0);
89565 }
89566 iKey = sqlite3VdbeIntValue(pIn3); /* Get the integer key value */
89567 newType = pIn3->flags; /* Record the type after applying numeric affinity */
89568 pIn3->flags = flags3; /* But convert the type back to its original */
89569
89570 /* If the P3 value could not be converted into an integer without
89571 ** loss of information, then special processing is required... */
89572 if( (newType & (MEM_Int|MEM_IntReal))==0 ){
89573 if( (newType & MEM_Real)==0 ){
89574 if( (newType & MEM_Null) || oc>=OP_SeekGE ){
89575 VdbeBranchTaken(1,2);
89576 goto jump_to_p2;
89577 }else{
89578 rc = sqlite3BtreeLast(pC->uc.pCursor, &res);
89579 if( rc!=SQLITE_OK ) goto abort_due_to_error;
89580 goto seek_not_found;
89581 }
89582 }else
89583
89584 /* If the approximation iKey is larger than the actual real search
89585 ** term, substitute >= for > and < for <=. e.g. if the search term
89586 ** is 4.9 and the integer approximation 5:
89587 **
89588 ** (x > 4.9) -> (x >= 5)
89589 ** (x <= 4.9) -> (x < 5)
89590 */
89591 if( pIn3->u.r<(double)iKey ){
89592 assert( OP_SeekGE==(OP_SeekGT-1) );
89593 assert( OP_SeekLT==(OP_SeekLE-1) );
89594 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
89595 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
89596 }
89597
89598 /* If the approximation iKey is smaller than the actual real search
89599 ** term, substitute <= for < and > for >=. */
89600 else if( pIn3->u.r>(double)iKey ){
89601 assert( OP_SeekLE==(OP_SeekLT+1) );
89602 assert( OP_SeekGT==(OP_SeekGE+1) );
89603 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
89604 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
89605 }
89606 }
89607 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)iKey, 0, &res);
89608 pC->movetoTarget = iKey; /* Used by OP_Delete */
89609 if( rc!=SQLITE_OK ){
89610 goto abort_due_to_error;
89611 }
89612 }else{
89613 /* For a cursor with the OPFLAG_SEEKEQ/BTREE_SEEK_EQ hint, only the
89614 ** OP_SeekGE and OP_SeekLE opcodes are allowed, and these must be
89615 ** immediately followed by an OP_IdxGT or OP_IdxLT opcode, respectively,
89616 ** with the same key.
89617 */
89619 eqOnly = 1;
89620 assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
89621 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
89622 assert( pOp->opcode==OP_SeekGE || pOp[1].opcode==OP_IdxLT );
89623 assert( pOp->opcode==OP_SeekLE || pOp[1].opcode==OP_IdxGT );
89624 assert( pOp[1].p1==pOp[0].p1 );
89625 assert( pOp[1].p2==pOp[0].p2 );
89626 assert( pOp[1].p3==pOp[0].p3 );
89627 assert( pOp[1].p4.i==pOp[0].p4.i );
89628 }
89629
89630 nField = pOp->p4.i;
89631 assert( pOp->p4type==P4_INT32 );
89632 assert( nField>0 );
89633 r.pKeyInfo = pC->pKeyInfo;
89634 r.nField = (u16)nField;
89635
89636 /* The next line of code computes as follows, only faster:
89637 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
89638 ** r.default_rc = -1;
89639 ** }else{
89640 ** r.default_rc = +1;
89641 ** }
89642 */
89643 r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1);
89644 assert( oc!=OP_SeekGT || r.default_rc==-1 );
89645 assert( oc!=OP_SeekLE || r.default_rc==-1 );
89646 assert( oc!=OP_SeekGE || r.default_rc==+1 );
89647 assert( oc!=OP_SeekLT || r.default_rc==+1 );
89648
89649 r.aMem = &aMem[pOp->p3];
89650#ifdef SQLITE_DEBUG
89651 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
89652#endif
89653 r.eqSeen = 0;
89654 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, &r, 0, 0, &res);
89655 if( rc!=SQLITE_OK ){
89656 goto abort_due_to_error;
89657 }
89658 if( eqOnly && r.eqSeen==0 ){
89659 assert( res!=0 );
89660 goto seek_not_found;
89661 }
89662 }
89663#ifdef SQLITE_TEST
89664 sqlite3_search_count++;
89665#endif
89666 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
89667 if( res<0 || (res==0 && oc==OP_SeekGT) ){
89668 res = 0;
89669 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
89670 if( rc!=SQLITE_OK ){
89671 if( rc==SQLITE_DONE ){
89672 rc = SQLITE_OK;
89673 res = 1;
89674 }else{
89675 goto abort_due_to_error;
89676 }
89677 }
89678 }else{
89679 res = 0;
89680 }
89681 }else{
89682 assert( oc==OP_SeekLT || oc==OP_SeekLE );
89683 if( res>0 || (res==0 && oc==OP_SeekLT) ){
89684 res = 0;
89685 rc = sqlite3BtreePrevious(pC->uc.pCursor, 0);
89686 if( rc!=SQLITE_OK ){
89687 if( rc==SQLITE_DONE ){
89688 rc = SQLITE_OK;
89689 res = 1;
89690 }else{
89691 goto abort_due_to_error;
89692 }
89693 }
89694 }else{
89695 /* res might be negative because the table is empty. Check to
89696 ** see if this is the case.
89697 */
89698 res = sqlite3BtreeEof(pC->uc.pCursor);
89699 }
89700 }
89701seek_not_found:
89702 assert( pOp->p2>0 );
89703 VdbeBranchTaken(res!=0,2);
89704 if( res ){
89705 goto jump_to_p2;
89706 }else if( eqOnly ){
89707 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
89708 pOp++; /* Skip the OP_IdxLt or OP_IdxGT that follows */
89709 }
89710 break;
89711}
89712
89713/* Opcode: SeekHit P1 P2 * * *
89714** Synopsis: seekHit=P2
89715**
89716** Set the seekHit flag on cursor P1 to the value in P2.
89717** The seekHit flag is used by the IfNoHope opcode.
89718**
89719** P1 must be a valid b-tree cursor. P2 must be a boolean value,
89720** either 0 or 1.
89721*/
89722case OP_SeekHit: {
89723 VdbeCursor *pC;
89724 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89725 pC = p->apCsr[pOp->p1];
89726 assert( pC!=0 );
89727 assert( pOp->p2==0 || pOp->p2==1 );
89728 pC->seekHit = pOp->p2 & 1;
89729 break;
89730}
89731
89732/* Opcode: IfNotOpen P1 P2 * * *
89733** Synopsis: if( !csr[P1] ) goto P2
89734**
89735** If cursor P1 is not open, jump to instruction P2. Otherwise, fall through.
89736*/
89737case OP_IfNotOpen: { /* jump */
89738 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89739 VdbeBranchTaken(p->apCsr[pOp->p1]==0, 2);
89740 if( !p->apCsr[pOp->p1] ){
89741 goto jump_to_p2_and_check_for_interrupt;
89742 }
89743 break;
89744}
89745
89746/* Opcode: Found P1 P2 P3 P4 *
89747** Synopsis: key=r[P3@P4]
89748**
89749** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
89750** P4>0 then register P3 is the first of P4 registers that form an unpacked
89751** record.
89752**
89753** Cursor P1 is on an index btree. If the record identified by P3 and P4
89754** is a prefix of any entry in P1 then a jump is made to P2 and
89755** P1 is left pointing at the matching entry.
89756**
89757** This operation leaves the cursor in a state where it can be
89758** advanced in the forward direction. The Next instruction will work,
89759** but not the Prev instruction.
89760**
89761** See also: NotFound, NoConflict, NotExists. SeekGe
89762*/
89763/* Opcode: NotFound P1 P2 P3 P4 *
89764** Synopsis: key=r[P3@P4]
89765**
89766** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
89767** P4>0 then register P3 is the first of P4 registers that form an unpacked
89768** record.
89769**
89770** Cursor P1 is on an index btree. If the record identified by P3 and P4
89771** is not the prefix of any entry in P1 then a jump is made to P2. If P1
89772** does contain an entry whose prefix matches the P3/P4 record then control
89773** falls through to the next instruction and P1 is left pointing at the
89774** matching entry.
89775**
89776** This operation leaves the cursor in a state where it cannot be
89777** advanced in either direction. In other words, the Next and Prev
89778** opcodes do not work after this operation.
89779**
89780** See also: Found, NotExists, NoConflict, IfNoHope
89781*/
89782/* Opcode: IfNoHope P1 P2 P3 P4 *
89783** Synopsis: key=r[P3@P4]
89784**
89785** Register P3 is the first of P4 registers that form an unpacked
89786** record.
89787**
89788** Cursor P1 is on an index btree. If the seekHit flag is set on P1, then
89789** this opcode is a no-op. But if the seekHit flag of P1 is clear, then
89790** check to see if there is any entry in P1 that matches the
89791** prefix identified by P3 and P4. If no entry matches the prefix,
89792** jump to P2. Otherwise fall through.
89793**
89794** This opcode behaves like OP_NotFound if the seekHit
89795** flag is clear and it behaves like OP_Noop if the seekHit flag is set.
89796**
89797** This opcode is used in IN clause processing for a multi-column key.
89798** If an IN clause is attached to an element of the key other than the
89799** left-most element, and if there are no matches on the most recent
89800** seek over the whole key, then it might be that one of the key element
89801** to the left is prohibiting a match, and hence there is "no hope" of
89802** any match regardless of how many IN clause elements are checked.
89803** In such a case, we abandon the IN clause search early, using this
89804** opcode. The opcode name comes from the fact that the
89805** jump is taken if there is "no hope" of achieving a match.
89806**
89807** See also: NotFound, SeekHit
89808*/
89809/* Opcode: NoConflict P1 P2 P3 P4 *
89810** Synopsis: key=r[P3@P4]
89811**
89812** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
89813** P4>0 then register P3 is the first of P4 registers that form an unpacked
89814** record.
89815**
89816** Cursor P1 is on an index btree. If the record identified by P3 and P4
89817** contains any NULL value, jump immediately to P2. If all terms of the
89818** record are not-NULL then a check is done to determine if any row in the
89819** P1 index btree has a matching key prefix. If there are no matches, jump
89820** immediately to P2. If there is a match, fall through and leave the P1
89821** cursor pointing to the matching row.
89822**
89823** This opcode is similar to OP_NotFound with the exceptions that the
89824** branch is always taken if any part of the search key input is NULL.
89825**
89826** This operation leaves the cursor in a state where it cannot be
89827** advanced in either direction. In other words, the Next and Prev
89828** opcodes do not work after this operation.
89829**
89830** See also: NotFound, Found, NotExists
89831*/
89832case OP_IfNoHope: { /* jump, in3 */
89833 VdbeCursor *pC;
89834 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89835 pC = p->apCsr[pOp->p1];
89836 assert( pC!=0 );
89837 if( pC->seekHit ) break;
89838 /* Fall through into OP_NotFound */
89839 /* no break */ deliberate_fall_through
89840}
89841case OP_NoConflict: /* jump, in3 */
89842case OP_NotFound: /* jump, in3 */
89843case OP_Found: { /* jump, in3 */
89844 int alreadyExists;
89845 int takeJump;
89846 int ii;
89847 VdbeCursor *pC;
89848 int res;
89849 UnpackedRecord *pFree;
89850 UnpackedRecord *pIdxKey;
89852
89853#ifdef SQLITE_TEST
89854 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
89855#endif
89856
89857 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89858 assert( pOp->p4type==P4_INT32 );
89859 pC = p->apCsr[pOp->p1];
89860 assert( pC!=0 );
89861#ifdef SQLITE_DEBUG
89862 pC->seekOp = pOp->opcode;
89863#endif
89864 pIn3 = &aMem[pOp->p3];
89865 assert( pC->eCurType==CURTYPE_BTREE );
89866 assert( pC->uc.pCursor!=0 );
89867 assert( pC->isTable==0 );
89868 if( pOp->p4.i>0 ){
89869 r.pKeyInfo = pC->pKeyInfo;
89870 r.nField = (u16)pOp->p4.i;
89871 r.aMem = pIn3;
89872#ifdef SQLITE_DEBUG
89873 for(ii=0; ii<r.nField; ii++){
89874 assert( memIsValid(&r.aMem[ii]) );
89875 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
89876 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
89877 }
89878#endif
89879 pIdxKey = &r;
89880 pFree = 0;
89881 }else{
89882 assert( pIn3->flags & MEM_Blob );
89883 rc = ExpandBlob(pIn3);
89884 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
89885 if( rc ) goto no_mem;
89886 pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
89887 if( pIdxKey==0 ) goto no_mem;
89888 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
89889 }
89890 pIdxKey->default_rc = 0;
89891 takeJump = 0;
89892 if( pOp->opcode==OP_NoConflict ){
89893 /* For the OP_NoConflict opcode, take the jump if any of the
89894 ** input fields are NULL, since any key with a NULL will not
89895 ** conflict */
89896 for(ii=0; ii<pIdxKey->nField; ii++){
89897 if( pIdxKey->aMem[ii].flags & MEM_Null ){
89898 takeJump = 1;
89899 break;
89900 }
89901 }
89902 }
89903 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
89904 if( pFree ) sqlite3DbFreeNN(db, pFree);
89905 if( rc!=SQLITE_OK ){
89906 goto abort_due_to_error;
89907 }
89908 pC->seekResult = res;
89909 alreadyExists = (res==0);
89910 pC->nullRow = 1-alreadyExists;
89911 pC->deferredMoveto = 0;
89913 if( pOp->opcode==OP_Found ){
89914 VdbeBranchTaken(alreadyExists!=0,2);
89915 if( alreadyExists ) goto jump_to_p2;
89916 }else{
89917 VdbeBranchTaken(takeJump||alreadyExists==0,2);
89918 if( takeJump || !alreadyExists ) goto jump_to_p2;
89919 }
89920 break;
89921}
89922
89923/* Opcode: SeekRowid P1 P2 P3 * *
89924** Synopsis: intkey=r[P3]
89925**
89926** P1 is the index of a cursor open on an SQL table btree (with integer
89927** keys). If register P3 does not contain an integer or if P1 does not
89928** contain a record with rowid P3 then jump immediately to P2.
89929** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
89930** a record with rowid P3 then
89931** leave the cursor pointing at that record and fall through to the next
89932** instruction.
89933**
89934** The OP_NotExists opcode performs the same operation, but with OP_NotExists
89935** the P3 register must be guaranteed to contain an integer value. With this
89936** opcode, register P3 might not contain an integer.
89937**
89938** The OP_NotFound opcode performs the same operation on index btrees
89939** (with arbitrary multi-value keys).
89940**
89941** This opcode leaves the cursor in a state where it cannot be advanced
89942** in either direction. In other words, the Next and Prev opcodes will
89943** not work following this opcode.
89944**
89945** See also: Found, NotFound, NoConflict, SeekRowid
89946*/
89947/* Opcode: NotExists P1 P2 P3 * *
89948** Synopsis: intkey=r[P3]
89949**
89950** P1 is the index of a cursor open on an SQL table btree (with integer
89951** keys). P3 is an integer rowid. If P1 does not contain a record with
89952** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
89953** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then
89954** leave the cursor pointing at that record and fall through to the next
89955** instruction.
89956**
89957** The OP_SeekRowid opcode performs the same operation but also allows the
89958** P3 register to contain a non-integer value, in which case the jump is
89959** always taken. This opcode requires that P3 always contain an integer.
89960**
89961** The OP_NotFound opcode performs the same operation on index btrees
89962** (with arbitrary multi-value keys).
89963**
89964** This opcode leaves the cursor in a state where it cannot be advanced
89965** in either direction. In other words, the Next and Prev opcodes will
89966** not work following this opcode.
89967**
89968** See also: Found, NotFound, NoConflict, SeekRowid
89969*/
89970case OP_SeekRowid: { /* jump, in3 */
89971 VdbeCursor *pC;
89972 BtCursor *pCrsr;
89973 int res;
89974 u64 iKey;
89975
89976 pIn3 = &aMem[pOp->p3];
89977 testcase( pIn3->flags & MEM_Int );
89978 testcase( pIn3->flags & MEM_IntReal );
89979 testcase( pIn3->flags & MEM_Real );
89980 testcase( (pIn3->flags & (MEM_Str|MEM_Int))==MEM_Str );
89981 if( (pIn3->flags & (MEM_Int|MEM_IntReal))==0 ){
89982 /* If pIn3->u.i does not contain an integer, compute iKey as the
89983 ** integer value of pIn3. Jump to P2 if pIn3 cannot be converted
89984 ** into an integer without loss of information. Take care to avoid
89985 ** changing the datatype of pIn3, however, as it is used by other
89986 ** parts of the prepared statement. */
89987 Mem x = pIn3[0];
89988 applyAffinity(&x, SQLITE_AFF_NUMERIC, encoding);
89989 if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
89990 iKey = x.u.i;
89991 goto notExistsWithKey;
89992 }
89993 /* Fall through into OP_NotExists */
89994 /* no break */ deliberate_fall_through
89995case OP_NotExists: /* jump, in3 */
89996 pIn3 = &aMem[pOp->p3];
89997 assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
89998 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89999 iKey = pIn3->u.i;
90000notExistsWithKey:
90001 pC = p->apCsr[pOp->p1];
90002 assert( pC!=0 );
90003#ifdef SQLITE_DEBUG
90004 if( pOp->opcode==OP_SeekRowid ) pC->seekOp = OP_SeekRowid;
90005#endif
90006 assert( pC->isTable );
90007 assert( pC->eCurType==CURTYPE_BTREE );
90008 pCrsr = pC->uc.pCursor;
90009 assert( pCrsr!=0 );
90010 res = 0;
90011 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
90012 assert( rc==SQLITE_OK || res==0 );
90013 pC->movetoTarget = iKey; /* Used by OP_Delete */
90014 pC->nullRow = 0;
90016 pC->deferredMoveto = 0;
90017 VdbeBranchTaken(res!=0,2);
90018 pC->seekResult = res;
90019 if( res!=0 ){
90020 assert( rc==SQLITE_OK );
90021 if( pOp->p2==0 ){
90023 }else{
90024 goto jump_to_p2;
90025 }
90026 }
90027 if( rc ) goto abort_due_to_error;
90028 break;
90029}
90030
90031/* Opcode: Sequence P1 P2 * * *
90032** Synopsis: r[P2]=cursor[P1].ctr++
90033**
90034** Find the next available sequence number for cursor P1.
90035** Write the sequence number into register P2.
90036** The sequence number on the cursor is incremented after this
90037** instruction.
90038*/
90039case OP_Sequence: { /* out2 */
90040 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90041 assert( p->apCsr[pOp->p1]!=0 );
90042 assert( p->apCsr[pOp->p1]->eCurType!=CURTYPE_VTAB );
90043 pOut = out2Prerelease(p, pOp);
90044 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
90045 break;
90046}
90047
90048
90049/* Opcode: NewRowid P1 P2 P3 * *
90050** Synopsis: r[P2]=rowid
90051**
90052** Get a new integer record number (a.k.a "rowid") used as the key to a table.
90053** The record number is not previously used as a key in the database
90054** table that cursor P1 points to. The new record number is written
90055** written to register P2.
90056**
90057** If P3>0 then P3 is a register in the root frame of this VDBE that holds
90058** the largest previously generated record number. No new record numbers are
90059** allowed to be less than this value. When this value reaches its maximum,
90060** an SQLITE_FULL error is generated. The P3 register is updated with the '
90061** generated record number. This P3 mechanism is used to help implement the
90062** AUTOINCREMENT feature.
90063*/
90064case OP_NewRowid: { /* out2 */
90065 i64 v; /* The new rowid */
90066 VdbeCursor *pC; /* Cursor of table to get the new rowid */
90067 int res; /* Result of an sqlite3BtreeLast() */
90068 int cnt; /* Counter to limit the number of searches */
90069 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
90070 VdbeFrame *pFrame; /* Root frame of VDBE */
90071
90072 v = 0;
90073 res = 0;
90074 pOut = out2Prerelease(p, pOp);
90075 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90076 pC = p->apCsr[pOp->p1];
90077 assert( pC!=0 );
90078 assert( pC->isTable );
90079 assert( pC->eCurType==CURTYPE_BTREE );
90080 assert( pC->uc.pCursor!=0 );
90081 {
90082 /* The next rowid or record number (different terms for the same
90083 ** thing) is obtained in a two-step algorithm.
90084 **
90085 ** First we attempt to find the largest existing rowid and add one
90086 ** to that. But if the largest existing rowid is already the maximum
90087 ** positive integer, we have to fall through to the second
90088 ** probabilistic algorithm
90089 **
90090 ** The second algorithm is to select a rowid at random and see if
90091 ** it already exists in the table. If it does not exist, we have
90092 ** succeeded. If the random rowid does exist, we select a new one
90093 ** and try again, up to 100 times.
90094 */
90095 assert( pC->isTable );
90096
90097#ifdef SQLITE_32BIT_ROWID
90098# define MAX_ROWID 0x7fffffff
90099#else
90100 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
90101 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems
90102 ** to provide the constant while making all compilers happy.
90103 */
90104# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
90105#endif
90106
90107 if( !pC->useRandomRowid ){
90108 rc = sqlite3BtreeLast(pC->uc.pCursor, &res);
90109 if( rc!=SQLITE_OK ){
90110 goto abort_due_to_error;
90111 }
90112 if( res ){
90113 v = 1; /* IMP: R-61914-48074 */
90114 }else{
90115 assert( sqlite3BtreeCursorIsValid(pC->uc.pCursor) );
90117 if( v>=MAX_ROWID ){
90118 pC->useRandomRowid = 1;
90119 }else{
90120 v++; /* IMP: R-29538-34987 */
90121 }
90122 }
90123 }
90124
90125#ifndef SQLITE_OMIT_AUTOINCREMENT
90126 if( pOp->p3 ){
90127 /* Assert that P3 is a valid memory cell. */
90128 assert( pOp->p3>0 );
90129 if( p->pFrame ){
90130 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
90131 /* Assert that P3 is a valid memory cell. */
90132 assert( pOp->p3<=pFrame->nMem );
90133 pMem = &pFrame->aMem[pOp->p3];
90134 }else{
90135 /* Assert that P3 is a valid memory cell. */
90136 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
90137 pMem = &aMem[pOp->p3];
90138 memAboutToChange(p, pMem);
90139 }
90140 assert( memIsValid(pMem) );
90141
90142 REGISTER_TRACE(pOp->p3, pMem);
90144 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
90145 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
90146 rc = SQLITE_FULL; /* IMP: R-17817-00630 */
90147 goto abort_due_to_error;
90148 }
90149 if( v<pMem->u.i+1 ){
90150 v = pMem->u.i + 1;
90151 }
90152 pMem->u.i = v;
90153 }
90154#endif
90155 if( pC->useRandomRowid ){
90156 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
90157 ** largest possible integer (9223372036854775807) then the database
90158 ** engine starts picking positive candidate ROWIDs at random until
90159 ** it finds one that is not previously used. */
90160 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
90161 ** an AUTOINCREMENT table. */
90162 cnt = 0;
90163 do{
90164 sqlite3_randomness(sizeof(v), &v);
90165 v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */
90166 }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)v,
90167 0, &res))==SQLITE_OK)
90168 && (res==0)
90169 && (++cnt<100));
90170 if( rc ) goto abort_due_to_error;
90171 if( res==0 ){
90172 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
90173 goto abort_due_to_error;
90174 }
90175 assert( v>0 ); /* EV: R-40812-03570 */
90176 }
90177 pC->deferredMoveto = 0;
90179 }
90180 pOut->u.i = v;
90181 break;
90182}
90183
90184/* Opcode: Insert P1 P2 P3 P4 P5
90185** Synopsis: intkey=r[P3] data=r[P2]
90186**
90187** Write an entry into the table of cursor P1. A new entry is
90188** created if it doesn't already exist or the data for an existing
90189** entry is overwritten. The data is the value MEM_Blob stored in register
90190** number P2. The key is stored in register P3. The key must
90191** be a MEM_Int.
90192**
90193** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
90194** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
90195** then rowid is stored for subsequent return by the
90196** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
90197**
90198** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
90199** run faster by avoiding an unnecessary seek on cursor P1. However,
90200** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
90201** seeks on the cursor or if the most recent seek used a key equal to P3.
90202**
90203** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
90204** UPDATE operation. Otherwise (if the flag is clear) then this opcode
90205** is part of an INSERT operation. The difference is only important to
90206** the update hook.
90207**
90208** Parameter P4 may point to a Table structure, or may be NULL. If it is
90209** not NULL, then the update-hook (sqlite3.xUpdateCallback) is invoked
90210** following a successful insert.
90211**
90212** (WARNING/TODO: If P1 is a pseudo-cursor and P2 is dynamically
90213** allocated, then ownership of P2 is transferred to the pseudo-cursor
90214** and register P2 becomes ephemeral. If the cursor is changed, the
90215** value of register P2 will then change. Make sure this does not
90216** cause any problems.)
90217**
90218** This instruction only works on tables. The equivalent instruction
90219** for indices is OP_IdxInsert.
90220*/
90221case OP_Insert: {
90222 Mem *pData; /* MEM cell holding data for the record to be inserted */
90223 Mem *pKey; /* MEM cell holding key for the record */
90224 VdbeCursor *pC; /* Cursor to table into which insert is written */
90225 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
90226 const char *zDb; /* database name - used by the update hook */
90227 Table *pTab; /* Table structure - used by update and pre-update hooks */
90228 BtreePayload x; /* Payload to be inserted */
90229
90230 pData = &aMem[pOp->p2];
90231 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90232 assert( memIsValid(pData) );
90233 pC = p->apCsr[pOp->p1];
90234 assert( pC!=0 );
90235 assert( pC->eCurType==CURTYPE_BTREE );
90236 assert( pC->deferredMoveto==0 );
90237 assert( pC->uc.pCursor!=0 );
90238 assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
90239 assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
90240 REGISTER_TRACE(pOp->p2, pData);
90242
90243 pKey = &aMem[pOp->p3];
90244 assert( pKey->flags & MEM_Int );
90245 assert( memIsValid(pKey) );
90246 REGISTER_TRACE(pOp->p3, pKey);
90247 x.nKey = pKey->u.i;
90248
90249 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
90250 assert( pC->iDb>=0 );
90251 zDb = db->aDb[pC->iDb].zDbSName;
90252 pTab = pOp->p4.pTab;
90253 assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
90254 }else{
90255 pTab = 0;
90256 zDb = 0; /* Not needed. Silence a compiler warning. */
90257 }
90258
90259#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
90260 /* Invoke the pre-update hook, if any */
90261 if( pTab ){
90262 if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){
90263 sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2);
90264 }
90265 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
90266 /* Prevent post-update hook from running in cases when it should not */
90267 pTab = 0;
90268 }
90269 }
90270 if( pOp->p5 & OPFLAG_ISNOOP ) break;
90271#endif
90272
90273 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
90274 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
90275 assert( pData->flags & (MEM_Blob|MEM_Str) );
90276 x.pData = pData->z;
90277 x.nData = pData->n;
90278 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
90279 if( pData->flags & MEM_Zero ){
90280 x.nZero = pData->u.nZero;
90281 }else{
90282 x.nZero = 0;
90283 }
90284 x.pKey = 0;
90285 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
90286 (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), seekResult
90287 );
90288 pC->deferredMoveto = 0;
90290
90291 /* Invoke the update-hook if required. */
90292 if( rc ) goto abort_due_to_error;
90293 if( pTab ){
90294 assert( db->xUpdateCallback!=0 );
90295 assert( pTab->aCol!=0 );
90298 zDb, pTab->zName, x.nKey);
90299 }
90300 break;
90301}
90302
90303/* Opcode: Delete P1 P2 P3 P4 P5
90304**
90305** Delete the record at which the P1 cursor is currently pointing.
90306**
90307** If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then
90308** the cursor will be left pointing at either the next or the previous
90309** record in the table. If it is left pointing at the next record, then
90310** the next Next instruction will be a no-op. As a result, in this case
90311** it is ok to delete a record from within a Next loop. If
90312** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
90313** left in an undefined state.
90314**
90315** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
90316** delete one of several associated with deleting a table row and all its
90317** associated index entries. Exactly one of those deletes is the "primary"
90318** delete. The others are all on OPFLAG_FORDELETE cursors or else are
90319** marked with the AUXDELETE flag.
90320**
90321** If the OPFLAG_NCHANGE flag of P2 (NB: P2 not P5) is set, then the row
90322** change count is incremented (otherwise not).
90323**
90324** P1 must not be pseudo-table. It has to be a real table with
90325** multiple rows.
90326**
90327** If P4 is not NULL then it points to a Table object. In this case either
90328** the update or pre-update hook, or both, may be invoked. The P1 cursor must
90329** have been positioned using OP_NotFound prior to invoking this opcode in
90330** this case. Specifically, if one is configured, the pre-update hook is
90331** invoked if P4 is not NULL. The update-hook is invoked if one is configured,
90332** P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.
90333**
90334** If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address
90335** of the memory cell that contains the value that the rowid of the row will
90336** be set to by the update.
90337*/
90338case OP_Delete: {
90339 VdbeCursor *pC;
90340 const char *zDb;
90341 Table *pTab;
90342 int opflags;
90343
90344 opflags = pOp->p2;
90345 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90346 pC = p->apCsr[pOp->p1];
90347 assert( pC!=0 );
90348 assert( pC->eCurType==CURTYPE_BTREE );
90349 assert( pC->uc.pCursor!=0 );
90350 assert( pC->deferredMoveto==0 );
90352
90353#ifdef SQLITE_DEBUG
90354 if( pOp->p4type==P4_TABLE
90355 && HasRowid(pOp->p4.pTab)
90356 && pOp->p5==0
90358 ){
90359 /* If p5 is zero, the seek operation that positioned the cursor prior to
90360 ** OP_Delete will have also set the pC->movetoTarget field to the rowid of
90361 ** the row that is being deleted */
90363 assert( CORRUPT_DB || pC->movetoTarget==iKey );
90364 }
90365#endif
90366
90367 /* If the update-hook or pre-update-hook will be invoked, set zDb to
90368 ** the name of the db to pass as to it. Also set local pTab to a copy
90369 ** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
90370 ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
90371 ** VdbeCursor.movetoTarget to the current rowid. */
90372 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
90373 assert( pC->iDb>=0 );
90374 assert( pOp->p4.pTab!=0 );
90375 zDb = db->aDb[pC->iDb].zDbSName;
90376 pTab = pOp->p4.pTab;
90377 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
90379 }
90380 }else{
90381 zDb = 0; /* Not needed. Silence a compiler warning. */
90382 pTab = 0; /* Not needed. Silence a compiler warning. */
90383 }
90384
90385#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
90386 /* Invoke the pre-update-hook if required. */
90387 if( db->xPreUpdateCallback && pOp->p4.pTab ){
90388 assert( !(opflags & OPFLAG_ISUPDATE)
90389 || HasRowid(pTab)==0
90390 || (aMem[pOp->p3].flags & MEM_Int)
90391 );
90392 sqlite3VdbePreUpdateHook(p, pC,
90394 zDb, pTab, pC->movetoTarget,
90395 pOp->p3
90396 );
90397 }
90398 if( opflags & OPFLAG_ISNOOP ) break;
90399#endif
90400
90401 /* Only flags that can be set are SAVEPOISTION and AUXDELETE */
90402 assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
90405
90406#ifdef SQLITE_DEBUG
90407 if( p->pFrame==0 ){
90408 if( pC->isEphemeral==0
90409 && (pOp->p5 & OPFLAG_AUXDELETE)==0
90410 && (pC->wrFlag & OPFLAG_FORDELETE)==0
90411 ){
90412 nExtraDelete++;
90413 }
90414 if( pOp->p2 & OPFLAG_NCHANGE ){
90415 nExtraDelete--;
90416 }
90417 }
90418#endif
90419
90420 rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
90422 pC->seekResult = 0;
90423 if( rc ) goto abort_due_to_error;
90424
90425 /* Invoke the update-hook if required. */
90426 if( opflags & OPFLAG_NCHANGE ){
90427 p->nChange++;
90428 if( db->xUpdateCallback && HasRowid(pTab) ){
90429 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, pTab->zName,
90430 pC->movetoTarget);
90431 assert( pC->iDb>=0 );
90432 }
90433 }
90434
90435 break;
90436}
90437/* Opcode: ResetCount * * * * *
90438**
90439** The value of the change counter is copied to the database handle
90440** change counter (returned by subsequent calls to sqlite3_changes()).
90441** Then the VMs internal change counter resets to 0.
90442** This is used by trigger programs.
90443*/
90444case OP_ResetCount: {
90446 p->nChange = 0;
90447 break;
90448}
90449
90450/* Opcode: SorterCompare P1 P2 P3 P4
90451** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
90452**
90453** P1 is a sorter cursor. This instruction compares a prefix of the
90454** record blob in register P3 against a prefix of the entry that
90455** the sorter cursor currently points to. Only the first P4 fields
90456** of r[P3] and the sorter record are compared.
90457**
90458** If either P3 or the sorter contains a NULL in one of their significant
90459** fields (not counting the P4 fields at the end which are ignored) then
90460** the comparison is assumed to be equal.
90461**
90462** Fall through to next instruction if the two records compare equal to
90463** each other. Jump to P2 if they are different.
90464*/
90465case OP_SorterCompare: {
90466 VdbeCursor *pC;
90467 int res;
90468 int nKeyCol;
90469
90470 pC = p->apCsr[pOp->p1];
90471 assert( isSorter(pC) );
90472 assert( pOp->p4type==P4_INT32 );
90473 pIn3 = &aMem[pOp->p3];
90474 nKeyCol = pOp->p4.i;
90475 res = 0;
90476 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
90477 VdbeBranchTaken(res!=0,2);
90478 if( rc ) goto abort_due_to_error;
90479 if( res ) goto jump_to_p2;
90480 break;
90481};
90482
90483/* Opcode: SorterData P1 P2 P3 * *
90484** Synopsis: r[P2]=data
90485**
90486** Write into register P2 the current sorter data for sorter cursor P1.
90487** Then clear the column header cache on cursor P3.
90488**
90489** This opcode is normally use to move a record out of the sorter and into
90490** a register that is the source for a pseudo-table cursor created using
90491** OpenPseudo. That pseudo-table cursor is the one that is identified by
90492** parameter P3. Clearing the P3 column cache as part of this opcode saves
90493** us from having to issue a separate NullRow instruction to clear that cache.
90494*/
90495case OP_SorterData: {
90496 VdbeCursor *pC;
90497
90498 pOut = &aMem[pOp->p2];
90499 pC = p->apCsr[pOp->p1];
90500 assert( isSorter(pC) );
90501 rc = sqlite3VdbeSorterRowkey(pC, pOut);
90502 assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
90503 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90504 if( rc ) goto abort_due_to_error;
90505 p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
90506 break;
90507}
90508
90509/* Opcode: RowData P1 P2 P3 * *
90510** Synopsis: r[P2]=data
90511**
90512** Write into register P2 the complete row content for the row at
90513** which cursor P1 is currently pointing.
90514** There is no interpretation of the data.
90515** It is just copied onto the P2 register exactly as
90516** it is found in the database file.
90517**
90518** If cursor P1 is an index, then the content is the key of the row.
90519** If cursor P2 is a table, then the content extracted is the data.
90520**
90521** If the P1 cursor must be pointing to a valid row (not a NULL row)
90522** of a real table, not a pseudo-table.
90523**
90524** If P3!=0 then this opcode is allowed to make an ephemeral pointer
90525** into the database page. That means that the content of the output
90526** register will be invalidated as soon as the cursor moves - including
90527** moves caused by other cursors that "save" the current cursors
90528** position in order that they can write to the same table. If P3==0
90529** then a copy of the data is made into memory. P3!=0 is faster, but
90530** P3==0 is safer.
90531**
90532** If P3!=0 then the content of the P2 register is unsuitable for use
90533** in OP_Result and any OP_Result will invalidate the P2 register content.
90534** The P2 register content is invalidated by opcodes like OP_Function or
90535** by any use of another cursor pointing to the same table.
90536*/
90537case OP_RowData: {
90538 VdbeCursor *pC;
90539 BtCursor *pCrsr;
90540 u32 n;
90541
90542 pOut = out2Prerelease(p, pOp);
90543
90544 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90545 pC = p->apCsr[pOp->p1];
90546 assert( pC!=0 );
90547 assert( pC->eCurType==CURTYPE_BTREE );
90548 assert( isSorter(pC)==0 );
90549 assert( pC->nullRow==0 );
90550 assert( pC->uc.pCursor!=0 );
90551 pCrsr = pC->uc.pCursor;
90552
90553 /* The OP_RowData opcodes always follow OP_NotExists or
90554 ** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
90555 ** that might invalidate the cursor.
90556 ** If this where not the case, on of the following assert()s
90557 ** would fail. Should this ever change (because of changes in the code
90558 ** generator) then the fix would be to insert a call to
90559 ** sqlite3VdbeCursorMoveto().
90560 */
90561 assert( pC->deferredMoveto==0 );
90562 assert( sqlite3BtreeCursorIsValid(pCrsr) );
90563
90564 n = sqlite3BtreePayloadSize(pCrsr);
90565 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
90566 goto too_big;
90567 }
90568 testcase( n==0 );
90569 rc = sqlite3VdbeMemFromBtreeZeroOffset(pCrsr, n, pOut);
90570 if( rc ) goto abort_due_to_error;
90571 if( !pOp->p3 ) Deephemeralize(pOut);
90572 UPDATE_MAX_BLOBSIZE(pOut);
90573 REGISTER_TRACE(pOp->p2, pOut);
90574 break;
90575}
90576
90577/* Opcode: Rowid P1 P2 * * *
90578** Synopsis: r[P2]=rowid
90579**
90580** Store in register P2 an integer which is the key of the table entry that
90581** P1 is currently point to.
90582**
90583** P1 can be either an ordinary table or a virtual table. There used to
90584** be a separate OP_VRowid opcode for use with virtual tables, but this
90585** one opcode now works for both table types.
90586*/
90587case OP_Rowid: { /* out2 */
90588 VdbeCursor *pC;
90589 i64 v;
90590 sqlite3_vtab *pVtab;
90591 const sqlite3_module *pModule;
90592
90593 pOut = out2Prerelease(p, pOp);
90594 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90595 pC = p->apCsr[pOp->p1];
90596 assert( pC!=0 );
90597 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
90598 if( pC->nullRow ){
90599 pOut->flags = MEM_Null;
90600 break;
90601 }else if( pC->deferredMoveto ){
90602 v = pC->movetoTarget;
90603#ifndef SQLITE_OMIT_VIRTUALTABLE
90604 }else if( pC->eCurType==CURTYPE_VTAB ){
90605 assert( pC->uc.pVCur!=0 );
90606 pVtab = pC->uc.pVCur->pVtab;
90607 pModule = pVtab->pModule;
90608 assert( pModule->xRowid );
90609 rc = pModule->xRowid(pC->uc.pVCur, &v);
90610 sqlite3VtabImportErrmsg(p, pVtab);
90611 if( rc ) goto abort_due_to_error;
90612#endif /* SQLITE_OMIT_VIRTUALTABLE */
90613 }else{
90614 assert( pC->eCurType==CURTYPE_BTREE );
90615 assert( pC->uc.pCursor!=0 );
90616 rc = sqlite3VdbeCursorRestore(pC);
90617 if( rc ) goto abort_due_to_error;
90618 if( pC->nullRow ){
90619 pOut->flags = MEM_Null;
90620 break;
90621 }
90623 }
90624 pOut->u.i = v;
90625 break;
90626}
90627
90628/* Opcode: NullRow P1 * * * *
90629**
90630** Move the cursor P1 to a null row. Any OP_Column operations
90631** that occur while the cursor is on the null row will always
90632** write a NULL.
90633*/
90634case OP_NullRow: {
90635 VdbeCursor *pC;
90636
90637 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90638 pC = p->apCsr[pOp->p1];
90639 assert( pC!=0 );
90640 pC->nullRow = 1;
90642 if( pC->eCurType==CURTYPE_BTREE ){
90643 assert( pC->uc.pCursor!=0 );
90645 }
90646#ifdef SQLITE_DEBUG
90647 if( pC->seekOp==0 ) pC->seekOp = OP_NullRow;
90648#endif
90649 break;
90650}
90651
90652/* Opcode: SeekEnd P1 * * * *
90653**
90654** Position cursor P1 at the end of the btree for the purpose of
90655** appending a new entry onto the btree.
90656**
90657** It is assumed that the cursor is used only for appending and so
90658** if the cursor is valid, then the cursor must already be pointing
90659** at the end of the btree and so no changes are made to
90660** the cursor.
90661*/
90662/* Opcode: Last P1 P2 * * *
90663**
90664** The next use of the Rowid or Column or Prev instruction for P1
90665** will refer to the last entry in the database table or index.
90666** If the table or index is empty and P2>0, then jump immediately to P2.
90667** If P2 is 0 or if the table or index is not empty, fall through
90668** to the following instruction.
90669**
90670** This opcode leaves the cursor configured to move in reverse order,
90671** from the end toward the beginning. In other words, the cursor is
90672** configured to use Prev, not Next.
90673*/
90674case OP_SeekEnd:
90675case OP_Last: { /* jump */
90676 VdbeCursor *pC;
90677 BtCursor *pCrsr;
90678 int res;
90679
90680 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90681 pC = p->apCsr[pOp->p1];
90682 assert( pC!=0 );
90683 assert( pC->eCurType==CURTYPE_BTREE );
90684 pCrsr = pC->uc.pCursor;
90685 res = 0;
90686 assert( pCrsr!=0 );
90687#ifdef SQLITE_DEBUG
90688 pC->seekOp = pOp->opcode;
90689#endif
90690 if( pOp->opcode==OP_SeekEnd ){
90691 assert( pOp->p2==0 );
90692 pC->seekResult = -1;
90693 if( sqlite3BtreeCursorIsValidNN(pCrsr) ){
90694 break;
90695 }
90696 }
90697 rc = sqlite3BtreeLast(pCrsr, &res);
90698 pC->nullRow = (u8)res;
90699 pC->deferredMoveto = 0;
90701 if( rc ) goto abort_due_to_error;
90702 if( pOp->p2>0 ){
90703 VdbeBranchTaken(res!=0,2);
90704 if( res ) goto jump_to_p2;
90705 }
90706 break;
90707}
90708
90709/* Opcode: IfSmaller P1 P2 P3 * *
90710**
90711** Estimate the number of rows in the table P1. Jump to P2 if that
90712** estimate is less than approximately 2**(0.1*P3).
90713*/
90714case OP_IfSmaller: { /* jump */
90715 VdbeCursor *pC;
90716 BtCursor *pCrsr;
90717 int res;
90718 i64 sz;
90719
90720 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90721 pC = p->apCsr[pOp->p1];
90722 assert( pC!=0 );
90723 pCrsr = pC->uc.pCursor;
90724 assert( pCrsr );
90725 rc = sqlite3BtreeFirst(pCrsr, &res);
90726 if( rc ) goto abort_due_to_error;
90727 if( res==0 ){
90728 sz = sqlite3BtreeRowCountEst(pCrsr);
90729 if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)<pOp->p3 ) res = 1;
90730 }
90731 VdbeBranchTaken(res!=0,2);
90732 if( res ) goto jump_to_p2;
90733 break;
90734}
90735
90736
90737/* Opcode: SorterSort P1 P2 * * *
90738**
90739** After all records have been inserted into the Sorter object
90740** identified by P1, invoke this opcode to actually do the sorting.
90741** Jump to P2 if there are no records to be sorted.
90742**
90743** This opcode is an alias for OP_Sort and OP_Rewind that is used
90744** for Sorter objects.
90745*/
90746/* Opcode: Sort P1 P2 * * *
90747**
90748** This opcode does exactly the same thing as OP_Rewind except that
90749** it increments an undocumented global variable used for testing.
90750**
90751** Sorting is accomplished by writing records into a sorting index,
90752** then rewinding that index and playing it back from beginning to
90753** end. We use the OP_Sort opcode instead of OP_Rewind to do the
90754** rewinding so that the global variable will be incremented and
90755** regression tests can determine whether or not the optimizer is
90756** correctly optimizing out sorts.
90757*/
90758case OP_SorterSort: /* jump */
90759case OP_Sort: { /* jump */
90760#ifdef SQLITE_TEST
90761 sqlite3_sort_count++;
90762 sqlite3_search_count--;
90763#endif
90765 /* Fall through into OP_Rewind */
90766 /* no break */ deliberate_fall_through
90767}
90768/* Opcode: Rewind P1 P2 * * *
90769**
90770** The next use of the Rowid or Column or Next instruction for P1
90771** will refer to the first entry in the database table or index.
90772** If the table or index is empty, jump immediately to P2.
90773** If the table or index is not empty, fall through to the following
90774** instruction.
90775**
90776** This opcode leaves the cursor configured to move in forward order,
90777** from the beginning toward the end. In other words, the cursor is
90778** configured to use Next, not Prev.
90779*/
90780case OP_Rewind: { /* jump */
90781 VdbeCursor *pC;
90782 BtCursor *pCrsr;
90783 int res;
90784
90785 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90786 assert( pOp->p5==0 );
90787 pC = p->apCsr[pOp->p1];
90788 assert( pC!=0 );
90789 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
90790 res = 1;
90791#ifdef SQLITE_DEBUG
90792 pC->seekOp = OP_Rewind;
90793#endif
90794 if( isSorter(pC) ){
90795 rc = sqlite3VdbeSorterRewind(pC, &res);
90796 }else{
90797 assert( pC->eCurType==CURTYPE_BTREE );
90798 pCrsr = pC->uc.pCursor;
90799 assert( pCrsr );
90800 rc = sqlite3BtreeFirst(pCrsr, &res);
90801 pC->deferredMoveto = 0;
90803 }
90804 if( rc ) goto abort_due_to_error;
90805 pC->nullRow = (u8)res;
90806 assert( pOp->p2>0 && pOp->p2<p->nOp );
90807 VdbeBranchTaken(res!=0,2);
90808 if( res ) goto jump_to_p2;
90809 break;
90810}
90811
90812/* Opcode: Next P1 P2 P3 P4 P5
90813**
90814** Advance cursor P1 so that it points to the next key/data pair in its
90815** table or index. If there are no more key/value pairs then fall through
90816** to the following instruction. But if the cursor advance was successful,
90817** jump immediately to P2.
90818**
90819** The Next opcode is only valid following an SeekGT, SeekGE, or
90820** OP_Rewind opcode used to position the cursor. Next is not allowed
90821** to follow SeekLT, SeekLE, or OP_Last.
90822**
90823** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
90824** been opened prior to this opcode or the program will segfault.
90825**
90826** The P3 value is a hint to the btree implementation. If P3==1, that
90827** means P1 is an SQL index and that this instruction could have been
90828** omitted if that index had been unique. P3 is usually 0. P3 is
90829** always either 0 or 1.
90830**
90831** P4 is always of type P4_ADVANCE. The function pointer points to
90832** sqlite3BtreeNext().
90833**
90834** If P5 is positive and the jump is taken, then event counter
90835** number P5-1 in the prepared statement is incremented.
90836**
90837** See also: Prev
90838*/
90839/* Opcode: Prev P1 P2 P3 P4 P5
90840**
90841** Back up cursor P1 so that it points to the previous key/data pair in its
90842** table or index. If there is no previous key/value pairs then fall through
90843** to the following instruction. But if the cursor backup was successful,
90844** jump immediately to P2.
90845**
90846**
90847** The Prev opcode is only valid following an SeekLT, SeekLE, or
90848** OP_Last opcode used to position the cursor. Prev is not allowed
90849** to follow SeekGT, SeekGE, or OP_Rewind.
90850**
90851** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
90852** not open then the behavior is undefined.
90853**
90854** The P3 value is a hint to the btree implementation. If P3==1, that
90855** means P1 is an SQL index and that this instruction could have been
90856** omitted if that index had been unique. P3 is usually 0. P3 is
90857** always either 0 or 1.
90858**
90859** P4 is always of type P4_ADVANCE. The function pointer points to
90860** sqlite3BtreePrevious().
90861**
90862** If P5 is positive and the jump is taken, then event counter
90863** number P5-1 in the prepared statement is incremented.
90864*/
90865/* Opcode: SorterNext P1 P2 * * P5
90866**
90867** This opcode works just like OP_Next except that P1 must be a
90868** sorter object for which the OP_SorterSort opcode has been
90869** invoked. This opcode advances the cursor to the next sorted
90870** record, or jumps to P2 if there are no more sorted records.
90871*/
90872case OP_SorterNext: { /* jump */
90873 VdbeCursor *pC;
90874
90875 pC = p->apCsr[pOp->p1];
90876 assert( isSorter(pC) );
90877 rc = sqlite3VdbeSorterNext(db, pC);
90878 goto next_tail;
90879case OP_Prev: /* jump */
90880case OP_Next: /* jump */
90881 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90882 assert( pOp->p5<ArraySize(p->aCounter) );
90883 pC = p->apCsr[pOp->p1];
90884 assert( pC!=0 );
90885 assert( pC->deferredMoveto==0 );
90886 assert( pC->eCurType==CURTYPE_BTREE );
90887 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
90888 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
90889
90890 /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found.
90891 ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */
90892 assert( pOp->opcode!=OP_Next
90893 || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
90894 || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found
90895 || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid
90896 || pC->seekOp==OP_IfNoHope);
90897 assert( pOp->opcode!=OP_Prev
90898 || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
90899 || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
90900 || pC->seekOp==OP_NullRow);
90901
90902 rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3);
90903next_tail:
90906 if( rc==SQLITE_OK ){
90907 pC->nullRow = 0;
90908 p->aCounter[pOp->p5]++;
90909#ifdef SQLITE_TEST
90910 sqlite3_search_count++;
90911#endif
90912 goto jump_to_p2_and_check_for_interrupt;
90913 }
90914 if( rc!=SQLITE_DONE ) goto abort_due_to_error;
90915 rc = SQLITE_OK;
90916 pC->nullRow = 1;
90917 goto check_for_interrupt;
90918}
90919
90920/* Opcode: IdxInsert P1 P2 P3 P4 P5
90921** Synopsis: key=r[P2]
90922**
90923** Register P2 holds an SQL index key made using the
90924** MakeRecord instructions. This opcode writes that key
90925** into the index P1. Data for the entry is nil.
90926**
90927** If P4 is not zero, then it is the number of values in the unpacked
90928** key of reg(P2). In that case, P3 is the index of the first register
90929** for the unpacked key. The availability of the unpacked key can sometimes
90930** be an optimization.
90931**
90932** If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
90933** that this insert is likely to be an append.
90934**
90935** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
90936** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
90937** then the change counter is unchanged.
90938**
90939** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
90940** run faster by avoiding an unnecessary seek on cursor P1. However,
90941** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
90942** seeks on the cursor or if the most recent seek used a key equivalent
90943** to P2.
90944**
90945** This instruction only works for indices. The equivalent instruction
90946** for tables is OP_Insert.
90947*/
90948case OP_IdxInsert: { /* in2 */
90949 VdbeCursor *pC;
90950 BtreePayload x;
90951
90952 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90953 pC = p->apCsr[pOp->p1];
90955 assert( pC!=0 );
90956 assert( !isSorter(pC) );
90957 pIn2 = &aMem[pOp->p2];
90958 assert( pIn2->flags & MEM_Blob );
90959 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
90960 assert( pC->eCurType==CURTYPE_BTREE );
90961 assert( pC->isTable==0 );
90962 rc = ExpandBlob(pIn2);
90963 if( rc ) goto abort_due_to_error;
90964 x.nKey = pIn2->n;
90965 x.pKey = pIn2->z;
90966 x.aMem = aMem + pOp->p3;
90967 x.nMem = (u16)pOp->p4.i;
90968 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
90970 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
90971 );
90972 assert( pC->deferredMoveto==0 );
90974 if( rc) goto abort_due_to_error;
90975 break;
90976}
90977
90978/* Opcode: SorterInsert P1 P2 * * *
90979** Synopsis: key=r[P2]
90980**
90981** Register P2 holds an SQL index key made using the
90982** MakeRecord instructions. This opcode writes that key
90983** into the sorter P1. Data for the entry is nil.
90984*/
90985case OP_SorterInsert: { /* in2 */
90986 VdbeCursor *pC;
90987
90988 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90989 pC = p->apCsr[pOp->p1];
90991 assert( pC!=0 );
90992 assert( isSorter(pC) );
90993 pIn2 = &aMem[pOp->p2];
90994 assert( pIn2->flags & MEM_Blob );
90995 assert( pC->isTable==0 );
90996 rc = ExpandBlob(pIn2);
90997 if( rc ) goto abort_due_to_error;
90998 rc = sqlite3VdbeSorterWrite(pC, pIn2);
90999 if( rc) goto abort_due_to_error;
91000 break;
91001}
91002
91003/* Opcode: IdxDelete P1 P2 P3 * P5
91004** Synopsis: key=r[P2@P3]
91005**
91006** The content of P3 registers starting at register P2 form
91007** an unpacked index key. This opcode removes that entry from the
91008** index opened by cursor P1.
91009**
91010** If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error
91011** if no matching index entry is found. This happens when running
91012** an UPDATE or DELETE statement and the index entry to be updated
91013** or deleted is not found. For some uses of IdxDelete
91014** (example: the EXCEPT operator) it does not matter that no matching
91015** entry is found. For those cases, P5 is zero.
91016*/
91017case OP_IdxDelete: {
91018 VdbeCursor *pC;
91019 BtCursor *pCrsr;
91020 int res;
91022
91023 assert( pOp->p3>0 );
91024 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem+1 - p->nCursor)+1 );
91025 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91026 pC = p->apCsr[pOp->p1];
91027 assert( pC!=0 );
91028 assert( pC->eCurType==CURTYPE_BTREE );
91030 pCrsr = pC->uc.pCursor;
91031 assert( pCrsr!=0 );
91032 r.pKeyInfo = pC->pKeyInfo;
91033 r.nField = (u16)pOp->p3;
91034 r.default_rc = 0;
91035 r.aMem = &aMem[pOp->p2];
91036 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
91037 if( rc ) goto abort_due_to_error;
91038 if( res==0 ){
91040 if( rc ) goto abort_due_to_error;
91041 }else if( pOp->p5 ){
91043 goto abort_due_to_error;
91044 }
91045 assert( pC->deferredMoveto==0 );
91047 pC->seekResult = 0;
91048 break;
91049}
91050
91051/* Opcode: DeferredSeek P1 * P3 P4 *
91052** Synopsis: Move P3 to P1.rowid if needed
91053**
91054** P1 is an open index cursor and P3 is a cursor on the corresponding
91055** table. This opcode does a deferred seek of the P3 table cursor
91056** to the row that corresponds to the current row of P1.
91057**
91058** This is a deferred seek. Nothing actually happens until
91059** the cursor is used to read a record. That way, if no reads
91060** occur, no unnecessary I/O happens.
91061**
91062** P4 may be an array of integers (type P4_INTARRAY) containing
91063** one entry for each column in the P3 table. If array entry a(i)
91064** is non-zero, then reading column a(i)-1 from cursor P3 is
91065** equivalent to performing the deferred seek and then reading column i
91066** from P1. This information is stored in P3 and used to redirect
91067** reads against P3 over to P1, thus possibly avoiding the need to
91068** seek and read cursor P3.
91069*/
91070/* Opcode: IdxRowid P1 P2 * * *
91071** Synopsis: r[P2]=rowid
91072**
91073** Write into register P2 an integer which is the last entry in the record at
91074** the end of the index key pointed to by cursor P1. This integer should be
91075** the rowid of the table entry to which this index entry points.
91076**
91077** See also: Rowid, MakeRecord.
91078*/
91079case OP_DeferredSeek:
91080case OP_IdxRowid: { /* out2 */
91081 VdbeCursor *pC; /* The P1 index cursor */
91082 VdbeCursor *pTabCur; /* The P2 table cursor (OP_DeferredSeek only) */
91083 i64 rowid; /* Rowid that P1 current points to */
91084
91085 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91086 pC = p->apCsr[pOp->p1];
91087 assert( pC!=0 );
91088 assert( pC->eCurType==CURTYPE_BTREE );
91089 assert( pC->uc.pCursor!=0 );
91090 assert( pC->isTable==0 );
91091 assert( pC->deferredMoveto==0 );
91092 assert( !pC->nullRow || pOp->opcode==OP_IdxRowid );
91093
91094 /* The IdxRowid and Seek opcodes are combined because of the commonality
91095 ** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
91096 rc = sqlite3VdbeCursorRestore(pC);
91097
91098 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
91099 ** out from under the cursor. That will never happens for an IdxRowid
91100 ** or Seek opcode */
91101 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
91102
91103 if( !pC->nullRow ){
91104 rowid = 0; /* Not needed. Only used to silence a warning. */
91105 rc = sqlite3VdbeIdxRowid(db, pC->uc.pCursor, &rowid);
91106 if( rc!=SQLITE_OK ){
91107 goto abort_due_to_error;
91108 }
91109 if( pOp->opcode==OP_DeferredSeek ){
91110 assert( pOp->p3>=0 && pOp->p3<p->nCursor );
91111 pTabCur = p->apCsr[pOp->p3];
91112 assert( pTabCur!=0 );
91113 assert( pTabCur->eCurType==CURTYPE_BTREE );
91114 assert( pTabCur->uc.pCursor!=0 );
91115 assert( pTabCur->isTable );
91116 pTabCur->nullRow = 0;
91117 pTabCur->movetoTarget = rowid;
91118 pTabCur->deferredMoveto = 1;
91119 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
91120 pTabCur->aAltMap = pOp->p4.ai;
91121 pTabCur->pAltCursor = pC;
91122 }else{
91123 pOut = out2Prerelease(p, pOp);
91124 pOut->u.i = rowid;
91125 }
91126 }else{
91127 assert( pOp->opcode==OP_IdxRowid );
91128 sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
91129 }
91130 break;
91131}
91132
91133/* Opcode: FinishSeek P1 * * * *
91134**
91135** If cursor P1 was previously moved via OP_DeferredSeek, complete that
91136** seek operation now, without further delay. If the cursor seek has
91137** already occurred, this instruction is a no-op.
91138*/
91139case OP_FinishSeek: {
91140 VdbeCursor *pC; /* The P1 index cursor */
91141
91142 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91143 pC = p->apCsr[pOp->p1];
91144 if( pC->deferredMoveto ){
91145 rc = sqlite3VdbeFinishMoveto(pC);
91146 if( rc ) goto abort_due_to_error;
91147 }
91148 break;
91149}
91150
91151/* Opcode: IdxGE P1 P2 P3 P4 P5
91152** Synopsis: key=r[P3@P4]
91153**
91154** The P4 register values beginning with P3 form an unpacked index
91155** key that omits the PRIMARY KEY. Compare this key value against the index
91156** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
91157** fields at the end.
91158**
91159** If the P1 index entry is greater than or equal to the key value
91160** then jump to P2. Otherwise fall through to the next instruction.
91161*/
91162/* Opcode: IdxGT P1 P2 P3 P4 P5
91163** Synopsis: key=r[P3@P4]
91164**
91165** The P4 register values beginning with P3 form an unpacked index
91166** key that omits the PRIMARY KEY. Compare this key value against the index
91167** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
91168** fields at the end.
91169**
91170** If the P1 index entry is greater than the key value
91171** then jump to P2. Otherwise fall through to the next instruction.
91172*/
91173/* Opcode: IdxLT P1 P2 P3 P4 P5
91174** Synopsis: key=r[P3@P4]
91175**
91176** The P4 register values beginning with P3 form an unpacked index
91177** key that omits the PRIMARY KEY or ROWID. Compare this key value against
91178** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
91179** ROWID on the P1 index.
91180**
91181** If the P1 index entry is less than the key value then jump to P2.
91182** Otherwise fall through to the next instruction.
91183*/
91184/* Opcode: IdxLE P1 P2 P3 P4 P5
91185** Synopsis: key=r[P3@P4]
91186**
91187** The P4 register values beginning with P3 form an unpacked index
91188** key that omits the PRIMARY KEY or ROWID. Compare this key value against
91189** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
91190** ROWID on the P1 index.
91191**
91192** If the P1 index entry is less than or equal to the key value then jump
91193** to P2. Otherwise fall through to the next instruction.
91194*/
91195case OP_IdxLE: /* jump */
91196case OP_IdxGT: /* jump */
91197case OP_IdxLT: /* jump */
91198case OP_IdxGE: { /* jump */
91199 VdbeCursor *pC;
91200 int res;
91202
91203 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91204 pC = p->apCsr[pOp->p1];
91205 assert( pC!=0 );
91206 assert( pC->isOrdered );
91207 assert( pC->eCurType==CURTYPE_BTREE );
91208 assert( pC->uc.pCursor!=0);
91209 assert( pC->deferredMoveto==0 );
91210 assert( pOp->p5==0 || pOp->p5==1 );
91211 assert( pOp->p4type==P4_INT32 );
91212 r.pKeyInfo = pC->pKeyInfo;
91213 r.nField = (u16)pOp->p4.i;
91214 if( pOp->opcode<OP_IdxLT ){
91215 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
91216 r.default_rc = -1;
91217 }else{
91218 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
91219 r.default_rc = 0;
91220 }
91221 r.aMem = &aMem[pOp->p3];
91222#ifdef SQLITE_DEBUG
91223 {
91224 int i;
91225 for(i=0; i<r.nField; i++){
91226 assert( memIsValid(&r.aMem[i]) );
91227 REGISTER_TRACE(pOp->p3+i, &aMem[pOp->p3+i]);
91228 }
91229 }
91230#endif
91231 res = 0; /* Not needed. Only used to silence a warning. */
91232 rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
91233 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
91234 if( (pOp->opcode&1)==(OP_IdxLT&1) ){
91235 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
91236 res = -res;
91237 }else{
91238 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
91239 res++;
91240 }
91241 VdbeBranchTaken(res>0,2);
91242 if( rc ) goto abort_due_to_error;
91243 if( res>0 ) goto jump_to_p2;
91244 break;
91245}
91246
91247/* Opcode: Destroy P1 P2 P3 * *
91248**
91249** Delete an entire database table or index whose root page in the database
91250** file is given by P1.
91251**
91252** The table being destroyed is in the main database file if P3==0. If
91253** P3==1 then the table to be clear is in the auxiliary database file
91254** that is used to store tables create using CREATE TEMPORARY TABLE.
91255**
91256** If AUTOVACUUM is enabled then it is possible that another root page
91257** might be moved into the newly deleted root page in order to keep all
91258** root pages contiguous at the beginning of the database. The former
91259** value of the root page that moved - its value before the move occurred -
91260** is stored in register P2. If no page movement was required (because the
91261** table being dropped was already the last one in the database) then a
91262** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
91263** is stored in register P2.
91264**
91265** This opcode throws an error if there are any active reader VMs when
91266** it is invoked. This is done to avoid the difficulty associated with
91267** updating existing cursors when a root page is moved in an AUTOVACUUM
91268** database. This error is thrown even if the database is not an AUTOVACUUM
91269** db in order to avoid introducing an incompatibility between autovacuum
91270** and non-autovacuum modes.
91271**
91272** See also: Clear
91273*/
91274case OP_Destroy: { /* out2 */
91275 int iMoved;
91276 int iDb;
91277
91279 assert( p->readOnly==0 );
91280 assert( pOp->p1>1 );
91281 pOut = out2Prerelease(p, pOp);
91282 pOut->flags = MEM_Null;
91283 if( db->nVdbeRead > db->nVDestroy+1 ){
91284 rc = SQLITE_LOCKED;
91285 p->errorAction = OE_Abort;
91286 goto abort_due_to_error;
91287 }else{
91288 iDb = pOp->p3;
91289 assert( DbMaskTest(p->btreeMask, iDb) );
91290 iMoved = 0; /* Not needed. Only to silence a warning. */
91291 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
91292 pOut->flags = MEM_Int;
91293 pOut->u.i = iMoved;
91294 if( rc ) goto abort_due_to_error;
91295#ifndef SQLITE_OMIT_AUTOVACUUM
91296 if( iMoved!=0 ){
91297 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
91298 /* All OP_Destroy operations occur on the same btree */
91299 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
91300 resetSchemaOnFault = iDb+1;
91301 }
91302#endif
91303 }
91304 break;
91305}
91306
91307/* Opcode: Clear P1 P2 P3
91308**
91309** Delete all contents of the database table or index whose root page
91310** in the database file is given by P1. But, unlike Destroy, do not
91311** remove the table or index from the database file.
91312**
91313** The table being clear is in the main database file if P2==0. If
91314** P2==1 then the table to be clear is in the auxiliary database file
91315** that is used to store tables create using CREATE TEMPORARY TABLE.
91316**
91317** If the P3 value is non-zero, then the table referred to must be an
91318** intkey table (an SQL table, not an index). In this case the row change
91319** count is incremented by the number of rows in the table being cleared.
91320** If P3 is greater than zero, then the value stored in register P3 is
91321** also incremented by the number of rows in the table being cleared.
91322**
91323** See also: Destroy
91324*/
91325case OP_Clear: {
91326 int nChange;
91327
91329 nChange = 0;
91330 assert( p->readOnly==0 );
91331 assert( DbMaskTest(p->btreeMask, pOp->p2) );
91333 db->aDb[pOp->p2].pBt, (u32)pOp->p1, (pOp->p3 ? &nChange : 0)
91334 );
91335 if( pOp->p3 ){
91336 p->nChange += nChange;
91337 if( pOp->p3>0 ){
91338 assert( memIsValid(&aMem[pOp->p3]) );
91339 memAboutToChange(p, &aMem[pOp->p3]);
91340 aMem[pOp->p3].u.i += nChange;
91341 }
91342 }
91343 if( rc ) goto abort_due_to_error;
91344 break;
91345}
91346
91347/* Opcode: ResetSorter P1 * * * *
91348**
91349** Delete all contents from the ephemeral table or sorter
91350** that is open on cursor P1.
91351**
91352** This opcode only works for cursors used for sorting and
91353** opened with OP_OpenEphemeral or OP_SorterOpen.
91354*/
91355case OP_ResetSorter: {
91356 VdbeCursor *pC;
91357
91358 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91359 pC = p->apCsr[pOp->p1];
91360 assert( pC!=0 );
91361 if( isSorter(pC) ){
91363 }else{
91364 assert( pC->eCurType==CURTYPE_BTREE );
91365 assert( pC->isEphemeral );
91367 if( rc ) goto abort_due_to_error;
91368 }
91369 break;
91370}
91371
91372/* Opcode: CreateBtree P1 P2 P3 * *
91373** Synopsis: r[P2]=root iDb=P1 flags=P3
91374**
91375** Allocate a new b-tree in the main database file if P1==0 or in the
91376** TEMP database file if P1==1 or in an attached database if
91377** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
91378** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
91379** The root page number of the new b-tree is stored in register P2.
91380*/
91381case OP_CreateBtree: { /* out2 */
91382 Pgno pgno;
91383 Db *pDb;
91384
91386 pOut = out2Prerelease(p, pOp);
91387 pgno = 0;
91388 assert( pOp->p3==BTREE_INTKEY || pOp->p3==BTREE_BLOBKEY );
91389 assert( pOp->p1>=0 && pOp->p1<db->nDb );
91390 assert( DbMaskTest(p->btreeMask, pOp->p1) );
91391 assert( p->readOnly==0 );
91392 pDb = &db->aDb[pOp->p1];
91393 assert( pDb->pBt!=0 );
91394 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, pOp->p3);
91395 if( rc ) goto abort_due_to_error;
91396 pOut->u.i = pgno;
91397 break;
91398}
91399
91400/* Opcode: SqlExec * * * P4 *
91401**
91402** Run the SQL statement or statements specified in the P4 string.
91403*/
91404case OP_SqlExec: {
91406 db->nSqlExec++;
91407 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, 0);
91408 db->nSqlExec--;
91409 if( rc ) goto abort_due_to_error;
91410 break;
91411}
91412
91413/* Opcode: ParseSchema P1 * * P4 *
91414**
91415** Read and parse all entries from the schema table of database P1
91416** that match the WHERE clause P4. If P4 is a NULL pointer, then the
91417** entire schema for P1 is reparsed.
91418**
91419** This opcode invokes the parser to create a new virtual machine,
91420** then runs the new virtual machine. It is thus a re-entrant opcode.
91421*/
91422case OP_ParseSchema: {
91423 int iDb;
91424 const char *zSchema;
91425 char *zSql;
91426 InitData initData;
91427
91428 /* Any prepared statement that invokes this opcode will hold mutexes
91429 ** on every btree. This is a prerequisite for invoking
91430 ** sqlite3InitCallback().
91431 */
91432#ifdef SQLITE_DEBUG
91433 for(iDb=0; iDb<db->nDb; iDb++){
91434 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
91435 }
91436#endif
91437
91438 iDb = pOp->p1;
91439 assert( iDb>=0 && iDb<db->nDb );
91440 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
91441
91442#ifndef SQLITE_OMIT_ALTERTABLE
91443 if( pOp->p4.z==0 ){
91444 sqlite3SchemaClear(db->aDb[iDb].pSchema);
91445 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
91446 rc = sqlite3InitOne(db, iDb, &p->zErrMsg, INITFLAG_AlterTable);
91448 p->expired = 0;
91449 }else
91450#endif
91451 {
91452 zSchema = DFLT_SCHEMA_TABLE;
91453 initData.db = db;
91454 initData.iDb = iDb;
91455 initData.pzErrMsg = &p->zErrMsg;
91456 initData.mInitFlags = 0;
91457 initData.mxPage = sqlite3BtreeLastPage(db->aDb[iDb].pBt);
91458 zSql = sqlite3MPrintf(db,
91459 "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
91460 db->aDb[iDb].zDbSName, zSchema, pOp->p4.z);
91461 if( zSql==0 ){
91462 rc = SQLITE_NOMEM_BKPT;
91463 }else{
91464 assert( db->init.busy==0 );
91465 db->init.busy = 1;
91466 initData.rc = SQLITE_OK;
91467 initData.nInitRow = 0;
91468 assert( !db->mallocFailed );
91469 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
91470 if( rc==SQLITE_OK ) rc = initData.rc;
91471 if( rc==SQLITE_OK && initData.nInitRow==0 ){
91472 /* The OP_ParseSchema opcode with a non-NULL P4 argument should parse
91473 ** at least one SQL statement. Any less than that indicates that
91474 ** the sqlite_schema table is corrupt. */
91476 }
91477 sqlite3DbFreeNN(db, zSql);
91478 db->init.busy = 0;
91479 }
91480 }
91481 if( rc ){
91483 if( rc==SQLITE_NOMEM ){
91484 goto no_mem;
91485 }
91486 goto abort_due_to_error;
91487 }
91488 break;
91489}
91490
91491#if !defined(SQLITE_OMIT_ANALYZE)
91492/* Opcode: LoadAnalysis P1 * * * *
91493**
91494** Read the sqlite_stat1 table for database P1 and load the content
91495** of that table into the internal index hash table. This will cause
91496** the analysis to be used when preparing all subsequent queries.
91497*/
91498case OP_LoadAnalysis: {
91499 assert( pOp->p1>=0 && pOp->p1<db->nDb );
91500 rc = sqlite3AnalysisLoad(db, pOp->p1);
91501 if( rc ) goto abort_due_to_error;
91502 break;
91503}
91504#endif /* !defined(SQLITE_OMIT_ANALYZE) */
91505
91506/* Opcode: DropTable P1 * * P4 *
91507**
91508** Remove the internal (in-memory) data structures that describe
91509** the table named P4 in database P1. This is called after a table
91510** is dropped from disk (using the Destroy opcode) in order to keep
91511** the internal representation of the
91512** schema consistent with what is on disk.
91513*/
91514case OP_DropTable: {
91516 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
91517 break;
91518}
91519
91520/* Opcode: DropIndex P1 * * P4 *
91521**
91522** Remove the internal (in-memory) data structures that describe
91523** the index named P4 in database P1. This is called after an index
91524** is dropped from disk (using the Destroy opcode)
91525** in order to keep the internal representation of the
91526** schema consistent with what is on disk.
91527*/
91528case OP_DropIndex: {
91530 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
91531 break;
91532}
91533
91534/* Opcode: DropTrigger P1 * * P4 *
91535**
91536** Remove the internal (in-memory) data structures that describe
91537** the trigger named P4 in database P1. This is called after a trigger
91538** is dropped from disk (using the Destroy opcode) in order to keep
91539** the internal representation of the
91540** schema consistent with what is on disk.
91541*/
91542case OP_DropTrigger: {
91544 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
91545 break;
91546}
91547
91548
91549#ifndef SQLITE_OMIT_INTEGRITY_CHECK
91550/* Opcode: IntegrityCk P1 P2 P3 P4 P5
91551**
91552** Do an analysis of the currently open database. Store in
91553** register P1 the text of an error message describing any problems.
91554** If no problems are found, store a NULL in register P1.
91555**
91556** The register P3 contains one less than the maximum number of allowed errors.
91557** At most reg(P3) errors will be reported.
91558** In other words, the analysis stops as soon as reg(P1) errors are
91559** seen. Reg(P1) is updated with the number of errors remaining.
91560**
91561** The root page numbers of all tables in the database are integers
91562** stored in P4_INTARRAY argument.
91563**
91564** If P5 is not zero, the check is done on the auxiliary database
91565** file, not the main database file.
91566**
91567** This opcode is used to implement the integrity_check pragma.
91568*/
91569case OP_IntegrityCk: {
91570 int nRoot; /* Number of tables to check. (Number of root pages.) */
91571 Pgno *aRoot; /* Array of rootpage numbers for tables to be checked */
91572 int nErr; /* Number of errors reported */
91573 char *z; /* Text of the error report */
91574 Mem *pnErr; /* Register keeping track of errors remaining */
91575
91576 assert( p->bIsReader );
91577 nRoot = pOp->p2;
91578 aRoot = pOp->p4.ai;
91579 assert( nRoot>0 );
91580 assert( aRoot[0]==(Pgno)nRoot );
91581 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
91582 pnErr = &aMem[pOp->p3];
91583 assert( (pnErr->flags & MEM_Int)!=0 );
91584 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
91585 pIn1 = &aMem[pOp->p1];
91586 assert( pOp->p5<db->nDb );
91587 assert( DbMaskTest(p->btreeMask, pOp->p5) );
91588 z = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
91589 (int)pnErr->u.i+1, &nErr);
91591 if( nErr==0 ){
91592 assert( z==0 );
91593 }else if( z==0 ){
91594 goto no_mem;
91595 }else{
91596 pnErr->u.i -= nErr-1;
91598 }
91599 UPDATE_MAX_BLOBSIZE(pIn1);
91600 sqlite3VdbeChangeEncoding(pIn1, encoding);
91601 goto check_for_interrupt;
91602}
91603#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
91604
91605/* Opcode: RowSetAdd P1 P2 * * *
91606** Synopsis: rowset(P1)=r[P2]
91607**
91608** Insert the integer value held by register P2 into a RowSet object
91609** held in register P1.
91610**
91611** An assertion fails if P2 is not an integer.
91612*/
91613case OP_RowSetAdd: { /* in1, in2 */
91614 pIn1 = &aMem[pOp->p1];
91615 pIn2 = &aMem[pOp->p2];
91616 assert( (pIn2->flags & MEM_Int)!=0 );
91617 if( (pIn1->flags & MEM_Blob)==0 ){
91618 if( sqlite3VdbeMemSetRowSet(pIn1) ) goto no_mem;
91619 }
91620 assert( sqlite3VdbeMemIsRowSet(pIn1) );
91621 sqlite3RowSetInsert((RowSet*)pIn1->z, pIn2->u.i);
91622 break;
91623}
91624
91625/* Opcode: RowSetRead P1 P2 P3 * *
91626** Synopsis: r[P3]=rowset(P1)
91627**
91628** Extract the smallest value from the RowSet object in P1
91629** and put that value into register P3.
91630** Or, if RowSet object P1 is initially empty, leave P3
91631** unchanged and jump to instruction P2.
91632*/
91633case OP_RowSetRead: { /* jump, in1, out3 */
91634 i64 val;
91635
91636 pIn1 = &aMem[pOp->p1];
91637 assert( (pIn1->flags & MEM_Blob)==0 || sqlite3VdbeMemIsRowSet(pIn1) );
91638 if( (pIn1->flags & MEM_Blob)==0
91639 || sqlite3RowSetNext((RowSet*)pIn1->z, &val)==0
91640 ){
91641 /* The boolean index is empty */
91643 VdbeBranchTaken(1,2);
91644 goto jump_to_p2_and_check_for_interrupt;
91645 }else{
91646 /* A value was pulled from the index */
91647 VdbeBranchTaken(0,2);
91648 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
91649 }
91650 goto check_for_interrupt;
91651}
91652
91653/* Opcode: RowSetTest P1 P2 P3 P4
91654** Synopsis: if r[P3] in rowset(P1) goto P2
91655**
91656** Register P3 is assumed to hold a 64-bit integer value. If register P1
91657** contains a RowSet object and that RowSet object contains
91658** the value held in P3, jump to register P2. Otherwise, insert the
91659** integer in P3 into the RowSet and continue on to the
91660** next opcode.
91661**
91662** The RowSet object is optimized for the case where sets of integers
91663** are inserted in distinct phases, which each set contains no duplicates.
91664** Each set is identified by a unique P4 value. The first set
91665** must have P4==0, the final set must have P4==-1, and for all other sets
91666** must have P4>0.
91667**
91668** This allows optimizations: (a) when P4==0 there is no need to test
91669** the RowSet object for P3, as it is guaranteed not to contain it,
91670** (b) when P4==-1 there is no need to insert the value, as it will
91671** never be tested for, and (c) when a value that is part of set X is
91672** inserted, there is no need to search to see if the same value was
91673** previously inserted as part of set X (only if it was previously
91674** inserted as part of some other set).
91675*/
91676case OP_RowSetTest: { /* jump, in1, in3 */
91677 int iSet;
91678 int exists;
91679
91680 pIn1 = &aMem[pOp->p1];
91681 pIn3 = &aMem[pOp->p3];
91682 iSet = pOp->p4.i;
91683 assert( pIn3->flags&MEM_Int );
91684
91685 /* If there is anything other than a rowset object in memory cell P1,
91686 ** delete it now and initialize P1 with an empty rowset
91687 */
91688 if( (pIn1->flags & MEM_Blob)==0 ){
91689 if( sqlite3VdbeMemSetRowSet(pIn1) ) goto no_mem;
91690 }
91691 assert( sqlite3VdbeMemIsRowSet(pIn1) );
91692 assert( pOp->p4type==P4_INT32 );
91693 assert( iSet==-1 || iSet>=0 );
91694 if( iSet ){
91695 exists = sqlite3RowSetTest((RowSet*)pIn1->z, iSet, pIn3->u.i);
91696 VdbeBranchTaken(exists!=0,2);
91697 if( exists ) goto jump_to_p2;
91698 }
91699 if( iSet>=0 ){
91700 sqlite3RowSetInsert((RowSet*)pIn1->z, pIn3->u.i);
91701 }
91702 break;
91703}
91704
91705
91706#ifndef SQLITE_OMIT_TRIGGER
91707
91708/* Opcode: Program P1 P2 P3 P4 P5
91709**
91710** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
91711**
91712** P1 contains the address of the memory cell that contains the first memory
91713** cell in an array of values used as arguments to the sub-program. P2
91714** contains the address to jump to if the sub-program throws an IGNORE
91715** exception using the RAISE() function. Register P3 contains the address
91716** of a memory cell in this (the parent) VM that is used to allocate the
91717** memory required by the sub-vdbe at runtime.
91718**
91719** P4 is a pointer to the VM containing the trigger program.
91720**
91721** If P5 is non-zero, then recursive program invocation is enabled.
91722*/
91723case OP_Program: { /* jump */
91724 int nMem; /* Number of memory registers for sub-program */
91725 int nByte; /* Bytes of runtime space required for sub-program */
91726 Mem *pRt; /* Register to allocate runtime space */
91727 Mem *pMem; /* Used to iterate through memory cells */
91728 Mem *pEnd; /* Last memory cell in new array */
91729 VdbeFrame *pFrame; /* New vdbe frame to execute in */
91730 SubProgram *pProgram; /* Sub-program to execute */
91731 void *t; /* Token identifying trigger */
91732
91733 pProgram = pOp->p4.pProgram;
91734 pRt = &aMem[pOp->p3];
91735 assert( pProgram->nOp>0 );
91736
91737 /* If the p5 flag is clear, then recursive invocation of triggers is
91738 ** disabled for backwards compatibility (p5 is set if this sub-program
91739 ** is really a trigger, not a foreign key action, and the flag set
91740 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
91741 **
91742 ** It is recursive invocation of triggers, at the SQL level, that is
91743 ** disabled. In some cases a single trigger may generate more than one
91744 ** SubProgram (if the trigger may be executed with more than one different
91745 ** ON CONFLICT algorithm). SubProgram structures associated with a
91746 ** single trigger all have the same value for the SubProgram.token
91747 ** variable. */
91748 if( pOp->p5 ){
91749 t = pProgram->token;
91750 for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent);
91751 if( pFrame ) break;
91752 }
91753
91755 rc = SQLITE_ERROR;
91756 sqlite3VdbeError(p, "too many levels of trigger recursion");
91757 goto abort_due_to_error;
91758 }
91759
91760 /* Register pRt is used to store the memory required to save the state
91761 ** of the current program, and the memory required at runtime to execute
91762 ** the trigger program. If this trigger has been fired before, then pRt
91763 ** is already allocated. Otherwise, it must be initialized. */
91764 if( (pRt->flags&MEM_Blob)==0 ){
91765 /* SubProgram.nMem is set to the number of memory cells used by the
91766 ** program stored in SubProgram.aOp. As well as these, one memory
91767 ** cell is required for each cursor used by the program. Set local
91768 ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
91769 */
91770 nMem = pProgram->nMem + pProgram->nCsr;
91771 assert( nMem>0 );
91772 if( pProgram->nCsr==0 ) nMem++;
91773 nByte = ROUND8(sizeof(VdbeFrame))
91774 + nMem * sizeof(Mem)
91775 + pProgram->nCsr * sizeof(VdbeCursor*)
91776 + (pProgram->nOp + 7)/8;
91777 pFrame = sqlite3DbMallocZero(db, nByte);
91778 if( !pFrame ){
91779 goto no_mem;
91780 }
91782 pRt->flags = MEM_Blob|MEM_Dyn;
91783 pRt->z = (char*)pFrame;
91784 pRt->n = nByte;
91786
91787 pFrame->v = p;
91788 pFrame->nChildMem = nMem;
91789 pFrame->nChildCsr = pProgram->nCsr;
91790 pFrame->pc = (int)(pOp - aOp);
91791 pFrame->aMem = p->aMem;
91792 pFrame->nMem = p->nMem;
91793 pFrame->apCsr = p->apCsr;
91794 pFrame->nCursor = p->nCursor;
91795 pFrame->aOp = p->aOp;
91796 pFrame->nOp = p->nOp;
91797 pFrame->token = pProgram->token;
91798#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
91799 pFrame->anExec = p->anExec;
91800#endif
91801#ifdef SQLITE_DEBUG
91802 pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
91803#endif
91804
91805 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
91806 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
91807 pMem->flags = MEM_Undefined;
91808 pMem->db = db;
91809 }
91810 }else{
91811 pFrame = (VdbeFrame*)pRt->z;
91812 assert( pRt->xDel==sqlite3VdbeFrameMemDel );
91813 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem
91814 || (pProgram->nCsr==0 && pProgram->nMem+1==pFrame->nChildMem) );
91815 assert( pProgram->nCsr==pFrame->nChildCsr );
91816 assert( (int)(pOp - aOp)==pFrame->pc );
91817 }
91818
91819 p->nFrame++;
91820 pFrame->pParent = p->pFrame;
91821 pFrame->lastRowid = db->lastRowid;
91822 pFrame->nChange = p->nChange;
91823 pFrame->nDbChange = p->db->nChange;
91824 assert( pFrame->pAuxData==0 );
91825 pFrame->pAuxData = p->pAuxData;
91826 p->pAuxData = 0;
91827 p->nChange = 0;
91828 p->pFrame = pFrame;
91829 p->aMem = aMem = VdbeFrameMem(pFrame);
91830 p->nMem = pFrame->nChildMem;
91831 p->nCursor = (u16)pFrame->nChildCsr;
91832 p->apCsr = (VdbeCursor **)&aMem[p->nMem];
91833 pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
91834 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
91835 p->aOp = aOp = pProgram->aOp;
91836 p->nOp = pProgram->nOp;
91837#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
91838 p->anExec = 0;
91839#endif
91840#ifdef SQLITE_DEBUG
91841 /* Verify that second and subsequent executions of the same trigger do not
91842 ** try to reuse register values from the first use. */
91843 {
91844 int i;
91845 for(i=0; i<p->nMem; i++){
91846 aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */
91847 MemSetTypeFlag(&aMem[i], MEM_Undefined); /* Fault if this reg is reused */
91848 }
91849 }
91850#endif
91851 pOp = &aOp[-1];
91852 goto check_for_interrupt;
91853}
91854
91855/* Opcode: Param P1 P2 * * *
91856**
91857** This opcode is only ever present in sub-programs called via the
91858** OP_Program instruction. Copy a value currently stored in a memory
91859** cell of the calling (parent) frame to cell P2 in the current frames
91860** address space. This is used by trigger programs to access the new.*
91861** and old.* values.
91862**
91863** The address of the cell in the parent frame is determined by adding
91864** the value of the P1 argument to the value of the P1 argument to the
91865** calling OP_Program instruction.
91866*/
91867case OP_Param: { /* out2 */
91868 VdbeFrame *pFrame;
91869 Mem *pIn;
91870 pOut = out2Prerelease(p, pOp);
91871 pFrame = p->pFrame;
91872 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
91874 break;
91875}
91876
91877#endif /* #ifndef SQLITE_OMIT_TRIGGER */
91878
91879#ifndef SQLITE_OMIT_FOREIGN_KEY
91880/* Opcode: FkCounter P1 P2 * * *
91881** Synopsis: fkctr[P1]+=P2
91882**
91883** Increment a "constraint counter" by P2 (P2 may be negative or positive).
91884** If P1 is non-zero, the database constraint counter is incremented
91885** (deferred foreign key constraints). Otherwise, if P1 is zero, the
91886** statement counter is incremented (immediate foreign key constraints).
91887*/
91888case OP_FkCounter: {
91889 if( db->flags & SQLITE_DeferFKs ){
91890 db->nDeferredImmCons += pOp->p2;
91891 }else if( pOp->p1 ){
91892 db->nDeferredCons += pOp->p2;
91893 }else{
91894 p->nFkConstraint += pOp->p2;
91895 }
91896 break;
91897}
91898
91899/* Opcode: FkIfZero P1 P2 * * *
91900** Synopsis: if fkctr[P1]==0 goto P2
91901**
91902** This opcode tests if a foreign key constraint-counter is currently zero.
91903** If so, jump to instruction P2. Otherwise, fall through to the next
91904** instruction.
91905**
91906** If P1 is non-zero, then the jump is taken if the database constraint-counter
91907** is zero (the one that counts deferred constraint violations). If P1 is
91908** zero, the jump is taken if the statement constraint-counter is zero
91909** (immediate foreign key constraint violations).
91910*/
91911case OP_FkIfZero: { /* jump */
91912 if( pOp->p1 ){
91913 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
91914 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
91915 }else{
91917 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
91918 }
91919 break;
91920}
91921#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
91922
91923#ifndef SQLITE_OMIT_AUTOINCREMENT
91924/* Opcode: MemMax P1 P2 * * *
91925** Synopsis: r[P1]=max(r[P1],r[P2])
91926**
91927** P1 is a register in the root frame of this VM (the root frame is
91928** different from the current frame if this instruction is being executed
91929** within a sub-program). Set the value of register P1 to the maximum of
91930** its current value and the value in register P2.
91931**
91932** This instruction throws an error if the memory cell is not initially
91933** an integer.
91934*/
91935case OP_MemMax: { /* in2 */
91936 VdbeFrame *pFrame;
91937 if( p->pFrame ){
91938 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
91939 pIn1 = &pFrame->aMem[pOp->p1];
91940 }else{
91941 pIn1 = &aMem[pOp->p1];
91942 }
91943 assert( memIsValid(pIn1) );
91945 pIn2 = &aMem[pOp->p2];
91947 if( pIn1->u.i<pIn2->u.i){
91948 pIn1->u.i = pIn2->u.i;
91949 }
91950 break;
91951}
91952#endif /* SQLITE_OMIT_AUTOINCREMENT */
91953
91954/* Opcode: IfPos P1 P2 P3 * *
91955** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
91956**
91957** Register P1 must contain an integer.
91958** If the value of register P1 is 1 or greater, subtract P3 from the
91959** value in P1 and jump to P2.
91960**
91961** If the initial value of register P1 is less than 1, then the
91962** value is unchanged and control passes through to the next instruction.
91963*/
91964case OP_IfPos: { /* jump, in1 */
91965 pIn1 = &aMem[pOp->p1];
91966 assert( pIn1->flags&MEM_Int );
91967 VdbeBranchTaken( pIn1->u.i>0, 2);
91968 if( pIn1->u.i>0 ){
91969 pIn1->u.i -= pOp->p3;
91970 goto jump_to_p2;
91971 }
91972 break;
91973}
91974
91975/* Opcode: OffsetLimit P1 P2 P3 * *
91976** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
91977**
91978** This opcode performs a commonly used computation associated with
91979** LIMIT and OFFSET process. r[P1] holds the limit counter. r[P3]
91980** holds the offset counter. The opcode computes the combined value
91981** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
91982** value computed is the total number of rows that will need to be
91983** visited in order to complete the query.
91984**
91985** If r[P3] is zero or negative, that means there is no OFFSET
91986** and r[P2] is set to be the value of the LIMIT, r[P1].
91987**
91988** if r[P1] is zero or negative, that means there is no LIMIT
91989** and r[P2] is set to -1.
91990**
91991** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
91992*/
91993case OP_OffsetLimit: { /* in1, out2, in3 */
91994 i64 x;
91995 pIn1 = &aMem[pOp->p1];
91996 pIn3 = &aMem[pOp->p3];
91997 pOut = out2Prerelease(p, pOp);
91998 assert( pIn1->flags & MEM_Int );
91999 assert( pIn3->flags & MEM_Int );
92000 x = pIn1->u.i;
92001 if( x<=0 || sqlite3AddInt64(&x, pIn3->u.i>0?pIn3->u.i:0) ){
92002 /* If the LIMIT is less than or equal to zero, loop forever. This
92003 ** is documented. But also, if the LIMIT+OFFSET exceeds 2^63 then
92004 ** also loop forever. This is undocumented. In fact, one could argue
92005 ** that the loop should terminate. But assuming 1 billion iterations
92006 ** per second (far exceeding the capabilities of any current hardware)
92007 ** it would take nearly 300 years to actually reach the limit. So
92008 ** looping forever is a reasonable approximation. */
92009 pOut->u.i = -1;
92010 }else{
92011 pOut->u.i = x;
92012 }
92013 break;
92014}
92015
92016/* Opcode: IfNotZero P1 P2 * * *
92017** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
92018**
92019** Register P1 must contain an integer. If the content of register P1 is
92020** initially greater than zero, then decrement the value in register P1.
92021** If it is non-zero (negative or positive) and then also jump to P2.
92022** If register P1 is initially zero, leave it unchanged and fall through.
92023*/
92024case OP_IfNotZero: { /* jump, in1 */
92025 pIn1 = &aMem[pOp->p1];
92026 assert( pIn1->flags&MEM_Int );
92027 VdbeBranchTaken(pIn1->u.i<0, 2);
92028 if( pIn1->u.i ){
92029 if( pIn1->u.i>0 ) pIn1->u.i--;
92030 goto jump_to_p2;
92031 }
92032 break;
92033}
92034
92035/* Opcode: DecrJumpZero P1 P2 * * *
92036** Synopsis: if (--r[P1])==0 goto P2
92037**
92038** Register P1 must hold an integer. Decrement the value in P1
92039** and jump to P2 if the new value is exactly zero.
92040*/
92041case OP_DecrJumpZero: { /* jump, in1 */
92042 pIn1 = &aMem[pOp->p1];
92043 assert( pIn1->flags&MEM_Int );
92044 if( pIn1->u.i>SMALLEST_INT64 ) pIn1->u.i--;
92045 VdbeBranchTaken(pIn1->u.i==0, 2);
92046 if( pIn1->u.i==0 ) goto jump_to_p2;
92047 break;
92048}
92049
92050
92051/* Opcode: AggStep * P2 P3 P4 P5
92052** Synopsis: accum=r[P3] step(r[P2@P5])
92053**
92054** Execute the xStep function for an aggregate.
92055** The function has P5 arguments. P4 is a pointer to the
92056** FuncDef structure that specifies the function. Register P3 is the
92057** accumulator.
92058**
92059** The P5 arguments are taken from register P2 and its
92060** successors.
92061*/
92062/* Opcode: AggInverse * P2 P3 P4 P5
92063** Synopsis: accum=r[P3] inverse(r[P2@P5])
92064**
92065** Execute the xInverse function for an aggregate.
92066** The function has P5 arguments. P4 is a pointer to the
92067** FuncDef structure that specifies the function. Register P3 is the
92068** accumulator.
92069**
92070** The P5 arguments are taken from register P2 and its
92071** successors.
92072*/
92073/* Opcode: AggStep1 P1 P2 P3 P4 P5
92074** Synopsis: accum=r[P3] step(r[P2@P5])
92075**
92076** Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
92077** aggregate. The function has P5 arguments. P4 is a pointer to the
92078** FuncDef structure that specifies the function. Register P3 is the
92079** accumulator.
92080**
92081** The P5 arguments are taken from register P2 and its
92082** successors.
92083**
92084** This opcode is initially coded as OP_AggStep0. On first evaluation,
92085** the FuncDef stored in P4 is converted into an sqlite3_context and
92086** the opcode is changed. In this way, the initialization of the
92087** sqlite3_context only happens once, instead of on each call to the
92088** step function.
92089*/
92090case OP_AggInverse:
92091case OP_AggStep: {
92092 int n;
92093 sqlite3_context *pCtx;
92094
92095 assert( pOp->p4type==P4_FUNCDEF );
92096 n = pOp->p5;
92097 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
92098 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
92099 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
92100 pCtx = sqlite3DbMallocRawNN(db, n*sizeof(sqlite3_value*) +
92101 (sizeof(pCtx[0]) + sizeof(Mem) - sizeof(sqlite3_value*)));
92102 if( pCtx==0 ) goto no_mem;
92103 pCtx->pMem = 0;
92104 pCtx->pOut = (Mem*)&(pCtx->argv[n]);
92105 sqlite3VdbeMemInit(pCtx->pOut, db, MEM_Null);
92106 pCtx->pFunc = pOp->p4.pFunc;
92107 pCtx->iOp = (int)(pOp - aOp);
92108 pCtx->pVdbe = p;
92109 pCtx->skipFlag = 0;
92110 pCtx->isError = 0;
92111 pCtx->argc = n;
92112 pOp->p4type = P4_FUNCCTX;
92113 pOp->p4.pCtx = pCtx;
92114
92115 /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
92116 assert( pOp->p1==(pOp->opcode==OP_AggInverse) );
92117
92118 pOp->opcode = OP_AggStep1;
92119 /* Fall through into OP_AggStep */
92120 /* no break */ deliberate_fall_through
92121}
92122case OP_AggStep1: {
92123 int i;
92124 sqlite3_context *pCtx;
92125 Mem *pMem;
92126
92127 assert( pOp->p4type==P4_FUNCCTX );
92128 pCtx = pOp->p4.pCtx;
92129 pMem = &aMem[pOp->p3];
92130
92131#ifdef SQLITE_DEBUG
92132 if( pOp->p1 ){
92133 /* This is an OP_AggInverse call. Verify that xStep has always
92134 ** been called at least once prior to any xInverse call. */
92135 assert( pMem->uTemp==0x1122e0e3 );
92136 }else{
92137 /* This is an OP_AggStep call. Mark it as such. */
92138 pMem->uTemp = 0x1122e0e3;
92139 }
92140#endif
92141
92142 /* If this function is inside of a trigger, the register array in aMem[]
92143 ** might change from one evaluation to the next. The next block of code
92144 ** checks to see if the register array has changed, and if so it
92145 ** reinitializes the relavant parts of the sqlite3_context object */
92146 if( pCtx->pMem != pMem ){
92147 pCtx->pMem = pMem;
92148 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
92149 }
92150
92151#ifdef SQLITE_DEBUG
92152 for(i=0; i<pCtx->argc; i++){
92153 assert( memIsValid(pCtx->argv[i]) );
92154 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
92155 }
92156#endif
92157
92158 pMem->n++;
92159 assert( pCtx->pOut->flags==MEM_Null );
92160 assert( pCtx->isError==0 );
92161 assert( pCtx->skipFlag==0 );
92162#ifndef SQLITE_OMIT_WINDOWFUNC
92163 if( pOp->p1 ){
92164 (pCtx->pFunc->xInverse)(pCtx,pCtx->argc,pCtx->argv);
92165 }else
92166#endif
92167 (pCtx->pFunc->xSFunc)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */
92168
92169 if( pCtx->isError ){
92170 if( pCtx->isError>0 ){
92171 sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
92172 rc = pCtx->isError;
92173 }
92174 if( pCtx->skipFlag ){
92175 assert( pOp[-1].opcode==OP_CollSeq );
92176 i = pOp[-1].p1;
92177 if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
92178 pCtx->skipFlag = 0;
92179 }
92181 pCtx->pOut->flags = MEM_Null;
92182 pCtx->isError = 0;
92183 if( rc ) goto abort_due_to_error;
92184 }
92185 assert( pCtx->pOut->flags==MEM_Null );
92186 assert( pCtx->skipFlag==0 );
92187 break;
92188}
92189
92190/* Opcode: AggFinal P1 P2 * P4 *
92191** Synopsis: accum=r[P1] N=P2
92192**
92193** P1 is the memory location that is the accumulator for an aggregate
92194** or window function. Execute the finalizer function
92195** for an aggregate and store the result in P1.
92196**
92197** P2 is the number of arguments that the step function takes and
92198** P4 is a pointer to the FuncDef for this function. The P2
92199** argument is not used by this opcode. It is only there to disambiguate
92200** functions that can take varying numbers of arguments. The
92201** P4 argument is only needed for the case where
92202** the step function was not previously called.
92203*/
92204/* Opcode: AggValue * P2 P3 P4 *
92205** Synopsis: r[P3]=value N=P2
92206**
92207** Invoke the xValue() function and store the result in register P3.
92208**
92209** P2 is the number of arguments that the step function takes and
92210** P4 is a pointer to the FuncDef for this function. The P2
92211** argument is not used by this opcode. It is only there to disambiguate
92212** functions that can take varying numbers of arguments. The
92213** P4 argument is only needed for the case where
92214** the step function was not previously called.
92215*/
92216case OP_AggValue:
92217case OP_AggFinal: {
92218 Mem *pMem;
92219 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
92220 assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
92221 pMem = &aMem[pOp->p1];
92222 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
92223#ifndef SQLITE_OMIT_WINDOWFUNC
92224 if( pOp->p3 ){
92225 memAboutToChange(p, &aMem[pOp->p3]);
92226 rc = sqlite3VdbeMemAggValue(pMem, &aMem[pOp->p3], pOp->p4.pFunc);
92227 pMem = &aMem[pOp->p3];
92228 }else
92229#endif
92230 {
92231 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
92232 }
92233
92234 if( rc ){
92235 sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem));
92236 goto abort_due_to_error;
92237 }
92238 sqlite3VdbeChangeEncoding(pMem, encoding);
92239 UPDATE_MAX_BLOBSIZE(pMem);
92240 if( sqlite3VdbeMemTooBig(pMem) ){
92241 goto too_big;
92242 }
92243 break;
92244}
92245
92246#ifndef SQLITE_OMIT_WAL
92247/* Opcode: Checkpoint P1 P2 P3 * *
92248**
92249** Checkpoint database P1. This is a no-op if P1 is not currently in
92250** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
92251** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
92252** SQLITE_BUSY or not, respectively. Write the number of pages in the
92253** WAL after the checkpoint into mem[P3+1] and the number of pages
92254** in the WAL that have been checkpointed after the checkpoint
92255** completes into mem[P3+2]. However on an error, mem[P3+1] and
92256** mem[P3+2] are initialized to -1.
92257*/
92258case OP_Checkpoint: {
92259 int i; /* Loop counter */
92260 int aRes[3]; /* Results */
92261 Mem *pMem; /* Write results here */
92262
92263 assert( p->readOnly==0 );
92264 aRes[0] = 0;
92265 aRes[1] = aRes[2] = -1;
92266 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
92267 || pOp->p2==SQLITE_CHECKPOINT_FULL
92270 );
92271 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
92272 if( rc ){
92273 if( rc!=SQLITE_BUSY ) goto abort_due_to_error;
92274 rc = SQLITE_OK;
92275 aRes[0] = 1;
92276 }
92277 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
92278 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
92279 }
92280 break;
92281};
92282#endif
92283
92284#ifndef SQLITE_OMIT_PRAGMA
92285/* Opcode: JournalMode P1 P2 P3 * *
92286**
92287** Change the journal mode of database P1 to P3. P3 must be one of the
92288** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
92289** modes (delete, truncate, persist, off and memory), this is a simple
92290** operation. No IO is required.
92291**
92292** If changing into or out of WAL mode the procedure is more complicated.
92293**
92294** Write a string containing the final journal-mode to register P2.
92295*/
92296case OP_JournalMode: { /* out2 */
92297 Btree *pBt; /* Btree to change journal mode of */
92298 Pager *pPager; /* Pager associated with pBt */
92299 int eNew; /* New journal mode */
92300 int eOld; /* The old journal mode */
92301#ifndef SQLITE_OMIT_WAL
92302 const char *zFilename; /* Name of database file for pPager */
92303#endif
92304
92305 pOut = out2Prerelease(p, pOp);
92306 eNew = pOp->p3;
92307 assert( eNew==PAGER_JOURNALMODE_DELETE
92310 || eNew==PAGER_JOURNALMODE_OFF
92312 || eNew==PAGER_JOURNALMODE_WAL
92314 );
92315 assert( pOp->p1>=0 && pOp->p1<db->nDb );
92316 assert( p->readOnly==0 );
92317
92318 pBt = db->aDb[pOp->p1].pBt;
92319 pPager = sqlite3BtreePager(pBt);
92320 eOld = sqlite3PagerGetJournalMode(pPager);
92321 if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld;
92322 if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
92323
92324#ifndef SQLITE_OMIT_WAL
92325 zFilename = sqlite3PagerFilename(pPager, 1);
92326
92327 /* Do not allow a transition to journal_mode=WAL for a database
92328 ** in temporary storage or if the VFS does not support shared memory
92329 */
92330 if( eNew==PAGER_JOURNALMODE_WAL
92331 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
92332 || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
92333 ){
92334 eNew = eOld;
92335 }
92336
92337 if( (eNew!=eOld)
92339 ){
92340 if( !db->autoCommit || db->nVdbeRead>1 ){
92341 rc = SQLITE_ERROR;
92343 "cannot change %s wal mode from within a transaction",
92344 (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
92345 );
92346 goto abort_due_to_error;
92347 }else{
92348
92349 if( eOld==PAGER_JOURNALMODE_WAL ){
92350 /* If leaving WAL mode, close the log file. If successful, the call
92351 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
92352 ** file. An EXCLUSIVE lock may still be held on the database file
92353 ** after a successful return.
92354 */
92355 rc = sqlite3PagerCloseWal(pPager, db);
92356 if( rc==SQLITE_OK ){
92357 sqlite3PagerSetJournalMode(pPager, eNew);
92358 }
92359 }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
92360 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
92361 ** as an intermediate */
92363 }
92364
92365 /* Open a transaction on the database file. Regardless of the journal
92366 ** mode, this transaction always uses a rollback journal.
92367 */
92368 assert( sqlite3BtreeIsInTrans(pBt)==0 );
92369 if( rc==SQLITE_OK ){
92370 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
92371 }
92372 }
92373 }
92374#endif /* ifndef SQLITE_OMIT_WAL */
92375
92376 if( rc ) eNew = eOld;
92377 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
92378
92380 pOut->z = (char *)sqlite3JournalModename(eNew);
92381 pOut->n = sqlite3Strlen30(pOut->z);
92382 pOut->enc = SQLITE_UTF8;
92383 sqlite3VdbeChangeEncoding(pOut, encoding);
92384 if( rc ) goto abort_due_to_error;
92385 break;
92386};
92387#endif /* SQLITE_OMIT_PRAGMA */
92388
92389#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
92390/* Opcode: Vacuum P1 P2 * * *
92391**
92392** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
92393** for an attached database. The "temp" database may not be vacuumed.
92394**
92395** If P2 is not zero, then it is a register holding a string which is
92396** the file into which the result of vacuum should be written. When
92397** P2 is zero, the vacuum overwrites the original database.
92398*/
92399case OP_Vacuum: {
92400 assert( p->readOnly==0 );
92401 rc = sqlite3RunVacuum(&p->zErrMsg, db, pOp->p1,
92402 pOp->p2 ? &aMem[pOp->p2] : 0);
92403 if( rc ) goto abort_due_to_error;
92404 break;
92405}
92406#endif
92407
92408#if !defined(SQLITE_OMIT_AUTOVACUUM)
92409/* Opcode: IncrVacuum P1 P2 * * *
92410**
92411** Perform a single step of the incremental vacuum procedure on
92412** the P1 database. If the vacuum has finished, jump to instruction
92413** P2. Otherwise, fall through to the next instruction.
92414*/
92415case OP_IncrVacuum: { /* jump */
92416 Btree *pBt;
92417
92418 assert( pOp->p1>=0 && pOp->p1<db->nDb );
92419 assert( DbMaskTest(p->btreeMask, pOp->p1) );
92420 assert( p->readOnly==0 );
92421 pBt = db->aDb[pOp->p1].pBt;
92422 rc = sqlite3BtreeIncrVacuum(pBt);
92424 if( rc ){
92425 if( rc!=SQLITE_DONE ) goto abort_due_to_error;
92426 rc = SQLITE_OK;
92427 goto jump_to_p2;
92428 }
92429 break;
92430}
92431#endif
92432
92433/* Opcode: Expire P1 P2 * * *
92434**
92435** Cause precompiled statements to expire. When an expired statement
92436** is executed using sqlite3_step() it will either automatically
92437** reprepare itself (if it was originally created using sqlite3_prepare_v2())
92438** or it will fail with SQLITE_SCHEMA.
92439**
92440** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
92441** then only the currently executing statement is expired.
92442**
92443** If P2 is 0, then SQL statements are expired immediately. If P2 is 1,
92444** then running SQL statements are allowed to continue to run to completion.
92445** The P2==1 case occurs when a CREATE INDEX or similar schema change happens
92446** that might help the statement run faster but which does not affect the
92447** correctness of operation.
92448*/
92449case OP_Expire: {
92450 assert( pOp->p2==0 || pOp->p2==1 );
92451 if( !pOp->p1 ){
92453 }else{
92454 p->expired = pOp->p2+1;
92455 }
92456 break;
92457}
92458
92459/* Opcode: CursorLock P1 * * * *
92460**
92461** Lock the btree to which cursor P1 is pointing so that the btree cannot be
92462** written by an other cursor.
92463*/
92464case OP_CursorLock: {
92465 VdbeCursor *pC;
92466 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
92467 pC = p->apCsr[pOp->p1];
92468 assert( pC!=0 );
92469 assert( pC->eCurType==CURTYPE_BTREE );
92471 break;
92472}
92473
92474/* Opcode: CursorUnlock P1 * * * *
92475**
92476** Unlock the btree to which cursor P1 is pointing so that it can be
92477** written by other cursors.
92478*/
92479case OP_CursorUnlock: {
92480 VdbeCursor *pC;
92481 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
92482 pC = p->apCsr[pOp->p1];
92483 assert( pC!=0 );
92484 assert( pC->eCurType==CURTYPE_BTREE );
92486 break;
92487}
92488
92489#ifndef SQLITE_OMIT_SHARED_CACHE
92490/* Opcode: TableLock P1 P2 P3 P4 *
92491** Synopsis: iDb=P1 root=P2 write=P3
92492**
92493** Obtain a lock on a particular table. This instruction is only used when
92494** the shared-cache feature is enabled.
92495**
92496** P1 is the index of the database in sqlite3.aDb[] of the database
92497** on which the lock is acquired. A readlock is obtained if P3==0 or
92498** a write lock if P3==1.
92499**
92500** P2 contains the root-page of the table to lock.
92501**
92502** P4 contains a pointer to the name of the table being locked. This is only
92503** used to generate an error message if the lock cannot be obtained.
92504*/
92505case OP_TableLock: {
92506 u8 isWriteLock = (u8)pOp->p3;
92507 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommit) ){
92508 int p1 = pOp->p1;
92509 assert( p1>=0 && p1<db->nDb );
92510 assert( DbMaskTest(p->btreeMask, p1) );
92511 assert( isWriteLock==0 || isWriteLock==1 );
92512 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
92513 if( rc ){
92514 if( (rc&0xFF)==SQLITE_LOCKED ){
92515 const char *z = pOp->p4.z;
92516 sqlite3VdbeError(p, "database table is locked: %s", z);
92517 }
92518 goto abort_due_to_error;
92519 }
92520 }
92521 break;
92522}
92523#endif /* SQLITE_OMIT_SHARED_CACHE */
92524
92525#ifndef SQLITE_OMIT_VIRTUALTABLE
92526/* Opcode: VBegin * * * P4 *
92527**
92528** P4 may be a pointer to an sqlite3_vtab structure. If so, call the
92529** xBegin method for that table.
92530**
92531** Also, whether or not P4 is set, check that this is not being called from
92532** within a callback to a virtual table xSync() method. If it is, the error
92533** code will be set to SQLITE_LOCKED.
92534*/
92535case OP_VBegin: {
92536 VTable *pVTab;
92537 pVTab = pOp->p4.pVtab;
92538 rc = sqlite3VtabBegin(db, pVTab);
92539 if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
92540 if( rc ) goto abort_due_to_error;
92541 break;
92542}
92543#endif /* SQLITE_OMIT_VIRTUALTABLE */
92544
92545#ifndef SQLITE_OMIT_VIRTUALTABLE
92546/* Opcode: VCreate P1 P2 * * *
92547**
92548** P2 is a register that holds the name of a virtual table in database
92549** P1. Call the xCreate method for that table.
92550*/
92551case OP_VCreate: {
92552 Mem sMem; /* For storing the record being decoded */
92553 const char *zTab; /* Name of the virtual table */
92554
92555 memset(&sMem, 0, sizeof(sMem));
92556 sMem.db = db;
92557 /* Because P2 is always a static string, it is impossible for the
92558 ** sqlite3VdbeMemCopy() to fail */
92559 assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
92560 assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
92561 rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]);
92562 assert( rc==SQLITE_OK );
92563 zTab = (const char*)sqlite3_value_text(&sMem);
92564 assert( zTab || db->mallocFailed );
92565 if( zTab ){
92566 rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg);
92567 }
92568 sqlite3VdbeMemRelease(&sMem);
92569 if( rc ) goto abort_due_to_error;
92570 break;
92571}
92572#endif /* SQLITE_OMIT_VIRTUALTABLE */
92573
92574#ifndef SQLITE_OMIT_VIRTUALTABLE
92575/* Opcode: VDestroy P1 * * P4 *
92576**
92577** P4 is the name of a virtual table in database P1. Call the xDestroy method
92578** of that table.
92579*/
92580case OP_VDestroy: {
92581 db->nVDestroy++;
92582 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
92583 db->nVDestroy--;
92584 assert( p->errorAction==OE_Abort && p->usesStmtJournal );
92585 if( rc ) goto abort_due_to_error;
92586 break;
92587}
92588#endif /* SQLITE_OMIT_VIRTUALTABLE */
92589
92590#ifndef SQLITE_OMIT_VIRTUALTABLE
92591/* Opcode: VOpen P1 * * P4 *
92592**
92593** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
92594** P1 is a cursor number. This opcode opens a cursor to the virtual
92595** table and stores that cursor in P1.
92596*/
92597case OP_VOpen: {
92598 VdbeCursor *pCur;
92599 sqlite3_vtab_cursor *pVCur;
92600 sqlite3_vtab *pVtab;
92601 const sqlite3_module *pModule;
92602
92603 assert( p->bIsReader );
92604 pCur = 0;
92605 pVCur = 0;
92606 pVtab = pOp->p4.pVtab->pVtab;
92607 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
92608 rc = SQLITE_LOCKED;
92609 goto abort_due_to_error;
92610 }
92611 pModule = pVtab->pModule;
92612 rc = pModule->xOpen(pVtab, &pVCur);
92613 sqlite3VtabImportErrmsg(p, pVtab);
92614 if( rc ) goto abort_due_to_error;
92615
92616 /* Initialize sqlite3_vtab_cursor base class */
92617 pVCur->pVtab = pVtab;
92618
92619 /* Initialize vdbe cursor object */
92620 pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB);
92621 if( pCur ){
92622 pCur->uc.pVCur = pVCur;
92623 pVtab->nRef++;
92624 }else{
92625 assert( db->mallocFailed );
92626 pModule->xClose(pVCur);
92627 goto no_mem;
92628 }
92629 break;
92630}
92631#endif /* SQLITE_OMIT_VIRTUALTABLE */
92632
92633#ifndef SQLITE_OMIT_VIRTUALTABLE
92634/* Opcode: VFilter P1 P2 P3 P4 *
92635** Synopsis: iplan=r[P3] zplan='P4'
92636**
92637** P1 is a cursor opened using VOpen. P2 is an address to jump to if
92638** the filtered result set is empty.
92639**
92640** P4 is either NULL or a string that was generated by the xBestIndex
92641** method of the module. The interpretation of the P4 string is left
92642** to the module implementation.
92643**
92644** This opcode invokes the xFilter method on the virtual table specified
92645** by P1. The integer query plan parameter to xFilter is stored in register
92646** P3. Register P3+1 stores the argc parameter to be passed to the
92647** xFilter method. Registers P3+2..P3+1+argc are the argc
92648** additional parameters which are passed to
92649** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
92650**
92651** A jump is made to P2 if the result set after filtering would be empty.
92652*/
92653case OP_VFilter: { /* jump */
92654 int nArg;
92655 int iQuery;
92656 const sqlite3_module *pModule;
92657 Mem *pQuery;
92658 Mem *pArgc;
92659 sqlite3_vtab_cursor *pVCur;
92660 sqlite3_vtab *pVtab;
92661 VdbeCursor *pCur;
92662 int res;
92663 int i;
92664 Mem **apArg;
92665
92666 pQuery = &aMem[pOp->p3];
92667 pArgc = &pQuery[1];
92668 pCur = p->apCsr[pOp->p1];
92669 assert( memIsValid(pQuery) );
92670 REGISTER_TRACE(pOp->p3, pQuery);
92671 assert( pCur->eCurType==CURTYPE_VTAB );
92672 pVCur = pCur->uc.pVCur;
92673 pVtab = pVCur->pVtab;
92674 pModule = pVtab->pModule;
92675
92676 /* Grab the index number and argc parameters */
92677 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
92678 nArg = (int)pArgc->u.i;
92679 iQuery = (int)pQuery->u.i;
92680
92681 /* Invoke the xFilter method */
92682 res = 0;
92683 apArg = p->apArg;
92684 for(i = 0; i<nArg; i++){
92685 apArg[i] = &pArgc[i+1];
92686 }
92687 rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg);
92688 sqlite3VtabImportErrmsg(p, pVtab);
92689 if( rc ) goto abort_due_to_error;
92690 res = pModule->xEof(pVCur);
92691 pCur->nullRow = 0;
92692 VdbeBranchTaken(res!=0,2);
92693 if( res ) goto jump_to_p2;
92694 break;
92695}
92696#endif /* SQLITE_OMIT_VIRTUALTABLE */
92697
92698#ifndef SQLITE_OMIT_VIRTUALTABLE
92699/* Opcode: VColumn P1 P2 P3 * P5
92700** Synopsis: r[P3]=vcolumn(P2)
92701**
92702** Store in register P3 the value of the P2-th column of
92703** the current row of the virtual-table of cursor P1.
92704**
92705** If the VColumn opcode is being used to fetch the value of
92706** an unchanging column during an UPDATE operation, then the P5
92707** value is OPFLAG_NOCHNG. This will cause the sqlite3_vtab_nochange()
92708** function to return true inside the xColumn method of the virtual
92709** table implementation. The P5 column might also contain other
92710** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
92711** unused by OP_VColumn.
92712*/
92713case OP_VColumn: {
92714 sqlite3_vtab *pVtab;
92715 const sqlite3_module *pModule;
92716 Mem *pDest;
92717 sqlite3_context sContext;
92718
92719 VdbeCursor *pCur = p->apCsr[pOp->p1];
92720 assert( pCur->eCurType==CURTYPE_VTAB );
92721 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
92722 pDest = &aMem[pOp->p3];
92723 memAboutToChange(p, pDest);
92724 if( pCur->nullRow ){
92725 sqlite3VdbeMemSetNull(pDest);
92726 break;
92727 }
92728 pVtab = pCur->uc.pVCur->pVtab;
92729 pModule = pVtab->pModule;
92730 assert( pModule->xColumn );
92731 memset(&sContext, 0, sizeof(sContext));
92732 sContext.pOut = pDest;
92733 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
92734 if( pOp->p5 & OPFLAG_NOCHNG ){
92735 sqlite3VdbeMemSetNull(pDest);
92736 pDest->flags = MEM_Null|MEM_Zero;
92737 pDest->u.nZero = 0;
92738 }else{
92739 MemSetTypeFlag(pDest, MEM_Null);
92740 }
92741 rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2);
92742 sqlite3VtabImportErrmsg(p, pVtab);
92743 if( sContext.isError>0 ){
92744 sqlite3VdbeError(p, "%s", sqlite3_value_text(pDest));
92745 rc = sContext.isError;
92746 }
92747 sqlite3VdbeChangeEncoding(pDest, encoding);
92748 REGISTER_TRACE(pOp->p3, pDest);
92749 UPDATE_MAX_BLOBSIZE(pDest);
92750
92751 if( sqlite3VdbeMemTooBig(pDest) ){
92752 goto too_big;
92753 }
92754 if( rc ) goto abort_due_to_error;
92755 break;
92756}
92757#endif /* SQLITE_OMIT_VIRTUALTABLE */
92758
92759#ifndef SQLITE_OMIT_VIRTUALTABLE
92760/* Opcode: VNext P1 P2 * * *
92761**
92762** Advance virtual table P1 to the next row in its result set and
92763** jump to instruction P2. Or, if the virtual table has reached
92764** the end of its result set, then fall through to the next instruction.
92765*/
92766case OP_VNext: { /* jump */
92767 sqlite3_vtab *pVtab;
92768 const sqlite3_module *pModule;
92769 int res;
92770 VdbeCursor *pCur;
92771
92772 res = 0;
92773 pCur = p->apCsr[pOp->p1];
92774 assert( pCur->eCurType==CURTYPE_VTAB );
92775 if( pCur->nullRow ){
92776 break;
92777 }
92778 pVtab = pCur->uc.pVCur->pVtab;
92779 pModule = pVtab->pModule;
92780 assert( pModule->xNext );
92781
92782 /* Invoke the xNext() method of the module. There is no way for the
92783 ** underlying implementation to return an error if one occurs during
92784 ** xNext(). Instead, if an error occurs, true is returned (indicating that
92785 ** data is available) and the error code returned when xColumn or
92786 ** some other method is next invoked on the save virtual table cursor.
92787 */
92788 rc = pModule->xNext(pCur->uc.pVCur);
92789 sqlite3VtabImportErrmsg(p, pVtab);
92790 if( rc ) goto abort_due_to_error;
92791 res = pModule->xEof(pCur->uc.pVCur);
92792 VdbeBranchTaken(!res,2);
92793 if( !res ){
92794 /* If there is data, jump to P2 */
92795 goto jump_to_p2_and_check_for_interrupt;
92796 }
92797 goto check_for_interrupt;
92798}
92799#endif /* SQLITE_OMIT_VIRTUALTABLE */
92800
92801#ifndef SQLITE_OMIT_VIRTUALTABLE
92802/* Opcode: VRename P1 * * P4 *
92803**
92804** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
92805** This opcode invokes the corresponding xRename method. The value
92806** in register P1 is passed as the zName argument to the xRename method.
92807*/
92808case OP_VRename: {
92809 sqlite3_vtab *pVtab;
92810 Mem *pName;
92811 int isLegacy;
92812
92813 isLegacy = (db->flags & SQLITE_LegacyAlter);
92815 pVtab = pOp->p4.pVtab->pVtab;
92816 pName = &aMem[pOp->p1];
92817 assert( pVtab->pModule->xRename );
92818 assert( memIsValid(pName) );
92819 assert( p->readOnly==0 );
92820 REGISTER_TRACE(pOp->p1, pName);
92821 assert( pName->flags & MEM_Str );
92822 testcase( pName->enc==SQLITE_UTF8 );
92823 testcase( pName->enc==SQLITE_UTF16BE );
92824 testcase( pName->enc==SQLITE_UTF16LE );
92826 if( rc ) goto abort_due_to_error;
92827 rc = pVtab->pModule->xRename(pVtab, pName->z);
92828 if( isLegacy==0 ) db->flags &= ~(u64)SQLITE_LegacyAlter;
92829 sqlite3VtabImportErrmsg(p, pVtab);
92830 p->expired = 0;
92831 if( rc ) goto abort_due_to_error;
92832 break;
92833}
92834#endif
92835
92836#ifndef SQLITE_OMIT_VIRTUALTABLE
92837/* Opcode: VUpdate P1 P2 P3 P4 P5
92838** Synopsis: data=r[P3@P2]
92839**
92840** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
92841** This opcode invokes the corresponding xUpdate method. P2 values
92842** are contiguous memory cells starting at P3 to pass to the xUpdate
92843** invocation. The value in register (P3+P2-1) corresponds to the
92844** p2th element of the argv array passed to xUpdate.
92845**
92846** The xUpdate method will do a DELETE or an INSERT or both.
92847** The argv[0] element (which corresponds to memory cell P3)
92848** is the rowid of a row to delete. If argv[0] is NULL then no
92849** deletion occurs. The argv[1] element is the rowid of the new
92850** row. This can be NULL to have the virtual table select the new
92851** rowid for itself. The subsequent elements in the array are
92852** the values of columns in the new row.
92853**
92854** If P2==1 then no insert is performed. argv[0] is the rowid of
92855** a row to delete.
92856**
92857** P1 is a boolean flag. If it is set to true and the xUpdate call
92858** is successful, then the value returned by sqlite3_last_insert_rowid()
92859** is set to the value of the rowid for the row just inserted.
92860**
92861** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
92862** apply in the case of a constraint failure on an insert or update.
92863*/
92864case OP_VUpdate: {
92865 sqlite3_vtab *pVtab;
92866 const sqlite3_module *pModule;
92867 int nArg;
92868 int i;
92869 sqlite_int64 rowid;
92870 Mem **apArg;
92871 Mem *pX;
92872
92873 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
92874 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
92875 );
92876 assert( p->readOnly==0 );
92877 if( db->mallocFailed ) goto no_mem;
92879 pVtab = pOp->p4.pVtab->pVtab;
92880 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
92881 rc = SQLITE_LOCKED;
92882 goto abort_due_to_error;
92883 }
92884 pModule = pVtab->pModule;
92885 nArg = pOp->p2;
92886 assert( pOp->p4type==P4_VTAB );
92887 if( ALWAYS(pModule->xUpdate) ){
92888 u8 vtabOnConflict = db->vtabOnConflict;
92889 apArg = p->apArg;
92890 pX = &aMem[pOp->p3];
92891 for(i=0; i<nArg; i++){
92892 assert( memIsValid(pX) );
92893 memAboutToChange(p, pX);
92894 apArg[i] = pX;
92895 pX++;
92896 }
92897 db->vtabOnConflict = pOp->p5;
92898 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
92899 db->vtabOnConflict = vtabOnConflict;
92900 sqlite3VtabImportErrmsg(p, pVtab);
92901 if( rc==SQLITE_OK && pOp->p1 ){
92902 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
92903 db->lastRowid = rowid;
92904 }
92905 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
92906 if( pOp->p5==OE_Ignore ){
92907 rc = SQLITE_OK;
92908 }else{
92909 p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5);
92910 }
92911 }else{
92912 p->nChange++;
92913 }
92914 if( rc ) goto abort_due_to_error;
92915 }
92916 break;
92917}
92918#endif /* SQLITE_OMIT_VIRTUALTABLE */
92919
92920#ifndef SQLITE_OMIT_PAGER_PRAGMAS
92921/* Opcode: Pagecount P1 P2 * * *
92922**
92923** Write the current number of pages in database P1 to memory cell P2.
92924*/
92925case OP_Pagecount: { /* out2 */
92926 pOut = out2Prerelease(p, pOp);
92927 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
92928 break;
92929}
92930#endif
92931
92932
92933#ifndef SQLITE_OMIT_PAGER_PRAGMAS
92934/* Opcode: MaxPgcnt P1 P2 P3 * *
92935**
92936** Try to set the maximum page count for database P1 to the value in P3.
92937** Do not let the maximum page count fall below the current page count and
92938** do not change the maximum page count value if P3==0.
92939**
92940** Store the maximum page count after the change in register P2.
92941*/
92942case OP_MaxPgcnt: { /* out2 */
92943 unsigned int newMax;
92944 Btree *pBt;
92945
92946 pOut = out2Prerelease(p, pOp);
92947 pBt = db->aDb[pOp->p1].pBt;
92948 newMax = 0;
92949 if( pOp->p3 ){
92950 newMax = sqlite3BtreeLastPage(pBt);
92951 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
92952 }
92953 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
92954 break;
92955}
92956#endif
92957
92958/* Opcode: Function P1 P2 P3 P4 *
92959** Synopsis: r[P3]=func(r[P2@NP])
92960**
92961** Invoke a user function (P4 is a pointer to an sqlite3_context object that
92962** contains a pointer to the function to be run) with arguments taken
92963** from register P2 and successors. The number of arguments is in
92964** the sqlite3_context object that P4 points to.
92965** The result of the function is stored
92966** in register P3. Register P3 must not be one of the function inputs.
92967**
92968** P1 is a 32-bit bitmask indicating whether or not each argument to the
92969** function was determined to be constant at compile time. If the first
92970** argument was constant then bit 0 of P1 is set. This is used to determine
92971** whether meta data associated with a user function argument using the
92972** sqlite3_set_auxdata() API may be safely retained until the next
92973** invocation of this opcode.
92974**
92975** See also: AggStep, AggFinal, PureFunc
92976*/
92977/* Opcode: PureFunc P1 P2 P3 P4 *
92978** Synopsis: r[P3]=func(r[P2@NP])
92979**
92980** Invoke a user function (P4 is a pointer to an sqlite3_context object that
92981** contains a pointer to the function to be run) with arguments taken
92982** from register P2 and successors. The number of arguments is in
92983** the sqlite3_context object that P4 points to.
92984** The result of the function is stored
92985** in register P3. Register P3 must not be one of the function inputs.
92986**
92987** P1 is a 32-bit bitmask indicating whether or not each argument to the
92988** function was determined to be constant at compile time. If the first
92989** argument was constant then bit 0 of P1 is set. This is used to determine
92990** whether meta data associated with a user function argument using the
92991** sqlite3_set_auxdata() API may be safely retained until the next
92992** invocation of this opcode.
92993**
92994** This opcode works exactly like OP_Function. The only difference is in
92995** its name. This opcode is used in places where the function must be
92996** purely non-deterministic. Some built-in date/time functions can be
92997** either determinitic of non-deterministic, depending on their arguments.
92998** When those function are used in a non-deterministic way, they will check
92999** to see if they were called using OP_PureFunc instead of OP_Function, and
93000** if they were, they throw an error.
93001**
93002** See also: AggStep, AggFinal, Function
93003*/
93004case OP_PureFunc: /* group */
93005case OP_Function: { /* group */
93006 int i;
93007 sqlite3_context *pCtx;
93008
93009 assert( pOp->p4type==P4_FUNCCTX );
93010 pCtx = pOp->p4.pCtx;
93011
93012 /* If this function is inside of a trigger, the register array in aMem[]
93013 ** might change from one evaluation to the next. The next block of code
93014 ** checks to see if the register array has changed, and if so it
93015 ** reinitializes the relavant parts of the sqlite3_context object */
93016 pOut = &aMem[pOp->p3];
93017 if( pCtx->pOut != pOut ){
93018 pCtx->pVdbe = p;
93019 pCtx->pOut = pOut;
93020 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
93021 }
93022 assert( pCtx->pVdbe==p );
93023
93024 memAboutToChange(p, pOut);
93025#ifdef SQLITE_DEBUG
93026 for(i=0; i<pCtx->argc; i++){
93027 assert( memIsValid(pCtx->argv[i]) );
93028 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
93029 }
93030#endif
93031 MemSetTypeFlag(pOut, MEM_Null);
93032 assert( pCtx->isError==0 );
93033 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
93034
93035 /* If the function returned an error, throw an exception */
93036 if( pCtx->isError ){
93037 if( pCtx->isError>0 ){
93038 sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
93039 rc = pCtx->isError;
93040 }
93041 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
93042 pCtx->isError = 0;
93043 if( rc ) goto abort_due_to_error;
93044 }
93045
93046 /* Copy the result of the function into register P3 */
93047 if( pOut->flags & (MEM_Str|MEM_Blob) ){
93048 sqlite3VdbeChangeEncoding(pOut, encoding);
93049 if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
93050 }
93051
93052 REGISTER_TRACE(pOp->p3, pOut);
93053 UPDATE_MAX_BLOBSIZE(pOut);
93054 break;
93055}
93056
93057/* Opcode: Trace P1 P2 * P4 *
93058**
93059** Write P4 on the statement trace output if statement tracing is
93060** enabled.
93061**
93062** Operand P1 must be 0x7fffffff and P2 must positive.
93063*/
93064/* Opcode: Init P1 P2 P3 P4 *
93065** Synopsis: Start at P2
93066**
93067** Programs contain a single instance of this opcode as the very first
93068** opcode.
93069**
93070** If tracing is enabled (by the sqlite3_trace()) interface, then
93071** the UTF-8 string contained in P4 is emitted on the trace callback.
93072** Or if P4 is blank, use the string returned by sqlite3_sql().
93073**
93074** If P2 is not zero, jump to instruction P2.
93075**
93076** Increment the value of P1 so that OP_Once opcodes will jump the
93077** first time they are evaluated for this run.
93078**
93079** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
93080** error is encountered.
93081*/
93082case OP_Trace:
93083case OP_Init: { /* jump */
93084 int i;
93085#ifndef SQLITE_OMIT_TRACE
93086 char *zTrace;
93087#endif
93088
93089 /* If the P4 argument is not NULL, then it must be an SQL comment string.
93090 ** The "--" string is broken up to prevent false-positives with srcck1.c.
93091 **
93092 ** This assert() provides evidence for:
93093 ** EVIDENCE-OF: R-50676-09860 The callback can compute the same text that
93094 ** would have been returned by the legacy sqlite3_trace() interface by
93095 ** using the X argument when X begins with "--" and invoking
93096 ** sqlite3_expanded_sql(P) otherwise.
93097 */
93098 assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
93099
93100 /* OP_Init is always instruction 0 */
93101 assert( pOp==p->aOp || pOp->opcode==OP_Trace );
93102
93103#ifndef SQLITE_OMIT_TRACE
93105 && !p->doingRerun
93106 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
93107 ){
93108#ifndef SQLITE_OMIT_DEPRECATED
93109 if( db->mTrace & SQLITE_TRACE_LEGACY ){
93110 char *z = sqlite3VdbeExpandSql(p, zTrace);
93111 db->trace.xLegacy(db->pTraceArg, z);
93112 sqlite3_free(z);
93113 }else
93114#endif
93115 if( db->nVdbeExec>1 ){
93116 char *z = sqlite3MPrintf(db, "-- %s", zTrace);
93117 (void)db->trace.xV2(SQLITE_TRACE_STMT, db->pTraceArg, p, z);
93118 sqlite3DbFree(db, z);
93119 }else{
93120 (void)db->trace.xV2(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace);
93121 }
93122 }
93123#ifdef SQLITE_USE_FCNTL_TRACE
93124 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
93125 if( zTrace ){
93126 int j;
93127 for(j=0; j<db->nDb; j++){
93128 if( DbMaskTest(p->btreeMask, j)==0 ) continue;
93130 }
93131 }
93132#endif /* SQLITE_USE_FCNTL_TRACE */
93133#ifdef SQLITE_DEBUG
93134 if( (db->flags & SQLITE_SqlTrace)!=0
93135 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
93136 ){
93137 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
93138 }
93139#endif /* SQLITE_DEBUG */
93140#endif /* SQLITE_OMIT_TRACE */
93141 assert( pOp->p2>0 );
93142 if( pOp->p1>=sqlite3GlobalConfig.iOnceResetThreshold ){
93143 if( pOp->opcode==OP_Trace ) break;
93144 for(i=1; i<p->nOp; i++){
93145 if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
93146 }
93147 pOp->p1 = 0;
93148 }
93149 pOp->p1++;
93151 goto jump_to_p2;
93152}
93153
93154#ifdef SQLITE_ENABLE_CURSOR_HINTS
93155/* Opcode: CursorHint P1 * * P4 *
93156**
93157** Provide a hint to cursor P1 that it only needs to return rows that
93158** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer
93159** to values currently held in registers. TK_COLUMN terms in the P4
93160** expression refer to columns in the b-tree to which cursor P1 is pointing.
93161*/
93162case OP_CursorHint: {
93163 VdbeCursor *pC;
93164
93165 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93166 assert( pOp->p4type==P4_EXPR );
93167 pC = p->apCsr[pOp->p1];
93168 if( pC ){
93169 assert( pC->eCurType==CURTYPE_BTREE );
93170 sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE,
93171 pOp->p4.pExpr, aMem);
93172 }
93173 break;
93174}
93175#endif /* SQLITE_ENABLE_CURSOR_HINTS */
93176
93177#ifdef SQLITE_DEBUG
93178/* Opcode: Abortable * * * * *
93179**
93180** Verify that an Abort can happen. Assert if an Abort at this point
93181** might cause database corruption. This opcode only appears in debugging
93182** builds.
93183**
93184** An Abort is safe if either there have been no writes, or if there is
93185** an active statement journal.
93186*/
93187case OP_Abortable: {
93189 break;
93190}
93191#endif
93192
93193#ifdef SQLITE_DEBUG
93194/* Opcode: ReleaseReg P1 P2 P3 * P5
93195** Synopsis: release r[P1@P2] mask P3
93196**
93197** Release registers from service. Any content that was in the
93198** the registers is unreliable after this opcode completes.
93199**
93200** The registers released will be the P2 registers starting at P1,
93201** except if bit ii of P3 set, then do not release register P1+ii.
93202** In other words, P3 is a mask of registers to preserve.
93203**
93204** Releasing a register clears the Mem.pScopyFrom pointer. That means
93205** that if the content of the released register was set using OP_SCopy,
93206** a change to the value of the source register for the OP_SCopy will no longer
93207** generate an assertion fault in sqlite3VdbeMemAboutToChange().
93208**
93209** If P5 is set, then all released registers have their type set
93210** to MEM_Undefined so that any subsequent attempt to read the released
93211** register (before it is reinitialized) will generate an assertion fault.
93212**
93213** P5 ought to be set on every call to this opcode.
93214** However, there are places in the code generator will release registers
93215** before their are used, under the (valid) assumption that the registers
93216** will not be reallocated for some other purpose before they are used and
93217** hence are safe to release.
93218**
93219** This opcode is only available in testing and debugging builds. It is
93220** not generated for release builds. The purpose of this opcode is to help
93221** validate the generated bytecode. This opcode does not actually contribute
93222** to computing an answer.
93223*/
93224case OP_ReleaseReg: {
93225 Mem *pMem;
93226 int i;
93227 u32 constMask;
93228 assert( pOp->p1>0 );
93229 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
93230 pMem = &aMem[pOp->p1];
93231 constMask = pOp->p3;
93232 for(i=0; i<pOp->p2; i++, pMem++){
93233 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
93234 pMem->pScopyFrom = 0;
93235 if( i<32 && pOp->p5 ) MemSetTypeFlag(pMem, MEM_Undefined);
93236 }
93237 }
93238 break;
93239}
93240#endif
93241
93242/* Opcode: Noop * * * * *
93243**
93244** Do nothing. This instruction is often useful as a jump
93245** destination.
93246*/
93247/*
93248** The magic Explain opcode are only inserted when explain==2 (which
93249** is to say when the EXPLAIN QUERY PLAN syntax is used.)
93250** This opcode records information from the optimizer. It is the
93251** the same as a no-op. This opcodesnever appears in a real VM program.
93252*/
93253default: { /* This is really OP_Noop, OP_Explain */
93254 assert( pOp->opcode==OP_Noop || pOp->opcode==OP_Explain );
93255
93256 break;
93257}
93258
93259/*****************************************************************************
93260** The cases of the switch statement above this line should all be indented
93261** by 6 spaces. But the left-most 6 spaces have been removed to improve the
93262** readability. From this point on down, the normal indentation rules are
93263** restored.
93264*****************************************************************************/
93265 }
93266
93267#ifdef VDBE_PROFILE
93268 {
93269 u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
93270 if( endTime>start ) pOrigOp->cycles += endTime - start;
93271 pOrigOp->cnt++;
93272 }
93273#endif
93274
93275 /* The following code adds nothing to the actual functionality
93276 ** of the program. It is only here for testing and debugging.
93277 ** On the other hand, it does burn CPU cycles every time through
93278 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
93279 */
93280#ifndef NDEBUG
93281 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
93282
93283#ifdef SQLITE_DEBUG
93284 if( db->flags & SQLITE_VdbeTrace ){
93285 u8 opProperty = sqlite3OpcodeProperty[pOrigOp->opcode];
93286 if( rc!=0 ) printf("rc=%d\n",rc);
93287 if( opProperty & (OPFLG_OUT2) ){
93288 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
93289 }
93290 if( opProperty & OPFLG_OUT3 ){
93291 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
93292 }
93293 if( opProperty==0xff ){
93294 /* Never happens. This code exists to avoid a harmless linkage
93295 ** warning aboud sqlite3VdbeRegisterDump() being defined but not
93296 ** used. */
93297 sqlite3VdbeRegisterDump(p);
93298 }
93299 }
93300#endif /* SQLITE_DEBUG */
93301#endif /* NDEBUG */
93302 } /* The end of the for(;;) loop the loops through opcodes */
93303
93304 /* If we reach this point, it means that execution is finished with
93305 ** an error of some kind.
93306 */
93307abort_due_to_error:
93308 if( db->mallocFailed ) rc = SQLITE_NOMEM_BKPT;
93309 assert( rc );
93310 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
93311 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
93312 }
93313 p->rc = rc;
93314 sqlite3SystemError(db, rc);
93315 testcase( sqlite3GlobalConfig.xLog!=0 );
93316 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
93317 (int)(pOp - aOp), p->zSql, p->zErrMsg);
93318 sqlite3VdbeHalt(p);
93319 if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db);
93320 rc = SQLITE_ERROR;
93321 if( resetSchemaOnFault>0 ){
93322 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
93323 }
93324
93325 /* This is the only way out of this procedure. We have to
93326 ** release the mutexes on btrees that were acquired at the
93327 ** top. */
93328vdbe_return:
93329#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
93330 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
93331 nProgressLimit += db->nProgressOps;
93332 if( db->xProgress(db->pProgressArg) ){
93333 nProgressLimit = LARGEST_UINT64;
93334 rc = SQLITE_INTERRUPT;
93335 goto abort_due_to_error;
93336 }
93337 }
93338#endif
93339 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
93341 assert( rc!=SQLITE_OK || nExtraDelete==0
93342 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
93343 );
93344 return rc;
93345
93346 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
93347 ** is encountered.
93348 */
93349too_big:
93350 sqlite3VdbeError(p, "string or blob too big");
93351 rc = SQLITE_TOOBIG;
93352 goto abort_due_to_error;
93353
93354 /* Jump to here if a malloc() fails.
93355 */
93356no_mem:
93357 sqlite3OomFault(db);
93358 sqlite3VdbeError(p, "out of memory");
93359 rc = SQLITE_NOMEM_BKPT;
93360 goto abort_due_to_error;
93361
93362 /* Jump to here if the sqlite3_interrupt() API sets the interrupt
93363 ** flag.
SQLITE_PRIVATE BtCursor * sqlite3BtreeFakeValidCursor(void)
Definition sqlite3.c:65372
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *, AuxData **, int, int)
Definition sqlite3.c:81140
#define OP_AggStep
Definition sqlite3.c:15720
#define CURTYPE_VTAB
Definition sqlite3.c:20766
#define OP_CursorHint
Definition sqlite3.c:15737
#define SQLITE_AFF_MASK
Definition sqlite3.c:17407
SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *)
Definition sqlite3.c:68352
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char *, Mem *, u32)
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor *)
Definition sqlite3.c:70139
SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *, i64 *)
Definition sqlite3.c:51446
#define OP_IfNoHope
Definition sqlite3.c:15593
SQLITE_PRIVATE int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *)
Definition sqlite3.c:95640
#define OP_AggFinal
Definition sqlite3.c:15723
#define OPFLAG_SEEKEQ
Definition sqlite3.c:18848
#define UPDATE_MAX_BLOBSIZE(P)
Definition sqlite3.c:85349
SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *, BtCursor *, i64 *)
Definition sqlite3.c:82633
SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor *, const BtreePayload *pPayload, int flags, int seekResult)
Definition sqlite3.c:73109
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor *, int *pRes)
Definition sqlite3.c:69796
#define getVarint32(A, B)
Definition sqlite3.c:19868
#define OP_AggValue
Definition sqlite3.c:15722
SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *, int, const char *, char **)
Definition sqlite3.c:140325
#define OP_MemMax
Definition sqlite3.c:15717
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *, FuncDef *)
Definition sqlite3.c:76264
SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor *)
Definition sqlite3.c:69064
#define SQLITE_QueryOnly
Definition sqlite3.c:16999
SQLITE_PRIVATE void sqlite3VdbeError(Vdbe *, const char *,...)
Definition sqlite3.c:77791
#define OP_Int64
Definition sqlite3.c:15636
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *, int *pRes)
Definition sqlite3.c:69818
SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor *, u32, Mem *)
Definition sqlite3.c:77023
SQLITE_PRIVATE int sqlite3VdbeSorterRewind(const VdbeCursor *, int *)
Definition sqlite3.c:96454
SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor *)
Definition sqlite3.c:73826
#define sqlite3VdbeIncrWriteCounter(V, C)
Definition sqlite3.c:21283
SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock)
Definition sqlite3.c:74890
SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor *)
Definition sqlite3.c:69068
#define OPFLAG_NOCHNG
Definition sqlite3.c:18838
SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *, u8 flags)
Definition sqlite3.c:73394
#define OP_Multiply
Definition sqlite3.c:15673
#define Deephemeralize(P)
Definition sqlite3.c:85461
#define MAX_ROWID
SQLITE_PRIVATE int sqlite3BtreeCount(sqlite3 *, BtCursor *, i64 *)
Definition sqlite3.c:74026
#define OPFLG_OUT3
Definition sqlite3.c:15752
static VdbeCursor * allocateCursor(Vdbe *p, int iCur, int nField, int iDb, u8 eCurType)
Definition sqlite3.c:85472
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *)
Definition sqlite3.c:96571
#define SQLITE_STMTSTATUS_SORT
Definition sqlite3.c:9295
#define SQLITE_FCNTL_TRACE
Definition sqlite3.c:2196
#define SQLITE_FRAME_MAGIC
Definition sqlite3.c:20891
SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int)
Definition sqlite3.c:68778
static u16 numericType(Mem *pMem)
Definition sqlite3.c:85696
#define OP_Function
Definition sqlite3.c:15630
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int)
Definition sqlite3.c:80709
#define SQLITE_N_BTREE_META
Definition sqlite3.c:15019
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *, int, const char *)
Definition sqlite3.c:140451
SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *, const Mem *, int)
Definition sqlite3.c:76827
#define OP_String
Definition sqlite3.c:15637
SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount(Btree *, Pgno)
Definition sqlite3.c:67411
SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8)
Definition sqlite3.c:81462
SQLITE_PRIVATE int sqlite3RunVacuum(char **, sqlite3 *, int, sqlite3_value *)
Definition sqlite3.c:139307
#define OP_SeekHit
Definition sqlite3.c:15684
SQLITE_PRIVATE int sqlite3RowSetTest(RowSet *, int iBatch, i64)
Definition sqlite3.c:51480
SQLITE_PRIVATE char * sqlite3VdbeExpandSql(Vdbe *, const char *)
Definition sqlite3.c:85107
#define OP_ResetCount
Definition sqlite3.c:15689
#define REGISTER_TRACE(R, M)
Definition sqlite3.c:85828
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char *, u32, Mem *)
Definition sqlite3.c:81623
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int)
Definition sqlite3.c:140624
SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *)
Definition sqlite3.c:95104
SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *, int, Pgno, Pgno)
Definition sqlite3.c:113198
#define OPFLG_IN1
Definition sqlite3.c:15748
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3 *, VdbeCursor *, UnpackedRecord *, int *)
Definition sqlite3.c:82712
SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet *, i64)
Definition sqlite3.c:51248
#define OP_AggInverse
Definition sqlite3.c:15719
SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem *, Mem *)
Definition sqlite3.c:76866
#define BTREE_HINT_RANGE
Definition sqlite3.c:15179
SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *)
Definition sqlite3.c:96604
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor *)
Definition sqlite3.c:70152
SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor *)
Definition sqlite3.c:69042
SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *, sqlite3 *, u16)
Definition sqlite3.c:76626
SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *)
Definition sqlite3.c:81276
#define MEM_Cleared
Definition sqlite3.c:20957
#define OPFLG_IN3
Definition sqlite3.c:15750
SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int)
Definition sqlite3.c:80728
#define SQLITE_MISMATCH
Definition sqlite3.c:1490
#define SQLITE_TRACE_ROW
Definition sqlite3.c:4246
SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *)
Definition sqlite3.c:140564
#define OP_ReopenIdx
Definition sqlite3.c:15661
SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree *, int, int *)
Definition sqlite3.c:73935
#define OP_Move
Definition sqlite3.c:15642
SQLITE_PRIVATE int sqlite3VarintLen(u64 v)
Definition sqlite3.c:32430
#define OP_DropIndex
Definition sqlite3.c:15710
SQLITE_PRIVATE const void * sqlite3BtreePayloadFetch(BtCursor *, u32 *pAmt)
Definition sqlite3.c:69557
#define MemSetTypeFlag(p, f)
Definition sqlite3.c:20987
#define VdbeFrameMem(p)
Definition sqlite3.c:20897
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *, int, const char *)
Definition sqlite3.c:110905
#define OP_Explain
Definition sqlite3.c:15740
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256]
Definition sqlite3.c:20453
SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe *)
Definition sqlite3.c:80755
#define VdbeBranchTaken(I, M)
Definition sqlite3.c:85410
#define OPFLG_OUT2
Definition sqlite3.c:15751
#define SQLITE_CORRUPT_INDEX
Definition sqlite3.c:1568
#define SQLITE_STMTSTATUS_RUN
Definition sqlite3.c:9299
SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *, Pgno *, int flags)
Definition sqlite3.c:73723
SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *)
Definition sqlite3.c:94806
#define OP_RowSetTest
Definition sqlite3.c:15611
#define OP_AggStep1
Definition sqlite3.c:15721
#define OP_VCreate
Definition sqlite3.c:15729
SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe *, sqlite3_vtab *)
Definition sqlite3.c:82880
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *, int, const char *)
Definition sqlite3.c:111114
#define OP_ParseSchema
Definition sqlite3.c:15707
SQLITE_PRIVATE int sqlite3SubInt64(i64 *, i64)
Definition sqlite3.c:32599
SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *)
Definition sqlite3.c:79521
#define OPFLG_IN2
Definition sqlite3.c:15749
#define MEM_AffMask
Definition sqlite3.c:20954
#define sqlite3VdbeAssertAbortable(V)
Definition sqlite3.c:21284
#define OP_DropTrigger
Definition sqlite3.c:15711
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *, int, const char *)
Definition sqlite3.c:137044
#define OP_IdxGE
Definition sqlite3.c:15607
#define OP_VNext
Definition sqlite3.c:15627
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **, u32 *)
Definition sqlite3.c:81297
#define OP_DropTable
Definition sqlite3.c:15709
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *, u8, u8)
Definition sqlite3.c:76230
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *, int)
Definition sqlite3.c:68747
SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor *, unsigned)
Definition sqlite3.c:65423
#define CACHE_STALE
Definition sqlite3.c:20842
SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem *, Mem *, FuncDef *)
Definition sqlite3.c:76294
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve)
Definition sqlite3.c:76055
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem *)
Definition sqlite3.c:76504
SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem *, u8, u8)
Definition sqlite3.c:76583
SQLITE_API void sqlite3_interrupt(sqlite3 *)
Definition sqlite3.c:162748
#define sqlite3VdbeIOTraceSql(X)
Definition sqlite3.c:20291
#define OP_IdxLT
Definition sqlite3.c:15606
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *)
Definition sqlite3.c:76518
#define OP_Abortable
Definition sqlite3.c:15741
SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem *)
Definition sqlite3.c:76748
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor *, u32, u32, Mem *)
Definition sqlite3.c:77000
SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *)
Definition sqlite3.c:79556
#define LARGEST_UINT64
Definition sqlite3.c:14465
#define BTREE_SEEK_EQ
Definition sqlite3.c:15195
SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager *)
Definition sqlite3.c:59046
#define OPFLAG_NOCHNG_MAGIC
Definition sqlite3.c:18854
SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor *, unsigned int mask)
Definition sqlite3.c:75014
SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem *)
Definition sqlite3.c:76205
#define SQLITE_TRACE_LEGACY
Definition sqlite3.c:16807
#define OP_IfNotOpen
Definition sqlite3.c:15592
SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem *)
Definition sqlite3.c:76766
#define SQLITE_BUSY_RECOVERY
Definition sqlite3.c:1557
#define HAS_UPDATE_HOOK(DB)
Definition sqlite3.c:85328
#define SQLITE_STMTSTATUS_VM_STEP
Definition sqlite3.c:9297
#define OP_LoadAnalysis
Definition sqlite3.c:15708
#define SQLITE_TRACE_STMT
Definition sqlite3.c:4244
#define BTREE_OMIT_JOURNAL
Definition sqlite3.c:15057
SQLITE_PRIVATE char * sqlite3BtreeIntegrityCheck(sqlite3 *, Btree *, Pgno *aRoot, int nRoot, int, int *)
Definition sqlite3.c:74616
SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *)
Definition sqlite3.c:96506
SQLITE_PRIVATE u8 sqlite3GetVarint32(const unsigned char *, u32 *)
Definition sqlite3.c:32308
#define MEM_Undefined
Definition sqlite3.c:20956
#define CURTYPE_SORTER
Definition sqlite3.c:20765
SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int)
Definition sqlite3.c:82747
#define OP_SeekLE
Definition sqlite3.c:15589
SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3 *)
Definition sqlite3.c:59237
SQLITE_PRIVATE int sqlite3BtreeCursor(Btree *, Pgno iTable, int wrFlag, struct KeyInfo *, BtCursor *pCursor)
Definition sqlite3.c:68927
SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem *, int ifNull)
Definition sqlite3.c:76465
#define OP_Real
Definition sqlite3.c:15716
#define isSorter(x)
Definition sqlite3.c:85466
SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *)
Definition sqlite3.c:76177
SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int)
Definition sqlite3.c:58946
sqlite3_value * aMem
Definition sqlite3.c:15292
char * zName
Definition sqlite3.c:17285
i64 nDeferredImmCons
Definition sqlite3.c:17287
i64 nDeferredCons
Definition sqlite3.c:17286
Bool useRandomRowid
Definition sqlite3.c:20791
sqlite3_vtab_cursor * pVCur
Definition sqlite3.c:20815
int seekResult
Definition sqlite3.c:20803
const u8 * aRow
Definition sqlite3.c:20825
KeyInfo * pKeyInfo
Definition sqlite3.c:20818
VdbeSorter * pSorter
Definition sqlite3.c:20816
u32 iHdrOffset
Definition sqlite3.c:20819
Bool isOrdered
Definition sqlite3.c:20792
u32 payloadSize
Definition sqlite3.c:20826
Pgno pgnoRoot
Definition sqlite3.c:20820
u32 cacheStatus
Definition sqlite3.c:20802
Bool seekHit
Definition sqlite3.c:20793
i64 movetoTarget
Definition sqlite3.c:20823
void * token
Definition sqlite3.c:20874
AuxData * pAuxData
Definition sqlite3.c:20876
int nChildCsr
Definition sqlite3.c:20885
Vdbe * v
Definition sqlite3.c:20867
VdbeCursor ** apCsr
Definition sqlite3.c:20872
int nChange
Definition sqlite3.c:20886
int nChildMem
Definition sqlite3.c:20884
Mem * aMem
Definition sqlite3.c:20871
int nCursor
Definition sqlite3.c:20880
int nDbChange
Definition sqlite3.c:20887
u8 * aOnce
Definition sqlite3.c:20873
i64 * anExec
Definition sqlite3.c:20870
i64 lastRowid
Definition sqlite3.c:20875
bft usesStmtJournal
Definition sqlite3.c:21131
int nChange
Definition sqlite3.c:21094
u8 minWriteFileFormat
Definition sqlite3.c:21124
Mem ** apArg
Definition sqlite3.c:21101
yDbMask btreeMask
Definition sqlite3.c:21134
u8 errorAction
Definition sqlite3.c:21123
u32 cacheCtr
Definition sqlite3.c:21091
int iStatement
Definition sqlite3.c:21095
sqlite3_value * argv[1]
Definition sqlite3.c:21042
int(* xFilter)(sqlite3_vtab_cursor *, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
Definition sqlite3.c:7771
int(* xRowid)(sqlite3_vtab_cursor *, sqlite3_int64 *pRowid)
Definition sqlite3.c:7776
int(* xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor)
Definition sqlite3.c:7769
int(* xColumn)(sqlite3_vtab_cursor *, sqlite3_context *, int)
Definition sqlite3.c:7775
int(* xClose)(sqlite3_vtab_cursor *)
Definition sqlite3.c:7770
int(* xNext)(sqlite3_vtab_cursor *)
Definition sqlite3.c:7773
int(* xEof)(sqlite3_vtab_cursor *)
Definition sqlite3.c:7774
void(* xLegacy)(void *, const char *)
Definition sqlite3.c:16872
int nStatement
Definition sqlite3.c:16931
i64 lastRowid
Definition sqlite3.c:16828
void * pUpdateArg
Definition sqlite3.c:16884
void(* xUpdateCallback)(void *, int, const char *, const char *, sqlite_int64)
Definition sqlite3.c:16885
u8 isTransactionSavepoint
Definition sqlite3.c:16845
u8 vtabOnConflict
Definition sqlite3.c:16844
u8 nSqlExec
Definition sqlite3.c:16848
int nVDestroy
Definition sqlite3.c:16868
SubProgram * pProgram
Definition sqlite3.c:15454

References VdbeCursor::aAltMap, Table::aCol, KeyInfo::aColl, Vdbe::aCounter, sqlite3::aDb, VdbeOp::p4union::ai, sqlite3::aLimit, allocateCursor(), ALWAYS, BtreePayload::aMem, UnpackedRecord::aMem, VdbeFrame::aMem, Vdbe::aMem, VdbeFrame::anExec, VdbeCursor::aOffset, VdbeFrame::aOnce, SubProgram::aOp, VdbeFrame::aOp, Vdbe::aOp, Vdbe::apArg, VdbeFrame::apCsr, Vdbe::apCsr, applyAffinity(), applyNumericAffinity(), sqlite3_context::argc, sqlite3_context::argv, VdbeCursor::aRow, ArraySize, KeyInfo::aSortFlags, AtomicLoad, VdbeCursor::aType, sqlite3::autoCommit, Vdbe::aVar, VTable::bConstraint, Vdbe::bIsReader, BTREE_AUXDELETE, BTREE_BLOBKEY, BTREE_BULKLOAD, BTREE_FILE_FORMAT, BTREE_FORDELETE, BTREE_HINT_RANGE, BTREE_INTKEY, BTREE_OMIT_JOURNAL, BTREE_SAVEPOSITION, BTREE_SCHEMA_VERSION, BTREE_SEEK_EQ, BTREE_SINGLE, BTREE_UNORDERED, BTREE_WRCSR, Vdbe::btreeMask, sqlite3::sqlite3InitInfo::busy, sqlite3::busyHandler, CACHE_STALE, Vdbe::cacheCtr, VdbeCursor::cacheStatus, CORRUPT_DB, CURTYPE_BTREE, CURTYPE_PSEUDO, CURTYPE_SORTER, CURTYPE_VTAB, KeyInfo::db, InitData::db, sqlite3_value::db, Vdbe::db, DB_SchemaLoaded, DBFLAG_SchemaChange, DbHasProperty, DbMaskTest, Deephemeralize, UnpackedRecord::default_rc, VdbeCursor::deferredMoveto, deliberate_fall_through, DFLT_SCHEMA_TABLE, Vdbe::doingRerun, VdbeCursor::eCurType, ENC, KeyInfo::enc, sqlite3_value::enc, UnpackedRecord::eqSeen, Vdbe::errorAction, ExpandBlob, Vdbe::expired, Vdbe::explain, Schema::file_format, sqlite3::flags, sqlite3_value::flags, getVarint32, HAS_UPDATE_HOOK, HasRowid, VdbeOp::p4union::i, sqlite3_value::MemValue::i, Vdbe::iCurrentTime, InitData::iDb, VdbeCursor::iDb, Schema::iGeneration, VdbeCursor::iHdrOffset, sqlite3::init, INITFLAG_AlterTable, sqlite3_context::iOp, VdbeCursor::isEphemeral, sqlite3_context::isError, sqlite3::isInterrupted, VdbeCursor::isOrdered, isSorter, VdbeCursor::isTable, Vdbe::iStatement, sqlite3::isTransactionSavepoint, KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, LARGEST_UINT64, sqlite3::lastRowid, VdbeFrame::lastRowid, Vdbe::magic, sqlite3::mallocFailed, MASKBIT32, MAX_ROWID, sqlite3::mDbFlags, MEM_AffMask, MEM_Agg, MEM_Blob, MEM_Cleared, MEM_Dyn, MEM_Ephem, MEM_FromBind, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Static, MEM_Str, MEM_Term, MEM_TypeMask, MEM_Undefined, MEM_Zero, memAboutToChange, MEMCELLSIZE, MemSetTypeFlag, InitData::mInitFlags, Vdbe::minWriteFileFormat, VdbeCursor::movetoTarget, sqlite3::mTrace, InitData::mxPage, sqlite3_value::n, KeyInfo::nAllField, BusyHandler::nBusy, sqlite3::nChange, VdbeFrame::nChange, Vdbe::nChange, VdbeFrame::nChildCsr, VdbeFrame::nChildMem, SubProgram::nCsr, VdbeFrame::nCursor, Vdbe::nCursor, BtreePayload::nData, sqlite3::nDb, VdbeFrame::nDbChange, sqlite3::nDeferredCons, Savepoint::nDeferredCons, sqlite3::nDeferredImmCons, Savepoint::nDeferredImmCons, NEVER, UnpackedRecord::nField, VdbeCursor::nField, Vdbe::nFkConstraint, Vdbe::nFrame, VdbeCursor::nHdrParsed, InitData::nInitRow, BtreePayload::nKey, BtreePayload::nMem, SubProgram::nMem, VdbeFrame::nMem, Vdbe::nMem, nName, SubProgram::nOp, VdbeFrame::nOp, Vdbe::nOp, sqlite3::nProgressOps, sqlite3_vtab::nRef, Vdbe::nResColumn, sqlite3::nSavepoint, sqlite3::nSqlExec, sqlite3::nStatement, Vdbe::nStmtDefCons, Vdbe::nStmtDefImmCons, VdbeCursor::nullRow, numericType(), Vdbe::nVar, sqlite3::nVdbeActive, sqlite3::nVdbeExec, sqlite3::nVdbeRead, sqlite3::nVdbeWrite, sqlite3::nVDestroy, sqlite3::nVTrans, BtreePayload::nZero, sqlite3_value::MemValue::nZero, OE_Abort, OE_Fail, OE_Ignore, OE_Replace, OE_Rollback, OP_Abortable, OP_Add, OP_AddImm, OP_Affinity, OP_AggFinal, OP_AggInverse, OP_AggStep, OP_AggStep1, OP_AggValue, OP_And, OP_AutoCommit, OP_BitAnd, OP_BitNot, OP_BitOr, OP_Blob, OP_Cast, OP_Checkpoint, OP_Clear, OP_Close, OP_CollSeq, OP_Column, OP_ColumnsUsed, OP_Compare, OP_Concat, OP_Copy, OP_Count, OP_CreateBtree, OP_CursorHint, OP_CursorLock, OP_CursorUnlock, OP_DecrJumpZero, OP_DeferredSeek, OP_Delete, OP_Destroy, OP_Divide, OP_DropIndex, OP_DropTable, OP_DropTrigger, OP_ElseNotEq, OP_EndCoroutine, OP_Eq, OP_Expire, OP_Explain, OP_FinishSeek, OP_FkCounter, OP_FkIfZero, OP_Found, OP_Function, OP_Ge, OP_Gosub, OP_Goto, OP_Gt, OP_Halt, OP_HaltIfNull, OP_IdxDelete, OP_IdxGE, OP_IdxGT, OP_IdxInsert, OP_IdxLE, OP_IdxLT, OP_IdxRowid, OP_If, OP_IfNoHope, OP_IfNot, OP_IfNotOpen, OP_IfNotZero, OP_IfNullRow, OP_IfPos, OP_IfSmaller, OP_IncrVacuum, OP_Init, OP_InitCoroutine, OP_Insert, OP_Int64, OP_IntCopy, OP_Integer, OP_IntegrityCk, OP_IsNull, OP_IsTrue, OP_JournalMode, OP_Jump, OP_Last, OP_Le, OP_LoadAnalysis, OP_Lt, OP_MakeRecord, OP_MaxPgcnt, OP_MemMax, OP_Move, OP_Multiply, OP_MustBeInt, OP_Ne, OP_NewRowid, OP_Next, OP_NoConflict, OP_Noop, OP_Not, OP_NotExists, OP_NotFound, OP_NotNull, OP_Null, OP_NullRow, OP_Offset, OP_OffsetLimit, OP_Once, OP_OpenAutoindex, OP_OpenDup, OP_OpenEphemeral, OP_OpenPseudo, OP_OpenRead, OP_OpenWrite, OP_Or, OP_Pagecount, OP_Param, OP_ParseSchema, OP_Permutation, OP_Prev, OP_Program, OP_PureFunc, OP_ReadCookie, OP_Real, OP_RealAffinity, OP_ReleaseReg, OP_Remainder, OP_ReopenIdx, OP_ResetCount, OP_ResetSorter, OP_ResultRow, OP_Return, OP_Rewind, OP_RowData, OP_Rowid, OP_RowSetAdd, OP_RowSetRead, OP_RowSetTest, OP_Savepoint, OP_SCopy, OP_SeekEnd, OP_SeekGE, OP_SeekGT, OP_SeekHit, OP_SeekLE, OP_SeekLT, OP_SeekRowid, OP_Sequence, OP_SequenceTest, OP_SetCookie, OP_ShiftLeft, OP_ShiftRight, OP_SoftNull, OP_Sort, OP_SorterCompare, OP_SorterData, OP_SorterInsert, OP_SorterNext, OP_SorterOpen, OP_SorterSort, OP_SqlExec, OP_String, OP_String8, OP_Subtract, OP_TableLock, OP_Trace, OP_Transaction, OP_Vacuum, OP_Variable, OP_VBegin, OP_VColumn, OP_VCreate, OP_VDestroy, OP_VFilter, OP_VNext, OP_VOpen, OP_VRename, OP_VUpdate, OP_Yield, VdbeOp::opcode, OPFLAG_APPEND, OPFLAG_AUXDELETE, OPFLAG_BULKCSR, OPFLAG_FORDELETE, OPFLAG_ISNOOP, OPFLAG_ISUPDATE, OPFLAG_LASTROWID, OPFLAG_LENGTHARG, OPFLAG_NCHANGE, OPFLAG_NOCHNG, OPFLAG_NOCHNG_MAGIC, OPFLAG_P2ISREG, OPFLAG_PERMUTE, OPFLAG_SAVEPOSITION, OPFLAG_SEEKEQ, OPFLAG_TYPEOFARG, OPFLAG_USESEEKRESULT, OPFLG_IN1, OPFLG_IN2, OPFLG_IN3, OPFLG_OUT2, OPFLG_OUT3, out2Prerelease(), VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, VdbeOp::p4, P4_COLLSEQ, P4_DYNAMIC, P4_EXPR, P4_FUNCCTX, P4_FUNCDEF, P4_INT32, P4_INTARRAY, P4_KEYINFO, P4_MEM, P4_STATIC, P4_TABLE, P4_VTAB, VdbeOp::p4type, VdbeOp::p5, PAGER_JOURNALMODE_DELETE, PAGER_JOURNALMODE_MEMORY, PAGER_JOURNALMODE_OFF, PAGER_JOURNALMODE_PERSIST, PAGER_JOURNALMODE_QUERY, PAGER_JOURNALMODE_TRUNCATE, PAGER_JOURNALMODE_WAL, VdbeCursor::pAltCursor, VdbeFrame::pAuxData, Vdbe::pAuxData, VdbeCursor::payloadSize, Db::pBt, VdbeCursor::pBtx, VdbeFrame::pc, Vdbe::pc, VdbeOp::p4union::pColl, VdbeOp::p4union::pCtx, VdbeCursor::pCursor, BtreePayload::pData, Vdbe::pFrame, VdbeOp::p4union::pFunc, sqlite3_context::pFunc, VdbeCursor::pgnoRoot, VdbeOp::p4union::pI64, BtreePayload::pKey, VdbeOp::p4union::pKeyInfo, UnpackedRecord::pKeyInfo, VdbeCursor::pKeyInfo, VdbeOp::p4union::pMem, sqlite3_context::pMem, sqlite3_vtab::pModule, Savepoint::pNext, sqlite3_context::pOut, VdbeFrame::pParent, VdbeOp::p4union::pProgram, sqlite3::pProgressArg, VdbeOp::p4union::pReal, Vdbe::pResultSet, printf, sqlite3::pSavepoint, Db::pSchema, VdbeCursor::pSorter, VdbeOp::p4union::pTab, sqlite3::pTraceArg, sqlite3::pUpdateArg, putVarint32, VdbeCursor::pVCur, sqlite3_context::pVdbe, sqlite3::pVfs, Vdbe::pVList, sqlite3_vtab_cursor::pVtab, VdbeOp::p4union::pVtab, VTable::pVtab, InitData::pzErrMsg, sqlite3_value::MemValue::r, InitData::rc, Vdbe::rc, Vdbe::readOnly, REGISTER_TRACE, ROUND8, SAVEPOINT_BEGIN, SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, Schema::schema_cookie, SCHEMA_ROOT, VdbeCursor::seekHit, VdbeCursor::seekResult, VdbeCursor::seqCount, sqlite3_context::skipFlag, SMALLEST_INT64, sqlite3_exec(), sqlite3_file_control(), sqlite3_free(), sqlite3_interrupt(), sqlite3_log(), sqlite3_randomness(), sqlite3_strlike(), sqlite3_value_text(), sqlite3AddInt64(), sqlite3AnalysisLoad(), sqlite3BeginBenignMalloc(), sqlite3BtreeBeginStmt(), sqlite3BtreeBeginTrans(), sqlite3BtreeClearCursor(), sqlite3BtreeClearTable(), sqlite3BtreeClearTableOfCursor(), sqlite3BtreeCount(), sqlite3BtreeCreateTable(), sqlite3BtreeCursor(), sqlite3BtreeCursorHasHint(), sqlite3BtreeCursorHintFlags(), sqlite3BtreeCursorIsValidNN(), sqlite3BtreeCursorPin(), sqlite3BtreeCursorUnpin(), sqlite3BtreeDelete(), sqlite3BtreeDropTable(), sqlite3BtreeEof(), sqlite3BtreeFakeValidCursor(), sqlite3BtreeFirst(), sqlite3BtreeGetMeta(), sqlite3BtreeIncrVacuum(), sqlite3BtreeInsert(), sqlite3BtreeIntegerKey(), sqlite3BtreeIntegrityCheck(), sqlite3BtreeIsInTrans(), sqlite3BtreeLast(), sqlite3BtreeLastPage(), sqlite3BtreeLockTable(), sqlite3BtreeMaxPageCount(), sqlite3BtreeMovetoUnpacked(), sqlite3BtreeNext(), sqlite3BtreeOpen(), sqlite3BtreePager(), sqlite3BtreePayloadFetch(), sqlite3BtreePayloadSize(), sqlite3BtreePrevious(), sqlite3BtreeRowCountEst(), sqlite3BtreeSavepoint(), sqlite3BtreeSetVersion(), sqlite3BtreeTripAllCursors(), sqlite3BtreeUpdateMeta(), sqlite3Checkpoint(), sqlite3CloseSavepoints(), sqlite3CtypeMap, sqlite3DbFree(), sqlite3DbFreeNN(), sqlite3DbMallocRawNN(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3EndBenignMalloc(), sqlite3ErrStr(), sqlite3ExpirePreparedStatements(), sqlite3GetVarint32(), sqlite3GlobalConfig, sqlite3InitCallback(), sqlite3InitOne(), sqlite3IsNaN(), sqlite3JournalModename(), sqlite3LogEst(), sqlite3MemCompare(), sqlite3MPrintf(), sqlite3MulInt64(), sqlite3OomFault(), sqlite3OpcodeProperty, sqlite3PagerCloseWal(), sqlite3PagerFilename(), sqlite3PagerGetJournalMode(), sqlite3PagerOkToChangeJournalMode(), sqlite3PagerSetJournalMode(), sqlite3PagerWalSupported(), sqlite3ResetAllSchemasOfConnection(), sqlite3ResetOneSchema(), sqlite3RollbackAll(), sqlite3RootPageMoved(), sqlite3RowSetInsert(), sqlite3RowSetNext(), sqlite3RowSetTest(), sqlite3RunVacuum(), sqlite3SchemaClear(), sqlite3StrICmp(), sqlite3Strlen30(), sqlite3SubInt64(), sqlite3SystemError(), sqlite3UnlinkAndDeleteIndex(), sqlite3UnlinkAndDeleteTable(), sqlite3UnlinkAndDeleteTrigger(), sqlite3VarintLen(), sqlite3VdbeAllocUnpackedRecord(), sqlite3VdbeAssertAbortable, sqlite3VdbeBooleanValue(), sqlite3VdbeChangeEncoding(), sqlite3VdbeCheckFk(), sqlite3VdbeCloseStatement(), sqlite3VdbeCursorMoveto(), sqlite3VdbeCursorRestore(), sqlite3VdbeDeleteAuxData(), sqlite3VdbeEnter(), sqlite3VdbeError(), sqlite3VdbeExpandSql(), sqlite3VdbeFinishMoveto(), sqlite3VdbeFrameMemDel(), sqlite3VdbeFrameRestore(), sqlite3VdbeFreeCursor(), sqlite3VdbeHalt(), sqlite3VdbeIdxKeyCompare(), sqlite3VdbeIdxRowid(), sqlite3VdbeIncrWriteCounter, sqlite3VdbeIntValue(), sqlite3VdbeIOTraceSql, sqlite3VdbeLeave(), sqlite3VdbeMemAggValue(), sqlite3VdbeMemCast(), sqlite3VdbeMemClearAndResize(), sqlite3VdbeMemCopy(), sqlite3VdbeMemExpandBlob(), sqlite3VdbeMemFinalize(), sqlite3VdbeMemFromBtree(), sqlite3VdbeMemFromBtreeZeroOffset(), sqlite3VdbeMemGrow(), sqlite3VdbeMemInit(), sqlite3VdbeMemIntegerify(), sqlite3VdbeMemMove(), sqlite3VdbeMemNulTerminate(), sqlite3VdbeMemRealify(), sqlite3VdbeMemRelease(), sqlite3VdbeMemSetInt64(), sqlite3VdbeMemSetNull(), sqlite3VdbeMemSetRowSet(), sqlite3VdbeMemSetStr(), sqlite3VdbeMemShallowCopy(), sqlite3VdbeMemStringify(), sqlite3VdbeMemTooBig(), sqlite3VdbeOneByteSerialTypeLen(), sqlite3VdbeRealValue(), sqlite3VdbeRecordUnpack(), sqlite3VdbeSerialGet(), sqlite3VdbeSerialPut(), sqlite3VdbeSerialTypeLen(), sqlite3VdbeSetChanges(), sqlite3VdbeSorterCompare(), sqlite3VdbeSorterInit(), sqlite3VdbeSorterNext(), sqlite3VdbeSorterReset(), sqlite3VdbeSorterRewind(), sqlite3VdbeSorterRowkey(), sqlite3VdbeSorterWrite(), sqlite3VListNumToName(), sqlite3VtabBegin(), sqlite3VtabCallCreate(), sqlite3VtabCallDestroy(), sqlite3VtabImportErrmsg(), sqlite3VtabSavepoint(), SQLITE_ABORT_ROLLBACK, SQLITE_AFF_BLOB, SQLITE_AFF_INTEGER, SQLITE_AFF_MASK, SQLITE_AFF_NONE, SQLITE_AFF_NUMERIC, SQLITE_AFF_REAL, SQLITE_AFF_TEXT, SQLITE_BUSY, SQLITE_BUSY_RECOVERY, SQLITE_BUSY_SNAPSHOT, SQLITE_CHECKPOINT_FULL, SQLITE_CHECKPOINT_PASSIVE, SQLITE_CHECKPOINT_RESTART, SQLITE_CHECKPOINT_TRUNCATE, SQLITE_CONSTRAINT, SQLITE_CORRUPT_BKPT, SQLITE_CORRUPT_INDEX, SQLITE_CountRows, SQLITE_DeferFKs, SQLITE_DELETE, SQLITE_DONE, SQLITE_ERROR, SQLITE_FCNTL_TRACE, SQLITE_FRAME_MAGIC, SQLITE_FULL, SQLITE_INSERT, SQLITE_INTERRUPT, SQLITE_IOERR_NOMEM, SQLITE_JUMPIFNULL, SQLITE_KEEPNULL, SQLITE_LegacyAlter, SQLITE_LIMIT_LENGTH, SQLITE_LIMIT_TRIGGER_DEPTH, SQLITE_LOCKED, SQLITE_MAX_LENGTH, SQLITE_MISMATCH, SQLITE_N_BTREE_META, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_NULLEQ, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_EXCLUSIVE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_TRANSIENT_DB, SQLITE_QueryOnly, SQLITE_READONLY, SQLITE_ReadUncommit, SQLITE_ROW, SQLITE_SCHEMA, SQLITE_STATIC, SQLITE_STMTSTATUS_RUN, SQLITE_STMTSTATUS_SORT, SQLITE_STMTSTATUS_VM_STEP, SQLITE_STOREP2, SQLITE_TOOBIG, SQLITE_TRACE_LEGACY, SQLITE_TRACE_ROW, SQLITE_TRACE_STMT, SQLITE_UPDATE, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, sqlite3_value::szMalloc, VdbeCursor::szRow, testcase, SubProgram::token, VdbeFrame::token, sqlite3::trace, sqlite3_value::u, sqlite3::u1, VdbeCursor::uc, UPDATE_MAX_BLOBSIZE, VdbeCursor::useRandomRowid, Vdbe::usesStmtJournal, sqlite3_value::uTemp, VdbeFrame::v, VDBE_MAGIC_RUN, VdbeBranchTaken, VdbeFrameMem, VdbeMemDynamic, sqlite3::vtabOnConflict, VdbeOp::p4union::xAdvance, sqlite3_module::xClose, sqlite3_module::xColumn, sqlite3_value::xDel, sqlite3_module::xEof, sqlite3_module::xFilter, FuncDef::xInverse, sqlite3::xLegacy, sqlite3_module::xNext, sqlite3_module::xOpen, sqlite3::xProgress, sqlite3_module::xRename, sqlite3_module::xRowid, FuncDef::xSFunc, sqlite3_module::xUpdate, sqlite3::xUpdateCallback, sqlite3::xV2, VdbeOp::p4union::z, sqlite3_value::z, Db::zDbSName, Vdbe::zErrMsg, sqlite3_value::zMalloc, Savepoint::zName, Table::zName, zName, and Vdbe::zSql.

Referenced by blobSeekToRow(), and sqlite3Step().

◆ sqlite3VdbeExpandSql()

SQLITE_PRIVATE char * sqlite3VdbeExpandSql ( Vdbe * p,
const char * zRawSql )

Definition at line 85107 of file sqlite3.c.

85116 {
85117 sqlite3 *db; /* The database connection */
85118 int idx = 0; /* Index of a host parameter */
85119 int nextIndex = 1; /* Index of next ? host parameter */
85120 int n; /* Length of a token prefix */
85121 int nToken; /* Length of the parameter token */
85122 int i; /* Loop counter */
85123 Mem *pVar; /* Value of a host parameter */
85124 StrAccum out; /* Accumulate the output here */
85125#ifndef SQLITE_OMIT_UTF16
85126 Mem utf8; /* Used to convert UTF16 into UTF8 for display */
85127#endif
85128 char zBase[100]; /* Initial working space */
85129
85130 db = p->db;
85131 sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase),
85133 if( db->nVdbeExec>1 ){
85134 while( *zRawSql ){
85135 const char *zStart = zRawSql;
85136 while( *(zRawSql++)!='\n' && *zRawSql );
85137 sqlite3_str_append(&out, "-- ", 3);
85138 assert( (zRawSql - zStart) > 0 );
85139 sqlite3_str_append(&out, zStart, (int)(zRawSql-zStart));
85140 }
85141 }else if( p->nVar==0 ){
85142 sqlite3_str_append(&out, zRawSql, sqlite3Strlen30(zRawSql));
85143 }else{
85144 while( zRawSql[0] ){
85145 n = findNextHostParameter(zRawSql, &nToken);
85146 assert( n>0 );
85147 sqlite3_str_append(&out, zRawSql, n);
85148 zRawSql += n;
85149 assert( zRawSql[0] || nToken==0 );
85150 if( nToken==0 ) break;
85151 if( zRawSql[0]=='?' ){
85152 if( nToken>1 ){
85153 assert( sqlite3Isdigit(zRawSql[1]) );
85154 sqlite3GetInt32(&zRawSql[1], &idx);
85155 }else{
85156 idx = nextIndex;
85157 }
85158 }else{
85159 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
85160 zRawSql[0]=='@' || zRawSql[0]=='#' );
85161 testcase( zRawSql[0]==':' );
85162 testcase( zRawSql[0]=='$' );
85163 testcase( zRawSql[0]=='@' );
85164 testcase( zRawSql[0]=='#' );
85165 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
85166 assert( idx>0 );
85167 }
85168 zRawSql += nToken;
85169 nextIndex = idx + 1;
85170 assert( idx>0 && idx<=p->nVar );
85171 pVar = &p->aVar[idx-1];
85172 if( pVar->flags & MEM_Null ){
85173 sqlite3_str_append(&out, "NULL", 4);
85174 }else if( pVar->flags & (MEM_Int|MEM_IntReal) ){
85175 sqlite3_str_appendf(&out, "%lld", pVar->u.i);
85176 }else if( pVar->flags & MEM_Real ){
85177 sqlite3_str_appendf(&out, "%!.15g", pVar->u.r);
85178 }else if( pVar->flags & MEM_Str ){
85179 int nOut; /* Number of bytes of the string text to include in output */
85180#ifndef SQLITE_OMIT_UTF16
85181 u8 enc = ENC(db);
85182 if( enc!=SQLITE_UTF8 ){
85183 memset(&utf8, 0, sizeof(utf8));
85184 utf8.db = db;
85185 sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
85187 out.accError = SQLITE_NOMEM;
85188 out.nAlloc = 0;
85189 }
85190 pVar = &utf8;
85191 }
85192#endif
85193 nOut = pVar->n;
85194#ifdef SQLITE_TRACE_SIZE_LIMIT
85195 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
85196 nOut = SQLITE_TRACE_SIZE_LIMIT;
85197 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
85198 }
85199#endif
85200 sqlite3_str_appendf(&out, "'%.*q'", nOut, pVar->z);
85201#ifdef SQLITE_TRACE_SIZE_LIMIT
85202 if( nOut<pVar->n ){
85203 sqlite3_str_appendf(&out, "/*+%d bytes*/", pVar->n-nOut);
85204 }
85205#endif
85206#ifndef SQLITE_OMIT_UTF16
85207 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
85208#endif
85209 }else if( pVar->flags & MEM_Zero ){
85210 sqlite3_str_appendf(&out, "zeroblob(%d)", pVar->u.nZero);
85211 }else{
85212 int nOut; /* Number of bytes of the blob to include in output */
85213 assert( pVar->flags & MEM_Blob );
85214 sqlite3_str_append(&out, "x'", 2);
85215 nOut = pVar->n;
85216#ifdef SQLITE_TRACE_SIZE_LIMIT
85217 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
85218#endif
85219 for(i=0; i<nOut; i++){
85220 sqlite3_str_appendf(&out, "%02x", pVar->z[i]&0xff);
85221 }
85222 sqlite3_str_append(&out, "'", 1);
85223#ifdef SQLITE_TRACE_SIZE_LIMIT
85224 if( nOut<pVar->n ){
85225 sqlite3_str_appendf(&out, "/*+%d bytes*/", pVar->n-nOut);
85226 }
85227#endif
static int findNextHostParameter(const char *zSql, int *pnToken)
Definition sqlite3.c:85064
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *, const char *, int)
Definition sqlite3.c:84584

References sqlite3_str::accError, sqlite3::aLimit, Vdbe::aVar, sqlite3_value::db, Vdbe::db, ENC, findNextHostParameter(), sqlite3_value::flags, sqlite3_value::MemValue::i, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, MEM_Zero, sqlite3_value::n, sqlite3_str::nAlloc, Vdbe::nVar, sqlite3::nVdbeExec, sqlite3_value::MemValue::nZero, sqlite3_value::MemValue::r, sqlite3_str_append(), sqlite3_str_appendf(), sqlite3_str_reset(), sqlite3GetInt32(), sqlite3Isdigit, sqlite3StrAccumFinish(), sqlite3StrAccumInit(), sqlite3Strlen30(), sqlite3VdbeChangeEncoding(), sqlite3VdbeMemRelease(), sqlite3VdbeMemSetStr(), sqlite3VdbeParameterIndex(), SQLITE_LIMIT_LENGTH, SQLITE_NOMEM, SQLITE_STATIC, SQLITE_UTF8, testcase, sqlite3_value::u, and sqlite3_value::z.

Referenced by sqlite3_expanded_sql(), and sqlite3VdbeExec().

◆ sqlite3VdbeExplain()

SQLITE_PRIVATE void sqlite3VdbeExplain ( Parse * pParse,
u8 bPush,
const char * zFmt,
... )

Definition at line 78164 of file sqlite3.c.

78170 {
78171#ifndef SQLITE_DEBUG
78172 /* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
78173 ** But omit them (for performance) during production builds */
78174 if( pParse->explain==2 )
78175#endif
78176 {
78177 char *zMsg;
78178 Vdbe *v;
78179 va_list ap;
78180 int iThis;
78181 va_start(ap, zFmt);
78182 zMsg = sqlite3VMPrintf(pParse->db, zFmt, ap);
78183 va_end(ap);
78184 v = pParse->pVdbe;
78185 iThis = v->nOp;
78186 sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
78187 zMsg, P4_DYNAMIC);

References Parse::addrExplain, Parse::db, Parse::explain, Vdbe::nOp, OP_Explain, VdbeOp::p4, P4_DYNAMIC, ValueNewStat4Ctx::pParse, Parse::pVdbe, sqlite3ExplainBreakpoint, sqlite3VdbeAddOp4(), sqlite3VdbeGetOp(), sqlite3VMPrintf(), and VdbeOp::p4union::z.

Referenced by explainSimpleCount().

◆ sqlite3VdbeExplainParent()

SQLITE_PRIVATE int sqlite3VdbeExplainParent ( Parse * pParse)

◆ sqlite3VdbeExplainPop()

SQLITE_PRIVATE void sqlite3VdbeExplainPop ( Parse * pParse)

Definition at line 78192 of file sqlite3.c.

◆ sqlite3VdbeFinalize()

SQLITE_PRIVATE int sqlite3VdbeFinalize ( Vdbe * p)

Definition at line 81114 of file sqlite3.c.

81120 {
81121 int rc = SQLITE_OK;
81122 if( p->magic==VDBE_MAGIC_RUN || p->magic==VDBE_MAGIC_HALT ){
#define VDBE_MAGIC_HALT
Definition sqlite3.c:21161

Referenced by sqlite3_declare_vtab(), sqlite3_exec(), sqlite3_finalize(), and sqlite3Reprepare().

◆ sqlite3VdbeFindCompare()

SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare ( UnpackedRecord * p)

Definition at line 82582 of file sqlite3.c.

82588 {
82589 /* varintRecordCompareInt() and varintRecordCompareString() both assume
82590 ** that the size-of-header varint that occurs at the start of each record
82591 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
82592 ** also assumes that it is safe to overread a buffer by at least the
82593 ** maximum possible legal header size plus 8 bytes. Because there is
82594 ** guaranteed to be at least 74 (but not 136) bytes of padding following each
82595 ** buffer passed to varintRecordCompareInt() this makes it convenient to
82596 ** limit the size of the header to 64 bytes in cases where the first field
82597 ** is an integer.
82598 **
82599 ** The easiest way to enforce this limit is to consider only records with
82600 ** 13 fields or less. If the first field is an integer, the maximum legal
82601 ** header size is (12*5 + 1 + 1) bytes. */
82602 if( p->pKeyInfo->nAllField<=13 ){
82603 int flags = p->aMem[0].flags;
82604 if( p->pKeyInfo->aSortFlags[0] ){
82607 }
82608 p->r1 = 1;
82609 p->r2 = -1;
82610 }else{
82611 p->r1 = -1;
82612 p->r2 = 1;
82613 }
82614 if( (flags & MEM_Int) ){
82615 return vdbeRecordCompareInt;
82616 }
82617 testcase( flags & MEM_Real );
82618 testcase( flags & MEM_Null );
82619 testcase( flags & MEM_Blob );
82620 if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
82621 && p->pKeyInfo->aColl[0]==0
82622 ){
82623 assert( flags & MEM_Str );
static int vdbeRecordCompareInt(int nKey1, const void *pKey1, UnpackedRecord *pPKey2)
Definition sqlite3.c:82424

References KeyInfo::aColl, UnpackedRecord::aMem, KeyInfo::aSortFlags, sqlite3_value::flags, KEYINFO_ORDER_BIGNULL, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, KeyInfo::nAllField, UnpackedRecord::pKeyInfo, UnpackedRecord::r1, UnpackedRecord::r2, sqlite3VdbeRecordCompare(), testcase, vdbeRecordCompareInt(), and vdbeRecordCompareString().

Referenced by sqlite3BtreeMovetoUnpacked().

◆ sqlite3VdbeFinishMoveto()

SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto ( VdbeCursor * p)

Definition at line 81235 of file sqlite3.c.

81241 {
81242 int res, rc;
81243#ifdef SQLITE_TEST
81244 extern int sqlite3_search_count;
81245#endif
81246 assert( p->deferredMoveto );
81247 assert( p->isTable );
81248 assert( p->eCurType==CURTYPE_BTREE );
81249 rc = sqlite3BtreeMovetoUnpacked(p->uc.pCursor, 0, p->movetoTarget, 0, &res);
81250 if( rc ) return rc;
81251 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
81252#ifdef SQLITE_TEST

References CACHE_STALE, VdbeCursor::cacheStatus, CURTYPE_BTREE, VdbeCursor::deferredMoveto, VdbeCursor::eCurType, VdbeCursor::isTable, VdbeCursor::movetoTarget, VdbeCursor::pCursor, sqlite3BtreeMovetoUnpacked(), SQLITE_CORRUPT_BKPT, SQLITE_OK, and VdbeCursor::uc.

Referenced by sqlite3VdbeCursorMoveto(), and sqlite3VdbeExec().

◆ sqlite3VdbeFrameDelete()

SQLITE_PRIVATE void sqlite3VdbeFrameDelete ( VdbeFrame * p)

Definition at line 79802 of file sqlite3.c.

79808 {
79809 int i;
79810 Mem *aMem = VdbeFrameMem(p);
79811 VdbeCursor **apCsr = (VdbeCursor **)&aMem[p->nChildMem];
79812 assert( sqlite3VdbeFrameIsValid(p) );
79813 for(i=0; i<p->nChildCsr; i++){

References Vdbe::db, VdbeFrame::nChildCsr, VdbeFrame::nChildMem, VdbeFrame::pAuxData, releaseMemArray(), sqlite3DbFree(), sqlite3VdbeDeleteAuxData(), sqlite3VdbeFreeCursor(), VdbeFrame::v, and VdbeFrameMem.

Referenced by closeAllCursors().

◆ sqlite3VdbeFrameMemDel()

SQLITE_PRIVATE void sqlite3VdbeFrameMemDel ( void * pArg)

Definition at line 79675 of file sqlite3.c.

References Vdbe::pDelFrame, VdbeFrame::pParent, and VdbeFrame::v.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeFrameRestore()

SQLITE_PRIVATE int sqlite3VdbeFrameRestore ( VdbeFrame * pFrame)

Definition at line 80255 of file sqlite3.c.

80261 {
80262 Vdbe *v = pFrame->v;
80264#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
80265 v->anExec = pFrame->anExec;
80266#endif
80267 v->aOp = pFrame->aOp;
80268 v->nOp = pFrame->nOp;
80269 v->aMem = pFrame->aMem;
80270 v->nMem = pFrame->nMem;
80271 v->apCsr = pFrame->apCsr;
80272 v->nCursor = pFrame->nCursor;
80273 v->db->lastRowid = pFrame->lastRowid;
80274 v->nChange = pFrame->nChange;

References VdbeFrame::aMem, Vdbe::aMem, VdbeFrame::anExec, VdbeFrame::aOp, Vdbe::aOp, VdbeFrame::apCsr, Vdbe::apCsr, closeCursorsInFrame(), Vdbe::db, sqlite3::lastRowid, VdbeFrame::lastRowid, sqlite3::nChange, VdbeFrame::nChange, Vdbe::nChange, VdbeFrame::nCursor, Vdbe::nCursor, VdbeFrame::nDbChange, VdbeFrame::nMem, Vdbe::nMem, VdbeFrame::nOp, Vdbe::nOp, VdbeFrame::pAuxData, Vdbe::pAuxData, VdbeFrame::pc, sqlite3VdbeDeleteAuxData(), and VdbeFrame::v.

Referenced by closeAllCursors(), and sqlite3VdbeExec().

◆ sqlite3VdbeFreeCursor()

SQLITE_PRIVATE void sqlite3VdbeFreeCursor ( Vdbe * p,
VdbeCursor * pCx )

Definition at line 80200 of file sqlite3.c.

80206 {
80207 if( pCx==0 ){
80208 return;
80209 }
80210 assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
80211 switch( pCx->eCurType ){
80212 case CURTYPE_SORTER: {
80213 sqlite3VdbeSorterClose(p->db, pCx);
80214 break;
80215 }
80216 case CURTYPE_BTREE: {
80217 if( pCx->isEphemeral ){
80218 if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
80219 /* The pCx->pCursor will be close automatically, if it exists, by
80220 ** the call above. */
80221 }else{
80222 assert( pCx->uc.pCursor!=0 );
80224 }
80225 break;
80226 }
80227#ifndef SQLITE_OMIT_VIRTUALTABLE
80228 case CURTYPE_VTAB: {
80229 sqlite3_vtab_cursor *pVCur = pCx->uc.pVCur;
80230 const sqlite3_module *pModule = pVCur->pVtab->pModule;
80231 assert( pVCur->pVtab->nRef>0 );
80232 pVCur->pVtab->nRef--;
SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *)
Definition sqlite3.c:95137

Referenced by allocateCursor(), sqlite3VdbeExec(), and sqlite3VdbeFrameDelete().

◆ sqlite3VdbeGetBoundValue()

SQLITE_PRIVATE sqlite3_value * sqlite3VdbeGetBoundValue ( Vdbe * v,
int iVar,
u8 aff )

Definition at line 82808 of file sqlite3.c.

82814 {
82815 assert( iVar>0 );
82816 if( v ){
82817 Mem *pMem = &v->aVar[iVar-1];
82818 assert( (v->db->flags & SQLITE_EnableQPSG)==0 );
82819 if( 0==(pMem->flags & MEM_Null) ){
82820 sqlite3_value *pRet = sqlite3ValueNew(v->db);
82821 if( pRet ){
82822 sqlite3VdbeMemCopy((Mem *)pRet, pMem);
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8)
Definition sqlite3.c:85654

References Vdbe::aVar, Vdbe::db, sqlite3::flags, sqlite3_value::flags, MEM_Null, sqlite3ValueApplyAffinity(), sqlite3ValueNew(), sqlite3VdbeMemCopy(), SQLITE_EnableQPSG, and SQLITE_UTF8.

Referenced by exprCompareVariable(), and isLikeOrGlob().

◆ sqlite3VdbeGetOp()

SQLITE_PRIVATE VdbeOp * sqlite3VdbeGetOp ( Vdbe * p,
int addr )

Definition at line 79158 of file sqlite3.c.

79164 {
79165 /* C89 specifies that the constant "dummy" will be initialized to all
79166 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
79167 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
79168 assert( p->magic==VDBE_MAGIC_INIT );
79169 if( addr<0 ){
79170 addr = p->nOp - 1;
79171 }
79172 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );

References Vdbe::aOp, Vdbe::db, dummy, Vdbe::magic, sqlite3::mallocFailed, Vdbe::nOp, and VDBE_MAGIC_INIT.

Referenced by readsTable(), selectInnerLoop(), sqlite3ComputeGeneratedColumns(), sqlite3ExprCodeExprList(), sqlite3ExprCodeGetColumn(), sqlite3FinishCoding(), sqlite3GenerateConstraintChecks(), sqlite3Insert(), sqlite3Pragma(), sqlite3VdbeChangeP2(), sqlite3VdbeChangeP3(), sqlite3VdbeChangeP5(), sqlite3VdbeExplain(), sqlite3VdbeExplainParent(), sqlite3VdbeJumpHereOrPopInst(), sqlite3WhereEnd(), translateColumnToCopy(), whereLikeOptimizationStringFixup(), and windowAggStep().

◆ sqlite3VdbeGoto()

◆ sqlite3VdbeHalt()

SQLITE_PRIVATE int sqlite3VdbeHalt ( Vdbe * p)

Definition at line 80755 of file sqlite3.c.

80761 {
80762 int rc; /* Used to store transient return codes */
80763 sqlite3 *db = p->db;
80764
80765 /* This function contains the logic that determines if a statement or
80766 ** transaction will be committed or rolled back as a result of the
80767 ** execution of this virtual machine.
80768 **
80769 ** If any of the following errors occur:
80770 **
80771 ** SQLITE_NOMEM
80772 ** SQLITE_IOERR
80773 ** SQLITE_FULL
80774 ** SQLITE_INTERRUPT
80775 **
80776 ** Then the internal cache might have been left in an inconsistent
80777 ** state. We need to rollback the statement transaction, if there is
80778 ** one, or the complete transaction if there is no statement transaction.
80779 */
80780
80781 if( p->magic!=VDBE_MAGIC_RUN ){
80782 return SQLITE_OK;
80783 }
80784 if( db->mallocFailed ){
80785 p->rc = SQLITE_NOMEM_BKPT;
80786 }
80787 closeAllCursors(p);
80789
80790 /* No commit or rollback needed if the program never started or if the
80791 ** SQL statement does not read or write a database file. */
80792 if( p->pc>=0 && p->bIsReader ){
80793 int mrc; /* Primary error code from p->rc */
80794 int eStatementOp = 0;
80795 int isSpecialError; /* Set to true if a 'special' error */
80796
80797 /* Lock all btrees used by the statement */
80799
80800 /* Check for one of the special errors */
80801 mrc = p->rc & 0xff;
80802 isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR
80803 || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL;
80804 if( isSpecialError ){
80805 /* If the query was read-only and the error code is SQLITE_INTERRUPT,
80806 ** no rollback is necessary. Otherwise, at least a savepoint
80807 ** transaction must be rolled back to restore the database to a
80808 ** consistent state.
80809 **
80810 ** Even if the statement is read-only, it is important to perform
80811 ** a statement or transaction rollback operation. If the error
80812 ** occurred while writing to the journal, sub-journal or database
80813 ** file as part of an effort to free up cache space (see function
80814 ** pagerStress() in pager.c), the rollback is required to restore
80815 ** the pager to a consistent state.
80816 */
80817 if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
80818 if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL) && p->usesStmtJournal ){
80819 eStatementOp = SAVEPOINT_ROLLBACK;
80820 }else{
80821 /* We are forced to roll back the active transaction. Before doing
80822 ** so, abort any other statements this handle currently has active.
80823 */
80826 db->autoCommit = 1;
80827 p->nChange = 0;
80828 }
80829 }
80830 }
80831
80832 /* Check for immediate foreign key violations. */
80833 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
80834 sqlite3VdbeCheckFk(p, 0);
80835 }
80836
80837 /* If the auto-commit flag is set and this is the only active writer
80838 ** VM, then we do either a commit or rollback of the current transaction.
80839 **
80840 ** Note: This block also runs if one of the special errors handled
80841 ** above has occurred.
80842 */
80843 if( !sqlite3VtabInSync(db)
80844 && db->autoCommit
80845 && db->nVdbeWrite==(p->readOnly==0)
80846 ){
80847 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
80848 rc = sqlite3VdbeCheckFk(p, 1);
80849 if( rc!=SQLITE_OK ){
80850 if( NEVER(p->readOnly) ){
80852 return SQLITE_ERROR;
80853 }
80855 }else{
80856 /* The auto-commit flag is true, the vdbe program was successful
80857 ** or hit an 'OR FAIL' constraint and there are no deferred foreign
80858 ** key constraints to hold up the transaction. This means a commit
80859 ** is required. */
80860 rc = vdbeCommit(db, p);
80861 }
80862 if( rc==SQLITE_BUSY && p->readOnly ){
80864 return SQLITE_BUSY;
80865 }else if( rc!=SQLITE_OK ){
80866 p->rc = rc;
80868 p->nChange = 0;
80869 }else{
80870 db->nDeferredCons = 0;
80871 db->nDeferredImmCons = 0;
80872 db->flags &= ~(u64)SQLITE_DeferFKs;
80874 }
80875 }else{
80877 p->nChange = 0;
80878 }
80879 db->nStatement = 0;
80880 }else if( eStatementOp==0 ){
80881 if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
80882 eStatementOp = SAVEPOINT_RELEASE;
80883 }else if( p->errorAction==OE_Abort ){
80884 eStatementOp = SAVEPOINT_ROLLBACK;
80885 }else{
80888 db->autoCommit = 1;
80889 p->nChange = 0;
80890 }
80891 }
80892
80893 /* If eStatementOp is non-zero, then a statement transaction needs to
80894 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
80895 ** do so. If this operation returns an error, and the current statement
80896 ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
80897 ** current statement error code.
80898 */
80899 if( eStatementOp ){
80900 rc = sqlite3VdbeCloseStatement(p, eStatementOp);
80901 if( rc ){
80902 if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){
80903 p->rc = rc;
80904 sqlite3DbFree(db, p->zErrMsg);
80905 p->zErrMsg = 0;
80906 }
80909 db->autoCommit = 1;
80910 p->nChange = 0;
80911 }
80912 }
80913
80914 /* If this was an INSERT, UPDATE or DELETE and no statement transaction
80915 ** has been rolled back, update the database connection change-counter.
80916 */
80917 if( p->changeCntOn ){
80918 if( eStatementOp!=SAVEPOINT_ROLLBACK ){
80920 }else{
80921 sqlite3VdbeSetChanges(db, 0);
80922 }
80923 p->nChange = 0;
80924 }
80925
80926 /* Release the locks */
80928 }
80929
80930 /* We have successfully halted and closed the VM. Record this fact. */
80931 if( p->pc>=0 ){
80932 db->nVdbeActive--;
80933 if( !p->readOnly ) db->nVdbeWrite--;
80934 if( p->bIsReader ) db->nVdbeRead--;
80935 assert( db->nVdbeActive>=db->nVdbeRead );
80936 assert( db->nVdbeRead>=db->nVdbeWrite );
80937 assert( db->nVdbeWrite>=0 );
80938 }
80941 if( db->mallocFailed ){
80942 p->rc = SQLITE_NOMEM_BKPT;
80943 }
80944
80945 /* If the auto-commit flag is set to true, then any locks that were held
80946 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
80947 ** to invoke any required unlock-notify callbacks.
80948 */
80949 if( db->autoCommit ){
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *)
Definition sqlite3.c:111013
static int vdbeCommit(sqlite3 *db, Vdbe *p)
Definition sqlite3.c:80367
#define checkActiveVdbeCnt(x)
Definition sqlite3.c:80650
#define sqlite3VtabInSync(db)
Definition sqlite3.c:20115
static void closeAllCursors(Vdbe *p)
Definition sqlite3.c:80284
bft changeCntOn
Definition sqlite3.c:21129

References sqlite3::autoCommit, Vdbe::bIsReader, Vdbe::changeCntOn, checkActiveVdbeCnt, closeAllCursors(), Vdbe::db, Vdbe::errorAction, sqlite3::flags, Vdbe::magic, sqlite3::mallocFailed, Vdbe::nChange, sqlite3::nDeferredCons, sqlite3::nDeferredImmCons, NEVER, sqlite3::nStatement, sqlite3::nVdbeActive, sqlite3::nVdbeRead, sqlite3::nVdbeWrite, OE_Abort, OE_Fail, Vdbe::pc, Vdbe::rc, Vdbe::readOnly, SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, sqlite3CloseSavepoints(), sqlite3CommitInternalChanges(), sqlite3ConnectionUnlocked, sqlite3DbFree(), sqlite3RollbackAll(), sqlite3VdbeCheckFk(), sqlite3VdbeCloseStatement(), sqlite3VdbeEnter(), sqlite3VdbeLeave(), sqlite3VdbeSetChanges(), sqlite3VtabInSync, SQLITE_ABORT_ROLLBACK, SQLITE_BUSY, SQLITE_CONSTRAINT, SQLITE_CONSTRAINT_FOREIGNKEY, SQLITE_DeferFKs, SQLITE_ERROR, SQLITE_FULL, SQLITE_INTERRUPT, SQLITE_IOERR, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, Vdbe::usesStmtJournal, VDBE_MAGIC_HALT, VDBE_MAGIC_RUN, vdbeCommit(), and Vdbe::zErrMsg.

Referenced by sqlite3VdbeExec(), and sqlite3VdbeReset().

◆ sqlite3VdbeHasSubProgram()

SQLITE_PRIVATE int sqlite3VdbeHasSubProgram ( Vdbe * pVdbe)

Definition at line 78926 of file sqlite3.c.

Referenced by sqlite3Insert().

◆ sqlite3VdbeIdxKeyCompare()

SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare ( sqlite3 * db,
VdbeCursor * pC,
UnpackedRecord * pUnpacked,
int * res )

Definition at line 82712 of file sqlite3.c.

82723 {
82724 i64 nCellKey = 0;
82725 int rc;
82726 BtCursor *pCur;
82727 Mem m;
82728
82729 assert( pC->eCurType==CURTYPE_BTREE );
82730 pCur = pC->uc.pCursor;
82731 assert( sqlite3BtreeCursorIsValid(pCur) );
82732 nCellKey = sqlite3BtreePayloadSize(pCur);
82733 /* nCellKey will always be between 0 and 0xffffffff because of the way
82734 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
82735 if( nCellKey<=0 || nCellKey>0x7fffffff ){
82736 *res = 0;
82737 return SQLITE_CORRUPT_BKPT;
82738 }
82739 sqlite3VdbeMemInit(&m, db, 0);
82740 rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m);
82741 if( rc ){

References CURTYPE_BTREE, VdbeCursor::eCurType, sqlite3_value::n, VdbeCursor::pCursor, sqlite3BtreePayloadSize(), sqlite3VdbeMemFromBtreeZeroOffset(), sqlite3VdbeMemInit(), sqlite3VdbeMemRelease(), sqlite3VdbeRecordCompareWithSkip(), SQLITE_CORRUPT_BKPT, SQLITE_OK, VdbeCursor::uc, and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeIdxRowid()

SQLITE_PRIVATE int sqlite3VdbeIdxRowid ( sqlite3 * db,
BtCursor * pCur,
i64 * rowid )

Definition at line 82633 of file sqlite3.c.

82639 {
82640 i64 nCellKey = 0;
82641 int rc;
82642 u32 szHdr; /* Size of the header */
82643 u32 typeRowid; /* Serial type of the rowid */
82644 u32 lenRowid; /* Size of the rowid */
82645 Mem m, v;
82646
82647 /* Get the size of the index entry. Only indices entries of less
82648 ** than 2GiB are support - anything large must be database corruption.
82649 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
82650 ** this code can safely assume that nCellKey is 32-bits
82651 */
82652 assert( sqlite3BtreeCursorIsValid(pCur) );
82653 nCellKey = sqlite3BtreePayloadSize(pCur);
82654 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
82655
82656 /* Read in the complete content of the index entry */
82657 sqlite3VdbeMemInit(&m, db, 0);
82658 rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m);
82659 if( rc ){
82660 return rc;
82661 }
82662
82663 /* The index entry must begin with a header size */
82664 getVarint32NR((u8*)m.z, szHdr);
82665 testcase( szHdr==3 );
82666 testcase( szHdr==m.n );
82667 testcase( szHdr>0x7fffffff );
82668 assert( m.n>=0 );
82669 if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){
82670 goto idx_rowid_corruption;
82671 }
82672
82673 /* The last field of the index should be an integer - the ROWID.
82674 ** Verify that the last entry really is an integer. */
82675 getVarint32NR((u8*)&m.z[szHdr-1], typeRowid);
82676 testcase( typeRowid==1 );
82677 testcase( typeRowid==2 );
82678 testcase( typeRowid==3 );
82679 testcase( typeRowid==4 );
82680 testcase( typeRowid==5 );
82681 testcase( typeRowid==6 );
82682 testcase( typeRowid==8 );
82683 testcase( typeRowid==9 );
82684 if( unlikely(typeRowid<1 || typeRowid>9 || typeRowid==7) ){
82685 goto idx_rowid_corruption;
82686 }
82687 lenRowid = sqlite3SmallTypeSizes[typeRowid];
82688 testcase( (u32)m.n==szHdr+lenRowid );
82689 if( unlikely((u32)m.n<szHdr+lenRowid) ){
82690 goto idx_rowid_corruption;
82691 }
82692
82693 /* Fetch the integer off the end of the index record */
82694 sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v);
82695 *rowid = v.u.i;
82697 return SQLITE_OK;
82698
82699 /* Jump here if database corruption is detected after m has been
static const u8 sqlite3SmallTypeSizes[]
Definition sqlite3.c:81433
#define getVarint32NR(A, B)
Definition sqlite3.c:19870

References getVarint32NR, sqlite3_value::MemValue::i, sqlite3_value::n, sqlite3BtreePayloadSize(), sqlite3SmallTypeSizes, sqlite3VdbeMemFromBtreeZeroOffset(), sqlite3VdbeMemInit(), sqlite3VdbeMemRelease(), sqlite3VdbeSerialGet(), SQLITE_CORRUPT_BKPT, SQLITE_MAX_U32, SQLITE_OK, sqlite3_value::szMalloc, testcase, sqlite3_value::u, unlikely, and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeIntegerAffinity()

SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity ( Mem * pMem)

Definition at line 76476 of file sqlite3.c.

76482 {
76483 i64 ix;
76484 assert( pMem->flags & MEM_Real );
76485 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76486 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76487 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
76488
76489 ix = doubleToInt64(pMem->u.r);
76490
76491 /* Only mark the value as an integer if
76492 **
76493 ** (1) the round-trip conversion real->int->real is a no-op, and
76494 ** (2) The integer is neither the largest nor the smallest
76495 ** possible integer (ticket #3922)
76496 **
76497 ** The second and third terms in the following conditional enforces
76498 ** the second condition under the assumption that addition overflow causes
76499 ** values to wrap around.
static SQLITE_NOINLINE i64 doubleToInt64(double r)
Definition sqlite3.c:76375

Referenced by applyAffinity(), and applyNumericAffinity().

◆ sqlite3VdbeIntValue()

SQLITE_PRIVATE i64 sqlite3VdbeIntValue ( Mem * pMem)

Definition at line 76416 of file sqlite3.c.

76417 {
76418 i64 value = 0;
76419 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
76420 return value;
76421}
76423 int flags;
76424 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76425 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
76426 flags = pMem->flags;
76427 if( flags & (MEM_Int|MEM_IntReal) ){
76428 testcase( flags & MEM_IntReal );
76429 return pMem->u.i;
76430 }else if( flags & MEM_Real ){
76431 return doubleToInt64(pMem->u.r);

References sqlite3_value::enc, sqlite3_value::n, sqlite3Atoi64(), value, and sqlite3_value::z.

Referenced by sqlite3_value_subtype(), and sqlite3VdbeExec().

◆ sqlite3VdbeJumpHere()

◆ sqlite3VdbeJumpHereOrPopInst()

SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst ( Vdbe * p,
int addr )

Definition at line 78814 of file sqlite3.c.

78815 :
78816**
78817** 7 Once 0 8 0
78818** 8 ...
78819*/
78821 if( addr==p->nOp-1 ){
78822 assert( p->aOp[addr].opcode==OP_Once
78823 || p->aOp[addr].opcode==OP_If
78824 || p->aOp[addr].opcode==OP_FkIfZero );
78825 assert( p->aOp[addr].p4type==0 );
78826#ifdef SQLITE_VDBE_COVERAGE
78827 sqlite3VdbeGetOp(p,-1)->iSrcLine = 0; /* Erase VdbeCoverage() macros */

References Vdbe::aOp, Vdbe::nOp, OP_FkIfZero, OP_If, OP_Once, VdbeOp::opcode, VdbeOp::p4type, sqlite3VdbeChangeP2(), and sqlite3VdbeGetOp().

Referenced by fkScanChildren(), sqlite3DeleteFrom(), sqlite3Update(), and updateAccumulator().

◆ sqlite3VdbeLeave()

SQLITE_PRIVATE void sqlite3VdbeLeave ( Vdbe * p)

Definition at line 79556 of file sqlite3.c.

79556 {
79557 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
79558 sqlite3BtreeLeave(aDb[i].pBt);
79559 }

References ALWAYS, DbMaskTest, Vdbe::lockMask, and sqlite3BtreeLeave().

Referenced by sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3VdbeLinkSubProgram()

SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram ( Vdbe * pVdbe,
SubProgram * p )

Definition at line 78918 of file sqlite3.c.

References SubProgram::pNext, and Vdbe::pProgram.

◆ sqlite3VdbeList()

SQLITE_PRIVATE int sqlite3VdbeList ( Vdbe * p)

Definition at line 79834 of file sqlite3.c.

79842 {
79843 Mem *pSub = 0; /* Memory cell hold array of subprogs */
79844 sqlite3 *db = p->db; /* The database connection */
79845 int i; /* Loop counter */
79846 int rc = SQLITE_OK; /* Return code */
79847 Mem *pMem = &p->aMem[1]; /* First Mem of result set */
79848 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
79849 Op *aOp; /* Array of opcodes */
79850 Op *pOp; /* Current opcode */
79851
79852 assert( p->explain );
79853 assert( p->magic==VDBE_MAGIC_RUN );
79854 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
79855
79856 /* Even though this opcode does not use dynamic strings for
79857 ** the result, result columns may become dynamic if the user calls
79858 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
79859 */
79860 releaseMemArray(pMem, 8);
79861 p->pResultSet = 0;
79862
79863 if( p->rc==SQLITE_NOMEM ){
79864 /* This happens if a malloc() inside a call to sqlite3_column_text() or
79865 ** sqlite3_column_text16() failed. */
79866 sqlite3OomFault(db);
79867 return SQLITE_ERROR;
79868 }
79869
79870 if( bListSubprogs ){
79871 /* The first 8 memory cells are used for the result set. So we will
79872 ** commandeer the 9th cell to use as storage for an array of pointers
79873 ** to trigger subprograms. The VDBE is guaranteed to have at least 9
79874 ** cells. */
79875 assert( p->nMem>9 );
79876 pSub = &p->aMem[9];
79877 }else{
79878 pSub = 0;
79879 }
79880
79881 /* Figure out which opcode is next to display */
79882 rc = sqlite3VdbeNextOpcode(p, pSub, p->explain==2, &p->pc, &i, &aOp);
79883
79884 if( rc==SQLITE_OK ){
79885 pOp = aOp + i;
79886 if( AtomicLoad(&db->u1.isInterrupted) ){
79887 p->rc = SQLITE_INTERRUPT;
79888 rc = SQLITE_ERROR;
79890 }else{
79891 char *zP4 = sqlite3VdbeDisplayP4(db, pOp);
79892 if( p->explain==2 ){
79893 sqlite3VdbeMemSetInt64(pMem, pOp->p1);
79894 sqlite3VdbeMemSetInt64(pMem+1, pOp->p2);
79895 sqlite3VdbeMemSetInt64(pMem+2, pOp->p3);
79897 p->nResColumn = 4;
79898 }else{
79899 sqlite3VdbeMemSetInt64(pMem+0, i);
79900 sqlite3VdbeMemSetStr(pMem+1, (char*)sqlite3OpcodeName(pOp->opcode),
79902 sqlite3VdbeMemSetInt64(pMem+2, pOp->p1);
79903 sqlite3VdbeMemSetInt64(pMem+3, pOp->p2);
79904 sqlite3VdbeMemSetInt64(pMem+4, pOp->p3);
79905 /* pMem+5 for p4 is done last */
79906 sqlite3VdbeMemSetInt64(pMem+6, pOp->p5);
79907#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
79908 {
79909 char *zCom = sqlite3VdbeDisplayComment(db, pOp, zP4);
79910 sqlite3VdbeMemSetStr(pMem+7, zCom, -1, SQLITE_UTF8, sqlite3_free);
79911 }
79912#else
79913 sqlite3VdbeMemSetNull(pMem+7);
79914#endif
79916 p->nResColumn = 8;
79917 }
79918 p->pResultSet = pMem;
79919 if( db->mallocFailed ){
79920 p->rc = SQLITE_NOMEM;
79921 rc = SQLITE_ERROR;
79922 }else{
79923 p->rc = SQLITE_OK;
SQLITE_PRIVATE const char * sqlite3OpcodeName(int)
Definition sqlite3.c:33160
SQLITE_PRIVATE char * sqlite3VdbeDisplayP4(sqlite3 *, Op *)
Definition sqlite3.c:79365
SQLITE_PRIVATE int sqlite3VdbeNextOpcode(Vdbe *, Mem *, int, int *, int *, Op **)
Definition sqlite3.c:79690

References Vdbe::aMem, AtomicLoad, Vdbe::db, Vdbe::explain, sqlite3::flags, sqlite3::isInterrupted, Vdbe::magic, sqlite3::mallocFailed, Vdbe::nMem, Vdbe::nResColumn, VdbeOp::opcode, VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, VdbeOp::p5, Vdbe::pc, Vdbe::pResultSet, Vdbe::rc, releaseMemArray(), sqlite3_free(), sqlite3ErrStr(), sqlite3OomFault(), sqlite3OpcodeName(), sqlite3VdbeDisplayP4(), sqlite3VdbeError(), sqlite3VdbeMemSetInt64(), sqlite3VdbeMemSetNull(), sqlite3VdbeMemSetStr(), sqlite3VdbeNextOpcode(), SQLITE_BUSY, SQLITE_ERROR, SQLITE_INTERRUPT, SQLITE_NOMEM, SQLITE_OK, SQLITE_ROW, SQLITE_STATIC, SQLITE_TriggerEQP, SQLITE_UTF8, sqlite3::u1, and VDBE_MAGIC_RUN.

Referenced by sqlite3Step().

◆ sqlite3VdbeLoadString()

SQLITE_PRIVATE int sqlite3VdbeLoadString ( Vdbe * p,
int iDest,
const char * zStr )

Definition at line 78022 of file sqlite3.c.

Referenced by analyzeOneTable(), sqlite3ExprCodeTarget(), and sqlite3Pragma().

◆ sqlite3VdbeMakeLabel()

◆ sqlite3VdbeMakeReady()

SQLITE_PRIVATE void sqlite3VdbeMakeReady ( Vdbe * p,
Parse * pParse )

Definition at line 80075 of file sqlite3.c.

80084 {
80085 sqlite3 *db; /* The database connection */
80086 int nVar; /* Number of parameters */
80087 int nMem; /* Number of VM memory registers */
80088 int nCursor; /* Number of cursors required */
80089 int nArg; /* Number of arguments in subprograms */
80090 int n; /* Loop counter */
80091 struct ReusableSpace x; /* Reusable bulk memory */
80092
80093 assert( p!=0 );
80094 assert( p->nOp>0 );
80095 assert( pParse!=0 );
80096 assert( p->magic==VDBE_MAGIC_INIT );
80097 assert( pParse==p->pParse );
80098 db = p->db;
80099 assert( db->mallocFailed==0 );
80100 nVar = pParse->nVar;
80101 nMem = pParse->nMem;
80102 nCursor = pParse->nTab;
80103 nArg = pParse->nMaxArg;
80104
80105 /* Each cursor uses a memory cell. The first cursor (cursor 0) can
80106 ** use aMem[0] which is not otherwise used by the VDBE program. Allocate
80107 ** space at the end of aMem[] for cursors 1 and greater.
80108 ** See also: allocateCursor().
80109 */
80110 nMem += nCursor;
80111 if( nCursor==0 && nMem>0 ) nMem++; /* Space for aMem[0] even if not used */
80112
80113 /* Figure out how much reusable memory is available at the end of the
80114 ** opcode array. This extra memory will be reallocated for other elements
80115 ** of the prepared statement.
80116 */
80117 n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
80118 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
80119 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
80120 x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */
80121 assert( x.nFree>=0 );
80122 assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
80123
80124 resolveP2Values(p, &nArg);
80125 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
80126 if( pParse->explain ){
80127 static const char * const azColName[] = {
80128 "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment",
80129 "id", "parent", "notused", "detail"
80130 };
80131 int iFirst, mx, i;
80132 if( nMem<10 ) nMem = 10;
80133 p->explain = pParse->explain;
80134 if( pParse->explain==2 ){
80136 iFirst = 8;
80137 mx = 12;
80138 }else{
80140 iFirst = 0;
80141 mx = 8;
80142 }
80143 for(i=iFirst; i<mx; i++){
80145 azColName[i], SQLITE_STATIC);
80146 }
80147 }
80148 p->expired = 0;
80149
80150 /* Memory for registers, parameters, cursor, etc, is allocated in one or two
80151 ** passes. On the first pass, we try to reuse unused memory at the
80152 ** end of the opcode array. If we are unable to satisfy all memory
80153 ** requirements by reusing the opcode array tail, then the second
80154 ** pass will fill in the remainder using a fresh memory allocation.
80155 **
80156 ** This two-pass approach that reuses as much memory as possible from
80157 ** the leftover memory at the end of the opcode array. This can significantly
80158 ** reduce the amount of memory held by a prepared statement.
80159 */
80160 x.nNeeded = 0;
80161 p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
80162 p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
80163 p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
80164 p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
80165#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
80166 p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
80167#endif
80168 if( x.nNeeded ){
80169 x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
80170 x.nFree = x.nNeeded;
80171 if( !db->mallocFailed ){
80172 p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
80173 p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
80174 p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
80175 p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
80176#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
80177 p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
80178#endif
80179 }
80180 }
80181
80182 p->pVList = pParse->pVList;
80183 pParse->pVList = 0;
80184 if( db->mallocFailed ){
80185 p->nVar = 0;
80186 p->nCursor = 0;
80187 p->nMem = 0;
80188 }else{
80189 p->nCursor = nCursor;
80190 p->nVar = (ynVar)nVar;
80191 initMemArray(p->aVar, nVar, db, MEM_Null);
80192 p->nMem = nMem;
80193 initMemArray(p->aMem, nMem, db, MEM_Undefined);
80194 memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags)
Definition sqlite3.c:79598
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs)
Definition sqlite3.c:78521
static void * allocSpace(struct ReusableSpace *p, void *pBuf, sqlite3_int64 nByte)
Definition sqlite3.c:79999
int szOpAlloc
Definition sqlite3.c:18699

References allocSpace(), Vdbe::aMem, Vdbe::aOp, Vdbe::apArg, Vdbe::apCsr, Vdbe::aVar, COLNAME_NAME, Vdbe::db, EIGHT_BYTE_ALIGNMENT, Vdbe::expired, Parse::explain, Vdbe::explain, initMemArray(), Parse::isMultiWrite, Vdbe::magic, sqlite3::mallocFailed, Parse::mayAbort, MEM_Null, MEM_Undefined, Vdbe::nCursor, ReusableSpace::nFree, Parse::nMaxArg, Parse::nMem, Vdbe::nMem, ReusableSpace::nNeeded, Vdbe::nOp, Parse::nTab, Parse::nVar, Vdbe::nVar, Vdbe::pFree, Vdbe::pParse, ReusableSpace::pSpace, Parse::pVList, Vdbe::pVList, resolveP2Values(), ROUND8, ROUNDDOWN8, sqlite3DbMallocRawNN(), sqlite3VdbeRewind(), sqlite3VdbeSetColName(), sqlite3VdbeSetNumCols(), SQLITE_STATIC, Parse::szOpAlloc, Vdbe::usesStmtJournal, and VDBE_MAGIC_INIT.

Referenced by sqlite3FinishCoding().

◆ sqlite3VdbeMemAggValue()

SQLITE_PRIVATE int sqlite3VdbeMemAggValue ( Mem * pAccum,
Mem * pOut,
FuncDef * pFunc )

Definition at line 76294 of file sqlite3.c.

76300 {
76301 sqlite3_context ctx;
76302 assert( pFunc!=0 );
76303 assert( pFunc->xValue!=0 );
76304 assert( (pAccum->flags & MEM_Null)!=0 || pFunc==pAccum->u.pDef );
76305 assert( pAccum->db==0 || sqlite3_mutex_held(pAccum->db->mutex) );
76306 memset(&ctx, 0, sizeof(ctx));

References sqlite3_value::db, sqlite3_value::flags, sqlite3_context::isError, MEM_Null, sqlite3::mutex, sqlite3_value::MemValue::pDef, sqlite3_context::pFunc, sqlite3_context::pMem, sqlite3_context::pOut, sqlite3_mutex_held(), sqlite3VdbeMemSetNull(), sqlite3_value::u, and FuncDef::xValue.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeMemCast()

SQLITE_PRIVATE int sqlite3VdbeMemCast ( Mem * pMem,
u8 aff,
u8 encoding )

Definition at line 76583 of file sqlite3.c.

76589 {
76590 if( pMem->flags & MEM_Null ) return SQLITE_OK;
76591 switch( aff ){
76592 case SQLITE_AFF_BLOB: { /* Really a cast to BLOB */
76593 if( (pMem->flags & MEM_Blob)==0 ){
76595 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
76596 if( pMem->flags & MEM_Str ) MemSetTypeFlag(pMem, MEM_Blob);
76597 }else{
76598 pMem->flags &= ~(MEM_TypeMask&~MEM_Blob);
76599 }
76600 break;
76601 }
76602 case SQLITE_AFF_NUMERIC: {
76604 break;
76605 }
76606 case SQLITE_AFF_INTEGER: {
76608 break;
76609 }
76610 case SQLITE_AFF_REAL: {
76612 break;
76613 }
76614 default: {
76615 assert( aff==SQLITE_AFF_TEXT );
76616 assert( MEM_Str==(MEM_Blob>>3) );
76617 pMem->flags |= (pMem->flags&MEM_Blob)>>3;
76619 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *)
Definition sqlite3.c:76551

References sqlite3_value::db, sqlite3_value::flags, sqlite3::mallocFailed, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, MEM_TypeMask, MEM_Zero, MemSetTypeFlag, sqlite3ValueApplyAffinity(), sqlite3VdbeChangeEncoding(), sqlite3VdbeMemIntegerify(), sqlite3VdbeMemNumerify(), sqlite3VdbeMemRealify(), SQLITE_AFF_BLOB, SQLITE_AFF_INTEGER, SQLITE_AFF_NUMERIC, SQLITE_AFF_REAL, SQLITE_AFF_TEXT, and SQLITE_OK.

Referenced by sqlite3VdbeExec(), and valueFromExpr().

◆ sqlite3VdbeMemClearAndResize()

SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize ( Mem * pMem,
int n )

Definition at line 76116 of file sqlite3.c.

76122 {
76123 assert( CORRUPT_DB || szNew>0 );
76124 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
76125 if( pMem->szMalloc<szNew ){
76126 return sqlite3VdbeMemGrow(pMem, szNew, 0);

References CORRUPT_DB, sqlite3_value::flags, MEM_Dyn, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, sqlite3VdbeMemGrow(), SQLITE_OK, sqlite3_value::szMalloc, sqlite3_value::z, and sqlite3_value::zMalloc.

Referenced by allocateCursor(), sqlite3VdbeExec(), sqlite3VdbeMemFromBtree(), sqlite3VdbeMemSetStr(), and sqlite3VdbeMemStringify().

◆ sqlite3VdbeMemCopy()

SQLITE_PRIVATE int sqlite3VdbeMemCopy ( Mem * pTo,
const Mem * pFrom )

Definition at line 76843 of file sqlite3.c.

76849 {
76850 int rc = SQLITE_OK;
76851
76852 assert( !sqlite3VdbeMemIsRowSet(pFrom) );
76854 memcpy(pTo, pFrom, MEMCELLSIZE);
76855 pTo->flags &= ~MEM_Dyn;
76856 if( pTo->flags&(MEM_Str|MEM_Blob) ){
76857 if( 0==(pFrom->flags&MEM_Static) ){
76858 pTo->flags |= MEM_Ephem;

Referenced by minmaxStep(), sqlite3VdbeExec(), and sqlite3VdbeGetBoundValue().

◆ sqlite3VdbeMemExpandBlob()

SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob ( Mem * pMem)

Definition at line 76177 of file sqlite3.c.

76183 {
76184 int nByte;
76185 assert( pMem->flags & MEM_Zero );
76186 assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
76188 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76189 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76190
76191 /* Set nByte to the number of bytes required to store the expanded blob. */
76192 nByte = pMem->n + pMem->u.nZero;
76193 if( nByte<=0 ){
76194 if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
76195 nByte = 1;
76196 }
76197 if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
76198 return SQLITE_NOMEM_BKPT;
76199 }
#define MemNullNochng(X)
Definition sqlite3.c:20993
SQLITE_API int sqlite3_value_nochange(sqlite3_value *)
Definition sqlite3.c:83302

References sqlite3_value::db, sqlite3_value::flags, MEM_Blob, MEM_Term, MEM_Zero, MemNullNochng, sqlite3::mutex, sqlite3_value::n, sqlite3_value::MemValue::nZero, sqlite3_mutex_held(), sqlite3_value_nochange(), sqlite3VdbeMemGrow(), SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, sqlite3_value::u, and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeMemFinalize()

SQLITE_PRIVATE int sqlite3VdbeMemFinalize ( Mem * pMem,
FuncDef * pFunc )

Definition at line 76264 of file sqlite3.c.

76270 {
76271 sqlite3_context ctx;
76272 Mem t;
76273 assert( pFunc!=0 );
76274 assert( pFunc->xFinalize!=0 );
76275 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
76276 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76277 memset(&ctx, 0, sizeof(ctx));
76278 memset(&t, 0, sizeof(t));
76279 t.flags = MEM_Null;
76280 t.db = pMem->db;
76281 ctx.pOut = &t;
76282 ctx.pMem = pMem;
76283 ctx.pFunc = pFunc;

References sqlite3_value::db, sqlite3_value::flags, sqlite3_context::isError, MEM_Dyn, MEM_Null, sqlite3::mutex, sqlite3_value::MemValue::pDef, sqlite3_context::pFunc, sqlite3_context::pMem, sqlite3_context::pOut, sqlite3_mutex_held(), sqlite3DbFreeNN(), sqlite3_value::szMalloc, sqlite3_value::u, FuncDef::xFinalize, and sqlite3_value::zMalloc.

Referenced by sqlite3VdbeExec(), and vdbeMemClearExternAndSetNull().

◆ sqlite3VdbeMemFromBtree()

SQLITE_PRIVATE int sqlite3VdbeMemFromBtree ( BtCursor * pCur,
u32 offset,
u32 amt,
Mem * pMem )

Definition at line 77000 of file sqlite3.c.

77011 {
77012 int rc;
77013 pMem->flags = MEM_Null;
77014 if( sqlite3BtreeMaxRecordSize(pCur)<offset+amt ){
77015 return SQLITE_CORRUPT_BKPT;
77016 }
77017 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+1)) ){
77018 rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
77019 if( rc==SQLITE_OK ){
77020 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
77021 pMem->flags = MEM_Blob;
77022 pMem->n = (int)amt;
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *)
Definition sqlite3.c:69116

References sqlite3_value::flags, MEM_Blob, MEM_Null, sqlite3_value::n, sqlite3BtreeMaxRecordSize(), sqlite3BtreePayload(), sqlite3VdbeMemClearAndResize(), SQLITE_CORRUPT_BKPT, SQLITE_OK, and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeMemFromBtreeZeroOffset()

SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset ( BtCursor * pCur,
u32 amt,
Mem * pMem )

Definition at line 77023 of file sqlite3.c.

77023 {
77025 }
77026 }
77027 return rc;
77028}
77030 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
77031 u32 amt, /* Number of bytes to return. */
77032 Mem *pMem /* OUT: Return data in this Mem structure. */
77033){
77034 u32 available = 0; /* Number of bytes available on the local btree page */
77035 int rc = SQLITE_OK; /* Return code */
77036
77037 assert( sqlite3BtreeCursorIsValid(pCur) );
77038 assert( !VdbeMemDynamic(pMem) );
77039
77040 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
77041 ** that both the BtShared and database handle mutexes are held. */
77042 assert( !sqlite3VdbeMemIsRowSet(pMem) );
77043 pMem->z = (char *)sqlite3BtreePayloadFetch(pCur, &available);
77044 assert( pMem->z!=0 );
77045
77046 if( amt<=available ){
77047 pMem->flags = MEM_Blob|MEM_Ephem;
77048 pMem->n = (int)amt;

Referenced by sqlite3VdbeExec(), sqlite3VdbeIdxKeyCompare(), and sqlite3VdbeIdxRowid().

◆ sqlite3VdbeMemGrow()

SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow ( Mem * pMem,
int n,
int preserve )

Definition at line 76055 of file sqlite3.c.

76061 {
76062 assert( sqlite3VdbeCheckMemInvariants(pMem) );
76063 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76064 testcase( pMem->db==0 );
76065
76066 /* If the bPreserve flag is set to true, then the memory cell must already
76067 ** contain a valid string or blob value. */
76068 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
76069 testcase( bPreserve && pMem->z==0 );
76070
76071 assert( pMem->szMalloc==0
76072 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
76073 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
76074 if( pMem->db ){
76075 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
76076 }else{
76077 pMem->zMalloc = sqlite3Realloc(pMem->z, n);
76078 if( pMem->zMalloc==0 ) sqlite3_free(pMem->z);
76079 pMem->z = pMem->zMalloc;
76080 }
76081 bPreserve = 0;
76082 }else{
76083 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
76084 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
76085 }
76086 if( pMem->zMalloc==0 ){
76088 pMem->z = 0;
76089 pMem->szMalloc = 0;
76090 return SQLITE_NOMEM_BKPT;
76091 }else{
76092 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
76093 }
76094
76095 if( bPreserve && pMem->z ){
76096 assert( pMem->z!=pMem->zMalloc );
76097 memcpy(pMem->zMalloc, pMem->z, pMem->n);
76098 }
76099 if( (pMem->flags&MEM_Dyn)!=0 ){
76100 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
76101 pMem->xDel((void *)(pMem->z));

References sqlite3_value::db, sqlite3_value::flags, MEM_Blob, MEM_Dyn, MEM_Ephem, MEM_Static, MEM_Str, sqlite3_value::n, sqlite3_free(), sqlite3DbFreeNN(), sqlite3DbMallocRaw(), sqlite3DbMallocSize(), sqlite3DbReallocOrFree(), sqlite3Realloc(), sqlite3VdbeMemSetNull(), SQLITE_DYNAMIC, SQLITE_NOMEM_BKPT, SQLITE_OK, sqlite3_value::szMalloc, testcase, sqlite3_value::xDel, sqlite3_value::z, and sqlite3_value::zMalloc.

Referenced by sqlite3VdbeExec(), sqlite3VdbeMemClearAndResize(), sqlite3VdbeMemExpandBlob(), sqlite3VdbeNextOpcode(), and vdbeMemAddTerminator().

◆ sqlite3VdbeMemHandleBom()

SQLITE_PRIVATE int sqlite3VdbeMemHandleBom ( Mem * pMem)

Definition at line 31019 of file sqlite3.c.

31025 {
31026 int rc = SQLITE_OK;
31027 u8 bom = 0;
31028
31029 assert( pMem->n>=0 );
31030 if( pMem->n>1 ){
31031 u8 b1 = *(u8 *)pMem->z;
31032 u8 b2 = *(((u8 *)pMem->z) + 1);
31033 if( b1==0xFE && b2==0xFF ){
31034 bom = SQLITE_UTF16BE;
31035 }
31036 if( b1==0xFF && b2==0xFE ){
31037 bom = SQLITE_UTF16LE;
31038 }
31039 }
31040
31041 if( bom ){
31042 rc = sqlite3VdbeMemMakeWriteable(pMem);
31043 if( rc==SQLITE_OK ){
31044 pMem->n -= 2;
31045 memmove(pMem->z, &pMem->z[2], pMem->n);
31046 pMem->z[pMem->n] = '\0';
31047 pMem->z[pMem->n+1] = '\0';

References sqlite3_value::enc, sqlite3_value::flags, MEM_Term, sqlite3_value::n, sqlite3VdbeMemMakeWriteable(), SQLITE_OK, SQLITE_UTF16BE, SQLITE_UTF16LE, and sqlite3_value::z.

Referenced by sqlite3VdbeMemSetStr().

◆ sqlite3VdbeMemInit()

SQLITE_PRIVATE void sqlite3VdbeMemInit ( Mem * pMem,
sqlite3 * db,
u16 flags )

◆ sqlite3VdbeMemIntegerify()

SQLITE_PRIVATE int sqlite3VdbeMemIntegerify ( Mem * pMem)

Definition at line 76504 of file sqlite3.c.

76510 {
76511 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76512 assert( !sqlite3VdbeMemIsRowSet(pMem) );

Referenced by sqlite3VdbeExec(), and sqlite3VdbeMemCast().

◆ sqlite3VdbeMemMakeWriteable()

SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable ( Mem * pMem)

Definition at line 76154 of file sqlite3.c.

76160 {
76161 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76162 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76163 if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
76164 if( ExpandBlob(pMem) ) return SQLITE_NOMEM;
76165 if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
76166 int rc = vdbeMemAddTerminator(pMem);
76167 if( rc ) return rc;
76168 }
76169 }
76170 pMem->flags &= ~MEM_Ephem;
static SQLITE_NOINLINE int vdbeMemAddTerminator(Mem *pMem)
Definition sqlite3.c:76137

References sqlite3_value::db, ExpandBlob, sqlite3_value::flags, MEM_Blob, MEM_Str, sqlite3::mutex, sqlite3_mutex_held(), SQLITE_NOMEM, SQLITE_OK, sqlite3_value::szMalloc, vdbeMemAddTerminator(), sqlite3_value::z, and sqlite3_value::zMalloc.

Referenced by sqlite3VdbeMemHandleBom(), sqlite3VdbeMemTranslate(), and valueToText().

◆ sqlite3VdbeMemMove()

SQLITE_PRIVATE void sqlite3VdbeMemMove ( Mem * pTo,
Mem * pFrom )

Definition at line 76866 of file sqlite3.c.

76872 {
76873 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
76874 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
76875 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );

References sqlite3_value::db, sqlite3_value::flags, MEM_Null, sqlite3::mutex, sqlite3_mutex_held(), sqlite3VdbeMemRelease(), and sqlite3_value::szMalloc.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeMemNulTerminate()

SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate ( Mem * pMem)

Definition at line 76205 of file sqlite3.c.

76211 {
76212 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76213 testcase( (pMem->flags & (MEM_Term|MEM_Str))==(MEM_Term|MEM_Str) );
76214 testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 );

Referenced by sqlite3VdbeExec(), and valueToText().

◆ sqlite3VdbeMemNumerify()

SQLITE_PRIVATE int sqlite3VdbeMemNumerify ( Mem * pMem)

Definition at line 76551 of file sqlite3.c.

76557 {
76558 testcase( pMem->flags & MEM_Int );
76559 testcase( pMem->flags & MEM_Real );
76560 testcase( pMem->flags & MEM_IntReal );
76561 testcase( pMem->flags & MEM_Null );
76562 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
76563 int rc;
76564 sqlite3_int64 ix;
76565 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
76566 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76567 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
76568 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
76569 || sqlite3RealSameAsInt(pMem->u.r, (ix = (i64)pMem->u.r))
76570 ){
76571 pMem->u.i = ix;
76572 MemSetTypeFlag(pMem, MEM_Int);
76573 }else{
76574 MemSetTypeFlag(pMem, MEM_Real);
SQLITE_PRIVATE int sqlite3RealSameAsInt(double, sqlite3_int64)
Definition sqlite3.c:76536

References sqlite3_value::db, sqlite3_value::enc, sqlite3_value::flags, sqlite3_value::MemValue::i, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, MEM_Zero, MemSetTypeFlag, sqlite3::mutex, sqlite3_value::n, sqlite3_value::MemValue::r, sqlite3_mutex_held(), sqlite3AtoF(), sqlite3Atoi64(), sqlite3RealSameAsInt(), SQLITE_OK, testcase, sqlite3_value::u, and sqlite3_value::z.

Referenced by sqlite3VdbeMemCast(), and valueFromExpr().

◆ sqlite3VdbeMemRealify()

SQLITE_PRIVATE int sqlite3VdbeMemRealify ( Mem * pMem)

Definition at line 76518 of file sqlite3.c.

76524 {
76525 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );

Referenced by sqlite3VdbeExec(), and sqlite3VdbeMemCast().

◆ sqlite3VdbeMemRelease()

◆ sqlite3VdbeMemSetDouble()

SQLITE_PRIVATE void sqlite3VdbeMemSetDouble ( Mem * pMem,
double val )

◆ sqlite3VdbeMemSetInt64()

SQLITE_PRIVATE void sqlite3VdbeMemSetInt64 ( Mem * pMem,
i64 val )

Definition at line 76686 of file sqlite3.c.

76692 {
76693 if( VdbeMemDynamic(pMem) ){

Referenced by sqlite3_bind_null(), sqlite3VdbeExec(), sqlite3VdbeList(), and valueFromExpr().

◆ sqlite3VdbeMemSetNull()

◆ sqlite3VdbeMemSetPointer()

SQLITE_PRIVATE void sqlite3VdbeMemSetPointer ( Mem * pMem,
void * pPtr,
const char * zPType,
void(*)(void *) xDestructor )

Definition at line 76702 of file sqlite3.c.

76702 { UNUSED_PARAMETER(p); }
76703
76704/*
76705** Set the value stored in *pMem should already be a NULL.
76706** Also store a pointer to go with it.
76707*/
76709 Mem *pMem,
76710 void *pPtr,
76711 const char *zPType,
76712 void (*xDestructor)(void*)
76713){
76714 assert( pMem->flags==MEM_Null );

References UNUSED_PARAMETER.

◆ sqlite3VdbeMemSetRowSet()

SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet ( Mem * pMem)

Definition at line 76748 of file sqlite3.c.

76754 {
76755 sqlite3 *db = pMem->db;
76756 RowSet *p;
76757 assert( db!=0 );
76758 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76760 p = sqlite3RowSetInit(db);
SQLITE_PRIVATE RowSet * sqlite3RowSetInit(sqlite3 *)
Definition sqlite3.c:51168

References sqlite3_value::db, sqlite3_value::flags, MEM_Blob, MEM_Dyn, sqlite3RowSetDelete(), sqlite3RowSetInit(), sqlite3VdbeMemRelease(), SQLITE_NOMEM, SQLITE_OK, sqlite3_value::xDel, and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeMemSetStr()

SQLITE_PRIVATE int sqlite3VdbeMemSetStr ( Mem * pMem,
const char * z,
int n,
u8 enc,
void(*)(void *) xDel )

Definition at line 76892 of file sqlite3.c.

76904 {
76905 int nByte = n; /* New value for pMem->n */
76906 int iLimit; /* Maximum allowed string or blob size */
76907 u16 flags = 0; /* New value for pMem->flags */
76908
76909 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76910 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76911
76912 /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
76913 if( !z ){
76915 return SQLITE_OK;
76916 }
76917
76918 if( pMem->db ){
76919 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
76920 }else{
76921 iLimit = SQLITE_MAX_LENGTH;
76922 }
76923 flags = (enc==0?MEM_Blob:MEM_Str);
76924 if( nByte<0 ){
76925 assert( enc!=0 );
76926 if( enc==SQLITE_UTF8 ){
76927 nByte = 0x7fffffff & (int)strlen(z);
76928 }else{
76929 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
76930 }
76931 flags |= MEM_Term;
76932 }
76933
76934 /* The following block sets the new values of Mem.z and Mem.xDel. It
76935 ** also sets a flag in local variable "flags" to indicate the memory
76936 ** management (one of MEM_Dyn or MEM_Static).
76937 */
76938 if( xDel==SQLITE_TRANSIENT ){
76939 u32 nAlloc = nByte;
76940 if( flags&MEM_Term ){
76941 nAlloc += (enc==SQLITE_UTF8?1:2);
76942 }
76943 if( nByte>iLimit ){
76944 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
76945 }
76946 testcase( nAlloc==0 );
76947 testcase( nAlloc==31 );
76948 testcase( nAlloc==32 );
76949 if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
76950 return SQLITE_NOMEM_BKPT;
76951 }
76952 memcpy(pMem->z, z, nAlloc);
76953 }else{
76955 pMem->z = (char *)z;
76956 if( xDel==SQLITE_DYNAMIC ){
76957 pMem->zMalloc = pMem->z;
76958 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
76959 }else{
76960 pMem->xDel = xDel;
76961 flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
76962 }
76963 }
76964
76965 pMem->n = nByte;
76966 pMem->flags = flags;
76967 if( enc ){
76968 pMem->enc = enc;
76969#ifdef SQLITE_ENABLE_SESSION
76970 }else if( pMem->db==0 ){
76971 pMem->enc = SQLITE_UTF8;
76972#endif
76973 }else{
76974 assert( pMem->db!=0 );
76975 pMem->enc = ENC(pMem->db);
76976 }
76977
76978#ifndef SQLITE_OMIT_UTF16
76979 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
76980 return SQLITE_NOMEM_BKPT;
76981 }
76982#endif
76983
SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3 *, int)
Definition sqlite3.c:31386
SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem)
Definition sqlite3.c:31019

References sqlite3::aLimit, sqlite3_value::db, ENC, sqlite3_value::enc, sqlite3_value::flags, MAX, MEM_Blob, MEM_Dyn, MEM_Static, MEM_Str, MEM_Term, sqlite3::mutex, sqlite3_value::n, sqlite3_mutex_held(), sqlite3DbMallocSize(), sqlite3ErrorToParser(), sqlite3VdbeMemClearAndResize(), sqlite3VdbeMemHandleBom(), sqlite3VdbeMemRelease(), sqlite3VdbeMemSetNull(), SQLITE_DYNAMIC, SQLITE_LIMIT_LENGTH, SQLITE_MAX_LENGTH, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_STATIC, SQLITE_TOOBIG, SQLITE_TRANSIENT, SQLITE_UTF8, sqlite3_value::szMalloc, testcase, sqlite3_value::xDel, sqlite3_value::z, and sqlite3_value::zMalloc.

Referenced by invokeValueDestructor(), sqlite3_result_error16(), sqlite3_result_int(), sqlite3Utf16to8(), sqlite3VdbeExec(), sqlite3VdbeExpandSql(), sqlite3VdbeList(), sqlite3VdbeSetColName(), and valueFromExpr().

◆ sqlite3VdbeMemSetZeroBlob()

SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob ( Mem * pMem,
int n )

Definition at line 76661 of file sqlite3.c.

76667 {
76669 pMem->flags = MEM_Blob|MEM_Zero;

Referenced by sqlite3_bind_zeroblob64().

◆ sqlite3VdbeMemShallowCopy()

SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy ( Mem * pTo,
const Mem * pFrom,
int srcType )

Definition at line 76827 of file sqlite3.c.

76828 {
76830 assert( !VdbeMemDynamic(pTo) );
76831 sqlite3VdbeMemShallowCopy(pTo, pFrom, eType);
76832}
76833SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
76834 assert( !sqlite3VdbeMemIsRowSet(pFrom) );
76835 assert( pTo->db==pFrom->db );
76836 if( VdbeMemDynamic(pTo) ){ vdbeClrCopy(pTo,pFrom,srcType); return; }
76837 memcpy(pTo, pFrom, MEMCELLSIZE);
static SQLITE_NOINLINE void vdbeClrCopy(Mem *pTo, const Mem *pFrom, int eType)
Definition sqlite3.c:76822

References eType, sqlite3VdbeMemShallowCopy(), vdbeMemClearExternAndSetNull(), and VdbeMemDynamic.

Referenced by sqlite3VdbeExec(), sqlite3VdbeMemShallowCopy(), and vdbeCompareMemString().

◆ sqlite3VdbeMemStringify()

SQLITE_PRIVATE int sqlite3VdbeMemStringify ( Mem * pMem,
u8 enc,
u8 bForce )

Definition at line 76230 of file sqlite3.c.

76236 {
76237 const int nByte = 32;
76238
76239 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76240 assert( !(pMem->flags&MEM_Zero) );
76241 assert( !(pMem->flags&(MEM_Str|MEM_Blob)) );
76242 assert( pMem->flags&(MEM_Int|MEM_Real|MEM_IntReal) );
76243 assert( !sqlite3VdbeMemIsRowSet(pMem) );
76244 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
76245
76246
76247 if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){
76248 pMem->enc = 0;
76249 return SQLITE_NOMEM_BKPT;
76250 }
76251
76252 vdbeMemRenderNum(nByte, pMem->z, pMem);
76253 assert( pMem->z!=0 );
76254 pMem->n = sqlite3Strlen30NN(pMem->z);
static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p)
Definition sqlite3.c:75928

References sqlite3_value::db, EIGHT_BYTE_ALIGNMENT, sqlite3_value::enc, sqlite3_value::flags, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Real, MEM_Str, MEM_Term, MEM_Zero, sqlite3::mutex, sqlite3_value::n, sqlite3_mutex_held(), sqlite3Strlen30NN, sqlite3VdbeChangeEncoding(), sqlite3VdbeMemClearAndResize(), SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_UTF8, vdbeMemRenderNum(), and sqlite3_value::z.

Referenced by applyAffinity(), sqlite3VdbeExec(), and valueToText().

◆ sqlite3VdbeMemTooBig()

SQLITE_PRIVATE int sqlite3VdbeMemTooBig ( Mem * p)

Definition at line 76766 of file sqlite3.c.

76772 {
76773 assert( p->db!=0 );
76774 if( p->flags & (MEM_Str|MEM_Blob) ){
76775 int n = p->n;
76776 if( p->flags & MEM_Zero ){

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeMemTranslate()

SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate ( Mem * pMem,
u8 desiredEnc )

Definition at line 30824 of file sqlite3.c.

30830 {
30831 sqlite3_int64 len; /* Maximum length of output string in bytes */
30832 unsigned char *zOut; /* Output buffer */
30833 unsigned char *zIn; /* Input iterator */
30834 unsigned char *zTerm; /* End of input */
30835 unsigned char *z; /* Output iterator */
30836 unsigned int c;
30837
30838 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
30839 assert( pMem->flags&MEM_Str );
30840 assert( pMem->enc!=desiredEnc );
30841 assert( pMem->enc!=0 );
30842 assert( pMem->n>=0 );
30843
30844#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
30845 {
30846 StrAccum acc;
30847 char zBuf[1000];
30848 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30849 sqlite3VdbeMemPrettyPrint(pMem, &acc);
30850 fprintf(stderr, "INPUT: %s\n", sqlite3StrAccumFinish(&acc));
30851 }
30852#endif
30853
30854 /* If the translation is between UTF-16 little and big endian, then
30855 ** all that is required is to swap the byte order. This case is handled
30856 ** differently from the others.
30857 */
30858 if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
30859 u8 temp;
30860 int rc;
30861 rc = sqlite3VdbeMemMakeWriteable(pMem);
30862 if( rc!=SQLITE_OK ){
30863 assert( rc==SQLITE_NOMEM );
30864 return SQLITE_NOMEM_BKPT;
30865 }
30866 zIn = (u8*)pMem->z;
30867 zTerm = &zIn[pMem->n&~1];
30868 while( zIn<zTerm ){
30869 temp = *zIn;
30870 *zIn = *(zIn+1);
30871 zIn++;
30872 *zIn++ = temp;
30873 }
30874 pMem->enc = desiredEnc;
30875 goto translate_out;
30876 }
30877
30878 /* Set len to the maximum number of bytes required in the output buffer. */
30879 if( desiredEnc==SQLITE_UTF8 ){
30880 /* When converting from UTF-16, the maximum growth results from
30881 ** translating a 2-byte character to a 4-byte UTF-8 character.
30882 ** A single byte is required for the output string
30883 ** nul-terminator.
30884 */
30885 pMem->n &= ~1;
30886 len = 2 * (sqlite3_int64)pMem->n + 1;
30887 }else{
30888 /* When converting from UTF-8 to UTF-16 the maximum growth is caused
30889 ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
30890 ** character. Two bytes are required in the output buffer for the
30891 ** nul-terminator.
30892 */
30893 len = 2 * (sqlite3_int64)pMem->n + 2;
30894 }
30895
30896 /* Set zIn to point at the start of the input buffer and zTerm to point 1
30897 ** byte past the end.
30898 **
30899 ** Variable zOut is set to point at the output buffer, space obtained
30900 ** from sqlite3_malloc().
30901 */
30902 zIn = (u8*)pMem->z;
30903 zTerm = &zIn[pMem->n];
30904 zOut = sqlite3DbMallocRaw(pMem->db, len);
30905 if( !zOut ){
30906 return SQLITE_NOMEM_BKPT;
30907 }
30908 z = zOut;
30909
30910 if( pMem->enc==SQLITE_UTF8 ){
30911 if( desiredEnc==SQLITE_UTF16LE ){
30912 /* UTF-8 -> UTF-16 Little-endian */
30913 while( zIn<zTerm ){
30914 READ_UTF8(zIn, zTerm, c);
30915 WRITE_UTF16LE(z, c);
30916 }
30917 }else{
30918 assert( desiredEnc==SQLITE_UTF16BE );
30919 /* UTF-8 -> UTF-16 Big-endian */
30920 while( zIn<zTerm ){
30921 READ_UTF8(zIn, zTerm, c);
30922 WRITE_UTF16BE(z, c);
30923 }
30924 }
30925 pMem->n = (int)(z - zOut);
30926 *z++ = 0;
30927 }else{
30928 assert( desiredEnc==SQLITE_UTF8 );
30929 if( pMem->enc==SQLITE_UTF16LE ){
30930 /* UTF-16 Little-endian -> UTF-8 */
30931 while( zIn<zTerm ){
30932 c = *(zIn++);
30933 c += (*(zIn++))<<8;
30934 if( c>=0xd800 && c<0xe000 ){
30935#ifdef SQLITE_REPLACE_INVALID_UTF
30936 if( c>=0xdc00 || zIn>=zTerm ){
30937 c = 0xfffd;
30938 }else{
30939 int c2 = *(zIn++);
30940 c2 += (*(zIn++))<<8;
30941 if( c2<0xdc00 || c2>=0xe000 ){
30942 zIn -= 2;
30943 c = 0xfffd;
30944 }else{
30945 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000;
30946 }
30947 }
30948#else
30949 if( zIn<zTerm ){
30950 int c2 = (*zIn++);
30951 c2 += ((*zIn++)<<8);
30952 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10);
30953 }
30954#endif
30955 }
30956 WRITE_UTF8(z, c);
30957 }
30958 }else{
30959 /* UTF-16 Big-endian -> UTF-8 */
30960 while( zIn<zTerm ){
30961 c = (*(zIn++))<<8;
30962 c += *(zIn++);
30963 if( c>=0xd800 && c<0xe000 ){
30964#ifdef SQLITE_REPLACE_INVALID_UTF
30965 if( c>=0xdc00 || zIn>=zTerm ){
30966 c = 0xfffd;
30967 }else{
30968 int c2 = (*(zIn++))<<8;
30969 c2 += *(zIn++);
30970 if( c2<0xdc00 || c2>=0xe000 ){
30971 zIn -= 2;
30972 c = 0xfffd;
30973 }else{
30974 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000;
30975 }
30976 }
30977#else
30978 if( zIn<zTerm ){
30979 int c2 = ((*zIn++)<<8);
30980 c2 += (*zIn++);
30981 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10);
30982 }
30983#endif
30984 }
30985 WRITE_UTF8(z, c);
30986 }
30987 }
30988 pMem->n = (int)(z - zOut);
30989 }
30990 *z = 0;
30991 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
30992
30995 pMem->flags = c;
30996 pMem->enc = desiredEnc;
30997 pMem->z = (char*)zOut;
30998 pMem->zMalloc = pMem->z;
30999 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
31000
31001translate_out:
31002#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
31003 {
31004 StrAccum acc;
31005 char zBuf[1000];
31006 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
#define READ_UTF8(zIn, zTerm, c)
Definition sqlite3.c:30777
#define WRITE_UTF16LE(zOut, c)
Definition sqlite3.c:30726
#define WRITE_UTF16BE(zOut, c)
Definition sqlite3.c:30738
#define WRITE_UTF8(zOut, c)
Definition sqlite3.c:30706

References sqlite3_value::db, sqlite3_value::enc, sqlite3_value::flags, MEM_AffMask, MEM_Str, MEM_Subtype, MEM_Term, sqlite3::mutex, sqlite3_value::n, READ_UTF8, sqlite3_mutex_held(), sqlite3DbMallocRaw(), sqlite3DbMallocSize(), sqlite3StrAccumFinish(), sqlite3StrAccumInit(), sqlite3VdbeMemMakeWriteable(), sqlite3VdbeMemRelease(), SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, sqlite3_value::szMalloc, WRITE_UTF16BE, WRITE_UTF16LE, WRITE_UTF8, sqlite3_value::z, and sqlite3_value::zMalloc.

Referenced by sqlite3VdbeChangeEncoding().

◆ sqlite3VdbeMultiLoad()

SQLITE_PRIVATE void sqlite3VdbeMultiLoad ( Vdbe * p,
int iDest,
const char * zTypes,
... )

Definition at line 78037 of file sqlite3.c.

78043 {
78044 va_list ap;
78045 int i;
78046 char c;
78047 va_start(ap, zTypes);
78048 for(i=0; (c = zTypes[i])!=0; i++){
78049 if( c=='s' ){
78050 const char *z = va_arg(ap, const char*);
78051 sqlite3VdbeAddOp4(p, z==0 ? OP_Null : OP_String8, 0, iDest+i, 0, z, 0);
78052 }else if( c=='i' ){
78053 sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest+i);
78054 }else{
78055 goto skip_op_resultrow;

References OP_Integer, OP_Null, OP_ResultRow, OP_String8, sqlite3VdbeAddOp2(), and sqlite3VdbeAddOp4().

Referenced by sqlite3Pragma().

◆ sqlite3VdbeNextOpcode()

SQLITE_PRIVATE int sqlite3VdbeNextOpcode ( Vdbe * p,
Mem * pSub,
int eMode,
int * piPc,
int * piAddr,
Op ** paOp )

Definition at line 79690 of file sqlite3.c.

79703 {
79704 int nRow; /* Stop when row count reaches this */
79705 int nSub = 0; /* Number of sub-vdbes seen so far */
79706 SubProgram **apSub = 0; /* Array of sub-vdbes */
79707 int i; /* Next instruction address */
79708 int rc = SQLITE_OK; /* Result code */
79709 Op *aOp = 0; /* Opcode array */
79710 int iPc; /* Rowid. Copy of value in *piPc */
79711
79712 /* When the number of output rows reaches nRow, that means the
79713 ** listing has finished and sqlite3_step() should return SQLITE_DONE.
79714 ** nRow is the sum of the number of rows in the main program, plus
79715 ** the sum of the number of rows in all trigger subprograms encountered
79716 ** so far. The nRow value will increase as new trigger subprograms are
79717 ** encountered, but p->pc will eventually catch up to nRow.
79718 */
79719 nRow = p->nOp;
79720 if( pSub!=0 ){
79721 if( pSub->flags&MEM_Blob ){
79722 /* pSub is initiallly NULL. It is initialized to a BLOB by
79723 ** the P4_SUBPROGRAM processing logic below */
79724 nSub = pSub->n/sizeof(Vdbe*);
79725 apSub = (SubProgram **)pSub->z;
79726 }
79727 for(i=0; i<nSub; i++){
79728 nRow += apSub[i]->nOp;
79729 }
79730 }
79731 iPc = *piPc;
79732 while(1){ /* Loop exits via break */
79733 i = iPc++;
79734 if( i>=nRow ){
79735 p->rc = SQLITE_OK;
79736 rc = SQLITE_DONE;
79737 break;
79738 }
79739 if( i<p->nOp ){
79740 /* The rowid is small enough that we are still in the
79741 ** main program. */
79742 aOp = p->aOp;
79743 }else{
79744 /* We are currently listing subprograms. Figure out which one and
79745 ** pick up the appropriate opcode. */
79746 int j;
79747 i -= p->nOp;
79748 assert( apSub!=0 );
79749 assert( nSub>0 );
79750 for(j=0; i>=apSub[j]->nOp; j++){
79751 i -= apSub[j]->nOp;
79752 assert( i<apSub[j]->nOp || j+1<nSub );
79753 }
79754 aOp = apSub[j]->aOp;
79755 }
79756
79757 /* When an OP_Program opcode is encounter (the only opcode that has
79758 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
79759 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
79760 ** has not already been seen.
79761 */
79762 if( pSub!=0 && aOp[i].p4type==P4_SUBPROGRAM ){
79763 int nByte = (nSub+1)*sizeof(SubProgram*);
79764 int j;
79765 for(j=0; j<nSub; j++){
79766 if( apSub[j]==aOp[i].p4.pProgram ) break;
79767 }
79768 if( j==nSub ){
79769 p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0);
79770 if( p->rc!=SQLITE_OK ){
79771 rc = SQLITE_ERROR;
79772 break;
79773 }
79774 apSub = (SubProgram **)pSub->z;
79775 apSub[nSub++] = aOp[i].p4.pProgram;
79776 MemSetTypeFlag(pSub, MEM_Blob);
79777 pSub->n = nSub*sizeof(SubProgram*);
79778 nRow += aOp[i].p4.pProgram->nOp;
79779 }
79780 }
79781 if( eMode==0 ) break;
79782#ifdef SQLITE_ENABLE_BYTECODE_VTAB
79783 if( eMode==2 ){
79784 Op *pOp = aOp + i;
79785 if( pOp->opcode==OP_OpenRead ) break;
79786 if( pOp->opcode==OP_OpenWrite && (pOp->p5 & OPFLAG_P2ISREG)==0 ) break;
79787 if( pOp->opcode==OP_ReopenIdx ) break;
79788 }else
79789#endif
79790 {
79791 assert( eMode==1 );
79792 if( aOp[i].opcode==OP_Explain ) break;
79793 if( aOp[i].opcode==OP_Init && iPc>1 ) break;
79794 }

References SubProgram::aOp, Vdbe::aOp, sqlite3_value::flags, MEM_Blob, MemSetTypeFlag, sqlite3_value::n, SubProgram::nOp, Vdbe::nOp, OP_Explain, OP_Init, OP_OpenRead, OP_OpenWrite, OP_ReopenIdx, VdbeOp::opcode, OPFLAG_P2ISREG, VdbeOp::p4, P4_SUBPROGRAM, VdbeOp::p5, VdbeOp::p4union::pProgram, Vdbe::rc, sqlite3VdbeMemGrow(), SQLITE_DONE, SQLITE_ERROR, SQLITE_OK, and sqlite3_value::z.

Referenced by sqlite3VdbeList().

◆ sqlite3VdbeOneByteSerialTypeLen()

SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen ( u8 serial_type)

Definition at line 81462 of file sqlite3.c.

81462 {
81463 assert( serial_type<12
81464 || sqlite3SmallTypeSizes[serial_type]==(serial_type - 12)/2 );
81465 return sqlite3SmallTypeSizes[serial_type];

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeParameterIndex()

SQLITE_PRIVATE int sqlite3VdbeParameterIndex ( Vdbe * p,
const char * zName,
int nName )

Definition at line 84584 of file sqlite3.c.

Referenced by sqlite3VdbeExpandSql().

◆ sqlite3VdbeParser()

SQLITE_PRIVATE Parse * sqlite3VdbeParser ( Vdbe * p)

Definition at line 77784 of file sqlite3.c.

◆ sqlite3VdbePrepareFlags()

SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags ( Vdbe * v)

Definition at line 82796 of file sqlite3.c.

Referenced by sqlite3Reprepare().

◆ sqlite3VdbeRealValue()

SQLITE_PRIVATE double sqlite3VdbeRealValue ( Mem * pMem)

Definition at line 76445 of file sqlite3.c.

76445 {
76446 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
76447 double val = (double)0;
76448 sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
76449 return val;
76450}
76452 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
76453 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
76454 if( pMem->flags & MEM_Real ){
76455 return pMem->u.r;
76456 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
76457 testcase( pMem->flags & MEM_IntReal );
76458 return (double)pMem->u.i;
76459 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){

References sqlite3_value::enc, sqlite3_value::n, sqlite3AtoF(), and sqlite3_value::z.

Referenced by sqlite3_value_int64(), and sqlite3VdbeExec().

◆ sqlite3VdbeRecordCompare()

SQLITE_PRIVATE int sqlite3VdbeRecordCompare ( int nKey1,
const void * pKey1,
UnpackedRecord * pPKey2 )

◆ sqlite3VdbeRecordCompareWithSkip()

SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip ( int nKey1,
const void * pKey1,
UnpackedRecord * pPKey2,
int bSkip )

Definition at line 82210 of file sqlite3.c.

82220 {
82221 u32 d1; /* Offset into aKey[] of next data element */
82222 int i; /* Index of next field to compare */
82223 u32 szHdr1; /* Size of record header in bytes */
82224 u32 idx1; /* Offset of first type in header */
82225 int rc = 0; /* Return value */
82226 Mem *pRhs = pPKey2->aMem; /* Next field of pPKey2 to compare */
82227 KeyInfo *pKeyInfo;
82228 const unsigned char *aKey1 = (const unsigned char *)pKey1;
82229 Mem mem1;
82230
82231 /* If bSkip is true, then the caller has already determined that the first
82232 ** two elements in the keys are equal. Fix the various stack variables so
82233 ** that this routine begins comparing at the second field. */
82234 if( bSkip ){
82235 u32 s1;
82236 idx1 = 1 + getVarint32(&aKey1[1], s1);
82237 szHdr1 = aKey1[0];
82238 d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
82239 i = 1;
82240 pRhs++;
82241 }else{
82242 idx1 = getVarint32(aKey1, szHdr1);
82243 d1 = szHdr1;
82244 i = 0;
82245 }
82246 if( d1>(unsigned)nKey1 ){
82247 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
82248 return 0; /* Corruption */
82249 }
82250
82251 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
82252 assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField
82253 || CORRUPT_DB );
82254 assert( pPKey2->pKeyInfo->aSortFlags!=0 );
82255 assert( pPKey2->pKeyInfo->nKeyField>0 );
82256 assert( idx1<=szHdr1 || CORRUPT_DB );
82257 do{
82258 u32 serial_type;
82259
82260 /* RHS is an integer */
82261 if( pRhs->flags & (MEM_Int|MEM_IntReal) ){
82262 testcase( pRhs->flags & MEM_Int );
82263 testcase( pRhs->flags & MEM_IntReal );
82264 serial_type = aKey1[idx1];
82265 testcase( serial_type==12 );
82266 if( serial_type>=10 ){
82267 rc = +1;
82268 }else if( serial_type==0 ){
82269 rc = -1;
82270 }else if( serial_type==7 ){
82271 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
82272 rc = -sqlite3IntFloatCompare(pRhs->u.i, mem1.u.r);
82273 }else{
82274 i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
82275 i64 rhs = pRhs->u.i;
82276 if( lhs<rhs ){
82277 rc = -1;
82278 }else if( lhs>rhs ){
82279 rc = +1;
82280 }
82281 }
82282 }
82283
82284 /* RHS is real */
82285 else if( pRhs->flags & MEM_Real ){
82286 serial_type = aKey1[idx1];
82287 if( serial_type>=10 ){
82288 /* Serial types 12 or greater are strings and blobs (greater than
82289 ** numbers). Types 10 and 11 are currently "reserved for future
82290 ** use", so it doesn't really matter what the results of comparing
82291 ** them to numberic values are. */
82292 rc = +1;
82293 }else if( serial_type==0 ){
82294 rc = -1;
82295 }else{
82296 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
82297 if( serial_type==7 ){
82298 if( mem1.u.r<pRhs->u.r ){
82299 rc = -1;
82300 }else if( mem1.u.r>pRhs->u.r ){
82301 rc = +1;
82302 }
82303 }else{
82304 rc = sqlite3IntFloatCompare(mem1.u.i, pRhs->u.r);
82305 }
82306 }
82307 }
82308
82309 /* RHS is a string */
82310 else if( pRhs->flags & MEM_Str ){
82311 getVarint32NR(&aKey1[idx1], serial_type);
82312 testcase( serial_type==12 );
82313 if( serial_type<12 ){
82314 rc = -1;
82315 }else if( !(serial_type & 0x01) ){
82316 rc = +1;
82317 }else{
82318 mem1.n = (serial_type - 12) / 2;
82319 testcase( (d1+mem1.n)==(unsigned)nKey1 );
82320 testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
82321 if( (d1+mem1.n) > (unsigned)nKey1
82322 || (pKeyInfo = pPKey2->pKeyInfo)->nAllField<=i
82323 ){
82324 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
82325 return 0; /* Corruption */
82326 }else if( pKeyInfo->aColl[i] ){
82327 mem1.enc = pKeyInfo->enc;
82328 mem1.db = pKeyInfo->db;
82329 mem1.flags = MEM_Str;
82330 mem1.z = (char*)&aKey1[d1];
82332 &mem1, pRhs, pKeyInfo->aColl[i], &pPKey2->errCode
82333 );
82334 }else{
82335 int nCmp = MIN(mem1.n, pRhs->n);
82336 rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
82337 if( rc==0 ) rc = mem1.n - pRhs->n;
82338 }
82339 }
82340 }
82341
82342 /* RHS is a blob */
82343 else if( pRhs->flags & MEM_Blob ){
82344 assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 );
82345 getVarint32NR(&aKey1[idx1], serial_type);
82346 testcase( serial_type==12 );
82347 if( serial_type<12 || (serial_type & 0x01) ){
82348 rc = -1;
82349 }else{
82350 int nStr = (serial_type - 12) / 2;
82351 testcase( (d1+nStr)==(unsigned)nKey1 );
82352 testcase( (d1+nStr+1)==(unsigned)nKey1 );
82353 if( (d1+nStr) > (unsigned)nKey1 ){
82354 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
82355 return 0; /* Corruption */
82356 }else if( pRhs->flags & MEM_Zero ){
82357 if( !isAllZero((const char*)&aKey1[d1],nStr) ){
82358 rc = 1;
82359 }else{
82360 rc = nStr - pRhs->u.nZero;
82361 }
82362 }else{
82363 int nCmp = MIN(nStr, pRhs->n);
82364 rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
82365 if( rc==0 ) rc = nStr - pRhs->n;
82366 }
82367 }
82368 }
82369
82370 /* RHS is null */
82371 else{
82372 serial_type = aKey1[idx1];
82373 rc = (serial_type!=0);
82374 }
82375
82376 if( rc!=0 ){
82377 int sortFlags = pPKey2->pKeyInfo->aSortFlags[i];
82378 if( sortFlags ){
82379 if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
82380 || ((sortFlags & KEYINFO_ORDER_DESC)
82381 !=(serial_type==0 || (pRhs->flags&MEM_Null)))
82382 ){
82383 rc = -rc;
82384 }
82385 }
82386 assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
82387 assert( mem1.szMalloc==0 ); /* See comment below */
82388 return rc;
82389 }
82390
82391 i++;
82392 if( i==pPKey2->nField ) break;
82393 pRhs++;
82394 d1 += sqlite3VdbeSerialTypeLen(serial_type);
82395 idx1 += sqlite3VarintLen(serial_type);
82396 }while( idx1<(unsigned)szHdr1 && d1<=(unsigned)nKey1 );
82397
82398 /* No memory allocation is ever used on mem1. Prove this using
82399 ** the following assert(). If the assert() fails, it indicates a
82400 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
82401 assert( mem1.szMalloc==0 );
82402
82403 /* rc==0 here means that one or both of the keys ran out of fields and
82404 ** all the fields up to that point were equal. Return the default_rc
82405 ** value. */
82406 assert( CORRUPT_DB
static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey)
Definition sqlite3.c:82155

References KeyInfo::aColl, UnpackedRecord::aMem, KeyInfo::aSortFlags, CORRUPT_DB, KeyInfo::db, sqlite3_value::db, KeyInfo::enc, sqlite3_value::enc, UnpackedRecord::errCode, sqlite3_value::flags, getVarint32, getVarint32NR, sqlite3_value::MemValue::i, isAllZero(), KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, MEM_Blob, MEM_Int, MEM_IntReal, MEM_Null, MEM_Real, MEM_Str, MEM_Zero, MIN, sqlite3_value::n, KeyInfo::nAllField, UnpackedRecord::nField, KeyInfo::nKeyField, sqlite3_value::MemValue::nZero, UnpackedRecord::pKeyInfo, sqlite3_value::MemValue::r, sqlite3IntFloatCompare(), sqlite3VarintLen(), sqlite3VdbeSerialGet(), sqlite3VdbeSerialTypeLen(), SQLITE_CORRUPT_BKPT, sqlite3_value::szMalloc, testcase, sqlite3_value::u, vdbeCompareMemString(), vdbeRecordDecodeInt(), VVA_ONLY, and sqlite3_value::z.

Referenced by sqlite3VdbeIdxKeyCompare(), vdbeRecordCompareInt(), vdbeRecordCompareString(), and vdbeSorterCompareTail().

◆ sqlite3VdbeRecordUnpack()

SQLITE_PRIVATE void sqlite3VdbeRecordUnpack ( KeyInfo * pKeyInfo,
int nKey,
const void * pKey,
UnpackedRecord * p )

Definition at line 81748 of file sqlite3.c.

81759 {
81760 const unsigned char *aKey = (const unsigned char *)pKey;
81761 u32 d;
81762 u32 idx; /* Offset in aKey[] to read from */
81763 u16 u; /* Unsigned loop counter */
81764 u32 szHdr;
81765 Mem *pMem = p->aMem;
81766
81767 p->default_rc = 0;
81768 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81769 idx = getVarint32(aKey, szHdr);
81770 d = szHdr;
81771 u = 0;
81772 while( idx<szHdr && d<=(u32)nKey ){
81773 u32 serial_type;
81774
81775 idx += getVarint32(&aKey[idx], serial_type);
81776 pMem->enc = pKeyInfo->enc;
81777 pMem->db = pKeyInfo->db;
81778 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
81779 pMem->szMalloc = 0;
81780 pMem->z = 0;
81781 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
81782 pMem++;
81783 if( (++u)>=p->nField ) break;
81784 }
81785 if( d>(u32)nKey && u ){
81786 assert( CORRUPT_DB );
81787 /* In a corrupt record entry, the last pMem might have been set up using
81788 ** uninitialized memory. Overwrite its value with NULL, to prevent

References UnpackedRecord::aMem, CORRUPT_DB, KeyInfo::db, sqlite3_value::db, UnpackedRecord::default_rc, EIGHT_BYTE_ALIGNMENT, KeyInfo::enc, sqlite3_value::enc, getVarint32, UnpackedRecord::nField, sqlite3VdbeMemSetNull(), sqlite3VdbeSerialGet(), sqlite3_value::szMalloc, and sqlite3_value::z.

Referenced by btreeMoveto(), sqlite3VdbeExec(), sqlite3VdbeSorterCompare(), vdbeSorterCompare(), and vdbeSorterCompareTail().

◆ sqlite3VdbeReset()

SQLITE_PRIVATE int sqlite3VdbeReset ( Vdbe * p)

Definition at line 81017 of file sqlite3.c.

81023 {
81024#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
81025 int i;
81026#endif
81027
81028 sqlite3 *db;
81029 db = p->db;
81030
81031 /* If the VM did not run to completion or if it encountered an
81032 ** error, then it might not have been halted properly. So halt
81033 ** it now.
81034 */
81035 sqlite3VdbeHalt(p);
81036
81037 /* If the VDBE has been run even partially, then transfer the error code
81038 ** and error message from the VDBE into the main database structure. But
81039 ** if the VDBE has just been set to run but has not actually executed any
81040 ** instructions yet, leave the main database error information unchanged.
81041 */
81042 if( p->pc>=0 ){
81044 if( db->pErr || p->zErrMsg ){
81046 }else{
81047 db->errCode = p->rc;
81048 }
81049 if( p->runOnlyOnce ) p->expired = 1;
81050 }else if( p->rc && p->expired ){
81051 /* The expired flag was set on the VDBE before the first call
81052 ** to sqlite3_step(). For consistency (since sqlite3_step() was
81053 ** called), set the database error in this case as well.
81054 */
81055 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
81056 }
81057
81058 /* Reset register contents and reclaim error message memory.
81059 */
81060#ifdef SQLITE_DEBUG
81061 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
81062 ** Vdbe.aMem[] arrays have already been cleaned up. */
81063 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
81064 if( p->aMem ){
81065 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
81066 }
81067#endif
81068 if( p->zErrMsg ){
81069 sqlite3DbFree(db, p->zErrMsg);
81070 p->zErrMsg = 0;
81071 }
81072 p->pResultSet = 0;
81073#ifdef SQLITE_DEBUG
81074 p->nWrite = 0;
81075#endif
81076
81077 /* Save profiling information from this VDBE run.
81078 */
81079#ifdef VDBE_PROFILE
81080 {
81081 FILE *out = fopen("vdbe_profile.out", "a");
81082 if( out ){
81083 fprintf(out, "---- ");
81084 for(i=0; i<p->nOp; i++){
81085 fprintf(out, "%02x", p->aOp[i].opcode);
81086 }
81087 fprintf(out, "\n");
81088 if( p->zSql ){
81089 char c, pc = 0;
81090 fprintf(out, "-- ");
81091 for(i=0; (c = p->zSql[i])!=0; i++){
81092 if( pc=='\n' ) fprintf(out, "-- ");
81093 putc(c, out);
81094 pc = c;
81095 }
81096 if( pc!='\n' ) fprintf(out, "\n");
81097 }
81098 for(i=0; i<p->nOp; i++){
81099 char zHdr[100];
81100 sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
81101 p->aOp[i].cnt,
81102 p->aOp[i].cycles,
81103 p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
81104 );
81105 fprintf(out, "%s", zHdr);
81106 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
81107 }
81108 fclose(out);
#define vdbeInvokeSqllog(x)
Definition sqlite3.c:81003
bft runOnlyOnce
Definition sqlite3.c:21130

References Vdbe::aMem, Vdbe::aOp, Vdbe::apCsr, Vdbe::db, sqlite3::errCode, sqlite3::errMask, Vdbe::expired, sqlite3_value::flags, Vdbe::magic, MEM_Undefined, Vdbe::nCursor, Vdbe::nMem, Vdbe::nOp, VdbeOp::opcode, Vdbe::pc, sqlite3::pErr, Vdbe::pResultSet, Vdbe::rc, Vdbe::runOnlyOnce, sqlite3_snprintf(), sqlite3DbFree(), sqlite3ErrorWithMsg(), sqlite3VdbeHalt(), sqlite3VdbeTransferError(), VDBE_MAGIC_RESET, vdbeInvokeSqllog, Vdbe::zErrMsg, and Vdbe::zSql.

Referenced by sqlite3_reset().

◆ sqlite3VdbeResetStepResult()

SQLITE_PRIVATE void sqlite3VdbeResetStepResult ( Vdbe * p)

Definition at line 80956 of file sqlite3.c.

References Vdbe::rc, and SQLITE_OK.

Referenced by sqlite3Reprepare().

◆ sqlite3VdbeResolveLabel()

◆ sqlite3VdbeReusable()

SQLITE_PRIVATE void sqlite3VdbeReusable ( Vdbe * p)

Definition at line 78325 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ sqlite3VdbeRewind()

SQLITE_PRIVATE void sqlite3VdbeRewind ( Vdbe * p)

Definition at line 80022 of file sqlite3.c.

80028 {
80029#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
80030 int i;
80031#endif
80032 assert( p!=0 );
80033 assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET );
80034
80035 /* There should be at least one opcode.
80036 */
80037 assert( p->nOp>0 );
80038
80039 /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
80040 p->magic = VDBE_MAGIC_RUN;
80041
80042#ifdef SQLITE_DEBUG
80043 for(i=0; i<p->nMem; i++){
80044 assert( p->aMem[i].db==p->db );
80045 }
80046#endif
80047 p->pc = -1;
80048 p->rc = SQLITE_OK;
80049 p->errorAction = OE_Abort;
80050 p->nChange = 0;
80051 p->cacheCtr = 1;
80052 p->minWriteFileFormat = 255;
80053 p->iStatement = 0;
80054 p->nFkConstraint = 0;
80055#ifdef VDBE_PROFILE
#define VDBE_MAGIC_RESET
Definition sqlite3.c:21162

Referenced by sqlite3_reset(), and sqlite3VdbeMakeReady().

◆ sqlite3VdbeRunOnlyOnce()

SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce ( Vdbe * p)

Definition at line 78318 of file sqlite3.c.

Referenced by sqlite3Pragma().

◆ sqlite3VdbeSerialGet()

SQLITE_PRIVATE u32 sqlite3VdbeSerialGet ( const unsigned char * buf,
u32 serial_type,
Mem * pMem )

Definition at line 81623 of file sqlite3.c.

81625 : MEM_Real;
81626 }
81627 return 8;
81628}
81630 const unsigned char *buf, /* Buffer to deserialize from */
81631 u32 serial_type, /* Serial type to deserialize */
81632 Mem *pMem /* Memory cell to write value into */
81633){
81634 switch( serial_type ){
81635 case 10: { /* Internal use only: NULL with virtual table
81636 ** UPDATE no-change flag set */
81637 pMem->flags = MEM_Null|MEM_Zero;
81638 pMem->n = 0;
81639 pMem->u.nZero = 0;
81640 break;
81641 }
81642 case 11: /* Reserved for future use */
81643 case 0: { /* Null */
81644 /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
81645 pMem->flags = MEM_Null;
81646 break;
81647 }
81648 case 1: {
81649 /* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement
81650 ** integer. */
81651 pMem->u.i = ONE_BYTE_INT(buf);
81652 pMem->flags = MEM_Int;
81653 testcase( pMem->u.i<0 );
81654 return 1;
81655 }
81656 case 2: { /* 2-byte signed integer */
81657 /* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit
81658 ** twos-complement integer. */
81659 pMem->u.i = TWO_BYTE_INT(buf);
81660 pMem->flags = MEM_Int;
81661 testcase( pMem->u.i<0 );
81662 return 2;
81663 }
81664 case 3: { /* 3-byte signed integer */
81665 /* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit
81666 ** twos-complement integer. */
81667 pMem->u.i = THREE_BYTE_INT(buf);
81668 pMem->flags = MEM_Int;
81669 testcase( pMem->u.i<0 );
81670 return 3;
81671 }
81672 case 4: { /* 4-byte signed integer */
81673 /* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit
81674 ** twos-complement integer. */
81675 pMem->u.i = FOUR_BYTE_INT(buf);
81676#ifdef __HP_cc
81677 /* Work around a sign-extension bug in the HP compiler for HP/UX */
81678 if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL;
81679#endif
81680 pMem->flags = MEM_Int;
81681 testcase( pMem->u.i<0 );
81682 return 4;
81683 }
81684 case 5: { /* 6-byte signed integer */
81685 /* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit
81686 ** twos-complement integer. */
81687 pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
81688 pMem->flags = MEM_Int;
81689 testcase( pMem->u.i<0 );
81690 return 6;
81691 }
81692 case 6: /* 8-byte signed integer */
81693 case 7: { /* IEEE floating point */
81694 /* These use local variables, so do them in a separate routine
81695 ** to avoid having to move the frame pointer in the common case */
81696 return serialGet(buf,serial_type,pMem);
81697 }
81698 case 8: /* Integer 0 */
81699 case 9: { /* Integer 1 */
81700 /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
81701 /* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */
81702 pMem->u.i = serial_type-8;
81703 pMem->flags = MEM_Int;
81704 return 0;
81705 }
81706 default: {
81707 /* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
81708 ** length.
81709 ** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and
81710 ** (N-13)/2 bytes in length. */
81711 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
81712 pMem->z = (char *)buf;
81713 pMem->n = (serial_type-12)/2;
#define TWO_BYTE_INT(x)
Definition sqlite3.c:81573
#define ONE_BYTE_INT(x)
Definition sqlite3.c:81572
#define FOUR_BYTE_INT(x)
Definition sqlite3.c:81576
static u32 serialGet(const unsigned char *buf, u32 serial_type, Mem *pMem)
Definition sqlite3.c:81587
#define THREE_BYTE_INT(x)
Definition sqlite3.c:81574

Referenced by sqlite3VdbeExec(), sqlite3VdbeIdxRowid(), sqlite3VdbeRecordCompareWithSkip(), and sqlite3VdbeRecordUnpack().

◆ sqlite3VdbeSerialPut() [1/2]

SQLITE_PRIVATE u32 sqlite3VdbeSerialPut ( u8 * buf,
Mem * pMem,
u32 serial_type )

Definition at line 81533 of file sqlite3.c.

81539 {
81540 u32 len;
81541
81542 /* Integer and Real */
81543 if( serial_type<=7 && serial_type>0 ){
81544 u64 v;
81545 u32 i;
81546 if( serial_type==7 ){
81547 assert( sizeof(v)==sizeof(pMem->u.r) );
81548 memcpy(&v, &pMem->u.r, sizeof(v));
81550 }else{
81551 v = pMem->u.i;
81552 }
81553 len = i = sqlite3SmallTypeSizes[serial_type];
81554 assert( i>0 );
81555 do{
81556 buf[--i] = (u8)(v&0xFF);
81557 v >>= 8;
81558 }while( i );
81559 return len;
81560 }
81561
81562 /* String or blob */
81563 if( serial_type>=12 ){
81564 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
81565 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
81566 len = pMem->n;
81567 if( len>0 ) memcpy(buf, pMem->z, len);

References sqlite3_value::flags, sqlite3_value::MemValue::i, MEM_Zero, sqlite3_value::n, sqlite3_value::MemValue::nZero, sqlite3_value::MemValue::r, sqlite3SmallTypeSizes, sqlite3VdbeSerialTypeLen(), swapMixedEndianFloat, sqlite3_value::u, and sqlite3_value::z.

◆ sqlite3VdbeSerialPut() [2/2]

SQLITE_PRIVATE u32 sqlite3VdbeSerialPut ( unsigned char * ,
Mem * ,
u32  )

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSerialTypeLen()

SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen ( u32 serial_type)

Definition at line 81453 of file sqlite3.c.

81459 {
81460 if( serial_type>=128 ){
81461 return (serial_type-12)/2;

Referenced by blobSeekToRow(), sqlite3VdbeExec(), sqlite3VdbeRecordCompareWithSkip(), and sqlite3VdbeSerialPut().

◆ sqlite3VdbeSetChanges()

SQLITE_PRIVATE void sqlite3VdbeSetChanges ( sqlite3 * db,
int nChange )

Definition at line 82747 of file sqlite3.c.

Referenced by sqlite3VdbeExec(), and sqlite3VdbeHalt().

◆ sqlite3VdbeSetColName()

SQLITE_PRIVATE int sqlite3VdbeSetColName ( Vdbe * p,
int idx,
int var,
const char * zName,
void(*)(void *) xDel )

Definition at line 80339 of file sqlite3.c.

80351 {
80352 int rc;
80353 Mem *pColName;
80354 assert( idx<p->nResColumn );
80355 assert( var<COLNAME_N );
80356 if( p->db->mallocFailed ){
80357 assert( !zName || xDel!=SQLITE_DYNAMIC );
80358 return SQLITE_NOMEM_BKPT;
80359 }

References Vdbe::aColName, COLNAME_N, Vdbe::db, sqlite3_value::flags, sqlite3::mallocFailed, MEM_Term, Vdbe::nResColumn, sqlite3VdbeMemSetStr(), SQLITE_DYNAMIC, SQLITE_NOMEM_BKPT, SQLITE_UTF8, and zName.

Referenced by generateColumnNames(), sqlite3DeleteFrom(), sqlite3Insert(), sqlite3Pragma(), sqlite3Update(), and sqlite3VdbeMakeReady().

◆ sqlite3VdbeSetNumCols()

SQLITE_PRIVATE void sqlite3VdbeSetNumCols ( Vdbe * p,
int nResColumn )

◆ sqlite3VdbeSetP4KeyInfo()

◆ sqlite3VdbeSetSql()

SQLITE_PRIVATE void sqlite3VdbeSetSql ( Vdbe * p,
const char * z,
int n,
u8 prepFlags )

Definition at line 77802 of file sqlite3.c.

77808 {
77809 if( p==0 ) return;
77810 p->prepFlags = prepFlags;

◆ sqlite3VdbeSetVarmask()

SQLITE_PRIVATE void sqlite3VdbeSetVarmask ( Vdbe * v,
int iVar )

Definition at line 82830 of file sqlite3.c.

82836 {
82837 assert( iVar>0 );
82838 assert( (v->db->flags & SQLITE_EnableQPSG)==0 );

References Vdbe::db, Vdbe::expmask, sqlite3::flags, and SQLITE_EnableQPSG.

Referenced by exprCompareVariable(), and isLikeOrGlob().

◆ sqlite3VdbeSorterClose()

SQLITE_PRIVATE void sqlite3VdbeSorterClose ( sqlite3 * db,
VdbeCursor * pCsr )

Definition at line 95137 of file sqlite3.c.

95143 {
95144 VdbeSorter *pSorter;
95145 assert( pCsr->eCurType==CURTYPE_SORTER );
95146 pSorter = pCsr->uc.pSorter;
95147 if( pSorter ){

◆ sqlite3VdbeSorterCompare()

SQLITE_PRIVATE int sqlite3VdbeSorterCompare ( const VdbeCursor * pCsr,
Mem * pVal,
int nKeyCol,
int * pRes )

Definition at line 96604 of file sqlite3.c.

96615 {
96616 VdbeSorter *pSorter;
96617 UnpackedRecord *r2;
96618 KeyInfo *pKeyInfo;
96619 int i;
96620 void *pKey; int nKey; /* Sorter key to compare pVal with */
96621
96622 assert( pCsr->eCurType==CURTYPE_SORTER );
96623 pSorter = pCsr->uc.pSorter;
96624 r2 = pSorter->pUnpacked;
96625 pKeyInfo = pCsr->pKeyInfo;
96626 if( r2==0 ){
96627 r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
96628 if( r2==0 ) return SQLITE_NOMEM_BKPT;
96629 r2->nField = nKeyCol;
96630 }
96631 assert( r2->nField==nKeyCol );
96632
96633 pKey = vdbeSorterRowkey(pSorter, &nKey);
96634 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
96635 for(i=0; i<nKeyCol; i++){
96636 if( r2->aMem[i].flags & MEM_Null ){
96637 *pRes = -1;
96638 return SQLITE_OK;
static void * vdbeSorterRowkey(const VdbeSorter *pSorter, int *pnKey)
Definition sqlite3.c:96544
UnpackedRecord * pUnpacked
Definition sqlite3.c:94204

References UnpackedRecord::aMem, CURTYPE_SORTER, VdbeCursor::eCurType, sqlite3_value::flags, MEM_Null, sqlite3_value::n, UnpackedRecord::nField, VdbeCursor::pKeyInfo, VdbeCursor::pSorter, VdbeSorter::pUnpacked, sqlite3VdbeAllocUnpackedRecord(), sqlite3VdbeRecordCompare(), sqlite3VdbeRecordUnpack(), SQLITE_NOMEM_BKPT, SQLITE_OK, VdbeCursor::uc, vdbeSorterRowkey(), and sqlite3_value::z.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSorterInit()

SQLITE_PRIVATE int sqlite3VdbeSorterInit ( sqlite3 * db,
int nField,
VdbeCursor * pCsr )

Definition at line 94806 of file sqlite3.c.

94816 {
94817 int pgsz; /* Page size of main database */
94818 int i; /* Used to iterate through aTask[] */
94819 VdbeSorter *pSorter; /* The new sorter */
94820 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
94821 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
94822 int sz; /* Size of pSorter in bytes */
94823 int rc = SQLITE_OK;
94824#if SQLITE_MAX_WORKER_THREADS==0
94825# define nWorker 0
94826#else
94827 int nWorker;
94828#endif
94829
94830 /* Initialize the upper limit on the number of worker threads */
94831#if SQLITE_MAX_WORKER_THREADS>0
94832 if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
94833 nWorker = 0;
94834 }else{
94835 nWorker = db->aLimit[SQLITE_LIMIT_WORKER_THREADS];
94836 }
94837#endif
94838
94839 /* Do not allow the total number of threads (main thread + all workers)
94840 ** to exceed the maximum merge count */
94841#if SQLITE_MAX_WORKER_THREADS>=SORTER_MAX_MERGE_COUNT
94842 if( nWorker>=SORTER_MAX_MERGE_COUNT ){
94843 nWorker = SORTER_MAX_MERGE_COUNT-1;
94844 }
94845#endif
94846
94847 assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
94848 assert( pCsr->eCurType==CURTYPE_SORTER );
94849 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
94850 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
94851
94852 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
94853 pCsr->uc.pSorter = pSorter;
94854 if( pSorter==0 ){
94855 rc = SQLITE_NOMEM_BKPT;
94856 }else{
94857 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
94858 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
94859 pKeyInfo->db = 0;
94860 if( nField && nWorker==0 ){
94861 pKeyInfo->nKeyField = nField;
94862 }
94863 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
94864 pSorter->nTask = nWorker + 1;
94865 pSorter->iPrev = (u8)(nWorker - 1);
94866 pSorter->bUseThreads = (pSorter->nTask>1);
94867 pSorter->db = db;
94868 for(i=0; i<pSorter->nTask; i++){
94869 SortSubtask *pTask = &pSorter->aTask[i];
94870 pTask->pSorter = pSorter;
94871 }
94872
94873 if( !sqlite3TempInMemory(db) ){
94874 i64 mxCache; /* Cache size in bytes*/
94875 u32 szPma = sqlite3GlobalConfig.szPma;
94876 pSorter->mnPmaSize = szPma * pgsz;
94877
94878 mxCache = db->aDb[0].pSchema->cache_size;
94879 if( mxCache<0 ){
94880 /* A negative cache-size value C indicates that the cache is abs(C)
94881 ** KiB in size. */
94882 mxCache = mxCache * -1024;
94883 }else{
94884 mxCache = mxCache * pgsz;
94885 }
94886 mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
94887 pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
94888
94889 /* Avoid large memory allocations if the application has requested
94890 ** SQLITE_CONFIG_SMALL_MALLOC. */
94891 if( sqlite3GlobalConfig.bSmallMalloc==0 ){
94892 assert( pSorter->iMemory==0 );
94893 pSorter->nMemory = pgsz;
94894 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
94895 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
94896 }
94897 }
94898
94899 if( pKeyInfo->nAllField<13
94900 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
94901 && (pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL)==0
94902 ){
struct VdbeSorter VdbeSorter
Definition sqlite3.c:20758
struct KeyInfo KeyInfo
Definition sqlite3.c:14677
#define SQLITE_MAX_PMASZ
Definition sqlite3.c:94033
#define SORTER_MAX_MERGE_COUNT
Definition sqlite3.c:94338
VdbeSorter * pSorter
Definition sqlite3.c:94176
u8 * aMemory
Definition sqlite3.c:94066
SorterList list
Definition sqlite3.c:94205
int mnPmaSize
Definition sqlite3.c:94196
sqlite3 * db
Definition sqlite3.c:94202
KeyInfo * pKeyInfo
Definition sqlite3.c:94203
int mxPmaSize
Definition sqlite3.c:94197
SortSubtask aTask[1]
Definition sqlite3.c:94213

References KeyInfo::aColl, sqlite3::aDb, sqlite3::aLimit, SorterList::aMemory, KeyInfo::aSortFlags, VdbeSorter::aTask, VdbeSorter::bUseThreads, Schema::cache_size, CURTYPE_SORTER, KeyInfo::db, VdbeSorter::db, VdbeCursor::eCurType, VdbeSorter::iMemory, VdbeSorter::iPrev, KEYINFO_ORDER_BIGNULL, VdbeSorter::list, MAX, MIN, VdbeSorter::mnPmaSize, VdbeSorter::mxPmaSize, KeyInfo::nAllField, KeyInfo::nKeyField, VdbeSorter::nMemory, VdbeSorter::nTask, Db::pBt, VdbeCursor::pBtx, sqlite3::pDfltColl, VdbeSorter::pgsz, VdbeCursor::pKeyInfo, VdbeSorter::pKeyInfo, Db::pSchema, VdbeCursor::pSorter, SortSubtask::pSorter, SORTER_MAX_MERGE_COUNT, SORTER_TYPE_INTEGER, SORTER_TYPE_TEXT, sqlite3BtreeGetPageSize(), sqlite3DbMallocZero(), sqlite3GlobalConfig, sqlite3Malloc(), sqlite3TempInMemory(), SQLITE_LIMIT_WORKER_THREADS, SQLITE_MAX_PMASZ, SQLITE_NOMEM_BKPT, SQLITE_OK, VdbeSorter::typeMask, and VdbeCursor::uc.

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSorterNext()

SQLITE_PRIVATE int sqlite3VdbeSorterNext ( sqlite3 * db,
const VdbeCursor * pCsr )

Definition at line 96506 of file sqlite3.c.

96506 :
96507**
96508** SQLITE_OK success
96509** SQLITE_DONE end of data
96510** otherwise some kind of error.
96511*/
96513 VdbeSorter *pSorter;
96514 int rc; /* Return code */
96515
96516 assert( pCsr->eCurType==CURTYPE_SORTER );
96517 pSorter = pCsr->uc.pSorter;
96518 assert( pSorter->bUsePMA || (pSorter->pReader==0 && pSorter->pMerger==0) );
96519 if( pSorter->bUsePMA ){
96520 assert( pSorter->pReader==0 || pSorter->pMerger==0 );
96521 assert( pSorter->bUseThreads==0 || pSorter->pReader );
96522 assert( pSorter->bUseThreads==1 || pSorter->pMerger );
96523#if SQLITE_MAX_WORKER_THREADS>0
96524 if( pSorter->bUseThreads ){
96525 rc = vdbePmaReaderNext(pSorter->pReader);
96526 if( rc==SQLITE_OK && pSorter->pReader->pFd==0 ) rc = SQLITE_DONE;
96527 }else
96528#endif
96529 /*if( !pSorter->bUseThreads )*/ {
96530 int res = 0;
96531 assert( pSorter->pMerger!=0 );
96532 assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
96533 rc = vdbeMergeEngineStep(pSorter->pMerger, &res);
96534 if( rc==SQLITE_OK && res ) rc = SQLITE_DONE;
96535 }
96536 }else{
96537 SorterRecord *pFree = pSorter->list.pList;
96538 pSorter->list.pList = pFree->u.pNext;
static int vdbeMergeEngineStep(MergeEngine *pMerger, int *pbEof)
Definition sqlite3.c:95485
static int vdbePmaReaderNext(PmaReader *pReadr)
Definition sqlite3.c:94555
SortSubtask * pTask
Definition sqlite3.c:94136
sqlite3_file * pFd
Definition sqlite3.c:94233
SorterRecord * pList
Definition sqlite3.c:94065
SorterRecord * pNext
Definition sqlite3.c:94323
union SorterRecord::@119 u
MergeEngine * pMerger
Definition sqlite3.c:94201
PmaReader * pReader
Definition sqlite3.c:94200

References SorterList::aMemory, VdbeSorter::aTask, VdbeSorter::bUsePMA, VdbeSorter::bUseThreads, CURTYPE_SORTER, VdbeCursor::eCurType, VdbeSorter::list, PmaReader::pFd, SorterList::pList, VdbeSorter::pMerger, SorterRecord::pNext, VdbeSorter::pReader, VdbeCursor::pSorter, MergeEngine::pTask, SQLITE_DONE, SQLITE_OK, SorterRecord::u, VdbeCursor::uc, vdbeMergeEngineStep(), vdbePmaReaderNext(), and vdbeSorterRecordFree().

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSorterReset()

SQLITE_PRIVATE void sqlite3VdbeSorterReset ( sqlite3 * db,
VdbeSorter * pSorter )

Definition at line 95104 of file sqlite3.c.

95110 {
95111 int i;
95112 (void)vdbeSorterJoinAll(pSorter, SQLITE_OK);
95113 assert( pSorter->bUseThreads || pSorter->pReader==0 );
95114#if SQLITE_MAX_WORKER_THREADS>0
95115 if( pSorter->pReader ){
95116 vdbePmaReaderClear(pSorter->pReader);
95117 sqlite3DbFree(db, pSorter->pReader);
95118 pSorter->pReader = 0;
95119 }
95120#endif
95121 vdbeMergeEngineFree(pSorter->pMerger);
95122 pSorter->pMerger = 0;
95123 for(i=0; i<pSorter->nTask; i++){
95124 SortSubtask *pTask = &pSorter->aTask[i];
95125 vdbeSortSubtaskCleanup(db, pTask);
95126 pTask->pSorter = pSorter;
95127 }
95128 if( pSorter->list.aMemory==0 ){
95129 vdbeSorterRecordFree(0, pSorter->list.pList);
95130 }
95131 pSorter->list.pList = 0;
95132 pSorter->list.szPMA = 0;
static int vdbeSorterJoinAll(VdbeSorter *pSorter, int rcin)
Definition sqlite3.c:95020
static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord)
Definition sqlite3.c:94908
static void vdbeMergeEngineFree(MergeEngine *pMerger)
Definition sqlite3.c:95073
static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask)
Definition sqlite3.c:94921
static void vdbePmaReaderClear(PmaReader *pReadr)
Definition sqlite3.c:94347

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSorterRewind()

SQLITE_PRIVATE int sqlite3VdbeSorterRewind ( const VdbeCursor * pCsr,
int * pbEof )

Definition at line 96454 of file sqlite3.c.

96460 {
96461 VdbeSorter *pSorter;
96462 int rc = SQLITE_OK; /* Return code */
96463
96464 assert( pCsr->eCurType==CURTYPE_SORTER );
96465 pSorter = pCsr->uc.pSorter;
96466 assert( pSorter );
96467
96468 /* If no data has been written to disk, then do not do so now. Instead,
96469 ** sort the VdbeSorter.pRecord list. The vdbe layer will read data directly
96470 ** from the in-memory list. */
96471 if( pSorter->bUsePMA==0 ){
96472 if( pSorter->list.pList ){
96473 *pbEof = 0;
96474 rc = vdbeSorterSort(&pSorter->aTask[0], &pSorter->list);
96475 }else{
96476 *pbEof = 1;
96477 }
96478 return rc;
96479 }
96480
96481 /* Write the current in-memory list to a PMA. When the VdbeSorterWrite()
96482 ** function flushes the contents of memory to disk, it immediately always
96483 ** creates a new list consisting of a single key immediately afterwards.
96484 ** So the list is never empty at this point. */
96485 assert( pSorter->list.pList );
96486 rc = vdbeSorterFlushPMA(pSorter);
96487
96488 /* Join all threads */
96489 rc = vdbeSorterJoinAll(pSorter, rc);
96490
96491 vdbeSorterRewindDebug("rewind");
96492
96493 /* Assuming no errors have occurred, set up a merger structure to
96494 ** incrementally read and merge all remaining PMAs. */
96495 assert( pSorter->pReader==0 );
96496 if( rc==SQLITE_OK ){
96497 rc = vdbeSorterSetupMerge(pSorter);
static int vdbeSorterSort(SortSubtask *pTask, SorterList *pList)
Definition sqlite3.c:95275
static int vdbeSorterSetupMerge(VdbeSorter *pSorter)
Definition sqlite3.c:96372
#define vdbeSorterRewindDebug(y)
Definition sqlite3.c:94977
static int vdbeSorterFlushPMA(VdbeSorter *pSorter)
Definition sqlite3.c:95570

References VdbeSorter::aTask, VdbeSorter::bUsePMA, CURTYPE_SORTER, VdbeCursor::eCurType, VdbeSorter::list, SorterList::pList, VdbeSorter::pReader, VdbeCursor::pSorter, SQLITE_OK, VdbeCursor::uc, vdbeSorterFlushPMA(), vdbeSorterJoinAll(), vdbeSorterRewindDebug, vdbeSorterSetupMerge(), and vdbeSorterSort().

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSorterRowkey()

SQLITE_PRIVATE int sqlite3VdbeSorterRowkey ( const VdbeCursor * pCsr,
Mem * pOut )

Definition at line 96571 of file sqlite3.c.

96577 {
96578 VdbeSorter *pSorter;
96579 void *pKey; int nKey; /* Sorter key to copy into pOut */
96580
96581 assert( pCsr->eCurType==CURTYPE_SORTER );
96582 pSorter = pCsr->uc.pSorter;
96583 pKey = vdbeSorterRowkey(pSorter, &nKey);
96584 if( sqlite3VdbeMemClearAndResize(pOut, nKey) ){
96585 return SQLITE_NOMEM_BKPT;
96586 }

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSorterWrite()

SQLITE_PRIVATE int sqlite3VdbeSorterWrite ( const VdbeCursor * pCsr,
Mem * pVal )

Definition at line 95640 of file sqlite3.c.

95649 {
95650 VdbeSorter *pSorter;
95651 int rc = SQLITE_OK; /* Return Code */
95652 SorterRecord *pNew; /* New list element */
95653 int bFlush; /* True to flush contents of memory to PMA */
95654 int nReq; /* Bytes of memory required */
95655 int nPMA; /* Bytes of PMA space required */
95656 int t; /* serial type of first record field */
95657
95658 assert( pCsr->eCurType==CURTYPE_SORTER );
95659 pSorter = pCsr->uc.pSorter;
95660 getVarint32NR((const u8*)&pVal->z[1], t);
95661 if( t>0 && t<10 && t!=7 ){
95662 pSorter->typeMask &= SORTER_TYPE_INTEGER;
95663 }else if( t>10 && (t & 0x01) ){
95664 pSorter->typeMask &= SORTER_TYPE_TEXT;
95665 }else{
95666 pSorter->typeMask = 0;
95667 }
95668
95669 assert( pSorter );
95670
95671 /* Figure out whether or not the current contents of memory should be
95672 ** flushed to a PMA before continuing. If so, do so.
95673 **
95674 ** If using the single large allocation mode (pSorter->aMemory!=0), then
95675 ** flush the contents of memory to a new PMA if (a) at least one value is
95676 ** already in memory and (b) the new value will not fit in memory.
95677 **
95678 ** Or, if using separate allocations for each record, flush the contents
95679 ** of memory to a PMA if either of the following are true:
95680 **
95681 ** * The total memory allocated for the in-memory list is greater
95682 ** than (page-size * cache-size), or
95683 **
95684 ** * The total memory allocated for the in-memory list is greater
95685 ** than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
95686 */
95687 nReq = pVal->n + sizeof(SorterRecord);
95688 nPMA = pVal->n + sqlite3VarintLen(pVal->n);
95689 if( pSorter->mxPmaSize ){
95690 if( pSorter->list.aMemory ){
95691 bFlush = pSorter->iMemory && (pSorter->iMemory+nReq) > pSorter->mxPmaSize;
95692 }else{
95693 bFlush = (
95694 (pSorter->list.szPMA > pSorter->mxPmaSize)
95695 || (pSorter->list.szPMA > pSorter->mnPmaSize && sqlite3HeapNearlyFull())
95696 );
95697 }
95698 if( bFlush ){
95699 rc = vdbeSorterFlushPMA(pSorter);
95700 pSorter->list.szPMA = 0;
95701 pSorter->iMemory = 0;
95702 assert( rc!=SQLITE_OK || pSorter->list.pList==0 );
95703 }
95704 }
95705
95706 pSorter->list.szPMA += nPMA;
95707 if( nPMA>pSorter->mxKeysize ){
95708 pSorter->mxKeysize = nPMA;
95709 }
95710
95711 if( pSorter->list.aMemory ){
95712 int nMin = pSorter->iMemory + nReq;
95713
95714 if( nMin>pSorter->nMemory ){
95715 u8 *aNew;
95716 sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory;
95717 int iListOff = -1;
95718 if( pSorter->list.pList ){
95719 iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
95720 }
95721 while( nNew < nMin ) nNew = nNew*2;
95722 if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
95723 if( nNew < nMin ) nNew = nMin;
95724 aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
95725 if( !aNew ) return SQLITE_NOMEM_BKPT;
95726 if( iListOff>=0 ){
95727 pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
95728 }
95729 pSorter->list.aMemory = aNew;
95730 pSorter->nMemory = nNew;
95731 }
95732
95733 pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
95734 pSorter->iMemory += ROUND8(nReq);
95735 if( pSorter->list.pList ){
95736 pNew->u.iNext = (int)((u8*)(pSorter->list.pList) - pSorter->list.aMemory);
95737 }
95738 }else{
95739 pNew = (SorterRecord *)sqlite3Malloc(nReq);
95740 if( pNew==0 ){
95741 return SQLITE_NOMEM_BKPT;
95742 }
95743 pNew->u.pNext = pSorter->list.pList;
95744 }
95745
SQLITE_PRIVATE int sqlite3HeapNearlyFull(void)
Definition sqlite3.c:27493
struct SorterRecord SorterRecord
Definition sqlite3.c:94041
#define SORTER_TYPE_TEXT
Definition sqlite3.c:94217
#define SORTER_TYPE_INTEGER
Definition sqlite3.c:94216
int mxKeysize
Definition sqlite3.c:94198

Referenced by sqlite3VdbeExec().

◆ sqlite3VdbeSwap()

SQLITE_PRIVATE void sqlite3VdbeSwap ( Vdbe * pA,
Vdbe * pB )

Definition at line 77852 of file sqlite3.c.

77858 {
77859 Vdbe tmp, *pTmp;
77860 char *zTmp;
77861 assert( pA->db==pB->db );
77862 tmp = *pA;
77863 *pA = *pB;
77864 *pB = tmp;
77865 pTmp = pA->pNext;
77866 pA->pNext = pB->pNext;
77867 pB->pNext = pTmp;
77868 pTmp = pA->pPrev;
77869 pA->pPrev = pB->pPrev;
77870 pB->pPrev = pTmp;
77871 zTmp = pA->zSql;
77872 pA->zSql = pB->zSql;
77873 pB->zSql = zTmp;
77874#ifdef SQLITE_ENABLE_NORMALIZE
77875 zTmp = pA->zNormSql;
77876 pA->zNormSql = pB->zNormSql;
77877 pB->zNormSql = zTmp;

Referenced by sqlite3Reprepare().

◆ sqlite3VdbeTakeOpArray()

SQLITE_PRIVATE VdbeOp * sqlite3VdbeTakeOpArray ( Vdbe * p,
int * pnOp,
int * pnMaxArg )

Definition at line 78680 of file sqlite3.c.

78686 {
78687 VdbeOp *aOp = p->aOp;
78688 assert( aOp && !p->db->mallocFailed );
78689
78690 /* Check that sqlite3VdbeUsesBtree() was not called on this VM */
78691 assert( DbMaskAllZero(p->btreeMask) );

References Vdbe::aOp, Vdbe::btreeMask, Vdbe::db, DbMaskAllZero, sqlite3::mallocFailed, Vdbe::nOp, and resolveP2Values().

◆ sqlite3VdbeTransferError()

SQLITE_PRIVATE int sqlite3VdbeTransferError ( Vdbe * p)

◆ sqlite3VdbeUsesBtree()

SQLITE_PRIVATE void sqlite3VdbeUsesBtree ( Vdbe * p,
int i )

Definition at line 79490 of file sqlite3.c.

79496 {
79497 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
unsigned int yDbMask
Definition sqlite3.c:18655

References sqlite3::aDb, Vdbe::btreeMask, Vdbe::db, DbMaskSet, Vdbe::lockMask, sqlite3::nDb, Db::pBt, and sqlite3BtreeSharable().

Referenced by sqlite3AlterFinishAddColumn(), sqlite3FinishCoding(), sqlite3Pragma(), sqlite3StartTable(), and sqlite3Vacuum().

◆ sqlite3VectorErrorMsg()

SQLITE_PRIVATE void sqlite3VectorErrorMsg ( Parse * pParse,
Expr * pExpr )

Definition at line 102503 of file sqlite3.c.

102505 :
102506**
102507** "row value misused"
102508*/
102509SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
102510#ifndef SQLITE_OMIT_SUBQUERY
102511 if( pExpr->flags & EP_xIsSelect ){
102512 sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *, Expr *)
Definition sqlite3.c:102503

References EP_xIsSelect, Expr::flags, ExprList::nExpr, Select::pEList, Expr::pSelect, sqlite3ErrorMsg(), sqlite3SubselectError(), and Expr::x.

Referenced by sqlite3ExprCheckIN(), and substExpr().

◆ sqlite3VectorFieldSubexpr()

SQLITE_PRIVATE Expr * sqlite3VectorFieldSubexpr ( Expr * pVector,
int i )

Definition at line 100153 of file sqlite3.c.

100159 {
100160 assert( i<sqlite3ExprVectorSize(pVector) );
100161 if( sqlite3ExprIsVector(pVector) ){
100162 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
100163 if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
100164 return pVector->x.pSelect->pEList->a[i].pExpr;

References ExprList::a, Expr::op, Expr::op2, Select::pEList, ExprList::ExprList_item::pExpr, Expr::pList, Expr::pSelect, sqlite3ExprIsVector(), sqlite3ExprVectorSize(), TK_REGISTER, TK_SELECT, and Expr::x.

Referenced by exprINAffinity(), exprVectorRegister(), sqlite3CodeRhsOfIN(), sqlite3ExprCodeIN(), sqlite3FindInIndex(), and updateRangeAffinityStr().

◆ sqlite3ViewGetColumnNames()

SQLITE_PRIVATE int sqlite3ViewGetColumnNames ( Parse * pParse,
Table * pTable )

Definition at line 113032 of file sqlite3.c.

113038 {
113039 Table *pSelTab; /* A fake table from which we get the result set */
113040 Select *pSel; /* Copy of the SELECT that implements the view */
113041 int nErr = 0; /* Number of errors encountered */
113042 int n; /* Temporarily holds the number of cursors assigned */
113043 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
113044#ifndef SQLITE_OMIT_VIRTUALTABLE
113045 int rc;
113046#endif
113047#ifndef SQLITE_OMIT_AUTHORIZATION
113048 sqlite3_xauth xAuth; /* Saved xAuth pointer */
113049#endif
113050
113051 assert( pTable );
113052
113053#ifndef SQLITE_OMIT_VIRTUALTABLE
113054 db->nSchemaLock++;
113055 rc = sqlite3VtabCallConnect(pParse, pTable);
113056 db->nSchemaLock--;
113057 if( rc ){
113058 return 1;
113059 }
113060 if( IsVirtual(pTable) ) return 0;
113061#endif
113062
113063#ifndef SQLITE_OMIT_VIEW
113064 /* A positive nCol means the columns names for this view are
113065 ** already known.
113066 */
113067 if( pTable->nCol>0 ) return 0;
113068
113069 /* A negative nCol is a special marker meaning that we are currently
113070 ** trying to compute the column names. If we enter this routine with
113071 ** a negative nCol, it means two or more views form a loop, like this:
113072 **
113073 ** CREATE VIEW one AS SELECT * FROM two;
113074 ** CREATE VIEW two AS SELECT * FROM one;
113075 **
113076 ** Actually, the error above is now caught prior to reaching this point.
113077 ** But the following test is still important as it does come up
113078 ** in the following:
113079 **
113080 ** CREATE TABLE main.ex1(a);
113081 ** CREATE TEMP VIEW ex1 AS SELECT a FROM ex1;
113082 ** SELECT * FROM temp.ex1;
113083 */
113084 if( pTable->nCol<0 ){
113085 sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName);
113086 return 1;
113087 }
113088 assert( pTable->nCol>=0 );
113089
113090 /* If we get this far, it means we need to compute the table names.
113091 ** Note that the call to sqlite3ResultSetOfSelect() will expand any
113092 ** "*" elements in the results set of the view and will assign cursors
113093 ** to the elements of the FROM clause. But we do not want these changes
113094 ** to be permanent. So the computation is done on a copy of the SELECT
113095 ** statement that defines the view.
113096 */
113097 assert( pTable->pSelect );
113098 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
113099 if( pSel ){
113100 u8 eParseMode = pParse->eParseMode;
113101 pParse->eParseMode = PARSE_MODE_NORMAL;
113102 n = pParse->nTab;
113103 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
113104 pTable->nCol = -1;
113106#ifndef SQLITE_OMIT_AUTHORIZATION
113107 xAuth = db->xAuth;
113108 db->xAuth = 0;
113109 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
113110 db->xAuth = xAuth;
113111#else
113112 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
113113#endif
113114 pParse->nTab = n;
113115 if( pSelTab==0 ){
113116 pTable->nCol = 0;
113117 nErr++;
113118 }else if( pTable->pCheck ){
113119 /* CREATE VIEW name(arglist) AS ...
113120 ** The names of the columns in the table are taken from
113121 ** arglist which is stored in pTable->pCheck. The pCheck field
113122 ** normally holds CHECK constraints on an ordinary table, but for
113123 ** a VIEW it holds the list of column names.
113124 */
113125 sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
113126 &pTable->nCol, &pTable->aCol);
113127 if( db->mallocFailed==0
113128 && pParse->nErr==0
113129 && pTable->nCol==pSel->pEList->nExpr
113130 ){
113131 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
113133 }
113134 }else{
113135 /* CREATE VIEW name AS... without an argument list. Construct
113136 ** the column names from the SELECT statement that defines the view.
113137 */
113138 assert( pTable->aCol==0 );
113139 pTable->nCol = pSelTab->nCol;
113140 pTable->aCol = pSelTab->aCol;
113141 pSelTab->nCol = 0;
113142 pSelTab->aCol = 0;
113143 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
113144 }
113145 pTable->nNVCol = pTable->nCol;
113146 sqlite3DeleteTable(db, pSelTab);
113147 sqlite3SelectDelete(db, pSel);
113149 pParse->eParseMode = eParseMode;
113150 } else {
113151 nErr++;
113152 }
113153 pTable->pSchema->schemaFlags |= DB_UnresetViews;
113154 if( db->mallocFailed ){
113155 sqlite3DeleteColumnNames(db, pTable);
#define DB_UnresetViews
Definition sqlite3.c:16664
SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *, Table *)
Definition sqlite3.c:140253
u16 schemaFlags
Definition sqlite3.c:16640

References Table::aCol, Parse::db, DB_UnresetViews, DisableLookaside, EnableLookaside, Parse::eParseMode, IsVirtual, sqlite3::mallocFailed, Table::nCol, Parse::nErr, ExprList::nExpr, Table::nNVCol, sqlite3::nSchemaLock, Parse::nTab, PARSE_MODE_NORMAL, Table::pCheck, Select::pEList, Table::pSchema, Table::pSelect, Select::pSrc, Schema::schemaFlags, sqlite3ColumnsFromExprList(), sqlite3DeleteColumnNames(), sqlite3DeleteTable(), sqlite3ErrorMsg(), sqlite3ResultSetOfSelect(), sqlite3SelectAddColumnTypeAndCollation(), sqlite3SelectDelete(), sqlite3SelectDup(), sqlite3SrcListAssignCursors(), sqlite3VtabCallConnect(), SQLITE_AFF_NONE, sqlite3::xAuth, and Table::zName.

Referenced by renameResolveTrigger(), selectExpander(), sqlite3DeleteFrom(), sqlite3Insert(), sqlite3Pragma(), and sqlite3Update().

◆ sqlite3VListAdd()

SQLITE_PRIVATE VList * sqlite3VListAdd ( sqlite3 * db,
VList * pIn,
const char * zName,
int nName,
int iVal )

Definition at line 32809 of file sqlite3.c.

32821 {
32822 int nInt; /* number of sizeof(int) objects needed for zName */
32823 char *z; /* Pointer to where zName will be stored */
32824 int i; /* Index in pIn[] where zName is stored */
32825
32826 nInt = nName/4 + 3;
32827 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
32828 if( pIn==0 || pIn[1]+nInt > pIn[0] ){
32829 /* Enlarge the allocation */
32830 sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt;
32831 VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
32832 if( pOut==0 ) return pIn;
32833 if( pIn==0 ) pOut[1] = 2;
32834 pIn = pOut;
32835 pIn[0] = nAlloc;
32836 }
32837 i = pIn[1];
32838 pIn[i] = iVal;
32839 pIn[i+1] = nInt;
32840 z = (char*)&pIn[i+2];
int VList
Definition sqlite3.c:14742

References nName, sqlite3DbRealloc(), and zName.

Referenced by sqlite3ExprAssignVarNumber().

◆ sqlite3VListNameToNum()

SQLITE_PRIVATE int sqlite3VListNameToNum ( VList * pIn,
const char * zName,
int nName )

Definition at line 32863 of file sqlite3.c.

32869 {
32870 int i, mx;
32871 if( pIn==0 ) return 0;
32872 mx = pIn[1];
32873 i = 2;
32874 do{

Referenced by sqlite3_bind_parameter_index(), and sqlite3ExprAssignVarNumber().

◆ sqlite3VListNumToName()

SQLITE_PRIVATE const char * sqlite3VListNumToName ( VList * pIn,
int iVal )

Definition at line 32847 of file sqlite3.c.

32853 {
32854 int i, mx;
32855 if( pIn==0 ) return 0;
32856 mx = pIn[1];
32857 i = 2;

Referenced by sqlite3_bind_parameter_name(), sqlite3ExprAssignVarNumber(), sqlite3ExprCodeTarget(), and sqlite3VdbeExec().

◆ sqlite3VMPrintf()

SQLITE_PRIVATE char * sqlite3VMPrintf ( sqlite3 * db,
const char * zFormat,
va_list ap )

Definition at line 29266 of file sqlite3.c.

29272 {
29273 char *z;
29274 char zBase[SQLITE_PRINT_BUF_SIZE];
29275 StrAccum acc;
29276 assert( db!=0 );
29277 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
29280 sqlite3_str_vappendf(&acc, zFormat, ap);
SQLITE_API void sqlite3_str_vappendf(sqlite3_str *, const char *zFormat, va_list)
Definition sqlite3.c:28341

Referenced by sqlite3ErrorMsg(), sqlite3ErrorWithMsg(), sqlite3NestedParse(), and sqlite3VdbeExplain().

◆ sqlite3VtabArgExtend()

SQLITE_PRIVATE void sqlite3VtabArgExtend ( Parse * pParse,
Token * p )

Definition at line 140105 of file sqlite3.c.

140111 {
140112 Token *pArg = &pParse->sArg;
140113 if( pArg->z==0 ){
140114 pArg->z = p->z;

Referenced by yy_reduce().

◆ sqlite3VtabArgInit()

SQLITE_PRIVATE void sqlite3VtabArgInit ( Parse * pParse)

Definition at line 140095 of file sqlite3.c.

Referenced by yy_reduce().

◆ sqlite3VtabBegin()

SQLITE_PRIVATE int sqlite3VtabBegin ( sqlite3 * db,
VTable * pVTab )

Definition at line 140564 of file sqlite3.c.

140570 {
140571 int rc = SQLITE_OK;
140572 const sqlite3_module *pModule;
140573
140574 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
140575 ** than zero, then this function is being called from within a
140576 ** virtual module xSync() callback. It is illegal to write to
140577 ** virtual module tables in this case, so return SQLITE_LOCKED.
140578 */
140579 if( sqlite3VtabInSync(db) ){
140580 return SQLITE_LOCKED;
140581 }
140582 if( !pVTab ){
140583 return SQLITE_OK;
140584 }
140585 pModule = pVTab->pVtab->pModule;
140586
140587 if( pModule->xBegin ){
140588 int i;
140589
140590 /* If pVtab is already in the aVTrans array, return early */
140591 for(i=0; i<db->nVTrans; i++){
140592 if( db->aVTrans[i]==pVTab ){
140593 return SQLITE_OK;
140594 }
140595 }
140596
140597 /* Invoke the xBegin method. If successful, add the vtab to the
140598 ** sqlite3.aVTrans[] array. */
140599 rc = growVTrans(db);
140600 if( rc==SQLITE_OK ){
140601 rc = pModule->xBegin(pVTab->pVtab);
140602 if( rc==SQLITE_OK ){
140603 int iSvpt = db->nStatement + db->nSavepoint;
140604 addToVTrans(db, pVTab);
140605 if( iSvpt && pModule->xSavepoint ){
140606 pVTab->iSavepoint = iSvpt;
140607 rc = pModule->xSavepoint(pVTab->pVtab, iSvpt-1);
static void addToVTrans(sqlite3 *db, VTable *pVTab)
Definition sqlite3.c:140311
static int growVTrans(sqlite3 *db)
Definition sqlite3.c:140288
int(* xBegin)(sqlite3_vtab *pVTab)
Definition sqlite3.c:7778
int(* xSavepoint)(sqlite3_vtab *pVTab, int)
Definition sqlite3.c:7788

References addToVTrans(), sqlite3::aVTrans, growVTrans(), VTable::iSavepoint, sqlite3::nSavepoint, sqlite3::nStatement, sqlite3::nVTrans, sqlite3_vtab::pModule, VTable::pVtab, sqlite3VtabInSync, SQLITE_LOCKED, SQLITE_OK, sqlite3_module::xBegin, and sqlite3_module::xSavepoint.

Referenced by sqlite3VdbeExec().

◆ sqlite3VtabBeginParse()

SQLITE_PRIVATE void sqlite3VtabBeginParse ( Parse * pParse,
Token * pName1,
Token * pName2,
Token * pModuleName,
int ifNotExists )

Definition at line 139948 of file sqlite3.c.

139960 {
139961 Table *pTable; /* The new virtual table */
139962 sqlite3 *db; /* Database connection */
139963
139964 sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
139965 pTable = pParse->pNewTable;
139966 if( pTable==0 ) return;
139967 assert( 0==pTable->pIndex );
139968
139969 db = pParse->db;
139970
139971 assert( pTable->nModuleArg==0 );
139972 addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
139973 addModuleArgument(pParse, pTable, 0);
139974 addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
139975 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
139976 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
139977 );
139978 pParse->sNameToken.n = (int)(
139979 &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
139980 );
139981
139982#ifndef SQLITE_OMIT_AUTHORIZATION
139983 /* Creating a virtual table invokes the authorization callback twice.
139984 ** The first invocation, to obtain permission to INSERT a row into the
139985 ** sqlite_schema table, has already been made by sqlite3StartTable().
139986 ** The second call, to obtain permission to create the table, is made now.
139987 */
139988 if( pTable->azModuleArg ){
139989 int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg)
Definition sqlite3.c:139925

References sqlite3::aDb, addModuleArgument(), Table::azModuleArg, Parse::db, Token::n, Table::nModuleArg, Table::pIndex, Parse::pNewTable, Table::pSchema, Parse::sNameToken, sqlite3AuthCheck(), sqlite3DbStrDup(), sqlite3NameFromToken(), sqlite3SchemaToIndex(), sqlite3StartTable(), SQLITE_CREATE_VTABLE, Token::z, Db::zDbSName, and Table::zName.

Referenced by yy_reduce().

◆ sqlite3VtabCallConnect()

SQLITE_PRIVATE int sqlite3VtabCallConnect ( Parse * pParse,
Table * pTab )

Definition at line 140253 of file sqlite3.c.

140259 {
140260 sqlite3 *db = pParse->db;
140261 const char *zMod;
140262 Module *pMod;
140263 int rc;
140264
140265 assert( pTab );
140266 if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
140267 return SQLITE_OK;
140268 }
140269
140270 /* Locate the required virtual table module */
140271 zMod = pTab->azModuleArg[0];
140272 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
140273
140274 if( !pMod ){
140275 const char *zModule = pTab->azModuleArg[0];
140276 sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
140277 rc = SQLITE_ERROR;
140278 }else{
140279 char *zErr = 0;
140280 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
140281 if( rc!=SQLITE_OK ){
140282 sqlite3ErrorMsg(pParse, "%s", zErr);
140283 pParse->rc = rc;
static int vtabCallConstructor(sqlite3 *db, Table *pTab, Module *pMod, int(*xConstruct)(sqlite3 *, void *, int, const char *const *, sqlite3_vtab **, char **), char **pzErr)
Definition sqlite3.c:140121
int(* xConnect)(sqlite3 *, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVTab, char **)
Definition sqlite3.c:7763

References sqlite3::aModule, Table::azModuleArg, Parse::db, IsVirtual, Module::pModule, Parse::rc, sqlite3DbFree(), sqlite3ErrorMsg(), sqlite3GetVTable(), sqlite3HashFind(), SQLITE_ERROR, SQLITE_OK, vtabCallConstructor(), and sqlite3_module::xConnect.

Referenced by sqlite3ViewGetColumnNames().

◆ sqlite3VtabCallCreate()

SQLITE_PRIVATE int sqlite3VtabCallCreate ( sqlite3 * db,
int iDb,
const char * zTab,
char ** pzErr )

Definition at line 140325 of file sqlite3.c.

140331 {
140332 int rc = SQLITE_OK;
140333 Table *pTab;
140334 Module *pMod;
140335 const char *zMod;
140336
140337 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
140338 assert( pTab && IsVirtual(pTab) && !pTab->pVTable );
140339
140340 /* Locate the required virtual table module */
140341 zMod = pTab->azModuleArg[0];
140342 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
140343
140344 /* If the module has been registered and includes a Create method,
140345 ** invoke it now. If the module has not been registered, return an
140346 ** error. Otherwise, do nothing.
140347 */
140348 if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
140349 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
140350 rc = SQLITE_ERROR;
140351 }else{
140352 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
140353 }
140354
140355 /* Justification of ALWAYS(): The xConstructor method is required to
140356 ** create a valid sqlite3_vtab if it returns SQLITE_OK. */
140357 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
140358 rc = growVTrans(db);
140359 if( rc==SQLITE_OK ){
int(* xDestroy)(sqlite3_vtab *pVTab)
Definition sqlite3.c:7768
int(* xCreate)(sqlite3 *, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVTab, char **)
Definition sqlite3.c:7760

References sqlite3::aDb, addToVTrans(), ALWAYS, sqlite3::aModule, Table::azModuleArg, growVTrans(), IsVirtual, Module::pModule, Table::pVTable, sqlite3FindTable(), sqlite3GetVTable(), sqlite3HashFind(), sqlite3MPrintf(), SQLITE_ERROR, SQLITE_OK, vtabCallConstructor(), sqlite3_module::xCreate, sqlite3_module::xDestroy, and Db::zDbSName.

Referenced by sqlite3VdbeExec().

◆ sqlite3VtabCallDestroy()

SQLITE_PRIVATE int sqlite3VtabCallDestroy ( sqlite3 * db,
int iDb,
const char * zTab )

Definition at line 140451 of file sqlite3.c.

140457 {
140458 int rc = SQLITE_OK;
140459 Table *pTab;
140460
140461 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
140462 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
140463 VTable *p;
140464 int (*xDestroy)(sqlite3_vtab *);
140465 for(p=pTab->pVTable; p; p=p->pNext){
140466 assert( p->pVtab );
140467 if( p->pVtab->nRef>0 ){
140468 return SQLITE_LOCKED;
140469 }
140470 }
140471 p = vtabDisconnectAll(db, pTab);
140472 xDestroy = p->pMod->pModule->xDestroy;
140473 if( xDestroy==0 ) xDestroy = p->pMod->pModule->xDisconnect;
140474 assert( xDestroy!=0 );
140475 pTab->nTabRef++;
140476 rc = xDestroy(p->pVtab);
140477 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
140478 if( rc==SQLITE_OK ){
140479 assert( pTab->pVTable==p && p->pNext==0 );
140480 p->pVtab = 0;
140481 pTab->pVTable = 0;
static VTable * vtabDisconnectAll(sqlite3 *db, Table *p)
Definition sqlite3.c:139799
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *)
Definition sqlite3.c:139774
VTable * pNext
Definition sqlite3.c:17474
int(* xDisconnect)(sqlite3_vtab *pVTab)
Definition sqlite3.c:7767

References sqlite3::aDb, ALWAYS, sqlite3_vtab::nRef, Table::nTabRef, VTable::pMod, Module::pModule, VTable::pNext, VTable::pVtab, Table::pVTable, sqlite3DeleteTable(), sqlite3FindTable(), sqlite3VtabUnlock(), SQLITE_LOCKED, SQLITE_OK, vtabDisconnectAll(), sqlite3_module::xDestroy, sqlite3_module::xDisconnect, and Db::zDbSName.

Referenced by sqlite3VdbeExec().

◆ sqlite3VtabClear()

SQLITE_PRIVATE void sqlite3VtabClear ( sqlite3 * db,
Table * p )

Definition at line 139908 of file sqlite3.c.

139914 {
139915 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
139916 if( p->azModuleArg ){
139917 int i;

References Table::azModuleArg, Table::nModuleArg, sqlite3::pnBytesFreed, sqlite3DbFree(), and vtabDisconnectAll().

Referenced by deleteTable().

◆ sqlite3VtabCommit()

SQLITE_PRIVATE int sqlite3VtabCommit ( sqlite3 * db)

Definition at line 140551 of file sqlite3.c.

Referenced by vdbeCommit().

◆ sqlite3VtabCreateModule()

SQLITE_PRIVATE Module * sqlite3VtabCreateModule ( sqlite3 * db,
const char * zName,
const sqlite3_module * pModule,
void * pAux,
void(*)(void *) xDestroy )

Definition at line 139610 of file sqlite3.c.

139622 {
139623 Module *pMod;
139624 Module *pDel;
139625 char *zCopy;
139626 if( pModule==0 ){
139627 zCopy = (char*)zName;
139628 pMod = 0;
139629 }else{
139630 int nName = sqlite3Strlen30(zName);
139631 pMod = (Module *)sqlite3Malloc(sizeof(Module) + nName + 1);
139632 if( pMod==0 ){
139633 sqlite3OomFault(db);
139634 return 0;
139635 }
139636 zCopy = (char *)(&pMod[1]);
139637 memcpy(zCopy, zName, nName+1);
139638 pMod->zName = zCopy;
139639 pMod->pModule = pModule;
139640 pMod->pAux = pAux;
139641 pMod->xDestroy = xDestroy;
139642 pMod->pEpoTab = 0;
139643 pMod->nRefModule = 1;
139644 }
139645 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
139646 if( pDel ){
139647 if( pDel==pMod ){
139648 sqlite3OomFault(db);
139649 sqlite3DbFree(db, pDel);
139650 pMod = 0;
139651 }else{
void(* xDestroy)(void *)
Definition sqlite3.c:17310
int nRefModule
Definition sqlite3.c:17308
void * pAux
Definition sqlite3.c:17309

References sqlite3::aModule, nName, Module::nRefModule, Module::pAux, Module::pEpoTab, Module::pModule, sqlite3DbFree(), sqlite3HashInsert(), sqlite3Malloc(), sqlite3OomFault(), sqlite3Strlen30(), sqlite3VtabEponymousTableClear(), sqlite3VtabModuleUnref(), Module::xDestroy, Module::zName, and zName.

Referenced by createModule(), and sqlite3PragmaVtabRegister().

◆ sqlite3VtabDisconnect()

SQLITE_PRIVATE void sqlite3VtabDisconnect ( sqlite3 * db,
Table * p )

Definition at line 139839 of file sqlite3.c.

139845 {
139846 VTable **ppVTab;
139847
139848 assert( IsVirtual(p) );
139849 assert( sqlite3BtreeHoldsAllMutexes(db) );
139850 assert( sqlite3_mutex_held(db->mutex) );
139851
139852 for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){
139853 if( (*ppVTab)->db==db ){
139854 VTable *pVTab = *ppVTab;

References IsVirtual, sqlite3::mutex, VTable::pNext, Table::pVTable, sqlite3_mutex_held(), and sqlite3VtabUnlock().

◆ sqlite3VtabEponymousTableClear()

SQLITE_PRIVATE void sqlite3VtabEponymousTableClear ( sqlite3 * db,
Module * pMod )

Definition at line 140811 of file sqlite3.c.

140817 {
140818 Table *pTab = pMod->pEpoTab;
140819 if( pTab!=0 ){
140820 /* Mark the table as Ephemeral prior to deleting it, so that the
140821 ** sqlite3DeleteTable() routine will know that it is not stored in

Referenced by sqlite3LeaveMutexAndCloseZombie(), sqlite3VtabCreateModule(), and sqlite3VtabEponymousTableInit().

◆ sqlite3VtabEponymousTableInit()

SQLITE_PRIVATE int sqlite3VtabEponymousTableInit ( Parse * pParse,
Module * pMod )

Definition at line 140774 of file sqlite3.c.

140780 {
140781 const sqlite3_module *pModule = pMod->pModule;
140782 Table *pTab;
140783 char *zErr = 0;
140784 int rc;
140785 sqlite3 *db = pParse->db;
140786 if( pMod->pEpoTab ) return 1;
140787 if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
140788 pTab = sqlite3DbMallocZero(db, sizeof(Table));
140789 if( pTab==0 ) return 0;
140790 pTab->zName = sqlite3DbStrDup(db, pMod->zName);
140791 if( pTab->zName==0 ){
140792 sqlite3DbFree(db, pTab);
140793 return 0;
140794 }
140795 pMod->pEpoTab = pTab;
140796 pTab->nTabRef = 1;
140797 pTab->pSchema = db->aDb[0].pSchema;
140798 assert( pTab->nModuleArg==0 );
140799 pTab->iPKey = -1;
140800 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
140801 addModuleArgument(pParse, pTab, 0);
140802 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
140803 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
140804 if( rc ){
140805 sqlite3ErrorMsg(pParse, "%s", zErr);

References sqlite3::aDb, addModuleArgument(), Parse::db, Table::iPKey, Table::nModuleArg, Table::nTabRef, Module::pEpoTab, Module::pModule, Db::pSchema, Table::pSchema, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ErrorMsg(), sqlite3VtabEponymousTableClear(), vtabCallConstructor(), sqlite3_module::xConnect, sqlite3_module::xCreate, Module::zName, and Table::zName.

Referenced by sqlite3LocateTable().

◆ sqlite3VtabFinishParse()

SQLITE_PRIVATE void sqlite3VtabFinishParse ( Parse * pParse,
Token * pEnd )

Definition at line 140009 of file sqlite3.c.

140015 {
140016 Table *pTab = pParse->pNewTable; /* The table being constructed */
140017 sqlite3 *db = pParse->db; /* The database connection */
140018
140019 if( pTab==0 ) return;
140020 addArgumentToVtab(pParse);
140021 pParse->sArg.z = 0;
140022 if( pTab->nModuleArg<1 ) return;
140023
140024 /* If the CREATE VIRTUAL TABLE statement is being entered for the
140025 ** first time (in other words if the virtual table is actually being
140026 ** created now instead of just being read out of sqlite_schema) then
140027 ** do additional initialization work and store the statement text
140028 ** in the sqlite_schema table.
140029 */
140030 if( !db->init.busy ){
140031 char *zStmt;
140032 char *zWhere;
140033 int iDb;
140034 int iReg;
140035 Vdbe *v;
140036
140037 sqlite3MayAbort(pParse);
140038
140039 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
140040 if( pEnd ){
140041 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
140042 }
140043 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
140044
140045 /* A slot for the record has already been allocated in the
140046 ** schema table. We just need to update that slot with all
140047 ** the information we've collected.
140048 **
140049 ** The VM register number pParse->regRowid holds the rowid of an
140050 ** entry in the sqlite_schema table tht was created for this vtab
140051 ** by sqlite3StartTable().
140052 */
140053 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
140054 sqlite3NestedParse(pParse,
140055 "UPDATE %Q." DFLT_SCHEMA_TABLE " "
140056 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
140057 "WHERE rowid=#%d",
140058 db->aDb[iDb].zDbSName,
140059 pTab->zName,
140060 pTab->zName,
140061 zStmt,
140062 pParse->regRowid
140063 );
140064 v = sqlite3GetVdbe(pParse);
140065 sqlite3ChangeCookie(pParse, iDb);
140066
140068 zWhere = sqlite3MPrintf(db, "name=%Q AND sql=%Q", pTab->zName, zStmt);
140069 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
140070 sqlite3DbFree(db, zStmt);
140071
140072 iReg = ++pParse->nMem;
140073 sqlite3VdbeLoadString(v, iReg, pTab->zName);
140074 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
140075 }
140076
140077 /* If we are rereading the sqlite_schema table create the in-memory
140078 ** record of the table. The xConnect() method is not called until
140079 ** the first time the virtual table is used in an SQL statement. This
140080 ** allows a schema that contains virtual tables to be loaded before
140081 ** the required virtual table implementations are registered. */
140082 else {
140083 Table *pOld;
140084 Schema *pSchema = pTab->pSchema;
140085 const char *zName = pTab->zName;
140086 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
140087 pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab);
140088 if( pOld ){
140089 sqlite3OomFault(db);
static void addArgumentToVtab(Parse *pParse)
Definition sqlite3.c:139996

Referenced by yy_reduce().

◆ sqlite3VtabImportErrmsg()

SQLITE_PRIVATE void sqlite3VtabImportErrmsg ( Vdbe * p,
sqlite3_vtab * pVtab )

Definition at line 82880 of file sqlite3.c.

82886 {
82887 if( pVtab->zErrMsg ){
82888 sqlite3 *db = p->db;
char * zErrMsg
Definition sqlite3.c:8047

References Vdbe::db, sqlite3_free(), sqlite3DbFree(), sqlite3DbStrDup(), sqlite3_vtab::zErrMsg, and Vdbe::zErrMsg.

Referenced by sqlite3VdbeExec(), and sqlite3VtabSync().

◆ sqlite3VtabLock()

SQLITE_PRIVATE void sqlite3VtabLock ( VTable * pVTab)

Definition at line 139753 of file sqlite3.c.

References VTable::nRef.

Referenced by sqlite3VtabSavepoint().

◆ sqlite3VtabMakeWritable()

SQLITE_PRIVATE void sqlite3VtabMakeWritable ( Parse * pParse,
Table * pTab )

Definition at line 140741 of file sqlite3.c.

140747 {
140748 Parse *pToplevel = sqlite3ParseToplevel(pParse);
140749 int i, n;
140750 Table **apVtabLock;
140751
140752 assert( IsVirtual(pTab) );
140753 for(i=0; i<pToplevel->nVtabLock; i++){
140754 if( pTab==pToplevel->apVtabLock[i] ) return;
140755 }
140756 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
140757 apVtabLock = sqlite3Realloc(pToplevel->apVtabLock, n);
140758 if( apVtabLock ){

References Parse::apVtabLock, Parse::db, IsVirtual, Parse::nVtabLock, sqlite3OomFault(), sqlite3ParseToplevel, and sqlite3Realloc().

Referenced by sqlite3DeleteFrom(), sqlite3Insert(), and updateVirtualTable().

◆ sqlite3VtabModuleUnref()

SQLITE_PRIVATE void sqlite3VtabModuleUnref ( sqlite3 * db,
Module * pMod )

Definition at line 139733 of file sqlite3.c.

139739 {
139740 assert( pMod->nRefModule>0 );
139741 pMod->nRefModule--;
139742 if( pMod->nRefModule==0 ){
139743 if( pMod->xDestroy ){

Referenced by sqlite3LeaveMutexAndCloseZombie(), and sqlite3VtabCreateModule().

◆ sqlite3VtabOverloadFunction()

SQLITE_PRIVATE FuncDef * sqlite3VtabOverloadFunction ( sqlite3 * db,
FuncDef * pDef,
int nArg,
Expr * pExpr )

Definition at line 140672 of file sqlite3.c.

140683 {
140684 Table *pTab;
140685 sqlite3_vtab *pVtab;
140686 sqlite3_module *pMod;
140687 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**) = 0;
140688 void *pArg = 0;
140689 FuncDef *pNew;
140690 int rc = 0;
140691
140692 /* Check to see the left operand is a column in a virtual table */
140693 if( NEVER(pExpr==0) ) return pDef;
140694 if( pExpr->op!=TK_COLUMN ) return pDef;
140695 pTab = pExpr->y.pTab;
140696 if( pTab==0 ) return pDef;
140697 if( !IsVirtual(pTab) ) return pDef;
140698 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
140699 assert( pVtab!=0 );
140700 assert( pVtab->pModule!=0 );
140701 pMod = (sqlite3_module *)pVtab->pModule;
140702 if( pMod->xFindFunction==0 ) return pDef;
140703
140704 /* Call the xFindFunction method on the virtual table implementation
140705 ** to see if the implementation wants to overload this function.
140706 **
140707 ** Though undocumented, we have historically always invoked xFindFunction
140708 ** with an all lower-case function name. Continue in this tradition to
140709 ** avoid any chance of an incompatibility.
140710 */
140711#ifdef SQLITE_DEBUG
140712 {
140713 int i;
140714 for(i=0; pDef->zName[i]; i++){
140715 unsigned char x = (unsigned char)pDef->zName[i];
140716 assert( x==sqlite3UpperToLower[x] );
140717 }
140718 }
140719#endif
140720 rc = pMod->xFindFunction(pVtab, nArg, pDef->zName, &xSFunc, &pArg);
140721 if( rc==0 ){
140722 return pDef;
140723 }
140724
140725 /* Create a new ephemeral function definition for the overloaded
140726 ** function */
140727 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
140728 + sqlite3Strlen30(pDef->zName) + 1);
140729 if( pNew==0 ){
140730 return pDef;
140731 }
140732 *pNew = *pDef;
140733 pNew->zName = (const char*)&pNew[1];
int(* xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, void(**pxFunc)(sqlite3_context *, int, sqlite3_value **), void **ppArg)
Definition sqlite3.c:7782

References FuncDef::funcFlags, IsVirtual, NEVER, Expr::op, sqlite3_vtab::pModule, Expr::pTab, FuncDef::pUserData, VTable::pVtab, sqlite3DbMallocZero(), sqlite3GetVTable(), sqlite3Strlen30(), sqlite3UpperToLower, SQLITE_FUNC_EPHEM, TK_COLUMN, sqlite3_module::xFindFunction, FuncDef::xSFunc, Expr::y, and FuncDef::zName.

Referenced by sqlite3ExprCodeTarget().

◆ sqlite3VtabRollback()

SQLITE_PRIVATE int sqlite3VtabRollback ( sqlite3 * db)

Definition at line 140542 of file sqlite3.c.

Referenced by sqlite3RollbackAll().

◆ sqlite3VtabSavepoint()

SQLITE_PRIVATE int sqlite3VtabSavepoint ( sqlite3 * db,
int op,
int iSavepoint )

Definition at line 140624 of file sqlite3.c.

140630 {
140631 int rc = SQLITE_OK;
140632
140633 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
140634 assert( iSavepoint>=-1 );
140635 if( db->aVTrans ){
140636 int i;
140637 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
140638 VTable *pVTab = db->aVTrans[i];
140639 const sqlite3_module *pMod = pVTab->pMod->pModule;
140640 if( pVTab->pVtab && pMod->iVersion>=2 ){
140641 int (*xMethod)(sqlite3_vtab *, int);
140642 sqlite3VtabLock(pVTab);
140643 switch( op ){
140644 case SAVEPOINT_BEGIN:
140645 xMethod = pMod->xSavepoint;
140646 pVTab->iSavepoint = iSavepoint+1;
140647 break;
140648 case SAVEPOINT_ROLLBACK:
140649 xMethod = pMod->xRollbackTo;
140650 break;
140651 default:
140652 xMethod = pMod->xRelease;
140653 break;
140654 }
140655 if( xMethod && pVTab->iSavepoint>iSavepoint ){
140656 rc = xMethod(pVTab->pVtab, iSavepoint);
140657 }
SQLITE_PRIVATE void sqlite3VtabLock(VTable *)
Definition sqlite3.c:139753
int(* xRollbackTo)(sqlite3_vtab *pVTab, int)
Definition sqlite3.c:7790
int(* xRelease)(sqlite3_vtab *pVTab, int)
Definition sqlite3.c:7789

References sqlite3::aVTrans, VTable::iSavepoint, sqlite3_module::iVersion, sqlite3::nVTrans, VTable::pMod, Module::pModule, VTable::pVtab, SAVEPOINT_BEGIN, SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, sqlite3VtabLock(), sqlite3VtabUnlock(), SQLITE_OK, sqlite3_module::xRelease, sqlite3_module::xRollbackTo, and sqlite3_module::xSavepoint.

Referenced by sqlite3VdbeExec(), and vdbeCloseStatement().

◆ sqlite3VtabSync()

SQLITE_PRIVATE int sqlite3VtabSync ( sqlite3 * db,
Vdbe * p )

Definition at line 140520 of file sqlite3.c.

140526 {
140527 int i;
140528 int rc = SQLITE_OK;
140529 VTable **aVTrans = db->aVTrans;
140530
140531 db->aVTrans = 0;
140532 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
140533 int (*x)(sqlite3_vtab *);
140534 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
140535 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
140536 rc = x(pVtab);
int(* xSync)(sqlite3_vtab *pVTab)
Definition sqlite3.c:7779

References sqlite3::aVTrans, sqlite3::nVTrans, sqlite3_vtab::pModule, VTable::pVtab, sqlite3VtabImportErrmsg(), SQLITE_OK, and sqlite3_module::xSync.

Referenced by vdbeCommit().

◆ sqlite3VtabUnlock()

SQLITE_PRIVATE void sqlite3VtabUnlock ( VTable * pVTab)

Definition at line 139774 of file sqlite3.c.

139780 {
139781 sqlite3 *db = pVTab->db;
139782
139783 assert( db );
139784 assert( pVTab->nRef>0 );
139785 assert( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ZOMBIE );
139786
139787 pVTab->nRef--;
139788 if( pVTab->nRef==0 ){
139789 sqlite3_vtab *p = pVTab->pVtab;
139790 sqlite3VtabModuleUnref(pVTab->db, pVTab->pMod);
int nRef
Definition sqlite3.c:17470
sqlite3 * db
Definition sqlite3.c:17467

Referenced by callFinaliser(), sqlite3VtabCallDestroy(), sqlite3VtabDisconnect(), sqlite3VtabSavepoint(), sqlite3VtabUnlockList(), and vtabCallConstructor().

◆ sqlite3VtabUnlockList()

SQLITE_PRIVATE void sqlite3VtabUnlockList ( sqlite3 * db)

Definition at line 139877 of file sqlite3.c.

139883 {
139884 VTable *p = db->pDisconnect;
139885
139886 assert( sqlite3BtreeHoldsAllMutexes(db) );
139887 assert( sqlite3_mutex_held(db->mutex) );
139888
139889 if( p ){
139890 db->pDisconnect = 0;
139892 do {
VTable * pDisconnect
Definition sqlite3.c:16921

References sqlite3::mutex, sqlite3::pDisconnect, VTable::pNext, sqlite3_mutex_held(), sqlite3ExpirePreparedStatements(), and sqlite3VtabUnlock().

Referenced by sqlite3LeaveMutexAndCloseZombie().

◆ sqlite3WalBeginReadTransaction()

SQLITE_PRIVATE int sqlite3WalBeginReadTransaction ( Wal * pWal,
int * pChanged )

Definition at line 62303 of file sqlite3.c.

62309 {
62310 int rc; /* Return code */
62311 int cnt = 0; /* Number of TryBeginRead attempts */
62312#ifdef SQLITE_ENABLE_SNAPSHOT
62313 int bChanged = 0;
62314 WalIndexHdr *pSnapshot = pWal->pSnapshot;
62315#endif
62316
62317 assert( pWal->ckptLock==0 );
62318
62319#ifdef SQLITE_ENABLE_SNAPSHOT
62320 if( pSnapshot ){
62321 if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
62322 bChanged = 1;
62323 }
62324
62325 /* It is possible that there is a checkpointer thread running
62326 ** concurrent with this code. If this is the case, it may be that the
62327 ** checkpointer has already determined that it will checkpoint
62328 ** snapshot X, where X is later in the wal file than pSnapshot, but
62329 ** has not yet set the pInfo->nBackfillAttempted variable to indicate
62330 ** its intent. To avoid the race condition this leads to, ensure that
62331 ** there is no checkpointer process by taking a shared CKPT lock
62332 ** before checking pInfo->nBackfillAttempted. */
62333 (void)walEnableBlocking(pWal);
62334 rc = walLockShared(pWal, WAL_CKPT_LOCK);
62335 walDisableBlocking(pWal);
62336
62337 if( rc!=SQLITE_OK ){
62338 return rc;
62339 }
62340 pWal->ckptLock = 1;
62341 }
62342#endif
62343
62344 do{
62345 rc = walTryBeginRead(pWal, pChanged, 0, ++cnt);
62346 }while( rc==WAL_RETRY );
62347 testcase( (rc&0xff)==SQLITE_BUSY );
62348 testcase( (rc&0xff)==SQLITE_IOERR );
62350 testcase( rc==SQLITE_OK );
62351
62352#ifdef SQLITE_ENABLE_SNAPSHOT
62353 if( rc==SQLITE_OK ){
62354 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
62355 /* At this point the client has a lock on an aReadMark[] slot holding
62356 ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr
62357 ** is populated with the wal-index header corresponding to the head
62358 ** of the wal file. Verify that pSnapshot is still valid before
62359 ** continuing. Reasons why pSnapshot might no longer be valid:
62360 **
62361 ** (1) The WAL file has been reset since the snapshot was taken.
62362 ** In this case, the salt will have changed.
62363 **
62364 ** (2) A checkpoint as been attempted that wrote frames past
62365 ** pSnapshot->mxFrame into the database file. Note that the
62366 ** checkpoint need not have completed for this to cause problems.
62367 */
62368 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
62369
62370 assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 );
62371 assert( pInfo->aReadMark[pWal->readLock]<=pSnapshot->mxFrame );
62372
62373 /* Check that the wal file has not been wrapped. Assuming that it has
62374 ** not, also check that no checkpointer has attempted to checkpoint any
62375 ** frames beyond pSnapshot->mxFrame. If either of these conditions are
62376 ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr
62377 ** with *pSnapshot and set *pChanged as appropriate for opening the
62378 ** snapshot. */
62379 if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt))
62380 && pSnapshot->mxFrame>=pInfo->nBackfillAttempted
62381 ){
62382 assert( pWal->readLock>0 );
62383 memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr));
62384 *pChanged = bChanged;
62385 }else{
62387 }
62388
62389 /* A client using a non-current snapshot may not ignore any frames
62390 ** from the start of the wal file. This is because, for a system
62391 ** where (minFrame < iSnapshot < maxFrame), a checkpointer may
62392 ** have omitted to checkpoint a frame earlier than minFrame in
62393 ** the file because there exists a frame after iSnapshot that
62394 ** is the same database page. */
62395 pWal->minFrame = 1;
62396
62397 if( rc!=SQLITE_OK ){
62399 }
62400 }
62401 }
62402
62403 /* Release the shared CKPT lock obtained above. */
62404 if( pWal->ckptLock ){
62405 assert( pSnapshot );
#define walDisableBlocking(x)
Definition sqlite3.c:61226
static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt)
Definition sqlite3.c:62003
static volatile WalCkptInfo * walCkptInfo(Wal *pWal)
Definition sqlite3.c:60018
#define WAL_CKPT_LOCK
Definition sqlite3.c:59690
#define WAL_RETRY
Definition sqlite3.c:61670
#define SQLITE_PROTOCOL
Definition sqlite3.c:1485
#define walEnableBlocking(x)
Definition sqlite3.c:61225
static int walLockShared(Wal *pWal, int lockIdx)
Definition sqlite3.c:60256
#define SQLITE_ERROR_SNAPSHOT
Definition sqlite3.c:1522
u32 nBackfillAttempted
Definition sqlite3.c:59792
u32 aReadMark[WAL_NREADER]
Definition sqlite3.c:59790
u32 aSalt[2]
Definition sqlite3.c:59725
i16 readLock
Definition sqlite3.c:59846
u8 ckptLock
Definition sqlite3.c:59850
u32 minFrame
Definition sqlite3.c:59857
WalIndexHdr hdr
Definition sqlite3.c:59856

References WalCkptInfo::aReadMark, WalIndexHdr::aSalt, Wal::ckptLock, Wal::hdr, Wal::minFrame, WalIndexHdr::mxFrame, WalCkptInfo::nBackfillAttempted, Wal::readLock, sqlite3WalEndReadTransaction(), SQLITE_BUSY, SQLITE_ERROR_SNAPSHOT, SQLITE_IOERR, SQLITE_OK, SQLITE_PROTOCOL, testcase, WAL_CKPT_LOCK, WAL_RETRY, walCkptInfo(), walDisableBlocking, walEnableBlocking, walLockShared(), walTryBeginRead(), and walUnlockShared().

Referenced by pagerBeginReadTransaction().

◆ sqlite3WalBeginWriteTransaction()

SQLITE_PRIVATE int sqlite3WalBeginWriteTransaction ( Wal * pWal)

Definition at line 62572 of file sqlite3.c.

62578 {
62579 int rc;
62580
62581#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
62582 /* If the write-lock is already held, then it was obtained before the
62583 ** read-transaction was even opened, making this call a no-op.
62584 ** Return early. */
62585 if( pWal->writeLock ){
62586 assert( !memcmp(&pWal->hdr,(void *)walIndexHdr(pWal),sizeof(WalIndexHdr)) );
62587 return SQLITE_OK;
62588 }
62589#endif
62590
62591 /* Cannot start a write transaction without first holding a read
62592 ** transaction. */
62593 assert( pWal->readLock>=0 );
62594 assert( pWal->writeLock==0 && pWal->iReCksum==0 );
62595
62596 if( pWal->readOnly ){
62597 return SQLITE_READONLY;
62598 }
62599
62600 /* Only one writer allowed at a time. Get the write lock. Return
62601 ** SQLITE_BUSY if unable.
62602 */
62603 rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1);
62604 if( rc ){
62605 return rc;
62606 }
62607 pWal->writeLock = 1;
62608
62609 /* If another connection has written to the database file since the
62610 ** time the read transaction on this connection was started, then
62611 ** the write is disallowed.
62612 */
62613 if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
static volatile WalIndexHdr * walIndexHdr(Wal *pWal)
Definition sqlite3.c:60026
#define WAL_WRITE_LOCK
Definition sqlite3.c:59688
static int walLockExclusive(Wal *pWal, int lockIdx, int n)
Definition sqlite3.c:60272
static void walUnlockExclusive(Wal *pWal, int lockIdx, int n)
Definition sqlite3.c:60282
u8 readOnly
Definition sqlite3.c:59851
u32 iReCksum
Definition sqlite3.c:59858
u8 writeLock
Definition sqlite3.c:59849

References Wal::hdr, Wal::iReCksum, Wal::readLock, Wal::readOnly, SQLITE_BUSY_SNAPSHOT, SQLITE_OK, SQLITE_READONLY, WAL_WRITE_LOCK, walIndexHdr(), walLockExclusive(), walUnlockExclusive(), and Wal::writeLock.

Referenced by sqlite3PagerBegin().

◆ sqlite3WalCallback()

SQLITE_PRIVATE int sqlite3WalCallback ( Wal * pWal)

Definition at line 63259 of file sqlite3.c.

63265 {
63266 u32 ret = 0;

References Wal::iCallback.

◆ sqlite3WalCheckpoint()

SQLITE_PRIVATE int sqlite3WalCheckpoint ( Wal * pWal,
sqlite3 * db,
int eMode,
int(*)(void *) xBusy,
void * pBusyArg,
int sync_flags,
int nBuf,
u8 * zBuf,
int * pnLog,
int * pnCkpt )

Definition at line 63134 of file sqlite3.c.

63151 {
63152 int rc; /* Return code */
63153 int isChanged = 0; /* True if a new wal-index header is loaded */
63154 int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
63155 int (*xBusy2)(void*) = xBusy; /* Busy handler for eMode2 */
63156
63157 assert( pWal->ckptLock==0 );
63158 assert( pWal->writeLock==0 );
63159
63160 /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
63161 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
63162 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
63163
63164 if( pWal->readOnly ) return SQLITE_READONLY;
63165 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
63166
63167 /* Enable blocking locks, if possible. If blocking locks are successfully
63168 ** enabled, set xBusy2=0 so that the busy-handler is never invoked. */
63169 sqlite3WalDb(pWal, db);
63170 (void)walEnableBlocking(pWal);
63171
63172 /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
63173 ** "checkpoint" lock on the database file.
63174 ** EVIDENCE-OF: R-10421-19736 If any other process is running a
63175 ** checkpoint operation at the same time, the lock cannot be obtained and
63176 ** SQLITE_BUSY is returned.
63177 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
63178 ** it will not be invoked in this case.
63179 */
63180 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
63181 testcase( rc==SQLITE_BUSY );
63182 testcase( rc!=SQLITE_OK && xBusy2!=0 );
63183 if( rc==SQLITE_OK ){
63184 pWal->ckptLock = 1;
63185
63186 /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
63187 ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
63188 ** file.
63189 **
63190 ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
63191 ** immediately, and a busy-handler is configured, it is invoked and the
63192 ** writer lock retried until either the busy-handler returns 0 or the
63193 ** lock is successfully obtained.
63194 */
63195 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
63196 rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1);
63197 if( rc==SQLITE_OK ){
63198 pWal->writeLock = 1;
63199 }else if( rc==SQLITE_BUSY ){
63201 xBusy2 = 0;
63202 rc = SQLITE_OK;
63203 }
63204 }
63205 }
63206
63207
63208 /* Read the wal-index header. */
63209 if( rc==SQLITE_OK ){
63210 walDisableBlocking(pWal);
63211 rc = walIndexReadHdr(pWal, &isChanged);
63212 (void)walEnableBlocking(pWal);
63213 if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){
63214 sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
63215 }
63216 }
63217
63218 /* Copy data from the log to the database file. */
63219 if( rc==SQLITE_OK ){
63220
63221 if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
63223 }else{
63224 rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags, zBuf);
63225 }
63226
63227 /* If no error occurred, set the output variables. */
63228 if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
63229 if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame;
63230 if( pnCkpt ) *pnCkpt = (int)(walCkptInfo(pWal)->nBackfill);
63231 }
63232 }
63233
63234 if( isChanged ){
63235 /* If a new wal-index header was loaded before the checkpoint was
63236 ** performed, then the pager-cache associated with pWal is now
63237 ** out of date. So zero the cached wal-index header to ensure that
63238 ** next time the pager opens a snapshot on this database it knows that
63239 ** the cache needs to be reset.
63240 */
63241 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
63242 }
63243
63244 walDisableBlocking(pWal);
63245 sqlite3WalDb(pWal, 0);
63246
63247 /* Release the locks. */
63249 if( pWal->ckptLock ){
63251 pWal->ckptLock = 0;
63252 }
static int walCheckpoint(Wal *pWal, sqlite3 *db, int eMode, int(*xBusy)(void *), void *pBusyArg, int sync_flags, u8 *zBuf)
Definition sqlite3.c:61330
#define sqlite3WalDb(pWal, db)
Definition sqlite3.c:61228
static int walIndexReadHdr(Wal *pWal, int *pChanged)
Definition sqlite3.c:61684
static int walBusyLock(Wal *pWal, int(*xBusy)(void *), void *pBusyArg, int lockIdx, int n)
Definition sqlite3.c:61238
static int walPagesize(Wal *pWal)
Definition sqlite3.c:61262
#define WALTRACE(X)
Definition sqlite3.c:59655
sqlite3_file * pDbFd
Definition sqlite3.c:59838

References Wal::ckptLock, Wal::hdr, sqlite3_io_methods::iVersion, WalIndexHdr::mxFrame, WalCkptInfo::nBackfill, Wal::pDbFd, sqlite3_file::pMethods, Wal::readOnly, sqlite3OsUnfetch(), sqlite3WalDb, sqlite3WalEndWriteTransaction(), SQLITE_BUSY, SQLITE_BUSY_TIMEOUT, SQLITE_CHECKPOINT_PASSIVE, SQLITE_CORRUPT_BKPT, SQLITE_OK, SQLITE_READONLY, testcase, WAL_CKPT_LOCK, WAL_WRITE_LOCK, walBusyLock(), walCheckpoint(), walCkptInfo(), walDisableBlocking, walEnableBlocking, walIndexReadHdr(), walLockExclusive(), walPagesize(), WALTRACE, walUnlockExclusive(), and Wal::writeLock.

Referenced by sqlite3PagerCheckpoint().

◆ sqlite3WalClose()

SQLITE_PRIVATE int sqlite3WalClose ( Wal * pWal,
sqlite3 * db,
int sync_flags,
int nBuf,
u8 * zBuf )

Definition at line 61533 of file sqlite3.c.

61545 {
61546 int rc = SQLITE_OK;
61547 if( pWal ){
61548 int isDelete = 0; /* True to unlink wal and wal-index files */
61549
61550 /* If an EXCLUSIVE lock can be obtained on the database file (using the
61551 ** ordinary, rollback-mode locking methods, this guarantees that the
61552 ** connection associated with this log file is the only connection to
61553 ** the database. In this case checkpoint the database and unlink both
61554 ** the wal and wal-index files.
61555 **
61556 ** The EXCLUSIVE lock is not released before returning.
61557 */
61558 if( zBuf!=0
61560 ){
61561 if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
61563 }
61564 rc = sqlite3WalCheckpoint(pWal, db,
61565 SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
61566 );
61567 if( rc==SQLITE_OK ){
61568 int bPersist = -1;
61570 pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
61571 );
61572 if( bPersist!=1 ){
61573 /* Try to delete the WAL file if the checkpoint completed and
61574 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
61575 ** mode (!bPersist) */
61576 isDelete = 1;
61577 }else if( pWal->mxWalSize>=0 ){
61578 /* Try to truncate the WAL file to zero bytes if the checkpoint
61579 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
61580 ** WAL mode (bPersist) and if the PRAGMA journal_size_limit is a
61581 ** non-negative value (pWal->mxWalSize>=0). Note that we truncate
61582 ** to zero bytes as truncating to the journal_size_limit might
61583 ** leave a corrupt WAL file on disk. */
61584 walLimitSize(pWal, 0);
61585 }
61586 }
61587 }
61588
61589 walIndexClose(pWal, isDelete);
61590 sqlite3OsClose(pWal->pWalFd);
61591 if( isDelete ){
61593 sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
61595 }
#define SQLITE_LOCK_EXCLUSIVE
Definition sqlite3.c:1688
#define WAL_EXCLUSIVE_MODE
Definition sqlite3.c:59876
static void walLimitSize(Wal *pWal, i64 nMax)
Definition sqlite3.c:61516
static void walIndexClose(Wal *pWal, int isDelete)
Definition sqlite3.c:60768
#define SQLITE_FCNTL_PERSIST_WAL
Definition sqlite3.c:2188
#define WAL_NORMAL_MODE
Definition sqlite3.c:59875
i64 mxWalSize
Definition sqlite3.c:59841
sqlite3_vfs * pVfs
Definition sqlite3.c:59837
const char * zWalName
Definition sqlite3.c:59859
u8 exclusiveMode
Definition sqlite3.c:59848
sqlite3_file * pWalFd
Definition sqlite3.c:59839

Referenced by sqlite3PagerClose(), and sqlite3PagerCloseWal().

◆ sqlite3WalDbsize()

SQLITE_PRIVATE Pgno sqlite3WalDbsize ( Wal * pWal)

Definition at line 62551 of file sqlite3.c.

62551 : nOut), iOffset);
62552}
62553
62554/*
62555** Return the size of the database in pages (or zero, if unknown).
62556*/

Referenced by pagerPagecount().

◆ sqlite3WalDefaultHook()

SQLITE_PRIVATE int sqlite3WalDefaultHook ( void * pClientData,
sqlite3 * db,
const char * zDb,
int nFrame )

Definition at line 163255 of file sqlite3.c.

163266 {
163267 if( nFrame>=SQLITE_PTR_TO_INT(pClientData) ){

References sqlite3_wal_checkpoint(), sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), SQLITE_OK, and SQLITE_PTR_TO_INT.

Referenced by sqlite3_wal_autocheckpoint(), and sqlite3Pragma().

◆ sqlite3WalEndReadTransaction()

SQLITE_PRIVATE void sqlite3WalEndReadTransaction ( Wal * pWal)

◆ sqlite3WalEndWriteTransaction()

SQLITE_PRIVATE int sqlite3WalEndWriteTransaction ( Wal * pWal)

Definition at line 62620 of file sqlite3.c.

62626 {
62627 if( pWal->writeLock ){

Referenced by pager_end_transaction(), and sqlite3WalCheckpoint().

◆ sqlite3WalExclusiveMode()

SQLITE_PRIVATE int sqlite3WalExclusiveMode ( Wal * pWal,
int op )

Definition at line 63292 of file sqlite3.c.

63298 {
63299 int rc;
63300 assert( pWal->writeLock==0 );
63301 assert( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE || op==-1 );
63302
63303 /* pWal->readLock is usually set, but might be -1 if there was a
63304 ** prior error while attempting to acquire are read-lock. This cannot
63305 ** happen if the connection is actually in exclusive mode (as no xShmLock
63306 ** locks are taken in this case). Nor should the pager attempt to
63307 ** upgrade to exclusive-mode following such an error.
63308 */
63309 assert( pWal->readLock>=0 || pWal->lockError );
63310 assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) );
63311
63312 if( op==0 ){
63313 if( pWal->exclusiveMode!=WAL_NORMAL_MODE ){
63315 if( walLockShared(pWal, WAL_READ_LOCK(pWal->readLock))!=SQLITE_OK ){
63317 }
63318 rc = pWal->exclusiveMode==WAL_NORMAL_MODE;
63319 }else{
63320 /* Already in locking_mode=NORMAL */
63321 rc = 0;
63322 }
63323 }else if( op>0 ){
63324 assert( pWal->exclusiveMode==WAL_NORMAL_MODE );
63325 assert( pWal->readLock>=0 );
#define WAL_READ_LOCK(I)
Definition sqlite3.c:59692
static void walUnlockShared(Wal *pWal, int lockIdx)
Definition sqlite3.c:60266
#define WAL_HEAPMEMORY_MODE
Definition sqlite3.c:59877

References Wal::exclusiveMode, Wal::readLock, SQLITE_OK, WAL_EXCLUSIVE_MODE, WAL_HEAPMEMORY_MODE, WAL_NORMAL_MODE, WAL_READ_LOCK, walLockShared(), walUnlockShared(), and Wal::writeLock.

Referenced by pager_end_transaction(), and sqlite3PagerBegin().

◆ sqlite3WalFile()

SQLITE_PRIVATE sqlite3_file * sqlite3WalFile ( Wal * pWal)

Definition at line 63443 of file sqlite3.c.

63443 : 0);
63444}
63445#endif

◆ sqlite3WalFindFrame()

SQLITE_PRIVATE int sqlite3WalFindFrame ( Wal * pWal,
Pgno pgno,
u32 * piRead )

Definition at line 62427 of file sqlite3.c.

62437 {
62438 u32 iRead = 0; /* If !=0, WAL frame to return data from */
62439 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
62440 int iHash; /* Used to loop through N hash tables */
62441 int iMinHash;
62442
62443 /* This routine is only be called from within a read transaction. */
62444 assert( pWal->readLock>=0 || pWal->lockError );
62445
62446 /* If the "last page" field of the wal-index header snapshot is 0, then
62447 ** no data will be read from the wal under any circumstances. Return early
62448 ** in this case as an optimization. Likewise, if pWal->readLock==0,
62449 ** then the WAL is ignored by the reader so return early, as if the
62450 ** WAL were empty.
62451 */
62452 if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){
62453 *piRead = 0;
62454 return SQLITE_OK;
62455 }
62456
62457 /* Search the hash table or tables for an entry matching page number
62458 ** pgno. Each iteration of the following for() loop searches one
62459 ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
62460 **
62461 ** This code might run concurrently to the code in walIndexAppend()
62462 ** that adds entries to the wal-index (and possibly to this hash
62463 ** table). This means the value just read from the hash
62464 ** slot (aHash[iKey]) may have been added before or after the
62465 ** current read transaction was opened. Values added after the
62466 ** read transaction was opened may have been written incorrectly -
62467 ** i.e. these slots may contain garbage data. However, we assume
62468 ** that any slots written before the current read transaction was
62469 ** opened remain unmodified.
62470 **
62471 ** For the reasons above, the if(...) condition featured in the inner
62472 ** loop of the following block is more stringent that would be required
62473 ** if we had exclusive access to the hash-table:
62474 **
62475 ** (aPgno[iFrame]==pgno):
62476 ** This condition filters out normal hash-table collisions.
62477 **
62478 ** (iFrame<=iLast):
62479 ** This condition filters out entries that were added to the hash
62480 ** table after the current read-transaction had started.
62481 */
62482 iMinHash = walFramePage(pWal->minFrame);
62483 for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){
62484 WalHashLoc sLoc; /* Hash table location */
62485 int iKey; /* Hash slot index */
62486 int nCollide; /* Number of hash collisions remaining */
62487 int rc; /* Error code */
62488 u32 iH;
62489
62490 rc = walHashGet(pWal, iHash, &sLoc);
62491 if( rc!=SQLITE_OK ){
62492 return rc;
62493 }
62494 nCollide = HASHTABLE_NSLOT;
62495 iKey = walHash(pgno);
62496 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
62497 u32 iFrame = iH + sLoc.iZero;
62498 if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){
62499 assert( iFrame>iRead || CORRUPT_DB );
62500 iRead = iFrame;
62501 }
62502 if( (nCollide--)==0 ){
62503 return SQLITE_CORRUPT_BKPT;
62504 }
62505 iKey = walNextHash(iKey);
62506 }
62507 if( iRead ) break;
62508 }
62509
62510#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
62511 /* If expensive assert() statements are available, do a linear search
62512 ** of the wal-index file content. Make sure the results agree with the
62513 ** result obtained using the hash indexes above. */
62514 {
62515 u32 iRead2 = 0;
62516 u32 iTest;
62517 assert( pWal->bShmUnreliable || pWal->minFrame>0 );
62518 for(iTest=iLast; iTest>=pWal->minFrame && iTest>0; iTest--){
62519 if( walFramePgno(pWal, iTest)==pgno ){
62520 iRead2 = iTest;
62521 break;
62522 }
62523 }
62524 assert( iRead==iRead2 );
static int walFramePage(u32 iFrame)
Definition sqlite3.c:60359
static int walHash(u32 iPage)
Definition sqlite3.c:60295
static u32 walFramePgno(Wal *pWal, u32 iFrame)
Definition sqlite3.c:60374
static int walNextHash(int iPriorHash)
Definition sqlite3.c:60300
static int walHashGet(Wal *pWal, int iHash, WalHashLoc *pLoc)
Definition sqlite3.c:60330
volatile u32 * aPgno
Definition sqlite3.c:60312
volatile ht_slot * aHash
Definition sqlite3.c:60311
u8 bShmUnreliable
Definition sqlite3.c:59855

References WalHashLoc::aHash, WalHashLoc::aPgno, AtomicLoad, Wal::bShmUnreliable, CORRUPT_DB, HASHTABLE_NSLOT, Wal::hdr, WalHashLoc::iZero, Wal::minFrame, WalIndexHdr::mxFrame, Wal::readLock, SQLITE_CORRUPT_BKPT, SQLITE_OK, walFramePage(), walFramePgno(), walHash(), walHashGet(), and walNextHash().

Referenced by readDbPage().

◆ sqlite3WalFrames()

SQLITE_PRIVATE int sqlite3WalFrames ( Wal * pWal,
int szPage,
PgHdr * pList,
Pgno nTruncate,
int isCommit,
int sync_flags )

Definition at line 62896 of file sqlite3.c.

62909 {
62910 int rc; /* Used to catch return codes */
62911 u32 iFrame; /* Next frame address */
62912 PgHdr *p; /* Iterator to run through pList with. */
62913 PgHdr *pLast = 0; /* Last frame in list */
62914 int nExtra = 0; /* Number of extra copies of last page */
62915 int szFrame; /* The size of a single frame */
62916 i64 iOffset; /* Next byte to write in WAL file */
62917 WalWriter w; /* The writer */
62918 u32 iFirst = 0; /* First frame that may be overwritten */
62919 WalIndexHdr *pLive; /* Pointer to shared header */
62920
62921 assert( pList );
62922 assert( pWal->writeLock );
62923
62924 /* If this frame set completes a transaction, then nTruncate>0. If
62925 ** nTruncate==0 then this frame set does not complete the transaction. */
62926 assert( (isCommit!=0)==(nTruncate!=0) );
62927
62928#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
62929 { int cnt; for(cnt=0, p=pList; p; p=p->pDirty, cnt++){}
62930 WALTRACE(("WAL%p: frame write begin. %d frames. mxFrame=%d. %s\n",
62931 pWal, cnt, pWal->hdr.mxFrame, isCommit ? "Commit" : "Spill"));
62932 }
62933#endif
62934
62935 pLive = (WalIndexHdr*)walIndexHdr(pWal);
62936 if( memcmp(&pWal->hdr, (void *)pLive, sizeof(WalIndexHdr))!=0 ){
62937 iFirst = pLive->mxFrame+1;
62938 }
62939
62940 /* See if it is possible to write these frames into the start of the
62941 ** log file, instead of appending to it at pWal->hdr.mxFrame.
62942 */
62943 if( SQLITE_OK!=(rc = walRestartLog(pWal)) ){
62944 return rc;
62945 }
62946
62947 /* If this is the first frame written into the log, write the WAL
62948 ** header to the start of the WAL file. See comments at the top of
62949 ** this source file for a description of the WAL header format.
62950 */
62951 iFrame = pWal->hdr.mxFrame;
62952 if( iFrame==0 ){
62953 u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assemble wal-header in */
62954 u32 aCksum[2]; /* Checksum for wal-header */
62955
62956 sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
62957 sqlite3Put4byte(&aWalHdr[4], WAL_MAX_VERSION);
62958 sqlite3Put4byte(&aWalHdr[8], szPage);
62959 sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt);
62960 if( pWal->nCkpt==0 ) sqlite3_randomness(8, pWal->hdr.aSalt);
62961 memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8);
62962 walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
62963 sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
62964 sqlite3Put4byte(&aWalHdr[28], aCksum[1]);
62965
62966 pWal->szPage = szPage;
62968 pWal->hdr.aFrameCksum[0] = aCksum[0];
62969 pWal->hdr.aFrameCksum[1] = aCksum[1];
62970 pWal->truncateOnCommit = 1;
62971
62972 rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0);
62973 WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok"));
62974 if( rc!=SQLITE_OK ){
62975 return rc;
62976 }
62977
62978 /* Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless
62979 ** all syncing is turned off by PRAGMA synchronous=OFF). Otherwise
62980 ** an out-of-order write following a WAL restart could result in
62981 ** database corruption. See the ticket:
62982 **
62983 ** https://sqlite.org/src/info/ff5be73dee
62984 */
62985 if( pWal->syncHeader ){
62986 rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
62987 if( rc ) return rc;
62988 }
62989 }
62990 assert( (int)pWal->szPage==szPage );
62991
62992 /* Setup information needed to write frames into the WAL */
62993 w.pWal = pWal;
62994 w.pFd = pWal->pWalFd;
62995 w.iSyncPoint = 0;
62996 w.syncFlags = sync_flags;
62997 w.szPage = szPage;
62998 iOffset = walFrameOffset(iFrame+1, szPage);
62999 szFrame = szPage + WAL_FRAME_HDRSIZE;
63000
63001 /* Write all frames into the log file exactly once */
63002 for(p=pList; p; p=p->pDirty){
63003 int nDbSize; /* 0 normally. Positive == commit flag */
63004
63005 /* Check if this page has already been written into the wal file by
63006 ** the current transaction. If so, overwrite the existing frame and
63007 ** set Wal.writeLock to WAL_WRITELOCK_RECKSUM - indicating that
63008 ** checksums must be recomputed when the transaction is committed. */
63009 if( iFirst && (p->pDirty || isCommit==0) ){
63010 u32 iWrite = 0;
63011 VVA_ONLY(rc =) sqlite3WalFindFrame(pWal, p->pgno, &iWrite);
63012 assert( rc==SQLITE_OK || iWrite==0 );
63013 if( iWrite>=iFirst ){
63014 i64 iOff = walFrameOffset(iWrite, szPage) + WAL_FRAME_HDRSIZE;
63015 void *pData;
63016 if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){
63017 pWal->iReCksum = iWrite;
63018 }
63019 pData = p->pData;
63020 rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOff);
63021 if( rc ) return rc;
63022 p->flags &= ~PGHDR_WAL_APPEND;
63023 continue;
63024 }
63025 }
63026
63027 iFrame++;
63028 assert( iOffset==walFrameOffset(iFrame, szPage) );
63029 nDbSize = (isCommit && p->pDirty==0) ? nTruncate : 0;
63030 rc = walWriteOneFrame(&w, p, nDbSize, iOffset);
63031 if( rc ) return rc;
63032 pLast = p;
63033 iOffset += szFrame;
63034 p->flags |= PGHDR_WAL_APPEND;
63035 }
63036
63037 /* Recalculate checksums within the wal file if required. */
63038 if( isCommit && pWal->iReCksum ){
63039 rc = walRewriteChecksums(pWal, iFrame);
63040 if( rc ) return rc;
63041 }
63042
63043 /* If this is the end of a transaction, then we might need to pad
63044 ** the transaction and/or sync the WAL file.
63045 **
63046 ** Padding and syncing only occur if this set of frames complete a
63047 ** transaction and if PRAGMA synchronous=FULL. If synchronous==NORMAL
63048 ** or synchronous==OFF, then no padding or syncing are needed.
63049 **
63050 ** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
63051 ** needed and only the sync is done. If padding is needed, then the
63052 ** final frame is repeated (with its commit mark) until the next sector
63053 ** boundary is crossed. Only the part of the WAL prior to the last
63054 ** sector boundary is synced; the part of the last frame that extends
63055 ** past the sector boundary is written after the sync.
63056 */
63057 if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){
63058 int bSync = 1;
63059 if( pWal->padToSectorBoundary ){
63060 int sectorSize = sqlite3SectorSize(pWal->pWalFd);
63061 w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize;
63062 bSync = (w.iSyncPoint==iOffset);
63063 testcase( bSync );
63064 while( iOffset<w.iSyncPoint ){
63065 rc = walWriteOneFrame(&w, pLast, nTruncate, iOffset);
63066 if( rc ) return rc;
63067 iOffset += szFrame;
63068 nExtra++;
63069 assert( pLast!=0 );
63070 }
63071 }
63072 if( bSync ){
63073 assert( rc==SQLITE_OK );
63074 rc = sqlite3OsSync(w.pFd, WAL_SYNC_FLAGS(sync_flags));
63075 }
63076 }
63077
63078 /* If this frame set completes the first transaction in the WAL and
63079 ** if PRAGMA journal_size_limit is set, then truncate the WAL to the
63080 ** journal size limit, if possible.
63081 */
63082 if( isCommit && pWal->truncateOnCommit && pWal->mxWalSize>=0 ){
63083 i64 sz = pWal->mxWalSize;
63084 if( walFrameOffset(iFrame+nExtra+1, szPage)>pWal->mxWalSize ){
63085 sz = walFrameOffset(iFrame+nExtra+1, szPage);
63086 }
63087 walLimitSize(pWal, sz);
63088 pWal->truncateOnCommit = 0;
63089 }
63090
63091 /* Append data to the wal-index. It is not necessary to lock the
63092 ** wal-index to do this as the SQLITE_SHM_WRITE lock held on the wal-index
63093 ** guarantees that there are no other writers, and no data that may
63094 ** be in use by existing readers is being overwritten.
63095 */
63096 iFrame = pWal->hdr.mxFrame;
63097 for(p=pList; p && rc==SQLITE_OK; p=p->pDirty){
63098 if( (p->flags & PGHDR_WAL_APPEND)==0 ) continue;
63099 iFrame++;
63100 rc = walIndexAppend(pWal, iFrame, p->pgno);
63101 }
63102 assert( pLast!=0 || nExtra==0 );
63103 while( rc==SQLITE_OK && nExtra>0 ){
63104 iFrame++;
63105 nExtra--;
63106 rc = walIndexAppend(pWal, iFrame, pLast->pgno);
63107 }
63108
63109 if( rc==SQLITE_OK ){
63110 /* Update the private copy of the header. */
63111 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
63112 testcase( szPage<=32768 );
63113 testcase( szPage>=65536 );
63114 pWal->hdr.mxFrame = iFrame;
63115 if( isCommit ){
63116 pWal->hdr.iChange++;
63117 pWal->hdr.nPage = nTruncate;
63118 }
63119 /* If this is a commit, update the wal-index header too. */
63120 if( isCommit ){
63121 walIndexWriteHdr(pWal);
63122 pWal->iCallback = iFrame;
static int walRestartLog(Wal *pWal)
Definition sqlite3.c:62733
static void walChecksumBytes(int nativeCksum, u8 *a, int nByte, const u32 *aIn, u32 *aOut)
Definition sqlite3.c:60052
static int walRewriteChecksums(Wal *pWal, u32 iLast)
Definition sqlite3.c:62847
static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage)
Definition sqlite3.c:60456
#define walFrameOffset(iFrame, szPage)
Definition sqlite3.c:59828
SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *)
Definition sqlite3.c:54333
static SQLITE_NO_TSAN void walIndexWriteHdr(Wal *pWal)
Definition sqlite3.c:60119
static int walWriteOneFrame(WalWriter *p, PgHdr *pPage, int nTruncate, sqlite3_int64 iOffset)
Definition sqlite3.c:62821
#define WAL_MAX_VERSION
Definition sqlite3.c:59671
#define WAL_MAGIC
Definition sqlite3.c:59821
#define WAL_SYNC_FLAGS(X)
Definition sqlite3.c:51592
#define CKPT_SYNC_FLAGS(X)
Definition sqlite3.c:51593
#define PGHDR_WAL_APPEND
Definition sqlite3.c:16077
u32 aFrameCksum[2]
Definition sqlite3.c:59724
sqlite3_file * pFd
Definition sqlite3.c:62782
sqlite3_int64 iSyncPoint
Definition sqlite3.c:62783
Wal * pWal
Definition sqlite3.c:62781
int syncFlags
Definition sqlite3.c:62784
u8 truncateOnCommit
Definition sqlite3.c:59852
u32 szPage
Definition sqlite3.c:59845
u32 nCkpt
Definition sqlite3.c:59860
u8 syncHeader
Definition sqlite3.c:59853

Referenced by pagerWalFrames().

◆ sqlite3WalHeapMemory()

SQLITE_PRIVATE int sqlite3WalHeapMemory ( Wal * pWal)

Definition at line 63334 of file sqlite3.c.

References Wal::exclusiveMode, and WAL_HEAPMEMORY_MODE.

Referenced by sqlite3PagerLockingMode().

◆ sqlite3WalkerDepthDecrease()

SQLITE_PRIVATE void sqlite3WalkerDepthDecrease ( Walker * pWalker,
Select * pSelect )

Definition at line 97719 of file sqlite3.c.

97720 {
97721 UNUSED_PARAMETER(pSelect);
97722 pWalker->walkerDepth++;

References UNUSED_PARAMETER, Walker::walkerDepth, and WRC_Continue.

Referenced by sqlite3ExprAnalyzeAggregates(), and sqlite3WindowRewrite().

◆ sqlite3WalkerDepthIncrease()

SQLITE_PRIVATE int sqlite3WalkerDepthIncrease ( Walker * pWalker,
Select * pSelect )

Definition at line 97714 of file sqlite3.c.

Referenced by sqlite3ExprAnalyzeAggregates(), and sqlite3WindowRewrite().

◆ sqlite3WalkExpr()

◆ sqlite3WalkExprList()

SQLITE_PRIVATE int sqlite3WalkExprList ( Walker * pWalker,
ExprList * p )

◆ sqlite3WalkSelect()

SQLITE_PRIVATE int sqlite3WalkSelect ( Walker * pWalker,
Select * p )

Definition at line 97691 of file sqlite3.c.

97697 {
97698 int rc;
97699 if( p==0 ) return WRC_Continue;
97700 if( pWalker->xSelectCallback==0 ) return WRC_Continue;
97701 do{
97702 rc = pWalker->xSelectCallback(pWalker, p);
97703 if( rc ) return rc & WRC_Abort;
97704 if( sqlite3WalkSelectExpr(pWalker, p)
97705 || sqlite3WalkSelectFrom(pWalker, p)
97706 ){
97707 return WRC_Abort;
97708 }
97709 if( pWalker->xSelectCallback2 ){
SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker *, Select *)
Definition sqlite3.c:97653
SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker *, Select *)
Definition sqlite3.c:97625

References Select::pPrior, sqlite3WalkSelectExpr(), sqlite3WalkSelectFrom(), WRC_Abort, WRC_Continue, Walker::xSelectCallback, and Walker::xSelectCallback2.

Referenced by flattenSubquery(), renameColumnFunc(), renameTableFunc(), resolveExprStep(), selectExpander(), sqlite3ResolveSelectNames(), sqlite3SelectAddTypeInfo(), sqlite3SelectExpand(), sqlite3WalkSelectFrom(), sqlite3WindowRewrite(), walkExpr(), and withExpand().

◆ sqlite3WalkSelectExpr()

SQLITE_PRIVATE int sqlite3WalkSelectExpr ( Walker * pWalker,
Select * p )

Definition at line 97625 of file sqlite3.c.

97631 {
97632 if( sqlite3WalkExprList(pWalker, p->pEList) ) return WRC_Abort;
97633 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
97634 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
97635 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
97636 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
97637 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
97638#if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
97639 {
97640 Parse *pParse = pWalker->pParse;
97641 if( pParse && IN_RENAME_OBJECT ){
97642 /* The following may return WRC_Abort if there are unresolvable
97643 ** symbols (e.g. a table that does not exist) in a window definition. */
97644 int rc = walkWindowList(pWalker, p->pWinDefn);
static int walkWindowList(Walker *pWalker, Window *pList)
Definition sqlite3.c:97525

References IN_RENAME_OBJECT, Select::pEList, Select::pGroupBy, Select::pHaving, Select::pLimit, Select::pOrderBy, Walker::pParse, Select::pWhere, Select::pWinDefn, sqlite3WalkExpr(), sqlite3WalkExprList(), walkWindowList(), WRC_Abort, and WRC_Continue.

Referenced by sqlite3WalkSelect().

◆ sqlite3WalkSelectFrom()

SQLITE_PRIVATE int sqlite3WalkSelectFrom ( Walker * pWalker,
Select * p )

Definition at line 97653 of file sqlite3.c.

97659 {
97660 SrcList *pSrc;
97661 int i;
97662 struct SrcList_item *pItem;
97663
97664 pSrc = p->pSrc;
97665 if( pSrc ){
97666 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
97667 if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
97668 return WRC_Abort;
97669 }
97670 if( pItem->fg.isTabFunc
97671 && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
97672 ){

References SrcList::a, SrcList::nSrc, Walker::pSelect, Select::pSrc, sqlite3WalkExprList(), sqlite3WalkSelect(), WRC_Abort, and WRC_Continue.

Referenced by sqlite3WalkSelect().

◆ sqlite3WalLimit()

SQLITE_PRIVATE void sqlite3WalLimit ( Wal * pWal,
i64 iLimit )

Definition at line 60870 of file sqlite3.c.

Referenced by sqlite3PagerJournalSizeLimit().

◆ sqlite3WalOpen()

SQLITE_PRIVATE int sqlite3WalOpen ( sqlite3_vfs * pVfs,
sqlite3_file * pDbFd,
const char * zWalName,
int bNoShm,
i64 mxWalSize,
Wal ** ppWal )

Definition at line 60796 of file sqlite3.c.

60809 {
60810 int rc; /* Return Code */
60811 Wal *pRet; /* Object to allocate and return */
60812 int flags; /* Flags passed to OsOpen() */
60813
60814 assert( zWalName && zWalName[0] );
60815 assert( pDbFd );
60816
60817 /* In the amalgamation, the os_unix.c and os_win.c source files come before
60818 ** this source file. Verify that the #defines of the locking byte offsets
60819 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
60820 ** For that matter, if the lock offset ever changes from its initial design
60821 ** value of 120, we need to know that so there is an assert() to check it.
60822 */
60823 assert( 120==WALINDEX_LOCK_OFFSET );
60824 assert( 136==WALINDEX_HDR_SIZE );
60825#ifdef WIN_SHM_BASE
60826 assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
60827#endif
60828#ifdef UNIX_SHM_BASE
60830#endif
60831
60832
60833 /* Allocate an instance of struct Wal to return. */
60834 *ppWal = 0;
60835 pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
60836 if( !pRet ){
60837 return SQLITE_NOMEM_BKPT;
60838 }
60839
60840 pRet->pVfs = pVfs;
60841 pRet->pWalFd = (sqlite3_file *)&pRet[1];
60842 pRet->pDbFd = pDbFd;
60843 pRet->readLock = -1;
60844 pRet->mxWalSize = mxWalSize;
60845 pRet->zWalName = zWalName;
60846 pRet->syncHeader = 1;
60847 pRet->padToSectorBoundary = 1;
60849
60850 /* Open file handle on the write-ahead log file. */
60852 rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
60853 if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
60854 pRet->readOnly = WAL_RDONLY;
60855 }
60856
60857 if( rc!=SQLITE_OK ){
60858 walIndexClose(pRet, 0);
60859 sqlite3OsClose(pRet->pWalFd);
60860 sqlite3_free(pRet);
60861 }else{
60862 int iDC = sqlite3OsDeviceCharacteristics(pDbFd);
60863 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
60865 pRet->padToSectorBoundary = 0;
#define WALINDEX_HDR_SIZE
Definition sqlite3.c:59804
#define UNIX_SHM_BASE
Definition sqlite3.c:37831
#define WAL_RDONLY
Definition sqlite3.c:59883
#define WALINDEX_LOCK_OFFSET
Definition sqlite3.c:59803
#define SQLITE_IOCAP_SEQUENTIAL
Definition sqlite3.c:1671
u8 padToSectorBoundary
Definition sqlite3.c:59854

References Wal::exclusiveMode, Wal::mxWalSize, Wal::padToSectorBoundary, Wal::pDbFd, Wal::pVfs, Wal::pWalFd, Wal::readLock, Wal::readOnly, sqlite3_free(), sqlite3MallocZero(), sqlite3OsClose(), sqlite3OsDeviceCharacteristics(), sqlite3OsOpen(), SQLITE_IOCAP_POWERSAFE_OVERWRITE, SQLITE_IOCAP_SEQUENTIAL, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_WAL, Wal::syncHeader, sqlite3_vfs::szOsFile, UNIX_SHM_BASE, WAL_HEAPMEMORY_MODE, WAL_NORMAL_MODE, WAL_RDONLY, WALINDEX_HDR_SIZE, WALINDEX_LOCK_OFFSET, walIndexClose(), WALTRACE, and Wal::zWalName.

Referenced by pagerOpenWal().

◆ sqlite3WalReadFrame()

SQLITE_PRIVATE int sqlite3WalReadFrame ( Wal * pWal,
u32 iRead,
int nOut,
u8 * pOut )

Definition at line 62531 of file sqlite3.c.

62542 {
62543 int sz;
62544 i64 iOffset;
62545 sz = pWal->hdr.szPage;
62546 sz = (sz&0xfe00) + ((sz&0x0001)<<16);

References Wal::hdr, WalIndexHdr::szPage, testcase, WAL_FRAME_HDRSIZE, and walFrameOffset.

Referenced by readDbPage().

◆ sqlite3WalSavepoint()

SQLITE_PRIVATE void sqlite3WalSavepoint ( Wal * pWal,
u32 * aWalData )

Definition at line 62682 of file sqlite3.c.

62688 {

References WalIndexHdr::aFrameCksum, Wal::hdr, WalIndexHdr::mxFrame, Wal::nCkpt, and Wal::writeLock.

Referenced by pagerOpenSavepoint().

◆ sqlite3WalSavepointUndo()

SQLITE_PRIVATE int sqlite3WalSavepointUndo ( Wal * pWal,
u32 * aWalData )

Definition at line 62696 of file sqlite3.c.

62702 {
62703 int rc = SQLITE_OK;
62704
62705 assert( pWal->writeLock );
62706 assert( aWalData[3]!=pWal->nCkpt || aWalData[0]<=pWal->hdr.mxFrame );
62707
62708 if( aWalData[3]!=pWal->nCkpt ){
62709 /* This savepoint was opened immediately after the write-transaction
62710 ** was started. Right after that, the writer decided to wrap around
62711 ** to the start of the log. Update the savepoint values to match.
62712 */
62713 aWalData[0] = 0;
62714 aWalData[3] = pWal->nCkpt;
62715 }
62716
62717 if( aWalData[0]<pWal->hdr.mxFrame ){
62718 pWal->hdr.mxFrame = aWalData[0];
62719 pWal->hdr.aFrameCksum[0] = aWalData[1];

References WalIndexHdr::aFrameCksum, Wal::hdr, WalIndexHdr::mxFrame, Wal::nCkpt, SQLITE_OK, walCleanupHash(), and Wal::writeLock.

Referenced by pagerPlaybackSavepoint().

◆ sqlite3WalUndo()

SQLITE_PRIVATE int sqlite3WalUndo ( Wal * pWal,
int(*)(void *, Pgno) xUndo,
void * pUndoCtx )

Definition at line 62642 of file sqlite3.c.

62648 {
62649 int rc = SQLITE_OK;
62650 if( ALWAYS(pWal->writeLock) ){
62651 Pgno iMax = pWal->hdr.mxFrame;
62652 Pgno iFrame;
62653
62654 /* Restore the clients cache of the wal-index header to the state it
62655 ** was in before the client began writing to the database.
62656 */
62657 memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
62658
62659 for(iFrame=pWal->hdr.mxFrame+1;
62660 ALWAYS(rc==SQLITE_OK) && iFrame<=iMax;
62661 iFrame++
62662 ){
62663 /* This call cannot fail. Unless the page for which the page number
62664 ** is passed as the second argument is (a) in the cache and
62665 ** (b) has an outstanding reference, then xUndo is either a no-op
62666 ** (if (a) is false) or simply expels the page from the cache (if (b)
62667 ** is false).
62668 **
62669 ** If the upper layer is doing a rollback, it is guaranteed that there
62670 ** are no outstanding references to any page other than page 1. And
62671 ** page 1 is never written to the log until the transaction is
62672 ** committed. As a result, the call to xUndo may not fail.
62673 */
62674 assert( walFramePgno(pWal, iFrame)!=1 );

References ALWAYS, Wal::hdr, WalIndexHdr::mxFrame, SQLITE_OK, walCleanupHash(), walFramePgno(), walIndexHdr(), and Wal::writeLock.

◆ sqlite3WhereBegin()

SQLITE_PRIVATE WhereInfo * sqlite3WhereBegin ( Parse * pParse,
SrcList * pTabList,
Expr * pWhere,
ExprList * pOrderBy,
ExprList * pResultSet,
u16 wctrlFlags,
int iAuxArg )

Definition at line 150295 of file sqlite3.c.

150310 {
150311 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
150312 int nTabList; /* Number of elements in pTabList */
150313 WhereInfo *pWInfo; /* Will become the return value of this function */
150314 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
150315 Bitmask notReady; /* Cursors that are not yet positioned */
150316 WhereLoopBuilder sWLB; /* The WhereLoop builder */
150317 WhereMaskSet *pMaskSet; /* The expression mask set */
150318 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
150319 WhereLoop *pLoop; /* Pointer to a single WhereLoop object */
150320 int ii; /* Loop counter */
150321 sqlite3 *db; /* Database connection */
150322 int rc; /* Return code */
150323 u8 bFordelete = 0; /* OPFLAG_FORDELETE or zero, as appropriate */
150324
150325 assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || (
150326 (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
150327 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
150328 ));
150329
150330 /* Only one of WHERE_OR_SUBCLAUSE or WHERE_USE_LIMIT */
150331 assert( (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
150332 || (wctrlFlags & WHERE_USE_LIMIT)==0 );
150333
150334 /* Variable initialization */
150335 db = pParse->db;
150336 memset(&sWLB, 0, sizeof(sWLB));
150337
150338 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
150339 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
150340 if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
150341 sWLB.pOrderBy = pOrderBy;
150342
150343 /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
150344 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
150346 wctrlFlags &= ~WHERE_WANT_DISTINCT;
150347 }
150348
150349 /* The number of tables in the FROM clause is limited by the number of
150350 ** bits in a Bitmask
150351 */
150352 testcase( pTabList->nSrc==BMS );
150353 if( pTabList->nSrc>BMS ){
150354 sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
150355 return 0;
150356 }
150357
150358 /* This function normally generates a nested loop for all tables in
150359 ** pTabList. But if the WHERE_OR_SUBCLAUSE flag is set, then we should
150360 ** only generate code for the first table in pTabList and assume that
150361 ** any cursors associated with subsequent tables are uninitialized.
150362 */
150363 nTabList = (wctrlFlags & WHERE_OR_SUBCLAUSE) ? 1 : pTabList->nSrc;
150364
150365 /* Allocate and initialize the WhereInfo structure that will become the
150366 ** return value. A single allocation is used to store the WhereInfo
150367 ** struct, the contents of WhereInfo.a[], the WhereClause structure
150368 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
150369 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
150370 ** some architectures. Hence the ROUND8() below.
150371 */
150372 nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
150373 pWInfo = sqlite3DbMallocRawNN(db, nByteWInfo + sizeof(WhereLoop));
150374 if( db->mallocFailed ){
150375 sqlite3DbFree(db, pWInfo);
150376 pWInfo = 0;
150377 goto whereBeginError;
150378 }
150379 pWInfo->pParse = pParse;
150380 pWInfo->pTabList = pTabList;
150381 pWInfo->pOrderBy = pOrderBy;
150382 pWInfo->pWhere = pWhere;
150383 pWInfo->pResultSet = pResultSet;
150384 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
150385 pWInfo->nLevel = nTabList;
150386 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
150387 pWInfo->wctrlFlags = wctrlFlags;
150388 pWInfo->iLimit = iAuxArg;
150389 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
150390 memset(&pWInfo->nOBSat, 0,
150391 offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
150392 memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
150393 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
150394 pMaskSet = &pWInfo->sMaskSet;
150395 sWLB.pWInfo = pWInfo;
150396 sWLB.pWC = &pWInfo->sWC;
150397 sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo);
150398 assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) );
150399 whereLoopInit(sWLB.pNew);
150400#ifdef SQLITE_DEBUG
150401 sWLB.pNew->cId = '*';
150402#endif
150403
150404 /* Split the WHERE clause into separate subexpressions where each
150405 ** subexpression is separated by an AND operator.
150406 */
150407 initMaskSet(pMaskSet);
150408 sqlite3WhereClauseInit(&pWInfo->sWC, pWInfo);
150409 sqlite3WhereSplit(&pWInfo->sWC, pWhere, TK_AND);
150410
150411 /* Special case: No FROM clause
150412 */
150413 if( nTabList==0 ){
150414 if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr;
150415 if( wctrlFlags & WHERE_WANT_DISTINCT ){
150416 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
150417 }
150418 ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW"));
150419 }else{
150420 /* Assign a bit from the bitmask to every term in the FROM clause.
150421 **
150422 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
150423 **
150424 ** The rule of the previous sentence ensures thta if X is the bitmask for
150425 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
150426 ** Knowing the bitmask for all tables to the left of a left join is
150427 ** important. Ticket #3015.
150428 **
150429 ** Note that bitmasks are created for all pTabList->nSrc tables in
150430 ** pTabList, not just the first nTabList tables. nTabList is normally
150431 ** equal to pTabList->nSrc but might be shortened to 1 if the
150432 ** WHERE_OR_SUBCLAUSE flag is set.
150433 */
150434 ii = 0;
150435 do{
150436 createMask(pMaskSet, pTabList->a[ii].iCursor);
150437 sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
150438 }while( (++ii)<pTabList->nSrc );
150439 #ifdef SQLITE_DEBUG
150440 {
150441 Bitmask mx = 0;
150442 for(ii=0; ii<pTabList->nSrc; ii++){
150443 Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
150444 assert( m>=mx );
150445 mx = m;
150446 }
150447 }
150448 #endif
150449 }
150450
150451 /* Analyze all of the subexpressions. */
150452 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
150453 if( db->mallocFailed ) goto whereBeginError;
150454
150455 /* Special case: WHERE terms that do not refer to any tables in the join
150456 ** (constant expressions). Evaluate each such term, and jump over all the
150457 ** generated code if the result is not true.
150458 **
150459 ** Do not do this if the expression contains non-deterministic functions
150460 ** that are not within a sub-select. This is not strictly required, but
150461 ** preserves SQLite's legacy behaviour in the following two cases:
150462 **
150463 ** FROM ... WHERE random()>0; -- eval random() once per row
150464 ** FROM ... WHERE (SELECT random())>0; -- eval random() once overall
150465 */
150466 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
150467 WhereTerm *pT = &sWLB.pWC->a[ii];
150468 if( pT->wtFlags & TERM_VIRTUAL ) continue;
150469 if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){
150470 sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL);
150471 pT->wtFlags |= TERM_CODED;
150472 }
150473 }
150474
150475 if( wctrlFlags & WHERE_WANT_DISTINCT ){
150476 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
150477 /* The DISTINCT marking is pointless. Ignore it. */
150478 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
150479 }else if( pOrderBy==0 ){
150480 /* Try to ORDER BY the result set to make distinct processing easier */
150481 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
150482 pWInfo->pOrderBy = pResultSet;
150483 }
150484 }
150485
150486 /* Construct the WhereLoop objects */
150487#if defined(WHERETRACE_ENABLED)
150488 if( sqlite3WhereTrace & 0xffff ){
150489 sqlite3DebugPrintf("*** Optimizer Start *** (wctrlFlags: 0x%x",wctrlFlags);
150490 if( wctrlFlags & WHERE_USE_LIMIT ){
150491 sqlite3DebugPrintf(", limit: %d", iAuxArg);
150492 }
150493 sqlite3DebugPrintf(")\n");
150494 if( sqlite3WhereTrace & 0x100 ){
150495 Select sSelect;
150496 memset(&sSelect, 0, sizeof(sSelect));
150497 sSelect.selFlags = SF_WhereBegin;
150498 sSelect.pSrc = pTabList;
150499 sSelect.pWhere = pWhere;
150500 sSelect.pOrderBy = pOrderBy;
150501 sSelect.pEList = pResultSet;
150502 sqlite3TreeViewSelect(0, &sSelect, 0);
150503 }
150504 }
150505 if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
150506 sqlite3DebugPrintf("---- WHERE clause at start of analysis:\n");
150507 sqlite3WhereClausePrint(sWLB.pWC);
150508 }
150509#endif
150510
150511 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
150512 rc = whereLoopAddAll(&sWLB);
150513 if( rc ) goto whereBeginError;
150514
150515#ifdef SQLITE_ENABLE_STAT4
150516 /* If one or more WhereTerm.truthProb values were used in estimating
150517 ** loop parameters, but then those truthProb values were subsequently
150518 ** changed based on STAT4 information while computing subsequent loops,
150519 ** then we need to rerun the whole loop building process so that all
150520 ** loops will be built using the revised truthProb values. */
150521 if( sWLB.bldFlags2 & SQLITE_BLDF2_2NDPASS ){
150522 WHERETRACE_ALL_LOOPS(pWInfo, sWLB.pWC);
150523 WHERETRACE(0xffff,
150524 ("**** Redo all loop computations due to"
150525 " TERM_HIGHTRUTH changes ****\n"));
150526 while( pWInfo->pLoops ){
150527 WhereLoop *p = pWInfo->pLoops;
150528 pWInfo->pLoops = p->pNextLoop;
150529 whereLoopDelete(db, p);
150530 }
150531 rc = whereLoopAddAll(&sWLB);
150532 if( rc ) goto whereBeginError;
150533 }
150534#endif
150535 WHERETRACE_ALL_LOOPS(pWInfo, sWLB.pWC);
150536
150537 wherePathSolver(pWInfo, 0);
150538 if( db->mallocFailed ) goto whereBeginError;
150539 if( pWInfo->pOrderBy ){
150540 wherePathSolver(pWInfo, pWInfo->nRowOut+1);
150541 if( db->mallocFailed ) goto whereBeginError;
150542 }
150543 }
150544 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
150545 pWInfo->revMask = ALLBITS;
150546 }
150547 if( pParse->nErr || NEVER(db->mallocFailed) ){
150548 goto whereBeginError;
150549 }
150550#ifdef WHERETRACE_ENABLED
150551 if( sqlite3WhereTrace ){
150552 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
150553 if( pWInfo->nOBSat>0 ){
150554 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
150555 }
150556 switch( pWInfo->eDistinct ){
150557 case WHERE_DISTINCT_UNIQUE: {
150558 sqlite3DebugPrintf(" DISTINCT=unique");
150559 break;
150560 }
150561 case WHERE_DISTINCT_ORDERED: {
150562 sqlite3DebugPrintf(" DISTINCT=ordered");
150563 break;
150564 }
150566 sqlite3DebugPrintf(" DISTINCT=unordered");
150567 break;
150568 }
150569 }
150570 sqlite3DebugPrintf("\n");
150571 for(ii=0; ii<pWInfo->nLevel; ii++){
150572 sqlite3WhereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
150573 }
150574 }
150575#endif
150576
150577 /* Attempt to omit tables from the join that do not affect the result.
150578 ** For a table to not affect the result, the following must be true:
150579 **
150580 ** 1) The query must not be an aggregate.
150581 ** 2) The table must be the RHS of a LEFT JOIN.
150582 ** 3) Either the query must be DISTINCT, or else the ON or USING clause
150583 ** must contain a constraint that limits the scan of the table to
150584 ** at most a single row.
150585 ** 4) The table must not be referenced by any part of the query apart
150586 ** from its own USING or ON clause.
150587 **
150588 ** For example, given:
150589 **
150590 ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
150591 ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
150592 ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
150593 **
150594 ** then table t2 can be omitted from the following:
150595 **
150596 ** SELECT v1, v3 FROM t1
150597 ** LEFT JOIN t2 ON (t1.ipk=t2.ipk)
150598 ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
150599 **
150600 ** or from:
150601 **
150602 ** SELECT DISTINCT v1, v3 FROM t1
150603 ** LEFT JOIN t2
150604 ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
150605 */
150606 notReady = ~(Bitmask)0;
150607 if( pWInfo->nLevel>=2
150608 && pResultSet!=0 /* guarantees condition (1) above */
150610 ){
150611 int i;
150612 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
150613 if( sWLB.pOrderBy ){
150614 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
150615 }
150616 for(i=pWInfo->nLevel-1; i>=1; i--){
150617 WhereTerm *pTerm, *pEnd;
150618 struct SrcList_item *pItem;
150619 pLoop = pWInfo->a[i].pWLoop;
150620 pItem = &pWInfo->pTabList->a[pLoop->iTab];
150621 if( (pItem->fg.jointype & JT_LEFT)==0 ) continue;
150622 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
150623 && (pLoop->wsFlags & WHERE_ONEROW)==0
150624 ){
150625 continue;
150626 }
150627 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
150628 pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
150629 for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
150630 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
150631 if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
150632 || pTerm->pExpr->iRightJoinTable!=pItem->iCursor
150633 ){
150634 break;
150635 }
150636 }
150637 }
150638 if( pTerm<pEnd ) continue;
150639 WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
150640 notReady &= ~pLoop->maskSelf;
150641 for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
150642 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
150643 pTerm->wtFlags |= TERM_CODED;
150644 }
150645 }
150646 if( i!=pWInfo->nLevel-1 ){
150647 int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel);
150648 memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte);
150649 }
150650 pWInfo->nLevel--;
150651 nTabList--;
150652 }
150653 }
150654#if defined(WHERETRACE_ENABLED)
150655 if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
150656 sqlite3DebugPrintf("---- WHERE clause at end of analysis:\n");
150657 sqlite3WhereClausePrint(sWLB.pWC);
150658 }
150659 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
150660#endif
150661 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
150662
150663 /* If the caller is an UPDATE or DELETE statement that is requesting
150664 ** to use a one-pass algorithm, determine if this is appropriate.
150665 **
150666 ** A one-pass approach can be used if the caller has requested one
150667 ** and either (a) the scan visits at most one row or (b) each
150668 ** of the following are true:
150669 **
150670 ** * the caller has indicated that a one-pass approach can be used
150671 ** with multiple rows (by setting WHERE_ONEPASS_MULTIROW), and
150672 ** * the table is not a virtual table, and
150673 ** * either the scan does not use the OR optimization or the caller
150674 ** is a DELETE operation (WHERE_DUPLICATES_OK is only specified
150675 ** for DELETE).
150676 **
150677 ** The last qualification is because an UPDATE statement uses
150678 ** WhereInfo.aiCurOnePass[1] to determine whether or not it really can
150679 ** use a one-pass approach, and this is not set accurately for scans
150680 ** that use the OR optimization.
150681 */
150682 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
150683 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){
150684 int wsFlags = pWInfo->a[0].pWLoop->wsFlags;
150685 int bOnerow = (wsFlags & WHERE_ONEROW)!=0;
150686 assert( !(wsFlags & WHERE_VIRTUALTABLE) || IsVirtual(pTabList->a[0].pTab) );
150687 if( bOnerow || (
150688 0!=(wctrlFlags & WHERE_ONEPASS_MULTIROW)
150689 && !IsVirtual(pTabList->a[0].pTab)
150690 && (0==(wsFlags & WHERE_MULTI_OR) || (wctrlFlags & WHERE_DUPLICATES_OK))
150691 )){
150692 pWInfo->eOnePass = bOnerow ? ONEPASS_SINGLE : ONEPASS_MULTI;
150693 if( HasRowid(pTabList->a[0].pTab) && (wsFlags & WHERE_IDX_ONLY) ){
150694 if( wctrlFlags & WHERE_ONEPASS_MULTIROW ){
150695 bFordelete = OPFLAG_FORDELETE;
150696 }
150697 pWInfo->a[0].pWLoop->wsFlags = (wsFlags & ~WHERE_IDX_ONLY);
150698 }
150699 }
150700 }
150701
150702 /* Open all tables in the pTabList and any indices selected for
150703 ** searching those tables.
150704 */
150705 for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
150706 Table *pTab; /* Table to open */
150707 int iDb; /* Index of database containing table/index */
150708 struct SrcList_item *pTabItem;
150709
150710 pTabItem = &pTabList->a[pLevel->iFrom];
150711 pTab = pTabItem->pTab;
150712 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
150713 pLoop = pLevel->pWLoop;
150714 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
150715 /* Do nothing */
150716 }else
150717#ifndef SQLITE_OMIT_VIRTUALTABLE
150718 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
150719 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
150720 int iCur = pTabItem->iCursor;
150721 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
150722 }else if( IsVirtual(pTab) ){
150723 /* noop */
150724 }else
150725#endif
150726 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
150727 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
150728 int op = OP_OpenRead;
150729 if( pWInfo->eOnePass!=ONEPASS_OFF ){
150730 op = OP_OpenWrite;
150731 pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
150732 };
150733 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
150734 assert( pTabItem->iCursor==pLevel->iTabCur );
150735 testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 );
150736 testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS );
150737 if( pWInfo->eOnePass==ONEPASS_OFF
150738 && pTab->nCol<BMS
150739 && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
150740 ){
150741 /* If we know that only a prefix of the record will be used,
150742 ** it is advantageous to reduce the "column count" field in
150743 ** the P4 operand of the OP_OpenRead/Write opcode. */
150744 Bitmask b = pTabItem->colUsed;
150745 int n = 0;
150746 for(; b; b=b>>1, n++){}
150748 assert( n<=pTab->nCol );
150749 }
150750#ifdef SQLITE_ENABLE_CURSOR_HINTS
150751 if( pLoop->u.btree.pIndex!=0 ){
150752 sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ|bFordelete);
150753 }else
150754#endif
150755 {
150756 sqlite3VdbeChangeP5(v, bFordelete);
150757 }
150758#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
150759 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
150760 (const u8*)&pTabItem->colUsed, P4_INT64);
150761#endif
150762 }else{
150763 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
150764 }
150765 if( pLoop->wsFlags & WHERE_INDEXED ){
150766 Index *pIx = pLoop->u.btree.pIndex;
150767 int iIndexCur;
150768 int op = OP_OpenRead;
150769 /* iAuxArg is always set to a positive value if ONEPASS is possible */
150770 assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
150771 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
150772 && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
150773 ){
150774 /* This is one term of an OR-optimization using the PRIMARY KEY of a
150775 ** WITHOUT ROWID table. No need for a separate index */
150776 iIndexCur = pLevel->iTabCur;
150777 op = 0;
150778 }else if( pWInfo->eOnePass!=ONEPASS_OFF ){
150779 Index *pJ = pTabItem->pTab->pIndex;
150780 iIndexCur = iAuxArg;
150781 assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
150782 while( ALWAYS(pJ) && pJ!=pIx ){
150783 iIndexCur++;
150784 pJ = pJ->pNext;
150785 }
150786 op = OP_OpenWrite;
150787 pWInfo->aiCurOnePass[1] = iIndexCur;
150788 }else if( iAuxArg && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 ){
150789 iIndexCur = iAuxArg;
150790 op = OP_ReopenIdx;
150791 }else{
150792 iIndexCur = pParse->nTab++;
150793 }
150794 pLevel->iIdxCur = iIndexCur;
150795 assert( pIx->pSchema==pTab->pSchema );
150796 assert( iIndexCur>=0 );
150797 if( op ){
150798 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
150799 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
150800 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
150801 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
150802 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0
150803 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
150804 && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
150805 ){
150807 }
150808 VdbeComment((v, "%s", pIx->zName));
150809#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
150810 {
150811 u64 colUsed = 0;
150812 int ii, jj;
150813 for(ii=0; ii<pIx->nColumn; ii++){
150814 jj = pIx->aiColumn[ii];
150815 if( jj<0 ) continue;
150816 if( jj>63 ) jj = 63;
150817 if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
150818 colUsed |= ((u64)1)<<(ii<63 ? ii : 63);
150819 }
150820 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
150821 (u8*)&colUsed, P4_INT64);
150822 }
150823#endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
150824 }
150825 }
150826 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
150827 }
150828 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
150829 if( db->mallocFailed ) goto whereBeginError;
150830
150831 /* Generate the code to do the search. Each iteration of the for
150832 ** loop below generates code for a single nested loop of the VM
150833 ** program.
150834 */
150835 for(ii=0; ii<nTabList; ii++){
150836 int addrExplain;
150837 int wsFlags;
150838 pLevel = &pWInfo->a[ii];
150839 wsFlags = pLevel->pWLoop->wsFlags;
150840#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
150841 if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
150842 constructAutomaticIndex(pParse, &pWInfo->sWC,
150843 &pTabList->a[pLevel->iFrom], notReady, pLevel);
150844 if( db->mallocFailed ) goto whereBeginError;
150845 }
150846#endif
150847 addrExplain = sqlite3WhereExplainOneScan(
150848 pParse, pTabList, pLevel, wctrlFlags
150849 );
150850 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
150851 notReady = sqlite3WhereCodeOneLoopStart(pParse,v,pWInfo,ii,pLevel,notReady);
150852 pWInfo->iContinue = pLevel->addrCont;
150853 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
150854 sqlite3WhereAddScanStatus(v, pTabList, pLevel, addrExplain);
150855 }
150856 }
150857
150858 /* Done. */
150859 VdbeModuleComment((v, "Begin WHERE-core"));
150860 return pWInfo;
150861
150862 /* Jump here if malloc fails */
150863whereBeginError:
#define SQLITE_BLDF2_2NDPASS
Definition sqlite3.c:141337
#define SQLITE_DistinctOpt
Definition sqlite3.c:17045
#define initMaskSet(P)
Definition sqlite3.c:141312
#define WHERETRACE_ALL_LOOPS(W, C)
Definition sqlite3.c:150204
static void whereLoopDelete(sqlite3 *db, WhereLoop *p)
Definition sqlite3.c:147531
#define WHERE_DISTINCTBY
Definition sqlite3.c:18311
#define WHERE_CONSTRAINT
Definition sqlite3.c:141516
#define SQLITE_OmitNoopJoin
Definition sqlite3.c:17049
#define SF_WhereBegin
Definition sqlite3.c:18490
#define WHERE_COLUMN_RANGE
Definition sqlite3.c:141513
#define WHERE_BIGNULL_SORT
Definition sqlite3.c:141532
SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse *, struct SrcList_item *, WhereClause *)
Definition sqlite3.c:145566
SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(Parse *pParse, Vdbe *v, WhereInfo *pWInfo, int iLevel, WhereLevel *pLevel, Bitmask notReady)
Definition sqlite3.c:142790
SQLITE_PRIVATE int sqlite3WhereExplainOneScan(Parse *pParse, SrcList *pTabList, WhereLevel *pLevel, u16 wctrlFlags)
Definition sqlite3.c:141637
static int whereLoopAddAll(WhereLoopBuilder *pBuilder)
Definition sqlite3.c:149207
static void constructAutomaticIndex(Parse *pParse, WhereClause *pWC, struct SrcList_item *pSrc, Bitmask notReady, WhereLevel *pLevel)
Definition sqlite3.c:146302
#define WHERE_SKIPSCAN
Definition sqlite3.c:141528
static void createMask(WhereMaskSet *pMaskSet, int iCursor)
Definition sqlite3.c:145838
#define WHERETRACE(K, X)
Definition sqlite3.c:140945
static void whereLoopInit(WhereLoop *p)
Definition sqlite3.c:147460
static int isDistinctRedundant(Parse *pParse, SrcList *pTabList, WhereClause *pWC, ExprList *pDistinct)
Definition sqlite3.c:146110
static int exprIsDeterministic(Expr *p)
Definition sqlite3.c:150175
static int whereShortCut(WhereLoopBuilder *pBuilder)
Definition sqlite3.c:150080
#define WHERE_ONEROW
Definition sqlite3.c:141525
static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst)
Definition sqlite3.c:149688
#define sqlite3WhereAddScanStatus(a, b, c, d)
Definition sqlite3.c:141452
WhereLevel a[1]
Definition sqlite3.c:141410
int iContinue
Definition sqlite3.c:141390
int aiCurOnePass[2]
Definition sqlite3.c:141389
LogEst iLimit
Definition sqlite3.c:141394
WhereClause sWC
Definition sqlite3.c:141408
ExprList * pResultSet
Definition sqlite3.c:141387
Expr * pWhere
Definition sqlite3.c:141388
int savedNQueryLoop
Definition sqlite3.c:141392
ExprList * pOrderBy
Definition sqlite3.c:141321
unsigned char bldFlags2
Definition sqlite3.c:141329
WhereLoop * pNew
Definition sqlite3.c:141322
WhereClause * pWC
Definition sqlite3.c:141320
Bitmask maskSelf
Definition sqlite3.c:141033
WhereLoop * pNextLoop
Definition sqlite3.c:141065

References SrcList::a, WhereClause::a, WhereInfo::a, WhereLevel::addrBody, WhereLevel::addrCont, Index::aiColumn, WhereInfo::aiCurOnePass, ALLBITS, ALWAYS, WhereLoopBuilder::bldFlags2, BMS, WhereLoop::btree, constructAutomaticIndex(), createMask(), Parse::db, WhereInfo::eDistinct, EIGHT_BYTE_ALIGNMENT, WhereInfo::eOnePass, EP_FromJoin, ExplainQueryPlan, ExprHasProperty, exprIsDeterministic(), sqlite3::flags, HasRowid, WhereInfo::iBreak, WhereInfo::iContinue, SrcList::SrcList_item::iCursor, WhereLevel::iFrom, WhereLevel::iIdxCur, WhereInfo::iLimit, initMaskSet, Expr::iRightJoinTable, isDistinctRedundant(), IsPrimaryKeyIndex, IsVirtual, WhereLoop::iTab, WhereLevel::iTabCur, WhereInfo::iTop, JT_LEFT, sqlite3::mallocFailed, MASKBIT, WhereLoop::maskSelf, Table::nCol, Index::nColumn, Parse::nErr, NEVER, ExprList::nExpr, WhereInfo::nLevel, WhereInfo::nOBSat, Parse::nQueryLoop, WhereInfo::nRowOut, SrcList::nSrc, Parse::nTab, WhereClause::nTerm, offsetof, ONEPASS_MULTI, ONEPASS_OFF, ONEPASS_SINGLE, OP_ColumnsUsed, OP_OpenRead, OP_OpenWrite, OP_ReopenIdx, OP_VOpen, OPFLAG_FORDELETE, OPFLAG_SEEKEQ, OptimizationDisabled, OptimizationEnabled, P4_INT32, P4_INT64, P4_VTAB, Select::pEList, WhereTerm::pExpr, WhereLoop::pIndex, WhereInfo::pLoops, WhereLoopBuilder::pNew, Index::pNext, WhereLoop::pNextLoop, Select::pOrderBy, WhereLoopBuilder::pOrderBy, WhereInfo::pOrderBy, WhereInfo::pParse, WhereTerm::prereqAll, WhereInfo::pResultSet, Table::pSchema, Index::pSchema, Table::pSelect, Select::pSrc, SrcList::SrcList_item::pTab, WhereInfo::pTabList, Parse::pVdbe, WhereLoopBuilder::pWC, Select::pWhere, WhereInfo::pWhere, WhereLoopBuilder::pWInfo, WhereLevel::pWLoop, WhereInfo::revMask, ROUND8, WhereInfo::savedNQueryLoop, Select::selFlags, SF_WhereBegin, WhereInfo::sMaskSet, sqlite3CodeVerifySchema(), sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3ErrorMsg(), sqlite3ExprIfFalse(), sqlite3GetVTable(), sqlite3OpenTable(), sqlite3SchemaToIndex(), sqlite3TableLock(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Dup8(), sqlite3VdbeChangeP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeMakeLabel(), sqlite3VdbeSetP4KeyInfo(), sqlite3WhereAddScanStatus, sqlite3WhereClauseInit(), sqlite3WhereCodeOneLoopStart(), sqlite3WhereExplainOneScan(), sqlite3WhereExprAnalyze(), sqlite3WhereExprListUsage(), sqlite3WhereGetMask(), sqlite3WhereSplit(), sqlite3WhereTabFuncArgs(), SQLITE_BLDF2_2NDPASS, SQLITE_DistinctOpt, SQLITE_INT_TO_PTR, SQLITE_JUMPIFNULL, SQLITE_OmitNoopJoin, SQLITE_ReverseOrder, WhereInfo::sWC, Table::tabFlags, TERM_CODED, TERM_VIRTUAL, testcase, TF_Ephemeral, TF_HasGenerated, TF_WithoutRowid, TK_AND, Table::tnum, Index::tnum, WhereLoop::u, VdbeComment, VdbeModuleComment, WhereInfo::wctrlFlags, WHERE_AUTO_INDEX, WHERE_BIGNULL_SORT, WHERE_COLUMN_RANGE, WHERE_CONSTRAINT, WHERE_DISTINCT_ORDERED, WHERE_DISTINCT_UNIQUE, WHERE_DISTINCT_UNORDERED, WHERE_DISTINCTBY, WHERE_DUPLICATES_OK, WHERE_IDX_ONLY, WHERE_INDEXED, WHERE_MULTI_OR, WHERE_ONEPASS_DESIRED, WHERE_ONEPASS_MULTIROW, WHERE_ONEROW, WHERE_OR_SUBCLAUSE, WHERE_ORDERBY_MIN, WHERE_SKIPSCAN, WHERE_USE_LIMIT, WHERE_VIRTUALTABLE, WHERE_WANT_DISTINCT, whereInfoFree(), whereLoopAddAll(), whereLoopDelete(), whereLoopInit(), wherePathSolver(), whereShortCut(), WHERETRACE, WHERETRACE_ALL_LOOPS, WhereLoop::wsFlags, WhereTerm::wtFlags, Table::zName, and Index::zName.

Referenced by fkScanChildren(), sqlite3DeleteFrom(), sqlite3Select(), sqlite3Update(), and updateVirtualTable().

◆ sqlite3WhereBreakLabel()

SQLITE_PRIVATE int sqlite3WhereBreakLabel ( WhereInfo * pWInfo)

Definition at line 145726 of file sqlite3.c.

Referenced by sqlite3Select().

◆ sqlite3WhereClauseClear()

SQLITE_PRIVATE void sqlite3WhereClauseClear ( WhereClause * pWC)

Definition at line 145473 of file sqlite3.c.

145479 {
145480 int i;
145481 WhereTerm *a;
145482 sqlite3 *db = pWC->pWInfo->pParse->db;
145483 for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){
145484 if( a->wtFlags & TERM_DYNAMIC ){
145485 sqlite3ExprDelete(db, a->pExpr);
145486 }
145487 if( a->wtFlags & TERM_ORINFO ){
145488 whereOrInfoDelete(db, a->u.pOrInfo);
145489 }else if( a->wtFlags & TERM_ANDINFO ){
145490 whereAndInfoDelete(db, a->u.pAndInfo);
static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p)
Definition sqlite3.c:144026
static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p)
Definition sqlite3.c:144018

References WhereClause::a, WhereClause::aStatic, Parse::db, WhereClause::nTerm, WhereInfo::pParse, WhereClause::pWInfo, sqlite3DbFree(), sqlite3ExprDelete(), TERM_ANDINFO, TERM_DYNAMIC, TERM_ORINFO, whereAndInfoDelete(), and whereOrInfoDelete().

◆ sqlite3WhereClauseInit()

SQLITE_PRIVATE void sqlite3WhereClauseInit ( WhereClause * pWC,
WhereInfo * pWInfo )

Definition at line 145456 of file sqlite3.c.

145465 {
145466 pWC->pWInfo = pWInfo;

Referenced by exprAnalyzeOrTerm(), and sqlite3WhereBegin().

◆ sqlite3WhereCodeOneLoopStart()

SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart ( Parse * pParse,
Vdbe * v,
WhereInfo * pWInfo,
int iLevel,
WhereLevel * pLevel,
Bitmask notReady )

Definition at line 142790 of file sqlite3.c.

142803 {
142804 int j, k; /* Loop counters */
142805 int iCur; /* The VDBE cursor for the table */
142806 int addrNxt; /* Where to jump to continue with the next IN case */
142807 int bRev; /* True if we need to scan in reverse order */
142808 WhereLoop *pLoop; /* The WhereLoop object being coded */
142809 WhereClause *pWC; /* Decomposition of the entire WHERE clause */
142810 WhereTerm *pTerm; /* A WHERE clause term */
142811 sqlite3 *db; /* Database connection */
142812 struct SrcList_item *pTabItem; /* FROM clause term being coded */
142813 int addrBrk; /* Jump here to break out of the loop */
142814 int addrHalt; /* addrBrk for the outermost loop */
142815 int addrCont; /* Jump here to continue with next cycle */
142816 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
142817 int iReleaseReg = 0; /* Temp register to free before returning */
142818 Index *pIdx = 0; /* Index used by loop (if any) */
142819 int iLoop; /* Iteration of constraint generator loop */
142820
142821 pWC = &pWInfo->sWC;
142822 db = pParse->db;
142823 pLoop = pLevel->pWLoop;
142824 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
142825 iCur = pTabItem->iCursor;
142826 pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
142827 bRev = (pWInfo->revMask>>iLevel)&1;
142828 VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
142829#if WHERETRACE_ENABLED /* 0x20800 */
142830 if( sqlite3WhereTrace & 0x800 ){
142831 sqlite3DebugPrintf("Coding level %d of %d: notReady=%llx iFrom=%d\n",
142832 iLevel, pWInfo->nLevel, (u64)notReady, pLevel->iFrom);
142833 sqlite3WhereLoopPrint(pLoop, pWC);
142834 }
142835 if( sqlite3WhereTrace & 0x20000 ){
142836 if( iLevel==0 ){
142837 sqlite3DebugPrintf("WHERE clause being coded:\n");
142838 sqlite3TreeViewExpr(0, pWInfo->pWhere, 0);
142839 }
142840 sqlite3DebugPrintf("All WHERE-clause terms before coding:\n");
142841 sqlite3WhereClausePrint(pWC);
142842 }
142843#endif
142844
142845 /* Create labels for the "break" and "continue" instructions
142846 ** for the current loop. Jump to addrBrk to break out of a loop.
142847 ** Jump to cont to go immediately to the next iteration of the
142848 ** loop.
142849 **
142850 ** When there is an IN operator, we also have a "addrNxt" label that
142851 ** means to continue with the next IN value combination. When
142852 ** there are no IN operators in the constraints, the "addrNxt" label
142853 ** is the same as "addrBrk".
142854 */
142855 addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
142856 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
142857
142858 /* If this is the right table of a LEFT OUTER JOIN, allocate and
142859 ** initialize a memory cell that records if this table matches any
142860 ** row of the left table of the join.
142861 */
142862 assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
142863 || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
142864 );
142865 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
142866 pLevel->iLeftJoin = ++pParse->nMem;
142867 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
142868 VdbeComment((v, "init LEFT JOIN no-match flag"));
142869 }
142870
142871 /* Compute a safe address to jump to if we discover that the table for
142872 ** this loop is empty and can never contribute content. */
142873 for(j=iLevel; j>0 && pWInfo->a[j].iLeftJoin==0; j--){}
142874 addrHalt = pWInfo->a[j].addrBrk;
142875
142876 /* Special case of a FROM clause subquery implemented as a co-routine */
142877 if( pTabItem->fg.viaCoroutine ){
142878 int regYield = pTabItem->regReturn;
142879 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
142880 pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
142881 VdbeCoverage(v);
142882 VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
142883 pLevel->op = OP_Goto;
142884 }else
142885
142886#ifndef SQLITE_OMIT_VIRTUALTABLE
142887 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
142888 /* Case 1: The table is a virtual-table. Use the VFilter and VNext
142889 ** to access the data.
142890 */
142891 int iReg; /* P3 Value for OP_VFilter */
142892 int addrNotFound;
142893 int nConstraint = pLoop->nLTerm;
142894 int iIn; /* Counter for IN constraints */
142895
142896 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
142897 addrNotFound = pLevel->addrBrk;
142898 for(j=0; j<nConstraint; j++){
142899 int iTarget = iReg+j+2;
142900 pTerm = pLoop->aLTerm[j];
142901 if( NEVER(pTerm==0) ) continue;
142902 if( pTerm->eOperator & WO_IN ){
142903 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
142904 addrNotFound = pLevel->addrNxt;
142905 }else{
142906 Expr *pRight = pTerm->pExpr->pRight;
142907 codeExprOrVector(pParse, pRight, iTarget, 1);
142908 }
142909 }
142910 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
142911 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
142912 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
142913 pLoop->u.vtab.idxStr,
142914 pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
142915 VdbeCoverage(v);
142916 pLoop->u.vtab.needFree = 0;
142917 pLevel->p1 = iCur;
142918 pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
142919 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
142920 iIn = pLevel->u.in.nIn;
142921 for(j=nConstraint-1; j>=0; j--){
142922 pTerm = pLoop->aLTerm[j];
142923 if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
142924 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
142925 disableTerm(pLevel, pTerm);
142926 }else if( (pTerm->eOperator & WO_IN)!=0
142927 && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1
142928 ){
142929 Expr *pCompare; /* The comparison operator */
142930 Expr *pRight; /* RHS of the comparison */
142931 VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
142932
142933 /* Reload the constraint value into reg[iReg+j+2]. The same value
142934 ** was loaded into the same register prior to the OP_VFilter, but
142935 ** the xFilter implementation might have changed the datatype or
142936 ** encoding of the value in the register, so it *must* be reloaded. */
142937 assert( pLevel->u.in.aInLoop!=0 || db->mallocFailed );
142938 if( !db->mallocFailed ){
142939 assert( iIn>=0 && iIn<pLevel->u.in.nIn );
142940 pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[iIn].addrInTop);
142941 assert( pOp->opcode==OP_Column || pOp->opcode==OP_Rowid );
142942 assert( pOp->opcode!=OP_Column || pOp->p3==iReg+j+2 );
142943 assert( pOp->opcode!=OP_Rowid || pOp->p2==iReg+j+2 );
142944 testcase( pOp->opcode==OP_Rowid );
142945 sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3);
142946 }
142947
142948 /* Generate code that will continue to the next row if
142949 ** the IN constraint is not satisfied */
142950 pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
142951 assert( pCompare!=0 || db->mallocFailed );
142952 if( pCompare ){
142953 pCompare->pLeft = pTerm->pExpr->pLeft;
142954 pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
142955 if( pRight ){
142956 pRight->iTable = iReg+j+2;
142958 pParse, pCompare, pLevel->addrCont, SQLITE_JUMPIFNULL
142959 );
142960 }
142961 pCompare->pLeft = 0;
142962 sqlite3ExprDelete(db, pCompare);
142963 }
142964 }
142965 }
142966 assert( iIn==0 || db->mallocFailed );
142967 /* These registers need to be preserved in case there is an IN operator
142968 ** loop. So we could deallocate the registers here (and potentially
142969 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
142970 ** simpler and safer to simply not reuse the registers.
142971 **
142972 ** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
142973 */
142974 }else
142975#endif /* SQLITE_OMIT_VIRTUALTABLE */
142976
142977 if( (pLoop->wsFlags & WHERE_IPK)!=0
142978 && (pLoop->wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_EQ))!=0
142979 ){
142980 /* Case 2: We can directly reference a single row using an
142981 ** equality comparison against the ROWID field. Or
142982 ** we reference multiple rows using a "rowid IN (...)"
142983 ** construct.
142984 */
142985 assert( pLoop->u.btree.nEq==1 );
142986 pTerm = pLoop->aLTerm[0];
142987 assert( pTerm!=0 );
142988 assert( pTerm->pExpr!=0 );
142989 testcase( pTerm->wtFlags & TERM_VIRTUAL );
142990 iReleaseReg = ++pParse->nMem;
142991 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
142992 if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
142993 addrNxt = pLevel->addrNxt;
142994 sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
142995 VdbeCoverage(v);
142996 pLevel->op = OP_Noop;
142997 if( (pTerm->prereqAll & pLevel->notReady)==0 ){
142998 pTerm->wtFlags |= TERM_CODED;
142999 }
143000 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
143001 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
143002 ){
143003 /* Case 3: We have an inequality comparison against the ROWID field.
143004 */
143005 int testOp = OP_Noop;
143006 int start;
143007 int memEndValue = 0;
143008 WhereTerm *pStart, *pEnd;
143009
143010 j = 0;
143011 pStart = pEnd = 0;
143012 if( pLoop->wsFlags & WHERE_BTM_LIMIT ) pStart = pLoop->aLTerm[j++];
143013 if( pLoop->wsFlags & WHERE_TOP_LIMIT ) pEnd = pLoop->aLTerm[j++];
143014 assert( pStart!=0 || pEnd!=0 );
143015 if( bRev ){
143016 pTerm = pStart;
143017 pStart = pEnd;
143018 pEnd = pTerm;
143019 }
143020 codeCursorHint(pTabItem, pWInfo, pLevel, pEnd);
143021 if( pStart ){
143022 Expr *pX; /* The expression that defines the start bound */
143023 int r1, rTemp; /* Registers for holding the start boundary */
143024 int op; /* Cursor seek operation */
143025
143026 /* The following constant maps TK_xx codes into corresponding
143027 ** seek opcodes. It depends on a particular ordering of TK_xx
143028 */
143029 const u8 aMoveOp[] = {
143030 /* TK_GT */ OP_SeekGT,
143031 /* TK_LE */ OP_SeekLE,
143032 /* TK_LT */ OP_SeekLT,
143033 /* TK_GE */ OP_SeekGE
143034 };
143035 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
143036 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
143037 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
143038
143039 assert( (pStart->wtFlags & TERM_VNULL)==0 );
143040 testcase( pStart->wtFlags & TERM_VIRTUAL );
143041 pX = pStart->pExpr;
143042 assert( pX!=0 );
143043 testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
143044 if( sqlite3ExprIsVector(pX->pRight) ){
143045 r1 = rTemp = sqlite3GetTempReg(pParse);
143046 codeExprOrVector(pParse, pX->pRight, r1, 1);
143047 testcase( pX->op==TK_GT );
143048 testcase( pX->op==TK_GE );
143049 testcase( pX->op==TK_LT );
143050 testcase( pX->op==TK_LE );
143051 op = aMoveOp[((pX->op - TK_GT - 1) & 0x3) | 0x1];
143052 assert( pX->op!=TK_GT || op==OP_SeekGE );
143053 assert( pX->op!=TK_GE || op==OP_SeekGE );
143054 assert( pX->op!=TK_LT || op==OP_SeekLE );
143055 assert( pX->op!=TK_LE || op==OP_SeekLE );
143056 }else{
143057 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
143058 disableTerm(pLevel, pStart);
143059 op = aMoveOp[(pX->op - TK_GT)];
143060 }
143061 sqlite3VdbeAddOp3(v, op, iCur, addrBrk, r1);
143062 VdbeComment((v, "pk"));
143063 VdbeCoverageIf(v, pX->op==TK_GT);
143064 VdbeCoverageIf(v, pX->op==TK_LE);
143065 VdbeCoverageIf(v, pX->op==TK_LT);
143066 VdbeCoverageIf(v, pX->op==TK_GE);
143067 sqlite3ReleaseTempReg(pParse, rTemp);
143068 }else{
143069 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrHalt);
143070 VdbeCoverageIf(v, bRev==0);
143071 VdbeCoverageIf(v, bRev!=0);
143072 }
143073 if( pEnd ){
143074 Expr *pX;
143075 pX = pEnd->pExpr;
143076 assert( pX!=0 );
143077 assert( (pEnd->wtFlags & TERM_VNULL)==0 );
143078 testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */
143079 testcase( pEnd->wtFlags & TERM_VIRTUAL );
143080 memEndValue = ++pParse->nMem;
143081 codeExprOrVector(pParse, pX->pRight, memEndValue, 1);
143082 if( 0==sqlite3ExprIsVector(pX->pRight)
143083 && (pX->op==TK_LT || pX->op==TK_GT)
143084 ){
143085 testOp = bRev ? OP_Le : OP_Ge;
143086 }else{
143087 testOp = bRev ? OP_Lt : OP_Gt;
143088 }
143089 if( 0==sqlite3ExprIsVector(pX->pRight) ){
143090 disableTerm(pLevel, pEnd);
143091 }
143092 }
143093 start = sqlite3VdbeCurrentAddr(v);
143094 pLevel->op = bRev ? OP_Prev : OP_Next;
143095 pLevel->p1 = iCur;
143096 pLevel->p2 = start;
143097 assert( pLevel->p5==0 );
143098 if( testOp!=OP_Noop ){
143099 iRowidReg = ++pParse->nMem;
143100 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
143101 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
143102 VdbeCoverageIf(v, testOp==OP_Le);
143103 VdbeCoverageIf(v, testOp==OP_Lt);
143104 VdbeCoverageIf(v, testOp==OP_Ge);
143105 VdbeCoverageIf(v, testOp==OP_Gt);
143107 }
143108 }else if( pLoop->wsFlags & WHERE_INDEXED ){
143109 /* Case 4: A scan using an index.
143110 **
143111 ** The WHERE clause may contain zero or more equality
143112 ** terms ("==" or "IN" operators) that refer to the N
143113 ** left-most columns of the index. It may also contain
143114 ** inequality constraints (>, <, >= or <=) on the indexed
143115 ** column that immediately follows the N equalities. Only
143116 ** the right-most column can be an inequality - the rest must
143117 ** use the "==" and "IN" operators. For example, if the
143118 ** index is on (x,y,z), then the following clauses are all
143119 ** optimized:
143120 **
143121 ** x=5
143122 ** x=5 AND y=10
143123 ** x=5 AND y<10
143124 ** x=5 AND y>5 AND y<10
143125 ** x=5 AND y=5 AND z<=10
143126 **
143127 ** The z<10 term of the following cannot be used, only
143128 ** the x=5 term:
143129 **
143130 ** x=5 AND z<10
143131 **
143132 ** N may be zero if there are inequality constraints.
143133 ** If there are no inequality constraints, then N is at
143134 ** least one.
143135 **
143136 ** This case is also used when there are no WHERE clause
143137 ** constraints but an index is selected anyway, in order
143138 ** to force the output order to conform to an ORDER BY.
143139 */
143140 static const u8 aStartOp[] = {
143141 0,
143142 0,
143143 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
143144 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
143145 OP_SeekGT, /* 4: (start_constraints && !startEq && !bRev) */
143146 OP_SeekLT, /* 5: (start_constraints && !startEq && bRev) */
143147 OP_SeekGE, /* 6: (start_constraints && startEq && !bRev) */
143148 OP_SeekLE /* 7: (start_constraints && startEq && bRev) */
143149 };
143150 static const u8 aEndOp[] = {
143151 OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
143152 OP_IdxGT, /* 1: (end_constraints && !bRev && endEq) */
143153 OP_IdxLE, /* 2: (end_constraints && bRev && !endEq) */
143154 OP_IdxLT, /* 3: (end_constraints && bRev && endEq) */
143155 };
143156 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
143157 u16 nBtm = pLoop->u.btree.nBtm; /* Length of BTM vector */
143158 u16 nTop = pLoop->u.btree.nTop; /* Length of TOP vector */
143159 int regBase; /* Base register holding constraint values */
143160 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
143161 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
143162 int startEq; /* True if range start uses ==, >= or <= */
143163 int endEq; /* True if range end uses ==, >= or <= */
143164 int start_constraints; /* Start of range is constrained */
143165 int nConstraint; /* Number of constraint terms */
143166 int iIdxCur; /* The VDBE cursor for the index */
143167 int nExtraReg = 0; /* Number of extra registers needed */
143168 int op; /* Instruction opcode */
143169 char *zStartAff; /* Affinity for start of range constraint */
143170 char *zEndAff = 0; /* Affinity for end of range constraint */
143171 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
143172 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
143173 int omitTable; /* True if we use the index only */
143174 int regBignull = 0; /* big-null flag register */
143175
143176 pIdx = pLoop->u.btree.pIndex;
143177 iIdxCur = pLevel->iIdxCur;
143178 assert( nEq>=pLoop->nSkip );
143179
143180 /* Find any inequality constraint terms for the start and end
143181 ** of the range.
143182 */
143183 j = nEq;
143184 if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
143185 pRangeStart = pLoop->aLTerm[j++];
143186 nExtraReg = MAX(nExtraReg, pLoop->u.btree.nBtm);
143187 /* Like optimization range constraints always occur in pairs */
143188 assert( (pRangeStart->wtFlags & TERM_LIKEOPT)==0 ||
143189 (pLoop->wsFlags & WHERE_TOP_LIMIT)!=0 );
143190 }
143191 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
143192 pRangeEnd = pLoop->aLTerm[j++];
143193 nExtraReg = MAX(nExtraReg, pLoop->u.btree.nTop);
143194#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
143195 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
143196 assert( pRangeStart!=0 ); /* LIKE opt constraints */
143197 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
143198 pLevel->iLikeRepCntr = (u32)++pParse->nMem;
143199 sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
143200 VdbeComment((v, "LIKE loop counter"));
143201 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
143202 /* iLikeRepCntr actually stores 2x the counter register number. The
143203 ** bottom bit indicates whether the search order is ASC or DESC. */
143204 testcase( bRev );
143205 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
143206 assert( (bRev & ~1)==0 );
143207 pLevel->iLikeRepCntr <<=1;
143208 pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC);
143209 }
143210#endif
143211 if( pRangeStart==0 ){
143212 j = pIdx->aiColumn[nEq];
143213 if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
143214 bSeekPastNull = 1;
143215 }
143216 }
143217 }
143218 assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );
143219
143220 /* If the WHERE_BIGNULL_SORT flag is set, then index column nEq uses
143221 ** a non-default "big-null" sort (either ASC NULLS LAST or DESC NULLS
143222 ** FIRST). In both cases separate ordered scans are made of those
143223 ** index entries for which the column is null and for those for which
143224 ** it is not. For an ASC sort, the non-NULL entries are scanned first.
143225 ** For DESC, NULL entries are scanned first.
143226 */
143227 if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
143228 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
143229 ){
143230 assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
143231 assert( pRangeEnd==0 && pRangeStart==0 );
143232 testcase( pLoop->nSkip>0 );
143233 nExtraReg = 1;
143234 bSeekPastNull = 1;
143235 pLevel->regBignull = regBignull = ++pParse->nMem;
143236 if( pLevel->iLeftJoin ){
143237 sqlite3VdbeAddOp2(v, OP_Integer, 0, regBignull);
143238 }
143239 pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse);
143240 }
143241
143242 /* If we are doing a reverse order scan on an ascending index, or
143243 ** a forward order scan on a descending index, interchange the
143244 ** start and end terms (pRangeStart and pRangeEnd).
143245 */
143246 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
143247 || (bRev && pIdx->nKeyCol==nEq)
143248 ){
143249 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
143250 SWAP(u8, bSeekPastNull, bStopAtNull);
143251 SWAP(u8, nBtm, nTop);
143252 }
143253
143254 /* Generate code to evaluate all constraint terms using == or IN
143255 ** and store the values of those terms in an array of registers
143256 ** starting at regBase.
143257 */
143258 codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
143259 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
143260 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
143261 if( zStartAff && nTop ){
143262 zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
143263 }
143264 addrNxt = (regBignull ? pLevel->addrBignull : pLevel->addrNxt);
143265
143266 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
143267 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
143268 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
143269 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
143270 startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
143271 endEq = !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
143272 start_constraints = pRangeStart || nEq>0;
143273
143274 /* Seek the index cursor to the start of the range. */
143275 nConstraint = nEq;
143276 if( pRangeStart ){
143277 Expr *pRight = pRangeStart->pExpr->pRight;
143278 codeExprOrVector(pParse, pRight, regBase+nEq, nBtm);
143279 whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
143280 if( (pRangeStart->wtFlags & TERM_VNULL)==0
143281 && sqlite3ExprCanBeNull(pRight)
143282 ){
143283 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143284 VdbeCoverage(v);
143285 }
143286 if( zStartAff ){
143287 updateRangeAffinityStr(pRight, nBtm, &zStartAff[nEq]);
143288 }
143289 nConstraint += nBtm;
143290 testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
143291 if( sqlite3ExprIsVector(pRight)==0 ){
143292 disableTerm(pLevel, pRangeStart);
143293 }else{
143294 startEq = 1;
143295 }
143296 bSeekPastNull = 0;
143297 }else if( bSeekPastNull ){
143298 startEq = 0;
143299 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
143300 start_constraints = 1;
143301 nConstraint++;
143302 }else if( regBignull ){
143303 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
143304 start_constraints = 1;
143305 nConstraint++;
143306 }
143307 codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
143308 if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
143309 /* The skip-scan logic inside the call to codeAllEqualityConstraints()
143310 ** above has already left the cursor sitting on the correct row,
143311 ** so no further seeking is needed */
143312 }else{
143313 if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
143314 sqlite3VdbeAddOp1(v, OP_SeekHit, iIdxCur);
143315 }
143316 if( regBignull ){
143317 sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
143318 VdbeComment((v, "NULL-scan pass ctr"));
143319 }
143320
143321 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
143322 assert( op!=0 );
143323 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
143324 VdbeCoverage(v);
143325 VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
143326 VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
143327 VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
143328 VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
143329 VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
143330 VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT );
143331
143332 assert( bSeekPastNull==0 || bStopAtNull==0 );
143333 if( regBignull ){
143334 assert( bSeekPastNull==1 || bStopAtNull==1 );
143335 assert( bSeekPastNull==!bStopAtNull );
143336 assert( bStopAtNull==startEq );
143338 op = aStartOp[(nConstraint>1)*4 + 2 + bRev];
143339 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase,
143340 nConstraint-startEq);
143341 VdbeCoverage(v);
143342 VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
143343 VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
143344 VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
143345 VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
143346 assert( op==OP_Rewind || op==OP_Last || op==OP_SeekGE || op==OP_SeekLE);
143347 }
143348 }
143349
143350 /* Load the value for the inequality constraint at the end of the
143351 ** range (if any).
143352 */
143353 nConstraint = nEq;
143354 if( pRangeEnd ){
143355 Expr *pRight = pRangeEnd->pExpr->pRight;
143356 codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
143357 whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
143358 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
143359 && sqlite3ExprCanBeNull(pRight)
143360 ){
143361 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143362 VdbeCoverage(v);
143363 }
143364 if( zEndAff ){
143365 updateRangeAffinityStr(pRight, nTop, zEndAff);
143366 codeApplyAffinity(pParse, regBase+nEq, nTop, zEndAff);
143367 }else{
143368 assert( pParse->db->mallocFailed );
143369 }
143370 nConstraint += nTop;
143371 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
143372
143373 if( sqlite3ExprIsVector(pRight)==0 ){
143374 disableTerm(pLevel, pRangeEnd);
143375 }else{
143376 endEq = 1;
143377 }
143378 }else if( bStopAtNull ){
143379 if( regBignull==0 ){
143380 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
143381 endEq = 0;
143382 }
143383 nConstraint++;
143384 }
143385 sqlite3DbFree(db, zStartAff);
143386 sqlite3DbFree(db, zEndAff);
143387
143388 /* Top of the loop body */
143389 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
143390
143391 /* Check if the index cursor is past the end of the range. */
143392 if( nConstraint ){
143393 if( regBignull ){
143394 /* Except, skip the end-of-range check while doing the NULL-scan */
143395 sqlite3VdbeAddOp2(v, OP_IfNot, regBignull, sqlite3VdbeCurrentAddr(v)+3);
143396 VdbeComment((v, "If NULL-scan 2nd pass"));
143397 VdbeCoverage(v);
143398 }
143399 op = aEndOp[bRev*2 + endEq];
143400 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
143401 testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT );
143402 testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE );
143403 testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT );
143404 testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE );
143405 }
143406 if( regBignull ){
143407 /* During a NULL-scan, check to see if we have reached the end of
143408 ** the NULLs */
143409 assert( bSeekPastNull==!bStopAtNull );
143410 assert( bSeekPastNull+bStopAtNull==1 );
143411 assert( nConstraint+bSeekPastNull>0 );
143412 sqlite3VdbeAddOp2(v, OP_If, regBignull, sqlite3VdbeCurrentAddr(v)+2);
143413 VdbeComment((v, "If NULL-scan 1st pass"));
143414 VdbeCoverage(v);
143415 op = aEndOp[bRev*2 + bSeekPastNull];
143416 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase,
143417 nConstraint+bSeekPastNull);
143418 testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT );
143419 testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE );
143420 testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT );
143421 testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE );
143422 }
143423
143424 if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
143425 sqlite3VdbeAddOp2(v, OP_SeekHit, iIdxCur, 1);
143426 }
143427
143428 /* Seek the table cursor, if required */
143429 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
143430 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
143431 if( omitTable ){
143432 /* pIdx is a covering index. No need to access the main table. */
143433 }else if( HasRowid(pIdx->pTable) ){
143434 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)
143435 || ( (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)!=0
143436 && (pWInfo->eOnePass==ONEPASS_SINGLE || pLoop->nLTerm==0) )
143437 ){
143438 iRowidReg = ++pParse->nMem;
143439 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
143440 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
143441 VdbeCoverage(v);
143442 }else{
143443 codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);
143444 }
143445 }else if( iCur!=iIdxCur ){
143446 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
143447 iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
143448 for(j=0; j<pPk->nKeyCol; j++){
143449 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
143450 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
143451 }
143452 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
143453 iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
143454 }
143455
143456 if( pLevel->iLeftJoin==0 ){
143457 /* If pIdx is an index on one or more expressions, then look through
143458 ** all the expressions in pWInfo and try to transform matching expressions
143459 ** into reference to index columns. Also attempt to translate references
143460 ** to virtual columns in the table into references to (stored) columns
143461 ** of the index.
143462 **
143463 ** Do not do this for the RHS of a LEFT JOIN. This is because the
143464 ** expression may be evaluated after OP_NullRow has been executed on
143465 ** the cursor. In this case it is important to do the full evaluation,
143466 ** as the result of the expression may not be NULL, even if all table
143467 ** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a
143468 **
143469 ** Also, do not do this when processing one index an a multi-index
143470 ** OR clause, since the transformation will become invalid once we
143471 ** move forward to the next index.
143472 ** https://sqlite.org/src/info/4e8e4857d32d401f
143473 */
143474 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
143475 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
143476 }
143477
143478 /* If a partial index is driving the loop, try to eliminate WHERE clause
143479 ** terms from the query that must be true due to the WHERE clause of
143480 ** the partial index.
143481 **
143482 ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work
143483 ** for a LEFT JOIN.
143484 */
143485 if( pIdx->pPartIdxWhere ){
143487 }
143488 }else{
143489 testcase( pIdx->pPartIdxWhere );
143490 /* The following assert() is not a requirement, merely an observation:
143491 ** The OR-optimization doesn't work for the right hand table of
143492 ** a LEFT JOIN: */
143493 assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 );
143494 }
143495
143496 /* Record the instruction used to terminate the loop. */
143497 if( pLoop->wsFlags & WHERE_ONEROW ){
143498 pLevel->op = OP_Noop;
143499 }else if( bRev ){
143500 pLevel->op = OP_Prev;
143501 }else{
143502 pLevel->op = OP_Next;
143503 }
143504 pLevel->p1 = iIdxCur;
143505 pLevel->p3 = (pLoop->wsFlags&WHERE_UNQ_WANTED)!=0 ? 1:0;
143506 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
143508 }else{
143509 assert( pLevel->p5==0 );
143510 }
143511 if( omitTable ) pIdx = 0;
143512 }else
143513
143514#ifndef SQLITE_OMIT_OR_OPTIMIZATION
143515 if( pLoop->wsFlags & WHERE_MULTI_OR ){
143516 /* Case 5: Two or more separately indexed terms connected by OR
143517 **
143518 ** Example:
143519 **
143520 ** CREATE TABLE t1(a,b,c,d);
143521 ** CREATE INDEX i1 ON t1(a);
143522 ** CREATE INDEX i2 ON t1(b);
143523 ** CREATE INDEX i3 ON t1(c);
143524 **
143525 ** SELECT * FROM t1 WHERE a=5 OR b=7 OR (c=11 AND d=13)
143526 **
143527 ** In the example, there are three indexed terms connected by OR.
143528 ** The top of the loop looks like this:
143529 **
143530 ** Null 1 # Zero the rowset in reg 1
143531 **
143532 ** Then, for each indexed term, the following. The arguments to
143533 ** RowSetTest are such that the rowid of the current row is inserted
143534 ** into the RowSet. If it is already present, control skips the
143535 ** Gosub opcode and jumps straight to the code generated by WhereEnd().
143536 **
143537 ** sqlite3WhereBegin(<term>)
143538 ** RowSetTest # Insert rowid into rowset
143539 ** Gosub 2 A
143540 ** sqlite3WhereEnd()
143541 **
143542 ** Following the above, code to terminate the loop. Label A, the target
143543 ** of the Gosub above, jumps to the instruction right after the Goto.
143544 **
143545 ** Null 1 # Zero the rowset in reg 1
143546 ** Goto B # The loop is finished.
143547 **
143548 ** A: <loop body> # Return data, whatever.
143549 **
143550 ** Return 2 # Jump back to the Gosub
143551 **
143552 ** B: <after the loop>
143553 **
143554 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
143555 ** use an ephemeral index instead of a RowSet to record the primary
143556 ** keys of the rows we have already seen.
143557 **
143558 */
143559 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
143560 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
143561 Index *pCov = 0; /* Potential covering index (or NULL) */
143562 int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */
143563
143564 int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
143565 int regRowset = 0; /* Register for RowSet object */
143566 int regRowid = 0; /* Register holding rowid */
143567 int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
143568 int iRetInit; /* Address of regReturn init */
143569 int untestedTerms = 0; /* Some terms not completely tested */
143570 int ii; /* Loop counter */
143571 u16 wctrlFlags; /* Flags for sub-WHERE clause */
143572 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
143573 Table *pTab = pTabItem->pTab;
143574
143575 pTerm = pLoop->aLTerm[0];
143576 assert( pTerm!=0 );
143577 assert( pTerm->eOperator & WO_OR );
143578 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
143579 pOrWc = &pTerm->u.pOrInfo->wc;
143580 pLevel->op = OP_Return;
143581 pLevel->p1 = regReturn;
143582
143583 /* Set up a new SrcList in pOrTab containing the table being scanned
143584 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
143585 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
143586 */
143587 if( pWInfo->nLevel>1 ){
143588 int nNotReady; /* The number of notReady tables */
143589 struct SrcList_item *origSrc; /* Original list of tables */
143590 nNotReady = pWInfo->nLevel - iLevel - 1;
143591 pOrTab = sqlite3StackAllocRaw(db,
143592 sizeof(*pOrTab)+ nNotReady*sizeof(pOrTab->a[0]));
143593 if( pOrTab==0 ) return notReady;
143594 pOrTab->nAlloc = (u8)(nNotReady + 1);
143595 pOrTab->nSrc = pOrTab->nAlloc;
143596 memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem));
143597 origSrc = pWInfo->pTabList->a;
143598 for(k=1; k<=nNotReady; k++){
143599 memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k]));
143600 }
143601 }else{
143602 pOrTab = pWInfo->pTabList;
143603 }
143604
143605 /* Initialize the rowset register to contain NULL. An SQL NULL is
143606 ** equivalent to an empty rowset. Or, create an ephemeral index
143607 ** capable of holding primary keys in the case of a WITHOUT ROWID.
143608 **
143609 ** Also initialize regReturn to contain the address of the instruction
143610 ** immediately following the OP_Return at the bottom of the loop. This
143611 ** is required in a few obscure LEFT JOIN cases where control jumps
143612 ** over the top of the loop into the body of it. In this case the
143613 ** correct response for the end-of-loop code (the OP_Return) is to
143614 ** fall through to the next instruction, just as an OP_Next does if
143615 ** called on an uninitialized cursor.
143616 */
143617 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
143618 if( HasRowid(pTab) ){
143619 regRowset = ++pParse->nMem;
143620 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
143621 }else{
143622 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
143623 regRowset = pParse->nTab++;
143624 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, regRowset, pPk->nKeyCol);
143625 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
143626 }
143627 regRowid = ++pParse->nMem;
143628 }
143629 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
143630
143631 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
143632 ** Then for every term xN, evaluate as the subexpression: xN AND z
143633 ** That way, terms in y that are factored into the disjunction will
143634 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
143635 **
143636 ** Actually, each subexpression is converted to "xN AND w" where w is
143637 ** the "interesting" terms of z - terms that did not originate in the
143638 ** ON or USING clause of a LEFT JOIN, and terms that are usable as
143639 ** indices.
143640 **
143641 ** This optimization also only applies if the (x1 OR x2 OR ...) term
143642 ** is not contained in the ON clause of a LEFT JOIN.
143643 ** See ticket http://www.sqlite.org/src/info/f2369304e4
143644 */
143645 if( pWC->nTerm>1 ){
143646 int iTerm;
143647 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
143648 Expr *pExpr = pWC->a[iTerm].pExpr;
143649 if( &pWC->a[iTerm] == pTerm ) continue;
143650 testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
143651 testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
143652 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
143653 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
143654 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
143655 pExpr = sqlite3ExprDup(db, pExpr, 0);
143656 pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
143657 }
143658 if( pAndExpr ){
143659 /* The extra 0x10000 bit on the opcode is masked off and does not
143660 ** become part of the new Expr.op. However, it does make the
143661 ** op==TK_AND comparison inside of sqlite3PExpr() false, and this
143662 ** prevents sqlite3PExpr() from implementing AND short-circuit
143663 ** optimization, which we do not want here. */
143664 pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
143665 }
143666 }
143667
143668 /* Run a separate WHERE clause for each term of the OR clause. After
143669 ** eliminating duplicates from other WHERE clauses, the action for each
143670 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
143671 */
143672 wctrlFlags = WHERE_OR_SUBCLAUSE | (pWInfo->wctrlFlags & WHERE_SEEK_TABLE);
143673 ExplainQueryPlan((pParse, 1, "MULTI-INDEX OR"));
143674 for(ii=0; ii<pOrWc->nTerm; ii++){
143675 WhereTerm *pOrTerm = &pOrWc->a[ii];
143676 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
143677 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
143678 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
143679 int jmp1 = 0; /* Address of jump operation */
143680 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
143681 && !ExprHasProperty(pOrExpr, EP_FromJoin)
143682 ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */
143683 if( pAndExpr ){
143684 pAndExpr->pLeft = pOrExpr;
143685 pOrExpr = pAndExpr;
143686 }
143687 /* Loop through table entries that match term pOrTerm. */
143688 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
143689 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
143690 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
143691 wctrlFlags, iCovCur);
143692 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
143693 if( pSubWInfo ){
143694 WhereLoop *pSubLoop;
143695 int addrExplain = sqlite3WhereExplainOneScan(
143696 pParse, pOrTab, &pSubWInfo->a[0], 0
143697 );
143698 sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
143699
143700 /* This is the sub-WHERE clause body. First skip over
143701 ** duplicate rows from prior sub-WHERE clauses, and record the
143702 ** rowid (or PRIMARY KEY) for the current row so that the same
143703 ** row will be skipped in subsequent sub-WHERE clauses.
143704 */
143705 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
143706 int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
143707 if( HasRowid(pTab) ){
143708 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, regRowid);
143709 jmp1 = sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 0,
143710 regRowid, iSet);
143711 VdbeCoverage(v);
143712 }else{
143713 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
143714 int nPk = pPk->nKeyCol;
143715 int iPk;
143716 int r;
143717
143718 /* Read the PK into an array of temp registers. */
143719 r = sqlite3GetTempRange(pParse, nPk);
143720 for(iPk=0; iPk<nPk; iPk++){
143721 int iCol = pPk->aiColumn[iPk];
143722 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
143723 }
143724
143725 /* Check if the temp table already contains this key. If so,
143726 ** the row has already been included in the result set and
143727 ** can be ignored (by jumping past the Gosub below). Otherwise,
143728 ** insert the key into the temp table and proceed with processing
143729 ** the row.
143730 **
143731 ** Use some of the same optimizations as OP_RowSetTest: If iSet
143732 ** is zero, assume that the key cannot already be present in
143733 ** the temp table. And if iSet is -1, assume that there is no
143734 ** need to insert the key into the temp table, as it will never
143735 ** be tested for. */
143736 if( iSet ){
143737 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
143738 VdbeCoverage(v);
143739 }
143740 if( iSet>=0 ){
143741 sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, regRowid);
143742 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, regRowset, regRowid,
143743 r, nPk);
143745 }
143746
143747 /* Release the array of temp registers */
143748 sqlite3ReleaseTempRange(pParse, r, nPk);
143749 }
143750 }
143751
143752 /* Invoke the main loop body as a subroutine */
143753 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
143754
143755 /* Jump here (skipping the main loop body subroutine) if the
143756 ** current sub-WHERE row is a duplicate from prior sub-WHEREs. */
143757 if( jmp1 ) sqlite3VdbeJumpHere(v, jmp1);
143758
143759 /* The pSubWInfo->untestedTerms flag means that this OR term
143760 ** contained one or more AND term from a notReady table. The
143761 ** terms from the notReady table could not be tested and will
143762 ** need to be tested later.
143763 */
143764 if( pSubWInfo->untestedTerms ) untestedTerms = 1;
143765
143766 /* If all of the OR-connected terms are optimized using the same
143767 ** index, and the index is opened using the same cursor number
143768 ** by each call to sqlite3WhereBegin() made by this loop, it may
143769 ** be possible to use that index as a covering index.
143770 **
143771 ** If the call to sqlite3WhereBegin() above resulted in a scan that
143772 ** uses an index, and this is either the first OR-connected term
143773 ** processed or the index is the same as that used by all previous
143774 ** terms, set pCov to the candidate covering index. Otherwise, set
143775 ** pCov to NULL to indicate that no candidate covering index will
143776 ** be available.
143777 */
143778 pSubLoop = pSubWInfo->a[0].pWLoop;
143779 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
143780 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
143781 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
143782 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pSubLoop->u.btree.pIndex))
143783 ){
143784 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
143785 pCov = pSubLoop->u.btree.pIndex;
143786 }else{
143787 pCov = 0;
143788 }
143789
143790 /* Finish the loop through table entries that match term pOrTerm. */
143791 sqlite3WhereEnd(pSubWInfo);
143792 ExplainQueryPlanPop(pParse);
143793 }
143794 }
143795 }
143796 ExplainQueryPlanPop(pParse);
143797 pLevel->u.pCovidx = pCov;
143798 if( pCov ) pLevel->iIdxCur = iCovCur;
143799 if( pAndExpr ){
143800 pAndExpr->pLeft = 0;
143801 sqlite3ExprDelete(db, pAndExpr);
143802 }
143804 sqlite3VdbeGoto(v, pLevel->addrBrk);
143805 sqlite3VdbeResolveLabel(v, iLoopBody);
143806
143807 if( pWInfo->nLevel>1 ){ sqlite3StackFree(db, pOrTab); }
143808 if( !untestedTerms ) disableTerm(pLevel, pTerm);
143809 }else
143810#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
143811
143812 {
143813 /* Case 6: There is no usable index. We must do a complete
143814 ** scan of the entire table.
143815 */
143816 static const u8 aStep[] = { OP_Next, OP_Prev };
143817 static const u8 aStart[] = { OP_Rewind, OP_Last };
143818 assert( bRev==0 || bRev==1 );
143819 if( pTabItem->fg.isRecursive ){
143820 /* Tables marked isRecursive have only a single row that is stored in
143821 ** a pseudo-cursor. No need to Rewind or Next such cursors. */
143822 pLevel->op = OP_Noop;
143823 }else{
143824 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
143825 pLevel->op = aStep[bRev];
143826 pLevel->p1 = iCur;
143827 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrHalt);
143828 VdbeCoverageIf(v, bRev==0);
143829 VdbeCoverageIf(v, bRev!=0);
143831 }
143832 }
143833
143834#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
143835 pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
143836#endif
143837
143838 /* Insert code to test every subexpression that can be completely
143839 ** computed using the current set of tables.
143840 **
143841 ** This loop may run between one and three times, depending on the
143842 ** constraints to be generated. The value of stack variable iLoop
143843 ** determines the constraints coded by each iteration, as follows:
143844 **
143845 ** iLoop==1: Code only expressions that are entirely covered by pIdx.
143846 ** iLoop==2: Code remaining expressions that do not contain correlated
143847 ** sub-queries.
143848 ** iLoop==3: Code all remaining expressions.
143849 **
143850 ** An effort is made to skip unnecessary iterations of the loop.
143851 */
143852 iLoop = (pIdx ? 1 : 2);
143853 do{
143854 int iNext = 0; /* Next value for iLoop */
143855 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
143856 Expr *pE;
143857 int skipLikeAddr = 0;
143858 testcase( pTerm->wtFlags & TERM_VIRTUAL );
143859 testcase( pTerm->wtFlags & TERM_CODED );
143860 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
143861 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
143862 testcase( pWInfo->untestedTerms==0
143863 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
143864 pWInfo->untestedTerms = 1;
143865 continue;
143866 }
143867 pE = pTerm->pExpr;
143868 assert( pE!=0 );
143869 if( (pTabItem->fg.jointype&JT_LEFT) && !ExprHasProperty(pE,EP_FromJoin) ){
143870 continue;
143871 }
143872
143873 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
143874 iNext = 2;
143875 continue;
143876 }
143877 if( iLoop<3 && (pTerm->wtFlags & TERM_VARSELECT) ){
143878 if( iNext==0 ) iNext = 3;
143879 continue;
143880 }
143881
143882 if( (pTerm->wtFlags & TERM_LIKECOND)!=0 ){
143883 /* If the TERM_LIKECOND flag is set, that means that the range search
143884 ** is sufficient to guarantee that the LIKE operator is true, so we
143885 ** can skip the call to the like(A,B) function. But this only works
143886 ** for strings. So do not skip the call to the function on the pass
143887 ** that compares BLOBs. */
143888#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
143889 continue;
143890#else
143891 u32 x = pLevel->iLikeRepCntr;
143892 if( x>0 ){
143893 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If,(int)(x>>1));
143894 VdbeCoverageIf(v, (x&1)==1);
143895 VdbeCoverageIf(v, (x&1)==0);
143896 }
143897#endif
143898 }
143899#ifdef WHERETRACE_ENABLED /* 0xffff */
143900 if( sqlite3WhereTrace ){
143901 VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
143902 pWC->nTerm-j, pTerm, iLoop));
143903 }
143904 if( sqlite3WhereTrace & 0x800 ){
143905 sqlite3DebugPrintf("Coding auxiliary constraint:\n");
143906 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
143907 }
143908#endif
143909 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
143910 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
143911 pTerm->wtFlags |= TERM_CODED;
143912 }
143913 iLoop = iNext;
143914 }while( iLoop>0 );
143915
143916 /* Insert code to test for implied constraints based on transitivity
143917 ** of the "==" operator.
143918 **
143919 ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
143920 ** and we are coding the t1 loop and the t2 loop has not yet coded,
143921 ** then we cannot use the "t1.a=t2.b" constraint, but we can code
143922 ** the implied "t1.a=123" constraint.
143923 */
143924 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
143925 Expr *pE, sEAlt;
143926 WhereTerm *pAlt;
143927 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
143928 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
143929 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
143930 if( pTerm->leftCursor!=iCur ) continue;
143931 if( pTabItem->fg.jointype & JT_LEFT ) continue;
143932 pE = pTerm->pExpr;
143933#ifdef WHERETRACE_ENABLED /* 0x800 */
143934 if( sqlite3WhereTrace & 0x800 ){
143935 sqlite3DebugPrintf("Coding transitive constraint:\n");
143936 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
143937 }
143938#endif
143939 assert( !ExprHasProperty(pE, EP_FromJoin) );
143940 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
143941 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.leftColumn, notReady,
143942 WO_EQ|WO_IN|WO_IS, 0);
143943 if( pAlt==0 ) continue;
143944 if( pAlt->wtFlags & (TERM_CODED) ) continue;
143945 if( (pAlt->eOperator & WO_IN)
143946 && (pAlt->pExpr->flags & EP_xIsSelect)
143947 && (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
143948 ){
143949 continue;
143950 }
143951 testcase( pAlt->eOperator & WO_EQ );
143952 testcase( pAlt->eOperator & WO_IS );
143953 testcase( pAlt->eOperator & WO_IN );
143954 VdbeModuleComment((v, "begin transitive constraint"));
143955 sEAlt = *pAlt->pExpr;
143956 sEAlt.pLeft = pE->pLeft;
143957 sqlite3ExprIfFalse(pParse, &sEAlt, addrCont, SQLITE_JUMPIFNULL);
143958 }
143959
143960 /* For a LEFT OUTER JOIN, generate code that will record the fact that
143961 ** at least one row of the right table has matched the left table.
143962 */
143963 if( pLevel->iLeftJoin ){
143964 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
143965 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
143966 VdbeComment((v, "record LEFT JOIN hit"));
143967 for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
143968 testcase( pTerm->wtFlags & TERM_VIRTUAL );
143969 testcase( pTerm->wtFlags & TERM_CODED );
143970 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
143971 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
143972 assert( pWInfo->untestedTerms );
143973 continue;
143974 }
143975 assert( pTerm->pExpr );
143976 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
143977 pTerm->wtFlags |= TERM_CODED;
143978 }
143979 }
143980
143981#if WHERETRACE_ENABLED /* 0x20800 */
143982 if( sqlite3WhereTrace & 0x20000 ){
143983 sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n",
143984 iLevel);
143985 sqlite3WhereClausePrint(pWC);
143986 }
143987 if( sqlite3WhereTrace & 0x800 ){
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr *, int iCur, Index *pIdx)
Definition sqlite3.c:105344
#define codeCursorHint(A, B, C, D)
Definition sqlite3.c:142531
static int codeAllEqualityTerms(Parse *pParse, WhereLevel *pLevel, int bRev, int nExtraReg, char **pzAff)
Definition sqlite3.c:142180
static void codeApplyAffinity(Parse *pParse, int base, int n, char *zAff)
Definition sqlite3.c:141844
static void whereApplyPartialIndexConstraints(Expr *pTruth, int iTabCur, WhereClause *pWC)
Definition sqlite3.c:142765
#define WHERE_IPK
Definition sqlite3.c:141521
static void updateRangeAffinityStr(Expr *pRight, int n, char *zAff)
Definition sqlite3.c:141881
#define WHERE_COLUMN_IN
Definition sqlite3.c:141514
static void whereIndexExprTrans(Index *pIdx, int iTabCur, int iIdxCur, WhereInfo *pWInfo)
Definition sqlite3.c:142702
static void whereLikeOptimizationStringFixup(Vdbe *v, WhereLevel *pLevel, WhereTerm *pTerm)
Definition sqlite3.c:142300
static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg)
Definition sqlite3.c:142596
static void codeDeferredSeek(WhereInfo *pWInfo, Index *pIdx, int iCur, int iIdxCur)
Definition sqlite3.c:142552
#define SQLITE_STMTSTATUS_FULLSCAN_STEP
Definition sqlite3.c:9294
#define WHERE_UNQ_WANTED
Definition sqlite3.c:141529
unsigned untestedTerms
Definition sqlite3.c:141400
Bitmask revMask
Definition sqlite3.c:141407
int addrBignull
Definition sqlite3.c:140989
Index * pCovidx
Definition sqlite3.c:141008
int addrLikeRep
Definition sqlite3.c:140992
u32 iLikeRepCntr
Definition sqlite3.c:140991
struct WhereLoop::@122::@124 vtab
char * idxStr
Definition sqlite3.c:141055

Referenced by sqlite3WhereBegin().

◆ sqlite3WhereContinueLabel()

SQLITE_PRIVATE int sqlite3WhereContinueLabel ( WhereInfo * pWInfo)

Definition at line 145717 of file sqlite3.c.

Referenced by sqlite3Select().

◆ sqlite3WhereEnd()

SQLITE_PRIVATE void sqlite3WhereEnd ( WhereInfo * pWInfo)

Definition at line 150889 of file sqlite3.c.

150895 {
150896 Parse *pParse = pWInfo->pParse;
150897 Vdbe *v = pParse->pVdbe;
150898 int i;
150899 WhereLevel *pLevel;
150900 WhereLoop *pLoop;
150901 SrcList *pTabList = pWInfo->pTabList;
150902 sqlite3 *db = pParse->db;
150903
150904 /* Generate loop termination code.
150905 */
150906 VdbeModuleComment((v, "End WHERE-core"));
150907 for(i=pWInfo->nLevel-1; i>=0; i--){
150908 int addr;
150909 pLevel = &pWInfo->a[i];
150910 pLoop = pLevel->pWLoop;
150911 if( pLevel->op!=OP_Noop ){
150912#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
150913 int addrSeek = 0;
150914 Index *pIdx;
150915 int n;
150916 if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
150917 && i==pWInfo->nLevel-1 /* Ticket [ef9318757b152e3] 2017-10-21 */
150918 && (pLoop->wsFlags & WHERE_INDEXED)!=0
150919 && (pIdx = pLoop->u.btree.pIndex)->hasStat1
150920 && (n = pLoop->u.btree.nDistinctCol)>0
150921 && pIdx->aiRowLogEst[n]>=36
150922 ){
150923 int r1 = pParse->nMem+1;
150924 int j, op;
150925 for(j=0; j<n; j++){
150926 sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
150927 }
150928 pParse->nMem += n+1;
150929 op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
150930 addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
150931 VdbeCoverageIf(v, op==OP_SeekLT);
150932 VdbeCoverageIf(v, op==OP_SeekGT);
150933 sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
150934 }
150935#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
150936 /* The common case: Advance to the next row */
150937 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
150938 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
150939 sqlite3VdbeChangeP5(v, pLevel->p5);
150940 VdbeCoverage(v);
150941 VdbeCoverageIf(v, pLevel->op==OP_Next);
150942 VdbeCoverageIf(v, pLevel->op==OP_Prev);
150943 VdbeCoverageIf(v, pLevel->op==OP_VNext);
150944 if( pLevel->regBignull ){
150946 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
150947 VdbeCoverage(v);
150948 }
150949#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
150950 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
150951#endif
150952 }else{
150953 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
150954 }
150955 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
150956 struct InLoop *pIn;
150957 int j;
150958 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
150959 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
150960 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
150961 if( pIn->eEndLoopOp!=OP_Noop ){
150962 if( pIn->nPrefix ){
150963 assert( pLoop->wsFlags & WHERE_IN_EARLYOUT );
150964 if( pLevel->iLeftJoin ){
150965 /* For LEFT JOIN queries, cursor pIn->iCur may not have been
150966 ** opened yet. This occurs for WHERE clauses such as
150967 ** "a = ? AND b IN (...)", where the index is on (a, b). If
150968 ** the RHS of the (a=?) is NULL, then the "b IN (...)" may
150969 ** never have been coded, but the body of the loop run to
150970 ** return the null-row. So, if the cursor is not open yet,
150971 ** jump over the OP_Next or OP_Prev instruction about to
150972 ** be coded. */
150973 sqlite3VdbeAddOp2(v, OP_IfNotOpen, pIn->iCur,
150974 sqlite3VdbeCurrentAddr(v) + 2 +
150975 ((pLoop->wsFlags & WHERE_VIRTUALTABLE)==0)
150976 );
150977 VdbeCoverage(v);
150978 }
150979 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){
150982 pIn->iBase, pIn->nPrefix);
150983 VdbeCoverage(v);
150984 }
150985 }
150986 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
150987 VdbeCoverage(v);
150988 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
150989 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Next);
150990 }
150991 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
150992 }
150993 }
150994 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
150995 if( pLevel->addrSkip ){
150996 sqlite3VdbeGoto(v, pLevel->addrSkip);
150997 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
150998 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
150999 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
151000 }
151001#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
151002 if( pLevel->addrLikeRep ){
151003 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
151004 pLevel->addrLikeRep);
151005 VdbeCoverage(v);
151006 }
151007#endif
151008 if( pLevel->iLeftJoin ){
151009 int ws = pLoop->wsFlags;
151010 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
151011 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
151012 if( (ws & WHERE_IDX_ONLY)==0 ){
151013 assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
151014 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
151015 }
151016 if( (ws & WHERE_INDEXED)
151017 || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
151018 ){
151019 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
151020 }
151021 if( pLevel->op==OP_Return ){
151022 sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
151023 }else{
151024 sqlite3VdbeGoto(v, pLevel->addrFirst);
151025 }
151026 sqlite3VdbeJumpHere(v, addr);
151027 }
151028 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
151029 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
151030 }
151031
151032 /* The "break" point is here, just past the end of the outer loop.
151033 ** Set it.
151034 */
151035 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
151036
151037 assert( pWInfo->nLevel<=pTabList->nSrc );
151038 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
151039 int k, last;
151040 VdbeOp *pOp;
151041 Index *pIdx = 0;
151042 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
151043 Table *pTab = pTabItem->pTab;
151044 assert( pTab!=0 );
151045 pLoop = pLevel->pWLoop;
151046
151047 /* For a co-routine, change all OP_Column references to the table of
151048 ** the co-routine into OP_Copy of result contained in a register.
151049 ** OP_Rowid becomes OP_Null.
151050 */
151051 if( pTabItem->fg.viaCoroutine ){
151052 testcase( pParse->db->mallocFailed );
151053 translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur,
151054 pTabItem->regResult, 0);
151055 continue;
151056 }
151057
151058#ifdef SQLITE_ENABLE_EARLY_CURSOR_CLOSE
151059 /* Close all of the cursors that were opened by sqlite3WhereBegin.
151060 ** Except, do not close cursors that will be reused by the OR optimization
151061 ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
151062 ** created for the ONEPASS optimization.
151063 */
151064 if( (pTab->tabFlags & TF_Ephemeral)==0
151065 && pTab->pSelect==0
151066 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
151067 ){
151068 int ws = pLoop->wsFlags;
151069 if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
151070 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
151071 }
151072 if( (ws & WHERE_INDEXED)!=0
151073 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
151074 && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
151075 ){
151076 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
151077 }
151078 }
151079#endif
151080
151081 /* If this scan uses an index, make VDBE code substitutions to read data
151082 ** from the index instead of from the table where possible. In some cases
151083 ** this optimization prevents the table from ever being read, which can
151084 ** yield a significant performance boost.
151085 **
151086 ** Calls to the code generator in between sqlite3WhereBegin and
151087 ** sqlite3WhereEnd will have created code that references the table
151088 ** directly. This loop scans all that code looking for opcodes
151089 ** that reference the table and converts them into opcodes that
151090 ** reference the index.
151091 */
151092 if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
151093 pIdx = pLoop->u.btree.pIndex;
151094 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
151095 pIdx = pLevel->u.pCovidx;
151096 }
151097 if( pIdx
151098 && (pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable))
151099 && !db->mallocFailed
151100 ){
151101 last = sqlite3VdbeCurrentAddr(v);
151102 k = pLevel->addrBody;
151103#ifdef SQLITE_DEBUG
151104 if( db->flags & SQLITE_VdbeAddopTrace ){
151105 printf("TRANSLATE opcodes in range %d..%d\n", k, last-1);
151106 }
151107#endif
151108 pOp = sqlite3VdbeGetOp(v, k);
151109 for(; k<last; k++, pOp++){
151110 if( pOp->p1!=pLevel->iTabCur ) continue;
151111 if( pOp->opcode==OP_Column
151112#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
151113 || pOp->opcode==OP_Offset
151114#endif
151115 ){
151116 int x = pOp->p2;
151117 assert( pIdx->pTable==pTab );
151118 if( !HasRowid(pTab) ){
151119 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
151120 x = pPk->aiColumn[x];
151121 assert( x>=0 );
151122 }else{
151124 x = sqlite3StorageColumnToTable(pTab,x);
151125 }
151126 x = sqlite3TableColumnToIndex(pIdx, x);
151127 if( x>=0 ){
151128 pOp->p2 = x;
151129 pOp->p1 = pLevel->iIdxCur;
151130 OpcodeRewriteTrace(db, k, pOp);
151131 }
151132 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
151133 || pWInfo->eOnePass );
151134 }else if( pOp->opcode==OP_Rowid ){
151135 pOp->p1 = pLevel->iIdxCur;
151136 pOp->opcode = OP_IdxRowid;
151137 OpcodeRewriteTrace(db, k, pOp);
151138 }else if( pOp->opcode==OP_IfNullRow ){
151139 pOp->p1 = pLevel->iIdxCur;
151140 OpcodeRewriteTrace(db, k, pOp);
151141 }
151142 }
151143#ifdef SQLITE_DEBUG
151144 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
151145#endif
151146 }
151147 }
151148
151149 /* Undo all Expr node modifications */
151150 while( pWInfo->pExprMods ){
151151 WhereExprMod *p = pWInfo->pExprMods;
151152 pWInfo->pExprMods = p->pNext;
151153 memcpy(p->pExpr, &p->orig, sizeof(p->orig));
151154 sqlite3DbFree(db, p);
151155 }
151156
#define OpcodeRewriteTrace(D, K, P)
Definition sqlite3.c:150872
SQLITE_PRIVATE i16 sqlite3StorageColumnToTable(Table *, i16)
Definition sqlite3.c:111342
WhereExprMod * pNext
Definition sqlite3.c:141368
WhereExprMod * pExprMods
Definition sqlite3.c:141406
u16 nDistinctCol
Definition sqlite3.c:141047

References SrcList::a, WhereInfo::a, WhereLevel::addrBignull, WhereLevel::addrBody, WhereLevel::addrBrk, WhereLevel::addrCont, WhereLevel::addrFirst, WhereLevel::addrLikeRep, WhereLevel::addrNxt, WhereLevel::addrSkip, Index::aiColumn, WhereInfo::aiCurOnePass, WhereLevel::aInLoop, Index::aiRowLogEst, WhereLoop::btree, Parse::db, WhereInfo::eDistinct, WhereInfo::eOnePass, sqlite3::flags, HasRowid, WhereInfo::iBreak, SrcList::SrcList_item::iCursor, WhereLevel::iFrom, WhereLevel::iIdxCur, WhereLevel::iLeftJoin, WhereLevel::iLikeRepCntr, WhereLevel::in, WhereLevel::iTabCur, sqlite3::mallocFailed, WhereLoop::nDistinctCol, WhereLevel::nIn, WhereInfo::nLevel, Parse::nMem, Parse::nQueryLoop, SrcList::nSrc, ONEPASS_OFF, WhereLevel::op, OP_Close, OP_Column, OP_DecrJumpZero, OP_Gosub, OP_Goto, OP_IdxRowid, OP_IfNoHope, OP_IfNotOpen, OP_IfNullRow, OP_IfPos, OP_Next, OP_Noop, OP_NullRow, OP_Offset, OP_Prev, OP_Return, OP_Rowid, OP_SeekGT, OP_SeekLT, OP_VNext, VdbeOp::opcode, OpcodeRewriteTrace, WhereExprMod::orig, VdbeOp::p1, WhereLevel::p1, VdbeOp::p2, WhereLevel::p2, WhereLevel::p3, WhereLevel::p5, WhereLevel::pCovidx, WhereExprMod::pExpr, WhereInfo::pExprMods, WhereLoop::pIndex, WhereExprMod::pNext, WhereInfo::pParse, printf, Table::pSelect, SrcList::SrcList_item::pTab, Index::pTable, WhereInfo::pTabList, Parse::pVdbe, WhereLevel::pWLoop, WhereLevel::regBignull, WhereInfo::savedNQueryLoop, sqlite3DbFree(), sqlite3PrimaryKeyIndex(), sqlite3StorageColumnToTable(), sqlite3TableColumnToIndex(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4Int(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetOp(), sqlite3VdbeGoto(), sqlite3VdbeJumpHere(), sqlite3VdbeResolveLabel(), Table::tabFlags, testcase, TF_Ephemeral, translateColumnToCopy(), WhereLevel::u, WhereLoop::u, VdbeComment, VdbeCoverage, VdbeCoverageIf, VdbeModuleComment, WhereInfo::wctrlFlags, WHERE_AUTO_INDEX, WHERE_DISTINCT_ORDERED, WHERE_IDX_ONLY, WHERE_IN_ABLE, WHERE_IN_EARLYOUT, WHERE_INDEXED, WHERE_IPK, WHERE_MULTI_OR, WHERE_OR_SUBCLAUSE, WHERE_VIRTUALTABLE, whereInfoFree(), WhereLoop::wsFlags, Table::zName, and Index::zName.

Referenced by fkScanChildren(), sqlite3DeleteFrom(), sqlite3Select(), sqlite3Update(), sqlite3WindowCodeStep(), and updateVirtualTable().

◆ sqlite3WhereExplainOneScan()

SQLITE_PRIVATE int sqlite3WhereExplainOneScan ( Parse * pParse,
SrcList * pTabList,
WhereLevel * pLevel,
u16 wctrlFlags )

Definition at line 141637 of file sqlite3.c.

141648 {
141649 int ret = 0;
141650#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
141651 if( sqlite3ParseToplevel(pParse)->explain==2 )
141652#endif
141653 {
141654 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
141655 Vdbe *v = pParse->pVdbe; /* VM being constructed */
141656 sqlite3 *db = pParse->db; /* Database handle */
141657 int isSearch; /* True for a SEARCH. False for SCAN. */
141658 WhereLoop *pLoop; /* The controlling WhereLoop object */
141659 u32 flags; /* Flags that describe this loop */
141660 char *zMsg; /* Text to add to EQP output */
141661 StrAccum str; /* EQP output string */
141662 char zBuf[100]; /* Initial space for EQP output string */
141663
141664 pLoop = pLevel->pWLoop;
141665 flags = pLoop->wsFlags;
141666 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_OR_SUBCLAUSE) ) return 0;
141667
141668 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
141669 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
141670 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
141671
141672 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
141673 sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN");
141674 if( pItem->pSelect ){
141675 sqlite3_str_appendf(&str, " SUBQUERY %u", pItem->pSelect->selId);
141676 }else{
141677 sqlite3_str_appendf(&str, " TABLE %s", pItem->zName);
141678 }
141679
141680 if( pItem->zAlias ){
141681 sqlite3_str_appendf(&str, " AS %s", pItem->zAlias);
141682 }
141683 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
141684 const char *zFmt = 0;
141685 Index *pIdx;
141686
141687 assert( pLoop->u.btree.pIndex!=0 );
141688 pIdx = pLoop->u.btree.pIndex;
141689 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
141690 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
141691 if( isSearch ){
141692 zFmt = "PRIMARY KEY";
141693 }
141694 }else if( flags & WHERE_PARTIALIDX ){
141695 zFmt = "AUTOMATIC PARTIAL COVERING INDEX";
141696 }else if( flags & WHERE_AUTO_INDEX ){
141697 zFmt = "AUTOMATIC COVERING INDEX";
141698 }else if( flags & WHERE_IDX_ONLY ){
141699 zFmt = "COVERING INDEX %s";
141700 }else{
141701 zFmt = "INDEX %s";
141702 }
141703 if( zFmt ){
141704 sqlite3_str_append(&str, " USING ", 7);
141705 sqlite3_str_appendf(&str, zFmt, pIdx->zName);
141706 explainIndexRange(&str, pLoop);
141707 }
141708 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
141709 const char *zRangeOp;
141710 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
141711 zRangeOp = "=";
141712 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
141713 zRangeOp = ">? AND rowid<";
141714 }else if( flags&WHERE_BTM_LIMIT ){
141715 zRangeOp = ">";
141716 }else{
141717 assert( flags&WHERE_TOP_LIMIT);
141718 zRangeOp = "<";
141719 }
141720 sqlite3_str_appendf(&str,
141721 " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
141722 }
141723#ifndef SQLITE_OMIT_VIRTUALTABLE
141724 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
141725 sqlite3_str_appendf(&str, " VIRTUAL TABLE INDEX %d:%s",
141726 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
141727 }
141728#endif
141729#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
141730 if( pLoop->nOut>=10 ){
141731 sqlite3_str_appendf(&str, " (~%llu rows)",
141732 sqlite3LogEstToInt(pLoop->nOut));
141733 }else{
141734 sqlite3_str_append(&str, " (~1 row)", 9);
141735 }
141736#endif
141737 zMsg = sqlite3StrAccumFinish(&str);
#define WHERE_BOTH_LIMIT
Definition sqlite3.c:141519
LogEst nOut
Definition sqlite3.c:141041

References SrcList::a, Parse::addrExplain, WhereLoop::btree, Parse::db, explainIndexRange(), HasRowid, WhereLoop::idxNum, WhereLoop::idxStr, WhereLevel::iFrom, IsPrimaryKeyIndex, WhereLoop::nEq, WhereLoop::nOut, OP_Explain, P4_DYNAMIC, WhereLoop::pIndex, Parse::pVdbe, WhereLevel::pWLoop, sqlite3_str_append(), sqlite3_str_appendall(), sqlite3_str_appendf(), sqlite3ExplainBreakpoint, sqlite3ParseToplevel, sqlite3StrAccumFinish(), sqlite3StrAccumInit(), sqlite3VdbeAddOp4(), sqlite3VdbeCurrentAddr(), SQLITE_MAX_LENGTH, WhereLoop::u, WhereLoop::vtab, WHERE_AUTO_INDEX, WHERE_BOTH_LIMIT, WHERE_BTM_LIMIT, WHERE_COLUMN_EQ, WHERE_COLUMN_IN, WHERE_CONSTRAINT, WHERE_IDX_ONLY, WHERE_IPK, WHERE_MULTI_OR, WHERE_OR_SUBCLAUSE, WHERE_ORDERBY_MAX, WHERE_ORDERBY_MIN, WHERE_PARTIALIDX, WHERE_TOP_LIMIT, WHERE_VIRTUALTABLE, WhereLoop::wsFlags, and Index::zName.

Referenced by sqlite3WhereBegin().

◆ sqlite3WhereExprAnalyze()

SQLITE_PRIVATE void sqlite3WhereExprAnalyze ( SrcList * pTabList,
WhereClause * pWC )

Definition at line 145549 of file sqlite3.c.

References exprAnalyze(), and WhereClause::nTerm.

Referenced by exprAnalyzeOrTerm(), and sqlite3WhereBegin().

◆ sqlite3WhereExprListUsage()

SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage ( WhereMaskSet * pMaskSet,
ExprList * pList )

Definition at line 145529 of file sqlite3.c.

145532 {
145533 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
145534}
145536 int i;
145537 Bitmask mask = 0;
145538 if( pList ){

Referenced by exprAnalyze(), exprSelectUsage(), sqlite3WhereBegin(), and sqlite3WhereExprUsageNN().

◆ sqlite3WhereExprUsage()

SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage ( WhereMaskSet * pMaskSet,
Expr * p )

Definition at line 145526 of file sqlite3.c.

Referenced by exprAnalyze(), exprSelectUsage(), and wherePathSatisfiesOrderBy().

◆ sqlite3WhereExprUsageNN()

SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN ( WhereMaskSet * pMaskSet,
Expr * p )

Definition at line 145498 of file sqlite3.c.

145504 {
145505 Bitmask mask;
145506 if( p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){
145507 return sqlite3WhereGetMask(pMaskSet, p->iTable);
145508 }else if( ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
145509 assert( p->op!=TK_IF_NULL_ROW );
145510 return 0;
145511 }
145512 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
145513 if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
145514 if( p->pRight ){
145515 mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
145516 assert( p->x.pList==0 );
145517 }else if( ExprHasProperty(p, EP_xIsSelect) ){
145518 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
145519 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
145520 }else if( p->x.pList ){
145521 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
145522 }
145523#ifndef SQLITE_OMIT_WINDOWFUNC
145524 if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){
145525 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);

References WhereMaskSet::bVarSelect, EP_FixedCol, EP_Leaf, EP_TokenOnly, EP_VarSelect, EP_xIsSelect, ExprHasProperty, exprSelectUsage(), Expr::iTable, mask, Expr::op, Expr::pLeft, Expr::pList, Window::pPartition, Expr::pRight, Expr::pSelect, Expr::pWin, sqlite3WhereExprListUsage(), sqlite3WhereExprUsageNN(), sqlite3WhereGetMask(), TK_AGG_FUNCTION, TK_COLUMN, TK_FUNCTION, TK_IF_NULL_ROW, Expr::x, and Expr::y.

Referenced by exprAnalyze(), and sqlite3WhereExprUsageNN().

◆ sqlite3WhereFindTerm()

SQLITE_PRIVATE WhereTerm * sqlite3WhereFindTerm ( WhereClause * pWC,
int iCur,
int iColumn,
Bitmask notReady,
u32 op,
Index * pIdx )

Definition at line 146024 of file sqlite3.c.

146037 {
146038 WhereTerm *pResult = 0;
146039 WhereTerm *p;
146040 WhereScan scan;
146041
146042 p = whereScanInit(&scan, pWC, iCur, iColumn, op, pIdx);
146043 op &= WO_EQ|WO_IS;
146044 while( p ){
146045 if( (p->prereqRight & notReady)==0 ){
146046 if( p->prereqRight==0 && (p->eOperator&op)!=0 ){
146047 testcase( p->eOperator & WO_IS );
146048 return p;
146049 }
static WhereTerm * whereScanInit(WhereScan *pScan, WhereClause *pWC, int iCur, int iColumn, u32 opMask, Index *pIdx)
Definition sqlite3.c:145960

References WhereTerm::eOperator, WhereTerm::prereqRight, testcase, whereScanInit(), whereScanNext(), WO_EQ, and WO_IS.

Referenced by isDistinctRedundant(), wherePathSatisfiesOrderBy(), and whereShortCut().

◆ sqlite3WhereGetMask()

SQLITE_PRIVATE Bitmask sqlite3WhereGetMask ( WhereMaskSet * pMaskSet,
int iCursor )

Definition at line 145819 of file sqlite3.c.

145825 {
145826 int i;
145827 assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 );
145828 for(i=0; i<pMaskSet->n; i++){

Referenced by exprAnalyze(), exprAnalyzeOrTerm(), sqlite3WhereBegin(), and sqlite3WhereExprUsageNN().

◆ sqlite3WhereIsDistinct()

SQLITE_PRIVATE int sqlite3WhereIsDistinct ( WhereInfo * pWInfo)

Definition at line 145662 of file sqlite3.c.

Referenced by sqlite3Select().

◆ sqlite3WhereIsOrdered()

SQLITE_PRIVATE int sqlite3WhereIsOrdered ( WhereInfo * pWInfo)

Definition at line 145674 of file sqlite3.c.

References WhereInfo::nOBSat.

Referenced by sqlite3Select().

◆ sqlite3WhereIsSorted()

SQLITE_PRIVATE int sqlite3WhereIsSorted ( WhereInfo * pWInfo)

Definition at line 149620 of file sqlite3.c.

References WhereInfo::sorted, WhereInfo::wctrlFlags, WHERE_GROUPBY, and WHERE_SORTBYGROUP.

Referenced by sqlite3Select().

◆ sqlite3WhereOkOnePass()

SQLITE_PRIVATE int sqlite3WhereOkOnePass ( WhereInfo * pWInfo,
int * aiCur )

Definition at line 145747 of file sqlite3.c.

145753 {
145754 memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);
145755#ifdef WHERETRACE_ENABLED
145756 if( sqlite3WhereTrace && pWInfo->eOnePass!=ONEPASS_OFF ){
145757 sqlite3DebugPrintf("%s cursors: %d %d\n",

References WhereInfo::aiCurOnePass, WhereInfo::eOnePass, ONEPASS_OFF, and ONEPASS_SINGLE.

Referenced by sqlite3DeleteFrom(), sqlite3Update(), and updateVirtualTable().

◆ sqlite3WhereOrderByLimitOptLabel()

SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel ( WhereInfo * pWInfo)

Definition at line 145701 of file sqlite3.c.

145707 {
145708 WhereLevel *pInner;
145709 if( !pWInfo->bOrderedInnerLoop ){
145710 /* The ORDER BY LIMIT optimization does not apply. Jump to the
145711 ** continuation of the inner-most loop. */
unsigned bOrderedInnerLoop
Definition sqlite3.c:141401

References WhereInfo::a, WhereLevel::addrNxt, WhereInfo::bOrderedInnerLoop, WhereInfo::iContinue, and WhereInfo::nLevel.

Referenced by sqlite3Select().

◆ sqlite3WhereOutputRowCount()

SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount ( WhereInfo * pWInfo)

Definition at line 145654 of file sqlite3.c.

References WhereInfo::nRowOut.

Referenced by sqlite3Select().

◆ sqlite3WhereSplit()

SQLITE_PRIVATE void sqlite3WhereSplit ( WhereClause * pWC,
Expr * pExpr,
u8 op )

Definition at line 145441 of file sqlite3.c.

145447 {
145449 pWC->op = op;
145450 if( pE2==0 ) return;
145451 if( pE2->op!=op ){

References Expr::op, WhereClause::op, Expr::pLeft, Expr::pRight, sqlite3ExprSkipCollateAndLikely(), sqlite3WhereSplit(), and whereClauseInsert().

Referenced by exprAnalyzeOrTerm(), sqlite3WhereBegin(), and sqlite3WhereSplit().

◆ sqlite3WhereTabFuncArgs()

SQLITE_PRIVATE void sqlite3WhereTabFuncArgs ( Parse * pParse,
struct SrcList_item * pItem,
WhereClause * pWC )

Definition at line 145566 of file sqlite3.c.

145576 {
145577 Table *pTab;
145578 int j, k;
145579 ExprList *pArgs;
145580 Expr *pColRef;
145581 Expr *pTerm;
145582 if( pItem->fg.isTabFunc==0 ) return;
145583 pTab = pItem->pTab;
145584 assert( pTab!=0 );
145585 pArgs = pItem->u1.pFuncArg;
145586 if( pArgs==0 ) return;
145587 for(j=k=0; j<pArgs->nExpr; j++){
145588 Expr *pRhs;
145589 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;}
145590 if( k>=pTab->nCol ){
145591 sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d",
145592 pTab->zName, j);
145593 return;
145594 }
145595 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
145596 if( pColRef==0 ) return;
145597 pColRef->iTable = pItem->iCursor;
145598 pColRef->iColumn = k++;
145599 pColRef->y.pTab = pTab;
145600 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
145601 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
145602 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);

References ExprList::a, Table::aCol, COLFLAG_HIDDEN, Column::colFlags, Parse::db, Expr::iColumn, Expr::iTable, JT_LEFT, Table::nCol, ExprList::nExpr, ExprList::ExprList_item::pExpr, Expr::pTab, sqlite3ErrorMsg(), sqlite3ExprAlloc(), sqlite3ExprDup(), sqlite3PExpr(), sqlite3SetJoinExpr(), TERM_DYNAMIC, TK_COLUMN, TK_EQ, TK_UPLUS, whereClauseInsert(), Expr::y, and Table::zName.

Referenced by sqlite3WhereBegin().

◆ sqlite3WhereUsesDeferredSeek()

SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek ( WhereInfo * pWInfo)

Definition at line 145763 of file sqlite3.c.

Referenced by sqlite3Update().

◆ sqlite3WindowAlloc()

SQLITE_PRIVATE Window * sqlite3WindowAlloc ( Parse * pParse,
int eType,
int eStart,
Expr * pStart,
int eEnd,
Expr * pEnd,
u8 eExclude )

Definition at line 152309 of file sqlite3.c.

152323 {
152324 Window *pWin = 0;
152325 int bImplicitFrame = 0;
152326
152327 /* Parser assures the following: */
152328 assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
152329 assert( eStart==TK_CURRENT || eStart==TK_PRECEDING
152330 || eStart==TK_UNBOUNDED || eStart==TK_FOLLOWING );
152331 assert( eEnd==TK_CURRENT || eEnd==TK_FOLLOWING
152332 || eEnd==TK_UNBOUNDED || eEnd==TK_PRECEDING );
152333 assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
152334 assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
152335
152336 if( eType==0 ){
152337 bImplicitFrame = 1;
152338 eType = TK_RANGE;
152339 }
152340
152341 /* Additionally, the
152342 ** starting boundary type may not occur earlier in the following list than
152343 ** the ending boundary type:
152344 **
152345 ** UNBOUNDED PRECEDING
152346 ** <expr> PRECEDING
152347 ** CURRENT ROW
152348 ** <expr> FOLLOWING
152349 ** UNBOUNDED FOLLOWING
152350 **
152351 ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
152352 ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
152353 ** frame boundary.
152354 */
152355 if( (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
152356 || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
152357 ){
152358 sqlite3ErrorMsg(pParse, "unsupported frame specification");
152359 goto windowAllocErr;
152360 }
152361
152362 pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
152363 if( pWin==0 ) goto windowAllocErr;
152364 pWin->eFrmType = eType;
152365 pWin->eStart = eStart;
152366 pWin->eEnd = eEnd;
152367 if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
152368 eExclude = TK_NO;
152369 }
152370 pWin->eExclude = eExclude;
152371 pWin->bImplicitFrame = bImplicitFrame;
152372 pWin->pEnd = sqlite3WindowOffsetExpr(pParse, pEnd);
152373 pWin->pStart = sqlite3WindowOffsetExpr(pParse, pStart);
152374 return pWin;
#define TK_RANGE
Definition sqlite3.c:14031
#define TK_FOLLOWING
Definition sqlite3.c:14028
#define TK_UNBOUNDED
Definition sqlite3.c:14032
#define TK_PRECEDING
Definition sqlite3.c:14030
#define SQLITE_WindowFunc
Definition sqlite3.c:17042
#define TK_GROUPS
Definition sqlite3.c:14034
#define TK_CURRENT
Definition sqlite3.c:14027
#define TK_NO
Definition sqlite3.c:14008
#define TK_ROWS
Definition sqlite3.c:14018
static Expr * sqlite3WindowOffsetExpr(Parse *pParse, Expr *pExpr)
Definition sqlite3.c:152297
u8 bImplicitFrame
Definition sqlite3.c:19198
Expr * pEnd
Definition sqlite3.c:19201
u8 eExclude
Definition sqlite3.c:19199
u8 eStart
Definition sqlite3.c:19196
u8 eEnd
Definition sqlite3.c:19197
u8 eFrmType
Definition sqlite3.c:19195
Expr * pStart
Definition sqlite3.c:19200

Referenced by yy_reduce().

◆ sqlite3WindowAssemble()

SQLITE_PRIVATE Window * sqlite3WindowAssemble ( Parse * pParse,
Window * pWin,
ExprList * pPartition,
ExprList * pOrderBy,
Token * pBase )

Definition at line 152381 of file sqlite3.c.

152393 {
152394 if( pWin ){
152395 pWin->pPartition = pPartition;
152396 pWin->pOrderBy = pOrderBy;
152397 if( pBase ){
152398 pWin->zBase = sqlite3DbStrNDup(pParse->db, pBase->z, pBase->n);
152399 }
char * zBase
Definition sqlite3.c:19192

References Parse::db, Token::n, Window::pOrderBy, Window::pPartition, WindowRewrite::pWin, sqlite3DbStrNDup(), sqlite3ExprListDelete(), Token::z, and Window::zBase.

Referenced by yy_reduce().

◆ sqlite3WindowAttach()

SQLITE_PRIVATE void sqlite3WindowAttach ( Parse * pParse,
Expr * p,
Window * pWin )

Definition at line 152442 of file sqlite3.c.

152448 {
152449 if( p ){
152450 assert( p->op==TK_FUNCTION );
152451 assert( pWin );
152452 p->y.pWin = pWin;
152454 pWin->pOwner = p;
152455 if( (p->flags & EP_Distinct) && pWin->eFrmType!=TK_FILTER ){
152456 sqlite3ErrorMsg(pParse,
152457 "DISTINCT is not supported for window functions"

Referenced by yy_reduce().

◆ sqlite3WindowChain()

SQLITE_PRIVATE void sqlite3WindowChain ( Parse * pParse,
Window * pWin,
Window * pList )

Definition at line 152408 of file sqlite3.c.

152414 {
152415 if( pWin->zBase ){
152416 sqlite3 *db = pParse->db;
152417 Window *pExist = windowFind(pParse, pList, pWin->zBase);
152418 if( pExist ){
152419 const char *zErr = 0;
152420 /* Check for errors */
152421 if( pWin->pPartition ){
152422 zErr = "PARTITION clause";
152423 }else if( pExist->pOrderBy && pWin->pOrderBy ){
152424 zErr = "ORDER BY clause";
152425 }else if( pExist->bImplicitFrame==0 ){
152426 zErr = "frame specification";
152427 }
152428 if( zErr ){
152429 sqlite3ErrorMsg(pParse,
152430 "cannot override %s of window: %s", zErr, pWin->zBase
152431 );
152432 }else{
152433 pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
152434 if( pExist->pOrderBy ){
152435 assert( pWin->pOrderBy==0 );
152436 pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
152437 }
static Window * windowFind(Parse *pParse, Window *pList, const char *zName)
Definition sqlite3.c:151790

References Window::bImplicitFrame, Parse::db, Window::pOrderBy, Window::pPartition, WindowRewrite::pWin, sqlite3DbFree(), sqlite3ErrorMsg(), sqlite3ExprListDup(), windowFind(), and Window::zBase.

Referenced by sqlite3WindowUpdate(), and yy_reduce().

◆ sqlite3WindowCodeInit()

SQLITE_PRIVATE void sqlite3WindowCodeInit ( Parse * pParse,
Select * pSelect )

Definition at line 152512 of file sqlite3.c.

152518 {
152519 int nEphExpr = pSelect->pSrc->a[0].pSelect->pEList->nExpr;
152520 Window *pMWin = pSelect->pWin;
152521 Window *pWin;
152522 Vdbe *v = sqlite3GetVdbe(pParse);
152523
152524 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, nEphExpr);
152525 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
152526 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
152527 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
152528
152529 /* Allocate registers to use for PARTITION BY values, if any. Initialize
152530 ** said registers to NULL. */
152531 if( pMWin->pPartition ){
152532 int nExpr = pMWin->pPartition->nExpr;
152533 pMWin->regPart = pParse->nMem+1;
152534 pParse->nMem += nExpr;
152535 sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
152536 }
152537
152538 pMWin->regOne = ++pParse->nMem;
152539 sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regOne);
152540
152541 if( pMWin->eExclude ){
152542 pMWin->regStartRowid = ++pParse->nMem;
152543 pMWin->regEndRowid = ++pParse->nMem;
152544 pMWin->csrApp = pParse->nTab++;
152547 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->csrApp, pMWin->iEphCsr);
152548 return;
152549 }
152550
152551 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
152552 FuncDef *p = pWin->pFunc;
152553 if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
152554 /* The inline versions of min() and max() require a single ephemeral
152555 ** table and 3 registers. The registers are used as follows:
152556 **
152557 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
152558 ** regApp+1: integer value used to ensure keys are unique
152559 ** regApp+2: output of MakeRecord
152560 */
152561 ExprList *pList = pWin->pOwner->x.pList;
152562 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
152563 pWin->csrApp = pParse->nTab++;
152564 pWin->regApp = pParse->nMem+1;
152565 pParse->nMem += 3;
152566 if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
152567 assert( pKeyInfo->aSortFlags[0]==0 );
152568 pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
152569 }
152571 sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
152572 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
152573 }
152574 else if( p->zName==nth_valueName || p->zName==first_valueName ){
152575 /* Allocate two registers at pWin->regApp. These will be used to
152576 ** store the start and end index of the current frame. */
152577 pWin->regApp = pParse->nMem+1;
152578 pWin->csrApp = pParse->nTab++;
152579 pParse->nMem += 2;
152580 sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
152581 }
static const char first_valueName[]
Definition sqlite3.c:151715
static const char nth_valueName[]
Definition sqlite3.c:151714
int csrApp
Definition sqlite3.c:19209
FuncDef * pFunc
Definition sqlite3.c:19205
int regEndRowid
Definition sqlite3.c:19217
int regStartRowid
Definition sqlite3.c:19216
int regApp
Definition sqlite3.c:19210
int regPart
Definition sqlite3.c:19211
int regOne
Definition sqlite3.c:19215

References SrcList::a, KeyInfo::aSortFlags, Window::csrApp, Window::eExclude, Window::eStart, first_valueName, FuncDef::funcFlags, Window::iEphCsr, KEYINFO_ORDER_DESC, lagName, leadName, ExprList::nExpr, Parse::nMem, Parse::nTab, nth_valueName, OP_Integer, OP_Null, OP_OpenDup, OP_OpenEphemeral, P4_KEYINFO, Select::pEList, Window::pFunc, Expr::pList, Window::pNextWin, Window::pOwner, Window::pPartition, SrcList::SrcList_item::pSelect, Select::pSrc, Select::pWin, WindowRewrite::pWin, Window::regApp, Window::regEndRowid, Window::regOne, Window::regPart, Window::regStartRowid, sqlite3GetVdbe(), sqlite3KeyInfoFromExprList(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAppendP4(), SQLITE_FUNC_MINMAX, TK_UNBOUNDED, Expr::x, and FuncDef::zName.

Referenced by sqlite3Select().

◆ sqlite3WindowCodeStep()

SQLITE_PRIVATE void sqlite3WindowCodeStep ( Parse * pParse,
Select * p,
WhereInfo * pWInfo,
int regGosub,
int addrGosub )

Definition at line 153875 of file sqlite3.c.

153887 {
153888 Window *pMWin = p->pWin;
153889 ExprList *pOrderBy = pMWin->pOrderBy;
153890 Vdbe *v = sqlite3GetVdbe(pParse);
153891 int csrWrite; /* Cursor used to write to eph. table */
153892 int csrInput = p->pSrc->a[0].iCursor; /* Cursor of sub-select */
153893 int nInput = p->pSrc->a[0].pTab->nCol; /* Number of cols returned by sub */
153894 int iInput; /* To iterate through sub cols */
153895 int addrNe; /* Address of OP_Ne */
153896 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
153897 int addrInteger = 0; /* Address of OP_Integer */
153898 int addrEmpty; /* Address of OP_Rewind in flush: */
153899 int regNew; /* Array of registers holding new input row */
153900 int regRecord; /* regNew array in record form */
153901 int regRowid; /* Rowid for regRecord in eph table */
153902 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
153903 int regPeer = 0; /* Peer values for current row */
153904 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
153905 WindowCodeArg s; /* Context object for sub-routines */
153906 int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
153907 int regStart = 0; /* Value of <expr> PRECEDING */
153908 int regEnd = 0; /* Value of <expr> FOLLOWING */
153909
153910 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT
153911 || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED
153912 );
153913 assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT
153914 || pMWin->eEnd==TK_UNBOUNDED || pMWin->eEnd==TK_PRECEDING
153915 );
153916 assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
153917 || pMWin->eExclude==TK_GROUP || pMWin->eExclude==TK_TIES
153918 || pMWin->eExclude==TK_NO
153919 );
153920
153921 lblWhereEnd = sqlite3VdbeMakeLabel(pParse);
153922
153923 /* Fill in the context object */
153924 memset(&s, 0, sizeof(WindowCodeArg));
153925 s.pParse = pParse;
153926 s.pMWin = pMWin;
153927 s.pVdbe = v;
153928 s.regGosub = regGosub;
153929 s.addrGosub = addrGosub;
153930 s.current.csr = pMWin->iEphCsr;
153931 csrWrite = s.current.csr+1;
153932 s.start.csr = s.current.csr+2;
153933 s.end.csr = s.current.csr+3;
153934
153935 /* Figure out when rows may be deleted from the ephemeral table. There
153936 ** are four options - they may never be deleted (eDelete==0), they may
153937 ** be deleted as soon as they are no longer part of the window frame
153938 ** (eDelete==WINDOW_AGGINVERSE), they may be deleted as after the row
153939 ** has been returned to the caller (WINDOW_RETURN_ROW), or they may
153940 ** be deleted after they enter the frame (WINDOW_AGGSTEP). */
153941 switch( pMWin->eStart ){
153942 case TK_FOLLOWING:
153943 if( pMWin->eFrmType!=TK_RANGE
153944 && windowExprGtZero(pParse, pMWin->pStart)
153945 ){
153946 s.eDelete = WINDOW_RETURN_ROW;
153947 }
153948 break;
153949 case TK_UNBOUNDED:
153950 if( windowCacheFrame(pMWin)==0 ){
153951 if( pMWin->eEnd==TK_PRECEDING ){
153952 if( pMWin->eFrmType!=TK_RANGE
153953 && windowExprGtZero(pParse, pMWin->pEnd)
153954 ){
153955 s.eDelete = WINDOW_AGGSTEP;
153956 }
153957 }else{
153958 s.eDelete = WINDOW_RETURN_ROW;
153959 }
153960 }
153961 break;
153962 default:
153963 s.eDelete = WINDOW_AGGINVERSE;
153964 break;
153965 }
153966
153967 /* Allocate registers for the array of values from the sub-query, the
153968 ** samve values in record form, and the rowid used to insert said record
153969 ** into the ephemeral table. */
153970 regNew = pParse->nMem+1;
153971 pParse->nMem += nInput;
153972 regRecord = ++pParse->nMem;
153973 regRowid = ++pParse->nMem;
153974
153975 /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
153976 ** clause, allocate registers to store the results of evaluating each
153977 ** <expr>. */
153978 if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
153979 regStart = ++pParse->nMem;
153980 }
153981 if( pMWin->eEnd==TK_PRECEDING || pMWin->eEnd==TK_FOLLOWING ){
153982 regEnd = ++pParse->nMem;
153983 }
153984
153985 /* If this is not a "ROWS BETWEEN ..." frame, then allocate arrays of
153986 ** registers to store copies of the ORDER BY expressions (peer values)
153987 ** for the main loop, and for each cursor (start, current and end). */
153988 if( pMWin->eFrmType!=TK_ROWS ){
153989 int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
153990 regNewPeer = regNew + pMWin->nBufferCol;
153991 if( pMWin->pPartition ) regNewPeer += pMWin->pPartition->nExpr;
153992 regPeer = pParse->nMem+1; pParse->nMem += nPeer;
153993 s.start.reg = pParse->nMem+1; pParse->nMem += nPeer;
153994 s.current.reg = pParse->nMem+1; pParse->nMem += nPeer;
153995 s.end.reg = pParse->nMem+1; pParse->nMem += nPeer;
153996 }
153997
153998 /* Load the column values for the row returned by the sub-select
153999 ** into an array of registers starting at regNew. Assemble them into
154000 ** a record in register regRecord. */
154001 for(iInput=0; iInput<nInput; iInput++){
154002 sqlite3VdbeAddOp3(v, OP_Column, csrInput, iInput, regNew+iInput);
154003 }
154004 sqlite3VdbeAddOp3(v, OP_MakeRecord, regNew, nInput, regRecord);
154005
154006 /* An input row has just been read into an array of registers starting
154007 ** at regNew. If the window has a PARTITION clause, this block generates
154008 ** VM code to check if the input row is the start of a new partition.
154009 ** If so, it does an OP_Gosub to an address to be filled in later. The
154010 ** address of the OP_Gosub is stored in local variable addrGosubFlush. */
154011 if( pMWin->pPartition ){
154012 int addr;
154013 ExprList *pPart = pMWin->pPartition;
154014 int nPart = pPart->nExpr;
154015 int regNewPart = regNew + pMWin->nBufferCol;
154016 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
154017
154018 regFlushPart = ++pParse->nMem;
154019 addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart, nPart);
154020 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
154021 sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
154022 VdbeCoverageEqNe(v);
154023 addrGosubFlush = sqlite3VdbeAddOp1(v, OP_Gosub, regFlushPart);
154024 VdbeComment((v, "call flush_partition"));
154025 sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
154026 }
154027
154028 /* Insert the new row into the ephemeral table */
154029 sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid);
154030 sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid);
154031 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid);
154033
154034 /* This block is run for the first row of each partition */
154035 s.regArg = windowInitAccum(pParse, pMWin);
154036
154037 if( regStart ){
154038 sqlite3ExprCode(pParse, pMWin->pStart, regStart);
154039 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0));
154040 }
154041 if( regEnd ){
154042 sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
154043 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0));
154044 }
154045
154046 if( pMWin->eFrmType!=TK_RANGE && pMWin->eStart==pMWin->eEnd && regStart ){
154047 int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
154048 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
154049 VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
154050 VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */
154051 windowAggFinal(&s, 0);
154052 sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
154055 sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
154056 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
154057 sqlite3VdbeJumpHere(v, addrGe);
154058 }
154059 if( pMWin->eStart==TK_FOLLOWING && pMWin->eFrmType!=TK_RANGE && regEnd ){
154060 assert( pMWin->eEnd==TK_FOLLOWING );
154061 sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
154062 }
154063
154064 if( pMWin->eStart!=TK_UNBOUNDED ){
154065 sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1);
154067 }
154068 sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
154070 sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1);
154072 if( regPeer && pOrderBy ){
154073 sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
154074 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
154075 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
154076 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
154077 }
154078
154079 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
154080
154081 sqlite3VdbeJumpHere(v, addrNe);
154082
154083 /* Beginning of the block executed for the second and subsequent rows. */
154084 if( regPeer ){
154085 windowIfNewPeer(pParse, pOrderBy, regNewPeer, regPeer, lblWhereEnd);
154086 }
154087 if( pMWin->eStart==TK_FOLLOWING ){
154088 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
154089 if( pMWin->eEnd!=TK_UNBOUNDED ){
154090 if( pMWin->eFrmType==TK_RANGE ){
154091 int lbl = sqlite3VdbeMakeLabel(pParse);
154092 int addrNext = sqlite3VdbeCurrentAddr(v);
154093 windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
154094 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154096 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
154097 sqlite3VdbeResolveLabel(v, lbl);
154098 }else{
154099 windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
154100 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154101 }
154102 }
154103 }else
154104 if( pMWin->eEnd==TK_PRECEDING ){
154105 int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
154106 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
154107 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154109 if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154110 }else{
154111 int addr = 0;
154112 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
154113 if( pMWin->eEnd!=TK_UNBOUNDED ){
154114 if( pMWin->eFrmType==TK_RANGE ){
154115 int lbl = 0;
154116 addr = sqlite3VdbeCurrentAddr(v);
154117 if( regEnd ){
154118 lbl = sqlite3VdbeMakeLabel(pParse);
154119 windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
154120 }
154122 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154123 if( regEnd ){
154124 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
154125 sqlite3VdbeResolveLabel(v, lbl);
154126 }
154127 }else{
154128 if( regEnd ){
154129 addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
154130 VdbeCoverage(v);
154131 }
154133 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154134 if( regEnd ) sqlite3VdbeJumpHere(v, addr);
154135 }
154136 }
154137 }
154138
154139 /* End of the main input loop */
154140 sqlite3VdbeResolveLabel(v, lblWhereEnd);
154141 sqlite3WhereEnd(pWInfo);
154142
154143 /* Fall through */
154144 if( pMWin->pPartition ){
154145 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
154146 sqlite3VdbeJumpHere(v, addrGosubFlush);
154147 }
154148
154149 addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
154150 VdbeCoverage(v);
154151 if( pMWin->eEnd==TK_PRECEDING ){
154152 int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
154153 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
154154 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154156 }else if( pMWin->eStart==TK_FOLLOWING ){
154157 int addrStart;
154158 int addrBreak1;
154159 int addrBreak2;
154160 int addrBreak3;
154161 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
154162 if( pMWin->eFrmType==TK_RANGE ){
154163 addrStart = sqlite3VdbeCurrentAddr(v);
154164 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
154165 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
154166 }else
154167 if( pMWin->eEnd==TK_UNBOUNDED ){
154168 addrStart = sqlite3VdbeCurrentAddr(v);
154169 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
154170 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
154171 }else{
154172 assert( pMWin->eEnd==TK_FOLLOWING );
154173 addrStart = sqlite3VdbeCurrentAddr(v);
154174 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
154175 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
154176 }
154177 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
154178 sqlite3VdbeJumpHere(v, addrBreak2);
154179 addrStart = sqlite3VdbeCurrentAddr(v);
154180 addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
154181 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
154182 sqlite3VdbeJumpHere(v, addrBreak1);
154183 sqlite3VdbeJumpHere(v, addrBreak3);
154184 }else{
154185 int addrBreak;
154186 int addrStart;
154187 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
154188 addrStart = sqlite3VdbeCurrentAddr(v);
154189 addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
154190 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
154191 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
154192 sqlite3VdbeJumpHere(v, addrBreak);
154193 }
154194 sqlite3VdbeJumpHere(v, addrEmpty);
154195
154196 sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
154197 if( pMWin->pPartition ){
154198 if( pMWin->regStartRowid ){
static void windowIfNewPeer(Parse *pParse, ExprList *pOrderBy, int regNew, int regOld, int addr)
Definition sqlite3.c:153161
#define VdbeCoverageNeverNullIf(v, x)
Definition sqlite3.c:15999
static void windowCheckValue(Parse *pParse, int reg, int eCond)
Definition sqlite3.c:152596
static int windowCacheFrame(Window *pMWin)
Definition sqlite3.c:153135
static void windowAggFinal(WindowCodeArg *p, int bFin)
Definition sqlite3.c:152882
static void windowCodeRangeTest(WindowCodeArg *p, int op, int csr1, int regVal, int csr2, int lbl)
Definition sqlite3.c:153207
#define VdbeCoverageNeverNull(v)
Definition sqlite3.c:15998
static int windowInitAccum(Parse *pParse, Window *pMWin)
Definition sqlite3.c:153103
static void windowReturnOneRow(WindowCodeArg *p)
Definition sqlite3.c:153027
#define WINDOW_AGGSTEP
Definition sqlite3.c:152874
#define WINDOW_RETURN_ROW
Definition sqlite3.c:152872
static int windowCodeOp(WindowCodeArg *p, int op, int regCountdown, int jumpOnEof)
Definition sqlite3.c:153332
#define WINDOW_AGGINVERSE
Definition sqlite3.c:152873
#define VdbeCoverageEqNe(v)
Definition sqlite3.c:16000
#define TK_TIES
Definition sqlite3.c:14036
#define TK_GROUP
Definition sqlite3.c:14086
static int windowExprGtZero(Parse *pParse, Expr *pExpr)
Definition sqlite3.c:153528
int nBufferCol
Definition sqlite3.c:19213

References SrcList::a, Window::eEnd, Window::eExclude, Window::eFrmType, Window::eStart, SrcList::SrcList_item::iCursor, Window::iEphCsr, Window::nBufferCol, Table::nCol, ExprList::nExpr, Parse::nMem, OP_Column, OP_Compare, OP_Copy, OP_Ge, OP_Gosub, OP_Goto, OP_IfPos, OP_Insert, OP_Integer, OP_Jump, OP_Le, OP_MakeRecord, OP_Ne, OP_NewRowid, OP_ResetSorter, OP_Return, OP_Rewind, OP_Subtract, P4_KEYINFO, Window::pEnd, Window::pOrderBy, Window::pPartition, Select::pSrc, Window::pStart, SrcList::SrcList_item::pTab, Select::pWin, Window::regEndRowid, Window::regOne, Window::regPart, Window::regStartRowid, s, sqlite3ExprCode(), sqlite3GetVdbe(), sqlite3KeyInfoFromExprList(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP1(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), sqlite3WhereEnd(), TK_CURRENT, TK_FOLLOWING, TK_GROUP, TK_NO, TK_PRECEDING, TK_RANGE, TK_ROWS, TK_TIES, TK_UNBOUNDED, VdbeComment, VdbeCoverage, VdbeCoverageEqNe, VdbeCoverageNeverNull, VdbeCoverageNeverNullIf, VdbeCoverageNeverTaken, WINDOW_AGGINVERSE, WINDOW_AGGSTEP, WINDOW_RETURN_ROW, windowAggFinal(), windowCacheFrame(), windowCheckValue(), windowCodeOp(), windowCodeRangeTest(), windowExprGtZero(), windowIfNewPeer(), windowInitAccum(), and windowReturnOneRow().

Referenced by sqlite3Select().

◆ sqlite3WindowCompare()

SQLITE_PRIVATE int sqlite3WindowCompare ( Parse * pParse,
Window * p1,
Window * p2,
int bFilter )

Definition at line 152483 of file sqlite3.c.

152489 {
152490 int res;
152491 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
152492 if( p1->eFrmType!=p2->eFrmType ) return 1;
152493 if( p1->eStart!=p2->eStart ) return 1;
152494 if( p1->eEnd!=p2->eEnd ) return 1;
152495 if( p1->eExclude!=p2->eExclude ) return 1;
152496 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
152497 if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
152498 if( (res = sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1)) ){
152499 return res;
152500 }
152501 if( (res = sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1)) ){
152502 return res;
152503 }
152504 if( bFilter ){

References Window::eEnd, Window::eExclude, Window::eFrmType, Window::eStart, NEVER, Window::pEnd, Window::pFilter, Window::pOrderBy, Window::pPartition, Window::pStart, sqlite3ExprCompare(), and sqlite3ExprListCompare().

Referenced by sqlite3ExprCompare(), sqlite3WindowLink(), and windowAggStep().

◆ sqlite3WindowDelete()

SQLITE_PRIVATE void sqlite3WindowDelete ( sqlite3 * db,
Window * p )

Definition at line 152265 of file sqlite3.c.

152271 {
152272 if( p ){
152274 sqlite3ExprDelete(db, p->pFilter);
152277 sqlite3ExprDelete(db, p->pEnd);
SQLITE_PRIVATE void sqlite3WindowUnlinkFromSelect(Window *)
Definition sqlite3.c:152254

Referenced by yy_destructor().

◆ sqlite3WindowDup()

SQLITE_PRIVATE Window * sqlite3WindowDup ( sqlite3 * db,
Expr * pOwner,
Window * p )

Definition at line 153473 of file sqlite3.c.

153479 {
153480 Window *pNew = 0;
153481 if( ALWAYS(p) ){
153482 pNew = sqlite3DbMallocZero(db, sizeof(Window));
153483 if( pNew ){
153484 pNew->zName = sqlite3DbStrDup(db, p->zName);
153485 pNew->zBase = sqlite3DbStrDup(db, p->zBase);
153486 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
153487 pNew->pFunc = p->pFunc;
153488 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
153489 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
153490 pNew->eFrmType = p->eFrmType;
153491 pNew->eEnd = p->eEnd;
153492 pNew->eStart = p->eStart;
153493 pNew->eExclude = p->eExclude;
153494 pNew->regResult = p->regResult;
153495 pNew->regAccum = p->regAccum;
153496 pNew->iArgCol = p->iArgCol;
153497 pNew->iEphCsr = p->iEphCsr;
153498 pNew->bExprArgs = p->bExprArgs;
153499 pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
153500 pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
char * zName
Definition sqlite3.c:19191
int regAccum
Definition sqlite3.c:19207
int iArgCol
Definition sqlite3.c:19214
u8 bExprArgs
Definition sqlite3.c:19218

References ALWAYS, Window::bExprArgs, Window::bImplicitFrame, Window::eEnd, Window::eExclude, Window::eFrmType, Window::eStart, Window::iArgCol, Window::iEphCsr, Window::pEnd, Window::pFilter, Window::pFunc, Window::pOrderBy, Window::pOwner, Window::pPartition, Window::pStart, Window::regAccum, Window::regResult, sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ExprDup(), sqlite3ExprListDup(), Window::zBase, and Window::zName.

Referenced by exprDup().

◆ sqlite3WindowExtraAggFuncDepth()

static int sqlite3WindowExtraAggFuncDepth ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 152088 of file sqlite3.c.

152094 {
152095 if( pExpr->op==TK_AGG_FUNCTION

References Expr::op, Expr::op2, TK_AGG_FUNCTION, Walker::walkerDepth, and WRC_Continue.

Referenced by sqlite3WindowRewrite().

◆ sqlite3WindowFunctions()

SQLITE_PRIVATE void sqlite3WindowFunctions ( void )

Definition at line 151769 of file sqlite3.c.

151775 {
151776 static FuncDef aWindowFuncs[] = {
151777 WINDOWFUNCX(row_number, 0, 0),
151778 WINDOWFUNCX(dense_rank, 0, 0),
151779 WINDOWFUNCX(rank, 0, 0),
151780 WINDOWFUNCALL(percent_rank, 0, 0),
151781 WINDOWFUNCALL(cume_dist, 0, 0),
151782 WINDOWFUNCALL(ntile, 1, 0),
151783 WINDOWFUNCALL(last_value, 1, 0),
151784 WINDOWFUNCALL(nth_value, 2, 0),
151785 WINDOWFUNCALL(first_value, 1, 0),
151786 WINDOWFUNCNOOP(lead, 1, 0),
151787 WINDOWFUNCNOOP(lead, 2, 0),
151788 WINDOWFUNCNOOP(lead, 3, 0),
#define WINDOWFUNCNOOP(name, nArg, extra)
Definition sqlite3.c:151750
#define WINDOWFUNCALL(name, nArg, extra)
Definition sqlite3.c:151742
#define WINDOWFUNCX(name, nArg, extra)
Definition sqlite3.c:151759

References WINDOWFUNCALL, WINDOWFUNCNOOP, and WINDOWFUNCX.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ sqlite3WindowLink()

SQLITE_PRIVATE void sqlite3WindowLink ( Select * pSel,
Window * pWin )

Definition at line 152465 of file sqlite3.c.

152471 {
152472 if( pSel!=0
152473 && (0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0))
152474 ){
152475 pWin->pNextWin = pSel->pWin;
152476 if( pSel->pWin ){

References Window::pNextWin, Window::ppThis, Select::pWin, WindowRewrite::pWin, and sqlite3WindowCompare().

Referenced by resolveExprStep().

◆ sqlite3WindowListDelete()

SQLITE_PRIVATE void sqlite3WindowListDelete ( sqlite3 * db,
Window * p )

Definition at line 152282 of file sqlite3.c.

152288 {

Referenced by clearSelect(), yy_destructor(), and yy_reduce().

◆ sqlite3WindowListDup()

SQLITE_PRIVATE Window * sqlite3WindowListDup ( sqlite3 * db,
Window * p )

Definition at line 153506 of file sqlite3.c.

153512 {
153513 Window *pWin;
153514 Window *pRet = 0;
153515 Window **pp = &pRet;
153516
153517 for(pWin=p; pWin; pWin=pWin->pNextWin){
153518 *pp = sqlite3WindowDup(db, 0, pWin);

◆ sqlite3WindowOffsetExpr()

static Expr * sqlite3WindowOffsetExpr ( Parse * pParse,
Expr * pExpr )
static

◆ sqlite3WindowRewrite()

SQLITE_PRIVATE int sqlite3WindowRewrite ( Parse * pParse,
Select * p )

Definition at line 152104 of file sqlite3.c.

152110 {
152111 int rc = SQLITE_OK;
152112 if( p->pWin && p->pPrior==0 && (p->selFlags & SF_WinRewrite)==0 ){
152113 Vdbe *v = sqlite3GetVdbe(pParse);
152114 sqlite3 *db = pParse->db;
152115 Select *pSub = 0; /* The subquery */
152116 SrcList *pSrc = p->pSrc;
152117 Expr *pWhere = p->pWhere;
152118 ExprList *pGroupBy = p->pGroupBy;
152119 Expr *pHaving = p->pHaving;
152120 ExprList *pSort = 0;
152121
152122 ExprList *pSublist = 0; /* Expression list for sub-query */
152123 Window *pMWin = p->pWin; /* Main window object */
152124 Window *pWin; /* Window object iterator */
152125 Table *pTab;
152126 Walker w;
152127
152128 u32 selFlags = p->selFlags;
152129
152130 pTab = sqlite3DbMallocZero(db, sizeof(Table));
152131 if( pTab==0 ){
152133 }
152135 sqlite3WalkSelect(&w, p);
152136
152137 p->pSrc = 0;
152138 p->pWhere = 0;
152139 p->pGroupBy = 0;
152140 p->pHaving = 0;
152141 p->selFlags &= ~SF_Aggregate;
152142 p->selFlags |= SF_WinRewrite;
152143
152144 /* Create the ORDER BY clause for the sub-select. This is the concatenation
152145 ** of the window PARTITION and ORDER BY clauses. Then, if this makes it
152146 ** redundant, remove the ORDER BY from the parent SELECT. */
152147 pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1);
152148 pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy, 1);
152149 if( pSort && p->pOrderBy && p->pOrderBy->nExpr<=pSort->nExpr ){
152150 int nSave = pSort->nExpr;
152151 pSort->nExpr = p->pOrderBy->nExpr;
152152 if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
152154 p->pOrderBy = 0;
152155 }
152156 pSort->nExpr = nSave;
152157 }
152158
152159 /* Assign a cursor number for the ephemeral table used to buffer rows.
152160 ** The OpenEphemeral instruction is coded later, after it is known how
152161 ** many columns the table will have. */
152162 pMWin->iEphCsr = pParse->nTab++;
152163 pParse->nTab += 3;
152164
152165 selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, pTab, &pSublist);
152166 selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, pTab, &pSublist);
152167 pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
152168
152169 /* Append the PARTITION BY and ORDER BY expressions to the to the
152170 ** sub-select expression list. They are required to figure out where
152171 ** boundaries for partitions and sets of peer rows lie. */
152172 pSublist = exprListAppendList(pParse, pSublist, pMWin->pPartition, 0);
152173 pSublist = exprListAppendList(pParse, pSublist, pMWin->pOrderBy, 0);
152174
152175 /* Append the arguments passed to each window function to the
152176 ** sub-select expression list. Also allocate two registers for each
152177 ** window function - one for the accumulator, another for interim
152178 ** results. */
152179 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
152180 ExprList *pArgs = pWin->pOwner->x.pList;
152181 if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
152182 selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
152183 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
152184 pWin->bExprArgs = 1;
152185 }else{
152186 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
152187 pSublist = exprListAppendList(pParse, pSublist, pArgs, 0);
152188 }
152189 if( pWin->pFilter ){
152190 Expr *pFilter = sqlite3ExprDup(db, pWin->pFilter, 0);
152191 pSublist = sqlite3ExprListAppend(pParse, pSublist, pFilter);
152192 }
152193 pWin->regAccum = ++pParse->nMem;
152194 pWin->regResult = ++pParse->nMem;
152195 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
152196 }
152197
152198 /* If there is no ORDER BY or PARTITION BY clause, and the window
152199 ** function accepts zero arguments, and there are no other columns
152200 ** selected (e.g. "SELECT row_number() OVER () FROM t1"), it is possible
152201 ** that pSublist is still NULL here. Add a constant expression here to
152202 ** keep everything legal in this case.
152203 */
152204 if( pSublist==0 ){
152205 pSublist = sqlite3ExprListAppend(pParse, 0,
152206 sqlite3Expr(db, TK_INTEGER, "0")
152207 );
152208 }
152209
152210 pSub = sqlite3SelectNew(
152211 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
152212 );
152213 SELECTTRACE(1,pParse,pSub,
152214 ("New window-function subquery in FROM clause of (%u/%p)\n",
152215 p->selId, p));
152216 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
152217 if( p->pSrc ){
152218 Table *pTab2;
152219 p->pSrc->a[0].pSelect = pSub;
152220 sqlite3SrcListAssignCursors(pParse, p->pSrc);
152221 pSub->selFlags |= SF_Expanded;
152222 pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
152223 pSub->selFlags |= (selFlags & SF_Aggregate);
152224 if( pTab2==0 ){
152225 /* Might actually be some other kind of error, but in that case
152226 ** pParse->nErr will be set, so if SQLITE_NOMEM is set, we will get
152227 ** the correct error message regardless. */
152228 rc = SQLITE_NOMEM;
152229 }else{
152230 memcpy(pTab, pTab2, sizeof(Table));
152231 pTab->tabFlags |= TF_Ephemeral;
152232 p->pSrc->a[0].pTab = pTab;
152233 pTab = pTab2;
152234 memset(&w, 0, sizeof(w));
152238 sqlite3WalkSelect(&w, pSub);
152239 }
152240 }else{
152241 sqlite3SelectDelete(db, pSub);
152242 }
152243 if( db->mallocFailed ) rc = SQLITE_NOMEM;
152244 sqlite3DbFree(db, pTab);
152245 }
152246
152247 if( rc ){
152248 if( pParse->nErr==0 ){
static void selectWindowRewriteEList(Parse *pParse, Window *pWin, SrcList *pSrc, ExprList *pEList, Table *pTab, ExprList **ppSub)
Definition sqlite3.c:152015
#define SQLITE_FUNC_SUBTYPE
Definition sqlite3.c:17163
static ExprList * exprListAppendList(Parse *pParse, ExprList *pList, ExprList *pAppend, int bIntToNull)
Definition sqlite3.c:152049
#define SF_WinRewrite
Definition sqlite3.c:18491
static int sqlite3WindowExtraAggFuncDepth(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:152088

References SrcList::a, Window::bExprArgs, Parse::db, exprListAppendList(), FuncDef::funcFlags, Window::iArgCol, Window::iEphCsr, sqlite3::mallocFailed, Window::nBufferCol, Parse::nErr, ExprList::nExpr, Parse::nMem, Parse::nTab, OP_Null, Select::pEList, Window::pFilter, Window::pFunc, Select::pGroupBy, Select::pHaving, Expr::pList, Window::pNextWin, Select::pOrderBy, Window::pOrderBy, Window::pOwner, Window::pPartition, Select::pPrior, SrcList::SrcList_item::pSelect, Select::pSrc, WindowRewrite::pSrc, WindowRewrite::pSub, SrcList::SrcList_item::pTab, WindowRewrite::pTab, Select::pWhere, Select::pWin, WindowRewrite::pWin, Window::regAccum, Window::regResult, SELECTTRACE, selectWindowRewriteEList(), Select::selFlags, Select::selId, SF_Aggregate, SF_Expanded, SF_WinRewrite, sqlite3AggInfoPersistWalkerInit(), sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3ErrorToParser(), sqlite3Expr(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3ExprListCompare(), sqlite3ExprListDelete(), sqlite3GetVdbe(), sqlite3ResultSetOfSelect(), sqlite3SelectDelete(), sqlite3SelectNew(), sqlite3SrcListAppend(), sqlite3SrcListAssignCursors(), sqlite3VdbeAddOp2(), sqlite3WalkerDepthDecrease(), sqlite3WalkerDepthIncrease(), sqlite3WalkSelect(), sqlite3WindowExtraAggFuncDepth(), SQLITE_AFF_NONE, SQLITE_FUNC_SUBTYPE, SQLITE_NOMEM, SQLITE_OK, Table::tabFlags, TF_Ephemeral, TK_INTEGER, Expr::x, Walker::xExprCallback, Walker::xSelectCallback, and Walker::xSelectCallback2.

Referenced by sqlite3Select().

◆ sqlite3WindowUnlinkFromSelect()

SQLITE_PRIVATE void sqlite3WindowUnlinkFromSelect ( Window * p)

Definition at line 152254 of file sqlite3.c.

152260 {

◆ sqlite3WindowUpdate()

SQLITE_PRIVATE void sqlite3WindowUpdate ( Parse * pParse,
Window * pList,
Window * pWin,
FuncDef * pFunc )

Definition at line 151818 of file sqlite3.c.

151829 {
151830 if( pWin->zName && pWin->eFrmType==0 ){
151831 Window *p = windowFind(pParse, pList, pWin->zName);
151832 if( p==0 ) return;
151833 pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
151834 pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
151835 pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
151836 pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
151837 pWin->eStart = p->eStart;
151838 pWin->eEnd = p->eEnd;
151839 pWin->eFrmType = p->eFrmType;
151840 pWin->eExclude = p->eExclude;
151841 }else{
151842 sqlite3WindowChain(pParse, pWin, pList);
151843 }
151844 if( (pWin->eFrmType==TK_RANGE)
151845 && (pWin->pStart || pWin->pEnd)
151846 && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
151847 ){
151848 sqlite3ErrorMsg(pParse,
151849 "RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression"
151850 );
151851 }else
151852 if( pFunc->funcFlags & SQLITE_FUNC_WINDOW ){
151853 sqlite3 *db = pParse->db;
151854 if( pWin->pFilter ){
151855 sqlite3ErrorMsg(pParse,
151856 "FILTER clause may only be used with aggregate window functions"
151857 );
151858 }else{
151859 struct WindowUpdate {
151860 const char *zFunc;
151861 int eFrmType;
151862 int eStart;
151863 int eEnd;
151864 } aUp[] = {
151873 };
151874 int i;
151875 for(i=0; i<ArraySize(aUp); i++){
151876 if( pFunc->zName==aUp[i].zFunc ){
151877 sqlite3ExprDelete(db, pWin->pStart);
151878 sqlite3ExprDelete(db, pWin->pEnd);
151879 pWin->pEnd = pWin->pStart = 0;
151880 pWin->eFrmType = aUp[i].eFrmType;
151881 pWin->eStart = aUp[i].eStart;
151882 pWin->eEnd = aUp[i].eEnd;
151883 pWin->eExclude = 0;
151884 if( pWin->eStart==TK_FOLLOWING ){
151885 pWin->pStart = sqlite3Expr(db, TK_INTEGER, "1");
151886 }
151887 break;
SQLITE_PRIVATE void sqlite3WindowChain(Parse *, Window *, Window *)
Definition sqlite3.c:152408
static const char cume_distName[]
Definition sqlite3.c:151711
static const char lagName[]
Definition sqlite3.c:151717
static const char ntileName[]
Definition sqlite3.c:151712
static const char percent_rankName[]
Definition sqlite3.c:151710
static const char leadName[]
Definition sqlite3.c:151716
static const char rankName[]
Definition sqlite3.c:151709
static const char row_numberName[]
Definition sqlite3.c:151707
static const char dense_rankName[]
Definition sqlite3.c:151708

References ArraySize, cume_distName, Parse::db, dense_rankName, Window::eEnd, Window::eExclude, Window::eFrmType, Window::eStart, FuncDef::funcFlags, lagName, leadName, ExprList::nExpr, ntileName, Window::pEnd, percent_rankName, Window::pFilter, Window::pFunc, Window::pOrderBy, Window::pPartition, Window::pStart, rankName, row_numberName, sqlite3ErrorMsg(), sqlite3Expr(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprListDup(), sqlite3WindowChain(), SQLITE_FUNC_WINDOW, TK_CURRENT, TK_FOLLOWING, TK_GROUPS, TK_INTEGER, TK_RANGE, TK_ROWS, TK_UNBOUNDED, windowFind(), FuncDef::zName, and Window::zName.

Referenced by resolveExprStep().

◆ sqlite3WithAdd()

SQLITE_PRIVATE With * sqlite3WithAdd ( Parse * pParse,
With * pWith,
Token * pName,
ExprList * pArglist,
Select * pQuery )

Definition at line 115471 of file sqlite3.c.

115483 {
115484 sqlite3 *db = pParse->db;
115485 With *pNew;
115486 char *zName;
115487
115488 /* Check that the CTE name is unique within this WITH clause. If
115489 ** not, store an error in the Parse structure. */
115490 zName = sqlite3NameFromToken(pParse->db, pName);
115491 if( zName && pWith ){
115492 int i;
115493 for(i=0; i<pWith->nCte; i++){
115494 if( sqlite3StrICmp(zName, pWith->a[i].zName)==0 ){
115495 sqlite3ErrorMsg(pParse, "duplicate WITH table name: %s", zName);
115496 }
115497 }
115498 }
115499
115500 if( pWith ){
115501 sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
115502 pNew = sqlite3DbRealloc(db, pWith, nByte);
115503 }else{
115504 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
115505 }
115506 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
115507
115508 if( db->mallocFailed ){
115509 sqlite3ExprListDelete(db, pArglist);
115510 sqlite3SelectDelete(db, pQuery);
115511 sqlite3DbFree(db, zName);
115512 pNew = pWith;
115513 }else{
115514 pNew->a[pNew->nCte].pSelect = pQuery;
115515 pNew->a[pNew->nCte].pCols = pArglist;
115516 pNew->a[pNew->nCte].zName = zName;
ExprList * pCols
Definition sqlite3.c:19150

References With::a, Parse::db, sqlite3::mallocFailed, With::nCte, With::Cte::pCols, With::Cte::pSelect, sqlite3DbFree(), sqlite3DbMallocZero(), sqlite3DbRealloc(), sqlite3ErrorMsg(), sqlite3ExprListDelete(), sqlite3NameFromToken(), sqlite3SelectDelete(), sqlite3StrICmp(), With::Cte::zCteErr, With::Cte::zName, and zName.

Referenced by yy_reduce().

◆ sqlite3WithDelete()

SQLITE_PRIVATE void sqlite3WithDelete ( sqlite3 * db,
With * pWith )

Definition at line 115521 of file sqlite3.c.

115527 {
115528 if( pWith ){
115529 int i;
115530 for(i=0; i<pWith->nCte; i++){
115531 struct Cte *pCte = &pWith->a[i];
115532 sqlite3ExprListDelete(db, pCte->pCols);

Referenced by clearSelect(), sqlite3RunParser(), yy_destructor(), and yy_reduce().

◆ sqlite3WithPush()

SQLITE_PRIVATE void sqlite3WithPush ( Parse * pParse,
With * pWith,
u8 bFree )

Definition at line 134046 of file sqlite3.c.

134052 {
134053 assert( bFree==0 || (pParse->pWith==0 && pParse->pWithToFree==0) );
134054 if( pWith ){

References With::pOuter, Parse::pWith, and Parse::pWithToFree.

Referenced by selectExpander(), and yy_reduce().

◆ sqlite3WritableSchema()

SQLITE_PRIVATE int sqlite3WritableSchema ( sqlite3 * db)

Definition at line 111250 of file sqlite3.c.

Referenced by lockBtree(), sqlite3CheckObjectName(), and tabIsReadOnly().

◆ sqliteAuthBadReturnCode()

static void sqliteAuthBadReturnCode ( Parse * pParse)
static

Definition at line 110202 of file sqlite3.c.

Referenced by sqlite3AuthCheck(), and sqlite3AuthReadCol().

◆ sqliteDefaultBusyCallback()

static int sqliteDefaultBusyCallback ( void * ptr,
int count )
static

Definition at line 162609 of file sqlite3.c.

162618 {
162619#if SQLITE_OS_WIN || HAVE_USLEEP
162620 /* This case is for systems that have support for sleeping for fractions of
162621 ** a second. Examples: All windows systems, unix systems with usleep() */
162622 static const u8 delays[] =
162623 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
162624 static const u8 totals[] =
162625 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
162626# define NDELAY ArraySize(delays)
162627 sqlite3 *db = (sqlite3 *)ptr;
162628 int tmout = db->busyTimeout;
162629 int delay, prior;
162630
162631 assert( count>=0 );
162632 if( count < NDELAY ){
162633 delay = delays[count];
162634 prior = totals[count];
162635 }else{
162636 delay = delays[NDELAY-1];
162637 prior = totals[NDELAY-1] + delay*(count-(NDELAY-1));
162638 }
162639 if( prior + delay > tmout ){
162640 delay = tmout - prior;
162641 if( delay<=0 ) return 0;
162642 }
162643 sqlite3OsSleep(db->pVfs, delay*1000);
162644 return 1;
162645#else
162646 /* This case for unix systems that lack usleep() support. Sleeping
162647 ** must be done in increments of whole seconds */
162648 sqlite3 *db = (sqlite3 *)ptr;
162649 int tmout = ((sqlite3 *)ptr)->busyTimeout;
162650 if( (count+1)*1000 > tmout ){
SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int)
Definition sqlite3.c:23232

References sqlite3::busyTimeout, sqlite3::pVfs, and sqlite3OsSleep().

Referenced by sqlite3_busy_timeout().

◆ sqliteErrorFromPosixError()

static int sqliteErrorFromPosixError ( int posixError,
int sqliteIOErr )
static

Definition at line 34404 of file sqlite3.c.

34410 {
34411 assert( (sqliteIOErr == SQLITE_IOERR_LOCK) ||
34412 (sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
34413 (sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
34414 (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) );
34415 switch (posixError) {
34416 case EACCES:
34417 case EAGAIN:
34418 case ETIMEDOUT:
34419 case EBUSY:
34420 case EINTR:
34421 case ENOLCK:
34422 /* random NFS retry error, unless during file system support
34423 * introspection, in which it actually means what it says */
34424 return SQLITE_BUSY;
34425
34426 case EPERM:

References SQLITE_BUSY, SQLITE_IOERR_CHECKRESERVEDLOCK, SQLITE_IOERR_LOCK, SQLITE_IOERR_RDLOCK, SQLITE_IOERR_UNLOCK, and SQLITE_PERM.

Referenced by dotlockLock(), posixUnlock(), and unixLock().

◆ sqliteProcessJoin()

static int sqliteProcessJoin ( Parse * pParse,
Select * p )
static

Definition at line 129728 of file sqlite3.c.

129734 {
129735 SrcList *pSrc; /* All tables in the FROM clause */
129736 int i, j; /* Loop counters */
129737 struct SrcList_item *pLeft; /* Left table being joined */
129738 struct SrcList_item *pRight; /* Right table being joined */
129739
129740 pSrc = p->pSrc;
129741 pLeft = &pSrc->a[0];
129742 pRight = &pLeft[1];
129743 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
129744 Table *pRightTab = pRight->pTab;
129745 int isOuter;
129746
129747 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
129748 isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
129749
129750 /* When the NATURAL keyword is present, add WHERE clause terms for
129751 ** every column that the two tables have in common.
129752 */
129753 if( pRight->fg.jointype & JT_NATURAL ){
129754 if( pRight->pOn || pRight->pUsing ){
129755 sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
129756 "an ON or USING clause", 0);
129757 return 1;
129758 }
129759 for(j=0; j<pRightTab->nCol; j++){
129760 char *zName; /* Name of column in the right table */
129761 int iLeft; /* Matching left table */
129762 int iLeftCol; /* Matching column in the left table */
129763
129764 if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
129765 zName = pRightTab->aCol[j].zName;
129766 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
129767 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
129768 isOuter, &p->pWhere);
129769 }
129770 }
129771 }
129772
129773 /* Disallow both ON and USING clauses in the same join
129774 */
129775 if( pRight->pOn && pRight->pUsing ){
129776 sqlite3ErrorMsg(pParse, "cannot have both ON and USING "
129777 "clauses in the same join");
129778 return 1;
129779 }
129780
129781 /* Add the ON clause to the end of the WHERE clause, connected by
129782 ** an AND operator.
129783 */
129784 if( pRight->pOn ){
129785 if( isOuter ) sqlite3SetJoinExpr(pRight->pOn, pRight->iCursor);
129786 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->pOn);
129787 pRight->pOn = 0;
129788 }
129789
129790 /* Create extra terms on the WHERE clause for each column named
129791 ** in the USING clause. Example: If the two tables to be joined are
129792 ** A and B and the USING clause names X, Y, and Z, then add this
129793 ** to the WHERE clause: A.X=B.X AND A.Y=B.Y AND A.Z=B.Z
129794 ** Report an error if any column mentioned in the USING clause is
129795 ** not contained in both tables to be joined.
129796 */
129797 if( pRight->pUsing ){
129798 IdList *pList = pRight->pUsing;
129799 for(j=0; j<pList->nId; j++){
129800 char *zName; /* Name of the term in the USING clause */
129801 int iLeft; /* Table on the left with matching column name */
129802 int iLeftCol; /* Column number of matching column on the left */
129803 int iRightCol; /* Column number of matching column on the right */
129804
129805 zName = pList->a[j].zName;
129806 iRightCol = columnIndex(pRightTab, zName);
129807 if( iRightCol<0
129808 || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 0)
129809 ){
129810 sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
129811 "not present in both tables", zName);
129812 return 1;
129813 }
129814 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, iRightCol,
static void addWhereTerm(Parse *pParse, SrcList *pSrc, int iLeft, int iColLeft, int iRight, int iColRight, int isOuterJoin, Expr **ppWhere)
Definition sqlite3.c:129615
static int columnIndex(Table *pTab, const char *zCol)
Definition sqlite3.c:129558

References IdList::a, SrcList::a, Table::aCol, addWhereTerm(), columnIndex(), IsHiddenColumn, JT_NATURAL, JT_OUTER, Table::nCol, NEVER, IdList::nId, SrcList::nSrc, Select::pSrc, Select::pWhere, sqlite3ErrorMsg(), sqlite3ExprAnd(), sqlite3SetJoinExpr(), tableAndColumnIndex(), Column::zName, IdList::IdList_item::zName, and zName.

Referenced by selectExpander().

◆ sqliteVdbePopStack()

void sqliteVdbePopStack ( Vdbe * ,
int  )

◆ sqliteViewResetAll()

static void sqliteViewResetAll ( sqlite3 * db,
int idx )
static

Definition at line 113162 of file sqlite3.c.

113168 {
113169 HashElem *i;
113170 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
113171 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
113172 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
113173 Table *pTab = sqliteHashData(i);
113174 if( pTab->pSelect ){
113175 sqlite3DeleteColumnNames(db, pTab);

References Table::aCol, sqlite3::aDb, DB_UnresetViews, DbClearProperty, DbHasProperty, Table::nCol, Db::pSchema, Table::pSelect, sqlite3DeleteColumnNames(), sqliteHashData, sqliteHashFirst, sqliteHashNext, and Schema::tblHash.

◆ sqliteViewTriggers()

void sqliteViewTriggers ( Parse * ,
Table * ,
Expr * ,
int ,
ExprList *  )

◆ statAccumDestructor()

static void statAccumDestructor ( void * pOld)
static

Definition at line 107908 of file sqlite3.c.

107914 {
107915 StatAccum *p = (StatAccum*)pOld;
107916#ifdef SQLITE_ENABLE_STAT4
107917 if( p->mxSample ){
107918 int i;
107919 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
sqlite3 * db
Definition sqlite3.c:107825

◆ statGet()

static void statGet ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 108357 of file sqlite3.c.

108367 {
108368 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
108369#ifdef SQLITE_ENABLE_STAT4
108370 /* STAT4 has a parameter on this routine. */
108371 int eCall = sqlite3_value_int(argv[1]);
108372 assert( argc==2 );
108373 assert( eCall==STAT_GET_STAT1 || eCall==STAT_GET_NEQ
108374 || eCall==STAT_GET_ROWID || eCall==STAT_GET_NLT
108375 || eCall==STAT_GET_NDLT
108376 );
108377 assert( eCall==STAT_GET_STAT1 || p->mxSample );
108378 if( eCall==STAT_GET_STAT1 )
108379#else
108380 assert( argc==1 );
108381#endif
108382 {
108383 /* Return the value to store in the "stat" column of the sqlite_stat1
108384 ** table for this index.
108385 **
108386 ** The value is a string composed of a list of integers describing
108387 ** the index. The first integer in the list is the total number of
108388 ** entries in the index. There is one additional integer in the list
108389 ** for each indexed column. This additional integer is an estimate of
108390 ** the number of rows matched by a equality query on the index using
108391 ** a key with the corresponding number of fields. In other words,
108392 ** if the index is on columns (a,b) and the sqlite_stat1 value is
108393 ** "100 10 2", then SQLite estimates that:
108394 **
108395 ** * the index contains 100 rows,
108396 ** * "WHERE a=?" matches 10 rows, and
108397 ** * "WHERE a=? AND b=?" matches 2 rows.
108398 **
108399 ** If D is the count of distinct values and K is the total number of
108400 ** rows, then each estimate is computed as:
108401 **
108402 ** I = (K+D-1)/D
108403 */
108404 char *z;
108405 int i;
108406
108407 char *zRet = sqlite3MallocZero( (p->nKeyCol+1)*25 );
108408 if( zRet==0 ){
108410 return;
108411 }
108412
108413 sqlite3_snprintf(24, zRet, "%llu",
108414 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
108415 z = zRet + sqlite3Strlen30(zRet);
108416 for(i=0; i<p->nKeyCol; i++){
108417 u64 nDistinct = p->current.anDLt[i] + 1;
108418 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
108419 sqlite3_snprintf(24, z, " %llu", iVal);
108420 z += sqlite3Strlen30(z);
108421 assert( p->current.anEq[i] );
108422 }
108423 assert( z[0]=='\0' && z>zRet );
108424
108425 sqlite3_result_text(context, zRet, -1, sqlite3_free);
108426 }
108427#ifdef SQLITE_ENABLE_STAT4
108428 else if( eCall==STAT_GET_ROWID ){
108429 if( p->iGet<0 ){
108430 samplePushPrevious(p, 0);
108431 p->iGet = 0;
108432 }
108433 if( p->iGet<p->nSample ){
108434 StatSample *pS = p->a + p->iGet;
108435 if( pS->nRowid==0 ){
108436 sqlite3_result_int64(context, pS->u.iRowid);
108437 }else{
108438 sqlite3_result_blob(context, pS->u.aRowid, pS->nRowid,
108440 }
108441 }
108442 }else{
108443 tRowcnt *aCnt = 0;
108444
108445 assert( p->iGet<p->nSample );
108446 switch( eCall ){
108447 case STAT_GET_NEQ: aCnt = p->a[p->iGet].anEq; break;
108448 case STAT_GET_NLT: aCnt = p->a[p->iGet].anLt; break;
108449 default: {
108450 aCnt = p->a[p->iGet].anDLt;
108451 p->iGet++;
108452 break;
108453 }
108454 }
108455
108456 {
108457 char *zRet = sqlite3MallocZero(p->nCol * 25);
108458 if( zRet==0 ){
108460 }else{
108461 int i;
108462 char *z = zRet;
108463 for(i=0; i<p->nCol; i++){
108464 sqlite3_snprintf(24, z, "%llu ", (u64)aCnt[i]);
108465 z += sqlite3Strlen30(z);
108466 }
108467 assert( z[0]=='\0' && z>zRet );
108468 z[-1] = '\0';
108469 sqlite3_result_text(context, zRet, -1, sqlite3_free);
108470 }
108471 }
tRowcnt nRow
Definition sqlite3.c:107827
StatSample current
Definition sqlite3.c:107832
tRowcnt nEst
Definition sqlite3.c:107826
tRowcnt * anEq
Definition sqlite3.c:107810
tRowcnt * anDLt
Definition sqlite3.c:107811

References StatSample::anDLt, StatSample::anEq, StatAccum::current, StatAccum::nCol, StatAccum::nEst, StatAccum::nKeyCol, StatAccum::nRow, StatAccum::nSkipAhead, sqlite3_free(), sqlite3_result_blob(), sqlite3_result_error_nomem(), sqlite3_result_int64(), sqlite3_result_text(), sqlite3_snprintf(), sqlite3_value_blob(), sqlite3_value_int(), sqlite3MallocZero(), sqlite3Strlen30(), SQLITE_TRANSIENT, STAT_GET_NDLT, STAT_GET_NEQ, STAT_GET_NLT, STAT_GET_ROWID, and STAT_GET_STAT1.

◆ statInit()

static void statInit ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 107943 of file sqlite3.c.

107953 {
107954 StatAccum *p;
107955 int nCol; /* Number of columns in index being sampled */
107956 int nKeyCol; /* Number of key columns */
107957 int nColUp; /* nCol rounded up for alignment */
107958 int n; /* Bytes of space to allocate */
107959 sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */
107960#ifdef SQLITE_ENABLE_STAT4
107961 /* Maximum number of samples. 0 if STAT4 data is not collected */
107963#endif
107964
107965 /* Decode the three function arguments */
107966 UNUSED_PARAMETER(argc);
107967 nCol = sqlite3_value_int(argv[0]);
107968 assert( nCol>0 );
107969 nColUp = sizeof(tRowcnt)<8 ? (nCol+1)&~1 : nCol;
107970 nKeyCol = sqlite3_value_int(argv[1]);
107971 assert( nKeyCol<=nCol );
107972 assert( nKeyCol>0 );
107973
107974 /* Allocate the space required for the StatAccum object */
107975 n = sizeof(*p)
107976 + sizeof(tRowcnt)*nColUp /* StatAccum.anEq */
107977 + sizeof(tRowcnt)*nColUp; /* StatAccum.anDLt */
107978#ifdef SQLITE_ENABLE_STAT4
107979 if( mxSample ){
107980 n += sizeof(tRowcnt)*nColUp /* StatAccum.anLt */
107981 + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */
107982 + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample);
107983 }
107984#endif
107985 db = sqlite3_context_db_handle(context);
107986 p = sqlite3DbMallocZero(db, n);
107987 if( p==0 ){
107989 return;
107990 }
107991
107992 p->db = db;
107993 p->nEst = sqlite3_value_int64(argv[2]);
107994 p->nRow = 0;
107995 p->nLimit = sqlite3_value_int64(argv[3]);
107996 p->nCol = nCol;
107997 p->nKeyCol = nKeyCol;
107998 p->nSkipAhead = 0;
107999 p->current.anDLt = (tRowcnt*)&p[1];
108000 p->current.anEq = &p->current.anDLt[nColUp];
108001
108002#ifdef SQLITE_ENABLE_STAT4
108003 p->mxSample = p->nLimit==0 ? mxSample : 0;
108004 if( mxSample ){
108005 u8 *pSpace; /* Allocated space not yet assigned */
108006 int i; /* Used to iterate through p->aSample[] */
108007
108008 p->iGet = -1;
108009 p->nPSample = (tRowcnt)(p->nEst/(mxSample/3+1) + 1);
108010 p->current.anLt = &p->current.anEq[nColUp];
108011 p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
108012
108013 /* Set up the StatAccum.a[] and aBest[] arrays */
108014 p->a = (struct StatSample*)&p->current.anLt[nColUp];
108015 p->aBest = &p->a[mxSample];
108016 pSpace = (u8*)(&p->a[mxSample+nCol]);
108017 for(i=0; i<(mxSample+nCol); i++){
108018 p->a[i].anEq = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);
108019 p->a[i].anLt = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);
108020 p->a[i].anDLt = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);
108021 }
108022 assert( (pSpace - (u8*)p)==n );
108023
108024 for(i=0; i<nCol; i++){
108025 p->aBest[i].iCol = i;
108026 }
108027 }
108028#endif
108029
#define SQLITE_STAT4_SAMPLES
Definition sqlite3.c:107693

References StatSample::anDLt, StatSample::anEq, StatAccum::current, StatAccum::db, StatAccum::nCol, StatAccum::nEst, StatAccum::nKeyCol, StatAccum::nLimit, StatAccum::nRow, StatAccum::nSkipAhead, OptimizationEnabled, sqlite3_context_db_handle(), sqlite3_result_error_nomem(), sqlite3_value_int(), sqlite3_value_int64(), sqlite3DbMallocZero(), SQLITE_Stat4, SQLITE_STAT4_SAMPLES, and UNUSED_PARAMETER.

◆ statPush()

static void statPush ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 108245 of file sqlite3.c.

108255 {
108256 int i;
108257
108258 /* The three function arguments */
108259 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
108260 int iChng = sqlite3_value_int(argv[1]);
108261
108262 UNUSED_PARAMETER( argc );
108263 UNUSED_PARAMETER( context );
108264 assert( p->nCol>0 );
108265 assert( iChng<p->nCol );
108266
108267 if( p->nRow==0 ){
108268 /* This is the first call to this function. Do initialization. */
108269 for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1;
108270 }else{
108271 /* Second and subsequent calls get processed here */
108272#ifdef SQLITE_ENABLE_STAT4
108273 if( p->mxSample ) samplePushPrevious(p, iChng);
108274#endif
108275
108276 /* Update anDLt[], anLt[] and anEq[] to reflect the values that apply
108277 ** to the current row of the index. */
108278 for(i=0; i<iChng; i++){
108279 p->current.anEq[i]++;
108280 }
108281 for(i=iChng; i<p->nCol; i++){
108282 p->current.anDLt[i]++;
108283#ifdef SQLITE_ENABLE_STAT4
108284 if( p->mxSample ) p->current.anLt[i] += p->current.anEq[i];
108285#endif
108286 p->current.anEq[i] = 1;
108287 }
108288 }
108289
108290 p->nRow++;
108291#ifdef SQLITE_ENABLE_STAT4
108292 if( p->mxSample ){
108293 tRowcnt nLt;
108294 if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){
108295 sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
108296 }else{
108297 sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
108298 sqlite3_value_blob(argv[2]));
108299 }
108300 p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345;
108301
108302 nLt = p->current.anLt[p->nCol-1];
108303 /* Check if this is to be a periodic sample. If so, add it. */
108304 if( (nLt/p->nPSample)!=(nLt+1)/p->nPSample ){
108305 p->current.isPSample = 1;
108306 p->current.iCol = 0;
108307 sampleInsert(p, &p->current, p->nCol-1);
108308 p->current.isPSample = 0;
108309 }
108310
108311 /* Update the aBest[] array. */
108312 for(i=0; i<(p->nCol-1); i++){
108313 p->current.iCol = i;
108314 if( i>=iChng || sampleIsBetterPost(p, &p->current, &p->aBest[i]) ){
108315 sampleCopy(p, &p->aBest[i], &p->current);
108316 }
108317 }
108318 }else

References StatSample::anDLt, StatSample::anEq, StatAccum::current, StatAccum::db, StatAccum::nCol, StatAccum::nRow, sqlite3_value_blob(), sqlite3_value_bytes(), sqlite3_value_int(), sqlite3_value_int64(), sqlite3_value_type(), SQLITE_INTEGER, and UNUSED_PARAMETER.

◆ storeLastErrno()

static void storeLastErrno ( unixFile * pFile,
int error )
static

◆ strAccumFinishRealloc()

static SQLITE_NOINLINE char * strAccumFinishRealloc ( StrAccum * p)
static

Definition at line 29150 of file sqlite3.c.

29156 {
29157 char *zText;
29158 assert( p->mxAlloc>0 && !isMalloced(p) );
29159 zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
29160 if( zText ){
29161 memcpy(zText, p->zText, p->nChar+1);

References sqlite3_str::db, isMalloced, sqlite3_str::mxAlloc, sqlite3_str::nChar, sqlite3_str::printfFlags, sqlite3DbMallocRaw(), SQLITE_PRINTF_MALLOCED, and sqlite3_str::zText.

◆ strftimeFunc()

static void strftimeFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 22714 of file sqlite3.c.

22723 {
22724 DateTime x;
22725 u64 n;
22726 size_t i,j;
22727 char *z;
22728 sqlite3 *db;
22729 const char *zFmt;
22730 char zBuf[100];
22731 if( argc==0 ) return;
22732 zFmt = (const char*)sqlite3_value_text(argv[0]);
22733 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
22734 db = sqlite3_context_db_handle(context);
22735 for(i=0, n=1; zFmt[i]; i++, n++){
22736 if( zFmt[i]=='%' ){
22737 switch( zFmt[i+1] ){
22738 case 'd':
22739 case 'H':
22740 case 'm':
22741 case 'M':
22742 case 'S':
22743 case 'W':
22744 n++;
22745 /* fall thru */
22746 case 'w':
22747 case '%':
22748 break;
22749 case 'f':
22750 n += 8;
22751 break;
22752 case 'j':
22753 n += 3;
22754 break;
22755 case 'Y':
22756 n += 8;
22757 break;
22758 case 's':
22759 case 'J':
22760 n += 50;
22761 break;
22762 default:
22763 return; /* ERROR. return a NULL */
22764 }
22765 i++;
22766 }
22767 }
22768 testcase( n==sizeof(zBuf)-1 );
22769 testcase( n==sizeof(zBuf) );
22770 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
22772 if( n<sizeof(zBuf) ){
22773 z = zBuf;
22774 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
22776 return;
22777 }else{
22778 z = sqlite3DbMallocRawNN(db, (int)n);
22779 if( z==0 ){
22781 return;
22782 }
22783 }
22784 computeJD(&x);
22785 computeYMD_HMS(&x);
22786 for(i=j=0; zFmt[i]; i++){
22787 if( zFmt[i]!='%' ){
22788 z[j++] = zFmt[i];
22789 }else{
22790 i++;
22791 switch( zFmt[i] ){
22792 case 'd': sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break;
22793 case 'f': {
22794 double s = x.s;
22795 if( s>59.999 ) s = 59.999;
22796 sqlite3_snprintf(7, &z[j],"%06.3f", s);
22797 j += sqlite3Strlen30(&z[j]);
22798 break;
22799 }
22800 case 'H': sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;
22801 case 'W': /* Fall thru */
22802 case 'j': {
22803 int nDay; /* Number of days since 1st day of year */
22804 DateTime y = x;
22805 y.validJD = 0;
22806 y.M = 1;
22807 y.D = 1;
22808 computeJD(&y);
22809 nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
22810 if( zFmt[i]=='W' ){
22811 int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
22812 wd = (int)(((x.iJD+43200000)/86400000)%7);
22813 sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7);
22814 j += 2;
22815 }else{
22816 sqlite3_snprintf(4, &z[j],"%03d",nDay+1);
22817 j += 3;
22818 }
22819 break;
22820 }
22821 case 'J': {
22822 sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0);
22823 j+=sqlite3Strlen30(&z[j]);
22824 break;
22825 }
22826 case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
22827 case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
22828 case 's': {
22829 i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
22830 sqlite3Int64ToText(iS, &z[j]);
22831 j += sqlite3Strlen30(&z[j]);
22832 break;
22833 }
22834 case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
22835 case 'w': {
22836 z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
22837 break;
22838 }
22839 case 'Y': {
22840 sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]);
22841 break;
22842 }
22843 default: z[j++] = '%'; break;
22844 }
22845 }
SQLITE_PRIVATE void sqlite3Int64ToText(i64, char *)
Definition sqlite3.c:31783

References sqlite3::aLimit, computeJD(), computeYMD_HMS(), DateTime::D, DateTime::h, DateTime::iJD, isDate(), DateTime::M, DateTime::m, DateTime::s, s, sqlite3_context_db_handle(), sqlite3_result_error_nomem(), sqlite3_result_error_toobig(), sqlite3_result_text(), sqlite3_snprintf(), sqlite3_value_text(), sqlite3DbMallocRawNN(), sqlite3Int64ToText(), sqlite3Strlen30(), SQLITE_DYNAMIC, SQLITE_LIMIT_LENGTH, SQLITE_TRANSIENT, testcase, DateTime::validJD, and DateTime::Y.

Referenced by sqlite3RegisterDateTimeFunctions().

◆ strHash()

static unsigned int strHash ( const char * z)
static

Definition at line 32932 of file sqlite3.c.

32938 {
32939 unsigned int h = 0;
32940 unsigned char c;
32941 while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
32942 /* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
32943 ** 0x9e3779b1 is 2654435761 which is the closest prime number to

Referenced by findElementWithHash(), rehash(), and sqlite3HashInsert().

◆ subjournalPage()

static int subjournalPage ( PgHdr * pPg)
static

Definition at line 56153 of file sqlite3.c.

56159 {
56160 int rc = SQLITE_OK;
56161 Pager *pPager = pPg->pPager;
56162 if( pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
56163
56164 /* Open the sub-journal, if it has not already been opened */
56165 assert( pPager->useJournal );
56166 assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
56167 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
56168 assert( pagerUseWal(pPager)
56169 || pageInJournal(pPager, pPg)
56170 || pPg->pgno>pPager->dbOrigSize
56171 );
56172 rc = openSubJournal(pPager);
56173
56174 /* If the sub-journal was opened successfully (or was already open),
56175 ** write the journal record into the file. */
56176 if( rc==SQLITE_OK ){
56177 void *pData = pPg->pData;
56178 i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
56179 char *pData2;
56180 pData2 = pData;
56181 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
56182 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
56183 if( rc==SQLITE_OK ){
56184 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
56185 }
56186 }
56187 }
56188 if( rc==SQLITE_OK ){
static int openSubJournal(Pager *pPager)
Definition sqlite3.c:56127

References Pager::dbOrigSize, isOpen, Pager::jfd, Pager::journalMode, Pager::nSubRec, openSubJournal(), PAGER_JOURNALMODE_OFF, PAGERID, PAGERTRACE, pagerUseWal, Pager::pageSize, PgHdr::pData, PgHdr::pgno, PgHdr::pPager, Pager::sjfd, sqlite3OsWrite(), SQLITE_OK, Pager::useJournal, and write32bits().

◆ subjournalPageIfRequired()

static int subjournalPageIfRequired ( PgHdr * pPg)
static

Definition at line 56189 of file sqlite3.c.

56195 {

Referenced by pager_write(), pagerStress(), sqlite3PagerMovepage(), and sqlite3PagerWrite().

◆ subjRequiresPage()

static int subjRequiresPage ( PgHdr * pPg)
static

Definition at line 52767 of file sqlite3.c.

52767 :
52768**
52769** * The page-number is less than or equal to PagerSavepoint.nOrig, and
52770** * The bit corresponding to the page-number is not set in
52772*/
52773static int subjRequiresPage(PgHdr *pPg){
52774 Pager *pPager = pPg->pPager;
52775 PagerSavepoint *p;
52776 Pgno pgno = pPg->pgno;
52777 int i;
52778 for(i=0; i<pPager->nSavepoint; i++){
52779 p = &pPager->aSavepoint[i];
static int subjRequiresPage(PgHdr *pPg)
Definition sqlite3.c:52767

References Pager::aSavepoint, PagerSavepoint::nOrig, Pager::nSavepoint, PgHdr::pgno, PagerSavepoint::pInSavepoint, PgHdr::pPager, and sqlite3BitvecTestNotNull().

◆ substExpr()

static Expr * substExpr ( SubstContext * pSubst,
Expr * pExpr )
static

Definition at line 132771 of file sqlite3.c.

132780 {
132781 if( pExpr==0 ) return 0;
132782 if( ExprHasProperty(pExpr, EP_FromJoin)
132783 && pExpr->iRightJoinTable==pSubst->iTable
132784 ){
132785 pExpr->iRightJoinTable = pSubst->iNewTable;
132786 }
132787 if( pExpr->op==TK_COLUMN
132788 && pExpr->iTable==pSubst->iTable
132789 && !ExprHasProperty(pExpr, EP_FixedCol)
132790 ){
132791 if( pExpr->iColumn<0 ){
132792 pExpr->op = TK_NULL;
132793 }else{
132794 Expr *pNew;
132795 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
132796 Expr ifNullRow;
132797 assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
132798 assert( pExpr->pRight==0 );
132799 if( sqlite3ExprIsVector(pCopy) ){
132800 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
132801 }else{
132802 sqlite3 *db = pSubst->pParse->db;
132803 if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
132804 memset(&ifNullRow, 0, sizeof(ifNullRow));
132805 ifNullRow.op = TK_IF_NULL_ROW;
132806 ifNullRow.pLeft = pCopy;
132807 ifNullRow.iTable = pSubst->iNewTable;
132808 ifNullRow.flags = EP_Skip;
132809 pCopy = &ifNullRow;
132810 }
132812 pNew = sqlite3ExprDup(db, pCopy, 0);
132813 if( pNew && pSubst->isLeftJoin ){
132815 }
132816 if( pNew && ExprHasProperty(pExpr,EP_FromJoin) ){
132817 pNew->iRightJoinTable = pExpr->iRightJoinTable;
132819 }
132820 sqlite3ExprDelete(db, pExpr);
132821 pExpr = pNew;
132822
132823 /* Ensure that the expression now has an implicit collation sequence,
132824 ** just as it did when it was a column of a view or sub-query. */
132825 if( pExpr ){
132826 if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
132827 CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
132828 pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr,
132829 (pColl ? pColl->zName : "BINARY")
132830 );
132831 }
132833 }
132834 }
132835 }
132836 }else{
132837 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
132838 pExpr->iTable = pSubst->iNewTable;
132839 }
132840 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
132841 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
132842 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
132843 substSelect(pSubst, pExpr->x.pSelect, 1);
132844 }else{
132845 substExprList(pSubst, pExpr->x.pList);
132846 }
132847#ifndef SQLITE_OMIT_WINDOWFUNC
132848 if( ExprHasProperty(pExpr, EP_WinFunc) ){
132849 Window *pWin = pExpr->y.pWin;
132850 pWin->pFilter = substExpr(pSubst, pWin->pFilter);
132851 substExprList(pSubst, pWin->pPartition);
static void substExprList(SubstContext *, ExprList *)
Definition sqlite3.c:132852

References ExprList::a, Parse::db, EP_CanBeNull, EP_Collate, EP_FixedCol, EP_FromJoin, EP_Skip, EP_Subquery, EP_WinFunc, EP_xIsSelect, ExprClearProperty, ExprHasProperty, ExprSetProperty, Expr::flags, Expr::iColumn, SubstContext::iNewTable, Expr::iRightJoinTable, SubstContext::isLeftJoin, Expr::iTable, SubstContext::iTable, ExprList::nExpr, Expr::op, SubstContext::pEList, ExprList::ExprList_item::pExpr, Window::pFilter, Expr::pLeft, Expr::pList, SubstContext::pParse, Window::pPartition, Expr::pRight, Expr::pSelect, Expr::pWin, sqlite3ExprAddCollateString(), sqlite3ExprCollSeq(), sqlite3ExprDelete(), sqlite3ExprDup(), sqlite3ExprIsVector(), sqlite3VectorErrorMsg(), substExpr(), substExprList(), substSelect(), testcase, TK_COLLATE, TK_COLUMN, TK_IF_NULL_ROW, TK_NULL, Expr::x, Expr::y, and CollSeq::zName.

Referenced by pushDownWhereTerms(), substExpr(), and substSelect().

◆ substExprList()

static void substExprList ( SubstContext * pSubst,
ExprList * pList )
static

Definition at line 132852 of file sqlite3.c.

132861 {

Referenced by substExpr().

◆ substrFunc()

static void substrFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117343 of file sqlite3.c.

117353 {
117354 const unsigned char *z;
117355 const unsigned char *z2;
117356 int len;
117357 int p0type;
117358 i64 p1, p2;
117359 int negP2 = 0;
117360
117361 assert( argc==3 || argc==2 );
117362 if( sqlite3_value_type(argv[1])==SQLITE_NULL
117363 || (argc==3 && sqlite3_value_type(argv[2])==SQLITE_NULL)
117364 ){
117365 return;
117366 }
117367 p0type = sqlite3_value_type(argv[0]);
117368 p1 = sqlite3_value_int(argv[1]);
117369 if( p0type==SQLITE_BLOB ){
117370 len = sqlite3_value_bytes(argv[0]);
117371 z = sqlite3_value_blob(argv[0]);
117372 if( z==0 ) return;
117373 assert( len==sqlite3_value_bytes(argv[0]) );
117374 }else{
117375 z = sqlite3_value_text(argv[0]);
117376 if( z==0 ) return;
117377 len = 0;
117378 if( p1<0 ){
117379 for(z2=z; *z2; len++){
117380 SQLITE_SKIP_UTF8(z2);
117381 }
117382 }
117383 }
117384#ifdef SQLITE_SUBSTR_COMPATIBILITY
117385 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
117386 ** as substr(X,1,N) - it returns the first N characters of X. This
117387 ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
117388 ** from 2009-02-02 for compatibility of applications that exploited the
117389 ** old buggy behavior. */
117390 if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
117391#endif
117392 if( argc==3 ){
117393 p2 = sqlite3_value_int(argv[2]);
117394 if( p2<0 ){
117395 p2 = -p2;
117396 negP2 = 1;
117397 }
117398 }else{
117400 }
117401 if( p1<0 ){
117402 p1 += len;
117403 if( p1<0 ){
117404 p2 += p1;
117405 if( p2<0 ) p2 = 0;
117406 p1 = 0;
117407 }
117408 }else if( p1>0 ){
117409 p1--;
117410 }else if( p2>0 ){
117411 p2--;
117412 }
117413 if( negP2 ){
117414 p1 -= p2;
117415 if( p1<0 ){
117416 p2 += p1;
117417 p1 = 0;
117418 }
117419 }
117420 assert( p1>=0 && p2>=0 );
117421 if( p0type!=SQLITE_BLOB ){
117422 while( *z && p1 ){
117423 SQLITE_SKIP_UTF8(z);
117424 p1--;
117425 }
117426 for(z2=z; *z2 && p2; p2--){
117427 SQLITE_SKIP_UTF8(z2);
117428 }
117429 sqlite3_result_text64(context, (char*)z, z2-z, SQLITE_TRANSIENT,
117430 SQLITE_UTF8);
117431 }else{
117432 if( p1+p2>len ){

References sqlite3::aLimit, sqlite3_context_db_handle(), sqlite3_result_blob64(), sqlite3_result_text64(), sqlite3_value_blob(), sqlite3_value_bytes(), sqlite3_value_int(), sqlite3_value_text(), sqlite3_value_type(), SQLITE_BLOB, SQLITE_LIMIT_LENGTH, SQLITE_NULL, SQLITE_SKIP_UTF8, SQLITE_TRANSIENT, and SQLITE_UTF8.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ substSelect()

static void substSelect ( SubstContext * pSubst,
Select * p,
int doPrior )
static

Definition at line 132862 of file sqlite3.c.

132864 {
132865 pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
132866 }
132867}
132868static void substSelect(
132869 SubstContext *pSubst, /* Description of the substitution */
132870 Select *p, /* SELECT statement in which to make substitutions */
132871 int doPrior /* Do substitutes on p->pPrior too */
132872){
132873 SrcList *pSrc;
132874 struct SrcList_item *pItem;
132875 int i;
132876 if( !p ) return;
132877 do{
132878 substExprList(pSubst, p->pEList);
132879 substExprList(pSubst, p->pGroupBy);
132880 substExprList(pSubst, p->pOrderBy);
132881 p->pHaving = substExpr(pSubst, p->pHaving);
132882 p->pWhere = substExpr(pSubst, p->pWhere);
132883 pSrc = p->pSrc;
132884 assert( pSrc!=0 );
132885 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
132886 substSelect(pSubst, pItem->pSelect, 1);

References ExprList::a, ExprList::ExprList_item::pExpr, and substExpr().

Referenced by flattenSubquery(), and substExpr().

◆ sumFinalize()

static void sumFinalize ( sqlite3_context * context)
static

Definition at line 118617 of file sqlite3.c.

118623 {
118624 SumCtx *p;
118625 p = sqlite3_aggregate_context(context, 0);
118626 if( p && p->cnt>0 ){
118627 if( p->overflow ){
118628 sqlite3_result_error(context,"integer overflow",-1);
118629 }else if( p->approx ){
u8 approx
Definition sqlite3.c:118557
u8 overflow
Definition sqlite3.c:118556
i64 cnt
Definition sqlite3.c:118555

Referenced by sqlite3RegisterBuiltinFunctions().

◆ sumInverse()

static void sumInverse ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118592 of file sqlite3.c.

118598 {
118599 SumCtx *p;
118600 int type;
118601 assert( argc==1 );
118602 UNUSED_PARAMETER(argc);
118603 p = sqlite3_aggregate_context(context, sizeof(*p));
118604 type = sqlite3_value_numeric_type(argv[0]);
118605 /* p is always non-NULL because sumStep() will have been called first
118606 ** to initialize it */
118607 if( ALWAYS(p) && type!=SQLITE_NULL ){
118608 assert( p->cnt>0 );
118609 p->cnt--;
118610 assert( type==SQLITE_INTEGER || p->approx );
118611 if( type==SQLITE_INTEGER && p->approx==0 ){
118612 i64 v = sqlite3_value_int64(argv[0]);
118613 p->rSum -= v;
double rSum
Definition sqlite3.c:118553

Referenced by sqlite3RegisterBuiltinFunctions().

◆ sumStep()

static void sumStep ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118570 of file sqlite3.c.

118576 {
118577 SumCtx *p;
118578 int type;
118579 assert( argc==1 );
118580 UNUSED_PARAMETER(argc);
118581 p = sqlite3_aggregate_context(context, sizeof(*p));
118582 type = sqlite3_value_numeric_type(argv[0]);
118583 if( p && type!=SQLITE_NULL ){
118584 p->cnt++;
118585 if( type==SQLITE_INTEGER ){
118586 i64 v = sqlite3_value_int64(argv[0]);
118587 p->rSum += v;
118588 if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, v) ){
118589 p->approx = p->overflow = 1;
118590 }
i64 iSum
Definition sqlite3.c:118554

References SumCtx::approx, SumCtx::cnt, SumCtx::iSum, SumCtx::overflow, SumCtx::rSum, sqlite3_aggregate_context(), sqlite3_value_int64(), sqlite3_value_numeric_type(), sqlite3AddInt64(), SQLITE_INTEGER, SQLITE_NULL, and UNUSED_PARAMETER.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ syncJournal()

static int syncJournal ( Pager * pPager,
int newHdr )
static

Definition at line 55893 of file sqlite3.c.

55899 {
55900 int rc; /* Return code */
55901
55902 assert( pPager->eState==PAGER_WRITER_CACHEMOD
55903 || pPager->eState==PAGER_WRITER_DBMOD
55904 );
55905 assert( assert_pager_state(pPager) );
55906 assert( !pagerUseWal(pPager) );
55907
55908 rc = sqlite3PagerExclusiveLock(pPager);
55909 if( rc!=SQLITE_OK ) return rc;
55910
55911 if( !pPager->noSync ){
55912 assert( !pPager->tempFile );
55913 if( isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_MEMORY ){
55914 const int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
55915 assert( isOpen(pPager->jfd) );
55916
55917 if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
55918 /* This block deals with an obscure problem. If the last connection
55919 ** that wrote to this database was operating in persistent-journal
55920 ** mode, then the journal file may at this point actually be larger
55921 ** than Pager.journalOff bytes. If the next thing in the journal
55922 ** file happens to be a journal-header (written as part of the
55923 ** previous connection's transaction), and a crash or power-failure
55924 ** occurs after nRec is updated but before this connection writes
55925 ** anything else to the journal file (or commits/rolls back its
55926 ** transaction), then SQLite may become confused when doing the
55927 ** hot-journal rollback following recovery. It may roll back all
55928 ** of this connections data, then proceed to rolling back the old,
55929 ** out-of-date data that follows it. Database corruption.
55930 **
55931 ** To work around this, if the journal file does appear to contain
55932 ** a valid header following Pager.journalOff, then write a 0x00
55933 ** byte to the start of it to prevent it from being recognized.
55934 **
55935 ** Variable iNextHdrOffset is set to the offset at which this
55936 ** problematic header will occur, if it exists. aMagic is used
55937 ** as a temporary buffer to inspect the first couple of bytes of
55938 ** the potential journal header.
55939 */
55940 i64 iNextHdrOffset;
55941 u8 aMagic[8];
55942 u8 zHeader[sizeof(aJournalMagic)+4];
55943
55944 memcpy(zHeader, aJournalMagic, sizeof(aJournalMagic));
55945 put32bits(&zHeader[sizeof(aJournalMagic)], pPager->nRec);
55946
55947 iNextHdrOffset = journalHdrOffset(pPager);
55948 rc = sqlite3OsRead(pPager->jfd, aMagic, 8, iNextHdrOffset);
55949 if( rc==SQLITE_OK && 0==memcmp(aMagic, aJournalMagic, 8) ){
55950 static const u8 zerobyte = 0;
55951 rc = sqlite3OsWrite(pPager->jfd, &zerobyte, 1, iNextHdrOffset);
55952 }
55953 if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
55954 return rc;
55955 }
55956
55957 /* Write the nRec value into the journal file header. If in
55958 ** full-synchronous mode, sync the journal first. This ensures that
55959 ** all data has really hit the disk before nRec is updated to mark
55960 ** it as a candidate for rollback.
55961 **
55962 ** This is not required if the persistent media supports the
55963 ** SAFE_APPEND property. Because in this case it is not possible
55964 ** for garbage data to be appended to the file, the nRec field
55965 ** is populated with 0xFFFFFFFF when the journal header is written
55966 ** and never needs to be updated.
55967 */
55968 if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
55969 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
55970 IOTRACE(("JSYNC %p\n", pPager))
55971 rc = sqlite3OsSync(pPager->jfd, pPager->syncFlags);
55972 if( rc!=SQLITE_OK ) return rc;
55973 }
55974 IOTRACE(("JHDR %p %lld\n", pPager, pPager->journalHdr));
55975 rc = sqlite3OsWrite(
55976 pPager->jfd, zHeader, sizeof(zHeader), pPager->journalHdr
55977 );
55978 if( rc!=SQLITE_OK ) return rc;
55979 }
55980 if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
55981 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
55982 IOTRACE(("JSYNC %p\n", pPager))
55983 rc = sqlite3OsSync(pPager->jfd, pPager->syncFlags|
55985 );
55986 if( rc!=SQLITE_OK ) return rc;
55987 }
55988
55989 pPager->journalHdr = pPager->journalOff;
55990 if( newHdr && 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
55991 pPager->nRec = 0;
55992 rc = writeJournalHdr(pPager);
55993 if( rc!=SQLITE_OK ) return rc;
55994 }
55995 }else{
55996 pPager->journalHdr = pPager->journalOff;
55997 }
55998 }
55999
56000 /* Unless the pager is in noSync mode, the journal file was just
56001 ** successfully synced. Either way, clear the PGHDR_NEED_SYNC flag on
56002 ** all pages.
SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager *)
Definition sqlite3.c:58022
#define SQLITE_IOCAP_SAFE_APPEND
Definition sqlite3.c:1670
#define SQLITE_SYNC_DATAONLY
Definition sqlite3.c:1718

References aJournalMagic, Pager::eState, Pager::fd, Pager::fullSync, IOTRACE, isOpen, Pager::jfd, Pager::journalHdr, journalHdrOffset(), Pager::journalMode, Pager::journalOff, Pager::noSync, Pager::nRec, PAGER_JOURNALMODE_MEMORY, PAGER_WRITER_CACHEMOD, PAGER_WRITER_DBMOD, PAGERID, PAGERTRACE, pagerUseWal, Pager::pPCache, put32bits, sqlite3OsDeviceCharacteristics(), sqlite3OsRead(), sqlite3OsSync(), sqlite3OsWrite(), sqlite3PagerExclusiveLock(), sqlite3PcacheClearSyncFlags(), SQLITE_IOCAP_SAFE_APPEND, SQLITE_IOCAP_SEQUENTIAL, SQLITE_IOERR_SHORT_READ, SQLITE_OK, SQLITE_SYNC_DATAONLY, SQLITE_SYNC_FULL, Pager::syncFlags, Pager::tempFile, and writeJournalHdr().

Referenced by pagerStress(), and sqlite3PagerCommitPhaseOne().

◆ synthCollSeq()

static int synthCollSeq ( sqlite3 * db,
CollSeq * pColl )
static

Definition at line 115588 of file sqlite3.c.

115594 {
115595 CollSeq *pColl2;
115596 char *z = pColl->zName;
115597 int i;
115598 static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
115599 for(i=0; i<3; i++){
115600 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
115601 if( pColl2->xCmp!=0 ){
115602 memcpy(pColl, pColl2, sizeof(CollSeq));

References sqlite3FindCollSeq(), SQLITE_ERROR, SQLITE_OK, SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8, CollSeq::xCmp, CollSeq::xDel, and CollSeq::zName.

Referenced by sqlite3GetCollSeq().

◆ tabIsReadOnly()

static int tabIsReadOnly ( Parse * pParse,
Table * pTab )
static

Definition at line 116137 of file sqlite3.c.

116143 {
116144 sqlite3 *db;
116145 if( IsVirtual(pTab) ){
116146 return sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0;
116147 }
116148 if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
116149 db = pParse->db;

References Parse::db, IsVirtual, Parse::nested, VTable::pMod, Module::pModule, sqlite3GetVTable(), sqlite3ReadOnlyShadowTables(), sqlite3WritableSchema(), Table::tabFlags, TF_Readonly, TF_Shadow, and sqlite3_module::xUpdate.

Referenced by sqlite3IsReadOnly().

◆ tableAndColumnIndex()

static int tableAndColumnIndex ( SrcList * pSrc,
int N,
const char * zCol,
int * piTab,
int * piCol,
int bIgnoreHidden )
static

Definition at line 129577 of file sqlite3.c.

129590 {
129591 int i; /* For looping over tables in pSrc */
129592 int iCol; /* Index of column matching zCol */
129593
129594 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
129595 for(i=0; i<N; i++){
129596 iCol = columnIndex(pSrc->a[i].pTab, zCol);
129597 if( iCol>=0
129598 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0)
129599 ){
129600 if( piTab ){
129601 *piTab = i;
129602 *piCol = iCol;

References SrcList::a, Table::aCol, columnIndex(), IsHiddenColumn, and SrcList::SrcList_item::pTab.

Referenced by selectExpander(), and sqliteProcessJoin().

◆ tableMayNotBeDropped()

static int tableMayNotBeDropped ( sqlite3 * db,
Table * pTab )
static

Definition at line 113418 of file sqlite3.c.

113424 {
113425 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
113426 if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0;
113427 if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0;
113428 return 1;

◆ tableOfTrigger()

static Table * tableOfTrigger ( Trigger * pTrigger)
static

Definition at line 136998 of file sqlite3.c.

Referenced by getRowTrigger().

◆ termCanDriveIndex()

static int termCanDriveIndex ( WhereTerm * pTerm,
struct SrcList_item * pSrc,
Bitmask notReady )
static

Definition at line 146269 of file sqlite3.c.

146279 {
146280 char aff;
146281 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
146282 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
146283 if( (pSrc->fg.jointype & JT_LEFT)
146284 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
146285 && (pTerm->eOperator & WO_IS)
146286 ){
146287 /* Cannot use an IS term from the WHERE clause as an index driver for
146288 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from
146289 ** the ON clause. */
146290 return 0;
146291 }
146292 if( (pTerm->prereqRight & notReady)!=0 ) return 0;

References WhereTerm::eOperator, EP_FromJoin, ExprHasProperty, JT_LEFT, WhereTerm::leftColumn, WhereTerm::leftCursor, Expr::op, WhereTerm::pExpr, WhereTerm::prereqRight, sqlite3IndexAffinityOk(), testcase, TK_IS, WhereTerm::u, WO_EQ, and WO_IS.

Referenced by constructAutomaticIndex(), and whereLoopAddBtree().

◆ termIsEquivalence()

static int termIsEquivalence ( Parse * pParse,
Expr * pExpr )
static

Definition at line 144889 of file sqlite3.c.

144895 {
144896 char aff1, aff2;
144897 CollSeq *pColl;
144898 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
144899 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
144900 if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0;
144901 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
144902 aff2 = sqlite3ExprAffinity(pExpr->pRight);
144903 if( aff1!=aff2
144905 ){
#define SQLITE_Transitive
Definition sqlite3.c:17048

References Parse::db, EP_FromJoin, ExprHasProperty, Expr::op, OptimizationEnabled, Expr::pLeft, Expr::pRight, sqlite3ExprAffinity(), sqlite3ExprCollSeqMatch(), sqlite3ExprCompareCollSeq(), sqlite3IsBinary(), sqlite3IsNumericAffinity, SQLITE_Transitive, TK_EQ, and TK_IS.

Referenced by exprAnalyze().

◆ timeFunc()

static void timeFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 22662 of file sqlite3.c.

22671 {
22672 DateTime x;
22673 if( isDate(context, argc, argv, &x)==0 ){
22674 char zBuf[100];

References computeHMS(), DateTime::h, isDate(), DateTime::m, DateTime::s, sqlite3_result_text(), sqlite3_snprintf(), and SQLITE_TRANSIENT.

Referenced by ctimeFunc(), and sqlite3RegisterDateTimeFunctions().

◆ tokenExpr()

static Expr * tokenExpr ( Parse * pParse,
int op,
Token t )
static

Definition at line 154344 of file sqlite3.c.

154350 {
154351 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
154352 if( p ){
154353 /* memset(p, 0, sizeof(Expr)); */
154354 p->op = (u8)op;
154355 p->affExpr = 0;
154356 p->flags = EP_Leaf;
154358 p->iAgg = -1;
154359 p->pLeft = p->pRight = 0;
154360 p->x.pList = 0;
154361 p->pAggInfo = 0;
154362 p->y.pTab = 0;
154363 p->op2 = 0;
154364 p->iTable = 0;
154365 p->iColumn = 0;
154366 p->u.zToken = (char*)&p[1];
154367 memcpy(p->u.zToken, t.z, t.n);
154368 p->u.zToken[t.n] = 0;
154369 if( sqlite3Isquote(p->u.zToken[0]) ){
154371 }
154372#if SQLITE_MAX_EXPR_DEPTH>0
154373 p->nHeight = 1;
154374#endif

References Expr::affExpr, Parse::db, EP_Leaf, ExprClearVVAProperties, Expr::flags, Expr::iAgg, Expr::iColumn, IN_RENAME_OBJECT, Expr::iTable, Token::n, Expr::nHeight, Expr::op, Expr::op2, Expr::pAggInfo, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pTab, sqlite3DbMallocRawNN(), sqlite3DequoteExpr(), sqlite3Isquote, sqlite3RenameTokenMap(), Expr::u, Expr::x, Expr::y, Token::z, and Expr::zToken.

Referenced by yy_reduce().

◆ total_changes()

static void total_changes ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 117636 of file sqlite3.c.

117646 {

Referenced by sqlite3RegisterBuiltinFunctions().

◆ totalFinalize()

static void totalFinalize ( sqlite3_context * context)
static

Definition at line 118637 of file sqlite3.c.

118639 {
118640 sqlite3_result_double(context, p->rSum/(double)p->cnt);
118641 }
118642}
SQLITE_API void sqlite3_result_double(sqlite3_context *, double)
Definition sqlite3.c:83403

Referenced by sqlite3RegisterBuiltinFunctions().

◆ transferJoinMarkings()

static void transferJoinMarkings ( Expr * pDerived,
Expr * pBase )
static

Definition at line 144441 of file sqlite3.c.

References EP_FromJoin, Expr::flags, and Expr::iRightJoinTable.

Referenced by exprAnalyze(), and exprAnalyzeOrTerm().

◆ transferParseError()

static void transferParseError ( Parse * pTo,
Parse * pFrom )
static

Definition at line 137263 of file sqlite3.c.

137269 {
137270 assert( pFrom->zErrMsg==0 || pFrom->nErr );
137271 assert( pTo->zErrMsg==0 || pTo->nErr );
137272 if( pTo->nErr==0 ){
137273 pTo->zErrMsg = pFrom->zErrMsg;

References Parse::db, Parse::nErr, Parse::rc, sqlite3DbFree(), and Parse::zErrMsg.

◆ translateColumnToCopy()

static void translateColumnToCopy ( Parse * pParse,
int iStart,
int iTabCur,
int iRegister,
int iAutoidxCur )
static

Definition at line 146187 of file sqlite3.c.

146199 {
146200 Vdbe *v = pParse->pVdbe;
146201 VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);
146202 int iEnd = sqlite3VdbeCurrentAddr(v);
146203 if( pParse->db->mallocFailed ) return;
146204 for(; iStart<iEnd; iStart++, pOp++){
146205 if( pOp->p1!=iTabCur ) continue;
146206 if( pOp->opcode==OP_Column ){
146207 pOp->opcode = OP_Copy;
146208 pOp->p1 = pOp->p2 + iRegister;
146209 pOp->p2 = pOp->p3;
146210 pOp->p3 = 0;
146211 }else if( pOp->opcode==OP_Rowid ){
146212 if( iAutoidxCur ){
146213 pOp->opcode = OP_Sequence;
146214 pOp->p1 = iAutoidxCur;
146215 }else{
146216 pOp->opcode = OP_Null;

References Parse::db, sqlite3::mallocFailed, OP_Column, OP_Copy, OP_Null, OP_Rowid, OP_Sequence, VdbeOp::opcode, VdbeOp::p1, VdbeOp::p2, VdbeOp::p3, Parse::pVdbe, sqlite3VdbeCurrentAddr(), and sqlite3VdbeGetOp().

Referenced by constructAutomaticIndex(), and sqlite3WhereEnd().

◆ triggerSpanDup()

static char * triggerSpanDup ( sqlite3 * db,
const char * zStart,
const char * zEnd )
static

Definition at line 136756 of file sqlite3.c.

Referenced by sqlite3TriggerSelectStep(), and triggerStepAllocate().

◆ triggerStepAllocate()

static TriggerStep * triggerStepAllocate ( Parse * pParse,
u8 op,
Token * pName,
const char * zStart,
const char * zEnd )
static

Definition at line 136794 of file sqlite3.c.

136806 {
136807 sqlite3 *db = pParse->db;
136808 TriggerStep *pTriggerStep;
136809
136810 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
136811 if( pTriggerStep ){
136812 char *z = (char*)&pTriggerStep[1];
136813 memcpy(z, pName->z, pName->n);
136814 sqlite3Dequote(z);
136815 pTriggerStep->zTarget = z;
136816 pTriggerStep->op = op;
136817 pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd);
static char * triggerSpanDup(sqlite3 *db, const char *zStart, const char *zEnd)
Definition sqlite3.c:136756

References Parse::db, IN_RENAME_OBJECT, Token::n, TriggerStep::op, sqlite3DbMallocZero(), sqlite3Dequote(), sqlite3RenameTokenMap(), triggerSpanDup(), Token::z, TriggerStep::zSpan, and TriggerStep::zTarget.

Referenced by sqlite3TriggerDeleteStep(), sqlite3TriggerInsertStep(), and sqlite3TriggerUpdateStep().

◆ trimFunc()

static void trimFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118355 of file sqlite3.c.

118365 {
118366 const unsigned char *zIn; /* Input string */
118367 const unsigned char *zCharSet; /* Set of characters to trim */
118368 int nIn; /* Number of bytes in input */
118369 int flags; /* 1: trimleft 2: trimright 3: trim */
118370 int i; /* Loop counter */
118371 unsigned char *aLen = 0; /* Length of each character in zCharSet */
118372 unsigned char **azChar = 0; /* Individual characters in zCharSet */
118373 int nChar; /* Number of characters in zCharSet */
118374
118375 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
118376 return;
118377 }
118378 zIn = sqlite3_value_text(argv[0]);
118379 if( zIn==0 ) return;
118380 nIn = sqlite3_value_bytes(argv[0]);
118381 assert( zIn==sqlite3_value_text(argv[0]) );
118382 if( argc==1 ){
118383 static const unsigned char lenOne[] = { 1 };
118384 static unsigned char * const azOne[] = { (u8*)" " };
118385 nChar = 1;
118386 aLen = (u8*)lenOne;
118387 azChar = (unsigned char **)azOne;
118388 zCharSet = 0;
118389 }else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
118390 return;
118391 }else{
118392 const unsigned char *z;
118393 for(z=zCharSet, nChar=0; *z; nChar++){
118394 SQLITE_SKIP_UTF8(z);
118395 }
118396 if( nChar>0 ){
118397 azChar = contextMalloc(context, ((i64)nChar)*(sizeof(char*)+1));
118398 if( azChar==0 ){
118399 return;
118400 }
118401 aLen = (unsigned char*)&azChar[nChar];
118402 for(z=zCharSet, nChar=0; *z; nChar++){
118403 azChar[nChar] = (unsigned char *)z;
118404 SQLITE_SKIP_UTF8(z);
118405 aLen[nChar] = (u8)(z - azChar[nChar]);
118406 }
118407 }
118408 }
118409 if( nChar>0 ){
118410 flags = SQLITE_PTR_TO_INT(sqlite3_user_data(context));
118411 if( flags & 1 ){
118412 while( nIn>0 ){
118413 int len = 0;
118414 for(i=0; i<nChar; i++){
118415 len = aLen[i];
118416 if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break;
118417 }
118418 if( i>=nChar ) break;
118419 zIn += len;
118420 nIn -= len;
118421 }
118422 }
118423 if( flags & 2 ){
118424 while( nIn>0 ){
118425 int len = 0;
118426 for(i=0; i<nChar; i++){
118427 len = aLen[i];
118428 if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
118429 }
118430 if( i>=nChar ) break;
118431 nIn -= len;
118432 }
118433 }

Referenced by sqlite3RegisterBuiltinFunctions().

◆ typeofFunc()

static void typeofFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** argv )
static

Definition at line 117123 of file sqlite3.c.

117133 {
117134 static const char *azType[] = { "integer", "real", "text", "blob", "null" };
117135 int i = sqlite3_value_type(argv[0]) - 1;
117136 UNUSED_PARAMETER(NotUsed);
117137 assert( i>=0 && i<ArraySize(azType) );
117138 assert( SQLITE_INTEGER==1 );
117139 assert( SQLITE_FLOAT==2 );
117140 assert( SQLITE_TEXT==3 );
117141 assert( SQLITE_BLOB==4 );
117142 assert( SQLITE_NULL==5 );

Referenced by sqlite3RegisterBuiltinFunctions().

◆ unicodeFunc()

static void unicodeFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118155 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ unixAccess()

static int unixAccess ( sqlite3_vfs * NotUsed,
const char * zPath,
int flags,
int * pResOut )
static

Definition at line 39820 of file sqlite3.c.

39820 : Return 1 if the file exists
39821** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
39822** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
39823**
39824** Otherwise return 0.
39825*/
39826static int unixAccess(
39827 sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */
39828 const char *zPath, /* Path of the file to examine */
39829 int flags, /* What do we want to learn about the zPath file? */
39830 int *pResOut /* Write result boolean here */
39831){
39832 UNUSED_PARAMETER(NotUsed);
39834 assert( pResOut!=0 );
39835
39836 /* The spec says there are three possible values for flags. But only
39837 ** two of them are actually used */
39838 assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
39839
39840 if( flags==SQLITE_ACCESS_EXISTS ){
39841 struct stat buf;
39842 *pResOut = 0==osStat(zPath, &buf) &&
static int readable(const char *filename)
#define SQLITE_IOERR_ACCESS
Definition sqlite3.c:1535

References osAccess, osStat, SimulateIOError, SQLITE_ACCESS_EXISTS, SQLITE_ACCESS_READWRITE, SQLITE_IOERR_ACCESS, and UNUSED_PARAMETER.

◆ unixCheckReservedLock()

static int unixCheckReservedLock ( sqlite3_file * id,
int * pResOut )
static

Definition at line 35048 of file sqlite3.c.

35054 {
35055 int rc = SQLITE_OK;
35056 int reserved = 0;
35057 unixFile *pFile = (unixFile*)id;
35058
35060
35061 assert( pFile );
35062 assert( pFile->eFileLock<=SHARED_LOCK );
35064
35065 /* Check if a thread in this process holds such a lock */
35066 if( pFile->pInode->eFileLock>SHARED_LOCK ){
35067 reserved = 1;
35068 }
35069
35070 /* Otherwise see if some other process holds it.
35071 */
35072#ifndef __DJGPP__
35073 if( !reserved && !pFile->pInode->bProcessLock ){
35074 struct flock lock;
35075 lock.l_whence = SEEK_SET;
35076 lock.l_start = RESERVED_BYTE;
35077 lock.l_len = 1;
35078 lock.l_type = F_WRLCK;
35079 if( osFcntl(pFile->h, F_GETLK, &lock) ){
35081 storeLastErrno(pFile, errno);
35082 } else if( lock.l_type!=F_UNLCK ){
35083 reserved = 1;
35084 }
35085 }
35086#endif
35087
unsigned char bProcessLock
Definition sqlite3.c:34708

References unixInodeInfo::bProcessLock, unixFile::eFileLock, unixInodeInfo::eFileLock, unixFile::h, osFcntl, OSTRACE, unixFile::pInode, unixInodeInfo::pLockMutex, RESERVED_BYTE, SHARED_LOCK, SimulateIOError, sqlite3_mutex_enter(), sqlite3_mutex_leave(), SQLITE_IOERR_CHECKRESERVEDLOCK, SQLITE_OK, and storeLastErrno().

◆ unixClose()

static int unixClose ( sqlite3_file * id)
static

Definition at line 35663 of file sqlite3.c.

35669 {
35670 int rc = SQLITE_OK;
35671 unixFile *pFile = (unixFile *)id;
35672 unixInodeInfo *pInode = pFile->pInode;
35673
35674 assert( pInode!=0 );
35675 verifyDbFile(pFile);
35676 unixUnlock(id, NO_LOCK);
35677 assert( unixFileMutexNotheld(pFile) );
35679
35680 /* unixFile.pInode is always valid here. Otherwise, a different close
35681 ** routine (e.g. nolockClose()) would be called instead.
35682 */
35683 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 );
35685 if( pInode->nLock ){
35686 /* If there are outstanding locks, do not actually close the file just
35687 ** yet because that would clear those locks. Instead, add the file
35688 ** descriptor to pInode->pUnused list. It will be automatically closed
35689 ** when the last lock is cleared.
35690 */
35691 setPendingFd(pFile);
35692 }
static void verifyDbFile(unixFile *pFile)
Definition sqlite3.c:35015
static void setPendingFd(unixFile *pFile)
Definition sqlite3.c:35423
static int unixUnlock(sqlite3_file *id, int eFileLock)
Definition sqlite3.c:35606

Referenced by unixOpen().

◆ unixCurrentTime()

static int unixCurrentTime ( sqlite3_vfs * NotUsed,
double * prNow )
static

Definition at line 40150 of file sqlite3.c.

40156 {
40157 sqlite3_int64 i = 0;

References unixCurrentTimeInt64(), and UNUSED_PARAMETER.

◆ unixCurrentTimeInt64()

static int unixCurrentTimeInt64 ( sqlite3_vfs * NotUsed,
sqlite3_int64 * piNow )
static

Definition at line 40118 of file sqlite3.c.

40124 {
40125 static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
40126 int rc = SQLITE_OK;
40127#if defined(NO_GETTOD)
40128 time_t t;
40129 time(&t);
40130 *piNow = ((sqlite3_int64)t)*1000 + unixEpoch;
40131#elif OS_VXWORKS
40132 struct timespec sNow;
40133 clock_gettime(CLOCK_REALTIME, &sNow);
40134 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
40135#else
40136 struct timeval sNow;
40137 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */
40138 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
40139#endif
40140
40141#ifdef SQLITE_TEST
40142 if( sqlite3_current_time ){

References SQLITE_OK, and UNUSED_PARAMETER.

Referenced by unixCurrentTime().

◆ unixDelete()

static int unixDelete ( sqlite3_vfs * NotUsed,
const char * zPath,
int dirSync )
static

Definition at line 39772 of file sqlite3.c.

39782 {
39783 int rc = SQLITE_OK;
39784 UNUSED_PARAMETER(NotUsed);
39786 if( osUnlink(zPath)==(-1) ){
39787 if( errno==ENOENT
39788#if OS_VXWORKS
39789 || osAccess(zPath,0)!=0
39790#endif
39791 ){
39793 }else{
39794 rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
39795 }
39796 return rc;
39797 }
39798#ifndef SQLITE_DISABLE_DIRSYNC
39799 if( (dirSync & 1)!=0 ){
39800 int fd;
39801 rc = osOpenDirectory(zPath, &fd);
39802 if( rc==SQLITE_OK ){
39803 if( full_fsync(fd,0,0) ){
39804 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
39805 }
39806 robust_close(0, fd, __LINE__);
39807 }else{
39808 assert( rc==SQLITE_CANTOPEN );
#define OS_VXWORKS
Definition sqlite3.c:928
#define SQLITE_IOERR_DELETE
Definition sqlite3.c:1532
#define SQLITE_IOERR_DIR_FSYNC
Definition sqlite3.c:1527
#define osAccess
static int full_fsync(int fd, int fullSync, int dataOnly)
Definition sqlite3.c:37122
#define osOpenDirectory
#define SQLITE_IOERR_DELETE_NOENT
Definition sqlite3.c:1545

References full_fsync(), OS_VXWORKS, osAccess, osOpenDirectory, osUnlink, robust_close(), SimulateIOError, SQLITE_CANTOPEN, SQLITE_IOERR_DELETE, SQLITE_IOERR_DELETE_NOENT, SQLITE_IOERR_DIR_FSYNC, SQLITE_OK, unixLogError, and UNUSED_PARAMETER.

◆ unixDeviceCharacteristics()

static int unixDeviceCharacteristics ( sqlite3_file * id)
static

Definition at line 37730 of file sqlite3.c.

References unixFile::deviceCharacteristics, and setDeviceCharacteristics().

◆ unixDlClose()

static void unixDlClose ( sqlite3_vfs * NotUsed,
void * pHandle )
static

Definition at line 40017 of file sqlite3.c.

◆ unixDlError()

static void unixDlError ( sqlite3_vfs * NotUsed,
int nBuf,
char * zBufOut )
static

Definition at line 39984 of file sqlite3.c.

39990 {
39991 const char *zErr;
39992 UNUSED_PARAMETER(NotUsed);

References unixEnterMutex(), and UNUSED_PARAMETER.

◆ unixDlOpen()

static void * unixDlOpen ( sqlite3_vfs * NotUsed,
const char * zFilename )
static

Definition at line 39972 of file sqlite3.c.

References UNUSED_PARAMETER.

◆ unixEnterMutex()

static void unixEnterMutex ( void )
static

Definition at line 34279 of file sqlite3.c.

34279 : enter(unixBigLock), enter(pLockInfo)
34280** OK: enter(unixBigLock)
34281** OK: enter(pLockInfo)
34282** ERROR: enter(pLockInfo), enter(unixBigLock)
static sqlite3_mutex * unixBigLock
Definition sqlite3.c:34278

Referenced by findReusableFd(), unixDlError(), unixOpenSharedMemory(), unixShmBarrier(), and unixShmUnmap().

◆ unixFetch()

static int unixFetch ( sqlite3_file * fd,
i64 iOff,
int nAmt,
void ** pp )
static

Definition at line 38711 of file sqlite3.c.

38717 {
38718#if SQLITE_MAX_MMAP_SIZE>0
38719 unixFile *pFd = (unixFile *)fd; /* The underlying database file */
38720#endif
38721 *pp = 0;
38722
38723#if SQLITE_MAX_MMAP_SIZE>0
38724 if( pFd->mmapSizeMax>0 ){
38725 if( pFd->pMapRegion==0 ){
38726 int rc = unixMapfile(pFd, -1);
38727 if( rc!=SQLITE_OK ) return rc;
38728 }
38729 if( pFd->mmapSize >= iOff+nAmt ){
38730 *pp = &((u8 *)pFd->pMapRegion)[iOff];

References SQLITE_OK.

◆ unixFileControl()

static int unixFileControl ( sqlite3_file * id,
int op,
void * pArg )
static

Definition at line 37478 of file sqlite3.c.

37484 {
37485 unixFile *pFile = (unixFile*)id;
37486 switch( op ){
37487#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
37489 int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
37491 }
37493 int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
37495 }
37497 int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
37499 }
37500#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
37501
37503 *(int*)pArg = pFile->eFileLock;
37504 return SQLITE_OK;
37505 }
37507 *(int*)pArg = pFile->lastErrno;
37508 return SQLITE_OK;
37509 }
37511 pFile->szChunk = *(int *)pArg;
37512 return SQLITE_OK;
37513 }
37515 int rc;
37517 rc = fcntlSizeHint(pFile, *(i64 *)pArg);
37519 return rc;
37520 }
37522 unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg);
37523 return SQLITE_OK;
37524 }
37526 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg);
37527 return SQLITE_OK;
37528 }
37529 case SQLITE_FCNTL_VFSNAME: {
37530 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
37531 return SQLITE_OK;
37532 }
37534 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
37535 if( zTFile ){
37536 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
37537 *(char**)pArg = zTFile;
37538 }
37539 return SQLITE_OK;
37540 }
37542 *(int*)pArg = fileHasMoved(pFile);
37543 return SQLITE_OK;
37544 }
37545#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
37547 int iOld = pFile->iBusyTimeout;
37548 pFile->iBusyTimeout = *(int*)pArg;
37549 *(int*)pArg = iOld;
37550 return SQLITE_OK;
37551 }
37552#endif
37553#if SQLITE_MAX_MMAP_SIZE>0
37555 i64 newLimit = *(i64*)pArg;
37556 int rc = SQLITE_OK;
37557 if( newLimit>sqlite3GlobalConfig.mxMmap ){
37558 newLimit = sqlite3GlobalConfig.mxMmap;
37559 }
37560
37561 /* The value of newLimit may be eventually cast to (size_t) and passed
37562 ** to mmap(). Restrict its value to 2GB if (size_t) is not at least a
37563 ** 64-bit type. */
37564 if( newLimit>0 && sizeof(size_t)<8 ){
37565 newLimit = (newLimit & 0x7FFFFFFF);
37566 }
37567
37568 *(i64*)pArg = pFile->mmapSizeMax;
37569 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
37570 pFile->mmapSizeMax = newLimit;
37571 if( pFile->mmapSize>0 ){
37572 unixUnmapfile(pFile);
37573 rc = unixMapfile(pFile, -1);
37574 }
37575 }
37576 return rc;
37577 }
37578#endif
37579#ifdef SQLITE_DEBUG
37580 /* The pager calls this method to signal that it has done
37581 ** a rollback and that the database is therefore unchanged and
37582 ** it hence it is OK for the transaction change counter to be
37583 ** unchanged.
37584 */
37586 ((unixFile*)id)->dbUpdate = 0;
37587 return SQLITE_OK;
37588 }
37589#endif
37590#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg)
Definition sqlite3.c:37462
#define SQLITE_FCNTL_SET_LOCKPROXYFILE
Definition sqlite3.c:2181
#define SimulateIOErrorBenign(X)
Definition sqlite3.c:33823
#define SQLITE_IOERR_BEGIN_ATOMIC
Definition sqlite3.c:1551
#define SQLITE_FCNTL_CHUNK_SIZE
Definition sqlite3.c:2184
#define SQLITE_FCNTL_VFSNAME
Definition sqlite3.c:2190
#define UNIXFILE_PERSIST_WAL
Definition sqlite3.c:33629
#define SQLITE_IOERR_COMMIT_ATOMIC
Definition sqlite3.c:1552
static int fcntlSizeHint(unixFile *pFile, i64 nByte)
Definition sqlite3.c:37393
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE
Definition sqlite3.c:2191
#define SQLITE_FCNTL_LAST_ERRNO
Definition sqlite3.c:2182
#define SQLITE_FCNTL_TEMPFILENAME
Definition sqlite3.c:2194
static int unixGetTempname(int nBuf, char *zBuf)
Definition sqlite3.c:39282
static int fileHasMoved(unixFile *pFile)
Definition sqlite3.c:34994
#define SQLITE_FCNTL_GET_LOCKPROXYFILE
Definition sqlite3.c:2180
#define SQLITE_IOERR_ROLLBACK_ATOMIC
Definition sqlite3.c:1553

◆ unixFileLock()

static int unixFileLock ( unixFile * pFile,
struct flock * pLock )
static

Definition at line 35146 of file sqlite3.c.

35152 {
35153 int rc;
35154 unixInodeInfo *pInode = pFile->pInode;
35155 assert( pInode!=0 );
35156 assert( sqlite3_mutex_held(pInode->pLockMutex) );
35158 if( pInode->bProcessLock==0 ){
35159 struct flock lock;
35160 assert( pInode->nLock==0 );
35161 lock.l_whence = SEEK_SET;
35162 lock.l_start = SHARED_FIRST;
35163 lock.l_len = SHARED_SIZE;
35164 lock.l_type = F_WRLCK;
35165 rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
35166 if( rc<0 ) return rc;
35167 pInode->bProcessLock = 1;
35168 pInode->nLock++;
35169 }else{
35170 rc = 0;
#define osSetPosixAdvisoryLock(h, x, t)
Definition sqlite3.c:35103
#define UNIXFILE_RDONLY
Definition sqlite3.c:33628

References unixInodeInfo::bProcessLock, unixFile::ctrlFlags, unixFile::h, unixInodeInfo::nLock, osSetPosixAdvisoryLock, unixFile::pInode, unixInodeInfo::pLockMutex, SHARED_FIRST, SHARED_SIZE, sqlite3_mutex_held(), UNIXFILE_EXCL, and UNIXFILE_RDONLY.

Referenced by posixUnlock(), and unixLock().

◆ unixFileSize()

static int unixFileSize ( sqlite3_file * id,
i64 * pSize )
static

Definition at line 37355 of file sqlite3.c.

37361 {
37362 int rc;
37363 struct stat buf;
37364 assert( id );
37365 rc = osFstat(((unixFile*)id)->h, &buf);
37366 SimulateIOError( rc=1 );
37367 if( rc!=0 ){
37368 storeLastErrno((unixFile*)id, errno);
37369 return SQLITE_IOERR_FSTAT;
37370 }
37371 *pSize = buf.st_size;
37372
37373 /* When opening a zero-size database, the findInodeInfo() procedure
37374 ** writes a single byte into that file in order to work around a bug
37375 ** in the OS-X msdos filesystem. In order to avoid problems with upper
37376 ** layers, we need to report this file size as zero even though it is
37377 ** really 1. Ticket #3260.

◆ unixFullPathname()

static int unixFullPathname ( sqlite3_vfs * pVfs,
const char * zPath,
int nOut,
char * zOut )
static

Definition at line 39880 of file sqlite3.c.

39891 {
39892#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
39893 return mkFullPathname(zPath, zOut, nOut);
39894#else
39895 int rc = SQLITE_OK;
39896 int nByte;
39897 int nLink = 0; /* Number of symbolic links followed so far */
39898 const char *zIn = zPath; /* Input path for each iteration of loop */
39899 char *zDel = 0;
39900
39901 assert( pVfs->mxPathname==MAX_PATHNAME );
39902 UNUSED_PARAMETER(pVfs);
39903
39904 /* It's odd to simulate an io-error here, but really this is just
39905 ** using the io-error infrastructure to test that SQLite handles this
39906 ** function failing. This function could fail if, for example, the
39907 ** current working directory has been unlinked.
39908 */
39909 SimulateIOError( return SQLITE_ERROR );
39910
39911 do {
39912
39913 /* Call stat() on path zIn. Set bLink to true if the path is a symbolic
39914 ** link, or false otherwise. */
39915 int bLink = 0;
39916 struct stat buf;
39917 if( osLstat(zIn, &buf)!=0 ){
39918 if( errno!=ENOENT ){
39919 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
39920 }
39921 }else{
39922 bLink = S_ISLNK(buf.st_mode);
39923 }
39924
39925 if( bLink ){
39926 nLink++;
39927 if( zDel==0 ){
39928 zDel = sqlite3_malloc(nOut);
39929 if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
39930 }else if( nLink>=SQLITE_MAX_SYMLINKS ){
39932 }
39933
39934 if( rc==SQLITE_OK ){
39935 nByte = osReadlink(zIn, zDel, nOut-1);
39936 if( nByte<0 ){
39937 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
39938 }else{
39939 if( zDel[0]!='/' ){
39940 int n;
39941 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
39942 if( nByte+n+1>nOut ){
39944 }else{
39945 memmove(&zDel[n], zDel, nByte+1);
39946 memcpy(zDel, zIn, n);
39947 nByte += n;
39948 }
39949 }
39950 zDel[nByte] = '\0';
39951 }
39952 }
39953
39954 zIn = zDel;
39955 }
39956
39957 assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
39958 if( rc==SQLITE_OK && zIn!=zOut ){
39959 rc = mkFullPathname(zIn, zOut, nOut);
39960 }
39961 if( bLink==0 ) break;
39962 zIn = zOut;
39963 }while( rc==SQLITE_OK );
#define osLstat
#define SQLITE_MAX_SYMLINKS
Definition sqlite3.c:33527
#define osReadlink
static int mkFullPathname(const char *zPath, char *zOut, int nOut)
Definition sqlite3.c:39847

References MAX_PATHNAME, mkFullPathname(), sqlite3_vfs::mxPathname, osLstat, osReadlink, SimulateIOError, sqlite3_free(), sqlite3_malloc(), sqlite3Strlen30(), SQLITE_CANTOPEN_BKPT, SQLITE_ERROR, SQLITE_MAX_SYMLINKS, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OK_SYMLINK, unixLogError, and UNUSED_PARAMETER.

◆ unixGetLastError()

static int unixGetLastError ( sqlite3_vfs * NotUsed,
int NotUsed2,
char * NotUsed3 )
static

Definition at line 40168 of file sqlite3.c.

References UNUSED_PARAMETER.

◆ unixGetpagesize()

static int unixGetpagesize ( void )
static

Definition at line 37744 of file sqlite3.c.

37750 {
37751#if OS_VXWORKS
37752 return 1024;

◆ unixGetSystemCall()

static sqlite3_syscall_ptr unixGetSystemCall ( sqlite3_vfs * pNotUsed,
const char * zName )
static

Definition at line 34156 of file sqlite3.c.

34165 {
34166 unsigned int i;
34167

References aSyscall, UNUSED_PARAMETER, and zName.

◆ unixGetTempname()

static int unixGetTempname ( int nBuf,
char * zBuf )
static

Definition at line 39282 of file sqlite3.c.

39288 {
39289 const char *zDir;
39290 int iLimit = 0;
39291
39292 /* It's odd to simulate an io-error here, but really this is just
39293 ** using the io-error infrastructure to test that SQLite handles this
39294 ** function failing.
39295 */
39296 zBuf[0] = 0;
39297 SimulateIOError( return SQLITE_IOERR );
39298
39299 zDir = unixTempFileDir();
39300 if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
39301 do{
39302 u64 r;
39303 sqlite3_randomness(sizeof(r), &r);
39304 assert( nBuf>2 );
39305 zBuf[nBuf-2] = 0;
static const char * unixTempFileDir(void)
Definition sqlite3.c:39248
#define SQLITE_IOERR_GETTEMPPATH
Definition sqlite3.c:1547

References osAccess, SimulateIOError, sqlite3_randomness(), sqlite3_snprintf(), SQLITE_ERROR, SQLITE_IOERR, SQLITE_IOERR_GETTEMPPATH, SQLITE_OK, SQLITE_TEMP_FILE_PREFIX, and unixTempFileDir().

Referenced by unixOpen().

◆ unixLeaveMutex()

static void unixLeaveMutex ( void )
static

Definition at line 34283 of file sqlite3.c.

34285 {
34286 assert( sqlite3_mutex_notheld(unixBigLock) ); /* Not a recursive mutex */

References sqlite3_mutex_enter(), sqlite3_mutex_notheld(), and unixBigLock.

Referenced by findReusableFd(), unixOpenSharedMemory(), unixShmBarrier(), and unixShmUnmap().

◆ unixLock()

static int unixLock ( sqlite3_file * id,
int eFileLock )
static

Definition at line 35196 of file sqlite3.c.

35202 {
35203 /* The following describes the implementation of the various locks and
35204 ** lock transitions in terms of the POSIX advisory shared and exclusive
35205 ** lock primitives (called read-locks and write-locks below, to avoid
35206 ** confusion with SQLite lock names). The algorithms are complicated
35207 ** slightly in order to be compatible with Windows95 systems simultaneously
35208 ** accessing the same database file, in case that is ever required.
35209 **
35210 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
35211 ** byte', each single bytes at well known offsets, and the 'shared byte
35212 ** range', a range of 510 bytes at a well known offset.
35213 **
35214 ** To obtain a SHARED lock, a read-lock is obtained on the 'pending
35215 ** byte'. If this is successful, 'shared byte range' is read-locked
35216 ** and the lock on the 'pending byte' released. (Legacy note: When
35217 ** SQLite was first developed, Windows95 systems were still very common,
35218 ** and Widnows95 lacks a shared-lock capability. So on Windows95, a
35219 ** single randomly selected by from the 'shared byte range' is locked.
35220 ** Windows95 is now pretty much extinct, but this work-around for the
35221 ** lack of shared-locks on Windows95 lives on, for backwards
35222 ** compatibility.)
35223 **
35224 ** A process may only obtain a RESERVED lock after it has a SHARED lock.
35225 ** A RESERVED lock is implemented by grabbing a write-lock on the
35226 ** 'reserved byte'.
35227 **
35228 ** A process may only obtain a PENDING lock after it has obtained a
35229 ** SHARED lock. A PENDING lock is implemented by obtaining a write-lock
35230 ** on the 'pending byte'. This ensures that no new SHARED locks can be
35231 ** obtained, but existing SHARED locks are allowed to persist. A process
35232 ** does not have to obtain a RESERVED lock on the way to a PENDING lock.
35233 ** This property is used by the algorithm for rolling back a journal file
35234 ** after a crash.
35235 **
35236 ** An EXCLUSIVE lock, obtained after a PENDING lock is held, is
35237 ** implemented by obtaining a write-lock on the entire 'shared byte
35238 ** range'. Since all other locks require a read-lock on one of the bytes
35239 ** within this range, this ensures that no other locks are held on the
35240 ** database.
35241 */
35242 int rc = SQLITE_OK;
35243 unixFile *pFile = (unixFile*)id;
35244 unixInodeInfo *pInode;
35245 struct flock lock;
35246 int tErrno = 0;
35247
35248 assert( pFile );
35249 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
35250 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
35251 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared,
35252 osGetpid(0)));
35253
35254 /* If there is already a lock of this type or more restrictive on the
35255 ** unixFile, do nothing. Don't use the end_lock: exit path, as
35256 ** unixEnterMutex() hasn't been called yet.
35257 */
35258 if( pFile->eFileLock>=eFileLock ){
35259 OSTRACE(("LOCK %d %s ok (already held) (unix)\n", pFile->h,
35260 azFileLock(eFileLock)));
35261 return SQLITE_OK;
35262 }
35263
35264 /* Make sure the locking sequence is correct.
35265 ** (1) We never move from unlocked to anything higher than shared lock.
35266 ** (2) SQLite never explicitly requests a pending lock.
35267 ** (3) A shared lock is always held when a reserve lock is requested.
35268 */
35269 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
35270 assert( eFileLock!=PENDING_LOCK );
35271 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
35272
35273 /* This mutex is needed because pFile->pInode is shared across threads
35274 */
35275 pInode = pFile->pInode;
35277
35278 /* If some thread using this PID has a lock via a different unixFile*
35279 ** handle that precludes the requested lock, return BUSY.
35280 */
35281 if( (pFile->eFileLock!=pInode->eFileLock &&
35282 (pInode->eFileLock>=PENDING_LOCK || eFileLock>SHARED_LOCK))
35283 ){
35284 rc = SQLITE_BUSY;
35285 goto end_lock;
35286 }
35287
35288 /* If a SHARED lock is requested, and some thread using this PID already
35289 ** has a SHARED or RESERVED lock, then increment reference counts and
35290 ** return SQLITE_OK.
35291 */
35292 if( eFileLock==SHARED_LOCK &&
35293 (pInode->eFileLock==SHARED_LOCK || pInode->eFileLock==RESERVED_LOCK) ){
35294 assert( eFileLock==SHARED_LOCK );
35295 assert( pFile->eFileLock==0 );
35296 assert( pInode->nShared>0 );
35297 pFile->eFileLock = SHARED_LOCK;
35298 pInode->nShared++;
35299 pInode->nLock++;
35300 goto end_lock;
35301 }
35302
35303
35304 /* A PENDING lock is needed before acquiring a SHARED lock and before
35305 ** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will
35306 ** be released.
35307 */
35308 lock.l_len = 1L;
35309 lock.l_whence = SEEK_SET;
35310 if( eFileLock==SHARED_LOCK
35311 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
35312 ){
35313 lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
35314 lock.l_start = PENDING_BYTE;
35315 if( unixFileLock(pFile, &lock) ){
35316 tErrno = errno;
35318 if( rc!=SQLITE_BUSY ){
35319 storeLastErrno(pFile, tErrno);
35320 }
35321 goto end_lock;
35322 }
35323 }
35324
35325
35326 /* If control gets to this point, then actually go ahead and make
35327 ** operating system calls for the specified lock.
35328 */
35329 if( eFileLock==SHARED_LOCK ){
35330 assert( pInode->nShared==0 );
35331 assert( pInode->eFileLock==0 );
35332 assert( rc==SQLITE_OK );
35333
35334 /* Now get the read-lock */
35335 lock.l_start = SHARED_FIRST;
35336 lock.l_len = SHARED_SIZE;
35337 if( unixFileLock(pFile, &lock) ){
35338 tErrno = errno;
35340 }
35341
35342 /* Drop the temporary PENDING lock */
35343 lock.l_start = PENDING_BYTE;
35344 lock.l_len = 1L;
35345 lock.l_type = F_UNLCK;
35346 if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){
35347 /* This could happen with a network mount */
35348 tErrno = errno;
35350 }
35351
35352 if( rc ){
35353 if( rc!=SQLITE_BUSY ){
35354 storeLastErrno(pFile, tErrno);
35355 }
35356 goto end_lock;
35357 }else{
35358 pFile->eFileLock = SHARED_LOCK;
35359 pInode->nLock++;
35360 pInode->nShared = 1;
35361 }
35362 }else if( eFileLock==EXCLUSIVE_LOCK && pInode->nShared>1 ){
35363 /* We are trying for an exclusive lock but another thread in this
35364 ** same process is still holding a shared lock. */
35365 rc = SQLITE_BUSY;
35366 }else{
35367 /* The request was for a RESERVED or EXCLUSIVE lock. It is
35368 ** assumed that there is a SHARED or greater lock on the file
35369 ** already.
35370 */
35371 assert( 0!=pFile->eFileLock );
35372 lock.l_type = F_WRLCK;
35373
35374 assert( eFileLock==RESERVED_LOCK || eFileLock==EXCLUSIVE_LOCK );
35375 if( eFileLock==RESERVED_LOCK ){
35376 lock.l_start = RESERVED_BYTE;
35377 lock.l_len = 1L;
35378 }else{
35379 lock.l_start = SHARED_FIRST;
35380 lock.l_len = SHARED_SIZE;
35381 }
35382
35383 if( unixFileLock(pFile, &lock) ){
35384 tErrno = errno;
35386 if( rc!=SQLITE_BUSY ){
35387 storeLastErrno(pFile, tErrno);
35388 }
35389 }
35390 }
35391
35392
35393#ifdef SQLITE_DEBUG
35394 /* Set up the transaction-counter change checking flags when
35395 ** transitioning from a SHARED to a RESERVED lock. The change
35396 ** from SHARED to RESERVED marks the beginning of a normal
35397 ** write operation (not a hot journal rollback).
35398 */
35399 if( rc==SQLITE_OK
35400 && pFile->eFileLock<=SHARED_LOCK
35401 && eFileLock==RESERVED_LOCK
35402 ){
35403 pFile->transCntrChng = 0;
35404 pFile->dbUpdate = 0;
35405 pFile->inNormalWrite = 1;
35406 }
35407#endif
35408
35409
35410 if( rc==SQLITE_OK ){
35411 pFile->eFileLock = eFileLock;
35412 pInode->eFileLock = eFileLock;
35413 }else if( eFileLock==EXCLUSIVE_LOCK ){
35414 pFile->eFileLock = PENDING_LOCK;
35415 pInode->eFileLock = PENDING_LOCK;
35416 }
35417
#define PENDING_LOCK
Definition sqlite3.c:16362

References unixFile::eFileLock, unixInodeInfo::eFileLock, EXCLUSIVE_LOCK, unixFile::h, unixInodeInfo::nLock, NO_LOCK, unixInodeInfo::nShared, osGetpid, OSTRACE, PENDING_BYTE, PENDING_LOCK, unixFile::pInode, unixInodeInfo::pLockMutex, RESERVED_BYTE, RESERVED_LOCK, SHARED_FIRST, SHARED_LOCK, SHARED_SIZE, sqlite3_mutex_enter(), sqlite3_mutex_leave(), SQLITE_BUSY, SQLITE_IOERR_LOCK, SQLITE_IOERR_UNLOCK, SQLITE_OK, sqliteErrorFromPosixError(), storeLastErrno(), and unixFileLock().

◆ unixLockSharedMemory()

static int unixLockSharedMemory ( unixFile * pDbFd,
unixShmNode * pShmNode )
static

Definition at line 37973 of file sqlite3.c.

37979 {
37980 struct flock lock;
37981 int rc = SQLITE_OK;
37982
37983 /* Use F_GETLK to determine the locks other processes are holding
37984 ** on the DMS byte. If it indicates that another process is holding
37985 ** a SHARED lock, then this process may also take a SHARED lock
37986 ** and proceed with opening the *-shm file.
37987 **
37988 ** Or, if no other process is holding any lock, then this process
37989 ** is the first to open it. In this case take an EXCLUSIVE lock on the
37990 ** DMS byte and truncate the *-shm file to zero bytes in size. Then
37991 ** downgrade to a SHARED lock on the DMS byte.
37992 **
37993 ** If another process is holding an EXCLUSIVE lock on the DMS byte,
37994 ** return SQLITE_BUSY to the caller (it will try again). An earlier
37995 ** version of this code attempted the SHARED lock at this point. But
37996 ** this introduced a subtle race condition: if the process holding
37997 ** EXCLUSIVE failed just before truncating the *-shm file, then this
37998 ** process might open and use the *-shm file without truncating it.
37999 ** And if the *-shm file has been corrupted by a power failure or
38000 ** system crash, the database itself may also become corrupt. */
38001 lock.l_whence = SEEK_SET;
38002 lock.l_start = UNIX_SHM_DMS;
38003 lock.l_len = 1;
38004 lock.l_type = F_WRLCK;
38005 if( osFcntl(pShmNode->hShm, F_GETLK, &lock)!=0 ) {
38006 rc = SQLITE_IOERR_LOCK;
38007 }else if( lock.l_type==F_UNLCK ){
38008 if( pShmNode->isReadonly ){
38009 pShmNode->isUnlocked = 1;
38011 }else{
38012 rc = unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1);
38013 /* The first connection to attach must truncate the -shm file. We
38014 ** truncate to 3 bytes (an arbitrary small number, less than the
38015 ** -shm header size) rather than 0 as a system debugging aid, to
38016 ** help detect if a -shm file truncation is legitimate or is the work
38017 ** or a rogue process. */
38018 if( rc==SQLITE_OK && robust_ftruncate(pShmNode->hShm, 3) ){
38019 rc = unixLogError(SQLITE_IOERR_SHMOPEN,"ftruncate",pShmNode->zFilename);
38020 }
38021 }
38022 }else if( lock.l_type==F_WRLCK ){
38023 rc = SQLITE_BUSY;
38024 }
38025
static int unixShmSystemLock(unixFile *pFile, int lockType, int ofst, int n)
Definition sqlite3.c:37840
#define SQLITE_IOERR_SHMOPEN
Definition sqlite3.c:1540
#define SQLITE_READONLY_CANTINIT
Definition sqlite3.c:1573
#define UNIX_SHM_DMS
Definition sqlite3.c:37832
char * zFilename
Definition sqlite3.c:37790

References unixShmNode::hShm, unixShmNode::isReadonly, unixShmNode::isUnlocked, osFcntl, robust_ftruncate(), SQLITE_BUSY, SQLITE_IOERR_LOCK, SQLITE_IOERR_SHMOPEN, SQLITE_OK, SQLITE_READONLY_CANTINIT, UNIX_SHM_DMS, unixLogError, unixShmSystemLock(), and unixShmNode::zFilename.

Referenced by unixOpenSharedMemory(), and unixShmMap().

◆ unixLogErrorAtLine()

static int unixLogErrorAtLine ( int errcode,
const char * zFunc,
const char * zPath,
int iLine )
static

Definition at line 34763 of file sqlite3.c.

34774 {
34775 char *zErr; /* Message from strerror() or equivalent */
34776 int iErrno = errno; /* Saved syscall error number */
34777
34778 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
34779 ** the strerror() function to obtain the human-readable error message
34780 ** equivalent to errno. Otherwise, use strerror_r().
34781 */
34782#if SQLITE_THREADSAFE && defined(HAVE_STRERROR_R)
34783 char aErr[80];
34784 memset(aErr, 0, sizeof(aErr));
34785 zErr = aErr;
34786
34787 /* If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined,
34788 ** assume that the system provides the GNU version of strerror_r() that
34789 ** returns a pointer to a buffer containing the error message. That pointer
34790 ** may point to aErr[], or it may point to some static storage somewhere.
34791 ** Otherwise, assume that the system provides the POSIX version of
34792 ** strerror_r(), which always writes an error message into aErr[].
34793 **
34794 ** If the code incorrectly assumes that it is the POSIX version that is
34795 ** available, the error message will often be an empty string. Not a
34796 ** huge problem. Incorrectly concluding that the GNU version is available
34797 ** could lead to a segfault though.
34798 */
34799#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
34800 zErr =
34801# endif
34802 strerror_r(iErrno, aErr, sizeof(aErr)-1);
34803
34804#elif SQLITE_THREADSAFE
34805 /* This is a threadsafe build, but strerror_r() is not available. */
34806 zErr = "";
34807#else
34808 /* Non-threadsafe build, use strerror(). */
34809 zErr = strerror(iErrno);
34810#endif
34811
34812 if( zPath==0 ) zPath = "";
34813 sqlite3_log(errcode,

References sqlite3_log().

Referenced by robust_close().

◆ unixModeBit()

static void unixModeBit ( unixFile * pFile,
unsigned char mask,
int * pArg )
static

Definition at line 37462 of file sqlite3.c.

37468 {
37469 if( *pArg<0 ){
37470 *pArg = (pFile->ctrlFlags & mask)!=0;

References unixFile::ctrlFlags, and mask.

◆ unixNextSystemCall()

static const char * unixNextSystemCall ( sqlite3_vfs * p,
const char * zName )
static

Definition at line 34175 of file sqlite3.c.

34181 {
34182 int i = -1;
34183
34185 if( zName ){
34186 for(i=0; i<ArraySize(aSyscall)-1; i++){
34187 if( strcmp(zName, aSyscall[i].zName)==0 ) break;
34188 }

References ArraySize, aSyscall, UNUSED_PARAMETER, zName, and unix_syscall::zName.

◆ unixOpen()

static int unixOpen ( sqlite3_vfs * pVfs,
const char * zPath,
sqlite3_file * pFile,
int flags,
int * pOutFlags )
static

Definition at line 39498 of file sqlite3.c.

39510 {
39511 unixFile *p = (unixFile *)pFile;
39512 int fd = -1; /* File descriptor returned by open() */
39513 int openFlags = 0; /* Flags to pass to open() */
39514 int eType = flags&0x0FFF00; /* Type of file to open */
39515 int noLock; /* True to omit locking primitives */
39516 int rc = SQLITE_OK; /* Function Return Code */
39517 int ctrlFlags = 0; /* UNIXFILE_* flags */
39518
39519 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
39520 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
39521 int isCreate = (flags & SQLITE_OPEN_CREATE);
39522 int isReadonly = (flags & SQLITE_OPEN_READONLY);
39523 int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
39524#if SQLITE_ENABLE_LOCKING_STYLE
39525 int isAutoProxy = (flags & SQLITE_OPEN_AUTOPROXY);
39526#endif
39527#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
39528 struct statfs fsInfo;
39529#endif
39530
39531 /* If creating a super- or main-file journal, this function will open
39532 ** a file-descriptor on the directory too. The first time unixSync()
39533 ** is called the directory file descriptor will be fsync()ed and close()d.
39534 */
39535 int isNewJrnl = (isCreate && (
39539 ));
39540
39541 /* If argument zPath is a NULL pointer, this function is required to open
39542 ** a temporary file. Use this buffer to store the file name in.
39543 */
39544 char zTmpname[MAX_PATHNAME+2];
39545 const char *zName = zPath;
39546
39547 /* Check the following statements are true:
39548 **
39549 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
39550 ** (b) if CREATE is set, then READWRITE must also be set, and
39551 ** (c) if EXCLUSIVE is set, then CREATE must also be set.
39552 ** (d) if DELETEONCLOSE is set, then CREATE must also be set.
39553 */
39554 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
39555 assert(isCreate==0 || isReadWrite);
39556 assert(isExclusive==0 || isCreate);
39557 assert(isDelete==0 || isCreate);
39558
39559 /* The main DB, main journal, WAL file and super-journal are never
39560 ** automatically deleted. Nor are they ever temporary files. */
39561 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
39562 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
39563 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL );
39564 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
39565
39566 /* Assert that the upper layer has set one of the "file-type" flags. */
39571 );
39572
39573 /* Detect a pid change and reset the PRNG. There is a race condition
39574 ** here such that two or more threads all trying to open databases at
39575 ** the same instant might all reset the PRNG. But multiple resets
39576 ** are harmless.
39577 */
39578 if( randomnessPid!=osGetpid(0) ){
39580 sqlite3_randomness(0,0);
39581 }
39582 memset(p, 0, sizeof(unixFile));
39583
39585 UnixUnusedFd *pUnused;
39586 pUnused = findReusableFd(zName, flags);
39587 if( pUnused ){
39588 fd = pUnused->fd;
39589 }else{
39590 pUnused = sqlite3_malloc64(sizeof(*pUnused));
39591 if( !pUnused ){
39592 return SQLITE_NOMEM_BKPT;
39593 }
39594 }
39595 p->pPreallocatedUnused = pUnused;
39596
39597 /* Database filenames are double-zero terminated if they are not
39598 ** URIs with parameters. Hence, they can always be passed into
39599 ** sqlite3_uri_parameter(). */
39600 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
39601
39602 }else if( !zName ){
39603 /* If zName is NULL, the upper layer is requesting a temp file. */
39604 assert(isDelete && !isNewJrnl);
39605 rc = unixGetTempname(pVfs->mxPathname, zTmpname);
39606 if( rc!=SQLITE_OK ){
39607 return rc;
39608 }
39609 zName = zTmpname;
39610
39611 /* Generated temporary filenames are always double-zero terminated
39612 ** for use by sqlite3_uri_parameter(). */
39613 assert( zName[strlen(zName)+1]==0 );
39614 }
39615
39616 /* Determine the value of the flags parameter passed to POSIX function
39617 ** open(). These must be calculated even if open() is not called, as
39618 ** they may be stored as part of the file handle and used by the
39619 ** 'conch file' locking functions later on. */
39620 if( isReadonly ) openFlags |= O_RDONLY;
39621 if( isReadWrite ) openFlags |= O_RDWR;
39622 if( isCreate ) openFlags |= O_CREAT;
39623 if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW);
39624 openFlags |= (O_LARGEFILE|O_BINARY|O_NOFOLLOW);
39625
39626 if( fd<0 ){
39627 mode_t openMode; /* Permissions to create file with */
39628 uid_t uid; /* Userid for the file */
39629 gid_t gid; /* Groupid for the file */
39630 rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
39631 if( rc!=SQLITE_OK ){
39632 assert( !p->pPreallocatedUnused );
39634 return rc;
39635 }
39636 fd = robust_open(zName, openFlags, openMode);
39637 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
39638 assert( !isExclusive || (openFlags & O_CREAT)!=0 );
39639 if( fd<0 ){
39640 if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
39641 /* If unable to create a journal because the directory is not
39642 ** writable, change the error code to indicate that. */
39644 }else if( errno!=EISDIR && isReadWrite ){
39645 /* Failed to open the file for read/write access. Try read-only. */
39647 openFlags &= ~(O_RDWR|O_CREAT);
39648 flags |= SQLITE_OPEN_READONLY;
39649 openFlags |= O_RDONLY;
39650 isReadonly = 1;
39651 fd = robust_open(zName, openFlags, openMode);
39652 }
39653 }
39654 if( fd<0 ){
39655 int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
39656 if( rc==SQLITE_OK ) rc = rc2;
39657 goto open_finished;
39658 }
39659
39660 /* The owner of the rollback journal or WAL file should always be the
39661 ** same as the owner of the database file. Try to ensure that this is
39662 ** the case. The chown() system call will be a no-op if the current
39663 ** process lacks root privileges, be we should at least try. Without
39664 ** this step, if a root process opens a database file, it can leave
39665 ** behinds a journal/WAL that is owned by root and hence make the
39666 ** database inaccessible to unprivileged processes.
39667 **
39668 ** If openMode==0, then that means uid and gid are not set correctly
39669 ** (probably because SQLite is configured to use 8+3 filename mode) and
39670 ** in that case we do not want to attempt the chown().
39671 */
39672 if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){
39673 robustFchown(fd, uid, gid);
39674 }
39675 }
39676 assert( fd>=0 );
39677 if( pOutFlags ){
39678 *pOutFlags = flags;
39679 }
39680
39681 if( p->pPreallocatedUnused ){
39682 p->pPreallocatedUnused->fd = fd;
39685 }
39686
39687 if( isDelete ){
39688#if OS_VXWORKS
39689 zPath = zName;
39690#elif defined(SQLITE_UNLINK_AFTER_CLOSE)
39691 zPath = sqlite3_mprintf("%s", zName);
39692 if( zPath==0 ){
39693 robust_close(p, fd, __LINE__);
39694 return SQLITE_NOMEM_BKPT;
39695 }
39696#else
39697 osUnlink(zName);
39698#endif
39699 }
39700#if SQLITE_ENABLE_LOCKING_STYLE
39701 else{
39702 p->openFlags = openFlags;
39703 }
39704#endif
39705
39706#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
39707 if( fstatfs(fd, &fsInfo) == -1 ){
39708 storeLastErrno(p, errno);
39709 robust_close(p, fd, __LINE__);
39710 return SQLITE_IOERR_ACCESS;
39711 }
39712 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
39713 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
39714 }
39715 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) {
39716 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
39717 }
39718#endif
39719
39720 /* Set up appropriate ctrlFlags */
39721 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
39722 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
39723 noLock = eType!=SQLITE_OPEN_MAIN_DB;
39724 if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK;
39725 if( isNewJrnl ) ctrlFlags |= UNIXFILE_DIRSYNC;
39726 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
39727
39728#if SQLITE_ENABLE_LOCKING_STYLE
39729#if SQLITE_PREFER_PROXY_LOCKING
39730 isAutoProxy = 1;
39731#endif
39732 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){
39733 char *envforce = getenv("SQLITE_FORCE_PROXY_LOCKING");
39734 int useProxy = 0;
39735
39736 /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
39737 ** never use proxy, NULL means use proxy for non-local files only. */
39738 if( envforce!=NULL ){
39739 useProxy = atoi(envforce)>0;
39740 }else{
39741 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
39742 }
39743 if( useProxy ){
39744 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
39745 if( rc==SQLITE_OK ){
39746 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
39747 if( rc!=SQLITE_OK ){
39748 /* Use unixClose to clean up the resources added in fillInUnixFile
39749 ** and clear all the structure's references. Specifically,
39750 ** pFile->pMethods will be NULL so sqlite3OsClose will be a no-op
39751 */
39752 unixClose(pFile);
39753 return rc;
39754 }
39755 }
39756 goto open_finished;
39757 }
39758 }
39759#endif
39760
39761 assert( zPath==0 || zPath[0]=='/'
39763 );
39764 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
39765
#define O_LARGEFILE
Definition sqlite3.c:33847
static int robustFchown(int fd, uid_t uid, gid_t gid)
Definition sqlite3.c:34099
#define UNIXFILE_DIRSYNC
Definition sqlite3.c:33631
static pid_t randomnessPid
Definition sqlite3.c:33622
#define SQLITE_OPEN_AUTOPROXY
Definition sqlite3.c:1606
#define O_NOFOLLOW
Definition sqlite3.c:33854
static int unixClose(sqlite3_file *id)
Definition sqlite3.c:35663
static UnixUnusedFd * findReusableFd(const char *zPath, int flags)
Definition sqlite3.c:39332
static int findCreateFileMode(const char *zPath, int flags, mode_t *pMode, uid_t *pUid, gid_t *pGid)
Definition sqlite3.c:39421
#define SQLITE_READONLY_DIRECTORY
Definition sqlite3.c:1574
int(* xOpen)(sqlite3_vfs *, const char *zName, sqlite3_file *, int flags, int *pOutFlags)
Definition sqlite3.c:2424

References eType, UnixUnusedFd::fd, findCreateFileMode(), findReusableFd(), UnixUnusedFd::flags, MAX_PATHNAME, sqlite3_vfs::mxPathname, NULL, O_BINARY, O_LARGEFILE, O_NOFOLLOW, osAccess, osGetpid, OSTRACE, osUnlink, unixFile::pPreallocatedUnused, randomnessPid, robust_close(), robust_open(), robustFchown(), sqlite3_free(), sqlite3_malloc64(), sqlite3_mprintf(), sqlite3_randomness(), SQLITE_CANTOPEN_BKPT, SQLITE_FSFLAGS_IS_MSDOS, SQLITE_IOERR_ACCESS, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_AUTOPROXY, SQLITE_OPEN_CREATE, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_EXCLUSIVE, SQLITE_OPEN_MAIN_DB, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SUBJOURNAL, SQLITE_OPEN_SUPER_JOURNAL, SQLITE_OPEN_TEMP_DB, SQLITE_OPEN_TEMP_JOURNAL, SQLITE_OPEN_TRANSIENT_DB, SQLITE_OPEN_URI, SQLITE_OPEN_WAL, SQLITE_READONLY_DIRECTORY, storeLastErrno(), unixClose(), UNIXFILE_DELETE, UNIXFILE_DIRSYNC, UNIXFILE_NOLOCK, UNIXFILE_RDONLY, UNIXFILE_URI, unixGetTempname(), unixLogError, sqlite3_vfs::xOpen, and zName.

◆ unixOpenSharedMemory()

static int unixOpenSharedMemory ( unixFile * pDbFd)
static

Definition at line 38062 of file sqlite3.c.

38068 {
38069 struct unixShm *p = 0; /* The connection to be opened */
38070 struct unixShmNode *pShmNode; /* The underlying mmapped file */
38071 int rc = SQLITE_OK; /* Result code */
38072 unixInodeInfo *pInode; /* The inode of fd */
38073 char *zShm; /* Name of the file used for SHM */
38074 int nShmFilename; /* Size of the SHM filename in bytes */
38075
38076 /* Allocate space for the new unixShm object. */
38077 p = sqlite3_malloc64( sizeof(*p) );
38078 if( p==0 ) return SQLITE_NOMEM_BKPT;
38079 memset(p, 0, sizeof(*p));
38080 assert( pDbFd->pShm==0 );
38081
38082 /* Check to see if a unixShmNode object already exists. Reuse an existing
38083 ** one if present. Create a new one if necessary.
38084 */
38085 assert( unixFileMutexNotheld(pDbFd) );
38087 pInode = pDbFd->pInode;
38088 pShmNode = pInode->pShmNode;
38089 if( pShmNode==0 ){
38090 struct stat sStat; /* fstat() info for database file */
38091#ifndef SQLITE_SHM_DIRECTORY
38092 const char *zBasePath = pDbFd->zPath;
38093#endif
38094
38095 /* Call fstat() to figure out the permissions on the database file. If
38096 ** a new *-shm file is created, an attempt will be made to create it
38097 ** with the same permissions.
38098 */
38099 if( osFstat(pDbFd->h, &sStat) ){
38100 rc = SQLITE_IOERR_FSTAT;
38101 goto shm_open_err;
38102 }
38103
38104#ifdef SQLITE_SHM_DIRECTORY
38105 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
38106#else
38107 nShmFilename = 6 + (int)strlen(zBasePath);
38108#endif
38109 pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
38110 if( pShmNode==0 ){
38111 rc = SQLITE_NOMEM_BKPT;
38112 goto shm_open_err;
38113 }
38114 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
38115 zShm = pShmNode->zFilename = (char*)&pShmNode[1];
38116#ifdef SQLITE_SHM_DIRECTORY
38117 sqlite3_snprintf(nShmFilename, zShm,
38118 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
38119 (u32)sStat.st_ino, (u32)sStat.st_dev);
38120#else
38121 sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath);
38122 sqlite3FileSuffix3(pDbFd->zPath, zShm);
38123#endif
38124 pShmNode->hShm = -1;
38125 pDbFd->pInode->pShmNode = pShmNode;
38126 pShmNode->pInode = pDbFd->pInode;
38127 if( sqlite3GlobalConfig.bCoreMutex ){
38129 if( pShmNode->pShmMutex==0 ){
38130 rc = SQLITE_NOMEM_BKPT;
38131 goto shm_open_err;
38132 }
38133 }
38134
38135 if( pInode->bProcessLock==0 ){
38136 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
38137 pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT|O_NOFOLLOW,
38138 (sStat.st_mode&0777));
38139 }
38140 if( pShmNode->hShm<0 ){
38141 pShmNode->hShm = robust_open(zShm, O_RDONLY|O_NOFOLLOW,
38142 (sStat.st_mode&0777));
38143 if( pShmNode->hShm<0 ){
38144 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
38145 goto shm_open_err;
38146 }
38147 pShmNode->isReadonly = 1;
38148 }
38149
38150 /* If this process is running as root, make sure that the SHM file
38151 ** is owned by the same user that owns the original database. Otherwise,
38152 ** the original owner will not be able to connect.
38153 */
38154 robustFchown(pShmNode->hShm, sStat.st_uid, sStat.st_gid);
38155
38156 rc = unixLockSharedMemory(pDbFd, pShmNode);
38157 if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
38158 }
38159 }
38160
38161 /* Make the new connection a child of the unixShmNode */
38162 p->pShmNode = pShmNode;
38163#ifdef SQLITE_DEBUG
38164 p->id = pShmNode->nextShmId++;
38165#endif
38166 pShmNode->nRef++;
38167 pDbFd->pShm = p;
38169
38170 /* The reference count on pShmNode has already been incremented under
38171 ** the cover of the unixEnterMutex() mutex and the pointer from the
38172 ** new (struct unixShm) object to the pShmNode has been set. All that is
38173 ** left to do is to link the new object into the linked list starting
38174 ** at pShmNode->pFirst. This must be done while holding the
38175 ** pShmNode->pShmMutex.
38176 */
38177 sqlite3_mutex_enter(pShmNode->pShmMutex);
38178 p->pNext = pShmNode->pFirst;
38179 pShmNode->pFirst = p;
38180 sqlite3_mutex_leave(pShmNode->pShmMutex);
38181 return rc;
38182
38183 /* Jump here on any error */
static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode)
Definition sqlite3.c:37973
unixShm * pShm
Definition sqlite3.c:33573
unixShm * pFirst
Definition sqlite3.c:37798
unixInodeInfo * pInode
Definition sqlite3.c:37788
sqlite3_mutex * pShmMutex
Definition sqlite3.c:37789
unixShm * pNext
Definition sqlite3.c:37821
unixShmNode * pShmNode
Definition sqlite3.c:37820

References unixInodeInfo::bProcessLock, unixFile::h, unixShmNode::hShm, unixShm::id, unixShmNode::isReadonly, unixShmNode::nRef, O_NOFOLLOW, osFstat, unixShmNode::pFirst, unixFile::pInode, unixShmNode::pInode, unixShm::pNext, unixFile::pShm, unixShmNode::pShmMutex, unixInodeInfo::pShmNode, unixShm::pShmNode, robust_open(), robustFchown(), sqlite3_free(), sqlite3_malloc64(), sqlite3_mutex_alloc(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_snprintf(), sqlite3_uri_boolean(), sqlite3FileSuffix3, sqlite3GlobalConfig, SQLITE_CANTOPEN_BKPT, SQLITE_IOERR_FSTAT, SQLITE_MUTEX_FAST, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_READONLY_CANTINIT, unixEnterMutex(), unixLeaveMutex(), unixLockSharedMemory(), unixLogError, unixShmPurge(), unixShmNode::zFilename, and unixFile::zPath.

Referenced by unixShmMap().

◆ unixRandomness()

static int unixRandomness ( sqlite3_vfs * NotUsed,
int nBuf,
char * zBuf )
static

Definition at line 40031 of file sqlite3.c.

40037 {
40038 UNUSED_PARAMETER(NotUsed);
40039 assert((size_t)nBuf>=(sizeof(time_t)+sizeof(int)));
40040
40041 /* We have to initialize zBuf to prevent valgrind from reporting
40042 ** errors. The reports issued by valgrind are incorrect - we would
40043 ** prefer that the randomness be increased by making use of the
40044 ** uninitialized space in zBuf - but valgrind errors tend to worry
40045 ** some users. Rather than argue, it seems easier just to initialize
40046 ** the whole array and silence valgrind, even if that means less randomness
40047 ** in the random seed.
40048 **
40049 ** When testing, initializing zBuf[] to zero is all we do. That means
40050 ** that we always use the same random number sequence. This makes the
40051 ** tests repeatable.
40052 */
40053 memset(zBuf, 0, nBuf);
40055#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
40056 {
40057 int fd, got;
40058 fd = robust_open("/dev/urandom", O_RDONLY, 0);
40059 if( fd<0 ){
40060 time_t t;
40061 time(&t);
40062 memcpy(zBuf, &t, sizeof(t));
40063 memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid));
40064 assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf );
40065 nBuf = sizeof(t) + sizeof(randomnessPid);
40066 }else{
40067 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );

References osGetpid, osRead, randomnessPid, robust_close(), robust_open(), and UNUSED_PARAMETER.

◆ unixRead()

static int unixRead ( sqlite3_file * id,
void * pBuf,
int amt,
sqlite3_int64 offset )
static

Definition at line 36873 of file sqlite3.c.

36884 {
36885 unixFile *pFile = (unixFile *)id;
36886 int got;
36887 assert( id );
36888 assert( offset>=0 );
36889 assert( amt>0 );
36890
36891 /* If this is a database file (not a journal, super-journal or temp
36892 ** file), the bytes in the locking range should never be read or written. */
36893#if 0
36894 assert( pFile->pPreallocatedUnused==0
36895 || offset>=PENDING_BYTE+512
36896 || offset+amt<=PENDING_BYTE
36897 );
36898#endif
36899
36900#if SQLITE_MAX_MMAP_SIZE>0
36901 /* Deal with as much of this read request as possible by transfering
36902 ** data from the memory mapping using memcpy(). */
36903 if( offset<pFile->mmapSize ){
36904 if( offset+amt <= pFile->mmapSize ){
36905 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
36906 return SQLITE_OK;
36907 }else{
36908 int nCopy = pFile->mmapSize - offset;
36909 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
36910 pBuf = &((u8 *)pBuf)[nCopy];
36911 amt -= nCopy;
36912 offset += nCopy;
36913 }
36914 }
36915#endif
36916
36917 got = seekAndRead(pFile, offset, pBuf, amt);
36918 if( got==amt ){
36919 return SQLITE_OK;
36920 }else if( got<0 ){
36921 /* lastErrno set by seekAndRead */
36922 return SQLITE_IOERR_READ;
36923 }else{
static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt)
Definition sqlite3.c:36824
#define SQLITE_IOERR_READ
Definition sqlite3.c:1523

References PENDING_BYTE, unixFile::pPreallocatedUnused, seekAndRead(), SQLITE_IOERR_READ, SQLITE_IOERR_SHORT_READ, SQLITE_OK, and storeLastErrno().

◆ unixSectorSize()

static int unixSectorSize ( sqlite3_file * id)
static

Definition at line 37711 of file sqlite3.c.

References unixFile::sectorSize, and setDeviceCharacteristics().

◆ unixSetSystemCall()

static int unixSetSystemCall ( sqlite3_vfs * pNotUsed,
const char * zName,
sqlite3_syscall_ptr pNewFunc )
static

Definition at line 34113 of file sqlite3.c.

34123 {
34124 unsigned int i;
34125 int rc = SQLITE_NOTFOUND;
34126
34127 UNUSED_PARAMETER(pNotUsed);
34128 if( zName==0 ){
34129 /* If no zName is given, restore all system calls to their default
34130 ** settings and return NULL
34131 */
34132 rc = SQLITE_OK;
34133 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
34134 if( aSyscall[i].pDefault ){
34136 }
34137 }
34138 }else{
34139 /* If zName is specified, operate on only the one system call
34140 ** specified.
34141 */
34142 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
34143 if( strcmp(zName, aSyscall[i].zName)==0 ){
34144 if( aSyscall[i].pDefault==0 ){
34146 }
34147 rc = SQLITE_OK;
34148 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
34149 aSyscall[i].pCurrent = pNewFunc;
sqlite3_syscall_ptr pDefault
Definition sqlite3.c:33928

References aSyscall, unix_syscall::pCurrent, unix_syscall::pDefault, SQLITE_NOTFOUND, SQLITE_OK, UNUSED_PARAMETER, and zName.

◆ unixShmBarrier()

static void unixShmBarrier ( sqlite3_file * fd)
static

Definition at line 38481 of file sqlite3.c.

38489 {
38490 UNUSED_PARAMETER(fd);
38491 sqlite3MemoryBarrier(); /* compiler-defined memory barrier */

References nolockLock(), sqlite3_file::pMethods, sqlite3MemoryBarrier(), unixEnterMutex(), unixLeaveMutex(), UNUSED_PARAMETER, and sqlite3_io_methods::xLock.

◆ unixShmLock()

static int unixShmLock ( sqlite3_file * fd,
int ofst,
int n,
int flags )
static

Definition at line 38347 of file sqlite3.c.

38358 {
38359 unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
38360 unixShm *p = pDbFd->pShm; /* The shared memory being locked */
38361 unixShm *pX; /* For looping over all siblings */
38362 unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
38363 int rc = SQLITE_OK; /* Result code */
38364 u16 mask; /* Mask of locks to take or release */
38365
38366 assert( pShmNode==pDbFd->pInode->pShmNode );
38367 assert( pShmNode->pInode==pDbFd->pInode );
38368 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
38369 assert( n>=1 );
38370 assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
38374 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
38375 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
38376 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
38377
38378 /* Check that, if this to be a blocking lock, no locks that occur later
38379 ** in the following list than the lock being obtained are already held:
38380 **
38381 ** 1. Checkpointer lock (ofst==1).
38382 ** 2. Write lock (ofst==0).
38383 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
38384 **
38385 ** In other words, if this is a blocking lock, none of the locks that
38386 ** occur later in the above list than the lock being obtained may be
38387 ** held.
38388 **
38389 ** It is not permitted to block on the RECOVER lock.
38390 */
38391#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
38392 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
38393 (ofst!=2) /* not RECOVER */
38394 && (ofst!=1 || (p->exclMask|p->sharedMask)==0)
38395 && (ofst!=0 || (p->exclMask|p->sharedMask)<3)
38396 && (ofst<3 || (p->exclMask|p->sharedMask)<(1<<ofst))
38397 ));
38398#endif
38399
38400 mask = (1<<(ofst+n)) - (1<<ofst);
38401 assert( n>1 || mask==(1<<ofst) );
38402 sqlite3_mutex_enter(pShmNode->pShmMutex);
38403 if( flags & SQLITE_SHM_UNLOCK ){
38404 u16 allMask = 0; /* Mask of locks held by siblings */
38405
38406 /* See if any siblings hold this same lock */
38407 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38408 if( pX==p ) continue;
38409 assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 );
38410 allMask |= pX->sharedMask;
38411 }
38412
38413 /* Unlock the system-level locks */
38414 if( (mask & allMask)==0 ){
38415 rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
38416 }else{
38417 rc = SQLITE_OK;
38418 }
38419
38420 /* Undo the local locks */
38421 if( rc==SQLITE_OK ){
38422 p->exclMask &= ~mask;
38423 p->sharedMask &= ~mask;
38424 }
38425 }else if( flags & SQLITE_SHM_SHARED ){
38426 u16 allShared = 0; /* Union of locks held by connections other than "p" */
38427
38428 /* Find out which shared locks are already held by sibling connections.
38429 ** If any sibling already holds an exclusive lock, go ahead and return
38430 ** SQLITE_BUSY.
38431 */
38432 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38433 if( (pX->exclMask & mask)!=0 ){
38434 rc = SQLITE_BUSY;
38435 break;
38436 }
38437 allShared |= pX->sharedMask;
38438 }
38439
38440 /* Get shared locks at the system level, if necessary */
38441 if( rc==SQLITE_OK ){
38442 if( (allShared & mask)==0 ){
38443 rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n);
38444 }else{
38445 rc = SQLITE_OK;
38446 }
38447 }
38448
38449 /* Get the local shared locks */
38450 if( rc==SQLITE_OK ){
38451 p->sharedMask |= mask;
38452 }
38453 }else{
38454 /* Make sure no sibling connections hold locks that will block this
38455 ** lock. If any do, return SQLITE_BUSY right away.
38456 */
38457 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38458 if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){
38459 rc = SQLITE_BUSY;
38460 break;
38461 }
38462 }
38463
38464 /* Get the exclusive locks at the system level. Then if successful
38465 ** also mark the local connection as being locked.
38466 */
38467 if( rc==SQLITE_OK ){
38468 rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n);
38469 if( rc==SQLITE_OK ){
38470 assert( (p->sharedMask & mask)==0 );
38471 p->exclMask |= mask;
38472 }
38473 }
#define SQLITE_SHM_LOCK
Definition sqlite3.c:2503
#define SQLITE_SHM_SHARED
Definition sqlite3.c:2504
#define SQLITE_SHM_UNLOCK
Definition sqlite3.c:2502
#define SQLITE_SHM_NLOCK
Definition sqlite3.c:2515
#define SQLITE_SHM_EXCLUSIVE
Definition sqlite3.c:2505
u16 sharedMask
Definition sqlite3.c:37824
u16 exclMask
Definition sqlite3.c:37825

References unixInodeInfo::bProcessLock, unixShm::exclMask, unixShmNode::hShm, unixShm::id, mask, osGetpid, OSTRACE, unixShmNode::pFirst, unixFile::pInode, unixShmNode::pInode, unixShm::pNext, unixFile::pShm, unixShmNode::pShmMutex, unixInodeInfo::pShmNode, unixShm::pShmNode, unixShm::sharedMask, sqlite3_mutex_enter(), sqlite3_mutex_leave(), SQLITE_BUSY, SQLITE_OK, SQLITE_SHM_EXCLUSIVE, SQLITE_SHM_LOCK, SQLITE_SHM_NLOCK, SQLITE_SHM_SHARED, SQLITE_SHM_UNLOCK, UNIX_SHM_BASE, and unixShmSystemLock().

◆ unixShmMap()

static int unixShmMap ( sqlite3_file * fd,
int iRegion,
int szRegion,
int bExtend,
void volatile ** pp )
static

Definition at line 38204 of file sqlite3.c.

38216 {
38217 unixFile *pDbFd = (unixFile*)fd;
38218 unixShm *p;
38219 unixShmNode *pShmNode;
38220 int rc = SQLITE_OK;
38221 int nShmPerMap = unixShmRegionPerMap();
38222 int nReqRegion;
38223
38224 /* If the shared-memory file has not yet been opened, open it now. */
38225 if( pDbFd->pShm==0 ){
38226 rc = unixOpenSharedMemory(pDbFd);
38227 if( rc!=SQLITE_OK ) return rc;
38228 }
38229
38230 p = pDbFd->pShm;
38231 pShmNode = p->pShmNode;
38232 sqlite3_mutex_enter(pShmNode->pShmMutex);
38233 if( pShmNode->isUnlocked ){
38234 rc = unixLockSharedMemory(pDbFd, pShmNode);
38235 if( rc!=SQLITE_OK ) goto shmpage_out;
38236 pShmNode->isUnlocked = 0;
38237 }
38238 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
38239 assert( pShmNode->pInode==pDbFd->pInode );
38240 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
38241 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
38242
38243 /* Minimum number of regions required to be mapped. */
38244 nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap;
38245
38246 if( pShmNode->nRegion<nReqRegion ){
38247 char **apNew; /* New apRegion[] array */
38248 int nByte = nReqRegion*szRegion; /* Minimum required file size */
38249 struct stat sStat; /* Used by fstat() */
38250
38251 pShmNode->szRegion = szRegion;
38252
38253 if( pShmNode->hShm>=0 ){
38254 /* The requested region is not mapped into this processes address space.
38255 ** Check to see if it has been allocated (i.e. if the wal-index file is
38256 ** large enough to contain the requested region).
38257 */
38258 if( osFstat(pShmNode->hShm, &sStat) ){
38260 goto shmpage_out;
38261 }
38262
38263 if( sStat.st_size<nByte ){
38264 /* The requested memory region does not exist. If bExtend is set to
38265 ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
38266 */
38267 if( !bExtend ){
38268 goto shmpage_out;
38269 }
38270
38271 /* Alternatively, if bExtend is true, extend the file. Do this by
38272 ** writing a single byte to the end of each (OS) page being
38273 ** allocated or extended. Technically, we need only write to the
38274 ** last page in order to extend the file. But writing to all new
38275 ** pages forces the OS to allocate them immediately, which reduces
38276 ** the chances of SIGBUS while accessing the mapped region later on.
38277 */
38278 else{
38279 static const int pgsz = 4096;
38280 int iPg;
38281
38282 /* Write to the last byte of each newly allocated or extended page */
38283 assert( (nByte % pgsz)==0 );
38284 for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
38285 int x = 0;
38286 if( seekAndWriteFd(pShmNode->hShm, iPg*pgsz + pgsz-1,"",1,&x)!=1 ){
38287 const char *zFile = pShmNode->zFilename;
38288 rc = unixLogError(SQLITE_IOERR_SHMSIZE, "write", zFile);
38289 goto shmpage_out;
38290 }
38291 }
38292 }
38293 }
38294 }
38295
38296 /* Map the requested memory region into this processes address space. */
38297 apNew = (char **)sqlite3_realloc(
38298 pShmNode->apRegion, nReqRegion*sizeof(char *)
38299 );
38300 if( !apNew ){
38302 goto shmpage_out;
38303 }
38304 pShmNode->apRegion = apNew;
38305 while( pShmNode->nRegion<nReqRegion ){
38306 int nMap = szRegion*nShmPerMap;
38307 int i;
38308 void *pMem;
38309 if( pShmNode->hShm>=0 ){
38310 pMem = osMmap(0, nMap,
38311 pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
38312 MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion
38313 );
38314 if( pMem==MAP_FAILED ){
38315 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
38316 goto shmpage_out;
38317 }
38318 }else{
38319 pMem = sqlite3_malloc64(nMap);
38320 if( pMem==0 ){
38321 rc = SQLITE_NOMEM_BKPT;
38322 goto shmpage_out;
38323 }
38324 memset(pMem, 0, nMap);
38325 }
38326
38327 for(i=0; i<nShmPerMap; i++){
38328 pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i];
38329 }
38330 pShmNode->nRegion += nShmPerMap;
38331 }
38332 }
38333
38334shmpage_out:
38335 if( pShmNode->nRegion>iRegion ){
38336 *pp = pShmNode->apRegion[iRegion];
38337 }else{
#define SQLITE_IOERR_SHMSIZE
Definition sqlite3.c:1541
static int unixOpenSharedMemory(unixFile *pDbFd)
Definition sqlite3.c:38062
#define SQLITE_IOERR_SHMMAP
Definition sqlite3.c:1543
SQLITE_API void * sqlite3_realloc(void *, int)
Definition sqlite3.c:27819
static int seekAndWriteFd(int fd, i64 iOff, const void *pBuf, int nBuf, int *piErrno)
Definition sqlite3.c:36932
#define osMmap
static int unixShmRegionPerMap(void)
Definition sqlite3.c:37925
char ** apRegion
Definition sqlite3.c:37796

References unixShmNode::apRegion, unixInodeInfo::bProcessLock, unixShmNode::hShm, unixShmNode::isReadonly, unixShmNode::isUnlocked, unixShmNode::nRegion, osFstat, osMmap, unixFile::pInode, unixShmNode::pInode, unixFile::pShm, unixShmNode::pShmMutex, unixShm::pShmNode, seekAndWriteFd(), sqlite3_malloc64(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3_realloc(), SQLITE_IOERR_NOMEM_BKPT, SQLITE_IOERR_SHMMAP, SQLITE_IOERR_SHMSIZE, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_READONLY, unixShmNode::szRegion, unixLockSharedMemory(), unixLogError, unixOpenSharedMemory(), unixShmRegionPerMap(), and unixShmNode::zFilename.

◆ unixShmPurge()

static void unixShmPurge ( unixFile * pFd)
static

Definition at line 37939 of file sqlite3.c.

37945 {
37946 unixShmNode *p = pFd->pInode->pShmNode;
37947 assert( unixMutexHeld() );
37948 if( p && ALWAYS(p->nRef==0) ){
37949 int nShmPerMap = unixShmRegionPerMap();
37950 int i;
37951 assert( p->pInode==pFd->pInode );
37953 for(i=0; i<p->nRegion; i+=nShmPerMap){
37954 if( p->hShm>=0 ){
37955 osMunmap(p->apRegion[i], p->szRegion);
37956 }else{
37957 sqlite3_free(p->apRegion[i]);
37958 }
37959 }
37961 if( p->hShm>=0 ){
37962 robust_close(pFd, p->hShm, __LINE__);
#define osMunmap

References ALWAYS, unixShmNode::apRegion, unixShmNode::hShm, unixShmNode::nRef, unixShmNode::nRegion, osMunmap, unixFile::pInode, unixShmNode::pInode, unixShmNode::pShmMutex, unixInodeInfo::pShmNode, robust_close(), sqlite3_free(), sqlite3_mutex_free(), unixShmNode::szRegion, and unixShmRegionPerMap().

Referenced by unixOpenSharedMemory(), and unixShmUnmap().

◆ unixShmRegionPerMap()

static int unixShmRegionPerMap ( void )
static

Definition at line 37925 of file sqlite3.c.

37931 {

References osGetpagesize.

Referenced by unixShmMap(), and unixShmPurge().

◆ unixShmSystemLock()

static int unixShmSystemLock ( unixFile * pFile,
int lockType,
int ofst,
int n )
static

Definition at line 37840 of file sqlite3.c.

37851 {
37852 unixShmNode *pShmNode; /* Apply locks to this open shared-memory segment */
37853 struct flock f; /* The posix advisory locking structure */
37854 int rc = SQLITE_OK; /* Result code form fcntl() */
37855
37856 /* Access to the unixShmNode object is serialized by the caller */
37857 pShmNode = pFile->pInode->pShmNode;
37858 assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) );
37859 assert( pShmNode->nRef>0 || unixMutexHeld() );
37860
37861 /* Shared locks never span more than one byte */
37862 assert( n==1 || lockType!=F_RDLCK );
37863
37864 /* Locks are within range */
37865 assert( n>=1 && n<=SQLITE_SHM_NLOCK );
37866
37867 if( pShmNode->hShm>=0 ){
37868 int res;
37869 /* Initialize the locking parameters */
37870 f.l_type = lockType;
37871 f.l_whence = SEEK_SET;
37872 f.l_start = ofst;
37873 f.l_len = n;
37874 res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
37875 if( res==-1 ){
37876#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
37877 rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY);
37878#else
37879 rc = SQLITE_BUSY;
37880#endif
37881 }
37882 }
37883
37884 /* Update the global lock state and do debug tracing */
37885#ifdef SQLITE_DEBUG
37886 { u16 mask;
37887 OSTRACE(("SHM-LOCK "));
37888 mask = ofst>31 ? 0xffff : (1<<(ofst+n)) - (1<<ofst);
37889 if( rc==SQLITE_OK ){
37890 if( lockType==F_UNLCK ){
37891 OSTRACE(("unlock %d ok", ofst));
37892 pShmNode->exclMask &= ~mask;
37893 pShmNode->sharedMask &= ~mask;
37894 }else if( lockType==F_RDLCK ){
37895 OSTRACE(("read-lock %d ok", ofst));
37896 pShmNode->exclMask &= ~mask;
37897 pShmNode->sharedMask |= mask;
37898 }else{
37899 assert( lockType==F_WRLCK );
37900 OSTRACE(("write-lock %d ok", ofst));
37901 pShmNode->exclMask |= mask;
37902 pShmNode->sharedMask &= ~mask;
37903 }
37904 }else{
37905 if( lockType==F_UNLCK ){
37906 OSTRACE(("unlock %d failed", ofst));
37907 }else if( lockType==F_RDLCK ){
37908 OSTRACE(("read-lock failed"));
37909 }else{
37910 assert( lockType==F_WRLCK );
37911 OSTRACE(("write-lock %d failed", ofst));
37912 }
37913 }
37914 OSTRACE((" - afterwards %03x,%03x\n",

References unixShmNode::hShm, mask, unixShmNode::nRef, osSetPosixAdvisoryLock, OSTRACE, unixFile::pInode, unixShmNode::pShmMutex, unixInodeInfo::pShmNode, sqlite3_mutex_held(), SQLITE_BUSY, SQLITE_BUSY_TIMEOUT, SQLITE_OK, and SQLITE_SHM_NLOCK.

Referenced by unixLockSharedMemory(), and unixShmLock().

◆ unixShmUnmap()

static int unixShmUnmap ( sqlite3_file * fd,
int deleteFlag )
static

Definition at line 38500 of file sqlite3.c.

38509 {
38510 unixShm *p; /* The connection to be closed */
38511 unixShmNode *pShmNode; /* The underlying shared-memory file */
38512 unixShm **pp; /* For looping over sibling connections */
38513 unixFile *pDbFd; /* The underlying database file */
38514
38515 pDbFd = (unixFile*)fd;
38516 p = pDbFd->pShm;
38517 if( p==0 ) return SQLITE_OK;
38518 pShmNode = p->pShmNode;
38519
38520 assert( pShmNode==pDbFd->pInode->pShmNode );
38521 assert( pShmNode->pInode==pDbFd->pInode );
38522
38523 /* Remove connection p from the set of connections associated
38524 ** with pShmNode */
38525 sqlite3_mutex_enter(pShmNode->pShmMutex);
38526 for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){}
38527 *pp = p->pNext;
38528
38529 /* Free the connection p */
38530 sqlite3_free(p);
38531 pDbFd->pShm = 0;
38532 sqlite3_mutex_leave(pShmNode->pShmMutex);
38533
38534 /* If pShmNode->nRef has reached 0, then close the underlying
38535 ** shared-memory file, too */
38536 assert( unixFileMutexNotheld(pDbFd) );
38538 assert( pShmNode->nRef>0 );
38539 pShmNode->nRef--;
38540 if( pShmNode->nRef==0 ){
38541 if( deleteFlag && pShmNode->hShm>=0 ){
38542 osUnlink(pShmNode->zFilename);
38543 }

References unixShmNode::hShm, unixShmNode::nRef, osUnlink, unixShmNode::pFirst, unixFile::pInode, unixShmNode::pInode, unixShm::pNext, unixFile::pShm, unixShmNode::pShmMutex, unixInodeInfo::pShmNode, unixShm::pShmNode, sqlite3_free(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), SQLITE_OK, unixEnterMutex(), unixLeaveMutex(), unixShmPurge(), and unixShmNode::zFilename.

◆ unixSleep()

static int unixSleep ( sqlite3_vfs * NotUsed,
int microseconds )
static

Definition at line 40078 of file sqlite3.c.

40084 {
40085#if OS_VXWORKS
40086 struct timespec sp;
40087
40088 sp.tv_sec = microseconds / 1000000;
40089 sp.tv_nsec = (microseconds % 1000000) * 1000;
40090 nanosleep(&sp, NULL);
40091 UNUSED_PARAMETER(NotUsed);
40092 return microseconds;
40093#elif defined(HAVE_USLEEP) && HAVE_USLEEP
40094 usleep(microseconds);
40095 UNUSED_PARAMETER(NotUsed);
40096 return microseconds;
40097#else

References NULL, and UNUSED_PARAMETER.

◆ unixSync()

static int unixSync ( sqlite3_file * id,
int flags )
static

Definition at line 37255 of file sqlite3.c.

37261 {
37262 int rc;
37263 unixFile *pFile = (unixFile*)id;
37264
37265 int isDataOnly = (flags&SQLITE_SYNC_DATAONLY);
37266 int isFullsync = (flags&0x0F)==SQLITE_SYNC_FULL;
37267
37268 /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */
37269 assert((flags&0x0F)==SQLITE_SYNC_NORMAL
37270 || (flags&0x0F)==SQLITE_SYNC_FULL
37271 );
37272
37273 /* Unix cannot, but some systems may return SQLITE_FULL from here. This
37274 ** line is to test that doing so does not cause any problems.
37275 */
37277
37278 assert( pFile );
37279 OSTRACE(("SYNC %-3d\n", pFile->h));
37280 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
37281 SimulateIOError( rc=1 );
37282 if( rc ){
37283 storeLastErrno(pFile, errno);
37284 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
37285 }
37286
37287 /* Also fsync the directory containing the file if the DIRSYNC flag
37288 ** is set. This is a one-time occurrence. Many systems (examples: AIX)
37289 ** are unable to fsync a directory, so ignore errors on the fsync.
37290 */
37291 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
37292 int dirfd;
37293 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
37294 HAVE_FULLFSYNC, isFullsync));
37295 rc = osOpenDirectory(pFile->zPath, &dirfd);
37296 if( rc==SQLITE_OK ){
37297 full_fsync(dirfd, 0, 0);
37298 robust_close(pFile, dirfd, __LINE__);
37299 }else{
37300 assert( rc==SQLITE_CANTOPEN );
#define HAVE_FULLFSYNC
Definition sqlite3.c:37094
#define SimulateDiskfullError(A)
Definition sqlite3.c:33825
#define SQLITE_IOERR_FSYNC
Definition sqlite3.c:1526

References unixFile::ctrlFlags, full_fsync(), unixFile::h, HAVE_FULLFSYNC, osOpenDirectory, OSTRACE, robust_close(), SimulateDiskfullError, SimulateIOError, SQLITE_CANTOPEN, SQLITE_FULL, SQLITE_IOERR_FSYNC, SQLITE_OK, SQLITE_SYNC_DATAONLY, SQLITE_SYNC_FULL, SQLITE_SYNC_NORMAL, storeLastErrno(), UNIXFILE_DIRSYNC, unixLogError, and unixFile::zPath.

◆ unixTempFileDir()

static const char * unixTempFileDir ( void )
static

Definition at line 39248 of file sqlite3.c.

39254 {
39255 static const char *azDirs[] = {
39256 0,
39257 0,
39258 "/var/tmp",
39259 "/usr/tmp",
39260 "/tmp",
39261 "."
39262 };
39263 unsigned int i = 0;
39264 struct stat buf;
39265 const char *zDir = sqlite3_temp_directory;
39266
39267 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
39268 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
39269 while(1){
39270 if( zDir!=0
39271 && osStat(zDir, &buf)==0
39272 && S_ISDIR(buf.st_mode)
39273 && osAccess(zDir, 03)==0
39274 ){
39275 return zDir;

Referenced by unixGetTempname().

◆ unixTruncate()

static int unixTruncate ( sqlite3_file * id,
i64 nByte )
static

Definition at line 37305 of file sqlite3.c.

37311 {
37312 unixFile *pFile = (unixFile *)id;
37313 int rc;
37314 assert( pFile );
37316
37317 /* If the user has configured a chunk-size for this file, truncate the
37318 ** file so that it consists of an integer number of chunks (i.e. the
37319 ** actual file size after the operation may be larger than the requested
37320 ** size).
37321 */
37322 if( pFile->szChunk>0 ){
37323 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
37324 }
37325
37326 rc = robust_ftruncate(pFile->h, nByte);
37327 if( rc ){
37328 storeLastErrno(pFile, errno);
37329 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
37330 }else{
37331#ifdef SQLITE_DEBUG
37332 /* If we are doing a normal write to a database file (as opposed to
37333 ** doing a hot-journal rollback or a write to some file other than a
37334 ** normal database file) and we truncate the file to zero length,
37335 ** that effectively updates the change counter. This might happen
37336 ** when restoring a database using the backup API from a zero-length
37337 ** source.
37338 */
37339 if( pFile->inNormalWrite && nByte==0 ){
37340 pFile->transCntrChng = 1;
37341 }
37342#endif
37343
37344#if SQLITE_MAX_MMAP_SIZE>0
37345 /* If the file was just truncated to a size smaller than the currently
37346 ** mapped region, reduce the effective mapping size as well. SQLite will
37347 ** use read() and write() to access data beyond this point from now on.
37348 */
37349 if( nByte<pFile->mmapSize ){
37350 pFile->mmapSize = nByte;

◆ unixUnfetch()

static int unixUnfetch ( sqlite3_file * fd,
i64 iOff,
void * p )
static

Definition at line 38742 of file sqlite3.c.

38748 {
38749#if SQLITE_MAX_MMAP_SIZE>0
38750 unixFile *pFd = (unixFile *)fd; /* The underlying database file */
38751 UNUSED_PARAMETER(iOff);
38752
38753 /* If p==0 (unmap the entire file) then there must be no outstanding
38754 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
38755 ** then there must be at least one outstanding. */
38756 assert( (p==0)==(pFd->nFetchOut==0) );
38757
38758 /* If p!=0, it must match the iOff value. */
38759 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] );
38760
38761 if( p ){
38762 pFd->nFetchOut--;
38763 }else{
38764 unixUnmapfile(pFd);
38765 }
38766
38767 assert( pFd->nFetchOut>=0 );
38768#else

References SQLITE_OK, and UNUSED_PARAMETER.

◆ unixUnlock()

static int unixUnlock ( sqlite3_file * id,
int eFileLock )
static

Definition at line 35606 of file sqlite3.c.

References posixUnlock(), and SHARED_LOCK.

◆ unixWrite()

static int unixWrite ( sqlite3_file * id,
const void * pBuf,
int amt,
sqlite3_int64 offset )
static

Definition at line 36987 of file sqlite3.c.

36998 {
36999 unixFile *pFile = (unixFile*)id;
37000 int wrote = 0;
37001 assert( id );
37002 assert( amt>0 );
37003
37004 /* If this is a database file (not a journal, super-journal or temp
37005 ** file), the bytes in the locking range should never be read or written. */
37006#if 0
37007 assert( pFile->pPreallocatedUnused==0
37008 || offset>=PENDING_BYTE+512
37009 || offset+amt<=PENDING_BYTE
37010 );
37011#endif
37012
37013#ifdef SQLITE_DEBUG
37014 /* If we are doing a normal write to a database file (as opposed to
37015 ** doing a hot-journal rollback or a write to some file other than a
37016 ** normal database file) then record the fact that the database
37017 ** has changed. If the transaction counter is modified, record that
37018 ** fact too.
37019 */
37020 if( pFile->inNormalWrite ){
37021 pFile->dbUpdate = 1; /* The database has been modified */
37022 if( offset<=24 && offset+amt>=27 ){
37023 int rc;
37024 char oldCntr[4];
37026 rc = seekAndRead(pFile, 24, oldCntr, 4);
37028 if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){
37029 pFile->transCntrChng = 1; /* The transaction counter has changed */
37030 }
37031 }
37032 }
37033#endif
37034
37035#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
37036 /* Deal with as much of this write request as possible by transfering
37037 ** data from the memory mapping using memcpy(). */
37038 if( offset<pFile->mmapSize ){
37039 if( offset+amt <= pFile->mmapSize ){
37040 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
37041 return SQLITE_OK;
37042 }else{
37043 int nCopy = pFile->mmapSize - offset;
37044 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
37045 pBuf = &((u8 *)pBuf)[nCopy];
37046 amt -= nCopy;
37047 offset += nCopy;
37048 }
37049 }
37050#endif
37051
37052 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
37053 amt -= wrote;
37054 offset += wrote;
37055 pBuf = &((char*)pBuf)[wrote];
37056 }
37057 SimulateIOError(( wrote=(-1), amt=1 ));
37058 SimulateDiskfullError(( wrote=0, amt=1 ));
37059
37060 if( amt>wrote ){
37061 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
37062 /* lastErrno set by seekAndWrite */
37063 return SQLITE_IOERR_WRITE;
37064 }else{
37065 storeLastErrno(pFile, 0); /* not a system error */

References PENDING_BYTE, unixFile::pPreallocatedUnused, seekAndRead(), seekAndWrite(), SimulateDiskfullError, SimulateIOError, SimulateIOErrorBenign, SQLITE_FULL, SQLITE_IOERR_WRITE, SQLITE_OK, and storeLastErrno().

◆ unlockBtreeIfUnused()

static void unlockBtreeIfUnused ( BtShared * pBt)
static

Definition at line 67745 of file sqlite3.c.

67751 {
67752 assert( sqlite3_mutex_held(pBt->mutex) );
67753 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
67754 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
67755 MemPage *pPage1 = pBt->pPage1;

References MemPage::aData, BtShared::inTransaction, BtShared::mutex, BtShared::pPage1, BtShared::pPager, releasePageOne(), sqlite3_mutex_held(), and TRANS_NONE.

Referenced by sqlite3BtreeBeginTrans().

◆ unlockBtreeMutex()

static void SQLITE_NOINLINE unlockBtreeMutex ( Btree * p)
static

Definition at line 64207 of file sqlite3.c.

64213 {
64214 BtShared *pBt = p->pBt;
64215 assert( p->locked==1 );
64216 assert( sqlite3_mutex_held(pBt->mutex) );

Referenced by btreeLockCarefully().

◆ unmapColumnIdlistNames()

static void unmapColumnIdlistNames ( Parse * pParse,
IdList * pIdList )
static

Definition at line 106572 of file sqlite3.c.

106581 {
106582 if( pIdList ){

◆ unsetJoinExpr()

static void unsetJoinExpr ( Expr * p,
int iTable )
static

Definition at line 129697 of file sqlite3.c.

129703 {
129704 while( p ){
129706 && (iTable<0 || p->iRightJoinTable==iTable) ){
129708 }
129709 if( p->op==TK_FUNCTION && p->x.pList ){
129710 int i;
129711 for(i=0; i<p->x.pList->nExpr; i++){
129712 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);

References ExprList::a, EP_FromJoin, ExprClearProperty, ExprHasProperty, ExprList::nExpr, Expr::op, ExprList::ExprList_item::pExpr, Expr::pLeft, Expr::pList, Expr::pRight, TK_FUNCTION, unsetJoinExpr(), and Expr::x.

Referenced by pushDownWhereTerms(), sqlite3Select(), and unsetJoinExpr().

◆ updateAccumulator()

static void updateAccumulator ( Parse * pParse,
int regAcc,
AggInfo * pAggInfo )
static

Definition at line 134752 of file sqlite3.c.

134758 {
134759 Vdbe *v = pParse->pVdbe;
134760 int i;
134761 int regHit = 0;
134762 int addrHitTest = 0;
134763 struct AggInfo_func *pF;
134764 struct AggInfo_col *pC;
134765
134766 pAggInfo->directMode = 1;
134767 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134768 int nArg;
134769 int addrNext = 0;
134770 int regAgg;
134771 ExprList *pList = pF->pFExpr->x.pList;
134772 assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
134773 assert( !IsWindowFunc(pF->pFExpr) );
134774 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
134775 Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
134776 if( pAggInfo->nAccumulator
134777 && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
134778 && regAcc
134779 ){
134780 /* If regAcc==0, there there exists some min() or max() function
134781 ** without a FILTER clause that will ensure the magnet registers
134782 ** are populated. */
134783 if( regHit==0 ) regHit = ++pParse->nMem;
134784 /* If this is the first row of the group (regAcc contains 0), clear the
134785 ** "magnet" register regHit so that the accumulator registers
134786 ** are populated if the FILTER clause jumps over the the
134787 ** invocation of min() or max() altogether. Or, if this is not
134788 ** the first row (regAcc contains 1), set the magnet register so that
134789 ** the accumulators are not populated unless the min()/max() is invoked
134790 ** and indicates that they should be. */
134791 sqlite3VdbeAddOp2(v, OP_Copy, regAcc, regHit);
134792 }
134793 addrNext = sqlite3VdbeMakeLabel(pParse);
134794 sqlite3ExprIfFalse(pParse, pFilter, addrNext, SQLITE_JUMPIFNULL);
134795 }
134796 if( pList ){
134797 nArg = pList->nExpr;
134798 regAgg = sqlite3GetTempRange(pParse, nArg);
134799 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
134800 }else{
134801 nArg = 0;
134802 regAgg = 0;
134803 }
134804 if( pF->iDistinct>=0 ){
134805 if( addrNext==0 ){
134806 addrNext = sqlite3VdbeMakeLabel(pParse);
134807 }
134808 testcase( nArg==0 ); /* Error condition */
134809 testcase( nArg>1 ); /* Also an error */
134810 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
134811 }
134812 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
134813 CollSeq *pColl = 0;
134814 struct ExprList_item *pItem;
134815 int j;
134816 assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
134817 for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
134818 pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
134819 }
134820 if( !pColl ){
134821 pColl = pParse->db->pDfltColl;
134822 }
134823 if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
134824 sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ);
134825 }
134826 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, pF->iMem);
134827 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
134828 sqlite3VdbeChangeP5(v, (u8)nArg);
134829 sqlite3ReleaseTempRange(pParse, regAgg, nArg);
134830 if( addrNext ){
134831 sqlite3VdbeResolveLabel(v, addrNext);
134832 }
134833 }
134834 if( regHit==0 && pAggInfo->nAccumulator ){
134835 regHit = regAcc;
134836 }
134837 if( regHit ){
134838 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
134839 }
134840 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
134841 sqlite3ExprCode(pParse, pC->pCExpr, pC->iMem);
134842 }

References ExprList::a, AggInfo::aCol, AggInfo::aFunc, codeDistinct(), Parse::db, AggInfo::directMode, EP_WinFunc, EP_xIsSelect, ExprHasProperty, IsWindowFunc, AggInfo::nAccumulator, ExprList::nExpr, AggInfo::nFunc, Parse::nMem, OP_AggStep, OP_CollSeq, OP_Copy, OP_If, P4_COLLSEQ, P4_FUNCDEF, sqlite3::pDfltColl, Window::pFilter, Parse::pVdbe, Expr::pWin, sqlite3ExprCode(), sqlite3ExprCodeExprList(), sqlite3ExprCollSeq(), sqlite3ExprIfFalse(), sqlite3GetTempRange(), sqlite3ReleaseTempRange(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeJumpHereOrPopInst(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), SQLITE_ECEL_DUP, SQLITE_FUNC_NEEDCOLL, SQLITE_JUMPIFNULL, testcase, VdbeCoverage, and Expr::y.

Referenced by sqlite3Select().

◆ updateFromSelect()

static void updateFromSelect ( Parse * pParse,
int iEph,
Index * pPk,
ExprList * pChanges,
SrcList * pTabList,
Expr * pWhere,
ExprList * pOrderBy,
Expr * pLimit )
static

Definition at line 137778 of file sqlite3.c.

137793 {
137794 int i;
137795 SelectDest dest;
137796 Select *pSelect = 0;
137797 ExprList *pList = 0;
137798 ExprList *pGrp = 0;
137799 Expr *pLimit2 = 0;
137800 ExprList *pOrderBy2 = 0;
137801 sqlite3 *db = pParse->db;
137802 Table *pTab = pTabList->a[0].pTab;
137803 SrcList *pSrc;
137804 Expr *pWhere2;
137805 int eDest;
137806
137807#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
137808 if( pOrderBy && pLimit==0 ) {
137809 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on UPDATE");
137810 return;
137811 }
137812 pOrderBy2 = sqlite3ExprListDup(db, pOrderBy, 0);
137813 pLimit2 = sqlite3ExprDup(db, pLimit, 0);
137814#else
137815 UNUSED_PARAMETER(pOrderBy);
137816 UNUSED_PARAMETER(pLimit);
137817#endif
137818
137819 pSrc = sqlite3SrcListDup(db, pTabList, 0);
137820 pWhere2 = sqlite3ExprDup(db, pWhere, 0);
137821
137822 assert( pTabList->nSrc>1 );
137823 if( pSrc ){
137824 pSrc->a[0].iCursor = -1;
137825 pSrc->a[0].pTab->nTabRef--;
137826 pSrc->a[0].pTab = 0;
137827 }
137828 if( pPk ){
137829 for(i=0; i<pPk->nKeyCol; i++){
137830 Expr *pNew = exprRowColumn(pParse, pPk->aiColumn[i]);
137831#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
137832 if( pLimit ){
137833 pGrp = sqlite3ExprListAppend(pParse, pGrp, sqlite3ExprDup(db, pNew, 0));
137834 }
137835#endif
137836 pList = sqlite3ExprListAppend(pParse, pList, pNew);
137837 }
137838 eDest = SRT_Upfrom;
137839 }else if( pTab->pSelect ){
137840 for(i=0; i<pTab->nCol; i++){
137841 pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
137842 }
137843 eDest = SRT_Table;
137844 }else{
137845 eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom;
137846 pList = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
137847#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
137848 if( pLimit ){
137849 pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
137850 }
137851#endif
137852 }
137853 if( ALWAYS(pChanges) ){
137854 for(i=0; i<pChanges->nExpr; i++){
137855 pList = sqlite3ExprListAppend(pParse, pList,
137856 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
137857 );
137858 }
137859 }
137860 pSelect = sqlite3SelectNew(pParse, pList,
137861 pSrc, pWhere2, pGrp, 0, pOrderBy2, SF_UpdateFrom|SF_IncludeHidden, pLimit2
static Expr * exprRowColumn(Parse *pParse, int iCol)
Definition sqlite3.c:137734

References ExprList::a, SrcList::a, Index::aiColumn, ALWAYS, Parse::db, exprRowColumn(), SrcList::SrcList_item::iCursor, SelectDest::iSDParm2, IsVirtual, Table::nCol, ExprList::nExpr, Index::nKeyCol, SrcList::nSrc, Table::nTabRef, ExprList::ExprList_item::pExpr, Table::pSelect, SrcList::SrcList_item::pTab, SF_IncludeHidden, SF_UpdateFrom, sqlite3ErrorMsg(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3ExprListDup(), sqlite3PExpr(), sqlite3Select(), sqlite3SelectDelete(), sqlite3SelectDestInit(), sqlite3SelectNew(), sqlite3SrcListDup(), SRT_Table, SRT_Upfrom, TK_ROW, and UNUSED_PARAMETER.

Referenced by sqlite3Update(), and updateVirtualTable().

◆ updateRangeAffinityStr()

static void updateRangeAffinityStr ( Expr * pRight,
int n,
char * zAff )
static

Definition at line 141881 of file sqlite3.c.

141882 :
141883**
141884** * the comparison will be performed with no affinity, or
141885** * the affinity change in zAff is guaranteed not to change the value.
141886*/
141887static void updateRangeAffinityStr(
141888 Expr *pRight, /* RHS of comparison */
141889 int n, /* Number of vector elements in comparison */
141890 char *zAff /* Affinity string to modify */
141891){
141892 int i;
141893 for(i=0; i<n; i++){
141894 Expr *p = sqlite3VectorFieldSubexpr(pRight, i);
141895 if( sqlite3CompareAffinity(p, zAff[i])==SQLITE_AFF_BLOB

References sqlite3CompareAffinity(), sqlite3ExprNeedsNoAffinityChange(), sqlite3VectorFieldSubexpr(), and SQLITE_AFF_BLOB.

◆ updateVirtualTable()

static void updateVirtualTable ( Parse * pParse,
SrcList * pSrc,
Table * pTab,
ExprList * pChanges,
Expr * pRowidExpr,
int * aXRef,
Expr * pWhere,
int onError )
static

Definition at line 138751 of file sqlite3.c.

138766 {
138767 Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */
138768 int ephemTab; /* Table holding the result of the SELECT */
138769 int i; /* Loop counter */
138770 sqlite3 *db = pParse->db; /* Database connection */
138771 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
138772 WhereInfo *pWInfo = 0;
138773 int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */
138774 int regArg; /* First register in VUpdate arg array */
138775 int regRec; /* Register in which to assemble record */
138776 int regRowid; /* Register for ephem table rowid */
138777 int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
138778 int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */
138779 int eOnePass; /* True to use onepass strategy */
138780 int addr; /* Address of OP_OpenEphemeral */
138781
138782 /* Allocate nArg registers in which to gather the arguments for VUpdate. Then
138783 ** create and open the ephemeral table in which the records created from
138784 ** these arguments will be temporarily stored. */
138785 assert( v );
138786 ephemTab = pParse->nTab++;
138787 addr= sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, nArg);
138788 regArg = pParse->nMem + 1;
138789 pParse->nMem += nArg;
138790 if( pSrc->nSrc>1 ){
138791 Expr *pRow;
138792 ExprList *pList;
138793 if( pRowid ){
138794 pRow = sqlite3ExprDup(db, pRowid, 0);
138795 }else{
138796 pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
138797 }
138798 pList = sqlite3ExprListAppend(pParse, 0, pRow);
138799
138800 for(i=0; i<pTab->nCol; i++){
138801 if( aXRef[i]>=0 ){
138802 pList = sqlite3ExprListAppend(pParse, pList,
138803 sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0)
138804 );
138805 }else{
138806 pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
138807 }
138808 }
138809
138810 updateFromSelect(pParse, ephemTab, 0, pList, pSrc, pWhere, 0, 0);
138811 sqlite3ExprListDelete(db, pList);
138812 eOnePass = ONEPASS_OFF;
138813 }else{
138814 regRec = ++pParse->nMem;
138815 regRowid = ++pParse->nMem;
138816
138817 /* Start scanning the virtual table */
138818 pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0);
138819 if( pWInfo==0 ) return;
138820
138821 /* Populate the argument registers. */
138822 for(i=0; i<pTab->nCol; i++){
138823 assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
138824 if( aXRef[i]>=0 ){
138825 sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
138826 }else{
138827 sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
138828 sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG);/* For sqlite3_vtab_nochange() */
138829 }
138830 }
138831 if( HasRowid(pTab) ){
138832 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
138833 if( pRowid ){
138834 sqlite3ExprCode(pParse, pRowid, regArg+1);
138835 }else{
138836 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);
138837 }
138838 }else{
138839 Index *pPk; /* PRIMARY KEY index */
138840 i16 iPk; /* PRIMARY KEY column */
138841 pPk = sqlite3PrimaryKeyIndex(pTab);
138842 assert( pPk!=0 );
138843 assert( pPk->nKeyCol==1 );
138844 iPk = pPk->aiColumn[0];
138845 sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, iPk, regArg);
138846 sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1);
138847 }
138848
138849 eOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);
138850
138851 /* There is no ONEPASS_MULTI on virtual tables */
138852 assert( eOnePass==ONEPASS_OFF || eOnePass==ONEPASS_SINGLE );
138853
138854 if( eOnePass ){
138855 /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
138856 ** above. */
138857 sqlite3VdbeChangeToNoop(v, addr);
138858 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
138859 }else{
138860 /* Create a record from the argument register contents and insert it into
138861 ** the ephemeral table. */
138862 sqlite3MultiWrite(pParse);
138863 sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);
138864#if defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_NULL_TRIM)
138865 /* Signal an assert() within OP_MakeRecord that it is allowed to
138866 ** accept no-change records with serial_type 10 */
138868#endif
138869 sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);
138870 sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);
138871 }
138872 }
138873
138874
138875 if( eOnePass==ONEPASS_OFF ){
138876 /* End the virtual table scan */
138877 if( pSrc->nSrc==1 ){
138878 sqlite3WhereEnd(pWInfo);
138879 }
138880
138881 /* Begin scannning through the ephemeral table. */
138882 addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v);
138883
138884 /* Extract arguments from the current row of the ephemeral table and
138885 ** invoke the VUpdate method. */
138886 for(i=0; i<nArg; i++){
138887 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i, regArg+i);
138888 }
138889 }
138890 sqlite3VtabMakeWritable(pParse, pTab);
138891 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, nArg, regArg, pVTab, P4_VTAB);
138892 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
138893 sqlite3MayAbort(pParse);
138894
138895 /* End of the ephemeral table scan. Or, if using the onepass strategy,
138896 ** jump to here if the scan visited zero rows. */
138897 if( eOnePass==ONEPASS_OFF ){
138898 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);

References ExprList::a, SrcList::a, Table::aCol, Index::aiColumn, COLFLAG_GENERATED, Column::colFlags, Parse::db, exprRowColumn(), HasRowid, SrcList::SrcList_item::iCursor, Table::nCol, Index::nKeyCol, Parse::nMem, SrcList::nSrc, Parse::nTab, OE_Abort, OE_Default, ONEPASS_OFF, ONEPASS_SINGLE, OP_Close, OP_Column, OP_Insert, OP_MakeRecord, OP_NewRowid, OP_Next, OP_OpenEphemeral, OP_Rewind, OP_Rowid, OP_SCopy, OP_VColumn, OP_VUpdate, OPFLAG_NOCHNG, OPFLAG_NOCHNG_MAGIC, P4_VTAB, ExprList::ExprList_item::pExpr, Parse::pVdbe, sqlite3ExprCode(), sqlite3ExprDup(), sqlite3ExprListAppend(), sqlite3ExprListDelete(), sqlite3GetVTable(), sqlite3MayAbort(), sqlite3MultiWrite(), sqlite3PExpr(), sqlite3PrimaryKeyIndex(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), sqlite3VdbeChangeToNoop(), sqlite3VdbeJumpHere(), sqlite3VtabMakeWritable(), sqlite3WhereBegin(), sqlite3WhereEnd(), sqlite3WhereOkOnePass(), TK_ROW, updateFromSelect(), VdbeCoverage, and WHERE_ONEPASS_DESIRED.

Referenced by sqlite3Update().

◆ upperFunc()

static void upperFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 117500 of file sqlite3.c.

117506 {
117507 char *z1;
117508 const char *z2;
117509 int i, n;
117510 UNUSED_PARAMETER(argc);
117511 z2 = (char*)sqlite3_value_text(argv[0]);
117512 n = sqlite3_value_bytes(argv[0]);
117513 /* Verify that the call to _bytes() does not invalidate the _text() pointer */
117514 assert( z2==(char*)sqlite3_value_text(argv[0]) );
117515 if( z2 ){
117516 z1 = contextMalloc(context, ((i64)n)+1);
117517 if( z1 ){
117518 for(i=0; i<n; i++){

Referenced by sqlite3RegisterBuiltinFunctions().

◆ uriParameter()

static const char * uriParameter ( const char * zFilename,
const char * zParam )
static

Definition at line 164035 of file sqlite3.c.

164041 {
164042 zFilename += sqlite3Strlen30(zFilename) + 1;
164043 while( zFilename[0] ){
164044 int x = strcmp(zFilename, zParam);

◆ validJulianDay()

static int validJulianDay ( sqlite3_int64 iJD)
static

Definition at line 22121 of file sqlite3.c.

References INT_464269060799999.

Referenced by isDate().

◆ valueBytes()

static SQLITE_NOINLINE int valueBytes ( sqlite3_value * pVal,
u8 enc )
static

Definition at line 77711 of file sqlite3.c.

◆ valueFromExpr()

static int valueFromExpr ( sqlite3 * db,
Expr * pExpr,
u8 enc,
u8 affinity,
sqlite3_value ** ppVal,
struct ValueNewStat4Ctx * pCtx )
static

Definition at line 77303 of file sqlite3.c.

77316 {
77317 int op;
77318 char *zVal = 0;
77319 sqlite3_value *pVal = 0;
77320 int negInt = 1;
77321 const char *zNeg = "";
77322 int rc = SQLITE_OK;
77323
77324 assert( pExpr!=0 );
77325 while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
77326#if defined(SQLITE_ENABLE_STAT4)
77327 if( op==TK_REGISTER ) op = pExpr->op2;
77328#else
77329 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
77330#endif
77331
77332 /* Compressed expressions only appear when parsing the DEFAULT clause
77333 ** on a table column definition, and hence only when pCtx==0. This
77334 ** check ensures that an EP_TokenOnly expression is never passed down
77335 ** into valueFromFunction(). */
77336 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
77337
77338 if( op==TK_CAST ){
77339 u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
77340 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
77341 testcase( rc!=SQLITE_OK );
77342 if( *ppVal ){
77343 sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
77344 sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
77345 }
77346 return rc;
77347 }
77348
77349 /* Handle negative integers in a single step. This is needed in the
77350 ** case when the value is -9223372036854775808.
77351 */
77352 if( op==TK_UMINUS
77353 && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){
77354 pExpr = pExpr->pLeft;
77355 op = pExpr->op;
77356 negInt = -1;
77357 zNeg = "-";
77358 }
77359
77360 if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
77361 pVal = valueNew(db, pCtx);
77362 if( pVal==0 ) goto no_mem;
77363 if( ExprHasProperty(pExpr, EP_IntValue) ){
77364 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
77365 }else{
77366 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
77367 if( zVal==0 ) goto no_mem;
77369 }
77370 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_BLOB ){
77372 }else{
77373 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
77374 }
77375 assert( (pVal->flags & MEM_IntReal)==0 );
77376 if( pVal->flags & (MEM_Int|MEM_IntReal|MEM_Real) ){
77377 testcase( pVal->flags & MEM_Int );
77378 testcase( pVal->flags & MEM_Real );
77379 pVal->flags &= ~MEM_Str;
77380 }
77381 if( enc!=SQLITE_UTF8 ){
77382 rc = sqlite3VdbeChangeEncoding(pVal, enc);
77383 }
77384 }else if( op==TK_UMINUS ) {
77385 /* This branch happens for multiple negative signs. Ex: -(-5) */
77386 if( SQLITE_OK==valueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal,pCtx)
77387 && pVal!=0
77388 ){
77390 if( pVal->flags & MEM_Real ){
77391 pVal->u.r = -pVal->u.r;
77392 }else if( pVal->u.i==SMALLEST_INT64 ){
77393#ifndef SQLITE_OMIT_FLOATING_POINT
77394 pVal->u.r = -(double)SMALLEST_INT64;
77395#else
77396 pVal->u.r = LARGEST_INT64;
77397#endif
77398 MemSetTypeFlag(pVal, MEM_Real);
77399 }else{
77400 pVal->u.i = -pVal->u.i;
77401 }
77402 sqlite3ValueApplyAffinity(pVal, affinity, enc);
77403 }
77404 }else if( op==TK_NULL ){
77405 pVal = valueNew(db, pCtx);
77406 if( pVal==0 ) goto no_mem;
77408 }
77409#ifndef SQLITE_OMIT_BLOB_LITERAL
77410 else if( op==TK_BLOB ){
77411 int nVal;
77412 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
77413 assert( pExpr->u.zToken[1]=='\'' );
77414 pVal = valueNew(db, pCtx);
77415 if( !pVal ) goto no_mem;
77416 zVal = &pExpr->u.zToken[2];
77417 nVal = sqlite3Strlen30(zVal)-1;
77418 assert( zVal[nVal]=='\'' );
77419 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
77420 0, SQLITE_DYNAMIC);
77421 }
77422#endif
77423#ifdef SQLITE_ENABLE_STAT4
77424 else if( op==TK_FUNCTION && pCtx!=0 ){
77425 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
77426 }
77427#endif
77428 else if( op==TK_TRUEFALSE ){
77429 pVal = valueNew(db, pCtx);
77430 if( pVal ){
77431 pVal->flags = MEM_Int;
77432 pVal->u.i = pExpr->u.zToken[4]==0;
77433 }
77434 }
77435
77436 *ppVal = pVal;
77437 return rc;
77438
77439no_mem:
77440#ifdef SQLITE_ENABLE_STAT4
77441 if( pCtx==0 || pCtx->pParse->nErr==0 )
77442#endif
77443 sqlite3OomFault(db);
77444 sqlite3DbFree(db, zVal);
77445 assert( *ppVal==0 );
77446#ifdef SQLITE_ENABLE_STAT4
static int valueFromExpr(sqlite3 *db, Expr *pExpr, u8 enc, u8 affinity, sqlite3_value **ppVal, struct ValueNewStat4Ctx *pCtx)
Definition sqlite3.c:77303
static sqlite3_value * valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p)
Definition sqlite3.c:77147
#define valueFromFunction(a, b, c, d, e, f)
Definition sqlite3.c:77290

References EP_IntValue, EP_TokenOnly, ExprHasProperty, Expr::flags, sqlite3_value::flags, sqlite3_value::MemValue::i, Expr::iValue, LARGEST_INT64, MEM_Int, MEM_IntReal, MEM_Real, MemSetTypeFlag, Parse::nErr, NEVER, Expr::op, Expr::op2, Expr::pLeft, ValueNewStat4Ctx::pParse, sqlite3_value::MemValue::r, SMALLEST_INT64, sqlite3AffinityType(), sqlite3DbFree(), sqlite3HexToBlob(), sqlite3MPrintf(), sqlite3OomFault(), sqlite3Strlen30(), sqlite3ValueApplyAffinity(), sqlite3ValueFree(), sqlite3ValueSetStr(), sqlite3VdbeChangeEncoding(), sqlite3VdbeMemCast(), sqlite3VdbeMemNumerify(), sqlite3VdbeMemSetInt64(), sqlite3VdbeMemSetNull(), sqlite3VdbeMemSetStr(), SQLITE_AFF_BLOB, SQLITE_AFF_NUMERIC, SQLITE_DYNAMIC, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_UTF8, testcase, TK_BLOB, TK_CAST, TK_FLOAT, TK_FUNCTION, TK_INTEGER, TK_NULL, TK_REGISTER, TK_SPAN, TK_STRING, TK_TRUEFALSE, TK_UMINUS, TK_UPLUS, Expr::u, sqlite3_value::u, valueFromExpr(), valueFromFunction, valueNew(), and Expr::zToken.

Referenced by sqlite3ValueFromExpr(), and valueFromExpr().

◆ valueNew()

static sqlite3_value * valueNew ( sqlite3 * db,
struct ValueNewStat4Ctx * p )
static

Definition at line 77147 of file sqlite3.c.

77153 {
77154#ifdef SQLITE_ENABLE_STAT4
77155 if( p ){
77156 UnpackedRecord *pRec = p->ppRec[0];
77157
77158 if( pRec==0 ){
77159 Index *pIdx = p->pIdx; /* Index being probed */
77160 int nByte; /* Bytes of space to allocate */
77161 int i; /* Counter variable */
77162 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
77163
77164 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
77165 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
77166 if( pRec ){
77167 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
77168 if( pRec->pKeyInfo ){
77169 assert( pRec->pKeyInfo->nAllField==nCol );
77170 assert( pRec->pKeyInfo->enc==ENC(db) );
77171 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
77172 for(i=0; i<nCol; i++){
77173 pRec->aMem[i].flags = MEM_Null;
77174 pRec->aMem[i].db = db;
77175 }
77176 }else{
77177 sqlite3DbFreeNN(db, pRec);
77178 pRec = 0;
77179 }
77180 }
77181 if( pRec==0 ) return 0;
77182 p->ppRec[0] = pRec;
77183 }
77184
77185 pRec->nField = p->iVal+1;
77186 return &pRec->aMem[p->iVal];
UnpackedRecord ** ppRec
Definition sqlite3.c:77132

References UnpackedRecord::aMem, sqlite3_value::db, ENC, KeyInfo::enc, sqlite3_value::flags, ValueNewStat4Ctx::iVal, MEM_Null, KeyInfo::nAllField, Index::nColumn, UnpackedRecord::nField, ValueNewStat4Ctx::pIdx, UnpackedRecord::pKeyInfo, ValueNewStat4Ctx::pParse, ValueNewStat4Ctx::ppRec, ROUND8, sqlite3DbFreeNN(), sqlite3DbMallocZero(), sqlite3KeyInfoOfIndex(), sqlite3ValueNew(), and UNUSED_PARAMETER.

Referenced by valueFromExpr().

◆ valueToText()

static SQLITE_NOINLINE const void * valueToText ( sqlite3_value * pVal,
u8 enc )
static

Definition at line 77055 of file sqlite3.c.

77061 {
77062 assert( pVal!=0 );
77063 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
77064 assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
77065 assert( !sqlite3VdbeMemIsRowSet(pVal) );
77066 assert( (pVal->flags & (MEM_Null))==0 );
77067 if( pVal->flags & (MEM_Blob|MEM_Str) ){
77068 if( ExpandBlob(pVal) ) return 0;
77069 pVal->flags |= MEM_Str;
77070 if( pVal->enc != (enc & ~SQLITE_UTF16_ALIGNED) ){
77072 }
77073 if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
77074 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
77076 return 0;
77077 }
77078 }
77079 sqlite3VdbeMemNulTerminate(pVal); /* IMP: R-31275-44060 */
77080 }else{
77081 sqlite3VdbeMemStringify(pVal, enc, 0);
77082 assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
77083 }
77084 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
77085 || pVal->db->mallocFailed );
77086 if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){

References sqlite3_value::db, sqlite3_value::enc, ExpandBlob, sqlite3_value::flags, sqlite3::mallocFailed, MEM_Blob, MEM_Ephem, MEM_Null, MEM_Static, MEM_Str, sqlite3::mutex, sqlite3_mutex_held(), sqlite3VdbeChangeEncoding(), sqlite3VdbeMemMakeWriteable(), sqlite3VdbeMemNulTerminate(), sqlite3VdbeMemStringify(), SQLITE_OK, SQLITE_PTR_TO_INT, SQLITE_UTF16_ALIGNED, and sqlite3_value::z.

Referenced by sqlite3ValueBytes().

◆ vdbeChangeP4Full()

static void SQLITE_NOINLINE vdbeChangeP4Full ( Vdbe * p,
Op * pOp,
const char * zP4,
int n )
static

Definition at line 79009 of file sqlite3.c.

79020 {
79021 if( pOp->p4type ){
79022 freeP4(p->db, pOp->p4type, pOp->p4.p);
79023 pOp->p4type = 0;
79024 pOp->p4.p = 0;
79025 }
79026 if( n<0 ){
79027 sqlite3VdbeChangeP4(p, (int)(pOp - p->aOp), zP4, n);

References Vdbe::aOp, Vdbe::db, freeP4(), VdbeOp::p4union::p, VdbeOp::p4, VdbeOp::p4type, and sqlite3VdbeChangeP4().

◆ vdbeCloseStatement()

static SQLITE_NOINLINE int vdbeCloseStatement ( Vdbe * p,
int eOp )
static

Definition at line 80663 of file sqlite3.c.

80669 {
80670 sqlite3 *const db = p->db;
80671 int rc = SQLITE_OK;
80672 int i;
80673 const int iSavepoint = p->iStatement-1;
80674
80675 assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
80676 assert( db->nStatement>0 );
80677 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
80678
80679 for(i=0; i<db->nDb; i++){
80680 int rc2 = SQLITE_OK;
80681 Btree *pBt = db->aDb[i].pBt;
80682 if( pBt ){
80683 if( eOp==SAVEPOINT_ROLLBACK ){
80684 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
80685 }
80686 if( rc2==SQLITE_OK ){
80687 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
80688 }
80689 if( rc==SQLITE_OK ){
80690 rc = rc2;
80691 }
80692 }
80693 }
80694 db->nStatement--;
80695 p->iStatement = 0;
80696
80697 if( rc==SQLITE_OK ){
80698 if( eOp==SAVEPOINT_ROLLBACK ){
80699 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
80700 }
80701 if( rc==SQLITE_OK ){
80702 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
80703 }
80704 }
80705
80706 /* If the statement transaction is being rolled back, also restore the
80707 ** database handles deferred constraint counter to the value it had when
80708 ** the statement transaction was opened. */

References sqlite3::aDb, Vdbe::db, Vdbe::iStatement, sqlite3::nDb, sqlite3::nSavepoint, sqlite3::nStatement, Db::pBt, SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, sqlite3BtreeSavepoint(), sqlite3VtabSavepoint(), and SQLITE_OK.

◆ vdbeClrCopy()

static SQLITE_NOINLINE void vdbeClrCopy ( Mem * pTo,
const Mem * pFrom,
int eType )
static

Definition at line 76822 of file sqlite3.c.

◆ vdbeCommit()

static int vdbeCommit ( sqlite3 * db,
Vdbe * p )
static

Definition at line 80367 of file sqlite3.c.

80373 {
80374 int i;
80375 int nTrans = 0; /* Number of databases with an active write-transaction
80376 ** that are candidates for a two-phase commit using a
80377 ** super-journal */
80378 int rc = SQLITE_OK;
80379 int needXcommit = 0;
80380
80381#ifdef SQLITE_OMIT_VIRTUALTABLE
80382 /* With this option, sqlite3VtabSync() is defined to be simply
80383 ** SQLITE_OK so p is not used.
80384 */
80386#endif
80387
80388 /* Before doing anything else, call the xSync() callback for any
80389 ** virtual module tables written in this transaction. This has to
80390 ** be done before determining whether a super-journal file is
80391 ** required, as an xSync() callback may add an attached database
80392 ** to the transaction.
80393 */
80394 rc = sqlite3VtabSync(db, p);
80395
80396 /* This loop determines (a) if the commit hook should be invoked and
80397 ** (b) how many database files have open write transactions, not
80398 ** including the temp database. (b) is important because if more than
80399 ** one database file has an open write transaction, a super-journal
80400 ** file is required for an atomic commit.
80401 */
80402 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80403 Btree *pBt = db->aDb[i].pBt;
80404 if( sqlite3BtreeIsInTrans(pBt) ){
80405 /* Whether or not a database might need a super-journal depends upon
80406 ** its journal mode (among other things). This matrix determines which
80407 ** journal modes use a super-journal and which do not */
80408 static const u8 aMJNeeded[] = {
80409 /* DELETE */ 1,
80410 /* PERSIST */ 1,
80411 /* OFF */ 0,
80412 /* TRUNCATE */ 1,
80413 /* MEMORY */ 0,
80414 /* WAL */ 0
80415 };
80416 Pager *pPager; /* Pager associated with pBt */
80417 needXcommit = 1;
80418 sqlite3BtreeEnter(pBt);
80419 pPager = sqlite3BtreePager(pBt);
80421 && aMJNeeded[sqlite3PagerGetJournalMode(pPager)]
80422 && sqlite3PagerIsMemdb(pPager)==0
80423 ){
80424 assert( i!=1 );
80425 nTrans++;
80426 }
80427 rc = sqlite3PagerExclusiveLock(pPager);
80428 sqlite3BtreeLeave(pBt);
80429 }
80430 }
80431 if( rc!=SQLITE_OK ){
80432 return rc;
80433 }
80434
80435 /* If there are any write-transactions at all, invoke the commit hook */
80436 if( needXcommit && db->xCommitCallback ){
80437 rc = db->xCommitCallback(db->pCommitArg);
80438 if( rc ){
80440 }
80441 }
80442
80443 /* The simple case - no more than one database file (not counting the
80444 ** TEMP database) has a transaction active. There is no need for the
80445 ** super-journal.
80446 **
80447 ** If the return value of sqlite3BtreeGetFilename() is a zero length
80448 ** string, it means the main database is :memory: or a temp file. In
80449 ** that case we do not support atomic multi-file commits, so use the
80450 ** simple case then too.
80451 */
80453 || nTrans<=1
80454 ){
80455 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80456 Btree *pBt = db->aDb[i].pBt;
80457 if( pBt ){
80458 rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
80459 }
80460 }
80461
80462 /* Do the commit only if all databases successfully complete phase 1.
80463 ** If one of the BtreeCommitPhaseOne() calls fails, this indicates an
80464 ** IO error while deleting or truncating a journal file. It is unlikely,
80465 ** but could happen. In this case abandon processing and return the error.
80466 */
80467 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80468 Btree *pBt = db->aDb[i].pBt;
80469 if( pBt ){
80470 rc = sqlite3BtreeCommitPhaseTwo(pBt, 0);
80471 }
80472 }
80473 if( rc==SQLITE_OK ){
80475 }
80476 }
80477
80478 /* The complex case - There is a multi-file write-transaction active.
80479 ** This requires a super-journal file to ensure the transaction is
80480 ** committed atomically.
80481 */
80482#ifndef SQLITE_OMIT_DISKIO
80483 else{
80484 sqlite3_vfs *pVfs = db->pVfs;
80485 char *zSuper = 0; /* File-name for the super-journal */
80486 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
80487 sqlite3_file *pSuperJrnl = 0;
80488 i64 offset = 0;
80489 int res;
80490 int retryCount = 0;
80491 int nMainFile;
80492
80493 /* Select a super-journal file name */
80494 nMainFile = sqlite3Strlen30(zMainFile);
80495 zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
80496 if( zSuper==0 ) return SQLITE_NOMEM_BKPT;
80497 zSuper += 4;
80498 do {
80499 u32 iRandom;
80500 if( retryCount ){
80501 if( retryCount>100 ){
80502 sqlite3_log(SQLITE_FULL, "MJ delete: %s", zSuper);
80503 sqlite3OsDelete(pVfs, zSuper, 0);
80504 break;
80505 }else if( retryCount==1 ){
80506 sqlite3_log(SQLITE_FULL, "MJ collide: %s", zSuper);
80507 }
80508 }
80509 retryCount++;
80510 sqlite3_randomness(sizeof(iRandom), &iRandom);
80511 sqlite3_snprintf(13, &zSuper[nMainFile], "-mj%06X9%02X",
80512 (iRandom>>8)&0xffffff, iRandom&0xff);
80513 /* The antipenultimate character of the super-journal name must
80514 ** be "9" to avoid name collisions when using 8+3 filenames. */
80515 assert( zSuper[sqlite3Strlen30(zSuper)-3]=='9' );
80516 sqlite3FileSuffix3(zMainFile, zSuper);
80517 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
80518 }while( rc==SQLITE_OK && res );
80519 if( rc==SQLITE_OK ){
80520 /* Open the super-journal. */
80521 rc = sqlite3OsOpenMalloc(pVfs, zSuper, &pSuperJrnl,
80524 );
80525 }
80526 if( rc!=SQLITE_OK ){
80527 sqlite3DbFree(db, zSuper-4);
80528 return rc;
80529 }
80530
80531 /* Write the name of each database file in the transaction into the new
80532 ** super-journal file. If an error occurs at this point close
80533 ** and delete the super-journal file. All the individual journal files
80534 ** still have 'null' as the super-journal pointer, so they will roll
80535 ** back independently if a failure occurs.
80536 */
80537 for(i=0; i<db->nDb; i++){
80538 Btree *pBt = db->aDb[i].pBt;
80539 if( sqlite3BtreeIsInTrans(pBt) ){
80540 char const *zFile = sqlite3BtreeGetJournalname(pBt);
80541 if( zFile==0 ){
80542 continue; /* Ignore TEMP and :memory: databases */
80543 }
80544 assert( zFile[0]!=0 );
80545 rc = sqlite3OsWrite(pSuperJrnl, zFile, sqlite3Strlen30(zFile)+1,offset);
80546 offset += sqlite3Strlen30(zFile)+1;
80547 if( rc!=SQLITE_OK ){
80548 sqlite3OsCloseFree(pSuperJrnl);
80549 sqlite3OsDelete(pVfs, zSuper, 0);
80550 sqlite3DbFree(db, zSuper-4);
80551 return rc;
80552 }
80553 }
80554 }
80555
80556 /* Sync the super-journal file. If the IOCAP_SEQUENTIAL device
80557 ** flag is set this is not required.
80558 */
80560 && SQLITE_OK!=(rc = sqlite3OsSync(pSuperJrnl, SQLITE_SYNC_NORMAL))
80561 ){
80562 sqlite3OsCloseFree(pSuperJrnl);
80563 sqlite3OsDelete(pVfs, zSuper, 0);
80564 sqlite3DbFree(db, zSuper-4);
80565 return rc;
80566 }
80567
80568 /* Sync all the db files involved in the transaction. The same call
80569 ** sets the super-journal pointer in each individual journal. If
80570 ** an error occurs here, do not delete the super-journal file.
80571 **
80572 ** If the error occurs during the first call to
80573 ** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
80574 ** super-journal file will be orphaned. But we cannot delete it,
80575 ** in case the super-journal file name was written into the journal
80576 ** file before the failure occurred.
80577 */
80578 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80579 Btree *pBt = db->aDb[i].pBt;
80580 if( pBt ){
80581 rc = sqlite3BtreeCommitPhaseOne(pBt, zSuper);
80582 }
80583 }
80584 sqlite3OsCloseFree(pSuperJrnl);
80585 assert( rc!=SQLITE_BUSY );
80586 if( rc!=SQLITE_OK ){
80587 sqlite3DbFree(db, zSuper-4);
80588 return rc;
80589 }
80590
80591 /* Delete the super-journal file. This commits the transaction. After
80592 ** doing this the directory is synced again before any individual
80593 ** transaction files are deleted.
80594 */
80595 rc = sqlite3OsDelete(pVfs, zSuper, 1);
80596 sqlite3DbFree(db, zSuper-4);
80597 zSuper = 0;
80598 if( rc ){
80599 return rc;
80600 }
80601
80602 /* All files and directories have already been synced, so the following
80603 ** calls to sqlite3BtreeCommitPhaseTwo() are only closing files and
80604 ** deleting or truncating journals. If something goes wrong while
80605 ** this is happening we don't really care. The integrity of the
80606 ** transaction is already guaranteed, but some stray 'cold' journals
80607 ** may be lying around. Returning an error code won't help matters.
80608 */
80611 for(i=0; i<db->nDb; i++){
80612 Btree *pBt = db->aDb[i].pBt;
80613 if( pBt ){
80615 }
80616 }
80619
SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int, int *)
Definition sqlite3.c:23256
SQLITE_PRIVATE const char * sqlite3BtreeGetJournalname(Btree *)
Definition sqlite3.c:74784
SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *)
Definition sqlite3.c:23278
#define SQLITE_CONSTRAINT_COMMITHOOK
Definition sqlite3.c:1577
SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db)
Definition sqlite3.c:140551
SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *)
Definition sqlite3.c:140520
void * pCommitArg
Definition sqlite3.c:16880
int(* xCommitCallback)(void *)
Definition sqlite3.c:16881

References sqlite3::aDb, disable_simulated_io_errors, enable_simulated_io_errors, sqlite3::nDb, PAGER_SYNCHRONOUS_OFF, Db::pBt, sqlite3::pCommitArg, sqlite3::pVfs, Db::safety_level, sqlite3_log(), sqlite3_randomness(), sqlite3_snprintf(), sqlite3BeginBenignMalloc(), sqlite3BtreeCommitPhaseOne(), sqlite3BtreeCommitPhaseTwo(), sqlite3BtreeEnter(), sqlite3BtreeGetFilename(), sqlite3BtreeGetJournalname(), sqlite3BtreeIsInTrans(), sqlite3BtreeLeave(), sqlite3BtreePager(), sqlite3DbFree(), sqlite3EndBenignMalloc(), sqlite3FileSuffix3, sqlite3MPrintf(), sqlite3OsAccess(), sqlite3OsCloseFree(), sqlite3OsDelete(), sqlite3OsDeviceCharacteristics(), sqlite3OsOpenMalloc(), sqlite3OsSync(), sqlite3OsWrite(), sqlite3PagerExclusiveLock(), sqlite3PagerGetJournalMode(), sqlite3PagerIsMemdb(), sqlite3Strlen30(), sqlite3VtabCommit(), sqlite3VtabSync(), SQLITE_ACCESS_EXISTS, SQLITE_BUSY, SQLITE_CONSTRAINT_COMMITHOOK, SQLITE_FULL, SQLITE_IOCAP_SEQUENTIAL, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_EXCLUSIVE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SUPER_JOURNAL, SQLITE_SYNC_NORMAL, UNUSED_PARAMETER, and sqlite3::xCommitCallback.

Referenced by sqlite3VdbeHalt().

◆ vdbeCompareMemString()

static int vdbeCompareMemString ( const Mem * pMem1,
const Mem * pMem2,
const CollSeq * pColl,
u8 * prcErr )
static

Definition at line 81943 of file sqlite3.c.

81954 {
81955 if( pMem1->enc==pColl->enc ){
81956 /* The strings are already in the correct encoding. Call the
81957 ** comparison function directly */
81958 return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
81959 }else{
81960 int rc;
81961 const void *v1, *v2;
81962 Mem c1;
81963 Mem c2;
81964 sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null);
81965 sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null);
81968 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
81969 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
81970 if( (v1==0 || v2==0) ){
81971 if( prcErr ) *prcErr = SQLITE_NOMEM_BKPT;
81972 rc = 0;
81973 }else{
81974 rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2);

References sqlite3_value::db, CollSeq::enc, sqlite3_value::enc, MEM_Ephem, MEM_Null, sqlite3_value::n, CollSeq::pUser, sqlite3ValueText(), sqlite3VdbeMemInit(), sqlite3VdbeMemRelease(), sqlite3VdbeMemShallowCopy(), SQLITE_NOMEM_BKPT, CollSeq::xCmp, and sqlite3_value::z.

Referenced by sqlite3MemCompare(), and sqlite3VdbeRecordCompareWithSkip().

◆ vdbeFreeOpArray()

static void vdbeFreeOpArray ( sqlite3 * db,
Op * aOp,
int nOp )
static

Definition at line 78900 of file sqlite3.c.

78906 {
78907 if( aOp ){
78908 Op *pOp;
78909 for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
78910 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
78911#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
#define P4_FREE_IF_LE
Definition sqlite3.c:15513

References freeP4(), VdbeOp::p4union::p, VdbeOp::p4, P4_FREE_IF_LE, VdbeOp::p4type, sqlite3DbFree(), and sqlite3DbFreeNN().

Referenced by sqlite3VdbeClearObject().

◆ vdbeIncrBgPopulate()

static int vdbeIncrBgPopulate ( IncrMerger * pIncr)
static

Definition at line 95804 of file sqlite3.c.

Referenced by vdbeIncrSwap().

◆ vdbeIncrFree()

static void vdbeIncrFree ( IncrMerger * pIncr)
static

Definition at line 95087 of file sqlite3.c.

95093 {
95094 if( pIncr ){
95095#if SQLITE_MAX_WORKER_THREADS>0
95096 if( pIncr->bUseThread ){
95098 if( pIncr->aFile[0].pFd ) sqlite3OsCloseFree(pIncr->aFile[0].pFd);
95099 if( pIncr->aFile[1].pFd ) sqlite3OsCloseFree(pIncr->aFile[1].pFd);
static int vdbeSorterJoinThread(SortSubtask *pTask)
Definition sqlite3.c:94986
SorterFile aFile[2]
Definition sqlite3.c:94281
SortSubtask * pTask
Definition sqlite3.c:94275
int bUseThread
Definition sqlite3.c:94280
sqlite3_file * pFd
Definition sqlite3.c:94052

Referenced by vdbeSorterAddToTree().

◆ vdbeIncrMergerNew()

static int vdbeIncrMergerNew ( SortSubtask * pTask,
MergeEngine * pMerger,
IncrMerger ** ppOut )
static

Definition at line 95867 of file sqlite3.c.

95877 {
95878 int rc = SQLITE_OK;
95879 IncrMerger *pIncr = *ppOut = (IncrMerger*)
95880 (sqlite3FaultSim(100) ? 0 : sqlite3MallocZero(sizeof(*pIncr)));
95881 if( pIncr ){
95882 pIncr->pMerger = pMerger;
95883 pIncr->pTask = pTask;
95884 pIncr->mxSz = MAX(pTask->pSorter->mxKeysize+9,pTask->pSorter->mxPmaSize/2);
95885 pTask->file2.iEof += pIncr->mxSz;
MergeEngine * pMerger
Definition sqlite3.c:94276
SorterFile file2
Definition sqlite3.c:94182

References SortSubtask::file2, SorterFile::iEof, MAX, VdbeSorter::mxKeysize, VdbeSorter::mxPmaSize, IncrMerger::mxSz, IncrMerger::pMerger, SortSubtask::pSorter, IncrMerger::pTask, sqlite3FaultSim(), sqlite3MallocZero(), SQLITE_NOMEM_BKPT, SQLITE_OK, and vdbeMergeEngineFree().

Referenced by vdbeSorterAddToTree(), vdbeSorterMergeTreeBuild(), and vdbeSorterSetupMerge().

◆ vdbeIncrMergerSetThreads()

static void vdbeIncrMergerSetThreads ( IncrMerger * pIncr)
static

Definition at line 95891 of file sqlite3.c.

Referenced by vdbeSorterSetupMerge().

◆ vdbeIncrPopulate()

static int vdbeIncrPopulate ( IncrMerger * pIncr)
static

Definition at line 95752 of file sqlite3.c.

95758 {
95759 int rc = SQLITE_OK;
95760 int rc2;
95761 i64 iStart = pIncr->iStartOff;
95762 SorterFile *pOut = &pIncr->aFile[1];
95763 SortSubtask *pTask = pIncr->pTask;
95764 MergeEngine *pMerger = pIncr->pMerger;
95766 assert( pIncr->bEof==0 );
95767
95768 vdbeSorterPopulateDebug(pTask, "enter");
95769
95770 vdbePmaWriterInit(pOut->pFd, &writer, pTask->pSorter->pgsz, iStart);
95771 while( rc==SQLITE_OK ){
95772 int dummy;
95773 PmaReader *pReader = &pMerger->aReadr[ pMerger->aTree[1] ];
95774 int nKey = pReader->nKey;
95775 i64 iEof = writer.iWriteOff + writer.iBufEnd;
95776
95777 /* Check if the output file is full or if the input has been exhausted.
95778 ** In either case exit the loop. */
95779 if( pReader->pFd==0 ) break;
95780 if( (iEof + nKey + sqlite3VarintLen(nKey))>(iStart + pIncr->mxSz) ) break;
95781
95782 /* Write the next key to the output. */
95783 vdbePmaWriteVarint(&writer, nKey);
95784 vdbePmaWriteBlob(&writer, pReader->aKey, nKey);
95785 assert( pIncr->pMerger->pTask==pTask );
95786 rc = vdbeMergeEngineStep(pIncr->pMerger, &dummy);
95787 }
static int writer(lua_State *L, const void *b, size_t size, void *B)
#define vdbeSorterPopulateDebug(x, y)
Definition sqlite3.c:94978
static void vdbePmaWriteVarint(PmaWriter *p, u64 iVal)
Definition sqlite3.c:95400
static void vdbePmaWriteBlob(PmaWriter *p, u8 *pData, int nData)
Definition sqlite3.c:95348
static void vdbePmaWriterInit(sqlite3_file *pFd, PmaWriter *p, int nBuf, i64 iStart)
Definition sqlite3.c:95326
i64 iStartOff
Definition sqlite3.c:94277
PmaReader * aReadr
Definition sqlite3.c:94138
int * aTree
Definition sqlite3.c:94137
u8 * aKey
Definition sqlite3.c:94235

References IncrMerger::aFile, PmaReader::aKey, MergeEngine::aReadr, MergeEngine::aTree, IncrMerger::bEof, dummy, SorterFile::iEof, IncrMerger::iStartOff, IncrMerger::mxSz, PmaReader::nKey, SorterFile::pFd, PmaReader::pFd, VdbeSorter::pgsz, IncrMerger::pMerger, SortSubtask::pSorter, MergeEngine::pTask, IncrMerger::pTask, sqlite3VarintLen(), SQLITE_OK, vdbeMergeEngineStep(), vdbePmaWriteBlob(), vdbePmaWriterFinish(), vdbePmaWriterInit(), vdbePmaWriteVarint(), vdbeSorterPopulateDebug, and writer().

Referenced by vdbeIncrPopulateThread(), vdbeIncrSwap(), and vdbePmaReaderIncrMergeInit().

◆ vdbeIncrPopulateThread()

static void * vdbeIncrPopulateThread ( void * pCtx)
static

◆ vdbeIncrSwap()

static int vdbeIncrSwap ( IncrMerger * pIncr)
static

Definition at line 95828 of file sqlite3.c.

95834 {
95835 int rc = SQLITE_OK;
95836
95837#if SQLITE_MAX_WORKER_THREADS>0
95838 if( pIncr->bUseThread ){
95839 rc = vdbeSorterJoinThread(pIncr->pTask);
95840
95841 if( rc==SQLITE_OK ){
95842 SorterFile f0 = pIncr->aFile[0];
95843 pIncr->aFile[0] = pIncr->aFile[1];
95844 pIncr->aFile[1] = f0;
95845 }
95846
95847 if( rc==SQLITE_OK ){
95848 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
95849 pIncr->bEof = 1;
95850 }else{
95851 rc = vdbeIncrBgPopulate(pIncr);
95852 }
95853 }
95854 }else
95855#endif
95856 {
95857 rc = vdbeIncrPopulate(pIncr);
95858 pIncr->aFile[0] = pIncr->aFile[1];
95859 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
static int vdbeIncrPopulate(IncrMerger *pIncr)
Definition sqlite3.c:95752
static int vdbeIncrBgPopulate(IncrMerger *pIncr)
Definition sqlite3.c:95804

References IncrMerger::aFile, IncrMerger::bEof, IncrMerger::bUseThread, SorterFile::iEof, IncrMerger::iStartOff, IncrMerger::pTask, SQLITE_OK, vdbeIncrBgPopulate(), vdbeIncrPopulate(), and vdbeSorterJoinThread().

◆ vdbeLeave()

static SQLITE_NOINLINE void vdbeLeave ( Vdbe * p)
static

Definition at line 79542 of file sqlite3.c.

79548 {
79549 int i;
79550 sqlite3 *db;
79551 Db *aDb;
79552 int nDb;
79553 db = p->db;
79554 aDb = db->aDb;
79555 nDb = db->nDb;

References sqlite3::aDb, Vdbe::db, and sqlite3::nDb.

◆ vdbeMemAddTerminator()

static SQLITE_NOINLINE int vdbeMemAddTerminator ( Mem * pMem)
static

Definition at line 76137 of file sqlite3.c.

76143 {
76144 if( sqlite3VdbeMemGrow(pMem, pMem->n+3, 1) ){
76145 return SQLITE_NOMEM_BKPT;
76146 }

References sqlite3_value::flags, MEM_Term, sqlite3_value::n, sqlite3VdbeMemGrow(), SQLITE_NOMEM_BKPT, SQLITE_OK, and sqlite3_value::z.

Referenced by sqlite3VdbeMemMakeWriteable().

◆ vdbeMemClear()

static SQLITE_NOINLINE void vdbeMemClear ( Mem * p)
static

◆ vdbeMemClearExternAndSetNull()

static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull ( Mem * p)
static

◆ vdbeMemRenderNum()

static void vdbeMemRenderNum ( int sz,
char * zBuf,
Mem * p )
static

Definition at line 75928 of file sqlite3.c.

75934 {
75935 StrAccum acc;
75936 assert( p->flags & (MEM_Int|MEM_Real|MEM_IntReal) );
75937 assert( sz>22 );
75938 if( p->flags & MEM_Int ){
75939#if GCC_VERSION>=7000000
75940 /* Work-around for GCC bug
75941 ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */
75942 i64 x;
75943 assert( (p->flags&MEM_Int)*2==sizeof(x) );
75944 memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
75945 sqlite3Int64ToText(x, zBuf);
75946#else
75947 sqlite3Int64ToText(p->u.i, zBuf);
75948#endif
75949 }else{
75950 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);

References sqlite3_value::flags, sqlite3_value::MemValue::i, MEM_Int, MEM_IntReal, MEM_Real, sqlite3_str::mxAlloc, sqlite3_str::nChar, sqlite3_value::MemValue::r, sqlite3_str_appendf(), sqlite3Int64ToText(), sqlite3StrAccumInit(), sqlite3_value::u, and sqlite3_str::zText.

Referenced by sqlite3VdbeMemStringify().

◆ vdbeMergeEngineCompare()

static void vdbeMergeEngineCompare ( MergeEngine * pMerger,
int iOut )
static

Definition at line 95904 of file sqlite3.c.

95913 {
95914 int i1;
95915 int i2;
95916 int iRes;
95917 PmaReader *p1;
95918 PmaReader *p2;
95919
95920 assert( iOut<pMerger->nTree && iOut>0 );
95921
95922 if( iOut>=(pMerger->nTree/2) ){
95923 i1 = (iOut - pMerger->nTree/2) * 2;
95924 i2 = i1 + 1;
95925 }else{
95926 i1 = pMerger->aTree[iOut*2];
95927 i2 = pMerger->aTree[iOut*2+1];
95928 }
95929
95930 p1 = &pMerger->aReadr[i1];
95931 p2 = &pMerger->aReadr[i2];
95932
95933 if( p1->pFd==0 ){
95934 iRes = i2;
95935 }else if( p2->pFd==0 ){
95936 iRes = i1;
95937 }else{
95938 SortSubtask *pTask = pMerger->pTask;
95939 int bCached = 0;
95940 int res;
95941 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
95942 res = pTask->xCompare(
95943 pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
95944 );
95945 if( res<=0 ){
95946 iRes = i1;
95947 }else{
SorterCompare xCompare
Definition sqlite3.c:94180
UnpackedRecord * pUnpacked
Definition sqlite3.c:94177

References PmaReader::aKey, MergeEngine::aReadr, MergeEngine::aTree, PmaReader::nKey, MergeEngine::nTree, PmaReader::pFd, MergeEngine::pTask, SortSubtask::pUnpacked, and SortSubtask::xCompare.

Referenced by vdbeMergeEngineInit().

◆ vdbeMergeEngineFree()

static void vdbeMergeEngineFree ( MergeEngine * pMerger)
static

Definition at line 95073 of file sqlite3.c.

95079 {
95080 int i;
95081 if( pMerger ){

Referenced by vdbeIncrMergerNew(), vdbeMergeEngineLevel0(), vdbeSorterMergeTreeBuild(), and vdbeSorterSetupMerge().

◆ vdbeMergeEngineInit()

static int vdbeMergeEngineInit ( SortSubtask * pTask,
MergeEngine * pMerger,
int eMode )
static

Definition at line 95986 of file sqlite3.c.

95996 {
95997 int rc = SQLITE_OK; /* Return code */
95998 int i; /* For looping over PmaReader objects */
95999 int nTree; /* Number of subtrees to merge */
96000
96001 /* Failure to allocate the merge would have been detected prior to
96002 ** invoking this routine */
96003 assert( pMerger!=0 );
96004
96005 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
96006 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
96007
96008 /* Verify that the MergeEngine is assigned to a single thread */
96009 assert( pMerger->pTask==0 );
96010 pMerger->pTask = pTask;
96011
96012 nTree = pMerger->nTree;
96013 for(i=0; i<nTree; i++){
96014 if( SQLITE_MAX_WORKER_THREADS>0 && eMode==INCRINIT_ROOT ){
96015 /* PmaReaders should be normally initialized in order, as if they are
96016 ** reading from the same temp file this makes for more linear file IO.
96017 ** However, in the INCRINIT_ROOT case, if PmaReader aReadr[nTask-1] is
96018 ** in use it will block the vdbePmaReaderNext() call while it uses
96019 ** the main thread to fill its buffer. So calling PmaReaderNext()
96020 ** on this PmaReader before any of the multi-threaded PmaReaders takes
96021 ** better advantage of multi-processor hardware. */
96022 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
96023 }else{
96024 rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
96025 }
96026 if( rc!=SQLITE_OK ) return rc;
96027 }
static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode)
Definition sqlite3.c:96150
#define INCRINIT_ROOT
Definition sqlite3.c:95959
#define INCRINIT_NORMAL
Definition sqlite3.c:95957

References MergeEngine::aReadr, UnpackedRecord::errCode, INCRINIT_NORMAL, INCRINIT_ROOT, MergeEngine::nTree, MergeEngine::pTask, SortSubtask::pUnpacked, SQLITE_MAX_WORKER_THREADS, SQLITE_OK, vdbeMergeEngineCompare(), vdbePmaReaderIncrInit(), and vdbePmaReaderNext().

Referenced by vdbePmaReaderIncrMergeInit(), and vdbeSorterSetupMerge().

◆ vdbeMergeEngineLevel0()

static int vdbeMergeEngineLevel0 ( SortSubtask * pTask,
int nPMA,
i64 * piOffset,
MergeEngine ** ppOut )
static

Definition at line 96180 of file sqlite3.c.

96191 {
96192 MergeEngine *pNew; /* Merge engine to return */
96193 i64 iOff = *piOffset;
96194 int i;
96195 int rc = SQLITE_OK;
96196
96197 *ppOut = pNew = vdbeMergeEngineNew(nPMA);
96198 if( pNew==0 ) rc = SQLITE_NOMEM_BKPT;
96199
96200 for(i=0; i<nPMA && rc==SQLITE_OK; i++){
96201 i64 nDummy = 0;
96202 PmaReader *pReadr = &pNew->aReadr[i];
96203 rc = vdbePmaReaderInit(pTask, &pTask->file, iOff, pReadr, &nDummy);
96204 iOff = pReadr->iEof;
96205 }
96206
96207 if( rc!=SQLITE_OK ){
static MergeEngine * vdbeMergeEngineNew(int nReader)
Definition sqlite3.c:95050
static int vdbePmaReaderInit(SortSubtask *pTask, SorterFile *pFile, i64 iStart, PmaReader *pReadr, i64 *pnByte)
Definition sqlite3.c:94602
SorterFile file
Definition sqlite3.c:94181

References MergeEngine::aReadr, SortSubtask::file, PmaReader::iEof, SQLITE_NOMEM_BKPT, SQLITE_OK, vdbeMergeEngineFree(), vdbeMergeEngineNew(), and vdbePmaReaderInit().

Referenced by vdbeSorterMergeTreeBuild().

◆ vdbeMergeEngineNew()

static MergeEngine * vdbeMergeEngineNew ( int nReader)
static

Definition at line 95050 of file sqlite3.c.

95056 {
95057 int N = 2; /* Smallest power of two >= nReader */
95058 int nByte; /* Total bytes of space to allocate */
95059 MergeEngine *pNew; /* Pointer to allocated object to return */
95060
95061 assert( nReader<=SORTER_MAX_MERGE_COUNT );
95062
95063 while( N<nReader ) N += N;
95064 nByte = sizeof(MergeEngine) + N * (sizeof(int) + sizeof(PmaReader));
95065
95066 pNew = sqlite3FaultSim(100) ? 0 : (MergeEngine*)sqlite3MallocZero(nByte);
95067 if( pNew ){
95068 pNew->nTree = N;
struct PmaReader PmaReader
Definition sqlite3.c:94039
struct MergeEngine MergeEngine
Definition sqlite3.c:94038

References MergeEngine::aReadr, MergeEngine::aTree, MergeEngine::nTree, MergeEngine::pTask, SORTER_MAX_MERGE_COUNT, sqlite3FaultSim(), and sqlite3MallocZero().

Referenced by vdbeMergeEngineLevel0(), vdbeSorterAddToTree(), and vdbeSorterMergeTreeBuild().

◆ vdbeMergeEngineStep()

static int vdbeMergeEngineStep ( MergeEngine * pMerger,
int * pbEof )
static

Definition at line 95485 of file sqlite3.c.

95494 {
95495 int rc;
95496 int iPrev = pMerger->aTree[1];/* Index of PmaReader to advance */
95497 SortSubtask *pTask = pMerger->pTask;
95498
95499 /* Advance the current PmaReader */
95500 rc = vdbePmaReaderNext(&pMerger->aReadr[iPrev]);
95501
95502 /* Update contents of aTree[] */
95503 if( rc==SQLITE_OK ){
95504 int i; /* Index of aTree[] to recalculate */
95505 PmaReader *pReadr1; /* First PmaReader to compare */
95506 PmaReader *pReadr2; /* Second PmaReader to compare */
95507 int bCached = 0;
95508
95509 /* Find the first two PmaReaders to compare. The one that was just
95510 ** advanced (iPrev) and the one next to it in the array. */
95511 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
95512 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
95513
95514 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
95515 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
95516 int iRes;
95517 if( pReadr1->pFd==0 ){
95518 iRes = +1;
95519 }else if( pReadr2->pFd==0 ){
95520 iRes = -1;
95521 }else{
95522 iRes = pTask->xCompare(pTask, &bCached,
95523 pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
95524 );
95525 }
95526
95527 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
95528 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
95529 ** case there is no cache of pReadr2 in pTask->pUnpacked, so set
95530 ** pKey2 to point to the record belonging to pReadr2.
95531 **
95532 ** Alternatively, if pReadr2 contains the smaller of the two values,
95533 ** set aTree[i] to its index and update pReadr1. If vdbeSorterCompare()
95534 ** was actually called above, then pTask->pUnpacked now contains
95535 ** a value equivalent to pReadr2. So set pKey2 to NULL to prevent
95536 ** vdbeSorterCompare() from decoding pReadr2 again.
95537 **
95538 ** If the two values were equal, then the value from the oldest
95539 ** PMA should be considered smaller. The VdbeSorter.aReadr[] array
95540 ** is sorted from oldest to newest, so pReadr1 contains older values
95541 ** than pReadr2 iff (pReadr1<pReadr2). */
95542 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
95543 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
95544 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
95545 bCached = 0;
95546 }else{
95547 if( pReadr1->pFd ) bCached = 0;
95548 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
95549 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
95550 }

References PmaReader::aKey, MergeEngine::aReadr, MergeEngine::aTree, UnpackedRecord::errCode, PmaReader::nKey, MergeEngine::nTree, PmaReader::pFd, MergeEngine::pTask, SortSubtask::pUnpacked, SQLITE_OK, vdbePmaReaderNext(), and SortSubtask::xCompare.

Referenced by sqlite3VdbeSorterNext(), and vdbeIncrPopulate().

◆ vdbePmaReadBlob()

static int vdbePmaReadBlob ( PmaReader * p,
int nByte,
u8 ** ppOut )
static

Definition at line 94364 of file sqlite3.c.

94374 {
94375 int iBuf; /* Offset within buffer to read from */
94376 int nAvail; /* Bytes of data available in buffer */
94377
94378 if( p->aMap ){
94379 *ppOut = &p->aMap[p->iReadOff];
94380 p->iReadOff += nByte;
94381 return SQLITE_OK;
94382 }
94383
94384 assert( p->aBuffer );
94385
94386 /* If there is no more data to be read from the buffer, read the next
94387 ** p->nBuffer bytes of data from the file into it. Or, if there are less
94388 ** than p->nBuffer bytes remaining in the PMA, read all remaining data. */
94389 iBuf = p->iReadOff % p->nBuffer;
94390 if( iBuf==0 ){
94391 int nRead; /* Bytes to read from disk */
94392 int rc; /* sqlite3OsRead() return code */
94393
94394 /* Determine how many bytes of data to read. */
94395 if( (p->iEof - p->iReadOff) > (i64)p->nBuffer ){
94396 nRead = p->nBuffer;
94397 }else{
94398 nRead = (int)(p->iEof - p->iReadOff);
94399 }
94400 assert( nRead>0 );
94401
94402 /* Readr data from the file. Return early if an error occurs. */
94403 rc = sqlite3OsRead(p->pFd, p->aBuffer, nRead, p->iReadOff);
94404 assert( rc!=SQLITE_IOERR_SHORT_READ );
94405 if( rc!=SQLITE_OK ) return rc;
94406 }
94407 nAvail = p->nBuffer - iBuf;
94408
94409 if( nByte<=nAvail ){
94410 /* The requested data is available in the in-memory buffer. In this
94411 ** case there is no need to make a copy of the data, just return a
94412 ** pointer into the buffer to the caller. */
94413 *ppOut = &p->aBuffer[iBuf];
94414 p->iReadOff += nByte;
94415 }else{
94416 /* The requested data is not all available in the in-memory buffer.
94417 ** In this case, allocate space at p->aAlloc[] to copy the requested
94418 ** range into. Then return a copy of pointer p->aAlloc to the caller. */
94419 int nRem; /* Bytes remaining to copy */
94420
94421 /* Extend the p->aAlloc[] allocation if required. */
94422 if( p->nAlloc<nByte ){
94423 u8 *aNew;
94424 sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
94425 while( nByte>nNew ) nNew = nNew*2;
94426 aNew = sqlite3Realloc(p->aAlloc, nNew);
94427 if( !aNew ) return SQLITE_NOMEM_BKPT;
94428 p->nAlloc = nNew;
94429 p->aAlloc = aNew;
94430 }
94431
94432 /* Copy as much data as is available in the buffer into the start of
94433 ** p->aAlloc[]. */
94434 memcpy(p->aAlloc, &p->aBuffer[iBuf], nAvail);
94435 p->iReadOff += nAvail;
94436 nRem = nByte - nAvail;
94437
94438 /* The following loop copies up to p->nBuffer bytes per iteration into
94439 ** the p->aAlloc[] buffer. */
94440 while( nRem>0 ){
94441 int rc; /* vdbePmaReadBlob() return code */
94442 int nCopy; /* Number of bytes to copy */
94443 u8 *aNext; /* Pointer to buffer to copy data from */
94444
94445 nCopy = nRem;
94446 if( nRem>p->nBuffer ) nCopy = p->nBuffer;
94447 rc = vdbePmaReadBlob(p, nCopy, &aNext);
94448 if( rc!=SQLITE_OK ) return rc;
94449 assert( aNext!=p->aAlloc );
94450 memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy);
94451 nRem -= nCopy;
94452 }
static int vdbePmaReadBlob(PmaReader *p, int nByte, u8 **ppOut)
Definition sqlite3.c:94364
i64 iReadOff
Definition sqlite3.c:94229
int nBuffer
Definition sqlite3.c:94237
u8 * aBuffer
Definition sqlite3.c:94236
u8 * aMap
Definition sqlite3.c:94238
u8 * aAlloc
Definition sqlite3.c:94234

References PmaReader::aAlloc, PmaReader::aBuffer, PmaReader::aMap, PmaReader::iEof, PmaReader::iReadOff, MAX, PmaReader::nAlloc, PmaReader::nBuffer, PmaReader::pFd, sqlite3OsRead(), sqlite3Realloc(), SQLITE_IOERR_SHORT_READ, SQLITE_NOMEM_BKPT, SQLITE_OK, and vdbePmaReadBlob().

Referenced by vdbePmaReadBlob().

◆ vdbePmaReaderBgIncrInit()

static void * vdbePmaReaderBgIncrInit ( void * pCtx)
static

◆ vdbePmaReaderClear()

static void vdbePmaReaderClear ( PmaReader * pReadr)
static

Definition at line 94347 of file sqlite3.c.

94353 {

◆ vdbePmaReaderIncrInit()

static int vdbePmaReaderIncrInit ( PmaReader * pReadr,
int eMode )
static

Definition at line 96150 of file sqlite3.c.

96156 {
96157 IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
96158 int rc = SQLITE_OK; /* Return code */
96159 if( pIncr ){
96160#if SQLITE_MAX_WORKER_THREADS>0
96161 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
96162 if( pIncr->bUseThread ){
96163 void *pCtx = (void*)pReadr;
96165 }else
96166#endif
static int vdbeSorterCreateThread(SortSubtask *pTask, void *(*xTask)(void *), void *pIn)
Definition sqlite3.c:95007
static void * vdbePmaReaderBgIncrInit(void *pCtx)
Definition sqlite3.c:96129
#define INCRINIT_TASK
Definition sqlite3.c:95958
IncrMerger * pIncr
Definition sqlite3.c:94239

References IncrMerger::bUseThread, INCRINIT_TASK, PmaReader::pIncr, IncrMerger::pTask, SQLITE_OK, vdbePmaReaderBgIncrInit(), vdbePmaReaderIncrMergeInit(), and vdbeSorterCreateThread().

Referenced by vdbeMergeEngineInit(), and vdbeSorterSetupMerge().

◆ vdbePmaReaderIncrMergeInit()

static int vdbePmaReaderIncrMergeInit ( PmaReader * pReadr,
int eMode )
static

Definition at line 96062 of file sqlite3.c.

96068 {
96069 int rc = SQLITE_OK;
96070 IncrMerger *pIncr = pReadr->pIncr;
96071 SortSubtask *pTask = pIncr->pTask;
96072 sqlite3 *db = pTask->pSorter->db;
96073
96074 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
96075 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
96076
96077 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
96078
96079 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
96080 ** requires two temp files to itself, whereas a single-threaded object
96081 ** only requires a region of pTask->file2. */
96082 if( rc==SQLITE_OK ){
96083 int mxSz = pIncr->mxSz;
96084#if SQLITE_MAX_WORKER_THREADS>0
96085 if( pIncr->bUseThread ){
96086 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
96087 if( rc==SQLITE_OK ){
96088 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
96089 }
96090 }else
96091#endif
96092 /*if( !pIncr->bUseThread )*/{
96093 if( pTask->file2.pFd==0 ){
96094 assert( pTask->file2.iEof>0 );
96095 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
96096 pTask->file2.iEof = 0;
96097 }
96098 if( rc==SQLITE_OK ){
96099 pIncr->aFile[1].pFd = pTask->file2.pFd;
96100 pIncr->iStartOff = pTask->file2.iEof;
96101 pTask->file2.iEof += mxSz;
96102 }
96103 }
96104 }
96105
96106#if SQLITE_MAX_WORKER_THREADS>0
96107 if( rc==SQLITE_OK && pIncr->bUseThread ){
96108 /* Use the current thread to populate aFile[1], even though this
96109 ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
96110 ** then this function is already running in background thread
96111 ** pIncr->pTask->thread.
96112 **
96113 ** If this is the INCRINIT_ROOT object, then it is running in the
96114 ** main VDBE thread. But that is Ok, as that thread cannot return
96115 ** control to the VDBE or proceed with anything useful until the
96116 ** first results are ready from this merger object anyway.
96117 */
96118 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
96119 rc = vdbeIncrPopulate(pIncr);
96120 }
96121#endif
96122
static int vdbeSorterOpenTempFile(sqlite3 *db, i64 nExtend, sqlite3_file **ppFd)
Definition sqlite3.c:95178
static int vdbeMergeEngineInit(SortSubtask *pTask, MergeEngine *pMerger, int eMode)
Definition sqlite3.c:95986

References IncrMerger::aFile, IncrMerger::bUseThread, VdbeSorter::db, SortSubtask::file2, SorterFile::iEof, INCRINIT_NORMAL, INCRINIT_ROOT, INCRINIT_TASK, IncrMerger::iStartOff, IncrMerger::mxSz, SorterFile::pFd, PmaReader::pIncr, IncrMerger::pMerger, SortSubtask::pSorter, IncrMerger::pTask, SQLITE_MAX_WORKER_THREADS, SQLITE_OK, vdbeIncrPopulate(), vdbeMergeEngineInit(), vdbePmaReaderNext(), and vdbeSorterOpenTempFile().

Referenced by vdbePmaReaderBgIncrInit(), vdbePmaReaderIncrInit(), and vdbeSorterSetupMerge().

◆ vdbePmaReaderInit()

static int vdbePmaReaderInit ( SortSubtask * pTask,
SorterFile * pFile,
i64 iStart,
PmaReader * pReadr,
i64 * pnByte )
static

Definition at line 94602 of file sqlite3.c.

94614 {
94615 int rc;
94616
94617 assert( pFile->iEof>iStart );
94618 assert( pReadr->aAlloc==0 && pReadr->nAlloc==0 );
94619 assert( pReadr->aBuffer==0 );
94620 assert( pReadr->aMap==0 );
94621
94622 rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart);
94623 if( rc==SQLITE_OK ){
94624 u64 nByte = 0; /* Size of PMA in bytes */
94625 rc = vdbePmaReadVarint(pReadr, &nByte);
94626 pReadr->iEof = pReadr->iReadOff + nByte;
94627 *pnByte += nByte;
94628 }
static int vdbePmaReadVarint(PmaReader *p, u64 *pnOut)
Definition sqlite3.c:94458
static int vdbePmaReaderSeek(SortSubtask *pTask, PmaReader *pReadr, SorterFile *pFile, i64 iOff)
Definition sqlite3.c:94508

References PmaReader::aAlloc, PmaReader::aBuffer, PmaReader::aMap, SorterFile::iEof, PmaReader::iEof, PmaReader::iReadOff, PmaReader::nAlloc, SQLITE_OK, vdbePmaReaderNext(), vdbePmaReaderSeek(), and vdbePmaReadVarint().

Referenced by vdbeMergeEngineLevel0().

◆ vdbePmaReaderNext()

static int vdbePmaReaderNext ( PmaReader * pReadr)
static

Definition at line 94555 of file sqlite3.c.

94561 {
94562 int rc = SQLITE_OK; /* Return Code */
94563 u64 nRec = 0; /* Size of record in bytes */
94564
94565
94566 if( pReadr->iReadOff>=pReadr->iEof ){
94567 IncrMerger *pIncr = pReadr->pIncr;
94568 int bEof = 1;
94569 if( pIncr ){
94570 rc = vdbeIncrSwap(pIncr);
94571 if( rc==SQLITE_OK && pIncr->bEof==0 ){
94572 rc = vdbePmaReaderSeek(
94573 pIncr->pTask, pReadr, &pIncr->aFile[0], pIncr->iStartOff
94574 );
94575 bEof = 0;
94576 }
94577 }
94578
94579 if( bEof ){
94580 /* This is an EOF condition */
94581 vdbePmaReaderClear(pReadr);
94582 testcase( rc!=SQLITE_OK );
94583 return rc;
94584 }
94585 }
94586
94587 if( rc==SQLITE_OK ){
94588 rc = vdbePmaReadVarint(pReadr, &nRec);
94589 }
94590 if( rc==SQLITE_OK ){
94591 pReadr->nKey = (int)nRec;
static int vdbeIncrSwap(IncrMerger *)
Definition sqlite3.c:95828

Referenced by sqlite3VdbeSorterNext(), vdbeMergeEngineInit(), vdbeMergeEngineStep(), vdbePmaReaderIncrMergeInit(), and vdbePmaReaderInit().

◆ vdbePmaReaderSeek()

static int vdbePmaReaderSeek ( SortSubtask * pTask,
PmaReader * pReadr,
SorterFile * pFile,
i64 iOff )
static

Definition at line 94508 of file sqlite3.c.

94519 {
94520 int rc = SQLITE_OK;
94521
94522 assert( pReadr->pIncr==0 || pReadr->pIncr->bEof==0 );
94523
94524 if( sqlite3FaultSim(201) ) return SQLITE_IOERR_READ;
94525 if( pReadr->aMap ){
94526 sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
94527 pReadr->aMap = 0;
94528 }
94529 pReadr->iReadOff = iOff;
94530 pReadr->iEof = pFile->iEof;
94531 pReadr->pFd = pFile->pFd;
94532
94533 rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
94534 if( rc==SQLITE_OK && pReadr->aMap==0 ){
94535 int pgsz = pTask->pSorter->pgsz;
94536 int iBuf = pReadr->iReadOff % pgsz;
94537 if( pReadr->aBuffer==0 ){
94538 pReadr->aBuffer = (u8*)sqlite3Malloc(pgsz);
94539 if( pReadr->aBuffer==0 ) rc = SQLITE_NOMEM_BKPT;
94540 pReadr->nBuffer = pgsz;
94541 }
94542 if( rc==SQLITE_OK && iBuf ){
94543 int nRead = pgsz - iBuf;
94544 if( (pReadr->iReadOff + nRead) > pReadr->iEof ){
94545 nRead = (int)(pReadr->iEof - pReadr->iReadOff);
94546 }
94547 rc = sqlite3OsRead(
94548 pReadr->pFd, &pReadr->aBuffer[iBuf], nRead, pReadr->iReadOff
94549 );
static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp)
Definition sqlite3.c:94491

References PmaReader::aBuffer, PmaReader::aMap, IncrMerger::bEof, SorterFile::iEof, PmaReader::iEof, PmaReader::iReadOff, PmaReader::nBuffer, SorterFile::pFd, PmaReader::pFd, VdbeSorter::pgsz, PmaReader::pIncr, SortSubtask::pSorter, sqlite3FaultSim(), sqlite3Malloc(), sqlite3OsRead(), sqlite3OsUnfetch(), SQLITE_IOERR_READ, SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, and vdbeSorterMapFile().

Referenced by vdbePmaReaderInit().

◆ vdbePmaReadVarint()

static int vdbePmaReadVarint ( PmaReader * p,
u64 * pnOut )
static

Definition at line 94458 of file sqlite3.c.

94464 {
94465 int iBuf;
94466
94467 if( p->aMap ){
94468 p->iReadOff += sqlite3GetVarint(&p->aMap[p->iReadOff], pnOut);
94469 }else{
94470 iBuf = p->iReadOff % p->nBuffer;
94471 if( iBuf && (p->nBuffer-iBuf)>=9 ){
94472 p->iReadOff += sqlite3GetVarint(&p->aBuffer[iBuf], pnOut);
94473 }else{
94474 u8 aVarint[16], *a;
94475 int i = 0, rc;
94476 do{
94477 rc = vdbePmaReadBlob(p, 1, &a);
94478 if( rc ) return rc;
94479 aVarint[(i++)&0xf] = a[0];
94480 }while( (a[0]&0x80)!=0 );

Referenced by vdbePmaReaderInit().

◆ vdbePmaWriteBlob()

static void vdbePmaWriteBlob ( PmaWriter * p,
u8 * pData,
int nData )
static

Definition at line 95348 of file sqlite3.c.

95354 {
95355 int nRem = nData;
95356 while( nRem>0 && p->eFWErr==0 ){
95357 int nCopy = nRem;
95358 if( nCopy>(p->nBuffer - p->iBufEnd) ){
95359 nCopy = p->nBuffer - p->iBufEnd;
95360 }
95361
95362 memcpy(&p->aBuffer[p->iBufEnd], &pData[nData-nRem], nCopy);
95363 p->iBufEnd += nCopy;
95364 if( p->iBufEnd==p->nBuffer ){
95365 p->eFWErr = sqlite3OsWrite(p->pFd,
95366 &p->aBuffer[p->iBufStart], p->iBufEnd - p->iBufStart,
95367 p->iWriteOff + p->iBufStart
95368 );
95369 p->iBufStart = p->iBufEnd = 0;
95370 p->iWriteOff += p->nBuffer;
sqlite3_file * pFd
Definition sqlite3.c:94299
int nBuffer
Definition sqlite3.c:94295
int iBufEnd
Definition sqlite3.c:94297
i64 iWriteOff
Definition sqlite3.c:94298
u8 * aBuffer
Definition sqlite3.c:94294
int iBufStart
Definition sqlite3.c:94296

Referenced by vdbeIncrPopulate(), and vdbeSorterListToPMA().

◆ vdbePmaWriterFinish()

static int vdbePmaWriterFinish ( PmaWriter * p,
i64 * piEof )
static

Definition at line 95381 of file sqlite3.c.

95387 {
95388 int rc;
95389 if( p->eFWErr==0 && ALWAYS(p->aBuffer) && p->iBufEnd>p->iBufStart ){
95390 p->eFWErr = sqlite3OsWrite(p->pFd,
95391 &p->aBuffer[p->iBufStart], p->iBufEnd - p->iBufStart,
95392 p->iWriteOff + p->iBufStart
95393 );
95394 }

References PmaWriter::aBuffer, ALWAYS, PmaWriter::eFWErr, PmaWriter::iBufEnd, PmaWriter::iBufStart, PmaWriter::iWriteOff, PmaWriter::pFd, sqlite3_free(), and sqlite3OsWrite().

Referenced by vdbeIncrPopulate(), and vdbeSorterListToPMA().

◆ vdbePmaWriterInit()

static void vdbePmaWriterInit ( sqlite3_file * pFd,
PmaWriter * p,
int nBuf,
i64 iStart )
static

Definition at line 95326 of file sqlite3.c.

95337 {
95338 memset(p, 0, sizeof(PmaWriter));
95339 p->aBuffer = (u8*)sqlite3Malloc(nBuf);
95340 if( !p->aBuffer ){
95342 }else{

Referenced by vdbeIncrPopulate(), and vdbeSorterListToPMA().

◆ vdbePmaWriteVarint()

static void vdbePmaWriteVarint ( PmaWriter * p,
u64 iVal )
static

Definition at line 95400 of file sqlite3.c.

Referenced by vdbeIncrPopulate(), and vdbeSorterListToPMA().

◆ vdbeRecordCompareInt()

static int vdbeRecordCompareInt ( int nKey1,
const void * pKey1,
UnpackedRecord * pPKey2 )
static

Definition at line 82424 of file sqlite3.c.

82433 {
82434 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
82435 int serial_type = ((const u8*)pKey1)[1];
82436 int res;
82437 u32 y;
82438 u64 x;
82439 i64 v;
82440 i64 lhs;
82441
82442 vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
82443 assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
82444 switch( serial_type ){
82445 case 1: { /* 1-byte signed integer */
82446 lhs = ONE_BYTE_INT(aKey);
82447 testcase( lhs<0 );
82448 break;
82449 }
82450 case 2: { /* 2-byte signed integer */
82451 lhs = TWO_BYTE_INT(aKey);
82452 testcase( lhs<0 );
82453 break;
82454 }
82455 case 3: { /* 3-byte signed integer */
82456 lhs = THREE_BYTE_INT(aKey);
82457 testcase( lhs<0 );
82458 break;
82459 }
82460 case 4: { /* 4-byte signed integer */
82461 y = FOUR_BYTE_UINT(aKey);
82462 lhs = (i64)*(int*)&y;
82463 testcase( lhs<0 );
82464 break;
82465 }
82466 case 5: { /* 6-byte signed integer */
82467 lhs = FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
82468 testcase( lhs<0 );
82469 break;
82470 }
82471 case 6: { /* 8-byte signed integer */
82472 x = FOUR_BYTE_UINT(aKey);
82473 x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
82474 lhs = *(i64*)&x;
82475 testcase( lhs<0 );
82476 break;
82477 }
82478 case 8:
82479 lhs = 0;
82480 break;
82481 case 9:
82482 lhs = 1;
82483 break;
82484
82485 /* This case could be removed without changing the results of running
82486 ** this code. Including it causes gcc to generate a faster switch
82487 ** statement (since the range of switch targets now starts at zero and
82488 ** is contiguous) but does not cause any duplicate code to be generated
82489 ** (as gcc is clever enough to combine the two like cases). Other
82490 ** compilers might be similar. */
82491 case 0: case 7:
82492 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
82493
82494 default:
82495 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
82496 }
82497
82498 v = pPKey2->aMem[0].u.i;
82499 if( v>lhs ){
82500 res = pPKey2->r1;
82501 }else if( v<lhs ){
82502 res = pPKey2->r2;
82503 }else if( pPKey2->nField>1 ){
82504 /* The first fields of the two keys are equal. Compare the trailing
82505 ** fields. */
82506 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
82507 }else{
82508 /* The first fields of the two keys are equal and there are no trailing
82509 ** fields. Return pPKey2->default_rc in this case. */
82510 res = pPKey2->default_rc;
#define vdbeAssertFieldCountWithinLimits(A, B, C)
Definition sqlite3.c:81934
SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int)
Definition sqlite3.c:82210

References UnpackedRecord::aMem, CORRUPT_DB, UnpackedRecord::default_rc, UnpackedRecord::eqSeen, FOUR_BYTE_UINT, sqlite3_value::MemValue::i, UnpackedRecord::nField, ONE_BYTE_INT, UnpackedRecord::pKeyInfo, UnpackedRecord::r1, UnpackedRecord::r2, sqlite3VdbeRecordCompare(), sqlite3VdbeRecordCompareWithSkip(), testcase, THREE_BYTE_INT, TWO_BYTE_INT, sqlite3_value::u, and vdbeAssertFieldCountWithinLimits.

Referenced by sqlite3VdbeFindCompare().

◆ vdbeRecordCompareString()

static int vdbeRecordCompareString ( int nKey1,
const void * pKey1,
UnpackedRecord * pPKey2 )
static

Definition at line 82518 of file sqlite3.c.

82527 {
82528 const u8 *aKey1 = (const u8*)pKey1;
82529 int serial_type;
82530 int res;
82531
82532 assert( pPKey2->aMem[0].flags & MEM_Str );
82533 vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
82534 serial_type = (u8)(aKey1[1]);
82535 if( serial_type >= 0x80 ){
82536 sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type);
82537 }
82538 if( serial_type<12 ){
82539 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
82540 }else if( !(serial_type & 0x01) ){
82541 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
82542 }else{
82543 int nCmp;
82544 int nStr;
82545 int szHdr = aKey1[0];
82546
82547 nStr = (serial_type-12) / 2;
82548 if( (szHdr + nStr) > nKey1 ){
82549 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
82550 return 0; /* Corruption */
82551 }
82552 nCmp = MIN( pPKey2->aMem[0].n, nStr );
82553 res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
82554
82555 if( res>0 ){
82556 res = pPKey2->r2;
82557 }else if( res<0 ){
82558 res = pPKey2->r1;
82559 }else{
82560 res = nStr - pPKey2->aMem[0].n;
82561 if( res==0 ){
82562 if( pPKey2->nField>1 ){
82563 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
82564 }else{
82565 res = pPKey2->default_rc;
82566 pPKey2->eqSeen = 1;
82567 }
82568 }else if( res>0 ){
82569 res = pPKey2->r2;
82570 }else{
82571 res = pPKey2->r1;
82572 }
82573 }
82574 }
82575

References UnpackedRecord::aMem, CORRUPT_DB, KeyInfo::db, UnpackedRecord::default_rc, UnpackedRecord::eqSeen, UnpackedRecord::errCode, sqlite3_value::flags, sqlite3::mallocFailed, MEM_Str, MIN, sqlite3_value::n, UnpackedRecord::nField, UnpackedRecord::pKeyInfo, UnpackedRecord::r1, UnpackedRecord::r2, sqlite3GetVarint32(), sqlite3VdbeRecordCompareWithSkip(), SQLITE_CORRUPT_BKPT, vdbeAssertFieldCountWithinLimits, and sqlite3_value::z.

Referenced by sqlite3VdbeFindCompare().

◆ vdbeRecordDecodeInt()

static i64 vdbeRecordDecodeInt ( u32 serial_type,
const u8 * aKey )
static

Definition at line 82155 of file sqlite3.c.

82161 {
82162 u32 y;
82163 assert( CORRUPT_DB || (serial_type>=1 && serial_type<=9 && serial_type!=7) );
82164 switch( serial_type ){
82165 case 0:
82166 case 1:
82167 testcase( aKey[0]&0x80 );
82168 return ONE_BYTE_INT(aKey);
82169 case 2:
82170 testcase( aKey[0]&0x80 );
82171 return TWO_BYTE_INT(aKey);
82172 case 3:
82173 testcase( aKey[0]&0x80 );
82174 return THREE_BYTE_INT(aKey);
82175 case 4: {
82176 testcase( aKey[0]&0x80 );
82177 y = FOUR_BYTE_UINT(aKey);
82178 return (i64)*(int*)&y;
82179 }
82180 case 5: {
82181 testcase( aKey[0]&0x80 );
82182 return FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
82183 }
82184 case 6: {
82185 u64 x = FOUR_BYTE_UINT(aKey);
82186 testcase( aKey[0]&0x80 );
82187 x = (x<<32) | FOUR_BYTE_UINT(aKey+4);

References CORRUPT_DB, FOUR_BYTE_UINT, ONE_BYTE_INT, testcase, THREE_BYTE_INT, and TWO_BYTE_INT.

Referenced by sqlite3VdbeRecordCompareWithSkip().

◆ vdbeReleaseAndSetInt64()

static SQLITE_NOINLINE void vdbeReleaseAndSetInt64 ( Mem * pMem,
i64 val )
static

◆ vdbeSafety()

static int vdbeSafety ( Vdbe * p)
static

Definition at line 83020 of file sqlite3.c.

83026 {
83027 if( p->db==0 ){

References Vdbe::db.

Referenced by sqlite3_finalize().

◆ vdbeSafetyNotNull()

static int vdbeSafetyNotNull ( Vdbe * p)
static

Definition at line 83028 of file sqlite3.c.

83030 {
83031 return 0;
83032 }
83033}
83034static int vdbeSafetyNotNull(Vdbe *p){
83035 if( p==0 ){

Referenced by sqlite3_step(), and vdbeUnbind().

◆ vdbeSortAllocUnpacked()

◆ vdbeSorterAddToTree()

static int vdbeSorterAddToTree ( SortSubtask * pTask,
int nDepth,
int iSeq,
MergeEngine * pRoot,
MergeEngine * pLeaf )
static

Definition at line 96237 of file sqlite3.c.

96249 {
96250 int rc = SQLITE_OK;
96251 int nDiv = 1;
96252 int i;
96253 MergeEngine *p = pRoot;
96254 IncrMerger *pIncr;
96255
96256 rc = vdbeIncrMergerNew(pTask, pLeaf, &pIncr);
96257
96258 for(i=1; i<nDepth; i++){
96259 nDiv = nDiv * SORTER_MAX_MERGE_COUNT;
96260 }
96261
96262 for(i=1; i<nDepth && rc==SQLITE_OK; i++){
96263 int iIter = (iSeq / nDiv) % SORTER_MAX_MERGE_COUNT;
96264 PmaReader *pReadr = &p->aReadr[iIter];
96265
96266 if( pReadr->pIncr==0 ){
96268 if( pNew==0 ){
96269 rc = SQLITE_NOMEM_BKPT;
96270 }else{
96271 rc = vdbeIncrMergerNew(pTask, pNew, &pReadr->pIncr);
96272 }
96273 }
96274 if( rc==SQLITE_OK ){
96275 p = pReadr->pIncr->pMerger;
96276 nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
96277 }
96278 }
96279
96280 if( rc==SQLITE_OK ){
static int vdbeIncrMergerNew(SortSubtask *pTask, MergeEngine *pMerger, IncrMerger **ppOut)
Definition sqlite3.c:95867

References MergeEngine::aReadr, PmaReader::pIncr, IncrMerger::pMerger, SORTER_MAX_MERGE_COUNT, SQLITE_NOMEM_BKPT, SQLITE_OK, vdbeIncrFree(), vdbeIncrMergerNew(), and vdbeMergeEngineNew().

Referenced by vdbeSorterMergeTreeBuild().

◆ vdbeSorterCompare()

static int vdbeSorterCompare ( SortSubtask * pTask,
int * pbKey2Cached,
const void * pKey1,
int nKey1,
const void * pKey2,
int nKey2 )
static

◆ vdbeSorterCompareInt()

static int vdbeSorterCompareInt ( SortSubtask * pTask,
int * pbKey2Cached,
const void * pKey1,
int nKey1,
const void * pKey2,
int nKey2 )
static

Definition at line 94723 of file sqlite3.c.

94734 {
94735 const u8 * const p1 = (const u8 * const)pKey1;
94736 const u8 * const p2 = (const u8 * const)pKey2;
94737 const int s1 = p1[1]; /* Left hand serial type */
94738 const int s2 = p2[1]; /* Right hand serial type */
94739 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
94740 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
94741 int res; /* Return value */
94742
94743 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
94744 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
94745
94746 if( s1==s2 ){
94747 /* The two values have the same sign. Compare using memcmp(). */
94748 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
94749 const u8 n = aLen[s1];
94750 int i;
94751 res = 0;
94752 for(i=0; i<n; i++){
94753 if( (res = v1[i] - v2[i])!=0 ){
94754 if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
94755 res = v1[0] & 0x80 ? -1 : +1;
94756 }
94757 break;
94758 }
94759 }
94760 }else if( s1>7 && s2>7 ){
94761 res = s1 - s2;
94762 }else{
94763 if( s2>7 ){
94764 res = +1;
94765 }else if( s1>7 ){
94766 res = -1;
94767 }else{
94768 res = s1 - s2;
94769 }
94770 assert( res!=0 );
94771
94772 if( res>0 ){
94773 if( *v1 & 0x80 ) res = -1;
94774 }else{
94775 if( *v2 & 0x80 ) res = +1;
94776 }
94777 }
94778
94779 if( res==0 ){
94780 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
94782 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
94783 );
94784 }
94785 }else if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
static int vdbeSorterCompareTail(SortSubtask *pTask, int *pbKey2Cached, const void *pKey1, int nKey1, const void *pKey2, int nKey2)
Definition sqlite3.c:94635

◆ vdbeSorterCompareTail()

static int vdbeSorterCompareTail ( SortSubtask * pTask,
int * pbKey2Cached,
const void * pKey1,
int nKey1,
const void * pKey2,
int nKey2 )
static

◆ vdbeSorterCompareText()

static int vdbeSorterCompareText ( SortSubtask * pTask,
int * pbKey2Cached,
const void * pKey1,
int nKey1,
const void * pKey2,
int nKey2 )
static

Definition at line 94681 of file sqlite3.c.

94692 {
94693 const u8 * const p1 = (const u8 * const)pKey1;
94694 const u8 * const p2 = (const u8 * const)pKey2;
94695 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
94696 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
94697
94698 int n1;
94699 int n2;
94700 int res;
94701
94702 getVarint32NR(&p1[1], n1);
94703 getVarint32NR(&p2[1], n2);
94704 res = memcmp(v1, v2, (MIN(n1, n2) - 13)/2);
94705 if( res==0 ){
94706 res = n1 - n2;
94707 }
94708
94709 if( res==0 ){
94710 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
94712 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
94713 );
94714 }
94715 }else{
94716 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
94717 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){

References KeyInfo::aSortFlags, getVarint32NR, KEYINFO_ORDER_BIGNULL, MIN, KeyInfo::nKeyField, VdbeSorter::pKeyInfo, SortSubtask::pSorter, and vdbeSorterCompareTail().

◆ vdbeSorterCreateThread()

static int vdbeSorterCreateThread ( SortSubtask * pTask,
void *(*)(void *) xTask,
void * pIn )
static

Definition at line 95007 of file sqlite3.c.

Referenced by vdbePmaReaderIncrInit(), and vdbeSorterFlushPMA().

◆ vdbeSorterFlushPMA()

static int vdbeSorterFlushPMA ( VdbeSorter * pSorter)
static

Definition at line 95570 of file sqlite3.c.

95576 {
95577#if SQLITE_MAX_WORKER_THREADS==0
95578 pSorter->bUsePMA = 1;
95579 return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list);
95580#else
95581 int rc = SQLITE_OK;
95582 int i;
95583 SortSubtask *pTask = 0; /* Thread context used to create new PMA */
95584 int nWorker = (pSorter->nTask-1);
95585
95586 /* Set the flag to indicate that at least one PMA has been written.
95587 ** Or will be, anyhow. */
95588 pSorter->bUsePMA = 1;
95589
95590 /* Select a sub-task to sort and flush the current list of in-memory
95591 ** records to disk. If the sorter is running in multi-threaded mode,
95592 ** round-robin between the first (pSorter->nTask-1) tasks. Except, if
95593 ** the background thread from a sub-tasks previous turn is still running,
95594 ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy,
95595 ** fall back to using the final sub-task. The first (pSorter->nTask-1)
95596 ** sub-tasks are prefered as they use background threads - the final
95597 ** sub-task uses the main thread. */
95598 for(i=0; i<nWorker; i++){
95599 int iTest = (pSorter->iPrev + i + 1) % nWorker;
95600 pTask = &pSorter->aTask[iTest];
95601 if( pTask->bDone ){
95602 rc = vdbeSorterJoinThread(pTask);
95603 }
95604 if( rc!=SQLITE_OK || pTask->pThread==0 ) break;
95605 }
95606
95607 if( rc==SQLITE_OK ){
95608 if( i==nWorker ){
95609 /* Use the foreground thread for this operation */
95610 rc = vdbeSorterListToPMA(&pSorter->aTask[nWorker], &pSorter->list);
95611 }else{
95612 /* Launch a background thread for this operation */
95613 u8 *aMem;
95614 void *pCtx;
95615
95616 assert( pTask!=0 );
95617 assert( pTask->pThread==0 && pTask->bDone==0 );
95618 assert( pTask->list.pList==0 );
95619 assert( pTask->list.aMemory==0 || pSorter->list.aMemory!=0 );
95620
95621 aMem = pTask->list.aMemory;
95622 pCtx = (void*)pTask;
95623 pSorter->iPrev = (u8)(pTask - pSorter->aTask);
95624 pTask->list = pSorter->list;
95625 pSorter->list.pList = 0;
95626 pSorter->list.szPMA = 0;
95627 if( aMem ){
95628 pSorter->list.aMemory = aMem;
95629 pSorter->nMemory = sqlite3MallocSize(aMem);
95630 }else if( pSorter->list.aMemory ){
95631 pSorter->list.aMemory = sqlite3Malloc(pSorter->nMemory);
95632 if( !pSorter->list.aMemory ) return SQLITE_NOMEM_BKPT;
95633 }
95634
static void * vdbeSorterFlushThread(void *pCtx)
Definition sqlite3.c:95556
static int vdbeSorterListToPMA(SortSubtask *pTask, SorterList *pList)
Definition sqlite3.c:95421
SorterList list
Definition sqlite3.c:94178
SQLiteThread * pThread
Definition sqlite3.c:94174

References SorterList::aMemory, VdbeSorter::aTask, SortSubtask::bDone, VdbeSorter::bUsePMA, VdbeSorter::iPrev, SortSubtask::list, VdbeSorter::list, VdbeSorter::nMemory, VdbeSorter::nTask, SorterList::pList, SortSubtask::pThread, sqlite3Malloc(), sqlite3MallocSize(), SQLITE_NOMEM_BKPT, SQLITE_OK, SorterList::szPMA, vdbeSorterCreateThread(), vdbeSorterFlushThread(), vdbeSorterJoinThread(), and vdbeSorterListToPMA().

Referenced by sqlite3VdbeSorterRewind().

◆ vdbeSorterFlushThread()

static void * vdbeSorterFlushThread ( void * pCtx)
static

Definition at line 95556 of file sqlite3.c.

95562 {
95563 SortSubtask *pTask = (SortSubtask*)pCtx;

Referenced by vdbeSorterFlushPMA().

◆ vdbeSorterGetCompare()

static SorterCompare vdbeSorterGetCompare ( VdbeSorter * p)
static

Definition at line 95261 of file sqlite3.c.

95267 {
95268 if( p->typeMask==SORTER_TYPE_INTEGER ){

Referenced by vdbeSorterSetupMerge(), and vdbeSorterSort().

◆ vdbeSorterJoinAll()

static int vdbeSorterJoinAll ( VdbeSorter * pSorter,
int rcin )
static

Definition at line 95020 of file sqlite3.c.

95026 {
95027 int rc = rcin;
95028 int i;
95029
95030 /* This function is always called by the main user thread.
95031 **
95032 ** If this function is being called after SorterRewind() has been called,
95033 ** it is possible that thread pSorter->aTask[pSorter->nTask-1].pThread
95034 ** is currently attempt to join one of the other threads. To avoid a race
95035 ** condition where this thread also attempts to join the same object, join
95036 ** thread pSorter->aTask[pSorter->nTask-1].pThread first. */
95037 for(i=pSorter->nTask-1; i>=0; i--){

Referenced by sqlite3VdbeSorterRewind().

◆ vdbeSorterJoinThread()

static int vdbeSorterJoinThread ( SortSubtask * pTask)
static

Definition at line 94986 of file sqlite3.c.

94992 {
94993 int rc = SQLITE_OK;
94994 if( pTask->pThread ){
94995#ifdef SQLITE_DEBUG_SORTER_THREADS
94996 int bDone = pTask->bDone;
94997#endif
94998 void *pRet = SQLITE_INT_TO_PTR(SQLITE_ERROR);
94999 vdbeSorterBlockDebug(pTask, !bDone, "enter");
95000 (void)sqlite3ThreadJoin(pTask->pThread, &pRet);
95001 vdbeSorterBlockDebug(pTask, !bDone, "exit");
95002 rc = SQLITE_PTR_TO_INT(pRet);
#define vdbeSorterBlockDebug(x, y, z)
Definition sqlite3.c:94979
SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread *, void **)
Definition sqlite3.c:30453

References SortSubtask::bDone, SortSubtask::pThread, sqlite3ThreadJoin(), SQLITE_ERROR, SQLITE_INT_TO_PTR, SQLITE_OK, SQLITE_PTR_TO_INT, and vdbeSorterBlockDebug.

Referenced by vdbeIncrSwap(), and vdbeSorterFlushPMA().

◆ vdbeSorterListToPMA()

static int vdbeSorterListToPMA ( SortSubtask * pTask,
SorterList * pList )
static

Definition at line 95421 of file sqlite3.c.

95427 {
95428 sqlite3 *db = pTask->pSorter->db;
95429 int rc = SQLITE_OK; /* Return code */
95430 PmaWriter writer; /* Object used to write to the file */
95431
95432#ifdef SQLITE_DEBUG
95433 /* Set iSz to the expected size of file pTask->file after writing the PMA.
95434 ** This is used by an assert() statement at the end of this function. */
95435 i64 iSz = pList->szPMA + sqlite3VarintLen(pList->szPMA) + pTask->file.iEof;
95436#endif
95437
95438 vdbeSorterWorkDebug(pTask, "enter");
95439 memset(&writer, 0, sizeof(PmaWriter));
95440 assert( pList->szPMA>0 );
95441
95442 /* If the first temporary PMA file has not been opened, open it now. */
95443 if( pTask->file.pFd==0 ){
95444 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
95445 assert( rc!=SQLITE_OK || pTask->file.pFd );
95446 assert( pTask->file.iEof==0 );
95447 assert( pTask->nPMA==0 );
95448 }
95449
95450 /* Try to get the file to memory map */
95451 if( rc==SQLITE_OK ){
95452 vdbeSorterExtendFile(db, pTask->file.pFd, pTask->file.iEof+pList->szPMA+9);
95453 }
95454
95455 /* Sort the list */
95456 if( rc==SQLITE_OK ){
95457 rc = vdbeSorterSort(pTask, pList);
95458 }
95459
95460 if( rc==SQLITE_OK ){
95461 SorterRecord *p;
95462 SorterRecord *pNext = 0;
95463
95464 vdbePmaWriterInit(pTask->file.pFd, &writer, pTask->pSorter->pgsz,
95465 pTask->file.iEof);
95466 pTask->nPMA++;
95468 for(p=pList->pList; p; p=pNext){
95469 pNext = p->u.pNext;
95472 if( pList->aMemory==0 ) sqlite3_free(p);
95473 }
95474 pList->pList = p;
95475 rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof);
95476 }
#define SRVAL(p)
Definition sqlite3.c:94334
#define vdbeSorterWorkDebug(x, y)
Definition sqlite3.c:94976
static int vdbePmaWriterFinish(PmaWriter *p, i64 *piEof)
Definition sqlite3.c:95381
#define vdbeSorterExtendFile(x, y, z)
Definition sqlite3.c:95170

References SorterList::aMemory, VdbeSorter::db, SortSubtask::file, SorterFile::iEof, SortSubtask::nPMA, SorterRecord::nVal, SorterFile::pFd, VdbeSorter::pgsz, SorterList::pList, SorterRecord::pNext, SortSubtask::pSorter, sqlite3_free(), sqlite3VarintLen(), SQLITE_OK, SRVAL, SorterList::szPMA, SorterRecord::u, vdbePmaWriteBlob(), vdbePmaWriterFinish(), vdbePmaWriterInit(), vdbePmaWriteVarint(), vdbeSorterExtendFile, vdbeSorterOpenTempFile(), vdbeSorterSort(), vdbeSorterWorkDebug, and writer().

Referenced by vdbeSorterFlushPMA().

◆ vdbeSorterMapFile()

static int vdbeSorterMapFile ( SortSubtask * pTask,
SorterFile * pFile,
u8 ** pp )
static

Definition at line 94491 of file sqlite3.c.

94497 {
94498 int rc = SQLITE_OK;
94499 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
94500 sqlite3_file *pFd = pFile->pFd;
94501 if( pFd->pMethods->iVersion>=3 ){

References VdbeSorter::db, SorterFile::iEof, sqlite3_io_methods::iVersion, sqlite3::nMaxSorterMmap, SorterFile::pFd, sqlite3_file::pMethods, SortSubtask::pSorter, sqlite3OsFetch(), SQLITE_OK, and testcase.

Referenced by vdbePmaReaderSeek().

◆ vdbeSorterMerge()

static SorterRecord * vdbeSorterMerge ( SortSubtask * pTask,
SorterRecord * p1,
SorterRecord * p2 )
static

Definition at line 95219 of file sqlite3.c.

95229 {
95230 SorterRecord *pFinal = 0;
95231 SorterRecord **pp = &pFinal;
95232 int bCached = 0;
95233
95234 assert( p1!=0 && p2!=0 );
95235 for(;;){
95236 int res;
95237 res = pTask->xCompare(
95238 pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
95239 );
95240
95241 if( res<=0 ){
95242 *pp = p1;
95243 pp = &p1->u.pNext;
95244 p1 = p1->u.pNext;
95245 if( p1==0 ){
95246 *pp = p2;
95247 break;
95248 }
95249 }else{
95250 *pp = p2;
95251 pp = &p2->u.pNext;
95252 p2 = p2->u.pNext;
95253 bCached = 0;
95254 if( p2==0 ){
95255 *pp = p1;

Referenced by vdbeSorterSort().

◆ vdbeSorterMergeTreeBuild()

static int vdbeSorterMergeTreeBuild ( VdbeSorter * pSorter,
MergeEngine ** ppOut )
static

Definition at line 96293 of file sqlite3.c.

96302 {
96303 MergeEngine *pMain = 0;
96304 int rc = SQLITE_OK;
96305 int iTask;
96306
96307#if SQLITE_MAX_WORKER_THREADS>0
96308 /* If the sorter uses more than one task, then create the top-level
96309 ** MergeEngine here. This MergeEngine will read data from exactly
96310 ** one PmaReader per sub-task. */
96311 assert( pSorter->bUseThreads || pSorter->nTask==1 );
96312 if( pSorter->nTask>1 ){
96313 pMain = vdbeMergeEngineNew(pSorter->nTask);
96314 if( pMain==0 ) rc = SQLITE_NOMEM_BKPT;
96315 }
96316#endif
96317
96318 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
96319 SortSubtask *pTask = &pSorter->aTask[iTask];
96320 assert( pTask->nPMA>0 || SQLITE_MAX_WORKER_THREADS>0 );
96321 if( SQLITE_MAX_WORKER_THREADS==0 || pTask->nPMA ){
96322 MergeEngine *pRoot = 0; /* Root node of tree for this task */
96323 int nDepth = vdbeSorterTreeDepth(pTask->nPMA);
96324 i64 iReadOff = 0;
96325
96326 if( pTask->nPMA<=SORTER_MAX_MERGE_COUNT ){
96327 rc = vdbeMergeEngineLevel0(pTask, pTask->nPMA, &iReadOff, &pRoot);
96328 }else{
96329 int i;
96330 int iSeq = 0;
96332 if( pRoot==0 ) rc = SQLITE_NOMEM_BKPT;
96333 for(i=0; i<pTask->nPMA && rc==SQLITE_OK; i += SORTER_MAX_MERGE_COUNT){
96334 MergeEngine *pMerger = 0; /* New level-0 PMA merger */
96335 int nReader; /* Number of level-0 PMAs to merge */
96336
96337 nReader = MIN(pTask->nPMA - i, SORTER_MAX_MERGE_COUNT);
96338 rc = vdbeMergeEngineLevel0(pTask, nReader, &iReadOff, &pMerger);
96339 if( rc==SQLITE_OK ){
96340 rc = vdbeSorterAddToTree(pTask, nDepth, iSeq++, pRoot, pMerger);
96341 }
96342 }
96343 }
96344
96345 if( rc==SQLITE_OK ){
96346#if SQLITE_MAX_WORKER_THREADS>0
96347 if( pMain!=0 ){
96348 rc = vdbeIncrMergerNew(pTask, pRoot, &pMain->aReadr[iTask].pIncr);
96349 }else
96350#endif
96351 {
96352 assert( pMain==0 );
96353 pMain = pRoot;
96354 }
96355 }else{
96356 vdbeMergeEngineFree(pRoot);
96357 }
96358 }
96359 }
96360
96361 if( rc!=SQLITE_OK ){
static int vdbeMergeEngineLevel0(SortSubtask *pTask, int nPMA, i64 *piOffset, MergeEngine **ppOut)
Definition sqlite3.c:96180
static int vdbeSorterAddToTree(SortSubtask *pTask, int nDepth, int iSeq, MergeEngine *pRoot, MergeEngine *pLeaf)
Definition sqlite3.c:96237
static int vdbeSorterTreeDepth(int nPMA)
Definition sqlite3.c:96219

References MergeEngine::aReadr, VdbeSorter::aTask, VdbeSorter::bUseThreads, MIN, SortSubtask::nPMA, VdbeSorter::nTask, PmaReader::pIncr, SORTER_MAX_MERGE_COUNT, SQLITE_MAX_WORKER_THREADS, SQLITE_NOMEM_BKPT, SQLITE_OK, vdbeIncrMergerNew(), vdbeMergeEngineFree(), vdbeMergeEngineLevel0(), vdbeMergeEngineNew(), vdbeSorterAddToTree(), and vdbeSorterTreeDepth().

Referenced by vdbeSorterSetupMerge().

◆ vdbeSorterOpenTempFile()

◆ vdbeSorterRecordFree()

static void vdbeSorterRecordFree ( sqlite3 * db,
SorterRecord * pRecord )
static

Definition at line 94908 of file sqlite3.c.

94914 {
94915 SorterRecord *p;

Referenced by sqlite3VdbeSorterNext().

◆ vdbeSorterRowkey()

static void * vdbeSorterRowkey ( const VdbeSorter * pSorter,
int * pnKey )
static

Definition at line 96544 of file sqlite3.c.

96553 {
96554 void *pKey;
96555 if( pSorter->bUsePMA ){
96556 PmaReader *pReader;
96557#if SQLITE_MAX_WORKER_THREADS>0
96558 if( pSorter->bUseThreads ){
96559 pReader = pSorter->pReader;
96560 }else
96561#endif
96562 /*if( !pSorter->bUseThreads )*/{
96563 pReader = &pSorter->pMerger->aReadr[pSorter->pMerger->aTree[1]];
96564 }
96565 *pnKey = pReader->nKey;
96566 pKey = pReader->aKey;

Referenced by sqlite3VdbeSorterCompare().

◆ vdbeSorterSetupMerge()

static int vdbeSorterSetupMerge ( VdbeSorter * pSorter)
static

Definition at line 96372 of file sqlite3.c.

96378 {
96379 int rc; /* Return code */
96380 SortSubtask *pTask0 = &pSorter->aTask[0];
96381 MergeEngine *pMain = 0;
96382#if SQLITE_MAX_WORKER_THREADS
96383 sqlite3 *db = pTask0->pSorter->db;
96384 int i;
96385 SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
96386 for(i=0; i<pSorter->nTask; i++){
96387 pSorter->aTask[i].xCompare = xCompare;
96388 }
96389#endif
96390
96391 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
96392 if( rc==SQLITE_OK ){
96393#if SQLITE_MAX_WORKER_THREADS
96394 assert( pSorter->bUseThreads==0 || pSorter->nTask>1 );
96395 if( pSorter->bUseThreads ){
96396 int iTask;
96397 PmaReader *pReadr = 0;
96398 SortSubtask *pLast = &pSorter->aTask[pSorter->nTask-1];
96399 rc = vdbeSortAllocUnpacked(pLast);
96400 if( rc==SQLITE_OK ){
96401 pReadr = (PmaReader*)sqlite3DbMallocZero(db, sizeof(PmaReader));
96402 pSorter->pReader = pReadr;
96403 if( pReadr==0 ) rc = SQLITE_NOMEM_BKPT;
96404 }
96405 if( rc==SQLITE_OK ){
96406 rc = vdbeIncrMergerNew(pLast, pMain, &pReadr->pIncr);
96407 if( rc==SQLITE_OK ){
96409 for(iTask=0; iTask<(pSorter->nTask-1); iTask++){
96410 IncrMerger *pIncr;
96411 if( (pIncr = pMain->aReadr[iTask].pIncr) ){
96413 assert( pIncr->pTask!=pLast );
96414 }
96415 }
96416 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
96417 /* Check that:
96418 **
96419 ** a) The incremental merge object is configured to use the
96420 ** right task, and
96421 ** b) If it is using task (nTask-1), it is configured to run
96422 ** in single-threaded mode. This is important, as the
96423 ** root merge (INCRINIT_ROOT) will be using the same task
96424 ** object.
96425 */
96426 PmaReader *p = &pMain->aReadr[iTask];
96427 assert( p->pIncr==0 || (
96428 (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
96429 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
96430 ));
96432 }
96433 }
96434 pMain = 0;
96435 }
96436 if( rc==SQLITE_OK ){
96438 }
96439 }else
96440#endif
96441 {
96442 rc = vdbeMergeEngineInit(pTask0, pMain, INCRINIT_NORMAL);
96443 pSorter->pMerger = pMain;
96444 pMain = 0;
96445 }
96446 }
static void vdbeIncrMergerSetThreads(IncrMerger *pIncr)
Definition sqlite3.c:95891
static int vdbeSorterMergeTreeBuild(VdbeSorter *pSorter, MergeEngine **ppOut)
Definition sqlite3.c:96293
static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode)
Definition sqlite3.c:96062
int(* SorterCompare)(SortSubtask *, int *, const void *, int, const void *, int)
Definition sqlite3.c:94172
static int vdbeSortAllocUnpacked(SortSubtask *pTask)
Definition sqlite3.c:95205
static SorterCompare vdbeSorterGetCompare(VdbeSorter *p)
Definition sqlite3.c:95261

References MergeEngine::aReadr, VdbeSorter::aTask, IncrMerger::bUseThread, VdbeSorter::bUseThreads, VdbeSorter::db, INCRINIT_NORMAL, INCRINIT_ROOT, INCRINIT_TASK, VdbeSorter::nTask, PmaReader::pIncr, VdbeSorter::pMerger, VdbeSorter::pReader, SortSubtask::pSorter, IncrMerger::pTask, sqlite3DbMallocZero(), SQLITE_NOMEM_BKPT, SQLITE_OK, vdbeIncrMergerNew(), vdbeIncrMergerSetThreads(), vdbeMergeEngineFree(), vdbeMergeEngineInit(), vdbePmaReaderIncrInit(), vdbePmaReaderIncrMergeInit(), vdbeSortAllocUnpacked(), vdbeSorterGetCompare(), vdbeSorterMergeTreeBuild(), and SortSubtask::xCompare.

Referenced by sqlite3VdbeSorterRewind().

◆ vdbeSorterSort()

static int vdbeSorterSort ( SortSubtask * pTask,
SorterList * pList )
static

Definition at line 95275 of file sqlite3.c.

95281 {
95282 int i;
95283 SorterRecord *p;
95284 int rc;
95285 SorterRecord *aSlot[64];
95286
95287 rc = vdbeSortAllocUnpacked(pTask);
95288 if( rc!=SQLITE_OK ) return rc;
95289
95290 p = pList->pList;
95291 pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
95292 memset(aSlot, 0, sizeof(aSlot));
95293
95294 while( p ){
95295 SorterRecord *pNext;
95296 if( pList->aMemory ){
95297 if( (u8*)p==pList->aMemory ){
95298 pNext = 0;
95299 }else{
95300 assert( p->u.iNext<sqlite3MallocSize(pList->aMemory) );
95301 pNext = (SorterRecord*)&pList->aMemory[p->u.iNext];
95302 }
95303 }else{
95304 pNext = p->u.pNext;
95305 }
95306
95307 p->u.pNext = 0;
95308 for(i=0; aSlot[i]; i++){
95309 p = vdbeSorterMerge(pTask, p, aSlot[i]);
95310 aSlot[i] = 0;
95311 }
95312 aSlot[i] = p;
95313 p = pNext;
95314 }
95315
95316 p = 0;
95317 for(i=0; i<ArraySize(aSlot); i++){
95318 if( aSlot[i]==0 ) continue;
95319 p = p ? vdbeSorterMerge(pTask, p, aSlot[i]) : aSlot[i];
95320 }
95321 pList->pList = p;
static SorterRecord * vdbeSorterMerge(SortSubtask *pTask, SorterRecord *p1, SorterRecord *p2)
Definition sqlite3.c:95219

References SorterList::aMemory, ArraySize, UnpackedRecord::errCode, SorterRecord::iNext, SorterList::pList, SorterRecord::pNext, SortSubtask::pSorter, SortSubtask::pUnpacked, sqlite3MallocSize(), SQLITE_NOMEM, SQLITE_OK, SorterRecord::u, vdbeSortAllocUnpacked(), vdbeSorterGetCompare(), vdbeSorterMerge(), and SortSubtask::xCompare.

Referenced by sqlite3VdbeSorterRewind(), and vdbeSorterListToPMA().

◆ vdbeSorterTreeDepth()

static int vdbeSorterTreeDepth ( int nPMA)
static

Definition at line 96219 of file sqlite3.c.

96225 {
96226 int nDepth = 0;

References SORTER_MAX_MERGE_COUNT.

Referenced by vdbeSorterMergeTreeBuild().

◆ vdbeSortSubtaskCleanup()

static void vdbeSortSubtaskCleanup ( sqlite3 * db,
SortSubtask * pTask )
static

Definition at line 94921 of file sqlite3.c.

94927 {
94928 sqlite3DbFree(db, pTask->pUnpacked);
94929#if SQLITE_MAX_WORKER_THREADS>0
94930 /* pTask->list.aMemory can only be non-zero if it was handed memory
94931 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
94932 if( pTask->list.aMemory ){
94933 sqlite3_free(pTask->list.aMemory);
94934 }else
94935#endif
94936 {
94937 assert( pTask->list.aMemory==0 );
94938 vdbeSorterRecordFree(0, pTask->list.pList);
94939 }
94940 if( pTask->file.pFd ){
94941 sqlite3OsCloseFree(pTask->file.pFd);

◆ vdbeUnbind()

static int vdbeUnbind ( Vdbe * p,
int i )
static

Definition at line 84311 of file sqlite3.c.

84317 {
84318 Mem *pVar;
84319 if( vdbeSafetyNotNull(p) ){
84320 return SQLITE_MISUSE_BKPT;
84321 }
84323 if( p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
84327 "bind on a busy prepared statement: [%s]", p->zSql);
84328 return SQLITE_MISUSE_BKPT;
84329 }
84330 if( i<1 || i>p->nVar ){
84333 return SQLITE_RANGE;
84334 }
84335 i--;
84336 pVar = &p->aVar[i];
84338 pVar->flags = MEM_Null;
84339 p->db->errCode = SQLITE_OK;
84340
84341 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
84342 ** binding a new value to this variable invalidates the current query plan.
84343 **
84344 ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host
84345 ** parameter in the WHERE clause might influence the choice of query plan
84346 ** for a statement, then the statement will be automatically recompiled,
84347 ** as if there had been a schema change, on the first sqlite3_step() call
84348 ** following any change to the bindings of that parameter.
84349 */
#define SQLITE_RANGE
Definition sqlite3.c:1495

References Vdbe::aVar, Vdbe::db, sqlite3::errCode, Vdbe::expired, Vdbe::expmask, sqlite3_value::flags, Vdbe::magic, MEM_Null, sqlite3::mutex, Vdbe::nVar, Vdbe::pc, Vdbe::prepFlags, sqlite3_log(), sqlite3_mutex_enter(), sqlite3_mutex_leave(), sqlite3Error(), sqlite3VdbeMemRelease(), SQLITE_MISUSE, SQLITE_MISUSE_BKPT, SQLITE_OK, SQLITE_PREPARE_SAVESQL, SQLITE_RANGE, VDBE_MAGIC_RUN, vdbeSafetyNotNull(), and Vdbe::zSql.

◆ verifyDbFile()

static void verifyDbFile ( unixFile * pFile)
static

Definition at line 35015 of file sqlite3.c.

35021 {
35022 struct stat buf;
35023 int rc;
35024
35025 /* These verifications occurs for the main database only */
35026 if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
35027
35028 rc = osFstat(pFile->h, &buf);
35029 if( rc!=0 ){
35030 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
35031 return;
35032 }
35033 if( buf.st_nlink==0 ){
35034 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
35035 return;
35036 }
35037 if( buf.st_nlink>1 ){
35038 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
35039 return;

References unixFile::ctrlFlags, fileHasMoved(), unixFile::h, osFstat, sqlite3_log(), SQLITE_WARNING, UNIXFILE_NOLOCK, and unixFile::zPath.

◆ versionFunc()

static void versionFunc ( sqlite3_context * context,
int NotUsed,
sqlite3_value ** NotUsed2 )
static

Definition at line 117977 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ vfsUnlink()

static void vfsUnlink ( sqlite3_vfs * pVfs)
static

Definition at line 23331 of file sqlite3.c.

23336 {
23338 if( pVfs==0 ){
23339 /* No-op */
23340 }else if( vfsList==pVfs ){
23341 vfsList = pVfs->pNext;
23342 }else if( vfsList ){
23343 sqlite3_vfs *p = vfsList;
23344 while( p->pNext && p->pNext!=pVfs ){
23345 p = p->pNext;
23346 }

Referenced by sqlite3_vfs_register().

◆ vtabBestIndex()

static int vtabBestIndex ( Parse * pParse,
Table * pTab,
sqlite3_index_info * p )
static

Definition at line 146664 of file sqlite3.c.

146670 {
146671 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
146672 int rc;
146673
146675 rc = pVtab->pModule->xBestIndex(pVtab, p);
146677
146678 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
146679 if( rc==SQLITE_NOMEM ){
146680 sqlite3OomFault(pParse->db);
146681 }else if( !pVtab->zErrMsg ){
146682 sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
146683 }else{
146684 sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
#define whereTraceIndexInfoOutputs(A)
Definition sqlite3.c:146260
#define whereTraceIndexInfoInputs(A)
Definition sqlite3.c:146259
int(* xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info *)
Definition sqlite3.c:7766

References Parse::db, sqlite3_vtab::pModule, VTable::pVtab, sqlite3_free(), sqlite3ErrorMsg(), sqlite3ErrStr(), sqlite3GetVTable(), sqlite3OomFault(), SQLITE_CONSTRAINT, SQLITE_NOMEM, SQLITE_OK, whereTraceIndexInfoInputs, whereTraceIndexInfoOutputs, sqlite3_module::xBestIndex, and sqlite3_vtab::zErrMsg.

Referenced by whereLoopAddVirtualOne().

◆ vtabCallConstructor()

static int vtabCallConstructor ( sqlite3 * db,
Table * pTab,
Module * pMod,
int(*)(sqlite3 *, void *, int, const char *const *, sqlite3_vtab **, char **) xConstruct,
char ** pzErr )
static

Definition at line 140121 of file sqlite3.c.

140133 {
140134 VtabCtx sCtx;
140135 VTable *pVTable;
140136 int rc;
140137 const char *const*azArg = (const char *const*)pTab->azModuleArg;
140138 int nArg = pTab->nModuleArg;
140139 char *zErr = 0;
140140 char *zModuleName;
140141 int iDb;
140142 VtabCtx *pCtx;
140143
140144 /* Check that the virtual-table is not already being initialized */
140145 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
140146 if( pCtx->pTab==pTab ){
140147 *pzErr = sqlite3MPrintf(db,
140148 "vtable constructor called recursively: %s", pTab->zName
140149 );
140150 return SQLITE_LOCKED;
140151 }
140152 }
140153
140154 zModuleName = sqlite3DbStrDup(db, pTab->zName);
140155 if( !zModuleName ){
140156 return SQLITE_NOMEM_BKPT;
140157 }
140158
140159 pVTable = sqlite3MallocZero(sizeof(VTable));
140160 if( !pVTable ){
140161 sqlite3OomFault(db);
140162 sqlite3DbFree(db, zModuleName);
140163 return SQLITE_NOMEM_BKPT;
140164 }
140165 pVTable->db = db;
140166 pVTable->pMod = pMod;
140167 pVTable->eVtabRisk = SQLITE_VTABRISK_Normal;
140168
140169 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
140170 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
140171
140172 /* Invoke the virtual table constructor */
140173 assert( &db->pVtabCtx );
140174 assert( xConstruct );
140175 sCtx.pTab = pTab;
140176 sCtx.pVTable = pVTable;
140177 sCtx.pPrior = db->pVtabCtx;
140178 sCtx.bDeclared = 0;
140179 db->pVtabCtx = &sCtx;
140180 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
140181 db->pVtabCtx = sCtx.pPrior;
140182 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
140183 assert( sCtx.pTab==pTab );
140184
140185 if( SQLITE_OK!=rc ){
140186 if( zErr==0 ){
140187 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
140188 }else {
140189 *pzErr = sqlite3MPrintf(db, "%s", zErr);
140190 sqlite3_free(zErr);
140191 }
140192 sqlite3DbFree(db, pVTable);
140193 }else if( ALWAYS(pVTable->pVtab) ){
140194 /* Justification of ALWAYS(): A correct vtab constructor must allocate
140195 ** the sqlite3_vtab object if successful. */
140196 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
140197 pVTable->pVtab->pModule = pMod->pModule;
140198 pMod->nRefModule++;
140199 pVTable->nRef = 1;
140200 if( sCtx.bDeclared==0 ){
140201 const char *zFormat = "vtable constructor did not declare schema: %s";
140202 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
140203 sqlite3VtabUnlock(pVTable);
140204 rc = SQLITE_ERROR;
140205 }else{
140206 int iCol;
140207 u16 oooHidden = 0;
140208 /* If everything went according to plan, link the new VTable structure
140209 ** into the linked list headed by pTab->pVTable. Then loop through the
140210 ** columns of the table to see if any of them contain the token "hidden".
140211 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
140212 ** the type string. */
140213 pVTable->pNext = pTab->pVTable;
140214 pTab->pVTable = pVTable;
140215
140216 for(iCol=0; iCol<pTab->nCol; iCol++){
140217 char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
140218 int nType;
140219 int i = 0;
140220 nType = sqlite3Strlen30(zType);
140221 for(i=0; i<nType; i++){
140222 if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
140223 && (i==0 || zType[i-1]==' ')
140224 && (zType[i+6]=='\0' || zType[i+6]==' ')
140225 ){
140226 break;
140227 }
140228 }
140229 if( i<nType ){
140230 int j;
140231 int nDel = 6 + (zType[i+6] ? 1 : 0);
140232 for(j=i; (j+nDel)<=nType; j++){
140233 zType[j] = zType[j+nDel];
140234 }
140235 if( zType[i]=='\0' && i>0 ){
140236 assert(zType[i-1]==' ');
140237 zType[i-1] = '\0';
140238 }
140239 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
140240 oooHidden = TF_OOOHidden;
140241 }else{
140242 pTab->tabFlags |= oooHidden;
140243 }
140244 }
#define SQLITE_VTABRISK_Normal
Definition sqlite3.c:17480
VtabCtx * pPrior
Definition sqlite3.c:139598

References Table::aCol, sqlite3::aDb, ALWAYS, Table::azModuleArg, VtabCtx::bDeclared, COLFLAG_HIDDEN, Column::colFlags, VTable::db, VTable::eVtabRisk, Table::nCol, Table::nModuleArg, VTable::nRef, Module::nRefModule, Module::pAux, VTable::pMod, sqlite3_vtab::pModule, Module::pModule, VTable::pNext, VtabCtx::pPrior, Table::pSchema, VtabCtx::pTab, VTable::pVtab, sqlite3::pVtabCtx, Table::pVTable, VtabCtx::pVTable, sqlite3_free(), sqlite3ColumnType(), sqlite3DbFree(), sqlite3DbStrDup(), sqlite3MallocZero(), sqlite3MPrintf(), sqlite3OomFault(), sqlite3SchemaToIndex(), sqlite3Strlen30(), sqlite3StrNICmp, sqlite3VtabUnlock(), SQLITE_ERROR, SQLITE_LOCKED, SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_VTABRISK_Normal, Table::tabFlags, TF_OOOHidden, Db::zDbSName, and Table::zName.

Referenced by sqlite3VtabCallConnect(), sqlite3VtabCallCreate(), and sqlite3VtabEponymousTableInit().

◆ vtabDisconnectAll()

static VTable * vtabDisconnectAll ( sqlite3 * db,
Table * p )
static

Definition at line 139799 of file sqlite3.c.

139805 {
139806 VTable *pRet = 0;
139807 VTable *pVTable = p->pVTable;
139808 p->pVTable = 0;
139809
139810 /* Assert that the mutex (if any) associated with the BtShared database
139811 ** that contains table p is held by the caller. See header comments
139812 ** above function sqlite3VtabUnlockList() for an explanation of why
139813 ** this makes it safe to access the sqlite3.pDisconnect list of any
139814 ** database connection that may have an entry in the p->pVTable list.
139815 */
139816 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
139817
139818 while( pVTable ){
139819 sqlite3 *db2 = pVTable->db;
139820 VTable *pNext = pVTable->pNext;
139821 assert( db2 );
139822 if( db2==db ){
139823 pRet = pVTable;
139824 p->pVTable = pRet;
139825 pRet->pNext = 0;
139826 }else{
139827 pVTable->pNext = db2->pDisconnect;
139828 db2->pDisconnect = pVTable;
139829 }

References VTable::db, sqlite3::pDisconnect, VTable::pNext, Table::pSchema, and Table::pVTable.

Referenced by sqlite3VtabCallDestroy(), and sqlite3VtabClear().

◆ walBeginShmUnreliable()

static int walBeginShmUnreliable ( Wal * pWal,
int * pChanged )
static

Definition at line 61808 of file sqlite3.c.

61814 {
61815 i64 szWal; /* Size of wal file on disk in bytes */
61816 i64 iOffset; /* Current offset when reading wal file */
61817 u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */
61818 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
61819 int szFrame; /* Number of bytes in buffer aFrame[] */
61820 u8 *aData; /* Pointer to data part of aFrame buffer */
61821 volatile void *pDummy; /* Dummy argument for xShmMap */
61822 int rc; /* Return code */
61823 u32 aSaveCksum[2]; /* Saved copy of pWal->hdr.aFrameCksum */
61824
61825 assert( pWal->bShmUnreliable );
61826 assert( pWal->readOnly & WAL_SHM_RDONLY );
61827 assert( pWal->nWiData>0 && pWal->apWiData[0] );
61828
61829 /* Take WAL_READ_LOCK(0). This has the effect of preventing any
61830 ** writers from running a checkpoint, but does not stop them
61831 ** from running recovery. */
61832 rc = walLockShared(pWal, WAL_READ_LOCK(0));
61833 if( rc!=SQLITE_OK ){
61834 if( rc==SQLITE_BUSY ) rc = WAL_RETRY;
61835 goto begin_unreliable_shm_out;
61836 }
61837 pWal->readLock = 0;
61838
61839 /* Check to see if a separate writer has attached to the shared-memory area,
61840 ** thus making the shared-memory "reliable" again. Do this by invoking
61841 ** the xShmMap() routine of the VFS and looking to see if the return
61842 ** is SQLITE_READONLY instead of SQLITE_READONLY_CANTINIT.
61843 **
61844 ** If the shared-memory is now "reliable" return WAL_RETRY, which will
61845 ** cause the heap-memory WAL-index to be discarded and the actual
61846 ** shared memory to be used in its place.
61847 **
61848 ** This step is important because, even though this connection is holding
61849 ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might
61850 ** have already checkpointed the WAL file and, while the current
61851 ** is active, wrap the WAL and start overwriting frames that this
61852 ** process wants to use.
61853 **
61854 ** Once sqlite3OsShmMap() has been called for an sqlite3_file and has
61855 ** returned any SQLITE_READONLY value, it must return only SQLITE_READONLY
61856 ** or SQLITE_READONLY_CANTINIT or some error for all subsequent invocations,
61857 ** even if some external agent does a "chmod" to make the shared-memory
61858 ** writable by us, until sqlite3OsShmUnmap() has been called.
61859 ** This is a requirement on the VFS implementation.
61860 */
61861 rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy);
61862 assert( rc!=SQLITE_OK ); /* SQLITE_OK not possible for read-only connection */
61863 if( rc!=SQLITE_READONLY_CANTINIT ){
61864 rc = (rc==SQLITE_READONLY ? WAL_RETRY : rc);
61865 goto begin_unreliable_shm_out;
61866 }
61867
61868 /* We reach this point only if the real shared-memory is still unreliable.
61869 ** Assume the in-memory WAL-index substitute is correct and load it
61870 ** into pWal->hdr.
61871 */
61872 memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr));
61873
61874 /* Make sure some writer hasn't come in and changed the WAL file out
61875 ** from under us, then disconnected, while we were not looking.
61876 */
61877 rc = sqlite3OsFileSize(pWal->pWalFd, &szWal);
61878 if( rc!=SQLITE_OK ){
61879 goto begin_unreliable_shm_out;
61880 }
61881 if( szWal<WAL_HDRSIZE ){
61882 /* If the wal file is too small to contain a wal-header and the
61883 ** wal-index header has mxFrame==0, then it must be safe to proceed
61884 ** reading the database file only. However, the page cache cannot
61885 ** be trusted, as a read/write connection may have connected, written
61886 ** the db, run a checkpoint, truncated the wal file and disconnected
61887 ** since this client's last read transaction. */
61888 *pChanged = 1;
61889 rc = (pWal->hdr.mxFrame==0 ? SQLITE_OK : WAL_RETRY);
61890 goto begin_unreliable_shm_out;
61891 }
61892
61893 /* Check the salt keys at the start of the wal file still match. */
61894 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
61895 if( rc!=SQLITE_OK ){
61896 goto begin_unreliable_shm_out;
61897 }
61898 if( memcmp(&pWal->hdr.aSalt, &aBuf[16], 8) ){
61899 /* Some writer has wrapped the WAL file while we were not looking.
61900 ** Return WAL_RETRY which will cause the in-memory WAL-index to be
61901 ** rebuilt. */
61902 rc = WAL_RETRY;
61903 goto begin_unreliable_shm_out;
61904 }
61905
61906 /* Allocate a buffer to read frames into */
61907 szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
61908 aFrame = (u8 *)sqlite3_malloc64(szFrame);
61909 if( aFrame==0 ){
61910 rc = SQLITE_NOMEM_BKPT;
61911 goto begin_unreliable_shm_out;
61912 }
61913 aData = &aFrame[WAL_FRAME_HDRSIZE];
61914
61915 /* Check to see if a complete transaction has been appended to the
61916 ** wal file since the heap-memory wal-index was created. If so, the
61917 ** heap-memory wal-index is discarded and WAL_RETRY returned to
61918 ** the caller. */
61919 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
61920 aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
61921 for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage);
61922 iOffset+szFrame<=szWal;
61923 iOffset+=szFrame
61924 ){
61925 u32 pgno; /* Database page number for frame */
61926 u32 nTruncate; /* dbsize field from frame header */
61927
61928 /* Read and decode the next log frame. */
61929 rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
61930 if( rc!=SQLITE_OK ) break;
61931 if( !walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame) ) break;
61932
61933 /* If nTruncate is non-zero, then a complete transaction has been
61934 ** appended to this wal file. Set rc to WAL_RETRY and break out of
61935 ** the loop. */
61936 if( nTruncate ){
61937 rc = WAL_RETRY;
61938 break;
61939 }
61940 }
61941 pWal->hdr.aFrameCksum[0] = aSaveCksum[0];
61942 pWal->hdr.aFrameCksum[1] = aSaveCksum[1];
61943
61944 begin_unreliable_shm_out:
61945 sqlite3_free(aFrame);
61946 if( rc!=SQLITE_OK ){
61947 int i;
61948 for(i=0; i<pWal->nWiData; i++){
61949 sqlite3_free((void*)pWal->apWiData[i]);
61950 pWal->apWiData[i] = 0;
61951 }
#define WALINDEX_PGSZ
Definition sqlite3.c:59939
#define WAL_SHM_RDONLY
Definition sqlite3.c:59884
static int walDecodeFrame(Wal *pWal, u32 *piPage, u32 *pnTruncate, u8 *aData, u8 *aFrame)
Definition sqlite3.c:60177
volatile u32 ** apWiData
Definition sqlite3.c:59844
int nWiData
Definition sqlite3.c:59842

References WalIndexHdr::aFrameCksum, Wal::apWiData, WalIndexHdr::aSalt, Wal::bShmUnreliable, Wal::hdr, WalIndexHdr::mxFrame, Wal::nWiData, Wal::pDbFd, Wal::pWalFd, Wal::readLock, Wal::readOnly, sqlite3_free(), sqlite3_malloc64(), sqlite3OsFileSize(), sqlite3OsRead(), sqlite3OsShmMap(), sqlite3WalEndReadTransaction(), SQLITE_BUSY, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_READONLY, SQLITE_READONLY_CANTINIT, WalIndexHdr::szPage, WAL_FRAME_HDRSIZE, WAL_HDRSIZE, WAL_READ_LOCK, WAL_RETRY, WAL_SHM_RDONLY, walDecodeFrame(), walFrameOffset, WALINDEX_PGSZ, walIndexHdr(), and walLockShared().

Referenced by walTryBeginRead().

◆ walBusyLock()

static int walBusyLock ( Wal * pWal,
int(*)(void *) xBusy,
void * pBusyArg,
int lockIdx,
int n )
static

Definition at line 61238 of file sqlite3.c.

61250 {
61251 int rc;
61252 do {
61253 rc = walLockExclusive(pWal, lockIdx, n);
61254 }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) );
61255#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61256 if( rc==SQLITE_BUSY_TIMEOUT ){

References SQLITE_BUSY, SQLITE_BUSY_TIMEOUT, walDisableBlocking, and walLockExclusive().

Referenced by sqlite3WalCheckpoint(), and walCheckpoint().

◆ walCheckpoint()

static int walCheckpoint ( Wal * pWal,
sqlite3 * db,
int eMode,
int(*)(void *) xBusy,
void * pBusyArg,
int sync_flags,
u8 * zBuf )
static

Definition at line 61330 of file sqlite3.c.

61344 {
61345 int rc = SQLITE_OK; /* Return code */
61346 int szPage; /* Database page-size */
61347 WalIterator *pIter = 0; /* Wal iterator context */
61348 u32 iDbpage = 0; /* Next database page to write */
61349 u32 iFrame = 0; /* Wal frame containing data for iDbpage */
61350 u32 mxSafeFrame; /* Max frame that can be backfilled */
61351 u32 mxPage; /* Max database page to write */
61352 int i; /* Loop counter */
61353 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
61354
61355 szPage = walPagesize(pWal);
61356 testcase( szPage<=32768 );
61357 testcase( szPage>=65536 );
61358 pInfo = walCkptInfo(pWal);
61359 if( pInfo->nBackfill<pWal->hdr.mxFrame ){
61360
61361 /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
61362 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
61363 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
61364
61365 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
61366 ** safe to write into the database. Frames beyond mxSafeFrame might
61367 ** overwrite database pages that are in use by active readers and thus
61368 ** cannot be backfilled from the WAL.
61369 */
61370 mxSafeFrame = pWal->hdr.mxFrame;
61371 mxPage = pWal->hdr.nPage;
61372 for(i=1; i<WAL_NREADER; i++){
61373 u32 y = AtomicLoad(pInfo->aReadMark+i);
61374 if( mxSafeFrame>y ){
61375 assert( y<=pWal->hdr.mxFrame );
61376 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
61377 if( rc==SQLITE_OK ){
61378 u32 iMark = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
61379 AtomicStore(pInfo->aReadMark+i, iMark);
61380 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
61381 }else if( rc==SQLITE_BUSY ){
61382 mxSafeFrame = y;
61383 xBusy = 0;
61384 }else{
61385 goto walcheckpoint_out;
61386 }
61387 }
61388 }
61389
61390 /* Allocate the iterator */
61391 if( pInfo->nBackfill<mxSafeFrame ){
61392 rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter);
61393 assert( rc==SQLITE_OK || pIter==0 );
61394 }
61395
61396 if( pIter
61397 && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
61398 ){
61399 u32 nBackfill = pInfo->nBackfill;
61400
61401 pInfo->nBackfillAttempted = mxSafeFrame;
61402
61403 /* Sync the WAL to disk */
61404 rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
61405
61406 /* If the database may grow as a result of this checkpoint, hint
61407 ** about the eventual size of the db file to the VFS layer.
61408 */
61409 if( rc==SQLITE_OK ){
61410 i64 nReq = ((i64)mxPage * szPage);
61411 i64 nSize; /* Current size of database file */
61413 rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
61414 if( rc==SQLITE_OK && nSize<nReq ){
61415 if( (nSize+65536+(i64)pWal->hdr.mxFrame*szPage)<nReq ){
61416 /* If the size of the final database is larger than the current
61417 ** database plus the amount of data in the wal file, plus the
61418 ** maximum size of the pending-byte page (65536 bytes), then
61419 ** must be corruption somewhere. */
61421 }else{
61423 }
61424 }
61425
61426 }
61427
61428 /* Iterate through the contents of the WAL, copying data to the db file */
61429 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
61430 i64 iOffset;
61431 assert( walFramePgno(pWal, iFrame)==iDbpage );
61432 if( AtomicLoad(&db->u1.isInterrupted) ){
61434 break;
61435 }
61436 if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
61437 continue;
61438 }
61439 iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
61440 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
61441 rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
61442 if( rc!=SQLITE_OK ) break;
61443 iOffset = (iDbpage-1)*(i64)szPage;
61444 testcase( IS_BIG_INT(iOffset) );
61445 rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
61446 if( rc!=SQLITE_OK ) break;
61447 }
61449
61450 /* If work was actually accomplished... */
61451 if( rc==SQLITE_OK ){
61452 if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
61453 i64 szDb = pWal->hdr.nPage*(i64)szPage;
61454 testcase( IS_BIG_INT(szDb) );
61455 rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
61456 if( rc==SQLITE_OK ){
61457 rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
61458 }
61459 }
61460 if( rc==SQLITE_OK ){
61461 AtomicStore(&pInfo->nBackfill, mxSafeFrame);
61462 }
61463 }
61464
61465 /* Release the reader lock held while backfilling */
61466 walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1);
61467 }
61468
61469 if( rc==SQLITE_BUSY ){
61470 /* Reset the return code so as not to report a checkpoint failure
61471 ** just because there are active readers. */
61472 rc = SQLITE_OK;
61473 }
61474 }
61475
61476 /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the
61477 ** entire wal file has been copied into the database file, then block
61478 ** until all readers have finished using the wal file. This ensures that
61479 ** the next process to write to the database restarts the wal file.
61480 */
61481 if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){
61482 assert( pWal->writeLock );
61483 if( pInfo->nBackfill<pWal->hdr.mxFrame ){
61484 rc = SQLITE_BUSY;
61485 }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){
61486 u32 salt1;
61487 sqlite3_randomness(4, &salt1);
61488 assert( pInfo->nBackfill==pWal->hdr.mxFrame );
61489 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1);
61490 if( rc==SQLITE_OK ){
61491 if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){
61492 /* IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as
61493 ** SQLITE_CHECKPOINT_RESTART with the addition that it also
61494 ** truncates the log file to zero bytes just prior to a
61495 ** successful return.
61496 **
61497 ** In theory, it might be safe to do this without updating the
61498 ** wal-index header in shared memory, as all subsequent reader or
61499 ** writer clients should see that the entire log file has been
61500 ** checkpointed and behave accordingly. This seems unsafe though,
61501 ** as it would leave the system in a state where the contents of
61502 ** the wal-index header do not match the contents of the
61503 ** file-system. To avoid this, update the wal-index header to
61504 ** indicate that the log file contains zero valid frames. */
61505 walRestartHdr(pWal, salt1);
61506 rc = sqlite3OsTruncate(pWal->pWalFd, 0);
61507 }
61509 }
61510 }
#define WAL_NREADER
Definition sqlite3.c:59693
static int walIteratorNext(WalIterator *p, u32 *piPage, u32 *piFrame)
Definition sqlite3.c:60884
#define SQLITE_FCNTL_CKPT_START
Definition sqlite3.c:2216
#define READMARK_NOT_USED
Definition sqlite3.c:59795
#define IS_BIG_INT(X)
Definition sqlite3.c:13828
static void walRestartHdr(Wal *pWal, u32 salt1)
Definition sqlite3.c:61283
#define SQLITE_FCNTL_CKPT_DONE
Definition sqlite3.c:2214
static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp)
Definition sqlite3.c:61074

References WalCkptInfo::aReadMark, AtomicLoad, AtomicStore, CKPT_SYNC_FLAGS, Wal::hdr, IS_BIG_INT, sqlite3::isInterrupted, sqlite3::mallocFailed, WalIndexHdr::mxFrame, WalCkptInfo::nBackfill, WalCkptInfo::nBackfillAttempted, WalIndexHdr::nPage, Wal::pDbFd, Wal::pWalFd, READMARK_NOT_USED, sqlite3_randomness(), sqlite3OsFileControl(), sqlite3OsFileControlHint(), sqlite3OsFileSize(), sqlite3OsRead(), sqlite3OsSync(), sqlite3OsTruncate(), sqlite3OsWrite(), SQLITE_BUSY, SQLITE_CHECKPOINT_PASSIVE, SQLITE_CHECKPOINT_RESTART, SQLITE_CHECKPOINT_TRUNCATE, SQLITE_CORRUPT_BKPT, SQLITE_FCNTL_CKPT_DONE, SQLITE_FCNTL_CKPT_START, SQLITE_FCNTL_SIZE_HINT, SQLITE_INTERRUPT, SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, sqlite3::u1, WAL_FRAME_HDRSIZE, WAL_NREADER, WAL_READ_LOCK, walBusyLock(), walCkptInfo(), walFrameOffset, walFramePgno(), walIndexHdr(), walIteratorFree(), walIteratorInit(), walIteratorNext(), walPagesize(), walRestartHdr(), walUnlockExclusive(), and Wal::writeLock.

Referenced by sqlite3WalCheckpoint().

◆ walChecksumBytes()

static void walChecksumBytes ( int nativeCksum,
u8 * a,
int nByte,
const u32 * aIn,
u32 * aOut )
static

Definition at line 60052 of file sqlite3.c.

60064 {
60065 u32 s1, s2;
60066 u32 *aData = (u32 *)a;
60067 u32 *aEnd = (u32 *)&a[nByte];
60068
60069 if( aIn ){
60070 s1 = aIn[0];
60071 s2 = aIn[1];
60072 }else{
60073 s1 = s2 = 0;
60074 }
60075
60076 assert( nByte>=8 );
60077 assert( (nByte&0x00000007)==0 );
60078 assert( nByte<=65536 );
60079
60080 if( nativeCksum ){
60081 do {
60082 s1 += *aData++ + s2;
60083 s2 += *aData++ + s1;
60084 }while( aData<aEnd );
60085 }else{
60086 do {
60087 s1 += BYTESWAP32(aData[0]) + s2;
60088 s2 += BYTESWAP32(aData[1]) + s1;
60089 aData += 2;
#define BYTESWAP32(x)
Definition sqlite3.c:60038

References BYTESWAP32.

Referenced by walDecodeFrame(), walEncodeFrame(), walIndexRecover(), walIndexTryHdr(), and walIndexWriteHdr().

◆ walCkptInfo()

static volatile WalCkptInfo * walCkptInfo ( Wal * pWal)
static

◆ walCleanupHash()

static void walCleanupHash ( Wal * pWal)
static

Definition at line 60394 of file sqlite3.c.

60400 {
60401 WalHashLoc sLoc; /* Hash table location */
60402 int iLimit = 0; /* Zero values greater than this */
60403 int nByte; /* Number of bytes to zero in aPgno[] */
60404 int i; /* Used to iterate through aHash[] */
60405 int rc; /* Return code form walHashGet() */
60406
60407 assert( pWal->writeLock );
60411
60412 if( pWal->hdr.mxFrame==0 ) return;
60413
60414 /* Obtain pointers to the hash-table and page-number array containing
60415 ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
60416 ** that the page said hash-table and array reside on is already mapped.(1)
60417 */
60418 assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
60419 assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
60420 rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
60421 if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */
60422
60423 /* Zero all hash-table entries that correspond to frame numbers greater
60424 ** than pWal->hdr.mxFrame.
60425 */
60426 iLimit = pWal->hdr.mxFrame - sLoc.iZero;
60427 assert( iLimit>0 );
60428 for(i=0; i<HASHTABLE_NSLOT; i++){
60429 if( sLoc.aHash[i]>iLimit ){
60430 sLoc.aHash[i] = 0;
60431 }
60432 }
60433
60434 /* Zero the entries in the aPgno array that correspond to frames with
60435 ** frame numbers greater than pWal->hdr.mxFrame.
60436 */
60437 nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit+1]);
60438 memset((void *)&sLoc.aPgno[iLimit+1], 0, nByte);
60439
60440#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
60441 /* Verify that the every entry in the mapping region is still reachable
60442 ** via the hash table even after the cleanup.
60443 */
60444 if( iLimit ){
60445 int j; /* Loop counter */
60446 int iKey; /* Hash key */
60447 for(j=1; j<=iLimit; j++){
60448 for(iKey=walHash(sLoc.aPgno[j]);sLoc.aHash[iKey];iKey=walNextHash(iKey)){
60449 if( sLoc.aHash[iKey]==j ) break;
#define HASHTABLE_NPAGE_ONE
Definition sqlite3.c:59936

References WalHashLoc::aHash, WalHashLoc::aPgno, Wal::apWiData, HASHTABLE_NPAGE_ONE, HASHTABLE_NSLOT, Wal::hdr, WalHashLoc::iZero, WalIndexHdr::mxFrame, NEVER, Wal::nWiData, testcase, walFramePage(), walHash(), walHashGet(), walNextHash(), and Wal::writeLock.

Referenced by sqlite3WalSavepointUndo(), sqlite3WalUndo(), and walIndexAppend().

◆ walDecodeFrame()

static int walDecodeFrame ( Wal * pWal,
u32 * piPage,
u32 * pnTruncate,
u8 * aData,
u8 * aFrame )
static

Definition at line 60177 of file sqlite3.c.

60189 {
60190 int nativeCksum; /* True for native byte-order checksums */
60191 u32 *aCksum = pWal->hdr.aFrameCksum;
60192 u32 pgno; /* Page number of the frame */
60193 assert( WAL_FRAME_HDRSIZE==24 );
60194
60195 /* A frame is only valid if the salt values in the frame-header
60196 ** match the salt values in the wal-header.
60197 */
60198 if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
60199 return 0;
60200 }
60201
60202 /* A frame is only valid if the page number is creater than zero.
60203 */
60204 pgno = sqlite3Get4byte(&aFrame[0]);
60205 if( pgno==0 ){
60206 return 0;
60207 }
60208
60209 /* A frame is only valid if a checksum of the WAL header,
60210 ** all prior frams, the first 16 bytes of this frame-header,
60211 ** and the frame-data matches the checksum in the last 8
60212 ** bytes of this frame-header.
60213 */
60214 nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
60215 walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
60216 walChecksumBytes(nativeCksum, aData, pWal->szPage, aCksum, aCksum);
60217 if( aCksum[0]!=sqlite3Get4byte(&aFrame[16])
60218 || aCksum[1]!=sqlite3Get4byte(&aFrame[20])
60219 ){
60220 /* Checksum failed. */
60221 return 0;
60222 }
60223
60224 /* If we reach this point, the frame is valid. Return the page number

References WalIndexHdr::aFrameCksum, WalIndexHdr::aSalt, WalIndexHdr::bigEndCksum, Wal::hdr, sqlite3Get4byte(), SQLITE_BIGENDIAN, Wal::szPage, WAL_FRAME_HDRSIZE, and walChecksumBytes().

Referenced by walBeginShmUnreliable(), and walIndexRecover().

◆ walEncodeFrame()

static void walEncodeFrame ( Wal * pWal,
u32 iPage,
u32 nTruncate,
u8 * aData,
u8 * aFrame )
static

Definition at line 60146 of file sqlite3.c.

60147 : Salt-1 (copied from the wal-header)
60148** 12: Salt-2 (copied from the wal-header)
60149** 16: Checksum-1.
60150** 20: Checksum-2.
60151*/
60152static void walEncodeFrame(
60153 Wal *pWal, /* The write-ahead log */
60154 u32 iPage, /* Database page number for frame */
60155 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
60156 u8 *aData, /* Pointer to page data */
60157 u8 *aFrame /* OUT: Write encoded frame here */
60158){
60159 int nativeCksum; /* True for native byte-order checksums */
60160 u32 *aCksum = pWal->hdr.aFrameCksum;
60161 assert( WAL_FRAME_HDRSIZE==24 );
60162 sqlite3Put4byte(&aFrame[0], iPage);
60163 sqlite3Put4byte(&aFrame[4], nTruncate);
60164 if( pWal->iReCksum==0 ){
60165 memcpy(&aFrame[8], pWal->hdr.aSalt, 8);
60166
60167 nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
60168 walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
60169 walChecksumBytes(nativeCksum, aData, pWal->szPage, aCksum, aCksum);
60170
static void walEncodeFrame(Wal *pWal, u32 iPage, u32 nTruncate, u8 *aData, u8 *aFrame)
Definition sqlite3.c:60146

References WalIndexHdr::aFrameCksum, WalIndexHdr::aSalt, WalIndexHdr::bigEndCksum, Wal::hdr, Wal::iReCksum, sqlite3Put4byte(), SQLITE_BIGENDIAN, Wal::szPage, WAL_FRAME_HDRSIZE, and walChecksumBytes().

Referenced by walRewriteChecksums().

◆ walFramePage()

static int walFramePage ( u32 iFrame)
static

Definition at line 60359 of file sqlite3.c.

60365 {
60366 int iHash = (iFrame+HASHTABLE_NPAGE-HASHTABLE_NPAGE_ONE-1) / HASHTABLE_NPAGE;
60367 assert( (iHash==0 || iFrame>HASHTABLE_NPAGE_ONE)
60368 && (iHash>=1 || iFrame<=HASHTABLE_NPAGE_ONE)
60369 && (iHash<=1 || iFrame>(HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE))

References HASHTABLE_NPAGE, and HASHTABLE_NPAGE_ONE.

Referenced by sqlite3WalFindFrame(), walCleanupHash(), walIndexAppend(), walIndexRecover(), and walIteratorInit().

◆ walFramePgno()

static u32 walFramePgno ( Wal * pWal,
u32 iFrame )
static

Definition at line 60374 of file sqlite3.c.

60380 {

Referenced by sqlite3WalFindFrame(), sqlite3WalUndo(), and walCheckpoint().

◆ walHash()

static int walHash ( u32 iPage)
static

Definition at line 60295 of file sqlite3.c.

Referenced by sqlite3WalFindFrame(), walCleanupHash(), and walIndexAppend().

◆ walHashGet()

static int walHashGet ( Wal * pWal,
int iHash,
WalHashLoc * pLoc )
static

Definition at line 60330 of file sqlite3.c.

60340 {
60341 int rc; /* Return code */
60342
60343 rc = walIndexPage(pWal, iHash, &pLoc->aPgno);
60344 assert( rc==SQLITE_OK || iHash>0 );
60345
60346 if( rc==SQLITE_OK ){
60347 pLoc->aHash = (volatile ht_slot *)&pLoc->aPgno[HASHTABLE_NPAGE];
60348 if( iHash==0 ){
60349 pLoc->aPgno = &pLoc->aPgno[WALINDEX_HDR_SIZE/sizeof(u32)];
60350 pLoc->iZero = 0;
60351 }else{
static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage)
Definition sqlite3.c:60004

References WalHashLoc::aHash, WalHashLoc::aPgno, HASHTABLE_NPAGE, HASHTABLE_NPAGE_ONE, WalHashLoc::iZero, SQLITE_OK, WALINDEX_HDR_SIZE, and walIndexPage().

Referenced by sqlite3WalFindFrame(), walCleanupHash(), walIndexAppend(), and walIteratorInit().

◆ walIndexAppend()

static int walIndexAppend ( Wal * pWal,
u32 iFrame,
u32 iPage )
static

Definition at line 60456 of file sqlite3.c.

60462 {
60463 int rc; /* Return code */
60464 WalHashLoc sLoc; /* Wal-index hash table location */
60465
60466 rc = walHashGet(pWal, walFramePage(iFrame), &sLoc);
60467
60468 /* Assuming the wal-index file was successfully mapped, populate the
60469 ** page number array and hash table entry.
60470 */
60471 if( rc==SQLITE_OK ){
60472 int iKey; /* Hash table key */
60473 int idx; /* Value to write to hash-table slot */
60474 int nCollide; /* Number of hash collisions */
60475
60476 idx = iFrame - sLoc.iZero;
60477 assert( idx <= HASHTABLE_NSLOT/2 + 1 );
60478
60479 /* If this is the first entry to be added to this hash-table, zero the
60480 ** entire hash table and aPgno[] array before proceeding.
60481 */
60482 if( idx==1 ){
60483 int nByte = (int)((u8 *)&sLoc.aHash[HASHTABLE_NSLOT]
60484 - (u8 *)&sLoc.aPgno[1]);
60485 memset((void*)&sLoc.aPgno[1], 0, nByte);
60486 }
60487
60488 /* If the entry in aPgno[] is already set, then the previous writer
60489 ** must have exited unexpectedly in the middle of a transaction (after
60490 ** writing one or more dirty pages to the WAL to free up memory).
60491 ** Remove the remnants of that writers uncommitted transaction from
60492 ** the hash-table before writing any new entries.
60493 */
60494 if( sLoc.aPgno[idx] ){
60495 walCleanupHash(pWal);
60496 assert( !sLoc.aPgno[idx] );
60497 }
60498
60499 /* Write the aPgno[] array entry and the hash-table slot. */
60500 nCollide = idx;
60501 for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
60502 if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
60503 }
60504 sLoc.aPgno[idx] = iPage;
60505 AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx);
60506
60507#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
60508 /* Verify that the number of entries in the hash table exactly equals
60509 ** the number of entries in the mapping region.
60510 */
60511 {
60512 int i; /* Loop counter */
60513 int nEntry = 0; /* Number of entries in the hash table */
60514 for(i=0; i<HASHTABLE_NSLOT; i++){ if( sLoc.aHash[i] ) nEntry++; }
60515 assert( nEntry==idx );
60516 }
60517
60518 /* Verify that the every entry in the mapping region is reachable
60519 ** via the hash table. This turns out to be a really, really expensive
60520 ** thing to check, so only do this occasionally - not on every
60521 ** iteration.
60522 */
60523 if( (idx&0x3ff)==0 ){
60524 int i; /* Loop counter */
60525 for(i=1; i<=idx; i++){
60526 for(iKey=walHash(sLoc.aPgno[i]);
60527 sLoc.aHash[iKey];
60528 iKey=walNextHash(iKey)){
60529 if( sLoc.aHash[iKey]==i ) break;
60530 }
60531 assert( sLoc.aHash[iKey]==i );
60532 }
60533 }
static void walCleanupHash(Wal *pWal)
Definition sqlite3.c:60394

References WalHashLoc::aHash, WalHashLoc::aPgno, AtomicStore, HASHTABLE_NSLOT, WalHashLoc::iZero, SQLITE_CORRUPT_BKPT, SQLITE_OK, walCleanupHash(), walFramePage(), walHash(), walHashGet(), and walNextHash().

Referenced by walIndexRecover().

◆ walIndexClose()

static void walIndexClose ( Wal * pWal,
int isDelete )
static

Definition at line 60768 of file sqlite3.c.

60774 {
60775 if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE || pWal->bShmUnreliable ){
60776 int i;
60777 for(i=0; i<pWal->nWiData; i++){
60778 sqlite3_free((void *)pWal->apWiData[i]);
60779 pWal->apWiData[i] = 0;

Referenced by sqlite3WalOpen(), and walIndexReadHdr().

◆ walIndexHdr()

static volatile WalIndexHdr * walIndexHdr ( Wal * pWal)
static

◆ walIndexPage()

static int walIndexPage ( Wal * pWal,
int iPage,
volatile u32 ** ppPage )
static

Definition at line 60004 of file sqlite3.c.

Referenced by walHashGet(), walIndexReadHdr(), and walIndexRecover().

◆ walIndexPageRealloc()

static SQLITE_NOINLINE int walIndexPageRealloc ( Wal * pWal,
int iPage,
volatile u32 ** ppPage )
static

Definition at line 59957 of file sqlite3.c.

59967 {
59968 int rc = SQLITE_OK;
59969
59970 /* Enlarge the pWal->apWiData[] array if required */
59971 if( pWal->nWiData<=iPage ){
59972 sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
59973 volatile u32 **apNew;
59974 apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte);
59975 if( !apNew ){
59976 *ppPage = 0;
59977 return SQLITE_NOMEM_BKPT;
59978 }
59979 memset((void*)&apNew[pWal->nWiData], 0,
59980 sizeof(u32*)*(iPage+1-pWal->nWiData));
59981 pWal->apWiData = apNew;
59982 pWal->nWiData = iPage+1;
59983 }
59984
59985 /* Request a pointer to the required page from the VFS */
59986 assert( pWal->apWiData[iPage]==0 );
59988 pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ);
59989 if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
59990 }else{
59991 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
59992 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
59993 );
59994 assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
59995 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
59996 if( rc==SQLITE_OK ){
59997 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
59998 }else if( (rc&0xff)==SQLITE_READONLY ){
59999 pWal->readOnly |= WAL_SHM_RDONLY;
60000 if( rc==SQLITE_READONLY ){
60001 rc = SQLITE_OK;
60002 }
60003 }

References Wal::apWiData, Wal::exclusiveMode, Wal::nWiData, Wal::pDbFd, Wal::readOnly, sqlite3FaultSim(), sqlite3MallocZero(), sqlite3OsShmMap(), sqlite3Realloc(), SQLITE_NOMEM, SQLITE_NOMEM_BKPT, SQLITE_OK, SQLITE_READONLY, testcase, WAL_HEAPMEMORY_MODE, WAL_SHM_RDONLY, WALINDEX_PGSZ, and Wal::writeLock.

◆ walIndexReadHdr()

static int walIndexReadHdr ( Wal * pWal,
int * pChanged )
static

Definition at line 61684 of file sqlite3.c.

61690 {
61691 int rc; /* Return code */
61692 int badHdr; /* True if a header read failed */
61693 volatile u32 *page0; /* Chunk of wal-index containing header */
61694
61695 /* Ensure that page 0 of the wal-index (the page that contains the
61696 ** wal-index header) is mapped. Return early if an error occurs here.
61697 */
61698 assert( pChanged );
61699 rc = walIndexPage(pWal, 0, &page0);
61700 if( rc!=SQLITE_OK ){
61701 assert( rc!=SQLITE_READONLY ); /* READONLY changed to OK in walIndexPage */
61702 if( rc==SQLITE_READONLY_CANTINIT ){
61703 /* The SQLITE_READONLY_CANTINIT return means that the shared-memory
61704 ** was openable but is not writable, and this thread is unable to
61705 ** confirm that another write-capable connection has the shared-memory
61706 ** open, and hence the content of the shared-memory is unreliable,
61707 ** since the shared-memory might be inconsistent with the WAL file
61708 ** and there is no writer on hand to fix it. */
61709 assert( page0==0 );
61710 assert( pWal->writeLock==0 );
61711 assert( pWal->readOnly & WAL_SHM_RDONLY );
61712 pWal->bShmUnreliable = 1;
61714 *pChanged = 1;
61715 }else{
61716 return rc; /* Any other non-OK return is just an error */
61717 }
61718 }else{
61719 /* page0 can be NULL if the SHM is zero bytes in size and pWal->writeLock
61720 ** is zero, which prevents the SHM from growing */
61721 testcase( page0!=0 );
61722 }
61723 assert( page0!=0 || pWal->writeLock==0 );
61724
61725 /* If the first page of the wal-index has been mapped, try to read the
61726 ** wal-index header immediately, without holding any lock. This usually
61727 ** works, but may fail if the wal-index header is corrupt or currently
61728 ** being modified by another thread or process.
61729 */
61730 badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1);
61731
61732 /* If the first attempt failed, it might have been due to a race
61733 ** with a writer. So get a WRITE lock and try again.
61734 */
61735 if( badHdr ){
61736 if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){
61737 if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
61740 }
61741 }else{
61742 int bWriteLock = pWal->writeLock;
61743 if( bWriteLock || SQLITE_OK==(rc = walLockWriter(pWal)) ){
61744 pWal->writeLock = 1;
61745 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
61746 badHdr = walIndexTryHdr(pWal, pChanged);
61747 if( badHdr ){
61748 /* If the wal-index header is still malformed even while holding
61749 ** a WRITE lock, it can only mean that the header is corrupted and
61750 ** needs to be reconstructed. So run recovery to do exactly that.
61751 */
61752 rc = walIndexRecover(pWal);
61753 *pChanged = 1;
61754 }
61755 }
61756 if( bWriteLock==0 ){
61757 pWal->writeLock = 0;
61759 }
61760 }
61761 }
61762 }
61763
61764 /* If the header is read successfully, check the version number to make
61765 ** sure the wal-index was not constructed with some future format that
61766 ** this version of SQLite cannot understand.
61767 */
61768 if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){
61770 }
61771 if( pWal->bShmUnreliable ){
61772 if( rc!=SQLITE_OK ){
61773 walIndexClose(pWal, 0);
61774 pWal->bShmUnreliable = 0;
61775 assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
61776 /* walIndexRecover() might have returned SHORT_READ if a concurrent
61777 ** writer truncated the WAL out from under it. If that happens, it
61778 ** indicates that a writer has fixed the SHM file for us, so retry */
61779 if( rc==SQLITE_IOERR_SHORT_READ ) rc = WAL_RETRY;
#define walLockWriter(pWal)
Definition sqlite3.c:61227
static SQLITE_NO_TSAN int walIndexTryHdr(Wal *pWal, int *pChanged)
Definition sqlite3.c:61614
#define WALINDEX_MAX_VERSION
Definition sqlite3.c:59672
static int walIndexRecover(Wal *pWal)
Definition sqlite3.c:60546
#define SQLITE_READONLY_RECOVERY
Definition sqlite3.c:1569

References Wal::apWiData, Wal::bShmUnreliable, Wal::exclusiveMode, Wal::hdr, WalIndexHdr::iVersion, Wal::nWiData, Wal::readOnly, SQLITE_CANTOPEN_BKPT, SQLITE_IOERR_SHORT_READ, SQLITE_OK, SQLITE_READONLY, SQLITE_READONLY_CANTINIT, SQLITE_READONLY_RECOVERY, testcase, WAL_HEAPMEMORY_MODE, WAL_NORMAL_MODE, WAL_RETRY, WAL_SHM_RDONLY, WAL_WRITE_LOCK, WALINDEX_MAX_VERSION, walIndexClose(), walIndexPage(), walIndexRecover(), walIndexTryHdr(), walLockShared(), walLockWriter, walUnlockExclusive(), walUnlockShared(), and Wal::writeLock.

Referenced by sqlite3WalCheckpoint(), and walTryBeginRead().

◆ walIndexRecover()

static int walIndexRecover ( Wal * pWal)
static

Definition at line 60546 of file sqlite3.c.

60552 {
60553 int rc; /* Return Code */
60554 i64 nSize; /* Size of log file */
60555 u32 aFrameCksum[2] = {0, 0};
60556 int iLock; /* Lock offset to lock for checkpoint */
60557
60558 /* Obtain an exclusive lock on all byte in the locking range not already
60559 ** locked by the caller. The caller is guaranteed to have locked the
60560 ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
60561 ** If successful, the same bytes that are locked here are unlocked before
60562 ** this function returns.
60563 */
60564 assert( pWal->ckptLock==1 || pWal->ckptLock==0 );
60565 assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
60567 assert( pWal->writeLock );
60568 iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
60569 rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60570 if( rc ){
60571 return rc;
60572 }
60573
60574 WALTRACE(("WAL%p: recovery begin...\n", pWal));
60575
60576 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
60577
60578 rc = sqlite3OsFileSize(pWal->pWalFd, &nSize);
60579 if( rc!=SQLITE_OK ){
60580 goto recovery_error;
60581 }
60582
60583 if( nSize>WAL_HDRSIZE ){
60584 u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */
60585 u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */
60586 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
60587 int szFrame; /* Number of bytes in buffer aFrame[] */
60588 u8 *aData; /* Pointer to data part of aFrame buffer */
60589 int szPage; /* Page size according to the log */
60590 u32 magic; /* Magic value read from WAL header */
60591 u32 version; /* Magic value read from WAL header */
60592 int isValid; /* True if this frame is valid */
60593 u32 iPg; /* Current 32KB wal-index page */
60594 u32 iLastFrame; /* Last frame in wal, based on nSize alone */
60595
60596 /* Read in the WAL header. */
60597 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
60598 if( rc!=SQLITE_OK ){
60599 goto recovery_error;
60600 }
60601
60602 /* If the database page size is not a power of two, or is greater than
60603 ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
60604 ** data. Similarly, if the 'magic' value is invalid, ignore the whole
60605 ** WAL file.
60606 */
60607 magic = sqlite3Get4byte(&aBuf[0]);
60608 szPage = sqlite3Get4byte(&aBuf[8]);
60609 if( (magic&0xFFFFFFFE)!=WAL_MAGIC
60610 || szPage&(szPage-1)
60611 || szPage>SQLITE_MAX_PAGE_SIZE
60612 || szPage<512
60613 ){
60614 goto finished;
60615 }
60616 pWal->hdr.bigEndCksum = (u8)(magic&0x00000001);
60617 pWal->szPage = szPage;
60618 pWal->nCkpt = sqlite3Get4byte(&aBuf[12]);
60619 memcpy(&pWal->hdr.aSalt, &aBuf[16], 8);
60620
60621 /* Verify that the WAL header checksum is correct */
60623 aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum
60624 );
60625 if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24])
60626 || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[28])
60627 ){
60628 goto finished;
60629 }
60630
60631 /* Verify that the version number on the WAL format is one that
60632 ** are able to understand */
60633 version = sqlite3Get4byte(&aBuf[4]);
60634 if( version!=WAL_MAX_VERSION ){
60636 goto finished;
60637 }
60638
60639 /* Malloc a buffer to read frames into. */
60640 szFrame = szPage + WAL_FRAME_HDRSIZE;
60641 aFrame = (u8 *)sqlite3_malloc64(szFrame + WALINDEX_PGSZ);
60642 if( !aFrame ){
60643 rc = SQLITE_NOMEM_BKPT;
60644 goto recovery_error;
60645 }
60646 aData = &aFrame[WAL_FRAME_HDRSIZE];
60647 aPrivate = (u32*)&aData[szPage];
60648
60649 /* Read all frames from the log file. */
60650 iLastFrame = (nSize - WAL_HDRSIZE) / szFrame;
60651 for(iPg=0; iPg<=(u32)walFramePage(iLastFrame); iPg++){
60652 u32 *aShare;
60653 u32 iFrame; /* Index of last frame read */
60654 u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE);
60655 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
60656 u32 nHdr, nHdr32;
60657 rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare);
60658 if( rc ) break;
60659 pWal->apWiData[iPg] = aPrivate;
60660
60661 for(iFrame=iFirst; iFrame<=iLast; iFrame++){
60662 i64 iOffset = walFrameOffset(iFrame, szPage);
60663 u32 pgno; /* Database page number for frame */
60664 u32 nTruncate; /* dbsize field from frame header */
60665
60666 /* Read and decode the next log frame. */
60667 rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
60668 if( rc!=SQLITE_OK ) break;
60669 isValid = walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame);
60670 if( !isValid ) break;
60671 rc = walIndexAppend(pWal, iFrame, pgno);
60672 if( NEVER(rc!=SQLITE_OK) ) break;
60673
60674 /* If nTruncate is non-zero, this is a commit record. */
60675 if( nTruncate ){
60676 pWal->hdr.mxFrame = iFrame;
60677 pWal->hdr.nPage = nTruncate;
60678 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
60679 testcase( szPage<=32768 );
60680 testcase( szPage>=65536 );
60681 aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
60682 aFrameCksum[1] = pWal->hdr.aFrameCksum[1];
60683 }
60684 }
60685 pWal->apWiData[iPg] = aShare;
60686 nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
60687 nHdr32 = nHdr / sizeof(u32);
60688#ifndef SQLITE_SAFER_WALINDEX_RECOVERY
60689 /* Memcpy() should work fine here, on all reasonable implementations.
60690 ** Technically, memcpy() might change the destination to some
60691 ** intermediate value before setting to the final value, and that might
60692 ** cause a concurrent reader to malfunction. Memcpy() is allowed to
60693 ** do that, according to the spec, but no memcpy() implementation that
60694 ** we know of actually does that, which is why we say that memcpy()
60695 ** is safe for this. Memcpy() is certainly a lot faster.
60696 */
60697 memcpy(&aShare[nHdr32], &aPrivate[nHdr32], WALINDEX_PGSZ-nHdr);
60698#else
60699 /* In the event that some platform is found for which memcpy()
60700 ** changes the destination to some intermediate value before
60701 ** setting the final value, this alternative copy routine is
60702 ** provided.
60703 */
60704 {
60705 int i;
60706 for(i=nHdr32; i<WALINDEX_PGSZ/sizeof(u32); i++){
60707 if( aShare[i]!=aPrivate[i] ){
60708 /* Atomic memory operations are not required here because if
60709 ** the value needs to be changed, that means it is not being
60710 ** accessed concurrently. */
60711 aShare[i] = aPrivate[i];
60712 }
60713 }
60714 }
60715#endif
60716 if( iFrame<=iLast ) break;
60717 }
60718
60719 sqlite3_free(aFrame);
60720 }
60721
60722finished:
60723 if( rc==SQLITE_OK ){
60724 volatile WalCkptInfo *pInfo;
60725 int i;
60726 pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
60727 pWal->hdr.aFrameCksum[1] = aFrameCksum[1];
60728 walIndexWriteHdr(pWal);
60729
60730 /* Reset the checkpoint-header. This is safe because this thread is
60731 ** currently holding locks that exclude all other writers and
60732 ** checkpointers. Then set the values of read-mark slots 1 through N.
60733 */
60734 pInfo = walCkptInfo(pWal);
60735 pInfo->nBackfill = 0;
60736 pInfo->nBackfillAttempted = pWal->hdr.mxFrame;
60737 pInfo->aReadMark[0] = 0;
60738 for(i=1; i<WAL_NREADER; i++){
60739 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
60740 if( rc==SQLITE_OK ){
60741 if( i==1 && pWal->hdr.mxFrame ){
60742 pInfo->aReadMark[i] = pWal->hdr.mxFrame;
60743 }else{
60744 pInfo->aReadMark[i] = READMARK_NOT_USED;
60745 }
60746 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
60747 }else if( rc!=SQLITE_BUSY ){
60748 goto recovery_error;
60749 }
60750 }
60751
60752 /* If more than one frame was recovered from the log file, report an
60753 ** event via sqlite3_log(). This is to help with identifying performance
60754 ** problems caused by applications routinely shutting down without
60755 ** checkpointing the log file.
60756 */
60757 if( pWal->hdr.nPage ){
60759 "recovered %d frames from WAL file %s",
60760 pWal->hdr.mxFrame, pWal->zWalName
60761 );
60762 }
60763 }
#define SQLITE_NOTICE_RECOVER_WAL
Definition sqlite3.c:1587
#define WAL_ALL_BUT_WRITE
Definition sqlite3.c:59689

References WalIndexHdr::aFrameCksum, Wal::apWiData, WalCkptInfo::aReadMark, WalIndexHdr::aSalt, WalIndexHdr::bigEndCksum, Wal::ckptLock, HASHTABLE_NPAGE, HASHTABLE_NPAGE_ONE, Wal::hdr, MIN, WalIndexHdr::mxFrame, WalCkptInfo::nBackfill, WalCkptInfo::nBackfillAttempted, Wal::nCkpt, NEVER, WalIndexHdr::nPage, Wal::pWalFd, READMARK_NOT_USED, sqlite3_free(), sqlite3_log(), sqlite3_malloc64(), sqlite3Get4byte(), sqlite3OsFileSize(), sqlite3OsRead(), SQLITE_BIGENDIAN, SQLITE_BUSY, SQLITE_CANTOPEN_BKPT, SQLITE_MAX_PAGE_SIZE, SQLITE_NOMEM_BKPT, SQLITE_NOTICE_RECOVER_WAL, SQLITE_OK, WalIndexHdr::szPage, Wal::szPage, testcase, WAL_ALL_BUT_WRITE, WAL_CKPT_LOCK, WAL_FRAME_HDRSIZE, WAL_HDRSIZE, WAL_MAGIC, WAL_MAX_VERSION, WAL_NREADER, WAL_READ_LOCK, WAL_WRITE_LOCK, walChecksumBytes(), walCkptInfo(), walDecodeFrame(), walFrameOffset, walFramePage(), WALINDEX_HDR_SIZE, WALINDEX_PGSZ, walIndexAppend(), walIndexPage(), walIndexWriteHdr(), walLockExclusive(), WALTRACE, walUnlockExclusive(), Wal::writeLock, and Wal::zWalName.

Referenced by walIndexReadHdr().

◆ walIndexTryHdr()

static SQLITE_NO_TSAN int walIndexTryHdr ( Wal * pWal,
int * pChanged )
static

Definition at line 61614 of file sqlite3.c.

61620 {
61621 u32 aCksum[2]; /* Checksum on the header content */
61622 WalIndexHdr h1, h2; /* Two copies of the header content */
61623 WalIndexHdr volatile *aHdr; /* Header in shared memory */
61624
61625 /* The first page of the wal-index must be mapped at this point. */
61626 assert( pWal->nWiData>0 && pWal->apWiData[0] );
61627
61628 /* Read the header. This might happen concurrently with a write to the
61629 ** same area of shared memory on a different CPU in a SMP,
61630 ** meaning it is possible that an inconsistent snapshot is read
61631 ** from the file. If this happens, return non-zero.
61632 **
61633 ** tag-20200519-1:
61634 ** There are two copies of the header at the beginning of the wal-index.
61635 ** When reading, read [0] first then [1]. Writes are in the reverse order.
61636 ** Memory barriers are used to prevent the compiler or the hardware from
61637 ** reordering the reads and writes. TSAN and similar tools can sometimes
61638 ** give false-positive warnings about these accesses because the tools do not
61639 ** account for the double-read and the memory barrier. The use of mutexes
61640 ** here would be problematic as the memory being accessed is potentially
61641 ** shared among multiple processes and not all mutex implementions work
61642 ** reliably in that environment.
61643 */
61644 aHdr = walIndexHdr(pWal);
61645 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
61646 walShmBarrier(pWal);
61647 memcpy(&h2, (void *)&aHdr[1], sizeof(h2));
61648
61649 if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
61650 return 1; /* Dirty read */
61651 }
61652 if( h1.isInit==0 ){
61653 return 1; /* Malformed header - probably all zeros */
61654 }
61655 walChecksumBytes(1, (u8*)&h1, sizeof(h1)-sizeof(h1.aCksum), 0, aCksum);
61656 if( aCksum[0]!=h1.aCksum[0] || aCksum[1]!=h1.aCksum[1] ){
61657 return 1; /* Checksum does not match */
61658 }
61659
61660 if( memcmp(&pWal->hdr, &h1, sizeof(WalIndexHdr)) ){
61661 *pChanged = 1;
61662 memcpy(&pWal->hdr, &h1, sizeof(WalIndexHdr));
61663 pWal->szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
61664 testcase( pWal->szPage<=32768 );
static void walShmBarrier(Wal *pWal)
Definition sqlite3.c:60095

References WalIndexHdr::aCksum, Wal::apWiData, Wal::hdr, WalIndexHdr::isInit, Wal::nWiData, WalIndexHdr::szPage, Wal::szPage, testcase, walChecksumBytes(), walIndexHdr(), and walShmBarrier().

Referenced by walIndexReadHdr().

◆ walIndexWriteHdr()

static SQLITE_NO_TSAN void walIndexWriteHdr ( Wal * pWal)
static

Definition at line 60119 of file sqlite3.c.

60125 {
60126 volatile WalIndexHdr *aHdr = walIndexHdr(pWal);
60127 const int nCksum = offsetof(WalIndexHdr, aCksum);
60128
60129 assert( pWal->writeLock );
60130 pWal->hdr.isInit = 1;

References WalIndexHdr::aCksum, Wal::hdr, WalIndexHdr::isInit, WalIndexHdr::iVersion, offsetof, walChecksumBytes(), WALINDEX_MAX_VERSION, walIndexHdr(), walShmBarrier(), and Wal::writeLock.

Referenced by walIndexRecover(), and walRestartHdr().

◆ walIteratorFree()

static void walIteratorFree ( WalIterator * p)
static

Definition at line 61057 of file sqlite3.c.

Referenced by walCheckpoint(), and walIteratorInit().

◆ walIteratorInit()

static int walIteratorInit ( Wal * pWal,
u32 nBackfill,
WalIterator ** pp )
static

Definition at line 61074 of file sqlite3.c.

61080 {
61081 WalIterator *p; /* Return value */
61082 int nSegment; /* Number of segments to merge */
61083 u32 iLast; /* Last frame in log */
61084 sqlite3_int64 nByte; /* Number of bytes to allocate */
61085 int i; /* Iterator variable */
61086 ht_slot *aTmp; /* Temp space used by merge-sort */
61087 int rc = SQLITE_OK; /* Return Code */
61088
61089 /* This routine only runs while holding the checkpoint lock. And
61090 ** it only runs if there is actually content in the log (mxFrame>0).
61091 */
61092 assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
61093 iLast = pWal->hdr.mxFrame;
61094
61095 /* Allocate space for the WalIterator object. */
61096 nSegment = walFramePage(iLast) + 1;
61097 nByte = sizeof(WalIterator)
61098 + (nSegment-1)*sizeof(struct WalSegment)
61099 + iLast*sizeof(ht_slot);
61100 p = (WalIterator *)sqlite3_malloc64(nByte);
61101 if( !p ){
61102 return SQLITE_NOMEM_BKPT;
61103 }
61104 memset(p, 0, nByte);
61105 p->nSegment = nSegment;
61106
61107 /* Allocate temporary space used by the merge-sort routine. This block
61108 ** of memory will be freed before this function returns.
61109 */
61110 aTmp = (ht_slot *)sqlite3_malloc64(
61111 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
61112 );
61113 if( !aTmp ){
61114 rc = SQLITE_NOMEM_BKPT;
61115 }
61116
61117 for(i=walFramePage(nBackfill+1); rc==SQLITE_OK && i<nSegment; i++){
61118 WalHashLoc sLoc;
61119
61120 rc = walHashGet(pWal, i, &sLoc);
61121 if( rc==SQLITE_OK ){
61122 int j; /* Counter variable */
61123 int nEntry; /* Number of entries in this segment */
61124 ht_slot *aIndex; /* Sorted index for this segment */
61125
61126 sLoc.aPgno++;
61127 if( (i+1)==nSegment ){
61128 nEntry = (int)(iLast - sLoc.iZero);
61129 }else{
61130 nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
61131 }
61132 aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[sLoc.iZero];
61133 sLoc.iZero++;
61134
61135 for(j=0; j<nEntry; j++){
61136 aIndex[j] = (ht_slot)j;
61137 }
61138 walMergesort((u32 *)sLoc.aPgno, aTmp, aIndex, &nEntry);
61139 p->aSegment[i].iZero = sLoc.iZero;
61140 p->aSegment[i].nEntry = nEntry;
61141 p->aSegment[i].aIndex = aIndex;
61142 p->aSegment[i].aPgno = (u32 *)sLoc.aPgno;
61143 }
61144 }
61145 sqlite3_free(aTmp);
61146
61147 if( rc!=SQLITE_OK ){
struct WalIterator WalIterator
Definition sqlite3.c:59698
static void walMergesort(const u32 *aContent, ht_slot *aBuffer, ht_slot *aList, int *pnList)
Definition sqlite3.c:60994

References WalHashLoc::aHash, WalIterator::WalSegment::aIndex, WalIterator::WalSegment::aPgno, WalHashLoc::aPgno, WalIterator::aSegment, Wal::ckptLock, HASHTABLE_NPAGE, Wal::hdr, WalIterator::WalSegment::iZero, WalHashLoc::iZero, WalIndexHdr::mxFrame, WalIterator::WalSegment::nEntry, WalIterator::nSegment, sqlite3_free(), sqlite3_malloc64(), SQLITE_NOMEM_BKPT, SQLITE_OK, walFramePage(), walHashGet(), walIteratorFree(), and walMergesort().

Referenced by walCheckpoint().

◆ walIteratorNext()

static int walIteratorNext ( WalIterator * p,
u32 * piPage,
u32 * piFrame )
static

Definition at line 60884 of file sqlite3.c.

60894 {
60895 u32 iMin; /* Result pgno must be greater than iMin */
60896 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
60897 int i; /* For looping through segments */
60898
60899 iMin = p->iPrior;
60900 assert( iMin<0xffffffff );
60901 for(i=p->nSegment-1; i>=0; i--){
60902 struct WalSegment *pSegment = &p->aSegment[i];
60903 while( pSegment->iNext<pSegment->nEntry ){
60904 u32 iPg = pSegment->aPgno[pSegment->aIndex[pSegment->iNext]];
60905 if( iPg>iMin ){
60906 if( iPg<iRet ){
60907 iRet = iPg;
60908 *piFrame = pSegment->iZero + pSegment->aIndex[pSegment->iNext];
60909 }
60910 break;
60911 }
60912 pSegment->iNext++;
struct WalIterator::WalSegment aSegment[1]

References WalIterator::WalSegment::aPgno, WalIterator::aSegment, WalIterator::iPrior, and WalIterator::nSegment.

Referenced by walCheckpoint().

◆ walkExpr()

static SQLITE_NOINLINE int walkExpr ( Walker * pWalker,
Expr * pExpr )
static

Definition at line 97568 of file sqlite3.c.

97574 {
97575 int rc;
97578 while(1){
97579 rc = pWalker->xExprCallback(pWalker, pExpr);
97580 if( rc ) return rc & WRC_Abort;
97581 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
97582 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
97583 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
97584 if( pExpr->pRight ){
97585 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
97586 pExpr = pExpr->pRight;
97587 continue;
97588 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
97589 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
97590 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
97591 }else{
97592 if( pExpr->x.pList ){
97593 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
97594 }
97595#ifndef SQLITE_OMIT_WINDOWFUNC
97596 if( ExprHasProperty(pExpr, EP_WinFunc) ){
97597 if( walkWindowList(pWalker, pExpr->y.pWin) ) return WRC_Abort;
97598 }
97599#endif
static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr)
Definition sqlite3.c:97568

References EP_Leaf, EP_Reduced, EP_TokenOnly, EP_WinFunc, EP_xIsSelect, ExprHasProperty, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pSelect, Expr::pWin, sqlite3WalkExprList(), sqlite3WalkSelect(), testcase, walkExpr(), walkWindowList(), WRC_Abort, Expr::x, Walker::xExprCallback, and Expr::y.

Referenced by walkExpr().

◆ walkWindowList()

static int walkWindowList ( Walker * pWalker,
Window * pList )
static

Definition at line 97525 of file sqlite3.c.

97531 {
97532 Window *pWin;
97533 for(pWin=pList; pWin; pWin=pWin->pNextWin){
97534 int rc;
97535 rc = sqlite3WalkExprList(pWalker, pWin->pOrderBy);
97536 if( rc ) return WRC_Abort;
97537 rc = sqlite3WalkExprList(pWalker, pWin->pPartition);
97538 if( rc ) return WRC_Abort;
97539 rc = sqlite3WalkExpr(pWalker, pWin->pFilter);
97540 if( rc ) return WRC_Abort;
97541
97542 /* The next two are purely for calls to sqlite3RenameExprUnmap()
97543 ** within sqlite3WindowOffsetExpr(). Because of constraints imposed
97544 ** by sqlite3WindowOffsetExpr(), they can never fail. The results do
97545 ** not matter anyhow. */
97546 rc = sqlite3WalkExpr(pWalker, pWin->pStart);

References NEVER, Window::pEnd, Window::pFilter, Window::pNextWin, Window::pOrderBy, Window::pPartition, Window::pStart, sqlite3WalkExpr(), sqlite3WalkExprList(), WRC_Abort, and WRC_Continue.

Referenced by sqlite3WalkSelectExpr(), and walkExpr().

◆ walLimitSize()

static void walLimitSize ( Wal * pWal,
i64 nMax )
static

Definition at line 61516 of file sqlite3.c.

61522 {
61523 i64 sz;
61524 int rx;
61526 rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
61527 if( rx==SQLITE_OK && (sz > nMax ) ){
61528 rx = sqlite3OsTruncate(pWal->pWalFd, nMax);

◆ walLockExclusive()

static int walLockExclusive ( Wal * pWal,
int lockIdx,
int n )
static

Definition at line 60272 of file sqlite3.c.

60272 {
60273 if( pWal->exclusiveMode ) return;
60274 (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1,
60276 WALTRACE(("WAL%p: release SHARED-%s\n", pWal, walLockName(lockIdx)));
60277}
60278static int walLockExclusive(Wal *pWal, int lockIdx, int n){
60279 int rc;
60280 if( pWal->exclusiveMode ) return SQLITE_OK;
60281 rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n,
SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int)
Definition sqlite3.c:23121

References Wal::exclusiveMode, Wal::pDbFd, sqlite3OsShmLock(), SQLITE_SHM_SHARED, SQLITE_SHM_UNLOCK, and WALTRACE.

Referenced by sqlite3WalBeginWriteTransaction(), sqlite3WalCheckpoint(), walBusyLock(), walIndexRecover(), walRestartLog(), and walTryBeginRead().

◆ walLockShared()

static int walLockShared ( Wal * pWal,
int lockIdx )
static

Definition at line 60256 of file sqlite3.c.

60262 {
60263 int rc;
60264 if( pWal->exclusiveMode ) return SQLITE_OK;
60265 rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1,

References Wal::exclusiveMode, Wal::pDbFd, sqlite3OsShmLock(), and SQLITE_OK.

Referenced by sqlite3WalBeginReadTransaction(), sqlite3WalExclusiveMode(), walBeginShmUnreliable(), walIndexReadHdr(), and walTryBeginRead().

◆ walMerge()

static void walMerge ( const u32 * aContent,
ht_slot * aLeft,
int nLeft,
ht_slot ** paRight,
int * pnRight,
ht_slot * aTmp )
static

Definition at line 60937 of file sqlite3.c.

60950 {
60951 int iLeft = 0; /* Current index in aLeft */
60952 int iRight = 0; /* Current index in aRight */
60953 int iOut = 0; /* Current index in output buffer */
60954 int nRight = *pnRight;
60955 ht_slot *aRight = *paRight;
60956
60957 assert( nLeft>0 && nRight>0 );
60958 while( iRight<nRight || iLeft<nLeft ){
60959 ht_slot logpage;
60960 Pgno dbpage;
60961
60962 if( (iLeft<nLeft)
60963 && (iRight>=nRight || aContent[aLeft[iLeft]]<aContent[aRight[iRight]])
60964 ){
60965 logpage = aLeft[iLeft++];
60966 }else{
60967 logpage = aRight[iRight++];
60968 }
60969 dbpage = aContent[logpage];
60970
60971 aTmp[iOut++] = logpage;
60972 if( iLeft<nLeft && aContent[aLeft[iLeft]]==dbpage ) iLeft++;
60973
60974 assert( iLeft>=nLeft || aContent[aLeft[iLeft]]>dbpage );
60975 assert( iRight>=nRight || aContent[aRight[iRight]]>dbpage );

Referenced by walMergesort().

◆ walMergesort()

static void walMergesort ( const u32 * aContent,
ht_slot * aBuffer,
ht_slot * aList,
int * pnList )
static

Definition at line 60994 of file sqlite3.c.

61005 {
61006 struct Sublist {
61007 int nList; /* Number of elements in aList */
61008 ht_slot *aList; /* Pointer to sub-list content */
61009 };
61010
61011 const int nList = *pnList; /* Size of input list */
61012 int nMerge = 0; /* Number of elements in list aMerge */
61013 ht_slot *aMerge = 0; /* List to be merged */
61014 int iList; /* Index into input list */
61015 u32 iSub = 0; /* Index into aSub array */
61016 struct Sublist aSub[13]; /* Array of sub-lists */
61017
61018 memset(aSub, 0, sizeof(aSub));
61019 assert( nList<=HASHTABLE_NPAGE && nList>0 );
61020 assert( HASHTABLE_NPAGE==(1<<(ArraySize(aSub)-1)) );
61021
61022 for(iList=0; iList<nList; iList++){
61023 nMerge = 1;
61024 aMerge = &aList[iList];
61025 for(iSub=0; iList & (1<<iSub); iSub++){
61026 struct Sublist *p;
61027 assert( iSub<ArraySize(aSub) );
61028 p = &aSub[iSub];
61029 assert( p->aList && p->nList<=(1<<iSub) );
61030 assert( p->aList==&aList[iList&~((2<<iSub)-1)] );
61031 walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
61032 }
61033 aSub[iSub].aList = aMerge;
61034 aSub[iSub].nList = nMerge;
61035 }
61036
61037 for(iSub++; iSub<ArraySize(aSub); iSub++){
61038 if( nList & (1<<iSub) ){
61039 struct Sublist *p;
61040 assert( iSub<ArraySize(aSub) );
61041 p = &aSub[iSub];
61042 assert( p->nList<=(1<<iSub) );
61043 assert( p->aList==&aList[nList&~((2<<iSub)-1)] );
61044 walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
61045 }
61046 }
61047 assert( aMerge==aList );
61048 *pnList = nMerge;
61049
61050#ifdef SQLITE_DEBUG
61051 {
61052 int i;
static void walMerge(const u32 *aContent, ht_slot *aLeft, int nLeft, ht_slot **paRight, int *pnRight, ht_slot *aTmp)
Definition sqlite3.c:60937

References ArraySize, HASHTABLE_NPAGE, and walMerge().

Referenced by walIteratorInit().

◆ walNextHash()

static int walNextHash ( int iPriorHash)
static

Definition at line 60300 of file sqlite3.c.

60301 {
60302 assert( iPage>0 );

References HASHTABLE_HASH_1, and HASHTABLE_NSLOT.

Referenced by sqlite3WalFindFrame(), walCleanupHash(), and walIndexAppend().

◆ walPagesize()

static int walPagesize ( Wal * pWal)
static

Definition at line 61262 of file sqlite3.c.

Referenced by sqlite3WalCheckpoint(), and walCheckpoint().

◆ walRestartHdr()

static void walRestartHdr ( Wal * pWal,
u32 salt1 )
static

Definition at line 61283 of file sqlite3.c.

61289 {
61290 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
61291 int i; /* Loop counter */
61292 u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
61293 pWal->nCkpt++;
61294 pWal->hdr.mxFrame = 0;
61295 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
61296 memcpy(&pWal->hdr.aSalt[1], &salt1, 4);
61297 walIndexWriteHdr(pWal);

References WalCkptInfo::aReadMark, WalIndexHdr::aSalt, AtomicStore, Wal::hdr, WalIndexHdr::mxFrame, WalCkptInfo::nBackfill, WalCkptInfo::nBackfillAttempted, Wal::nCkpt, READMARK_NOT_USED, sqlite3Get4byte(), sqlite3Put4byte(), WAL_NREADER, walCkptInfo(), and walIndexWriteHdr().

Referenced by walCheckpoint(), and walRestartLog().

◆ walRestartLog()

static int walRestartLog ( Wal * pWal)
static

Definition at line 62733 of file sqlite3.c.

62739 {
62740 int rc = SQLITE_OK;
62741 int cnt;
62742
62743 if( pWal->readLock==0 ){
62744 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
62745 assert( pInfo->nBackfill==pWal->hdr.mxFrame );
62746 if( pInfo->nBackfill>0 ){
62747 u32 salt1;
62748 sqlite3_randomness(4, &salt1);
62749 rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
62750 if( rc==SQLITE_OK ){
62751 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
62752 ** readers are currently using the WAL), then the transactions
62753 ** frames will overwrite the start of the existing log. Update the
62754 ** wal-index header to reflect this.
62755 **
62756 ** In theory it would be Ok to update the cache of the header only
62757 ** at this point. But updating the actual wal-index header is also
62758 ** safe and means there is no special case for sqlite3WalUndo()
62759 ** to handle if this transaction is rolled back. */
62760 walRestartHdr(pWal, salt1);
62762 }else if( rc!=SQLITE_BUSY ){
62763 return rc;
62764 }
62765 }
62767 pWal->readLock = -1;
62768 cnt = 0;
62769 do{
62770 int notUsed;
62771 rc = walTryBeginRead(pWal, &notUsed, 1, ++cnt);
62772 }while( rc==WAL_RETRY );
62773 assert( (rc&0xff)!=SQLITE_BUSY ); /* BUSY not possible when useWal==1 */

References Wal::hdr, WalIndexHdr::mxFrame, WalCkptInfo::nBackfill, Wal::readLock, sqlite3_randomness(), SQLITE_BUSY, SQLITE_IOERR, SQLITE_OK, SQLITE_PROTOCOL, testcase, WAL_NREADER, WAL_READ_LOCK, WAL_RETRY, walCkptInfo(), walLockExclusive(), walRestartHdr(), walTryBeginRead(), walUnlockExclusive(), and walUnlockShared().

◆ walRewriteChecksums()

static int walRewriteChecksums ( Wal * pWal,
u32 iLast )
static

Definition at line 62847 of file sqlite3.c.

62853 {
62854 const int szPage = pWal->szPage;/* Database page size */
62855 int rc = SQLITE_OK; /* Return code */
62856 u8 *aBuf; /* Buffer to load data from wal file into */
62857 u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-headers in */
62858 u32 iRead; /* Next frame to read from wal file */
62859 i64 iCksumOff;
62860
62861 aBuf = sqlite3_malloc(szPage + WAL_FRAME_HDRSIZE);
62862 if( aBuf==0 ) return SQLITE_NOMEM_BKPT;
62863
62864 /* Find the checksum values to use as input for the recalculating the
62865 ** first checksum. If the first frame is frame 1 (implying that the current
62866 ** transaction restarted the wal file), these values must be read from the
62867 ** wal-file header. Otherwise, read them from the frame header of the
62868 ** previous frame. */
62869 assert( pWal->iReCksum>0 );
62870 if( pWal->iReCksum==1 ){
62871 iCksumOff = 24;
62872 }else{
62873 iCksumOff = walFrameOffset(pWal->iReCksum-1, szPage) + 16;
62874 }
62875 rc = sqlite3OsRead(pWal->pWalFd, aBuf, sizeof(u32)*2, iCksumOff);
62876 pWal->hdr.aFrameCksum[0] = sqlite3Get4byte(aBuf);
62877 pWal->hdr.aFrameCksum[1] = sqlite3Get4byte(&aBuf[sizeof(u32)]);
62878
62879 iRead = pWal->iReCksum;
62880 pWal->iReCksum = 0;
62881 for(; rc==SQLITE_OK && iRead<=iLast; iRead++){
62882 i64 iOff = walFrameOffset(iRead, szPage);
62883 rc = sqlite3OsRead(pWal->pWalFd, aBuf, szPage+WAL_FRAME_HDRSIZE, iOff);
62884 if( rc==SQLITE_OK ){
62885 u32 iPgno, nDbSize;
62886 iPgno = sqlite3Get4byte(aBuf);
62887 nDbSize = sqlite3Get4byte(&aBuf[4]);
62888
62889 walEncodeFrame(pWal, iPgno, nDbSize, &aBuf[WAL_FRAME_HDRSIZE], aFrame);
62890 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOff);

References WalIndexHdr::aFrameCksum, Wal::hdr, Wal::iReCksum, Wal::pWalFd, sqlite3_free(), sqlite3_malloc(), sqlite3Get4byte(), sqlite3OsRead(), sqlite3OsWrite(), SQLITE_NOMEM_BKPT, SQLITE_OK, Wal::szPage, WAL_FRAME_HDRSIZE, walEncodeFrame(), and walFrameOffset.

◆ walShmBarrier()

static void walShmBarrier ( Wal * pWal)
static

Definition at line 60095 of file sqlite3.c.

Referenced by walIndexTryHdr(), walIndexWriteHdr(), and walTryBeginRead().

◆ walTryBeginRead()

static int walTryBeginRead ( Wal * pWal,
int * pChanged,
int useWal,
int cnt )
static

Definition at line 62003 of file sqlite3.c.

62009 {
62010 volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
62011 u32 mxReadMark; /* Largest aReadMark[] value */
62012 int mxI; /* Index of largest aReadMark[] value */
62013 int i; /* Loop counter */
62014 int rc = SQLITE_OK; /* Return code */
62015 u32 mxFrame; /* Wal frame to lock to */
62016
62017 assert( pWal->readLock<0 ); /* Not currently locked */
62018
62019 /* useWal may only be set for read/write connections */
62020 assert( (pWal->readOnly & WAL_SHM_RDONLY)==0 || useWal==0 );
62021
62022 /* Take steps to avoid spinning forever if there is a protocol error.
62023 **
62024 ** Circumstances that cause a RETRY should only last for the briefest
62025 ** instances of time. No I/O or other system calls are done while the
62026 ** locks are held, so the locks should not be held for very long. But
62027 ** if we are unlucky, another process that is holding a lock might get
62028 ** paged out or take a page-fault that is time-consuming to resolve,
62029 ** during the few nanoseconds that it is holding the lock. In that case,
62030 ** it might take longer than normal for the lock to free.
62031 **
62032 ** After 5 RETRYs, we begin calling sqlite3OsSleep(). The first few
62033 ** calls to sqlite3OsSleep() have a delay of 1 microsecond. Really this
62034 ** is more of a scheduler yield than an actual delay. But on the 10th
62035 ** an subsequent retries, the delays start becoming longer and longer,
62036 ** so that on the 100th (and last) RETRY we delay for 323 milliseconds.
62037 ** The total delay time before giving up is less than 10 seconds.
62038 */
62039 if( cnt>5 ){
62040 int nDelay = 1; /* Pause time in microseconds */
62041 if( cnt>100 ){
62042 VVA_ONLY( pWal->lockError = 1; )
62043 return SQLITE_PROTOCOL;
62044 }
62045 if( cnt>=10 ) nDelay = (cnt-9)*(cnt-9)*39;
62046 sqlite3OsSleep(pWal->pVfs, nDelay);
62047 }
62048
62049 if( !useWal ){
62050 assert( rc==SQLITE_OK );
62051 if( pWal->bShmUnreliable==0 ){
62052 rc = walIndexReadHdr(pWal, pChanged);
62053 }
62054 if( rc==SQLITE_BUSY ){
62055 /* If there is not a recovery running in another thread or process
62056 ** then convert BUSY errors to WAL_RETRY. If recovery is known to
62057 ** be running, convert BUSY to BUSY_RECOVERY. There is a race here
62058 ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
62059 ** would be technically correct. But the race is benign since with
62060 ** WAL_RETRY this routine will be called again and will probably be
62061 ** right on the second iteration.
62062 */
62063 if( pWal->apWiData[0]==0 ){
62064 /* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
62065 ** We assume this is a transient condition, so return WAL_RETRY. The
62066 ** xShmMap() implementation used by the default unix and win32 VFS
62067 ** modules may return SQLITE_BUSY due to a race condition in the
62068 ** code that determines whether or not the shared-memory region
62069 ** must be zeroed before the requested page is returned.
62070 */
62071 rc = WAL_RETRY;
62072 }else if( SQLITE_OK==(rc = walLockShared(pWal, WAL_RECOVER_LOCK)) ){
62074 rc = WAL_RETRY;
62075 }else if( rc==SQLITE_BUSY ){
62077 }
62078 }
62079 if( rc!=SQLITE_OK ){
62080 return rc;
62081 }
62082 else if( pWal->bShmUnreliable ){
62083 return walBeginShmUnreliable(pWal, pChanged);
62084 }
62085 }
62086
62087 assert( pWal->nWiData>0 );
62088 assert( pWal->apWiData[0]!=0 );
62089 pInfo = walCkptInfo(pWal);
62090 if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame
62091#ifdef SQLITE_ENABLE_SNAPSHOT
62092 && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
62093#endif
62094 ){
62095 /* The WAL has been completely backfilled (or it is empty).
62096 ** and can be safely ignored.
62097 */
62098 rc = walLockShared(pWal, WAL_READ_LOCK(0));
62099 walShmBarrier(pWal);
62100 if( rc==SQLITE_OK ){
62101 if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){
62102 /* It is not safe to allow the reader to continue here if frames
62103 ** may have been appended to the log before READ_LOCK(0) was obtained.
62104 ** When holding READ_LOCK(0), the reader ignores the entire log file,
62105 ** which implies that the database file contains a trustworthy
62106 ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
62107 ** happening, this is usually correct.
62108 **
62109 ** However, if frames have been appended to the log (or if the log
62110 ** is wrapped and written for that matter) before the READ_LOCK(0)
62111 ** is obtained, that is not necessarily true. A checkpointer may
62112 ** have started to backfill the appended frames but crashed before
62113 ** it finished. Leaving a corrupt image in the database file.
62114 */
62116 return WAL_RETRY;
62117 }
62118 pWal->readLock = 0;
62119 return SQLITE_OK;
62120 }else if( rc!=SQLITE_BUSY ){
62121 return rc;
62122 }
62123 }
62124
62125 /* If we get this far, it means that the reader will want to use
62126 ** the WAL to get at content from recent commits. The job now is
62127 ** to select one of the aReadMark[] entries that is closest to
62128 ** but not exceeding pWal->hdr.mxFrame and lock that entry.
62129 */
62130 mxReadMark = 0;
62131 mxI = 0;
62132 mxFrame = pWal->hdr.mxFrame;
62133#ifdef SQLITE_ENABLE_SNAPSHOT
62134 if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){
62135 mxFrame = pWal->pSnapshot->mxFrame;
62136 }
62137#endif
62138 for(i=1; i<WAL_NREADER; i++){
62139 u32 thisMark = AtomicLoad(pInfo->aReadMark+i);
62140 if( mxReadMark<=thisMark && thisMark<=mxFrame ){
62141 assert( thisMark!=READMARK_NOT_USED );
62142 mxReadMark = thisMark;
62143 mxI = i;
62144 }
62145 }
62146 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
62147 && (mxReadMark<mxFrame || mxI==0)
62148 ){
62149 for(i=1; i<WAL_NREADER; i++){
62150 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
62151 if( rc==SQLITE_OK ){
62152 AtomicStore(pInfo->aReadMark+i,mxFrame);
62153 mxReadMark = mxFrame;
62154 mxI = i;
62155 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
62156 break;
62157 }else if( rc!=SQLITE_BUSY ){
62158 return rc;
62159 }
62160 }
62161 }
62162 if( mxI==0 ){
62163 assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
62165 }
62166
62167 rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
62168 if( rc ){
62169 return rc==SQLITE_BUSY ? WAL_RETRY : rc;
62170 }
62171 /* Now that the read-lock has been obtained, check that neither the
62172 ** value in the aReadMark[] array or the contents of the wal-index
62173 ** header have changed.
62174 **
62175 ** It is necessary to check that the wal-index header did not change
62176 ** between the time it was read and when the shared-lock was obtained
62177 ** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
62178 ** that the log file may have been wrapped by a writer, or that frames
62179 ** that occur later in the log than pWal->hdr.mxFrame may have been
62180 ** copied into the database by a checkpointer. If either of these things
62181 ** happened, then reading the database with the current value of
62182 ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
62183 ** instead.
62184 **
62185 ** Before checking that the live wal-index header has not changed
62186 ** since it was read, set Wal.minFrame to the first frame in the wal
62187 ** file that has not yet been checkpointed. This client will not need
62188 ** to read any frames earlier than minFrame from the wal file - they
62189 ** can be safely read directly from the database file.
62190 **
62191 ** Because a ShmBarrier() call is made between taking the copy of
62192 ** nBackfill and checking that the wal-header in shared-memory still
62193 ** matches the one cached in pWal->hdr, it is guaranteed that the
62194 ** checkpointer that set nBackfill was not working with a wal-index
62195 ** header newer than that cached in pWal->hdr. If it were, that could
62196 ** cause a problem. The checkpointer could omit to checkpoint
62197 ** a version of page X that lies before pWal->minFrame (call that version
62198 ** A) on the basis that there is a newer version (version B) of the same
62199 ** page later in the wal file. But if version B happens to like past
62200 ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
62201 ** that it can read version A from the database file. However, since
62202 ** we can guarantee that the checkpointer that set nBackfill could not
62203 ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
62204 */
62205 pWal->minFrame = AtomicLoad(&pInfo->nBackfill)+1;
62206 walShmBarrier(pWal);
62207 if( AtomicLoad(pInfo->aReadMark+mxI)!=mxReadMark
62208 || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
62209 ){
62210 walUnlockShared(pWal, WAL_READ_LOCK(mxI));
62211 return WAL_RETRY;
#define WAL_RECOVER_LOCK
Definition sqlite3.c:59691
static int walBeginShmUnreliable(Wal *pWal, int *pChanged)
Definition sqlite3.c:61808

References Wal::apWiData, WalCkptInfo::aReadMark, AtomicLoad, AtomicStore, Wal::bShmUnreliable, Wal::hdr, Wal::minFrame, WalIndexHdr::mxFrame, WalCkptInfo::nBackfill, Wal::nWiData, Wal::pVfs, Wal::readLock, READMARK_NOT_USED, Wal::readOnly, sqlite3OsSleep(), SQLITE_BUSY, SQLITE_BUSY_RECOVERY, SQLITE_OK, SQLITE_PROTOCOL, SQLITE_READONLY_CANTINIT, VVA_ONLY, WAL_NREADER, WAL_READ_LOCK, WAL_RECOVER_LOCK, WAL_RETRY, WAL_SHM_RDONLY, walBeginShmUnreliable(), walCkptInfo(), walIndexHdr(), walIndexReadHdr(), walLockExclusive(), walLockShared(), walShmBarrier(), walUnlockExclusive(), and walUnlockShared().

Referenced by sqlite3WalBeginReadTransaction(), and walRestartLog().

◆ walUnlockExclusive()

static void walUnlockExclusive ( Wal * pWal,
int lockIdx,
int n )
static

Definition at line 60282 of file sqlite3.c.

60283 : acquire EXCLUSIVE-%s cnt=%d %s\n", pWal,
60284 walLockName(lockIdx), n, rc ? "failed" : "ok"));
60285 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
60286 return rc;
60287}
60288static void walUnlockExclusive(Wal *pWal, int lockIdx, int n){

Referenced by sqlite3WalBeginWriteTransaction(), sqlite3WalCheckpoint(), walCheckpoint(), walIndexReadHdr(), walIndexRecover(), walRestartLog(), and walTryBeginRead().

◆ walUnlockShared()

static void walUnlockShared ( Wal * pWal,
int lockIdx )
static

Definition at line 60266 of file sqlite3.c.

60267 : acquire SHARED-%s %s\n", pWal,
60268 walLockName(lockIdx), rc ? "failed" : "ok"));
60269 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
60270 return rc;
60271}

Referenced by sqlite3WalBeginReadTransaction(), sqlite3WalExclusiveMode(), walIndexReadHdr(), walRestartLog(), and walTryBeginRead().

◆ walWriteOneFrame()

static int walWriteOneFrame ( WalWriter * p,
PgHdr * pPage,
int nTruncate,
sqlite3_int64 iOffset )
static

Definition at line 62821 of file sqlite3.c.

62832 {
62833 int rc; /* Result code from subfunctions */
62834 void *pData; /* Data actually written */
62835 u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */
62836 pData = pPage->pData;
62837 walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame);

◆ walWriteToLog()

static int walWriteToLog ( WalWriter * p,
void * pContent,
int iAmt,
sqlite3_int64 iOffset )
static

Definition at line 62796 of file sqlite3.c.

62807 {
62808 int rc;
62809 if( iOffset<p->iSyncPoint && iOffset+iAmt>=p->iSyncPoint ){
62810 int iFirstAmt = (int)(p->iSyncPoint - iOffset);
62811 rc = sqlite3OsWrite(p->pFd, pContent, iFirstAmt, iOffset);
62812 if( rc ) return rc;
62813 iOffset += iFirstAmt;
62814 iAmt -= iFirstAmt;
62815 pContent = (void*)(iFirstAmt + (char*)pContent);
62816 assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 );

References WalWriter::iSyncPoint, WalWriter::pFd, sqlite3OsSync(), sqlite3OsWrite(), WalWriter::syncFlags, and WAL_SYNC_FLAGS.

◆ whereAndInfoDelete()

static void whereAndInfoDelete ( sqlite3 * db,
WhereAndInfo * p )
static

Definition at line 144026 of file sqlite3.c.

Referenced by sqlite3WhereClauseClear().

◆ whereApplyPartialIndexConstraints()

static void whereApplyPartialIndexConstraints ( Expr * pTruth,
int iTabCur,
WhereClause * pWC )
static

Definition at line 142765 of file sqlite3.c.

142775 {
142776 int i;
142777 WhereTerm *pTerm;
142778 while( pTruth->op==TK_AND ){
142779 whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
142780 pTruth = pTruth->pRight;
142781 }
142782 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
142783 Expr *pExpr;
142784 if( pTerm->wtFlags & TERM_CODED ) continue;

References WhereClause::a, WhereClause::nTerm, Expr::op, WhereTerm::pExpr, Expr::pLeft, Expr::pRight, sqlite3ExprCompare(), TERM_CODED, TK_AND, whereApplyPartialIndexConstraints(), and WhereTerm::wtFlags.

Referenced by whereApplyPartialIndexConstraints().

◆ whereClauseInsert()

static int whereClauseInsert ( WhereClause * pWC,
Expr * p,
u16 wtFlags )
static

Definition at line 144050 of file sqlite3.c.

144051 : This routine might reallocate the space used to store
144052** WhereTerms. All pointers to WhereTerms should be invalidated after
144053** calling this routine. Such pointers may be reinitialized by referencing
144054** the pWC->a[] array.
144055*/
144056static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){
144057 WhereTerm *pTerm;
144058 int idx;
144059 testcase( wtFlags & TERM_VIRTUAL );
144060 if( pWC->nTerm>=pWC->nSlot ){
144061 WhereTerm *pOld = pWC->a;
144062 sqlite3 *db = pWC->pWInfo->pParse->db;
144063 pWC->a = sqlite3DbMallocRawNN(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
144064 if( pWC->a==0 ){
144065 if( wtFlags & TERM_DYNAMIC ){
144066 sqlite3ExprDelete(db, p);
144067 }
144068 pWC->a = pOld;
144069 return 0;
144070 }
144071 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
144072 if( pOld!=pWC->aStatic ){
144073 sqlite3DbFree(db, pOld);
144074 }
144075 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
144076 }
144077 pTerm = &pWC->a[idx = pWC->nTerm++];
144078 if( p && ExprHasProperty(p, EP_Unlikely) ){
144079 pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
144080 }else{
144081 pTerm->truthProb = 1;
144082 }
144084 pTerm->wtFlags = wtFlags;
LogEst truthProb
Definition sqlite3.c:141171

References WhereClause::a, WhereClause::aStatic, Parse::db, WhereTerm::eOperator, EP_Unlikely, ExprHasProperty, WhereTerm::iParent, Expr::iTable, WhereClause::nSlot, WhereClause::nTerm, offsetof, WhereTerm::pExpr, WhereInfo::pParse, WhereTerm::pWC, WhereClause::pWInfo, sqlite3DbFree(), sqlite3DbMallocRawNN(), sqlite3DbMallocSize(), sqlite3ExprDelete(), sqlite3ExprSkipCollateAndLikely(), sqlite3LogEst(), TERM_DYNAMIC, TERM_VIRTUAL, testcase, WhereTerm::truthProb, and WhereTerm::wtFlags.

Referenced by exprAnalyze(), exprAnalyzeOrTerm(), sqlite3WhereSplit(), sqlite3WhereTabFuncArgs(), and whereCombineDisjuncts().

◆ whereCombineDisjuncts()

static void whereCombineDisjuncts ( SrcList * pSrc,
WhereClause * pWC,
WhereTerm * pOne,
WhereTerm * pTwo )
static

Definition at line 144492 of file sqlite3.c.

144494 :
144495**
144496** x<y OR x>y --> x!=y
144497*/
144498static void whereCombineDisjuncts(
144499 SrcList *pSrc, /* the FROM clause */
144500 WhereClause *pWC, /* The complete WHERE clause */
144501 WhereTerm *pOne, /* First disjunct */
144502 WhereTerm *pTwo /* Second disjunct */
144503){
144504 u16 eOp = pOne->eOperator | pTwo->eOperator;
144505 sqlite3 *db; /* Database connection (for malloc) */
144506 Expr *pNew; /* New virtual expression */
144507 int op; /* Operator for the combined expression */
144508 int idxNew; /* Index in pWC of the next virtual term */
144509
144510 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
144511 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
144512 if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp
144513 && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return;
144514 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
144515 assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 );
144516 if( sqlite3ExprCompare(0,pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return;
144517 if( sqlite3ExprCompare(0,pOne->pExpr->pRight, pTwo->pExpr->pRight,-1) )return;
144518 /* If we reach this point, it means the two subterms can be combined */
144519 if( (eOp & (eOp-1))!=0 ){
144520 if( eOp & (WO_LT|WO_LE) ){
144521 eOp = WO_LE;
144522 }else{
144523 assert( eOp & (WO_GT|WO_GE) );
144524 eOp = WO_GE;
144525 }
144526 }
144527 db = pWC->pWInfo->pParse->db;
144528 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);

References Parse::db, WhereTerm::eOperator, exprAnalyze(), Expr::op, WhereTerm::pExpr, Expr::pLeft, WhereInfo::pParse, Expr::pRight, WhereClause::pWInfo, sqlite3ExprCompare(), sqlite3ExprDup(), TERM_DYNAMIC, TERM_VIRTUAL, TK_EQ, TK_GE, whereClauseInsert(), WO_EQ, WO_GE, WO_GT, WO_LE, and WO_LT.

Referenced by exprAnalyzeOrTerm().

◆ whereIndexExprTrans()

static void whereIndexExprTrans ( Index * pIdx,
int iTabCur,
int iIdxCur,
WhereInfo * pWInfo )
static

Definition at line 142702 of file sqlite3.c.

142704 : Updated to also translate references to a VIRTUAL column in
142705** the table into references to the corresponding (stored) column of the
142706** index.
142707*/
142708static void whereIndexExprTrans(
142709 Index *pIdx, /* The Index */
142710 int iTabCur, /* Cursor of the table that is being indexed */
142711 int iIdxCur, /* Cursor of the index itself */
142712 WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
142713){
142714 int iIdxCol; /* Column number of the index */
142715 ExprList *aColExpr; /* Expressions that are indexed */
142716 Table *pTab;
142717 Walker w;
142718 IdxExprTrans x;
142719 aColExpr = pIdx->aColExpr;
142720 if( aColExpr==0 && !pIdx->bHasVCol ){
142721 /* The index does not reference any expressions or virtual columns
142722 ** so no translations are needed. */
142723 return;
142724 }
142725 pTab = pIdx->pTable;
142726 memset(&w, 0, sizeof(w));
142727 w.u.pIdxTrans = &x;
142728 x.iTabCur = iTabCur;
142729 x.iIdxCur = iIdxCur;
142730 x.pWInfo = pWInfo;
142731 x.db = pWInfo->pParse->db;
142732 for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
142733 i16 iRef = pIdx->aiColumn[iIdxCol];
142734 if( iRef==XN_EXPR ){
142735 assert( aColExpr->a[iIdxCol].pExpr!=0 );
142736 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
142737 if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
142739#ifndef SQLITE_OMIT_GENERATED_COLUMNS
142740 }else if( iRef>=0
142741 && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
142742 && (pTab->aCol[iRef].zColl==0
142743 || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0)
142744 ){
142745 /* Check to see if there are direct references to generated columns
142746 ** that are contained in the index. Pulling the generated column
142747 ** out of the index is an optimization only - the main table is always
142748 ** available if the index cannot be used. To avoid unnecessary
142749 ** complication, omit this optimization if the collating sequence for
142750 ** the column is non-standard */
142751 x.iTabCol = iRef;
142753#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
142754 }else{
142755 continue;
142756 }
static int whereIndexExprTransColumn(Walker *p, Expr *pExpr)
Definition sqlite3.c:142677
static int whereIndexExprTransNode(Walker *p, Expr *pExpr)
Definition sqlite3.c:142655
WhereInfo * pWInfo
Definition sqlite3.c:142632
Expr * pIdxExpr
Definition sqlite3.c:142627
struct IdxExprTrans * pIdxTrans
Definition sqlite3.c:19106

References ExprList::a, Table::aCol, Index::aColExpr, Index::aiColumn, Index::bHasVCol, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, IdxExprTrans::db, IdxExprTrans::iIdxCol, IdxExprTrans::iIdxCur, IdxExprTrans::iTabCol, IdxExprTrans::iTabCur, Index::nColumn, ExprList::ExprList_item::pExpr, IdxExprTrans::pIdxExpr, Walker::pIdxTrans, WhereInfo::pOrderBy, WhereInfo::pParse, WhereInfo::pResultSet, Index::pTable, WhereInfo::pWhere, IdxExprTrans::pWInfo, sqlite3ExprIsConstant(), sqlite3StrBINARY, sqlite3StrICmp(), sqlite3WalkExpr(), sqlite3WalkExprList(), Walker::u, whereIndexExprTransColumn(), whereIndexExprTransNode(), Walker::xExprCallback, XN_EXPR, and Column::zColl.

◆ whereIndexExprTransColumn()

static int whereIndexExprTransColumn ( Walker * p,
Expr * pExpr )
static

Definition at line 142677 of file sqlite3.c.

142683 {
142684 if( pExpr->op==TK_COLUMN ){
142685 IdxExprTrans *pX = p->u.pIdxTrans;
142686 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
142687 assert( pExpr->y.pTab!=0 );
142688 preserveExpr(pX, pExpr);
142689 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
142690 pExpr->iTable = pX->iIdxCur;
static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr)
Definition sqlite3.c:142639

Referenced by whereIndexExprTrans().

◆ whereIndexExprTransNode()

static int whereIndexExprTransNode ( Walker * p,
Expr * pExpr )
static

◆ whereInfoFree()

static void whereInfoFree ( sqlite3 * db,
WhereInfo * pWInfo )
static

Definition at line 147539 of file sqlite3.c.

147545 {
147546 int i;
147547 assert( pWInfo!=0 );
147548 for(i=0; i<pWInfo->nLevel; i++){
147549 WhereLevel *pLevel = &pWInfo->a[i];
147550 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
147551 sqlite3DbFree(db, pLevel->u.in.aInLoop);
147552 }
147553 }
147554 sqlite3WhereClauseClear(&pWInfo->sWC);
147555 while( pWInfo->pLoops ){
147556 WhereLoop *p = pWInfo->pLoops;
SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause *)
Definition sqlite3.c:145473
WhereLoop * pLoops
Definition sqlite3.c:141405

Referenced by sqlite3WhereBegin(), and sqlite3WhereEnd().

◆ whereLikeOptimizationStringFixup()

static void whereLikeOptimizationStringFixup ( Vdbe * v,
WhereLevel * pLevel,
WhereTerm * pTerm )
static

Definition at line 142300 of file sqlite3.c.

142310 {
142311 if( pTerm->wtFlags & TERM_LIKEOPT ){
142312 VdbeOp *pOp;
142313 assert( pLevel->iLikeRepCntr>0 );
142314 pOp = sqlite3VdbeGetOp(v, -1);
142315 assert( pOp!=0 );

References Parse::db, WhereLevel::iLikeRepCntr, sqlite3::mallocFailed, OP_String8, VdbeOp::opcode, VdbeOp::p3, VdbeOp::p5, WhereInfo::pParse, WhereTerm::pWC, WhereClause::pWInfo, sqlite3VdbeGetOp(), TERM_LIKEOPT, and WhereTerm::wtFlags.

◆ whereLoopAddAll()

static int whereLoopAddAll ( WhereLoopBuilder * pBuilder)
static

Definition at line 149207 of file sqlite3.c.

149213 {
149214 WhereInfo *pWInfo = pBuilder->pWInfo;
149215 Bitmask mPrereq = 0;
149216 Bitmask mPrior = 0;
149217 int iTab;
149218 SrcList *pTabList = pWInfo->pTabList;
149219 struct SrcList_item *pItem;
149220 struct SrcList_item *pEnd = &pTabList->a[pWInfo->nLevel];
149221 sqlite3 *db = pWInfo->pParse->db;
149222 int rc = SQLITE_OK;
149223 WhereLoop *pNew;
149224
149225 /* Loop over the tables in the join, from left to right */
149226 pNew = pBuilder->pNew;
149227 whereLoopInit(pNew);
149229 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
149230 Bitmask mUnusable = 0;
149231 pNew->iTab = iTab;
149233 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
149234 if( (pItem->fg.jointype & (JT_LEFT|JT_CROSS))!=0 ){
149235 /* This condition is true when pItem is the FROM clause term on the
149236 ** right-hand-side of a LEFT or CROSS JOIN. */
149237 mPrereq = mPrior;
149238 }else{
149239 mPrereq = 0;
149240 }
149241#ifndef SQLITE_OMIT_VIRTUALTABLE
149242 if( IsVirtual(pItem->pTab) ){
149243 struct SrcList_item *p;
149244 for(p=&pItem[1]; p<pEnd; p++){
149245 if( mUnusable || (p->fg.jointype & (JT_LEFT|JT_CROSS)) ){
149246 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
149247 }
149248 }
149249 rc = whereLoopAddVirtual(pBuilder, mPrereq, mUnusable);
149250 }else
149251#endif /* SQLITE_OMIT_VIRTUALTABLE */
149252 {
149253 rc = whereLoopAddBtree(pBuilder, mPrereq);
149254 }
149255 if( rc==SQLITE_OK && pBuilder->pWC->hasOr ){
149256 rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable);
149257 }
149258 mPrior |= pNew->maskSelf;
149259 if( rc || db->mallocFailed ){
149260 if( rc==SQLITE_DONE ){
149261 /* We hit the query planner search limit set by iPlanLimit */
149262 sqlite3_log(SQLITE_WARNING, "abbreviated query algorithm search");
149263 rc = SQLITE_OK;
149264 }else{
149265 break;
149266 }
#define SQLITE_QUERY_PLANNER_LIMIT_INCR
Definition sqlite3.c:141356
static int whereLoopAddOr(WhereLoopBuilder *pBuilder, Bitmask mPrereq, Bitmask mUnusable)
Definition sqlite3.c:149083
static int whereLoopAddBtree(WhereLoopBuilder *pBuilder, Bitmask mPrereq)
Definition sqlite3.c:148501
#define SQLITE_QUERY_PLANNER_LIMIT
Definition sqlite3.c:141353
static int whereLoopAddVirtual(WhereLoopBuilder *pBuilder, Bitmask mPrereq, Bitmask mUnusable)
Definition sqlite3.c:148960
unsigned int iPlanLimit
Definition sqlite3.c:141330

Referenced by sqlite3WhereBegin().

◆ whereLoopAddBtree()

static int whereLoopAddBtree ( WhereLoopBuilder * pBuilder,
Bitmask mPrereq )
static

Definition at line 148501 of file sqlite3.c.

148510 {
148511 WhereInfo *pWInfo; /* WHERE analysis context */
148512 Index *pProbe; /* An index we are evaluating */
148513 Index sPk; /* A fake index object for the primary key */
148514 LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */
148515 i16 aiColumnPk = -1; /* The aColumn[] value for the sPk index */
148516 SrcList *pTabList; /* The FROM clause */
148517 struct SrcList_item *pSrc; /* The FROM clause btree term to add */
148518 WhereLoop *pNew; /* Template WhereLoop object */
148519 int rc = SQLITE_OK; /* Return code */
148520 int iSortIdx = 1; /* Index number */
148521 int b; /* A boolean value */
148522 LogEst rSize; /* number of rows in the table */
148523 LogEst rLogSize; /* Logarithm of the number of rows in the table */
148524 WhereClause *pWC; /* The parsed WHERE clause */
148525 Table *pTab; /* Table being queried */
148526
148527 pNew = pBuilder->pNew;
148528 pWInfo = pBuilder->pWInfo;
148529 pTabList = pWInfo->pTabList;
148530 pSrc = pTabList->a + pNew->iTab;
148531 pTab = pSrc->pTab;
148532 pWC = pBuilder->pWC;
148533 assert( !IsVirtual(pSrc->pTab) );
148534
148535 if( pSrc->pIBIndex ){
148536 /* An INDEXED BY clause specifies a particular index to use */
148537 pProbe = pSrc->pIBIndex;
148538 }else if( !HasRowid(pTab) ){
148539 pProbe = pTab->pIndex;
148540 }else{
148541 /* There is no INDEXED BY clause. Create a fake Index object in local
148542 ** variable sPk to represent the rowid primary key index. Make this
148543 ** fake index the first in a chain of Index objects with all of the real
148544 ** indices to follow */
148545 Index *pFirst; /* First of real indices on the table */
148546 memset(&sPk, 0, sizeof(Index));
148547 sPk.nKeyCol = 1;
148548 sPk.nColumn = 1;
148549 sPk.aiColumn = &aiColumnPk;
148550 sPk.aiRowLogEst = aiRowEstPk;
148551 sPk.onError = OE_Replace;
148552 sPk.pTable = pTab;
148553 sPk.szIdxRow = pTab->szTabRow;
148555 aiRowEstPk[0] = pTab->nRowLogEst;
148556 aiRowEstPk[1] = 0;
148557 pFirst = pSrc->pTab->pIndex;
148558 if( pSrc->fg.notIndexed==0 ){
148559 /* The real indices of the table are only considered if the
148560 ** NOT INDEXED qualifier is omitted from the FROM clause */
148561 sPk.pNext = pFirst;
148562 }
148563 pProbe = &sPk;
148564 }
148565 rSize = pTab->nRowLogEst;
148566 rLogSize = estLog(rSize);
148567
148568#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
148569 /* Automatic indexes */
148570 if( !pBuilder->pOrSet /* Not part of an OR optimization */
148571 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
148572 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
148573 && pSrc->pIBIndex==0 /* Has no INDEXED BY clause */
148574 && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
148575 && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
148576 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
148577 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
148578 ){
148579 /* Generate auto-index WhereLoops */
148580 WhereTerm *pTerm;
148581 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
148582 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
148583 if( pTerm->prereqRight & pNew->maskSelf ) continue;
148584 if( termCanDriveIndex(pTerm, pSrc, 0) ){
148585 pNew->u.btree.nEq = 1;
148586 pNew->nSkip = 0;
148587 pNew->u.btree.pIndex = 0;
148588 pNew->nLTerm = 1;
148589 pNew->aLTerm[0] = pTerm;
148590 /* TUNING: One-time cost for computing the automatic index is
148591 ** estimated to be X*N*log2(N) where N is the number of rows in
148592 ** the table being indexed and where X is 7 (LogEst=28) for normal
148593 ** tables or 0.5 (LogEst=-10) for views and subqueries. The value
148594 ** of X is smaller for views and subqueries so that the query planner
148595 ** will be more aggressive about generating automatic indexes for
148596 ** those objects, since there is no opportunity to add schema
148597 ** indexes on subqueries and views. */
148598 pNew->rSetup = rLogSize + rSize;
148599 if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){
148600 pNew->rSetup += 28;
148601 }else{
148602 pNew->rSetup -= 10;
148603 }
148604 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
148605 if( pNew->rSetup<0 ) pNew->rSetup = 0;
148606 /* TUNING: Each index lookup yields 20 rows in the table. This
148607 ** is more than the usual guess of 10 rows, since we have no way
148608 ** of knowing how selective the index will ultimately be. It would
148609 ** not be unreasonable to make this value much larger. */
148610 pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
148611 pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut);
148612 pNew->wsFlags = WHERE_AUTO_INDEX;
148613 pNew->prereq = mPrereq | pTerm->prereqRight;
148614 rc = whereLoopInsert(pBuilder, pNew);
148615 }
148616 }
148617 }
148618#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
148619
148620 /* Loop over all indices. If there was an INDEXED BY clause, then only
148621 ** consider index pProbe. */
148622 for(; rc==SQLITE_OK && pProbe;
148623 pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
148624 ){
148625 int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
148626 if( pProbe->pPartIdxWhere!=0
148627 && !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC,
148628 pProbe->pPartIdxWhere)
148629 ){
148630 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
148631 continue; /* Partial index inappropriate for this query */
148632 }
148633 if( pProbe->bNoQuery ) continue;
148634 rSize = pProbe->aiRowLogEst[0];
148635 pNew->u.btree.nEq = 0;
148636 pNew->u.btree.nBtm = 0;
148637 pNew->u.btree.nTop = 0;
148638 pNew->nSkip = 0;
148639 pNew->nLTerm = 0;
148640 pNew->iSortIdx = 0;
148641 pNew->rSetup = 0;
148642 pNew->prereq = mPrereq;
148643 pNew->nOut = rSize;
148644 pNew->u.btree.pIndex = pProbe;
148645 b = indexMightHelpWithOrderBy(pBuilder, pProbe, pSrc->iCursor);
148646
148647 /* The ONEPASS_DESIRED flags never occurs together with ORDER BY */
148648 assert( (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || b==0 );
148649 if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){
148650 /* Integer primary key index */
148651 pNew->wsFlags = WHERE_IPK;
148652
148653 /* Full table scan */
148654 pNew->iSortIdx = b ? iSortIdx : 0;
148655 /* TUNING: Cost of full table scan is (N*3.0). */
148656 pNew->rRun = rSize + 16;
148657 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
148658 whereLoopOutputAdjust(pWC, pNew, rSize);
148659 rc = whereLoopInsert(pBuilder, pNew);
148660 pNew->nOut = rSize;
148661 if( rc ) break;
148662 }else{
148663 Bitmask m;
148664 if( pProbe->isCovering ){
148666 m = 0;
148667 }else{
148668 m = pSrc->colUsed & pProbe->colNotIdxed;
148669 pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
148670 }
148671
148672 /* Full scan via index */
148673 if( b
148674 || !HasRowid(pTab)
148675 || pProbe->pPartIdxWhere!=0
148676 || pSrc->fg.isIndexedBy
148677 || ( m==0
148678 && pProbe->bUnordered==0
148679 && (pProbe->szIdxRow<pTab->szTabRow)
148680 && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
148681 && sqlite3GlobalConfig.bUseCis
148683 )
148684 ){
148685 pNew->iSortIdx = b ? iSortIdx : 0;
148686
148687 /* The cost of visiting the index rows is N*K, where K is
148688 ** between 1.1 and 3.0, depending on the relative sizes of the
148689 ** index and table rows. */
148690 pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
148691 if( m!=0 ){
148692 /* If this is a non-covering index scan, add in the cost of
148693 ** doing table lookups. The cost will be 3x the number of
148694 ** lookups. Take into account WHERE clause terms that can be
148695 ** satisfied using just the index, and that do not require a
148696 ** table lookup. */
148697 LogEst nLookup = rSize + 16; /* Base cost: N*3 */
148698 int ii;
148699 int iCur = pSrc->iCursor;
148700 WhereClause *pWC2 = &pWInfo->sWC;
148701 for(ii=0; ii<pWC2->nTerm; ii++){
148702 WhereTerm *pTerm = &pWC2->a[ii];
148703 if( !sqlite3ExprCoveredByIndex(pTerm->pExpr, iCur, pProbe) ){
148704 break;
148705 }
148706 /* pTerm can be evaluated using just the index. So reduce
148707 ** the expected number of table lookups accordingly */
148708 if( pTerm->truthProb<=0 ){
148709 nLookup += pTerm->truthProb;
148710 }else{
148711 nLookup--;
148712 if( pTerm->eOperator & (WO_EQ|WO_IS) ) nLookup -= 19;
148713 }
148714 }
148715
148716 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, nLookup);
148717 }
148718 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
148719 whereLoopOutputAdjust(pWC, pNew, rSize);
148720 rc = whereLoopInsert(pBuilder, pNew);
148721 pNew->nOut = rSize;
148722 if( rc ) break;
148723 }
148724 }
148725
148726 pBuilder->bldFlags1 = 0;
148727 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
148728 if( pBuilder->bldFlags1==SQLITE_BLDF1_INDEXED ){
148729 /* If a non-unique index is used, or if a prefix of the key for
148730 ** unique index is used (making the index functionally non-unique)
148731 ** then the sqlite_stat1 data becomes important for scoring the
148732 ** plan */
148733 pTab->tabFlags |= TF_StatsUsed;
148734 }
148735#ifdef SQLITE_ENABLE_STAT4
148736 sqlite3Stat4ProbeFree(pBuilder->pRec);
#define ApplyCostMultiplier(C, T)
Definition sqlite3.c:148005
#define SQLITE_IDXTYPE_IPK
Definition sqlite3.c:17820
#define SQLITE_CoverIdxScan
Definition sqlite3.c:17046
static int indexMightHelpWithOrderBy(WhereLoopBuilder *pBuilder, Index *pIndex, int iCursor)
Definition sqlite3.c:148405
static int whereUsablePartialIndex(int iTab, int isLeft, WhereClause *pWC, Expr *pWhere)
Definition sqlite3.c:148438
#define SQLITE_BLDF1_INDEXED
Definition sqlite3.c:141334
static int whereLoopAddBtreeIndex(WhereLoopBuilder *pBuilder, struct SrcList_item *pSrc, Index *pProbe, LogEst nInMul)
Definition sqlite3.c:148020
static LogEst estLog(LogEst N)
Definition sqlite3.c:146171
static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate)
Definition sqlite3.c:147742
static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, LogEst nRow)
Definition sqlite3.c:147879
unsigned char bldFlags1
Definition sqlite3.c:141328
WhereOrSet * pOrSet
Definition sqlite3.c:141323
LogEst rRun
Definition sqlite3.c:141040
LogEst rSetup
Definition sqlite3.c:141039

References SrcList::a, WhereClause::a, Index::aiColumn, Index::aiRowLogEst, WhereLoop::aLTerm, ApplyCostMultiplier, WhereLoopBuilder::bldFlags1, Index::bNoQuery, WhereLoop::btree, Index::bUnordered, Index::colNotIdxed, Parse::db, WhereTerm::eOperator, estLog(), sqlite3::flags, HasRowid, Index::idxType, indexMightHelpWithOrderBy(), Index::isCovering, WhereLoop::iSortIdx, IsVirtual, WhereLoop::iTab, JT_OUTER, WhereLoop::maskSelf, WhereLoop::nBtm, Index::nColumn, WhereLoop::nEq, Index::nKeyCol, WhereLoop::nLTerm, WhereLoop::nOut, Table::nRowLogEst, WhereLoop::nSkip, WhereClause::nTerm, WhereLoop::nTop, OE_Replace, Index::onError, OptimizationEnabled, WhereTerm::pExpr, Table::pIndex, WhereLoop::pIndex, WhereLoopBuilder::pNew, Index::pNext, WhereLoopBuilder::pOrSet, WhereInfo::pParse, Index::pPartIdxWhere, WhereLoop::prereq, WhereTerm::prereqRight, Table::pSelect, Index::pTable, WhereInfo::pTabList, WhereLoopBuilder::pWC, WhereLoopBuilder::pWInfo, WhereLoop::rRun, WhereLoop::rSetup, sqlite3ExprCoveredByIndex(), sqlite3GlobalConfig, sqlite3LogEst(), sqlite3LogEstAdd(), SQLITE_AutoIndex, SQLITE_BLDF1_INDEXED, SQLITE_CoverIdxScan, SQLITE_IDXTYPE_IPK, SQLITE_OK, WhereInfo::sWC, Index::szIdxRow, Table::szTabRow, Table::tabFlags, termCanDriveIndex(), testcase, TF_Ephemeral, TF_StatsUsed, WhereTerm::truthProb, WhereLoop::u, WhereInfo::wctrlFlags, WHERE_AUTO_INDEX, WHERE_IDX_ONLY, WHERE_INDEXED, WHERE_IPK, WHERE_ONEPASS_DESIRED, WHERE_OR_SUBCLAUSE, whereLoopAddBtreeIndex(), whereLoopInsert(), whereLoopOutputAdjust(), whereUsablePartialIndex(), WO_EQ, WO_IS, and WhereLoop::wsFlags.

Referenced by whereLoopAddOr().

◆ whereLoopAddBtreeIndex()

static int whereLoopAddBtreeIndex ( WhereLoopBuilder * pBuilder,
struct SrcList_item * pSrc,
Index * pProbe,
LogEst nInMul )
static

Definition at line 148020 of file sqlite3.c.

148031 {
148032 WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */
148033 Parse *pParse = pWInfo->pParse; /* Parsing context */
148034 sqlite3 *db = pParse->db; /* Database connection malloc context */
148035 WhereLoop *pNew; /* Template WhereLoop under construction */
148036 WhereTerm *pTerm; /* A WhereTerm under consideration */
148037 int opMask; /* Valid operators for constraints */
148038 WhereScan scan; /* Iterator for WHERE terms */
148039 Bitmask saved_prereq; /* Original value of pNew->prereq */
148040 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
148041 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
148042 u16 saved_nBtm; /* Original value of pNew->u.btree.nBtm */
148043 u16 saved_nTop; /* Original value of pNew->u.btree.nTop */
148044 u16 saved_nSkip; /* Original value of pNew->nSkip */
148045 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
148046 LogEst saved_nOut; /* Original value of pNew->nOut */
148047 int rc = SQLITE_OK; /* Return code */
148048 LogEst rSize; /* Number of rows in the table */
148049 LogEst rLogSize; /* Logarithm of table size */
148050 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
148051
148052 pNew = pBuilder->pNew;
148053 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
148054 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d\n",
148055 pProbe->pTable->zName,pProbe->zName,
148056 pNew->u.btree.nEq, pNew->nSkip));
148057
148058 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
148059 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
148060 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
148061 opMask = WO_LT|WO_LE;
148062 }else{
148063 assert( pNew->u.btree.nBtm==0 );
148065 }
148066 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
148067
148068 assert( pNew->u.btree.nEq<pProbe->nColumn );
148069
148070 saved_nEq = pNew->u.btree.nEq;
148071 saved_nBtm = pNew->u.btree.nBtm;
148072 saved_nTop = pNew->u.btree.nTop;
148073 saved_nSkip = pNew->nSkip;
148074 saved_nLTerm = pNew->nLTerm;
148075 saved_wsFlags = pNew->wsFlags;
148076 saved_prereq = pNew->prereq;
148077 saved_nOut = pNew->nOut;
148078 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, saved_nEq,
148079 opMask, pProbe);
148080 pNew->rSetup = 0;
148081 rSize = pProbe->aiRowLogEst[0];
148082 rLogSize = estLog(rSize);
148083 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
148084 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
148085 LogEst rCostIdx;
148086 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
148087 int nIn = 0;
148088#ifdef SQLITE_ENABLE_STAT4
148089 int nRecValid = pBuilder->nRecValid;
148090#endif
148091 if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
148092 && indexColumnNotNull(pProbe, saved_nEq)
148093 ){
148094 continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
148095 }
148096 if( pTerm->prereqRight & pNew->maskSelf ) continue;
148097
148098 /* Do not allow the upper bound of a LIKE optimization range constraint
148099 ** to mix with a lower range bound from some other source */
148100 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
148101
148102 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
148103 ** be used by the right table of a LEFT JOIN. Only constraints in the
148104 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
148105 if( (pSrc->fg.jointype & JT_LEFT)!=0
148106 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
148107 ){
148108 continue;
148109 }
148110
148111 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
148112 pBuilder->bldFlags1 |= SQLITE_BLDF1_UNIQUE;
148113 }else{
148114 pBuilder->bldFlags1 |= SQLITE_BLDF1_INDEXED;
148115 }
148116 pNew->wsFlags = saved_wsFlags;
148117 pNew->u.btree.nEq = saved_nEq;
148118 pNew->u.btree.nBtm = saved_nBtm;
148119 pNew->u.btree.nTop = saved_nTop;
148120 pNew->nLTerm = saved_nLTerm;
148121 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
148122 pNew->aLTerm[pNew->nLTerm++] = pTerm;
148123 pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
148124
148125 assert( nInMul==0
148126 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
148127 || (pNew->wsFlags & WHERE_COLUMN_IN)!=0
148128 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
148129 );
148130
148131 if( eOp & WO_IN ){
148132 Expr *pExpr = pTerm->pExpr;
148133 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
148134 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
148135 int i;
148136 nIn = 46; assert( 46==sqlite3LogEst(25) );
148137
148138 /* The expression may actually be of the form (x, y) IN (SELECT...).
148139 ** In this case there is a separate term for each of (x) and (y).
148140 ** However, the nIn multiplier should only be applied once, not once
148141 ** for each such term. The following loop checks that pTerm is the
148142 ** first such term in use, and sets nIn back to 0 if it is not. */
148143 for(i=0; i<pNew->nLTerm-1; i++){
148144 if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ) nIn = 0;
148145 }
148146 }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
148147 /* "x IN (value, value, ...)" */
148148 nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
148149 }
148150 if( pProbe->hasStat1 ){
148151 LogEst M, logK, safetyMargin;
148152 /* Let:
148153 ** N = the total number of rows in the table
148154 ** K = the number of entries on the RHS of the IN operator
148155 ** M = the number of rows in the table that match terms to the
148156 ** to the left in the same index. If the IN operator is on
148157 ** the left-most index column, M==N.
148158 **
148159 ** Given the definitions above, it is better to omit the IN operator
148160 ** from the index lookup and instead do a scan of the M elements,
148161 ** testing each scanned row against the IN operator separately, if:
148162 **
148163 ** M*log(K) < K*log(N)
148164 **
148165 ** Our estimates for M, K, and N might be inaccurate, so we build in
148166 ** a safety margin of 2 (LogEst: 10) that favors using the IN operator
148167 ** with the index, as using an index has better worst-case behavior.
148168 ** If we do not have real sqlite_stat1 data, always prefer to use
148169 ** the index.
148170 */
148171 M = pProbe->aiRowLogEst[saved_nEq];
148172 logK = estLog(nIn);
148173 safetyMargin = 10; /* TUNING: extra weight for indexed IN */
148174 if( M + logK + safetyMargin < nIn + rLogSize ){
148175 WHERETRACE(0x40,
148176 ("Scan preferred over IN operator on column %d of \"%s\" (%d<%d)\n",
148177 saved_nEq, pProbe->zName, M+logK+10, nIn+rLogSize));
148178 continue;
148179 }else{
148180 WHERETRACE(0x40,
148181 ("IN operator preferred on column %d of \"%s\" (%d>=%d)\n",
148182 saved_nEq, pProbe->zName, M+logK+10, nIn+rLogSize));
148183 }
148184 }
148185 pNew->wsFlags |= WHERE_COLUMN_IN;
148186 }else if( eOp & (WO_EQ|WO_IS) ){
148187 int iCol = pProbe->aiColumn[saved_nEq];
148188 pNew->wsFlags |= WHERE_COLUMN_EQ;
148189 assert( saved_nEq==pNew->u.btree.nEq );
148190 if( iCol==XN_ROWID
148191 || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
148192 ){
148193 if( iCol==XN_ROWID || pProbe->uniqNotNull
148194 || (pProbe->nKeyCol==1 && pProbe->onError && eOp==WO_EQ)
148195 ){
148196 pNew->wsFlags |= WHERE_ONEROW;
148197 }else{
148198 pNew->wsFlags |= WHERE_UNQ_WANTED;
148199 }
148200 }
148201 }else if( eOp & WO_ISNULL ){
148202 pNew->wsFlags |= WHERE_COLUMN_NULL;
148203 }else if( eOp & (WO_GT|WO_GE) ){
148204 testcase( eOp & WO_GT );
148205 testcase( eOp & WO_GE );
148208 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
148209 );
148210 pBtm = pTerm;
148211 pTop = 0;
148212 if( pTerm->wtFlags & TERM_LIKEOPT ){
148213 /* Range contraints that come from the LIKE optimization are
148214 ** always used in pairs. */
148215 pTop = &pTerm[1];
148216 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
148217 assert( pTop->wtFlags & TERM_LIKEOPT );
148218 assert( pTop->eOperator==WO_LT );
148219 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
148220 pNew->aLTerm[pNew->nLTerm++] = pTop;
148221 pNew->wsFlags |= WHERE_TOP_LIMIT;
148222 pNew->u.btree.nTop = 1;
148223 }
148224 }else{
148225 assert( eOp & (WO_LT|WO_LE) );
148226 testcase( eOp & WO_LT );
148227 testcase( eOp & WO_LE );
148230 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
148231 );
148232 pTop = pTerm;
148233 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
148234 pNew->aLTerm[pNew->nLTerm-2] : 0;
148235 }
148236
148237 /* At this point pNew->nOut is set to the number of rows expected to
148238 ** be visited by the index scan before considering term pTerm, or the
148239 ** values of nIn and nInMul. In other words, assuming that all
148240 ** "x IN(...)" terms are replaced with "x = ?". This block updates
148241 ** the value of pNew->nOut to account for pTerm (but not nIn/nInMul). */
148242 assert( pNew->nOut==saved_nOut );
148243 if( pNew->wsFlags & WHERE_COLUMN_RANGE ){
148244 /* Adjust nOut using stat4 data. Or, if there is no stat4
148245 ** data, using some other estimate. */
148246 whereRangeScanEst(pParse, pBuilder, pBtm, pTop, pNew);
148247 }else{
148248 int nEq = ++pNew->u.btree.nEq;
148249 assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );
148250
148251 assert( pNew->nOut==saved_nOut );
148252 if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
148253 assert( (eOp & WO_IN) || nIn==0 );
148254 testcase( eOp & WO_IN );
148255 pNew->nOut += pTerm->truthProb;
148256 pNew->nOut -= nIn;
148257 }else{
148258#ifdef SQLITE_ENABLE_STAT4
148259 tRowcnt nOut = 0;
148260 if( nInMul==0
148261 && pProbe->nSample
148262 && pNew->u.btree.nEq<=pProbe->nSampleCol
148263 && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
148265 ){
148266 Expr *pExpr = pTerm->pExpr;
148267 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
148268 testcase( eOp & WO_EQ );
148269 testcase( eOp & WO_IS );
148270 testcase( eOp & WO_ISNULL );
148271 rc = whereEqualScanEst(pParse, pBuilder, pExpr->pRight, &nOut);
148272 }else{
148273 rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut);
148274 }
148275 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
148276 if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */
148277 if( nOut ){
148278 pNew->nOut = sqlite3LogEst(nOut);
148279 if( nEq==1
148280 /* TUNING: Mark terms as "low selectivity" if they seem likely
148281 ** to be true for half or more of the rows in the table.
148282 ** See tag-202002240-1 */
148283 && pNew->nOut+10 > pProbe->aiRowLogEst[0]
148284 ){
148285#if WHERETRACE_ENABLED /* 0x01 */
148286 if( sqlite3WhereTrace & 0x01 ){
148287 sqlite3DebugPrintf(
148288 "STAT4 determines term has low selectivity:\n");
148289 sqlite3WhereTermPrint(pTerm, 999);
148290 }
148291#endif
148292 pTerm->wtFlags |= TERM_HIGHTRUTH;
148293 if( pTerm->wtFlags & TERM_HEURTRUTH ){
148294 /* If the term has previously been used with an assumption of
148295 ** higher selectivity, then set the flag to rerun the
148296 ** loop computations. */
148297 pBuilder->bldFlags2 |= SQLITE_BLDF2_2NDPASS;
148298 }
148299 }
148300 if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut;
148301 pNew->nOut -= nIn;
148302 }
148303 }
148304 if( nOut==0 )
148305#endif
148306 {
148307 pNew->nOut += (pProbe->aiRowLogEst[nEq] - pProbe->aiRowLogEst[nEq-1]);
148308 if( eOp & WO_ISNULL ){
148309 /* TUNING: If there is no likelihood() value, assume that a
148310 ** "col IS NULL" expression matches twice as many rows
148311 ** as (col=?). */
148312 pNew->nOut += 10;
148313 }
148314 }
148315 }
148316 }
148317
148318 /* Set rCostIdx to the cost of visiting selected rows in index. Add
148319 ** it to pNew->rRun, which is currently set to the cost of the index
148320 ** seek only. Then, if this is a non-covering index, add the cost of
148321 ** visiting the rows in the main table. */
148322 assert( pSrc->pTab->szTabRow>0 );
148323 rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
148324 pNew->rRun = sqlite3LogEstAdd(rLogSize, rCostIdx);
148325 if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){
148326 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut + 16);
148327 }
148328 ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult);
148329
148330 nOutUnadjusted = pNew->nOut;
148331 pNew->rRun += nInMul + nIn;
148332 pNew->nOut += nInMul + nIn;
148333 whereLoopOutputAdjust(pBuilder->pWC, pNew, rSize);
148334 rc = whereLoopInsert(pBuilder, pNew);
148335
148336 if( pNew->wsFlags & WHERE_COLUMN_RANGE ){
148337 pNew->nOut = saved_nOut;
148338 }else{
148339 pNew->nOut = nOutUnadjusted;
148340 }
148341
148342 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
148343 && pNew->u.btree.nEq<pProbe->nColumn
148344 ){
148345 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
148346 }
148347 pNew->nOut = saved_nOut;
148348#ifdef SQLITE_ENABLE_STAT4
148349 pBuilder->nRecValid = nRecValid;
148350#endif
148351 }
148352 pNew->prereq = saved_prereq;
148353 pNew->u.btree.nEq = saved_nEq;
148354 pNew->u.btree.nBtm = saved_nBtm;
148355 pNew->u.btree.nTop = saved_nTop;
148356 pNew->nSkip = saved_nSkip;
148357 pNew->wsFlags = saved_wsFlags;
148358 pNew->nOut = saved_nOut;
148359 pNew->nLTerm = saved_nLTerm;
148360
148361 /* Consider using a skip-scan if there are no WHERE clause constraints
148362 ** available for the left-most terms of the index, and if the average
148363 ** number of repeats in the left-most terms is at least 18.
148364 **
148365 ** The magic number 18 is selected on the basis that scanning 17 rows
148366 ** is almost always quicker than an index seek (even though if the index
148367 ** contains fewer than 2^17 rows we assume otherwise in other parts of
148368 ** the code). And, even if it is not, it should not be too much slower.
148369 ** On the other hand, the extra seeks could end up being significantly
148370 ** more expensive. */
148371 assert( 42==sqlite3LogEst(18) );
148372 if( saved_nEq==saved_nSkip
148373 && saved_nEq+1<pProbe->nKeyCol
148374 && saved_nEq==pNew->nLTerm
148375 && pProbe->noSkipScan==0
148376 && pProbe->hasStat1!=0
148378 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
148379 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
148380 ){
148381 LogEst nIter;
148382 pNew->u.btree.nEq++;
148383 pNew->nSkip++;
148384 pNew->aLTerm[pNew->nLTerm++] = 0;
148385 pNew->wsFlags |= WHERE_SKIPSCAN;
148386 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
148387 pNew->nOut -= nIter;
148388 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
148389 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
148390 nIter += 5;
148391 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
148392 pNew->nOut = saved_nOut;
148393 pNew->u.btree.nEq = saved_nEq;
148394 pNew->nSkip = saved_nSkip;
148395 pNew->wsFlags = saved_wsFlags;
#define SQLITE_SkipScan
Definition sqlite3.c:17056
#define TERM_HEURTRUTH
Definition sqlite3.c:141208
#define WHERE_COLUMN_NULL
Definition sqlite3.c:141515
#define SQLITE_BLDF1_UNIQUE
Definition sqlite3.c:141335
static int whereRangeScanEst(Parse *pParse, WhereLoopBuilder *pBuilder, WhereTerm *pLower, WhereTerm *pUpper, WhereLoop *pLoop)
Definition sqlite3.c:147069
static WhereTerm * whereScanNext(WhereScan *pScan)
Definition sqlite3.c:145848
#define TERM_HIGHTRUTH
Definition sqlite3.c:141212
static int whereRangeVectorLen(Parse *pParse, int iCur, Index *pIdx, int nEq, WhereTerm *pTerm)
Definition sqlite3.c:147949

References WhereClause::a, Index::aiColumn, Index::aiRowLogEst, WhereLoop::aLTerm, ALWAYS, ApplyCostMultiplier, WhereLoopBuilder::bldFlags1, WhereLoopBuilder::bldFlags2, WhereLoop::btree, Index::bUnordered, Parse::db, WhereTerm::eOperator, EP_FromJoin, EP_xIsSelect, estLog(), ExprHasProperty, Index::hasStat1, indexColumnNotNull(), IsUniqueIndex, JT_LEFT, sqlite3::mallocFailed, WhereLoop::maskSelf, WhereLoop::nBtm, Index::nColumn, WhereLoop::nEq, ExprList::nExpr, Index::nKeyCol, WhereLoop::nLTerm, Index::noSkipScan, WhereLoop::nOut, WhereLoop::nSkip, WhereClause::nTerm, WhereLoop::nTop, Index::onError, OptimizationEnabled, WhereTerm::pExpr, Expr::pList, WhereLoopBuilder::pNew, WhereInfo::pParse, WhereLoop::prereq, WhereTerm::prereqRight, Expr::pRight, Index::pTable, WhereTerm::pWC, WhereLoopBuilder::pWC, WhereLoopBuilder::pWInfo, WhereLoop::rRun, WhereLoop::rSetup, sqlite3LogEst(), sqlite3LogEstAdd(), SQLITE_BLDF1_INDEXED, SQLITE_BLDF1_UNIQUE, SQLITE_BLDF2_2NDPASS, SQLITE_NOMEM_BKPT, SQLITE_NOTFOUND, SQLITE_OK, SQLITE_SkipScan, SQLITE_Stat4, Index::szIdxRow, TERM_HEURTRUTH, TERM_HIGHTRUTH, TERM_LIKEOPT, TERM_VNULL, testcase, WhereTerm::truthProb, WhereLoop::u, Index::uniqNotNull, WHERE_BTM_LIMIT, WHERE_COLUMN_EQ, WHERE_COLUMN_IN, WHERE_COLUMN_NULL, WHERE_COLUMN_RANGE, WHERE_IDX_ONLY, WHERE_IPK, WHERE_ONEROW, WHERE_SKIPSCAN, WHERE_TOP_LIMIT, WHERE_UNQ_WANTED, WHERE_VIRTUALTABLE, whereLoopAddBtreeIndex(), whereLoopInsert(), whereLoopOutputAdjust(), whereLoopResize(), whereRangeScanEst(), whereRangeVectorLen(), whereScanInit(), whereScanNext(), WHERETRACE, WO_EQ, WO_GE, WO_GT, WO_IN, WO_IS, WO_ISNULL, WO_LE, WO_LT, WhereLoop::wsFlags, WhereTerm::wtFlags, Expr::x, XN_ROWID, Table::zName, and Index::zName.

Referenced by whereLoopAddBtree(), and whereLoopAddBtreeIndex().

◆ whereLoopAddOr()

static int whereLoopAddOr ( WhereLoopBuilder * pBuilder,
Bitmask mPrereq,
Bitmask mUnusable )
static

Definition at line 149083 of file sqlite3.c.

149093 {
149094 WhereInfo *pWInfo = pBuilder->pWInfo;
149095 WhereClause *pWC;
149096 WhereLoop *pNew;
149097 WhereTerm *pTerm, *pWCEnd;
149098 int rc = SQLITE_OK;
149099 int iCur;
149100 WhereClause tempWC;
149101 WhereLoopBuilder sSubBuild;
149102 WhereOrSet sSum, sCur;
149103 struct SrcList_item *pItem;
149104
149105 pWC = pBuilder->pWC;
149106 pWCEnd = pWC->a + pWC->nTerm;
149107 pNew = pBuilder->pNew;
149108 memset(&sSum, 0, sizeof(sSum));
149109 pItem = pWInfo->pTabList->a + pNew->iTab;
149110 iCur = pItem->iCursor;
149111
149112 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
149113 if( (pTerm->eOperator & WO_OR)!=0
149114 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
149115 ){
149116 WhereClause * const pOrWC = &pTerm->u.pOrInfo->wc;
149117 WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm];
149118 WhereTerm *pOrTerm;
149119 int once = 1;
149120 int i, j;
149121
149122 sSubBuild = *pBuilder;
149123 sSubBuild.pOrderBy = 0;
149124 sSubBuild.pOrSet = &sCur;
149125
149126 WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
149127 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
149128 if( (pOrTerm->eOperator & WO_AND)!=0 ){
149129 sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
149130 }else if( pOrTerm->leftCursor==iCur ){
149131 tempWC.pWInfo = pWC->pWInfo;
149132 tempWC.pOuter = pWC;
149133 tempWC.op = TK_AND;
149134 tempWC.nTerm = 1;
149135 tempWC.a = pOrTerm;
149136 sSubBuild.pWC = &tempWC;
149137 }else{
149138 continue;
149139 }
149140 sCur.n = 0;
149141#ifdef WHERETRACE_ENABLED
149142 WHERETRACE(0x200, ("OR-term %d of %p has %d subterms:\n",
149143 (int)(pOrTerm-pOrWC->a), pTerm, sSubBuild.pWC->nTerm));
149144 if( sqlite3WhereTrace & 0x400 ){
149145 sqlite3WhereClausePrint(sSubBuild.pWC);
149146 }
149147#endif
149148#ifndef SQLITE_OMIT_VIRTUALTABLE
149149 if( IsVirtual(pItem->pTab) ){
149150 rc = whereLoopAddVirtual(&sSubBuild, mPrereq, mUnusable);
149151 }else
149152#endif
149153 {
149154 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
149155 }
149156 if( rc==SQLITE_OK ){
149157 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
149158 }
149159 assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 );
149160 testcase( rc==SQLITE_DONE );
149161 if( sCur.n==0 ){
149162 sSum.n = 0;
149163 break;
149164 }else if( once ){
149165 whereOrMove(&sSum, &sCur);
149166 once = 0;
149167 }else{
149168 WhereOrSet sPrev;
149169 whereOrMove(&sPrev, &sSum);
149170 sSum.n = 0;
149171 for(i=0; i<sPrev.n; i++){
149172 for(j=0; j<sCur.n; j++){
149173 whereOrInsert(&sSum, sPrev.a[i].prereq | sCur.a[j].prereq,
149174 sqlite3LogEstAdd(sPrev.a[i].rRun, sCur.a[j].rRun),
149175 sqlite3LogEstAdd(sPrev.a[i].nOut, sCur.a[j].nOut));
149176 }
149177 }
149178 }
149179 }
149180 pNew->nLTerm = 1;
149181 pNew->aLTerm[0] = pTerm;
149182 pNew->wsFlags = WHERE_MULTI_OR;
149183 pNew->rSetup = 0;
149184 pNew->iSortIdx = 0;
149185 memset(&pNew->u, 0, sizeof(pNew->u));
149186 for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
149187 /* TUNING: Currently sSum.a[i].rRun is set to the sum of the costs
149188 ** of all sub-scans required by the OR-scan. However, due to rounding
149189 ** errors, it may be that the cost of the OR-scan is equal to its
149190 ** most expensive sub-scan. Add the smallest possible penalty
149191 ** (equivalent to multiplying the cost by 1.07) to ensure that
149192 ** this does not happen. Otherwise, for WHERE clauses such as the
149193 ** following where there is an index on "y":
149194 **
149195 ** WHERE likelihood(x=?, 0.99) OR y=?
149196 **
149197 ** the planner may elect to "OR" together a full-table scan and an
149198 ** index lookup. And other similarly odd results. */
149199 pNew->rRun = sSum.a[i].rRun + 1;
149200 pNew->nOut = sSum.a[i].nOut;
149201 pNew->prereq = sSum.a[i].prereq;
149202 rc = whereLoopInsert(pBuilder, pNew);
static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc)
Definition sqlite3.c:145770
static int whereOrInsert(WhereOrSet *pSet, Bitmask prereq, LogEst rRun, LogEst nOut)
Definition sqlite3.c:145782
Bitmask prereq
Definition sqlite3.c:141074
LogEst rRun
Definition sqlite3.c:141075
LogEst nOut
Definition sqlite3.c:141076
WhereOrCost a[N_OR_COST]
Definition sqlite3.c:141086

References SrcList::a, WhereOrSet::a, WhereClause::a, WhereLoop::aLTerm, WhereTerm::eOperator, WhereOrInfo::indexable, WhereLoop::iSortIdx, IsVirtual, WhereLoop::iTab, WhereTerm::leftCursor, WhereLoop::maskSelf, WhereOrSet::n, WhereLoop::nLTerm, WhereLoop::nOut, WhereOrCost::nOut, WhereClause::nTerm, WhereClause::op, WhereTerm::pAndInfo, WhereLoopBuilder::pNew, WhereLoopBuilder::pOrderBy, WhereTerm::pOrInfo, WhereLoopBuilder::pOrSet, WhereClause::pOuter, WhereLoop::prereq, WhereOrCost::prereq, WhereInfo::pTabList, WhereLoopBuilder::pWC, WhereClause::pWInfo, WhereLoopBuilder::pWInfo, WhereLoop::rRun, WhereOrCost::rRun, WhereLoop::rSetup, sqlite3LogEstAdd(), SQLITE_DONE, SQLITE_OK, testcase, TK_AND, WhereLoop::u, WhereTerm::u, WhereOrInfo::wc, WhereAndInfo::wc, WHERE_MULTI_OR, whereLoopAddBtree(), whereLoopAddOr(), whereLoopAddVirtual(), whereLoopInsert(), whereOrInsert(), whereOrMove(), WHERETRACE, WO_AND, WO_OR, and WhereLoop::wsFlags.

Referenced by whereLoopAddOr().

◆ whereLoopAddVirtual()

static int whereLoopAddVirtual ( WhereLoopBuilder * pBuilder,
Bitmask mPrereq,
Bitmask mUnusable )
static

Definition at line 148960 of file sqlite3.c.

148970 {
148971 int rc = SQLITE_OK; /* Return code */
148972 WhereInfo *pWInfo; /* WHERE analysis context */
148973 Parse *pParse; /* The parsing context */
148974 WhereClause *pWC; /* The WHERE clause */
148975 struct SrcList_item *pSrc; /* The FROM clause term to search */
148976 sqlite3_index_info *p; /* Object to pass to xBestIndex() */
148977 int nConstraint; /* Number of constraints in p */
148978 int bIn; /* True if plan uses IN(...) operator */
148979 WhereLoop *pNew;
148980 Bitmask mBest; /* Tables used by best possible plan */
148981 u16 mNoOmit;
148982
148983 assert( (mPrereq & mUnusable)==0 );
148984 pWInfo = pBuilder->pWInfo;
148985 pParse = pWInfo->pParse;
148986 pWC = pBuilder->pWC;
148987 pNew = pBuilder->pNew;
148988 pSrc = &pWInfo->pTabList->a[pNew->iTab];
148989 assert( IsVirtual(pSrc->pTab) );
148990 p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy,
148991 &mNoOmit);
148992 if( p==0 ) return SQLITE_NOMEM_BKPT;
148993 pNew->rSetup = 0;
148994 pNew->wsFlags = WHERE_VIRTUALTABLE;
148995 pNew->nLTerm = 0;
148996 pNew->u.vtab.needFree = 0;
148997 nConstraint = p->nConstraint;
148998 if( whereLoopResize(pParse->db, pNew, nConstraint) ){
148999 sqlite3DbFree(pParse->db, p);
149000 return SQLITE_NOMEM_BKPT;
149001 }
149002
149003 /* First call xBestIndex() with all constraints usable. */
149004 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
149005 WHERETRACE(0x40, (" VirtualOne: all usable\n"));
149006 rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
149007
149008 /* If the call to xBestIndex() with all terms enabled produced a plan
149009 ** that does not require any source tables (IOW: a plan with mBest==0)
149010 ** and does not use an IN(...) operator, then there is no point in making
149011 ** any further calls to xBestIndex() since they will all return the same
149012 ** result (if the xBestIndex() implementation is sane). */
149013 if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
149014 int seenZero = 0; /* True if a plan with no prereqs seen */
149015 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
149016 Bitmask mPrev = 0;
149017 Bitmask mBestNoIn = 0;
149018
149019 /* If the plan produced by the earlier call uses an IN(...) term, call
149020 ** xBestIndex again, this time with IN(...) terms disabled. */
149021 if( bIn ){
149022 WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n"));
149024 pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn);
149025 assert( bIn==0 );
149026 mBestNoIn = pNew->prereq & ~mPrereq;
149027 if( mBestNoIn==0 ){
149028 seenZero = 1;
149029 seenZeroNoIN = 1;
149030 }
149031 }
149032
149033 /* Call xBestIndex once for each distinct value of (prereqRight & ~mPrereq)
149034 ** in the set of terms that apply to the current virtual table. */
149035 while( rc==SQLITE_OK ){
149036 int i;
149037 Bitmask mNext = ALLBITS;
149038 assert( mNext>0 );
149039 for(i=0; i<nConstraint; i++){
149040 Bitmask mThis = (
149041 pWC->a[p->aConstraint[i].iTermOffset].prereqRight & ~mPrereq
149042 );
149043 if( mThis>mPrev && mThis<mNext ) mNext = mThis;
149044 }
149045 mPrev = mNext;
149046 if( mNext==ALLBITS ) break;
149047 if( mNext==mBest || mNext==mBestNoIn ) continue;
149048 WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
149049 (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext));
149051 pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn);
149052 if( pNew->prereq==mPrereq ){
149053 seenZero = 1;
149054 if( bIn==0 ) seenZeroNoIN = 1;
149055 }
149056 }
149057
149058 /* If the calls to xBestIndex() in the above loop did not find a plan
149059 ** that requires no source tables at all (i.e. one guaranteed to be
149060 ** usable), make a call here with all source tables disabled */
149061 if( rc==SQLITE_OK && seenZero==0 ){
149062 WHERETRACE(0x40, (" VirtualOne: all disabled\n"));
149064 pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn);
149065 if( bIn==0 ) seenZeroNoIN = 1;
149066 }
149067
149068 /* If the calls to xBestIndex() have so far failed to find a plan
149069 ** that requires no source tables at all and does not use an IN(...)
149070 ** operator, make a final call to obtain one here. */
149071 if( rc==SQLITE_OK && seenZeroNoIN==0 ){
149072 WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n"));
149074 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
149075 }
149076 }
static int whereLoopAddVirtualOne(WhereLoopBuilder *pBuilder, Bitmask mPrereq, Bitmask mUsable, u16 mExclude, sqlite3_index_info *pIdxInfo, u16 mNoOmit, int *pbIn)
Definition sqlite3.c:148760
static sqlite3_index_info * allocateIndexInfo(Parse *pParse, WhereClause *pWC, Bitmask mUnusable, struct SrcList_item *pSrc, ExprList *pOrderBy, u16 *pmNoOmit)
Definition sqlite3.c:146509

References SrcList::a, WhereClause::a, sqlite3_index_info::aConstraint, ALLBITS, allocateIndexInfo(), Parse::db, sqlite3_index_info::idxStr, IsVirtual, WhereLoop::iTab, sqlite3_index_info::sqlite3_index_constraint::iTermOffset, sqlite3_index_info::nConstraint, WhereLoop::needFree, sqlite3_index_info::needToFreeIdxStr, WhereLoop::nLTerm, WhereLoopBuilder::pNew, WhereLoopBuilder::pOrderBy, WhereInfo::pParse, WhereLoop::prereq, WhereTerm::prereqRight, WhereInfo::pTabList, WhereLoopBuilder::pWC, WhereLoopBuilder::pWInfo, WhereLoop::rSetup, sqlite3_free(), sqlite3DbFree(), sqlite3DbFreeNN(), SQLITE_NOMEM_BKPT, SQLITE_OK, WhereLoop::u, WhereLoop::vtab, WHERE_VIRTUALTABLE, whereLoopAddVirtualOne(), whereLoopResize(), WHERETRACE, WO_IN, and WhereLoop::wsFlags.

Referenced by whereLoopAddOr().

◆ whereLoopAddVirtualOne()

static int whereLoopAddVirtualOne ( WhereLoopBuilder * pBuilder,
Bitmask mPrereq,
Bitmask mUsable,
u16 mExclude,
sqlite3_index_info * pIdxInfo,
u16 mNoOmit,
int * pbIn )
static

Definition at line 148760 of file sqlite3.c.

148774 {
148775 WhereClause *pWC = pBuilder->pWC;
148776 struct sqlite3_index_constraint *pIdxCons;
148777 struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
148778 int i;
148779 int mxTerm;
148780 int rc = SQLITE_OK;
148781 WhereLoop *pNew = pBuilder->pNew;
148782 Parse *pParse = pBuilder->pWInfo->pParse;
148783 struct SrcList_item *pSrc = &pBuilder->pWInfo->pTabList->a[pNew->iTab];
148784 int nConstraint = pIdxInfo->nConstraint;
148785
148786 assert( (mUsable & mPrereq)==mPrereq );
148787 *pbIn = 0;
148788 pNew->prereq = mPrereq;
148789
148790 /* Set the usable flag on the subset of constraints identified by
148791 ** arguments mUsable and mExclude. */
148792 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
148793 for(i=0; i<nConstraint; i++, pIdxCons++){
148794 WhereTerm *pTerm = &pWC->a[pIdxCons->iTermOffset];
148795 pIdxCons->usable = 0;
148796 if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight
148797 && (pTerm->eOperator & mExclude)==0
148798 ){
148799 pIdxCons->usable = 1;
148800 }
148801 }
148802
148803 /* Initialize the output fields of the sqlite3_index_info structure */
148804 memset(pUsage, 0, sizeof(pUsage[0])*nConstraint);
148805 assert( pIdxInfo->needToFreeIdxStr==0 );
148806 pIdxInfo->idxStr = 0;
148807 pIdxInfo->idxNum = 0;
148808 pIdxInfo->orderByConsumed = 0;
148809 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
148810 pIdxInfo->estimatedRows = 25;
148811 pIdxInfo->idxFlags = 0;
148812 pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
148813
148814 /* Invoke the virtual table xBestIndex() method */
148815 rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
148816 if( rc ){
148817 if( rc==SQLITE_CONSTRAINT ){
148818 /* If the xBestIndex method returns SQLITE_CONSTRAINT, that means
148819 ** that the particular combination of parameters provided is unusable.
148820 ** Make no entries in the loop table.
148821 */
148822 WHERETRACE(0xffff, (" ^^^^--- non-viable plan rejected!\n"));
148823 return SQLITE_OK;
148824 }
148825 return rc;
148826 }
148827
148828 mxTerm = -1;
148829 assert( pNew->nLSlot>=nConstraint );
148830 for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
148831 pNew->u.vtab.omitMask = 0;
148832 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
148833 for(i=0; i<nConstraint; i++, pIdxCons++){
148834 int iTerm;
148835 if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
148836 WhereTerm *pTerm;
148837 int j = pIdxCons->iTermOffset;
148838 if( iTerm>=nConstraint
148839 || j<0
148840 || j>=pWC->nTerm
148841 || pNew->aLTerm[iTerm]!=0
148842 || pIdxCons->usable==0
148843 ){
148844 sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName);
148845 testcase( pIdxInfo->needToFreeIdxStr );
148846 return SQLITE_ERROR;
148847 }
148848 testcase( iTerm==nConstraint-1 );
148849 testcase( j==0 );
148850 testcase( j==pWC->nTerm-1 );
148851 pTerm = &pWC->a[j];
148852 pNew->prereq |= pTerm->prereqRight;
148853 assert( iTerm<pNew->nLSlot );
148854 pNew->aLTerm[iTerm] = pTerm;
148855 if( iTerm>mxTerm ) mxTerm = iTerm;
148856 testcase( iTerm==15 );
148857 testcase( iTerm==16 );
148858 if( pUsage[i].omit ){
148859 if( i<16 && ((1<<i)&mNoOmit)==0 ){
148860 testcase( i!=iTerm );
148861 pNew->u.vtab.omitMask |= 1<<iTerm;
148862 }else{
148863 testcase( i!=iTerm );
148864 }
148865 }
148866 if( (pTerm->eOperator & WO_IN)!=0 ){
148867 /* A virtual table that is constrained by an IN clause may not
148868 ** consume the ORDER BY clause because (1) the order of IN terms
148869 ** is not necessarily related to the order of output terms and
148870 ** (2) Multiple outputs from a single IN value will not merge
148871 ** together. */
148872 pIdxInfo->orderByConsumed = 0;
148873 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
148874 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
148875 }
148876 }
148877 }
148878
148879 pNew->nLTerm = mxTerm+1;
148880 for(i=0; i<=mxTerm; i++){
148881 if( pNew->aLTerm[i]==0 ){
148882 /* The non-zero argvIdx values must be contiguous. Raise an
148883 ** error if they are not */
148884 sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName);
148885 testcase( pIdxInfo->needToFreeIdxStr );
148886 return SQLITE_ERROR;
148887 }
148888 }
148889 assert( pNew->nLTerm<=pNew->nLSlot );
148890 pNew->u.vtab.idxNum = pIdxInfo->idxNum;
148891 pNew->u.vtab.needFree = pIdxInfo->needToFreeIdxStr;
148892 pIdxInfo->needToFreeIdxStr = 0;
148893 pNew->u.vtab.idxStr = pIdxInfo->idxStr;
148894 pNew->u.vtab.isOrdered = (i8)(pIdxInfo->orderByConsumed ?
148895 pIdxInfo->nOrderBy : 0);
148896 pNew->rSetup = 0;
148897 pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
148898 pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);
148899
148900 /* Set the WHERE_ONEROW flag if the xBestIndex() method indicated
148901 ** that the scan will visit at most one row. Clear it otherwise. */
148902 if( pIdxInfo->idxFlags & SQLITE_INDEX_SCAN_UNIQUE ){
148903 pNew->wsFlags |= WHERE_ONEROW;
148904 }else{
148905 pNew->wsFlags &= ~WHERE_ONEROW;
148906 }
148907 rc = whereLoopInsert(pBuilder, pNew);
148908 if( pNew->u.vtab.needFree ){
148909 sqlite3_free(pNew->u.vtab.idxStr);
148910 pNew->u.vtab.needFree = 0;
148911 }
SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double)
Definition sqlite3.c:32734
static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p)
Definition sqlite3.c:146664
#define SQLITE_BIG_DBL
Definition sqlite3.c:14161
#define SQLITE_INDEX_SCAN_UNIQUE
Definition sqlite3.c:7937
INT8_TYPE i8
Definition sqlite3.c:14335
sqlite3_uint64 colUsed
Definition sqlite3.c:7927

References SrcList::a, WhereClause::a, sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, WhereLoop::aLTerm, sqlite3_index_info::colUsed, WhereTerm::eOperator, sqlite3_index_info::estimatedCost, sqlite3_index_info::estimatedRows, sqlite3_index_info::idxFlags, sqlite3_index_info::idxNum, WhereLoop::idxNum, sqlite3_index_info::idxStr, WhereLoop::idxStr, WhereLoop::isOrdered, WhereLoop::iTab, sqlite3_index_info::nConstraint, WhereLoop::needFree, sqlite3_index_info::needToFreeIdxStr, WhereLoop::nLSlot, WhereLoop::nLTerm, sqlite3_index_info::nOrderBy, WhereLoop::nOut, WhereClause::nTerm, WhereLoop::omitMask, sqlite3_index_info::orderByConsumed, WhereLoopBuilder::pNew, WhereInfo::pParse, WhereLoop::prereq, WhereTerm::prereqRight, WhereInfo::pTabList, WhereLoopBuilder::pWC, WhereLoopBuilder::pWInfo, WhereLoop::rRun, WhereLoop::rSetup, sqlite3_free(), sqlite3ErrorMsg(), sqlite3LogEst(), sqlite3LogEstFromDouble(), SQLITE_BIG_DBL, SQLITE_CONSTRAINT, SQLITE_ERROR, SQLITE_INDEX_SCAN_UNIQUE, SQLITE_OK, testcase, WhereLoop::u, WhereLoop::vtab, vtabBestIndex(), WHERE_ONEROW, whereLoopInsert(), WHERETRACE, WO_IN, and WhereLoop::wsFlags.

Referenced by whereLoopAddVirtual().

◆ whereLoopAdjustCost()

static void whereLoopAdjustCost ( const WhereLoop * p,
WhereLoop * pTemplate )
static

Definition at line 147617 of file sqlite3.c.

147623 {
147624 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
147625 for(; p; p=p->pNextLoop){
147626 if( p->iTab!=pTemplate->iTab ) continue;
147627 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
147628 if( whereLoopCheaperProperSubset(p, pTemplate) ){
147629 /* Adjust pTemplate cost downward so that it is cheaper than its
147630 ** subset p. */
147631 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
147632 pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1));
147633 pTemplate->rRun = p->rRun;
147634 pTemplate->nOut = p->nOut - 1;
147635 }else if( whereLoopCheaperProperSubset(pTemplate, p) ){
147636 /* Adjust pTemplate cost upward so that it is costlier than p since
147637 ** pTemplate is a proper subset of p */
147638 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
static int whereLoopCheaperProperSubset(const WhereLoop *pX, const WhereLoop *pY)
Definition sqlite3.c:147576

References WhereLoop::iTab, WhereLoop::nOut, WhereLoop::pNextLoop, WhereLoop::rRun, WHERE_INDEXED, whereLoopCheaperProperSubset(), WHERETRACE, and WhereLoop::wsFlags.

Referenced by whereLoopInsert().

◆ whereLoopCheaperProperSubset()

static int whereLoopCheaperProperSubset ( const WhereLoop * pX,
const WhereLoop * pY )
static

Definition at line 147576 of file sqlite3.c.

147585 {
147586 int i, j;
147587 if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){
147588 return 0; /* X is not a subset of Y */
147589 }
147590 if( pY->nSkip > pX->nSkip ) return 0;
147591 if( pX->rRun >= pY->rRun ){
147592 if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
147593 if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
147594 }
147595 for(i=pX->nLTerm-1; i>=0; i--){
147596 if( pX->aLTerm[i]==0 ) continue;
147597 for(j=pY->nLTerm-1; j>=0; j--){
147598 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
147599 }
147600 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
147601 }

References WhereLoop::aLTerm, WhereLoop::nLTerm, WhereLoop::nOut, WhereLoop::nSkip, WhereLoop::rRun, WHERE_IDX_ONLY, and WhereLoop::wsFlags.

Referenced by whereLoopAdjustCost().

◆ whereLoopClear()

static void whereLoopClear ( sqlite3 * db,
WhereLoop * p )
static

Definition at line 147487 of file sqlite3.c.

◆ whereLoopClearUnion()

static void whereLoopClearUnion ( sqlite3 * db,
WhereLoop * p )
static

Definition at line 147470 of file sqlite3.c.

147476 {
147478 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
147480 p->u.vtab.needFree = 0;
147481 p->u.vtab.idxStr = 0;
147482 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){

◆ whereLoopDelete()

static void whereLoopDelete ( sqlite3 * db,
WhereLoop * p )
static

Definition at line 147531 of file sqlite3.c.

Referenced by sqlite3WhereBegin(), and whereLoopInsert().

◆ whereLoopFindLesser()

static WhereLoop ** whereLoopFindLesser ( WhereLoop ** ppPrev,
const WhereLoop * pTemplate )
static

Definition at line 147654 of file sqlite3.c.

147663 {
147664 WhereLoop *p;
147665 for(p=(*ppPrev); p; ppPrev=&p->pNextLoop, p=*ppPrev){
147666 if( p->iTab!=pTemplate->iTab || p->iSortIdx!=pTemplate->iSortIdx ){
147667 /* If either the iTab or iSortIdx values for two WhereLoop are different
147668 ** then those WhereLoops need to be considered separately. Neither is
147669 ** a candidate to replace the other. */
147670 continue;
147671 }
147672 /* In the current implementation, the rSetup value is either zero
147673 ** or the cost of building an automatic index (NlogN) and the NlogN
147674 ** is the same for compatible WhereLoops. */
147675 assert( p->rSetup==0 || pTemplate->rSetup==0
147676 || p->rSetup==pTemplate->rSetup );
147677
147678 /* whereLoopAddBtree() always generates and inserts the automatic index
147679 ** case first. Hence compatible candidate WhereLoops never have a larger
147680 ** rSetup. Call this SETUP-INVARIANT */
147681 assert( p->rSetup>=pTemplate->rSetup );
147682
147683 /* Any loop using an appliation-defined index (or PRIMARY KEY or
147684 ** UNIQUE constraint) with one or more == constraints is better
147685 ** than an automatic index. Unless it is a skip-scan. */
147686 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
147687 && (pTemplate->nSkip)==0
147688 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
147689 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
147690 && (p->prereq & pTemplate->prereq)==pTemplate->prereq
147691 ){
147692 break;
147693 }
147694
147695 /* If existing WhereLoop p is better than pTemplate, pTemplate can be
147696 ** discarded. WhereLoop p is better if:
147697 ** (1) p has no more dependencies than pTemplate, and
147698 ** (2) p has an equal or lower cost than pTemplate
147699 */
147700 if( (p->prereq & pTemplate->prereq)==p->prereq /* (1) */
147701 && p->rSetup<=pTemplate->rSetup /* (2a) */
147702 && p->rRun<=pTemplate->rRun /* (2b) */
147703 && p->nOut<=pTemplate->nOut /* (2c) */
147704 ){
147705 return 0; /* Discard pTemplate */
147706 }
147707
147708 /* If pTemplate is always better than p, then cause p to be overwritten
147709 ** with pTemplate. pTemplate is better than p if:
147710 ** (1) pTemplate has no more dependences than p, and
147711 ** (2) pTemplate has an equal or lower cost than p.
147712 */
147713 if( (p->prereq & pTemplate->prereq)==pTemplate->prereq /* (1) */
147714 && p->rRun>=pTemplate->rRun /* (2a) */
147715 && p->nOut>=pTemplate->nOut /* (2b) */
147716 ){

References WhereLoop::iSortIdx, WhereLoop::iTab, WhereLoop::nOut, WhereLoop::nSkip, WhereLoop::pNextLoop, WhereLoop::prereq, WhereLoop::rRun, WhereLoop::rSetup, WHERE_AUTO_INDEX, WHERE_COLUMN_EQ, WHERE_INDEXED, and WhereLoop::wsFlags.

Referenced by whereLoopInsert().

◆ whereLoopInit()

static void whereLoopInit ( WhereLoop * p)
static

◆ whereLoopInsert()

static int whereLoopInsert ( WhereLoopBuilder * pBuilder,
WhereLoop * pTemplate )
static

Definition at line 147742 of file sqlite3.c.

147748 {
147749 WhereLoop **ppPrev, *p;
147750 WhereInfo *pWInfo = pBuilder->pWInfo;
147751 sqlite3 *db = pWInfo->pParse->db;
147752 int rc;
147753
147754 /* Stop the search once we hit the query planner search limit */
147755 if( pBuilder->iPlanLimit==0 ){
147756 WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
147757 if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
147758 return SQLITE_DONE;
147759 }
147760 pBuilder->iPlanLimit--;
147761
147762 whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
147763
147764 /* If pBuilder->pOrSet is defined, then only keep track of the costs
147765 ** and prereqs.
147766 */
147767 if( pBuilder->pOrSet!=0 ){
147768 if( pTemplate->nLTerm ){
147769#if WHERETRACE_ENABLED
147770 u16 n = pBuilder->pOrSet->n;
147771 int x =
147772#endif
147773 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
147774 pTemplate->nOut);
147775#if WHERETRACE_ENABLED /* 0x8 */
147776 if( sqlite3WhereTrace & 0x8 ){
147777 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
147778 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
147779 }
147780#endif
147781 }
147782 return SQLITE_OK;
147783 }
147784
147785 /* Look for an existing WhereLoop to replace with pTemplate
147786 */
147787 ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
147788
147789 if( ppPrev==0 ){
147790 /* There already exists a WhereLoop on the list that is better
147791 ** than pTemplate, so just ignore pTemplate */
147792#if WHERETRACE_ENABLED /* 0x8 */
147793 if( sqlite3WhereTrace & 0x8 ){
147794 sqlite3DebugPrintf(" skip: ");
147795 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
147796 }
147797#endif
147798 return SQLITE_OK;
147799 }else{
147800 p = *ppPrev;
147801 }
147802
147803 /* If we reach this point it means that either p[] should be overwritten
147804 ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
147805 ** WhereLoop and insert it.
147806 */
147807#if WHERETRACE_ENABLED /* 0x8 */
147808 if( sqlite3WhereTrace & 0x8 ){
147809 if( p!=0 ){
147810 sqlite3DebugPrintf("replace: ");
147811 sqlite3WhereLoopPrint(p, pBuilder->pWC);
147812 sqlite3DebugPrintf(" with: ");
147813 }else{
147814 sqlite3DebugPrintf(" add: ");
147815 }
147816 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
147817 }
147818#endif
147819 if( p==0 ){
147820 /* Allocate a new WhereLoop to add to the end of the list */
147821 *ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop));
147822 if( p==0 ) return SQLITE_NOMEM_BKPT;
147823 whereLoopInit(p);
147824 p->pNextLoop = 0;
147825 }else{
147826 /* We will be overwriting WhereLoop p[]. But before we do, first
147827 ** go through the rest of the list and delete any other entries besides
147828 ** p[] that are also supplated by pTemplate */
147829 WhereLoop **ppTail = &p->pNextLoop;
147830 WhereLoop *pToDel;
147831 while( *ppTail ){
147832 ppTail = whereLoopFindLesser(ppTail, pTemplate);
147833 if( ppTail==0 ) break;
147834 pToDel = *ppTail;
147835 if( pToDel==0 ) break;
147836 *ppTail = pToDel->pNextLoop;
147837#if WHERETRACE_ENABLED /* 0x8 */
147838 if( sqlite3WhereTrace & 0x8 ){
147839 sqlite3DebugPrintf(" delete: ");
147840 sqlite3WhereLoopPrint(pToDel, pBuilder->pWC);
147841 }
147842#endif
147843 whereLoopDelete(db, pToDel);
147844 }
147845 }
147846 rc = whereLoopXfer(db, p, pTemplate);
147847 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
147848 Index *pIndex = p->u.btree.pIndex;
static WhereLoop ** whereLoopFindLesser(WhereLoop **ppPrev, const WhereLoop *pTemplate)
Definition sqlite3.c:147654
static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate)
Definition sqlite3.c:147617
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom)
Definition sqlite3.c:147512

References WhereLoop::btree, Parse::db, Index::idxType, WhereLoopBuilder::iPlanLimit, WhereOrSet::n, WhereLoop::nLTerm, WhereLoop::nOut, WhereLoop::pIndex, WhereInfo::pLoops, WhereLoop::pNextLoop, WhereLoopBuilder::pOrSet, WhereInfo::pParse, WhereLoop::prereq, WhereLoopBuilder::pWC, WhereLoopBuilder::pWInfo, WhereLoop::rRun, sqlite3DbMallocRawNN(), SQLITE_DONE, SQLITE_IDXTYPE_IPK, SQLITE_NOMEM_BKPT, SQLITE_OK, WhereLoop::u, WHERE_VIRTUALTABLE, whereLoopAdjustCost(), whereLoopDelete(), whereLoopFindLesser(), whereLoopInit(), whereLoopXfer(), whereOrInsert(), WHERETRACE, and WhereLoop::wsFlags.

Referenced by whereLoopAddBtree(), whereLoopAddBtreeIndex(), whereLoopAddOr(), and whereLoopAddVirtualOne().

◆ whereLoopOutputAdjust()

static void whereLoopOutputAdjust ( WhereClause * pWC,
WhereLoop * pLoop,
LogEst nRow )
static

Definition at line 147879 of file sqlite3.c.

147889 {
147890 WhereTerm *pTerm, *pX;
147891 Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
147892 int i, j;
147893 LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */
147894
147895 assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
147896 for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
147897 assert( pTerm!=0 );
147898 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
147899 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
147900 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
147901 for(j=pLoop->nLTerm-1; j>=0; j--){
147902 pX = pLoop->aLTerm[j];
147903 if( pX==0 ) continue;
147904 if( pX==pTerm ) break;
147905 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
147906 }
147907 if( j<0 ){
147908 if( pTerm->truthProb<=0 ){
147909 /* If a truth probability is specified using the likelihood() hints,
147910 ** then use the probability provided by the application. */
147911 pLoop->nOut += pTerm->truthProb;
147912 }else{
147913 /* In the absence of explicit truth probabilities, use heuristics to
147914 ** guess a reasonable truth probability. */
147915 pLoop->nOut--;
147916 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
147917 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
147918 ){
147919 Expr *pRight = pTerm->pExpr->pRight;
147920 int k = 0;
147921 testcase( pTerm->pExpr->op==TK_IS );
147922 if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){
147923 k = 10;
147924 }else{
147925 k = 20;
147926 }
147927 if( iReduce<k ){
147928 pTerm->wtFlags |= TERM_HEURTRUTH;
147929 iReduce = k;
147930 }

References WhereClause::a, WhereLoop::aLTerm, WhereTerm::eOperator, WhereTerm::iParent, WhereLoop::maskSelf, WhereLoop::nLTerm, WhereLoop::nOut, WhereClause::nTerm, Expr::op, WhereTerm::pExpr, WhereLoop::prereq, WhereTerm::prereqAll, Expr::pRight, sqlite3ExprIsInteger(), TERM_HEURTRUTH, TERM_HIGHTRUTH, TERM_VIRTUAL, testcase, TK_IS, WhereTerm::truthProb, WHERE_AUTO_INDEX, WO_EQ, WO_IS, WhereLoop::wsFlags, and WhereTerm::wtFlags.

Referenced by whereLoopAddBtree(), and whereLoopAddBtreeIndex().

◆ whereLoopResize()

static int whereLoopResize ( sqlite3 * db,
WhereLoop * p,
int n )
static

Definition at line 147496 of file sqlite3.c.

147502 {
147503 WhereTerm **paNew;
147504 if( p->nLSlot>=n ) return SQLITE_OK;
147505 n = (n+7)&~7;
147506 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
147507 if( paNew==0 ) return SQLITE_NOMEM_BKPT;

Referenced by constructAutomaticIndex(), whereLoopAddBtreeIndex(), and whereLoopAddVirtual().

◆ whereLoopXfer()

static int whereLoopXfer ( sqlite3 * db,
WhereLoop * pTo,
WhereLoop * pFrom )
static

Definition at line 147512 of file sqlite3.c.

147518 {
147519 whereLoopClearUnion(db, pTo);
147520 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
147521 memset(&pTo->u, 0, sizeof(pTo->u));
147522 return SQLITE_NOMEM_BKPT;
147523 }
147524 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
147525 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
147526 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
#define WHERE_LOOP_XFER_SZ
Definition sqlite3.c:141062
static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p)
Definition sqlite3.c:147470

Referenced by whereLoopInsert().

◆ whereNthSubterm()

static WhereTerm * whereNthSubterm ( WhereTerm * pTerm,
int N )
static

Definition at line 144462 of file sqlite3.c.

144468 {
144469 if( pTerm->eOperator!=WO_AND ){
144470 return N==0 ? pTerm : 0;

References WhereClause::a, WhereTerm::eOperator, WhereTerm::pAndInfo, WhereTerm::u, WhereAndInfo::wc, and WO_AND.

Referenced by exprAnalyzeOrTerm().

◆ whereOrInfoDelete()

static void whereOrInfoDelete ( sqlite3 * db,
WhereOrInfo * p )
static

Definition at line 144018 of file sqlite3.c.

Referenced by sqlite3WhereClauseClear().

◆ whereOrInsert()

static int whereOrInsert ( WhereOrSet * pSet,
Bitmask prereq,
LogEst rRun,
LogEst nOut )
static

Definition at line 145782 of file sqlite3.c.

145793 {
145794 u16 i;
145795 WhereOrCost *p;
145796 for(i=pSet->n, p=pSet->a; i>0; i--, p++){
145797 if( rRun<=p->rRun && (prereq & p->prereq)==prereq ){
145798 goto whereOrInsert_done;
145799 }
145800 if( p->rRun<=rRun && (p->prereq & prereq)==p->prereq ){
145801 return 0;
145802 }
145803 }
145804 if( pSet->n<N_OR_COST ){
145805 p = &pSet->a[pSet->n++];
145806 p->nOut = nOut;
145807 }else{
145808 p = pSet->a;
145809 for(i=1; i<pSet->n; i++){
145810 if( p->rRun>pSet->a[i].rRun ) p = pSet->a + i;
145811 }
145812 if( p->rRun<=rRun ) return 0;
145813 }
#define N_OR_COST
Definition sqlite3.c:141083

References WhereOrSet::a, WhereOrSet::n, N_OR_COST, WhereOrCost::nOut, WhereOrCost::prereq, and WhereOrCost::rRun.

Referenced by whereLoopAddOr(), and whereLoopInsert().

◆ whereOrMove()

static void whereOrMove ( WhereOrSet * pDest,
WhereOrSet * pSrc )
static

Definition at line 145770 of file sqlite3.c.

Referenced by whereLoopAddOr().

◆ wherePathSatisfiesOrderBy()

static i8 wherePathSatisfiesOrderBy ( WhereInfo * pWInfo,
ExprList * pOrderBy,
WherePath * pPath,
u16 wctrlFlags,
u16 nLoop,
WhereLoop * pLast,
Bitmask * pRevMask )
static

Definition at line 149285 of file sqlite3.c.

149299 {
149300 u8 revSet; /* True if rev is known */
149301 u8 rev; /* Composite sort order */
149302 u8 revIdx; /* Index sort order */
149303 u8 isOrderDistinct; /* All prior WhereLoops are order-distinct */
149304 u8 distinctColumns; /* True if the loop has UNIQUE NOT NULL columns */
149305 u8 isMatch; /* iColumn matches a term of the ORDER BY clause */
149306 u16 eqOpMask; /* Allowed equality operators */
149307 u16 nKeyCol; /* Number of key columns in pIndex */
149308 u16 nColumn; /* Total number of ordered columns in the index */
149309 u16 nOrderBy; /* Number terms in the ORDER BY clause */
149310 int iLoop; /* Index of WhereLoop in pPath being processed */
149311 int i, j; /* Loop counters */
149312 int iCur; /* Cursor number for current WhereLoop */
149313 int iColumn; /* A column number within table iCur */
149314 WhereLoop *pLoop = 0; /* Current WhereLoop being processed. */
149315 WhereTerm *pTerm; /* A single term of the WHERE clause */
149316 Expr *pOBExpr; /* An expression from the ORDER BY clause */
149317 CollSeq *pColl; /* COLLATE function from an ORDER BY clause term */
149318 Index *pIndex; /* The index associated with pLoop */
149319 sqlite3 *db = pWInfo->pParse->db; /* Database connection */
149320 Bitmask obSat = 0; /* Mask of ORDER BY terms satisfied so far */
149321 Bitmask obDone; /* Mask of all ORDER BY terms */
149322 Bitmask orderDistinctMask; /* Mask of all well-ordered loops */
149323 Bitmask ready; /* Mask of inner loops */
149324
149325 /*
149326 ** We say the WhereLoop is "one-row" if it generates no more than one
149327 ** row of output. A WhereLoop is one-row if all of the following are true:
149328 ** (a) All index columns match with WHERE_COLUMN_EQ.
149329 ** (b) The index is unique
149330 ** Any WhereLoop with an WHERE_COLUMN_EQ constraint on the rowid is one-row.
149331 ** Every one-row WhereLoop will have the WHERE_ONEROW bit set in wsFlags.
149332 **
149333 ** We say the WhereLoop is "order-distinct" if the set of columns from
149334 ** that WhereLoop that are in the ORDER BY clause are different for every
149335 ** row of the WhereLoop. Every one-row WhereLoop is automatically
149336 ** order-distinct. A WhereLoop that has no columns in the ORDER BY clause
149337 ** is not order-distinct. To be order-distinct is not quite the same as being
149338 ** UNIQUE since a UNIQUE column or index can have multiple rows that
149339 ** are NULL and NULL values are equivalent for the purpose of order-distinct.
149340 ** To be order-distinct, the columns must be UNIQUE and NOT NULL.
149341 **
149342 ** The rowid for a table is always UNIQUE and NOT NULL so whenever the
149343 ** rowid appears in the ORDER BY clause, the corresponding WhereLoop is
149344 ** automatically order-distinct.
149345 */
149346
149347 assert( pOrderBy!=0 );
149348 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
149349
149350 nOrderBy = pOrderBy->nExpr;
149351 testcase( nOrderBy==BMS-1 );
149352 if( nOrderBy>BMS-1 ) return 0; /* Cannot optimize overly large ORDER BYs */
149353 isOrderDistinct = 1;
149354 obDone = MASKBIT(nOrderBy)-1;
149355 orderDistinctMask = 0;
149356 ready = 0;
149357 eqOpMask = WO_EQ | WO_IS | WO_ISNULL;
149359 eqOpMask |= WO_IN;
149360 }
149361 for(iLoop=0; isOrderDistinct && obSat<obDone && iLoop<=nLoop; iLoop++){
149362 if( iLoop>0 ) ready |= pLoop->maskSelf;
149363 if( iLoop<nLoop ){
149364 pLoop = pPath->aLoop[iLoop];
149365 if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
149366 }else{
149367 pLoop = pLast;
149368 }
149369 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
149370 if( pLoop->u.vtab.isOrdered && (wctrlFlags & WHERE_DISTINCTBY)==0 ){
149371 obSat = obDone;
149372 }
149373 break;
149374 }else if( wctrlFlags & WHERE_DISTINCTBY ){
149375 pLoop->u.btree.nDistinctCol = 0;
149376 }
149377 iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
149378
149379 /* Mark off any ORDER BY term X that is a column in the table of
149380 ** the current loop for which there is term in the WHERE
149381 ** clause of the form X IS NULL or X=? that reference only outer
149382 ** loops.
149383 */
149384 for(i=0; i<nOrderBy; i++){
149385 if( MASKBIT(i) & obSat ) continue;
149386 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
149387 if( pOBExpr->op!=TK_COLUMN ) continue;
149388 if( pOBExpr->iTable!=iCur ) continue;
149389 pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
149390 ~ready, eqOpMask, 0);
149391 if( pTerm==0 ) continue;
149392 if( pTerm->eOperator==WO_IN ){
149393 /* IN terms are only valid for sorting in the ORDER BY LIMIT
149394 ** optimization, and then only if they are actually used
149395 ** by the query plan */
149396 assert( wctrlFlags &
149398 for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){}
149399 if( j>=pLoop->nLTerm ) continue;
149400 }
149401 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){
149402 Parse *pParse = pWInfo->pParse;
149403 CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[i].pExpr);
149404 CollSeq *pColl2 = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr);
149405 assert( pColl1 );
149406 if( pColl2==0 || sqlite3StrICmp(pColl1->zName, pColl2->zName) ){
149407 continue;
149408 }
149409 testcase( pTerm->pExpr->op==TK_IS );
149410 }
149411 obSat |= MASKBIT(i);
149412 }
149413
149414 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
149415 if( pLoop->wsFlags & WHERE_IPK ){
149416 pIndex = 0;
149417 nKeyCol = 0;
149418 nColumn = 1;
149419 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
149420 return 0;
149421 }else{
149422 nKeyCol = pIndex->nKeyCol;
149423 nColumn = pIndex->nColumn;
149424 assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
149425 assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
149426 || !HasRowid(pIndex->pTable));
149427 isOrderDistinct = IsUniqueIndex(pIndex)
149428 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
149429 }
149430
149431 /* Loop through all columns of the index and deal with the ones
149432 ** that are not constrained by == or IN.
149433 */
149434 rev = revSet = 0;
149435 distinctColumns = 0;
149436 for(j=0; j<nColumn; j++){
149437 u8 bOnce = 1; /* True to run the ORDER BY search loop */
149438
149439 assert( j>=pLoop->u.btree.nEq
149440 || (pLoop->aLTerm[j]==0)==(j<pLoop->nSkip)
149441 );
149442 if( j<pLoop->u.btree.nEq && j>=pLoop->nSkip ){
149443 u16 eOp = pLoop->aLTerm[j]->eOperator;
149444
149445 /* Skip over == and IS and ISNULL terms. (Also skip IN terms when
149446 ** doing WHERE_ORDERBY_LIMIT processing). Except, IS and ISNULL
149447 ** terms imply that the index is not UNIQUE NOT NULL in which case
149448 ** the loop need to be marked as not order-distinct because it can
149449 ** have repeated NULL rows.
149450 **
149451 ** If the current term is a column of an ((?,?) IN (SELECT...))
149452 ** expression for which the SELECT returns more than one column,
149453 ** check that it is the only column used by this loop. Otherwise,
149454 ** if it is one of two or more, none of the columns can be
149455 ** considered to match an ORDER BY term.
149456 */
149457 if( (eOp & eqOpMask)!=0 ){
149458 if( eOp & (WO_ISNULL|WO_IS) ){
149459 testcase( eOp & WO_ISNULL );
149460 testcase( eOp & WO_IS );
149461 testcase( isOrderDistinct );
149462 isOrderDistinct = 0;
149463 }
149464 continue;
149465 }else if( ALWAYS(eOp & WO_IN) ){
149466 /* ALWAYS() justification: eOp is an equality operator due to the
149467 ** j<pLoop->u.btree.nEq constraint above. Any equality other
149468 ** than WO_IN is captured by the previous "if". So this one
149469 ** always has to be WO_IN. */
149470 Expr *pX = pLoop->aLTerm[j]->pExpr;
149471 for(i=j+1; i<pLoop->u.btree.nEq; i++){
149472 if( pLoop->aLTerm[i]->pExpr==pX ){
149473 assert( (pLoop->aLTerm[i]->eOperator & WO_IN) );
149474 bOnce = 0;
149475 break;
149476 }
149477 }
149478 }
149479 }
149480
149481 /* Get the column number in the table (iColumn) and sort order
149482 ** (revIdx) for the j-th column of the index.
149483 */
149484 if( pIndex ){
149485 iColumn = pIndex->aiColumn[j];
149486 revIdx = pIndex->aSortOrder[j] & KEYINFO_ORDER_DESC;
149487 if( iColumn==pIndex->pTable->iPKey ) iColumn = XN_ROWID;
149488 }else{
149489 iColumn = XN_ROWID;
149490 revIdx = 0;
149491 }
149492
149493 /* An unconstrained column that might be NULL means that this
149494 ** WhereLoop is not well-ordered
149495 */
149496 if( isOrderDistinct
149497 && iColumn>=0
149498 && j>=pLoop->u.btree.nEq
149499 && pIndex->pTable->aCol[iColumn].notNull==0
149500 ){
149501 isOrderDistinct = 0;
149502 }
149503
149504 /* Find the ORDER BY term that corresponds to the j-th column
149505 ** of the index and mark that ORDER BY term off
149506 */
149507 isMatch = 0;
149508 for(i=0; bOnce && i<nOrderBy; i++){
149509 if( MASKBIT(i) & obSat ) continue;
149510 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
149511 testcase( wctrlFlags & WHERE_GROUPBY );
149512 testcase( wctrlFlags & WHERE_DISTINCTBY );
149513 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
149514 if( iColumn>=XN_ROWID ){
149515 if( pOBExpr->op!=TK_COLUMN ) continue;
149516 if( pOBExpr->iTable!=iCur ) continue;
149517 if( pOBExpr->iColumn!=iColumn ) continue;
149518 }else{
149519 Expr *pIdxExpr = pIndex->aColExpr->a[j].pExpr;
149520 if( sqlite3ExprCompareSkip(pOBExpr, pIdxExpr, iCur) ){
149521 continue;
149522 }
149523 }
149524 if( iColumn!=XN_ROWID ){
149525 pColl = sqlite3ExprNNCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
149526 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
149527 }
149528 if( wctrlFlags & WHERE_DISTINCTBY ){
149529 pLoop->u.btree.nDistinctCol = j+1;
149530 }
149531 isMatch = 1;
149532 break;
149533 }
149534 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
149535 /* Make sure the sort order is compatible in an ORDER BY clause.
149536 ** Sort order is irrelevant for a GROUP BY clause. */
149537 if( revSet ){
149538 if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
149539 isMatch = 0;
149540 }
149541 }else{
149542 rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
149543 if( rev ) *pRevMask |= MASKBIT(iLoop);
149544 revSet = 1;
149545 }
149546 }
149547 if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
149548 if( j==pLoop->u.btree.nEq ){
149549 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
149550 }else{
149551 isMatch = 0;
149552 }
149553 }
149554 if( isMatch ){
149555 if( iColumn==XN_ROWID ){
149556 testcase( distinctColumns==0 );
149557 distinctColumns = 1;
149558 }
149559 obSat |= MASKBIT(i);
149560 }else{
149561 /* No match found */
149562 if( j==0 || j<nKeyCol ){
149563 testcase( isOrderDistinct!=0 );
149564 isOrderDistinct = 0;
149565 }
149566 break;
149567 }
149568 } /* end Loop over all index columns */
149569 if( distinctColumns ){
149570 testcase( isOrderDistinct==0 );
149571 isOrderDistinct = 1;
149572 }
149573 } /* end-if not one-row */
149574
149575 /* Mark off any other ORDER BY terms that reference pLoop */
149576 if( isOrderDistinct ){
149577 orderDistinctMask |= pLoop->maskSelf;
149578 for(i=0; i<nOrderBy; i++){
149579 Expr *p;
149580 Bitmask mTerm;
149581 if( MASKBIT(i) & obSat ) continue;
149582 p = pOrderBy->a[i].pExpr;
149583 mTerm = sqlite3WhereExprUsage(&pWInfo->sMaskSet,p);
149584 if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue;
149585 if( (mTerm&~orderDistinctMask)==0 ){
149586 obSat |= MASKBIT(i);
149587 }
149588 }
149589 }
149590 } /* End the loop over all WhereLoops from outer-most down to inner-most */
149591 if( obSat==obDone ) return (i8)nOrderBy;
149592 if( !isOrderDistinct ){
149593 for(i=nOrderBy-1; i>0; i--){
149594 Bitmask m = MASKBIT(i) - 1;
#define WHERE_ORDERBY_LIMIT
Definition sqlite3.c:18315
#define SQLITE_OrderByIdxJoin
Definition sqlite3.c:17047
WhereLoop ** aLoop
Definition sqlite3.c:141114

References ExprList::a, SrcList::a, Table::aCol, Index::aColExpr, Index::aiColumn, WherePath::aLoop, WhereLoop::aLTerm, ALWAYS, Index::aSortOrder, Index::azColl, BMS, WhereLoop::btree, Index::bUnordered, Parse::db, WhereTerm::eOperator, HasRowid, Expr::iColumn, SrcList::SrcList_item::iCursor, Table::iPKey, WhereLoop::isOrdered, IsUniqueIndex, WhereLoop::iTab, Expr::iTable, KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, MASKBIT, WhereLoop::maskSelf, Index::nColumn, WhereLoop::nDistinctCol, WhereLoop::nEq, ExprList::nExpr, Index::nKeyCol, WhereLoop::nLTerm, Column::notNull, WhereLoop::nSkip, Expr::op, OptimizationDisabled, ExprList::ExprList_item::pExpr, WhereTerm::pExpr, WhereLoop::pIndex, WhereInfo::pParse, Index::pTable, WhereInfo::pTabList, WhereInfo::sMaskSet, ExprList::ExprList_item::sortFlags, sqlite3ExprCompareCollSeq(), sqlite3ExprCompareSkip(), sqlite3ExprIsConstant(), sqlite3ExprNNCollSeq(), sqlite3ExprSkipCollateAndLikely(), sqlite3StrICmp(), sqlite3WhereExprUsage(), sqlite3WhereFindTerm(), SQLITE_OrderByIdxJoin, WhereInfo::sWC, testcase, TK_COLUMN, TK_IS, WhereLoop::u, WhereLoop::vtab, WHERE_BIGNULL_SORT, WHERE_DISTINCTBY, WHERE_GROUPBY, WHERE_IPK, WHERE_ONEROW, WHERE_ORDERBY_LIMIT, WHERE_ORDERBY_MAX, WHERE_ORDERBY_MIN, WHERE_SKIPSCAN, WHERE_VIRTUALTABLE, WO_EQ, WO_IN, WO_IS, WO_ISNULL, WhereLoop::wsFlags, XN_ROWID, and CollSeq::zName.

Referenced by wherePathSolver().

◆ wherePathSolver()

static int wherePathSolver ( WhereInfo * pWInfo,
LogEst nRowEst )
static

Definition at line 149688 of file sqlite3.c.

149694 {
149695 int mxChoice; /* Maximum number of simultaneous paths tracked */
149696 int nLoop; /* Number of terms in the join */
149697 Parse *pParse; /* Parsing context */
149698 sqlite3 *db; /* The database connection */
149699 int iLoop; /* Loop counter over the terms of the join */
149700 int ii, jj; /* Loop counters */
149701 int mxI = 0; /* Index of next entry to replace */
149702 int nOrderBy; /* Number of ORDER BY clause terms */
149703 LogEst mxCost = 0; /* Maximum cost of a set of paths */
149704 LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */
149705 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
149706 WherePath *aFrom; /* All nFrom paths at the previous level */
149707 WherePath *aTo; /* The nTo best paths at the current level */
149708 WherePath *pFrom; /* An element of aFrom[] that we are working on */
149709 WherePath *pTo; /* An element of aTo[] that we are working on */
149710 WhereLoop *pWLoop; /* One of the WhereLoop objects */
149711 WhereLoop **pX; /* Used to divy up the pSpace memory */
149712 LogEst *aSortCost = 0; /* Sorting and partial sorting costs */
149713 char *pSpace; /* Temporary memory used by this routine */
149714 int nSpace; /* Bytes of space allocated at pSpace */
149715
149716 pParse = pWInfo->pParse;
149717 db = pParse->db;
149718 nLoop = pWInfo->nLevel;
149719 /* TUNING: For simple queries, only the best path is tracked.
149720 ** For 2-way joins, the 5 best paths are followed.
149721 ** For joins of 3 or more tables, track the 10 best paths */
149722 mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10);
149723 assert( nLoop<=pWInfo->pTabList->nSrc );
149724 WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d)\n", nRowEst));
149725
149726 /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
149727 ** case the purpose of this call is to estimate the number of rows returned
149728 ** by the overall query. Once this estimate has been obtained, the caller
149729 ** will invoke this function a second time, passing the estimate as the
149730 ** nRowEst parameter. */
149731 if( pWInfo->pOrderBy==0 || nRowEst==0 ){
149732 nOrderBy = 0;
149733 }else{
149734 nOrderBy = pWInfo->pOrderBy->nExpr;
149735 }
149736
149737 /* Allocate and initialize space for aTo, aFrom and aSortCost[] */
149738 nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
149739 nSpace += sizeof(LogEst) * nOrderBy;
149740 pSpace = sqlite3DbMallocRawNN(db, nSpace);
149741 if( pSpace==0 ) return SQLITE_NOMEM_BKPT;
149742 aTo = (WherePath*)pSpace;
149743 aFrom = aTo+mxChoice;
149744 memset(aFrom, 0, sizeof(aFrom[0]));
149745 pX = (WhereLoop**)(aFrom+mxChoice);
149746 for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
149747 pFrom->aLoop = pX;
149748 }
149749 if( nOrderBy ){
149750 /* If there is an ORDER BY clause and it is not being ignored, set up
149751 ** space for the aSortCost[] array. Each element of the aSortCost array
149752 ** is either zero - meaning it has not yet been initialized - or the
149753 ** cost of sorting nRowEst rows of data where the first X terms of
149754 ** the ORDER BY clause are already in order, where X is the array
149755 ** index. */
149756 aSortCost = (LogEst*)pX;
149757 memset(aSortCost, 0, sizeof(LogEst) * nOrderBy);
149758 }
149759 assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
149760 assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
149761
149762 /* Seed the search with a single WherePath containing zero WhereLoops.
149763 **
149764 ** TUNING: Do not let the number of iterations go above 28. If the cost
149765 ** of computing an automatic index is not paid back within the first 28
149766 ** rows, then do not use the automatic index. */
149767 aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) );
149768 nFrom = 1;
149769 assert( aFrom[0].isOrdered==0 );
149770 if( nOrderBy ){
149771 /* If nLoop is zero, then there are no FROM terms in the query. Since
149772 ** in this case the query may return a maximum of one row, the results
149773 ** are already in the requested order. Set isOrdered to nOrderBy to
149774 ** indicate this. Or, if nLoop is greater than zero, set isOrdered to
149775 ** -1, indicating that the result set may or may not be ordered,
149776 ** depending on the loops added to the current plan. */
149777 aFrom[0].isOrdered = nLoop>0 ? -1 : nOrderBy;
149778 }
149779
149780 /* Compute successively longer WherePaths using the previous generation
149781 ** of WherePaths as the basis for the next. Keep track of the mxChoice
149782 ** best paths at each generation */
149783 for(iLoop=0; iLoop<nLoop; iLoop++){
149784 nTo = 0;
149785 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
149786 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
149787 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
149788 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
149789 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
149790 i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
149791 Bitmask maskNew; /* Mask of src visited by (..) */
149792 Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
149793
149794 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
149795 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
149796 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
149797 /* Do not use an automatic index if the this loop is expected
149798 ** to run less than 1.25 times. It is tempting to also exclude
149799 ** automatic index usage on an outer loop, but sometimes an automatic
149800 ** index is useful in the outer loop of a correlated subquery. */
149801 assert( 10==sqlite3LogEst(2) );
149802 continue;
149803 }
149804
149805 /* At this point, pWLoop is a candidate to be the next loop.
149806 ** Compute its cost */
149807 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
149808 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
149809 nOut = pFrom->nRow + pWLoop->nOut;
149810 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
149811 if( isOrdered<0 ){
149812 isOrdered = wherePathSatisfiesOrderBy(pWInfo,
149813 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
149814 iLoop, pWLoop, &revMask);
149815 }else{
149816 revMask = pFrom->revLoop;
149817 }
149818 if( isOrdered>=0 && isOrdered<nOrderBy ){
149819 if( aSortCost[isOrdered]==0 ){
149820 aSortCost[isOrdered] = whereSortingCost(
149821 pWInfo, nRowEst, nOrderBy, isOrdered
149822 );
149823 }
149824 /* TUNING: Add a small extra penalty (5) to sorting as an
149825 ** extra encouragment to the query planner to select a plan
149826 ** where the rows emerge in the correct order without any sorting
149827 ** required. */
149828 rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 5;
149829
149830 WHERETRACE(0x002,
149831 ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n",
149832 aSortCost[isOrdered], (nOrderBy-isOrdered), nOrderBy,
149833 rUnsorted, rCost));
149834 }else{
149835 rCost = rUnsorted;
149836 rUnsorted -= 2; /* TUNING: Slight bias in favor of no-sort plans */
149837 }
149838
149839 /* Check to see if pWLoop should be added to the set of
149840 ** mxChoice best-so-far paths.
149841 **
149842 ** First look for an existing path among best-so-far paths
149843 ** that covers the same set of loops and has the same isOrdered
149844 ** setting as the current path candidate.
149845 **
149846 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
149847 ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
149848 ** of legal values for isOrdered, -1..64.
149849 */
149850 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
149851 if( pTo->maskLoop==maskNew
149852 && ((pTo->isOrdered^isOrdered)&0x80)==0
149853 ){
149854 testcase( jj==nTo-1 );
149855 break;
149856 }
149857 }
149858 if( jj>=nTo ){
149859 /* None of the existing best-so-far paths match the candidate. */
149860 if( nTo>=mxChoice
149861 && (rCost>mxCost || (rCost==mxCost && rUnsorted>=mxUnsorted))
149862 ){
149863 /* The current candidate is no better than any of the mxChoice
149864 ** paths currently in the best-so-far buffer. So discard
149865 ** this candidate as not viable. */
149866#ifdef WHERETRACE_ENABLED /* 0x4 */
149867 if( sqlite3WhereTrace&0x4 ){
149868 sqlite3DebugPrintf("Skip %s cost=%-3d,%3d,%3d order=%c\n",
149869 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
149870 isOrdered>=0 ? isOrdered+'0' : '?');
149871 }
149872#endif
149873 continue;
149874 }
149875 /* If we reach this points it means that the new candidate path
149876 ** needs to be added to the set of best-so-far paths. */
149877 if( nTo<mxChoice ){
149878 /* Increase the size of the aTo set by one */
149879 jj = nTo++;
149880 }else{
149881 /* New path replaces the prior worst to keep count below mxChoice */
149882 jj = mxI;
149883 }
149884 pTo = &aTo[jj];
149885#ifdef WHERETRACE_ENABLED /* 0x4 */
149886 if( sqlite3WhereTrace&0x4 ){
149887 sqlite3DebugPrintf("New %s cost=%-3d,%3d,%3d order=%c\n",
149888 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
149889 isOrdered>=0 ? isOrdered+'0' : '?');
149890 }
149891#endif
149892 }else{
149893 /* Control reaches here if best-so-far path pTo=aTo[jj] covers the
149894 ** same set of loops and has the same isOrdered setting as the
149895 ** candidate path. Check to see if the candidate should replace
149896 ** pTo or if the candidate should be skipped.
149897 **
149898 ** The conditional is an expanded vector comparison equivalent to:
149899 ** (pTo->rCost,pTo->nRow,pTo->rUnsorted) <= (rCost,nOut,rUnsorted)
149900 */
149901 if( pTo->rCost<rCost
149902 || (pTo->rCost==rCost
149903 && (pTo->nRow<nOut
149904 || (pTo->nRow==nOut && pTo->rUnsorted<=rUnsorted)
149905 )
149906 )
149907 ){
149908#ifdef WHERETRACE_ENABLED /* 0x4 */
149909 if( sqlite3WhereTrace&0x4 ){
149910 sqlite3DebugPrintf(
149911 "Skip %s cost=%-3d,%3d,%3d order=%c",
149912 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
149913 isOrdered>=0 ? isOrdered+'0' : '?');
149914 sqlite3DebugPrintf(" vs %s cost=%-3d,%3d,%3d order=%c\n",
149915 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
149916 pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
149917 }
149918#endif
149919 /* Discard the candidate path from further consideration */
149920 testcase( pTo->rCost==rCost );
149921 continue;
149922 }
149923 testcase( pTo->rCost==rCost+1 );
149924 /* Control reaches here if the candidate path is better than the
149925 ** pTo path. Replace pTo with the candidate. */
149926#ifdef WHERETRACE_ENABLED /* 0x4 */
149927 if( sqlite3WhereTrace&0x4 ){
149928 sqlite3DebugPrintf(
149929 "Update %s cost=%-3d,%3d,%3d order=%c",
149930 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
149931 isOrdered>=0 ? isOrdered+'0' : '?');
149932 sqlite3DebugPrintf(" was %s cost=%-3d,%3d,%3d order=%c\n",
149933 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
149934 pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
149935 }
149936#endif
149937 }
149938 /* pWLoop is a winner. Add it to the set of best so far */
149939 pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
149940 pTo->revLoop = revMask;
149941 pTo->nRow = nOut;
149942 pTo->rCost = rCost;
149943 pTo->rUnsorted = rUnsorted;
149944 pTo->isOrdered = isOrdered;
149945 memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
149946 pTo->aLoop[iLoop] = pWLoop;
149947 if( nTo>=mxChoice ){
149948 mxI = 0;
149949 mxCost = aTo[0].rCost;
149950 mxUnsorted = aTo[0].nRow;
149951 for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
149952 if( pTo->rCost>mxCost
149953 || (pTo->rCost==mxCost && pTo->rUnsorted>mxUnsorted)
149954 ){
149955 mxCost = pTo->rCost;
149956 mxUnsorted = pTo->rUnsorted;
149957 mxI = jj;
149958 }
149959 }
149960 }
149961 }
149962 }
149963
149964#ifdef WHERETRACE_ENABLED /* >=2 */
149965 if( sqlite3WhereTrace & 0x02 ){
149966 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
149967 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
149968 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
149969 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
149970 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
149971 if( pTo->isOrdered>0 ){
149972 sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
149973 }else{
149974 sqlite3DebugPrintf("\n");
149975 }
149976 }
149977 }
149978#endif
149979
149980 /* Swap the roles of aFrom and aTo for the next generation */
149981 pFrom = aTo;
149982 aTo = aFrom;
149983 aFrom = pFrom;
149984 nFrom = nTo;
149985 }
149986
149987 if( nFrom==0 ){
149988 sqlite3ErrorMsg(pParse, "no query solution");
149989 sqlite3DbFreeNN(db, pSpace);
149990 return SQLITE_ERROR;
149991 }
149992
149993 /* Find the lowest cost path. pFrom will be left pointing to that path */
149994 pFrom = aFrom;
149995 for(ii=1; ii<nFrom; ii++){
149996 if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
149997 }
149998 assert( pWInfo->nLevel==nLoop );
149999 /* Load the lowest cost path into pWInfo */
150000 for(iLoop=0; iLoop<nLoop; iLoop++){
150001 WhereLevel *pLevel = pWInfo->a + iLoop;
150002 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
150003 pLevel->iFrom = pWLoop->iTab;
150004 pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
150005 }
150006 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
150007 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
150008 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
150009 && nRowEst
150010 ){
150011 Bitmask notUsed;
150012 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
150013 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
150014 if( rc==pWInfo->pResultSet->nExpr ){
150016 }
150017 }
150018 pWInfo->bOrderedInnerLoop = 0;
150019 if( pWInfo->pOrderBy ){
150020 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
150021 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
150023 }
150024 }else{
150025 pWInfo->nOBSat = pFrom->isOrdered;
150026 pWInfo->revMask = pFrom->revLoop;
150027 if( pWInfo->nOBSat<=0 ){
150028 pWInfo->nOBSat = 0;
150029 if( nLoop>0 ){
150030 u32 wsFlags = pFrom->aLoop[nLoop-1]->wsFlags;
150031 if( (wsFlags & WHERE_ONEROW)==0
150033 ){
150034 Bitmask m = 0;
150035 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, pFrom,
150036 WHERE_ORDERBY_LIMIT, nLoop-1, pFrom->aLoop[nLoop-1], &m);
150037 testcase( wsFlags & WHERE_IPK );
150038 testcase( wsFlags & WHERE_COLUMN_IN );
150039 if( rc==pWInfo->pOrderBy->nExpr ){
150040 pWInfo->bOrderedInnerLoop = 1;
150041 pWInfo->revMask = m;
150042 }
150043 }
150044 }
150045 }else if( nLoop
150046 && pWInfo->nOBSat==1
150048 ){
150049 pWInfo->bOrderedInnerLoop = 1;
150050 }
150051 }
150052 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
150053 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
150054 ){
150055 Bitmask revMask = 0;
150056 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
150057 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
150058 );
150059 assert( pWInfo->sorted==0 );
150060 if( nOrder==pWInfo->pOrderBy->nExpr ){
150061 pWInfo->sorted = 1;
150062 pWInfo->revMask = revMask;
150063 }
150064 }
150065 }
150066
150067
static i8 wherePathSatisfiesOrderBy(WhereInfo *pWInfo, ExprList *pOrderBy, WherePath *pPath, u16 wctrlFlags, u16 nLoop, WhereLoop *pLast, Bitmask *pRevMask)
Definition sqlite3.c:149285
struct WherePath WherePath
Definition sqlite3.c:140956
static LogEst whereSortingCost(WhereInfo *pWInfo, LogEst nRow, int nOrderBy, int nSorted)
Definition sqlite3.c:149643
unsigned sorted
Definition sqlite3.c:141402
Bitmask maskLoop
Definition sqlite3.c:141108
LogEst rUnsorted
Definition sqlite3.c:141112
Bitmask revLoop
Definition sqlite3.c:141109
LogEst rCost
Definition sqlite3.c:141111
LogEst nRow
Definition sqlite3.c:141110

References SrcList::a, WhereInfo::a, WherePath::aLoop, WhereInfo::bOrderedInnerLoop, Parse::db, WhereInfo::eDistinct, SrcList::SrcList_item::iCursor, WhereLevel::iFrom, WherePath::isOrdered, WhereLoop::iTab, WhereLevel::iTabCur, WherePath::maskLoop, WhereLoop::maskSelf, MIN, ExprList::nExpr, WhereInfo::nLevel, WhereInfo::nOBSat, WhereLoop::nOut, Parse::nQueryLoop, WherePath::nRow, WhereInfo::nRowOut, WhereInfo::pLoops, WhereLoop::pNextLoop, WhereInfo::pOrderBy, WhereInfo::pParse, WhereLoop::prereq, WhereInfo::pResultSet, WhereInfo::pTabList, WhereLevel::pWLoop, WherePath::rCost, WherePath::revLoop, WhereInfo::revMask, WhereLoop::rRun, WhereLoop::rSetup, WherePath::rUnsorted, WhereInfo::sorted, sqlite3DbFreeNN(), sqlite3DbMallocRawNN(), sqlite3ErrorMsg(), sqlite3LogEst(), sqlite3LogEstAdd(), SQLITE_ERROR, SQLITE_NOMEM_BKPT, SQLITE_OK, testcase, WhereInfo::wctrlFlags, WHERE_AUTO_INDEX, WHERE_COLUMN_IN, WHERE_DISTINCT_NOOP, WHERE_DISTINCT_ORDERED, WHERE_DISTINCTBY, WHERE_IPK, WHERE_ONEROW, WHERE_ORDERBY_LIMIT, WHERE_ORDERBY_MAX, WHERE_ORDERBY_MIN, WHERE_SORTBYGROUP, WHERE_WANT_DISTINCT, wherePathSatisfiesOrderBy(), whereSortingCost(), WHERETRACE, and WhereLoop::wsFlags.

Referenced by sqlite3WhereBegin().

◆ whereRangeAdjust()

static LogEst whereRangeAdjust ( WhereTerm * pTerm,
LogEst nNew )
static

Definition at line 146893 of file sqlite3.c.

146899 {
146900 LogEst nRet = nNew;
146901 if( pTerm ){
146902 if( pTerm->truthProb<=0 ){
146903 nRet += pTerm->truthProb;

References sqlite3LogEst(), TERM_VNULL, WhereTerm::truthProb, and WhereTerm::wtFlags.

Referenced by whereRangeScanEst().

◆ whereRangeScanEst()

static int whereRangeScanEst ( Parse * pParse,
WhereLoopBuilder * pBuilder,
WhereTerm * pLower,
WhereTerm * pUpper,
WhereLoop * pLoop )
static

Definition at line 147069 of file sqlite3.c.

147081 {
147082 int rc = SQLITE_OK;
147083 int nOut = pLoop->nOut;
147084 LogEst nNew;
147085
147086#ifdef SQLITE_ENABLE_STAT4
147087 Index *p = pLoop->u.btree.pIndex;
147088 int nEq = pLoop->u.btree.nEq;
147089
147090 if( p->nSample>0 && ALWAYS(nEq<p->nSampleCol)
147091 && OptimizationEnabled(pParse->db, SQLITE_Stat4)
147092 ){
147093 if( nEq==pBuilder->nRecValid ){
147094 UnpackedRecord *pRec = pBuilder->pRec;
147095 tRowcnt a[2];
147096 int nBtm = pLoop->u.btree.nBtm;
147097 int nTop = pLoop->u.btree.nTop;
147098
147099 /* Variable iLower will be set to the estimate of the number of rows in
147100 ** the index that are less than the lower bound of the range query. The
147101 ** lower bound being the concatenation of $P and $L, where $P is the
147102 ** key-prefix formed by the nEq values matched against the nEq left-most
147103 ** columns of the index, and $L is the value in pLower.
147104 **
147105 ** Or, if pLower is NULL or $L cannot be extracted from it (because it
147106 ** is not a simple variable or literal value), the lower bound of the
147107 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
147108 ** if $L is available, whereKeyStats() is called for both ($P) and
147109 ** ($P:$L) and the larger of the two returned values is used.
147110 **
147111 ** Similarly, iUpper is to be set to the estimate of the number of rows
147112 ** less than the upper bound of the range query. Where the upper bound
147113 ** is either ($P) or ($P:$U). Again, even if $U is available, both values
147114 ** of iUpper are requested of whereKeyStats() and the smaller used.
147115 **
147116 ** The number of rows between the two bounds is then just iUpper-iLower.
147117 */
147118 tRowcnt iLower; /* Rows less than the lower bound */
147119 tRowcnt iUpper; /* Rows less than the upper bound */
147120 int iLwrIdx = -2; /* aSample[] for the lower bound */
147121 int iUprIdx = -1; /* aSample[] for the upper bound */
147122
147123 if( pRec ){
147124 testcase( pRec->nField!=pBuilder->nRecValid );
147125 pRec->nField = pBuilder->nRecValid;
147126 }
147127 /* Determine iLower and iUpper using ($P) only. */
147128 if( nEq==0 ){
147129 iLower = 0;
147130 iUpper = p->nRowEst0;
147131 }else{
147132 /* Note: this call could be optimized away - since the same values must
147133 ** have been requested when testing key $P in whereEqualScanEst(). */
147134 whereKeyStats(pParse, p, pRec, 0, a);
147135 iLower = a[0];
147136 iUpper = a[0] + a[1];
147137 }
147138
147139 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
147140 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
147141 assert( p->aSortOrder!=0 );
147142 if( p->aSortOrder[nEq] ){
147143 /* The roles of pLower and pUpper are swapped for a DESC index */
147144 SWAP(WhereTerm*, pLower, pUpper);
147145 SWAP(int, nBtm, nTop);
147146 }
147147
147148 /* If possible, improve on the iLower estimate using ($P:$L). */
147149 if( pLower ){
147150 int n; /* Values extracted from pExpr */
147151 Expr *pExpr = pLower->pExpr->pRight;
147152 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, nBtm, nEq, &n);
147153 if( rc==SQLITE_OK && n ){
147154 tRowcnt iNew;
147155 u16 mask = WO_GT|WO_LE;
147156 if( sqlite3ExprVectorSize(pExpr)>n ) mask = (WO_LE|WO_LT);
147157 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
147158 iNew = a[0] + ((pLower->eOperator & mask) ? a[1] : 0);
147159 if( iNew>iLower ) iLower = iNew;
147160 nOut--;
147161 pLower = 0;
147162 }
147163 }
147164
147165 /* If possible, improve on the iUpper estimate using ($P:$U). */
147166 if( pUpper ){
147167 int n; /* Values extracted from pExpr */
147168 Expr *pExpr = pUpper->pExpr->pRight;
147169 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, nTop, nEq, &n);
147170 if( rc==SQLITE_OK && n ){
147171 tRowcnt iNew;
147172 u16 mask = WO_GT|WO_LE;
147173 if( sqlite3ExprVectorSize(pExpr)>n ) mask = (WO_LE|WO_LT);
147174 iUprIdx = whereKeyStats(pParse, p, pRec, 1, a);
147175 iNew = a[0] + ((pUpper->eOperator & mask) ? a[1] : 0);
147176 if( iNew<iUpper ) iUpper = iNew;
147177 nOut--;
147178 pUpper = 0;
147179 }
147180 }
147181
147182 pBuilder->pRec = pRec;
147183 if( rc==SQLITE_OK ){
147184 if( iUpper>iLower ){
147185 nNew = sqlite3LogEst(iUpper - iLower);
147186 /* TUNING: If both iUpper and iLower are derived from the same
147187 ** sample, then assume they are 4x more selective. This brings
147188 ** the estimated selectivity more in line with what it would be
147189 ** if estimated without the use of STAT4 tables. */
147190 if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) );
147191 }else{
147192 nNew = 10; assert( 10==sqlite3LogEst(2) );
147193 }
147194 if( nNew<nOut ){
147195 nOut = nNew;
147196 }
147197 WHERETRACE(0x10, ("STAT4 range scan: %u..%u est=%d\n",
147198 (u32)iLower, (u32)iUpper, nOut));
147199 }
147200 }else{
147201 int bDone = 0;
147202 rc = whereRangeSkipScanEst(pParse, pLower, pUpper, pLoop, &bDone);
147203 if( bDone ) return rc;
147204 }
147205 }
147206#else
147207 UNUSED_PARAMETER(pParse);
147208 UNUSED_PARAMETER(pBuilder);
147209 assert( pLower || pUpper );
147210#endif
147211 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
147212 nNew = whereRangeAdjust(pLower, nOut);
147213 nNew = whereRangeAdjust(pUpper, nNew);
147214
147215 /* TUNING: If there is both an upper and lower limit and neither limit
147216 ** has an application-defined likelihood(), assume the range is
147217 ** reduced by an additional 75%. This means that, by default, an open-ended
147218 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
147219 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
147220 ** match 1/64 of the index. */
147221 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
147222 nNew -= 20;
147223 }
147224
147225 nOut -= (pLower!=0) + (pUpper!=0);
147226 if( nNew<10 ) nNew = 10;
147227 if( nNew<nOut ) nOut = nNew;
147228#if defined(WHERETRACE_ENABLED)
147229 if( pLoop->nOut>nOut ){
147230 WHERETRACE(0x10,("Range scan lowers nOut from %d to %d\n",
static LogEst whereRangeAdjust(WhereTerm *pTerm, LogEst nNew)
Definition sqlite3.c:146893

References ALWAYS, Index::aSortOrder, WhereLoop::btree, Parse::db, WhereTerm::eOperator, mask, WhereLoop::nBtm, WhereLoop::nEq, UnpackedRecord::nField, WhereLoop::nOut, WhereLoop::nTop, OptimizationEnabled, WhereTerm::pExpr, WhereLoop::pIndex, Expr::pRight, sqlite3ExprVectorSize(), sqlite3LogEst(), SQLITE_OK, SQLITE_Stat4, SWAP, TERM_VNULL, testcase, WhereTerm::truthProb, WhereLoop::u, UNUSED_PARAMETER, whereRangeAdjust(), WHERETRACE, WO_GE, WO_GT, WO_LE, WO_LT, and WhereTerm::wtFlags.

Referenced by whereLoopAddBtreeIndex().

◆ whereRangeVectorLen()

static int whereRangeVectorLen ( Parse * pParse,
int iCur,
Index * pIdx,
int nEq,
WhereTerm * pTerm )
static

Definition at line 147949 of file sqlite3.c.

147961 {
147962 int nCmp = sqlite3ExprVectorSize(pTerm->pExpr->pLeft);
147963 int i;
147964
147965 nCmp = MIN(nCmp, (pIdx->nColumn - nEq));
147966 for(i=1; i<nCmp; i++){
147967 /* Test if comparison i of pTerm is compatible with column (i+nEq)
147968 ** of the index. If not, exit the loop. */
147969 char aff; /* Comparison affinity */
147970 char idxaff = 0; /* Indexed columns affinity */
147971 CollSeq *pColl; /* Comparison collation sequence */
147972 Expr *pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
147973 Expr *pRhs = pTerm->pExpr->pRight;
147974 if( pRhs->flags & EP_xIsSelect ){
147975 pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
147976 }else{
147977 pRhs = pRhs->x.pList->a[i].pExpr;
147978 }
147979
147980 /* Check that the LHS of the comparison is a column reference to
147981 ** the right column of the right source table. And that the sort
147982 ** order of the index column is the same as the sort order of the
147983 ** leftmost index column. */
147984 if( pLhs->op!=TK_COLUMN
147985 || pLhs->iTable!=iCur
147986 || pLhs->iColumn!=pIdx->aiColumn[i+nEq]
147987 || pIdx->aSortOrder[i+nEq]!=pIdx->aSortOrder[nEq]
147988 ){
147989 break;
147990 }
147991
147992 testcase( pLhs->iColumn==XN_ROWID );
147993 aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs));
147994 idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn);
147995 if( aff!=idxaff ) break;
147996

References ExprList::a, Index::aiColumn, Index::aSortOrder, Index::azColl, EP_xIsSelect, Expr::flags, Expr::iColumn, Expr::iTable, MIN, Index::nColumn, Expr::op, Select::pEList, ExprList::ExprList_item::pExpr, WhereTerm::pExpr, Expr::pLeft, Expr::pList, Expr::pRight, Expr::pSelect, Index::pTable, sqlite3BinaryCompareCollSeq(), sqlite3CompareAffinity(), sqlite3ExprAffinity(), sqlite3ExprVectorSize(), sqlite3StrICmp(), sqlite3TableColumnAffinity(), testcase, TK_COLUMN, Expr::x, XN_ROWID, and CollSeq::zName.

Referenced by whereLoopAddBtreeIndex().

◆ whereScanInit()

static WhereTerm * whereScanInit ( WhereScan * pScan,
WhereClause * pWC,
int iCur,
int iColumn,
u32 opMask,
Index * pIdx )
static

Definition at line 145960 of file sqlite3.c.

145973 {
145974 pScan->pOrigWC = pWC;
145975 pScan->pWC = pWC;
145976 pScan->pIdxExpr = 0;
145977 pScan->idxaff = 0;
145978 pScan->zCollName = 0;
145979 pScan->opMask = opMask;
145980 pScan->k = 0;
145981 pScan->aiCur[0] = iCur;
145982 pScan->nEquiv = 1;
145983 pScan->iEquiv = 1;
145984 if( pIdx ){
145985 int j = iColumn;
145986 iColumn = pIdx->aiColumn[j];
145987 if( iColumn==XN_EXPR ){
145988 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
145989 pScan->zCollName = pIdx->azColl[j];
145990 pScan->aiColumn[0] = XN_EXPR;
145991 return whereScanInitIndexExpr(pScan);
145992 }else if( iColumn==pIdx->pTable->iPKey ){
145993 iColumn = XN_ROWID;
145994 }else if( iColumn>=0 ){
145995 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
145996 pScan->zCollName = pIdx->azColl[j];
145997 }
static SQLITE_NOINLINE WhereTerm * whereScanInitIndexExpr(WhereScan *pScan)
Definition sqlite3.c:145936
int aiCur[11]
Definition sqlite3.c:141229
WhereClause * pWC
Definition sqlite3.c:141221
unsigned char iEquiv
Definition sqlite3.c:141226
i16 aiColumn[11]
Definition sqlite3.c:141230
unsigned char nEquiv
Definition sqlite3.c:141225
WhereClause * pOrigWC
Definition sqlite3.c:141220
const char * zCollName
Definition sqlite3.c:141222
char idxaff
Definition sqlite3.c:141224
Expr * pIdxExpr
Definition sqlite3.c:141223

References ExprList::a, Table::aCol, Index::aColExpr, Column::affinity, Index::aiColumn, WhereScan::aiColumn, WhereScan::aiCur, Index::azColl, WhereScan::idxaff, WhereScan::iEquiv, Table::iPKey, WhereScan::k, WhereScan::nEquiv, WhereScan::opMask, ExprList::ExprList_item::pExpr, WhereScan::pIdxExpr, WhereScan::pOrigWC, Index::pTable, WhereScan::pWC, whereScanInitIndexExpr(), whereScanNext(), XN_EXPR, XN_ROWID, and WhereScan::zCollName.

Referenced by sqlite3WhereFindTerm(), and whereLoopAddBtreeIndex().

◆ whereScanInitIndexExpr()

static SQLITE_NOINLINE WhereTerm * whereScanInitIndexExpr ( WhereScan * pScan)
static

Definition at line 145936 of file sqlite3.c.

References WhereScan::idxaff, WhereScan::pIdxExpr, sqlite3ExprAffinity(), and whereScanNext().

Referenced by whereScanInit().

◆ whereScanNext()

static WhereTerm * whereScanNext ( WhereScan * pScan)
static

Definition at line 145848 of file sqlite3.c.

145854 {
145855 int iCur; /* The cursor on the LHS of the term */
145856 i16 iColumn; /* The column on the LHS of the term. -1 for IPK */
145857 Expr *pX; /* An expression being tested */
145858 WhereClause *pWC; /* Shorthand for pScan->pWC */
145859 WhereTerm *pTerm; /* The term being tested */
145860 int k = pScan->k; /* Where to start scanning */
145861
145862 assert( pScan->iEquiv<=pScan->nEquiv );
145863 pWC = pScan->pWC;
145864 while(1){
145865 iColumn = pScan->aiColumn[pScan->iEquiv-1];
145866 iCur = pScan->aiCur[pScan->iEquiv-1];
145867 assert( pWC!=0 );
145868 do{
145869 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
145870 if( pTerm->leftCursor==iCur
145871 && pTerm->u.leftColumn==iColumn
145872 && (iColumn!=XN_EXPR
145874 pScan->pIdxExpr,iCur)==0)
145875 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
145876 ){
145877 if( (pTerm->eOperator & WO_EQUIV)!=0
145878 && pScan->nEquiv<ArraySize(pScan->aiCur)
145879 && (pX = sqlite3ExprSkipCollateAndLikely(pTerm->pExpr->pRight))->op
145880 ==TK_COLUMN
145881 ){
145882 int j;
145883 for(j=0; j<pScan->nEquiv; j++){
145884 if( pScan->aiCur[j]==pX->iTable
145885 && pScan->aiColumn[j]==pX->iColumn ){
145886 break;
145887 }
145888 }
145889 if( j==pScan->nEquiv ){
145890 pScan->aiCur[j] = pX->iTable;
145891 pScan->aiColumn[j] = pX->iColumn;
145892 pScan->nEquiv++;
145893 }
145894 }
145895 if( (pTerm->eOperator & pScan->opMask)!=0 ){
145896 /* Verify the affinity and collating sequence match */
145897 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
145898 CollSeq *pColl;
145899 Parse *pParse = pWC->pWInfo->pParse;
145900 pX = pTerm->pExpr;
145901 if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){
145902 continue;
145903 }
145904 assert(pX->pLeft);
145905 pColl = sqlite3ExprCompareCollSeq(pParse, pX);
145906 if( pColl==0 ) pColl = pParse->db->pDfltColl;
145907 if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){
145908 continue;
145909 }
145910 }
145911 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
145912 && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
145913 && pX->iTable==pScan->aiCur[0]
145914 && pX->iColumn==pScan->aiColumn[0]
145915 ){
145916 testcase( pTerm->eOperator & WO_IS );
145917 continue;
145918 }
145919 pScan->pWC = pWC;
145920 pScan->k = k+1;
145921 return pTerm;
145922 }
145923 }
145924 }
145925 pWC = pWC->pOuter;
145926 k = 0;
145927 }while( pWC!=0 );
145928 if( pScan->iEquiv>=pScan->nEquiv ) break;
SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity)
Definition sqlite3.c:100004

References WhereClause::a, WhereScan::aiColumn, WhereScan::aiCur, ArraySize, Parse::db, WhereTerm::eOperator, EP_FromJoin, ExprHasProperty, Expr::iColumn, WhereScan::idxaff, WhereScan::iEquiv, Expr::iTable, WhereScan::k, WhereTerm::leftColumn, WhereTerm::leftCursor, WhereScan::nEquiv, WhereClause::nTerm, WhereScan::opMask, sqlite3::pDfltColl, WhereTerm::pExpr, WhereScan::pIdxExpr, Expr::pLeft, WhereScan::pOrigWC, WhereClause::pOuter, WhereInfo::pParse, Expr::pRight, WhereScan::pWC, WhereClause::pWInfo, sqlite3ExprCompareCollSeq(), sqlite3ExprCompareSkip(), sqlite3ExprSkipCollateAndLikely(), sqlite3IndexAffinityOk(), sqlite3StrICmp(), testcase, TK_COLUMN, WhereTerm::u, WO_EQ, WO_EQUIV, WO_IS, WO_ISNULL, XN_EXPR, WhereScan::zCollName, and CollSeq::zName.

Referenced by sqlite3WhereFindTerm(), whereLoopAddBtreeIndex(), whereScanInit(), and whereScanInitIndexExpr().

◆ whereShortCut()

static int whereShortCut ( WhereLoopBuilder * pBuilder)
static

Definition at line 150080 of file sqlite3.c.

150086 {
150087 WhereInfo *pWInfo;
150088 struct SrcList_item *pItem;
150089 WhereClause *pWC;
150090 WhereTerm *pTerm;
150091 WhereLoop *pLoop;
150092 int iCur;
150093 int j;
150094 Table *pTab;
150095 Index *pIdx;
150096
150097 pWInfo = pBuilder->pWInfo;
150098 if( pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE ) return 0;
150099 assert( pWInfo->pTabList->nSrc>=1 );
150100 pItem = pWInfo->pTabList->a;
150101 pTab = pItem->pTab;
150102 if( IsVirtual(pTab) ) return 0;
150103 if( pItem->fg.isIndexedBy ) return 0;
150104 iCur = pItem->iCursor;
150105 pWC = &pWInfo->sWC;
150106 pLoop = pBuilder->pNew;
150107 pLoop->wsFlags = 0;
150108 pLoop->nSkip = 0;
150109 pTerm = sqlite3WhereFindTerm(pWC, iCur, -1, 0, WO_EQ|WO_IS, 0);
150110 if( pTerm ){
150111 testcase( pTerm->eOperator & WO_IS );
150113 pLoop->aLTerm[0] = pTerm;
150114 pLoop->nLTerm = 1;
150115 pLoop->u.btree.nEq = 1;
150116 /* TUNING: Cost of a rowid lookup is 10 */
150117 pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
150118 }else{
150119 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
150120 int opMask;
150121 assert( pLoop->aLTermSpace==pLoop->aLTerm );
150122 if( !IsUniqueIndex(pIdx)
150123 || pIdx->pPartIdxWhere!=0
150124 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
150125 ) continue;
150126 opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
150127 for(j=0; j<pIdx->nKeyCol; j++){
150128 pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx);
150129 if( pTerm==0 ) break;
150130 testcase( pTerm->eOperator & WO_IS );
150131 pLoop->aLTerm[j] = pTerm;
150132 }
150133 if( j!=pIdx->nKeyCol ) continue;
150135 if( pIdx->isCovering || (pItem->colUsed & pIdx->colNotIdxed)==0 ){
150136 pLoop->wsFlags |= WHERE_IDX_ONLY;
150137 }
150138 pLoop->nLTerm = j;
150139 pLoop->u.btree.nEq = j;
150140 pLoop->u.btree.pIndex = pIdx;
150141 /* TUNING: Cost of a unique index lookup is 15 */
150142 pLoop->rRun = 39; /* 39==sqlite3LogEst(15) */
150143 break;
150144 }
150145 }
150146 if( pLoop->wsFlags ){
150147 pLoop->nOut = (LogEst)1;
150148 pWInfo->a[0].pWLoop = pLoop;
150149 assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
150150 pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
150151 pWInfo->a[0].iTabCur = iCur;
150152 pWInfo->nRowOut = 1;
150153 if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr;
150154 if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
150156 }
150157#ifdef SQLITE_DEBUG
Bitmask colNotIdxed
Definition sqlite3.c:17811
LogEst nRowOut
Definition sqlite3.c:141403
WhereTerm * aLTermSpace[3]
Definition sqlite3.c:141066
int ix[BMS]
Definition sqlite3.c:141306

References SrcList::a, WhereInfo::a, WhereLoop::aLTerm, WhereLoop::aLTermSpace, ArraySize, WhereLoop::btree, Index::colNotIdxed, WhereInfo::eDistinct, WhereTerm::eOperator, Index::isCovering, IsUniqueIndex, IsVirtual, WhereLevel::iTabCur, WhereMaskSet::ix, WhereLoop::maskSelf, WhereMaskSet::n, WhereLoop::nEq, ExprList::nExpr, Index::nKeyCol, WhereLoop::nLTerm, WhereInfo::nOBSat, WhereLoop::nOut, WhereInfo::nRowOut, WhereLoop::nSkip, SrcList::nSrc, Table::pIndex, WhereLoop::pIndex, WhereLoopBuilder::pNew, Index::pNext, WhereInfo::pOrderBy, Index::pPartIdxWhere, WhereInfo::pTabList, WhereLoopBuilder::pWInfo, WhereLevel::pWLoop, WhereLoop::rRun, WhereInfo::sMaskSet, sqlite3WhereFindTerm(), WhereInfo::sWC, testcase, WhereLoop::u, Index::uniqNotNull, WhereInfo::wctrlFlags, WHERE_COLUMN_EQ, WHERE_DISTINCT_UNIQUE, WHERE_IDX_ONLY, WHERE_INDEXED, WHERE_IPK, WHERE_ONEROW, WHERE_OR_SUBCLAUSE, WHERE_WANT_DISTINCT, WO_EQ, WO_IS, and WhereLoop::wsFlags.

Referenced by sqlite3WhereBegin().

◆ whereSortingCost()

static LogEst whereSortingCost ( WhereInfo * pWInfo,
LogEst nRow,
int nOrderBy,
int nSorted )
static

Definition at line 149643 of file sqlite3.c.

149654 {
149655 /* TUNING: Estimated cost of a full external sort, where N is
149656 ** the number of rows to sort is:
149657 **
149658 ** cost = (3.0 * N * log(N)).
149659 **
149660 ** Or, if the order-by clause has X terms but only the last Y
149661 ** terms are out of order, then block-sorting will reduce the
149662 ** sorting cost to:
149663 **
149664 ** cost = (3.0 * N * log(N)) * (Y/X)
149665 **
149666 ** The (Y/X) term is implemented using stack variable rScale
149667 ** below. */
149668 LogEst rScale, rSortCost;
149669 assert( nOrderBy>0 && 66==sqlite3LogEst(100) );
149670 rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
149671 rSortCost = nRow + rScale + 16;
149672
149673 /* Multiple by log(M) where M is the number of output rows.
149674 ** Use the LIMIT for M if it is smaller */

References estLog(), WhereInfo::iLimit, sqlite3LogEst(), WhereInfo::wctrlFlags, and WHERE_USE_LIMIT.

Referenced by wherePathSolver().

◆ whereUsablePartialIndex()

static int whereUsablePartialIndex ( int iTab,
int isLeft,
WhereClause * pWC,
Expr * pWhere )
static

Definition at line 148438 of file sqlite3.c.

148449 {
148450 int i;
148451 WhereTerm *pTerm;
148452 Parse *pParse = pWC->pWInfo->pParse;
148453 while( pWhere->op==TK_AND ){
148454 if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0;
148455 pWhere = pWhere->pRight;
148456 }
148457 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
148458 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
148459 Expr *pExpr;
148460 pExpr = pTerm->pExpr;
148461 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
148462 && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
148463 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)

Referenced by whereLoopAddBtree().

◆ windowAggFinal()

static void windowAggFinal ( WindowCodeArg * p,
int bFin )
static

Definition at line 152882 of file sqlite3.c.

152888 {
152889 Parse *pParse = p->pParse;
152890 Window *pMWin = p->pMWin;
152891 Vdbe *v = sqlite3GetVdbe(pParse);
152892 Window *pWin;
152893
152894 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
152895 if( pMWin->regStartRowid==0
152896 && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
152897 && (pWin->eStart!=TK_UNBOUNDED)
152898 ){
152899 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
152900 sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
152901 VdbeCoverage(v);
152902 sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
152904 }else if( pWin->regApp ){
152905 assert( pMWin->regStartRowid==0 );
152906 }else{
152907 int nArg = windowArgCount(pWin);
152908 if( bFin ){
152909 sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg);
152911 sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult);
152912 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
152913 }else{
static int windowArgCount(Window *pWin)
Definition sqlite3.c:152642
Parse * pParse
Definition sqlite3.c:152714
Window * pMWin
Definition sqlite3.c:152715

References Window::csrApp, Window::eStart, FuncDef::funcFlags, OP_AggFinal, OP_AggValue, OP_Column, OP_Copy, OP_Last, OP_Null, P4_FUNCDEF, Window::pFunc, WindowCodeArg::pMWin, Window::pNextWin, WindowCodeArg::pParse, Window::regAccum, Window::regApp, Window::regResult, Window::regStartRowid, sqlite3GetVdbe(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAppendP4(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), SQLITE_FUNC_MINMAX, TK_UNBOUNDED, VdbeCoverage, and windowArgCount().

Referenced by sqlite3WindowCodeStep(), windowCodeOp(), and windowFullScan().

◆ windowAggStep()

static void windowAggStep ( WindowCodeArg * p,
Window * pMWin,
int csr,
int bInverse,
int reg )
static

Definition at line 152768 of file sqlite3.c.

152780 {
152781 Parse *pParse = p->pParse;
152782 Vdbe *v = sqlite3GetVdbe(pParse);
152783 Window *pWin;
152784 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
152785 FuncDef *pFunc = pWin->pFunc;
152786 int regArg;
152787 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
152788 int i;
152789
152790 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
152791
152792 /* All OVER clauses in the same window function aggregate step must
152793 ** be the same. */
152794 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );
152795
152796 for(i=0; i<nArg; i++){
152797 if( i!=1 || pFunc->zName!=nth_valueName ){
152798 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
152799 }else{
152800 sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
152801 }
152802 }
152803 regArg = reg;
152804
152805 if( pMWin->regStartRowid==0
152806 && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
152807 && (pWin->eStart!=TK_UNBOUNDED)
152808 ){
152809 int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
152810 VdbeCoverage(v);
152811 if( bInverse==0 ){
152812 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
152813 sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
152814 sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
152815 sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
152816 }else{
152817 sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
152821 }
152822 sqlite3VdbeJumpHere(v, addrIsNull);
152823 }else if( pWin->regApp ){
152824 assert( pFunc->zName==nth_valueName
152825 || pFunc->zName==first_valueName
152826 );
152827 assert( bInverse==0 || bInverse==1 );
152828 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
152829 }else if( pFunc->xSFunc!=noopStepFunc ){
152830 int addrIf = 0;
152831 if( pWin->pFilter ){
152832 int regTmp;
152833 assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
152834 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
152835 regTmp = sqlite3GetTempReg(pParse);
152836 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
152837 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
152838 VdbeCoverage(v);
152839 sqlite3ReleaseTempReg(pParse, regTmp);
152840 }
152841
152842 if( pWin->bExprArgs ){
152843 int iStart = sqlite3VdbeCurrentAddr(v);
152844 VdbeOp *pOp, *pEnd;
152845
152846 nArg = pWin->pOwner->x.pList->nExpr;
152847 regArg = sqlite3GetTempRange(pParse, nArg);
152848 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
152849
152850 pEnd = sqlite3VdbeGetOp(v, -1);
152851 for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
152852 if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
152853 pOp->p1 = csr;
152854 }
152855 }
152856 }
152857 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
152858 CollSeq *pColl;
152859 assert( nArg>0 );
152860 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
152861 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
152862 }
152864 bInverse, regArg, pWin->regAccum);
152865 sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
152866 sqlite3VdbeChangeP5(v, (u8)nArg);
152867 if( pWin->bExprArgs ){

References ExprList::a, Window::bExprArgs, Window::csrApp, Window::eStart, first_valueName, FuncDef::funcFlags, Window::iArgCol, Window::iEphCsr, ExprList::nExpr, noopStepFunc(), nth_valueName, OP_AddImm, OP_AggInverse, OP_AggStep, OP_CollSeq, OP_Column, OP_Delete, OP_IdxInsert, OP_IfNot, OP_IsNull, OP_MakeRecord, OP_SCopy, OP_SeekGE, VdbeOp::opcode, VdbeOp::p1, P4_COLLSEQ, P4_FUNCDEF, ExprList::ExprList_item::pExpr, Window::pFilter, Window::pFunc, Expr::pList, Window::pNextWin, Window::pOwner, WindowCodeArg::pParse, Window::regAccum, Window::regApp, Window::regStartRowid, sqlite3ExprCodeExprList(), sqlite3ExprNNCollSeq(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAddOp4Int(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeGetOp(), sqlite3VdbeJumpHere(), sqlite3WindowCompare(), SQLITE_FUNC_MINMAX, SQLITE_FUNC_NEEDCOLL, TK_UNBOUNDED, VdbeCoverage, VdbeCoverageNeverTaken, windowArgCount(), Expr::x, FuncDef::xSFunc, and FuncDef::zName.

Referenced by windowCodeOp(), and windowFullScan().

◆ windowArgCount()

static int windowArgCount ( Window * pWin)
static

Definition at line 152642 of file sqlite3.c.

Referenced by windowAggFinal(), windowAggStep(), and windowInitAccum().

◆ windowCacheFrame()

static int windowCacheFrame ( Window * pMWin)
static

Definition at line 153135 of file sqlite3.c.

153141 {
153142 Window *pWin;
153143 if( pMWin->regStartRowid ) return 1;
153144 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
153145 FuncDef *pFunc = pWin->pFunc;
153146 if( (pFunc->zName==nth_valueName)
153147 || (pFunc->zName==first_valueName)
153148 || (pFunc->zName==leadName)
153149 || (pFunc->zName==lagName)

Referenced by sqlite3WindowCodeStep().

◆ windowCheckValue()

static void windowCheckValue ( Parse * pParse,
int reg,
int eCond )
static

Definition at line 152596 of file sqlite3.c.

152602 {
152603 static const char *azErr[] = {
152604 "frame starting offset must be a non-negative integer",
152605 "frame ending offset must be a non-negative integer",
152606 "second argument to nth_value must be a positive integer",
152607 "frame starting offset must be a non-negative number",
152608 "frame ending offset must be a non-negative number",
152609 };
152610 static int aOp[] = { OP_Ge, OP_Ge, OP_Gt, OP_Ge, OP_Ge };
152611 Vdbe *v = sqlite3GetVdbe(pParse);
152612 int regZero = sqlite3GetTempReg(pParse);
152613 assert( eCond>=0 && eCond<ArraySize(azErr) );
152614 sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
152615 if( eCond>=WINDOW_STARTING_NUM ){
152616 int regString = sqlite3GetTempReg(pParse);
152617 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
152618 sqlite3VdbeAddOp3(v, OP_Ge, regString, sqlite3VdbeCurrentAddr(v)+2, reg);
152620 VdbeCoverage(v);
152621 assert( eCond==3 || eCond==4 );
152622 VdbeCoverageIf(v, eCond==3);
152623 VdbeCoverageIf(v, eCond==4);
152624 }else{
152626 VdbeCoverage(v);
152627 assert( eCond==0 || eCond==1 || eCond==2 );
152628 VdbeCoverageIf(v, eCond==0);
152629 VdbeCoverageIf(v, eCond==1);
152630 VdbeCoverageIf(v, eCond==2);
152631 }
152632 sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
152633 VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
152634 VdbeCoverageNeverNullIf(v, eCond==1); /* the OP_MustBeInt */
152635 VdbeCoverageNeverNullIf(v, eCond==2);
152636 VdbeCoverageNeverNullIf(v, eCond==3); /* NULL case caught by */
#define WINDOW_STARTING_NUM
Definition sqlite3.c:152586

References ArraySize, OE_Abort, OP_Ge, OP_Gt, OP_Halt, OP_Integer, OP_MustBeInt, OP_String8, P4_STATIC, sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3MayAbort(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeAppendP4(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), SQLITE_AFF_NUMERIC, SQLITE_ERROR, SQLITE_JUMPIFNULL, VdbeCoverage, VdbeCoverageIf, VdbeCoverageNeverNullIf, and WINDOW_STARTING_NUM.

Referenced by sqlite3WindowCodeStep(), and windowReturnOneRow().

◆ windowCodeOp()

static int windowCodeOp ( WindowCodeArg * p,
int op,
int regCountdown,
int jumpOnEof )
static

Definition at line 153332 of file sqlite3.c.

153343 {
153344 int csr, reg;
153345 Parse *pParse = p->pParse;
153346 Window *pMWin = p->pMWin;
153347 int ret = 0;
153348 Vdbe *v = p->pVdbe;
153349 int addrContinue = 0;
153350 int bPeer = (pMWin->eFrmType!=TK_ROWS);
153351
153352 int lblDone = sqlite3VdbeMakeLabel(pParse);
153353 int addrNextRange = 0;
153354
153355 /* Special case - WINDOW_AGGINVERSE is always a no-op if the frame
153356 ** starts with UNBOUNDED PRECEDING. */
153357 if( op==WINDOW_AGGINVERSE && pMWin->eStart==TK_UNBOUNDED ){
153358 assert( regCountdown==0 && jumpOnEof==0 );
153359 return 0;
153360 }
153361
153362 if( regCountdown>0 ){
153363 if( pMWin->eFrmType==TK_RANGE ){
153364 addrNextRange = sqlite3VdbeCurrentAddr(v);
153365 assert( op==WINDOW_AGGINVERSE || op==WINDOW_AGGSTEP );
153366 if( op==WINDOW_AGGINVERSE ){
153367 if( pMWin->eStart==TK_FOLLOWING ){
153369 p, OP_Le, p->current.csr, regCountdown, p->start.csr, lblDone
153370 );
153371 }else{
153373 p, OP_Ge, p->start.csr, regCountdown, p->current.csr, lblDone
153374 );
153375 }
153376 }else{
153378 p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
153379 );
153380 }
153381 }else{
153382 sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, lblDone, 1);
153383 VdbeCoverage(v);
153384 }
153385 }
153386
153387 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
153388 windowAggFinal(p, 0);
153389 }
153390 addrContinue = sqlite3VdbeCurrentAddr(v);
153391
153392 /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
153393 ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
153394 ** start cursor does not advance past the end cursor within the
153395 ** temporary table. It otherwise might, if (a>b). */
153396 if( pMWin->eStart==pMWin->eEnd && regCountdown
153397 && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE
153398 ){
153399 int regRowid1 = sqlite3GetTempReg(pParse);
153400 int regRowid2 = sqlite3GetTempReg(pParse);
153401 sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
153402 sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
153403 sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
153404 VdbeCoverage(v);
153405 sqlite3ReleaseTempReg(pParse, regRowid1);
153406 sqlite3ReleaseTempReg(pParse, regRowid2);
153407 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
153408 }
153409
153410 switch( op ){
153411 case WINDOW_RETURN_ROW:
153412 csr = p->current.csr;
153413 reg = p->current.reg;
153415 break;
153416
153417 case WINDOW_AGGINVERSE:
153418 csr = p->start.csr;
153419 reg = p->start.reg;
153420 if( pMWin->regStartRowid ){
153421 assert( pMWin->regEndRowid );
153423 }else{
153424 windowAggStep(p, pMWin, csr, 1, p->regArg);
153425 }
153426 break;
153427
153428 default:
153429 assert( op==WINDOW_AGGSTEP );
153430 csr = p->end.csr;
153431 reg = p->end.reg;
153432 if( pMWin->regStartRowid ){
153433 assert( pMWin->regEndRowid );
153434 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
153435 }else{
153436 windowAggStep(p, pMWin, csr, 0, p->regArg);
153437 }
153438 break;
153439 }
153440
153441 if( op==p->eDelete ){
153442 sqlite3VdbeAddOp1(v, OP_Delete, csr);
153444 }
153445
153446 if( jumpOnEof ){
153448 VdbeCoverage(v);
153449 ret = sqlite3VdbeAddOp0(v, OP_Goto);
153450 }else{
153451 sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
153452 VdbeCoverage(v);
153453 if( bPeer ){
153454 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
153455 }
153456 }
153457
153458 if( bPeer ){
153459 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
153460 int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
153461 windowReadPeerValues(p, csr, regTmp);
153462 windowIfNewPeer(pParse, pMWin->pOrderBy, regTmp, reg, addrContinue);
153463 sqlite3ReleaseTempRange(pParse, regTmp, nReg);
153464 }
153465
static void windowReadPeerValues(WindowCodeArg *p, int csr, int reg)
Definition sqlite3.c:152731
static void windowAggStep(WindowCodeArg *p, Window *pMWin, int csr, int bInverse, int reg)
Definition sqlite3.c:152768
WindowCsrAndReg current
Definition sqlite3.c:152723
WindowCsrAndReg start
Definition sqlite3.c:152722
WindowCsrAndReg end
Definition sqlite3.c:152724

References WindowCsrAndReg::csr, WindowCodeArg::current, WindowCodeArg::eDelete, Window::eEnd, Window::eFrmType, WindowCodeArg::end, Window::eStart, ExprList::nExpr, OP_AddImm, OP_Delete, OP_Ge, OP_Goto, OP_Gt, OP_IfPos, OP_Le, OP_Next, OP_Rowid, OPFLAG_SAVEPOSITION, WindowCodeArg::pMWin, Window::pOrderBy, WindowCodeArg::pParse, WindowCodeArg::pVdbe, WindowCsrAndReg::reg, WindowCodeArg::regArg, Window::regEndRowid, Window::regStartRowid, sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), WindowCodeArg::start, TK_FOLLOWING, TK_PRECEDING, TK_RANGE, TK_ROWS, TK_UNBOUNDED, VdbeCoverage, WINDOW_AGGINVERSE, WINDOW_AGGSTEP, WINDOW_RETURN_ROW, windowAggFinal(), windowAggStep(), windowCodeRangeTest(), windowIfNewPeer(), windowReadPeerValues(), and windowReturnOneRow().

Referenced by sqlite3WindowCodeStep().

◆ windowCodeRangeTest()

static void windowCodeRangeTest ( WindowCodeArg * p,
int op,
int csr1,
int regVal,
int csr2,
int lbl )
static

Definition at line 153207 of file sqlite3.c.

153220 {
153221 Parse *pParse = p->pParse;
153222 Vdbe *v = sqlite3GetVdbe(pParse);
153223 ExprList *pOrderBy = p->pMWin->pOrderBy; /* ORDER BY clause for window */
153224 int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
153225 int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
153226 int regString = ++pParse->nMem; /* Reg. for constant value '' */
153227 int arith = OP_Add; /* OP_Add or OP_Subtract */
153228 int addrGe; /* Jump destination */
153229
153230 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
153231 assert( pOrderBy && pOrderBy->nExpr==1 );
153232 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
153233 switch( op ){
153234 case OP_Ge: op = OP_Le; break;
153235 case OP_Gt: op = OP_Lt; break;
153236 default: assert( op==OP_Le ); op = OP_Ge; break;
153237 }
153238 arith = OP_Subtract;
153239 }
153240
153241 /* Read the peer-value from each cursor into a register */
153242 windowReadPeerValues(p, csr1, reg1);
153243 windowReadPeerValues(p, csr2, reg2);
153244
153245 VdbeModuleComment((v, "CodeRangeTest: if( R%d %s R%d %s R%d ) goto lbl",
153246 reg1, (arith==OP_Add ? "+" : "-"), regVal,
153247 ((op==OP_Ge) ? ">=" : (op==OP_Le) ? "<=" : (op==OP_Gt) ? ">" : "<"), reg2
153248 ));
153249
153250 /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
153251 ** This block adds (or subtracts for DESC) the numeric value in regVal
153252 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
153253 ** then leave reg1 as it is. In pseudo-code, this is implemented as:
153254 **
153255 ** if( reg1>='' ) goto addrGe;
153256 ** reg1 = reg1 +/- regVal
153257 ** addrGe:
153258 **
153259 ** Since all strings and blobs are greater-than-or-equal-to an empty string,
153260 ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
153261 ** then the arithmetic is performed, but since adding or subtracting from
153262 ** NULL is always NULL anyway, this case is handled as required too. */
153263 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
153264 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
153265 VdbeCoverage(v);
153266 sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
153267 sqlite3VdbeJumpHere(v, addrGe);
153268
153269 /* If the BIGNULL flag is set for the ORDER BY, then it is required to
153270 ** consider NULL values to be larger than all other values, instead of
153271 ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
153272 ** (and adding that capability causes a performance regression), so
153273 ** instead if the BIGNULL flag is set then cases where either reg1 or
153274 ** reg2 are NULL are handled separately in the following block. The code
153275 ** generated is equivalent to:
153276 **
153277 ** if( reg1 IS NULL ){
153278 ** if( op==OP_Ge ) goto lbl;
153279 ** if( op==OP_Gt && reg2 IS NOT NULL ) goto lbl;
153280 ** if( op==OP_Le && reg2 IS NULL ) goto lbl;
153281 ** }else if( reg2 IS NULL ){
153282 ** if( op==OP_Le ) goto lbl;
153283 ** }
153284 **
153285 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
153286 ** not taken, control jumps over the comparison operator coded below this
153287 ** block. */
153288 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
153289 /* This block runs if reg1 contains a NULL. */
153290 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
153291 switch( op ){
153292 case OP_Ge:
153293 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
153294 break;
153295 case OP_Gt:
153296 sqlite3VdbeAddOp2(v, OP_NotNull, reg2, lbl);
153297 VdbeCoverage(v);
153298 break;
153299 case OP_Le:
153300 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl);
153301 VdbeCoverage(v);
153302 break;
153303 default: assert( op==OP_Lt ); /* no-op */ break;
153304 }
153306
153307 /* This block runs if reg1 is not NULL, but reg2 is. */
153308 sqlite3VdbeJumpHere(v, addr);
153309 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
153310 if( op==OP_Gt || op==OP_Ge ){
153312 }
153313 }
153314
153315 /* Compare registers reg2 and reg1, taking the jump if required. Note that
153316 ** control skips over this test if the BIGNULL flag is set and either
153317 ** reg1 or reg2 contain a NULL value. */
153318 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
153320
153321 assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
153322 testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
153323 testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
153324 testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
static int arith(lua_State *L, int op, const char *mtname)

References ExprList::a, arith(), KEYINFO_ORDER_BIGNULL, KEYINFO_ORDER_DESC, ExprList::nExpr, Parse::nMem, OP_Add, OP_Ge, OP_Goto, OP_Gt, OP_IsNull, OP_Le, OP_Lt, OP_NotNull, OP_String8, OP_Subtract, P4_STATIC, WindowCodeArg::pMWin, Window::pOrderBy, WindowCodeArg::pParse, ExprList::ExprList_item::sortFlags, sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP2(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), SQLITE_NULLEQ, testcase, VdbeCoverage, VdbeCoverageIf, VdbeModuleComment, and windowReadPeerValues().

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ windowExprGtZero()

static int windowExprGtZero ( Parse * pParse,
Expr * pExpr )
static

Definition at line 153528 of file sqlite3.c.

153534 {
153535 int ret = 0;
153536 sqlite3 *db = pParse->db;
153537 sqlite3_value *pVal = 0;
153538 sqlite3ValueFromExpr(db, pExpr, db->enc, SQLITE_AFF_NUMERIC, &pVal);

References Parse::db, sqlite3::enc, sqlite3_value_int(), sqlite3ValueFree(), sqlite3ValueFromExpr(), and SQLITE_AFF_NUMERIC.

Referenced by sqlite3WindowCodeStep().

◆ windowFind()

static Window * windowFind ( Parse * pParse,
Window * pList,
const char * zName )
static

Definition at line 151790 of file sqlite3.c.

151796 {
151797 Window *p;
151798 for(p=pList; p; p=p->pNextWin){
151799 if( sqlite3StrICmp(p->zName, zName)==0 ) break;

Referenced by sqlite3WindowChain(), and sqlite3WindowUpdate().

◆ windowFullScan()

static void windowFullScan ( WindowCodeArg * p)
static

Definition at line 152921 of file sqlite3.c.

152927 {
152928 Window *pWin;
152929 Parse *pParse = p->pParse;
152930 Window *pMWin = p->pMWin;
152931 Vdbe *v = p->pVdbe;
152932
152933 int regCRowid = 0; /* Current rowid value */
152934 int regCPeer = 0; /* Current peer values */
152935 int regRowid = 0; /* AggStep rowid value */
152936 int regPeer = 0; /* AggStep peer values */
152937
152938 int nPeer;
152939 int lblNext;
152940 int lblBrk;
152941 int addrNext;
152942 int csr;
152943
152944 VdbeModuleComment((v, "windowFullScan begin"));
152945
152946 assert( pMWin!=0 );
152947 csr = pMWin->csrApp;
152948 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
152949
152950 lblNext = sqlite3VdbeMakeLabel(pParse);
152951 lblBrk = sqlite3VdbeMakeLabel(pParse);
152952
152953 regCRowid = sqlite3GetTempReg(pParse);
152954 regRowid = sqlite3GetTempReg(pParse);
152955 if( nPeer ){
152956 regCPeer = sqlite3GetTempRange(pParse, nPeer);
152957 regPeer = sqlite3GetTempRange(pParse, nPeer);
152958 }
152959
152960 sqlite3VdbeAddOp2(v, OP_Rowid, pMWin->iEphCsr, regCRowid);
152961 windowReadPeerValues(p, pMWin->iEphCsr, regCPeer);
152962
152963 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
152964 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
152965 }
152966
152967 sqlite3VdbeAddOp3(v, OP_SeekGE, csr, lblBrk, pMWin->regStartRowid);
152968 VdbeCoverage(v);
152969 addrNext = sqlite3VdbeCurrentAddr(v);
152970 sqlite3VdbeAddOp2(v, OP_Rowid, csr, regRowid);
152971 sqlite3VdbeAddOp3(v, OP_Gt, pMWin->regEndRowid, lblBrk, regRowid);
152973
152974 if( pMWin->eExclude==TK_CURRENT ){
152975 sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, lblNext, regRowid);
152977 }else if( pMWin->eExclude!=TK_NO ){
152978 int addr;
152979 int addrEq = 0;
152980 KeyInfo *pKeyInfo = 0;
152981
152982 if( pMWin->pOrderBy ){
152983 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
152984 }
152985 if( pMWin->eExclude==TK_TIES ){
152986 addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
152988 }
152989 if( pKeyInfo ){
152990 windowReadPeerValues(p, csr, regPeer);
152991 sqlite3VdbeAddOp3(v, OP_Compare, regPeer, regCPeer, nPeer);
152992 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
152993 addr = sqlite3VdbeCurrentAddr(v)+1;
152994 sqlite3VdbeAddOp3(v, OP_Jump, addr, lblNext, addr);
152995 VdbeCoverageEqNe(v);
152996 }else{
152997 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
152998 }
152999 if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
153000 }
153001
153002 windowAggStep(p, pMWin, csr, 0, p->regArg);
153003
153004 sqlite3VdbeResolveLabel(v, lblNext);
153005 sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
153006 VdbeCoverage(v);
153007 sqlite3VdbeJumpHere(v, addrNext-1);
153008 sqlite3VdbeJumpHere(v, addrNext+1);
153009 sqlite3ReleaseTempReg(pParse, regRowid);
153010 sqlite3ReleaseTempReg(pParse, regCRowid);
153011 if( nPeer ){
153012 sqlite3ReleaseTempRange(pParse, regPeer, nPeer);

References Window::csrApp, Window::eExclude, Window::iEphCsr, ExprList::nExpr, OP_Compare, OP_Eq, OP_Goto, OP_Gt, OP_Jump, OP_Next, OP_Null, OP_Rowid, OP_SeekGE, P4_KEYINFO, WindowCodeArg::pMWin, Window::pNextWin, Window::pOrderBy, WindowCodeArg::pParse, WindowCodeArg::pVdbe, Window::regAccum, WindowCodeArg::regArg, Window::regEndRowid, Window::regStartRowid, sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3KeyInfoFromExprList(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAppendP4(), sqlite3VdbeCurrentAddr(), sqlite3VdbeJumpHere(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), TK_CURRENT, TK_NO, TK_TIES, VdbeCoverage, VdbeCoverageEqNe, VdbeCoverageNeverNull, VdbeModuleComment, windowAggFinal(), windowAggStep(), and windowReadPeerValues().

Referenced by windowReturnOneRow().

◆ windowIfNewPeer()

static void windowIfNewPeer ( Parse * pParse,
ExprList * pOrderBy,
int regNew,
int regOld,
int addr )
static

Definition at line 153161 of file sqlite3.c.

153173 {
153174 Vdbe *v = sqlite3GetVdbe(pParse);
153175 if( pOrderBy ){
153176 int nVal = pOrderBy->nExpr;
153177 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
153178 sqlite3VdbeAddOp3(v, OP_Compare, regOld, regNew, nVal);
153179 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
153182 );

References ExprList::nExpr, OP_Compare, OP_Copy, OP_Goto, OP_Jump, P4_KEYINFO, sqlite3GetVdbe(), sqlite3KeyInfoFromExprList(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAppendP4(), sqlite3VdbeCurrentAddr(), and VdbeCoverageEqNe.

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ windowInitAccum()

static int windowInitAccum ( Parse * pParse,
Window * pMWin )
static

Definition at line 153103 of file sqlite3.c.

153109 {
153110 Vdbe *v = sqlite3GetVdbe(pParse);
153111 int regArg;
153112 int nArg = 0;
153113 Window *pWin;
153114 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
153115 FuncDef *pFunc = pWin->pFunc;
153116 assert( pWin->regAccum );
153117 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
153118 nArg = MAX(nArg, windowArgCount(pWin));
153119 if( pMWin->regStartRowid==0 ){
153120 if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){
153121 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
153122 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
153123 }
153124
153125 if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
153126 assert( pWin->eStart!=TK_UNBOUNDED );
153128 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
153129 }

References Window::csrApp, Window::eStart, first_valueName, FuncDef::funcFlags, MAX, Parse::nMem, nth_valueName, OP_Integer, OP_Null, OP_ResetSorter, Window::pFunc, Window::pNextWin, Window::regAccum, Window::regApp, Window::regStartRowid, sqlite3GetVdbe(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), SQLITE_FUNC_MINMAX, TK_UNBOUNDED, windowArgCount(), and FuncDef::zName.

Referenced by sqlite3WindowCodeStep().

◆ windowReadPeerValues()

static void windowReadPeerValues ( WindowCodeArg * p,
int csr,
int reg )
static

Definition at line 152731 of file sqlite3.c.

152741 {
152742 Window *pMWin = p->pMWin;
152743 ExprList *pOrderBy = pMWin->pOrderBy;
152744 if( pOrderBy ){
152745 Vdbe *v = sqlite3GetVdbe(p->pParse);
152746 ExprList *pPart = pMWin->pPartition;
152747 int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);

Referenced by windowCodeOp(), windowCodeRangeTest(), and windowFullScan().

◆ windowRemoveExprFromSelect()

static void windowRemoveExprFromSelect ( Select * pSelect,
Expr * pExpr )
static

Definition at line 99166 of file sqlite3.c.

99172 {
99173 if( pSelect->pWin ){
99174 Walker sWalker;

Referenced by resolveOrderGroupBy().

◆ windowReturnOneRow()

static void windowReturnOneRow ( WindowCodeArg * p)
static

Definition at line 153027 of file sqlite3.c.

153033 {
153034 Window *pMWin = p->pMWin;
153035 Vdbe *v = p->pVdbe;
153036
153037 if( pMWin->regStartRowid ){
153038 windowFullScan(p);
153039 }else{
153040 Parse *pParse = p->pParse;
153041 Window *pWin;
153042
153043 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
153044 FuncDef *pFunc = pWin->pFunc;
153045 if( pFunc->zName==nth_valueName
153046 || pFunc->zName==first_valueName
153047 ){
153048 int csr = pWin->csrApp;
153049 int lbl = sqlite3VdbeMakeLabel(pParse);
153050 int tmpReg = sqlite3GetTempReg(pParse);
153051 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
153052
153053 if( pFunc->zName==nth_valueName ){
153054 sqlite3VdbeAddOp3(v, OP_Column,pMWin->iEphCsr,pWin->iArgCol+1,tmpReg);
153055 windowCheckValue(pParse, tmpReg, 2);
153056 }else{
153057 sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
153058 }
153059 sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
153060 sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
153062 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
153064 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
153065 sqlite3VdbeResolveLabel(v, lbl);
153066 sqlite3ReleaseTempReg(pParse, tmpReg);
153067 }
153068 else if( pFunc->zName==leadName || pFunc->zName==lagName ){
153069 int nArg = pWin->pOwner->x.pList->nExpr;
153070 int csr = pWin->csrApp;
153071 int lbl = sqlite3VdbeMakeLabel(pParse);
153072 int tmpReg = sqlite3GetTempReg(pParse);
153073 int iEph = pMWin->iEphCsr;
153074
153075 if( nArg<3 ){
153076 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
153077 }else{
153078 sqlite3VdbeAddOp3(v, OP_Column, iEph,pWin->iArgCol+2,pWin->regResult);
153079 }
153080 sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
153081 if( nArg<2 ){
153082 int val = (pFunc->zName==leadName ? 1 : -1);
153083 sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
153084 }else{
153085 int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
153086 int tmpReg2 = sqlite3GetTempReg(pParse);
153087 sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
153088 sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
153089 sqlite3ReleaseTempReg(pParse, tmpReg2);
153090 }
153091
153092 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
153093 VdbeCoverage(v);
153094 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
153095 sqlite3VdbeResolveLabel(v, lbl);
static void windowFullScan(WindowCodeArg *p)
Definition sqlite3.c:152921

References WindowCodeArg::addrGosub, Window::csrApp, first_valueName, Window::iArgCol, Window::iEphCsr, lagName, leadName, ExprList::nExpr, nth_valueName, OP_Add, OP_AddImm, OP_Column, OP_Gosub, OP_Gt, OP_Integer, OP_Null, OP_Rowid, OP_SeekRowid, OP_Subtract, Window::pFunc, Expr::pList, WindowCodeArg::pMWin, Window::pNextWin, Window::pOwner, WindowCodeArg::pParse, WindowCodeArg::pVdbe, Window::regApp, WindowCodeArg::regGosub, Window::regResult, Window::regStartRowid, sqlite3GetTempReg(), sqlite3ReleaseTempReg(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeMakeLabel(), sqlite3VdbeResolveLabel(), VdbeCoverage, VdbeCoverageNeverNull, VdbeCoverageNeverTaken, windowCheckValue(), windowFullScan(), Expr::x, and FuncDef::zName.

Referenced by sqlite3WindowCodeStep(), and windowCodeOp().

◆ withDup()

static With * withDup ( sqlite3 * db,
With * p )
static

Definition at line 101090 of file sqlite3.c.

101096 {
101097 With *pRet = 0;
101098 if( p ){
101099 sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
101100 pRet = sqlite3DbMallocZero(db, nByte);
101101 if( pRet ){
101102 int i;
101103 pRet->nCte = p->nCte;
101104 for(i=0; i<p->nCte; i++){
101105 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
101106 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);

References With::a, With::nCte, With::Cte::pCols, With::Cte::pSelect, sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ExprListDup(), sqlite3SelectDup(), and With::Cte::zName.

◆ withExpand()

static int withExpand ( Walker * pWalker,
struct SrcList_item * pFrom )
static

Definition at line 134071 of file sqlite3.c.

134080 {
134081 Parse *pParse = pWalker->pParse;
134082 sqlite3 *db = pParse->db;
134083 struct Cte *pCte; /* Matched CTE (or NULL if no match) */
134084 With *pWith; /* WITH clause that pCte belongs to */
134085
134086 assert( pFrom->pTab==0 );
134087 if( pParse->nErr ){
134088 return SQLITE_ERROR;
134089 }
134090
134091 pCte = searchWith(pParse->pWith, pFrom, &pWith);
134092 if( pCte ){
134093 Table *pTab;
134094 ExprList *pEList;
134095 Select *pSel;
134096 Select *pLeft; /* Left-most SELECT statement */
134097 int bMayRecursive; /* True if compound joined by UNION [ALL] */
134098 With *pSavedWith; /* Initial value of pParse->pWith */
134099
134100 /* If pCte->zCteErr is non-NULL at this point, then this is an illegal
134101 ** recursive reference to CTE pCte. Leave an error in pParse and return
134102 ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
134103 ** In this case, proceed. */
134104 if( pCte->zCteErr ){
134105 sqlite3ErrorMsg(pParse, pCte->zCteErr, pCte->zName);
134106 return SQLITE_ERROR;
134107 }
134108 if( cannotBeFunction(pParse, pFrom) ) return SQLITE_ERROR;
134109
134110 assert( pFrom->pTab==0 );
134111 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
134112 if( pTab==0 ) return WRC_Abort;
134113 pTab->nTabRef = 1;
134114 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
134115 pTab->iPKey = -1;
134116 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
134118 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
134119 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
134120 assert( pFrom->pSelect );
134121
134122 /* Check if this is a recursive CTE. */
134123 pSel = pFrom->pSelect;
134124 bMayRecursive = ( pSel->op==TK_ALL || pSel->op==TK_UNION );
134125 if( bMayRecursive ){
134126 int i;
134127 SrcList *pSrc = pFrom->pSelect->pSrc;
134128 for(i=0; i<pSrc->nSrc; i++){
134129 struct SrcList_item *pItem = &pSrc->a[i];
134130 if( pItem->zDatabase==0
134131 && pItem->zName!=0
134132 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
134133 ){
134134 pItem->pTab = pTab;
134135 pItem->fg.isRecursive = 1;
134136 pTab->nTabRef++;
134137 pSel->selFlags |= SF_Recursive;
134138 }
134139 }
134140 }
134141
134142 /* Only one recursive reference is permitted. */
134143 if( pTab->nTabRef>2 ){
134145 pParse, "multiple references to recursive table: %s", pCte->zName
134146 );
134147 return SQLITE_ERROR;
134148 }
134149 assert( pTab->nTabRef==1 ||
134150 ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 ));
134151
134152 pCte->zCteErr = "circular reference: %s";
134153 pSavedWith = pParse->pWith;
134154 pParse->pWith = pWith;
134155 if( bMayRecursive ){
134156 Select *pPrior = pSel->pPrior;
134157 assert( pPrior->pWith==0 );
134158 pPrior->pWith = pSel->pWith;
134159 sqlite3WalkSelect(pWalker, pPrior);
134160 pPrior->pWith = 0;
134161 }else{
134162 sqlite3WalkSelect(pWalker, pSel);
134163 }
134164 pParse->pWith = pWith;
134165
134166 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
134167 pEList = pLeft->pEList;
134168 if( pCte->pCols ){
134169 if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
134170 sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
134171 pCte->zName, pEList->nExpr, pCte->pCols->nExpr
134172 );
134173 pParse->pWith = pSavedWith;
134174 return SQLITE_ERROR;
134175 }
134176 pEList = pCte->pCols;
134177 }
134178
134179 sqlite3ColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
134180 if( bMayRecursive ){
134181 if( pSel->selFlags & SF_Recursive ){
134182 pCte->zCteErr = "multiple recursive references: %s";
134183 }else{
134184 pCte->zCteErr = "recursive reference in a subquery: %s";
134185 }
134186 sqlite3WalkSelect(pWalker, pSel);
134187 }
static struct Cte * searchWith(With *pWith, struct SrcList_item *pItem, With **ppContext)
Definition sqlite3.c:134015

References SrcList::a, Table::aCol, cannotBeFunction(), Parse::db, Table::iPKey, sqlite3::mallocFailed, Table::nCol, Parse::nErr, ExprList::nExpr, Table::nRowLogEst, SrcList::nSrc, Table::nTabRef, Select::op, Select::pEList, Walker::pParse, Select::pPrior, Select::pWith, Parse::pWith, searchWith(), Select::selFlags, SF_Recursive, sqlite3ColumnsFromExprList(), sqlite3DbMallocZero(), sqlite3DbStrDup(), sqlite3ErrorMsg(), sqlite3LogEst(), sqlite3SelectDup(), sqlite3StrICmp(), sqlite3WalkSelect(), SQLITE_ERROR, SQLITE_NOMEM_BKPT, SQLITE_OK, Table::tabFlags, TF_Ephemeral, TF_NoVisibleRowid, TK_ALL, TK_UNION, WRC_Abort, and Table::zName.

Referenced by selectExpander().

◆ write32bits()

static int write32bits ( sqlite3_file * fd,
i64 offset,
u32 val )
static

Definition at line 52816 of file sqlite3.c.

References put32bits, and sqlite3OsWrite().

Referenced by subjournalPage(), and writeSuperJournal().

◆ writeJournalHdr()

static int writeJournalHdr ( Pager * pPager)
static

Definition at line 53136 of file sqlite3.c.

53136 : Initial database page count.
53137** - 4 bytes: Sector size used by the process that wrote this journal.
53138** - 4 bytes: Database page size.
53139**
53140** Followed by (JOURNAL_HDR_SZ - 28) bytes of unused space.
53141*/
53142static int writeJournalHdr(Pager *pPager){
53143 int rc = SQLITE_OK; /* Return code */
53144 char *zHeader = pPager->pTmpSpace; /* Temporary space used to build header */
53145 u32 nHeader = (u32)pPager->pageSize;/* Size of buffer pointed to by zHeader */
53146 u32 nWrite; /* Bytes of header sector written */
53147 int ii; /* Loop counter */
53148
53149 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
53150
53151 if( nHeader>JOURNAL_HDR_SZ(pPager) ){
53152 nHeader = JOURNAL_HDR_SZ(pPager);
53153 }
53154
53155 /* If there are active savepoints and any of them were created
53156 ** since the most recent journal header was written, update the
53157 ** PagerSavepoint.iHdrOffset fields now.
53158 */
53159 for(ii=0; ii<pPager->nSavepoint; ii++){
53160 if( pPager->aSavepoint[ii].iHdrOffset==0 ){
53161 pPager->aSavepoint[ii].iHdrOffset = pPager->journalOff;
53162 }
53163 }
53164
53165 pPager->journalHdr = pPager->journalOff = journalHdrOffset(pPager);
53166
53167 /*
53168 ** Write the nRec Field - the number of page records that follow this
53169 ** journal header. Normally, zero is written to this value at this time.
53170 ** After the records are added to the journal (and the journal synced,
53171 ** if in full-sync mode), the zero is overwritten with the true number
53172 ** of records (see syncJournal()).
53173 **
53174 ** A faster alternative is to write 0xFFFFFFFF to the nRec field. When
53175 ** reading the journal this value tells SQLite to assume that the
53176 ** rest of the journal file contains valid page records. This assumption
53177 ** is dangerous, as if a failure occurred whilst writing to the journal
53178 ** file it may contain some garbage data. There are two scenarios
53179 ** where this risk can be ignored:
53180 **
53181 ** * When the pager is in no-sync mode. Corruption can follow a
53182 ** power failure in this case anyway.
53183 **
53184 ** * When the SQLITE_IOCAP_SAFE_APPEND flag is set. This guarantees
53185 ** that garbage data is never appended to the journal file.
53186 */
53187 assert( isOpen(pPager->fd) || pPager->noSync );
53188 if( pPager->noSync || (pPager->journalMode==PAGER_JOURNALMODE_MEMORY)
53190 ){
53191 memcpy(zHeader, aJournalMagic, sizeof(aJournalMagic));
53192 put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
53193 }else{
53194 memset(zHeader, 0, sizeof(aJournalMagic)+4);
53195 }
53196
53197 /* The random check-hash initializer */
53198 sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
53199 put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
53200 /* The initial database size */
53201 put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
53202 /* The assumed sector size for this process */
53203 put32bits(&zHeader[sizeof(aJournalMagic)+12], pPager->sectorSize);
53204
53205 /* The page size */
53206 put32bits(&zHeader[sizeof(aJournalMagic)+16], pPager->pageSize);
53207
53208 /* Initializing the tail of the buffer is not necessary. Everything
53209 ** works find if the following memset() is omitted. But initializing
53210 ** the memory prevents valgrind from complaining, so we are willing to
53211 ** take the performance hit.
53212 */
53213 memset(&zHeader[sizeof(aJournalMagic)+20], 0,
53214 nHeader-(sizeof(aJournalMagic)+20));
53215
53216 /* In theory, it is only necessary to write the 28 bytes that the
53217 ** journal header consumes to the journal file here. Then increment the
53218 ** Pager.journalOff variable by JOURNAL_HDR_SZ so that the next
53219 ** record is written to the following sector (leaving a gap in the file
53220 ** that will be implicitly filled in by the OS).
53221 **
53222 ** However it has been discovered that on some systems this pattern can
53223 ** be significantly slower than contiguously writing data to the file,
53224 ** even if that means explicitly writing data to the block of
53225 ** (JOURNAL_HDR_SZ - 28) bytes that will not be used. So that is what
53226 ** is done.
53227 **
53228 ** The loop is required here in case the sector-size is larger than the
53229 ** database page size. Since the zHeader buffer is only Pager.pageSize
53230 ** bytes in size, more than one call to sqlite3OsWrite() may be required
53231 ** to populate the entire journal header sector.
53232 */
53233 for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
53234 IOTRACE(("JHDR %p %lld %d\n", pPager, pPager->journalHdr, nHeader))
53235 rc = sqlite3OsWrite(pPager->jfd, zHeader, nHeader, pPager->journalOff);

References aJournalMagic, Pager::aSavepoint, Pager::cksumInit, Pager::dbOrigSize, Pager::fd, PagerSavepoint::iHdrOffset, IOTRACE, isOpen, Pager::jfd, JOURNAL_HDR_SZ, Pager::journalHdr, journalHdrOffset(), Pager::journalMode, Pager::journalOff, Pager::noSync, Pager::nSavepoint, PAGER_JOURNALMODE_MEMORY, Pager::pageSize, Pager::pTmpSpace, put32bits, Pager::sectorSize, sqlite3_randomness(), sqlite3OsDeviceCharacteristics(), sqlite3OsWrite(), SQLITE_IOCAP_SAFE_APPEND, and SQLITE_OK.

Referenced by pager_open_journal(), and syncJournal().

◆ writeSuperJournal()

static int writeSuperJournal ( Pager * pPager,
const char * zSuper )
static

Definition at line 53379 of file sqlite3.c.

53385 {
53386 int rc; /* Return code */
53387 int nSuper; /* Length of string zSuper */
53388 i64 iHdrOff; /* Offset of header in journal file */
53389 i64 jrnlSize; /* Size of journal file on disk */
53390 u32 cksum = 0; /* Checksum of string zSuper */
53391
53392 assert( pPager->setSuper==0 );
53393 assert( !pagerUseWal(pPager) );
53394
53395 if( !zSuper
53397 || !isOpen(pPager->jfd)
53398 ){
53399 return SQLITE_OK;
53400 }
53401 pPager->setSuper = 1;
53402 assert( pPager->journalHdr <= pPager->journalOff );
53403
53404 /* Calculate the length in bytes and the checksum of zSuper */
53405 for(nSuper=0; zSuper[nSuper]; nSuper++){
53406 cksum += zSuper[nSuper];
53407 }
53408
53409 /* If in full-sync mode, advance to the next disk sector before writing
53410 ** the super-journal name. This is in case the previous page written to
53411 ** the journal has already been synced.
53412 */
53413 if( pPager->fullSync ){
53414 pPager->journalOff = journalHdrOffset(pPager);
53415 }
53416 iHdrOff = pPager->journalOff;
53417
53418 /* Write the super-journal data to the end of the journal file. If
53419 ** an error occurs, return the error code to the caller.
53420 */
53421 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
53422 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
53423 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
53424 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
53425 || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
53426 iHdrOff+4+nSuper+8)))
53427 ){
53428 return rc;
53429 }
53430 pPager->journalOff += (nSuper+20);
53431
53432 /* If the pager is in peristent-journal mode, then the physical
53433 ** journal-file may extend past the end of the super-journal name
53434 ** and 8 bytes of magic data just written to the file. This is
53435 ** dangerous because the code to rollback a hot-journal file
53436 ** will not be able to find the super-journal name to determine
53437 ** whether or not the journal is hot.
53438 **
53439 ** Easiest thing to do in this scenario is to truncate the journal
53440 ** file to the required size.
53441 */
53442 if( SQLITE_OK==(rc = sqlite3OsFileSize(pPager->jfd, &jrnlSize))

References aJournalMagic, Pager::fullSync, isOpen, Pager::jfd, Pager::journalHdr, journalHdrOffset(), Pager::journalMode, Pager::journalOff, PAGER_JOURNALMODE_MEMORY, PAGER_MJ_PGNO, pagerUseWal, Pager::setSuper, sqlite3OsFileSize(), sqlite3OsTruncate(), sqlite3OsWrite(), SQLITE_OK, and write32bits().

Referenced by sqlite3PagerCommitPhaseOne().

◆ xferCompatibleIndex()

static int xferCompatibleIndex ( Index * pDest,
Index * pSrc )
static

Definition at line 123008 of file sqlite3.c.

123014 {
123015 int i;
123016 assert( pDest && pSrc );
123017 assert( pDest->pTable!=pSrc->pTable );
123018 if( pDest->nKeyCol!=pSrc->nKeyCol || pDest->nColumn!=pSrc->nColumn ){
123019 return 0; /* Different number of columns */
123020 }
123021 if( pDest->onError!=pSrc->onError ){
123022 return 0; /* Different conflict resolution strategies */
123023 }
123024 for(i=0; i<pSrc->nKeyCol; i++){
123025 if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
123026 return 0; /* Different columns indexed */
123027 }
123028 if( pSrc->aiColumn[i]==XN_EXPR ){
123029 assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
123030 if( sqlite3ExprCompare(0, pSrc->aColExpr->a[i].pExpr,
123031 pDest->aColExpr->a[i].pExpr, -1)!=0 ){
123032 return 0; /* Different expressions in the index */
123033 }
123034 }
123035 if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
123036 return 0; /* Different sort orders */
123037 }
123038 if( sqlite3_stricmp(pSrc->azColl[i],pDest->azColl[i])!=0 ){
123039 return 0; /* Different collating sequences */
123040 }
123041 }
123042 if( sqlite3ExprCompare(0, pSrc->pPartIdxWhere, pDest->pPartIdxWhere, -1) ){

References ExprList::a, Index::aColExpr, Index::aiColumn, Index::aSortOrder, Index::azColl, Index::nColumn, Index::nKeyCol, Index::onError, ExprList::ExprList_item::pExpr, Index::pPartIdxWhere, Index::pTable, sqlite3_stricmp(), sqlite3ExprCompare(), and XN_EXPR.

Referenced by xferOptimization().

◆ xferOptimization()

static int xferOptimization ( Parse * pParse,
Table * pDest,
Select * pSelect,
int onError,
int iDbDest )
static

Definition at line 123069 of file sqlite3.c.

123081 {
123082 sqlite3 *db = pParse->db;
123083 ExprList *pEList; /* The result set of the SELECT */
123084 Table *pSrc; /* The table in the FROM clause of SELECT */
123085 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
123086 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
123087 int i; /* Loop counter */
123088 int iDbSrc; /* The database of pSrc */
123089 int iSrc, iDest; /* Cursors from source and destination */
123090 int addr1, addr2; /* Loop addresses */
123091 int emptyDestTest = 0; /* Address of test for empty pDest */
123092 int emptySrcTest = 0; /* Address of test for empty pSrc */
123093 Vdbe *v; /* The VDBE we are building */
123094 int regAutoinc; /* Memory register used by AUTOINC */
123095 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
123096 int regData, regRowid; /* Registers holding data and rowid */
123097
123098 if( pSelect==0 ){
123099 return 0; /* Must be of the form INSERT INTO ... SELECT ... */
123100 }
123101 if( pParse->pWith || pSelect->pWith ){
123102 /* Do not attempt to process this query if there are an WITH clauses
123103 ** attached to it. Proceeding may generate a false "no such table: xxx"
123104 ** error if pSelect reads from a CTE named "xxx". */
123105 return 0;
123106 }
123107 if( sqlite3TriggerList(pParse, pDest) ){
123108 return 0; /* tab1 must not have triggers */
123109 }
123110#ifndef SQLITE_OMIT_VIRTUALTABLE
123111 if( IsVirtual(pDest) ){
123112 return 0; /* tab1 must not be a virtual table */
123113 }
123114#endif
123115 if( onError==OE_Default ){
123116 if( pDest->iPKey>=0 ) onError = pDest->keyConf;
123117 if( onError==OE_Default ) onError = OE_Abort;
123118 }
123119 assert(pSelect->pSrc); /* allocated even if there is no FROM clause */
123120 if( pSelect->pSrc->nSrc!=1 ){
123121 return 0; /* FROM clause must have exactly one term */
123122 }
123123 if( pSelect->pSrc->a[0].pSelect ){
123124 return 0; /* FROM clause cannot contain a subquery */
123125 }
123126 if( pSelect->pWhere ){
123127 return 0; /* SELECT may not have a WHERE clause */
123128 }
123129 if( pSelect->pOrderBy ){
123130 return 0; /* SELECT may not have an ORDER BY clause */
123131 }
123132 /* Do not need to test for a HAVING clause. If HAVING is present but
123133 ** there is no ORDER BY, we will get an error. */
123134 if( pSelect->pGroupBy ){
123135 return 0; /* SELECT may not have a GROUP BY clause */
123136 }
123137 if( pSelect->pLimit ){
123138 return 0; /* SELECT may not have a LIMIT clause */
123139 }
123140 if( pSelect->pPrior ){
123141 return 0; /* SELECT may not be a compound query */
123142 }
123143 if( pSelect->selFlags & SF_Distinct ){
123144 return 0; /* SELECT may not be DISTINCT */
123145 }
123146 pEList = pSelect->pEList;
123147 assert( pEList!=0 );
123148 if( pEList->nExpr!=1 ){
123149 return 0; /* The result set must have exactly one column */
123150 }
123151 assert( pEList->a[0].pExpr );
123152 if( pEList->a[0].pExpr->op!=TK_ASTERISK ){
123153 return 0; /* The result set must be the special operator "*" */
123154 }
123155
123156 /* At this point we have established that the statement is of the
123157 ** correct syntactic form to participate in this optimization. Now
123158 ** we have to check the semantics.
123159 */
123160 pItem = pSelect->pSrc->a;
123161 pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
123162 if( pSrc==0 ){
123163 return 0; /* FROM clause does not contain a real table */
123164 }
123165 if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){
123166 testcase( pSrc!=pDest ); /* Possible due to bad sqlite_schema.rootpage */
123167 return 0; /* tab1 and tab2 may not be the same table */
123168 }
123169 if( HasRowid(pDest)!=HasRowid(pSrc) ){
123170 return 0; /* source and destination must both be WITHOUT ROWID or not */
123171 }
123172#ifndef SQLITE_OMIT_VIRTUALTABLE
123173 if( IsVirtual(pSrc) ){
123174 return 0; /* tab2 must not be a virtual table */
123175 }
123176#endif
123177 if( pSrc->pSelect ){
123178 return 0; /* tab2 may not be a view */
123179 }
123180 if( pDest->nCol!=pSrc->nCol ){
123181 return 0; /* Number of columns must be the same in tab1 and tab2 */
123182 }
123183 if( pDest->iPKey!=pSrc->iPKey ){
123184 return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
123185 }
123186 for(i=0; i<pDest->nCol; i++){
123187 Column *pDestCol = &pDest->aCol[i];
123188 Column *pSrcCol = &pSrc->aCol[i];
123189#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
123190 if( (db->mDbFlags & DBFLAG_Vacuum)==0
123191 && (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN
123192 ){
123193 return 0; /* Neither table may have __hidden__ columns */
123194 }
123195#endif
123196#ifndef SQLITE_OMIT_GENERATED_COLUMNS
123197 /* Even if tables t1 and t2 have identical schemas, if they contain
123198 ** generated columns, then this statement is semantically incorrect:
123199 **
123200 ** INSERT INTO t2 SELECT * FROM t1;
123201 **
123202 ** The reason is that generated column values are returned by the
123203 ** the SELECT statement on the right but the INSERT statement on the
123204 ** left wants them to be omitted.
123205 **
123206 ** Nevertheless, this is a useful notational shorthand to tell SQLite
123207 ** to do a bulk transfer all of the content from t1 over to t2.
123208 **
123209 ** We could, in theory, disable this (except for internal use by the
123210 ** VACUUM command where it is actually needed). But why do that? It
123211 ** seems harmless enough, and provides a useful service.
123212 */
123213 if( (pDestCol->colFlags & COLFLAG_GENERATED) !=
123214 (pSrcCol->colFlags & COLFLAG_GENERATED) ){
123215 return 0; /* Both columns have the same generated-column type */
123216 }
123217 /* But the transfer is only allowed if both the source and destination
123218 ** tables have the exact same expressions for generated columns.
123219 ** This requirement could be relaxed for VIRTUAL columns, I suppose.
123220 */
123221 if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
123222 if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){
123223 testcase( pDestCol->colFlags & COLFLAG_VIRTUAL );
123224 testcase( pDestCol->colFlags & COLFLAG_STORED );
123225 return 0; /* Different generator expressions */
123226 }
123227 }
123228#endif
123229 if( pDestCol->affinity!=pSrcCol->affinity ){
123230 return 0; /* Affinity must be the same on all columns */
123231 }
123232 if( sqlite3_stricmp(pDestCol->zColl, pSrcCol->zColl)!=0 ){
123233 return 0; /* Collating sequence must be the same on all columns */
123234 }
123235 if( pDestCol->notNull && !pSrcCol->notNull ){
123236 return 0; /* tab2 must be NOT NULL if tab1 is */
123237 }
123238 /* Default values for second and subsequent columns need to match. */
123239 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
123240 assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN );
123241 assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN );
123242 if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0)
123243 || (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken,
123244 pSrcCol->pDflt->u.zToken)!=0)
123245 ){
123246 return 0; /* Default values must be the same for all columns */
123247 }
123248 }
123249 }
123250 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
123251 if( IsUniqueIndex(pDestIdx) ){
123252 destHasUniqueIdx = 1;
123253 }
123254 for(pSrcIdx=pSrc->pIndex; pSrcIdx; pSrcIdx=pSrcIdx->pNext){
123255 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
123256 }
123257 if( pSrcIdx==0 ){
123258 return 0; /* pDestIdx has no corresponding index in pSrc */
123259 }
123260 if( pSrcIdx->tnum==pDestIdx->tnum && pSrc->pSchema==pDest->pSchema
123261 && sqlite3FaultSim(411)==SQLITE_OK ){
123262 /* The sqlite3FaultSim() call allows this corruption test to be
123263 ** bypassed during testing, in order to exercise other corruption tests
123264 ** further downstream. */
123265 return 0; /* Corrupt schema - two indexes on the same btree */
123266 }
123267 }
123268#ifndef SQLITE_OMIT_CHECK
123269 if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
123270 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
123271 }
123272#endif
123273#ifndef SQLITE_OMIT_FOREIGN_KEY
123274 /* Disallow the transfer optimization if the destination table constains
123275 ** any foreign key constraints. This is more restrictive than necessary.
123276 ** But the main beneficiary of the transfer optimization is the VACUUM
123277 ** command, and the VACUUM command disables foreign key constraints. So
123278 ** the extra complication to make this rule less restrictive is probably
123279 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
123280 */
123281 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
123282 return 0;
123283 }
123284#endif
123285 if( (db->flags & SQLITE_CountRows)!=0 ){
123286 return 0; /* xfer opt does not play well with PRAGMA count_changes */
123287 }
123288
123289 /* If we get this far, it means that the xfer optimization is at
123290 ** least a possibility, though it might only work if the destination
123291 ** table (tab1) is initially empty.
123292 */
123293#ifdef SQLITE_TEST
123294 sqlite3_xferopt_count++;
123295#endif
123296 iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
123297 v = sqlite3GetVdbe(pParse);
123298 sqlite3CodeVerifySchema(pParse, iDbSrc);
123299 iSrc = pParse->nTab++;
123300 iDest = pParse->nTab++;
123301 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
123302 regData = sqlite3GetTempReg(pParse);
123303 regRowid = sqlite3GetTempReg(pParse);
123304 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
123305 assert( HasRowid(pDest) || destHasUniqueIdx );
123306 if( (db->mDbFlags & DBFLAG_Vacuum)==0 && (
123307 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
123308 || destHasUniqueIdx /* (2) */
123309 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
123310 )){
123311 /* In some circumstances, we are able to run the xfer optimization
123312 ** only if the destination table is initially empty. Unless the
123313 ** DBFLAG_Vacuum flag is set, this block generates code to make
123314 ** that determination. If DBFLAG_Vacuum is set, then the destination
123315 ** table is always empty.
123316 **
123317 ** Conditions under which the destination must be empty:
123318 **
123319 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
123320 ** (If the destination is not initially empty, the rowid fields
123321 ** of index entries might need to change.)
123322 **
123323 ** (2) The destination has a unique index. (The xfer optimization
123324 ** is unable to test uniqueness.)
123325 **
123326 ** (3) onError is something other than OE_Abort and OE_Rollback.
123327 */
123328 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
123329 emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
123330 sqlite3VdbeJumpHere(v, addr1);
123331 }
123332 if( HasRowid(pSrc) ){
123333 u8 insFlags;
123334 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
123335 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
123336 if( pDest->iPKey>=0 ){
123337 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
123338 sqlite3VdbeVerifyAbortable(v, onError);
123339 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
123340 VdbeCoverage(v);
123341 sqlite3RowidConstraint(pParse, onError, pDest);
123342 sqlite3VdbeJumpHere(v, addr2);
123343 autoIncStep(pParse, regAutoinc, regRowid);
123344 }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
123345 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
123346 }else{
123347 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
123348 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
123349 }
123350 if( db->mDbFlags & DBFLAG_Vacuum ){
123351 sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
123353 }else{
123355 }
123356 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
123357 sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid,
123358 (char*)pDest, P4_TABLE);
123359 sqlite3VdbeChangeP5(v, insFlags);
123360 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
123361 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
123362 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
123363 }else{
123364 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
123365 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
123366 }
123367 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
123368 u8 idxInsFlags = 0;
123369 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
123370 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
123371 }
123372 assert( pSrcIdx );
123373 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
123374 sqlite3VdbeSetP4KeyInfo(pParse, pSrcIdx);
123375 VdbeComment((v, "%s", pSrcIdx->zName));
123376 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
123377 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
123379 VdbeComment((v, "%s", pDestIdx->zName));
123380 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
123381 if( db->mDbFlags & DBFLAG_Vacuum ){
123382 /* This INSERT command is part of a VACUUM operation, which guarantees
123383 ** that the destination table is empty. If all indexed columns use
123384 ** collation sequence BINARY, then it can also be assumed that the
123385 ** index will be populated by inserting keys in strictly sorted
123386 ** order. In this case, instead of seeking within the b-tree as part
123387 ** of every OP_IdxInsert opcode, an OP_SeekEnd is added before the
123388 ** OP_IdxInsert to seek to the point within the b-tree where each key
123389 ** should be inserted. This is faster.
123390 **
123391 ** If any of the indexed columns use a collation sequence other than
123392 ** BINARY, this optimization is disabled. This is because the user
123393 ** might change the definition of a collation sequence and then run
123394 ** a VACUUM command. In that case keys may not be written in strictly
123395 ** sorted order. */
123396 for(i=0; i<pSrcIdx->nColumn; i++){
123397 const char *zColl = pSrcIdx->azColl[i];
123398 if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
123399 }
123400 if( i==pSrcIdx->nColumn ){
123401 idxInsFlags = OPFLAG_USESEEKRESULT;
123402 sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
123403 }
123404 }else if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
123405 idxInsFlags |= OPFLAG_NCHANGE;
123406 }
123407 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
123408 sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
123409 sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
123410 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
123411 sqlite3VdbeJumpHere(v, addr1);
123412 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
123413 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
123414 }
123415 if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
123416 sqlite3ReleaseTempReg(pParse, regRowid);
123417 sqlite3ReleaseTempReg(pParse, regData);
123418 if( emptyDestTest ){
123419 sqlite3AutoincrementEnd(pParse);
123421 sqlite3VdbeJumpHere(v, emptyDestTest);
static int xferCompatibleIndex(Index *pDest, Index *pSrc)
Definition sqlite3.c:123008

References ExprList::a, SrcList::a, Table::aCol, Column::affinity, ALWAYS, autoIncBegin(), autoIncStep(), Index::azColl, COLFLAG_GENERATED, COLFLAG_HIDDEN, COLFLAG_STORED, COLFLAG_VIRTUAL, Column::colFlags, Parse::db, DBFLAG_Vacuum, DBFLAG_VacuumInto, sqlite3::flags, HasRowid, Index::idxType, Table::iPKey, IsUniqueIndex, IsVirtual, Table::keyConf, sqlite3::mDbFlags, Table::nCol, Index::nColumn, ExprList::nExpr, Column::notNull, SrcList::nSrc, Parse::nTab, OE_Abort, OE_Default, OE_Rollback, Expr::op, OP_Close, OP_Goto, OP_Halt, OP_IdxInsert, OP_Insert, OP_NewRowid, OP_Next, OP_NotExists, OP_OpenRead, OP_OpenWrite, OP_Rewind, OP_RowData, OP_Rowid, OP_SeekEnd, OPFLAG_APPEND, OPFLAG_BULKCSR, OPFLAG_LASTROWID, OPFLAG_NCHANGE, OPFLAG_USESEEKRESULT, P4_TABLE, Table::pCheck, Column::pDflt, Select::pEList, ExprList::ExprList_item::pExpr, Table::pFKey, Select::pGroupBy, Table::pIndex, Select::pLimit, Index::pNext, Select::pOrderBy, Select::pPrior, Table::pSchema, Table::pSelect, SrcList::SrcList_item::pSelect, Select::pSrc, Select::pWhere, Select::pWith, Parse::pWith, Select::selFlags, SF_Distinct, sqlite3_stricmp(), sqlite3AutoincrementEnd(), sqlite3CodeVerifySchema(), sqlite3ExprCompare(), sqlite3ExprListCompare(), sqlite3FaultSim(), sqlite3GetTempReg(), sqlite3GetVdbe(), sqlite3LocateTableItem(), sqlite3OpenTable(), sqlite3ReleaseTempReg(), sqlite3RowidConstraint(), sqlite3SchemaToIndex(), sqlite3StrBINARY, sqlite3TableLock(), sqlite3TriggerList(), sqlite3VdbeAddOp0(), sqlite3VdbeAddOp1(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP5(), sqlite3VdbeJumpHere(), sqlite3VdbeSetP4KeyInfo(), sqlite3VdbeVerifyAbortable, SQLITE_CountRows, SQLITE_ForeignKeys, SQLITE_IDXTYPE_PRIMARYKEY, SQLITE_OK, Table::tabFlags, testcase, TF_Autoincrement, TK_ASTERISK, TK_SPAN, Table::tnum, Index::tnum, Expr::u, VdbeComment, VdbeCoverage, xferCompatibleIndex(), Column::zColl, Table::zName, Index::zName, and Expr::zToken.

Referenced by sqlite3Insert().

◆ yy_accept()

static void yy_accept ( yyParser * yypParser)
static

Definition at line 159030 of file sqlite3.c.

159038 {
159041#ifndef NDEBUG
159042 if( yyTraceFILE ){
159043 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
159044 }
159045#endif
159046#ifndef YYNOERRORRECOVERY
159047 yypParser->yyerrcnt = -1;
159048#endif
159049 assert( yypParser->yytos==yypParser->yystack );
159050 /* Here code is inserted which will be executed whenever the
#define sqlite3ParserARG_FETCH
Definition sqlite3.c:154506

Referenced by sqlite3Parser().

◆ yy_destructor()

static void yy_destructor ( yyParser * yypParser,
YYCODETYPE yymajor,
YYMINORTYPE * yypminor )
static

Definition at line 156267 of file sqlite3.c.

156277 {
156280 switch( yymajor ){
156281 /* Here is inserted the actions which take place when a
156282 ** terminal or non-terminal is destroyed. This can happen
156283 ** when the symbol is popped from the stack during a
156284 ** reduce or during error processing or when a parser is
156285 ** being destroyed before it is finished parsing.
156286 **
156287 ** Note: during a reduce, the only symbols destroyed are those
156288 ** which appear on the RHS of the rule, but which are *not* used
156289 ** inside the C code.
156290 */
156291/********* Begin destructor definitions ***************************************/
156292 case 200: /* select */
156293 case 234: /* selectnowith */
156294 case 235: /* oneselect */
156295 case 247: /* values */
156296{
156297sqlite3SelectDelete(pParse->db, (yypminor->yy539));
156298}
156299 break;
156300 case 211: /* term */
156301 case 212: /* expr */
156302 case 241: /* where_opt */
156303 case 243: /* having_opt */
156304 case 255: /* on_opt */
156305 case 271: /* case_operand */
156306 case 273: /* case_else */
156307 case 276: /* vinto */
156308 case 283: /* when_clause */
156309 case 288: /* key_opt */
156310 case 302: /* filter_clause */
156311{
156312sqlite3ExprDelete(pParse->db, (yypminor->yy202));
156313}
156314 break;
156315 case 216: /* eidlist_opt */
156316 case 226: /* sortlist */
156317 case 227: /* eidlist */
156318 case 239: /* selcollist */
156319 case 242: /* groupby_opt */
156320 case 244: /* orderby_opt */
156321 case 248: /* nexprlist */
156322 case 249: /* sclp */
156323 case 257: /* exprlist */
156324 case 262: /* setlist */
156325 case 270: /* paren_exprlist */
156326 case 272: /* case_exprlist */
156327 case 301: /* part_opt */
156328{
156329sqlite3ExprListDelete(pParse->db, (yypminor->yy242));
156330}
156331 break;
156332 case 233: /* fullname */
156333 case 240: /* from */
156334 case 251: /* seltablist */
156335 case 252: /* stl_prefix */
156336 case 258: /* xfullname */
156337{
156338sqlite3SrcListDelete(pParse->db, (yypminor->yy47));
156339}
156340 break;
156341 case 236: /* wqlist */
156342{
156343sqlite3WithDelete(pParse->db, (yypminor->yy131));
156344}
156345 break;
156346 case 246: /* window_clause */
156347 case 297: /* windowdefn_list */
156348{
156349sqlite3WindowListDelete(pParse->db, (yypminor->yy303));
156350}
156351 break;
156352 case 256: /* using_opt */
156353 case 259: /* idlist */
156354 case 264: /* idlist_opt */
156355{
156356sqlite3IdListDelete(pParse->db, (yypminor->yy600));
156357}
156358 break;
156359 case 266: /* filter_over */
156360 case 298: /* windowdefn */
156361 case 299: /* window */
156362 case 300: /* frame_opt */
156363 case 303: /* over_clause */
156364{
156365sqlite3WindowDelete(pParse->db, (yypminor->yy303));
156366}
156367 break;
156368 case 279: /* trigger_cmd_list */
156369 case 284: /* trigger_cmd */
156370{
156371sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy447));
156372}
156373 break;
156374 case 281: /* trigger_event */
156375{
156376sqlite3IdListDelete(pParse->db, (yypminor->yy230).b);
156377}
156378 break;
156379 case 305: /* frame_bound */
156380 case 306: /* frame_bound_s */
156381 case 307: /* frame_bound_e */
156382{
156383sqlite3ExprDelete(pParse->db, (yypminor->yy77).pExpr);
SrcList * yy47
Definition sqlite3.c:154484
struct TrigEvent yy230
Definition sqlite3.c:154491
struct FrameBound yy77
Definition sqlite3.c:154486
Window * yy303
Definition sqlite3.c:154493
Expr * yy202
Definition sqlite3.c:154489
Select * yy539
Definition sqlite3.c:154497
ExprList * yy242
Definition sqlite3.c:154492
TriggerStep * yy447
Definition sqlite3.c:154496
IdList * yy600
Definition sqlite3.c:154498
With * yy131
Definition sqlite3.c:154487

References Parse::db, sqlite3DeleteTriggerStep(), sqlite3ExprDelete(), sqlite3ExprListDelete(), sqlite3IdListDelete(), sqlite3ParserARG_FETCH, sqlite3ParserCTX_FETCH, sqlite3SelectDelete(), sqlite3SrcListDelete(), sqlite3WindowDelete(), sqlite3WindowListDelete(), sqlite3WithDelete(), YYMINORTYPE::yy131, YYMINORTYPE::yy202, YYMINORTYPE::yy230, YYMINORTYPE::yy242, YYMINORTYPE::yy303, YYMINORTYPE::yy447, YYMINORTYPE::yy47, YYMINORTYPE::yy539, YYMINORTYPE::yy600, and YYMINORTYPE::yy77.

Referenced by sqlite3Parser().

◆ yy_find_reduce_action()

static YYACTIONTYPE yy_find_reduce_action ( YYACTIONTYPE stateno,
YYCODETYPE iLookAhead )
static

Definition at line 156554 of file sqlite3.c.

156563 {
156564 int i;
156565#ifdef YYERRORSYMBOL
156566 if( stateno>YY_REDUCE_COUNT ){
156567 return yy_default[stateno];
156568 }
156569#else
156570 assert( stateno<=YY_REDUCE_COUNT );
156571#endif
156572 i = yy_reduce_ofst[stateno];
156573 assert( iLookAhead!=YYNOCODE );
156574 i += iLookAhead;
156575#ifdef YYERRORSYMBOL
156576 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
156577 return yy_default[stateno];
156578 }
static const YYCODETYPE yy_lookahead[]
Definition sqlite3.c:154792
static const YYACTIONTYPE yy_default[]
Definition sqlite3.c:155115
#define YY_ACTTAB_COUNT
Definition sqlite3.c:154592
static const short yy_reduce_ofst[]
Definition sqlite3.c:155073
#define YY_REDUCE_COUNT
Definition sqlite3.c:155070

Referenced by sqlite3Parser(), and yy_reduce().

◆ yy_find_shift_action()

static YYACTIONTYPE yy_find_shift_action ( YYCODETYPE iLookAhead,
YYACTIONTYPE stateno )
static

Definition at line 156489 of file sqlite3.c.

156498 {
156499 int i;
156500
156501 if( stateno>YY_MAX_SHIFT ) return stateno;
156502 assert( stateno <= YY_SHIFT_COUNT );
156503#if defined(YYCOVERAGE)
156504 yycoverage[stateno][iLookAhead] = 1;
156505#endif
156506 do{
156507 i = yy_shift_ofst[stateno];
156508 assert( i>=0 );
156509 assert( i<=YY_ACTTAB_COUNT );
156510 assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );
156511 assert( iLookAhead!=YYNOCODE );
156512 assert( iLookAhead < YYNTOKEN );
156513 i += iLookAhead;
156514 assert( i<(int)YY_NLOOKAHEAD );
156515 if( yy_lookahead[i]!=iLookAhead ){
156516#ifdef YYFALLBACK
156517 YYCODETYPE iFallback; /* Fallback token */
156518 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
156519 iFallback = yyFallback[iLookAhead];
156520 if( iFallback!=0 ){
156521#ifndef NDEBUG
156522 if( yyTraceFILE ){
156523 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
156524 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
156525 }
156526#endif
156527 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
156528 iLookAhead = iFallback;
156529 continue;
156530 }
156531#endif
156532#ifdef YYWILDCARD
156533 {
156534 int j = i - iLookAhead + YYWILDCARD;
156535 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
156536 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
156537#ifndef NDEBUG
156538 if( yyTraceFILE ){
156539 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
156540 yyTracePrompt, yyTokenName[iLookAhead],
156541 yyTokenName[YYWILDCARD]);
156542 }
156543#endif /* NDEBUG */
156544 return yy_action[j];
156545 }
156546 }
156547#endif /* YYWILDCARD */
156548 return yy_default[stateno];
static const YYACTIONTYPE yy_action[]
Definition sqlite3.c:154593
#define YY_NLOOKAHEAD
Definition sqlite3.c:154527
static const unsigned short int yy_shift_ofst[]
Definition sqlite3.c:155012
#define YY_MAX_SHIFT
Definition sqlite3.c:154518
#define YYWILDCARD
Definition sqlite3.c:154479
#define YY_SHIFT_COUNT
Definition sqlite3.c:155009
#define YYNTOKEN
Definition sqlite3.c:154517

References yy_action, YY_ACTTAB_COUNT, yy_default, yy_lookahead, YY_MAX_SHIFT, YY_NLOOKAHEAD, YY_SHIFT_COUNT, yy_shift_ofst, YYCODETYPE, yyFallback, YYNOCODE, YYNTOKEN, and YYWILDCARD.

Referenced by sqlite3Parser().

◆ yy_pop_parser_stack()

static void yy_pop_parser_stack ( yyParser * pParser)
static

Definition at line 156391 of file sqlite3.c.

156397 {
156398 yyStackEntry *yytos;
156399 assert( pParser->yytos!=0 );
156400 assert( pParser->yytos > pParser->yystack );
156401 yytos = pParser->yytos--;
156402#ifndef NDEBUG
156403 if( yyTraceFILE ){
156404 fprintf(yyTraceFILE,"%sPopping %s\n",

References yyStackEntry::major, yyParser::yystack, and yyParser::yytos.

Referenced by sqlite3Parser().

◆ yy_reduce()

static YYACTIONTYPE yy_reduce ( yyParser * yypParser,
unsigned int yyruleno,
int yyLookahead,
sqlite3ParserTOKENTYPE yyLookaheadToken sqlite3ParserCTX_PDECL )
static

Definition at line 157457 of file sqlite3.c.

157469 {
157470 int yygoto; /* The next state */
157471 YYACTIONTYPE yyact; /* The next action */
157472 yyStackEntry *yymsp; /* The top of the parser's stack */
157473 int yysize; /* Amount to pop the stack */
157475 (void)yyLookahead;
157476 (void)yyLookaheadToken;
157477 yymsp = yypParser->yytos;
157478#ifndef NDEBUG
157479 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
157480 yysize = yyRuleInfoNRhs[yyruleno];
157481 if( yysize ){
157482 fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
157483 yyTracePrompt,
157484 yyruleno, yyRuleName[yyruleno],
157485 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
157486 yymsp[yysize].stateno);
157487 }else{
157488 fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
157489 yyTracePrompt, yyruleno, yyRuleName[yyruleno],
157490 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
157491 }
157492 }
157493#endif /* NDEBUG */
157494
157495 /* Check that the stack is large enough to grow by a single entry
157496 ** if the RHS of the rule is empty. This ensures that there is room
157497 ** enough on the stack to push the LHS value */
157498 if( yyRuleInfoNRhs[yyruleno]==0 ){
157499#ifdef YYTRACKMAXSTACKDEPTH
157500 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
157501 yypParser->yyhwm++;
157502 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
157503 }
157504#endif
157505#if YYSTACKDEPTH>0
157506 if( yypParser->yytos>=yypParser->yystackEnd ){
157507 yyStackOverflow(yypParser);
157508 /* The call to yyStackOverflow() above pops the stack until it is
157509 ** empty, causing the main parser loop to exit. So the return value
157510 ** is never used and does not matter. */
157511 return 0;
157512 }
157513#else
157514 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
157515 if( yyGrowStack(yypParser) ){
157516 yyStackOverflow(yypParser);
157517 /* The call to yyStackOverflow() above pops the stack until it is
157518 ** empty, causing the main parser loop to exit. So the return value
157519 ** is never used and does not matter. */
157520 return 0;
157521 }
157522 yymsp = yypParser->yytos;
157523 }
157524#endif
157525 }
157526
157527 switch( yyruleno ){
157528 /* Beginning here are the reduction cases. A typical example
157529 ** follows:
157530 ** case 0:
157531 ** #line <lineno> <grammarfile>
157532 ** { ... } // User supplied code
157533 ** #line <lineno> <thisfile>
157534 ** break;
157535 */
157536/********** Begin reduce actions **********************************************/
157537 YYMINORTYPE yylhsminor;
157538 case 0: /* explain ::= EXPLAIN */
157539{ pParse->explain = 1; }
157540 break;
157541 case 1: /* explain ::= EXPLAIN QUERY PLAN */
157542{ pParse->explain = 2; }
157543 break;
157544 case 2: /* cmdx ::= cmd */
157545{ sqlite3FinishCoding(pParse); }
157546 break;
157547 case 3: /* cmd ::= BEGIN transtype trans_opt */
157548{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy192);}
157549 break;
157550 case 4: /* transtype ::= */
157551{yymsp[1].minor.yy192 = TK_DEFERRED;}
157552 break;
157553 case 5: /* transtype ::= DEFERRED */
157554 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
157555 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
157556 case 306: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==306);
157557{yymsp[0].minor.yy192 = yymsp[0].major; /*A-overwrites-X*/}
157558 break;
157559 case 8: /* cmd ::= COMMIT|END trans_opt */
157560 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
157561{sqlite3EndTransaction(pParse,yymsp[-1].major);}
157562 break;
157563 case 10: /* cmd ::= SAVEPOINT nm */
157564{
157565 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
157566}
157567 break;
157568 case 11: /* cmd ::= RELEASE savepoint_opt nm */
157569{
157570 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
157571}
157572 break;
157573 case 12: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
157574{
157575 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
157576}
157577 break;
157578 case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
157579{
157580 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy192,0,0,yymsp[-2].minor.yy192);
157581}
157582 break;
157583 case 14: /* createkw ::= CREATE */
157584{disableLookaside(pParse);}
157585 break;
157586 case 15: /* ifnotexists ::= */
157587 case 18: /* temp ::= */ yytestcase(yyruleno==18);
157588 case 21: /* table_options ::= */ yytestcase(yyruleno==21);
157589 case 45: /* autoinc ::= */ yytestcase(yyruleno==45);
157590 case 60: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==60);
157591 case 70: /* defer_subclause_opt ::= */ yytestcase(yyruleno==70);
157592 case 79: /* ifexists ::= */ yytestcase(yyruleno==79);
157593 case 96: /* distinct ::= */ yytestcase(yyruleno==96);
157594 case 232: /* collate ::= */ yytestcase(yyruleno==232);
157595{yymsp[1].minor.yy192 = 0;}
157596 break;
157597 case 16: /* ifnotexists ::= IF NOT EXISTS */
157598{yymsp[-2].minor.yy192 = 1;}
157599 break;
157600 case 17: /* temp ::= TEMP */
157601 case 46: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==46);
157602{yymsp[0].minor.yy192 = 1;}
157603 break;
157604 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
157605{
157606 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy192,0);
157607}
157608 break;
157609 case 20: /* create_table_args ::= AS select */
157610{
157611 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy539);
157612 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy539);
157613}
157614 break;
157615 case 22: /* table_options ::= WITHOUT nm */
157616{
157617 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
157619 }else{
157620 yymsp[-1].minor.yy192 = 0;
157621 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
157622 }
157623}
157624 break;
157625 case 23: /* columnname ::= nm typetoken */
157626{sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
157627 break;
157628 case 24: /* typetoken ::= */
157629 case 63: /* conslist_opt ::= */ yytestcase(yyruleno==63);
157630 case 102: /* as ::= */ yytestcase(yyruleno==102);
157631{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
157632 break;
157633 case 25: /* typetoken ::= typename LP signed RP */
157634{
157635 yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
157636}
157637 break;
157638 case 26: /* typetoken ::= typename LP signed COMMA signed RP */
157639{
157640 yymsp[-5].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
157641}
157642 break;
157643 case 27: /* typename ::= typename ID|STRING */
157644{yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
157645 break;
157646 case 28: /* scanpt ::= */
157647{
157648 assert( yyLookahead!=YYNOCODE );
157649 yymsp[1].minor.yy436 = yyLookaheadToken.z;
157650}
157651 break;
157652 case 29: /* scantok ::= */
157653{
157654 assert( yyLookahead!=YYNOCODE );
157655 yymsp[1].minor.yy0 = yyLookaheadToken;
157656}
157657 break;
157658 case 30: /* ccons ::= CONSTRAINT nm */
157659 case 65: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==65);
157660{pParse->constraintName = yymsp[0].minor.yy0;}
157661 break;
157662 case 31: /* ccons ::= DEFAULT scantok term */
157663{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy202,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
157664 break;
157665 case 32: /* ccons ::= DEFAULT LP expr RP */
157666{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy202,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
157667 break;
157668 case 33: /* ccons ::= DEFAULT PLUS scantok term */
157669{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy202,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
157670 break;
157671 case 34: /* ccons ::= DEFAULT MINUS scantok term */
157672{
157673 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy202, 0);
157674 sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);
157675}
157676 break;
157677 case 35: /* ccons ::= DEFAULT scantok ID|INDEXED */
157678{
157679 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
157680 if( p ){
157683 }
157684 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
157685}
157686 break;
157687 case 36: /* ccons ::= NOT NULL onconf */
157688{sqlite3AddNotNull(pParse, yymsp[0].minor.yy192);}
157689 break;
157690 case 37: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
157691{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy192,yymsp[0].minor.yy192,yymsp[-2].minor.yy192);}
157692 break;
157693 case 38: /* ccons ::= UNIQUE onconf */
157694{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy192,0,0,0,0,
157696 break;
157697 case 39: /* ccons ::= CHECK LP expr RP */
157698{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy202);}
157699 break;
157700 case 40: /* ccons ::= REFERENCES nm eidlist_opt refargs */
157701{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy242,yymsp[0].minor.yy192);}
157702 break;
157703 case 41: /* ccons ::= defer_subclause */
157704{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy192);}
157705 break;
157706 case 42: /* ccons ::= COLLATE ID|STRING */
157707{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
157708 break;
157709 case 43: /* generated ::= LP expr RP */
157710{sqlite3AddGenerated(pParse,yymsp[-1].minor.yy202,0);}
157711 break;
157712 case 44: /* generated ::= LP expr RP ID */
157713{sqlite3AddGenerated(pParse,yymsp[-2].minor.yy202,&yymsp[0].minor.yy0);}
157714 break;
157715 case 47: /* refargs ::= */
157716{ yymsp[1].minor.yy192 = OE_None*0x0101; /* EV: R-19803-45884 */}
157717 break;
157718 case 48: /* refargs ::= refargs refarg */
157719{ yymsp[-1].minor.yy192 = (yymsp[-1].minor.yy192 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; }
157720 break;
157721 case 49: /* refarg ::= MATCH nm */
157722{ yymsp[-1].minor.yy207.value = 0; yymsp[-1].minor.yy207.mask = 0x000000; }
157723 break;
157724 case 50: /* refarg ::= ON INSERT refact */
157725{ yymsp[-2].minor.yy207.value = 0; yymsp[-2].minor.yy207.mask = 0x000000; }
157726 break;
157727 case 51: /* refarg ::= ON DELETE refact */
157728{ yymsp[-2].minor.yy207.value = yymsp[0].minor.yy192; yymsp[-2].minor.yy207.mask = 0x0000ff; }
157729 break;
157730 case 52: /* refarg ::= ON UPDATE refact */
157731{ yymsp[-2].minor.yy207.value = yymsp[0].minor.yy192<<8; yymsp[-2].minor.yy207.mask = 0x00ff00; }
157732 break;
157733 case 53: /* refact ::= SET NULL */
157734{ yymsp[-1].minor.yy192 = OE_SetNull; /* EV: R-33326-45252 */}
157735 break;
157736 case 54: /* refact ::= SET DEFAULT */
157737{ yymsp[-1].minor.yy192 = OE_SetDflt; /* EV: R-33326-45252 */}
157738 break;
157739 case 55: /* refact ::= CASCADE */
157740{ yymsp[0].minor.yy192 = OE_Cascade; /* EV: R-33326-45252 */}
157741 break;
157742 case 56: /* refact ::= RESTRICT */
157743{ yymsp[0].minor.yy192 = OE_Restrict; /* EV: R-33326-45252 */}
157744 break;
157745 case 57: /* refact ::= NO ACTION */
157746{ yymsp[-1].minor.yy192 = OE_None; /* EV: R-33326-45252 */}
157747 break;
157748 case 58: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
157749{yymsp[-2].minor.yy192 = 0;}
157750 break;
157751 case 59: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
157752 case 74: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==74);
157753 case 162: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==162);
157754{yymsp[-1].minor.yy192 = yymsp[0].minor.yy192;}
157755 break;
157756 case 61: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
157757 case 78: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==78);
157758 case 204: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==204);
157759 case 207: /* in_op ::= NOT IN */ yytestcase(yyruleno==207);
157760 case 233: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==233);
157761{yymsp[-1].minor.yy192 = 1;}
157762 break;
157763 case 62: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
157764{yymsp[-1].minor.yy192 = 0;}
157765 break;
157766 case 64: /* tconscomma ::= COMMA */
157767{pParse->constraintName.n = 0;}
157768 break;
157769 case 66: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
157770{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy242,yymsp[0].minor.yy192,yymsp[-2].minor.yy192,0);}
157771 break;
157772 case 67: /* tcons ::= UNIQUE LP sortlist RP onconf */
157773{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy242,yymsp[0].minor.yy192,0,0,0,0,
157775 break;
157776 case 68: /* tcons ::= CHECK LP expr RP onconf */
157777{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy202);}
157778 break;
157779 case 69: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
157780{
157781 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy242, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy242, yymsp[-1].minor.yy192);
157782 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy192);
157783}
157784 break;
157785 case 71: /* onconf ::= */
157786 case 73: /* orconf ::= */ yytestcase(yyruleno==73);
157787{yymsp[1].minor.yy192 = OE_Default;}
157788 break;
157789 case 72: /* onconf ::= ON CONFLICT resolvetype */
157790{yymsp[-2].minor.yy192 = yymsp[0].minor.yy192;}
157791 break;
157792 case 75: /* resolvetype ::= IGNORE */
157793{yymsp[0].minor.yy192 = OE_Ignore;}
157794 break;
157795 case 76: /* resolvetype ::= REPLACE */
157796 case 163: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==163);
157797{yymsp[0].minor.yy192 = OE_Replace;}
157798 break;
157799 case 77: /* cmd ::= DROP TABLE ifexists fullname */
157800{
157801 sqlite3DropTable(pParse, yymsp[0].minor.yy47, 0, yymsp[-1].minor.yy192);
157802}
157803 break;
157804 case 80: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
157805{
157806 sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy242, yymsp[0].minor.yy539, yymsp[-7].minor.yy192, yymsp[-5].minor.yy192);
157807}
157808 break;
157809 case 81: /* cmd ::= DROP VIEW ifexists fullname */
157810{
157811 sqlite3DropTable(pParse, yymsp[0].minor.yy47, 1, yymsp[-1].minor.yy192);
157812}
157813 break;
157814 case 82: /* cmd ::= select */
157815{
157816 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0};
157817 sqlite3Select(pParse, yymsp[0].minor.yy539, &dest);
157818 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy539);
157819}
157820 break;
157821 case 83: /* select ::= WITH wqlist selectnowith */
157822{
157823 Select *p = yymsp[0].minor.yy539;
157824 if( p ){
157825 p->pWith = yymsp[-1].minor.yy131;
157826 parserDoubleLinkSelect(pParse, p);
157827 }else{
157828 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy131);
157829 }
157830 yymsp[-2].minor.yy539 = p;
157831}
157832 break;
157833 case 84: /* select ::= WITH RECURSIVE wqlist selectnowith */
157834{
157835 Select *p = yymsp[0].minor.yy539;
157836 if( p ){
157837 p->pWith = yymsp[-1].minor.yy131;
157838 parserDoubleLinkSelect(pParse, p);
157839 }else{
157840 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy131);
157841 }
157842 yymsp[-3].minor.yy539 = p;
157843}
157844 break;
157845 case 85: /* select ::= selectnowith */
157846{
157847 Select *p = yymsp[0].minor.yy539;
157848 if( p ){
157849 parserDoubleLinkSelect(pParse, p);
157850 }
157851 yymsp[0].minor.yy539 = p; /*A-overwrites-X*/
157852}
157853 break;
157854 case 86: /* selectnowith ::= selectnowith multiselect_op oneselect */
157855{
157856 Select *pRhs = yymsp[0].minor.yy539;
157857 Select *pLhs = yymsp[-2].minor.yy539;
157858 if( pRhs && pRhs->pPrior ){
157859 SrcList *pFrom;
157860 Token x;
157861 x.n = 0;
157862 parserDoubleLinkSelect(pParse, pRhs);
157863 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
157864 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
157865 }
157866 if( pRhs ){
157867 pRhs->op = (u8)yymsp[-1].minor.yy192;
157868 pRhs->pPrior = pLhs;
157869 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
157870 pRhs->selFlags &= ~SF_MultiValue;
157871 if( yymsp[-1].minor.yy192!=TK_ALL ) pParse->hasCompound = 1;
157872 }else{
157873 sqlite3SelectDelete(pParse->db, pLhs);
157874 }
157875 yymsp[-2].minor.yy539 = pRhs;
157876}
157877 break;
157878 case 87: /* multiselect_op ::= UNION */
157879 case 89: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==89);
157880{yymsp[0].minor.yy192 = yymsp[0].major; /*A-overwrites-OP*/}
157881 break;
157882 case 88: /* multiselect_op ::= UNION ALL */
157883{yymsp[-1].minor.yy192 = TK_ALL;}
157884 break;
157885 case 90: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
157886{
157887 yymsp[-8].minor.yy539 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy242,yymsp[-5].minor.yy47,yymsp[-4].minor.yy202,yymsp[-3].minor.yy242,yymsp[-2].minor.yy202,yymsp[-1].minor.yy242,yymsp[-7].minor.yy192,yymsp[0].minor.yy202);
157888}
157889 break;
157890 case 91: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
157891{
157892 yymsp[-9].minor.yy539 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy242,yymsp[-6].minor.yy47,yymsp[-5].minor.yy202,yymsp[-4].minor.yy242,yymsp[-3].minor.yy202,yymsp[-1].minor.yy242,yymsp[-8].minor.yy192,yymsp[0].minor.yy202);
157893 if( yymsp[-9].minor.yy539 ){
157894 yymsp[-9].minor.yy539->pWinDefn = yymsp[-2].minor.yy303;
157895 }else{
157896 sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy303);
157897 }
157898}
157899 break;
157900 case 92: /* values ::= VALUES LP nexprlist RP */
157901{
157902 yymsp[-3].minor.yy539 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy242,0,0,0,0,0,SF_Values,0);
157903}
157904 break;
157905 case 93: /* values ::= values COMMA LP nexprlist RP */
157906{
157907 Select *pRight, *pLeft = yymsp[-4].minor.yy539;
157908 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy242,0,0,0,0,0,SF_Values|SF_MultiValue,0);
157909 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
157910 if( pRight ){
157911 pRight->op = TK_ALL;
157912 pRight->pPrior = pLeft;
157913 yymsp[-4].minor.yy539 = pRight;
157914 }else{
157915 yymsp[-4].minor.yy539 = pLeft;
157916 }
157917}
157918 break;
157919 case 94: /* distinct ::= DISTINCT */
157920{yymsp[0].minor.yy192 = SF_Distinct;}
157921 break;
157922 case 95: /* distinct ::= ALL */
157923{yymsp[0].minor.yy192 = SF_All;}
157924 break;
157925 case 97: /* sclp ::= */
157926 case 130: /* orderby_opt ::= */ yytestcase(yyruleno==130);
157927 case 140: /* groupby_opt ::= */ yytestcase(yyruleno==140);
157928 case 220: /* exprlist ::= */ yytestcase(yyruleno==220);
157929 case 223: /* paren_exprlist ::= */ yytestcase(yyruleno==223);
157930 case 228: /* eidlist_opt ::= */ yytestcase(yyruleno==228);
157931{yymsp[1].minor.yy242 = 0;}
157932 break;
157933 case 98: /* selcollist ::= sclp scanpt expr scanpt as */
157934{
157935 yymsp[-4].minor.yy242 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy242, yymsp[-2].minor.yy202);
157936 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy242, &yymsp[0].minor.yy0, 1);
157937 sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy242,yymsp[-3].minor.yy436,yymsp[-1].minor.yy436);
157938}
157939 break;
157940 case 99: /* selcollist ::= sclp scanpt STAR */
157941{
157942 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
157943 yymsp[-2].minor.yy242 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy242, p);
157944}
157945 break;
157946 case 100: /* selcollist ::= sclp scanpt nm DOT STAR */
157947{
157948 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
157949 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
157950 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
157951 yymsp[-4].minor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242, pDot);
157952}
157953 break;
157954 case 101: /* as ::= AS nm */
157955 case 112: /* dbnm ::= DOT nm */ yytestcase(yyruleno==112);
157956 case 244: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==244);
157957 case 245: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==245);
157958{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
157959 break;
157960 case 103: /* from ::= */
157961 case 106: /* stl_prefix ::= */ yytestcase(yyruleno==106);
157962{yymsp[1].minor.yy47 = 0;}
157963 break;
157964 case 104: /* from ::= FROM seltablist */
157965{
157966 yymsp[-1].minor.yy47 = yymsp[0].minor.yy47;
157967 sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy47);
157968}
157969 break;
157970 case 105: /* stl_prefix ::= seltablist joinop */
157971{
157972 if( ALWAYS(yymsp[-1].minor.yy47 && yymsp[-1].minor.yy47->nSrc>0) ) yymsp[-1].minor.yy47->a[yymsp[-1].minor.yy47->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy192;
157973}
157974 break;
157975 case 107: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
157976{
157977 yymsp[-6].minor.yy47 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy47,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy202,yymsp[0].minor.yy600);
157978 sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy47, &yymsp[-2].minor.yy0);
157979}
157980 break;
157981 case 108: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
157982{
157983 yymsp[-8].minor.yy47 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy47,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy202,yymsp[0].minor.yy600);
157984 sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy47, yymsp[-4].minor.yy242);
157985}
157986 break;
157987 case 109: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
157988{
157989 yymsp[-6].minor.yy47 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy47,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy539,yymsp[-1].minor.yy202,yymsp[0].minor.yy600);
157990 }
157991 break;
157992 case 110: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
157993{
157994 if( yymsp[-6].minor.yy47==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy202==0 && yymsp[0].minor.yy600==0 ){
157995 yymsp[-6].minor.yy47 = yymsp[-4].minor.yy47;
157996 }else if( yymsp[-4].minor.yy47->nSrc==1 ){
157997 yymsp[-6].minor.yy47 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy47,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy202,yymsp[0].minor.yy600);
157998 if( yymsp[-6].minor.yy47 ){
157999 struct SrcList_item *pNew = &yymsp[-6].minor.yy47->a[yymsp[-6].minor.yy47->nSrc-1];
158000 struct SrcList_item *pOld = yymsp[-4].minor.yy47->a;
158001 pNew->zName = pOld->zName;
158002 pNew->zDatabase = pOld->zDatabase;
158003 pNew->pSelect = pOld->pSelect;
158004 if( pOld->fg.isTabFunc ){
158005 pNew->u1.pFuncArg = pOld->u1.pFuncArg;
158006 pOld->u1.pFuncArg = 0;
158007 pOld->fg.isTabFunc = 0;
158008 pNew->fg.isTabFunc = 1;
158009 }
158010 pOld->zName = pOld->zDatabase = 0;
158011 pOld->pSelect = 0;
158012 }
158013 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy47);
158014 }else{
158015 Select *pSubquery;
158016 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy47);
158017 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy47,0,0,0,0,SF_NestedFrom,0);
158018 yymsp[-6].minor.yy47 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy47,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy202,yymsp[0].minor.yy600);
158019 }
158020 }
158021 break;
158022 case 111: /* dbnm ::= */
158023 case 125: /* indexed_opt ::= */ yytestcase(yyruleno==125);
158024{yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
158025 break;
158026 case 113: /* fullname ::= nm */
158027{
158028 yylhsminor.yy47 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
158029 if( IN_RENAME_OBJECT && yylhsminor.yy47 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy47->a[0].zName, &yymsp[0].minor.yy0);
158030}
158031 yymsp[0].minor.yy47 = yylhsminor.yy47;
158032 break;
158033 case 114: /* fullname ::= nm DOT nm */
158034{
158035 yylhsminor.yy47 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
158036 if( IN_RENAME_OBJECT && yylhsminor.yy47 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy47->a[0].zName, &yymsp[0].minor.yy0);
158037}
158038 yymsp[-2].minor.yy47 = yylhsminor.yy47;
158039 break;
158040 case 115: /* xfullname ::= nm */
158041{yymsp[0].minor.yy47 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
158042 break;
158043 case 116: /* xfullname ::= nm DOT nm */
158044{yymsp[-2].minor.yy47 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
158045 break;
158046 case 117: /* xfullname ::= nm DOT nm AS nm */
158047{
158048 yymsp[-4].minor.yy47 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
158049 if( yymsp[-4].minor.yy47 ) yymsp[-4].minor.yy47->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
158050}
158051 break;
158052 case 118: /* xfullname ::= nm AS nm */
158053{
158054 yymsp[-2].minor.yy47 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
158055 if( yymsp[-2].minor.yy47 ) yymsp[-2].minor.yy47->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
158056}
158057 break;
158058 case 119: /* joinop ::= COMMA|JOIN */
158059{ yymsp[0].minor.yy192 = JT_INNER; }
158060 break;
158061 case 120: /* joinop ::= JOIN_KW JOIN */
158062{yymsp[-1].minor.yy192 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
158063 break;
158064 case 121: /* joinop ::= JOIN_KW nm JOIN */
158065{yymsp[-2].minor.yy192 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
158066 break;
158067 case 122: /* joinop ::= JOIN_KW nm nm JOIN */
158068{yymsp[-3].minor.yy192 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
158069 break;
158070 case 123: /* on_opt ::= ON expr */
158071 case 143: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==143);
158072 case 150: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==150);
158073 case 216: /* case_else ::= ELSE expr */ yytestcase(yyruleno==216);
158074 case 237: /* vinto ::= INTO expr */ yytestcase(yyruleno==237);
158075{yymsp[-1].minor.yy202 = yymsp[0].minor.yy202;}
158076 break;
158077 case 124: /* on_opt ::= */
158078 case 142: /* having_opt ::= */ yytestcase(yyruleno==142);
158079 case 144: /* limit_opt ::= */ yytestcase(yyruleno==144);
158080 case 149: /* where_opt ::= */ yytestcase(yyruleno==149);
158081 case 217: /* case_else ::= */ yytestcase(yyruleno==217);
158082 case 219: /* case_operand ::= */ yytestcase(yyruleno==219);
158083 case 238: /* vinto ::= */ yytestcase(yyruleno==238);
158084{yymsp[1].minor.yy202 = 0;}
158085 break;
158086 case 126: /* indexed_opt ::= INDEXED BY nm */
158087{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
158088 break;
158089 case 127: /* indexed_opt ::= NOT INDEXED */
158090{yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
158091 break;
158092 case 128: /* using_opt ::= USING LP idlist RP */
158093{yymsp[-3].minor.yy600 = yymsp[-1].minor.yy600;}
158094 break;
158095 case 129: /* using_opt ::= */
158096 case 164: /* idlist_opt ::= */ yytestcase(yyruleno==164);
158097{yymsp[1].minor.yy600 = 0;}
158098 break;
158099 case 131: /* orderby_opt ::= ORDER BY sortlist */
158100 case 141: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==141);
158101{yymsp[-2].minor.yy242 = yymsp[0].minor.yy242;}
158102 break;
158103 case 132: /* sortlist ::= sortlist COMMA expr sortorder nulls */
158104{
158105 yymsp[-4].minor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242,yymsp[-2].minor.yy202);
158106 sqlite3ExprListSetSortOrder(yymsp[-4].minor.yy242,yymsp[-1].minor.yy192,yymsp[0].minor.yy192);
158107}
158108 break;
158109 case 133: /* sortlist ::= expr sortorder nulls */
158110{
158111 yymsp[-2].minor.yy242 = sqlite3ExprListAppend(pParse,0,yymsp[-2].minor.yy202); /*A-overwrites-Y*/
158112 sqlite3ExprListSetSortOrder(yymsp[-2].minor.yy242,yymsp[-1].minor.yy192,yymsp[0].minor.yy192);
158113}
158114 break;
158115 case 134: /* sortorder ::= ASC */
158116{yymsp[0].minor.yy192 = SQLITE_SO_ASC;}
158117 break;
158118 case 135: /* sortorder ::= DESC */
158119{yymsp[0].minor.yy192 = SQLITE_SO_DESC;}
158120 break;
158121 case 136: /* sortorder ::= */
158122 case 139: /* nulls ::= */ yytestcase(yyruleno==139);
158123{yymsp[1].minor.yy192 = SQLITE_SO_UNDEFINED;}
158124 break;
158125 case 137: /* nulls ::= NULLS FIRST */
158126{yymsp[-1].minor.yy192 = SQLITE_SO_ASC;}
158127 break;
158128 case 138: /* nulls ::= NULLS LAST */
158129{yymsp[-1].minor.yy192 = SQLITE_SO_DESC;}
158130 break;
158131 case 145: /* limit_opt ::= LIMIT expr */
158132{yymsp[-1].minor.yy202 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy202,0);}
158133 break;
158134 case 146: /* limit_opt ::= LIMIT expr OFFSET expr */
158135{yymsp[-3].minor.yy202 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy202,yymsp[0].minor.yy202);}
158136 break;
158137 case 147: /* limit_opt ::= LIMIT expr COMMA expr */
158138{yymsp[-3].minor.yy202 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy202,yymsp[-2].minor.yy202);}
158139 break;
158140 case 148: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
158141{
158142 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy47, &yymsp[-1].minor.yy0);
158143 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy47,yymsp[0].minor.yy202,0,0);
158144}
158145 break;
158146 case 151: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt */
158147{
158148 sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy47, &yymsp[-4].minor.yy0);
158149 sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy242,"set list");
158150 yymsp[-5].minor.yy47 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy47, yymsp[-1].minor.yy47);
158151 sqlite3Update(pParse,yymsp[-5].minor.yy47,yymsp[-2].minor.yy242,yymsp[0].minor.yy202,yymsp[-6].minor.yy192,0,0,0);
158152}
158153 break;
158154 case 152: /* setlist ::= setlist COMMA nm EQ expr */
158155{
158156 yymsp[-4].minor.yy242 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy242, yymsp[0].minor.yy202);
158157 sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy242, &yymsp[-2].minor.yy0, 1);
158158}
158159 break;
158160 case 153: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
158161{
158162 yymsp[-6].minor.yy242 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy242, yymsp[-3].minor.yy600, yymsp[0].minor.yy202);
158163}
158164 break;
158165 case 154: /* setlist ::= nm EQ expr */
158166{
158167 yylhsminor.yy242 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy202);
158168 sqlite3ExprListSetName(pParse, yylhsminor.yy242, &yymsp[-2].minor.yy0, 1);
158169}
158170 yymsp[-2].minor.yy242 = yylhsminor.yy242;
158171 break;
158172 case 155: /* setlist ::= LP idlist RP EQ expr */
158173{
158174 yymsp[-4].minor.yy242 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy600, yymsp[0].minor.yy202);
158175}
158176 break;
158177 case 156: /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
158178{
158179 sqlite3Insert(pParse, yymsp[-3].minor.yy47, yymsp[-1].minor.yy539, yymsp[-2].minor.yy600, yymsp[-5].minor.yy192, yymsp[0].minor.yy318);
158180}
158181 break;
158182 case 157: /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
158183{
158184 sqlite3Insert(pParse, yymsp[-3].minor.yy47, 0, yymsp[-2].minor.yy600, yymsp[-5].minor.yy192, 0);
158185}
158186 break;
158187 case 158: /* upsert ::= */
158188{ yymsp[1].minor.yy318 = 0; }
158189 break;
158190 case 159: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
158191{ yymsp[-10].minor.yy318 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy242,yymsp[-5].minor.yy202,yymsp[-1].minor.yy242,yymsp[0].minor.yy202);}
158192 break;
158193 case 160: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
158194{ yymsp[-7].minor.yy318 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy242,yymsp[-2].minor.yy202,0,0); }
158195 break;
158196 case 161: /* upsert ::= ON CONFLICT DO NOTHING */
158197{ yymsp[-3].minor.yy318 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
158198 break;
158199 case 165: /* idlist_opt ::= LP idlist RP */
158200{yymsp[-2].minor.yy600 = yymsp[-1].minor.yy600;}
158201 break;
158202 case 166: /* idlist ::= idlist COMMA nm */
158203{yymsp[-2].minor.yy600 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy600,&yymsp[0].minor.yy0);}
158204 break;
158205 case 167: /* idlist ::= nm */
158206{yymsp[0].minor.yy600 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
158207 break;
158208 case 168: /* expr ::= LP expr RP */
158209{yymsp[-2].minor.yy202 = yymsp[-1].minor.yy202;}
158210 break;
158211 case 169: /* expr ::= ID|INDEXED */
158212 case 170: /* expr ::= JOIN_KW */ yytestcase(yyruleno==170);
158213{yymsp[0].minor.yy202=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
158214 break;
158215 case 171: /* expr ::= nm DOT nm */
158216{
158217 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
158218 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
158219 if( IN_RENAME_OBJECT ){
158220 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
158221 sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
158222 }
158223 yylhsminor.yy202 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
158224}
158225 yymsp[-2].minor.yy202 = yylhsminor.yy202;
158226 break;
158227 case 172: /* expr ::= nm DOT nm DOT nm */
158228{
158229 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
158230 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
158231 Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
158232 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
158233 if( IN_RENAME_OBJECT ){
158234 sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
158235 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
158236 }
158237 yylhsminor.yy202 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
158238}
158239 yymsp[-4].minor.yy202 = yylhsminor.yy202;
158240 break;
158241 case 173: /* term ::= NULL|FLOAT|BLOB */
158242 case 174: /* term ::= STRING */ yytestcase(yyruleno==174);
158243{yymsp[0].minor.yy202=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
158244 break;
158245 case 175: /* term ::= INTEGER */
158246{
158247 yylhsminor.yy202 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
158248}
158249 yymsp[0].minor.yy202 = yylhsminor.yy202;
158250 break;
158251 case 176: /* expr ::= VARIABLE */
158252{
158253 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
158254 u32 n = yymsp[0].minor.yy0.n;
158255 yymsp[0].minor.yy202 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
158256 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy202, n);
158257 }else{
158258 /* When doing a nested parse, one can include terms in an expression
158259 ** that look like this: #1 #2 ... These terms refer to registers
158260 ** in the virtual machine. #N is the N-th register. */
158261 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
158262 assert( t.n>=2 );
158263 if( pParse->nested==0 ){
158264 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
158265 yymsp[0].minor.yy202 = 0;
158266 }else{
158267 yymsp[0].minor.yy202 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
158268 if( yymsp[0].minor.yy202 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy202->iTable);
158269 }
158270 }
158271}
158272 break;
158273 case 177: /* expr ::= expr COLLATE ID|STRING */
158274{
158275 yymsp[-2].minor.yy202 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy202, &yymsp[0].minor.yy0, 1);
158276}
158277 break;
158278 case 178: /* expr ::= CAST LP expr AS typetoken RP */
158279{
158280 yymsp[-5].minor.yy202 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
158281 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy202, yymsp[-3].minor.yy202, 0);
158282}
158283 break;
158284 case 179: /* expr ::= ID|INDEXED LP distinct exprlist RP */
158285{
158286 yylhsminor.yy202 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy242, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy192);
158287}
158288 yymsp[-4].minor.yy202 = yylhsminor.yy202;
158289 break;
158290 case 180: /* expr ::= ID|INDEXED LP STAR RP */
158291{
158292 yylhsminor.yy202 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
158293}
158294 yymsp[-3].minor.yy202 = yylhsminor.yy202;
158295 break;
158296 case 181: /* expr ::= ID|INDEXED LP distinct exprlist RP filter_over */
158297{
158298 yylhsminor.yy202 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy242, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy192);
158299 sqlite3WindowAttach(pParse, yylhsminor.yy202, yymsp[0].minor.yy303);
158300}
158301 yymsp[-5].minor.yy202 = yylhsminor.yy202;
158302 break;
158303 case 182: /* expr ::= ID|INDEXED LP STAR RP filter_over */
158304{
158305 yylhsminor.yy202 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
158306 sqlite3WindowAttach(pParse, yylhsminor.yy202, yymsp[0].minor.yy303);
158307}
158308 yymsp[-4].minor.yy202 = yylhsminor.yy202;
158309 break;
158310 case 183: /* term ::= CTIME_KW */
158311{
158312 yylhsminor.yy202 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
158313}
158314 yymsp[0].minor.yy202 = yylhsminor.yy202;
158315 break;
158316 case 184: /* expr ::= LP nexprlist COMMA expr RP */
158317{
158318 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy242, yymsp[-1].minor.yy202);
158319 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
158320 if( yymsp[-4].minor.yy202 ){
158321 yymsp[-4].minor.yy202->x.pList = pList;
158322 if( ALWAYS(pList->nExpr) ){
158323 yymsp[-4].minor.yy202->flags |= pList->a[0].pExpr->flags & EP_Propagate;
158324 }
158325 }else{
158326 sqlite3ExprListDelete(pParse->db, pList);
158327 }
158328}
158329 break;
158330 case 185: /* expr ::= expr AND expr */
158331{yymsp[-2].minor.yy202=sqlite3ExprAnd(pParse,yymsp[-2].minor.yy202,yymsp[0].minor.yy202);}
158332 break;
158333 case 186: /* expr ::= expr OR expr */
158334 case 187: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==187);
158335 case 188: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==188);
158336 case 189: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==189);
158337 case 190: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==190);
158338 case 191: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==191);
158339 case 192: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==192);
158340{yymsp[-2].minor.yy202=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy202,yymsp[0].minor.yy202);}
158341 break;
158342 case 193: /* likeop ::= NOT LIKE_KW|MATCH */
158343{yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
158344 break;
158345 case 194: /* expr ::= expr likeop expr */
158346{
158347 ExprList *pList;
158348 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
158349 yymsp[-1].minor.yy0.n &= 0x7fffffff;
158350 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy202);
158351 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy202);
158352 yymsp[-2].minor.yy202 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
158353 if( bNot ) yymsp[-2].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy202, 0);
158354 if( yymsp[-2].minor.yy202 ) yymsp[-2].minor.yy202->flags |= EP_InfixFunc;
158355}
158356 break;
158357 case 195: /* expr ::= expr likeop expr ESCAPE expr */
158358{
158359 ExprList *pList;
158360 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
158361 yymsp[-3].minor.yy0.n &= 0x7fffffff;
158362 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy202);
158363 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy202);
158364 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy202);
158365 yymsp[-4].minor.yy202 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
158366 if( bNot ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
158367 if( yymsp[-4].minor.yy202 ) yymsp[-4].minor.yy202->flags |= EP_InfixFunc;
158368}
158369 break;
158370 case 196: /* expr ::= expr ISNULL|NOTNULL */
158371{yymsp[-1].minor.yy202 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy202,0);}
158372 break;
158373 case 197: /* expr ::= expr NOT NULL */
158374{yymsp[-2].minor.yy202 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy202,0);}
158375 break;
158376 case 198: /* expr ::= expr IS expr */
158377{
158378 yymsp[-2].minor.yy202 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy202,yymsp[0].minor.yy202);
158379 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy202, yymsp[-2].minor.yy202, TK_ISNULL);
158380}
158381 break;
158382 case 199: /* expr ::= expr IS NOT expr */
158383{
158384 yymsp[-3].minor.yy202 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy202,yymsp[0].minor.yy202);
158385 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy202, yymsp[-3].minor.yy202, TK_NOTNULL);
158386}
158387 break;
158388 case 200: /* expr ::= NOT expr */
158389 case 201: /* expr ::= BITNOT expr */ yytestcase(yyruleno==201);
158390{yymsp[-1].minor.yy202 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy202, 0);/*A-overwrites-B*/}
158391 break;
158392 case 202: /* expr ::= PLUS|MINUS expr */
158393{
158394 yymsp[-1].minor.yy202 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy202, 0);
158395 /*A-overwrites-B*/
158396}
158397 break;
158398 case 203: /* between_op ::= BETWEEN */
158399 case 206: /* in_op ::= IN */ yytestcase(yyruleno==206);
158400{yymsp[0].minor.yy192 = 0;}
158401 break;
158402 case 205: /* expr ::= expr between_op expr AND expr */
158403{
158404 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy202);
158405 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy202);
158406 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy202, 0);
158407 if( yymsp[-4].minor.yy202 ){
158408 yymsp[-4].minor.yy202->x.pList = pList;
158409 }else{
158410 sqlite3ExprListDelete(pParse->db, pList);
158411 }
158412 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
158413}
158414 break;
158415 case 208: /* expr ::= expr in_op LP exprlist RP */
158416{
158417 if( yymsp[-1].minor.yy242==0 ){
158418 /* Expressions of the form
158419 **
158420 ** expr1 IN ()
158421 ** expr1 NOT IN ()
158422 **
158423 ** simplify to constants 0 (false) and 1 (true), respectively,
158424 ** regardless of the value of expr1.
158425 */
158426 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202);
158427 yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0");
158428 }else if( yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){
158429 Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr;
158430 yymsp[-1].minor.yy242->a[0].pExpr = 0;
158431 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242);
158432 pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
158433 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS);
158434 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
158435 }else{
158436 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0);
158437 if( yymsp[-4].minor.yy202 ){
158438 yymsp[-4].minor.yy202->x.pList = yymsp[-1].minor.yy242;
158439 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy202);
158440 }else{
158441 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242);
158442 }
158443 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
158444 }
158445 }
158446 break;
158447 case 209: /* expr ::= LP select RP */
158448{
158449 yymsp[-2].minor.yy202 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
158450 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy202, yymsp[-1].minor.yy539);
158451 }
158452 break;
158453 case 210: /* expr ::= expr in_op LP select RP */
158454{
158455 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0);
158456 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy202, yymsp[-1].minor.yy539);
158457 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
158458 }
158459 break;
158460 case 211: /* expr ::= expr in_op nm dbnm paren_exprlist */
158461{
158462 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
158463 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
158464 if( yymsp[0].minor.yy242 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy242);
158465 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0);
158466 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy202, pSelect);
158467 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
158468 }
158469 break;
158470 case 212: /* expr ::= EXISTS LP select RP */
158471{
158472 Expr *p;
158473 p = yymsp[-3].minor.yy202 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
158474 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy539);
158475 }
158476 break;
158477 case 213: /* expr ::= CASE case_operand case_exprlist case_else END */
158478{
158479 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy202, 0);
158480 if( yymsp[-4].minor.yy202 ){
158481 yymsp[-4].minor.yy202->x.pList = yymsp[-1].minor.yy202 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy242,yymsp[-1].minor.yy202) : yymsp[-2].minor.yy242;
158482 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy202);
158483 }else{
158484 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy242);
158485 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy202);
158486 }
158487}
158488 break;
158489 case 214: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
158490{
158491 yymsp[-4].minor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242, yymsp[-2].minor.yy202);
158492 yymsp[-4].minor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242, yymsp[0].minor.yy202);
158493}
158494 break;
158495 case 215: /* case_exprlist ::= WHEN expr THEN expr */
158496{
158497 yymsp[-3].minor.yy242 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy202);
158498 yymsp[-3].minor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy242, yymsp[0].minor.yy202);
158499}
158500 break;
158501 case 218: /* case_operand ::= expr */
158502{yymsp[0].minor.yy202 = yymsp[0].minor.yy202; /*A-overwrites-X*/}
158503 break;
158504 case 221: /* nexprlist ::= nexprlist COMMA expr */
158505{yymsp[-2].minor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy242,yymsp[0].minor.yy202);}
158506 break;
158507 case 222: /* nexprlist ::= expr */
158508{yymsp[0].minor.yy242 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy202); /*A-overwrites-Y*/}
158509 break;
158510 case 224: /* paren_exprlist ::= LP exprlist RP */
158511 case 229: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==229);
158512{yymsp[-2].minor.yy242 = yymsp[-1].minor.yy242;}
158513 break;
158514 case 225: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
158515{
158516 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
158517 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy242, yymsp[-10].minor.yy192,
158518 &yymsp[-11].minor.yy0, yymsp[0].minor.yy202, SQLITE_SO_ASC, yymsp[-8].minor.yy192, SQLITE_IDXTYPE_APPDEF);
158519 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
158520 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
158521 }
158522}
158523 break;
158524 case 226: /* uniqueflag ::= UNIQUE */
158525 case 268: /* raisetype ::= ABORT */ yytestcase(yyruleno==268);
158526{yymsp[0].minor.yy192 = OE_Abort;}
158527 break;
158528 case 227: /* uniqueflag ::= */
158529{yymsp[1].minor.yy192 = OE_None;}
158530 break;
158531 case 230: /* eidlist ::= eidlist COMMA nm collate sortorder */
158532{
158533 yymsp[-4].minor.yy242 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy242, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy192, yymsp[0].minor.yy192);
158534}
158535 break;
158536 case 231: /* eidlist ::= nm collate sortorder */
158537{
158538 yymsp[-2].minor.yy242 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy192, yymsp[0].minor.yy192); /*A-overwrites-Y*/
158539}
158540 break;
158541 case 234: /* cmd ::= DROP INDEX ifexists fullname */
158542{sqlite3DropIndex(pParse, yymsp[0].minor.yy47, yymsp[-1].minor.yy192);}
158543 break;
158544 case 235: /* cmd ::= VACUUM vinto */
158545{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy202);}
158546 break;
158547 case 236: /* cmd ::= VACUUM nm vinto */
158548{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy202);}
158549 break;
158550 case 239: /* cmd ::= PRAGMA nm dbnm */
158551{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
158552 break;
158553 case 240: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
158554{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
158555 break;
158556 case 241: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
158557{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
158558 break;
158559 case 242: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
158560{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
158561 break;
158562 case 243: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
158563{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
158564 break;
158565 case 246: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
158566{
158567 Token all;
158568 all.z = yymsp[-3].minor.yy0.z;
158569 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
158570 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy447, &all);
158571}
158572 break;
158573 case 247: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
158574{
158575 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy192, yymsp[-4].minor.yy230.a, yymsp[-4].minor.yy230.b, yymsp[-2].minor.yy47, yymsp[0].minor.yy202, yymsp[-10].minor.yy192, yymsp[-8].minor.yy192);
158576 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
158577}
158578 break;
158579 case 248: /* trigger_time ::= BEFORE|AFTER */
158580{ yymsp[0].minor.yy192 = yymsp[0].major; /*A-overwrites-X*/ }
158581 break;
158582 case 249: /* trigger_time ::= INSTEAD OF */
158583{ yymsp[-1].minor.yy192 = TK_INSTEAD;}
158584 break;
158585 case 250: /* trigger_time ::= */
158586{ yymsp[1].minor.yy192 = TK_BEFORE; }
158587 break;
158588 case 251: /* trigger_event ::= DELETE|INSERT */
158589 case 252: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==252);
158590{yymsp[0].minor.yy230.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy230.b = 0;}
158591 break;
158592 case 253: /* trigger_event ::= UPDATE OF idlist */
158593{yymsp[-2].minor.yy230.a = TK_UPDATE; yymsp[-2].minor.yy230.b = yymsp[0].minor.yy600;}
158594 break;
158595 case 254: /* when_clause ::= */
158596 case 273: /* key_opt ::= */ yytestcase(yyruleno==273);
158597{ yymsp[1].minor.yy202 = 0; }
158598 break;
158599 case 255: /* when_clause ::= WHEN expr */
158600 case 274: /* key_opt ::= KEY expr */ yytestcase(yyruleno==274);
158601{ yymsp[-1].minor.yy202 = yymsp[0].minor.yy202; }
158602 break;
158603 case 256: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
158604{
158605 assert( yymsp[-2].minor.yy447!=0 );
158606 yymsp[-2].minor.yy447->pLast->pNext = yymsp[-1].minor.yy447;
158607 yymsp[-2].minor.yy447->pLast = yymsp[-1].minor.yy447;
158608}
158609 break;
158610 case 257: /* trigger_cmd_list ::= trigger_cmd SEMI */
158611{
158612 assert( yymsp[-1].minor.yy447!=0 );
158613 yymsp[-1].minor.yy447->pLast = yymsp[-1].minor.yy447;
158614}
158615 break;
158616 case 258: /* trnm ::= nm DOT nm */
158617{
158618 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
158619 sqlite3ErrorMsg(pParse,
158620 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
158621 "statements within triggers");
158622}
158623 break;
158624 case 259: /* tridxby ::= INDEXED BY nm */
158625{
158626 sqlite3ErrorMsg(pParse,
158627 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
158628 "within triggers");
158629}
158630 break;
158631 case 260: /* tridxby ::= NOT INDEXED */
158632{
158633 sqlite3ErrorMsg(pParse,
158634 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
158635 "within triggers");
158636}
158637 break;
158638 case 261: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
158639{yylhsminor.yy447 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy47, yymsp[-3].minor.yy242, yymsp[-1].minor.yy202, yymsp[-7].minor.yy192, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy436);}
158640 yymsp[-8].minor.yy447 = yylhsminor.yy447;
158641 break;
158642 case 262: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
158643{
158644 yylhsminor.yy447 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy600,yymsp[-2].minor.yy539,yymsp[-6].minor.yy192,yymsp[-1].minor.yy318,yymsp[-7].minor.yy436,yymsp[0].minor.yy436);/*yylhsminor.yy447-overwrites-yymsp[-6].minor.yy192*/
158645}
158646 yymsp[-7].minor.yy447 = yylhsminor.yy447;
158647 break;
158648 case 263: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
158649{yylhsminor.yy447 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy202, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy436);}
158650 yymsp[-5].minor.yy447 = yylhsminor.yy447;
158651 break;
158652 case 264: /* trigger_cmd ::= scanpt select scanpt */
158653{yylhsminor.yy447 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy539, yymsp[-2].minor.yy436, yymsp[0].minor.yy436); /*yylhsminor.yy447-overwrites-yymsp[-1].minor.yy539*/}
158654 yymsp[-2].minor.yy447 = yylhsminor.yy447;
158655 break;
158656 case 265: /* expr ::= RAISE LP IGNORE RP */
158657{
158658 yymsp[-3].minor.yy202 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
158659 if( yymsp[-3].minor.yy202 ){
158660 yymsp[-3].minor.yy202->affExpr = OE_Ignore;
158661 }
158662}
158663 break;
158664 case 266: /* expr ::= RAISE LP raisetype COMMA nm RP */
158665{
158666 yymsp[-5].minor.yy202 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
158667 if( yymsp[-5].minor.yy202 ) {
158668 yymsp[-5].minor.yy202->affExpr = (char)yymsp[-3].minor.yy192;
158669 }
158670}
158671 break;
158672 case 267: /* raisetype ::= ROLLBACK */
158673{yymsp[0].minor.yy192 = OE_Rollback;}
158674 break;
158675 case 269: /* raisetype ::= FAIL */
158676{yymsp[0].minor.yy192 = OE_Fail;}
158677 break;
158678 case 270: /* cmd ::= DROP TRIGGER ifexists fullname */
158679{
158680 sqlite3DropTrigger(pParse,yymsp[0].minor.yy47,yymsp[-1].minor.yy192);
158681}
158682 break;
158683 case 271: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
158684{
158685 sqlite3Attach(pParse, yymsp[-3].minor.yy202, yymsp[-1].minor.yy202, yymsp[0].minor.yy202);
158686}
158687 break;
158688 case 272: /* cmd ::= DETACH database_kw_opt expr */
158689{
158690 sqlite3Detach(pParse, yymsp[0].minor.yy202);
158691}
158692 break;
158693 case 275: /* cmd ::= REINDEX */
158694{sqlite3Reindex(pParse, 0, 0);}
158695 break;
158696 case 276: /* cmd ::= REINDEX nm dbnm */
158697{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
158698 break;
158699 case 277: /* cmd ::= ANALYZE */
158700{sqlite3Analyze(pParse, 0, 0);}
158701 break;
158702 case 278: /* cmd ::= ANALYZE nm dbnm */
158703{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
158704 break;
158705 case 279: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
158706{
158707 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy47,&yymsp[0].minor.yy0);
158708}
158709 break;
158710 case 280: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
158711{
158712 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
158713 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
158714}
158715 break;
158716 case 281: /* add_column_fullname ::= fullname */
158717{
158718 disableLookaside(pParse);
158719 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy47);
158720}
158721 break;
158722 case 282: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
158723{
158724 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy47, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
158725}
158726 break;
158727 case 283: /* cmd ::= create_vtab */
158728{sqlite3VtabFinishParse(pParse,0);}
158729 break;
158730 case 284: /* cmd ::= create_vtab LP vtabarglist RP */
158731{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
158732 break;
158733 case 285: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
158734{
158735 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy192);
158736}
158737 break;
158738 case 286: /* vtabarg ::= */
158739{sqlite3VtabArgInit(pParse);}
158740 break;
158741 case 287: /* vtabargtoken ::= ANY */
158742 case 288: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==288);
158743 case 289: /* lp ::= LP */ yytestcase(yyruleno==289);
158744{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
158745 break;
158746 case 290: /* with ::= WITH wqlist */
158747 case 291: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==291);
158748{ sqlite3WithPush(pParse, yymsp[0].minor.yy131, 1); }
158749 break;
158750 case 292: /* wqlist ::= nm eidlist_opt AS LP select RP */
158751{
158752 yymsp[-5].minor.yy131 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy242, yymsp[-1].minor.yy539); /*A-overwrites-X*/
158753}
158754 break;
158755 case 293: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
158756{
158757 yymsp[-7].minor.yy131 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy131, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy242, yymsp[-1].minor.yy539);
158758}
158759 break;
158760 case 294: /* windowdefn_list ::= windowdefn */
158761{ yylhsminor.yy303 = yymsp[0].minor.yy303; }
158762 yymsp[0].minor.yy303 = yylhsminor.yy303;
158763 break;
158764 case 295: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
158765{
158766 assert( yymsp[0].minor.yy303!=0 );
158767 sqlite3WindowChain(pParse, yymsp[0].minor.yy303, yymsp[-2].minor.yy303);
158768 yymsp[0].minor.yy303->pNextWin = yymsp[-2].minor.yy303;
158769 yylhsminor.yy303 = yymsp[0].minor.yy303;
158770}
158771 yymsp[-2].minor.yy303 = yylhsminor.yy303;
158772 break;
158773 case 296: /* windowdefn ::= nm AS LP window RP */
158774{
158775 if( ALWAYS(yymsp[-1].minor.yy303) ){
158776 yymsp[-1].minor.yy303->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
158777 }
158778 yylhsminor.yy303 = yymsp[-1].minor.yy303;
158779}
158780 yymsp[-4].minor.yy303 = yylhsminor.yy303;
158781 break;
158782 case 297: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
158783{
158784 yymsp[-4].minor.yy303 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy303, yymsp[-2].minor.yy242, yymsp[-1].minor.yy242, 0);
158785}
158786 break;
158787 case 298: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
158788{
158789 yylhsminor.yy303 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy303, yymsp[-2].minor.yy242, yymsp[-1].minor.yy242, &yymsp[-5].minor.yy0);
158790}
158791 yymsp[-5].minor.yy303 = yylhsminor.yy303;
158792 break;
158793 case 299: /* window ::= ORDER BY sortlist frame_opt */
158794{
158795 yymsp[-3].minor.yy303 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy303, 0, yymsp[-1].minor.yy242, 0);
158796}
158797 break;
158798 case 300: /* window ::= nm ORDER BY sortlist frame_opt */
158799{
158800 yylhsminor.yy303 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy303, 0, yymsp[-1].minor.yy242, &yymsp[-4].minor.yy0);
158801}
158802 yymsp[-4].minor.yy303 = yylhsminor.yy303;
158803 break;
158804 case 301: /* window ::= frame_opt */
158805 case 320: /* filter_over ::= over_clause */ yytestcase(yyruleno==320);
158806{
158807 yylhsminor.yy303 = yymsp[0].minor.yy303;
158808}
158809 yymsp[0].minor.yy303 = yylhsminor.yy303;
158810 break;
158811 case 302: /* window ::= nm frame_opt */
158812{
158813 yylhsminor.yy303 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy303, 0, 0, &yymsp[-1].minor.yy0);
158814}
158815 yymsp[-1].minor.yy303 = yylhsminor.yy303;
158816 break;
158817 case 303: /* frame_opt ::= */
158818{
158819 yymsp[1].minor.yy303 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
158820}
158821 break;
158822 case 304: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
158823{
158824 yylhsminor.yy303 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy192, yymsp[-1].minor.yy77.eType, yymsp[-1].minor.yy77.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy58);
158825}
158826 yymsp[-2].minor.yy303 = yylhsminor.yy303;
158827 break;
158828 case 305: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
158829{
158830 yylhsminor.yy303 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy192, yymsp[-3].minor.yy77.eType, yymsp[-3].minor.yy77.pExpr, yymsp[-1].minor.yy77.eType, yymsp[-1].minor.yy77.pExpr, yymsp[0].minor.yy58);
158831}
158832 yymsp[-5].minor.yy303 = yylhsminor.yy303;
158833 break;
158834 case 307: /* frame_bound_s ::= frame_bound */
158835 case 309: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==309);
158836{yylhsminor.yy77 = yymsp[0].minor.yy77;}
158837 yymsp[0].minor.yy77 = yylhsminor.yy77;
158838 break;
158839 case 308: /* frame_bound_s ::= UNBOUNDED PRECEDING */
158840 case 310: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==310);
158841 case 312: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==312);
158842{yylhsminor.yy77.eType = yymsp[-1].major; yylhsminor.yy77.pExpr = 0;}
158843 yymsp[-1].minor.yy77 = yylhsminor.yy77;
158844 break;
158845 case 311: /* frame_bound ::= expr PRECEDING|FOLLOWING */
158846{yylhsminor.yy77.eType = yymsp[0].major; yylhsminor.yy77.pExpr = yymsp[-1].minor.yy202;}
158847 yymsp[-1].minor.yy77 = yylhsminor.yy77;
158848 break;
158849 case 313: /* frame_exclude_opt ::= */
158850{yymsp[1].minor.yy58 = 0;}
158851 break;
158852 case 314: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
158853{yymsp[-1].minor.yy58 = yymsp[0].minor.yy58;}
158854 break;
158855 case 315: /* frame_exclude ::= NO OTHERS */
158856 case 316: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==316);
158857{yymsp[-1].minor.yy58 = yymsp[-1].major; /*A-overwrites-X*/}
158858 break;
158859 case 317: /* frame_exclude ::= GROUP|TIES */
158860{yymsp[0].minor.yy58 = yymsp[0].major; /*A-overwrites-X*/}
158861 break;
158862 case 318: /* window_clause ::= WINDOW windowdefn_list */
158863{ yymsp[-1].minor.yy303 = yymsp[0].minor.yy303; }
158864 break;
158865 case 319: /* filter_over ::= filter_clause over_clause */
158866{
158867 yymsp[0].minor.yy303->pFilter = yymsp[-1].minor.yy202;
158868 yylhsminor.yy303 = yymsp[0].minor.yy303;
158869}
158870 yymsp[-1].minor.yy303 = yylhsminor.yy303;
158871 break;
158872 case 321: /* filter_over ::= filter_clause */
158873{
158874 yylhsminor.yy303 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
158875 if( yylhsminor.yy303 ){
158876 yylhsminor.yy303->eFrmType = TK_FILTER;
158877 yylhsminor.yy303->pFilter = yymsp[0].minor.yy202;
158878 }else{
158879 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy202);
158880 }
158881}
158882 yymsp[0].minor.yy303 = yylhsminor.yy303;
158883 break;
158884 case 322: /* over_clause ::= OVER LP window RP */
158885{
158886 yymsp[-3].minor.yy303 = yymsp[-1].minor.yy303;
158887 assert( yymsp[-3].minor.yy303!=0 );
158888}
158889 break;
158890 case 323: /* over_clause ::= OVER nm */
158891{
158892 yymsp[-1].minor.yy303 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
158893 if( yymsp[-1].minor.yy303 ){
158894 yymsp[-1].minor.yy303->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
158895 }
158896}
158897 break;
158898 case 324: /* filter_clause ::= FILTER LP WHERE expr RP */
158899{ yymsp[-4].minor.yy202 = yymsp[-1].minor.yy202; }
158900 break;
158901 default:
158902 /* (325) input ::= cmdlist */ yytestcase(yyruleno==325);
158903 /* (326) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==326);
158904 /* (327) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=327);
158905 /* (328) ecmd ::= SEMI */ yytestcase(yyruleno==328);
158906 /* (329) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==329);
158907 /* (330) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=330);
158908 /* (331) trans_opt ::= */ yytestcase(yyruleno==331);
158909 /* (332) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==332);
158910 /* (333) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==333);
158911 /* (334) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==334);
158912 /* (335) savepoint_opt ::= */ yytestcase(yyruleno==335);
158913 /* (336) cmd ::= create_table create_table_args */ yytestcase(yyruleno==336);
158914 /* (337) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==337);
158915 /* (338) columnlist ::= columnname carglist */ yytestcase(yyruleno==338);
158916 /* (339) nm ::= ID|INDEXED */ yytestcase(yyruleno==339);
158917 /* (340) nm ::= STRING */ yytestcase(yyruleno==340);
158918 /* (341) nm ::= JOIN_KW */ yytestcase(yyruleno==341);
158919 /* (342) typetoken ::= typename */ yytestcase(yyruleno==342);
158920 /* (343) typename ::= ID|STRING */ yytestcase(yyruleno==343);
158921 /* (344) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=344);
158922 /* (345) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=345);
158923 /* (346) carglist ::= carglist ccons */ yytestcase(yyruleno==346);
158924 /* (347) carglist ::= */ yytestcase(yyruleno==347);
158925 /* (348) ccons ::= NULL onconf */ yytestcase(yyruleno==348);
158926 /* (349) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==349);
158927 /* (350) ccons ::= AS generated */ yytestcase(yyruleno==350);
158928 /* (351) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==351);
158929 /* (352) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==352);
158930 /* (353) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=353);
158931 /* (354) tconscomma ::= */ yytestcase(yyruleno==354);
158932 /* (355) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=355);
158933 /* (356) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=356);
158934 /* (357) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=357);
158935 /* (358) oneselect ::= values */ yytestcase(yyruleno==358);
158936 /* (359) sclp ::= selcollist COMMA */ yytestcase(yyruleno==359);
158937 /* (360) as ::= ID|STRING */ yytestcase(yyruleno==360);
158938 /* (361) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=361);
158939 /* (362) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==362);
158940 /* (363) exprlist ::= nexprlist */ yytestcase(yyruleno==363);
158941 /* (364) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=364);
158942 /* (365) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=365);
158943 /* (366) nmnum ::= ON */ yytestcase(yyruleno==366);
158944 /* (367) nmnum ::= DELETE */ yytestcase(yyruleno==367);
158945 /* (368) nmnum ::= DEFAULT */ yytestcase(yyruleno==368);
158946 /* (369) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==369);
158947 /* (370) foreach_clause ::= */ yytestcase(yyruleno==370);
158948 /* (371) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==371);
158949 /* (372) trnm ::= nm */ yytestcase(yyruleno==372);
158950 /* (373) tridxby ::= */ yytestcase(yyruleno==373);
158951 /* (374) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==374);
158952 /* (375) database_kw_opt ::= */ yytestcase(yyruleno==375);
158953 /* (376) kwcolumn_opt ::= */ yytestcase(yyruleno==376);
158954 /* (377) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==377);
158955 /* (378) vtabarglist ::= vtabarg */ yytestcase(yyruleno==378);
158956 /* (379) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==379);
158957 /* (380) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==380);
158958 /* (381) anylist ::= */ yytestcase(yyruleno==381);
158959 /* (382) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==382);
158960 /* (383) anylist ::= anylist ANY */ yytestcase(yyruleno==383);
158961 /* (384) with ::= */ yytestcase(yyruleno==384);
158962 break;
158963/********** End reduce actions ************************************************/
158964 };
158965 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
158966 yygoto = yyRuleInfoLhs[yyruleno];
158967 yysize = yyRuleInfoNRhs[yyruleno];
158968 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
158969
158970 /* There are no SHIFTREDUCE actions on nonterminals because the table
158971 ** generator has simplified them to pure REDUCE actions. */
158972 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
158973
158974 /* It is not possible for a REDUCE to be followed by an error */
158975 assert( yyact!=YY_ERROR_ACTION );
158976
158977 yymsp += yysize+1;
static ExprList * parserAddExprIdListTerm(Parse *pParse, ExprList *pPrior, Token *pIdToken, int hasCollate, int sortOrder)
Definition sqlite3.c:154393
SQLITE_PRIVATE TriggerStep * sqlite3TriggerSelectStep(sqlite3 *, Select *, const char *, const char *)
Definition sqlite3.c:136770
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse *, Token *, Token *, Token *, int)
Definition sqlite3.c:139948
SQLITE_PRIVATE void sqlite3CreateView(Parse *, Token *, Token *, Token *, ExprList *, Select *, int, int)
Definition sqlite3.c:112951
SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse *, Expr *, Select *)
Definition sqlite3.c:100626
SQLITE_PRIVATE void sqlite3Pragma(Parse *, Token *, Token *, Token *, int)
Definition sqlite3.c:126117
SQLITE_PRIVATE void sqlite3FinishTrigger(Parse *, TriggerStep *, Token *)
Definition sqlite3.c:136668
SQLITE_PRIVATE void sqlite3AddCollateType(Parse *, Token *)
Definition sqlite3.c:112033
SQLITE_PRIVATE void sqlite3EndTransaction(Parse *, int)
Definition sqlite3.c:115049
SQLITE_PRIVATE IdList * sqlite3IdListAppend(Parse *, IdList *, Token *)
Definition sqlite3.c:114617
SQLITE_PRIVATE TriggerStep * sqlite3TriggerUpdateStep(Parse *, Token *, SrcList *, ExprList *, Expr *, u8, const char *, const char *)
Definition sqlite3.c:136871
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *, Token *)
Definition sqlite3.c:140009
#define SQLITE_IDXTYPE_UNIQUE
Definition sqlite3.c:17818
SQLITE_PRIVATE void sqlite3AddGenerated(Parse *, Expr *, Token *)
Definition sqlite3.c:112068
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *)
Definition sqlite3.c:106078
SQLITE_PRIVATE void sqlite3DropIndex(Parse *, SrcList *, int)
Definition sqlite3.c:114506
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse *, Expr *, const char *, const char *)
Definition sqlite3.c:111833
SQLITE_PRIVATE Window * sqlite3WindowAssemble(Parse *, Window *, ExprList *, ExprList *, Token *)
Definition sqlite3.c:152381
SQLITE_PRIVATE void sqlite3AddNotNull(Parse *, int)
Definition sqlite3.c:111709
SQLITE_PRIVATE void sqlite3DropTable(Parse *, SrcList *, int, int)
Definition sqlite3.c:113434
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *)
Definition sqlite3.c:114937
SQLITE_PRIVATE TriggerStep * sqlite3TriggerInsertStep(Parse *, Token *, IdList *, Select *, u8, Upsert *, const char *, const char *)
Definition sqlite3.c:136826
SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse *, ExprList *, Token *, ExprList *, int)
Definition sqlite3.c:113551
SQLITE_PRIVATE void sqlite3VtabArgInit(Parse *)
Definition sqlite3.c:140095
SQLITE_PRIVATE void sqlite3FinishCoding(Parse *)
Definition sqlite3.c:110520
SQLITE_PRIVATE void sqlite3Savepoint(Parse *, int, Token *)
Definition sqlite3.c:115071
SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *)
Definition sqlite3.c:106223
static void disableLookaside(Parse *pParse)
Definition sqlite3.c:154288
SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse *, Expr *)
Definition sqlite3.c:100856
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *)
Definition sqlite3.c:115009
SQLITE_PRIVATE void sqlite3WindowAttach(Parse *, Expr *, Window *)
Definition sqlite3.c:152442
SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse *, SrcList *, Token *, Token *)
Definition sqlite3.c:106334
#define yytestcase(X)
Definition sqlite3.c:154244
SQLITE_PRIVATE Window * sqlite3WindowAlloc(Parse *, int, int, Expr *, int, Expr *, u8)
Definition sqlite3.c:152309
SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse *, SrcList *, Token *)
Definition sqlite3.c:105885
SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *, int)
Definition sqlite3.c:113681
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *, Expr *, u32)
Definition sqlite3.c:100742
#define SF_All
Definition sqlite3.c:18472
SQLITE_PRIVATE void sqlite3Detach(Parse *, Expr *)
Definition sqlite3.c:109886
SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse *, Token *)
Definition sqlite3.c:140105
SQLITE_PRIVATE void sqlite3Reindex(Parse *, Token *, Token *)
Definition sqlite3.c:115366
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse *, ExprList *, const char *, const char *)
Definition sqlite3.c:101529
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse *, int)
Definition sqlite3.c:115022
SQLITE_PRIVATE With * sqlite3WithAdd(Parse *, With *, Token *, ExprList *, Select *)
Definition sqlite3.c:115471
SQLITE_PRIVATE Expr * sqlite3ExprFunction(Parse *, ExprList *, Token *, int)
Definition sqlite3.c:100667
static const signed char yyRuleInfoNRhs[]
Definition sqlite3.c:157057
SQLITE_PRIVATE void sqlite3BeginTrigger(Parse *, Token *, Token *, int, int, IdList *, SrcList *, Expr *, int, int)
Definition sqlite3.c:136467
SQLITE_PRIVATE int sqlite3JoinType(Parse *, Token *, Token *, Token *)
Definition sqlite3.c:129497
static void parserDoubleLinkSelect(Parse *pParse, Select *p)
Definition sqlite3.c:154321
SQLITE_PRIVATE void sqlite3Analyze(Parse *, Token *, Token *)
Definition sqlite3.c:108955
SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse *, SrcList *, ExprList *)
Definition sqlite3.c:114981
SQLITE_PRIVATE Expr * sqlite3ExprAddCollateToken(Parse *pParse, Expr *, const Token *, int)
Definition sqlite3.c:99798
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse *, Expr *)
Definition sqlite3.c:112008
SQLITE_PRIVATE void sqlite3Vacuum(Parse *, Token *, Expr *)
Definition sqlite3.c:139269
SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p)
Definition sqlite3.c:100458
static const YYCODETYPE yyRuleInfoLhs[]
Definition sqlite3.c:156667
SQLITE_PRIVATE void sqlite3Attach(Parse *, Expr *, Expr *, Expr *)
Definition sqlite3.c:109906
SQLITE_PRIVATE TriggerStep * sqlite3TriggerDeleteStep(Parse *, Token *, Expr *, const char *, const char *)
Definition sqlite3.c:136911
static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op)
Definition sqlite3.c:154379
SQLITE_PRIVATE void sqlite3AddColumn(Parse *, Token *, Token *)
Definition sqlite3.c:111640
SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse *, ExprList *, int, int, int)
Definition sqlite3.c:111933
static void yyStackOverflow(yyParser *yypParser)
Definition sqlite3.c:156583
static Expr * tokenExpr(Parse *pParse, int op, Token t)
Definition sqlite3.c:154344
#define YYNRULE_WITH_ACTION
Definition sqlite3.c:154516
SQLITE_PRIVATE void sqlite3DropTrigger(Parse *, SrcList *, int)
Definition sqlite3.c:136956
Expr * pExpr
Definition sqlite3.c:154282
IdList * b
Definition sqlite3.c:154280
TriggerStep * pLast
Definition sqlite3.c:18946
yyStackEntry * yystackEnd
Definition sqlite3.c:155418
YYMINORTYPE minor
Definition sqlite3.c:155395
Upsert * yy318
Definition sqlite3.c:154494
const char * yy436
Definition sqlite3.c:154495
struct YYMINORTYPE::@126 yy207

References ExprList::a, SrcList::a, TrigEvent::a, Expr::affExpr, ALWAYS, TrigEvent::b, binaryToUnaryIfNull(), Parse::constraintName, Parse::db, disableLookaside(), Window::eFrmType, EP_InfixFunc, EP_Propagate, FrameBound::eType, Parse::explain, SrcList::SrcList_item::fg, Expr::flags, Parse::hasCompound, IN_RENAME_OBJECT, Expr::iTable, SrcList::SrcList_item::jointype, JT_INNER, yyStackEntry::major, YYMINORTYPE::mask, yyStackEntry::minor, Token::n, Parse::nested, ExprList::nExpr, SrcList::nSrc, OE_Abort, OE_Cascade, OE_Default, OE_Fail, OE_Ignore, OE_None, OE_Replace, OE_Restrict, OE_Rollback, OE_SetDflt, OE_SetNull, Expr::op, Select::op, parserAddExprIdListTerm(), parserDoubleLinkSelect(), ExprList::ExprList_item::pExpr, FrameBound::pExpr, Window::pFilter, TriggerStep::pLast, Expr::pList, Parse::pNewIndex, TriggerStep::pNext, Window::pNextWin, Select::pPrior, Select::pWinDefn, Select::pWith, SAVEPOINT_BEGIN, SAVEPOINT_RELEASE, SAVEPOINT_ROLLBACK, Select::selFlags, SF_All, SF_Distinct, SF_MultiValue, SF_NestedFrom, SF_Values, Parse::sLastToken, sqlite3_strnicmp(), sqlite3AddCheckConstraint(), sqlite3AddCollateType(), sqlite3AddColumn(), sqlite3AddDefaultValue(), sqlite3AddGenerated(), sqlite3AddNotNull(), sqlite3AddPrimaryKey(), sqlite3AlterBeginAddColumn(), sqlite3AlterFinishAddColumn(), sqlite3AlterRenameColumn(), sqlite3AlterRenameTable(), sqlite3Analyze(), sqlite3Attach(), sqlite3BeginTransaction(), sqlite3BeginTrigger(), sqlite3CreateForeignKey(), sqlite3CreateIndex(), sqlite3CreateView(), sqlite3DbMallocZero(), sqlite3DbStrNDup(), sqlite3DeferForeignKey(), sqlite3DeleteFrom(), sqlite3Detach(), sqlite3DropIndex(), sqlite3DropTable(), sqlite3DropTrigger(), sqlite3EndTable(), sqlite3EndTransaction(), sqlite3ErrorMsg(), sqlite3Expr(), sqlite3ExprAddCollateToken(), sqlite3ExprAlloc(), sqlite3ExprAnd(), sqlite3ExprAssignVarNumber(), sqlite3ExprAttachSubtrees(), sqlite3ExprDelete(), sqlite3ExprFunction(), sqlite3ExprIdToTrueFalse(), sqlite3ExprIsConstant(), sqlite3ExprListAppend(), sqlite3ExprListAppendVector(), sqlite3ExprListCheckLength(), sqlite3ExprListDelete(), sqlite3ExprListSetName(), sqlite3ExprListSetSortOrder(), sqlite3ExprListSetSpan(), sqlite3ExprSetHeightAndFlags(), sqlite3ExprTruthValue(), sqlite3ExprUnmapAndDelete(), sqlite3FinishCoding(), sqlite3FinishTrigger(), sqlite3GetInt32(), sqlite3IdListAppend(), sqlite3Insert(), sqlite3Isdigit, sqlite3JoinType(), sqlite3NameFromToken(), sqlite3ParserARG_FETCH, sqlite3PExpr(), sqlite3PExprAddSelect(), sqlite3Pragma(), sqlite3Reindex(), sqlite3RenameTokenMap(), sqlite3Savepoint(), sqlite3Select(), sqlite3SelectDelete(), sqlite3SelectNew(), sqlite3SrcListAppend(), sqlite3SrcListAppendFromTerm(), sqlite3SrcListAppendList(), sqlite3SrcListDelete(), sqlite3SrcListFuncArgs(), sqlite3SrcListIndexedBy(), sqlite3SrcListShiftJoinType(), sqlite3StartTable(), sqlite3TriggerDeleteStep(), sqlite3TriggerInsertStep(), sqlite3TriggerSelectStep(), sqlite3TriggerUpdateStep(), sqlite3Update(), sqlite3UpsertNew(), sqlite3Vacuum(), sqlite3VtabArgExtend(), sqlite3VtabArgInit(), sqlite3VtabBeginParse(), sqlite3VtabFinishParse(), sqlite3WindowAlloc(), sqlite3WindowAssemble(), sqlite3WindowAttach(), sqlite3WindowChain(), sqlite3WindowListDelete(), sqlite3WithAdd(), sqlite3WithDelete(), sqlite3WithPush(), SQLITE_IDXTYPE_APPDEF, SQLITE_IDXTYPE_UNIQUE, SQLITE_SO_ASC, SQLITE_SO_DESC, SQLITE_SO_UNDEFINED, SRT_Output, yyStackEntry::stateno, testcase, TF_NoVisibleRowid, TF_WithoutRowid, TK_ALL, TK_ASTERISK, TK_BEFORE, TK_BETWEEN, TK_CASE, TK_CAST, TK_CURRENT, TK_DEFERRED, TK_DOT, TK_EQ, TK_EXISTS, TK_FILTER, TK_ID, TK_IN, TK_INSTEAD, TK_INTEGER, TK_IS, TK_ISNOT, TK_ISNULL, TK_LIMIT, TK_NOT, TK_NOTNULL, TK_PLUS, TK_RAISE, TK_REGISTER, TK_SELECT, TK_STRING, TK_TRUEFALSE, TK_UMINUS, TK_UNBOUNDED, TK_UPDATE, TK_UPLUS, TK_VARIABLE, TK_VECTOR, tokenExpr(), YYMINORTYPE::value, Expr::x, YYMINORTYPE::yy0, YYMINORTYPE::yy131, YYMINORTYPE::yy192, YYMINORTYPE::yy202, YYMINORTYPE::yy207, YYMINORTYPE::yy230, YYMINORTYPE::yy242, YYMINORTYPE::yy303, YYMINORTYPE::yy318, YYMINORTYPE::yy436, YYMINORTYPE::yy447, YYMINORTYPE::yy47, YYMINORTYPE::yy539, YYMINORTYPE::yy58, YYMINORTYPE::yy600, YYMINORTYPE::yy77, YY_ERROR_ACTION, yy_find_reduce_action(), YY_MAX_SHIFT, YY_MAX_SHIFTREDUCE, YYACTIONTYPE, YYCODETYPE, YYNOCODE, YYNRULE_WITH_ACTION, yyRuleInfoLhs, yyRuleInfoNRhs, yyParser::yystack, yyParser::yystackEnd, yyStackOverflow(), yytestcase, yyParser::yytos, yyTraceShift, Token::z, SrcList::SrcList_item::zAlias, Index::zName, SrcList::SrcList_item::zName, and Window::zName.

Referenced by sqlite3Parser().

◆ yy_shift()

static void yy_shift ( yyParser * yypParser,
YYACTIONTYPE yyNewState,
YYCODETYPE yyMajor,
sqlite3ParserTOKENTYPE yyMinor )
static

Definition at line 156626 of file sqlite3.c.

156637 {
156638 yyStackEntry *yytos;
156639 yypParser->yytos++;
156640#ifdef YYTRACKMAXSTACKDEPTH
156641 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
156642 yypParser->yyhwm++;
156643 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
156644 }
156645#endif
156646#if YYSTACKDEPTH>0
156647 if( yypParser->yytos>yypParser->yystackEnd ){
156648 yypParser->yytos--;
156649 yyStackOverflow(yypParser);
156650 return;
156651 }
156652#else
156653 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
156654 if( yyGrowStack(yypParser) ){
156655 yypParser->yytos--;
156656 yyStackOverflow(yypParser);
156657 return;
156658 }
156659 }
156660#endif
156661 if( yyNewState > YY_MAX_SHIFT ){
156662 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
156663 }
#define YY_MIN_SHIFTREDUCE
Definition sqlite3.c:154519

References yyStackEntry::major, yyStackEntry::stateno, YY_MAX_SHIFT, YY_MIN_REDUCE, YY_MIN_SHIFTREDUCE, yyParser::yystack, yyParser::yystackEnd, yyStackOverflow(), and yyParser::yytos.

Referenced by sqlite3Parser().

◆ yy_syntax_error()

static void yy_syntax_error ( yyParser * yypParser,
int yymajor,
sqlite3ParserTOKENTYPE yyminor )
static

Definition at line 159006 of file sqlite3.c.

159016 {
159019#define TOKEN yyminor
159020/************ Begin %syntax_error code ****************************************/
159021
159022 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
159023 if( TOKEN.z[0] ){
159024 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
159025 }else{
#define TOKEN

Referenced by sqlite3Parser().

◆ yyStackOverflow()

static void yyStackOverflow ( yyParser * yypParser)
static

Definition at line 156583 of file sqlite3.c.

156589 {
156592#ifndef NDEBUG
156593 if( yyTraceFILE ){
156594 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
156595 }
156596#endif
156597 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
156598 /* Here code is inserted which will execute if the parser
156599 ** stack every overflows */
156600/******** Begin %stack_overflow code ******************************************/

Referenced by yy_reduce(), and yy_shift().

◆ zeroblobFunc()

static void zeroblobFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 118239 of file sqlite3.c.

118249 {
118250 i64 n;
118251 int rc;
118252 assert( argc==1 );
118253 UNUSED_PARAMETER(argc);
118254 n = sqlite3_value_int64(argv[0]);

Referenced by sqlite3RegisterBuiltinFunctions().

◆ zeroJournalHdr()

static int zeroJournalHdr ( Pager * pPager,
int doTruncate )
static

Definition at line 53086 of file sqlite3.c.

53092 {
53093 int rc = SQLITE_OK; /* Return code */
53094 assert( isOpen(pPager->jfd) );
53095 assert( !sqlite3JournalIsInMemory(pPager->jfd) );
53096 if( pPager->journalOff ){
53097 const i64 iLimit = pPager->journalSizeLimit; /* Local cache of jsl */
53098
53099 IOTRACE(("JZEROHDR %p\n", pPager))
53100 if( doTruncate || iLimit==0 ){
53101 rc = sqlite3OsTruncate(pPager->jfd, 0);
53102 }else{
53103 static const char zeroHdr[28] = {0};
53104 rc = sqlite3OsWrite(pPager->jfd, zeroHdr, sizeof(zeroHdr), 0);
53105 }
53106 if( rc==SQLITE_OK && !pPager->noSync ){
53107 rc = sqlite3OsSync(pPager->jfd, SQLITE_SYNC_DATAONLY|pPager->syncFlags);
53108 }
53109
53110 /* At this point the transaction is committed but the write lock
53111 ** is still held on the file. If there is a size limit configured for
53112 ** the persistent journal and the journal file currently consumes more
53113 ** space than that limit allows for, truncate it now. There is no need
53114 ** to sync the file following this operation.
53115 */
53116 if( rc==SQLITE_OK && iLimit>0 ){
53117 i64 sz;
53118 rc = sqlite3OsFileSize(pPager->jfd, &sz);
53119 if( rc==SQLITE_OK && sz>iLimit ){

References IOTRACE, isOpen, Pager::jfd, Pager::journalOff, Pager::journalSizeLimit, Pager::noSync, sqlite3JournalIsInMemory(), sqlite3OsFileSize(), sqlite3OsSync(), sqlite3OsTruncate(), sqlite3OsWrite(), SQLITE_OK, SQLITE_SYNC_DATAONLY, and Pager::syncFlags.

Referenced by pager_end_transaction().

◆ zeroPage()

static void zeroPage ( MemPage * pPage,
int flags )
static

Definition at line 66521 of file sqlite3.c.

66527 {
66528 unsigned char *data = pPage->aData;
66529 BtShared *pBt = pPage->pBt;
66530 u8 hdr = pPage->hdrOffset;
66531 u16 first;
66532
66533 assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
66534 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
66535 assert( sqlite3PagerGetData(pPage->pDbPage) == data );
66536 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
66537 assert( sqlite3_mutex_held(pBt->mutex) );
66538 if( pBt->btsFlags & BTS_FAST_SECURE ){
66539 memset(&data[hdr], 0, pBt->usableSize - hdr);
66540 }
66541 data[hdr] = (char)flags;
66542 first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
66543 memset(&data[hdr+1], 0, 4);
66544 data[hdr+7] = 0;
66545 put2byte(&data[hdr+5], pBt->usableSize);
66546 pPage->nFree = (u16)(pBt->usableSize - first);
66547 decodeFlags(pPage, flags);
66548 pPage->cellOffset = first;
66549 pPage->aDataEnd = &data[pBt->usableSize];
66550 pPage->aCellIdx = &data[first];
66551 pPage->aDataOfst = &data[pPage->childPtrSize];

Referenced by balance_deeper(), balance_nonroot(), balance_quick(), and newDatabase().

Variable Documentation

◆ aDigits

const char aDigits[] = "0123456789ABCDEF0123456789abcdef"
static

Definition at line 28204 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ aHardLimit

◆ aiClass

const unsigned char aiClass[]
static

Definition at line 159315 of file sqlite3.c.

159321 {
159322#ifdef SQLITE_ASCII
159323/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
159324/* 0x */ 28, 27, 27, 27, 27, 27, 27, 27, 27, 7, 7, 27, 7, 7, 27, 27,
159325/* 1x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
159326/* 2x */ 7, 15, 8, 5, 4, 22, 24, 8, 17, 18, 21, 20, 23, 11, 26, 16,
159327/* 3x */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 19, 12, 14, 13, 6,
159328/* 4x */ 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
159329/* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 9, 27, 27, 27, 1,
159330/* 6x */ 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
159331/* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 27, 10, 27, 25, 27,
159332/* 8x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159333/* 9x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159334/* Ax */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159335/* Bx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159336/* Cx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159337/* Dx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159338/* Ex */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159339/* Fx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
159340#endif
159341#ifdef SQLITE_EBCDIC
159342/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
159343/* 0x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 7, 7, 27, 27,
159344/* 1x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
159345/* 2x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
159346/* 3x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
159347/* 4x */ 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 12, 17, 20, 10,
159348/* 5x */ 24, 27, 27, 27, 27, 27, 27, 27, 27, 27, 15, 4, 21, 18, 19, 27,
159349/* 6x */ 11, 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 23, 22, 1, 13, 6,
159350/* 7x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 8, 5, 5, 5, 8, 14, 8,
159351/* 8x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
159352/* 9x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
159353/* Ax */ 27, 25, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
159354/* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 9, 27, 27, 27, 27, 27,

Referenced by sqlite3GetToken().

◆ aJournalMagic

const unsigned char aJournalMagic[]
static
Initial value:
= {
0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7,
}

Definition at line 52453 of file sqlite3.c.

Referenced by readJournalHdr(), readSuperJournal(), syncJournal(), writeJournalHdr(), and writeSuperJournal().

◆ aKWCode

const unsigned char aKWCode[145]
static

Definition at line 159530 of file sqlite3.c.

159536 {
#define TK_EXCLUDE
Definition sqlite3.c:14033
#define TK_ESCAPE
Definition sqlite3.c:14000
#define TK_WHEN
Definition sqlite3.c:14097
#define TK_GENERATED
Definition sqlite3.c:14037
#define TK_JOIN
Definition sqlite3.c:14083
#define TK_WHERE
Definition sqlite3.c:14089
#define TK_CONSTRAINT
Definition sqlite3.c:14059
#define TK_DROP
Definition sqlite3.c:14073
#define TK_VIRTUAL
Definition sqlite3.c:14022
#define TK_COLUMNKW
Definition sqlite3.c:14002
#define TK_UNIQUE
Definition sqlite3.c:14063
#define TK_AUTOINCR
Definition sqlite3.c:14066
#define TK_EACH
Definition sqlite3.c:13983
#define TK_RENAME
Definition sqlite3.c:14040
#define TK_TRANSACTION
Definition sqlite3.c:13948
#define TK_SET
Definition sqlite3.c:14070
#define TK_FOREIGN
Definition sqlite3.c:14072
#define TK_QUERY
Definition sqlite3.c:13945
#define TK_CREATE
Definition sqlite3.c:13959
#define TK_WITH
Definition sqlite3.c:14023
#define TK_INTO
Definition sqlite3.c:14090
#define TK_PRAGMA
Definition sqlite3.c:14012
#define TK_DATABASE
Definition sqlite3.c:13980
#define TK_REPLACE
Definition sqlite3.c:14015
#define TK_ALWAYS
Definition sqlite3.c:14038
#define TK_INDEX
Definition sqlite3.c:14100
#define TK_ABORT
Definition sqlite3.c:13969
#define TK_CONFLICT
Definition sqlite3.c:13979
#define TK_RECURSIVE
Definition sqlite3.c:14014
#define TK_CTIME_KW
Definition sqlite3.c:14041
#define TK_FOR
Definition sqlite3.c:14004
#define TK_TEMP
Definition sqlite3.c:13963
#define TK_DESC
Definition sqlite3.c:13981
#define TK_DISTINCT
Definition sqlite3.c:14080
#define TK_THEN
Definition sqlite3.c:14098
#define TK_OF
Definition sqlite3.c:14010
#define TK_EXCLUSIVE
Definition sqlite3.c:13951
#define TK_PARTITION
Definition sqlite3.c:14029
#define TK_INDEXED
Definition sqlite3.c:14056
#define TK_NOTHING
Definition sqlite3.c:14091
#define TK_REFERENCES
Definition sqlite3.c:14065
#define TK_LAST
Definition sqlite3.c:14026
#define TK_ATTACH
Definition sqlite3.c:13974
#define TK_HAVING
Definition sqlite3.c:14087
#define TK_SAVEPOINT
Definition sqlite3.c:13955
#define TK_DEFERRABLE
Definition sqlite3.c:14071
#define TK_ELSE
Definition sqlite3.c:14099
#define TK_DETACH
Definition sqlite3.c:13982
#define TK_TO
Definition sqlite3.c:13957
#define TK_IGNORE
Definition sqlite3.c:14005
#define TK_WITHOUT
Definition sqlite3.c:13967
#define TK_ASC
Definition sqlite3.c:13973
#define TK_EXPLAIN
Definition sqlite3.c:13944
#define TK_LIKE_KW
Definition sqlite3.c:13989
#define TK_REINDEX
Definition sqlite3.c:14039
#define TK_CHECK
Definition sqlite3.c:14064
#define TK_OFFSET
Definition sqlite3.c:14011
#define TK_VALUES
Definition sqlite3.c:14079
#define TK_NULLS
Definition sqlite3.c:14024
#define TK_ON
Definition sqlite3.c:14055
#define TK_CASCADE
Definition sqlite3.c:13977
#define TK_ANALYZE
Definition sqlite3.c:13972
#define TK_DEFAULT
Definition sqlite3.c:14060
#define TK_FAIL
Definition sqlite3.c:13984
#define TK_PLAN
Definition sqlite3.c:13946
#define TK_BEGIN
Definition sqlite3.c:13947
#define TK_RELEASE
Definition sqlite3.c:13956
#define TK_ADD
Definition sqlite3.c:14102
#define TK_ACTION
Definition sqlite3.c:13970
#define TK_KEY
Definition sqlite3.c:14009
#define TK_ALTER
Definition sqlite3.c:14101
#define TK_TABLE
Definition sqlite3.c:13958
#define TK_IMMEDIATE
Definition sqlite3.c:13950
#define TK_AFTER
Definition sqlite3.c:13971

◆ aKWHash

const unsigned char aKWHash[127]
static
Initial value:
= {
84, 102, 132, 82, 114, 29, 0, 0, 91, 0, 85, 72, 0,
53, 35, 86, 15, 0, 42, 94, 54, 126, 133, 19, 0, 0,
138, 0, 40, 128, 0, 22, 104, 0, 9, 0, 0, 122, 80,
0, 78, 6, 0, 65, 99, 145, 0, 134, 112, 0, 0, 48,
0, 100, 24, 0, 17, 0, 27, 70, 23, 26, 5, 60, 140,
107, 121, 0, 73, 101, 71, 143, 61, 119, 74, 0, 49, 0,
11, 41, 0, 110, 0, 0, 0, 106, 10, 108, 113, 124, 14,
50, 123, 0, 89, 0, 18, 120, 142, 56, 129, 137, 88, 83,
37, 30, 125, 0, 0, 105, 51, 130, 127, 0, 34, 0, 0,
44, 0, 95, 38, 39, 0, 20, 45, 116, 90,
}

Definition at line 159469 of file sqlite3.c.

159475 {
159476 84, 102, 132, 82, 114, 29, 0, 0, 91, 0, 85, 72, 0,
159477 53, 35, 86, 15, 0, 42, 94, 54, 126, 133, 19, 0, 0,
159478 138, 0, 40, 128, 0, 22, 104, 0, 9, 0, 0, 122, 80,
159479 0, 78, 6, 0, 65, 99, 145, 0, 134, 112, 0, 0, 48,
159480 0, 100, 24, 0, 17, 0, 27, 70, 23, 26, 5, 60, 140,

Referenced by keywordCode().

◆ aKWLen

const unsigned char aKWLen[145]
static
Initial value:
= {
7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 7,
6, 9, 4, 2, 6, 5, 9, 9, 4, 7, 3, 2, 4,
4, 6, 11, 6, 2, 7, 5, 5, 9, 6, 10, 4, 6,
2, 3, 7, 5, 9, 6, 6, 4, 5, 5, 10, 6, 5,
7, 4, 5, 7, 6, 7, 7, 6, 5, 7, 3, 7, 4,
7, 6, 12, 9, 4, 6, 5, 4, 7, 6, 5, 6, 6,
7, 6, 4, 5, 9, 5, 6, 3, 8, 8, 2, 13, 2,
2, 4, 6, 6, 8, 5, 17, 12, 7, 9, 4, 9, 4,
4, 6, 7, 5, 9, 4, 4, 5, 2, 5, 8, 6, 4,
5, 8, 4, 3, 9, 5, 5, 6, 4, 6, 2, 2, 9,
3, 7,
}

Definition at line 159499 of file sqlite3.c.

159505 {
159506 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
159507 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 7,
159508 6, 9, 4, 2, 6, 5, 9, 9, 4, 7, 3, 2, 4,
159509 4, 6, 11, 6, 2, 7, 5, 5, 9, 6, 10, 4, 6,
159510 2, 3, 7, 5, 9, 6, 6, 4, 5, 5, 10, 6, 5,
159511 7, 4, 5, 7, 6, 7, 7, 6, 5, 7, 3, 7, 4,
159512 7, 6, 12, 9, 4, 6, 5, 4, 7, 6, 5, 6, 6,

Referenced by keywordCode().

◆ aKWNext

const unsigned char aKWNext[145]
static
Initial value:
= {
0, 0, 0, 0, 4, 0, 43, 0, 0, 103, 111, 0, 0,
0, 2, 0, 0, 141, 0, 0, 0, 13, 0, 0, 0, 0,
139, 0, 0, 118, 52, 0, 0, 135, 12, 0, 0, 62, 0,
136, 0, 131, 0, 0, 36, 0, 0, 28, 77, 0, 0, 0,
0, 59, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 69, 0, 0, 0, 0, 0, 144, 3, 0, 58, 0, 1,
75, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 64, 66,
63, 0, 0, 0, 0, 46, 0, 16, 0, 115, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 81, 97, 0, 8, 0, 109,
21, 7, 67, 0, 79, 93, 117, 0, 0, 68, 0, 0, 96,
0, 55, 0, 76, 0, 92, 32, 33, 57, 25, 0, 98, 0,
0, 87,
}

Definition at line 159484 of file sqlite3.c.

159490 {
159491 0, 0, 0, 0, 4, 0, 43, 0, 0, 103, 111, 0, 0,
159492 0, 2, 0, 0, 141, 0, 0, 0, 13, 0, 0, 0, 0,
159493 139, 0, 0, 118, 52, 0, 0, 135, 12, 0, 0, 62, 0,
159494 136, 0, 131, 0, 0, 36, 0, 0, 28, 77, 0, 0, 0,
159495 0, 59, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0,
159496 0, 69, 0, 0, 0, 0, 0, 144, 3, 0, 58, 0, 1,
159497 75, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 64, 66,

Referenced by keywordCode().

◆ aKWOffset

const unsigned short int aKWOffset[145]
static
Initial value:
= {
0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
86, 90, 90, 94, 99, 101, 105, 111, 119, 123, 123, 123, 126,
129, 132, 137, 142, 146, 147, 152, 156, 160, 168, 174, 181, 184,
184, 187, 189, 195, 198, 206, 211, 216, 219, 222, 226, 236, 239,
244, 244, 248, 252, 259, 265, 271, 277, 277, 283, 284, 288, 295,
299, 306, 312, 324, 333, 335, 341, 346, 348, 355, 360, 365, 371,
377, 382, 388, 392, 395, 404, 408, 414, 416, 423, 424, 431, 433,
435, 444, 448, 454, 460, 468, 473, 473, 473, 489, 498, 501, 510,
513, 517, 522, 529, 534, 543, 547, 550, 555, 557, 561, 569, 575,
578, 583, 591, 591, 595, 604, 609, 614, 620, 623, 626, 629, 631,
636, 640,
}

Definition at line 159515 of file sqlite3.c.

159521 {
159522 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
159523 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
159524 86, 90, 90, 94, 99, 101, 105, 111, 119, 123, 123, 123, 126,
159525 129, 132, 137, 142, 146, 147, 152, 156, 160, 168, 174, 181, 184,
159526 184, 187, 189, 195, 198, 206, 211, 216, 219, 222, 226, 236, 239,
159527 244, 244, 248, 252, 259, 265, 271, 277, 277, 283, 284, 288, 295,
159528 299, 306, 312, 324, 333, 335, 341, 346, 348, 355, 360, 365, 371,

Referenced by keywordCode().

◆ aPragmaName

const PragmaName aPragmaName[]
static

Definition at line 125254 of file sqlite3.c.

125260 {
125261#if defined(SQLITE_ENABLE_CEROD)
125262 {/* zName: */ "activate_extensions",
125263 /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS,
125264 /* ePragFlg: */ 0,
125265 /* ColNames: */ 0, 0,
125266 /* iArg: */ 0 },
125267#endif
125268 {/* zName: */ "analysis_limit",
125269 /* ePragTyp: */ PragTyp_ANALYSIS_LIMIT,
125270 /* ePragFlg: */ PragFlg_Result0,
125271 /* ColNames: */ 0, 0,
125272 /* iArg: */ 0 },
125273#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
125274 {/* zName: */ "application_id",
125275 /* ePragTyp: */ PragTyp_HEADER_VALUE,
125276 /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0,
125277 /* ColNames: */ 0, 0,
125278 /* iArg: */ BTREE_APPLICATION_ID },
125279#endif
125280#if !defined(SQLITE_OMIT_AUTOVACUUM)
125281 {/* zName: */ "auto_vacuum",
125282 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
125284 /* ColNames: */ 0, 0,
125285 /* iArg: */ 0 },
125286#endif
125287#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125288#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
125289 {/* zName: */ "automatic_index",
125290 /* ePragTyp: */ PragTyp_FLAG,
125291 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125292 /* ColNames: */ 0, 0,
125293 /* iArg: */ SQLITE_AutoIndex },
125294#endif
125295#endif
125296 {/* zName: */ "busy_timeout",
125297 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
125298 /* ePragFlg: */ PragFlg_Result0,
125299 /* ColNames: */ 50, 1,
125300 /* iArg: */ 0 },
125301#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125302 {/* zName: */ "cache_size",
125303 /* ePragTyp: */ PragTyp_CACHE_SIZE,
125305 /* ColNames: */ 0, 0,
125306 /* iArg: */ 0 },
125307#endif
125308#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125309 {/* zName: */ "cache_spill",
125310 /* ePragTyp: */ PragTyp_CACHE_SPILL,
125312 /* ColNames: */ 0, 0,
125313 /* iArg: */ 0 },
125314#endif
125315#if !defined(SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA)
125316 {/* zName: */ "case_sensitive_like",
125317 /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
125318 /* ePragFlg: */ PragFlg_NoColumns,
125319 /* ColNames: */ 0, 0,
125320 /* iArg: */ 0 },
125321#endif
125322 {/* zName: */ "cell_size_check",
125323 /* ePragTyp: */ PragTyp_FLAG,
125324 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125325 /* ColNames: */ 0, 0,
125326 /* iArg: */ SQLITE_CellSizeCk },
125327#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125328 {/* zName: */ "checkpoint_fullfsync",
125329 /* ePragTyp: */ PragTyp_FLAG,
125330 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125331 /* ColNames: */ 0, 0,
125332 /* iArg: */ SQLITE_CkptFullFSync },
125333#endif
125334#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
125335 {/* zName: */ "collation_list",
125336 /* ePragTyp: */ PragTyp_COLLATION_LIST,
125337 /* ePragFlg: */ PragFlg_Result0,
125338 /* ColNames: */ 32, 2,
125339 /* iArg: */ 0 },
125340#endif
125341#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
125342 {/* zName: */ "compile_options",
125343 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
125344 /* ePragFlg: */ PragFlg_Result0,
125345 /* ColNames: */ 0, 0,
125346 /* iArg: */ 0 },
125347#endif
125348#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125349 {/* zName: */ "count_changes",
125350 /* ePragTyp: */ PragTyp_FLAG,
125351 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125352 /* ColNames: */ 0, 0,
125353 /* iArg: */ SQLITE_CountRows },
125354#endif
125355#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
125356 {/* zName: */ "data_store_directory",
125357 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
125358 /* ePragFlg: */ PragFlg_NoColumns1,
125359 /* ColNames: */ 0, 0,
125360 /* iArg: */ 0 },
125361#endif
125362#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
125363 {/* zName: */ "data_version",
125364 /* ePragTyp: */ PragTyp_HEADER_VALUE,
125365 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
125366 /* ColNames: */ 0, 0,
125367 /* iArg: */ BTREE_DATA_VERSION },
125368#endif
125369#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
125370 {/* zName: */ "database_list",
125371 /* ePragTyp: */ PragTyp_DATABASE_LIST,
125372 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
125373 /* ColNames: */ 41, 3,
125374 /* iArg: */ 0 },
125375#endif
125376#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
125377 {/* zName: */ "default_cache_size",
125378 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
125380 /* ColNames: */ 49, 1,
125381 /* iArg: */ 0 },
125382#endif
125383#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125384#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
125385 {/* zName: */ "defer_foreign_keys",
125386 /* ePragTyp: */ PragTyp_FLAG,
125387 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125388 /* ColNames: */ 0, 0,
125389 /* iArg: */ SQLITE_DeferFKs },
125390#endif
125391#endif
125392#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125393 {/* zName: */ "empty_result_callbacks",
125394 /* ePragTyp: */ PragTyp_FLAG,
125395 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125396 /* ColNames: */ 0, 0,
125397 /* iArg: */ SQLITE_NullCallback },
125398#endif
125399#if !defined(SQLITE_OMIT_UTF16)
125400 {/* zName: */ "encoding",
125401 /* ePragTyp: */ PragTyp_ENCODING,
125402 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125403 /* ColNames: */ 0, 0,
125404 /* iArg: */ 0 },
125405#endif
125406#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
125407 {/* zName: */ "foreign_key_check",
125408 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
125410 /* ColNames: */ 37, 4,
125411 /* iArg: */ 0 },
125412#endif
125413#if !defined(SQLITE_OMIT_FOREIGN_KEY)
125414 {/* zName: */ "foreign_key_list",
125415 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
125417 /* ColNames: */ 0, 8,
125418 /* iArg: */ 0 },
125419#endif
125420#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125421#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
125422 {/* zName: */ "foreign_keys",
125423 /* ePragTyp: */ PragTyp_FLAG,
125424 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125425 /* ColNames: */ 0, 0,
125426 /* iArg: */ SQLITE_ForeignKeys },
125427#endif
125428#endif
125429#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
125430 {/* zName: */ "freelist_count",
125431 /* ePragTyp: */ PragTyp_HEADER_VALUE,
125432 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
125433 /* ColNames: */ 0, 0,
125434 /* iArg: */ BTREE_FREE_PAGE_COUNT },
125435#endif
125436#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125437 {/* zName: */ "full_column_names",
125438 /* ePragTyp: */ PragTyp_FLAG,
125439 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125440 /* ColNames: */ 0, 0,
125441 /* iArg: */ SQLITE_FullColNames },
125442 {/* zName: */ "fullfsync",
125443 /* ePragTyp: */ PragTyp_FLAG,
125444 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125445 /* ColNames: */ 0, 0,
125446 /* iArg: */ SQLITE_FullFSync },
125447#endif
125448#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
125449#if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
125450 {/* zName: */ "function_list",
125451 /* ePragTyp: */ PragTyp_FUNCTION_LIST,
125452 /* ePragFlg: */ PragFlg_Result0,
125453 /* ColNames: */ 21, 6,
125454 /* iArg: */ 0 },
125455#endif
125456#endif
125457 {/* zName: */ "hard_heap_limit",
125458 /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
125459 /* ePragFlg: */ PragFlg_Result0,
125460 /* ColNames: */ 0, 0,
125461 /* iArg: */ 0 },
125462#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125463#if !defined(SQLITE_OMIT_CHECK)
125464 {/* zName: */ "ignore_check_constraints",
125465 /* ePragTyp: */ PragTyp_FLAG,
125466 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125467 /* ColNames: */ 0, 0,
125468 /* iArg: */ SQLITE_IgnoreChecks },
125469#endif
125470#endif
125471#if !defined(SQLITE_OMIT_AUTOVACUUM)
125472 {/* zName: */ "incremental_vacuum",
125473 /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
125474 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_NoColumns,
125475 /* ColNames: */ 0, 0,
125476 /* iArg: */ 0 },
125477#endif
125478#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
125479 {/* zName: */ "index_info",
125480 /* ePragTyp: */ PragTyp_INDEX_INFO,
125482 /* ColNames: */ 15, 3,
125483 /* iArg: */ 0 },
125484 {/* zName: */ "index_list",
125485 /* ePragTyp: */ PragTyp_INDEX_LIST,
125487 /* ColNames: */ 32, 5,
125488 /* iArg: */ 0 },
125489 {/* zName: */ "index_xinfo",
125490 /* ePragTyp: */ PragTyp_INDEX_INFO,
125492 /* ColNames: */ 15, 6,
125493 /* iArg: */ 1 },
125494#endif
125495#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
125496 {/* zName: */ "integrity_check",
125497 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
125499 /* ColNames: */ 0, 0,
125500 /* iArg: */ 0 },
125501#endif
125502#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125503 {/* zName: */ "journal_mode",
125504 /* ePragTyp: */ PragTyp_JOURNAL_MODE,
125506 /* ColNames: */ 0, 0,
125507 /* iArg: */ 0 },
125508 {/* zName: */ "journal_size_limit",
125509 /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT,
125510 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
125511 /* ColNames: */ 0, 0,
125512 /* iArg: */ 0 },
125513#endif
125514#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125515 {/* zName: */ "legacy_alter_table",
125516 /* ePragTyp: */ PragTyp_FLAG,
125517 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125518 /* ColNames: */ 0, 0,
125519 /* iArg: */ SQLITE_LegacyAlter },
125520#endif
125521#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
125522 {/* zName: */ "lock_proxy_file",
125523 /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
125524 /* ePragFlg: */ PragFlg_NoColumns1,
125525 /* ColNames: */ 0, 0,
125526 /* iArg: */ 0 },
125527#endif
125528#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
125529 {/* zName: */ "lock_status",
125530 /* ePragTyp: */ PragTyp_LOCK_STATUS,
125531 /* ePragFlg: */ PragFlg_Result0,
125532 /* ColNames: */ 47, 2,
125533 /* iArg: */ 0 },
125534#endif
125535#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125536 {/* zName: */ "locking_mode",
125537 /* ePragTyp: */ PragTyp_LOCKING_MODE,
125538 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
125539 /* ColNames: */ 0, 0,
125540 /* iArg: */ 0 },
125541 {/* zName: */ "max_page_count",
125542 /* ePragTyp: */ PragTyp_PAGE_COUNT,
125544 /* ColNames: */ 0, 0,
125545 /* iArg: */ 0 },
125546 {/* zName: */ "mmap_size",
125547 /* ePragTyp: */ PragTyp_MMAP_SIZE,
125548 /* ePragFlg: */ 0,
125549 /* ColNames: */ 0, 0,
125550 /* iArg: */ 0 },
125551#endif
125552#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
125553#if !defined(SQLITE_OMIT_VIRTUALTABLE)
125554#if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
125555 {/* zName: */ "module_list",
125556 /* ePragTyp: */ PragTyp_MODULE_LIST,
125557 /* ePragFlg: */ PragFlg_Result0,
125558 /* ColNames: */ 9, 1,
125559 /* iArg: */ 0 },
125560#endif
125561#endif
125562#endif
125563 {/* zName: */ "optimize",
125564 /* ePragTyp: */ PragTyp_OPTIMIZE,
125565 /* ePragFlg: */ PragFlg_Result1|PragFlg_NeedSchema,
125566 /* ColNames: */ 0, 0,
125567 /* iArg: */ 0 },
125568#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125569 {/* zName: */ "page_count",
125570 /* ePragTyp: */ PragTyp_PAGE_COUNT,
125572 /* ColNames: */ 0, 0,
125573 /* iArg: */ 0 },
125574 {/* zName: */ "page_size",
125575 /* ePragTyp: */ PragTyp_PAGE_SIZE,
125577 /* ColNames: */ 0, 0,
125578 /* iArg: */ 0 },
125579#endif
125580#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125581#if defined(SQLITE_DEBUG)
125582 {/* zName: */ "parser_trace",
125583 /* ePragTyp: */ PragTyp_FLAG,
125584 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125585 /* ColNames: */ 0, 0,
125586 /* iArg: */ SQLITE_ParserTrace },
125587#endif
125588#endif
125589#if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
125590 {/* zName: */ "pragma_list",
125591 /* ePragTyp: */ PragTyp_PRAGMA_LIST,
125592 /* ePragFlg: */ PragFlg_Result0,
125593 /* ColNames: */ 9, 1,
125594 /* iArg: */ 0 },
125595#endif
125596#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125597 {/* zName: */ "query_only",
125598 /* ePragTyp: */ PragTyp_FLAG,
125599 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125600 /* ColNames: */ 0, 0,
125601 /* iArg: */ SQLITE_QueryOnly },
125602#endif
125603#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
125604 {/* zName: */ "quick_check",
125605 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
125607 /* ColNames: */ 0, 0,
125608 /* iArg: */ 0 },
125609#endif
125610#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125611 {/* zName: */ "read_uncommitted",
125612 /* ePragTyp: */ PragTyp_FLAG,
125613 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125614 /* ColNames: */ 0, 0,
125615 /* iArg: */ SQLITE_ReadUncommit },
125616 {/* zName: */ "recursive_triggers",
125617 /* ePragTyp: */ PragTyp_FLAG,
125618 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125619 /* ColNames: */ 0, 0,
125620 /* iArg: */ SQLITE_RecTriggers },
125621 {/* zName: */ "reverse_unordered_selects",
125622 /* ePragTyp: */ PragTyp_FLAG,
125623 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125624 /* ColNames: */ 0, 0,
125625 /* iArg: */ SQLITE_ReverseOrder },
125626#endif
125627#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
125628 {/* zName: */ "schema_version",
125629 /* ePragTyp: */ PragTyp_HEADER_VALUE,
125630 /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0,
125631 /* ColNames: */ 0, 0,
125632 /* iArg: */ BTREE_SCHEMA_VERSION },
125633#endif
125634#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125635 {/* zName: */ "secure_delete",
125636 /* ePragTyp: */ PragTyp_SECURE_DELETE,
125637 /* ePragFlg: */ PragFlg_Result0,
125638 /* ColNames: */ 0, 0,
125639 /* iArg: */ 0 },
125640#endif
125641#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125642 {/* zName: */ "short_column_names",
125643 /* ePragTyp: */ PragTyp_FLAG,
125644 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125645 /* ColNames: */ 0, 0,
125646 /* iArg: */ SQLITE_ShortColNames },
125647#endif
125648 {/* zName: */ "shrink_memory",
125649 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
125650 /* ePragFlg: */ PragFlg_NoColumns,
125651 /* ColNames: */ 0, 0,
125652 /* iArg: */ 0 },
125653 {/* zName: */ "soft_heap_limit",
125654 /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
125655 /* ePragFlg: */ PragFlg_Result0,
125656 /* ColNames: */ 0, 0,
125657 /* iArg: */ 0 },
125658#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125659#if defined(SQLITE_DEBUG)
125660 {/* zName: */ "sql_trace",
125661 /* ePragTyp: */ PragTyp_FLAG,
125662 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125663 /* ColNames: */ 0, 0,
125664 /* iArg: */ SQLITE_SqlTrace },
125665#endif
125666#endif
125667#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
125668 {/* zName: */ "stats",
125669 /* ePragTyp: */ PragTyp_STATS,
125671 /* ColNames: */ 27, 5,
125672 /* iArg: */ 0 },
125673#endif
125674#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125675 {/* zName: */ "synchronous",
125676 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
125678 /* ColNames: */ 0, 0,
125679 /* iArg: */ 0 },
125680#endif
125681#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
125682 {/* zName: */ "table_info",
125683 /* ePragTyp: */ PragTyp_TABLE_INFO,
125685 /* ColNames: */ 8, 6,
125686 /* iArg: */ 0 },
125687 {/* zName: */ "table_xinfo",
125688 /* ePragTyp: */ PragTyp_TABLE_INFO,
125690 /* ColNames: */ 8, 7,
125691 /* iArg: */ 1 },
125692#endif
125693#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
125694 {/* zName: */ "temp_store",
125695 /* ePragTyp: */ PragTyp_TEMP_STORE,
125696 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125697 /* ColNames: */ 0, 0,
125698 /* iArg: */ 0 },
125699 {/* zName: */ "temp_store_directory",
125700 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
125701 /* ePragFlg: */ PragFlg_NoColumns1,
125702 /* ColNames: */ 0, 0,
125703 /* iArg: */ 0 },
125704#endif
125705 {/* zName: */ "threads",
125706 /* ePragTyp: */ PragTyp_THREADS,
125707 /* ePragFlg: */ PragFlg_Result0,
125708 /* ColNames: */ 0, 0,
125709 /* iArg: */ 0 },
125710#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125711 {/* zName: */ "trusted_schema",
125712 /* ePragTyp: */ PragTyp_FLAG,
125713 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125714 /* ColNames: */ 0, 0,
125715 /* iArg: */ SQLITE_TrustedSchema },
125716#endif
125717#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
125718 {/* zName: */ "user_version",
125719 /* ePragTyp: */ PragTyp_HEADER_VALUE,
125720 /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0,
125721 /* ColNames: */ 0, 0,
125722 /* iArg: */ BTREE_USER_VERSION },
125723#endif
125724#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125725#if defined(SQLITE_DEBUG)
125726 {/* zName: */ "vdbe_addoptrace",
125727 /* ePragTyp: */ PragTyp_FLAG,
125728 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125729 /* ColNames: */ 0, 0,
125730 /* iArg: */ SQLITE_VdbeAddopTrace },
125731 {/* zName: */ "vdbe_debug",
125732 /* ePragTyp: */ PragTyp_FLAG,
125733 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125734 /* ColNames: */ 0, 0,
125735 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
125736 {/* zName: */ "vdbe_eqp",
125737 /* ePragTyp: */ PragTyp_FLAG,
125738 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125739 /* ColNames: */ 0, 0,
125740 /* iArg: */ SQLITE_VdbeEQP },
125741 {/* zName: */ "vdbe_listing",
125742 /* ePragTyp: */ PragTyp_FLAG,
125743 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125744 /* ColNames: */ 0, 0,
125745 /* iArg: */ SQLITE_VdbeListing },
125746 {/* zName: */ "vdbe_trace",
125747 /* ePragTyp: */ PragTyp_FLAG,
125748 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
125749 /* ColNames: */ 0, 0,
125750 /* iArg: */ SQLITE_VdbeTrace },
125751#endif
125752#endif
125753#if !defined(SQLITE_OMIT_WAL)
125754 {/* zName: */ "wal_autocheckpoint",
125755 /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
125756 /* ePragFlg: */ 0,
125757 /* ColNames: */ 0, 0,
125758 /* iArg: */ 0 },
125759 {/* zName: */ "wal_checkpoint",
125760 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
125761 /* ePragFlg: */ PragFlg_NeedSchema,
125762 /* ColNames: */ 44, 3,
125763 /* iArg: */ 0 },
125764#endif
125765#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
125766 {/* zName: */ "writable_schema",
#define BTREE_FREE_PAGE_COUNT
Definition sqlite3.c:15141
#define PragFlg_Result0
Definition sqlite3.c:125178

Referenced by sqlite3Pragma().

◆ aPrefix

const char aPrefix[] = "-x0\000X0"
static

Definition at line 28205 of file sqlite3.c.

Referenced by sqlite3_str_vappendf().

◆ arRound

const double arRound[]
static
Initial value:
= {
5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10,
}

Definition at line 28237 of file sqlite3.c.

28237 { 'T', 0, 0, etTOKEN, 0, 0 },
28238 { 'S', 0, 0, etSRCLIST, 0, 0 },
28239 { 'r', 10, 1, etORDINAL, 0, 0 },
28240};

Referenced by sqlite3_str_vappendf().

◆ aSyscall

◆ [struct]

const struct { ... } aXformType[]
Initial value:
= {
{ 0, 6, "second", 464269060800.0, 1000.0 },
{ 0, 6, "minute", 7737817680.0, 60000.0 },
{ 0, 4, "hour", 128963628.0, 3600000.0 },
{ 0, 3, "day", 5373485.0, 86400000.0 },
{ 1, 5, "month", 176546.0, 2592000000.0 },
{ 2, 4, "year", 14713.0, 31536000000.0 },
}

Referenced by parseModifier().

◆ cume_distName

const char cume_distName[] = "cume_dist"
static

Definition at line 151711 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ dense_rankName

const char dense_rankName[] = "dense_rank"
static

Definition at line 151708 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ eType

◆ first_valueName

const char first_valueName[] = "first_value"
static

◆ fmtinfo

const et_info fmtinfo[]
static
Initial value:
= {
{ 'd', 10, 1, etDECIMAL, 0, 0 },
{ 's', 0, 4, etSTRING, 0, 0 },
{ 'g', 0, 1, etGENERIC, 30, 0 },
{ 'z', 0, 4, etDYNSTRING, 0, 0 },
{ 'q', 0, 4, etSQLESCAPE, 0, 0 },
{ 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
{ 'w', 0, 4, etSQLESCAPE3, 0, 0 },
{ 'c', 0, 0, etCHARX, 0, 0 },
{ 'o', 8, 0, etRADIX, 0, 2 },
{ 'u', 10, 0, etDECIMAL, 0, 0 },
{ 'x', 16, 0, etRADIX, 16, 1 },
{ 'X', 16, 0, etRADIX, 0, 4 },
{ 'f', 0, 1, etFLOAT, 0, 0 },
{ 'e', 0, 1, etEXP, 30, 0 },
{ 'E', 0, 1, etEXP, 14, 0 },
{ 'G', 0, 1, etGENERIC, 14, 0 },
{ 'i', 10, 1, etDECIMAL, 0, 0 },
{ 'n', 0, 0, etSIZE, 0, 0 },
{ '%', 0, 0, etPERCENT, 0, 0 },
{ 'p', 16, 0, etPOINTER, 0, 1 },
{ 'T', 0, 0, etTOKEN, 0, 0 },
{ 'S', 0, 0, etSRCLIST, 0, 0 },
{ 'r', 10, 1, etORDINAL, 0, 0 },
}

Definition at line 28206 of file sqlite3.c.

28212 {
28213 { 'd', 10, 1, etDECIMAL, 0, 0 },
28214 { 's', 0, 4, etSTRING, 0, 0 },
28215 { 'g', 0, 1, etGENERIC, 30, 0 },
28216 { 'z', 0, 4, etDYNSTRING, 0, 0 },
28217 { 'q', 0, 4, etSQLESCAPE, 0, 0 },
28218 { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
28219 { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
28220 { 'c', 0, 0, etCHARX, 0, 0 },
28221 { 'o', 8, 0, etRADIX, 0, 2 },
28222 { 'u', 10, 0, etDECIMAL, 0, 0 },
28223 { 'x', 16, 0, etRADIX, 16, 1 },
28224 { 'X', 16, 0, etRADIX, 0, 4 },
28225#ifndef SQLITE_OMIT_FLOATING_POINT
28226 { 'f', 0, 1, etFLOAT, 0, 0 },
28227 { 'e', 0, 1, etEXP, 30, 0 },
28228 { 'E', 0, 1, etEXP, 14, 0 },
28229 { 'G', 0, 1, etGENERIC, 14, 0 },
28230#endif
28231 { 'i', 10, 1, etDECIMAL, 0, 0 },
28232 { 'n', 0, 0, etSIZE, 0, 0 },
28233 { '%', 0, 0, etPERCENT, 0, 0 },
28234 { 'p', 16, 0, etPOINTER, 0, 1 },

Referenced by sqlite3_str_vappendf().

◆ globInfo

const struct compareInfo globInfo = { '*', '?', '[', 0 }
static

Definition at line 117671 of file sqlite3.c.

Referenced by sqlite3RegisterBuiltinFunctions().

◆ hexdigits

const char hexdigits[]
static
Initial value:
= {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
}

Definition at line 118067 of file sqlite3.c.

Referenced by quoteFunc().

◆ inodeList

unixInodeInfo* inodeList = 0
static

Definition at line 34728 of file sqlite3.c.

Referenced by findInodeInfo(), findReusableFd(), and releaseInodeInfo().

◆ lagName

const char lagName[] = "lag"
static

Definition at line 151717 of file sqlite3.c.

Referenced by sqlite3WindowCodeInit(), sqlite3WindowUpdate(), and windowReturnOneRow().

◆ last_valueName

const char last_valueName[] = "last_value"
static

Definition at line 151713 of file sqlite3.c.

◆ leadName

const char leadName[] = "lead"
static

Definition at line 151716 of file sqlite3.c.

Referenced by sqlite3WindowCodeInit(), sqlite3WindowUpdate(), and windowReturnOneRow().

◆ likeInfoAlt

const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }
static

Definition at line 117677 of file sqlite3.c.

117677{ '*', '?', '[', 0 };

Referenced by sqlite3IsLikeFunction(), sqlite3RegisterBuiltinFunctions(), and sqlite3RegisterLikeFunctions().

◆ likeInfoNorm

const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 }
static

Definition at line 117674 of file sqlite3.c.

117674:sqlite3Utf8Read(&A))

Referenced by sqlite3RegisterBuiltinFunctions(), and sqlite3RegisterLikeFunctions().

◆ mem0

SQLITE_WSD struct Mem0Global mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 }
static

◆ MemJournalMethods

const struct sqlite3_io_methods MemJournalMethods
static
Initial value:
= {
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}
static int memjrnlClose(sqlite3_file *pJfd)
Definition sqlite3.c:97349
static int memjrnlRead(sqlite3_file *pJfd, void *zBuf, int iAmt, sqlite_int64 iOfst)
Definition sqlite3.c:97155
static int memjrnlSync(sqlite3_file *pJfd, int flags)
Definition sqlite3.c:97361
static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size)
Definition sqlite3.c:97333
static int memjrnlWrite(sqlite3_file *pJfd, const void *zBuf, int iAmt, sqlite_int64 iOfst)
Definition sqlite3.c:97254
static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize)
Definition sqlite3.c:97369

Definition at line 97378 of file sqlite3.c.

97384 {
97385 1, /* iVersion */
97386 memjrnlClose, /* xClose */
97387 memjrnlRead, /* xRead */
97388 memjrnlWrite, /* xWrite */
97389 memjrnlTruncate, /* xTruncate */
97390 memjrnlSync, /* xSync */
97391 memjrnlFileSize, /* xFileSize */
97392 0, /* xLock */
97393 0, /* xUnlock */
97394 0, /* xCheckReservedLock */
97395 0, /* xFileControl */
97396 0, /* xSectorSize */
97397 0, /* xDeviceCharacteristics */
97398 0, /* xShmMap */

Referenced by sqlite3JournalIsInMemory(), and sqlite3JournalOpen().

◆ nName

◆ nth_valueName

const char nth_valueName[] = "nth_value"
static

◆ ntileName

const char ntileName[] = "ntile"
static

Definition at line 151712 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ pcache1_g

SQLITE_WSD struct PCacheGlobal pcache1_g
static

◆ percent_rankName

const char percent_rankName[] = "percent_rank"
static

Definition at line 151710 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ pragCName

const char* const pragCName[]
static

Definition at line 125187 of file sqlite3.c.

125193 {
125194 /* 0 */ "id", /* Used by: foreign_key_list */
125195 /* 1 */ "seq",
125196 /* 2 */ "table",
125197 /* 3 */ "from",
125198 /* 4 */ "to",
125199 /* 5 */ "on_update",
125200 /* 6 */ "on_delete",
125201 /* 7 */ "match",
125202 /* 8 */ "cid", /* Used by: table_xinfo */
125203 /* 9 */ "name",
125204 /* 10 */ "type",
125205 /* 11 */ "notnull",
125206 /* 12 */ "dflt_value",
125207 /* 13 */ "pk",
125208 /* 14 */ "hidden",
125209 /* table_info reuses 8 */
125210 /* 15 */ "seqno", /* Used by: index_xinfo */
125211 /* 16 */ "cid",
125212 /* 17 */ "name",
125213 /* 18 */ "desc",
125214 /* 19 */ "coll",
125215 /* 20 */ "key",
125216 /* 21 */ "name", /* Used by: function_list */
125217 /* 22 */ "builtin",
125218 /* 23 */ "type",
125219 /* 24 */ "enc",
125220 /* 25 */ "narg",
125221 /* 26 */ "flags",
125222 /* 27 */ "tbl", /* Used by: stats */
125223 /* 28 */ "idx",
125224 /* 29 */ "wdth",
125225 /* 30 */ "hght",
125226 /* 31 */ "flgs",
125227 /* 32 */ "seq", /* Used by: index_list */
125228 /* 33 */ "name",
125229 /* 34 */ "unique",
125230 /* 35 */ "origin",
125231 /* 36 */ "partial",
125232 /* 37 */ "table", /* Used by: foreign_key_check */
125233 /* 38 */ "rowid",
125234 /* 39 */ "parent",
125235 /* 40 */ "fkid",
125236 /* index_info reuses 15 */
125237 /* 41 */ "seq", /* Used by: database_list */
125238 /* 42 */ "name",
125239 /* 43 */ "file",
125240 /* 44 */ "busy", /* Used by: wal_checkpoint */
125241 /* 45 */ "log",
125242 /* 46 */ "checkpointed",
125243 /* collation_list reuses 32 */

◆ pragmaVtabModule

const sqlite3_module pragmaVtabModule
static
Initial value:
= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}
static int pragmaVtabDisconnect(sqlite3_vtab *pVtab)
Definition sqlite3.c:128105
static int pragmaVtabConnect(sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
Definition sqlite3.c:128043
static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
Definition sqlite3.c:128118
static int pragmaVtabClose(sqlite3_vtab_cursor *cur)
Definition sqlite3.c:128177
static int pragmaVtabColumn(sqlite3_vtab_cursor *pVtabCursor, sqlite3_context *ctx, int i)
Definition sqlite3.c:128261
static int pragmaVtabNext(sqlite3_vtab_cursor *pVtabCursor)
Definition sqlite3.c:128185
static int pragmaVtabRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *p)
Definition sqlite3.c:128279
static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor)
Definition sqlite3.c:128155
static int pragmaVtabFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
Definition sqlite3.c:128203
static int pragmaVtabEof(sqlite3_vtab_cursor *pVtabCursor)
Definition sqlite3.c:128253

Definition at line 128286 of file sqlite3.c.

128292 {
128293 0, /* iVersion */
128294 0, /* xCreate - create a table */
128295 pragmaVtabConnect, /* xConnect - connect to an existing table */
128296 pragmaVtabBestIndex, /* xBestIndex - Determine search strategy */
128297 pragmaVtabDisconnect, /* xDisconnect - Disconnect from a table */
128298 0, /* xDestroy - Drop a table */
128299 pragmaVtabOpen, /* xOpen - open a cursor */
128300 pragmaVtabClose, /* xClose - close a cursor */
128301 pragmaVtabFilter, /* xFilter - configure scan constraints */
128302 pragmaVtabNext, /* xNext - advance a cursor */
128303 pragmaVtabEof, /* xEof */
128304 pragmaVtabColumn, /* xColumn - read data */
128305 pragmaVtabRowid, /* xRowid - read data */
128306 0, /* xUpdate - write data */
128307 0, /* xBegin - begin transaction */
128308 0, /* xSync - sync transaction */
128309 0, /* xCommit - commit transaction */
128310 0, /* xRollback - rollback transaction */
128311 0, /* xFindFunction - function overloading */

Referenced by sqlite3PragmaVtabRegister().

◆ randomnessPid

pid_t randomnessPid = 0
static

Definition at line 33622 of file sqlite3.c.

Referenced by unixOpen(), and unixRandomness().

◆ rankName

const char rankName[] = "rank"
static

Definition at line 151709 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ rLimit

double rLimit

Definition at line 22330 of file sqlite3.c.

◆ row_numberName

const char row_numberName[] = "row_number"
static

Definition at line 151707 of file sqlite3.c.

Referenced by sqlite3WindowUpdate().

◆ rXform

double rXform

Definition at line 22331 of file sqlite3.c.

Referenced by parseModifier().

◆ sqlite3_data_directory

SQLITE_API char * sqlite3_data_directory = 0

Definition at line 7121 of file sqlite3.c.

Referenced by sqlite3_shutdown(), and sqlite3Pragma().

◆ sqlite3_temp_directory

SQLITE_API char * sqlite3_temp_directory = 0

Definition at line 7084 of file sqlite3.c.

Referenced by lsqlite_temp_directory(), sqlite3_shutdown(), and sqlite3Pragma().

◆ sqlite3_unsupported_selecttrace

SQLITE_API u32 sqlite3_unsupported_selecttrace = 0

Definition at line 20669 of file sqlite3.c.

Referenced by flattenSubquery(), havingToWhere(), and sqlite3Select().

◆ sqlite3_version

SQLITE_API const char sqlite3_version[] = SQLITE_VERSION

Definition at line 1210 of file sqlite3.c.

Referenced by sqlite3_libversion().

◆ sqlite3Apis

const sqlite3_api_routines sqlite3Apis
static

Definition at line 124365 of file sqlite3.c.

124371 {
124373#ifndef SQLITE_OMIT_DEPRECATED
124375#else
124376 0,
124377#endif
124431 sqlite3_exec,
124432#ifndef SQLITE_OMIT_DEPRECATED
124434#else
124435 0,
124436#endif
124438 sqlite3_free,
124443 0, /* Was sqlite3_global_recover(), but that function is deprecated */
124450 sqlite3_open,
124474 sqlite3_step,
124476#ifndef SQLITE_OMIT_DEPRECATED
124478#else
124479 0,
124480#endif
124483#ifndef SQLITE_OMIT_DEPRECATED
124485#else
124486 0,
124487#endif
124503 /*
124504 ** The original API set ends here. All extensions can call any
124505 ** of the APIs above provided that the pointer is not NULL. But
124506 ** before calling APIs that follow, extension should check the
124507 ** sqlite3_libversion_number() to make sure they are dealing with
124508 ** a library that is new enough to support that API.
124509 *************************************************************************
124510 */
124512
124513 /*
124514 ** Added after 3.3.13
124515 */
124519
124520 /*
124521 ** Added for 3.4.1
124522 */
124524
124525 /*
124526 ** Added for 3.5.0
124527 */
124538#ifdef SQLITE_MUTEX_OMIT
124539 0,
124540 0,
124541 0,
124542 0,
124543 0,
124544#else
124550#endif
124560
124561 /*
124562 ** Added for 3.5.8
124563 */
124570
124571 /*
124572 ** Added for 3.6.0
124573 */
124577 sqlite3_sql,
124579
124580 /*
124581 ** Added for 3.7.4
124582 */
124588#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
124591#else
124592 0,
124593 0,
124594#endif
124600 sqlite3_log,
124605#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
124607#else
124608 0,
124609#endif
124610#ifndef SQLITE_OMIT_WAL
124614#else
124615 0,
124616 0,
124617 0,
124618#endif
124635 /* Version 3.8.7 and later */
124648 /* Version 3.8.11 and later */
124653 /* Version 3.9.0 and later */
124656 /* Version 3.10.0 and later */
124660 /* Version 3.12.0 and later */
124662 /* Version 3.14.0 and later */
124665 /* Version 3.18.0 and later */
124667 /* Version 3.20.0 and later */
124673 /* Version 3.22.0 and later */
124677 /* Version 3.24.0 and later */
124692 /* Version 3.25.0 and later */
124694 /* Version 3.26.0 and later */
124695#ifdef SQLITE_ENABLE_NORMALIZE
124697#else
124698 0,
124699#endif
124700 /* Version 3.28.0 and later */
124703 /* Version 3.30.0 and later */
124704#ifndef SQLITE_OMIT_VIRTUALTABLE
124706#else
124707 0,
124708#endif
124709 /* Version 3.31.0 and later */
SQLITE_API int sqlite3_column_bytes(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84101
SQLITE_API sqlite3 * sqlite3_db_handle(sqlite3_stmt *)
Definition sqlite3.c:84646
SQLITE_API int sqlite3_prepare_v3(sqlite3 *db, const char *zSql, int nByte, unsigned int prepFlags, sqlite3_stmt **ppStmt, const char **pzTail)
Definition sqlite3.c:129164
SQLITE_API int sqlite3_overload_function(sqlite3 *, const char *zFuncName, int nArg)
Definition sqlite3.c:163042
SQLITE_API int sqlite3_extended_result_codes(sqlite3 *, int onoff)
Definition sqlite3.c:164768
SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *)
Definition sqlite3.c:93830
SQLITE_API int sqlite3_table_column_metadata(sqlite3 *db, const char *zDbName, const char *zTableName, const char *zColumnName, char const **pzDataType, char const **pzCollSeq, int *pNotNull, int *pPrimaryKey, int *pAutoinc)
Definition sqlite3.c:164634
SQLITE_API int sqlite3_trace_v2(sqlite3 *, unsigned uMask, int(*xCallback)(unsigned, void *, void *, void *), void *pCtx)
Definition sqlite3.c:163096
SQLITE_API int sqlite3_wal_checkpoint_v2(sqlite3 *db, const char *zDb, int eMode, int *pnLog, int *pnCkpt)
Definition sqlite3.c:163329
SQLITE_API char * sqlite3_vsnprintf(int, char *, const char *, va_list)
Definition sqlite3.c:29348
SQLITE_API char * sqlite3_str_value(sqlite3_str *)
Definition sqlite3.c:29207
SQLITE_API const void * sqlite3_value_text16le(sqlite3_value *)
Definition sqlite3.c:83208
SQLITE_API int sqlite3_keyword_check(const char *, int)
Definition sqlite3.c:159878
SQLITE_API int sqlite3_unlock_notify(sqlite3 *pBlocked, void(*xNotify)(void **apArg, int nArg), void *pNotifyArg)
SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset)
Definition sqlite3.c:93820
SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64)
Definition sqlite3.c:93845
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *, int n)
Definition sqlite3.c:83507
SQLITE_API SQLITE_DEPRECATED void * sqlite3_profile(sqlite3 *, void(*xProfile)(void *, const char *, sqlite3_uint64), void *)
Definition sqlite3.c:163126
#define sqlite3_column_table_name
Definition sqlite3.c:124263
SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *)
Definition sqlite3.c:23381
SQLITE_API sqlite3_backup * sqlite3_backup_init(sqlite3 *pDest, const char *zDestName, sqlite3 *pSource, const char *zSourceName)
Definition sqlite3.c:75191
SQLITE_API int sqlite3_str_length(sqlite3_str *)
Definition sqlite3.c:29202
SQLITE_API sqlite3_mutex * sqlite3_db_mutex(sqlite3 *)
Definition sqlite3.c:161843
SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt)
Definition sqlite3.c:84662
SQLITE_API const char * sqlite3_uri_key(const char *zFilename, int N)
Definition sqlite3.c:165304
SQLITE_API int sqlite3_create_module_v2(sqlite3 *db, const char *zName, const sqlite3_module *p, void *pClientData, void(*xDestroy)(void *))
Definition sqlite3.c:139694
SQLITE_API void sqlite3_result_error16(sqlite3_context *, const void *, int)
Definition sqlite3.c:83413
#define sqlite3_column_database_name16
Definition sqlite3.c:124262
SQLITE_API const void * sqlite3_column_decltype16(sqlite3_stmt *, int)
Definition sqlite3.c:84245
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p)
Definition sqlite3.c:75679
SQLITE_API int sqlite3_complete16(const void *sql)
Definition sqlite3.c:160875
SQLITE_API int sqlite3_str_errcode(sqlite3_str *)
Definition sqlite3.c:29197
SQLITE_API double sqlite3_column_double(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84111
SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84121
SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N)
Definition sqlite3.c:27432
SQLITE_API int sqlite3_db_cacheflush(sqlite3 *)
Definition sqlite3.c:161881
SQLITE_API int sqlite3_test_control(int op,...)
Definition sqlite3.c:164829
SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *, const char *zName)
Definition sqlite3.c:84588
SQLITE_API int sqlite3_create_collation16(sqlite3 *, const void *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *))
Definition sqlite3.c:164477
SQLITE_API SQLITE_EXPERIMENTAL const char * sqlite3_vtab_collation(sqlite3_index_info *, int)
Definition sqlite3.c:148920
SQLITE_API const char * sqlite3_libversion(void)
Definition sqlite3.c:161104
SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3 *, sqlite3_int64)
Definition sqlite3.c:162067
SQLITE_API void * sqlite3_commit_hook(sqlite3 *, int(*)(void *), void *)
Definition sqlite3.c:163156
SQLITE_API sqlite3_stmt * sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt)
Definition sqlite3.c:84680
SQLITE_API int sqlite3_compileoption_used(const char *zOptName)
Definition sqlite3.c:165553
SQLITE_API const char * sqlite3_column_decltype(sqlite3_stmt *, int)
Definition sqlite3.c:84241
SQLITE_API const char * sqlite3_errstr(int)
Definition sqlite3.c:163580
SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag)
Definition sqlite3.c:27521
SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb)
Definition sqlite3.c:163391
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p)
Definition sqlite3.c:75693
SQLITE_API int sqlite3_enable_shared_cache(int)
Definition sqlite3.c:64566
SQLITE_API int sqlite3_get_table(sqlite3 *db, const char *zSql, char ***pazResult, int *pnRow, int *pnColumn, char **pzErrmsg)
Definition sqlite3.c:136299
SQLITE_API void sqlite3_result_subtype(sqlite3_context *, unsigned int)
Definition sqlite3.c:83443
SQLITE_API char * sqlite3_expanded_sql(sqlite3_stmt *pStmt)
Definition sqlite3.c:84745
SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void)
Definition sqlite3.c:164626
SQLITE_API int sqlite3_column_int(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84116
#define sqlite3_column_database_name
Definition sqlite3.c:124261
SQLITE_API const char * sqlite3_filename_database(const char *)
Definition sqlite3.c:165350
SQLITE_API int sqlite3_vtab_config(sqlite3 *, int op,...)
Definition sqlite3.c:140848
SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *, int makeDflt)
Definition sqlite3.c:23353
SQLITE_API int sqlite3_set_authorizer(sqlite3 *, int(*xAuth)(void *, int, const char *, const char *, const char *, const char *), void *pUserData)
Definition sqlite3.c:110182
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt *, sqlite3_stmt *)
Definition sqlite3.c:84622
SQLITE_API void sqlite3_progress_handler(sqlite3 *, int, int(*)(void *), void *)
Definition sqlite3.c:162700
SQLITE_API const char * sqlite3_normalized_sql(sqlite3_stmt *pStmt)
SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt *)
Definition sqlite3.c:83128
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context *)
Definition sqlite3.c:83969
SQLITE_API int sqlite3_libversion_number(void)
Definition sqlite3.c:161117
SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void))
Definition sqlite3.c:124953
SQLITE_API int sqlite3_get_autocommit(sqlite3 *)
Definition sqlite3.c:164561
SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *, int op, int resetFlg)
Definition sqlite3.c:84701
SQLITE_API int sqlite3_blob_close(sqlite3_blob *)
Definition sqlite3.c:93719
SQLITE_API int sqlite3_total_changes(sqlite3 *)
Definition sqlite3.c:162095
SQLITE_API int sqlite3_keyword_name(int, const char **, int *)
Definition sqlite3.c:159871
SQLITE_API const char * sqlite3_bind_parameter_name(sqlite3_stmt *, int)
Definition sqlite3.c:84573
SQLITE_API int sqlite3_prepare(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail)
Definition sqlite3.c:129134
SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void))
Definition sqlite3.c:125000
SQLITE_API int sqlite3_release_memory(int)
Definition sqlite3.c:27335
SQLITE_API int sqlite3_collation_needed16(sqlite3 *, void *, void(*)(void *, sqlite3 *, int eTextRep, const void *))
Definition sqlite3.c:164528
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName)
Definition sqlite3.c:165400
SQLITE_API int sqlite3_open(const char *filename, sqlite3 **ppDb)
Definition sqlite3.c:164380
SQLITE_API void * sqlite3_update_hook(sqlite3 *, void(*)(void *, int, char const *, char const *, sqlite3_int64), void *)
Definition sqlite3.c:163181
SQLITE_API int sqlite3_load_extension(sqlite3 *db, const char *zFile, const char *zProc, char **pzErrMsg)
Definition sqlite3.c:124876
SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value *)
Definition sqlite3.c:83181
#define sqlite3_column_origin_name
Definition sqlite3.c:124265
SQLITE_API void * sqlite3_rollback_hook(sqlite3 *, void(*)(void *), void *)
Definition sqlite3.c:163206
SQLITE_API const void * sqlite3_errmsg16(sqlite3 *)
Definition sqlite3.c:163511
SQLITE_API int sqlite3_bind_int(sqlite3_stmt *, int, int)
Definition sqlite3.c:84426
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *)
Definition sqlite3.c:140830
SQLITE_API const void * sqlite3_column_text16(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84141
SQLITE_API int sqlite3_threadsafe(void)
Definition sqlite3.c:161123
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt)
Definition sqlite3.c:84654
SQLITE_API int sqlite3_db_status(sqlite3 *, int op, int *pCur, int *pHiwtr, int resetFlg)
Definition sqlite3.c:21515
#define sqlite3_column_origin_name16
Definition sqlite3.c:124266
SQLITE_API sqlite3_int64 sqlite3_memory_used(void)
Definition sqlite3.c:27510
SQLITE_API int sqlite3_create_module(sqlite3 *db, const char *zName, const sqlite3_module *p, void *pClientData)
Definition sqlite3.c:139679
#define sqlite3_column_table_name16
Definition sqlite3.c:124264
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag)
Definition sqlite3.c:21472
SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84106
SQLITE_API int sqlite3_keyword_count(void)
Definition sqlite3.c:159877
SQLITE_API const void * sqlite3_column_name16(sqlite3_stmt *, int N)
Definition sqlite3.c:84222
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *)
Definition sqlite3.c:84562
SQLITE_API int sqlite3_create_collation_v2(sqlite3 *, const char *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *), void(*xDestroy)(void *))
Definition sqlite3.c:164452
SQLITE_API const void * sqlite3_column_blob(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84091
SQLITE_API int sqlite3_sleep(int)
Definition sqlite3.c:164752
SQLITE_API int sqlite3_prepare16(sqlite3 *db, const void *zSql, int nByte, sqlite3_stmt **ppStmt, const void **pzTail)
Definition sqlite3.c:129250
SQLITE_API int sqlite3_close_v2(sqlite3 *)
Definition sqlite3.c:162247
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt)
Definition sqlite3.c:83987
SQLITE_API const void * sqlite3_value_text16be(sqlite3_value *)
Definition sqlite3.c:83205
SQLITE_API int sqlite3_blob_open(sqlite3 *, const char *zDb, const char *zTable, const char *zColumn, sqlite3_int64 iRow, int flags, sqlite3_blob **ppBlob)
Definition sqlite3.c:93486
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3 *)
Definition sqlite3.c:162054
SQLITE_API int sqlite3_open16(const void *filename, sqlite3 **ppDb)
Definition sqlite3.c:164400
SQLITE_API int sqlite3_create_collation(sqlite3 *, const char *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *))
Definition sqlite3.c:164439
SQLITE_API sqlite3_str * sqlite3_str_new(sqlite3 *)
Definition sqlite3.c:29251
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *)
Definition sqlite3.c:84669
SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset)
Definition sqlite3.c:93813
SQLITE_API int sqlite3_value_frombind(sqlite3_value *)
Definition sqlite3.c:83307
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt *)
Definition sqlite3.c:83009
SQLITE_API int sqlite3_drop_modules(sqlite3 *db, const char **azKeep)
Definition sqlite3.c:139711
SQLITE_API char * sqlite3_vmprintf(const char *, va_list)
Definition sqlite3.c:29299
SQLITE_API const char * sqlite3_db_filename(sqlite3 *db, const char *zDbName)
Definition sqlite3.c:165384
SQLITE_API SQLITE_DEPRECATED void * sqlite3_trace(sqlite3 *, void(*xTrace)(void *, const char *), void *)
Definition sqlite3.c:163075
SQLITE_API int sqlite3_collation_needed(sqlite3 *, void *, void(*)(void *, sqlite3 *, int eTextRep, const char *))
Definition sqlite3.c:164507
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *)
Definition sqlite3.c:83813
SQLITE_API int sqlite3_system_errno(sqlite3 *)
Definition sqlite3.c:163571

Referenced by sqlite3AutoLoadExtensions(), and sqlite3LoadExtension().

◆ sqlite3Autoext

SQLITE_WSD struct sqlite3AutoExtList sqlite3Autoext = { 0, 0 }
static

◆ sqlite3azCompileOpt

const char* const sqlite3azCompileOpt[]
static

Definition at line 72 of file sqlite3.c.

72 {
73
74/*
75** BEGIN CODE GENERATED BY tool/mkctime.tcl
76*/
77#if SQLITE_32BIT_ROWID
78 "32BIT_ROWID",
79#endif
80#if SQLITE_4_BYTE_ALIGNED_MALLOC
81 "4_BYTE_ALIGNED_MALLOC",
82#endif
83#if SQLITE_64BIT_STATS
84 "64BIT_STATS",
85#endif
86#if SQLITE_ALLOW_COVERING_INDEX_SCAN
87 "ALLOW_COVERING_INDEX_SCAN",
88#endif
89#if SQLITE_ALLOW_URI_AUTHORITY
90 "ALLOW_URI_AUTHORITY",
91#endif
92#ifdef SQLITE_BITMASK_TYPE
93 "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE),
94#endif
95#if SQLITE_BUG_COMPATIBLE_20160819
96 "BUG_COMPATIBLE_20160819",
97#endif
98#if SQLITE_CASE_SENSITIVE_LIKE
99 "CASE_SENSITIVE_LIKE",
100#endif
101#if SQLITE_CHECK_PAGES
102 "CHECK_PAGES",
103#endif
104#if defined(__clang__) && defined(__clang_major__)
105 "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
106 CTIMEOPT_VAL(__clang_minor__) "."
107 CTIMEOPT_VAL(__clang_patchlevel__),
108#elif defined(_MSC_VER)
109 "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
110#elif defined(__GNUC__) && defined(__VERSION__)
111 "COMPILER=gcc-" __VERSION__,
112#endif
113#if SQLITE_COVERAGE_TEST
114 "COVERAGE_TEST",
115#endif
116#if SQLITE_DEBUG
117 "DEBUG",
118#endif
119#if SQLITE_DEFAULT_AUTOMATIC_INDEX
120 "DEFAULT_AUTOMATIC_INDEX",
121#endif
122#if SQLITE_DEFAULT_AUTOVACUUM
123 "DEFAULT_AUTOVACUUM",
124#endif
125#ifdef SQLITE_DEFAULT_CACHE_SIZE
126 "DEFAULT_CACHE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_CACHE_SIZE),
127#endif
128#if SQLITE_DEFAULT_CKPTFULLFSYNC
129 "DEFAULT_CKPTFULLFSYNC",
130#endif
131#ifdef SQLITE_DEFAULT_FILE_FORMAT
132 "DEFAULT_FILE_FORMAT=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_FORMAT),
133#endif
134#ifdef SQLITE_DEFAULT_FILE_PERMISSIONS
135 "DEFAULT_FILE_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_PERMISSIONS),
136#endif
137#if SQLITE_DEFAULT_FOREIGN_KEYS
138 "DEFAULT_FOREIGN_KEYS",
139#endif
140#ifdef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
141 "DEFAULT_JOURNAL_SIZE_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT),
142#endif
143#ifdef SQLITE_DEFAULT_LOCKING_MODE
144 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
145#endif
146#ifdef SQLITE_DEFAULT_LOOKASIDE
147 "DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE),
148#endif
149#if SQLITE_DEFAULT_MEMSTATUS
150 "DEFAULT_MEMSTATUS",
151#endif
152#ifdef SQLITE_DEFAULT_MMAP_SIZE
153 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
154#endif
155#ifdef SQLITE_DEFAULT_PAGE_SIZE
156 "DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_PAGE_SIZE),
157#endif
158#ifdef SQLITE_DEFAULT_PCACHE_INITSZ
159 "DEFAULT_PCACHE_INITSZ=" CTIMEOPT_VAL(SQLITE_DEFAULT_PCACHE_INITSZ),
160#endif
161#ifdef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS
162 "DEFAULT_PROXYDIR_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS),
163#endif
164#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
165 "DEFAULT_RECURSIVE_TRIGGERS",
166#endif
167#ifdef SQLITE_DEFAULT_ROWEST
168 "DEFAULT_ROWEST=" CTIMEOPT_VAL(SQLITE_DEFAULT_ROWEST),
169#endif
170#ifdef SQLITE_DEFAULT_SECTOR_SIZE
171 "DEFAULT_SECTOR_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_SECTOR_SIZE),
172#endif
173#ifdef SQLITE_DEFAULT_SYNCHRONOUS
174 "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
175#endif
176#ifdef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
177 "DEFAULT_WAL_AUTOCHECKPOINT=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT),
178#endif
179#ifdef SQLITE_DEFAULT_WAL_SYNCHRONOUS
180 "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
181#endif
182#ifdef SQLITE_DEFAULT_WORKER_THREADS
183 "DEFAULT_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WORKER_THREADS),
184#endif
185#if SQLITE_DIRECT_OVERFLOW_READ
186 "DIRECT_OVERFLOW_READ",
187#endif
188#if SQLITE_DISABLE_DIRSYNC
189 "DISABLE_DIRSYNC",
190#endif
191#if SQLITE_DISABLE_FTS3_UNICODE
192 "DISABLE_FTS3_UNICODE",
193#endif
194#if SQLITE_DISABLE_FTS4_DEFERRED
195 "DISABLE_FTS4_DEFERRED",
196#endif
197#if SQLITE_DISABLE_INTRINSIC
198 "DISABLE_INTRINSIC",
199#endif
200#if SQLITE_DISABLE_LFS
201 "DISABLE_LFS",
202#endif
203#if SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
204 "DISABLE_PAGECACHE_OVERFLOW_STATS",
205#endif
206#if SQLITE_DISABLE_SKIPAHEAD_DISTINCT
207 "DISABLE_SKIPAHEAD_DISTINCT",
208#endif
209#ifdef SQLITE_ENABLE_8_3_NAMES
210 "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
211#endif
212#if SQLITE_ENABLE_API_ARMOR
213 "ENABLE_API_ARMOR",
214#endif
215#if SQLITE_ENABLE_ATOMIC_WRITE
216 "ENABLE_ATOMIC_WRITE",
217#endif
218#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
219 "ENABLE_BATCH_ATOMIC_WRITE",
220#endif
221#if SQLITE_ENABLE_BYTECODE_VTAB
222 "ENABLE_BYTECODE_VTAB",
223#endif
224#if SQLITE_ENABLE_CEROD
225 "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
226#endif
227#if SQLITE_ENABLE_COLUMN_METADATA
228 "ENABLE_COLUMN_METADATA",
229#endif
230#if SQLITE_ENABLE_COLUMN_USED_MASK
231 "ENABLE_COLUMN_USED_MASK",
232#endif
233#if SQLITE_ENABLE_COSTMULT
234 "ENABLE_COSTMULT",
235#endif
236#if SQLITE_ENABLE_CURSOR_HINTS
237 "ENABLE_CURSOR_HINTS",
238#endif
239#if SQLITE_ENABLE_DBSTAT_VTAB
240 "ENABLE_DBSTAT_VTAB",
241#endif
242#if SQLITE_ENABLE_EXPENSIVE_ASSERT
243 "ENABLE_EXPENSIVE_ASSERT",
244#endif
245#if SQLITE_ENABLE_FTS1
246 "ENABLE_FTS1",
247#endif
248#if SQLITE_ENABLE_FTS2
249 "ENABLE_FTS2",
250#endif
251#if SQLITE_ENABLE_FTS3
252 "ENABLE_FTS3",
253#endif
254#if SQLITE_ENABLE_FTS3_PARENTHESIS
255 "ENABLE_FTS3_PARENTHESIS",
256#endif
257#if SQLITE_ENABLE_FTS3_TOKENIZER
258 "ENABLE_FTS3_TOKENIZER",
259#endif
260#if SQLITE_ENABLE_FTS4
261 "ENABLE_FTS4",
262#endif
263#if SQLITE_ENABLE_FTS5
264 "ENABLE_FTS5",
265#endif
266#if SQLITE_ENABLE_GEOPOLY
267 "ENABLE_GEOPOLY",
268#endif
269#if SQLITE_ENABLE_HIDDEN_COLUMNS
270 "ENABLE_HIDDEN_COLUMNS",
271#endif
272#if SQLITE_ENABLE_ICU
273 "ENABLE_ICU",
274#endif
275#if SQLITE_ENABLE_IOTRACE
276 "ENABLE_IOTRACE",
277#endif
278#if SQLITE_ENABLE_JSON1
279 "ENABLE_JSON1",
280#endif
281#if SQLITE_ENABLE_LOAD_EXTENSION
282 "ENABLE_LOAD_EXTENSION",
283#endif
284#ifdef SQLITE_ENABLE_LOCKING_STYLE
285 "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
286#endif
287#if SQLITE_ENABLE_MEMORY_MANAGEMENT
288 "ENABLE_MEMORY_MANAGEMENT",
289#endif
290#if SQLITE_ENABLE_MEMSYS3
291 "ENABLE_MEMSYS3",
292#endif
293#if SQLITE_ENABLE_MEMSYS5
294 "ENABLE_MEMSYS5",
295#endif
296#if SQLITE_ENABLE_MULTIPLEX
297 "ENABLE_MULTIPLEX",
298#endif
299#if SQLITE_ENABLE_NORMALIZE
300 "ENABLE_NORMALIZE",
301#endif
302#if SQLITE_ENABLE_NULL_TRIM
303 "ENABLE_NULL_TRIM",
304#endif
305#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
306 "ENABLE_OVERSIZE_CELL_CHECK",
307#endif
308#if SQLITE_ENABLE_PREUPDATE_HOOK
309 "ENABLE_PREUPDATE_HOOK",
310#endif
311#if SQLITE_ENABLE_QPSG
312 "ENABLE_QPSG",
313#endif
314#if SQLITE_ENABLE_RBU
315 "ENABLE_RBU",
316#endif
317#if SQLITE_ENABLE_RTREE
318 "ENABLE_RTREE",
319#endif
320#if SQLITE_ENABLE_SELECTTRACE
321 "ENABLE_SELECTTRACE",
322#endif
323#if SQLITE_ENABLE_SESSION
324 "ENABLE_SESSION",
325#endif
326#if SQLITE_ENABLE_SNAPSHOT
327 "ENABLE_SNAPSHOT",
328#endif
329#if SQLITE_ENABLE_SORTER_REFERENCES
330 "ENABLE_SORTER_REFERENCES",
331#endif
332#if SQLITE_ENABLE_SQLLOG
333 "ENABLE_SQLLOG",
334#endif
335#if defined(SQLITE_ENABLE_STAT4)
336 "ENABLE_STAT4",
337#endif
338#if SQLITE_ENABLE_STMTVTAB
339 "ENABLE_STMTVTAB",
340#endif
341#if SQLITE_ENABLE_STMT_SCANSTATUS
342 "ENABLE_STMT_SCANSTATUS",
343#endif
344#if SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
345 "ENABLE_UNKNOWN_SQL_FUNCTION",
346#endif
347#if SQLITE_ENABLE_UNLOCK_NOTIFY
348 "ENABLE_UNLOCK_NOTIFY",
349#endif
350#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
351 "ENABLE_UPDATE_DELETE_LIMIT",
352#endif
353#if SQLITE_ENABLE_URI_00_ERROR
354 "ENABLE_URI_00_ERROR",
355#endif
356#if SQLITE_ENABLE_VFSTRACE
357 "ENABLE_VFSTRACE",
358#endif
359#if SQLITE_ENABLE_WHERETRACE
360 "ENABLE_WHERETRACE",
361#endif
362#if SQLITE_ENABLE_ZIPVFS
363 "ENABLE_ZIPVFS",
364#endif
365#if SQLITE_EXPLAIN_ESTIMATED_ROWS
366 "EXPLAIN_ESTIMATED_ROWS",
367#endif
368#if SQLITE_EXTRA_IFNULLROW
369 "EXTRA_IFNULLROW",
370#endif
371#ifdef SQLITE_EXTRA_INIT
372 "EXTRA_INIT=" CTIMEOPT_VAL(SQLITE_EXTRA_INIT),
373#endif
374#ifdef SQLITE_EXTRA_SHUTDOWN
375 "EXTRA_SHUTDOWN=" CTIMEOPT_VAL(SQLITE_EXTRA_SHUTDOWN),
376#endif
377#ifdef SQLITE_FTS3_MAX_EXPR_DEPTH
378 "FTS3_MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_FTS3_MAX_EXPR_DEPTH),
379#endif
380#if SQLITE_FTS5_ENABLE_TEST_MI
381 "FTS5_ENABLE_TEST_MI",
382#endif
383#if SQLITE_FTS5_NO_WITHOUT_ROWID
384 "FTS5_NO_WITHOUT_ROWID",
385#endif
386#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
387 "HAVE_ISNAN",
388#endif
389#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
390 "HOMEGROWN_RECURSIVE_MUTEX",
391#endif
392#if SQLITE_IGNORE_AFP_LOCK_ERRORS
393 "IGNORE_AFP_LOCK_ERRORS",
394#endif
395#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
396 "IGNORE_FLOCK_LOCK_ERRORS",
397#endif
398#if SQLITE_INLINE_MEMCPY
399 "INLINE_MEMCPY",
400#endif
401#if SQLITE_INT64_TYPE
402 "INT64_TYPE",
403#endif
404#ifdef SQLITE_INTEGRITY_CHECK_ERROR_MAX
405 "INTEGRITY_CHECK_ERROR_MAX=" CTIMEOPT_VAL(SQLITE_INTEGRITY_CHECK_ERROR_MAX),
406#endif
407#if SQLITE_LIKE_DOESNT_MATCH_BLOBS
408 "LIKE_DOESNT_MATCH_BLOBS",
409#endif
410#if SQLITE_LOCK_TRACE
411 "LOCK_TRACE",
412#endif
413#if SQLITE_LOG_CACHE_SPILL
414 "LOG_CACHE_SPILL",
415#endif
416#ifdef SQLITE_MALLOC_SOFT_LIMIT
417 "MALLOC_SOFT_LIMIT=" CTIMEOPT_VAL(SQLITE_MALLOC_SOFT_LIMIT),
418#endif
419#ifdef SQLITE_MAX_ATTACHED
420 "MAX_ATTACHED=" CTIMEOPT_VAL(SQLITE_MAX_ATTACHED),
421#endif
422#ifdef SQLITE_MAX_COLUMN
423 "MAX_COLUMN=" CTIMEOPT_VAL(SQLITE_MAX_COLUMN),
424#endif
425#ifdef SQLITE_MAX_COMPOUND_SELECT
426 "MAX_COMPOUND_SELECT=" CTIMEOPT_VAL(SQLITE_MAX_COMPOUND_SELECT),
427#endif
428#ifdef SQLITE_MAX_DEFAULT_PAGE_SIZE
429 "MAX_DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_DEFAULT_PAGE_SIZE),
430#endif
431#ifdef SQLITE_MAX_EXPR_DEPTH
432 "MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_EXPR_DEPTH),
433#endif
434#ifdef SQLITE_MAX_FUNCTION_ARG
435 "MAX_FUNCTION_ARG=" CTIMEOPT_VAL(SQLITE_MAX_FUNCTION_ARG),
436#endif
437#ifdef SQLITE_MAX_LENGTH
438 "MAX_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LENGTH),
439#endif
440#ifdef SQLITE_MAX_LIKE_PATTERN_LENGTH
441 "MAX_LIKE_PATTERN_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LIKE_PATTERN_LENGTH),
442#endif
443#ifdef SQLITE_MAX_MEMORY
444 "MAX_MEMORY=" CTIMEOPT_VAL(SQLITE_MAX_MEMORY),
445#endif
446#ifdef SQLITE_MAX_MMAP_SIZE
447 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
448#endif
449#ifdef SQLITE_MAX_MMAP_SIZE_
450 "MAX_MMAP_SIZE_=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE_),
451#endif
452#ifdef SQLITE_MAX_PAGE_COUNT
453 "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT),
454#endif
455#ifdef SQLITE_MAX_PAGE_SIZE
456 "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE),
457#endif
458#ifdef SQLITE_MAX_SCHEMA_RETRY
459 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
460#endif
461#ifdef SQLITE_MAX_SQL_LENGTH
462 "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH),
463#endif
464#ifdef SQLITE_MAX_TRIGGER_DEPTH
465 "MAX_TRIGGER_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_TRIGGER_DEPTH),
466#endif
467#ifdef SQLITE_MAX_VARIABLE_NUMBER
468 "MAX_VARIABLE_NUMBER=" CTIMEOPT_VAL(SQLITE_MAX_VARIABLE_NUMBER),
469#endif
470#ifdef SQLITE_MAX_VDBE_OP
471 "MAX_VDBE_OP=" CTIMEOPT_VAL(SQLITE_MAX_VDBE_OP),
472#endif
473#ifdef SQLITE_MAX_WORKER_THREADS
474 "MAX_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_MAX_WORKER_THREADS),
475#endif
476#if SQLITE_MEMDEBUG
477 "MEMDEBUG",
478#endif
479#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
480 "MIXED_ENDIAN_64BIT_FLOAT",
481#endif
482#if SQLITE_MMAP_READWRITE
483 "MMAP_READWRITE",
484#endif
485#if SQLITE_MUTEX_NOOP
486 "MUTEX_NOOP",
487#endif
488#if SQLITE_MUTEX_NREF
489 "MUTEX_NREF",
490#endif
491#if SQLITE_MUTEX_OMIT
492 "MUTEX_OMIT",
493#endif
494#if SQLITE_MUTEX_PTHREADS
495 "MUTEX_PTHREADS",
496#endif
497#if SQLITE_MUTEX_W32
498 "MUTEX_W32",
499#endif
500#if SQLITE_NEED_ERR_NAME
501 "NEED_ERR_NAME",
502#endif
503#if SQLITE_NOINLINE
504 "NOINLINE",
505#endif
506#if SQLITE_NO_SYNC
507 "NO_SYNC",
508#endif
509#if SQLITE_OMIT_ALTERTABLE
510 "OMIT_ALTERTABLE",
511#endif
512#if SQLITE_OMIT_ANALYZE
513 "OMIT_ANALYZE",
514#endif
515#if SQLITE_OMIT_ATTACH
516 "OMIT_ATTACH",
517#endif
518#if SQLITE_OMIT_AUTHORIZATION
519 "OMIT_AUTHORIZATION",
520#endif
521#if SQLITE_OMIT_AUTOINCREMENT
522 "OMIT_AUTOINCREMENT",
523#endif
524#if SQLITE_OMIT_AUTOINIT
525 "OMIT_AUTOINIT",
526#endif
527#if SQLITE_OMIT_AUTOMATIC_INDEX
528 "OMIT_AUTOMATIC_INDEX",
529#endif
530#if SQLITE_OMIT_AUTORESET
531 "OMIT_AUTORESET",
532#endif
533#if SQLITE_OMIT_AUTOVACUUM
534 "OMIT_AUTOVACUUM",
535#endif
536#if SQLITE_OMIT_BETWEEN_OPTIMIZATION
537 "OMIT_BETWEEN_OPTIMIZATION",
538#endif
539#if SQLITE_OMIT_BLOB_LITERAL
540 "OMIT_BLOB_LITERAL",
541#endif
542#if SQLITE_OMIT_CAST
543 "OMIT_CAST",
544#endif
545#if SQLITE_OMIT_CHECK
546 "OMIT_CHECK",
547#endif
548#if SQLITE_OMIT_COMPLETE
549 "OMIT_COMPLETE",
550#endif
551#if SQLITE_OMIT_COMPOUND_SELECT
552 "OMIT_COMPOUND_SELECT",
553#endif
554#if SQLITE_OMIT_CONFLICT_CLAUSE
555 "OMIT_CONFLICT_CLAUSE",
556#endif
557#if SQLITE_OMIT_CTE
558 "OMIT_CTE",
559#endif
560#if SQLITE_OMIT_DATETIME_FUNCS
561 "OMIT_DATETIME_FUNCS",
562#endif
563#if SQLITE_OMIT_DECLTYPE
564 "OMIT_DECLTYPE",
565#endif
566#if SQLITE_OMIT_DEPRECATED
567 "OMIT_DEPRECATED",
568#endif
569#if SQLITE_OMIT_DISKIO
570 "OMIT_DISKIO",
571#endif
572#if SQLITE_OMIT_EXPLAIN
573 "OMIT_EXPLAIN",
574#endif
575#if SQLITE_OMIT_FLAG_PRAGMAS
576 "OMIT_FLAG_PRAGMAS",
577#endif
578#if SQLITE_OMIT_FLOATING_POINT
579 "OMIT_FLOATING_POINT",
580#endif
581#if SQLITE_OMIT_FOREIGN_KEY
582 "OMIT_FOREIGN_KEY",
583#endif
584#if SQLITE_OMIT_GET_TABLE
585 "OMIT_GET_TABLE",
586#endif
587#if SQLITE_OMIT_HEX_INTEGER
588 "OMIT_HEX_INTEGER",
589#endif
590#if SQLITE_OMIT_INCRBLOB
591 "OMIT_INCRBLOB",
592#endif
593#if SQLITE_OMIT_INTEGRITY_CHECK
594 "OMIT_INTEGRITY_CHECK",
595#endif
596#if SQLITE_OMIT_LIKE_OPTIMIZATION
597 "OMIT_LIKE_OPTIMIZATION",
598#endif
599#if SQLITE_OMIT_LOAD_EXTENSION
600 "OMIT_LOAD_EXTENSION",
601#endif
602#if SQLITE_OMIT_LOCALTIME
603 "OMIT_LOCALTIME",
604#endif
605#if SQLITE_OMIT_LOOKASIDE
606 "OMIT_LOOKASIDE",
607#endif
608#if SQLITE_OMIT_MEMORYDB
609 "OMIT_MEMORYDB",
610#endif
611#if SQLITE_OMIT_OR_OPTIMIZATION
612 "OMIT_OR_OPTIMIZATION",
613#endif
614#if SQLITE_OMIT_PAGER_PRAGMAS
615 "OMIT_PAGER_PRAGMAS",
616#endif
617#if SQLITE_OMIT_PARSER_TRACE
618 "OMIT_PARSER_TRACE",
619#endif
620#if SQLITE_OMIT_POPEN
621 "OMIT_POPEN",
622#endif
623#if SQLITE_OMIT_PRAGMA
624 "OMIT_PRAGMA",
625#endif
626#if SQLITE_OMIT_PROGRESS_CALLBACK
627 "OMIT_PROGRESS_CALLBACK",
628#endif
629#if SQLITE_OMIT_QUICKBALANCE
630 "OMIT_QUICKBALANCE",
631#endif
632#if SQLITE_OMIT_REINDEX
633 "OMIT_REINDEX",
634#endif
635#if SQLITE_OMIT_SCHEMA_PRAGMAS
636 "OMIT_SCHEMA_PRAGMAS",
637#endif
638#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
639 "OMIT_SCHEMA_VERSION_PRAGMAS",
640#endif
641#if SQLITE_OMIT_SHARED_CACHE
642 "OMIT_SHARED_CACHE",
643#endif
644#if SQLITE_OMIT_SHUTDOWN_DIRECTORIES
645 "OMIT_SHUTDOWN_DIRECTORIES",
646#endif
647#if SQLITE_OMIT_SUBQUERY
648 "OMIT_SUBQUERY",
649#endif
650#if SQLITE_OMIT_TCL_VARIABLE
651 "OMIT_TCL_VARIABLE",
652#endif
653#if SQLITE_OMIT_TEMPDB
654 "OMIT_TEMPDB",
655#endif
656#if SQLITE_OMIT_TEST_CONTROL
657 "OMIT_TEST_CONTROL",
658#endif
659#if SQLITE_OMIT_TRACE
660 "OMIT_TRACE",
661#endif
662#if SQLITE_OMIT_TRIGGER
663 "OMIT_TRIGGER",
664#endif
665#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
666 "OMIT_TRUNCATE_OPTIMIZATION",
667#endif
668#if SQLITE_OMIT_UTF16
669 "OMIT_UTF16",
670#endif
671#if SQLITE_OMIT_VACUUM
672 "OMIT_VACUUM",
673#endif
674#if SQLITE_OMIT_VIEW
675 "OMIT_VIEW",
676#endif
677#if SQLITE_OMIT_VIRTUALTABLE
678 "OMIT_VIRTUALTABLE",
679#endif
680#if SQLITE_OMIT_WAL
681 "OMIT_WAL",
682#endif
683#if SQLITE_OMIT_WSD
684 "OMIT_WSD",
685#endif
686#if SQLITE_OMIT_XFER_OPT
687 "OMIT_XFER_OPT",
688#endif
689#if SQLITE_PCACHE_SEPARATE_HEADER
690 "PCACHE_SEPARATE_HEADER",
691#endif
692#if SQLITE_PERFORMANCE_TRACE
693 "PERFORMANCE_TRACE",
694#endif
695#if SQLITE_POWERSAFE_OVERWRITE
696 "POWERSAFE_OVERWRITE",
697#endif
698#if SQLITE_PREFER_PROXY_LOCKING
699 "PREFER_PROXY_LOCKING",
700#endif
701#if SQLITE_PROXY_DEBUG
702 "PROXY_DEBUG",
703#endif
704#if SQLITE_REVERSE_UNORDERED_SELECTS
705 "REVERSE_UNORDERED_SELECTS",
706#endif
707#if SQLITE_RTREE_INT_ONLY
708 "RTREE_INT_ONLY",
709#endif
710#if SQLITE_SECURE_DELETE
711 "SECURE_DELETE",
712#endif
713#if SQLITE_SMALL_STACK
714 "SMALL_STACK",
715#endif
716#ifdef SQLITE_SORTER_PMASZ
717 "SORTER_PMASZ=" CTIMEOPT_VAL(SQLITE_SORTER_PMASZ),
718#endif
719#if SQLITE_SOUNDEX
720 "SOUNDEX",
721#endif
722#ifdef SQLITE_STAT4_SAMPLES
723 "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES),
724#endif
725#ifdef SQLITE_STMTJRNL_SPILL
726 "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL),
727#endif
728#if SQLITE_SUBSTR_COMPATIBILITY
729 "SUBSTR_COMPATIBILITY",
730#endif
731#if SQLITE_SYSTEM_MALLOC
732 "SYSTEM_MALLOC",
733#endif
734#if SQLITE_TCL
735 "TCL",
736#endif
737#ifdef SQLITE_TEMP_STORE
738 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
739#endif
740#if SQLITE_TEST
741 "TEST",
742#endif
743#if defined(SQLITE_THREADSAFE)
744 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
745#elif defined(THREADSAFE)
746 "THREADSAFE=" CTIMEOPT_VAL(THREADSAFE),
747#else
748 "THREADSAFE=1",
749#endif
750#if SQLITE_UNLINK_AFTER_CLOSE
751 "UNLINK_AFTER_CLOSE",
752#endif
753#if SQLITE_UNTESTABLE
754 "UNTESTABLE",
755#endif
756#if SQLITE_USER_AUTHENTICATION
757 "USER_AUTHENTICATION",
758#endif
759#if SQLITE_USE_ALLOCA
760 "USE_ALLOCA",
761#endif
762#if SQLITE_USE_FCNTL_TRACE
763 "USE_FCNTL_TRACE",
764#endif
765#if SQLITE_USE_URI
766 "USE_URI",
767#endif
768#if SQLITE_VDBE_COVERAGE
769 "VDBE_COVERAGE",
770#endif
771#if SQLITE_WIN32_MALLOC
772 "WIN32_MALLOC",
773#endif
774#if SQLITE_ZERO_MALLOC
775 "ZERO_MALLOC",
776#endif
777/*
778** END CODE GENERATED BY tool/mkctime.tcl
779*/
780};
#define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS
Definition sqlite3.c:33516
#define SQLITE_SORTER_PMASZ
Definition sqlite3.c:20525
#define SQLITE_MAX_MEMORY
Definition sqlite3.c:27351
#define CTIMEOPT_VAL2(opt)
Definition sqlite3.c:62
#define SQLITE_DEFAULT_FILE_FORMAT
Definition sqlite3.c:14183
#define CTIMEOPT_VAL(opt)
Definition sqlite3.c:56
#define SQLITE_STMTJRNL_SPILL
Definition sqlite3.c:20537
#define SQLITE_DEFAULT_LOOKASIDE
Definition sqlite3.c:20557
#define SQLITE_DEFAULT_SECTOR_SIZE
Definition sqlite3.c:16314
#define SQLITE_DEFAULT_PCACHE_INITSZ
Definition sqlite3.c:14232

Referenced by sqlite3CompileOptions().

◆ sqlite3BuiltinExtensions

int(*const sqlite3BuiltinExtensions[])(sqlite3 *) ( sqlite3 * )
static

Definition at line 161057 of file sqlite3.c.

161063 {
161064#ifdef SQLITE_ENABLE_FTS1
161065 sqlite3Fts1Init,
161066#endif
161067#ifdef SQLITE_ENABLE_FTS2
161068 sqlite3Fts2Init,
161069#endif
161070#ifdef SQLITE_ENABLE_FTS3
161071 sqlite3Fts3Init,
161072#endif
161073#ifdef SQLITE_ENABLE_FTS5
161074 sqlite3Fts5Init,
161075#endif
161076#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)
161077 sqlite3IcuInit,
161078#endif
161079#ifdef SQLITE_ENABLE_RTREE
161080 sqlite3RtreeInit,
161081#endif
161082#ifdef SQLITE_ENABLE_DBPAGE_VTAB
161083 sqlite3DbpageRegister,
161084#endif
161085#ifdef SQLITE_ENABLE_DBSTAT_VTAB
161086 sqlite3DbstatRegister,
161087#endif
161089#ifdef SQLITE_ENABLE_JSON1
161090 sqlite3Json1Init,
161091#endif
161092#ifdef SQLITE_ENABLE_STMTVTAB
static int sqlite3TestExtInit(sqlite3 *db)
Definition sqlite3.c:161027

Referenced by openDatabase().

◆ sqlite3BuiltinFunctions

SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions

Definition at line 20634 of file sqlite3.c.

Referenced by sqlite3_initialize(), sqlite3Pragma(), and sqlite3RegisterBuiltinFunctions().

◆ sqlite3Config

SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config

Definition at line 20573 of file sqlite3.c.

20578 {
20579 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
20580 1, /* bCoreMutex */
20581 SQLITE_THREADSAFE==1, /* bFullMutex */
20582 SQLITE_USE_URI, /* bOpenUri */
20584 0, /* bSmallMalloc */
20585 1, /* bExtraSchemaChecks */
20586 0x7ffffffe, /* mxStrlen */
20587 0, /* neverCorrupt */
20588 SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
20589 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
20590 {0,0,0,0,0,0,0,0}, /* m */
20591 {0,0,0,0,0,0,0,0,0}, /* mutex */
20592 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
20593 (void*)0, /* pHeap */
20594 0, /* nHeap */
20595 0, 0, /* mnHeap, mxHeap */
20596 SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */
20597 SQLITE_MAX_MMAP_SIZE, /* mxMmap */
20598 (void*)0, /* pPage */
20599 0, /* szPage */
20600 SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
20601 0, /* mxParserStack */
20602 0, /* sharedCacheEnabled */
20603 SQLITE_SORTER_PMASZ, /* szPma */
20604 /* All the rest should always be initialized to zero */
20605 0, /* isInit */
20606 0, /* inProgress */
20607 0, /* isMutexInit */
20608 0, /* isMallocInit */
20609 0, /* isPCacheInit */
20610 0, /* nRefInitMutex */
20611 0, /* pInitMutex */
20612 0, /* xLog */
20613 0, /* pLogArg */
20614#ifdef SQLITE_ENABLE_SQLLOG
20615 0, /* xSqllog */
20616 0, /* pSqllogArg */
20617#endif
20618#ifdef SQLITE_VDBE_COVERAGE
20619 0, /* xVdbeBranch */
20620 0, /* pVbeBranchArg */
20621#endif
20622#ifdef SQLITE_ENABLE_DESERIALIZE
20623 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
20624#endif
20625#ifndef SQLITE_UNTESTABLE
20626 0, /* xTestCallback */
20627#endif
#define SQLITE_ALLOW_COVERING_INDEX_SCAN
Definition sqlite3.c:20511
#define SQLITE_MEMDB_DEFAULT_MAXSIZE
Definition sqlite3.c:20566
#define SQLITE_USE_URI
Definition sqlite3.c:20503
#define SQLITE_DEFAULT_MEMSTATUS
Definition sqlite3.c:13589

Referenced by openSubJournal(), pager_open_journal(), sqlite3CheckObjectName(), and sqlite3InitCallback().

◆ sqlite3CtypeMap

SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256]

Definition at line 20453 of file sqlite3.c.

20458 {
20459 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
20460 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
20461 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
20462 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
20463 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
20464 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
20465 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
20466 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
20467
20468 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
20469 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
20470 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
20471 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
20472 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
20473 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
20474 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
20475 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
20476
20477 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
20478 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */
20479 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */
20480 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */
20481 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */
20482 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */
20483 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */
20484 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */
20485
20486 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */
20487 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */
20488 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */
20489 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */

Referenced by sqlite3VdbeExec().

◆ sqlite3Hooks

SQLITE_WSD struct BenignMallocHooks sqlite3Hooks = { 0, 0 }
static

◆ sqlite3one

const int sqlite3one = 1

Definition at line 14450 of file sqlite3.c.

◆ sqlite3OomStr

sqlite3_str sqlite3OomStr
static
Initial value:
= {
0, 0, 0, 0, 0, SQLITE_NOMEM, 0
}

Definition at line 29179 of file sqlite3.c.

◆ sqlite3OpcodeProperty

SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER

◆ sqlite3OsDlSym

SQLITE_PRIVATE void(*)(void) sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHdle, const char *zSym) ( sqlite3_vfs * pVfs,
void * pHdle,
const char * zSym )

Definition at line 16471 of file sqlite3.c.

Referenced by sqlite3LoadExtension().

◆ sqlite3PendingByte

SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000

Definition at line 20663 of file sqlite3.c.

◆ sqlite3Prng

SQLITE_WSD struct sqlite3PrngType sqlite3Prng
static

◆ sqlite3SavedPrng

SQLITE_WSD struct sqlite3PrngType sqlite3SavedPrng
static

Definition at line 30347 of file sqlite3.c.

◆ sqlite3SharedCacheList

BtShared* SQLITE_WSD sqlite3SharedCacheList = 0
static

Definition at line 64554 of file sqlite3.c.

Referenced by removeFromSharingList(), and sqlite3BtreeOpen().

◆ sqlite3SmallTypeSizes

const u8 sqlite3SmallTypeSizes[]
static
Initial value:
= {
0, 1, 2, 3, 4, 6, 8, 8, 0, 0,
0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
19, 19, 20, 20, 21, 21, 22, 22, 23, 23,
24, 24, 25, 25, 26, 26, 27, 27, 28, 28,
29, 29, 30, 30, 31, 31, 32, 32, 33, 33,
34, 34, 35, 35, 36, 36, 37, 37, 38, 38,
39, 39, 40, 40, 41, 41, 42, 42, 43, 43,
44, 44, 45, 45, 46, 46, 47, 47, 48, 48,
49, 49, 50, 50, 51, 51, 52, 52, 53, 53,
54, 54, 55, 55, 56, 56, 57, 57
}

Definition at line 81433 of file sqlite3.c.

81439 {
81440 /* 0 1 2 3 4 5 6 7 8 9 */
81441/* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0,
81442/* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
81443/* 20 */ 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
81444/* 30 */ 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
81445/* 40 */ 14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
81446/* 50 */ 19, 19, 20, 20, 21, 21, 22, 22, 23, 23,
81447/* 60 */ 24, 24, 25, 25, 26, 26, 27, 27, 28, 28,
81448/* 70 */ 29, 29, 30, 30, 31, 31, 32, 32, 33, 33,

Referenced by sqlite3VdbeIdxRowid(), and sqlite3VdbeSerialPut().

◆ sqlite3Stat

SQLITE_WSD struct sqlite3StatType sqlite3Stat = { {0,}, {0,} }
static

◆ sqlite3StrBINARY

◆ sqlite3UpperToLower

SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]

Definition at line 20387 of file sqlite3.c.

20392 {
20393#ifdef SQLITE_ASCII
20394 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
20395 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
20396 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
20397 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
20398 104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
20399 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
20400 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
20401 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
20402 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
20403 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
20404 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
20405 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
20406 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
20407 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
20408 252,253,254,255
20409#endif
20410#ifdef SQLITE_EBCDIC
20411 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
20412 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
20413 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
20414 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */
20415 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */
20416 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */
20417 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */
20418 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */
20419 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */
20420 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */
20421 160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */
20422 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */
20423 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */

Referenced by exprAnalyze(), parseModifier(), sqlite3AffinityType(), sqlite3FindFunction(), sqlite3LoadExtension(), and sqlite3VtabOverloadFunction().

◆ sqlite3Utf8Trans1

const unsigned char sqlite3Utf8Trans1[]
static
Initial value:
= {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
}

Definition at line 30694 of file sqlite3.c.

30700 {
30701 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
30702 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
30703 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,

Referenced by sqlite3Utf8Read().

◆ statGetFuncdef

const FuncDef statGetFuncdef
static
Initial value:
= {
1+IsStat4,
0,
0,
0,
0, 0,
"stat_get",
{0}
}
static void statGet(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:108357

Definition at line 108472 of file sqlite3.c.

108478 {
108479 1+IsStat4, /* nArg */
108480 SQLITE_UTF8, /* funcFlags */
108481 0, /* pUserData */
108482 0, /* pNext */

◆ statInitFuncdef

const FuncDef statInitFuncdef
static
Initial value:
= {
4,
0,
0,
0,
0, 0,
"stat_init",
{0}
}
static void statInit(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:107943

Definition at line 108030 of file sqlite3.c.

108036 {
108037 4, /* nArg */
108038 SQLITE_UTF8, /* funcFlags */
108039 0, /* pUserData */
108040 0, /* pNext */

Referenced by analyzeOneTable().

◆ statMutex

const char statMutex[]
static
Initial value:
= {
0,
1,
1,
0,
0,
0,
0,
1,
0,
0,
}

Definition at line 21350 of file sqlite3.c.

21355 {
21356 0, /* SQLITE_STATUS_MEMORY_USED */
21357 1, /* SQLITE_STATUS_PAGECACHE_USED */
21358 1, /* SQLITE_STATUS_PAGECACHE_OVERFLOW */
21359 0, /* SQLITE_STATUS_SCRATCH_USED */
21360 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */
21361 0, /* SQLITE_STATUS_MALLOC_SIZE */

Referenced by sqlite3StatusHighwater(), sqlite3StatusUp(), and sqlite3StatusValue().

◆ statPushFuncdef

const FuncDef statPushFuncdef
static
Initial value:
= {
2+IsStat4,
0,
0,
0,
0, 0,
"stat_push",
{0}
}
static void statPush(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition sqlite3.c:108245

Definition at line 108320 of file sqlite3.c.

108320 {
108321 p->nSkipAhead++;
108322 sqlite3_result_int(context, p->current.anDLt[0]>0);
108323 }
108324}
108325
108326static const FuncDef statPushFuncdef = {
108327 2+IsStat4, /* nArg */
108328 SQLITE_UTF8, /* funcFlags */
108329 0, /* pUserData */
108330 0, /* pNext */

Referenced by analyzeOneTable().

◆ unixBigLock

sqlite3_mutex* unixBigLock = 0
static

Definition at line 34278 of file sqlite3.c.

Referenced by sqlite3_os_end(), sqlite3_os_init(), and unixLeaveMutex().

◆ unixDlSym

void(*)(void) unixDlSym(sqlite3_vfs *NotUsed, void *p, const char *zSym) ( sqlite3_vfs * NotUsed,
void * p,
const char * zSym )
static

Definition at line 39994 of file sqlite3.c.

39995 {
39996 sqlite3_snprintf(nBuf, zBufOut, "%s", zErr);
39997 }
39999}
40000static void (*unixDlSym(sqlite3_vfs *NotUsed, void *p, const char*zSym))(void){
40001 /*
40002 ** GCC with -pedantic-errors says that C90 does not allow a void* to be
40003 ** cast into a pointer to a function. And yet the library dlsym() routine
40004 ** returns a void* which is really a pointer to a function. So how do we
40005 ** use dlsym() with -pedantic-errors?
40006 **
40007 ** Variable x below is defined to be a pointer to a function taking
40008 ** parameters void* and const char* and returning a pointer to a function.
40009 ** We initialize x by assigning it a pointer to the dlsym() function.
40010 ** (That assignment requires a cast.) Then we call the function that
40011 ** x points to.
40012 **
40013 ** This work-around is unlikely to work correctly on any system where
40014 ** you really cannot cast a function pointer into void*. But then, on the
40015 ** other hand, dlsym() will not work on such a system either, so we have
40016 ** not really lost anything.

◆ vfsList

sqlite3_vfs* SQLITE_WSD vfsList = 0
static

Definition at line 23300 of file sqlite3.c.

◆ yy_action

const YYACTIONTYPE yy_action[]
static

Definition at line 154593 of file sqlite3.c.

154599 {
154600 /* 0 */ 546, 1222, 546, 451, 1260, 546, 1239, 546, 114, 111,
154601 /* 10 */ 211, 546, 1537, 546, 1260, 523, 114, 111, 211, 392,
154602 /* 20 */ 1232, 344, 42, 42, 42, 42, 1225, 42, 42, 71,
154603 /* 30 */ 71, 937, 1224, 71, 71, 71, 71, 1462, 1493, 938,
154604 /* 40 */ 820, 453, 6, 121, 122, 112, 1165, 1165, 1006, 1009,
154605 /* 50 */ 999, 999, 119, 119, 120, 120, 120, 120, 1543, 392,
154606 /* 60 */ 1358, 1517, 552, 2, 1193, 194, 528, 436, 143, 291,
154607 /* 70 */ 528, 136, 528, 371, 261, 504, 272, 385, 1273, 527,
154608 /* 80 */ 503, 493, 164, 121, 122, 112, 1165, 1165, 1006, 1009,
154609 /* 90 */ 999, 999, 119, 119, 120, 120, 120, 120, 1358, 442,
154610 /* 100 */ 1514, 118, 118, 118, 118, 117, 117, 116, 116, 116,
154611 /* 110 */ 115, 424, 266, 266, 266, 266, 1498, 358, 1500, 435,
154612 /* 120 */ 357, 1498, 517, 524, 1485, 543, 1114, 543, 1114, 392,
154613 /* 130 */ 405, 241, 208, 114, 111, 211, 98, 290, 537, 221,
154614 /* 140 */ 1029, 118, 118, 118, 118, 117, 117, 116, 116, 116,
154615 /* 150 */ 115, 424, 1142, 121, 122, 112, 1165, 1165, 1006, 1009,
154616 /* 160 */ 999, 999, 119, 119, 120, 120, 120, 120, 406, 428,
154617 /* 170 */ 117, 117, 116, 116, 116, 115, 424, 1418, 468, 123,
154618 /* 180 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
154619 /* 190 */ 424, 116, 116, 116, 115, 424, 540, 540, 540, 392,
154620 /* 200 */ 505, 120, 120, 120, 120, 113, 1051, 1142, 1143, 1144,
154621 /* 210 */ 1051, 118, 118, 118, 118, 117, 117, 116, 116, 116,
154622 /* 220 */ 115, 424, 1461, 121, 122, 112, 1165, 1165, 1006, 1009,
154623 /* 230 */ 999, 999, 119, 119, 120, 120, 120, 120, 392, 444,
154624 /* 240 */ 316, 83, 463, 81, 359, 382, 1142, 80, 118, 118,
154625 /* 250 */ 118, 118, 117, 117, 116, 116, 116, 115, 424, 179,
154626 /* 260 */ 434, 424, 121, 122, 112, 1165, 1165, 1006, 1009, 999,
154627 /* 270 */ 999, 119, 119, 120, 120, 120, 120, 434, 433, 266,
154628 /* 280 */ 266, 118, 118, 118, 118, 117, 117, 116, 116, 116,
154629 /* 290 */ 115, 424, 543, 1109, 903, 506, 1142, 114, 111, 211,
154630 /* 300 */ 1431, 1142, 1143, 1144, 206, 491, 1109, 392, 449, 1109,
154631 /* 310 */ 545, 330, 120, 120, 120, 120, 298, 1431, 1433, 17,
154632 /* 320 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
154633 /* 330 */ 424, 121, 122, 112, 1165, 1165, 1006, 1009, 999, 999,
154634 /* 340 */ 119, 119, 120, 120, 120, 120, 392, 1358, 434, 1142,
154635 /* 350 */ 482, 1142, 1143, 1144, 996, 996, 1007, 1010, 445, 118,
154636 /* 360 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 424,
154637 /* 370 */ 121, 122, 112, 1165, 1165, 1006, 1009, 999, 999, 119,
154638 /* 380 */ 119, 120, 120, 120, 120, 1054, 1054, 465, 1431, 118,
154639 /* 390 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 424,
154640 /* 400 */ 1142, 451, 546, 1426, 1142, 1143, 1144, 233, 966, 1142,
154641 /* 410 */ 481, 478, 477, 171, 360, 392, 164, 407, 414, 842,
154642 /* 420 */ 476, 164, 185, 334, 71, 71, 1243, 1000, 118, 118,
154643 /* 430 */ 118, 118, 117, 117, 116, 116, 116, 115, 424, 121,
154644 /* 440 */ 122, 112, 1165, 1165, 1006, 1009, 999, 999, 119, 119,
154645 /* 450 */ 120, 120, 120, 120, 392, 1142, 1143, 1144, 835, 12,
154646 /* 460 */ 314, 509, 163, 356, 1142, 1143, 1144, 114, 111, 211,
154647 /* 470 */ 508, 290, 537, 546, 276, 180, 290, 537, 121, 122,
154648 /* 480 */ 112, 1165, 1165, 1006, 1009, 999, 999, 119, 119, 120,
154649 /* 490 */ 120, 120, 120, 345, 484, 71, 71, 118, 118, 118,
154650 /* 500 */ 118, 117, 117, 116, 116, 116, 115, 424, 1142, 209,
154651 /* 510 */ 411, 523, 1142, 1109, 1571, 378, 252, 269, 342, 487,
154652 /* 520 */ 337, 486, 238, 392, 513, 364, 1109, 1127, 333, 1109,
154653 /* 530 */ 191, 409, 286, 32, 457, 443, 118, 118, 118, 118,
154654 /* 540 */ 117, 117, 116, 116, 116, 115, 424, 121, 122, 112,
154655 /* 550 */ 1165, 1165, 1006, 1009, 999, 999, 119, 119, 120, 120,
154656 /* 560 */ 120, 120, 392, 1142, 1143, 1144, 987, 1142, 1143, 1144,
154657 /* 570 */ 1142, 233, 492, 1492, 481, 478, 477, 6, 163, 546,
154658 /* 580 */ 512, 546, 115, 424, 476, 5, 121, 122, 112, 1165,
154659 /* 590 */ 1165, 1006, 1009, 999, 999, 119, 119, 120, 120, 120,
154660 /* 600 */ 120, 13, 13, 13, 13, 118, 118, 118, 118, 117,
154661 /* 610 */ 117, 116, 116, 116, 115, 424, 403, 502, 408, 546,
154662 /* 620 */ 1486, 544, 1142, 892, 892, 1142, 1143, 1144, 1473, 1142,
154663 /* 630 */ 275, 392, 808, 809, 810, 971, 422, 422, 422, 16,
154664 /* 640 */ 16, 55, 55, 1242, 118, 118, 118, 118, 117, 117,
154665 /* 650 */ 116, 116, 116, 115, 424, 121, 122, 112, 1165, 1165,
154666 /* 660 */ 1006, 1009, 999, 999, 119, 119, 120, 120, 120, 120,
154667 /* 670 */ 392, 1189, 1, 1, 552, 2, 1193, 1142, 1143, 1144,
154668 /* 680 */ 194, 291, 898, 136, 1142, 1143, 1144, 897, 521, 1492,
154669 /* 690 */ 1273, 3, 380, 6, 121, 122, 112, 1165, 1165, 1006,
154670 /* 700 */ 1009, 999, 999, 119, 119, 120, 120, 120, 120, 858,
154671 /* 710 */ 546, 924, 546, 118, 118, 118, 118, 117, 117, 116,
154672 /* 720 */ 116, 116, 115, 424, 266, 266, 1092, 1569, 1142, 551,
154673 /* 730 */ 1569, 1193, 13, 13, 13, 13, 291, 543, 136, 392,
154674 /* 740 */ 485, 421, 420, 966, 344, 1273, 468, 410, 859, 279,
154675 /* 750 */ 140, 221, 118, 118, 118, 118, 117, 117, 116, 116,
154676 /* 760 */ 116, 115, 424, 121, 122, 112, 1165, 1165, 1006, 1009,
154677 /* 770 */ 999, 999, 119, 119, 120, 120, 120, 120, 546, 266,
154678 /* 780 */ 266, 428, 392, 1142, 1143, 1144, 1172, 830, 1172, 468,
154679 /* 790 */ 431, 145, 543, 1146, 401, 314, 439, 302, 838, 1490,
154680 /* 800 */ 71, 71, 412, 6, 1090, 473, 221, 100, 112, 1165,
154681 /* 810 */ 1165, 1006, 1009, 999, 999, 119, 119, 120, 120, 120,
154682 /* 820 */ 120, 118, 118, 118, 118, 117, 117, 116, 116, 116,
154683 /* 830 */ 115, 424, 237, 1425, 546, 451, 428, 287, 986, 546,
154684 /* 840 */ 236, 235, 234, 830, 97, 529, 429, 1265, 1265, 1146,
154685 /* 850 */ 494, 307, 430, 838, 977, 546, 71, 71, 976, 1241,
154686 /* 860 */ 546, 51, 51, 300, 118, 118, 118, 118, 117, 117,
154687 /* 870 */ 116, 116, 116, 115, 424, 194, 103, 70, 70, 266,
154688 /* 880 */ 266, 546, 71, 71, 266, 266, 30, 391, 344, 976,
154689 /* 890 */ 976, 978, 543, 528, 1109, 328, 392, 543, 495, 397,
154690 /* 900 */ 1470, 195, 530, 13, 13, 1358, 240, 1109, 277, 280,
154691 /* 910 */ 1109, 280, 304, 457, 306, 333, 392, 31, 188, 419,
154692 /* 920 */ 121, 122, 112, 1165, 1165, 1006, 1009, 999, 999, 119,
154693 /* 930 */ 119, 120, 120, 120, 120, 142, 392, 365, 457, 986,
154694 /* 940 */ 121, 122, 112, 1165, 1165, 1006, 1009, 999, 999, 119,
154695 /* 950 */ 119, 120, 120, 120, 120, 977, 323, 1142, 326, 976,
154696 /* 960 */ 121, 110, 112, 1165, 1165, 1006, 1009, 999, 999, 119,
154697 /* 970 */ 119, 120, 120, 120, 120, 464, 377, 1185, 118, 118,
154698 /* 980 */ 118, 118, 117, 117, 116, 116, 116, 115, 424, 1142,
154699 /* 990 */ 976, 976, 978, 305, 9, 366, 244, 362, 118, 118,
154700 /* 1000 */ 118, 118, 117, 117, 116, 116, 116, 115, 424, 313,
154701 /* 1010 */ 546, 344, 1142, 1143, 1144, 299, 290, 537, 118, 118,
154702 /* 1020 */ 118, 118, 117, 117, 116, 116, 116, 115, 424, 1263,
154703 /* 1030 */ 1263, 1163, 13, 13, 278, 421, 420, 468, 392, 923,
154704 /* 1040 */ 260, 260, 289, 1169, 1142, 1143, 1144, 189, 1171, 266,
154705 /* 1050 */ 266, 468, 390, 543, 1186, 546, 1170, 263, 144, 489,
154706 /* 1060 */ 922, 546, 543, 122, 112, 1165, 1165, 1006, 1009, 999,
154707 /* 1070 */ 999, 119, 119, 120, 120, 120, 120, 71, 71, 1142,
154708 /* 1080 */ 1172, 1272, 1172, 13, 13, 898, 1070, 1163, 546, 468,
154709 /* 1090 */ 897, 107, 538, 1491, 4, 1268, 1109, 6, 525, 1049,
154710 /* 1100 */ 12, 1071, 1092, 1570, 312, 455, 1570, 520, 541, 1109,
154711 /* 1110 */ 56, 56, 1109, 1489, 423, 1358, 1072, 6, 345, 285,
154712 /* 1120 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
154713 /* 1130 */ 424, 425, 1271, 321, 1142, 1143, 1144, 878, 266, 266,
154714 /* 1140 */ 1277, 107, 538, 535, 4, 1488, 293, 879, 1211, 6,
154715 /* 1150 */ 210, 543, 543, 164, 294, 496, 416, 204, 541, 267,
154716 /* 1160 */ 267, 1214, 398, 511, 499, 204, 266, 266, 396, 531,
154717 /* 1170 */ 8, 986, 543, 519, 546, 922, 458, 105, 105, 543,
154718 /* 1180 */ 1090, 425, 266, 266, 106, 417, 425, 548, 547, 266,
154719 /* 1190 */ 266, 976, 518, 535, 1373, 543, 15, 15, 266, 266,
154720 /* 1200 */ 456, 1120, 543, 266, 266, 1070, 1372, 515, 290, 537,
154721 /* 1210 */ 546, 543, 514, 97, 444, 316, 543, 546, 922, 125,
154722 /* 1220 */ 1071, 986, 976, 976, 978, 979, 27, 105, 105, 401,
154723 /* 1230 */ 343, 1511, 44, 44, 106, 1072, 425, 548, 547, 57,
154724 /* 1240 */ 57, 976, 343, 1511, 107, 538, 546, 4, 462, 401,
154725 /* 1250 */ 214, 1120, 459, 297, 377, 1091, 534, 1309, 546, 539,
154726 /* 1260 */ 398, 541, 290, 537, 104, 244, 102, 526, 58, 58,
154727 /* 1270 */ 546, 199, 976, 976, 978, 979, 27, 1516, 1131, 427,
154728 /* 1280 */ 59, 59, 270, 237, 425, 138, 95, 375, 375, 374,
154729 /* 1290 */ 255, 372, 60, 60, 817, 1180, 535, 546, 273, 546,
154730 /* 1300 */ 1163, 1308, 389, 388, 546, 438, 546, 215, 210, 296,
154731 /* 1310 */ 515, 849, 546, 265, 208, 516, 1476, 295, 274, 61,
154732 /* 1320 */ 61, 62, 62, 308, 986, 109, 45, 45, 46, 46,
154733 /* 1330 */ 105, 105, 1186, 922, 47, 47, 341, 106, 546, 425,
154734 /* 1340 */ 548, 547, 1542, 546, 976, 867, 340, 217, 546, 937,
154735 /* 1350 */ 397, 107, 538, 218, 4, 156, 1163, 938, 158, 546,
154736 /* 1360 */ 49, 49, 1162, 546, 268, 50, 50, 546, 541, 1450,
154737 /* 1370 */ 63, 63, 546, 1449, 216, 976, 976, 978, 979, 27,
154738 /* 1380 */ 446, 64, 64, 546, 460, 65, 65, 546, 318, 14,
154739 /* 1390 */ 14, 425, 1305, 546, 66, 66, 1087, 546, 141, 379,
154740 /* 1400 */ 38, 546, 963, 535, 322, 127, 127, 546, 393, 67,
154741 /* 1410 */ 67, 546, 325, 290, 537, 52, 52, 515, 546, 68,
154742 /* 1420 */ 68, 845, 514, 69, 69, 399, 165, 857, 856, 53,
154743 /* 1430 */ 53, 986, 311, 151, 151, 97, 432, 105, 105, 327,
154744 /* 1440 */ 152, 152, 526, 1048, 106, 1048, 425, 548, 547, 1131,
154745 /* 1450 */ 427, 976, 1032, 270, 968, 239, 329, 243, 375, 375,
154746 /* 1460 */ 374, 255, 372, 940, 941, 817, 1296, 546, 220, 546,
154747 /* 1470 */ 107, 538, 546, 4, 546, 1256, 199, 845, 215, 1036,
154748 /* 1480 */ 296, 1530, 976, 976, 978, 979, 27, 541, 295, 76,
154749 /* 1490 */ 76, 54, 54, 980, 72, 72, 128, 128, 864, 865,
154750 /* 1500 */ 107, 538, 546, 4, 1047, 546, 1047, 533, 469, 546,
154751 /* 1510 */ 425, 546, 450, 1240, 546, 243, 546, 541, 217, 546,
154752 /* 1520 */ 452, 197, 535, 243, 73, 73, 156, 129, 129, 158,
154753 /* 1530 */ 336, 130, 130, 126, 126, 1036, 150, 150, 149, 149,
154754 /* 1540 */ 425, 134, 134, 317, 474, 216, 97, 239, 331, 980,
154755 /* 1550 */ 986, 97, 535, 346, 347, 546, 105, 105, 902, 931,
154756 /* 1560 */ 546, 895, 243, 106, 109, 425, 548, 547, 546, 1505,
154757 /* 1570 */ 976, 828, 99, 538, 139, 4, 546, 133, 133, 393,
154758 /* 1580 */ 986, 1317, 131, 131, 290, 537, 105, 105, 1357, 541,
154759 /* 1590 */ 132, 132, 1292, 106, 1303, 425, 548, 547, 75, 75,
154760 /* 1600 */ 976, 976, 976, 978, 979, 27, 546, 432, 896, 1289,
154761 /* 1610 */ 532, 109, 425, 1363, 546, 1221, 1213, 1202, 258, 546,
154762 /* 1620 */ 349, 546, 1201, 11, 535, 1203, 1524, 351, 77, 77,
154763 /* 1630 */ 376, 976, 976, 978, 979, 27, 74, 74, 353, 213,
154764 /* 1640 */ 301, 43, 43, 48, 48, 437, 310, 201, 303, 1350,
154765 /* 1650 */ 315, 355, 986, 454, 479, 1239, 339, 192, 105, 105,
154766 /* 1660 */ 1422, 1421, 193, 536, 205, 106, 1527, 425, 548, 547,
154767 /* 1670 */ 1180, 167, 976, 270, 247, 1469, 1467, 1177, 375, 375,
154768 /* 1680 */ 374, 255, 372, 200, 369, 817, 400, 83, 79, 82,
154769 /* 1690 */ 1427, 448, 177, 95, 1342, 161, 169, 1339, 215, 440,
154770 /* 1700 */ 296, 172, 173, 976, 976, 978, 979, 27, 295, 174,
154771 /* 1710 */ 175, 441, 472, 223, 1347, 383, 35, 381, 36, 461,
154772 /* 1720 */ 88, 1353, 181, 447, 384, 1416, 227, 467, 259, 229,
154773 /* 1730 */ 186, 488, 470, 324, 1250, 230, 231, 320, 217, 1204,
154774 /* 1740 */ 1438, 1259, 386, 1258, 413, 90, 156, 849, 1541, 158,
154775 /* 1750 */ 206, 415, 1540, 507, 1300, 1257, 94, 348, 1229, 1301,
154776 /* 1760 */ 387, 1510, 1228, 338, 1227, 216, 350, 1539, 498, 283,
154777 /* 1770 */ 284, 1249, 501, 1299, 352, 245, 246, 418, 1298, 354,
154778 /* 1780 */ 1496, 1495, 124, 10, 526, 363, 101, 1324, 253, 96,
154779 /* 1790 */ 510, 1210, 34, 549, 1137, 254, 256, 257, 166, 393,
154780 /* 1800 */ 550, 1199, 1282, 361, 290, 537, 1281, 196, 367, 368,
154781 /* 1810 */ 1194, 153, 1454, 137, 281, 1323, 1455, 804, 154, 426,
154782 /* 1820 */ 198, 155, 1453, 1452, 292, 212, 202, 432, 1402, 203,
154783 /* 1830 */ 271, 135, 288, 78, 1046, 1044, 960, 168, 157, 881,
154784 /* 1840 */ 170, 219, 309, 222, 1060, 176, 964, 159, 402, 84,
154785 /* 1850 */ 178, 404, 85, 86, 87, 160, 1063, 224, 394, 395,
154786 /* 1860 */ 225, 1059, 146, 18, 226, 319, 243, 1174, 466, 228,
154787 /* 1870 */ 1052, 182, 183, 37, 819, 471, 340, 232, 332, 483,
154788 /* 1880 */ 184, 89, 162, 19, 20, 475, 91, 480, 847, 335,
154789 /* 1890 */ 147, 860, 282, 92, 490, 93, 1125, 148, 1012, 1095,
154790 /* 1900 */ 39, 497, 1096, 40, 500, 262, 207, 264, 930, 187,
154791 /* 1910 */ 925, 109, 1111, 1115, 1113, 7, 1099, 242, 33, 1119,

Referenced by yy_find_shift_action().

◆ yy_default

const YYACTIONTYPE yy_default[]
static

Definition at line 155115 of file sqlite3.c.

155121 {
155122 /* 0 */ 1575, 1575, 1575, 1411, 1188, 1297, 1188, 1188, 1188, 1411,
155123 /* 10 */ 1411, 1411, 1188, 1327, 1327, 1464, 1219, 1188, 1188, 1188,
155124 /* 20 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1410, 1188, 1188,
155125 /* 30 */ 1188, 1188, 1494, 1494, 1188, 1188, 1188, 1188, 1188, 1188,
155126 /* 40 */ 1188, 1188, 1188, 1336, 1188, 1188, 1188, 1188, 1188, 1188,
155127 /* 50 */ 1412, 1413, 1188, 1188, 1188, 1463, 1465, 1428, 1346, 1345,
155128 /* 60 */ 1344, 1343, 1446, 1314, 1341, 1334, 1338, 1406, 1407, 1405,
155129 /* 70 */ 1409, 1413, 1412, 1188, 1337, 1377, 1391, 1376, 1188, 1188,
155130 /* 80 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155131 /* 90 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155132 /* 100 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155133 /* 110 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155134 /* 120 */ 1188, 1188, 1188, 1188, 1188, 1188, 1385, 1390, 1396, 1389,
155135 /* 130 */ 1386, 1379, 1378, 1380, 1381, 1188, 1209, 1261, 1188, 1188,
155136 /* 140 */ 1188, 1188, 1482, 1481, 1188, 1188, 1219, 1371, 1370, 1382,
155137 /* 150 */ 1383, 1393, 1392, 1471, 1529, 1528, 1429, 1188, 1188, 1188,
155138 /* 160 */ 1188, 1188, 1188, 1494, 1188, 1188, 1188, 1188, 1188, 1188,
155139 /* 170 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155140 /* 180 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1494, 1494,
155141 /* 190 */ 1188, 1219, 1494, 1494, 1215, 1215, 1321, 1188, 1477, 1297,
155142 /* 200 */ 1288, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155143 /* 210 */ 1188, 1188, 1188, 1188, 1188, 1468, 1466, 1188, 1188, 1188,
155144 /* 220 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155145 /* 230 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155146 /* 240 */ 1188, 1188, 1188, 1188, 1188, 1293, 1188, 1188, 1188, 1188,
155147 /* 250 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1523, 1188, 1441,
155148 /* 260 */ 1275, 1293, 1293, 1293, 1293, 1295, 1276, 1274, 1287, 1220,
155149 /* 270 */ 1195, 1567, 1294, 1316, 1316, 1564, 1340, 1294, 1564, 1236,
155150 /* 280 */ 1545, 1231, 1327, 1327, 1327, 1316, 1321, 1321, 1408, 1294,
155151 /* 290 */ 1287, 1188, 1567, 1302, 1302, 1566, 1566, 1302, 1429, 1349,
155152 /* 300 */ 1355, 1340, 1264, 1340, 1270, 1270, 1270, 1270, 1302, 1206,
155153 /* 310 */ 1340, 1340, 1349, 1355, 1264, 1340, 1264, 1340, 1302, 1206,
155154 /* 320 */ 1445, 1561, 1302, 1206, 1419, 1302, 1206, 1302, 1206, 1419,
155155 /* 330 */ 1262, 1262, 1262, 1251, 1188, 1188, 1419, 1262, 1236, 1262,
155156 /* 340 */ 1251, 1262, 1262, 1512, 1419, 1423, 1423, 1419, 1320, 1315,
155157 /* 350 */ 1320, 1315, 1320, 1315, 1320, 1315, 1302, 1504, 1504, 1330,
155158 /* 360 */ 1330, 1335, 1321, 1414, 1302, 1188, 1335, 1333, 1331, 1340,
155159 /* 370 */ 1212, 1254, 1526, 1526, 1522, 1522, 1522, 1572, 1572, 1477,
155160 /* 380 */ 1538, 1219, 1219, 1219, 1219, 1538, 1238, 1238, 1220, 1220,
155161 /* 390 */ 1219, 1538, 1188, 1188, 1188, 1188, 1188, 1188, 1533, 1188,
155162 /* 400 */ 1430, 1306, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155163 /* 410 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155164 /* 420 */ 1188, 1188, 1188, 1188, 1188, 1360, 1188, 1191, 1474, 1188,
155165 /* 430 */ 1188, 1472, 1188, 1188, 1188, 1188, 1188, 1188, 1307, 1188,
155166 /* 440 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155167 /* 450 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1563, 1188, 1188,
155168 /* 460 */ 1188, 1188, 1188, 1188, 1444, 1443, 1188, 1188, 1304, 1188,
155169 /* 470 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155170 /* 480 */ 1188, 1188, 1234, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155171 /* 490 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188,
155172 /* 500 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1332,

Referenced by yy_find_shift_action().

◆ yy_lookahead

const YYCODETYPE yy_lookahead[]
static

Definition at line 154792 of file sqlite3.c.

154798 {
154799 /* 0 */ 189, 211, 189, 189, 218, 189, 220, 189, 267, 268,
154800 /* 10 */ 269, 189, 210, 189, 228, 189, 267, 268, 269, 19,
154801 /* 20 */ 218, 189, 211, 212, 211, 212, 211, 211, 212, 211,
154802 /* 30 */ 212, 31, 211, 211, 212, 211, 212, 288, 300, 39,
154803 /* 40 */ 21, 189, 304, 43, 44, 45, 46, 47, 48, 49,
154804 /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 225, 19,
154805 /* 60 */ 189, 183, 184, 185, 186, 189, 248, 263, 236, 191,
154806 /* 70 */ 248, 193, 248, 197, 208, 257, 262, 201, 200, 257,
154807 /* 80 */ 200, 257, 81, 43, 44, 45, 46, 47, 48, 49,
154808 /* 90 */ 50, 51, 52, 53, 54, 55, 56, 57, 189, 80,
154809 /* 100 */ 189, 101, 102, 103, 104, 105, 106, 107, 108, 109,
154810 /* 110 */ 110, 111, 234, 235, 234, 235, 305, 306, 305, 118,
154811 /* 120 */ 307, 305, 306, 297, 298, 247, 86, 247, 88, 19,
154812 /* 130 */ 259, 251, 252, 267, 268, 269, 26, 136, 137, 261,
154813 /* 140 */ 121, 101, 102, 103, 104, 105, 106, 107, 108, 109,
154814 /* 150 */ 110, 111, 59, 43, 44, 45, 46, 47, 48, 49,
154815 /* 160 */ 50, 51, 52, 53, 54, 55, 56, 57, 259, 291,
154816 /* 170 */ 105, 106, 107, 108, 109, 110, 111, 158, 189, 69,
154817 /* 180 */ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
154818 /* 190 */ 111, 107, 108, 109, 110, 111, 205, 206, 207, 19,
154819 /* 200 */ 19, 54, 55, 56, 57, 58, 29, 114, 115, 116,
154820 /* 210 */ 33, 101, 102, 103, 104, 105, 106, 107, 108, 109,
154821 /* 220 */ 110, 111, 233, 43, 44, 45, 46, 47, 48, 49,
154822 /* 230 */ 50, 51, 52, 53, 54, 55, 56, 57, 19, 126,
154823 /* 240 */ 127, 148, 65, 24, 214, 200, 59, 67, 101, 102,
154824 /* 250 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 22,
154825 /* 260 */ 189, 111, 43, 44, 45, 46, 47, 48, 49, 50,
154826 /* 270 */ 51, 52, 53, 54, 55, 56, 57, 206, 207, 234,
154827 /* 280 */ 235, 101, 102, 103, 104, 105, 106, 107, 108, 109,
154828 /* 290 */ 110, 111, 247, 76, 107, 114, 59, 267, 268, 269,
154829 /* 300 */ 189, 114, 115, 116, 162, 163, 89, 19, 263, 92,
154830 /* 310 */ 189, 23, 54, 55, 56, 57, 189, 206, 207, 22,
154831 /* 320 */ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
154832 /* 330 */ 111, 43, 44, 45, 46, 47, 48, 49, 50, 51,
154833 /* 340 */ 52, 53, 54, 55, 56, 57, 19, 189, 277, 59,
154834 /* 350 */ 23, 114, 115, 116, 46, 47, 48, 49, 61, 101,
154835 /* 360 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
154836 /* 370 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
154837 /* 380 */ 53, 54, 55, 56, 57, 125, 126, 127, 277, 101,
154838 /* 390 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
154839 /* 400 */ 59, 189, 189, 276, 114, 115, 116, 117, 73, 59,
154840 /* 410 */ 120, 121, 122, 72, 214, 19, 81, 259, 19, 23,
154841 /* 420 */ 130, 81, 72, 24, 211, 212, 221, 119, 101, 102,
154842 /* 430 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 43,
154843 /* 440 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
154844 /* 450 */ 54, 55, 56, 57, 19, 114, 115, 116, 23, 208,
154845 /* 460 */ 125, 248, 189, 189, 114, 115, 116, 267, 268, 269,
154846 /* 470 */ 189, 136, 137, 189, 262, 22, 136, 137, 43, 44,
154847 /* 480 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
154848 /* 490 */ 55, 56, 57, 189, 95, 211, 212, 101, 102, 103,
154849 /* 500 */ 104, 105, 106, 107, 108, 109, 110, 111, 59, 189,
154850 /* 510 */ 111, 189, 59, 76, 294, 295, 117, 118, 119, 120,
154851 /* 520 */ 121, 122, 123, 19, 87, 189, 89, 23, 129, 92,
154852 /* 530 */ 279, 227, 248, 22, 189, 284, 101, 102, 103, 104,
154853 /* 540 */ 105, 106, 107, 108, 109, 110, 111, 43, 44, 45,
154854 /* 550 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
154855 /* 560 */ 56, 57, 19, 114, 115, 116, 23, 114, 115, 116,
154856 /* 570 */ 59, 117, 299, 300, 120, 121, 122, 304, 189, 189,
154857 /* 580 */ 143, 189, 110, 111, 130, 22, 43, 44, 45, 46,
154858 /* 590 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
154859 /* 600 */ 57, 211, 212, 211, 212, 101, 102, 103, 104, 105,
154860 /* 610 */ 106, 107, 108, 109, 110, 111, 226, 189, 226, 189,
154861 /* 620 */ 298, 132, 59, 134, 135, 114, 115, 116, 189, 59,
154862 /* 630 */ 285, 19, 7, 8, 9, 23, 205, 206, 207, 211,
154863 /* 640 */ 212, 211, 212, 221, 101, 102, 103, 104, 105, 106,
154864 /* 650 */ 107, 108, 109, 110, 111, 43, 44, 45, 46, 47,
154865 /* 660 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
154866 /* 670 */ 19, 181, 182, 183, 184, 185, 186, 114, 115, 116,
154867 /* 680 */ 189, 191, 133, 193, 114, 115, 116, 138, 299, 300,
154868 /* 690 */ 200, 22, 201, 304, 43, 44, 45, 46, 47, 48,
154869 /* 700 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 35,
154870 /* 710 */ 189, 141, 189, 101, 102, 103, 104, 105, 106, 107,
154871 /* 720 */ 108, 109, 110, 111, 234, 235, 22, 23, 59, 184,
154872 /* 730 */ 26, 186, 211, 212, 211, 212, 191, 247, 193, 19,
154873 /* 740 */ 66, 105, 106, 73, 189, 200, 189, 226, 74, 226,
154874 /* 750 */ 22, 261, 101, 102, 103, 104, 105, 106, 107, 108,
154875 /* 760 */ 109, 110, 111, 43, 44, 45, 46, 47, 48, 49,
154876 /* 770 */ 50, 51, 52, 53, 54, 55, 56, 57, 189, 234,
154877 /* 780 */ 235, 291, 19, 114, 115, 116, 150, 59, 152, 189,
154878 /* 790 */ 233, 236, 247, 59, 189, 125, 126, 127, 59, 300,
154879 /* 800 */ 211, 212, 128, 304, 100, 19, 261, 156, 45, 46,
154880 /* 810 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
154881 /* 820 */ 57, 101, 102, 103, 104, 105, 106, 107, 108, 109,
154882 /* 830 */ 110, 111, 46, 233, 189, 189, 291, 248, 99, 189,
154883 /* 840 */ 125, 126, 127, 115, 26, 200, 289, 230, 231, 115,
154884 /* 850 */ 200, 16, 189, 114, 115, 189, 211, 212, 119, 221,
154885 /* 860 */ 189, 211, 212, 258, 101, 102, 103, 104, 105, 106,
154886 /* 870 */ 107, 108, 109, 110, 111, 189, 156, 211, 212, 234,
154887 /* 880 */ 235, 189, 211, 212, 234, 235, 22, 201, 189, 150,
154888 /* 890 */ 151, 152, 247, 248, 76, 16, 19, 247, 248, 113,
154889 /* 900 */ 189, 24, 257, 211, 212, 189, 26, 89, 262, 223,
154890 /* 910 */ 92, 225, 77, 189, 79, 129, 19, 53, 226, 248,
154891 /* 920 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
154892 /* 930 */ 53, 54, 55, 56, 57, 236, 19, 271, 189, 99,
154893 /* 940 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
154894 /* 950 */ 53, 54, 55, 56, 57, 115, 77, 59, 79, 119,
154895 /* 960 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
154896 /* 970 */ 53, 54, 55, 56, 57, 259, 22, 23, 101, 102,
154897 /* 980 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 59,
154898 /* 990 */ 150, 151, 152, 158, 22, 244, 24, 246, 101, 102,
154899 /* 1000 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 285,
154900 /* 1010 */ 189, 189, 114, 115, 116, 200, 136, 137, 101, 102,
154901 /* 1020 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 230,
154902 /* 1030 */ 231, 59, 211, 212, 285, 105, 106, 189, 19, 141,
154903 /* 1040 */ 234, 235, 239, 113, 114, 115, 116, 226, 118, 234,
154904 /* 1050 */ 235, 189, 249, 247, 100, 189, 126, 23, 236, 107,
154905 /* 1060 */ 26, 189, 247, 44, 45, 46, 47, 48, 49, 50,
154906 /* 1070 */ 51, 52, 53, 54, 55, 56, 57, 211, 212, 59,
154907 /* 1080 */ 150, 233, 152, 211, 212, 133, 12, 115, 189, 189,
154908 /* 1090 */ 138, 19, 20, 300, 22, 233, 76, 304, 226, 11,
154909 /* 1100 */ 208, 27, 22, 23, 200, 19, 26, 87, 36, 89,
154910 /* 1110 */ 211, 212, 92, 300, 248, 189, 42, 304, 189, 250,
154911 /* 1120 */ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
154912 /* 1130 */ 111, 59, 200, 233, 114, 115, 116, 63, 234, 235,
154913 /* 1140 */ 235, 19, 20, 71, 22, 300, 189, 73, 200, 304,
154914 /* 1150 */ 116, 247, 247, 81, 189, 200, 227, 26, 36, 234,
154915 /* 1160 */ 235, 203, 204, 143, 200, 26, 234, 235, 194, 200,
154916 /* 1170 */ 48, 99, 247, 66, 189, 141, 284, 105, 106, 247,
154917 /* 1180 */ 100, 59, 234, 235, 112, 259, 114, 115, 116, 234,
154918 /* 1190 */ 235, 119, 85, 71, 266, 247, 211, 212, 234, 235,
154919 /* 1200 */ 114, 94, 247, 234, 235, 12, 266, 85, 136, 137,
154920 /* 1210 */ 189, 247, 90, 26, 126, 127, 247, 189, 26, 22,
154921 /* 1220 */ 27, 99, 150, 151, 152, 153, 154, 105, 106, 189,
154922 /* 1230 */ 302, 303, 211, 212, 112, 42, 114, 115, 116, 211,
154923 /* 1240 */ 212, 119, 302, 303, 19, 20, 189, 22, 274, 189,
154924 /* 1250 */ 15, 144, 278, 189, 22, 23, 63, 189, 189, 203,
154925 /* 1260 */ 204, 36, 136, 137, 155, 24, 157, 143, 211, 212,
154926 /* 1270 */ 189, 140, 150, 151, 152, 153, 154, 0, 1, 2,
154927 /* 1280 */ 211, 212, 5, 46, 59, 161, 147, 10, 11, 12,
154928 /* 1290 */ 13, 14, 211, 212, 17, 60, 71, 189, 258, 189,
154929 /* 1300 */ 59, 189, 105, 106, 189, 189, 189, 30, 116, 32,
154930 /* 1310 */ 85, 124, 189, 251, 252, 90, 189, 40, 258, 211,
154931 /* 1320 */ 212, 211, 212, 189, 99, 26, 211, 212, 211, 212,
154932 /* 1330 */ 105, 106, 100, 141, 211, 212, 119, 112, 189, 114,
154933 /* 1340 */ 115, 116, 23, 189, 119, 26, 129, 70, 189, 31,
154934 /* 1350 */ 113, 19, 20, 24, 22, 78, 115, 39, 81, 189,
154935 /* 1360 */ 211, 212, 26, 189, 22, 211, 212, 189, 36, 189,
154936 /* 1370 */ 211, 212, 189, 189, 97, 150, 151, 152, 153, 154,
154937 /* 1380 */ 127, 211, 212, 189, 189, 211, 212, 189, 189, 211,
154938 /* 1390 */ 212, 59, 189, 189, 211, 212, 23, 189, 22, 26,
154939 /* 1400 */ 24, 189, 149, 71, 189, 211, 212, 189, 131, 211,
154940 /* 1410 */ 212, 189, 189, 136, 137, 211, 212, 85, 189, 211,
154941 /* 1420 */ 212, 59, 90, 211, 212, 292, 293, 118, 119, 211,
154942 /* 1430 */ 212, 99, 23, 211, 212, 26, 159, 105, 106, 189,
154943 /* 1440 */ 211, 212, 143, 150, 112, 152, 114, 115, 116, 1,
154944 /* 1450 */ 2, 119, 23, 5, 23, 26, 189, 26, 10, 11,
154945 /* 1460 */ 12, 13, 14, 83, 84, 17, 253, 189, 139, 189,
154946 /* 1470 */ 19, 20, 189, 22, 189, 189, 140, 115, 30, 59,
154947 /* 1480 */ 32, 139, 150, 151, 152, 153, 154, 36, 40, 211,
154948 /* 1490 */ 212, 211, 212, 59, 211, 212, 211, 212, 7, 8,
154949 /* 1500 */ 19, 20, 189, 22, 150, 189, 152, 231, 281, 189,
154950 /* 1510 */ 59, 189, 23, 189, 189, 26, 189, 36, 70, 189,
154951 /* 1520 */ 23, 237, 71, 26, 211, 212, 78, 211, 212, 81,
154952 /* 1530 */ 189, 211, 212, 211, 212, 115, 211, 212, 211, 212,
154953 /* 1540 */ 59, 211, 212, 23, 23, 97, 26, 26, 23, 115,
154954 /* 1550 */ 99, 26, 71, 189, 189, 189, 105, 106, 107, 23,
154955 /* 1560 */ 189, 23, 26, 112, 26, 114, 115, 116, 189, 309,
154956 /* 1570 */ 119, 23, 19, 20, 26, 22, 189, 211, 212, 131,
154957 /* 1580 */ 99, 189, 211, 212, 136, 137, 105, 106, 189, 36,
154958 /* 1590 */ 211, 212, 189, 112, 189, 114, 115, 116, 211, 212,
154959 /* 1600 */ 119, 150, 151, 152, 153, 154, 189, 159, 23, 250,
154960 /* 1610 */ 189, 26, 59, 189, 189, 189, 189, 189, 280, 189,
154961 /* 1620 */ 250, 189, 189, 238, 71, 189, 189, 250, 211, 212,
154962 /* 1630 */ 187, 150, 151, 152, 153, 154, 211, 212, 250, 290,
154963 /* 1640 */ 240, 211, 212, 211, 212, 254, 286, 209, 254, 241,
154964 /* 1650 */ 240, 254, 99, 286, 215, 220, 214, 244, 105, 106,
154965 /* 1660 */ 214, 214, 244, 273, 224, 112, 192, 114, 115, 116,
154966 /* 1670 */ 60, 290, 119, 5, 139, 196, 196, 38, 10, 11,
154967 /* 1680 */ 12, 13, 14, 238, 240, 17, 196, 148, 287, 287,
154968 /* 1690 */ 276, 113, 22, 147, 241, 43, 229, 241, 30, 18,
154969 /* 1700 */ 32, 232, 232, 150, 151, 152, 153, 154, 40, 232,
154970 /* 1710 */ 232, 196, 18, 195, 265, 265, 264, 241, 264, 196,
154971 /* 1720 */ 155, 229, 229, 241, 241, 241, 195, 62, 196, 195,
154972 /* 1730 */ 22, 113, 216, 196, 222, 195, 195, 282, 70, 196,
154973 /* 1740 */ 283, 213, 216, 213, 64, 22, 78, 124, 219, 81,
154974 /* 1750 */ 162, 111, 219, 142, 256, 213, 113, 255, 213, 256,
154975 /* 1760 */ 216, 303, 215, 213, 213, 97, 255, 213, 216, 275,
154976 /* 1770 */ 275, 222, 216, 256, 255, 196, 91, 82, 256, 255,
154977 /* 1780 */ 308, 308, 146, 22, 143, 196, 155, 260, 25, 145,
154978 /* 1790 */ 144, 199, 26, 198, 13, 190, 190, 6, 293, 131,
154979 /* 1800 */ 188, 188, 245, 244, 136, 137, 245, 243, 242, 241,
154980 /* 1810 */ 188, 202, 208, 217, 217, 260, 208, 4, 202, 3,
154981 /* 1820 */ 22, 202, 208, 208, 160, 15, 209, 159, 270, 209,
154982 /* 1830 */ 98, 16, 272, 208, 23, 23, 137, 148, 128, 20,
154983 /* 1840 */ 140, 24, 16, 142, 1, 140, 149, 128, 61, 53,
154984 /* 1850 */ 148, 37, 53, 53, 53, 128, 114, 34, 296, 296,
154985 /* 1860 */ 139, 1, 5, 22, 113, 158, 26, 75, 41, 139,
154986 /* 1870 */ 68, 68, 113, 24, 20, 19, 129, 123, 23, 96,
154987 /* 1880 */ 22, 22, 37, 22, 22, 67, 22, 67, 59, 24,
154988 /* 1890 */ 23, 28, 67, 147, 22, 26, 23, 23, 23, 23,
154989 /* 1900 */ 22, 24, 23, 22, 24, 23, 139, 23, 114, 22,
154990 /* 1910 */ 141, 26, 88, 75, 86, 44, 23, 34, 22, 75,
154991 /* 1920 */ 34, 24, 34, 34, 34, 93, 34, 26, 26, 34,
154992 /* 1930 */ 23, 23, 23, 23, 23, 11, 23, 22, 26, 22,
154993 /* 1940 */ 22, 133, 23, 23, 22, 22, 139, 26, 139, 23,
154994 /* 1950 */ 15, 1, 1, 310, 310, 310, 310, 310, 310, 310,
154995 /* 1960 */ 139, 139, 310, 310, 310, 310, 310, 310, 310, 310,
154996 /* 1970 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
154997 /* 1980 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
154998 /* 1990 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
154999 /* 2000 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155000 /* 2010 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155001 /* 2020 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155002 /* 2030 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155003 /* 2040 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155004 /* 2050 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155005 /* 2060 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155006 /* 2070 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155007 /* 2080 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
155008 /* 2090 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,

Referenced by yy_find_shift_action().

◆ yy_reduce_ofst

const short yy_reduce_ofst[]
static

Definition at line 155073 of file sqlite3.c.

155079 {
155080 /* 0 */ 490, -122, 545, 645, 650, -120, -189, -187, -184, -182,
155081 /* 10 */ -178, -176, 45, 30, 200, -251, -134, 390, 392, 521,
155082 /* 20 */ 523, 213, 692, 821, 284, 589, 872, 666, 671, 866,
155083 /* 30 */ 71, 111, 273, 389, 686, 815, 904, 932, 948, 955,
155084 /* 40 */ 964, 969, -259, -259, -259, -259, -259, -259, -259, -259,
155085 /* 50 */ -259, -259, -259, -259, -259, -259, -259, -259, -259, -259,
155086 /* 60 */ -259, -259, -259, -259, -259, -259, -259, -259, -259, -259,
155087 /* 70 */ -259, -259, -259, -259, -259, -259, -259, -259, 428, 430,
155088 /* 80 */ 899, 985, 1021, 1028, 1057, 1069, 1081, 1108, 1110, 1115,
155089 /* 90 */ 1117, 1123, 1149, 1154, 1159, 1170, 1174, 1178, 1183, 1194,
155090 /* 100 */ 1198, 1204, 1208, 1212, 1218, 1222, 1229, 1278, 1280, 1283,
155091 /* 110 */ 1285, 1313, 1316, 1320, 1322, 1325, 1327, 1330, 1366, 1371,
155092 /* 120 */ 1379, 1387, 1417, 1425, 1430, 1432, -259, -259, -259, -259,
155093 /* 130 */ -259, -259, -259, -259, -259, 557, 974, -214, -174, -9,
155094 /* 140 */ 431, -124, 806, 925, 806, 925, 251, 928, 940, -259,
155095 /* 150 */ -259, -259, -259, -198, -198, -198, 127, -186, -168, 212,
155096 /* 160 */ 646, 617, 799, -262, 555, 220, 220, 491, 605, 1040,
155097 /* 170 */ 1060, 699, -11, 600, 848, 862, 345, -129, 724, -91,
155098 /* 180 */ 158, 749, 716, 900, 304, 822, 929, 926, 499, 793,
155099 /* 190 */ 322, 892, 813, 845, 958, 1056, 751, 905, 1133, 1062,
155100 /* 200 */ 803, -210, -185, -179, -148, -167, -89, 121, 274, 281,
155101 /* 210 */ 320, 336, 439, 663, 711, 957, 965, 1064, 1068, 1112,
155102 /* 220 */ 1116, -196, 1127, 1134, 1180, 1184, 1195, 1199, 1203, 1215,
155103 /* 230 */ 1223, 1250, 1267, 1286, 205, 422, 638, 1324, 1341, 1364,
155104 /* 240 */ 1365, 1213, 1392, 1399, 1403, 869, 1260, 1405, 1421, 1276,
155105 /* 250 */ 1424, 121, 1426, 1427, 1428, 1433, 1436, 1437, 1227, 1338,
155106 /* 260 */ 1284, 1359, 1370, 1377, 1388, 1213, 1284, 1284, 1385, 1438,
155107 /* 270 */ 1443, 1349, 1400, 1391, 1394, 1360, 1408, 1410, 1367, 1439,
155108 /* 280 */ 1440, 1435, 1442, 1446, 1447, 1397, 1413, 1418, 1390, 1444,
155109 /* 290 */ 1445, 1474, 1381, 1479, 1480, 1401, 1402, 1490, 1414, 1449,
155110 /* 300 */ 1452, 1453, 1467, 1456, 1469, 1470, 1477, 1478, 1515, 1518,
155111 /* 310 */ 1476, 1482, 1450, 1454, 1492, 1483, 1493, 1484, 1523, 1531,
155112 /* 320 */ 1457, 1455, 1532, 1534, 1516, 1537, 1540, 1543, 1541, 1526,
155113 /* 330 */ 1528, 1530, 1542, 1512, 1529, 1533, 1544, 1545, 1547, 1550,
155114 /* 340 */ 1549, 1551, 1554, 1458, 1552, 1494, 1495, 1556, 1498, 1502,

◆ yy_shift_ofst

const unsigned short int yy_shift_ofst[]
static

Definition at line 155012 of file sqlite3.c.

155018 {
155019 /* 0 */ 1448, 1277, 1668, 1072, 1072, 340, 1122, 1225, 1332, 1481,
155020 /* 10 */ 1481, 1481, 335, 0, 0, 180, 897, 1481, 1481, 1481,
155021 /* 20 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
155022 /* 30 */ 930, 930, 1020, 1020, 290, 1, 340, 340, 340, 340,
155023 /* 40 */ 340, 340, 40, 110, 219, 288, 327, 396, 435, 504,
155024 /* 50 */ 543, 612, 651, 720, 877, 897, 897, 897, 897, 897,
155025 /* 60 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897,
155026 /* 70 */ 897, 897, 897, 917, 897, 1019, 763, 763, 1451, 1481,
155027 /* 80 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
155028 /* 90 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
155029 /* 100 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
155030 /* 110 */ 1481, 1481, 1553, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
155031 /* 120 */ 1481, 1481, 1481, 1481, 1481, 1481, 147, 258, 258, 258,
155032 /* 130 */ 258, 258, 79, 65, 84, 449, 19, 786, 449, 636,
155033 /* 140 */ 636, 449, 880, 880, 880, 880, 113, 142, 142, 472,
155034 /* 150 */ 150, 1962, 1962, 399, 399, 399, 93, 237, 341, 237,
155035 /* 160 */ 237, 1074, 1074, 437, 350, 704, 1080, 449, 449, 449,
155036 /* 170 */ 449, 449, 449, 449, 449, 449, 449, 449, 449, 449,
155037 /* 180 */ 449, 449, 449, 449, 449, 449, 449, 449, 818, 818,
155038 /* 190 */ 449, 1088, 217, 217, 734, 734, 1124, 1126, 1962, 1962,
155039 /* 200 */ 1962, 739, 840, 840, 453, 454, 511, 187, 563, 570,
155040 /* 210 */ 898, 669, 449, 449, 449, 449, 449, 449, 449, 449,
155041 /* 220 */ 449, 670, 449, 449, 449, 449, 449, 449, 449, 449,
155042 /* 230 */ 449, 449, 449, 449, 674, 674, 674, 449, 449, 449,
155043 /* 240 */ 449, 1034, 449, 449, 449, 972, 1107, 449, 449, 1193,
155044 /* 250 */ 449, 449, 449, 449, 449, 449, 449, 449, 260, 177,
155045 /* 260 */ 489, 1241, 1241, 1241, 1241, 1192, 489, 489, 952, 1197,
155046 /* 270 */ 625, 1235, 1131, 181, 181, 1086, 1139, 1131, 1086, 1187,
155047 /* 280 */ 1319, 1237, 1318, 1318, 1318, 181, 1299, 1299, 1109, 1336,
155048 /* 290 */ 549, 1376, 1610, 1535, 1535, 1639, 1639, 1535, 1539, 1578,
155049 /* 300 */ 1670, 1546, 1652, 1546, 1681, 1681, 1681, 1681, 1535, 1694,
155050 /* 310 */ 1546, 1546, 1578, 1670, 1652, 1546, 1652, 1546, 1535, 1694,
155051 /* 320 */ 1565, 1665, 1535, 1694, 1708, 1535, 1694, 1535, 1694, 1708,
155052 /* 330 */ 1618, 1618, 1618, 1680, 1723, 1723, 1708, 1618, 1623, 1618,
155053 /* 340 */ 1680, 1618, 1618, 1588, 1708, 1640, 1640, 1708, 1611, 1643,
155054 /* 350 */ 1611, 1643, 1611, 1643, 1611, 1643, 1535, 1685, 1685, 1695,
155055 /* 360 */ 1695, 1636, 1641, 1761, 1535, 1631, 1636, 1644, 1646, 1546,
155056 /* 370 */ 1763, 1766, 1781, 1781, 1791, 1791, 1791, 1962, 1962, 1962,
155057 /* 380 */ 1962, 1962, 1962, 1962, 1962, 1962, 1962, 1962, 1962, 1962,
155058 /* 390 */ 1962, 1962, 308, 835, 954, 1232, 879, 715, 728, 1373,
155059 /* 400 */ 864, 1329, 1253, 1409, 297, 1431, 1489, 1497, 1520, 1521,
155060 /* 410 */ 1525, 1362, 1309, 1491, 1217, 1420, 1429, 1536, 1380, 1538,
155061 /* 420 */ 1293, 1354, 1548, 1585, 1434, 1342, 1813, 1816, 1798, 1664,
155062 /* 430 */ 1810, 1732, 1815, 1811, 1812, 1699, 1689, 1710, 1817, 1700,
155063 /* 440 */ 1819, 1701, 1826, 1843, 1705, 1697, 1719, 1787, 1814, 1702,
155064 /* 450 */ 1796, 1799, 1800, 1801, 1727, 1742, 1823, 1721, 1860, 1857,
155065 /* 460 */ 1841, 1751, 1707, 1802, 1840, 1803, 1792, 1827, 1730, 1759,
155066 /* 470 */ 1849, 1854, 1856, 1747, 1754, 1858, 1818, 1859, 1861, 1855,
155067 /* 480 */ 1862, 1820, 1829, 1865, 1783, 1863, 1864, 1825, 1845, 1867,
155068 /* 490 */ 1746, 1872, 1873, 1874, 1875, 1869, 1876, 1878, 1877, 1879,
155069 /* 500 */ 1881, 1880, 1767, 1882, 1884, 1794, 1883, 1887, 1769, 1885,

Referenced by yy_find_shift_action().

◆ yyFallback

const YYCODETYPE yyFallback[]
static

Definition at line 155190 of file sqlite3.c.

155196 {
155197 0, /* $ => nothing */
155198 0, /* SEMI => nothing */
155199 59, /* EXPLAIN => ID */
155200 59, /* QUERY => ID */
155201 59, /* PLAN => ID */
155202 59, /* BEGIN => ID */
155203 0, /* TRANSACTION => nothing */
155204 59, /* DEFERRED => ID */
155205 59, /* IMMEDIATE => ID */
155206 59, /* EXCLUSIVE => ID */
155207 0, /* COMMIT => nothing */
155208 59, /* END => ID */
155209 59, /* ROLLBACK => ID */
155210 59, /* SAVEPOINT => ID */
155211 59, /* RELEASE => ID */
155212 0, /* TO => nothing */
155213 0, /* TABLE => nothing */
155214 0, /* CREATE => nothing */
155215 59, /* IF => ID */
155216 0, /* NOT => nothing */
155217 0, /* EXISTS => nothing */
155218 59, /* TEMP => ID */
155219 0, /* LP => nothing */
155220 0, /* RP => nothing */
155221 0, /* AS => nothing */
155222 59, /* WITHOUT => ID */
155223 0, /* COMMA => nothing */
155224 59, /* ABORT => ID */
155225 59, /* ACTION => ID */
155226 59, /* AFTER => ID */
155227 59, /* ANALYZE => ID */
155228 59, /* ASC => ID */
155229 59, /* ATTACH => ID */
155230 59, /* BEFORE => ID */
155231 59, /* BY => ID */
155232 59, /* CASCADE => ID */
155233 59, /* CAST => ID */
155234 59, /* CONFLICT => ID */
155235 59, /* DATABASE => ID */
155236 59, /* DESC => ID */
155237 59, /* DETACH => ID */
155238 59, /* EACH => ID */
155239 59, /* FAIL => ID */
155240 0, /* OR => nothing */
155241 0, /* AND => nothing */
155242 0, /* IS => nothing */
155243 59, /* MATCH => ID */
155244 59, /* LIKE_KW => ID */
155245 0, /* BETWEEN => nothing */
155246 0, /* IN => nothing */
155247 0, /* ISNULL => nothing */
155248 0, /* NOTNULL => nothing */
155249 0, /* NE => nothing */
155250 0, /* EQ => nothing */
155251 0, /* GT => nothing */
155252 0, /* LE => nothing */
155253 0, /* LT => nothing */
155254 0, /* GE => nothing */
155255 0, /* ESCAPE => nothing */
155256 0, /* ID => nothing */
155257 59, /* COLUMNKW => ID */
155258 59, /* DO => ID */
155259 59, /* FOR => ID */
155260 59, /* IGNORE => ID */
155261 59, /* INITIALLY => ID */
155262 59, /* INSTEAD => ID */
155263 59, /* NO => ID */
155264 59, /* KEY => ID */
155265 59, /* OF => ID */
155266 59, /* OFFSET => ID */
155267 59, /* PRAGMA => ID */
155268 59, /* RAISE => ID */
155269 59, /* RECURSIVE => ID */
155270 59, /* REPLACE => ID */
155271 59, /* RESTRICT => ID */
155272 59, /* ROW => ID */
155273 59, /* ROWS => ID */
155274 59, /* TRIGGER => ID */
155275 59, /* VACUUM => ID */
155276 59, /* VIEW => ID */
155277 59, /* VIRTUAL => ID */
155278 59, /* WITH => ID */
155279 59, /* NULLS => ID */
155280 59, /* FIRST => ID */
155281 59, /* LAST => ID */
155282 59, /* CURRENT => ID */
155283 59, /* FOLLOWING => ID */
155284 59, /* PARTITION => ID */
155285 59, /* PRECEDING => ID */
155286 59, /* RANGE => ID */
155287 59, /* UNBOUNDED => ID */
155288 59, /* EXCLUDE => ID */
155289 59, /* GROUPS => ID */
155290 59, /* OTHERS => ID */
155291 59, /* TIES => ID */
155292 59, /* GENERATED => ID */
155293 59, /* ALWAYS => ID */
155294 59, /* REINDEX => ID */
155295 59, /* RENAME => ID */
155296 59, /* CTIME_KW => ID */
155297 0, /* ANY => nothing */
155298 0, /* BITAND => nothing */
155299 0, /* BITOR => nothing */
155300 0, /* LSHIFT => nothing */
155301 0, /* RSHIFT => nothing */
155302 0, /* PLUS => nothing */
155303 0, /* MINUS => nothing */
155304 0, /* STAR => nothing */
155305 0, /* SLASH => nothing */
155306 0, /* REM => nothing */
155307 0, /* CONCAT => nothing */
155308 0, /* COLLATE => nothing */
155309 0, /* BITNOT => nothing */
155310 0, /* ON => nothing */
155311 0, /* INDEXED => nothing */
155312 0, /* STRING => nothing */
155313 0, /* JOIN_KW => nothing */
155314 0, /* CONSTRAINT => nothing */
155315 0, /* DEFAULT => nothing */
155316 0, /* NULL => nothing */
155317 0, /* PRIMARY => nothing */
155318 0, /* UNIQUE => nothing */
155319 0, /* CHECK => nothing */
155320 0, /* REFERENCES => nothing */
155321 0, /* AUTOINCR => nothing */
155322 0, /* INSERT => nothing */
155323 0, /* DELETE => nothing */
155324 0, /* UPDATE => nothing */
155325 0, /* SET => nothing */
155326 0, /* DEFERRABLE => nothing */
155327 0, /* FOREIGN => nothing */
155328 0, /* DROP => nothing */
155329 0, /* UNION => nothing */
155330 0, /* ALL => nothing */
155331 0, /* EXCEPT => nothing */
155332 0, /* INTERSECT => nothing */
155333 0, /* SELECT => nothing */
155334 0, /* VALUES => nothing */
155335 0, /* DISTINCT => nothing */
155336 0, /* DOT => nothing */
155337 0, /* FROM => nothing */
155338 0, /* JOIN => nothing */
155339 0, /* USING => nothing */
155340 0, /* ORDER => nothing */
155341 0, /* GROUP => nothing */
155342 0, /* HAVING => nothing */
155343 0, /* LIMIT => nothing */
155344 0, /* WHERE => nothing */
155345 0, /* INTO => nothing */
155346 0, /* NOTHING => nothing */
155347 0, /* FLOAT => nothing */
155348 0, /* BLOB => nothing */
155349 0, /* INTEGER => nothing */
155350 0, /* VARIABLE => nothing */
155351 0, /* CASE => nothing */
155352 0, /* WHEN => nothing */
155353 0, /* THEN => nothing */
155354 0, /* ELSE => nothing */
155355 0, /* INDEX => nothing */
155356 0, /* ALTER => nothing */
155357 0, /* ADD => nothing */
155358 0, /* WINDOW => nothing */
155359 0, /* OVER => nothing */
155360 0, /* FILTER => nothing */
155361 0, /* COLUMN => nothing */
155362 0, /* AGG_FUNCTION => nothing */
155363 0, /* AGG_COLUMN => nothing */
155364 0, /* TRUEFALSE => nothing */
155365 0, /* ISNOT => nothing */
155366 0, /* FUNCTION => nothing */
155367 0, /* UMINUS => nothing */
155368 0, /* UPLUS => nothing */
155369 0, /* TRUTH => nothing */
155370 0, /* REGISTER => nothing */
155371 0, /* VECTOR => nothing */
155372 0, /* SELECT_COLUMN => nothing */

Referenced by yy_find_shift_action().

◆ yyRuleInfoLhs

const YYCODETYPE yyRuleInfoLhs[]
static

Definition at line 156667 of file sqlite3.c.

156673 {
156674 185, /* (0) explain ::= EXPLAIN */
156675 185, /* (1) explain ::= EXPLAIN QUERY PLAN */
156676 184, /* (2) cmdx ::= cmd */
156677 186, /* (3) cmd ::= BEGIN transtype trans_opt */
156678 187, /* (4) transtype ::= */
156679 187, /* (5) transtype ::= DEFERRED */
156680 187, /* (6) transtype ::= IMMEDIATE */
156681 187, /* (7) transtype ::= EXCLUSIVE */
156682 186, /* (8) cmd ::= COMMIT|END trans_opt */
156683 186, /* (9) cmd ::= ROLLBACK trans_opt */
156684 186, /* (10) cmd ::= SAVEPOINT nm */
156685 186, /* (11) cmd ::= RELEASE savepoint_opt nm */
156686 186, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
156687 191, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
156688 193, /* (14) createkw ::= CREATE */
156689 195, /* (15) ifnotexists ::= */
156690 195, /* (16) ifnotexists ::= IF NOT EXISTS */
156691 194, /* (17) temp ::= TEMP */
156692 194, /* (18) temp ::= */
156693 192, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
156694 192, /* (20) create_table_args ::= AS select */
156695 199, /* (21) table_options ::= */
156696 199, /* (22) table_options ::= WITHOUT nm */
156697 201, /* (23) columnname ::= nm typetoken */
156698 203, /* (24) typetoken ::= */
156699 203, /* (25) typetoken ::= typename LP signed RP */
156700 203, /* (26) typetoken ::= typename LP signed COMMA signed RP */
156701 204, /* (27) typename ::= typename ID|STRING */
156702 208, /* (28) scanpt ::= */
156703 209, /* (29) scantok ::= */
156704 210, /* (30) ccons ::= CONSTRAINT nm */
156705 210, /* (31) ccons ::= DEFAULT scantok term */
156706 210, /* (32) ccons ::= DEFAULT LP expr RP */
156707 210, /* (33) ccons ::= DEFAULT PLUS scantok term */
156708 210, /* (34) ccons ::= DEFAULT MINUS scantok term */
156709 210, /* (35) ccons ::= DEFAULT scantok ID|INDEXED */
156710 210, /* (36) ccons ::= NOT NULL onconf */
156711 210, /* (37) ccons ::= PRIMARY KEY sortorder onconf autoinc */
156712 210, /* (38) ccons ::= UNIQUE onconf */
156713 210, /* (39) ccons ::= CHECK LP expr RP */
156714 210, /* (40) ccons ::= REFERENCES nm eidlist_opt refargs */
156715 210, /* (41) ccons ::= defer_subclause */
156716 210, /* (42) ccons ::= COLLATE ID|STRING */
156717 219, /* (43) generated ::= LP expr RP */
156718 219, /* (44) generated ::= LP expr RP ID */
156719 215, /* (45) autoinc ::= */
156720 215, /* (46) autoinc ::= AUTOINCR */
156721 217, /* (47) refargs ::= */
156722 217, /* (48) refargs ::= refargs refarg */
156723 220, /* (49) refarg ::= MATCH nm */
156724 220, /* (50) refarg ::= ON INSERT refact */
156725 220, /* (51) refarg ::= ON DELETE refact */
156726 220, /* (52) refarg ::= ON UPDATE refact */
156727 221, /* (53) refact ::= SET NULL */
156728 221, /* (54) refact ::= SET DEFAULT */
156729 221, /* (55) refact ::= CASCADE */
156730 221, /* (56) refact ::= RESTRICT */
156731 221, /* (57) refact ::= NO ACTION */
156732 218, /* (58) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
156733 218, /* (59) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
156734 222, /* (60) init_deferred_pred_opt ::= */
156735 222, /* (61) init_deferred_pred_opt ::= INITIALLY DEFERRED */
156736 222, /* (62) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
156737 198, /* (63) conslist_opt ::= */
156738 224, /* (64) tconscomma ::= COMMA */
156739 225, /* (65) tcons ::= CONSTRAINT nm */
156740 225, /* (66) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
156741 225, /* (67) tcons ::= UNIQUE LP sortlist RP onconf */
156742 225, /* (68) tcons ::= CHECK LP expr RP onconf */
156743 225, /* (69) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
156744 228, /* (70) defer_subclause_opt ::= */
156745 213, /* (71) onconf ::= */
156746 213, /* (72) onconf ::= ON CONFLICT resolvetype */
156747 229, /* (73) orconf ::= */
156748 229, /* (74) orconf ::= OR resolvetype */
156749 230, /* (75) resolvetype ::= IGNORE */
156750 230, /* (76) resolvetype ::= REPLACE */
156751 186, /* (77) cmd ::= DROP TABLE ifexists fullname */
156752 232, /* (78) ifexists ::= IF EXISTS */
156753 232, /* (79) ifexists ::= */
156754 186, /* (80) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
156755 186, /* (81) cmd ::= DROP VIEW ifexists fullname */
156756 186, /* (82) cmd ::= select */
156757 200, /* (83) select ::= WITH wqlist selectnowith */
156758 200, /* (84) select ::= WITH RECURSIVE wqlist selectnowith */
156759 200, /* (85) select ::= selectnowith */
156760 234, /* (86) selectnowith ::= selectnowith multiselect_op oneselect */
156761 237, /* (87) multiselect_op ::= UNION */
156762 237, /* (88) multiselect_op ::= UNION ALL */
156763 237, /* (89) multiselect_op ::= EXCEPT|INTERSECT */
156764 235, /* (90) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
156765 235, /* (91) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
156766 247, /* (92) values ::= VALUES LP nexprlist RP */
156767 247, /* (93) values ::= values COMMA LP nexprlist RP */
156768 238, /* (94) distinct ::= DISTINCT */
156769 238, /* (95) distinct ::= ALL */
156770 238, /* (96) distinct ::= */
156771 249, /* (97) sclp ::= */
156772 239, /* (98) selcollist ::= sclp scanpt expr scanpt as */
156773 239, /* (99) selcollist ::= sclp scanpt STAR */
156774 239, /* (100) selcollist ::= sclp scanpt nm DOT STAR */
156775 250, /* (101) as ::= AS nm */
156776 250, /* (102) as ::= */
156777 240, /* (103) from ::= */
156778 240, /* (104) from ::= FROM seltablist */
156779 252, /* (105) stl_prefix ::= seltablist joinop */
156780 252, /* (106) stl_prefix ::= */
156781 251, /* (107) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
156782 251, /* (108) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
156783 251, /* (109) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
156784 251, /* (110) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
156785 196, /* (111) dbnm ::= */
156786 196, /* (112) dbnm ::= DOT nm */
156787 233, /* (113) fullname ::= nm */
156788 233, /* (114) fullname ::= nm DOT nm */
156789 258, /* (115) xfullname ::= nm */
156790 258, /* (116) xfullname ::= nm DOT nm */
156791 258, /* (117) xfullname ::= nm DOT nm AS nm */
156792 258, /* (118) xfullname ::= nm AS nm */
156793 253, /* (119) joinop ::= COMMA|JOIN */
156794 253, /* (120) joinop ::= JOIN_KW JOIN */
156795 253, /* (121) joinop ::= JOIN_KW nm JOIN */
156796 253, /* (122) joinop ::= JOIN_KW nm nm JOIN */
156797 255, /* (123) on_opt ::= ON expr */
156798 255, /* (124) on_opt ::= */
156799 254, /* (125) indexed_opt ::= */
156800 254, /* (126) indexed_opt ::= INDEXED BY nm */
156801 254, /* (127) indexed_opt ::= NOT INDEXED */
156802 256, /* (128) using_opt ::= USING LP idlist RP */
156803 256, /* (129) using_opt ::= */
156804 244, /* (130) orderby_opt ::= */
156805 244, /* (131) orderby_opt ::= ORDER BY sortlist */
156806 226, /* (132) sortlist ::= sortlist COMMA expr sortorder nulls */
156807 226, /* (133) sortlist ::= expr sortorder nulls */
156808 214, /* (134) sortorder ::= ASC */
156809 214, /* (135) sortorder ::= DESC */
156810 214, /* (136) sortorder ::= */
156811 260, /* (137) nulls ::= NULLS FIRST */
156812 260, /* (138) nulls ::= NULLS LAST */
156813 260, /* (139) nulls ::= */
156814 242, /* (140) groupby_opt ::= */
156815 242, /* (141) groupby_opt ::= GROUP BY nexprlist */
156816 243, /* (142) having_opt ::= */
156817 243, /* (143) having_opt ::= HAVING expr */
156818 245, /* (144) limit_opt ::= */
156819 245, /* (145) limit_opt ::= LIMIT expr */
156820 245, /* (146) limit_opt ::= LIMIT expr OFFSET expr */
156821 245, /* (147) limit_opt ::= LIMIT expr COMMA expr */
156822 186, /* (148) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
156823 241, /* (149) where_opt ::= */
156824 241, /* (150) where_opt ::= WHERE expr */
156825 186, /* (151) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt */
156826 262, /* (152) setlist ::= setlist COMMA nm EQ expr */
156827 262, /* (153) setlist ::= setlist COMMA LP idlist RP EQ expr */
156828 262, /* (154) setlist ::= nm EQ expr */
156829 262, /* (155) setlist ::= LP idlist RP EQ expr */
156830 186, /* (156) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
156831 186, /* (157) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
156832 265, /* (158) upsert ::= */
156833 265, /* (159) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
156834 265, /* (160) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
156835 265, /* (161) upsert ::= ON CONFLICT DO NOTHING */
156836 263, /* (162) insert_cmd ::= INSERT orconf */
156837 263, /* (163) insert_cmd ::= REPLACE */
156838 264, /* (164) idlist_opt ::= */
156839 264, /* (165) idlist_opt ::= LP idlist RP */
156840 259, /* (166) idlist ::= idlist COMMA nm */
156841 259, /* (167) idlist ::= nm */
156842 212, /* (168) expr ::= LP expr RP */
156843 212, /* (169) expr ::= ID|INDEXED */
156844 212, /* (170) expr ::= JOIN_KW */
156845 212, /* (171) expr ::= nm DOT nm */
156846 212, /* (172) expr ::= nm DOT nm DOT nm */
156847 211, /* (173) term ::= NULL|FLOAT|BLOB */
156848 211, /* (174) term ::= STRING */
156849 211, /* (175) term ::= INTEGER */
156850 212, /* (176) expr ::= VARIABLE */
156851 212, /* (177) expr ::= expr COLLATE ID|STRING */
156852 212, /* (178) expr ::= CAST LP expr AS typetoken RP */
156853 212, /* (179) expr ::= ID|INDEXED LP distinct exprlist RP */
156854 212, /* (180) expr ::= ID|INDEXED LP STAR RP */
156855 212, /* (181) expr ::= ID|INDEXED LP distinct exprlist RP filter_over */
156856 212, /* (182) expr ::= ID|INDEXED LP STAR RP filter_over */
156857 211, /* (183) term ::= CTIME_KW */
156858 212, /* (184) expr ::= LP nexprlist COMMA expr RP */
156859 212, /* (185) expr ::= expr AND expr */
156860 212, /* (186) expr ::= expr OR expr */
156861 212, /* (187) expr ::= expr LT|GT|GE|LE expr */
156862 212, /* (188) expr ::= expr EQ|NE expr */
156863 212, /* (189) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
156864 212, /* (190) expr ::= expr PLUS|MINUS expr */
156865 212, /* (191) expr ::= expr STAR|SLASH|REM expr */
156866 212, /* (192) expr ::= expr CONCAT expr */
156867 267, /* (193) likeop ::= NOT LIKE_KW|MATCH */
156868 212, /* (194) expr ::= expr likeop expr */
156869 212, /* (195) expr ::= expr likeop expr ESCAPE expr */
156870 212, /* (196) expr ::= expr ISNULL|NOTNULL */
156871 212, /* (197) expr ::= expr NOT NULL */
156872 212, /* (198) expr ::= expr IS expr */
156873 212, /* (199) expr ::= expr IS NOT expr */
156874 212, /* (200) expr ::= NOT expr */
156875 212, /* (201) expr ::= BITNOT expr */
156876 212, /* (202) expr ::= PLUS|MINUS expr */
156877 268, /* (203) between_op ::= BETWEEN */
156878 268, /* (204) between_op ::= NOT BETWEEN */
156879 212, /* (205) expr ::= expr between_op expr AND expr */
156880 269, /* (206) in_op ::= IN */
156881 269, /* (207) in_op ::= NOT IN */
156882 212, /* (208) expr ::= expr in_op LP exprlist RP */
156883 212, /* (209) expr ::= LP select RP */
156884 212, /* (210) expr ::= expr in_op LP select RP */
156885 212, /* (211) expr ::= expr in_op nm dbnm paren_exprlist */
156886 212, /* (212) expr ::= EXISTS LP select RP */
156887 212, /* (213) expr ::= CASE case_operand case_exprlist case_else END */
156888 272, /* (214) case_exprlist ::= case_exprlist WHEN expr THEN expr */
156889 272, /* (215) case_exprlist ::= WHEN expr THEN expr */
156890 273, /* (216) case_else ::= ELSE expr */
156891 273, /* (217) case_else ::= */
156892 271, /* (218) case_operand ::= expr */
156893 271, /* (219) case_operand ::= */
156894 257, /* (220) exprlist ::= */
156895 248, /* (221) nexprlist ::= nexprlist COMMA expr */
156896 248, /* (222) nexprlist ::= expr */
156897 270, /* (223) paren_exprlist ::= */
156898 270, /* (224) paren_exprlist ::= LP exprlist RP */
156899 186, /* (225) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
156900 274, /* (226) uniqueflag ::= UNIQUE */
156901 274, /* (227) uniqueflag ::= */
156902 216, /* (228) eidlist_opt ::= */
156903 216, /* (229) eidlist_opt ::= LP eidlist RP */
156904 227, /* (230) eidlist ::= eidlist COMMA nm collate sortorder */
156905 227, /* (231) eidlist ::= nm collate sortorder */
156906 275, /* (232) collate ::= */
156907 275, /* (233) collate ::= COLLATE ID|STRING */
156908 186, /* (234) cmd ::= DROP INDEX ifexists fullname */
156909 186, /* (235) cmd ::= VACUUM vinto */
156910 186, /* (236) cmd ::= VACUUM nm vinto */
156911 276, /* (237) vinto ::= INTO expr */
156912 276, /* (238) vinto ::= */
156913 186, /* (239) cmd ::= PRAGMA nm dbnm */
156914 186, /* (240) cmd ::= PRAGMA nm dbnm EQ nmnum */
156915 186, /* (241) cmd ::= PRAGMA nm dbnm LP nmnum RP */
156916 186, /* (242) cmd ::= PRAGMA nm dbnm EQ minus_num */
156917 186, /* (243) cmd ::= PRAGMA nm dbnm LP minus_num RP */
156918 206, /* (244) plus_num ::= PLUS INTEGER|FLOAT */
156919 207, /* (245) minus_num ::= MINUS INTEGER|FLOAT */
156920 186, /* (246) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
156921 278, /* (247) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
156922 280, /* (248) trigger_time ::= BEFORE|AFTER */
156923 280, /* (249) trigger_time ::= INSTEAD OF */
156924 280, /* (250) trigger_time ::= */
156925 281, /* (251) trigger_event ::= DELETE|INSERT */
156926 281, /* (252) trigger_event ::= UPDATE */
156927 281, /* (253) trigger_event ::= UPDATE OF idlist */
156928 283, /* (254) when_clause ::= */
156929 283, /* (255) when_clause ::= WHEN expr */
156930 279, /* (256) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
156931 279, /* (257) trigger_cmd_list ::= trigger_cmd SEMI */
156932 285, /* (258) trnm ::= nm DOT nm */
156933 286, /* (259) tridxby ::= INDEXED BY nm */
156934 286, /* (260) tridxby ::= NOT INDEXED */
156935 284, /* (261) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
156936 284, /* (262) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
156937 284, /* (263) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
156938 284, /* (264) trigger_cmd ::= scanpt select scanpt */
156939 212, /* (265) expr ::= RAISE LP IGNORE RP */
156940 212, /* (266) expr ::= RAISE LP raisetype COMMA nm RP */
156941 231, /* (267) raisetype ::= ROLLBACK */
156942 231, /* (268) raisetype ::= ABORT */
156943 231, /* (269) raisetype ::= FAIL */
156944 186, /* (270) cmd ::= DROP TRIGGER ifexists fullname */
156945 186, /* (271) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
156946 186, /* (272) cmd ::= DETACH database_kw_opt expr */
156947 288, /* (273) key_opt ::= */
156948 288, /* (274) key_opt ::= KEY expr */
156949 186, /* (275) cmd ::= REINDEX */
156950 186, /* (276) cmd ::= REINDEX nm dbnm */
156951 186, /* (277) cmd ::= ANALYZE */
156952 186, /* (278) cmd ::= ANALYZE nm dbnm */
156953 186, /* (279) cmd ::= ALTER TABLE fullname RENAME TO nm */
156954 186, /* (280) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
156955 289, /* (281) add_column_fullname ::= fullname */
156956 186, /* (282) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
156957 186, /* (283) cmd ::= create_vtab */
156958 186, /* (284) cmd ::= create_vtab LP vtabarglist RP */
156959 291, /* (285) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
156960 293, /* (286) vtabarg ::= */
156961 294, /* (287) vtabargtoken ::= ANY */
156962 294, /* (288) vtabargtoken ::= lp anylist RP */
156963 295, /* (289) lp ::= LP */
156964 261, /* (290) with ::= WITH wqlist */
156965 261, /* (291) with ::= WITH RECURSIVE wqlist */
156966 236, /* (292) wqlist ::= nm eidlist_opt AS LP select RP */
156967 236, /* (293) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
156968 297, /* (294) windowdefn_list ::= windowdefn */
156969 297, /* (295) windowdefn_list ::= windowdefn_list COMMA windowdefn */
156970 298, /* (296) windowdefn ::= nm AS LP window RP */
156971 299, /* (297) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
156972 299, /* (298) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
156973 299, /* (299) window ::= ORDER BY sortlist frame_opt */
156974 299, /* (300) window ::= nm ORDER BY sortlist frame_opt */
156975 299, /* (301) window ::= frame_opt */
156976 299, /* (302) window ::= nm frame_opt */
156977 300, /* (303) frame_opt ::= */
156978 300, /* (304) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
156979 300, /* (305) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
156980 304, /* (306) range_or_rows ::= RANGE|ROWS|GROUPS */
156981 306, /* (307) frame_bound_s ::= frame_bound */
156982 306, /* (308) frame_bound_s ::= UNBOUNDED PRECEDING */
156983 307, /* (309) frame_bound_e ::= frame_bound */
156984 307, /* (310) frame_bound_e ::= UNBOUNDED FOLLOWING */
156985 305, /* (311) frame_bound ::= expr PRECEDING|FOLLOWING */
156986 305, /* (312) frame_bound ::= CURRENT ROW */
156987 308, /* (313) frame_exclude_opt ::= */
156988 308, /* (314) frame_exclude_opt ::= EXCLUDE frame_exclude */
156989 309, /* (315) frame_exclude ::= NO OTHERS */
156990 309, /* (316) frame_exclude ::= CURRENT ROW */
156991 309, /* (317) frame_exclude ::= GROUP|TIES */
156992 246, /* (318) window_clause ::= WINDOW windowdefn_list */
156993 266, /* (319) filter_over ::= filter_clause over_clause */
156994 266, /* (320) filter_over ::= over_clause */
156995 266, /* (321) filter_over ::= filter_clause */
156996 303, /* (322) over_clause ::= OVER LP window RP */
156997 303, /* (323) over_clause ::= OVER nm */
156998 302, /* (324) filter_clause ::= FILTER LP WHERE expr RP */
156999 181, /* (325) input ::= cmdlist */
157000 182, /* (326) cmdlist ::= cmdlist ecmd */
157001 182, /* (327) cmdlist ::= ecmd */
157002 183, /* (328) ecmd ::= SEMI */
157003 183, /* (329) ecmd ::= cmdx SEMI */
157004 183, /* (330) ecmd ::= explain cmdx SEMI */
157005 188, /* (331) trans_opt ::= */
157006 188, /* (332) trans_opt ::= TRANSACTION */
157007 188, /* (333) trans_opt ::= TRANSACTION nm */
157008 190, /* (334) savepoint_opt ::= SAVEPOINT */
157009 190, /* (335) savepoint_opt ::= */
157010 186, /* (336) cmd ::= create_table create_table_args */
157011 197, /* (337) columnlist ::= columnlist COMMA columnname carglist */
157012 197, /* (338) columnlist ::= columnname carglist */
157013 189, /* (339) nm ::= ID|INDEXED */
157014 189, /* (340) nm ::= STRING */
157015 189, /* (341) nm ::= JOIN_KW */
157016 203, /* (342) typetoken ::= typename */
157017 204, /* (343) typename ::= ID|STRING */
157018 205, /* (344) signed ::= plus_num */
157019 205, /* (345) signed ::= minus_num */
157020 202, /* (346) carglist ::= carglist ccons */
157021 202, /* (347) carglist ::= */
157022 210, /* (348) ccons ::= NULL onconf */
157023 210, /* (349) ccons ::= GENERATED ALWAYS AS generated */
157024 210, /* (350) ccons ::= AS generated */
157025 198, /* (351) conslist_opt ::= COMMA conslist */
157026 223, /* (352) conslist ::= conslist tconscomma tcons */
157027 223, /* (353) conslist ::= tcons */
157028 224, /* (354) tconscomma ::= */
157029 228, /* (355) defer_subclause_opt ::= defer_subclause */
157030 230, /* (356) resolvetype ::= raisetype */
157031 234, /* (357) selectnowith ::= oneselect */
157032 235, /* (358) oneselect ::= values */
157033 249, /* (359) sclp ::= selcollist COMMA */
157034 250, /* (360) as ::= ID|STRING */
157035 212, /* (361) expr ::= term */
157036 267, /* (362) likeop ::= LIKE_KW|MATCH */
157037 257, /* (363) exprlist ::= nexprlist */
157038 277, /* (364) nmnum ::= plus_num */
157039 277, /* (365) nmnum ::= nm */
157040 277, /* (366) nmnum ::= ON */
157041 277, /* (367) nmnum ::= DELETE */
157042 277, /* (368) nmnum ::= DEFAULT */
157043 206, /* (369) plus_num ::= INTEGER|FLOAT */
157044 282, /* (370) foreach_clause ::= */
157045 282, /* (371) foreach_clause ::= FOR EACH ROW */
157046 285, /* (372) trnm ::= nm */
157047 286, /* (373) tridxby ::= */
157048 287, /* (374) database_kw_opt ::= DATABASE */
157049 287, /* (375) database_kw_opt ::= */
157050 290, /* (376) kwcolumn_opt ::= */
157051 290, /* (377) kwcolumn_opt ::= COLUMNKW */
157052 292, /* (378) vtabarglist ::= vtabarg */
157053 292, /* (379) vtabarglist ::= vtabarglist COMMA vtabarg */

Referenced by yy_reduce().

◆ yyRuleInfoNRhs

const signed char yyRuleInfoNRhs[]
static

Definition at line 157057 of file sqlite3.c.

157063 {
157064 -1, /* (0) explain ::= EXPLAIN */
157065 -3, /* (1) explain ::= EXPLAIN QUERY PLAN */
157066 -1, /* (2) cmdx ::= cmd */
157067 -3, /* (3) cmd ::= BEGIN transtype trans_opt */
157068 0, /* (4) transtype ::= */
157069 -1, /* (5) transtype ::= DEFERRED */
157070 -1, /* (6) transtype ::= IMMEDIATE */
157071 -1, /* (7) transtype ::= EXCLUSIVE */
157072 -2, /* (8) cmd ::= COMMIT|END trans_opt */
157073 -2, /* (9) cmd ::= ROLLBACK trans_opt */
157074 -2, /* (10) cmd ::= SAVEPOINT nm */
157075 -3, /* (11) cmd ::= RELEASE savepoint_opt nm */
157076 -5, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
157077 -6, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
157078 -1, /* (14) createkw ::= CREATE */
157079 0, /* (15) ifnotexists ::= */
157080 -3, /* (16) ifnotexists ::= IF NOT EXISTS */
157081 -1, /* (17) temp ::= TEMP */
157082 0, /* (18) temp ::= */
157083 -5, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
157084 -2, /* (20) create_table_args ::= AS select */
157085 0, /* (21) table_options ::= */
157086 -2, /* (22) table_options ::= WITHOUT nm */
157087 -2, /* (23) columnname ::= nm typetoken */
157088 0, /* (24) typetoken ::= */
157089 -4, /* (25) typetoken ::= typename LP signed RP */
157090 -6, /* (26) typetoken ::= typename LP signed COMMA signed RP */
157091 -2, /* (27) typename ::= typename ID|STRING */
157092 0, /* (28) scanpt ::= */
157093 0, /* (29) scantok ::= */
157094 -2, /* (30) ccons ::= CONSTRAINT nm */
157095 -3, /* (31) ccons ::= DEFAULT scantok term */
157096 -4, /* (32) ccons ::= DEFAULT LP expr RP */
157097 -4, /* (33) ccons ::= DEFAULT PLUS scantok term */
157098 -4, /* (34) ccons ::= DEFAULT MINUS scantok term */
157099 -3, /* (35) ccons ::= DEFAULT scantok ID|INDEXED */
157100 -3, /* (36) ccons ::= NOT NULL onconf */
157101 -5, /* (37) ccons ::= PRIMARY KEY sortorder onconf autoinc */
157102 -2, /* (38) ccons ::= UNIQUE onconf */
157103 -4, /* (39) ccons ::= CHECK LP expr RP */
157104 -4, /* (40) ccons ::= REFERENCES nm eidlist_opt refargs */
157105 -1, /* (41) ccons ::= defer_subclause */
157106 -2, /* (42) ccons ::= COLLATE ID|STRING */
157107 -3, /* (43) generated ::= LP expr RP */
157108 -4, /* (44) generated ::= LP expr RP ID */
157109 0, /* (45) autoinc ::= */
157110 -1, /* (46) autoinc ::= AUTOINCR */
157111 0, /* (47) refargs ::= */
157112 -2, /* (48) refargs ::= refargs refarg */
157113 -2, /* (49) refarg ::= MATCH nm */
157114 -3, /* (50) refarg ::= ON INSERT refact */
157115 -3, /* (51) refarg ::= ON DELETE refact */
157116 -3, /* (52) refarg ::= ON UPDATE refact */
157117 -2, /* (53) refact ::= SET NULL */
157118 -2, /* (54) refact ::= SET DEFAULT */
157119 -1, /* (55) refact ::= CASCADE */
157120 -1, /* (56) refact ::= RESTRICT */
157121 -2, /* (57) refact ::= NO ACTION */
157122 -3, /* (58) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
157123 -2, /* (59) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
157124 0, /* (60) init_deferred_pred_opt ::= */
157125 -2, /* (61) init_deferred_pred_opt ::= INITIALLY DEFERRED */
157126 -2, /* (62) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
157127 0, /* (63) conslist_opt ::= */
157128 -1, /* (64) tconscomma ::= COMMA */
157129 -2, /* (65) tcons ::= CONSTRAINT nm */
157130 -7, /* (66) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
157131 -5, /* (67) tcons ::= UNIQUE LP sortlist RP onconf */
157132 -5, /* (68) tcons ::= CHECK LP expr RP onconf */
157133 -10, /* (69) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
157134 0, /* (70) defer_subclause_opt ::= */
157135 0, /* (71) onconf ::= */
157136 -3, /* (72) onconf ::= ON CONFLICT resolvetype */
157137 0, /* (73) orconf ::= */
157138 -2, /* (74) orconf ::= OR resolvetype */
157139 -1, /* (75) resolvetype ::= IGNORE */
157140 -1, /* (76) resolvetype ::= REPLACE */
157141 -4, /* (77) cmd ::= DROP TABLE ifexists fullname */
157142 -2, /* (78) ifexists ::= IF EXISTS */
157143 0, /* (79) ifexists ::= */
157144 -9, /* (80) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
157145 -4, /* (81) cmd ::= DROP VIEW ifexists fullname */
157146 -1, /* (82) cmd ::= select */
157147 -3, /* (83) select ::= WITH wqlist selectnowith */
157148 -4, /* (84) select ::= WITH RECURSIVE wqlist selectnowith */
157149 -1, /* (85) select ::= selectnowith */
157150 -3, /* (86) selectnowith ::= selectnowith multiselect_op oneselect */
157151 -1, /* (87) multiselect_op ::= UNION */
157152 -2, /* (88) multiselect_op ::= UNION ALL */
157153 -1, /* (89) multiselect_op ::= EXCEPT|INTERSECT */
157154 -9, /* (90) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
157155 -10, /* (91) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
157156 -4, /* (92) values ::= VALUES LP nexprlist RP */
157157 -5, /* (93) values ::= values COMMA LP nexprlist RP */
157158 -1, /* (94) distinct ::= DISTINCT */
157159 -1, /* (95) distinct ::= ALL */
157160 0, /* (96) distinct ::= */
157161 0, /* (97) sclp ::= */
157162 -5, /* (98) selcollist ::= sclp scanpt expr scanpt as */
157163 -3, /* (99) selcollist ::= sclp scanpt STAR */
157164 -5, /* (100) selcollist ::= sclp scanpt nm DOT STAR */
157165 -2, /* (101) as ::= AS nm */
157166 0, /* (102) as ::= */
157167 0, /* (103) from ::= */
157168 -2, /* (104) from ::= FROM seltablist */
157169 -2, /* (105) stl_prefix ::= seltablist joinop */
157170 0, /* (106) stl_prefix ::= */
157171 -7, /* (107) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
157172 -9, /* (108) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
157173 -7, /* (109) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
157174 -7, /* (110) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
157175 0, /* (111) dbnm ::= */
157176 -2, /* (112) dbnm ::= DOT nm */
157177 -1, /* (113) fullname ::= nm */
157178 -3, /* (114) fullname ::= nm DOT nm */
157179 -1, /* (115) xfullname ::= nm */
157180 -3, /* (116) xfullname ::= nm DOT nm */
157181 -5, /* (117) xfullname ::= nm DOT nm AS nm */
157182 -3, /* (118) xfullname ::= nm AS nm */
157183 -1, /* (119) joinop ::= COMMA|JOIN */
157184 -2, /* (120) joinop ::= JOIN_KW JOIN */
157185 -3, /* (121) joinop ::= JOIN_KW nm JOIN */
157186 -4, /* (122) joinop ::= JOIN_KW nm nm JOIN */
157187 -2, /* (123) on_opt ::= ON expr */
157188 0, /* (124) on_opt ::= */
157189 0, /* (125) indexed_opt ::= */
157190 -3, /* (126) indexed_opt ::= INDEXED BY nm */
157191 -2, /* (127) indexed_opt ::= NOT INDEXED */
157192 -4, /* (128) using_opt ::= USING LP idlist RP */
157193 0, /* (129) using_opt ::= */
157194 0, /* (130) orderby_opt ::= */
157195 -3, /* (131) orderby_opt ::= ORDER BY sortlist */
157196 -5, /* (132) sortlist ::= sortlist COMMA expr sortorder nulls */
157197 -3, /* (133) sortlist ::= expr sortorder nulls */
157198 -1, /* (134) sortorder ::= ASC */
157199 -1, /* (135) sortorder ::= DESC */
157200 0, /* (136) sortorder ::= */
157201 -2, /* (137) nulls ::= NULLS FIRST */
157202 -2, /* (138) nulls ::= NULLS LAST */
157203 0, /* (139) nulls ::= */
157204 0, /* (140) groupby_opt ::= */
157205 -3, /* (141) groupby_opt ::= GROUP BY nexprlist */
157206 0, /* (142) having_opt ::= */
157207 -2, /* (143) having_opt ::= HAVING expr */
157208 0, /* (144) limit_opt ::= */
157209 -2, /* (145) limit_opt ::= LIMIT expr */
157210 -4, /* (146) limit_opt ::= LIMIT expr OFFSET expr */
157211 -4, /* (147) limit_opt ::= LIMIT expr COMMA expr */
157212 -6, /* (148) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
157213 0, /* (149) where_opt ::= */
157214 -2, /* (150) where_opt ::= WHERE expr */
157215 -9, /* (151) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt */
157216 -5, /* (152) setlist ::= setlist COMMA nm EQ expr */
157217 -7, /* (153) setlist ::= setlist COMMA LP idlist RP EQ expr */
157218 -3, /* (154) setlist ::= nm EQ expr */
157219 -5, /* (155) setlist ::= LP idlist RP EQ expr */
157220 -7, /* (156) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
157221 -7, /* (157) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
157222 0, /* (158) upsert ::= */
157223 -11, /* (159) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
157224 -8, /* (160) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
157225 -4, /* (161) upsert ::= ON CONFLICT DO NOTHING */
157226 -2, /* (162) insert_cmd ::= INSERT orconf */
157227 -1, /* (163) insert_cmd ::= REPLACE */
157228 0, /* (164) idlist_opt ::= */
157229 -3, /* (165) idlist_opt ::= LP idlist RP */
157230 -3, /* (166) idlist ::= idlist COMMA nm */
157231 -1, /* (167) idlist ::= nm */
157232 -3, /* (168) expr ::= LP expr RP */
157233 -1, /* (169) expr ::= ID|INDEXED */
157234 -1, /* (170) expr ::= JOIN_KW */
157235 -3, /* (171) expr ::= nm DOT nm */
157236 -5, /* (172) expr ::= nm DOT nm DOT nm */
157237 -1, /* (173) term ::= NULL|FLOAT|BLOB */
157238 -1, /* (174) term ::= STRING */
157239 -1, /* (175) term ::= INTEGER */
157240 -1, /* (176) expr ::= VARIABLE */
157241 -3, /* (177) expr ::= expr COLLATE ID|STRING */
157242 -6, /* (178) expr ::= CAST LP expr AS typetoken RP */
157243 -5, /* (179) expr ::= ID|INDEXED LP distinct exprlist RP */
157244 -4, /* (180) expr ::= ID|INDEXED LP STAR RP */
157245 -6, /* (181) expr ::= ID|INDEXED LP distinct exprlist RP filter_over */
157246 -5, /* (182) expr ::= ID|INDEXED LP STAR RP filter_over */
157247 -1, /* (183) term ::= CTIME_KW */
157248 -5, /* (184) expr ::= LP nexprlist COMMA expr RP */
157249 -3, /* (185) expr ::= expr AND expr */
157250 -3, /* (186) expr ::= expr OR expr */
157251 -3, /* (187) expr ::= expr LT|GT|GE|LE expr */
157252 -3, /* (188) expr ::= expr EQ|NE expr */
157253 -3, /* (189) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
157254 -3, /* (190) expr ::= expr PLUS|MINUS expr */
157255 -3, /* (191) expr ::= expr STAR|SLASH|REM expr */
157256 -3, /* (192) expr ::= expr CONCAT expr */
157257 -2, /* (193) likeop ::= NOT LIKE_KW|MATCH */
157258 -3, /* (194) expr ::= expr likeop expr */
157259 -5, /* (195) expr ::= expr likeop expr ESCAPE expr */
157260 -2, /* (196) expr ::= expr ISNULL|NOTNULL */
157261 -3, /* (197) expr ::= expr NOT NULL */
157262 -3, /* (198) expr ::= expr IS expr */
157263 -4, /* (199) expr ::= expr IS NOT expr */
157264 -2, /* (200) expr ::= NOT expr */
157265 -2, /* (201) expr ::= BITNOT expr */
157266 -2, /* (202) expr ::= PLUS|MINUS expr */
157267 -1, /* (203) between_op ::= BETWEEN */
157268 -2, /* (204) between_op ::= NOT BETWEEN */
157269 -5, /* (205) expr ::= expr between_op expr AND expr */
157270 -1, /* (206) in_op ::= IN */
157271 -2, /* (207) in_op ::= NOT IN */
157272 -5, /* (208) expr ::= expr in_op LP exprlist RP */
157273 -3, /* (209) expr ::= LP select RP */
157274 -5, /* (210) expr ::= expr in_op LP select RP */
157275 -5, /* (211) expr ::= expr in_op nm dbnm paren_exprlist */
157276 -4, /* (212) expr ::= EXISTS LP select RP */
157277 -5, /* (213) expr ::= CASE case_operand case_exprlist case_else END */
157278 -5, /* (214) case_exprlist ::= case_exprlist WHEN expr THEN expr */
157279 -4, /* (215) case_exprlist ::= WHEN expr THEN expr */
157280 -2, /* (216) case_else ::= ELSE expr */
157281 0, /* (217) case_else ::= */
157282 -1, /* (218) case_operand ::= expr */
157283 0, /* (219) case_operand ::= */
157284 0, /* (220) exprlist ::= */
157285 -3, /* (221) nexprlist ::= nexprlist COMMA expr */
157286 -1, /* (222) nexprlist ::= expr */
157287 0, /* (223) paren_exprlist ::= */
157288 -3, /* (224) paren_exprlist ::= LP exprlist RP */
157289 -12, /* (225) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
157290 -1, /* (226) uniqueflag ::= UNIQUE */
157291 0, /* (227) uniqueflag ::= */
157292 0, /* (228) eidlist_opt ::= */
157293 -3, /* (229) eidlist_opt ::= LP eidlist RP */
157294 -5, /* (230) eidlist ::= eidlist COMMA nm collate sortorder */
157295 -3, /* (231) eidlist ::= nm collate sortorder */
157296 0, /* (232) collate ::= */
157297 -2, /* (233) collate ::= COLLATE ID|STRING */
157298 -4, /* (234) cmd ::= DROP INDEX ifexists fullname */
157299 -2, /* (235) cmd ::= VACUUM vinto */
157300 -3, /* (236) cmd ::= VACUUM nm vinto */
157301 -2, /* (237) vinto ::= INTO expr */
157302 0, /* (238) vinto ::= */
157303 -3, /* (239) cmd ::= PRAGMA nm dbnm */
157304 -5, /* (240) cmd ::= PRAGMA nm dbnm EQ nmnum */
157305 -6, /* (241) cmd ::= PRAGMA nm dbnm LP nmnum RP */
157306 -5, /* (242) cmd ::= PRAGMA nm dbnm EQ minus_num */
157307 -6, /* (243) cmd ::= PRAGMA nm dbnm LP minus_num RP */
157308 -2, /* (244) plus_num ::= PLUS INTEGER|FLOAT */
157309 -2, /* (245) minus_num ::= MINUS INTEGER|FLOAT */
157310 -5, /* (246) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
157311 -11, /* (247) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
157312 -1, /* (248) trigger_time ::= BEFORE|AFTER */
157313 -2, /* (249) trigger_time ::= INSTEAD OF */
157314 0, /* (250) trigger_time ::= */
157315 -1, /* (251) trigger_event ::= DELETE|INSERT */
157316 -1, /* (252) trigger_event ::= UPDATE */
157317 -3, /* (253) trigger_event ::= UPDATE OF idlist */
157318 0, /* (254) when_clause ::= */
157319 -2, /* (255) when_clause ::= WHEN expr */
157320 -3, /* (256) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
157321 -2, /* (257) trigger_cmd_list ::= trigger_cmd SEMI */
157322 -3, /* (258) trnm ::= nm DOT nm */
157323 -3, /* (259) tridxby ::= INDEXED BY nm */
157324 -2, /* (260) tridxby ::= NOT INDEXED */
157325 -9, /* (261) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
157326 -8, /* (262) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
157327 -6, /* (263) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
157328 -3, /* (264) trigger_cmd ::= scanpt select scanpt */
157329 -4, /* (265) expr ::= RAISE LP IGNORE RP */
157330 -6, /* (266) expr ::= RAISE LP raisetype COMMA nm RP */
157331 -1, /* (267) raisetype ::= ROLLBACK */
157332 -1, /* (268) raisetype ::= ABORT */
157333 -1, /* (269) raisetype ::= FAIL */
157334 -4, /* (270) cmd ::= DROP TRIGGER ifexists fullname */
157335 -6, /* (271) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
157336 -3, /* (272) cmd ::= DETACH database_kw_opt expr */
157337 0, /* (273) key_opt ::= */
157338 -2, /* (274) key_opt ::= KEY expr */
157339 -1, /* (275) cmd ::= REINDEX */
157340 -3, /* (276) cmd ::= REINDEX nm dbnm */
157341 -1, /* (277) cmd ::= ANALYZE */
157342 -3, /* (278) cmd ::= ANALYZE nm dbnm */
157343 -6, /* (279) cmd ::= ALTER TABLE fullname RENAME TO nm */
157344 -7, /* (280) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
157345 -1, /* (281) add_column_fullname ::= fullname */
157346 -8, /* (282) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
157347 -1, /* (283) cmd ::= create_vtab */
157348 -4, /* (284) cmd ::= create_vtab LP vtabarglist RP */
157349 -8, /* (285) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
157350 0, /* (286) vtabarg ::= */
157351 -1, /* (287) vtabargtoken ::= ANY */
157352 -3, /* (288) vtabargtoken ::= lp anylist RP */
157353 -1, /* (289) lp ::= LP */
157354 -2, /* (290) with ::= WITH wqlist */
157355 -3, /* (291) with ::= WITH RECURSIVE wqlist */
157356 -6, /* (292) wqlist ::= nm eidlist_opt AS LP select RP */
157357 -8, /* (293) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
157358 -1, /* (294) windowdefn_list ::= windowdefn */
157359 -3, /* (295) windowdefn_list ::= windowdefn_list COMMA windowdefn */
157360 -5, /* (296) windowdefn ::= nm AS LP window RP */
157361 -5, /* (297) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
157362 -6, /* (298) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
157363 -4, /* (299) window ::= ORDER BY sortlist frame_opt */
157364 -5, /* (300) window ::= nm ORDER BY sortlist frame_opt */
157365 -1, /* (301) window ::= frame_opt */
157366 -2, /* (302) window ::= nm frame_opt */
157367 0, /* (303) frame_opt ::= */
157368 -3, /* (304) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
157369 -6, /* (305) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
157370 -1, /* (306) range_or_rows ::= RANGE|ROWS|GROUPS */
157371 -1, /* (307) frame_bound_s ::= frame_bound */
157372 -2, /* (308) frame_bound_s ::= UNBOUNDED PRECEDING */
157373 -1, /* (309) frame_bound_e ::= frame_bound */
157374 -2, /* (310) frame_bound_e ::= UNBOUNDED FOLLOWING */
157375 -2, /* (311) frame_bound ::= expr PRECEDING|FOLLOWING */
157376 -2, /* (312) frame_bound ::= CURRENT ROW */
157377 0, /* (313) frame_exclude_opt ::= */
157378 -2, /* (314) frame_exclude_opt ::= EXCLUDE frame_exclude */
157379 -2, /* (315) frame_exclude ::= NO OTHERS */
157380 -2, /* (316) frame_exclude ::= CURRENT ROW */
157381 -1, /* (317) frame_exclude ::= GROUP|TIES */
157382 -2, /* (318) window_clause ::= WINDOW windowdefn_list */
157383 -2, /* (319) filter_over ::= filter_clause over_clause */
157384 -1, /* (320) filter_over ::= over_clause */
157385 -1, /* (321) filter_over ::= filter_clause */
157386 -4, /* (322) over_clause ::= OVER LP window RP */
157387 -2, /* (323) over_clause ::= OVER nm */
157388 -5, /* (324) filter_clause ::= FILTER LP WHERE expr RP */
157389 -1, /* (325) input ::= cmdlist */
157390 -2, /* (326) cmdlist ::= cmdlist ecmd */
157391 -1, /* (327) cmdlist ::= ecmd */
157392 -1, /* (328) ecmd ::= SEMI */
157393 -2, /* (329) ecmd ::= cmdx SEMI */
157394 -3, /* (330) ecmd ::= explain cmdx SEMI */
157395 0, /* (331) trans_opt ::= */
157396 -1, /* (332) trans_opt ::= TRANSACTION */
157397 -2, /* (333) trans_opt ::= TRANSACTION nm */
157398 -1, /* (334) savepoint_opt ::= SAVEPOINT */
157399 0, /* (335) savepoint_opt ::= */
157400 -2, /* (336) cmd ::= create_table create_table_args */
157401 -4, /* (337) columnlist ::= columnlist COMMA columnname carglist */
157402 -2, /* (338) columnlist ::= columnname carglist */
157403 -1, /* (339) nm ::= ID|INDEXED */
157404 -1, /* (340) nm ::= STRING */
157405 -1, /* (341) nm ::= JOIN_KW */
157406 -1, /* (342) typetoken ::= typename */
157407 -1, /* (343) typename ::= ID|STRING */
157408 -1, /* (344) signed ::= plus_num */
157409 -1, /* (345) signed ::= minus_num */
157410 -2, /* (346) carglist ::= carglist ccons */
157411 0, /* (347) carglist ::= */
157412 -2, /* (348) ccons ::= NULL onconf */
157413 -4, /* (349) ccons ::= GENERATED ALWAYS AS generated */
157414 -2, /* (350) ccons ::= AS generated */
157415 -2, /* (351) conslist_opt ::= COMMA conslist */
157416 -3, /* (352) conslist ::= conslist tconscomma tcons */
157417 -1, /* (353) conslist ::= tcons */
157418 0, /* (354) tconscomma ::= */
157419 -1, /* (355) defer_subclause_opt ::= defer_subclause */
157420 -1, /* (356) resolvetype ::= raisetype */
157421 -1, /* (357) selectnowith ::= oneselect */
157422 -1, /* (358) oneselect ::= values */
157423 -2, /* (359) sclp ::= selcollist COMMA */
157424 -1, /* (360) as ::= ID|STRING */
157425 -1, /* (361) expr ::= term */
157426 -1, /* (362) likeop ::= LIKE_KW|MATCH */
157427 -1, /* (363) exprlist ::= nexprlist */
157428 -1, /* (364) nmnum ::= plus_num */
157429 -1, /* (365) nmnum ::= nm */
157430 -1, /* (366) nmnum ::= ON */
157431 -1, /* (367) nmnum ::= DELETE */
157432 -1, /* (368) nmnum ::= DEFAULT */
157433 -1, /* (369) plus_num ::= INTEGER|FLOAT */
157434 0, /* (370) foreach_clause ::= */
157435 -3, /* (371) foreach_clause ::= FOR EACH ROW */
157436 -1, /* (372) trnm ::= nm */
157437 0, /* (373) tridxby ::= */
157438 -1, /* (374) database_kw_opt ::= DATABASE */
157439 0, /* (375) database_kw_opt ::= */
157440 0, /* (376) kwcolumn_opt ::= */
157441 -1, /* (377) kwcolumn_opt ::= COLUMNKW */
157442 -1, /* (378) vtabarglist ::= vtabarg */
157443 -3, /* (379) vtabarglist ::= vtabarglist COMMA vtabarg */

Referenced by yy_reduce().

◆ zKWText

const char zKWText[647]
static

Definition at line 159430 of file sqlite3.c.

159436 {
159437 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
159438 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
159439 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
159440 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
159441 'E','R','R','A','B','L','E','L','S','E','X','C','L','U','D','E','L','E',
159442 'T','E','M','P','O','R','A','R','Y','I','S','N','U','L','L','S','A','V',
159443 'E','P','O','I','N','T','E','R','S','E','C','T','I','E','S','N','O','T',
159444 'N','U','L','L','I','K','E','X','C','E','P','T','R','A','N','S','A','C',
159445 'T','I','O','N','A','T','U','R','A','L','T','E','R','A','I','S','E','X',
159446 'C','L','U','S','I','V','E','X','I','S','T','S','C','O','N','S','T','R',
159447 'A','I','N','T','O','F','F','S','E','T','R','I','G','G','E','R','A','N',
159448 'G','E','N','E','R','A','T','E','D','E','T','A','C','H','A','V','I','N',
159449 'G','L','O','B','E','G','I','N','N','E','R','E','F','E','R','E','N','C',
159450 'E','S','U','N','I','Q','U','E','R','Y','W','I','T','H','O','U','T','E',
159451 'R','E','L','E','A','S','E','A','T','T','A','C','H','B','E','T','W','E',
159452 'E','N','O','T','H','I','N','G','R','O','U','P','S','C','A','S','C','A',
159453 'D','E','F','A','U','L','T','C','A','S','E','C','O','L','L','A','T','E',
159454 'C','R','E','A','T','E','C','U','R','R','E','N','T','_','D','A','T','E',
159455 'I','M','M','E','D','I','A','T','E','J','O','I','N','S','E','R','T','M',
159456 'A','T','C','H','P','L','A','N','A','L','Y','Z','E','P','R','A','G','M',
159457 'A','B','O','R','T','U','P','D','A','T','E','V','A','L','U','E','S','V',
159458 'I','R','T','U','A','L','W','A','Y','S','W','H','E','N','W','H','E','R',
159459 'E','C','U','R','S','I','V','E','A','F','T','E','R','E','N','A','M','E',
159460 'A','N','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','A',
159461 'U','T','O','I','N','C','R','E','M','E','N','T','C','A','S','T','C','O',
159462 'L','U','M','N','C','O','M','M','I','T','C','O','N','F','L','I','C','T',
159463 'C','R','O','S','S','C','U','R','R','E','N','T','_','T','I','M','E','S',
159464 'T','A','M','P','A','R','T','I','T','I','O','N','D','R','O','P','R','E',
159465 'C','E','D','I','N','G','F','A','I','L','A','S','T','F','I','L','T','E',
159466 'R','E','P','L','A','C','E','F','I','R','S','T','F','O','L','L','O','W',
159467 'I','N','G','F','R','O','M','F','U','L','L','I','M','I','T','I','F','O',

Referenced by keywordCode().

◆ zMagicHeader

const char zMagicHeader[] = SQLITE_FILE_HEADER
static

Definition at line 64499 of file sqlite3.c.

Referenced by lockBtree(), and newDatabase().

◆ zName