| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.37.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3037000 |
| 457 | | -#define SQLITE_SOURCE_ID "2021-07-21 15:42:05 60695359dc5d3bcba68a68e1842c40f4a01650eb5af408e02fb856fd8245e16d" |
| 457 | +#define SQLITE_SOURCE_ID "2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -13872,10 +13872,11 @@ |
| 13872 | 13872 | #ifndef SQLITE_PTRSIZE |
| 13873 | 13873 | # if defined(__SIZEOF_POINTER__) |
| 13874 | 13874 | # define SQLITE_PTRSIZE __SIZEOF_POINTER__ |
| 13875 | 13875 | # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ |
| 13876 | 13876 | defined(_M_ARM) || defined(__arm__) || defined(__x86) || \ |
| 13877 | + (defined(__APPLE__) && defined(__POWERPC__)) || \ |
| 13877 | 13878 | (defined(__TOS_AIX__) && !defined(__64BIT__)) |
| 13878 | 13879 | # define SQLITE_PTRSIZE 4 |
| 13879 | 13880 | # else |
| 13880 | 13881 | # define SQLITE_PTRSIZE 8 |
| 13881 | 13882 | # endif |
| | @@ -16881,22 +16882,45 @@ |
| 16881 | 16882 | ** record BLOB generated by the OP_MakeRecord |
| 16882 | 16883 | ** opcode. The storage column index is less than |
| 16883 | 16884 | ** or equal to the table column index. It is |
| 16884 | 16885 | ** equal if and only if there are no VIRTUAL |
| 16885 | 16886 | ** columns to the left. |
| 16887 | +** |
| 16888 | +** Notes on zCnName: |
| 16889 | +** The zCnName field stores the name of the column, the datatype of the |
| 16890 | +** column, and the collating sequence for the column, in that order, all in |
| 16891 | +** a single allocation. Each string is 0x00 terminated. The datatype |
| 16892 | +** is only included if the COLFLAG_HASTYPE bit of colFlags is set and the |
| 16893 | +** collating sequence name is only included if the COLFLAG_HASCOLL bit is |
| 16894 | +** set. |
| 16886 | 16895 | */ |
| 16887 | 16896 | struct Column { |
| 16888 | | - char *zName; /* Name of this column, \000, then the type */ |
| 16889 | | - Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */ |
| 16890 | | - char *zColl; /* Collating sequence. If NULL, use the default */ |
| 16891 | | - u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ |
| 16892 | | - char affinity; /* One of the SQLITE_AFF_... values */ |
| 16893 | | - u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ |
| 16894 | | - u8 hName; /* Column name hash for faster lookup */ |
| 16895 | | - u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 16897 | + char *zCnName; /* Name of this column */ |
| 16898 | + unsigned notNull :4; /* An OE_ code for handling a NOT NULL constraint */ |
| 16899 | + unsigned eType :4; /* One of the standard types */ |
| 16900 | + char affinity; /* One of the SQLITE_AFF_... values */ |
| 16901 | + u8 szEst; /* Est size of value in this column. sizeof(INT)==1 */ |
| 16902 | + u8 hName; /* Column name hash for faster lookup */ |
| 16903 | + u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */ |
| 16904 | + u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 16896 | 16905 | }; |
| 16897 | 16906 | |
| 16907 | +/* Allowed values for Column.eType. |
| 16908 | +** |
| 16909 | +** Values must match entries in the global constant arrays |
| 16910 | +** sqlite3StdTypeLen[] and sqlite3StdType[]. Each value is one more |
| 16911 | +** than the offset into these arrays for the corresponding name. |
| 16912 | +** Adjust the SQLITE_N_STDTYPE value if adding or removing entries. |
| 16913 | +*/ |
| 16914 | +#define COLTYPE_CUSTOM 0 /* Type appended to zName */ |
| 16915 | +#define COLTYPE_BLOB 1 |
| 16916 | +#define COLTYPE_INT 2 |
| 16917 | +#define COLTYPE_INTEGER 3 |
| 16918 | +#define COLTYPE_REAL 4 |
| 16919 | +#define COLTYPE_TEXT 5 |
| 16920 | +#define SQLITE_N_STDTYPE 5 /* Number of standard types */ |
| 16921 | + |
| 16898 | 16922 | /* Allowed values for Column.colFlags. |
| 16899 | 16923 | ** |
| 16900 | 16924 | ** Constraints: |
| 16901 | 16925 | ** TF_HasVirtual == COLFLAG_VIRTUAL |
| 16902 | 16926 | ** TF_HasStored == COLFLAG_STORED |
| | @@ -16909,10 +16933,11 @@ |
| 16909 | 16933 | #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */ |
| 16910 | 16934 | #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */ |
| 16911 | 16935 | #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */ |
| 16912 | 16936 | #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */ |
| 16913 | 16937 | #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */ |
| 16938 | +#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */ |
| 16914 | 16939 | #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */ |
| 16915 | 16940 | #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */ |
| 16916 | 16941 | |
| 16917 | 16942 | /* |
| 16918 | 16943 | ** A "Collating Sequence" is defined by an instance of the following |
| | @@ -17038,19 +17063,17 @@ |
| 17038 | 17063 | #define SQLITE_VTABRISK_Low 0 |
| 17039 | 17064 | #define SQLITE_VTABRISK_Normal 1 |
| 17040 | 17065 | #define SQLITE_VTABRISK_High 2 |
| 17041 | 17066 | |
| 17042 | 17067 | /* |
| 17043 | | -** The schema for each SQL table and view is represented in memory |
| 17044 | | -** by an instance of the following structure. |
| 17068 | +** The schema for each SQL table, virtual table, and view is represented |
| 17069 | +** in memory by an instance of the following structure. |
| 17045 | 17070 | */ |
| 17046 | 17071 | struct Table { |
| 17047 | 17072 | char *zName; /* Name of the table or view */ |
| 17048 | 17073 | Column *aCol; /* Information about each column */ |
| 17049 | 17074 | Index *pIndex; /* List of SQL indexes on this table. */ |
| 17050 | | - Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
| 17051 | | - FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 17052 | 17075 | char *zColAff; /* String defining the affinity of each column */ |
| 17053 | 17076 | ExprList *pCheck; /* All CHECK constraints */ |
| 17054 | 17077 | /* ... also used as column name list in a VIEW */ |
| 17055 | 17078 | Pgno tnum; /* Root BTree page for this table */ |
| 17056 | 17079 | u32 nTabRef; /* Number of pointers to this Table */ |
| | @@ -17062,19 +17085,28 @@ |
| 17062 | 17085 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 17063 | 17086 | #ifdef SQLITE_ENABLE_COSTMULT |
| 17064 | 17087 | LogEst costMult; /* Cost multiplier for using this table */ |
| 17065 | 17088 | #endif |
| 17066 | 17089 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 17067 | | -#ifndef SQLITE_OMIT_ALTERTABLE |
| 17068 | | - int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 17069 | | -#endif |
| 17070 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17071 | | - int nModuleArg; /* Number of arguments to the module */ |
| 17072 | | - char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */ |
| 17073 | | - VTable *pVTable; /* List of VTable objects. */ |
| 17074 | | -#endif |
| 17075 | | - Trigger *pTrigger; /* List of triggers stored in pSchema */ |
| 17090 | + u8 eTabType; /* 0: normal, 1: virtual, 2: view */ |
| 17091 | + union { |
| 17092 | + struct { /* Used by ordinary tables: */ |
| 17093 | + int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 17094 | + FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 17095 | + ExprList *pDfltList; /* DEFAULT clauses on various columns. |
| 17096 | + ** Or the AS clause for generated columns. */ |
| 17097 | + } tab; |
| 17098 | + struct { /* Used by views: */ |
| 17099 | + Select *pSelect; /* View definition */ |
| 17100 | + } view; |
| 17101 | + struct { /* Used by virtual tables only: */ |
| 17102 | + int nArg; /* Number of arguments to the module */ |
| 17103 | + char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */ |
| 17104 | + VTable *p; /* List of VTable objects. */ |
| 17105 | + } vtab; |
| 17106 | + } u; |
| 17107 | + Trigger *pTrigger; /* List of triggers on this object */ |
| 17076 | 17108 | Schema *pSchema; /* Schema that contains this table */ |
| 17077 | 17109 | }; |
| 17078 | 17110 | |
| 17079 | 17111 | /* |
| 17080 | 17112 | ** Allowed values for Table.tabFlags. |
| | @@ -17089,38 +17121,48 @@ |
| 17089 | 17121 | ** |
| 17090 | 17122 | ** TF_HasVirtual == COLFLAG_VIRTUAL |
| 17091 | 17123 | ** TF_HasStored == COLFLAG_STORED |
| 17092 | 17124 | ** TF_HasHidden == COLFLAG_HIDDEN |
| 17093 | 17125 | */ |
| 17094 | | -#define TF_Readonly 0x0001 /* Read-only system table */ |
| 17095 | | -#define TF_HasHidden 0x0002 /* Has one or more hidden columns */ |
| 17096 | | -#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */ |
| 17097 | | -#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */ |
| 17098 | | -#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */ |
| 17099 | | -#define TF_HasVirtual 0x0020 /* Has one or more VIRTUAL columns */ |
| 17100 | | -#define TF_HasStored 0x0040 /* Has one or more STORED columns */ |
| 17101 | | -#define TF_HasGenerated 0x0060 /* Combo: HasVirtual + HasStored */ |
| 17102 | | -#define TF_WithoutRowid 0x0080 /* No rowid. PRIMARY KEY is the key */ |
| 17103 | | -#define TF_StatsUsed 0x0100 /* Query planner decisions affected by |
| 17126 | +#define TF_Readonly 0x00000001 /* Read-only system table */ |
| 17127 | +#define TF_HasHidden 0x00000002 /* Has one or more hidden columns */ |
| 17128 | +#define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */ |
| 17129 | +#define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */ |
| 17130 | +#define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */ |
| 17131 | +#define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */ |
| 17132 | +#define TF_HasStored 0x00000040 /* Has one or more STORED columns */ |
| 17133 | +#define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */ |
| 17134 | +#define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */ |
| 17135 | +#define TF_StatsUsed 0x00000100 /* Query planner decisions affected by |
| 17104 | 17136 | ** Index.aiRowLogEst[] values */ |
| 17105 | | -#define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */ |
| 17106 | | -#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */ |
| 17107 | | -#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */ |
| 17108 | | -#define TF_Shadow 0x1000 /* True for a shadow table */ |
| 17109 | | -#define TF_HasStat4 0x2000 /* STAT4 info available for this table */ |
| 17110 | | -#define TF_Ephemeral 0x4000 /* An ephemeral table */ |
| 17111 | | -#define TF_Eponymous 0x8000 /* An eponymous virtual table */ |
| 17137 | +#define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */ |
| 17138 | +#define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */ |
| 17139 | +#define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */ |
| 17140 | +#define TF_Shadow 0x00001000 /* True for a shadow table */ |
| 17141 | +#define TF_HasStat4 0x00002000 /* STAT4 info available for this table */ |
| 17142 | +#define TF_Ephemeral 0x00004000 /* An ephemeral table */ |
| 17143 | +#define TF_Eponymous 0x00008000 /* An eponymous virtual table */ |
| 17144 | + |
| 17145 | +/* |
| 17146 | +** Allowed values for Table.eTabType |
| 17147 | +*/ |
| 17148 | +#define TABTYP_NORM 0 /* Ordinary table */ |
| 17149 | +#define TABTYP_VTAB 1 /* Virtual table */ |
| 17150 | +#define TABTYP_VIEW 2 /* A view */ |
| 17151 | + |
| 17152 | +#define IsView(X) ((X)->eTabType==TABTYP_VIEW) |
| 17153 | +#define IsOrdinaryTable(X) ((X)->eTabType==TABTYP_NORM) |
| 17112 | 17154 | |
| 17113 | 17155 | /* |
| 17114 | 17156 | ** Test to see whether or not a table is a virtual table. This is |
| 17115 | 17157 | ** done as a macro so that it will be optimized out when virtual |
| 17116 | 17158 | ** table support is omitted from the build. |
| 17117 | 17159 | */ |
| 17118 | 17160 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17119 | | -# define IsVirtual(X) ((X)->nModuleArg) |
| 17161 | +# define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB) |
| 17120 | 17162 | # define ExprIsVtab(X) \ |
| 17121 | | - ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg) |
| 17163 | + ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB) |
| 17122 | 17164 | #else |
| 17123 | 17165 | # define IsVirtual(X) 0 |
| 17124 | 17166 | # define ExprIsVtab(X) 0 |
| 17125 | 17167 | #endif |
| 17126 | 17168 | |
| | @@ -19170,10 +19212,11 @@ |
| 19170 | 19212 | SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); |
| 19171 | 19213 | SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); |
| 19172 | 19214 | SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int); |
| 19173 | 19215 | SQLITE_PRIVATE void sqlite3Dequote(char*); |
| 19174 | 19216 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*); |
| 19217 | +SQLITE_PRIVATE void sqlite3DequoteToken(Token*); |
| 19175 | 19218 | SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*); |
| 19176 | 19219 | SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); |
| 19177 | 19220 | SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); |
| 19178 | 19221 | SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); |
| 19179 | 19222 | SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); |
| | @@ -19215,10 +19258,14 @@ |
| 19215 | 19258 | #endif |
| 19216 | 19259 | SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*); |
| 19217 | 19260 | SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int); |
| 19218 | 19261 | SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*); |
| 19219 | 19262 | SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*); |
| 19263 | +SQLITE_PRIVATE void sqlite3ColumnSetExpr(Parse*,Table*,Column*,Expr*); |
| 19264 | +SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table*,Column*); |
| 19265 | +SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl); |
| 19266 | +SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*); |
| 19220 | 19267 | SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*); |
| 19221 | 19268 | SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect); |
| 19222 | 19269 | SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); |
| 19223 | 19270 | SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char); |
| 19224 | 19271 | SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char); |
| | @@ -19236,11 +19283,11 @@ |
| 19236 | 19283 | #if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 19237 | 19284 | SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*); |
| 19238 | 19285 | #else |
| 19239 | 19286 | # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ |
| 19240 | 19287 | #endif |
| 19241 | | -SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*); |
| 19288 | +SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token,Token); |
| 19242 | 19289 | SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); |
| 19243 | 19290 | SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); |
| 19244 | 19291 | SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*); |
| 19245 | 19292 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); |
| 19246 | 19293 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| | @@ -19353,11 +19400,11 @@ |
| 19353 | 19400 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 19354 | 19401 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 19355 | 19402 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 19356 | 19403 | SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 19357 | 19404 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 19358 | | -SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int); |
| 19405 | +SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int); |
| 19359 | 19406 | #endif |
| 19360 | 19407 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 19361 | 19408 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 19362 | 19409 | SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int); |
| 19363 | 19410 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| | @@ -19646,10 +19693,13 @@ |
| 19646 | 19693 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 19647 | 19694 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| 19648 | 19695 | #ifndef SQLITE_AMALGAMATION |
| 19649 | 19696 | SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 19650 | 19697 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 19698 | +SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[]; |
| 19699 | +SQLITE_PRIVATE const char sqlite3StdTypeAffinity[]; |
| 19700 | +SQLITE_PRIVATE const char *sqlite3StdType[]; |
| 19651 | 19701 | SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 19652 | 19702 | SQLITE_PRIVATE const unsigned char *sqlite3aLTb; |
| 19653 | 19703 | SQLITE_PRIVATE const unsigned char *sqlite3aEQb; |
| 19654 | 19704 | SQLITE_PRIVATE const unsigned char *sqlite3aGTb; |
| 19655 | 19705 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; |
| | @@ -20076,10 +20126,207 @@ |
| 20076 | 20126 | #endif |
| 20077 | 20127 | |
| 20078 | 20128 | #endif /* SQLITEINT_H */ |
| 20079 | 20129 | |
| 20080 | 20130 | /************** End of sqliteInt.h *******************************************/ |
| 20131 | +/************** Begin file os_common.h ***************************************/ |
| 20132 | +/* |
| 20133 | +** 2004 May 22 |
| 20134 | +** |
| 20135 | +** The author disclaims copyright to this source code. In place of |
| 20136 | +** a legal notice, here is a blessing: |
| 20137 | +** |
| 20138 | +** May you do good and not evil. |
| 20139 | +** May you find forgiveness for yourself and forgive others. |
| 20140 | +** May you share freely, never taking more than you give. |
| 20141 | +** |
| 20142 | +****************************************************************************** |
| 20143 | +** |
| 20144 | +** This file contains macros and a little bit of code that is common to |
| 20145 | +** all of the platform-specific files (os_*.c) and is #included into those |
| 20146 | +** files. |
| 20147 | +** |
| 20148 | +** This file should be #included by the os_*.c files only. It is not a |
| 20149 | +** general purpose header file. |
| 20150 | +*/ |
| 20151 | +#ifndef _OS_COMMON_H_ |
| 20152 | +#define _OS_COMMON_H_ |
| 20153 | + |
| 20154 | +/* |
| 20155 | +** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 20156 | +** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 20157 | +** switch. The following code should catch this problem at compile-time. |
| 20158 | +*/ |
| 20159 | +#ifdef MEMORY_DEBUG |
| 20160 | +# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 20161 | +#endif |
| 20162 | + |
| 20163 | +/* |
| 20164 | +** Macros for performance tracing. Normally turned off. Only works |
| 20165 | +** on i486 hardware. |
| 20166 | +*/ |
| 20167 | +#ifdef SQLITE_PERFORMANCE_TRACE |
| 20168 | + |
| 20169 | +/* |
| 20170 | +** hwtime.h contains inline assembler code for implementing |
| 20171 | +** high-performance timing routines. |
| 20172 | +*/ |
| 20173 | +/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 20174 | +/************** Begin file hwtime.h ******************************************/ |
| 20175 | +/* |
| 20176 | +** 2008 May 27 |
| 20177 | +** |
| 20178 | +** The author disclaims copyright to this source code. In place of |
| 20179 | +** a legal notice, here is a blessing: |
| 20180 | +** |
| 20181 | +** May you do good and not evil. |
| 20182 | +** May you find forgiveness for yourself and forgive others. |
| 20183 | +** May you share freely, never taking more than you give. |
| 20184 | +** |
| 20185 | +****************************************************************************** |
| 20186 | +** |
| 20187 | +** This file contains inline asm code for retrieving "high-performance" |
| 20188 | +** counters for x86 and x86_64 class CPUs. |
| 20189 | +*/ |
| 20190 | +#ifndef SQLITE_HWTIME_H |
| 20191 | +#define SQLITE_HWTIME_H |
| 20192 | + |
| 20193 | +/* |
| 20194 | +** The following routine only works on pentium-class (or newer) processors. |
| 20195 | +** It uses the RDTSC opcode to read the cycle count value out of the |
| 20196 | +** processor and returns that value. This can be used for high-res |
| 20197 | +** profiling. |
| 20198 | +*/ |
| 20199 | +#if !defined(__STRICT_ANSI__) && \ |
| 20200 | + (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 20201 | + (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 20202 | + |
| 20203 | + #if defined(__GNUC__) |
| 20204 | + |
| 20205 | + __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 20206 | + unsigned int lo, hi; |
| 20207 | + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 20208 | + return (sqlite_uint64)hi << 32 | lo; |
| 20209 | + } |
| 20210 | + |
| 20211 | + #elif defined(_MSC_VER) |
| 20212 | + |
| 20213 | + __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 20214 | + __asm { |
| 20215 | + rdtsc |
| 20216 | + ret ; return value at EDX:EAX |
| 20217 | + } |
| 20218 | + } |
| 20219 | + |
| 20220 | + #endif |
| 20221 | + |
| 20222 | +#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 20223 | + |
| 20224 | + __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 20225 | + unsigned long val; |
| 20226 | + __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 20227 | + return val; |
| 20228 | + } |
| 20229 | + |
| 20230 | +#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 20231 | + |
| 20232 | + __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 20233 | + unsigned long long retval; |
| 20234 | + unsigned long junk; |
| 20235 | + __asm__ __volatile__ ("\n\ |
| 20236 | + 1: mftbu %1\n\ |
| 20237 | + mftb %L0\n\ |
| 20238 | + mftbu %0\n\ |
| 20239 | + cmpw %0,%1\n\ |
| 20240 | + bne 1b" |
| 20241 | + : "=r" (retval), "=r" (junk)); |
| 20242 | + return retval; |
| 20243 | + } |
| 20244 | + |
| 20245 | +#else |
| 20246 | + |
| 20247 | + /* |
| 20248 | + ** asm() is needed for hardware timing support. Without asm(), |
| 20249 | + ** disable the sqlite3Hwtime() routine. |
| 20250 | + ** |
| 20251 | + ** sqlite3Hwtime() is only used for some obscure debugging |
| 20252 | + ** and analysis configurations, not in any deliverable, so this |
| 20253 | + ** should not be a great loss. |
| 20254 | + */ |
| 20255 | +SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 20256 | + |
| 20257 | +#endif |
| 20258 | + |
| 20259 | +#endif /* !defined(SQLITE_HWTIME_H) */ |
| 20260 | + |
| 20261 | +/************** End of hwtime.h **********************************************/ |
| 20262 | +/************** Continuing where we left off in os_common.h ******************/ |
| 20263 | + |
| 20264 | +static sqlite_uint64 g_start; |
| 20265 | +static sqlite_uint64 g_elapsed; |
| 20266 | +#define TIMER_START g_start=sqlite3Hwtime() |
| 20267 | +#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 20268 | +#define TIMER_ELAPSED g_elapsed |
| 20269 | +#else |
| 20270 | +#define TIMER_START |
| 20271 | +#define TIMER_END |
| 20272 | +#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 20273 | +#endif |
| 20274 | + |
| 20275 | +/* |
| 20276 | +** If we compile with the SQLITE_TEST macro set, then the following block |
| 20277 | +** of code will give us the ability to simulate a disk I/O error. This |
| 20278 | +** is used for testing the I/O recovery logic. |
| 20279 | +*/ |
| 20280 | +#if defined(SQLITE_TEST) |
| 20281 | +SQLITE_API extern int sqlite3_io_error_hit; |
| 20282 | +SQLITE_API extern int sqlite3_io_error_hardhit; |
| 20283 | +SQLITE_API extern int sqlite3_io_error_pending; |
| 20284 | +SQLITE_API extern int sqlite3_io_error_persist; |
| 20285 | +SQLITE_API extern int sqlite3_io_error_benign; |
| 20286 | +SQLITE_API extern int sqlite3_diskfull_pending; |
| 20287 | +SQLITE_API extern int sqlite3_diskfull; |
| 20288 | +#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 20289 | +#define SimulateIOError(CODE) \ |
| 20290 | + if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 20291 | + || sqlite3_io_error_pending-- == 1 ) \ |
| 20292 | + { local_ioerr(); CODE; } |
| 20293 | +static void local_ioerr(){ |
| 20294 | + IOTRACE(("IOERR\n")); |
| 20295 | + sqlite3_io_error_hit++; |
| 20296 | + if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 20297 | +} |
| 20298 | +#define SimulateDiskfullError(CODE) \ |
| 20299 | + if( sqlite3_diskfull_pending ){ \ |
| 20300 | + if( sqlite3_diskfull_pending == 1 ){ \ |
| 20301 | + local_ioerr(); \ |
| 20302 | + sqlite3_diskfull = 1; \ |
| 20303 | + sqlite3_io_error_hit = 1; \ |
| 20304 | + CODE; \ |
| 20305 | + }else{ \ |
| 20306 | + sqlite3_diskfull_pending--; \ |
| 20307 | + } \ |
| 20308 | + } |
| 20309 | +#else |
| 20310 | +#define SimulateIOErrorBenign(X) |
| 20311 | +#define SimulateIOError(A) |
| 20312 | +#define SimulateDiskfullError(A) |
| 20313 | +#endif /* defined(SQLITE_TEST) */ |
| 20314 | + |
| 20315 | +/* |
| 20316 | +** When testing, keep a count of the number of open files. |
| 20317 | +*/ |
| 20318 | +#if defined(SQLITE_TEST) |
| 20319 | +SQLITE_API extern int sqlite3_open_file_count; |
| 20320 | +#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 20321 | +#else |
| 20322 | +#define OpenCounter(X) |
| 20323 | +#endif /* defined(SQLITE_TEST) */ |
| 20324 | + |
| 20325 | +#endif /* !defined(_OS_COMMON_H_) */ |
| 20326 | + |
| 20327 | +/************** End of os_common.h *******************************************/ |
| 20081 | 20328 | /************** Begin file ctime.c *******************************************/ |
| 20082 | 20329 | /* |
| 20083 | 20330 | ** 2010 February 23 |
| 20084 | 20331 | ** |
| 20085 | 20332 | ** The author disclaims copyright to this source code. In place of |
| | @@ -21213,10 +21460,30 @@ |
| 21213 | 21460 | |
| 21214 | 21461 | /* |
| 21215 | 21462 | ** Name of the default collating sequence |
| 21216 | 21463 | */ |
| 21217 | 21464 | SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY"; |
| 21465 | + |
| 21466 | +/* |
| 21467 | +** Standard typenames. These names must match the COLTYPE_* definitions. |
| 21468 | +** Adjust the SQLITE_N_STDTYPE value if adding or removing entries. |
| 21469 | +*/ |
| 21470 | +SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[] = { 4, 3, 7, 4, 4 }; |
| 21471 | +SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = { |
| 21472 | + SQLITE_AFF_BLOB, |
| 21473 | + SQLITE_AFF_INTEGER, |
| 21474 | + SQLITE_AFF_INTEGER, |
| 21475 | + SQLITE_AFF_REAL, |
| 21476 | + SQLITE_AFF_TEXT |
| 21477 | +}; |
| 21478 | +SQLITE_PRIVATE const char *sqlite3StdType[] = { |
| 21479 | + "BLOB", |
| 21480 | + "INT", |
| 21481 | + "INTEGER", |
| 21482 | + "REAL", |
| 21483 | + "TEXT" |
| 21484 | +}; |
| 21218 | 21485 | |
| 21219 | 21486 | /************** End of global.c **********************************************/ |
| 21220 | 21487 | /************** Begin file status.c ******************************************/ |
| 21221 | 21488 | /* |
| 21222 | 21489 | ** 2008 June 18 |
| | @@ -27183,209 +27450,11 @@ |
| 27183 | 27450 | |
| 27184 | 27451 | #if SQLITE_OS_WIN |
| 27185 | 27452 | /* |
| 27186 | 27453 | ** Include code that is common to all os_*.c files |
| 27187 | 27454 | */ |
| 27188 | | -/************** Include os_common.h in the middle of mutex_w32.c *************/ |
| 27189 | | -/************** Begin file os_common.h ***************************************/ |
| 27190 | | -/* |
| 27191 | | -** 2004 May 22 |
| 27192 | | -** |
| 27193 | | -** The author disclaims copyright to this source code. In place of |
| 27194 | | -** a legal notice, here is a blessing: |
| 27195 | | -** |
| 27196 | | -** May you do good and not evil. |
| 27197 | | -** May you find forgiveness for yourself and forgive others. |
| 27198 | | -** May you share freely, never taking more than you give. |
| 27199 | | -** |
| 27200 | | -****************************************************************************** |
| 27201 | | -** |
| 27202 | | -** This file contains macros and a little bit of code that is common to |
| 27203 | | -** all of the platform-specific files (os_*.c) and is #included into those |
| 27204 | | -** files. |
| 27205 | | -** |
| 27206 | | -** This file should be #included by the os_*.c files only. It is not a |
| 27207 | | -** general purpose header file. |
| 27208 | | -*/ |
| 27209 | | -#ifndef _OS_COMMON_H_ |
| 27210 | | -#define _OS_COMMON_H_ |
| 27211 | | - |
| 27212 | | -/* |
| 27213 | | -** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 27214 | | -** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 27215 | | -** switch. The following code should catch this problem at compile-time. |
| 27216 | | -*/ |
| 27217 | | -#ifdef MEMORY_DEBUG |
| 27218 | | -# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 27219 | | -#endif |
| 27220 | | - |
| 27221 | | -/* |
| 27222 | | -** Macros for performance tracing. Normally turned off. Only works |
| 27223 | | -** on i486 hardware. |
| 27224 | | -*/ |
| 27225 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 27226 | | - |
| 27227 | | -/* |
| 27228 | | -** hwtime.h contains inline assembler code for implementing |
| 27229 | | -** high-performance timing routines. |
| 27230 | | -*/ |
| 27231 | | -/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 27232 | | -/************** Begin file hwtime.h ******************************************/ |
| 27233 | | -/* |
| 27234 | | -** 2008 May 27 |
| 27235 | | -** |
| 27236 | | -** The author disclaims copyright to this source code. In place of |
| 27237 | | -** a legal notice, here is a blessing: |
| 27238 | | -** |
| 27239 | | -** May you do good and not evil. |
| 27240 | | -** May you find forgiveness for yourself and forgive others. |
| 27241 | | -** May you share freely, never taking more than you give. |
| 27242 | | -** |
| 27243 | | -****************************************************************************** |
| 27244 | | -** |
| 27245 | | -** This file contains inline asm code for retrieving "high-performance" |
| 27246 | | -** counters for x86 and x86_64 class CPUs. |
| 27247 | | -*/ |
| 27248 | | -#ifndef SQLITE_HWTIME_H |
| 27249 | | -#define SQLITE_HWTIME_H |
| 27250 | | - |
| 27251 | | -/* |
| 27252 | | -** The following routine only works on pentium-class (or newer) processors. |
| 27253 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 27254 | | -** processor and returns that value. This can be used for high-res |
| 27255 | | -** profiling. |
| 27256 | | -*/ |
| 27257 | | -#if !defined(__STRICT_ANSI__) && \ |
| 27258 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 27259 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 27260 | | - |
| 27261 | | - #if defined(__GNUC__) |
| 27262 | | - |
| 27263 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 27264 | | - unsigned int lo, hi; |
| 27265 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 27266 | | - return (sqlite_uint64)hi << 32 | lo; |
| 27267 | | - } |
| 27268 | | - |
| 27269 | | - #elif defined(_MSC_VER) |
| 27270 | | - |
| 27271 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 27272 | | - __asm { |
| 27273 | | - rdtsc |
| 27274 | | - ret ; return value at EDX:EAX |
| 27275 | | - } |
| 27276 | | - } |
| 27277 | | - |
| 27278 | | - #endif |
| 27279 | | - |
| 27280 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 27281 | | - |
| 27282 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 27283 | | - unsigned long val; |
| 27284 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 27285 | | - return val; |
| 27286 | | - } |
| 27287 | | - |
| 27288 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 27289 | | - |
| 27290 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 27291 | | - unsigned long long retval; |
| 27292 | | - unsigned long junk; |
| 27293 | | - __asm__ __volatile__ ("\n\ |
| 27294 | | - 1: mftbu %1\n\ |
| 27295 | | - mftb %L0\n\ |
| 27296 | | - mftbu %0\n\ |
| 27297 | | - cmpw %0,%1\n\ |
| 27298 | | - bne 1b" |
| 27299 | | - : "=r" (retval), "=r" (junk)); |
| 27300 | | - return retval; |
| 27301 | | - } |
| 27302 | | - |
| 27303 | | -#else |
| 27304 | | - |
| 27305 | | - /* |
| 27306 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 27307 | | - ** disable the sqlite3Hwtime() routine. |
| 27308 | | - ** |
| 27309 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 27310 | | - ** and analysis configurations, not in any deliverable, so this |
| 27311 | | - ** should not be a great loss. |
| 27312 | | - */ |
| 27313 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 27314 | | - |
| 27315 | | -#endif |
| 27316 | | - |
| 27317 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 27318 | | - |
| 27319 | | -/************** End of hwtime.h **********************************************/ |
| 27320 | | -/************** Continuing where we left off in os_common.h ******************/ |
| 27321 | | - |
| 27322 | | -static sqlite_uint64 g_start; |
| 27323 | | -static sqlite_uint64 g_elapsed; |
| 27324 | | -#define TIMER_START g_start=sqlite3Hwtime() |
| 27325 | | -#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 27326 | | -#define TIMER_ELAPSED g_elapsed |
| 27327 | | -#else |
| 27328 | | -#define TIMER_START |
| 27329 | | -#define TIMER_END |
| 27330 | | -#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 27331 | | -#endif |
| 27332 | | - |
| 27333 | | -/* |
| 27334 | | -** If we compile with the SQLITE_TEST macro set, then the following block |
| 27335 | | -** of code will give us the ability to simulate a disk I/O error. This |
| 27336 | | -** is used for testing the I/O recovery logic. |
| 27337 | | -*/ |
| 27338 | | -#if defined(SQLITE_TEST) |
| 27339 | | -SQLITE_API extern int sqlite3_io_error_hit; |
| 27340 | | -SQLITE_API extern int sqlite3_io_error_hardhit; |
| 27341 | | -SQLITE_API extern int sqlite3_io_error_pending; |
| 27342 | | -SQLITE_API extern int sqlite3_io_error_persist; |
| 27343 | | -SQLITE_API extern int sqlite3_io_error_benign; |
| 27344 | | -SQLITE_API extern int sqlite3_diskfull_pending; |
| 27345 | | -SQLITE_API extern int sqlite3_diskfull; |
| 27346 | | -#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 27347 | | -#define SimulateIOError(CODE) \ |
| 27348 | | - if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 27349 | | - || sqlite3_io_error_pending-- == 1 ) \ |
| 27350 | | - { local_ioerr(); CODE; } |
| 27351 | | -static void local_ioerr(){ |
| 27352 | | - IOTRACE(("IOERR\n")); |
| 27353 | | - sqlite3_io_error_hit++; |
| 27354 | | - if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 27355 | | -} |
| 27356 | | -#define SimulateDiskfullError(CODE) \ |
| 27357 | | - if( sqlite3_diskfull_pending ){ \ |
| 27358 | | - if( sqlite3_diskfull_pending == 1 ){ \ |
| 27359 | | - local_ioerr(); \ |
| 27360 | | - sqlite3_diskfull = 1; \ |
| 27361 | | - sqlite3_io_error_hit = 1; \ |
| 27362 | | - CODE; \ |
| 27363 | | - }else{ \ |
| 27364 | | - sqlite3_diskfull_pending--; \ |
| 27365 | | - } \ |
| 27366 | | - } |
| 27367 | | -#else |
| 27368 | | -#define SimulateIOErrorBenign(X) |
| 27369 | | -#define SimulateIOError(A) |
| 27370 | | -#define SimulateDiskfullError(A) |
| 27371 | | -#endif /* defined(SQLITE_TEST) */ |
| 27372 | | - |
| 27373 | | -/* |
| 27374 | | -** When testing, keep a count of the number of open files. |
| 27375 | | -*/ |
| 27376 | | -#if defined(SQLITE_TEST) |
| 27377 | | -SQLITE_API extern int sqlite3_open_file_count; |
| 27378 | | -#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 27379 | | -#else |
| 27380 | | -#define OpenCounter(X) |
| 27381 | | -#endif /* defined(SQLITE_TEST) */ |
| 27382 | | - |
| 27383 | | -#endif /* !defined(_OS_COMMON_H_) */ |
| 27384 | | - |
| 27385 | | -/************** End of os_common.h *******************************************/ |
| 27386 | | -/************** Continuing where we left off in mutex_w32.c ******************/ |
| 27455 | +/* #include "os_common.h" */ |
| 27387 | 27456 | |
| 27388 | 27457 | /* |
| 27389 | 27458 | ** Include the header file for the Windows VFS. |
| 27390 | 27459 | */ |
| 27391 | 27460 | /************** Include os_win.h in the middle of mutex_w32.c ****************/ |
| | @@ -30484,12 +30553,12 @@ |
| 30484 | 30553 | case TK_NULL: { |
| 30485 | 30554 | sqlite3TreeViewLine(pView,"NULL"); |
| 30486 | 30555 | break; |
| 30487 | 30556 | } |
| 30488 | 30557 | case TK_TRUEFALSE: { |
| 30489 | | - sqlite3TreeViewLine(pView, |
| 30490 | | - sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE"); |
| 30558 | + sqlite3TreeViewLine(pView,"%s%s", |
| 30559 | + sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
| 30491 | 30560 | break; |
| 30492 | 30561 | } |
| 30493 | 30562 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 30494 | 30563 | case TK_BLOB: { |
| 30495 | 30564 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| | @@ -31856,12 +31925,18 @@ |
| 31856 | 31925 | ** |
| 31857 | 31926 | ** The column type is an extra string stored after the zero-terminator on |
| 31858 | 31927 | ** the column name if and only if the COLFLAG_HASTYPE flag is set. |
| 31859 | 31928 | */ |
| 31860 | 31929 | SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){ |
| 31861 | | - if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt; |
| 31862 | | - return pCol->zName + strlen(pCol->zName) + 1; |
| 31930 | + if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 31931 | + return pCol->zCnName + strlen(pCol->zCnName) + 1; |
| 31932 | + }else if( pCol->eType ){ |
| 31933 | + assert( pCol->eType<=SQLITE_N_STDTYPE ); |
| 31934 | + return (char*)sqlite3StdType[pCol->eType-1]; |
| 31935 | + }else{ |
| 31936 | + return zDflt; |
| 31937 | + } |
| 31863 | 31938 | } |
| 31864 | 31939 | |
| 31865 | 31940 | /* |
| 31866 | 31941 | ** Helper function for sqlite3Error() - called rarely. Broken out into |
| 31867 | 31942 | ** a separate routine to avoid unnecessary register saves on entry to |
| | @@ -32032,10 +32107,32 @@ |
| 32032 | 32107 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){ |
| 32033 | 32108 | assert( sqlite3Isquote(p->u.zToken[0]) ); |
| 32034 | 32109 | p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; |
| 32035 | 32110 | sqlite3Dequote(p->u.zToken); |
| 32036 | 32111 | } |
| 32112 | + |
| 32113 | +/* |
| 32114 | +** If the input token p is quoted, try to adjust the token to remove |
| 32115 | +** the quotes. This is not always possible: |
| 32116 | +** |
| 32117 | +** "abc" -> abc |
| 32118 | +** "ab""cd" -> (not possible because of the interior "") |
| 32119 | +** |
| 32120 | +** Remove the quotes if possible. This is a optimization. The overall |
| 32121 | +** system should still return the correct answer even if this routine |
| 32122 | +** is always a no-op. |
| 32123 | +*/ |
| 32124 | +SQLITE_PRIVATE void sqlite3DequoteToken(Token *p){ |
| 32125 | + unsigned int i; |
| 32126 | + if( p->n<2 ) return; |
| 32127 | + if( !sqlite3Isquote(p->z[0]) ) return; |
| 32128 | + for(i=1; i<p->n-1; i++){ |
| 32129 | + if( sqlite3Isquote(p->z[i]) ) return; |
| 32130 | + } |
| 32131 | + p->n -= 2; |
| 32132 | + p->z++; |
| 32133 | +} |
| 32037 | 32134 | |
| 32038 | 32135 | /* |
| 32039 | 32136 | ** Generate a Token object from a string |
| 32040 | 32137 | */ |
| 32041 | 32138 | SQLITE_PRIVATE void sqlite3TokenInit(Token *p, char *z){ |
| | @@ -34243,209 +34340,11 @@ |
| 34243 | 34340 | #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ |
| 34244 | 34341 | |
| 34245 | 34342 | /* |
| 34246 | 34343 | ** Include code that is common to all os_*.c files |
| 34247 | 34344 | */ |
| 34248 | | -/************** Include os_common.h in the middle of os_unix.c ***************/ |
| 34249 | | -/************** Begin file os_common.h ***************************************/ |
| 34250 | | -/* |
| 34251 | | -** 2004 May 22 |
| 34252 | | -** |
| 34253 | | -** The author disclaims copyright to this source code. In place of |
| 34254 | | -** a legal notice, here is a blessing: |
| 34255 | | -** |
| 34256 | | -** May you do good and not evil. |
| 34257 | | -** May you find forgiveness for yourself and forgive others. |
| 34258 | | -** May you share freely, never taking more than you give. |
| 34259 | | -** |
| 34260 | | -****************************************************************************** |
| 34261 | | -** |
| 34262 | | -** This file contains macros and a little bit of code that is common to |
| 34263 | | -** all of the platform-specific files (os_*.c) and is #included into those |
| 34264 | | -** files. |
| 34265 | | -** |
| 34266 | | -** This file should be #included by the os_*.c files only. It is not a |
| 34267 | | -** general purpose header file. |
| 34268 | | -*/ |
| 34269 | | -#ifndef _OS_COMMON_H_ |
| 34270 | | -#define _OS_COMMON_H_ |
| 34271 | | - |
| 34272 | | -/* |
| 34273 | | -** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 34274 | | -** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 34275 | | -** switch. The following code should catch this problem at compile-time. |
| 34276 | | -*/ |
| 34277 | | -#ifdef MEMORY_DEBUG |
| 34278 | | -# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 34279 | | -#endif |
| 34280 | | - |
| 34281 | | -/* |
| 34282 | | -** Macros for performance tracing. Normally turned off. Only works |
| 34283 | | -** on i486 hardware. |
| 34284 | | -*/ |
| 34285 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 34286 | | - |
| 34287 | | -/* |
| 34288 | | -** hwtime.h contains inline assembler code for implementing |
| 34289 | | -** high-performance timing routines. |
| 34290 | | -*/ |
| 34291 | | -/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 34292 | | -/************** Begin file hwtime.h ******************************************/ |
| 34293 | | -/* |
| 34294 | | -** 2008 May 27 |
| 34295 | | -** |
| 34296 | | -** The author disclaims copyright to this source code. In place of |
| 34297 | | -** a legal notice, here is a blessing: |
| 34298 | | -** |
| 34299 | | -** May you do good and not evil. |
| 34300 | | -** May you find forgiveness for yourself and forgive others. |
| 34301 | | -** May you share freely, never taking more than you give. |
| 34302 | | -** |
| 34303 | | -****************************************************************************** |
| 34304 | | -** |
| 34305 | | -** This file contains inline asm code for retrieving "high-performance" |
| 34306 | | -** counters for x86 and x86_64 class CPUs. |
| 34307 | | -*/ |
| 34308 | | -#ifndef SQLITE_HWTIME_H |
| 34309 | | -#define SQLITE_HWTIME_H |
| 34310 | | - |
| 34311 | | -/* |
| 34312 | | -** The following routine only works on pentium-class (or newer) processors. |
| 34313 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 34314 | | -** processor and returns that value. This can be used for high-res |
| 34315 | | -** profiling. |
| 34316 | | -*/ |
| 34317 | | -#if !defined(__STRICT_ANSI__) && \ |
| 34318 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 34319 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 34320 | | - |
| 34321 | | - #if defined(__GNUC__) |
| 34322 | | - |
| 34323 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 34324 | | - unsigned int lo, hi; |
| 34325 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 34326 | | - return (sqlite_uint64)hi << 32 | lo; |
| 34327 | | - } |
| 34328 | | - |
| 34329 | | - #elif defined(_MSC_VER) |
| 34330 | | - |
| 34331 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 34332 | | - __asm { |
| 34333 | | - rdtsc |
| 34334 | | - ret ; return value at EDX:EAX |
| 34335 | | - } |
| 34336 | | - } |
| 34337 | | - |
| 34338 | | - #endif |
| 34339 | | - |
| 34340 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 34341 | | - |
| 34342 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 34343 | | - unsigned long val; |
| 34344 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 34345 | | - return val; |
| 34346 | | - } |
| 34347 | | - |
| 34348 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 34349 | | - |
| 34350 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 34351 | | - unsigned long long retval; |
| 34352 | | - unsigned long junk; |
| 34353 | | - __asm__ __volatile__ ("\n\ |
| 34354 | | - 1: mftbu %1\n\ |
| 34355 | | - mftb %L0\n\ |
| 34356 | | - mftbu %0\n\ |
| 34357 | | - cmpw %0,%1\n\ |
| 34358 | | - bne 1b" |
| 34359 | | - : "=r" (retval), "=r" (junk)); |
| 34360 | | - return retval; |
| 34361 | | - } |
| 34362 | | - |
| 34363 | | -#else |
| 34364 | | - |
| 34365 | | - /* |
| 34366 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 34367 | | - ** disable the sqlite3Hwtime() routine. |
| 34368 | | - ** |
| 34369 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 34370 | | - ** and analysis configurations, not in any deliverable, so this |
| 34371 | | - ** should not be a great loss. |
| 34372 | | - */ |
| 34373 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 34374 | | - |
| 34375 | | -#endif |
| 34376 | | - |
| 34377 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 34378 | | - |
| 34379 | | -/************** End of hwtime.h **********************************************/ |
| 34380 | | -/************** Continuing where we left off in os_common.h ******************/ |
| 34381 | | - |
| 34382 | | -static sqlite_uint64 g_start; |
| 34383 | | -static sqlite_uint64 g_elapsed; |
| 34384 | | -#define TIMER_START g_start=sqlite3Hwtime() |
| 34385 | | -#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 34386 | | -#define TIMER_ELAPSED g_elapsed |
| 34387 | | -#else |
| 34388 | | -#define TIMER_START |
| 34389 | | -#define TIMER_END |
| 34390 | | -#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 34391 | | -#endif |
| 34392 | | - |
| 34393 | | -/* |
| 34394 | | -** If we compile with the SQLITE_TEST macro set, then the following block |
| 34395 | | -** of code will give us the ability to simulate a disk I/O error. This |
| 34396 | | -** is used for testing the I/O recovery logic. |
| 34397 | | -*/ |
| 34398 | | -#if defined(SQLITE_TEST) |
| 34399 | | -SQLITE_API extern int sqlite3_io_error_hit; |
| 34400 | | -SQLITE_API extern int sqlite3_io_error_hardhit; |
| 34401 | | -SQLITE_API extern int sqlite3_io_error_pending; |
| 34402 | | -SQLITE_API extern int sqlite3_io_error_persist; |
| 34403 | | -SQLITE_API extern int sqlite3_io_error_benign; |
| 34404 | | -SQLITE_API extern int sqlite3_diskfull_pending; |
| 34405 | | -SQLITE_API extern int sqlite3_diskfull; |
| 34406 | | -#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 34407 | | -#define SimulateIOError(CODE) \ |
| 34408 | | - if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 34409 | | - || sqlite3_io_error_pending-- == 1 ) \ |
| 34410 | | - { local_ioerr(); CODE; } |
| 34411 | | -static void local_ioerr(){ |
| 34412 | | - IOTRACE(("IOERR\n")); |
| 34413 | | - sqlite3_io_error_hit++; |
| 34414 | | - if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 34415 | | -} |
| 34416 | | -#define SimulateDiskfullError(CODE) \ |
| 34417 | | - if( sqlite3_diskfull_pending ){ \ |
| 34418 | | - if( sqlite3_diskfull_pending == 1 ){ \ |
| 34419 | | - local_ioerr(); \ |
| 34420 | | - sqlite3_diskfull = 1; \ |
| 34421 | | - sqlite3_io_error_hit = 1; \ |
| 34422 | | - CODE; \ |
| 34423 | | - }else{ \ |
| 34424 | | - sqlite3_diskfull_pending--; \ |
| 34425 | | - } \ |
| 34426 | | - } |
| 34427 | | -#else |
| 34428 | | -#define SimulateIOErrorBenign(X) |
| 34429 | | -#define SimulateIOError(A) |
| 34430 | | -#define SimulateDiskfullError(A) |
| 34431 | | -#endif /* defined(SQLITE_TEST) */ |
| 34432 | | - |
| 34433 | | -/* |
| 34434 | | -** When testing, keep a count of the number of open files. |
| 34435 | | -*/ |
| 34436 | | -#if defined(SQLITE_TEST) |
| 34437 | | -SQLITE_API extern int sqlite3_open_file_count; |
| 34438 | | -#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 34439 | | -#else |
| 34440 | | -#define OpenCounter(X) |
| 34441 | | -#endif /* defined(SQLITE_TEST) */ |
| 34442 | | - |
| 34443 | | -#endif /* !defined(_OS_COMMON_H_) */ |
| 34444 | | - |
| 34445 | | -/************** End of os_common.h *******************************************/ |
| 34446 | | -/************** Continuing where we left off in os_unix.c ********************/ |
| 34345 | +/* #include "os_common.h" */ |
| 34447 | 34346 | |
| 34448 | 34347 | /* |
| 34449 | 34348 | ** Define various macros that are missing from some systems. |
| 34450 | 34349 | */ |
| 34451 | 34350 | #ifndef O_LARGEFILE |
| | @@ -42271,209 +42170,11 @@ |
| 42271 | 42170 | #if SQLITE_OS_WIN /* This file is used for Windows only */ |
| 42272 | 42171 | |
| 42273 | 42172 | /* |
| 42274 | 42173 | ** Include code that is common to all os_*.c files |
| 42275 | 42174 | */ |
| 42276 | | -/************** Include os_common.h in the middle of os_win.c ****************/ |
| 42277 | | -/************** Begin file os_common.h ***************************************/ |
| 42278 | | -/* |
| 42279 | | -** 2004 May 22 |
| 42280 | | -** |
| 42281 | | -** The author disclaims copyright to this source code. In place of |
| 42282 | | -** a legal notice, here is a blessing: |
| 42283 | | -** |
| 42284 | | -** May you do good and not evil. |
| 42285 | | -** May you find forgiveness for yourself and forgive others. |
| 42286 | | -** May you share freely, never taking more than you give. |
| 42287 | | -** |
| 42288 | | -****************************************************************************** |
| 42289 | | -** |
| 42290 | | -** This file contains macros and a little bit of code that is common to |
| 42291 | | -** all of the platform-specific files (os_*.c) and is #included into those |
| 42292 | | -** files. |
| 42293 | | -** |
| 42294 | | -** This file should be #included by the os_*.c files only. It is not a |
| 42295 | | -** general purpose header file. |
| 42296 | | -*/ |
| 42297 | | -#ifndef _OS_COMMON_H_ |
| 42298 | | -#define _OS_COMMON_H_ |
| 42299 | | - |
| 42300 | | -/* |
| 42301 | | -** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 42302 | | -** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 42303 | | -** switch. The following code should catch this problem at compile-time. |
| 42304 | | -*/ |
| 42305 | | -#ifdef MEMORY_DEBUG |
| 42306 | | -# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 42307 | | -#endif |
| 42308 | | - |
| 42309 | | -/* |
| 42310 | | -** Macros for performance tracing. Normally turned off. Only works |
| 42311 | | -** on i486 hardware. |
| 42312 | | -*/ |
| 42313 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 42314 | | - |
| 42315 | | -/* |
| 42316 | | -** hwtime.h contains inline assembler code for implementing |
| 42317 | | -** high-performance timing routines. |
| 42318 | | -*/ |
| 42319 | | -/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 42320 | | -/************** Begin file hwtime.h ******************************************/ |
| 42321 | | -/* |
| 42322 | | -** 2008 May 27 |
| 42323 | | -** |
| 42324 | | -** The author disclaims copyright to this source code. In place of |
| 42325 | | -** a legal notice, here is a blessing: |
| 42326 | | -** |
| 42327 | | -** May you do good and not evil. |
| 42328 | | -** May you find forgiveness for yourself and forgive others. |
| 42329 | | -** May you share freely, never taking more than you give. |
| 42330 | | -** |
| 42331 | | -****************************************************************************** |
| 42332 | | -** |
| 42333 | | -** This file contains inline asm code for retrieving "high-performance" |
| 42334 | | -** counters for x86 and x86_64 class CPUs. |
| 42335 | | -*/ |
| 42336 | | -#ifndef SQLITE_HWTIME_H |
| 42337 | | -#define SQLITE_HWTIME_H |
| 42338 | | - |
| 42339 | | -/* |
| 42340 | | -** The following routine only works on pentium-class (or newer) processors. |
| 42341 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 42342 | | -** processor and returns that value. This can be used for high-res |
| 42343 | | -** profiling. |
| 42344 | | -*/ |
| 42345 | | -#if !defined(__STRICT_ANSI__) && \ |
| 42346 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 42347 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 42348 | | - |
| 42349 | | - #if defined(__GNUC__) |
| 42350 | | - |
| 42351 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 42352 | | - unsigned int lo, hi; |
| 42353 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 42354 | | - return (sqlite_uint64)hi << 32 | lo; |
| 42355 | | - } |
| 42356 | | - |
| 42357 | | - #elif defined(_MSC_VER) |
| 42358 | | - |
| 42359 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 42360 | | - __asm { |
| 42361 | | - rdtsc |
| 42362 | | - ret ; return value at EDX:EAX |
| 42363 | | - } |
| 42364 | | - } |
| 42365 | | - |
| 42366 | | - #endif |
| 42367 | | - |
| 42368 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 42369 | | - |
| 42370 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 42371 | | - unsigned long val; |
| 42372 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 42373 | | - return val; |
| 42374 | | - } |
| 42375 | | - |
| 42376 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 42377 | | - |
| 42378 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 42379 | | - unsigned long long retval; |
| 42380 | | - unsigned long junk; |
| 42381 | | - __asm__ __volatile__ ("\n\ |
| 42382 | | - 1: mftbu %1\n\ |
| 42383 | | - mftb %L0\n\ |
| 42384 | | - mftbu %0\n\ |
| 42385 | | - cmpw %0,%1\n\ |
| 42386 | | - bne 1b" |
| 42387 | | - : "=r" (retval), "=r" (junk)); |
| 42388 | | - return retval; |
| 42389 | | - } |
| 42390 | | - |
| 42391 | | -#else |
| 42392 | | - |
| 42393 | | - /* |
| 42394 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 42395 | | - ** disable the sqlite3Hwtime() routine. |
| 42396 | | - ** |
| 42397 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 42398 | | - ** and analysis configurations, not in any deliverable, so this |
| 42399 | | - ** should not be a great loss. |
| 42400 | | - */ |
| 42401 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 42402 | | - |
| 42403 | | -#endif |
| 42404 | | - |
| 42405 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 42406 | | - |
| 42407 | | -/************** End of hwtime.h **********************************************/ |
| 42408 | | -/************** Continuing where we left off in os_common.h ******************/ |
| 42409 | | - |
| 42410 | | -static sqlite_uint64 g_start; |
| 42411 | | -static sqlite_uint64 g_elapsed; |
| 42412 | | -#define TIMER_START g_start=sqlite3Hwtime() |
| 42413 | | -#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 42414 | | -#define TIMER_ELAPSED g_elapsed |
| 42415 | | -#else |
| 42416 | | -#define TIMER_START |
| 42417 | | -#define TIMER_END |
| 42418 | | -#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 42419 | | -#endif |
| 42420 | | - |
| 42421 | | -/* |
| 42422 | | -** If we compile with the SQLITE_TEST macro set, then the following block |
| 42423 | | -** of code will give us the ability to simulate a disk I/O error. This |
| 42424 | | -** is used for testing the I/O recovery logic. |
| 42425 | | -*/ |
| 42426 | | -#if defined(SQLITE_TEST) |
| 42427 | | -SQLITE_API extern int sqlite3_io_error_hit; |
| 42428 | | -SQLITE_API extern int sqlite3_io_error_hardhit; |
| 42429 | | -SQLITE_API extern int sqlite3_io_error_pending; |
| 42430 | | -SQLITE_API extern int sqlite3_io_error_persist; |
| 42431 | | -SQLITE_API extern int sqlite3_io_error_benign; |
| 42432 | | -SQLITE_API extern int sqlite3_diskfull_pending; |
| 42433 | | -SQLITE_API extern int sqlite3_diskfull; |
| 42434 | | -#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 42435 | | -#define SimulateIOError(CODE) \ |
| 42436 | | - if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 42437 | | - || sqlite3_io_error_pending-- == 1 ) \ |
| 42438 | | - { local_ioerr(); CODE; } |
| 42439 | | -static void local_ioerr(){ |
| 42440 | | - IOTRACE(("IOERR\n")); |
| 42441 | | - sqlite3_io_error_hit++; |
| 42442 | | - if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 42443 | | -} |
| 42444 | | -#define SimulateDiskfullError(CODE) \ |
| 42445 | | - if( sqlite3_diskfull_pending ){ \ |
| 42446 | | - if( sqlite3_diskfull_pending == 1 ){ \ |
| 42447 | | - local_ioerr(); \ |
| 42448 | | - sqlite3_diskfull = 1; \ |
| 42449 | | - sqlite3_io_error_hit = 1; \ |
| 42450 | | - CODE; \ |
| 42451 | | - }else{ \ |
| 42452 | | - sqlite3_diskfull_pending--; \ |
| 42453 | | - } \ |
| 42454 | | - } |
| 42455 | | -#else |
| 42456 | | -#define SimulateIOErrorBenign(X) |
| 42457 | | -#define SimulateIOError(A) |
| 42458 | | -#define SimulateDiskfullError(A) |
| 42459 | | -#endif /* defined(SQLITE_TEST) */ |
| 42460 | | - |
| 42461 | | -/* |
| 42462 | | -** When testing, keep a count of the number of open files. |
| 42463 | | -*/ |
| 42464 | | -#if defined(SQLITE_TEST) |
| 42465 | | -SQLITE_API extern int sqlite3_open_file_count; |
| 42466 | | -#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 42467 | | -#else |
| 42468 | | -#define OpenCounter(X) |
| 42469 | | -#endif /* defined(SQLITE_TEST) */ |
| 42470 | | - |
| 42471 | | -#endif /* !defined(_OS_COMMON_H_) */ |
| 42472 | | - |
| 42473 | | -/************** End of os_common.h *******************************************/ |
| 42474 | | -/************** Continuing where we left off in os_win.c *********************/ |
| 42175 | +/* #include "os_common.h" */ |
| 42475 | 42176 | |
| 42476 | 42177 | /* |
| 42477 | 42178 | ** Include the header file for the Windows VFS. |
| 42478 | 42179 | */ |
| 42479 | 42180 | /* #include "os_win.h" */ |
| | @@ -60605,11 +60306,14 @@ |
| 60605 | 60306 | ** Each index block except for the first contains information on |
| 60606 | 60307 | ** HASHTABLE_NPAGE frames. The first index block contains information on |
| 60607 | 60308 | ** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and |
| 60608 | 60309 | ** HASHTABLE_NPAGE are selected so that together the wal-index header and |
| 60609 | 60310 | ** first index block are the same size as all other index blocks in the |
| 60610 | | -** wal-index. |
| 60311 | +** wal-index. The values are: |
| 60312 | +** |
| 60313 | +** HASHTABLE_NPAGE 4096 |
| 60314 | +** HASHTABLE_NPAGE_ONE 4062 |
| 60611 | 60315 | ** |
| 60612 | 60316 | ** Each index block contains two sections, a page-mapping that contains the |
| 60613 | 60317 | ** database page number associated with each wal frame, and a hash-table |
| 60614 | 60318 | ** that allows readers to query an index block for a specific page number. |
| 60615 | 60319 | ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE |
| | @@ -60841,10 +60545,74 @@ |
| 60841 | 60545 | u32 nBackfillAttempted; /* WAL frames perhaps written, or maybe not */ |
| 60842 | 60546 | u32 notUsed0; /* Available for future enhancements */ |
| 60843 | 60547 | }; |
| 60844 | 60548 | #define READMARK_NOT_USED 0xffffffff |
| 60845 | 60549 | |
| 60550 | +/* |
| 60551 | +** This is a schematic view of the complete 136-byte header of the |
| 60552 | +** wal-index file (also known as the -shm file): |
| 60553 | +** |
| 60554 | +** +-----------------------------+ |
| 60555 | +** 0: | iVersion | \ |
| 60556 | +** +-----------------------------+ | |
| 60557 | +** 4: | (unused padding) | | |
| 60558 | +** +-----------------------------+ | |
| 60559 | +** 8: | iChange | | |
| 60560 | +** +-------+-------+-------------+ | |
| 60561 | +** 12: | bInit | bBig | szPage | | |
| 60562 | +** +-------+-------+-------------+ | |
| 60563 | +** 16: | mxFrame | | First copy of the |
| 60564 | +** +-----------------------------+ | WalIndexHdr object |
| 60565 | +** 20: | nPage | | |
| 60566 | +** +-----------------------------+ | |
| 60567 | +** 24: | aFrameCksum | | |
| 60568 | +** | | | |
| 60569 | +** +-----------------------------+ | |
| 60570 | +** 32: | aSalt | | |
| 60571 | +** | | | |
| 60572 | +** +-----------------------------+ | |
| 60573 | +** 40: | aCksum | | |
| 60574 | +** | | / |
| 60575 | +** +-----------------------------+ |
| 60576 | +** 48: | iVersion | \ |
| 60577 | +** +-----------------------------+ | |
| 60578 | +** 52: | (unused padding) | | |
| 60579 | +** +-----------------------------+ | |
| 60580 | +** 56: | iChange | | |
| 60581 | +** +-------+-------+-------------+ | |
| 60582 | +** 60: | bInit | bBig | szPage | | |
| 60583 | +** +-------+-------+-------------+ | Second copy of the |
| 60584 | +** 64: | mxFrame | | WalIndexHdr |
| 60585 | +** +-----------------------------+ | |
| 60586 | +** 68: | nPage | | |
| 60587 | +** +-----------------------------+ | |
| 60588 | +** 72: | aFrameCksum | | |
| 60589 | +** | | | |
| 60590 | +** +-----------------------------+ | |
| 60591 | +** 80: | aSalt | | |
| 60592 | +** | | | |
| 60593 | +** +-----------------------------+ | |
| 60594 | +** 88: | aCksum | | |
| 60595 | +** | | / |
| 60596 | +** +-----------------------------+ |
| 60597 | +** 96: | nBackfill | |
| 60598 | +** +-----------------------------+ |
| 60599 | +** 100: | 5 read marks | |
| 60600 | +** | | |
| 60601 | +** | | |
| 60602 | +** | | |
| 60603 | +** | | |
| 60604 | +** +-------+-------+------+------+ |
| 60605 | +** 120: | Write | Ckpt | Rcvr | Rd0 | \ |
| 60606 | +** +-------+-------+------+------+ ) 8 lock bytes |
| 60607 | +** | Read1 | Read2 | Rd3 | Rd4 | / |
| 60608 | +** +-------+-------+------+------+ |
| 60609 | +** 128: | nBackfillAttempted | |
| 60610 | +** +-----------------------------+ |
| 60611 | +** 132: | (unused padding) | |
| 60612 | +** +-----------------------------+ |
| 60613 | +*/ |
| 60846 | 60614 | |
| 60847 | 60615 | /* A block of WALINDEX_LOCK_RESERVED bytes beginning at |
| 60848 | 60616 | ** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems |
| 60849 | 60617 | ** only support mandatory file-locks, we do not read or write data |
| 60850 | 60618 | ** from the region of the file on which locks are applied. |
| | @@ -61853,19 +61621,48 @@ |
| 61853 | 61621 | Wal *pRet; /* Object to allocate and return */ |
| 61854 | 61622 | int flags; /* Flags passed to OsOpen() */ |
| 61855 | 61623 | |
| 61856 | 61624 | assert( zWalName && zWalName[0] ); |
| 61857 | 61625 | assert( pDbFd ); |
| 61626 | + |
| 61627 | + /* Verify the values of various constants. Any changes to the values |
| 61628 | + ** of these constants would result in an incompatible on-disk format |
| 61629 | + ** for the -shm file. Any change that causes one of these asserts to |
| 61630 | + ** fail is a backward compatibility problem, even if the change otherwise |
| 61631 | + ** works. |
| 61632 | + ** |
| 61633 | + ** This table also serves as a helpful cross-reference when trying to |
| 61634 | + ** interpret hex dumps of the -shm file. |
| 61635 | + */ |
| 61636 | + assert( 48 == sizeof(WalIndexHdr) ); |
| 61637 | + assert( 40 == sizeof(WalCkptInfo) ); |
| 61638 | + assert( 120 == WALINDEX_LOCK_OFFSET ); |
| 61639 | + assert( 136 == WALINDEX_HDR_SIZE ); |
| 61640 | + assert( 4096 == HASHTABLE_NPAGE ); |
| 61641 | + assert( 4062 == HASHTABLE_NPAGE_ONE ); |
| 61642 | + assert( 8192 == HASHTABLE_NSLOT ); |
| 61643 | + assert( 383 == HASHTABLE_HASH_1 ); |
| 61644 | + assert( 32768 == WALINDEX_PGSZ ); |
| 61645 | + assert( 8 == SQLITE_SHM_NLOCK ); |
| 61646 | + assert( 5 == WAL_NREADER ); |
| 61647 | + assert( 24 == WAL_FRAME_HDRSIZE ); |
| 61648 | + assert( 32 == WAL_HDRSIZE ); |
| 61649 | + assert( 120 == WALINDEX_LOCK_OFFSET + WAL_WRITE_LOCK ); |
| 61650 | + assert( 121 == WALINDEX_LOCK_OFFSET + WAL_CKPT_LOCK ); |
| 61651 | + assert( 122 == WALINDEX_LOCK_OFFSET + WAL_RECOVER_LOCK ); |
| 61652 | + assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) ); |
| 61653 | + assert( 124 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(1) ); |
| 61654 | + assert( 125 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(2) ); |
| 61655 | + assert( 126 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(3) ); |
| 61656 | + assert( 127 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(4) ); |
| 61858 | 61657 | |
| 61859 | 61658 | /* In the amalgamation, the os_unix.c and os_win.c source files come before |
| 61860 | 61659 | ** this source file. Verify that the #defines of the locking byte offsets |
| 61861 | 61660 | ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value. |
| 61862 | 61661 | ** For that matter, if the lock offset ever changes from its initial design |
| 61863 | 61662 | ** value of 120, we need to know that so there is an assert() to check it. |
| 61864 | 61663 | */ |
| 61865 | | - assert( 120==WALINDEX_LOCK_OFFSET ); |
| 61866 | | - assert( 136==WALINDEX_HDR_SIZE ); |
| 61867 | 61664 | #ifdef WIN_SHM_BASE |
| 61868 | 61665 | assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET ); |
| 61869 | 61666 | #endif |
| 61870 | 61667 | #ifdef UNIX_SHM_BASE |
| 61871 | 61668 | assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET ); |
| | @@ -80741,11 +80538,11 @@ |
| 80741 | 80538 | } |
| 80742 | 80539 | #endif |
| 80743 | 80540 | case P4_COLLSEQ: { |
| 80744 | 80541 | static const char *const encnames[] = {"?", "8", "16LE", "16BE"}; |
| 80745 | 80542 | CollSeq *pColl = pOp->p4.pColl; |
| 80746 | | - assert( pColl->enc>=0 && pColl->enc<4 ); |
| 80543 | + assert( pColl->enc<4 ); |
| 80747 | 80544 | sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName, |
| 80748 | 80545 | encnames[pColl->enc]); |
| 80749 | 80546 | break; |
| 80750 | 80547 | } |
| 80751 | 80548 | case P4_FUNCDEF: { |
| | @@ -87207,100 +87004,11 @@ |
| 87207 | 87004 | |
| 87208 | 87005 | /* |
| 87209 | 87006 | ** hwtime.h contains inline assembler code for implementing |
| 87210 | 87007 | ** high-performance timing routines. |
| 87211 | 87008 | */ |
| 87212 | | -/************** Include hwtime.h in the middle of vdbe.c *********************/ |
| 87213 | | -/************** Begin file hwtime.h ******************************************/ |
| 87214 | | -/* |
| 87215 | | -** 2008 May 27 |
| 87216 | | -** |
| 87217 | | -** The author disclaims copyright to this source code. In place of |
| 87218 | | -** a legal notice, here is a blessing: |
| 87219 | | -** |
| 87220 | | -** May you do good and not evil. |
| 87221 | | -** May you find forgiveness for yourself and forgive others. |
| 87222 | | -** May you share freely, never taking more than you give. |
| 87223 | | -** |
| 87224 | | -****************************************************************************** |
| 87225 | | -** |
| 87226 | | -** This file contains inline asm code for retrieving "high-performance" |
| 87227 | | -** counters for x86 and x86_64 class CPUs. |
| 87228 | | -*/ |
| 87229 | | -#ifndef SQLITE_HWTIME_H |
| 87230 | | -#define SQLITE_HWTIME_H |
| 87231 | | - |
| 87232 | | -/* |
| 87233 | | -** The following routine only works on pentium-class (or newer) processors. |
| 87234 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 87235 | | -** processor and returns that value. This can be used for high-res |
| 87236 | | -** profiling. |
| 87237 | | -*/ |
| 87238 | | -#if !defined(__STRICT_ANSI__) && \ |
| 87239 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 87240 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 87241 | | - |
| 87242 | | - #if defined(__GNUC__) |
| 87243 | | - |
| 87244 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 87245 | | - unsigned int lo, hi; |
| 87246 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 87247 | | - return (sqlite_uint64)hi << 32 | lo; |
| 87248 | | - } |
| 87249 | | - |
| 87250 | | - #elif defined(_MSC_VER) |
| 87251 | | - |
| 87252 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 87253 | | - __asm { |
| 87254 | | - rdtsc |
| 87255 | | - ret ; return value at EDX:EAX |
| 87256 | | - } |
| 87257 | | - } |
| 87258 | | - |
| 87259 | | - #endif |
| 87260 | | - |
| 87261 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 87262 | | - |
| 87263 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 87264 | | - unsigned long val; |
| 87265 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 87266 | | - return val; |
| 87267 | | - } |
| 87268 | | - |
| 87269 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 87270 | | - |
| 87271 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 87272 | | - unsigned long long retval; |
| 87273 | | - unsigned long junk; |
| 87274 | | - __asm__ __volatile__ ("\n\ |
| 87275 | | - 1: mftbu %1\n\ |
| 87276 | | - mftb %L0\n\ |
| 87277 | | - mftbu %0\n\ |
| 87278 | | - cmpw %0,%1\n\ |
| 87279 | | - bne 1b" |
| 87280 | | - : "=r" (retval), "=r" (junk)); |
| 87281 | | - return retval; |
| 87282 | | - } |
| 87283 | | - |
| 87284 | | -#else |
| 87285 | | - |
| 87286 | | - /* |
| 87287 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 87288 | | - ** disable the sqlite3Hwtime() routine. |
| 87289 | | - ** |
| 87290 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 87291 | | - ** and analysis configurations, not in any deliverable, so this |
| 87292 | | - ** should not be a great loss. |
| 87293 | | - */ |
| 87294 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 87295 | | - |
| 87296 | | -#endif |
| 87297 | | - |
| 87298 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 87299 | | - |
| 87300 | | -/************** End of hwtime.h **********************************************/ |
| 87301 | | -/************** Continuing where we left off in vdbe.c ***********************/ |
| 87009 | +/* #include "hwtime.h" */ |
| 87302 | 87010 | |
| 87303 | 87011 | #endif |
| 87304 | 87012 | |
| 87305 | 87013 | #ifndef NDEBUG |
| 87306 | 87014 | /* |
| | @@ -95148,11 +94856,11 @@ |
| 95148 | 94856 | if( pTab && !HasRowid(pTab) ){ |
| 95149 | 94857 | pTab = 0; |
| 95150 | 94858 | sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable); |
| 95151 | 94859 | } |
| 95152 | 94860 | #ifndef SQLITE_OMIT_VIEW |
| 95153 | | - if( pTab && pTab->pSelect ){ |
| 94861 | + if( pTab && IsView(pTab) ){ |
| 95154 | 94862 | pTab = 0; |
| 95155 | 94863 | sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable); |
| 95156 | 94864 | } |
| 95157 | 94865 | #endif |
| 95158 | 94866 | if( !pTab ){ |
| | @@ -95168,11 +94876,11 @@ |
| 95168 | 94876 | pBlob->pTab = pTab; |
| 95169 | 94877 | pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName; |
| 95170 | 94878 | |
| 95171 | 94879 | /* Now search pTab for the exact column. */ |
| 95172 | 94880 | for(iCol=0; iCol<pTab->nCol; iCol++) { |
| 95173 | | - if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){ |
| 94881 | + if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){ |
| 95174 | 94882 | break; |
| 95175 | 94883 | } |
| 95176 | 94884 | } |
| 95177 | 94885 | if( iCol==pTab->nCol ){ |
| 95178 | 94886 | sqlite3DbFree(db, zErr); |
| | @@ -95193,11 +94901,12 @@ |
| 95193 | 94901 | /* Check that the column is not part of an FK child key definition. It |
| 95194 | 94902 | ** is not necessary to check if it is part of a parent key, as parent |
| 95195 | 94903 | ** key columns must be indexed. The check below will pick up this |
| 95196 | 94904 | ** case. */ |
| 95197 | 94905 | FKey *pFKey; |
| 95198 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 94906 | + assert( !IsVirtual(pTab) ); |
| 94907 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 95199 | 94908 | int j; |
| 95200 | 94909 | for(j=0; j<pFKey->nCol; j++){ |
| 95201 | 94910 | if( pFKey->aCol[j].iFrom==iCol ){ |
| 95202 | 94911 | zFault = "foreign key"; |
| 95203 | 94912 | } |
| | @@ -99719,11 +99428,13 @@ |
| 99719 | 99428 | sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 99720 | 99429 | } |
| 99721 | 99430 | } |
| 99722 | 99431 | hCol = sqlite3StrIHash(zCol); |
| 99723 | 99432 | for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ |
| 99724 | | - if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 99433 | + if( pCol->hName==hCol |
| 99434 | + && sqlite3StrICmp(pCol->zCnName, zCol)==0 |
| 99435 | + ){ |
| 99725 | 99436 | /* If there has been exactly one prior match and this match |
| 99726 | 99437 | ** is for the right-hand table of a NATURAL JOIN or is in a |
| 99727 | 99438 | ** USING clause, then skip this match. |
| 99728 | 99439 | */ |
| 99729 | 99440 | if( cnt==1 ){ |
| | @@ -99796,11 +99507,13 @@ |
| 99796 | 99507 | int iCol; |
| 99797 | 99508 | u8 hCol = sqlite3StrIHash(zCol); |
| 99798 | 99509 | pSchema = pTab->pSchema; |
| 99799 | 99510 | cntTab++; |
| 99800 | 99511 | for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){ |
| 99801 | | - if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 99512 | + if( pCol->hName==hCol |
| 99513 | + && sqlite3StrICmp(pCol->zCnName, zCol)==0 |
| 99514 | + ){ |
| 99802 | 99515 | if( iCol==pTab->iPKey ){ |
| 99803 | 99516 | iCol = -1; |
| 99804 | 99517 | } |
| 99805 | 99518 | break; |
| 99806 | 99519 | } |
| | @@ -100204,10 +99917,11 @@ |
| 100204 | 99917 | for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ |
| 100205 | 99918 | anRef[i] = p->nRef; |
| 100206 | 99919 | } |
| 100207 | 99920 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 100208 | 99921 | if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ |
| 99922 | + testcase( ExprHasProperty(pExpr, EP_FromJoin) ); |
| 100209 | 99923 | if( pExpr->op==TK_NOTNULL ){ |
| 100210 | 99924 | pExpr->u.zToken = "true"; |
| 100211 | 99925 | ExprSetProperty(pExpr, EP_IsTrue); |
| 100212 | 99926 | }else{ |
| 100213 | 99927 | pExpr->u.zToken = "false"; |
| | @@ -101582,11 +101296,11 @@ |
| 101582 | 101296 | ){ |
| 101583 | 101297 | /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally |
| 101584 | 101298 | ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 101585 | 101299 | int j = p->iColumn; |
| 101586 | 101300 | if( j>=0 ){ |
| 101587 | | - const char *zColl = p->y.pTab->aCol[j].zColl; |
| 101301 | + const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); |
| 101588 | 101302 | pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 101589 | 101303 | } |
| 101590 | 101304 | break; |
| 101591 | 101305 | } |
| 101592 | 101306 | if( op==TK_CAST || op==TK_UPLUS ){ |
| | @@ -103922,11 +103636,11 @@ |
| 103922 | 103636 | assert( pSrc!=0 ); |
| 103923 | 103637 | if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */ |
| 103924 | 103638 | if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */ |
| 103925 | 103639 | pTab = pSrc->a[0].pTab; |
| 103926 | 103640 | assert( pTab!=0 ); |
| 103927 | | - assert( pTab->pSelect==0 ); /* FROM clause is not a view */ |
| 103641 | + assert( !IsView(pTab) ); /* FROM clause is not a view */ |
| 103928 | 103642 | if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */ |
| 103929 | 103643 | pEList = p->pEList; |
| 103930 | 103644 | assert( pEList!=0 ); |
| 103931 | 103645 | /* All SELECT results must be columns. */ |
| 103932 | 103646 | for(i=0; i<pEList->nExpr; i++){ |
| | @@ -105052,13 +104766,14 @@ |
| 105052 | 104766 | /* |
| 105053 | 104767 | ** Generate code that will compute the value of generated column pCol |
| 105054 | 104768 | ** and store the result in register regOut |
| 105055 | 104769 | */ |
| 105056 | 104770 | SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn( |
| 105057 | | - Parse *pParse, |
| 105058 | | - Column *pCol, |
| 105059 | | - int regOut |
| 104771 | + Parse *pParse, /* Parsing context */ |
| 104772 | + Table *pTab, /* Table containing the generated column */ |
| 104773 | + Column *pCol, /* The generated column */ |
| 104774 | + int regOut /* Put the result in this register */ |
| 105060 | 104775 | ){ |
| 105061 | 104776 | int iAddr; |
| 105062 | 104777 | Vdbe *v = pParse->pVdbe; |
| 105063 | 104778 | assert( v!=0 ); |
| 105064 | 104779 | assert( pParse->iSelfTab!=0 ); |
| | @@ -105065,11 +104780,11 @@ |
| 105065 | 104780 | if( pParse->iSelfTab>0 ){ |
| 105066 | 104781 | iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut); |
| 105067 | 104782 | }else{ |
| 105068 | 104783 | iAddr = 0; |
| 105069 | 104784 | } |
| 105070 | | - sqlite3ExprCodeCopy(pParse, pCol->pDflt, regOut); |
| 104785 | + sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut); |
| 105071 | 104786 | if( pCol->affinity>=SQLITE_AFF_TEXT ){ |
| 105072 | 104787 | sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1); |
| 105073 | 104788 | } |
| 105074 | 104789 | if( iAddr ) sqlite3VdbeJumpHere(v, iAddr); |
| 105075 | 104790 | } |
| | @@ -105101,16 +104816,17 @@ |
| 105101 | 104816 | x = iCol; |
| 105102 | 104817 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 105103 | 104818 | }else if( (pCol = &pTab->aCol[iCol])->colFlags & COLFLAG_VIRTUAL ){ |
| 105104 | 104819 | Parse *pParse = sqlite3VdbeParser(v); |
| 105105 | 104820 | if( pCol->colFlags & COLFLAG_BUSY ){ |
| 105106 | | - sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pCol->zName); |
| 104821 | + sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", |
| 104822 | + pCol->zCnName); |
| 105107 | 104823 | }else{ |
| 105108 | 104824 | int savedSelfTab = pParse->iSelfTab; |
| 105109 | 104825 | pCol->colFlags |= COLFLAG_BUSY; |
| 105110 | 104826 | pParse->iSelfTab = iTabCur+1; |
| 105111 | | - sqlite3ExprCodeGeneratedColumn(pParse, pCol, regOut); |
| 104827 | + sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, regOut); |
| 105112 | 104828 | pParse->iSelfTab = savedSelfTab; |
| 105113 | 104829 | pCol->colFlags &= ~COLFLAG_BUSY; |
| 105114 | 104830 | } |
| 105115 | 104831 | return; |
| 105116 | 104832 | #endif |
| | @@ -105374,11 +105090,12 @@ |
| 105374 | 105090 | sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab, |
| 105375 | 105091 | pCol->iSorterColumn, target); |
| 105376 | 105092 | if( pCol->iColumn<0 ){ |
| 105377 | 105093 | VdbeComment((v,"%s.rowid",pTab->zName)); |
| 105378 | 105094 | }else{ |
| 105379 | | - VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName)); |
| 105095 | + VdbeComment((v,"%s.%s", |
| 105096 | + pTab->zName, pTab->aCol[pCol->iColumn].zCnName)); |
| 105380 | 105097 | if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){ |
| 105381 | 105098 | sqlite3VdbeAddOp1(v, OP_RealAffinity, target); |
| 105382 | 105099 | } |
| 105383 | 105100 | } |
| 105384 | 105101 | return target; |
| | @@ -105435,16 +105152,16 @@ |
| 105435 | 105152 | iSrc = sqlite3TableColumnToStorage(pTab, iCol) - pParse->iSelfTab; |
| 105436 | 105153 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 105437 | 105154 | if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 105438 | 105155 | if( pCol->colFlags & COLFLAG_BUSY ){ |
| 105439 | 105156 | sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", |
| 105440 | | - pCol->zName); |
| 105157 | + pCol->zCnName); |
| 105441 | 105158 | return 0; |
| 105442 | 105159 | } |
| 105443 | 105160 | pCol->colFlags |= COLFLAG_BUSY; |
| 105444 | 105161 | if( pCol->colFlags & COLFLAG_NOTAVAIL ){ |
| 105445 | | - sqlite3ExprCodeGeneratedColumn(pParse, pCol, iSrc); |
| 105162 | + sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, iSrc); |
| 105446 | 105163 | } |
| 105447 | 105164 | pCol->colFlags &= ~(COLFLAG_BUSY|COLFLAG_NOTAVAIL); |
| 105448 | 105165 | return iSrc; |
| 105449 | 105166 | }else |
| 105450 | 105167 | #endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| | @@ -105918,11 +105635,11 @@ |
| 105918 | 105635 | assert( p1>=0 && p1<(pTab->nCol*2+2) ); |
| 105919 | 105636 | |
| 105920 | 105637 | sqlite3VdbeAddOp2(v, OP_Param, p1, target); |
| 105921 | 105638 | VdbeComment((v, "r[%d]=%s.%s", target, |
| 105922 | 105639 | (pExpr->iTable ? "new" : "old"), |
| 105923 | | - (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zName) |
| 105640 | + (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName) |
| 105924 | 105641 | )); |
| 105925 | 105642 | |
| 105926 | 105643 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 105927 | 105644 | /* If the column has REAL affinity, it may currently be stored as an |
| 105928 | 105645 | ** integer. Use OP_RealAffinity to make sure it is really real. |
| | @@ -107090,13 +106807,13 @@ |
| 107090 | 106807 | testcase( pExpr->op==TK_LE ); |
| 107091 | 106808 | testcase( pExpr->op==TK_GT ); |
| 107092 | 106809 | testcase( pExpr->op==TK_GE ); |
| 107093 | 106810 | /* The y.pTab=0 assignment in wherecode.c always happens after the |
| 107094 | 106811 | ** impliesNotNullRow() test */ |
| 107095 | | - if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0) |
| 106812 | + if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0 |
| 107096 | 106813 | && IsVirtual(pLeft->y.pTab)) |
| 107097 | | - || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0) |
| 106814 | + || (pRight->op==TK_COLUMN && pRight->y.pTab!=0 |
| 107098 | 106815 | && IsVirtual(pRight->y.pTab)) |
| 107099 | 106816 | ){ |
| 107100 | 106817 | return WRC_Prune; |
| 107101 | 106818 | } |
| 107102 | 106819 | /* no break */ deliberate_fall_through |
| | @@ -107771,22 +107488,19 @@ |
| 107771 | 107488 | sqlite3 *db = pParse->db; /* Database connection */ |
| 107772 | 107489 | int nTabName; /* Number of UTF-8 characters in zTabName */ |
| 107773 | 107490 | const char *zTabName; /* Original name of the table */ |
| 107774 | 107491 | Vdbe *v; |
| 107775 | 107492 | VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */ |
| 107776 | | - u32 savedDbFlags; /* Saved value of db->mDbFlags */ |
| 107777 | 107493 | |
| 107778 | | - savedDbFlags = db->mDbFlags; |
| 107779 | 107494 | if( NEVER(db->mallocFailed) ) goto exit_rename_table; |
| 107780 | 107495 | assert( pSrc->nSrc==1 ); |
| 107781 | 107496 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| 107782 | 107497 | |
| 107783 | 107498 | pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); |
| 107784 | 107499 | if( !pTab ) goto exit_rename_table; |
| 107785 | 107500 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 107786 | 107501 | zDb = db->aDb[iDb].zDbSName; |
| 107787 | | - db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 107788 | 107502 | |
| 107789 | 107503 | /* Get a NULL terminated version of the new table name. */ |
| 107790 | 107504 | zName = sqlite3NameFromToken(db, pName); |
| 107791 | 107505 | if( !zName ) goto exit_rename_table; |
| 107792 | 107506 | |
| | @@ -107811,11 +107525,11 @@ |
| 107811 | 107525 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){ |
| 107812 | 107526 | goto exit_rename_table; |
| 107813 | 107527 | } |
| 107814 | 107528 | |
| 107815 | 107529 | #ifndef SQLITE_OMIT_VIEW |
| 107816 | | - if( pTab->pSelect ){ |
| 107530 | + if( IsView(pTab) ){ |
| 107817 | 107531 | sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName); |
| 107818 | 107532 | goto exit_rename_table; |
| 107819 | 107533 | } |
| 107820 | 107534 | #endif |
| 107821 | 107535 | |
| | @@ -107923,11 +107637,10 @@ |
| 107923 | 107637 | renameTestSchema(pParse, zDb, iDb==1, "after rename", 0); |
| 107924 | 107638 | |
| 107925 | 107639 | exit_rename_table: |
| 107926 | 107640 | sqlite3SrcListDelete(db, pSrc); |
| 107927 | 107641 | sqlite3DbFree(db, zName); |
| 107928 | | - db->mDbFlags = savedDbFlags; |
| 107929 | 107642 | } |
| 107930 | 107643 | |
| 107931 | 107644 | /* |
| 107932 | 107645 | ** Write code that will raise an error if the table described by |
| 107933 | 107646 | ** zDb and zTab is not empty. |
| | @@ -107973,11 +107686,11 @@ |
| 107973 | 107686 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 107974 | 107687 | iDb = sqlite3SchemaToIndex(db, pNew->pSchema); |
| 107975 | 107688 | zDb = db->aDb[iDb].zDbSName; |
| 107976 | 107689 | zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */ |
| 107977 | 107690 | pCol = &pNew->aCol[pNew->nCol-1]; |
| 107978 | | - pDflt = pCol->pDflt; |
| 107691 | + pDflt = sqlite3ColumnExpr(pNew, pCol); |
| 107979 | 107692 | pTab = sqlite3FindTable(db, zTab, zDb); |
| 107980 | 107693 | assert( pTab ); |
| 107981 | 107694 | |
| 107982 | 107695 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 107983 | 107696 | /* Invoke the authorization callback. */ |
| | @@ -108007,11 +107720,11 @@ |
| 108007 | 107720 | */ |
| 108008 | 107721 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 108009 | 107722 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 108010 | 107723 | pDflt = 0; |
| 108011 | 107724 | } |
| 108012 | | - if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){ |
| 107725 | + if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){ |
| 108013 | 107726 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 108014 | 107727 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 108015 | 107728 | } |
| 108016 | 107729 | if( pCol->notNull && !pDflt ){ |
| 108017 | 107730 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| | @@ -108044,27 +107757,25 @@ |
| 108044 | 107757 | |
| 108045 | 107758 | /* Modify the CREATE TABLE statement. */ |
| 108046 | 107759 | zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); |
| 108047 | 107760 | if( zCol ){ |
| 108048 | 107761 | char *zEnd = &zCol[pColDef->n-1]; |
| 108049 | | - u32 savedDbFlags = db->mDbFlags; |
| 108050 | 107762 | while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ |
| 108051 | 107763 | *zEnd-- = '\0'; |
| 108052 | 107764 | } |
| 108053 | | - db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 108054 | 107765 | /* substr() operations on characters, but addColOffset is in bytes. So we |
| 108055 | 107766 | ** have to use printf() to translate between these units: */ |
| 107767 | + assert( !IsVirtual(pTab) ); |
| 108056 | 107768 | sqlite3NestedParse(pParse, |
| 108057 | 107769 | "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 108058 | 107770 | "sql = printf('%%.%ds, ',sql) || %Q" |
| 108059 | 107771 | " || substr(sql,1+length(printf('%%.%ds',sql))) " |
| 108060 | 107772 | "WHERE type = 'table' AND name = %Q", |
| 108061 | | - zDb, pNew->addColOffset, zCol, pNew->addColOffset, |
| 107773 | + zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset, |
| 108062 | 107774 | zTab |
| 108063 | 107775 | ); |
| 108064 | 107776 | sqlite3DbFree(db, zCol); |
| 108065 | | - db->mDbFlags = savedDbFlags; |
| 108066 | 107777 | } |
| 108067 | 107778 | |
| 108068 | 107779 | v = sqlite3GetVdbe(pParse); |
| 108069 | 107780 | if( v ){ |
| 108070 | 107781 | /* Make sure the schema version is at least 3. But do not upgrade |
| | @@ -108136,20 +107847,20 @@ |
| 108136 | 107847 | goto exit_begin_add_column; |
| 108137 | 107848 | } |
| 108138 | 107849 | #endif |
| 108139 | 107850 | |
| 108140 | 107851 | /* Make sure this is not an attempt to ALTER a view. */ |
| 108141 | | - if( pTab->pSelect ){ |
| 107852 | + if( IsView(pTab) ){ |
| 108142 | 107853 | sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); |
| 108143 | 107854 | goto exit_begin_add_column; |
| 108144 | 107855 | } |
| 108145 | 107856 | if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ |
| 108146 | 107857 | goto exit_begin_add_column; |
| 108147 | 107858 | } |
| 108148 | 107859 | |
| 108149 | 107860 | sqlite3MayAbort(pParse); |
| 108150 | | - assert( pTab->addColOffset>0 ); |
| 107861 | + assert( pTab->u.tab.addColOffset>0 ); |
| 108151 | 107862 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 108152 | 107863 | |
| 108153 | 107864 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| 108154 | 107865 | ** sqlite3AddColumn() function and friends to modify. But modify |
| 108155 | 107866 | ** the name by adding an "sqlite_altertab_" prefix. By adding this |
| | @@ -108172,17 +107883,17 @@ |
| 108172 | 107883 | goto exit_begin_add_column; |
| 108173 | 107884 | } |
| 108174 | 107885 | memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol); |
| 108175 | 107886 | for(i=0; i<pNew->nCol; i++){ |
| 108176 | 107887 | Column *pCol = &pNew->aCol[i]; |
| 108177 | | - pCol->zName = sqlite3DbStrDup(db, pCol->zName); |
| 108178 | | - pCol->hName = sqlite3StrIHash(pCol->zName); |
| 108179 | | - pCol->zColl = 0; |
| 108180 | | - pCol->pDflt = 0; |
| 107888 | + pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName); |
| 107889 | + pCol->hName = sqlite3StrIHash(pCol->zCnName); |
| 108181 | 107890 | } |
| 107891 | + assert( !IsVirtual(pNew) ); |
| 107892 | + pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0); |
| 108182 | 107893 | pNew->pSchema = db->aDb[iDb].pSchema; |
| 108183 | | - pNew->addColOffset = pTab->addColOffset; |
| 107894 | + pNew->u.tab.addColOffset = pTab->u.tab.addColOffset; |
| 108184 | 107895 | pNew->nTabRef = 1; |
| 108185 | 107896 | |
| 108186 | 107897 | exit_begin_add_column: |
| 108187 | 107898 | sqlite3SrcListDelete(db, pSrc); |
| 108188 | 107899 | return; |
| | @@ -108198,11 +107909,11 @@ |
| 108198 | 107909 | */ |
| 108199 | 107910 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 108200 | 107911 | static int isRealTable(Parse *pParse, Table *pTab, int bDrop){ |
| 108201 | 107912 | const char *zType = 0; |
| 108202 | 107913 | #ifndef SQLITE_OMIT_VIEW |
| 108203 | | - if( pTab->pSelect ){ |
| 107914 | + if( IsView(pTab) ){ |
| 108204 | 107915 | zType = "view"; |
| 108205 | 107916 | } |
| 108206 | 107917 | #endif |
| 108207 | 107918 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 108208 | 107919 | if( IsVirtual(pTab) ){ |
| | @@ -108265,11 +107976,11 @@ |
| 108265 | 107976 | /* Make sure the old name really is a column name in the table to be |
| 108266 | 107977 | ** altered. Set iCol to be the index of the column being renamed */ |
| 108267 | 107978 | zOld = sqlite3NameFromToken(db, pOld); |
| 108268 | 107979 | if( !zOld ) goto exit_rename_column; |
| 108269 | 107980 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 108270 | | - if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break; |
| 107981 | + if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break; |
| 108271 | 107982 | } |
| 108272 | 107983 | if( iCol==pTab->nCol ){ |
| 108273 | 107984 | sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); |
| 108274 | 107985 | goto exit_rename_column; |
| 108275 | 107986 | } |
| | @@ -109111,11 +108822,11 @@ |
| 109111 | 108822 | pTab = sqlite3FindTable(db, zTable, zDb); |
| 109112 | 108823 | if( pTab==0 || iCol>=pTab->nCol ){ |
| 109113 | 108824 | sqlite3BtreeLeaveAll(db); |
| 109114 | 108825 | return; |
| 109115 | 108826 | } |
| 109116 | | - zOld = pTab->aCol[iCol].zName; |
| 108827 | + zOld = pTab->aCol[iCol].zCnName; |
| 109117 | 108828 | memset(&sCtx, 0, sizeof(sCtx)); |
| 109118 | 108829 | sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol); |
| 109119 | 108830 | |
| 109120 | 108831 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 109121 | 108832 | db->xAuth = 0; |
| | @@ -109130,30 +108841,29 @@ |
| 109130 | 108841 | sWalker.u.pRename = &sCtx; |
| 109131 | 108842 | |
| 109132 | 108843 | sCtx.pTab = pTab; |
| 109133 | 108844 | if( rc!=SQLITE_OK ) goto renameColumnFunc_done; |
| 109134 | 108845 | if( sParse.pNewTable ){ |
| 109135 | | - Select *pSelect = sParse.pNewTable->pSelect; |
| 109136 | | - if( pSelect ){ |
| 108846 | + if( IsView(sParse.pNewTable) ){ |
| 108847 | + Select *pSelect = sParse.pNewTable->u.view.pSelect; |
| 109137 | 108848 | pSelect->selFlags &= ~SF_View; |
| 109138 | 108849 | sParse.rc = SQLITE_OK; |
| 109139 | 108850 | sqlite3SelectPrep(&sParse, pSelect, 0); |
| 109140 | 108851 | rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc); |
| 109141 | 108852 | if( rc==SQLITE_OK ){ |
| 109142 | 108853 | sqlite3WalkSelect(&sWalker, pSelect); |
| 109143 | 108854 | } |
| 109144 | 108855 | if( rc!=SQLITE_OK ) goto renameColumnFunc_done; |
| 109145 | | - }else{ |
| 108856 | + }else if( ALWAYS(IsOrdinaryTable(sParse.pNewTable)) ){ |
| 109146 | 108857 | /* A regular table */ |
| 109147 | 108858 | int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName); |
| 109148 | 108859 | FKey *pFKey; |
| 109149 | | - assert( sParse.pNewTable->pSelect==0 ); |
| 109150 | 108860 | sCtx.pTab = sParse.pNewTable; |
| 109151 | 108861 | if( bFKOnly==0 ){ |
| 109152 | 108862 | if( iCol<sParse.pNewTable->nCol ){ |
| 109153 | 108863 | renameTokenFind( |
| 109154 | | - &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName |
| 108864 | + &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zCnName |
| 109155 | 108865 | ); |
| 109156 | 108866 | } |
| 109157 | 108867 | if( sCtx.iCol<0 ){ |
| 109158 | 108868 | renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey); |
| 109159 | 108869 | } |
| | @@ -109164,16 +108874,19 @@ |
| 109164 | 108874 | for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){ |
| 109165 | 108875 | sqlite3WalkExprList(&sWalker, pIdx->aColExpr); |
| 109166 | 108876 | } |
| 109167 | 108877 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 109168 | 108878 | for(i=0; i<sParse.pNewTable->nCol; i++){ |
| 109169 | | - sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); |
| 108879 | + Expr *pExpr = sqlite3ColumnExpr(sParse.pNewTable, |
| 108880 | + &sParse.pNewTable->aCol[i]); |
| 108881 | + sqlite3WalkExpr(&sWalker, pExpr); |
| 109170 | 108882 | } |
| 109171 | 108883 | #endif |
| 109172 | 108884 | } |
| 109173 | 108885 | |
| 109174 | | - for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 108886 | + assert( !IsVirtual(sParse.pNewTable) ); |
| 108887 | + for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109175 | 108888 | for(i=0; i<pFKey->nCol; i++){ |
| 109176 | 108889 | if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ |
| 109177 | 108890 | renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]); |
| 109178 | 108891 | } |
| 109179 | 108892 | if( 0==sqlite3_stricmp(pFKey->zTo, zTable) |
| | @@ -109335,32 +109048,35 @@ |
| 109335 | 109048 | if( rc==SQLITE_OK ){ |
| 109336 | 109049 | int isLegacy = (db->flags & SQLITE_LegacyAlter); |
| 109337 | 109050 | if( sParse.pNewTable ){ |
| 109338 | 109051 | Table *pTab = sParse.pNewTable; |
| 109339 | 109052 | |
| 109340 | | - if( pTab->pSelect ){ |
| 109053 | + if( IsView(pTab) ){ |
| 109341 | 109054 | if( isLegacy==0 ){ |
| 109342 | | - Select *pSelect = pTab->pSelect; |
| 109055 | + Select *pSelect = pTab->u.view.pSelect; |
| 109343 | 109056 | NameContext sNC; |
| 109344 | 109057 | memset(&sNC, 0, sizeof(sNC)); |
| 109345 | 109058 | sNC.pParse = &sParse; |
| 109346 | 109059 | |
| 109347 | 109060 | assert( pSelect->selFlags & SF_View ); |
| 109348 | 109061 | pSelect->selFlags &= ~SF_View; |
| 109349 | | - sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC); |
| 109062 | + sqlite3SelectPrep(&sParse, pTab->u.view.pSelect, &sNC); |
| 109350 | 109063 | if( sParse.nErr ){ |
| 109351 | 109064 | rc = sParse.rc; |
| 109352 | 109065 | }else{ |
| 109353 | | - sqlite3WalkSelect(&sWalker, pTab->pSelect); |
| 109066 | + sqlite3WalkSelect(&sWalker, pTab->u.view.pSelect); |
| 109354 | 109067 | } |
| 109355 | 109068 | } |
| 109356 | 109069 | }else{ |
| 109357 | 109070 | /* Modify any FK definitions to point to the new table. */ |
| 109358 | 109071 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 109359 | | - if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){ |
| 109072 | + if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys)) |
| 109073 | + && !IsVirtual(pTab) |
| 109074 | + ){ |
| 109360 | 109075 | FKey *pFKey; |
| 109361 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109076 | + assert( !IsVirtual(pTab) ); |
| 109077 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109362 | 109078 | if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 109363 | 109079 | renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 109364 | 109080 | } |
| 109365 | 109081 | } |
| 109366 | 109082 | } |
| | @@ -109496,12 +109212,12 @@ |
| 109496 | 109212 | sWalker.xExprCallback = renameQuotefixExprCb; |
| 109497 | 109213 | sWalker.xSelectCallback = renameColumnSelectCb; |
| 109498 | 109214 | sWalker.u.pRename = &sCtx; |
| 109499 | 109215 | |
| 109500 | 109216 | if( sParse.pNewTable ){ |
| 109501 | | - Select *pSelect = sParse.pNewTable->pSelect; |
| 109502 | | - if( pSelect ){ |
| 109217 | + if( IsView(sParse.pNewTable) ){ |
| 109218 | + Select *pSelect = sParse.pNewTable->u.view.pSelect; |
| 109503 | 109219 | pSelect->selFlags &= ~SF_View; |
| 109504 | 109220 | sParse.rc = SQLITE_OK; |
| 109505 | 109221 | sqlite3SelectPrep(&sParse, pSelect, 0); |
| 109506 | 109222 | rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc); |
| 109507 | 109223 | if( rc==SQLITE_OK ){ |
| | @@ -109510,11 +109226,13 @@ |
| 109510 | 109226 | }else{ |
| 109511 | 109227 | int i; |
| 109512 | 109228 | sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck); |
| 109513 | 109229 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 109514 | 109230 | for(i=0; i<sParse.pNewTable->nCol; i++){ |
| 109515 | | - sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); |
| 109231 | + sqlite3WalkExpr(&sWalker, |
| 109232 | + sqlite3ColumnExpr(sParse.pNewTable, |
| 109233 | + &sParse.pNewTable->aCol[i])); |
| 109516 | 109234 | } |
| 109517 | 109235 | #endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 109518 | 109236 | } |
| 109519 | 109237 | }else if( sParse.pNewIndex ){ |
| 109520 | 109238 | sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr); |
| | @@ -109593,15 +109311,15 @@ |
| 109593 | 109311 | int flags = db->flags; |
| 109594 | 109312 | if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL); |
| 109595 | 109313 | rc = renameParseSql(&sParse, zDb, db, zInput, bTemp); |
| 109596 | 109314 | db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL)); |
| 109597 | 109315 | if( rc==SQLITE_OK ){ |
| 109598 | | - if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){ |
| 109316 | + if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){ |
| 109599 | 109317 | NameContext sNC; |
| 109600 | 109318 | memset(&sNC, 0, sizeof(sNC)); |
| 109601 | 109319 | sNC.pParse = &sParse; |
| 109602 | | - sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC); |
| 109320 | + sqlite3SelectPrep(&sParse, sParse.pNewTable->u.view.pSelect, &sNC); |
| 109603 | 109321 | if( sParse.nErr ) rc = sParse.rc; |
| 109604 | 109322 | } |
| 109605 | 109323 | |
| 109606 | 109324 | else if( sParse.pNewTrigger ){ |
| 109607 | 109325 | if( isLegacy==0 ){ |
| | @@ -109668,17 +109386,18 @@ |
| 109668 | 109386 | /* This can happen if the sqlite_schema table is corrupt */ |
| 109669 | 109387 | rc = SQLITE_CORRUPT_BKPT; |
| 109670 | 109388 | goto drop_column_done; |
| 109671 | 109389 | } |
| 109672 | 109390 | |
| 109673 | | - pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zName); |
| 109391 | + pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName); |
| 109674 | 109392 | if( iCol<pTab->nCol-1 ){ |
| 109675 | 109393 | RenameToken *pEnd; |
| 109676 | | - pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zName); |
| 109394 | + pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName); |
| 109677 | 109395 | zEnd = (const char*)pEnd->t.z; |
| 109678 | 109396 | }else{ |
| 109679 | | - zEnd = (const char*)&zSql[pTab->addColOffset]; |
| 109397 | + assert( !IsVirtual(pTab) ); |
| 109398 | + zEnd = (const char*)&zSql[pTab->u.tab.addColOffset]; |
| 109680 | 109399 | while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--; |
| 109681 | 109400 | } |
| 109682 | 109401 | |
| 109683 | 109402 | zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd); |
| 109684 | 109403 | sqlite3_result_text(context, zNew, -1, SQLITE_TRANSIENT); |
| | @@ -109809,10 +109528,16 @@ |
| 109809 | 109528 | }else{ |
| 109810 | 109529 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut); |
| 109811 | 109530 | } |
| 109812 | 109531 | nField++; |
| 109813 | 109532 | } |
| 109533 | + } |
| 109534 | + if( nField==0 ){ |
| 109535 | + /* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */ |
| 109536 | + pParse->nMem++; |
| 109537 | + sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1); |
| 109538 | + nField = 1; |
| 109814 | 109539 | } |
| 109815 | 109540 | sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec); |
| 109816 | 109541 | if( pPk ){ |
| 109817 | 109542 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol); |
| 109818 | 109543 | }else{ |
| | @@ -110814,11 +110539,11 @@ |
| 110814 | 110539 | if( NEVER(i==XN_ROWID) ){ |
| 110815 | 110540 | VdbeComment((v,"%s.rowid",pIdx->zName)); |
| 110816 | 110541 | }else if( i==XN_EXPR ){ |
| 110817 | 110542 | VdbeComment((v,"%s.expr(%d)",pIdx->zName, k)); |
| 110818 | 110543 | }else{ |
| 110819 | | - VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zName)); |
| 110544 | + VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName)); |
| 110820 | 110545 | } |
| 110821 | 110546 | } |
| 110822 | 110547 | #else |
| 110823 | 110548 | # define analyzeVdbeCommentIndexWithColumnName(a,b,c) |
| 110824 | 110549 | #endif /* SQLITE_DEBUG */ |
| | @@ -112567,14 +112292,14 @@ |
| 112567 | 112292 | iCol = pExpr->iColumn; |
| 112568 | 112293 | if( pTab==0 ) return; |
| 112569 | 112294 | |
| 112570 | 112295 | if( iCol>=0 ){ |
| 112571 | 112296 | assert( iCol<pTab->nCol ); |
| 112572 | | - zCol = pTab->aCol[iCol].zName; |
| 112297 | + zCol = pTab->aCol[iCol].zCnName; |
| 112573 | 112298 | }else if( pTab->iPKey>=0 ){ |
| 112574 | 112299 | assert( pTab->iPKey<pTab->nCol ); |
| 112575 | | - zCol = pTab->aCol[pTab->iPKey].zName; |
| 112300 | + zCol = pTab->aCol[pTab->iPKey].zCnName; |
| 112576 | 112301 | }else{ |
| 112577 | 112302 | zCol = "ROWID"; |
| 112578 | 112303 | } |
| 112579 | 112304 | assert( iDb>=0 && iDb<pParse->db->nDb ); |
| 112580 | 112305 | if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){ |
| | @@ -112948,24 +112673,26 @@ |
| 112948 | 112673 | } |
| 112949 | 112674 | |
| 112950 | 112675 | /* |
| 112951 | 112676 | ** Run the parser and code generator recursively in order to generate |
| 112952 | 112677 | ** code for the SQL statement given onto the end of the pParse context |
| 112953 | | -** currently under construction. When the parser is run recursively |
| 112954 | | -** this way, the final OP_Halt is not appended and other initialization |
| 112955 | | -** and finalization steps are omitted because those are handling by the |
| 112956 | | -** outermost parser. |
| 112678 | +** currently under construction. Notes: |
| 112957 | 112679 | ** |
| 112958 | | -** Not everything is nestable. This facility is designed to permit |
| 112959 | | -** INSERT, UPDATE, and DELETE operations against the schema table. Use |
| 112960 | | -** care if you decide to try to use this routine for some other purposes. |
| 112680 | +** * The final OP_Halt is not appended and other initialization |
| 112681 | +** and finalization steps are omitted because those are handling by the |
| 112682 | +** outermost parser. |
| 112683 | +** |
| 112684 | +** * Built-in SQL functions always take precedence over application-defined |
| 112685 | +** SQL functions. In other words, it is not possible to override a |
| 112686 | +** built-in function. |
| 112961 | 112687 | */ |
| 112962 | 112688 | SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ |
| 112963 | 112689 | va_list ap; |
| 112964 | 112690 | char *zSql; |
| 112965 | 112691 | char *zErrMsg = 0; |
| 112966 | 112692 | sqlite3 *db = pParse->db; |
| 112693 | + u32 savedDbFlags = db->mDbFlags; |
| 112967 | 112694 | char saveBuf[PARSE_TAIL_SZ]; |
| 112968 | 112695 | |
| 112969 | 112696 | if( pParse->nErr ) return; |
| 112970 | 112697 | assert( pParse->nested<10 ); /* Nesting should only be of limited depth */ |
| 112971 | 112698 | va_start(ap, zFormat); |
| | @@ -112980,11 +112707,13 @@ |
| 112980 | 112707 | return; |
| 112981 | 112708 | } |
| 112982 | 112709 | pParse->nested++; |
| 112983 | 112710 | memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ); |
| 112984 | 112711 | memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); |
| 112712 | + db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 112985 | 112713 | sqlite3RunParser(pParse, zSql, &zErrMsg); |
| 112714 | + db->mDbFlags = savedDbFlags; |
| 112986 | 112715 | sqlite3DbFree(db, zErrMsg); |
| 112987 | 112716 | sqlite3DbFree(db, zSql); |
| 112988 | 112717 | memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ); |
| 112989 | 112718 | pParse->nested--; |
| 112990 | 112719 | } |
| | @@ -113329,10 +113058,88 @@ |
| 113329 | 113058 | ** This routine is called when a commit occurs. |
| 113330 | 113059 | */ |
| 113331 | 113060 | SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){ |
| 113332 | 113061 | db->mDbFlags &= ~DBFLAG_SchemaChange; |
| 113333 | 113062 | } |
| 113063 | + |
| 113064 | +/* |
| 113065 | +** Set the expression associated with a column. This is usually |
| 113066 | +** the DEFAULT value, but might also be the expression that computes |
| 113067 | +** the value for a generated column. |
| 113068 | +*/ |
| 113069 | +SQLITE_PRIVATE void sqlite3ColumnSetExpr( |
| 113070 | + Parse *pParse, /* Parsing context */ |
| 113071 | + Table *pTab, /* The table containing the column */ |
| 113072 | + Column *pCol, /* The column to receive the new DEFAULT expression */ |
| 113073 | + Expr *pExpr /* The new default expression */ |
| 113074 | +){ |
| 113075 | + ExprList *pList; |
| 113076 | + assert( !IsVirtual(pTab) ); |
| 113077 | + pList = pTab->u.tab.pDfltList; |
| 113078 | + if( pCol->iDflt==0 |
| 113079 | + || NEVER(pList==0) |
| 113080 | + || NEVER(pList->nExpr<pCol->iDflt) |
| 113081 | + ){ |
| 113082 | + pCol->iDflt = pList==0 ? 1 : pList->nExpr+1; |
| 113083 | + pTab->u.tab.pDfltList = sqlite3ExprListAppend(pParse, pList, pExpr); |
| 113084 | + }else{ |
| 113085 | + sqlite3ExprDelete(pParse->db, pList->a[pCol->iDflt-1].pExpr); |
| 113086 | + pList->a[pCol->iDflt-1].pExpr = pExpr; |
| 113087 | + } |
| 113088 | +} |
| 113089 | + |
| 113090 | +/* |
| 113091 | +** Return the expression associated with a column. The expression might be |
| 113092 | +** the DEFAULT clause or the AS clause of a generated column. |
| 113093 | +** Return NULL if the column has no associated expression. |
| 113094 | +*/ |
| 113095 | +SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){ |
| 113096 | + if( pCol->iDflt==0 ) return 0; |
| 113097 | + if( NEVER(IsVirtual(pTab)) ) return 0; |
| 113098 | + if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 113099 | + if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 113100 | + return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 113101 | +} |
| 113102 | + |
| 113103 | +/* |
| 113104 | +** Set the collating sequence name for a column. |
| 113105 | +*/ |
| 113106 | +SQLITE_PRIVATE void sqlite3ColumnSetColl( |
| 113107 | + sqlite3 *db, |
| 113108 | + Column *pCol, |
| 113109 | + const char *zColl |
| 113110 | +){ |
| 113111 | + int nColl; |
| 113112 | + int n; |
| 113113 | + char *zNew; |
| 113114 | + assert( zColl!=0 ); |
| 113115 | + n = sqlite3Strlen30(pCol->zCnName) + 1; |
| 113116 | + if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 113117 | + n += sqlite3Strlen30(pCol->zCnName+n) + 1; |
| 113118 | + } |
| 113119 | + nColl = sqlite3Strlen30(zColl) + 1; |
| 113120 | + zNew = sqlite3DbRealloc(db, pCol->zCnName, nColl+n); |
| 113121 | + if( zNew ){ |
| 113122 | + pCol->zCnName = zNew; |
| 113123 | + memcpy(pCol->zCnName + n, zColl, nColl); |
| 113124 | + pCol->colFlags |= COLFLAG_HASCOLL; |
| 113125 | + } |
| 113126 | +} |
| 113127 | + |
| 113128 | +/* |
| 113129 | +** Return the collating squence name for a column |
| 113130 | +*/ |
| 113131 | +SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| 113132 | + const char *z; |
| 113133 | + if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0; |
| 113134 | + z = pCol->zCnName; |
| 113135 | + while( *z ){ z++; } |
| 113136 | + if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 113137 | + do{ z++; }while( *z ); |
| 113138 | + } |
| 113139 | + return z+1; |
| 113140 | +} |
| 113334 | 113141 | |
| 113335 | 113142 | /* |
| 113336 | 113143 | ** Delete memory allocated for the column names of a table or view (the |
| 113337 | 113144 | ** Table.aCol[] array). |
| 113338 | 113145 | */ |
| | @@ -113340,16 +113147,24 @@ |
| 113340 | 113147 | int i; |
| 113341 | 113148 | Column *pCol; |
| 113342 | 113149 | assert( pTable!=0 ); |
| 113343 | 113150 | if( (pCol = pTable->aCol)!=0 ){ |
| 113344 | 113151 | for(i=0; i<pTable->nCol; i++, pCol++){ |
| 113345 | | - assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) ); |
| 113346 | | - sqlite3DbFree(db, pCol->zName); |
| 113347 | | - sqlite3ExprDelete(db, pCol->pDflt); |
| 113348 | | - sqlite3DbFree(db, pCol->zColl); |
| 113152 | + assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) ); |
| 113153 | + sqlite3DbFree(db, pCol->zCnName); |
| 113349 | 113154 | } |
| 113350 | 113155 | sqlite3DbFree(db, pTable->aCol); |
| 113156 | + if( !IsVirtual(pTable) ){ |
| 113157 | + sqlite3ExprListDelete(db, pTable->u.tab.pDfltList); |
| 113158 | + } |
| 113159 | + if( db==0 || db->pnBytesFreed==0 ){ |
| 113160 | + pTable->aCol = 0; |
| 113161 | + pTable->nCol = 0; |
| 113162 | + if( !IsVirtual(pTable) ){ |
| 113163 | + pTable->u.tab.pDfltList = 0; |
| 113164 | + } |
| 113165 | + } |
| 113351 | 113166 | } |
| 113352 | 113167 | } |
| 113353 | 113168 | |
| 113354 | 113169 | /* |
| 113355 | 113170 | ** Remove the memory data structures associated with the given |
| | @@ -113397,23 +113212,29 @@ |
| 113397 | 113212 | assert( pOld==pIndex || pOld==0 ); |
| 113398 | 113213 | } |
| 113399 | 113214 | sqlite3FreeIndex(db, pIndex); |
| 113400 | 113215 | } |
| 113401 | 113216 | |
| 113402 | | - /* Delete any foreign keys attached to this table. */ |
| 113403 | | - sqlite3FkDelete(db, pTable); |
| 113217 | + if( IsOrdinaryTable(pTable) ){ |
| 113218 | + sqlite3FkDelete(db, pTable); |
| 113219 | + } |
| 113220 | +#ifndef SQLITE_OMIT_VIRTUAL_TABLE |
| 113221 | + else if( IsVirtual(pTable) ){ |
| 113222 | + sqlite3VtabClear(db, pTable); |
| 113223 | + } |
| 113224 | +#endif |
| 113225 | + else{ |
| 113226 | + assert( IsView(pTable) ); |
| 113227 | + sqlite3SelectDelete(db, pTable->u.view.pSelect); |
| 113228 | + } |
| 113404 | 113229 | |
| 113405 | 113230 | /* Delete the Table structure itself. |
| 113406 | 113231 | */ |
| 113407 | 113232 | sqlite3DeleteColumnNames(db, pTable); |
| 113408 | 113233 | sqlite3DbFree(db, pTable->zName); |
| 113409 | 113234 | sqlite3DbFree(db, pTable->zColAff); |
| 113410 | | - sqlite3SelectDelete(db, pTable->pSelect); |
| 113411 | 113235 | sqlite3ExprListDelete(db, pTable->pCheck); |
| 113412 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 113413 | | - sqlite3VtabClear(db, pTable); |
| 113414 | | -#endif |
| 113415 | 113236 | sqlite3DbFree(db, pTable); |
| 113416 | 113237 | |
| 113417 | 113238 | /* Verify that no lookaside memory was used by schema tables */ |
| 113418 | 113239 | assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) ); |
| 113419 | 113240 | } |
| | @@ -113935,20 +113756,21 @@ |
| 113935 | 113756 | /* Normal (non-error) return. */ |
| 113936 | 113757 | return; |
| 113937 | 113758 | |
| 113938 | 113759 | /* If an error occurs, we jump here */ |
| 113939 | 113760 | begin_table_error: |
| 113761 | + pParse->checkSchema = 1; |
| 113940 | 113762 | sqlite3DbFree(db, zName); |
| 113941 | 113763 | return; |
| 113942 | 113764 | } |
| 113943 | 113765 | |
| 113944 | 113766 | /* Set properties of a table column based on the (magical) |
| 113945 | 113767 | ** name of the column. |
| 113946 | 113768 | */ |
| 113947 | 113769 | #if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 113948 | 113770 | SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){ |
| 113949 | | - if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){ |
| 113771 | + if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){ |
| 113950 | 113772 | pCol->colFlags |= COLFLAG_HIDDEN; |
| 113951 | 113773 | if( pTab ) pTab->tabFlags |= TF_HasHidden; |
| 113952 | 113774 | }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){ |
| 113953 | 113775 | pTab->tabFlags |= TF_OOOHidden; |
| 113954 | 113776 | } |
| | @@ -114035,67 +113857,108 @@ |
| 114035 | 113857 | ** The parser calls this routine once for each column declaration |
| 114036 | 113858 | ** in a CREATE TABLE statement. sqlite3StartTable() gets called |
| 114037 | 113859 | ** first to get things going. Then this routine is called for each |
| 114038 | 113860 | ** column. |
| 114039 | 113861 | */ |
| 114040 | | -SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ |
| 113862 | +SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){ |
| 114041 | 113863 | Table *p; |
| 114042 | 113864 | int i; |
| 114043 | 113865 | char *z; |
| 114044 | 113866 | char *zType; |
| 114045 | 113867 | Column *pCol; |
| 114046 | 113868 | sqlite3 *db = pParse->db; |
| 114047 | 113869 | u8 hName; |
| 113870 | + Column *aNew; |
| 113871 | + u8 eType = COLTYPE_CUSTOM; |
| 113872 | + u8 szEst = 1; |
| 113873 | + char affinity = SQLITE_AFF_BLOB; |
| 114048 | 113874 | |
| 114049 | 113875 | if( (p = pParse->pNewTable)==0 ) return; |
| 114050 | 113876 | if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 114051 | 113877 | sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName); |
| 114052 | 113878 | return; |
| 114053 | 113879 | } |
| 114054 | | - z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2); |
| 113880 | + if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName); |
| 113881 | + |
| 113882 | + /* Because keywords GENERATE ALWAYS can be converted into indentifiers |
| 113883 | + ** by the parser, we can sometimes end up with a typename that ends |
| 113884 | + ** with "generated always". Check for this case and omit the surplus |
| 113885 | + ** text. */ |
| 113886 | + if( sType.n>=16 |
| 113887 | + && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0 |
| 113888 | + ){ |
| 113889 | + sType.n -= 6; |
| 113890 | + while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--; |
| 113891 | + if( sType.n>=9 |
| 113892 | + && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0 |
| 113893 | + ){ |
| 113894 | + sType.n -= 9; |
| 113895 | + while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--; |
| 113896 | + } |
| 113897 | + } |
| 113898 | + |
| 113899 | + /* Check for standard typenames. For standard typenames we will |
| 113900 | + ** set the Column.eType field rather than storing the typename after |
| 113901 | + ** the column name, in order to save space. */ |
| 113902 | + if( sType.n>=3 ){ |
| 113903 | + sqlite3DequoteToken(&sType); |
| 113904 | + for(i=0; i<SQLITE_N_STDTYPE; i++){ |
| 113905 | + if( sType.n==sqlite3StdTypeLen[i] |
| 113906 | + && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0 |
| 113907 | + ){ |
| 113908 | + sType.n = 0; |
| 113909 | + eType = i+1; |
| 113910 | + affinity = sqlite3StdTypeAffinity[i]; |
| 113911 | + if( affinity<=SQLITE_AFF_TEXT ) szEst = 5; |
| 113912 | + break; |
| 113913 | + } |
| 113914 | + } |
| 113915 | + } |
| 113916 | + |
| 113917 | + z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) ); |
| 114055 | 113918 | if( z==0 ) return; |
| 114056 | | - if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, pName); |
| 114057 | | - memcpy(z, pName->z, pName->n); |
| 114058 | | - z[pName->n] = 0; |
| 113919 | + if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName); |
| 113920 | + memcpy(z, sName.z, sName.n); |
| 113921 | + z[sName.n] = 0; |
| 114059 | 113922 | sqlite3Dequote(z); |
| 114060 | 113923 | hName = sqlite3StrIHash(z); |
| 114061 | 113924 | for(i=0; i<p->nCol; i++){ |
| 114062 | | - if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zName)==0 ){ |
| 113925 | + if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){ |
| 114063 | 113926 | sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); |
| 114064 | 113927 | sqlite3DbFree(db, z); |
| 114065 | 113928 | return; |
| 114066 | 113929 | } |
| 114067 | 113930 | } |
| 114068 | | - if( (p->nCol & 0x7)==0 ){ |
| 114069 | | - Column *aNew; |
| 114070 | | - aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0])); |
| 114071 | | - if( aNew==0 ){ |
| 114072 | | - sqlite3DbFree(db, z); |
| 114073 | | - return; |
| 114074 | | - } |
| 114075 | | - p->aCol = aNew; |
| 114076 | | - } |
| 113931 | + aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0])); |
| 113932 | + if( aNew==0 ){ |
| 113933 | + sqlite3DbFree(db, z); |
| 113934 | + return; |
| 113935 | + } |
| 113936 | + p->aCol = aNew; |
| 114077 | 113937 | pCol = &p->aCol[p->nCol]; |
| 114078 | 113938 | memset(pCol, 0, sizeof(p->aCol[0])); |
| 114079 | | - pCol->zName = z; |
| 113939 | + pCol->zCnName = z; |
| 114080 | 113940 | pCol->hName = hName; |
| 114081 | 113941 | sqlite3ColumnPropertiesFromName(p, pCol); |
| 114082 | 113942 | |
| 114083 | | - if( pType->n==0 ){ |
| 113943 | + if( sType.n==0 ){ |
| 114084 | 113944 | /* If there is no type specified, columns have the default affinity |
| 114085 | 113945 | ** 'BLOB' with a default size of 4 bytes. */ |
| 114086 | | - pCol->affinity = SQLITE_AFF_BLOB; |
| 114087 | | - pCol->szEst = 1; |
| 113946 | + pCol->affinity = affinity; |
| 113947 | + pCol->eType = eType; |
| 113948 | + pCol->szEst = szEst; |
| 114088 | 113949 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 114089 | | - if( 4>=sqlite3GlobalConfig.szSorterRef ){ |
| 114090 | | - pCol->colFlags |= COLFLAG_SORTERREF; |
| 113950 | + if( affinity==SQLITE_AFF_BLOB ){ |
| 113951 | + if( 4>=sqlite3GlobalConfig.szSorterRef ){ |
| 113952 | + pCol->colFlags |= COLFLAG_SORTERREF; |
| 113953 | + } |
| 114091 | 113954 | } |
| 114092 | 113955 | #endif |
| 114093 | 113956 | }else{ |
| 114094 | 113957 | zType = z + sqlite3Strlen30(z) + 1; |
| 114095 | | - memcpy(zType, pType->z, pType->n); |
| 114096 | | - zType[pType->n] = 0; |
| 113958 | + memcpy(zType, sType.z, sType.n); |
| 113959 | + zType[sType.n] = 0; |
| 114097 | 113960 | sqlite3Dequote(zType); |
| 114098 | 113961 | pCol->affinity = sqlite3AffinityType(zType, pCol); |
| 114099 | 113962 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 114100 | 113963 | } |
| 114101 | 113964 | p->nCol++; |
| | @@ -114246,11 +114109,11 @@ |
| 114246 | 114109 | if( p!=0 ){ |
| 114247 | 114110 | int isInit = db->init.busy && db->init.iDb!=1; |
| 114248 | 114111 | pCol = &(p->aCol[p->nCol-1]); |
| 114249 | 114112 | if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){ |
| 114250 | 114113 | sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", |
| 114251 | | - pCol->zName); |
| 114114 | + pCol->zCnName); |
| 114252 | 114115 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 114253 | 114116 | }else if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 114254 | 114117 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 114255 | 114118 | testcase( pCol->colFlags & COLFLAG_STORED ); |
| 114256 | 114119 | sqlite3ErrorMsg(pParse, "cannot use DEFAULT on a generated column"); |
| | @@ -114257,19 +114120,19 @@ |
| 114257 | 114120 | #endif |
| 114258 | 114121 | }else{ |
| 114259 | 114122 | /* A copy of pExpr is used instead of the original, as pExpr contains |
| 114260 | 114123 | ** tokens that point to volatile memory. |
| 114261 | 114124 | */ |
| 114262 | | - Expr x; |
| 114263 | | - sqlite3ExprDelete(db, pCol->pDflt); |
| 114125 | + Expr x, *pDfltExpr; |
| 114264 | 114126 | memset(&x, 0, sizeof(x)); |
| 114265 | 114127 | x.op = TK_SPAN; |
| 114266 | 114128 | x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd); |
| 114267 | 114129 | x.pLeft = pExpr; |
| 114268 | 114130 | x.flags = EP_Skip; |
| 114269 | | - pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE); |
| 114131 | + pDfltExpr = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE); |
| 114270 | 114132 | sqlite3DbFree(db, x.u.zToken); |
| 114133 | + sqlite3ColumnSetExpr(pParse, p, pCol, pDfltExpr); |
| 114271 | 114134 | } |
| 114272 | 114135 | } |
| 114273 | 114136 | if( IN_RENAME_OBJECT ){ |
| 114274 | 114137 | sqlite3RenameExprUnmap(pParse, pExpr); |
| 114275 | 114138 | } |
| | @@ -114363,11 +114226,11 @@ |
| 114363 | 114226 | assert( pCExpr!=0 ); |
| 114364 | 114227 | sqlite3StringToId(pCExpr); |
| 114365 | 114228 | if( pCExpr->op==TK_ID ){ |
| 114366 | 114229 | const char *zCName = pCExpr->u.zToken; |
| 114367 | 114230 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114368 | | - if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){ |
| 114231 | + if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){ |
| 114369 | 114232 | pCol = &pTab->aCol[iCol]; |
| 114370 | 114233 | makeColumnPartOfPrimaryKey(pParse, pCol); |
| 114371 | 114234 | break; |
| 114372 | 114235 | } |
| 114373 | 114236 | } |
| | @@ -114374,11 +114237,11 @@ |
| 114374 | 114237 | } |
| 114375 | 114238 | } |
| 114376 | 114239 | } |
| 114377 | 114240 | if( nTerm==1 |
| 114378 | 114241 | && pCol |
| 114379 | | - && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0 |
| 114242 | + && pCol->eType==COLTYPE_INTEGER |
| 114380 | 114243 | && sortOrder!=SQLITE_SO_DESC |
| 114381 | 114244 | ){ |
| 114382 | 114245 | if( IN_RENAME_OBJECT && pList ){ |
| 114383 | 114246 | Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr); |
| 114384 | 114247 | sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr); |
| | @@ -114454,26 +114317,24 @@ |
| 114454 | 114317 | zColl = sqlite3NameFromToken(db, pToken); |
| 114455 | 114318 | if( !zColl ) return; |
| 114456 | 114319 | |
| 114457 | 114320 | if( sqlite3LocateCollSeq(pParse, zColl) ){ |
| 114458 | 114321 | Index *pIdx; |
| 114459 | | - sqlite3DbFree(db, p->aCol[i].zColl); |
| 114460 | | - p->aCol[i].zColl = zColl; |
| 114322 | + sqlite3ColumnSetColl(db, &p->aCol[i], zColl); |
| 114461 | 114323 | |
| 114462 | 114324 | /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>", |
| 114463 | 114325 | ** then an index may have been created on this column before the |
| 114464 | 114326 | ** collation type was added. Correct this if it is the case. |
| 114465 | 114327 | */ |
| 114466 | 114328 | for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 114467 | 114329 | assert( pIdx->nKeyCol==1 ); |
| 114468 | 114330 | if( pIdx->aiColumn[0]==i ){ |
| 114469 | | - pIdx->azColl[0] = p->aCol[i].zColl; |
| 114331 | + pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]); |
| 114470 | 114332 | } |
| 114471 | 114333 | } |
| 114472 | | - }else{ |
| 114473 | | - sqlite3DbFree(db, zColl); |
| 114474 | 114334 | } |
| 114335 | + sqlite3DbFree(db, zColl); |
| 114475 | 114336 | } |
| 114476 | 114337 | |
| 114477 | 114338 | /* Change the most recently parsed column to be a GENERATED ALWAYS AS |
| 114478 | 114339 | ** column. |
| 114479 | 114340 | */ |
| | @@ -114489,11 +114350,11 @@ |
| 114489 | 114350 | pCol = &(pTab->aCol[pTab->nCol-1]); |
| 114490 | 114351 | if( IN_DECLARE_VTAB ){ |
| 114491 | 114352 | sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns"); |
| 114492 | 114353 | goto generated_done; |
| 114493 | 114354 | } |
| 114494 | | - if( pCol->pDflt ) goto generated_error; |
| 114355 | + if( pCol->iDflt>0 ) goto generated_error; |
| 114495 | 114356 | if( pType ){ |
| 114496 | 114357 | if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){ |
| 114497 | 114358 | /* no-op */ |
| 114498 | 114359 | }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){ |
| 114499 | 114360 | eType = COLFLAG_STORED; |
| | @@ -114507,17 +114368,17 @@ |
| 114507 | 114368 | assert( TF_HasStored==COLFLAG_STORED ); |
| 114508 | 114369 | pTab->tabFlags |= eType; |
| 114509 | 114370 | if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 114510 | 114371 | makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */ |
| 114511 | 114372 | } |
| 114512 | | - pCol->pDflt = pExpr; |
| 114373 | + sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr); |
| 114513 | 114374 | pExpr = 0; |
| 114514 | 114375 | goto generated_done; |
| 114515 | 114376 | |
| 114516 | 114377 | generated_error: |
| 114517 | 114378 | sqlite3ErrorMsg(pParse, "error in generated column \"%s\"", |
| 114518 | | - pCol->zName); |
| 114379 | + pCol->zCnName); |
| 114519 | 114380 | generated_done: |
| 114520 | 114381 | sqlite3ExprDelete(pParse->db, pExpr); |
| 114521 | 114382 | #else |
| 114522 | 114383 | /* Throw and error for the GENERATED ALWAYS AS clause if the |
| 114523 | 114384 | ** SQLITE_OMIT_GENERATED_COLUMNS compile-time option is used. */ |
| | @@ -114615,11 +114476,11 @@ |
| 114615 | 114476 | char *zStmt; |
| 114616 | 114477 | char *zSep, *zSep2, *zEnd; |
| 114617 | 114478 | Column *pCol; |
| 114618 | 114479 | n = 0; |
| 114619 | 114480 | for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){ |
| 114620 | | - n += identLength(pCol->zName) + 5; |
| 114481 | + n += identLength(pCol->zCnName) + 5; |
| 114621 | 114482 | } |
| 114622 | 114483 | n += identLength(p->zName); |
| 114623 | 114484 | if( n<50 ){ |
| 114624 | 114485 | zSep = ""; |
| 114625 | 114486 | zSep2 = ","; |
| | @@ -114651,11 +114512,11 @@ |
| 114651 | 114512 | const char *zType; |
| 114652 | 114513 | |
| 114653 | 114514 | sqlite3_snprintf(n-k, &zStmt[k], zSep); |
| 114654 | 114515 | k += sqlite3Strlen30(&zStmt[k]); |
| 114655 | 114516 | zSep = zSep2; |
| 114656 | | - identPut(zStmt, &k, pCol->zName); |
| 114517 | + identPut(zStmt, &k, pCol->zCnName); |
| 114657 | 114518 | assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 ); |
| 114658 | 114519 | assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) ); |
| 114659 | 114520 | testcase( pCol->affinity==SQLITE_AFF_BLOB ); |
| 114660 | 114521 | testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 114661 | 114522 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| | @@ -114870,11 +114731,11 @@ |
| 114870 | 114731 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 114871 | 114732 | */ |
| 114872 | 114733 | if( pTab->iPKey>=0 ){ |
| 114873 | 114734 | ExprList *pList; |
| 114874 | 114735 | Token ipkToken; |
| 114875 | | - sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName); |
| 114736 | + sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zCnName); |
| 114876 | 114737 | pList = sqlite3ExprListAppend(pParse, 0, |
| 114877 | 114738 | sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0)); |
| 114878 | 114739 | if( pList==0 ){ |
| 114879 | 114740 | pTab->tabFlags &= ~TF_WithoutRowid; |
| 114880 | 114741 | return; |
| | @@ -115000,11 +114861,11 @@ |
| 115000 | 114861 | |
| 115001 | 114862 | if( !IsVirtual(pTab) ) return 0; |
| 115002 | 114863 | nName = sqlite3Strlen30(pTab->zName); |
| 115003 | 114864 | if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0; |
| 115004 | 114865 | if( zName[nName]!='_' ) return 0; |
| 115005 | | - pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]); |
| 114866 | + pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]); |
| 115006 | 114867 | if( pMod==0 ) return 0; |
| 115007 | 114868 | if( pMod->pModule->iVersion<3 ) return 0; |
| 115008 | 114869 | if( pMod->pModule->xShadowName==0 ) return 0; |
| 115009 | 114870 | return pMod->pModule->xShadowName(zName+nName+1); |
| 115010 | 114871 | } |
| | @@ -115161,22 +115022,22 @@ |
| 115161 | 115022 | testcase( p->tabFlags & TF_HasVirtual ); |
| 115162 | 115023 | testcase( p->tabFlags & TF_HasStored ); |
| 115163 | 115024 | for(ii=0; ii<p->nCol; ii++){ |
| 115164 | 115025 | u32 colFlags = p->aCol[ii].colFlags; |
| 115165 | 115026 | if( (colFlags & COLFLAG_GENERATED)!=0 ){ |
| 115166 | | - Expr *pX = p->aCol[ii].pDflt; |
| 115027 | + Expr *pX = sqlite3ColumnExpr(p, &p->aCol[ii]); |
| 115167 | 115028 | testcase( colFlags & COLFLAG_VIRTUAL ); |
| 115168 | 115029 | testcase( colFlags & COLFLAG_STORED ); |
| 115169 | 115030 | if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){ |
| 115170 | 115031 | /* If there are errors in resolving the expression, change the |
| 115171 | 115032 | ** expression to a NULL. This prevents code generators that operate |
| 115172 | 115033 | ** on the expression from inserting extra parts into the expression |
| 115173 | 115034 | ** tree that have been allocated from lookaside memory, which is |
| 115174 | 115035 | ** illegal in a schema and will lead to errors or heap corruption |
| 115175 | 115036 | ** when the database connection closes. */ |
| 115176 | | - sqlite3ExprDelete(db, pX); |
| 115177 | | - p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0); |
| 115037 | + sqlite3ColumnSetExpr(pParse, p, &p->aCol[ii], |
| 115038 | + sqlite3ExprAlloc(db, TK_NULL, 0, 0)); |
| 115178 | 115039 | } |
| 115179 | 115040 | }else{ |
| 115180 | 115041 | nNG++; |
| 115181 | 115042 | } |
| 115182 | 115043 | } |
| | @@ -115212,11 +115073,11 @@ |
| 115212 | 115073 | sqlite3VdbeAddOp1(v, OP_Close, 0); |
| 115213 | 115074 | |
| 115214 | 115075 | /* |
| 115215 | 115076 | ** Initialize zType for the new view or table. |
| 115216 | 115077 | */ |
| 115217 | | - if( p->pSelect==0 ){ |
| 115078 | + if( IsOrdinaryTable(p) ){ |
| 115218 | 115079 | /* A regular table */ |
| 115219 | 115080 | zType = "table"; |
| 115220 | 115081 | zType2 = "TABLE"; |
| 115221 | 115082 | #ifndef SQLITE_OMIT_VIEW |
| 115222 | 115083 | }else{ |
| | @@ -115362,16 +115223,16 @@ |
| 115362 | 115223 | } |
| 115363 | 115224 | #endif |
| 115364 | 115225 | } |
| 115365 | 115226 | |
| 115366 | 115227 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 115367 | | - if( !pSelect && !p->pSelect ){ |
| 115228 | + if( !pSelect && IsOrdinaryTable(p) ){ |
| 115368 | 115229 | assert( pCons && pEnd ); |
| 115369 | 115230 | if( pCons->z==0 ){ |
| 115370 | 115231 | pCons = pEnd; |
| 115371 | 115232 | } |
| 115372 | | - p->addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z); |
| 115233 | + p->u.tab.addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z); |
| 115373 | 115234 | } |
| 115374 | 115235 | #endif |
| 115375 | 115236 | } |
| 115376 | 115237 | |
| 115377 | 115238 | #ifndef SQLITE_OMIT_VIEW |
| | @@ -115424,16 +115285,17 @@ |
| 115424 | 115285 | ** allocated rather than point to the input string - which means that |
| 115425 | 115286 | ** they will persist after the current sqlite3_exec() call returns. |
| 115426 | 115287 | */ |
| 115427 | 115288 | pSelect->selFlags |= SF_View; |
| 115428 | 115289 | if( IN_RENAME_OBJECT ){ |
| 115429 | | - p->pSelect = pSelect; |
| 115290 | + p->u.view.pSelect = pSelect; |
| 115430 | 115291 | pSelect = 0; |
| 115431 | 115292 | }else{ |
| 115432 | | - p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 115293 | + p->u.view.pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 115433 | 115294 | } |
| 115434 | 115295 | p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE); |
| 115296 | + p->eTabType = TABTYP_VIEW; |
| 115435 | 115297 | if( db->mallocFailed ) goto create_view_fail; |
| 115436 | 115298 | |
| 115437 | 115299 | /* Locate the end of the CREATE VIEW statement. Make sEnd point to |
| 115438 | 115300 | ** the end. |
| 115439 | 115301 | */ |
| | @@ -115526,12 +115388,12 @@ |
| 115526 | 115388 | ** "*" elements in the results set of the view and will assign cursors |
| 115527 | 115389 | ** to the elements of the FROM clause. But we do not want these changes |
| 115528 | 115390 | ** to be permanent. So the computation is done on a copy of the SELECT |
| 115529 | 115391 | ** statement that defines the view. |
| 115530 | 115392 | */ |
| 115531 | | - assert( pTable->pSelect ); |
| 115532 | | - pSel = sqlite3SelectDup(db, pTable->pSelect, 0); |
| 115393 | + assert( IsView(pTable) ); |
| 115394 | + pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0); |
| 115533 | 115395 | if( pSel ){ |
| 115534 | 115396 | u8 eParseMode = pParse->eParseMode; |
| 115535 | 115397 | pParse->eParseMode = PARSE_MODE_NORMAL; |
| 115536 | 115398 | n = pParse->nTab; |
| 115537 | 115399 | sqlite3SrcListAssignCursors(pParse, pSel->pSrc); |
| | @@ -115586,12 +115448,10 @@ |
| 115586 | 115448 | nErr++; |
| 115587 | 115449 | } |
| 115588 | 115450 | pTable->pSchema->schemaFlags |= DB_UnresetViews; |
| 115589 | 115451 | if( db->mallocFailed ){ |
| 115590 | 115452 | sqlite3DeleteColumnNames(db, pTable); |
| 115591 | | - pTable->aCol = 0; |
| 115592 | | - pTable->nCol = 0; |
| 115593 | 115453 | } |
| 115594 | 115454 | #endif /* SQLITE_OMIT_VIEW */ |
| 115595 | 115455 | return nErr; |
| 115596 | 115456 | } |
| 115597 | 115457 | #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| | @@ -115604,14 +115464,12 @@ |
| 115604 | 115464 | HashElem *i; |
| 115605 | 115465 | assert( sqlite3SchemaMutexHeld(db, idx, 0) ); |
| 115606 | 115466 | if( !DbHasProperty(db, idx, DB_UnresetViews) ) return; |
| 115607 | 115467 | for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){ |
| 115608 | 115468 | Table *pTab = sqliteHashData(i); |
| 115609 | | - if( pTab->pSelect ){ |
| 115469 | + if( IsView(pTab) ){ |
| 115610 | 115470 | sqlite3DeleteColumnNames(db, pTab); |
| 115611 | | - pTab->aCol = 0; |
| 115612 | | - pTab->nCol = 0; |
| 115613 | 115471 | } |
| 115614 | 115472 | } |
| 115615 | 115473 | DbClearProperty(db, idx, DB_UnresetViews); |
| 115616 | 115474 | } |
| 115617 | 115475 | #else |
| | @@ -115948,15 +115806,15 @@ |
| 115948 | 115806 | |
| 115949 | 115807 | #ifndef SQLITE_OMIT_VIEW |
| 115950 | 115808 | /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used |
| 115951 | 115809 | ** on a table. |
| 115952 | 115810 | */ |
| 115953 | | - if( isView && pTab->pSelect==0 ){ |
| 115811 | + if( isView && !IsView(pTab) ){ |
| 115954 | 115812 | sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName); |
| 115955 | 115813 | goto exit_drop_table; |
| 115956 | 115814 | } |
| 115957 | | - if( !isView && pTab->pSelect ){ |
| 115815 | + if( !isView && IsView(pTab) ){ |
| 115958 | 115816 | sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName); |
| 115959 | 115817 | goto exit_drop_table; |
| 115960 | 115818 | } |
| 115961 | 115819 | #endif |
| 115962 | 115820 | |
| | @@ -116016,11 +115874,11 @@ |
| 116016 | 115874 | int iCol = p->nCol-1; |
| 116017 | 115875 | if( NEVER(iCol<0) ) goto fk_end; |
| 116018 | 115876 | if( pToCol && pToCol->nExpr!=1 ){ |
| 116019 | 115877 | sqlite3ErrorMsg(pParse, "foreign key on %s" |
| 116020 | 115878 | " should reference only one column of table %T", |
| 116021 | | - p->aCol[iCol].zName, pTo); |
| 115879 | + p->aCol[iCol].zCnName, pTo); |
| 116022 | 115880 | goto fk_end; |
| 116023 | 115881 | } |
| 116024 | 115882 | nCol = 1; |
| 116025 | 115883 | }else if( pToCol && pToCol->nExpr!=pFromCol->nExpr ){ |
| 116026 | 115884 | sqlite3ErrorMsg(pParse, |
| | @@ -116039,11 +115897,11 @@ |
| 116039 | 115897 | pFKey = sqlite3DbMallocZero(db, nByte ); |
| 116040 | 115898 | if( pFKey==0 ){ |
| 116041 | 115899 | goto fk_end; |
| 116042 | 115900 | } |
| 116043 | 115901 | pFKey->pFrom = p; |
| 116044 | | - pFKey->pNextFrom = p->pFKey; |
| 115902 | + pFKey->pNextFrom = p->u.tab.pFKey; |
| 116045 | 115903 | z = (char*)&pFKey->aCol[nCol]; |
| 116046 | 115904 | pFKey->zTo = z; |
| 116047 | 115905 | if( IN_RENAME_OBJECT ){ |
| 116048 | 115906 | sqlite3RenameTokenMap(pParse, (void*)z, pTo); |
| 116049 | 115907 | } |
| | @@ -116056,11 +115914,11 @@ |
| 116056 | 115914 | pFKey->aCol[0].iFrom = p->nCol-1; |
| 116057 | 115915 | }else{ |
| 116058 | 115916 | for(i=0; i<nCol; i++){ |
| 116059 | 115917 | int j; |
| 116060 | 115918 | for(j=0; j<p->nCol; j++){ |
| 116061 | | - if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){ |
| 115919 | + if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){ |
| 116062 | 115920 | pFKey->aCol[i].iFrom = j; |
| 116063 | 115921 | break; |
| 116064 | 115922 | } |
| 116065 | 115923 | } |
| 116066 | 115924 | if( j>=p->nCol ){ |
| | @@ -116104,11 +115962,12 @@ |
| 116104 | 115962 | pNextTo->pPrevTo = pFKey; |
| 116105 | 115963 | } |
| 116106 | 115964 | |
| 116107 | 115965 | /* Link the foreign key to the table as the last step. |
| 116108 | 115966 | */ |
| 116109 | | - p->pFKey = pFKey; |
| 115967 | + assert( !IsVirtual(p) ); |
| 115968 | + p->u.tab.pFKey = pFKey; |
| 116110 | 115969 | pFKey = 0; |
| 116111 | 115970 | |
| 116112 | 115971 | fk_end: |
| 116113 | 115972 | sqlite3DbFree(db, pFKey); |
| 116114 | 115973 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| | @@ -116125,11 +115984,13 @@ |
| 116125 | 115984 | */ |
| 116126 | 115985 | SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){ |
| 116127 | 115986 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 116128 | 115987 | Table *pTab; |
| 116129 | 115988 | FKey *pFKey; |
| 116130 | | - if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return; |
| 115989 | + if( (pTab = pParse->pNewTable)==0 ) return; |
| 115990 | + if( NEVER(IsVirtual(pTab)) ) return; |
| 115991 | + if( (pFKey = pTab->u.tab.pFKey)==0 ) return; |
| 116131 | 115992 | assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */ |
| 116132 | 115993 | pFKey->isDeferred = (u8)isDeferred; |
| 116133 | 115994 | #endif |
| 116134 | 115995 | } |
| 116135 | 115996 | |
| | @@ -116417,11 +116278,11 @@ |
| 116417 | 116278 | ){ |
| 116418 | 116279 | sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName); |
| 116419 | 116280 | goto exit_create_index; |
| 116420 | 116281 | } |
| 116421 | 116282 | #ifndef SQLITE_OMIT_VIEW |
| 116422 | | - if( pTab->pSelect ){ |
| 116283 | + if( IsView(pTab) ){ |
| 116423 | 116284 | sqlite3ErrorMsg(pParse, "views may not be indexed"); |
| 116424 | 116285 | goto exit_create_index; |
| 116425 | 116286 | } |
| 116426 | 116287 | #endif |
| 116427 | 116288 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -116508,11 +116369,11 @@ |
| 116508 | 116369 | */ |
| 116509 | 116370 | if( pList==0 ){ |
| 116510 | 116371 | Token prevCol; |
| 116511 | 116372 | Column *pCol = &pTab->aCol[pTab->nCol-1]; |
| 116512 | 116373 | pCol->colFlags |= COLFLAG_UNIQUE; |
| 116513 | | - sqlite3TokenInit(&prevCol, pCol->zName); |
| 116374 | + sqlite3TokenInit(&prevCol, pCol->zCnName); |
| 116514 | 116375 | pList = sqlite3ExprListAppend(pParse, 0, |
| 116515 | 116376 | sqlite3ExprAlloc(db, TK_ID, &prevCol, 0)); |
| 116516 | 116377 | if( pList==0 ) goto exit_create_index; |
| 116517 | 116378 | assert( pList->nExpr==1 ); |
| 116518 | 116379 | sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED); |
| | @@ -116629,11 +116490,11 @@ |
| 116629 | 116490 | memcpy(zExtra, zColl, nColl); |
| 116630 | 116491 | zColl = zExtra; |
| 116631 | 116492 | zExtra += nColl; |
| 116632 | 116493 | nExtra -= nColl; |
| 116633 | 116494 | }else if( j>=0 ){ |
| 116634 | | - zColl = pTab->aCol[j].zColl; |
| 116495 | + zColl = sqlite3ColumnColl(&pTab->aCol[j]); |
| 116635 | 116496 | } |
| 116636 | 116497 | if( !zColl ) zColl = sqlite3StrBINARY; |
| 116637 | 116498 | if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){ |
| 116638 | 116499 | goto exit_create_index; |
| 116639 | 116500 | } |
| | @@ -117721,11 +117582,11 @@ |
| 117721 | 117582 | sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName); |
| 117722 | 117583 | }else{ |
| 117723 | 117584 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 117724 | 117585 | char *zCol; |
| 117725 | 117586 | assert( pIdx->aiColumn[j]>=0 ); |
| 117726 | | - zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 117587 | + zCol = pTab->aCol[pIdx->aiColumn[j]].zCnName; |
| 117727 | 117588 | if( j ) sqlite3_str_append(&errMsg, ", ", 2); |
| 117728 | 117589 | sqlite3_str_appendall(&errMsg, pTab->zName); |
| 117729 | 117590 | sqlite3_str_append(&errMsg, ".", 1); |
| 117730 | 117591 | sqlite3_str_appendall(&errMsg, zCol); |
| 117731 | 117592 | } |
| | @@ -117748,11 +117609,11 @@ |
| 117748 | 117609 | ){ |
| 117749 | 117610 | char *zMsg; |
| 117750 | 117611 | int rc; |
| 117751 | 117612 | if( pTab->iPKey>=0 ){ |
| 117752 | 117613 | zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName, |
| 117753 | | - pTab->aCol[pTab->iPKey].zName); |
| 117614 | + pTab->aCol[pTab->iPKey].zCnName); |
| 117754 | 117615 | rc = SQLITE_CONSTRAINT_PRIMARYKEY; |
| 117755 | 117616 | }else{ |
| 117756 | 117617 | zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName); |
| 117757 | 117618 | rc = SQLITE_CONSTRAINT_ROWID; |
| 117758 | 117619 | } |
| | @@ -118675,11 +118536,11 @@ |
| 118675 | 118536 | if( tabIsReadOnly(pParse, pTab) ){ |
| 118676 | 118537 | sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName); |
| 118677 | 118538 | return 1; |
| 118678 | 118539 | } |
| 118679 | 118540 | #ifndef SQLITE_OMIT_VIEW |
| 118680 | | - if( !viewOk && pTab->pSelect ){ |
| 118541 | + if( !viewOk && IsView(pTab) ){ |
| 118681 | 118542 | sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName); |
| 118682 | 118543 | return 1; |
| 118683 | 118544 | } |
| 118684 | 118545 | #endif |
| 118685 | 118546 | return 0; |
| | @@ -118779,17 +118640,17 @@ |
| 118779 | 118640 | pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0) |
| 118780 | 118641 | ); |
| 118781 | 118642 | }else{ |
| 118782 | 118643 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 118783 | 118644 | if( pPk->nKeyCol==1 ){ |
| 118784 | | - const char *zName = pTab->aCol[pPk->aiColumn[0]].zName; |
| 118645 | + const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName; |
| 118785 | 118646 | pLhs = sqlite3Expr(db, TK_ID, zName); |
| 118786 | 118647 | pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName)); |
| 118787 | 118648 | }else{ |
| 118788 | 118649 | int i; |
| 118789 | 118650 | for(i=0; i<pPk->nKeyCol; i++){ |
| 118790 | | - Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName); |
| 118651 | + Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName); |
| 118791 | 118652 | pEList = sqlite3ExprListAppend(pParse, pEList, p); |
| 118792 | 118653 | } |
| 118793 | 118654 | pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 118794 | 118655 | if( pLhs ){ |
| 118795 | 118656 | pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0); |
| | @@ -118892,11 +118753,11 @@ |
| 118892 | 118753 | /* Figure out if we have any triggers and if the table being |
| 118893 | 118754 | ** deleted from is a view |
| 118894 | 118755 | */ |
| 118895 | 118756 | #ifndef SQLITE_OMIT_TRIGGER |
| 118896 | 118757 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 118897 | | - isView = pTab->pSelect!=0; |
| 118758 | + isView = IsView(pTab); |
| 118898 | 118759 | #else |
| 118899 | 118760 | # define pTrigger 0 |
| 118900 | 118761 | # define isView 0 |
| 118901 | 118762 | #endif |
| 118902 | 118763 | bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); |
| | @@ -119142,11 +119003,11 @@ |
| 119142 | 119003 | ** where-clause loop above. |
| 119143 | 119004 | */ |
| 119144 | 119005 | if( eOnePass!=ONEPASS_OFF ){ |
| 119145 | 119006 | assert( nKey==nPk ); /* OP_Found will use an unpacked key */ |
| 119146 | 119007 | if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){ |
| 119147 | | - assert( pPk!=0 || pTab->pSelect!=0 ); |
| 119008 | + assert( pPk!=0 || IsView(pTab) ); |
| 119148 | 119009 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 119149 | 119010 | VdbeCoverage(v); |
| 119150 | 119011 | } |
| 119151 | 119012 | }else if( pPk ){ |
| 119152 | 119013 | addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v); |
| | @@ -119376,11 +119237,11 @@ |
| 119376 | 119237 | ** invoke the update-hook. The pre-update-hook, on the other hand should |
| 119377 | 119238 | ** be invoked unless table pTab is a system table. The difference is that |
| 119378 | 119239 | ** the update-hook is not invoked for rows removed by REPLACE, but the |
| 119379 | 119240 | ** pre-update-hook is. |
| 119380 | 119241 | */ |
| 119381 | | - if( pTab->pSelect==0 ){ |
| 119242 | + if( !IsView(pTab) ){ |
| 119382 | 119243 | u8 p5 = 0; |
| 119383 | 119244 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 119384 | 119245 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 119385 | 119246 | if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){ |
| 119386 | 119247 | sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); |
| | @@ -122070,11 +121931,13 @@ |
| 122070 | 121931 | ** 2) The FK is explicitly mapped to a column declared as INTEGER |
| 122071 | 121932 | ** PRIMARY KEY. |
| 122072 | 121933 | */ |
| 122073 | 121934 | if( pParent->iPKey>=0 ){ |
| 122074 | 121935 | if( !zKey ) return 0; |
| 122075 | | - if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0; |
| 121936 | + if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zCnName, zKey) ){ |
| 121937 | + return 0; |
| 121938 | + } |
| 122076 | 121939 | } |
| 122077 | 121940 | }else if( paiCol ){ |
| 122078 | 121941 | assert( nCol>1 ); |
| 122079 | 121942 | aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int)); |
| 122080 | 121943 | if( !aiCol ) return 1; |
| | @@ -122112,15 +121975,15 @@ |
| 122112 | 121975 | if( iCol<0 ) break; /* No foreign keys against expression indexes */ |
| 122113 | 121976 | |
| 122114 | 121977 | /* If the index uses a collation sequence that is different from |
| 122115 | 121978 | ** the default collation sequence for the column, this index is |
| 122116 | 121979 | ** unusable. Bail out early in this case. */ |
| 122117 | | - zDfltColl = pParent->aCol[iCol].zColl; |
| 121980 | + zDfltColl = sqlite3ColumnColl(&pParent->aCol[iCol]); |
| 122118 | 121981 | if( !zDfltColl ) zDfltColl = sqlite3StrBINARY; |
| 122119 | 121982 | if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break; |
| 122120 | 121983 | |
| 122121 | | - zIdxCol = pParent->aCol[iCol].zName; |
| 121984 | + zIdxCol = pParent->aCol[iCol].zCnName; |
| 122122 | 121985 | for(j=0; j<nCol; j++){ |
| 122123 | 121986 | if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){ |
| 122124 | 121987 | if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom; |
| 122125 | 121988 | break; |
| 122126 | 121989 | } |
| | @@ -122340,11 +122203,11 @@ |
| 122340 | 122203 | if( pExpr ){ |
| 122341 | 122204 | if( iCol>=0 && iCol!=pTab->iPKey ){ |
| 122342 | 122205 | pCol = &pTab->aCol[iCol]; |
| 122343 | 122206 | pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1; |
| 122344 | 122207 | pExpr->affExpr = pCol->affinity; |
| 122345 | | - zColl = pCol->zColl; |
| 122208 | + zColl = sqlite3ColumnColl(pCol); |
| 122346 | 122209 | if( zColl==0 ) zColl = db->pDfltColl->zName; |
| 122347 | 122210 | pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl); |
| 122348 | 122211 | }else{ |
| 122349 | 122212 | pExpr->iTable = regBase; |
| 122350 | 122213 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| | @@ -122449,11 +122312,11 @@ |
| 122449 | 122312 | |
| 122450 | 122313 | iCol = pIdx ? pIdx->aiColumn[i] : -1; |
| 122451 | 122314 | pLeft = exprTableRegister(pParse, pTab, regData, iCol); |
| 122452 | 122315 | iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 122453 | 122316 | assert( iCol>=0 ); |
| 122454 | | - zCol = pFKey->pFrom->aCol[iCol].zName; |
| 122317 | + zCol = pFKey->pFrom->aCol[iCol].zCnName; |
| 122455 | 122318 | pRight = sqlite3Expr(db, TK_ID, zCol); |
| 122456 | 122319 | pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight); |
| 122457 | 122320 | pWhere = sqlite3ExprAnd(pParse, pWhere, pEq); |
| 122458 | 122321 | } |
| 122459 | 122322 | |
| | @@ -122484,11 +122347,11 @@ |
| 122484 | 122347 | assert( pIdx!=0 ); |
| 122485 | 122348 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 122486 | 122349 | i16 iCol = pIdx->aiColumn[i]; |
| 122487 | 122350 | assert( iCol>=0 ); |
| 122488 | 122351 | pLeft = exprTableRegister(pParse, pTab, regData, iCol); |
| 122489 | | - pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName); |
| 122352 | + pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zCnName); |
| 122490 | 122353 | pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight); |
| 122491 | 122354 | pAll = sqlite3ExprAnd(pParse, pAll, pEq); |
| 122492 | 122355 | } |
| 122493 | 122356 | pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0); |
| 122494 | 122357 | } |
| | @@ -122578,19 +122441,20 @@ |
| 122578 | 122441 | if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){ |
| 122579 | 122442 | int iSkip = 0; |
| 122580 | 122443 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 122581 | 122444 | |
| 122582 | 122445 | assert( v ); /* VDBE has already been allocated */ |
| 122583 | | - assert( pTab->pSelect==0 ); /* Not a view */ |
| 122446 | + assert( !IsView(pTab) ); /* Not a view */ |
| 122447 | + assert( !IsVirtual(pTab) ); |
| 122584 | 122448 | if( sqlite3FkReferences(pTab)==0 ){ |
| 122585 | 122449 | /* Search for a deferred foreign key constraint for which this table |
| 122586 | 122450 | ** is the child table. If one cannot be found, return without |
| 122587 | 122451 | ** generating any VDBE code. If one can be found, then jump over |
| 122588 | 122452 | ** the entire DELETE if there are no outstanding deferred constraints |
| 122589 | 122453 | ** when this statement is run. */ |
| 122590 | 122454 | FKey *p; |
| 122591 | | - for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 122455 | + for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 122592 | 122456 | if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break; |
| 122593 | 122457 | } |
| 122594 | 122458 | if( !p ) return; |
| 122595 | 122459 | iSkip = sqlite3VdbeMakeLabel(pParse); |
| 122596 | 122460 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v); |
| | @@ -122675,11 +122539,11 @@ |
| 122675 | 122539 | int iKey; |
| 122676 | 122540 | for(iKey=0; iKey<pTab->nCol; iKey++){ |
| 122677 | 122541 | if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){ |
| 122678 | 122542 | Column *pCol = &pTab->aCol[iKey]; |
| 122679 | 122543 | if( zKey ){ |
| 122680 | | - if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1; |
| 122544 | + if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1; |
| 122681 | 122545 | }else if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 122682 | 122546 | return 1; |
| 122683 | 122547 | } |
| 122684 | 122548 | } |
| 122685 | 122549 | } |
| | @@ -122748,11 +122612,12 @@ |
| 122748 | 122612 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 122749 | 122613 | zDb = db->aDb[iDb].zDbSName; |
| 122750 | 122614 | |
| 122751 | 122615 | /* Loop through all the foreign key constraints for which pTab is the |
| 122752 | 122616 | ** child table (the table that the foreign key definition is part of). */ |
| 122753 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 122617 | + assert( !IsVirtual(pTab) ); |
| 122618 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 122754 | 122619 | Table *pTo; /* Parent table of foreign key pFKey */ |
| 122755 | 122620 | Index *pIdx = 0; /* Index on key columns in pTo */ |
| 122756 | 122621 | int *aiFree = 0; |
| 122757 | 122622 | int *aiCol; |
| 122758 | 122623 | int iCol; |
| | @@ -122815,11 +122680,11 @@ |
| 122815 | 122680 | /* Request permission to read the parent key columns. If the |
| 122816 | 122681 | ** authorization callback returns SQLITE_IGNORE, behave as if any |
| 122817 | 122682 | ** values read from the parent table are NULL. */ |
| 122818 | 122683 | if( db->xAuth ){ |
| 122819 | 122684 | int rcauth; |
| 122820 | | - char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName; |
| 122685 | + char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zCnName; |
| 122821 | 122686 | rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb); |
| 122822 | 122687 | bIgnore = (rcauth==SQLITE_IGNORE); |
| 122823 | 122688 | } |
| 122824 | 122689 | #endif |
| 122825 | 122690 | } |
| | @@ -122933,11 +122798,12 @@ |
| 122933 | 122798 | ){ |
| 122934 | 122799 | u32 mask = 0; |
| 122935 | 122800 | if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 122936 | 122801 | FKey *p; |
| 122937 | 122802 | int i; |
| 122938 | | - for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 122803 | + assert( !IsVirtual(pTab) ); |
| 122804 | + for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 122939 | 122805 | for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); |
| 122940 | 122806 | } |
| 122941 | 122807 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 122942 | 122808 | Index *pIdx = 0; |
| 122943 | 122809 | sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0); |
| | @@ -122983,23 +122849,23 @@ |
| 122983 | 122849 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 122984 | 122850 | int chngRowid /* True for UPDATE that affects rowid */ |
| 122985 | 122851 | ){ |
| 122986 | 122852 | int eRet = 1; /* Value to return if bHaveFK is true */ |
| 122987 | 122853 | int bHaveFK = 0; /* If FK processing is required */ |
| 122988 | | - if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 122854 | + if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){ |
| 122989 | 122855 | if( !aChange ){ |
| 122990 | 122856 | /* A DELETE operation. Foreign key processing is required if the |
| 122991 | 122857 | ** table in question is either the child or parent table for any |
| 122992 | 122858 | ** foreign key constraint. */ |
| 122993 | | - bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey); |
| 122859 | + bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey); |
| 122994 | 122860 | }else{ |
| 122995 | 122861 | /* This is an UPDATE. Foreign key processing is only required if the |
| 122996 | 122862 | ** operation modifies one or more child or parent key columns. */ |
| 122997 | 122863 | FKey *p; |
| 122998 | 122864 | |
| 122999 | 122865 | /* Check if any child key columns are being modified. */ |
| 123000 | | - for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 122866 | + for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 123001 | 122867 | if( fkChildIsModified(pTab, p, aChange, chngRowid) ){ |
| 123002 | 122868 | if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2; |
| 123003 | 122869 | bHaveFK = 1; |
| 123004 | 122870 | } |
| 123005 | 122871 | } |
| | @@ -123088,12 +122954,12 @@ |
| 123088 | 122954 | iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 123089 | 122955 | assert( iFromCol>=0 ); |
| 123090 | 122956 | assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) ); |
| 123091 | 122957 | assert( pIdx==0 || pIdx->aiColumn[i]>=0 ); |
| 123092 | 122958 | sqlite3TokenInit(&tToCol, |
| 123093 | | - pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName); |
| 123094 | | - sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName); |
| 122959 | + pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zCnName); |
| 122960 | + sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zCnName); |
| 123095 | 122961 | |
| 123096 | 122962 | /* Create the expression "OLD.zToCol = zFromCol". It is important |
| 123097 | 122963 | ** that the "OLD.zToCol" term is on the LHS of the = operator, so |
| 123098 | 122964 | ** that the affinity and collation sequence associated with the |
| 123099 | 122965 | ** parent table are used for the comparison. */ |
| | @@ -123134,11 +123000,11 @@ |
| 123134 | 123000 | if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 123135 | 123001 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 123136 | 123002 | testcase( pCol->colFlags & COLFLAG_STORED ); |
| 123137 | 123003 | pDflt = 0; |
| 123138 | 123004 | }else{ |
| 123139 | | - pDflt = pCol->pDflt; |
| 123005 | + pDflt = sqlite3ColumnExpr(pFKey->pFrom, pCol); |
| 123140 | 123006 | } |
| 123141 | 123007 | if( pDflt ){ |
| 123142 | 123008 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| 123143 | 123009 | }else{ |
| 123144 | 123010 | pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0); |
| | @@ -123271,13 +123137,13 @@ |
| 123271 | 123137 | */ |
| 123272 | 123138 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 123273 | 123139 | FKey *pFKey; /* Iterator variable */ |
| 123274 | 123140 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 123275 | 123141 | |
| 123276 | | - assert( db==0 || IsVirtual(pTab) |
| 123277 | | - || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 123278 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){ |
| 123142 | + assert( !IsVirtual(pTab) ); |
| 123143 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){ |
| 123144 | + assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 123279 | 123145 | |
| 123280 | 123146 | /* Remove the FK from the fkeyHash hash table. */ |
| 123281 | 123147 | if( !db || db->pnBytesFreed==0 ){ |
| 123282 | 123148 | if( pFKey->pPrevTo ){ |
| 123283 | 123149 | pFKey->pPrevTo->pNextTo = pFKey->pNextTo; |
| | @@ -123603,26 +123469,26 @@ |
| 123603 | 123469 | Column *pCol = pTab->aCol + i; |
| 123604 | 123470 | if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){ |
| 123605 | 123471 | int x; |
| 123606 | 123472 | pCol->colFlags |= COLFLAG_BUSY; |
| 123607 | 123473 | w.eCode = 0; |
| 123608 | | - sqlite3WalkExpr(&w, pCol->pDflt); |
| 123474 | + sqlite3WalkExpr(&w, sqlite3ColumnExpr(pTab, pCol)); |
| 123609 | 123475 | pCol->colFlags &= ~COLFLAG_BUSY; |
| 123610 | 123476 | if( w.eCode & COLFLAG_NOTAVAIL ){ |
| 123611 | 123477 | pRedo = pCol; |
| 123612 | 123478 | continue; |
| 123613 | 123479 | } |
| 123614 | 123480 | eProgress = 1; |
| 123615 | 123481 | assert( pCol->colFlags & COLFLAG_GENERATED ); |
| 123616 | 123482 | x = sqlite3TableColumnToStorage(pTab, i) + iRegStore; |
| 123617 | | - sqlite3ExprCodeGeneratedColumn(pParse, pCol, x); |
| 123483 | + sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, x); |
| 123618 | 123484 | pCol->colFlags &= ~COLFLAG_NOTAVAIL; |
| 123619 | 123485 | } |
| 123620 | 123486 | } |
| 123621 | 123487 | }while( pRedo && eProgress ); |
| 123622 | 123488 | if( pRedo ){ |
| 123623 | | - sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zName); |
| 123489 | + sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zCnName); |
| 123624 | 123490 | } |
| 123625 | 123491 | pParse->iSelfTab = 0; |
| 123626 | 123492 | } |
| 123627 | 123493 | #endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 123628 | 123494 | |
| | @@ -124013,11 +123879,11 @@ |
| 124013 | 123879 | /* Figure out if we have any triggers and if the table being |
| 124014 | 123880 | ** inserted into is a view |
| 124015 | 123881 | */ |
| 124016 | 123882 | #ifndef SQLITE_OMIT_TRIGGER |
| 124017 | 123883 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask); |
| 124018 | | - isView = pTab->pSelect!=0; |
| 123884 | + isView = IsView(pTab); |
| 124019 | 123885 | #else |
| 124020 | 123886 | # define pTrigger 0 |
| 124021 | 123887 | # define tmask 0 |
| 124022 | 123888 | # define isView 0 |
| 124023 | 123889 | #endif |
| | @@ -124104,21 +123970,21 @@ |
| 124104 | 123970 | for(i=0; i<pColumn->nId; i++){ |
| 124105 | 123971 | pColumn->a[i].idx = -1; |
| 124106 | 123972 | } |
| 124107 | 123973 | for(i=0; i<pColumn->nId; i++){ |
| 124108 | 123974 | for(j=0; j<pTab->nCol; j++){ |
| 124109 | | - if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){ |
| 123975 | + if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){ |
| 124110 | 123976 | pColumn->a[i].idx = j; |
| 124111 | 123977 | if( i!=j ) bIdListInOrder = 0; |
| 124112 | 123978 | if( j==pTab->iPKey ){ |
| 124113 | 123979 | ipkColumn = i; assert( !withoutRowid ); |
| 124114 | 123980 | } |
| 124115 | 123981 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 124116 | 123982 | if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){ |
| 124117 | 123983 | sqlite3ErrorMsg(pParse, |
| 124118 | 123984 | "cannot INSERT into generated column \"%s\"", |
| 124119 | | - pTab->aCol[j].zName); |
| 123985 | + pTab->aCol[j].zCnName); |
| 124120 | 123986 | goto insert_cleanup; |
| 124121 | 123987 | } |
| 124122 | 123988 | #endif |
| 124123 | 123989 | break; |
| 124124 | 123990 | } |
| | @@ -124299,11 +124165,11 @@ |
| 124299 | 124165 | if( IsVirtual(pTab) ){ |
| 124300 | 124166 | sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"", |
| 124301 | 124167 | pTab->zName); |
| 124302 | 124168 | goto insert_cleanup; |
| 124303 | 124169 | } |
| 124304 | | - if( pTab->pSelect ){ |
| 124170 | + if( IsView(pTab) ){ |
| 124305 | 124171 | sqlite3ErrorMsg(pParse, "cannot UPSERT a view"); |
| 124306 | 124172 | goto insert_cleanup; |
| 124307 | 124173 | } |
| 124308 | 124174 | if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){ |
| 124309 | 124175 | goto insert_cleanup; |
| | @@ -124398,26 +124264,32 @@ |
| 124398 | 124264 | } |
| 124399 | 124265 | continue; |
| 124400 | 124266 | }else if( pColumn==0 ){ |
| 124401 | 124267 | /* Hidden columns that are not explicitly named in the INSERT |
| 124402 | 124268 | ** get there default value */ |
| 124403 | | - sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 124269 | + sqlite3ExprCodeFactorable(pParse, |
| 124270 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 124271 | + iRegStore); |
| 124404 | 124272 | continue; |
| 124405 | 124273 | } |
| 124406 | 124274 | } |
| 124407 | 124275 | if( pColumn ){ |
| 124408 | 124276 | for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){} |
| 124409 | 124277 | if( j>=pColumn->nId ){ |
| 124410 | 124278 | /* A column not named in the insert column list gets its |
| 124411 | 124279 | ** default value */ |
| 124412 | | - sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 124280 | + sqlite3ExprCodeFactorable(pParse, |
| 124281 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 124282 | + iRegStore); |
| 124413 | 124283 | continue; |
| 124414 | 124284 | } |
| 124415 | 124285 | k = j; |
| 124416 | 124286 | }else if( nColumn==0 ){ |
| 124417 | 124287 | /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */ |
| 124418 | | - sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 124288 | + sqlite3ExprCodeFactorable(pParse, |
| 124289 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 124290 | + iRegStore); |
| 124419 | 124291 | continue; |
| 124420 | 124292 | }else{ |
| 124421 | 124293 | k = i - nHidden; |
| 124422 | 124294 | } |
| 124423 | 124295 | |
| | @@ -124928,11 +124800,11 @@ |
| 124928 | 124800 | |
| 124929 | 124801 | isUpdate = regOldData!=0; |
| 124930 | 124802 | db = pParse->db; |
| 124931 | 124803 | v = pParse->pVdbe; |
| 124932 | 124804 | assert( v!=0 ); |
| 124933 | | - assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 124805 | + assert( !IsView(pTab) ); /* This table is not a VIEW */ |
| 124934 | 124806 | nCol = pTab->nCol; |
| 124935 | 124807 | |
| 124936 | 124808 | /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for |
| 124937 | 124809 | ** normal rowid tables. nPkField is the number of key fields in the |
| 124938 | 124810 | ** pPk index or 1 for a rowid table. In other words, nPkField is the |
| | @@ -124979,11 +124851,11 @@ |
| 124979 | 124851 | }else if( onError==OE_Default ){ |
| 124980 | 124852 | onError = OE_Abort; |
| 124981 | 124853 | } |
| 124982 | 124854 | if( onError==OE_Replace ){ |
| 124983 | 124855 | if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */ |
| 124984 | | - || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */ |
| 124856 | + || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */ |
| 124985 | 124857 | ){ |
| 124986 | 124858 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 124987 | 124859 | testcase( pCol->colFlags & COLFLAG_STORED ); |
| 124988 | 124860 | testcase( pCol->colFlags & COLFLAG_GENERATED ); |
| 124989 | 124861 | onError = OE_Abort; |
| | @@ -125001,21 +124873,22 @@ |
| 125001 | 124873 | case OE_Replace: { |
| 125002 | 124874 | int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg); |
| 125003 | 124875 | VdbeCoverage(v); |
| 125004 | 124876 | assert( (pCol->colFlags & COLFLAG_GENERATED)==0 ); |
| 125005 | 124877 | nSeenReplace++; |
| 125006 | | - sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg); |
| 124878 | + sqlite3ExprCodeCopy(pParse, |
| 124879 | + sqlite3ColumnExpr(pTab, pCol), iReg); |
| 125007 | 124880 | sqlite3VdbeJumpHere(v, addr1); |
| 125008 | 124881 | break; |
| 125009 | 124882 | } |
| 125010 | 124883 | case OE_Abort: |
| 125011 | 124884 | sqlite3MayAbort(pParse); |
| 125012 | 124885 | /* no break */ deliberate_fall_through |
| 125013 | 124886 | case OE_Rollback: |
| 125014 | 124887 | case OE_Fail: { |
| 125015 | 124888 | char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName, |
| 125016 | | - pCol->zName); |
| 124889 | + pCol->zCnName); |
| 125017 | 124890 | sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, |
| 125018 | 124891 | onError, iReg); |
| 125019 | 124892 | sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC); |
| 125020 | 124893 | sqlite3VdbeChangeP5(v, P5_ConstraintNotNull); |
| 125021 | 124894 | VdbeCoverage(v); |
| | @@ -125429,11 +125302,11 @@ |
| 125429 | 125302 | VdbeComment((v, "rowid")); |
| 125430 | 125303 | }else{ |
| 125431 | 125304 | testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField ); |
| 125432 | 125305 | x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1; |
| 125433 | 125306 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 125434 | | - VdbeComment((v, "%s", pTab->aCol[iField].zName)); |
| 125307 | + VdbeComment((v, "%s", pTab->aCol[iField].zCnName)); |
| 125435 | 125308 | } |
| 125436 | 125309 | } |
| 125437 | 125310 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]); |
| 125438 | 125311 | VdbeComment((v, "for %s", pIdx->zName)); |
| 125439 | 125312 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| | @@ -125488,11 +125361,11 @@ |
| 125488 | 125361 | && pPk==pIdx /* Condition 2 */ |
| 125489 | 125362 | && onError==OE_Replace /* Condition 1 */ |
| 125490 | 125363 | && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */ |
| 125491 | 125364 | 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0)) |
| 125492 | 125365 | && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */ |
| 125493 | | - (0==pTab->pFKey && 0==sqlite3FkReferences(pTab))) |
| 125366 | + (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab))) |
| 125494 | 125367 | ){ |
| 125495 | 125368 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| 125496 | 125369 | continue; |
| 125497 | 125370 | } |
| 125498 | 125371 | #endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */ |
| | @@ -125523,11 +125396,11 @@ |
| 125523 | 125396 | for(i=0; i<pPk->nKeyCol; i++){ |
| 125524 | 125397 | assert( pPk->aiColumn[i]>=0 ); |
| 125525 | 125398 | x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]); |
| 125526 | 125399 | sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); |
| 125527 | 125400 | VdbeComment((v, "%s.%s", pTab->zName, |
| 125528 | | - pTab->aCol[pPk->aiColumn[i]].zName)); |
| 125401 | + pTab->aCol[pPk->aiColumn[i]].zCnName)); |
| 125529 | 125402 | } |
| 125530 | 125403 | } |
| 125531 | 125404 | if( isUpdate ){ |
| 125532 | 125405 | /* If currently processing the PRIMARY KEY of a WITHOUT ROWID |
| 125533 | 125406 | ** table, only conflict if the new PRIMARY KEY values are actually |
| | @@ -125722,11 +125595,11 @@ |
| 125722 | 125595 | /* Records with omitted columns are only allowed for schema format |
| 125723 | 125596 | ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */ |
| 125724 | 125597 | if( pTab->pSchema->file_format<2 ) return; |
| 125725 | 125598 | |
| 125726 | 125599 | for(i=pTab->nCol-1; i>0; i--){ |
| 125727 | | - if( pTab->aCol[i].pDflt!=0 ) break; |
| 125600 | + if( pTab->aCol[i].iDflt!=0 ) break; |
| 125728 | 125601 | if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break; |
| 125729 | 125602 | } |
| 125730 | 125603 | sqlite3VdbeChangeP5(v, i+1); |
| 125731 | 125604 | } |
| 125732 | 125605 | #endif |
| | @@ -125787,11 +125660,11 @@ |
| 125787 | 125660 | || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION) |
| 125788 | 125661 | ); |
| 125789 | 125662 | |
| 125790 | 125663 | v = pParse->pVdbe; |
| 125791 | 125664 | assert( v!=0 ); |
| 125792 | | - assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 125665 | + assert( !IsView(pTab) ); /* This table is not a VIEW */ |
| 125793 | 125666 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 125794 | 125667 | /* All REPLACE indexes are at the end of the list */ |
| 125795 | 125668 | assert( pIdx->onError!=OE_Replace |
| 125796 | 125669 | || pIdx->pNext==0 |
| 125797 | 125670 | || pIdx->pNext->onError==OE_Replace ); |
| | @@ -126089,17 +125962,12 @@ |
| 126089 | 125962 | return 0; /* tab1 and tab2 may not be the same table */ |
| 126090 | 125963 | } |
| 126091 | 125964 | if( HasRowid(pDest)!=HasRowid(pSrc) ){ |
| 126092 | 125965 | return 0; /* source and destination must both be WITHOUT ROWID or not */ |
| 126093 | 125966 | } |
| 126094 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 126095 | | - if( IsVirtual(pSrc) ){ |
| 126096 | | - return 0; /* tab2 must not be a virtual table */ |
| 126097 | | - } |
| 126098 | | -#endif |
| 126099 | | - if( pSrc->pSelect ){ |
| 126100 | | - return 0; /* tab2 may not be a view */ |
| 125967 | + if( !IsOrdinaryTable(pSrc) ){ |
| 125968 | + return 0; /* tab2 may not be a view or virtual table */ |
| 126101 | 125969 | } |
| 126102 | 125970 | if( pDest->nCol!=pSrc->nCol ){ |
| 126103 | 125971 | return 0; /* Number of columns must be the same in tab1 and tab2 */ |
| 126104 | 125972 | } |
| 126105 | 125973 | if( pDest->iPKey!=pSrc->iPKey ){ |
| | @@ -126139,33 +126007,38 @@ |
| 126139 | 126007 | /* But the transfer is only allowed if both the source and destination |
| 126140 | 126008 | ** tables have the exact same expressions for generated columns. |
| 126141 | 126009 | ** This requirement could be relaxed for VIRTUAL columns, I suppose. |
| 126142 | 126010 | */ |
| 126143 | 126011 | if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){ |
| 126144 | | - if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){ |
| 126012 | + if( sqlite3ExprCompare(0, |
| 126013 | + sqlite3ColumnExpr(pSrc, pSrcCol), |
| 126014 | + sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){ |
| 126145 | 126015 | testcase( pDestCol->colFlags & COLFLAG_VIRTUAL ); |
| 126146 | 126016 | testcase( pDestCol->colFlags & COLFLAG_STORED ); |
| 126147 | 126017 | return 0; /* Different generator expressions */ |
| 126148 | 126018 | } |
| 126149 | 126019 | } |
| 126150 | 126020 | #endif |
| 126151 | 126021 | if( pDestCol->affinity!=pSrcCol->affinity ){ |
| 126152 | 126022 | return 0; /* Affinity must be the same on all columns */ |
| 126153 | 126023 | } |
| 126154 | | - if( sqlite3_stricmp(pDestCol->zColl, pSrcCol->zColl)!=0 ){ |
| 126024 | + if( sqlite3_stricmp(sqlite3ColumnColl(pDestCol), |
| 126025 | + sqlite3ColumnColl(pSrcCol))!=0 ){ |
| 126155 | 126026 | return 0; /* Collating sequence must be the same on all columns */ |
| 126156 | 126027 | } |
| 126157 | 126028 | if( pDestCol->notNull && !pSrcCol->notNull ){ |
| 126158 | 126029 | return 0; /* tab2 must be NOT NULL if tab1 is */ |
| 126159 | 126030 | } |
| 126160 | 126031 | /* Default values for second and subsequent columns need to match. */ |
| 126161 | 126032 | if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){ |
| 126162 | | - assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN ); |
| 126163 | | - assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN ); |
| 126164 | | - if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0) |
| 126165 | | - || (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken, |
| 126166 | | - pSrcCol->pDflt->u.zToken)!=0) |
| 126033 | + Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol); |
| 126034 | + Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol); |
| 126035 | + assert( pDestExpr==0 || pDestExpr->op==TK_SPAN ); |
| 126036 | + assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN ); |
| 126037 | + if( (pDestExpr==0)!=(pSrcExpr==0) |
| 126038 | + || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken, |
| 126039 | + pSrcExpr->u.zToken)!=0) |
| 126167 | 126040 | ){ |
| 126168 | 126041 | return 0; /* Default values must be the same for all columns */ |
| 126169 | 126042 | } |
| 126170 | 126043 | } |
| 126171 | 126044 | } |
| | @@ -126198,11 +126071,11 @@ |
| 126198 | 126071 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 126199 | 126072 | ** command, and the VACUUM command disables foreign key constraints. So |
| 126200 | 126073 | ** the extra complication to make this rule less restrictive is probably |
| 126201 | 126074 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 126202 | 126075 | */ |
| 126203 | | - if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 126076 | + if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){ |
| 126204 | 126077 | return 0; |
| 126205 | 126078 | } |
| 126206 | 126079 | #endif |
| 126207 | 126080 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 126208 | 126081 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| | @@ -129888,17 +129761,20 @@ |
| 129888 | 129761 | }else if( pPk==0 ){ |
| 129889 | 129762 | k = 1; |
| 129890 | 129763 | }else{ |
| 129891 | 129764 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 129892 | 129765 | } |
| 129893 | | - assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN || isHidden>=2 ); |
| 129766 | + assert( sqlite3ColumnExpr(pTab,pCol)==0 |
| 129767 | + || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN |
| 129768 | + || isHidden>=2 ); |
| 129894 | 129769 | sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", |
| 129895 | 129770 | i-nHidden, |
| 129896 | | - pCol->zName, |
| 129771 | + pCol->zCnName, |
| 129897 | 129772 | sqlite3ColumnType(pCol,""), |
| 129898 | 129773 | pCol->notNull ? 1 : 0, |
| 129899 | | - pCol->pDflt && isHidden<2 ? pCol->pDflt->u.zToken : 0, |
| 129774 | + isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 : |
| 129775 | + sqlite3ColumnExpr(pTab,pCol)->u.zToken, |
| 129900 | 129776 | k, |
| 129901 | 129777 | isHidden); |
| 129902 | 129778 | } |
| 129903 | 129779 | } |
| 129904 | 129780 | } |
| | @@ -129961,11 +129837,11 @@ |
| 129961 | 129837 | sqlite3CodeVerifySchema(pParse, iIdxDb); |
| 129962 | 129838 | assert( pParse->nMem<=pPragma->nPragCName ); |
| 129963 | 129839 | for(i=0; i<mx; i++){ |
| 129964 | 129840 | i16 cnum = pIdx->aiColumn[i]; |
| 129965 | 129841 | sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum, |
| 129966 | | - cnum<0 ? 0 : pTab->aCol[cnum].zName); |
| 129842 | + cnum<0 ? 0 : pTab->aCol[cnum].zCnName); |
| 129967 | 129843 | if( pPragma->iArg ){ |
| 129968 | 129844 | sqlite3VdbeMultiLoad(v, 4, "isiX", |
| 129969 | 129845 | pIdx->aSortOrder[i], |
| 129970 | 129846 | pIdx->azColl[i], |
| 129971 | 129847 | i<pIdx->nKeyCol); |
| | @@ -130068,12 +129944,12 @@ |
| 130068 | 129944 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 130069 | 129945 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
| 130070 | 129946 | FKey *pFK; |
| 130071 | 129947 | Table *pTab; |
| 130072 | 129948 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 130073 | | - if( pTab ){ |
| 130074 | | - pFK = pTab->pFKey; |
| 129949 | + if( pTab && !IsVirtual(pTab) ){ |
| 129950 | + pFK = pTab->u.tab.pFKey; |
| 130075 | 129951 | if( pFK ){ |
| 130076 | 129952 | int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 130077 | 129953 | int i = 0; |
| 130078 | 129954 | pParse->nMem = 8; |
| 130079 | 129955 | sqlite3CodeVerifySchema(pParse, iTabDb); |
| | @@ -130082,11 +129958,11 @@ |
| 130082 | 129958 | for(j=0; j<pFK->nCol; j++){ |
| 130083 | 129959 | sqlite3VdbeMultiLoad(v, 1, "iissssss", |
| 130084 | 129960 | i, |
| 130085 | 129961 | j, |
| 130086 | 129962 | pFK->zTo, |
| 130087 | | - pTab->aCol[pFK->aCol[j].iFrom].zName, |
| 129963 | + pTab->aCol[pFK->aCol[j].iFrom].zCnName, |
| 130088 | 129964 | pFK->aCol[j].zCol, |
| 130089 | 129965 | actionName(pFK->aAction[1]), /* ON UPDATE */ |
| 130090 | 129966 | actionName(pFK->aAction[0]), /* ON DELETE */ |
| 130091 | 129967 | "NONE"); |
| 130092 | 129968 | } |
| | @@ -130128,19 +130004,20 @@ |
| 130128 | 130004 | k = 0; |
| 130129 | 130005 | }else{ |
| 130130 | 130006 | pTab = (Table*)sqliteHashData(k); |
| 130131 | 130007 | k = sqliteHashNext(k); |
| 130132 | 130008 | } |
| 130133 | | - if( pTab==0 || pTab->pFKey==0 ) continue; |
| 130009 | + if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue; |
| 130134 | 130010 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 130135 | 130011 | zDb = db->aDb[iDb].zDbSName; |
| 130136 | 130012 | sqlite3CodeVerifySchema(pParse, iDb); |
| 130137 | 130013 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 130138 | 130014 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
| 130139 | 130015 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
| 130140 | 130016 | sqlite3VdbeLoadString(v, regResult, pTab->zName); |
| 130141 | | - for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130017 | + assert( !IsVirtual(pTab) ); |
| 130018 | + for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130142 | 130019 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 130143 | 130020 | if( pParent==0 ) continue; |
| 130144 | 130021 | pIdx = 0; |
| 130145 | 130022 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
| 130146 | 130023 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); |
| | @@ -130158,11 +130035,12 @@ |
| 130158 | 130035 | } |
| 130159 | 130036 | assert( pParse->nErr>0 || pFK==0 ); |
| 130160 | 130037 | if( pFK ) break; |
| 130161 | 130038 | if( pParse->nTab<i ) pParse->nTab = i; |
| 130162 | 130039 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
| 130163 | | - for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130040 | + assert( !IsVirtual(pTab) ); |
| 130041 | + for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130164 | 130042 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 130165 | 130043 | pIdx = 0; |
| 130166 | 130044 | aiCols = 0; |
| 130167 | 130045 | if( pParent ){ |
| 130168 | 130046 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
| | @@ -130393,11 +130271,11 @@ |
| 130393 | 130271 | if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){ |
| 130394 | 130272 | sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 130395 | 130273 | } |
| 130396 | 130274 | jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 130397 | 130275 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 130398 | | - pTab->aCol[j].zName); |
| 130276 | + pTab->aCol[j].zCnName); |
| 130399 | 130277 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 130400 | 130278 | integrityCheckResultRow(v); |
| 130401 | 130279 | sqlite3VdbeJumpHere(v, jmp2); |
| 130402 | 130280 | } |
| 130403 | 130281 | /* Verify CHECK constraints */ |
| | @@ -132601,11 +132479,11 @@ |
| 132601 | 132479 | SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){ |
| 132602 | 132480 | int i; |
| 132603 | 132481 | u8 h = sqlite3StrIHash(zCol); |
| 132604 | 132482 | Column *pCol; |
| 132605 | 132483 | for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){ |
| 132606 | | - if( pCol->hName==h && sqlite3StrICmp(pCol->zName, zCol)==0 ) return i; |
| 132484 | + if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i; |
| 132607 | 132485 | } |
| 132608 | 132486 | return -1; |
| 132609 | 132487 | } |
| 132610 | 132488 | |
| 132611 | 132489 | /* |
| | @@ -132800,11 +132678,11 @@ |
| 132800 | 132678 | char *zName; /* Name of column in the right table */ |
| 132801 | 132679 | int iLeft; /* Matching left table */ |
| 132802 | 132680 | int iLeftCol; /* Matching column in the left table */ |
| 132803 | 132681 | |
| 132804 | 132682 | if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue; |
| 132805 | | - zName = pRightTab->aCol[j].zName; |
| 132683 | + zName = pRightTab->aCol[j].zCnName; |
| 132806 | 132684 | if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){ |
| 132807 | 132685 | addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j, |
| 132808 | 132686 | isOuter, &p->pWhere); |
| 132809 | 132687 | } |
| 132810 | 132688 | } |
| | @@ -133203,11 +133081,13 @@ |
| 133203 | 133081 | Parse *pParse, /* Parsing and code generating context */ |
| 133204 | 133082 | int eTnctType, /* WHERE_DISTINCT_* value */ |
| 133205 | 133083 | int iVal, /* Value returned by codeDistinct() */ |
| 133206 | 133084 | int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */ |
| 133207 | 133085 | ){ |
| 133208 | | - if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){ |
| 133086 | + if( pParse->nErr==0 |
| 133087 | + && (eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED) |
| 133088 | + ){ |
| 133209 | 133089 | Vdbe *v = pParse->pVdbe; |
| 133210 | 133090 | sqlite3VdbeChangeToNoop(v, iOpenEphAddr); |
| 133211 | 133091 | if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){ |
| 133212 | 133092 | sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1); |
| 133213 | 133093 | } |
| | @@ -134165,11 +134045,11 @@ |
| 134165 | 134045 | assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) ); |
| 134166 | 134046 | if( iCol<0 ){ |
| 134167 | 134047 | zType = "INTEGER"; |
| 134168 | 134048 | zOrigCol = "rowid"; |
| 134169 | 134049 | }else{ |
| 134170 | | - zOrigCol = pTab->aCol[iCol].zName; |
| 134050 | + zOrigCol = pTab->aCol[iCol].zCnName; |
| 134171 | 134051 | zType = sqlite3ColumnType(&pTab->aCol[iCol],0); |
| 134172 | 134052 | } |
| 134173 | 134053 | zOrigTab = pTab->zName; |
| 134174 | 134054 | if( pNC->pParse && pTab->pSchema ){ |
| 134175 | 134055 | int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema); |
| | @@ -134337,11 +134217,11 @@ |
| 134337 | 134217 | if( iCol<0 ) iCol = pTab->iPKey; |
| 134338 | 134218 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); |
| 134339 | 134219 | if( iCol<0 ){ |
| 134340 | 134220 | zCol = "rowid"; |
| 134341 | 134221 | }else{ |
| 134342 | | - zCol = pTab->aCol[iCol].zName; |
| 134222 | + zCol = pTab->aCol[iCol].zCnName; |
| 134343 | 134223 | } |
| 134344 | 134224 | if( fullName ){ |
| 134345 | 134225 | char *zName = 0; |
| 134346 | 134226 | zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol); |
| 134347 | 134227 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC); |
| | @@ -134422,11 +134302,11 @@ |
| 134422 | 134302 | } |
| 134423 | 134303 | if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){ |
| 134424 | 134304 | /* For columns use the column name name */ |
| 134425 | 134305 | int iCol = pColExpr->iColumn; |
| 134426 | 134306 | if( iCol<0 ) iCol = pTab->iPKey; |
| 134427 | | - zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid"; |
| 134307 | + zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid"; |
| 134428 | 134308 | }else if( pColExpr->op==TK_ID ){ |
| 134429 | 134309 | assert( !ExprHasProperty(pColExpr, EP_IntValue) ); |
| 134430 | 134310 | zName = pColExpr->u.zToken; |
| 134431 | 134311 | }else{ |
| 134432 | 134312 | /* Use the original text of the column expression as its name */ |
| | @@ -134450,21 +134330,21 @@ |
| 134450 | 134330 | if( zName[j]==':' ) nName = j; |
| 134451 | 134331 | } |
| 134452 | 134332 | zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); |
| 134453 | 134333 | if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); |
| 134454 | 134334 | } |
| 134455 | | - pCol->zName = zName; |
| 134335 | + pCol->zCnName = zName; |
| 134456 | 134336 | pCol->hName = sqlite3StrIHash(zName); |
| 134457 | 134337 | sqlite3ColumnPropertiesFromName(0, pCol); |
| 134458 | 134338 | if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ |
| 134459 | 134339 | sqlite3OomFault(db); |
| 134460 | 134340 | } |
| 134461 | 134341 | } |
| 134462 | 134342 | sqlite3HashClear(&ht); |
| 134463 | 134343 | if( db->mallocFailed ){ |
| 134464 | 134344 | for(j=0; j<i; j++){ |
| 134465 | | - sqlite3DbFree(db, aCol[j].zName); |
| 134345 | + sqlite3DbFree(db, aCol[j].zCnName); |
| 134466 | 134346 | } |
| 134467 | 134347 | sqlite3DbFree(db, aCol); |
| 134468 | 134348 | *paCol = 0; |
| 134469 | 134349 | *pnCol = 0; |
| 134470 | 134350 | return SQLITE_NOMEM_BKPT; |
| | @@ -134512,21 +134392,22 @@ |
| 134512 | 134392 | zType = columnType(&sNC, p, 0, 0, 0); |
| 134513 | 134393 | /* pCol->szEst = ... // Column size est for SELECT tables never used */ |
| 134514 | 134394 | pCol->affinity = sqlite3ExprAffinity(p); |
| 134515 | 134395 | if( zType ){ |
| 134516 | 134396 | m = sqlite3Strlen30(zType); |
| 134517 | | - n = sqlite3Strlen30(pCol->zName); |
| 134518 | | - pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2); |
| 134519 | | - if( pCol->zName ){ |
| 134520 | | - memcpy(&pCol->zName[n+1], zType, m+1); |
| 134397 | + n = sqlite3Strlen30(pCol->zCnName); |
| 134398 | + pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); |
| 134399 | + if( pCol->zCnName ){ |
| 134400 | + memcpy(&pCol->zCnName[n+1], zType, m+1); |
| 134521 | 134401 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 134522 | 134402 | } |
| 134523 | 134403 | } |
| 134524 | 134404 | if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff; |
| 134525 | 134405 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 134526 | | - if( pColl && pCol->zColl==0 ){ |
| 134527 | | - pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 134406 | + if( pColl && (pCol->colFlags & COLFLAG_HASCOLL)==0 ){ |
| 134407 | + assert( pTab->pIndex==0 ); |
| 134408 | + sqlite3ColumnSetColl(db, pCol, pColl->zName); |
| 134528 | 134409 | } |
| 134529 | 134410 | } |
| 134530 | 134411 | pTab->szTabRow = 1; /* Any non-zero value works */ |
| 134531 | 134412 | } |
| 134532 | 134413 | |
| | @@ -137261,11 +137142,11 @@ |
| 137261 | 137142 | ){ |
| 137262 | 137143 | return 0; |
| 137263 | 137144 | } |
| 137264 | 137145 | pTab = p->pSrc->a[0].pTab; |
| 137265 | 137146 | pExpr = p->pEList->a[0].pExpr; |
| 137266 | | - assert( pTab && !pTab->pSelect && pExpr ); |
| 137147 | + assert( pTab && !IsView(pTab) && pExpr ); |
| 137267 | 137148 | |
| 137268 | 137149 | if( IsVirtual(pTab) ) return 0; |
| 137269 | 137150 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; |
| 137270 | 137151 | if( NEVER(pAggInfo->nFunc==0) ) return 0; |
| 137271 | 137152 | if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0; |
| | @@ -137806,34 +137687,35 @@ |
| 137806 | 137687 | pTab->nTabRef++; |
| 137807 | 137688 | if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){ |
| 137808 | 137689 | return WRC_Abort; |
| 137809 | 137690 | } |
| 137810 | 137691 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 137811 | | - if( IsVirtual(pTab) || pTab->pSelect ){ |
| 137692 | + if( !IsOrdinaryTable(pTab) ){ |
| 137812 | 137693 | i16 nCol; |
| 137813 | 137694 | u8 eCodeOrig = pWalker->eCode; |
| 137814 | 137695 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 137815 | 137696 | assert( pFrom->pSelect==0 ); |
| 137816 | | - if( pTab->pSelect |
| 137817 | | - && (db->flags & SQLITE_EnableView)==0 |
| 137818 | | - && pTab->pSchema!=db->aDb[1].pSchema |
| 137819 | | - ){ |
| 137820 | | - sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 137821 | | - pTab->zName); |
| 137822 | | - } |
| 137697 | + if( IsView(pTab) ){ |
| 137698 | + if( (db->flags & SQLITE_EnableView)==0 |
| 137699 | + && pTab->pSchema!=db->aDb[1].pSchema |
| 137700 | + ){ |
| 137701 | + sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 137702 | + pTab->zName); |
| 137703 | + } |
| 137704 | + pFrom->pSelect = sqlite3SelectDup(db, pTab->u.view.pSelect, 0); |
| 137705 | + }else |
| 137823 | 137706 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 137824 | | - assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 ); |
| 137825 | | - if( IsVirtual(pTab) |
| 137707 | + if( ALWAYS(IsVirtual(pTab)) |
| 137826 | 137708 | && pFrom->fg.fromDDL |
| 137827 | | - && ALWAYS(pTab->pVTable!=0) |
| 137828 | | - && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 137709 | + && ALWAYS(pTab->u.vtab.p!=0) |
| 137710 | + && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 137829 | 137711 | ){ |
| 137830 | 137712 | sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"", |
| 137831 | 137713 | pTab->zName); |
| 137832 | 137714 | } |
| 137715 | + assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 ); |
| 137833 | 137716 | #endif |
| 137834 | | - pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); |
| 137835 | 137717 | nCol = pTab->nCol; |
| 137836 | 137718 | pTab->nCol = -1; |
| 137837 | 137719 | pWalker->eCode = 1; /* Turn on Select.selId renumbering */ |
| 137838 | 137720 | sqlite3WalkSelect(pWalker, pFrom->pSelect); |
| 137839 | 137721 | pWalker->eCode = eCodeOrig; |
| | @@ -137929,11 +137811,11 @@ |
| 137929 | 137811 | } |
| 137930 | 137812 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 137931 | 137813 | zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*"; |
| 137932 | 137814 | } |
| 137933 | 137815 | for(j=0; j<pTab->nCol; j++){ |
| 137934 | | - char *zName = pTab->aCol[j].zName; |
| 137816 | + char *zName = pTab->aCol[j].zCnName; |
| 137935 | 137817 | char *zColname; /* The computed column name */ |
| 137936 | 137818 | char *zToFree; /* Malloced string that needs to be freed */ |
| 137937 | 137819 | Token sColname; /* Computed column name as a token */ |
| 137938 | 137820 | |
| 137939 | 137821 | assert( zName ); |
| | @@ -140214,16 +140096,16 @@ |
| 140214 | 140096 | } |
| 140215 | 140097 | |
| 140216 | 140098 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 140217 | 140099 | ** of triggers. |
| 140218 | 140100 | */ |
| 140219 | | - if( pTab->pSelect && tr_tm!=TK_INSTEAD ){ |
| 140101 | + if( IsView(pTab) && tr_tm!=TK_INSTEAD ){ |
| 140220 | 140102 | sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S", |
| 140221 | 140103 | (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a); |
| 140222 | 140104 | goto trigger_orphan_error; |
| 140223 | 140105 | } |
| 140224 | | - if( !pTab->pSelect && tr_tm==TK_INSTEAD ){ |
| 140106 | + if( !IsView(pTab) && tr_tm==TK_INSTEAD ){ |
| 140225 | 140107 | sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF" |
| 140226 | 140108 | " trigger on table: %S", pTableName->a); |
| 140227 | 140109 | goto trigger_orphan_error; |
| 140228 | 140110 | } |
| 140229 | 140111 | |
| | @@ -140872,15 +140754,15 @@ |
| 140872 | 140754 | if( isAsteriskTerm(pParse, pOldExpr) ){ |
| 140873 | 140755 | int jj; |
| 140874 | 140756 | for(jj=0; jj<pTab->nCol; jj++){ |
| 140875 | 140757 | Expr *pNewExpr; |
| 140876 | 140758 | if( IsHiddenColumn(pTab->aCol+jj) ) continue; |
| 140877 | | - pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zName); |
| 140759 | + pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName); |
| 140878 | 140760 | pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr); |
| 140879 | 140761 | if( !db->mallocFailed ){ |
| 140880 | 140762 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 140881 | | - pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zName); |
| 140763 | + pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName); |
| 140882 | 140764 | pItem->eEName = ENAME_NAME; |
| 140883 | 140765 | } |
| 140884 | 140766 | } |
| 140885 | 140767 | }else{ |
| 140886 | 140768 | Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0); |
| | @@ -141477,17 +141359,18 @@ |
| 141477 | 141359 | ** integer. In that case, add an OP_RealAffinity opcode to make sure |
| 141478 | 141360 | ** it has been converted into REAL. |
| 141479 | 141361 | */ |
| 141480 | 141362 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ |
| 141481 | 141363 | assert( pTab!=0 ); |
| 141482 | | - if( !pTab->pSelect ){ |
| 141364 | + if( !IsView(pTab) ){ |
| 141483 | 141365 | sqlite3_value *pValue = 0; |
| 141484 | 141366 | u8 enc = ENC(sqlite3VdbeDb(v)); |
| 141485 | 141367 | Column *pCol = &pTab->aCol[i]; |
| 141486 | | - VdbeComment((v, "%s.%s", pTab->zName, pCol->zName)); |
| 141368 | + VdbeComment((v, "%s.%s", pTab->zName, pCol->zCnName)); |
| 141487 | 141369 | assert( i<pTab->nCol ); |
| 141488 | | - sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, |
| 141370 | + sqlite3ValueFromExpr(sqlite3VdbeDb(v), |
| 141371 | + sqlite3ColumnExpr(pTab,pCol), enc, |
| 141489 | 141372 | pCol->affinity, &pValue); |
| 141490 | 141373 | if( pValue ){ |
| 141491 | 141374 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 141492 | 141375 | } |
| 141493 | 141376 | } |
| | @@ -141653,11 +141536,11 @@ |
| 141653 | 141536 | } |
| 141654 | 141537 | #endif |
| 141655 | 141538 | pList = sqlite3ExprListAppend(pParse, pList, pNew); |
| 141656 | 141539 | } |
| 141657 | 141540 | eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom; |
| 141658 | | - }else if( pTab->pSelect ){ |
| 141541 | + }else if( IsView(pTab) ){ |
| 141659 | 141542 | for(i=0; i<pTab->nCol; i++){ |
| 141660 | 141543 | pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i)); |
| 141661 | 141544 | } |
| 141662 | 141545 | eDest = SRT_Table; |
| 141663 | 141546 | }else{ |
| | @@ -141778,11 +141661,11 @@ |
| 141778 | 141661 | /* Figure out if we have any triggers and if the table being |
| 141779 | 141662 | ** updated is a view. |
| 141780 | 141663 | */ |
| 141781 | 141664 | #ifndef SQLITE_OMIT_TRIGGER |
| 141782 | 141665 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask); |
| 141783 | | - isView = pTab->pSelect!=0; |
| 141666 | + isView = IsView(pTab); |
| 141784 | 141667 | assert( pTrigger || tmask==0 ); |
| 141785 | 141668 | #else |
| 141786 | 141669 | # define pTrigger 0 |
| 141787 | 141670 | # define isView 0 |
| 141788 | 141671 | # define tmask 0 |
| | @@ -141867,17 +141750,20 @@ |
| 141867 | 141750 | ** column to be updated, make sure we have authorization to change |
| 141868 | 141751 | ** that column. |
| 141869 | 141752 | */ |
| 141870 | 141753 | chngRowid = chngPk = 0; |
| 141871 | 141754 | for(i=0; i<pChanges->nExpr; i++){ |
| 141755 | + u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName); |
| 141872 | 141756 | /* If this is an UPDATE with a FROM clause, do not resolve expressions |
| 141873 | 141757 | ** here. The call to sqlite3Select() below will do that. */ |
| 141874 | 141758 | if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){ |
| 141875 | 141759 | goto update_cleanup; |
| 141876 | 141760 | } |
| 141877 | 141761 | for(j=0; j<pTab->nCol; j++){ |
| 141878 | | - if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){ |
| 141762 | + if( pTab->aCol[j].hName==hCol |
| 141763 | + && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0 |
| 141764 | + ){ |
| 141879 | 141765 | if( j==pTab->iPKey ){ |
| 141880 | 141766 | chngRowid = 1; |
| 141881 | 141767 | pRowidExpr = pChanges->a[i].pExpr; |
| 141882 | 141768 | iRowidExpr = i; |
| 141883 | 141769 | }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){ |
| | @@ -141887,11 +141773,11 @@ |
| 141887 | 141773 | else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){ |
| 141888 | 141774 | testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ); |
| 141889 | 141775 | testcase( pTab->aCol[j].colFlags & COLFLAG_STORED ); |
| 141890 | 141776 | sqlite3ErrorMsg(pParse, |
| 141891 | 141777 | "cannot UPDATE generated column \"%s\"", |
| 141892 | | - pTab->aCol[j].zName); |
| 141778 | + pTab->aCol[j].zCnName); |
| 141893 | 141779 | goto update_cleanup; |
| 141894 | 141780 | } |
| 141895 | 141781 | #endif |
| 141896 | 141782 | aXRef[j] = i; |
| 141897 | 141783 | break; |
| | @@ -141911,11 +141797,11 @@ |
| 141911 | 141797 | } |
| 141912 | 141798 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 141913 | 141799 | { |
| 141914 | 141800 | int rc; |
| 141915 | 141801 | rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName, |
| 141916 | | - j<0 ? "ROWID" : pTab->aCol[j].zName, |
| 141802 | + j<0 ? "ROWID" : pTab->aCol[j].zCnName, |
| 141917 | 141803 | db->aDb[iDb].zDbSName); |
| 141918 | 141804 | if( rc==SQLITE_DENY ){ |
| 141919 | 141805 | goto update_cleanup; |
| 141920 | 141806 | }else if( rc==SQLITE_IGNORE ){ |
| 141921 | 141807 | aXRef[j] = -1; |
| | @@ -141943,12 +141829,14 @@ |
| 141943 | 141829 | do{ |
| 141944 | 141830 | bProgress = 0; |
| 141945 | 141831 | for(i=0; i<pTab->nCol; i++){ |
| 141946 | 141832 | if( aXRef[i]>=0 ) continue; |
| 141947 | 141833 | if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue; |
| 141948 | | - if( sqlite3ExprReferencesUpdatedColumn(pTab->aCol[i].pDflt, |
| 141949 | | - aXRef, chngRowid) ){ |
| 141834 | + if( sqlite3ExprReferencesUpdatedColumn( |
| 141835 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 141836 | + aXRef, chngRowid) |
| 141837 | + ){ |
| 141950 | 141838 | aXRef[i] = 99999; |
| 141951 | 141839 | bProgress = 1; |
| 141952 | 141840 | } |
| 141953 | 141841 | } |
| 141954 | 141842 | }while( bProgress ); |
| | @@ -143036,11 +142924,11 @@ |
| 143036 | 142924 | int k; |
| 143037 | 142925 | assert( pPk->aiColumn[i]>=0 ); |
| 143038 | 142926 | k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]); |
| 143039 | 142927 | sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i); |
| 143040 | 142928 | VdbeComment((v, "%s.%s", pIdx->zName, |
| 143041 | | - pTab->aCol[pPk->aiColumn[i]].zName)); |
| 142929 | + pTab->aCol[pPk->aiColumn[i]].zCnName)); |
| 143042 | 142930 | } |
| 143043 | 142931 | sqlite3VdbeVerifyAbortable(v, OE_Abort); |
| 143044 | 142932 | i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk); |
| 143045 | 142933 | VdbeCoverage(v); |
| 143046 | 142934 | sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0, |
| | @@ -143666,11 +143554,11 @@ |
| 143666 | 143554 | ** this virtual-table, if one has been created, or NULL otherwise. |
| 143667 | 143555 | */ |
| 143668 | 143556 | SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){ |
| 143669 | 143557 | VTable *pVtab; |
| 143670 | 143558 | assert( IsVirtual(pTab) ); |
| 143671 | | - for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext); |
| 143559 | + for(pVtab=pTab->u.vtab.p; pVtab && pVtab->db!=db; pVtab=pVtab->pNext); |
| 143672 | 143560 | return pVtab; |
| 143673 | 143561 | } |
| 143674 | 143562 | |
| 143675 | 143563 | /* |
| 143676 | 143564 | ** Decrement the ref-count on a virtual table object. When the ref-count |
| | @@ -143694,35 +143582,35 @@ |
| 143694 | 143582 | } |
| 143695 | 143583 | } |
| 143696 | 143584 | |
| 143697 | 143585 | /* |
| 143698 | 143586 | ** Table p is a virtual table. This function moves all elements in the |
| 143699 | | -** p->pVTable list to the sqlite3.pDisconnect lists of their associated |
| 143587 | +** p->u.vtab.p list to the sqlite3.pDisconnect lists of their associated |
| 143700 | 143588 | ** database connections to be disconnected at the next opportunity. |
| 143701 | 143589 | ** Except, if argument db is not NULL, then the entry associated with |
| 143702 | | -** connection db is left in the p->pVTable list. |
| 143590 | +** connection db is left in the p->u.vtab.p list. |
| 143703 | 143591 | */ |
| 143704 | 143592 | static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){ |
| 143705 | 143593 | VTable *pRet = 0; |
| 143706 | | - VTable *pVTable = p->pVTable; |
| 143707 | | - p->pVTable = 0; |
| 143594 | + VTable *pVTable = p->u.vtab.p; |
| 143595 | + p->u.vtab.p = 0; |
| 143708 | 143596 | |
| 143709 | 143597 | /* Assert that the mutex (if any) associated with the BtShared database |
| 143710 | 143598 | ** that contains table p is held by the caller. See header comments |
| 143711 | 143599 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| 143712 | 143600 | ** this makes it safe to access the sqlite3.pDisconnect list of any |
| 143713 | | - ** database connection that may have an entry in the p->pVTable list. |
| 143601 | + ** database connection that may have an entry in the p->u.vtab.p list. |
| 143714 | 143602 | */ |
| 143715 | 143603 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) ); |
| 143716 | 143604 | |
| 143717 | 143605 | while( pVTable ){ |
| 143718 | 143606 | sqlite3 *db2 = pVTable->db; |
| 143719 | 143607 | VTable *pNext = pVTable->pNext; |
| 143720 | 143608 | assert( db2 ); |
| 143721 | 143609 | if( db2==db ){ |
| 143722 | 143610 | pRet = pVTable; |
| 143723 | | - p->pVTable = pRet; |
| 143611 | + p->u.vtab.p = pRet; |
| 143724 | 143612 | pRet->pNext = 0; |
| 143725 | 143613 | }else{ |
| 143726 | 143614 | pVTable->pNext = db2->pDisconnect; |
| 143727 | 143615 | db2->pDisconnect = pVTable; |
| 143728 | 143616 | } |
| | @@ -143746,11 +143634,11 @@ |
| 143746 | 143634 | |
| 143747 | 143635 | assert( IsVirtual(p) ); |
| 143748 | 143636 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 143749 | 143637 | assert( sqlite3_mutex_held(db->mutex) ); |
| 143750 | 143638 | |
| 143751 | | - for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){ |
| 143639 | + for(ppVTab=&p->u.vtab.p; *ppVTab; ppVTab=&(*ppVTab)->pNext){ |
| 143752 | 143640 | if( (*ppVTab)->db==db ){ |
| 143753 | 143641 | VTable *pVTab = *ppVTab; |
| 143754 | 143642 | *ppVTab = pVTab->pNext; |
| 143755 | 143643 | sqlite3VtabUnlock(pVTab); |
| 143756 | 143644 | break; |
| | @@ -143810,40 +143698,40 @@ |
| 143810 | 143698 | ** in the list are moved to the sqlite3.pDisconnect list of the associated |
| 143811 | 143699 | ** database connection. |
| 143812 | 143700 | */ |
| 143813 | 143701 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){ |
| 143814 | 143702 | if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); |
| 143815 | | - if( p->azModuleArg ){ |
| 143703 | + if( p->u.vtab.azArg ){ |
| 143816 | 143704 | int i; |
| 143817 | | - for(i=0; i<p->nModuleArg; i++){ |
| 143818 | | - if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]); |
| 143705 | + for(i=0; i<p->u.vtab.nArg; i++){ |
| 143706 | + if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]); |
| 143819 | 143707 | } |
| 143820 | | - sqlite3DbFree(db, p->azModuleArg); |
| 143708 | + sqlite3DbFree(db, p->u.vtab.azArg); |
| 143821 | 143709 | } |
| 143822 | 143710 | } |
| 143823 | 143711 | |
| 143824 | 143712 | /* |
| 143825 | | -** Add a new module argument to pTable->azModuleArg[]. |
| 143713 | +** Add a new module argument to pTable->u.vtab.azArg[]. |
| 143826 | 143714 | ** The string is not copied - the pointer is stored. The |
| 143827 | 143715 | ** string will be freed automatically when the table is |
| 143828 | 143716 | ** deleted. |
| 143829 | 143717 | */ |
| 143830 | 143718 | static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ |
| 143831 | | - sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg); |
| 143719 | + sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); |
| 143832 | 143720 | char **azModuleArg; |
| 143833 | 143721 | sqlite3 *db = pParse->db; |
| 143834 | | - if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 143722 | + if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 143835 | 143723 | sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); |
| 143836 | 143724 | } |
| 143837 | | - azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes); |
| 143725 | + azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes); |
| 143838 | 143726 | if( azModuleArg==0 ){ |
| 143839 | 143727 | sqlite3DbFree(db, zArg); |
| 143840 | 143728 | }else{ |
| 143841 | | - int i = pTable->nModuleArg++; |
| 143729 | + int i = pTable->u.vtab.nArg++; |
| 143842 | 143730 | azModuleArg[i] = zArg; |
| 143843 | 143731 | azModuleArg[i+1] = 0; |
| 143844 | | - pTable->azModuleArg = azModuleArg; |
| 143732 | + pTable->u.vtab.azArg = azModuleArg; |
| 143845 | 143733 | } |
| 143846 | 143734 | } |
| 143847 | 143735 | |
| 143848 | 143736 | /* |
| 143849 | 143737 | ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE |
| | @@ -143862,14 +143750,15 @@ |
| 143862 | 143750 | |
| 143863 | 143751 | sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists); |
| 143864 | 143752 | pTable = pParse->pNewTable; |
| 143865 | 143753 | if( pTable==0 ) return; |
| 143866 | 143754 | assert( 0==pTable->pIndex ); |
| 143755 | + pTable->eTabType = TABTYP_VTAB; |
| 143867 | 143756 | |
| 143868 | 143757 | db = pParse->db; |
| 143869 | 143758 | |
| 143870 | | - assert( pTable->nModuleArg==0 ); |
| 143759 | + assert( pTable->u.vtab.nArg==0 ); |
| 143871 | 143760 | addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName)); |
| 143872 | 143761 | addModuleArgument(pParse, pTable, 0); |
| 143873 | 143762 | addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName)); |
| 143874 | 143763 | assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0) |
| 143875 | 143764 | || (pParse->sNameToken.z==pName1->z && pName2->z==0) |
| | @@ -143882,15 +143771,15 @@ |
| 143882 | 143771 | /* Creating a virtual table invokes the authorization callback twice. |
| 143883 | 143772 | ** The first invocation, to obtain permission to INSERT a row into the |
| 143884 | 143773 | ** sqlite_schema table, has already been made by sqlite3StartTable(). |
| 143885 | 143774 | ** The second call, to obtain permission to create the table, is made now. |
| 143886 | 143775 | */ |
| 143887 | | - if( pTable->azModuleArg ){ |
| 143776 | + if( pTable->u.vtab.azArg ){ |
| 143888 | 143777 | int iDb = sqlite3SchemaToIndex(db, pTable->pSchema); |
| 143889 | 143778 | assert( iDb>=0 ); /* The database the table is being created in */ |
| 143890 | 143779 | sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName, |
| 143891 | | - pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName); |
| 143780 | + pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName); |
| 143892 | 143781 | } |
| 143893 | 143782 | #endif |
| 143894 | 143783 | } |
| 143895 | 143784 | |
| 143896 | 143785 | /* |
| | @@ -143916,11 +143805,11 @@ |
| 143916 | 143805 | sqlite3 *db = pParse->db; /* The database connection */ |
| 143917 | 143806 | |
| 143918 | 143807 | if( pTab==0 ) return; |
| 143919 | 143808 | addArgumentToVtab(pParse); |
| 143920 | 143809 | pParse->sArg.z = 0; |
| 143921 | | - if( pTab->nModuleArg<1 ) return; |
| 143810 | + if( pTab->u.vtab.nArg<1 ) return; |
| 143922 | 143811 | |
| 143923 | 143812 | /* If the CREATE VIRTUAL TABLE statement is being entered for the |
| 143924 | 143813 | ** first time (in other words if the virtual table is actually being |
| 143925 | 143814 | ** created now instead of just being read out of sqlite_schema) then |
| 143926 | 143815 | ** do additional initialization work and store the statement text |
| | @@ -144031,12 +143920,12 @@ |
| 144031 | 143920 | char **pzErr |
| 144032 | 143921 | ){ |
| 144033 | 143922 | VtabCtx sCtx; |
| 144034 | 143923 | VTable *pVTable; |
| 144035 | 143924 | int rc; |
| 144036 | | - const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 144037 | | - int nArg = pTab->nModuleArg; |
| 143925 | + const char *const*azArg = (const char *const*)pTab->u.vtab.azArg; |
| 143926 | + int nArg = pTab->u.vtab.nArg; |
| 144038 | 143927 | char *zErr = 0; |
| 144039 | 143928 | char *zModuleName; |
| 144040 | 143929 | int iDb; |
| 144041 | 143930 | VtabCtx *pCtx; |
| 144042 | 143931 | |
| | @@ -144064,11 +143953,11 @@ |
| 144064 | 143953 | pVTable->db = db; |
| 144065 | 143954 | pVTable->pMod = pMod; |
| 144066 | 143955 | pVTable->eVtabRisk = SQLITE_VTABRISK_Normal; |
| 144067 | 143956 | |
| 144068 | 143957 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 144069 | | - pTab->azModuleArg[1] = db->aDb[iDb].zDbSName; |
| 143958 | + pTab->u.vtab.azArg[1] = db->aDb[iDb].zDbSName; |
| 144070 | 143959 | |
| 144071 | 143960 | /* Invoke the virtual table constructor */ |
| 144072 | 143961 | assert( &db->pVtabCtx ); |
| 144073 | 143962 | assert( xConstruct ); |
| 144074 | 143963 | sCtx.pTab = pTab; |
| | @@ -144103,16 +143992,16 @@ |
| 144103 | 143992 | rc = SQLITE_ERROR; |
| 144104 | 143993 | }else{ |
| 144105 | 143994 | int iCol; |
| 144106 | 143995 | u16 oooHidden = 0; |
| 144107 | 143996 | /* If everything went according to plan, link the new VTable structure |
| 144108 | | - ** into the linked list headed by pTab->pVTable. Then loop through the |
| 143997 | + ** into the linked list headed by pTab->u.vtab.p. Then loop through the |
| 144109 | 143998 | ** columns of the table to see if any of them contain the token "hidden". |
| 144110 | 143999 | ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from |
| 144111 | 144000 | ** the type string. */ |
| 144112 | | - pVTable->pNext = pTab->pVTable; |
| 144113 | | - pTab->pVTable = pVTable; |
| 144001 | + pVTable->pNext = pTab->u.vtab.p; |
| 144002 | + pTab->u.vtab.p = pVTable; |
| 144114 | 144003 | |
| 144115 | 144004 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 144116 | 144005 | char *zType = sqlite3ColumnType(&pTab->aCol[iCol], ""); |
| 144117 | 144006 | int nType; |
| 144118 | 144007 | int i = 0; |
| | @@ -144166,15 +144055,15 @@ |
| 144166 | 144055 | if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){ |
| 144167 | 144056 | return SQLITE_OK; |
| 144168 | 144057 | } |
| 144169 | 144058 | |
| 144170 | 144059 | /* Locate the required virtual table module */ |
| 144171 | | - zMod = pTab->azModuleArg[0]; |
| 144060 | + zMod = pTab->u.vtab.azArg[0]; |
| 144172 | 144061 | pMod = (Module*)sqlite3HashFind(&db->aModule, zMod); |
| 144173 | 144062 | |
| 144174 | 144063 | if( !pMod ){ |
| 144175 | | - const char *zModule = pTab->azModuleArg[0]; |
| 144064 | + const char *zModule = pTab->u.vtab.azArg[0]; |
| 144176 | 144065 | sqlite3ErrorMsg(pParse, "no such module: %s", zModule); |
| 144177 | 144066 | rc = SQLITE_ERROR; |
| 144178 | 144067 | }else{ |
| 144179 | 144068 | char *zErr = 0; |
| 144180 | 144069 | rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr); |
| | @@ -144233,14 +144122,14 @@ |
| 144233 | 144122 | Table *pTab; |
| 144234 | 144123 | Module *pMod; |
| 144235 | 144124 | const char *zMod; |
| 144236 | 144125 | |
| 144237 | 144126 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 144238 | | - assert( pTab && IsVirtual(pTab) && !pTab->pVTable ); |
| 144127 | + assert( pTab && IsVirtual(pTab) && !pTab->u.vtab.p ); |
| 144239 | 144128 | |
| 144240 | 144129 | /* Locate the required virtual table module */ |
| 144241 | | - zMod = pTab->azModuleArg[0]; |
| 144130 | + zMod = pTab->u.vtab.azArg[0]; |
| 144242 | 144131 | pMod = (Module*)sqlite3HashFind(&db->aModule, zMod); |
| 144243 | 144132 | |
| 144244 | 144133 | /* If the module has been registered and includes a Create method, |
| 144245 | 144134 | ** invoke it now. If the module has not been registered, return an |
| 144246 | 144135 | ** error. Otherwise, do nothing. |
| | @@ -144296,17 +144185,17 @@ |
| 144296 | 144185 | sParse.db = db; |
| 144297 | 144186 | sParse.nQueryLoop = 1; |
| 144298 | 144187 | if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr) |
| 144299 | 144188 | && sParse.pNewTable |
| 144300 | 144189 | && !db->mallocFailed |
| 144301 | | - && !sParse.pNewTable->pSelect |
| 144302 | | - && !IsVirtual(sParse.pNewTable) |
| 144190 | + && IsOrdinaryTable(sParse.pNewTable) |
| 144303 | 144191 | ){ |
| 144304 | 144192 | if( !pTab->aCol ){ |
| 144305 | 144193 | Table *pNew = sParse.pNewTable; |
| 144306 | 144194 | Index *pIdx; |
| 144307 | 144195 | pTab->aCol = pNew->aCol; |
| 144196 | + sqlite3ExprListDelete(db, pNew->u.tab.pDfltList); |
| 144308 | 144197 | pTab->nNVCol = pTab->nCol = pNew->nCol; |
| 144309 | 144198 | pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 144310 | 144199 | pNew->nCol = 0; |
| 144311 | 144200 | pNew->aCol = 0; |
| 144312 | 144201 | assert( pTab->pIndex==0 ); |
| | @@ -144357,14 +144246,14 @@ |
| 144357 | 144246 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ |
| 144358 | 144247 | int rc = SQLITE_OK; |
| 144359 | 144248 | Table *pTab; |
| 144360 | 144249 | |
| 144361 | 144250 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 144362 | | - if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){ |
| 144251 | + if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){ |
| 144363 | 144252 | VTable *p; |
| 144364 | 144253 | int (*xDestroy)(sqlite3_vtab *); |
| 144365 | | - for(p=pTab->pVTable; p; p=p->pNext){ |
| 144254 | + for(p=pTab->u.vtab.p; p; p=p->pNext){ |
| 144366 | 144255 | assert( p->pVtab ); |
| 144367 | 144256 | if( p->pVtab->nRef>0 ){ |
| 144368 | 144257 | return SQLITE_LOCKED; |
| 144369 | 144258 | } |
| 144370 | 144259 | } |
| | @@ -144374,13 +144263,13 @@ |
| 144374 | 144263 | assert( xDestroy!=0 ); |
| 144375 | 144264 | pTab->nTabRef++; |
| 144376 | 144265 | rc = xDestroy(p->pVtab); |
| 144377 | 144266 | /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */ |
| 144378 | 144267 | if( rc==SQLITE_OK ){ |
| 144379 | | - assert( pTab->pVTable==p && p->pNext==0 ); |
| 144268 | + assert( pTab->u.vtab.p==p && p->pNext==0 ); |
| 144380 | 144269 | p->pVtab = 0; |
| 144381 | | - pTab->pVTable = 0; |
| 144270 | + pTab->u.vtab.p = 0; |
| 144382 | 144271 | sqlite3VtabUnlock(p); |
| 144383 | 144272 | } |
| 144384 | 144273 | sqlite3DeleteTable(db, pTab); |
| 144385 | 144274 | } |
| 144386 | 144275 | |
| | @@ -144693,12 +144582,13 @@ |
| 144693 | 144582 | sqlite3DbFree(db, pTab); |
| 144694 | 144583 | return 0; |
| 144695 | 144584 | } |
| 144696 | 144585 | pMod->pEpoTab = pTab; |
| 144697 | 144586 | pTab->nTabRef = 1; |
| 144587 | + pTab->eTabType = TABTYP_VTAB; |
| 144698 | 144588 | pTab->pSchema = db->aDb[0].pSchema; |
| 144699 | | - assert( pTab->nModuleArg==0 ); |
| 144589 | + assert( pTab->u.vtab.nArg==0 ); |
| 144700 | 144590 | pTab->iPKey = -1; |
| 144701 | 144591 | pTab->tabFlags |= TF_Eponymous; |
| 144702 | 144592 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 144703 | 144593 | addModuleArgument(pParse, pTab, 0); |
| 144704 | 144594 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| | @@ -145438,11 +145328,11 @@ |
| 145438 | 145328 | */ |
| 145439 | 145329 | static const char *explainIndexColumnName(Index *pIdx, int i){ |
| 145440 | 145330 | i = pIdx->aiColumn[i]; |
| 145441 | 145331 | if( i==XN_EXPR ) return "<expr>"; |
| 145442 | 145332 | if( i==XN_ROWID ) return "rowid"; |
| 145443 | | - return pIdx->pTable->aCol[i].zName; |
| 145333 | + return pIdx->pTable->aCol[i].zCnName; |
| 145444 | 145334 | } |
| 145445 | 145335 | |
| 145446 | 145336 | /* |
| 145447 | 145337 | ** This routine is a helper for explainIndexRange() below |
| 145448 | 145338 | ** |
| | @@ -146650,12 +146540,13 @@ |
| 146650 | 146540 | if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue; |
| 146651 | 146541 | w.xExprCallback = whereIndexExprTransNode; |
| 146652 | 146542 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 146653 | 146543 | }else if( iRef>=0 |
| 146654 | 146544 | && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0 |
| 146655 | | - && (pTab->aCol[iRef].zColl==0 |
| 146656 | | - || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0) |
| 146545 | + && ((pTab->aCol[iRef].colFlags & COLFLAG_HASCOLL)==0 |
| 146546 | + || sqlite3StrICmp(sqlite3ColumnColl(&pTab->aCol[iRef]), |
| 146547 | + sqlite3StrBINARY)==0) |
| 146657 | 146548 | ){ |
| 146658 | 146549 | /* Check to see if there are direct references to generated columns |
| 146659 | 146550 | ** that are contained in the index. Pulling the generated column |
| 146660 | 146551 | ** out of the index is an optimization only - the main table is always |
| 146661 | 146552 | ** available if the index cannot be used. To avoid unnecessary |
| | @@ -149070,11 +148961,15 @@ |
| 149070 | 148961 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 149071 | 148962 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 149072 | 148963 | pNew->prereqRight = prereqLeft | extraRight; |
| 149073 | 148964 | pNew->prereqAll = prereqAll; |
| 149074 | 148965 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| 149075 | | - }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){ |
| 148966 | + }else |
| 148967 | + if( op==TK_ISNULL |
| 148968 | + && !ExprHasProperty(pExpr,EP_FromJoin) |
| 148969 | + && 0==sqlite3ExprCanBeNull(pLeft) |
| 148970 | + ){ |
| 149076 | 148971 | pExpr->op = TK_TRUEFALSE; |
| 149077 | 148972 | pExpr->u.zToken = "false"; |
| 149078 | 148973 | ExprSetProperty(pExpr, EP_IsFalse); |
| 149079 | 148974 | pTerm->prereqAll = 0; |
| 149080 | 148975 | pTerm->eOperator = 0; |
| | @@ -150357,11 +150252,11 @@ |
| 150357 | 150252 | testcase( iCol==BMS ); |
| 150358 | 150253 | testcase( iCol==BMS-1 ); |
| 150359 | 150254 | if( !sentWarning ){ |
| 150360 | 150255 | sqlite3_log(SQLITE_WARNING_AUTOINDEX, |
| 150361 | 150256 | "automatic index on %s(%s)", pTable->zName, |
| 150362 | | - pTable->aCol[iCol].zName); |
| 150257 | + pTable->aCol[iCol].zCnName); |
| 150363 | 150258 | sentWarning = 1; |
| 150364 | 150259 | } |
| 150365 | 150260 | if( (idxCols & cMask)==0 ){ |
| 150366 | 150261 | if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){ |
| 150367 | 150262 | goto end_auto_index_create; |
| | @@ -152536,11 +152431,10 @@ |
| 152536 | 152431 | WhereLoop *pNew; /* Template WhereLoop object */ |
| 152537 | 152432 | int rc = SQLITE_OK; /* Return code */ |
| 152538 | 152433 | int iSortIdx = 1; /* Index number */ |
| 152539 | 152434 | int b; /* A boolean value */ |
| 152540 | 152435 | LogEst rSize; /* number of rows in the table */ |
| 152541 | | - LogEst rLogSize; /* Logarithm of the number of rows in the table */ |
| 152542 | 152436 | WhereClause *pWC; /* The parsed WHERE clause */ |
| 152543 | 152437 | Table *pTab; /* Table being queried */ |
| 152544 | 152438 | |
| 152545 | 152439 | pNew = pBuilder->pNew; |
| 152546 | 152440 | pWInfo = pBuilder->pWInfo; |
| | @@ -152579,11 +152473,10 @@ |
| 152579 | 152473 | sPk.pNext = pFirst; |
| 152580 | 152474 | } |
| 152581 | 152475 | pProbe = &sPk; |
| 152582 | 152476 | } |
| 152583 | 152477 | rSize = pTab->nRowLogEst; |
| 152584 | | - rLogSize = estLog(rSize); |
| 152585 | 152478 | |
| 152586 | 152479 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 152587 | 152480 | /* Automatic indexes */ |
| 152588 | 152481 | if( !pBuilder->pOrSet /* Not part of an OR optimization */ |
| 152589 | 152482 | && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 |
| | @@ -152593,12 +152486,14 @@ |
| 152593 | 152486 | && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */ |
| 152594 | 152487 | && !pSrc->fg.isCorrelated /* Not a correlated subquery */ |
| 152595 | 152488 | && !pSrc->fg.isRecursive /* Not a recursive common table expression. */ |
| 152596 | 152489 | ){ |
| 152597 | 152490 | /* Generate auto-index WhereLoops */ |
| 152491 | + LogEst rLogSize; /* Logarithm of the number of rows in the table */ |
| 152598 | 152492 | WhereTerm *pTerm; |
| 152599 | 152493 | WhereTerm *pWCEnd = pWC->a + pWC->nTerm; |
| 152494 | + rLogSize = estLog(rSize); |
| 152600 | 152495 | for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){ |
| 152601 | 152496 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 152602 | 152497 | if( termCanDriveIndex(pTerm, pSrc, 0) ){ |
| 152603 | 152498 | pNew->u.btree.nEq = 1; |
| 152604 | 152499 | pNew->nSkip = 0; |
| | @@ -152612,11 +152507,11 @@ |
| 152612 | 152507 | ** of X is smaller for views and subqueries so that the query planner |
| 152613 | 152508 | ** will be more aggressive about generating automatic indexes for |
| 152614 | 152509 | ** those objects, since there is no opportunity to add schema |
| 152615 | 152510 | ** indexes on subqueries and views. */ |
| 152616 | 152511 | pNew->rSetup = rLogSize + rSize; |
| 152617 | | - if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){ |
| 152512 | + if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){ |
| 152618 | 152513 | pNew->rSetup += 28; |
| 152619 | 152514 | }else{ |
| 152620 | 152515 | pNew->rSetup -= 10; |
| 152621 | 152516 | } |
| 152622 | 152517 | ApplyCostMultiplier(pNew->rSetup, pTab->costMult); |
| | @@ -154763,11 +154658,11 @@ |
| 154763 | 154658 | |
| 154764 | 154659 | pTabItem = &pTabList->a[pLevel->iFrom]; |
| 154765 | 154660 | pTab = pTabItem->pTab; |
| 154766 | 154661 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 154767 | 154662 | pLoop = pLevel->pWLoop; |
| 154768 | | - if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){ |
| 154663 | + if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){ |
| 154769 | 154664 | /* Do nothing */ |
| 154770 | 154665 | }else |
| 154771 | 154666 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 154772 | 154667 | if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){ |
| 154773 | 154668 | const char *pVTab = (const char *)sqlite3GetVTable(db, pTab); |
| | @@ -155132,11 +155027,11 @@ |
| 155132 | 155027 | ** Except, do not close cursors that will be reused by the OR optimization |
| 155133 | 155028 | ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors |
| 155134 | 155029 | ** created for the ONEPASS optimization. |
| 155135 | 155030 | */ |
| 155136 | 155031 | if( (pTab->tabFlags & TF_Ephemeral)==0 |
| 155137 | | - && pTab->pSelect==0 |
| 155032 | + && !IsView(pTab) |
| 155138 | 155033 | && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 |
| 155139 | 155034 | ){ |
| 155140 | 155035 | int ws = pLoop->wsFlags; |
| 155141 | 155036 | if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){ |
| 155142 | 155037 | sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); |
| | @@ -161958,11 +161853,11 @@ |
| 161958 | 161853 | sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z); |
| 161959 | 161854 | } |
| 161960 | 161855 | } |
| 161961 | 161856 | break; |
| 161962 | 161857 | case 23: /* columnname ::= nm typetoken */ |
| 161963 | | -{sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);} |
| 161858 | +{sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);} |
| 161964 | 161859 | break; |
| 161965 | 161860 | case 24: /* typetoken ::= */ |
| 161966 | 161861 | case 63: /* conslist_opt ::= */ yytestcase(yyruleno==63); |
| 161967 | 161862 | case 102: /* as ::= */ yytestcase(yyruleno==102); |
| 161968 | 161863 | {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;} |
| | @@ -169147,11 +169042,11 @@ |
| 169147 | 169042 | goto error_out; |
| 169148 | 169043 | } |
| 169149 | 169044 | |
| 169150 | 169045 | /* Locate the table in question */ |
| 169151 | 169046 | pTab = sqlite3FindTable(db, zTableName, zDbName); |
| 169152 | | - if( !pTab || pTab->pSelect ){ |
| 169047 | + if( !pTab || IsView(pTab) ){ |
| 169153 | 169048 | pTab = 0; |
| 169154 | 169049 | goto error_out; |
| 169155 | 169050 | } |
| 169156 | 169051 | |
| 169157 | 169052 | /* Find the column for which info is requested */ |
| | @@ -169158,11 +169053,11 @@ |
| 169158 | 169053 | if( zColumnName==0 ){ |
| 169159 | 169054 | /* Query for existance of table only */ |
| 169160 | 169055 | }else{ |
| 169161 | 169056 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 169162 | 169057 | pCol = &pTab->aCol[iCol]; |
| 169163 | | - if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){ |
| 169058 | + if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){ |
| 169164 | 169059 | break; |
| 169165 | 169060 | } |
| 169166 | 169061 | } |
| 169167 | 169062 | if( iCol==pTab->nCol ){ |
| 169168 | 169063 | if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){ |
| | @@ -169185,11 +169080,11 @@ |
| 169185 | 169080 | ** 2. The table is not a view and the column name identified an |
| 169186 | 169081 | ** explicitly declared column. Copy meta information from *pCol. |
| 169187 | 169082 | */ |
| 169188 | 169083 | if( pCol ){ |
| 169189 | 169084 | zDataType = sqlite3ColumnType(pCol,0); |
| 169190 | | - zCollSeq = pCol->zColl; |
| 169085 | + zCollSeq = sqlite3ColumnColl(pCol); |
| 169191 | 169086 | notnull = pCol->notNull!=0; |
| 169192 | 169087 | primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0; |
| 169193 | 169088 | autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0; |
| 169194 | 169089 | }else{ |
| 169195 | 169090 | zDataType = "INTEGER"; |
| | @@ -201618,11 +201513,13 @@ |
| 201618 | 201513 | *piPk = 0; |
| 201619 | 201514 | |
| 201620 | 201515 | assert( p->rc==SQLITE_OK ); |
| 201621 | 201516 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg, |
| 201622 | 201517 | sqlite3_mprintf( |
| 201623 | | - "SELECT (sql LIKE 'create virtual%%'), rootpage" |
| 201518 | + "SELECT " |
| 201519 | + " (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM')," |
| 201520 | + " rootpage" |
| 201624 | 201521 | " FROM sqlite_schema" |
| 201625 | 201522 | " WHERE name=%Q", zTab |
| 201626 | 201523 | )); |
| 201627 | 201524 | if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){ |
| 201628 | 201525 | /* Either an error, or no such table. */ |
| | @@ -203151,11 +203048,11 @@ |
| 203151 | 203048 | case RBU_STATE_COOKIE: |
| 203152 | 203049 | pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1); |
| 203153 | 203050 | break; |
| 203154 | 203051 | |
| 203155 | 203052 | case RBU_STATE_OALSZ: |
| 203156 | | - pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1); |
| 203053 | + pRet->iOalSz = sqlite3_column_int64(pStmt, 1); |
| 203157 | 203054 | break; |
| 203158 | 203055 | |
| 203159 | 203056 | case RBU_STATE_PHASEONESTEP: |
| 203160 | 203057 | pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1); |
| 203161 | 203058 | break; |
| | @@ -230952,11 +230849,11 @@ |
| 230952 | 230849 | int nArg, /* Number of args */ |
| 230953 | 230850 | sqlite3_value **apUnused /* Function arguments */ |
| 230954 | 230851 | ){ |
| 230955 | 230852 | assert( nArg==0 ); |
| 230956 | 230853 | UNUSED_PARAM2(nArg, apUnused); |
| 230957 | | - sqlite3_result_text(pCtx, "fts5: 2021-07-20 14:57:49 1e35cc6d5c2f563c6bb163bb150d7bc6ede4c993efa828af1face3261bf65a2c", -1, SQLITE_TRANSIENT); |
| 230854 | + sqlite3_result_text(pCtx, "fts5: 2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a", -1, SQLITE_TRANSIENT); |
| 230958 | 230855 | } |
| 230959 | 230856 | |
| 230960 | 230857 | /* |
| 230961 | 230858 | ** Return true if zName is the extension on one of the shadow tables used |
| 230962 | 230859 | ** by this module. |
| 230963 | 230860 | |