欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

sqlite源码剖析(2)

程序员文章站 2022-03-02 16:28:31
...

声明:本SQLite源码剖析系列为刘兴(http://deepfuture.iteye.com/)原创,未经笔者授权,任何人和机构不能转载

/*

** The maximum number of opcodes in a VDBE program.

** Not currently enforced.

*/

//VDBE程序的最大操作码数目

#ifndef SQLITE_MAX_VDBE_OP

# define SQLITE_MAX_VDBE_OP 25000

#endif

 

/*

** The maximum number of arguments to an SQL function.

*/

//SQL函数的最大参数数目

#ifndef SQLITE_MAX_FUNCTION_ARG

# define SQLITE_MAX_FUNCTION_ARG 127

#endif

 

/*

** The maximum number of in-memory pages to use for the main database

** table and for temporary tables.  The SQLITE_DEFAULT_CACHE_SIZE

*/

//主数据库表和临时表的最大内存大小

#ifndef SQLITE_DEFAULT_CACHE_SIZE

# define SQLITE_DEFAULT_CACHE_SIZE  2000

#endif

#ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE

# define SQLITE_DEFAULT_TEMP_CACHE_SIZE  500

#endif

 

/*

** The maximum number of attached databases.  This must be between 0

** and 30.  The upper bound on 30 is because a 32-bit integer bitmap

** is used internally to track attached databases.

*/

//附加数据库的数目

#ifndef SQLITE_MAX_ATTACHED

# define SQLITE_MAX_ATTACHED 10

#endif

 

 

/*

** The maximum value of a ?nnn wildcard that the parser will accept.

*/

//解析器接受的匹配符参数最大值

#ifndef SQLITE_MAX_VARIABLE_NUMBER

# define SQLITE_MAX_VARIABLE_NUMBER 999

#endif

 

/* Maximum page size.  The upper bound on this value is 32768.  This a limit

** imposed by the necessity of storing the value in a 2-byte unsigned integer

** and the fact that the page size must be a power of 2.

**

** If this limit is changed, then the compiled library is technically

** incompatible with an SQLite library compiled with a different limit. If

** a process operating on a database with a page-size of 65536 bytes

** crashes, then an instance of SQLite compiled with the default page-size

** limit will not be able to rollback the aborted transaction. This could

** lead to database corruption.

*/

//最大页面大小

#ifndef SQLITE_MAX_PAGE_SIZE

# define SQLITE_MAX_PAGE_SIZE 32768

#endif

 

 

/*

** The default size of a database page.

*/

//数据库页面的默认大小

#ifndef SQLITE_DEFAULT_PAGE_SIZE

# define SQLITE_DEFAULT_PAGE_SIZE 1024

#endif

#if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE

# undef SQLITE_DEFAULT_PAGE_SIZE

# define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE

#endif

 

/*

** Ordinarily, if no value is explicitly provided, SQLite creates databases

** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain

** device characteristics (sector-size and atomic write() support),

** SQLite may choose a larger value. This constant is the maximum value

** SQLite will choose on its own.

*/

//数据库页面的最大默认大小

#ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE

# define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192

#endif

#if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE

# undef SQLITE_MAX_DEFAULT_PAGE_SIZE

# define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE

#endif

 

 

/*

** Maximum number of pages in one database file.

**

** This is really just the default value for the max_page_count pragma.

** This value can be lowered (or raised) at run-time using that the

** max_page_count macro.

*/

//单个数据库文件的最大页数数

#ifndef SQLITE_MAX_PAGE_COUNT

# define SQLITE_MAX_PAGE_COUNT 1073741823

#endif

 

/*

** Maximum length (in bytes) of the pattern in a LIKE or GLOB

** operator.

*/

// LIKE or GLOB模式的最大长度(字节)

#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH

# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000

#endif

 

/*

** Maximum depth of recursion for triggers.

**

** A value of 1 means that a trigger program will not be able to itself

** fire any triggers. A value of 0 means that no trigger programs at all

** may be executed.

*/

//触发器程序的递归深度

#ifndef SQLITE_MAX_TRIGGER_DEPTH

# define SQLITE_MAX_TRIGGER_DEPTH 1000

#endif

//SQLITE限制参数定义完毕

/************** End of sqliteLimit.h *****************************************/

/************** Continuing where we left off in sqliteInt.h ******************/

//禁止Borland编译器的讨厌的警告

/* Disable nuisance warnings on Borland compilers */

#if defined(__BORLANDC__)

#pragma warn -rch /* unreachable code */

#pragma warn -ccc /* Condition is always true or false */

#pragma warn -aus /* Assigned value is never used */

#pragma warn -csu /* Comparing signed and unsigned */

#pragma warn -spa /* Suspicious pointer arithmetic */

#endif

//定义为GNU源码

/* Needed for various definitions... */

#ifndef _GNU_SOURCE

# define _GNU_SOURCE

#endif

 

/*

** Include standard header files as necessary

*/

//包含必要的头文件

#ifdef HAVE_STDINT_H

#include <stdint.h>

#endif

#ifdef HAVE_INTTYPES_H

#include <inttypes.h>

#endif

 

/*

** The number of samples of an index that SQLite takes in order to

** construct a histogram of the table content when running ANALYZE

** and with SQLITE_ENABLE_STAT2

*/

//索引样本数

#define SQLITE_INDEX_SAMPLES 10

 

/*

** The following macros are used to cast pointers to integers and

** integers to pointers.  The way you do this varies from one compiler

** to the next, so we have developed the following set of #if statements

** to generate appropriate macros for a wide range of compilers.

**

** The correct "ANSI" way to do this is to use the intptr_t type.

** Unfortunately, that typedef is not available on all compilers, or

** if it is available, it requires an #include of specific headers

** that very from one machine to the next.

**

** Ticket #3860:  The llvm-gcc-4.2 compiler from Apple chokes on

** the ((void*)&((char*)0)[X]) construct.  But MSVC chokes on ((void*)(X)).

** So we have to define the macros in different ways depending on the

** compiler.

*/

//下列宏完成指针转整数和整数转指针

#if defined(__PTRDIFF_TYPE__)  /* This case should work for GCC */

# define SQLITE_INT_TO_PTR(X)  ((void*)(__PTRDIFF_TYPE__)(X))

# define SQLITE_PTR_TO_INT(X)  ((int)(__PTRDIFF_TYPE__)(X))

#elif !defined(__GNUC__)       /* Works for compilers other than LLVM */

# define SQLITE_INT_TO_PTR(X)  ((void*)&((char*)0)[X])

# define SQLITE_PTR_TO_INT(X)  ((int)(((char*)X)-(char*)0))

#elif defined(HAVE_STDINT_H)   /* Use this case if we have ANSI headers */

# define SQLITE_INT_TO_PTR(X)  ((void*)(intptr_t)(X))

# define SQLITE_PTR_TO_INT(X)  ((int)(intptr_t)(X))

#else                          /* Generates a warning - but it always works */

# define SQLITE_INT_TO_PTR(X)  ((void*)(X))

# define SQLITE_PTR_TO_INT(X)  ((int)(X))

#endif

 

/*

** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.

** Older versions of SQLite used an optional THREADSAFE macro.

** We support that for legacy

*/

// SQLITE_THREADSAFE线程安全宏被定义为01,

#if !defined(SQLITE_THREADSAFE)

#if defined(THREADSAFE)

# define SQLITE_THREADSAFE THREADSAFE

#else

# define SQLITE_THREADSAFE 1

#endif

#endif

 

/*

** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.

** It determines whether or not the features related to

** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can

** be overridden at runtime using the sqlite3_config() API.

*/

// SQLITE_DEFAULT_MEMSTATUS宏被定义为01,在运行时可使

//sqlite3_config() API修改该值

#if !defined(SQLITE_DEFAULT_MEMSTATUS)

# define SQLITE_DEFAULT_MEMSTATUS 1

#endif