drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2003 April 6 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** This file contains code used to implement the PRAGMA command. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 13 | */ |
| 14 | #include "sqliteInt.h" |
| 15 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 16 | #if !defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 17 | # if defined(__APPLE__) |
| 18 | # define SQLITE_ENABLE_LOCKING_STYLE 1 |
| 19 | # else |
| 20 | # define SQLITE_ENABLE_LOCKING_STYLE 0 |
| 21 | # endif |
| 22 | #endif |
| 23 | |
| 24 | /*************************************************************************** |
drh | 67e65e5 | 2015-02-02 21:34:54 +0000 | [diff] [blame] | 25 | ** The "pragma.h" include file is an automatically generated file that |
| 26 | ** that includes the PragType_XXXX macro definitions and the aPragmaName[] |
| 27 | ** object. This ensures that the aPragmaName[] table is arranged in |
| 28 | ** lexicographical order to facility a binary search of the pragma name. |
| 29 | ** Do not edit pragma.h directly. Edit and rerun the script in at |
| 30 | ** ../tool/mkpragmatab.tcl. */ |
| 31 | #include "pragma.h" |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 32 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 33 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 34 | ** Interpret the given string as a safety level. Return 0 for OFF, |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 35 | ** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or |
| 36 | ** unrecognized string argument. The FULL and EXTRA option is disallowed |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 37 | ** if the omitFull parameter it 1. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 38 | ** |
| 39 | ** Note that the values returned are one less that the values that |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 40 | ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 41 | ** to support legacy SQL code. The safety level used to be boolean |
| 42 | ** and older scripts may have used numbers 0 for OFF and 1 for ON. |
| 43 | */ |
drh | eac5bd7 | 2014-07-25 21:35:39 +0000 | [diff] [blame] | 44 | static u8 getSafetyLevel(const char *z, int omitFull, u8 dflt){ |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 45 | /* 123456789 123456789 123 */ |
| 46 | static const char zText[] = "onoffalseyestruextrafull"; |
| 47 | static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 15, 20}; |
| 48 | static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 5, 4}; |
| 49 | static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2}; |
| 50 | /* on no off false yes true extra full */ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 51 | int i, n; |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 52 | if( sqlite3Isdigit(*z) ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 53 | return (u8)sqlite3Atoi(z); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 54 | } |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 55 | n = sqlite3Strlen30(z); |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 56 | for(i=0; i<ArraySize(iLength); i++){ |
| 57 | if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 |
| 58 | && (!omitFull || iValue[i]<=1) |
| 59 | ){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 60 | return iValue[i]; |
| 61 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 62 | } |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 63 | return dflt; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 67 | ** Interpret the given string as a boolean value. |
| 68 | */ |
drh | eac5bd7 | 2014-07-25 21:35:39 +0000 | [diff] [blame] | 69 | u8 sqlite3GetBoolean(const char *z, u8 dflt){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 70 | return getSafetyLevel(z,1,dflt)!=0; |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 71 | } |
| 72 | |
drh | c7dc9bf | 2011-06-03 13:02:57 +0000 | [diff] [blame] | 73 | /* The sqlite3GetBoolean() function is used by other modules but the |
| 74 | ** remainder of this file is specific to PRAGMA processing. So omit |
| 75 | ** the rest of the file if PRAGMAs are omitted from the build. |
| 76 | */ |
| 77 | #if !defined(SQLITE_OMIT_PRAGMA) |
| 78 | |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 79 | /* |
| 80 | ** Interpret the given string as a locking mode value. |
| 81 | */ |
| 82 | static int getLockingMode(const char *z){ |
| 83 | if( z ){ |
| 84 | if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE; |
| 85 | if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL; |
| 86 | } |
| 87 | return PAGER_LOCKINGMODE_QUERY; |
| 88 | } |
| 89 | |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 90 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 91 | /* |
| 92 | ** Interpret the given string as an auto-vacuum mode value. |
| 93 | ** |
| 94 | ** The following strings, "none", "full" and "incremental" are |
| 95 | ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively. |
| 96 | */ |
| 97 | static int getAutoVacuum(const char *z){ |
| 98 | int i; |
| 99 | if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE; |
| 100 | if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL; |
| 101 | if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR; |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 102 | i = sqlite3Atoi(z); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 103 | return (u8)((i>=0&&i<=2)?i:0); |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 104 | } |
| 105 | #endif /* ifndef SQLITE_OMIT_AUTOVACUUM */ |
| 106 | |
danielk1977 | b84f96f | 2005-01-20 11:32:23 +0000 | [diff] [blame] | 107 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 108 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 109 | ** Interpret the given string as a temp db location. Return 1 for file |
| 110 | ** backed temporary databases, 2 for the Red-Black tree in memory database |
| 111 | ** and 0 to use the compile-time default. |
| 112 | */ |
| 113 | static int getTempStore(const char *z){ |
| 114 | if( z[0]>='0' && z[0]<='2' ){ |
| 115 | return z[0] - '0'; |
| 116 | }else if( sqlite3StrICmp(z, "file")==0 ){ |
| 117 | return 1; |
| 118 | }else if( sqlite3StrICmp(z, "memory")==0 ){ |
| 119 | return 2; |
| 120 | }else{ |
| 121 | return 0; |
| 122 | } |
| 123 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 124 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 125 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 126 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 127 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 128 | ** Invalidate temp storage, either when the temp storage is changed |
| 129 | ** from default, or when 'file' and the temp_store_directory has changed |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 130 | */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 131 | static int invalidateTempStorage(Parse *pParse){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 132 | sqlite3 *db = pParse->db; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 133 | if( db->aDb[1].pBt!=0 ){ |
drh | 99744fa | 2020-08-25 19:09:07 +0000 | [diff] [blame] | 134 | if( !db->autoCommit |
| 135 | || sqlite3BtreeTxnState(db->aDb[1].pBt)!=SQLITE_TXN_NONE |
| 136 | ){ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 137 | sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " |
| 138 | "from within a transaction"); |
| 139 | return SQLITE_ERROR; |
| 140 | } |
| 141 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 142 | db->aDb[1].pBt = 0; |
drh | 81028a4 | 2012-05-15 18:28:27 +0000 | [diff] [blame] | 143 | sqlite3ResetAllSchemasOfConnection(db); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 144 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 145 | return SQLITE_OK; |
| 146 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 147 | #endif /* SQLITE_PAGER_PRAGMAS */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 148 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 149 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 150 | /* |
| 151 | ** If the TEMP database is open, close it and mark the database schema |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 152 | ** as needing reloading. This must be done when using the SQLITE_TEMP_STORE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 153 | ** or DEFAULT_TEMP_STORE pragmas. |
| 154 | */ |
| 155 | static int changeTempStorage(Parse *pParse, const char *zStorageType){ |
| 156 | int ts = getTempStore(zStorageType); |
| 157 | sqlite3 *db = pParse->db; |
| 158 | if( db->temp_store==ts ) return SQLITE_OK; |
| 159 | if( invalidateTempStorage( pParse ) != SQLITE_OK ){ |
| 160 | return SQLITE_ERROR; |
| 161 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 162 | db->temp_store = (u8)ts; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 163 | return SQLITE_OK; |
| 164 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 165 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 166 | |
| 167 | /* |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 168 | ** Set result column names for a pragma. |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 169 | */ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 170 | static void setPragmaResultColumnNames( |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 171 | Vdbe *v, /* The query under construction */ |
| 172 | const PragmaName *pPragma /* The pragma */ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 173 | ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 174 | u8 n = pPragma->nPragCName; |
| 175 | sqlite3VdbeSetNumCols(v, n==0 ? 1 : n); |
| 176 | if( n==0 ){ |
| 177 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, SQLITE_STATIC); |
| 178 | }else{ |
| 179 | int i, j; |
| 180 | for(i=0, j=pPragma->iPragCName; i<n; i++, j++){ |
| 181 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, pragCName[j], SQLITE_STATIC); |
| 182 | } |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 185 | |
| 186 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 187 | ** Generate code to return a single integer value. |
| 188 | */ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 189 | static void returnSingleInt(Vdbe *v, i64 value){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 190 | sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 191 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | ** Generate code to return a single text value. |
| 196 | */ |
| 197 | static void returnSingleText( |
| 198 | Vdbe *v, /* Prepared statement under construction */ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 199 | const char *zValue /* Value to be returned */ |
| 200 | ){ |
| 201 | if( zValue ){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 202 | sqlite3VdbeLoadString(v, 1, (const char*)zValue); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 203 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 204 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 205 | } |
| 206 | |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 207 | |
| 208 | /* |
| 209 | ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| 210 | ** set these values for all pagers. |
| 211 | */ |
| 212 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 213 | static void setAllPagerFlags(sqlite3 *db){ |
| 214 | if( db->autoCommit ){ |
| 215 | Db *pDb = db->aDb; |
| 216 | int n = db->nDb; |
| 217 | assert( SQLITE_FullFSync==PAGER_FULLFSYNC ); |
| 218 | assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC ); |
| 219 | assert( SQLITE_CacheSpill==PAGER_CACHESPILL ); |
| 220 | assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL) |
| 221 | == PAGER_FLAGS_MASK ); |
| 222 | assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level ); |
| 223 | while( (n--) > 0 ){ |
| 224 | if( pDb->pBt ){ |
| 225 | sqlite3BtreeSetPagerFlags(pDb->pBt, |
| 226 | pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) ); |
| 227 | } |
| 228 | pDb++; |
| 229 | } |
| 230 | } |
| 231 | } |
drh | feb56e0 | 2013-08-23 17:33:46 +0000 | [diff] [blame] | 232 | #else |
| 233 | # define setAllPagerFlags(X) /* no-op */ |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 234 | #endif |
| 235 | |
| 236 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 237 | /* |
| 238 | ** Return a human-readable name for a constraint resolution action. |
| 239 | */ |
dan | ba9108b | 2009-09-22 07:13:42 +0000 | [diff] [blame] | 240 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 241 | static const char *actionName(u8 action){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 242 | const char *zName; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 243 | switch( action ){ |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 244 | case OE_SetNull: zName = "SET NULL"; break; |
| 245 | case OE_SetDflt: zName = "SET DEFAULT"; break; |
| 246 | case OE_Cascade: zName = "CASCADE"; break; |
| 247 | case OE_Restrict: zName = "RESTRICT"; break; |
| 248 | default: zName = "NO ACTION"; |
| 249 | assert( action==OE_None ); break; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 250 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 251 | return zName; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 252 | } |
dan | ba9108b | 2009-09-22 07:13:42 +0000 | [diff] [blame] | 253 | #endif |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 254 | |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | ** Parameter eMode must be one of the PAGER_JOURNALMODE_XXX constants |
| 258 | ** defined in pager.h. This function returns the associated lowercase |
| 259 | ** journal-mode name. |
| 260 | */ |
| 261 | const char *sqlite3JournalModename(int eMode){ |
| 262 | static char * const azModeName[] = { |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 263 | "delete", "persist", "off", "truncate", "memory" |
| 264 | #ifndef SQLITE_OMIT_WAL |
| 265 | , "wal" |
| 266 | #endif |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 267 | }; |
| 268 | assert( PAGER_JOURNALMODE_DELETE==0 ); |
| 269 | assert( PAGER_JOURNALMODE_PERSIST==1 ); |
| 270 | assert( PAGER_JOURNALMODE_OFF==2 ); |
| 271 | assert( PAGER_JOURNALMODE_TRUNCATE==3 ); |
| 272 | assert( PAGER_JOURNALMODE_MEMORY==4 ); |
| 273 | assert( PAGER_JOURNALMODE_WAL==5 ); |
| 274 | assert( eMode>=0 && eMode<=ArraySize(azModeName) ); |
| 275 | |
| 276 | if( eMode==ArraySize(azModeName) ) return 0; |
| 277 | return azModeName[eMode]; |
| 278 | } |
| 279 | |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 280 | /* |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 281 | ** Locate a pragma in the aPragmaName[] array. |
| 282 | */ |
| 283 | static const PragmaName *pragmaLocate(const char *zName){ |
mistachkin | 2e52532 | 2017-02-01 22:43:08 +0000 | [diff] [blame] | 284 | int upr, lwr, mid = 0, rc; |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 285 | lwr = 0; |
| 286 | upr = ArraySize(aPragmaName)-1; |
| 287 | while( lwr<=upr ){ |
| 288 | mid = (lwr+upr)/2; |
| 289 | rc = sqlite3_stricmp(zName, aPragmaName[mid].zName); |
| 290 | if( rc==0 ) break; |
| 291 | if( rc<0 ){ |
| 292 | upr = mid - 1; |
| 293 | }else{ |
| 294 | lwr = mid + 1; |
| 295 | } |
| 296 | } |
| 297 | return lwr>upr ? 0 : &aPragmaName[mid]; |
| 298 | } |
| 299 | |
| 300 | /* |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 301 | ** Create zero or more entries in the output for the SQL functions |
| 302 | ** defined by FuncDef p. |
| 303 | */ |
drh | 337ca51 | 2020-01-04 19:58:28 +0000 | [diff] [blame] | 304 | static void pragmaFunclistLine( |
| 305 | Vdbe *v, /* The prepared statement being created */ |
| 306 | FuncDef *p, /* A particular function definition */ |
| 307 | int isBuiltin, /* True if this is a built-in function */ |
| 308 | int showInternFuncs /* True if showing internal functions */ |
| 309 | ){ |
drh | 9606a13 | 2022-02-25 01:23:17 +0000 | [diff] [blame] | 310 | u32 mask = |
| 311 | SQLITE_DETERMINISTIC | |
| 312 | SQLITE_DIRECTONLY | |
| 313 | SQLITE_SUBTYPE | |
| 314 | SQLITE_INNOCUOUS | |
| 315 | SQLITE_FUNC_INTERNAL |
| 316 | ; |
drh | ceff761 | 2022-03-02 01:02:16 +0000 | [diff] [blame] | 317 | if( showInternFuncs ) mask = 0xffffffff; |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 318 | for(; p; p=p->pNext){ |
| 319 | const char *zType; |
drh | b84fda3 | 2020-01-09 16:28:50 +0000 | [diff] [blame] | 320 | static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; |
| 321 | |
| 322 | assert( SQLITE_FUNC_ENCMASK==0x3 ); |
| 323 | assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 ); |
| 324 | assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 ); |
| 325 | assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 ); |
drh | 337ca51 | 2020-01-04 19:58:28 +0000 | [diff] [blame] | 326 | |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 327 | if( p->xSFunc==0 ) continue; |
drh | 337ca51 | 2020-01-04 19:58:28 +0000 | [diff] [blame] | 328 | if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0 |
| 329 | && showInternFuncs==0 |
| 330 | ){ |
| 331 | continue; |
| 332 | } |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 333 | if( p->xValue!=0 ){ |
| 334 | zType = "w"; |
| 335 | }else if( p->xFinalize!=0 ){ |
| 336 | zType = "a"; |
| 337 | }else{ |
| 338 | zType = "s"; |
| 339 | } |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 340 | sqlite3VdbeMultiLoad(v, 1, "sissii", |
| 341 | p->zName, isBuiltin, |
drh | b84fda3 | 2020-01-09 16:28:50 +0000 | [diff] [blame] | 342 | zType, azEnc[p->funcFlags&SQLITE_FUNC_ENCMASK], |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 343 | p->nArg, |
| 344 | (p->funcFlags & mask) ^ SQLITE_INNOCUOUS |
| 345 | ); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | |
| 350 | /* |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 351 | ** Helper subroutine for PRAGMA integrity_check: |
| 352 | ** |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 353 | ** Generate code to output a single-column result row with a value of the |
| 354 | ** string held in register 3. Decrement the result count in register 1 |
| 355 | ** and halt if the maximum number of result rows have been issued. |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 356 | */ |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 357 | static int integrityCheckResultRow(Vdbe *v){ |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 358 | int addr; |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 359 | sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 360 | addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1); |
| 361 | VdbeCoverage(v); |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 362 | sqlite3VdbeAddOp0(v, OP_Halt); |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 363 | return addr; |
| 364 | } |
| 365 | |
| 366 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 367 | ** Process a pragma statement. |
| 368 | ** |
| 369 | ** Pragmas are of this form: |
| 370 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 371 | ** PRAGMA [schema.]id [= value] |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 372 | ** |
| 373 | ** The identifier might also be a string. The value is a string, and |
| 374 | ** identifier, or a number. If minusFlag is true, then the value is |
| 375 | ** a number that was preceded by a minus sign. |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 376 | ** |
| 377 | ** If the left side is "database.id" then pId1 is the database name |
| 378 | ** and pId2 is the id. If the left side is just "id" then pId1 is the |
| 379 | ** id and pId2 is any empty string. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 380 | */ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 381 | void sqlite3Pragma( |
| 382 | Parse *pParse, |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 383 | Token *pId1, /* First part of [schema.]id field */ |
| 384 | Token *pId2, /* Second part of [schema.]id field, or NULL */ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 385 | Token *pValue, /* Token for <value>, or NULL */ |
| 386 | int minusFlag /* True if a '-' sign preceded <value> */ |
| 387 | ){ |
| 388 | char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ |
| 389 | char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
| 390 | const char *zDb = 0; /* The database name */ |
| 391 | Token *pId; /* Pointer to <id> token */ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 392 | char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 393 | int iDb; /* Database index for <database> */ |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 394 | int rc; /* return value form SQLITE_FCNTL_PRAGMA */ |
| 395 | sqlite3 *db = pParse->db; /* The database connection */ |
| 396 | Db *pDb; /* The specific database being pragmaed */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 397 | Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */ |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 398 | const PragmaName *pPragma; /* The pragma */ |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 399 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 400 | if( v==0 ) return; |
drh | 4611d92 | 2010-02-25 14:47:01 +0000 | [diff] [blame] | 401 | sqlite3VdbeRunOnlyOnce(v); |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 402 | pParse->nMem = 2; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 403 | |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 404 | /* Interpret the [schema.] part of the pragma statement. iDb is the |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 405 | ** index of the database this pragma is being applied to in db.aDb[]. */ |
| 406 | iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); |
| 407 | if( iDb<0 ) return; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 408 | pDb = &db->aDb[iDb]; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 409 | |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 410 | /* If the temp database has been explicitly named as part of the |
| 411 | ** pragma, make sure it is open. |
| 412 | */ |
| 413 | if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){ |
| 414 | return; |
| 415 | } |
| 416 | |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 417 | zLeft = sqlite3NameFromToken(db, pId); |
danielk1977 | 96fb0dd | 2004-06-30 09:49:22 +0000 | [diff] [blame] | 418 | if( !zLeft ) return; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 419 | if( minusFlag ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 420 | zRight = sqlite3MPrintf(db, "-%T", pValue); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 421 | }else{ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 422 | zRight = sqlite3NameFromToken(db, pValue); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 423 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 424 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 425 | assert( pId2 ); |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 426 | zDb = pId2->n>0 ? pDb->zDbSName : 0; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 427 | if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 428 | goto pragma_out; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 429 | } |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 430 | |
| 431 | /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS |
| 432 | ** connection. If it returns SQLITE_OK, then assume that the VFS |
| 433 | ** handled the pragma and generate a no-op prepared statement. |
drh | 8dd7a6a | 2015-03-06 04:37:26 +0000 | [diff] [blame] | 434 | ** |
| 435 | ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed, |
| 436 | ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file |
| 437 | ** object corresponding to the database file to which the pragma |
| 438 | ** statement refers. |
| 439 | ** |
| 440 | ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA |
| 441 | ** file control is an array of pointers to strings (char**) in which the |
| 442 | ** second element of the array is the name of the pragma and the third |
| 443 | ** element is the argument to the pragma or NULL if the pragma has no |
| 444 | ** argument. |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 445 | */ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 446 | aFcntl[0] = 0; |
| 447 | aFcntl[1] = zLeft; |
| 448 | aFcntl[2] = zRight; |
| 449 | aFcntl[3] = 0; |
dan | 80bb6f8 | 2012-10-01 18:44:33 +0000 | [diff] [blame] | 450 | db->busyHandler.nBusy = 0; |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 451 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 452 | if( rc==SQLITE_OK ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 453 | sqlite3VdbeSetNumCols(v, 1); |
| 454 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, aFcntl[0], SQLITE_TRANSIENT); |
| 455 | returnSingleText(v, aFcntl[0]); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 456 | sqlite3_free(aFcntl[0]); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 457 | goto pragma_out; |
| 458 | } |
| 459 | if( rc!=SQLITE_NOTFOUND ){ |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 460 | if( aFcntl[0] ){ |
| 461 | sqlite3ErrorMsg(pParse, "%s", aFcntl[0]); |
| 462 | sqlite3_free(aFcntl[0]); |
| 463 | } |
| 464 | pParse->nErr++; |
| 465 | pParse->rc = rc; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 466 | goto pragma_out; |
| 467 | } |
| 468 | |
| 469 | /* Locate the pragma in the lookup table */ |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 470 | pPragma = pragmaLocate(zLeft); |
drh | bc98f90 | 2021-10-14 17:30:32 +0000 | [diff] [blame] | 471 | if( pPragma==0 ){ |
| 472 | /* IMP: R-43042-22504 No error messages are generated if an |
| 473 | ** unknown pragma is issued. */ |
| 474 | goto pragma_out; |
| 475 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 476 | |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 477 | /* Make sure the database schema is loaded if the pragma requires that */ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 478 | if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){ |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 479 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 480 | } |
| 481 | |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 482 | /* Register the result column names for pragmas that return results */ |
dan | 9e1ab1a | 2017-01-05 19:32:48 +0000 | [diff] [blame] | 483 | if( (pPragma->mPragFlg & PragFlg_NoColumns)==0 |
| 484 | && ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0) |
| 485 | ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 486 | setPragmaResultColumnNames(v, pPragma); |
| 487 | } |
| 488 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 489 | /* Jump to the appropriate pragma handler */ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 490 | switch( pPragma->ePragTyp ){ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 491 | |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 492 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 493 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 494 | ** PRAGMA [schema.]default_cache_size |
| 495 | ** PRAGMA [schema.]default_cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 496 | ** |
| 497 | ** The first form reports the current persistent setting for the |
| 498 | ** page cache size. The value returned is the maximum number of |
| 499 | ** pages in the page cache. The second form sets both the current |
| 500 | ** page cache size value and the persistent page cache size value |
| 501 | ** stored in the database file. |
| 502 | ** |
drh | 93791ea | 2010-04-26 17:36:35 +0000 | [diff] [blame] | 503 | ** Older versions of SQLite would set the default cache size to a |
| 504 | ** negative number to indicate synchronous=OFF. These days, synchronous |
| 505 | ** is always on by default regardless of the sign of the default cache |
| 506 | ** size. But continue to take the absolute value of the default cache |
| 507 | ** size of historical compatibility. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 508 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 509 | case PragTyp_DEFAULT_CACHE_SIZE: { |
drh | b06a4ec | 2014-03-10 18:03:09 +0000 | [diff] [blame] | 510 | static const int iLn = VDBE_OFFSET_LINENO(2); |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 511 | static const VdbeOpList getCacheSize[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 512 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 513 | { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 514 | { OP_IfPos, 1, 8, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 515 | { OP_Integer, 0, 2, 0}, |
| 516 | { OP_Subtract, 1, 2, 1}, |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 517 | { OP_IfPos, 1, 8, 0}, |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 518 | { OP_Integer, 0, 1, 0}, /* 6 */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 519 | { OP_Noop, 0, 0, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 520 | { OP_ResultRow, 1, 1, 0}, |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 521 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 522 | VdbeOp *aOp; |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 523 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 524 | if( !zRight ){ |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 525 | pParse->nMem += 2; |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 526 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 527 | aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 528 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 529 | aOp[0].p1 = iDb; |
| 530 | aOp[1].p1 = iDb; |
| 531 | aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 532 | }else{ |
drh | d50ffc4 | 2011-03-08 02:38:28 +0000 | [diff] [blame] | 533 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 534 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 535 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, size); |
drh | 2120608 | 2011-04-04 18:22:02 +0000 | [diff] [blame] | 536 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 537 | pDb->pSchema->cache_size = size; |
| 538 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 539 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 540 | break; |
| 541 | } |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 542 | #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 543 | |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 544 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 545 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 546 | ** PRAGMA [schema.]page_size |
| 547 | ** PRAGMA [schema.]page_size=N |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 548 | ** |
| 549 | ** The first form reports the current setting for the |
| 550 | ** database page size in bytes. The second form sets the |
| 551 | ** database page size value. The value can only be set if |
| 552 | ** the database has not yet been created. |
| 553 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 554 | case PragTyp_PAGE_SIZE: { |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 555 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 556 | assert( pBt!=0 ); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 557 | if( !zRight ){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 558 | int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0; |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 559 | returnSingleInt(v, size); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 560 | }else{ |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 561 | /* Malloc may fail when setting the page-size, as there is an internal |
| 562 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 563 | */ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 564 | db->nextPagesize = sqlite3Atoi(zRight); |
drh | e937df8 | 2020-05-07 01:56:57 +0000 | [diff] [blame] | 565 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){ |
drh | 4a642b6 | 2016-02-05 01:55:27 +0000 | [diff] [blame] | 566 | sqlite3OomFault(db); |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 567 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 568 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 569 | break; |
| 570 | } |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 571 | |
| 572 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 573 | ** PRAGMA [schema.]secure_delete |
drh | a5907a8 | 2017-06-19 11:44:22 +0000 | [diff] [blame] | 574 | ** PRAGMA [schema.]secure_delete=ON/OFF/FAST |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 575 | ** |
| 576 | ** The first form reports the current setting for the |
| 577 | ** secure_delete flag. The second form changes the secure_delete |
drh | a5907a8 | 2017-06-19 11:44:22 +0000 | [diff] [blame] | 578 | ** flag setting and reports the new value. |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 579 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 580 | case PragTyp_SECURE_DELETE: { |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 581 | Btree *pBt = pDb->pBt; |
| 582 | int b = -1; |
| 583 | assert( pBt!=0 ); |
| 584 | if( zRight ){ |
drh | a5907a8 | 2017-06-19 11:44:22 +0000 | [diff] [blame] | 585 | if( sqlite3_stricmp(zRight, "fast")==0 ){ |
| 586 | b = 2; |
| 587 | }else{ |
| 588 | b = sqlite3GetBoolean(zRight, 0); |
| 589 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 590 | } |
drh | af034ed | 2010-02-12 19:46:26 +0000 | [diff] [blame] | 591 | if( pId2->n==0 && b>=0 ){ |
| 592 | int ii; |
| 593 | for(ii=0; ii<db->nDb; ii++){ |
| 594 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| 595 | } |
| 596 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 597 | b = sqlite3BtreeSecureDelete(pBt, b); |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 598 | returnSingleInt(v, b); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 599 | break; |
| 600 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 601 | |
| 602 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 603 | ** PRAGMA [schema.]max_page_count |
| 604 | ** PRAGMA [schema.]max_page_count=N |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 605 | ** |
| 606 | ** The first form reports the current setting for the |
| 607 | ** maximum number of pages in the database file. The |
| 608 | ** second form attempts to change this setting. Both |
| 609 | ** forms return the current setting. |
| 610 | ** |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 611 | ** The absolute value of N is used. This is undocumented and might |
| 612 | ** change. The only purpose is to provide an easy way to test |
| 613 | ** the sqlite3AbsInt32() function. |
| 614 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 615 | ** PRAGMA [schema.]page_count |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 616 | ** |
| 617 | ** Return the number of pages in the specified database. |
| 618 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 619 | case PragTyp_PAGE_COUNT: { |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 620 | int iReg; |
drh | e9261db | 2020-07-20 12:47:32 +0000 | [diff] [blame] | 621 | i64 x = 0; |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 622 | sqlite3CodeVerifySchema(pParse, iDb); |
| 623 | iReg = ++pParse->nMem; |
drh | c522731 | 2011-10-13 17:09:01 +0000 | [diff] [blame] | 624 | if( sqlite3Tolower(zLeft[0])=='p' ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 625 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 626 | }else{ |
drh | e9261db | 2020-07-20 12:47:32 +0000 | [diff] [blame] | 627 | if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){ |
| 628 | if( x<0 ) x = 0; |
| 629 | else if( x>0xfffffffe ) x = 0xfffffffe; |
| 630 | }else{ |
| 631 | x = 0; |
| 632 | } |
| 633 | sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, (int)x); |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 634 | } |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 635 | sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 636 | break; |
| 637 | } |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 638 | |
| 639 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 640 | ** PRAGMA [schema.]locking_mode |
| 641 | ** PRAGMA [schema.]locking_mode = (normal|exclusive) |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 642 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 643 | case PragTyp_LOCKING_MODE: { |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 644 | const char *zRet = "normal"; |
| 645 | int eMode = getLockingMode(zRight); |
| 646 | |
| 647 | if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){ |
| 648 | /* Simple "PRAGMA locking_mode;" statement. This is a query for |
| 649 | ** the current default locking mode (which may be different to |
| 650 | ** the locking-mode of the main database). |
| 651 | */ |
| 652 | eMode = db->dfltLockMode; |
| 653 | }else{ |
| 654 | Pager *pPager; |
| 655 | if( pId2->n==0 ){ |
| 656 | /* This indicates that no database name was specified as part |
| 657 | ** of the PRAGMA command. In this case the locking-mode must be |
| 658 | ** set on all attached databases, as well as the main db file. |
| 659 | ** |
| 660 | ** Also, the sqlite3.dfltLockMode variable is set so that |
| 661 | ** any subsequently attached databases also use the specified |
| 662 | ** locking mode. |
| 663 | */ |
| 664 | int ii; |
| 665 | assert(pDb==&db->aDb[0]); |
| 666 | for(ii=2; ii<db->nDb; ii++){ |
| 667 | pPager = sqlite3BtreePager(db->aDb[ii].pBt); |
| 668 | sqlite3PagerLockingMode(pPager, eMode); |
| 669 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 670 | db->dfltLockMode = (u8)eMode; |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 671 | } |
| 672 | pPager = sqlite3BtreePager(pDb->pBt); |
| 673 | eMode = sqlite3PagerLockingMode(pPager, eMode); |
| 674 | } |
| 675 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 676 | assert( eMode==PAGER_LOCKINGMODE_NORMAL |
| 677 | || eMode==PAGER_LOCKINGMODE_EXCLUSIVE ); |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 678 | if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){ |
| 679 | zRet = "exclusive"; |
| 680 | } |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 681 | returnSingleText(v, zRet); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 682 | break; |
| 683 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 684 | |
| 685 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 686 | ** PRAGMA [schema.]journal_mode |
| 687 | ** PRAGMA [schema.]journal_mode = |
drh | 3ebaee9 | 2010-05-06 21:37:22 +0000 | [diff] [blame] | 688 | ** (delete|persist|off|truncate|memory|wal|off) |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 689 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 690 | case PragTyp_JOURNAL_MODE: { |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 691 | int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ |
| 692 | int ii; /* Loop counter */ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 693 | |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 694 | if( zRight==0 ){ |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 695 | /* If there is no "=MODE" part of the pragma, do a query for the |
| 696 | ** current mode */ |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 697 | eMode = PAGER_JOURNALMODE_QUERY; |
| 698 | }else{ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 699 | const char *zMode; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 700 | int n = sqlite3Strlen30(zRight); |
drh | f77e2ac | 2010-07-07 14:33:09 +0000 | [diff] [blame] | 701 | for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 702 | if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break; |
| 703 | } |
| 704 | if( !zMode ){ |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 705 | /* If the "=MODE" part does not match any known journal mode, |
| 706 | ** then do a query */ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 707 | eMode = PAGER_JOURNALMODE_QUERY; |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 708 | } |
drh | 6c35b30 | 2019-05-17 20:37:17 +0000 | [diff] [blame] | 709 | if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){ |
| 710 | /* Do not allow journal-mode "OFF" in defensive since the database |
| 711 | ** can become corrupted using ordinary SQL when the journal is off */ |
| 712 | eMode = PAGER_JOURNALMODE_QUERY; |
| 713 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 714 | } |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 715 | if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){ |
| 716 | /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */ |
| 717 | iDb = 0; |
| 718 | pId2->n = 1; |
| 719 | } |
| 720 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 721 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
| 722 | sqlite3VdbeUsesBtree(v, ii); |
| 723 | sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode); |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 724 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 725 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 726 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 727 | break; |
| 728 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 729 | |
| 730 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 731 | ** PRAGMA [schema.]journal_size_limit |
| 732 | ** PRAGMA [schema.]journal_size_limit=N |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 733 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 734 | ** Get or set the size limit on rollback journal files. |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 735 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 736 | case PragTyp_JOURNAL_SIZE_LIMIT: { |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 737 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 738 | i64 iLimit = -2; |
| 739 | if( zRight ){ |
drh | 9296c18 | 2014-07-23 13:40:49 +0000 | [diff] [blame] | 740 | sqlite3DecOrHexToI64(zRight, &iLimit); |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 741 | if( iLimit<-1 ) iLimit = -1; |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 742 | } |
| 743 | iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 744 | returnSingleInt(v, iLimit); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 745 | break; |
| 746 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 747 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 748 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 749 | |
| 750 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 751 | ** PRAGMA [schema.]auto_vacuum |
| 752 | ** PRAGMA [schema.]auto_vacuum=N |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 753 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 754 | ** Get or set the value of the database 'auto-vacuum' parameter. |
| 755 | ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 756 | */ |
| 757 | #ifndef SQLITE_OMIT_AUTOVACUUM |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 758 | case PragTyp_AUTO_VACUUM: { |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 759 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 760 | assert( pBt!=0 ); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 761 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 762 | returnSingleInt(v, sqlite3BtreeGetAutoVacuum(pBt)); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 763 | }else{ |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 764 | int eAuto = getAutoVacuum(zRight); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 765 | assert( eAuto>=0 && eAuto<=2 ); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 766 | db->nextAutovac = (u8)eAuto; |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 767 | /* Call SetAutoVacuum() to set initialize the internal auto and |
| 768 | ** incr-vacuum flags. This is required in case this connection |
| 769 | ** creates the database file. It is important that it is created |
| 770 | ** as an auto-vacuum capable db. |
| 771 | */ |
| 772 | rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 773 | if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 774 | /* When setting the auto_vacuum mode to either "full" or |
| 775 | ** "incremental", write the value of meta[6] in the database |
| 776 | ** file. Before writing to meta[6], check that meta[3] indicates |
| 777 | ** that this really is an auto-vacuum capable database. |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 778 | */ |
drh | b06a4ec | 2014-03-10 18:03:09 +0000 | [diff] [blame] | 779 | static const int iLn = VDBE_OFFSET_LINENO(2); |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 780 | static const VdbeOpList setMeta6[] = { |
| 781 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 782 | { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 783 | { OP_If, 1, 0, 0}, /* 2 */ |
| 784 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 785 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */ |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 786 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 787 | VdbeOp *aOp; |
| 788 | int iAddr = sqlite3VdbeCurrentAddr(v); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 789 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setMeta6)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 790 | aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 791 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 792 | aOp[0].p1 = iDb; |
| 793 | aOp[1].p1 = iDb; |
| 794 | aOp[2].p2 = iAddr+4; |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 795 | aOp[4].p1 = iDb; |
| 796 | aOp[4].p3 = eAuto - 1; |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 797 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 798 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 799 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 800 | break; |
| 801 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 802 | #endif |
| 803 | |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 804 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 805 | ** PRAGMA [schema.]incremental_vacuum(N) |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 806 | ** |
| 807 | ** Do N steps of incremental vacuuming on a database. |
| 808 | */ |
| 809 | #ifndef SQLITE_OMIT_AUTOVACUUM |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 810 | case PragTyp_INCREMENTAL_VACUUM: { |
drh | 00946d7 | 2022-04-01 16:22:41 +0000 | [diff] [blame] | 811 | int iLimit = 0, addr; |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 812 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 813 | iLimit = 0x7fffffff; |
| 814 | } |
| 815 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 4c58312 | 2008-01-04 22:01:03 +0000 | [diff] [blame] | 816 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 817 | addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 818 | sqlite3VdbeAddOp1(v, OP_ResultRow, 1); |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 819 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 820 | sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v); |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 821 | sqlite3VdbeJumpHere(v, addr); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 822 | break; |
| 823 | } |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 824 | #endif |
| 825 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 826 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 827 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 828 | ** PRAGMA [schema.]cache_size |
| 829 | ** PRAGMA [schema.]cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 830 | ** |
| 831 | ** The first form reports the current local setting for the |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 832 | ** page cache size. The second form sets the local |
| 833 | ** page cache size value. If N is positive then that is the |
| 834 | ** number of pages in the cache. If N is negative, then the |
| 835 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 836 | ** of memory. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 837 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 838 | case PragTyp_CACHE_SIZE: { |
drh | 2120608 | 2011-04-04 18:22:02 +0000 | [diff] [blame] | 839 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 840 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 841 | returnSingleInt(v, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 842 | }else{ |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 843 | int size = sqlite3Atoi(zRight); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 844 | pDb->pSchema->cache_size = size; |
| 845 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 846 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 847 | break; |
| 848 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 849 | |
| 850 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 851 | ** PRAGMA [schema.]cache_spill |
| 852 | ** PRAGMA cache_spill=BOOLEAN |
| 853 | ** PRAGMA [schema.]cache_spill=N |
| 854 | ** |
| 855 | ** The first form reports the current local setting for the |
| 856 | ** page cache spill size. The second form turns cache spill on |
| 857 | ** or off. When turnning cache spill on, the size is set to the |
| 858 | ** current cache_size. The third form sets a spill size that |
| 859 | ** may be different form the cache size. |
| 860 | ** If N is positive then that is the |
| 861 | ** number of pages in the cache. If N is negative, then the |
| 862 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 863 | ** of memory. |
| 864 | ** |
| 865 | ** If the number of cache_spill pages is less then the number of |
| 866 | ** cache_size pages, no spilling occurs until the page count exceeds |
| 867 | ** the number of cache_size pages. |
| 868 | ** |
| 869 | ** The cache_spill=BOOLEAN setting applies to all attached schemas, |
| 870 | ** not just the schema specified. |
| 871 | */ |
| 872 | case PragTyp_CACHE_SPILL: { |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 873 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 874 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 875 | returnSingleInt(v, |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 876 | (db->flags & SQLITE_CacheSpill)==0 ? 0 : |
| 877 | sqlite3BtreeSetSpillSize(pDb->pBt,0)); |
| 878 | }else{ |
drh | 4f9c8ec | 2015-11-12 15:47:48 +0000 | [diff] [blame] | 879 | int size = 1; |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 880 | if( sqlite3GetInt32(zRight, &size) ){ |
| 881 | sqlite3BtreeSetSpillSize(pDb->pBt, size); |
| 882 | } |
drh | 4f9c8ec | 2015-11-12 15:47:48 +0000 | [diff] [blame] | 883 | if( sqlite3GetBoolean(zRight, size!=0) ){ |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 884 | db->flags |= SQLITE_CacheSpill; |
| 885 | }else{ |
drh | d5b44d6 | 2018-12-06 17:06:02 +0000 | [diff] [blame] | 886 | db->flags &= ~(u64)SQLITE_CacheSpill; |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 887 | } |
drh | 4f9c8ec | 2015-11-12 15:47:48 +0000 | [diff] [blame] | 888 | setAllPagerFlags(db); |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 889 | } |
| 890 | break; |
| 891 | } |
| 892 | |
| 893 | /* |
| 894 | ** PRAGMA [schema.]mmap_size(N) |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 895 | ** |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 896 | ** Used to set mapping size limit. The mapping size limit is |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 897 | ** used to limit the aggregate size of all memory mapped regions of the |
| 898 | ** database file. If this parameter is set to zero, then memory mapping |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 899 | ** is not used at all. If N is negative, then the default memory map |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 900 | ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set. |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 901 | ** The parameter N is measured in bytes. |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 902 | ** |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 903 | ** This value is advisory. The underlying VFS is free to memory map |
| 904 | ** as little or as much as it wants. Except, if N is set to 0 then the |
| 905 | ** upper layers will never invoke the xFetch interfaces to the VFS. |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 906 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 907 | case PragTyp_MMAP_SIZE: { |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 908 | sqlite3_int64 sz; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 909 | #if SQLITE_MAX_MMAP_SIZE>0 |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 910 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 911 | if( zRight ){ |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 912 | int ii; |
drh | 9296c18 | 2014-07-23 13:40:49 +0000 | [diff] [blame] | 913 | sqlite3DecOrHexToI64(zRight, &sz); |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 914 | if( sz<0 ) sz = sqlite3GlobalConfig.szMmap; |
| 915 | if( pId2->n==0 ) db->szMmap = sz; |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 916 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 917 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 918 | sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz); |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 919 | } |
| 920 | } |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 921 | } |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 922 | sz = -1; |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 923 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz); |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 924 | #else |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 925 | sz = 0; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 926 | rc = SQLITE_OK; |
drh | 188d488 | 2013-04-08 20:47:49 +0000 | [diff] [blame] | 927 | #endif |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 928 | if( rc==SQLITE_OK ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 929 | returnSingleInt(v, sz); |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 930 | }else if( rc!=SQLITE_NOTFOUND ){ |
| 931 | pParse->nErr++; |
| 932 | pParse->rc = rc; |
drh | 34f7490 | 2013-04-03 13:09:18 +0000 | [diff] [blame] | 933 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 934 | break; |
| 935 | } |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 936 | |
| 937 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 938 | ** PRAGMA temp_store |
| 939 | ** PRAGMA temp_store = "default"|"memory"|"file" |
| 940 | ** |
| 941 | ** Return or set the local value of the temp_store flag. Changing |
| 942 | ** the local value does not make changes to the disk file and the default |
| 943 | ** value will be restored the next time the database is opened. |
| 944 | ** |
| 945 | ** Note that it is possible for the library compile-time options to |
| 946 | ** override this setting |
| 947 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 948 | case PragTyp_TEMP_STORE: { |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 949 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 950 | returnSingleInt(v, db->temp_store); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 951 | }else{ |
| 952 | changeTempStorage(pParse, zRight); |
| 953 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 954 | break; |
| 955 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 956 | |
| 957 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 958 | ** PRAGMA temp_store_directory |
| 959 | ** PRAGMA temp_store_directory = ""|"directory_name" |
| 960 | ** |
| 961 | ** Return or set the local value of the temp_store_directory flag. Changing |
| 962 | ** the value sets a specific directory to be used for temporary files. |
| 963 | ** Setting to a null string reverts to the default temporary directory search. |
| 964 | ** If temporary directory is changed, then invalidateTempStorage. |
| 965 | ** |
| 966 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 967 | case PragTyp_TEMP_STORE_DIRECTORY: { |
drh | 18a3a48 | 2022-09-02 00:36:16 +0000 | [diff] [blame] | 968 | sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 969 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 970 | returnSingleText(v, sqlite3_temp_directory); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 971 | }else{ |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 972 | #ifndef SQLITE_OMIT_WSD |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 973 | if( zRight[0] ){ |
| 974 | int res; |
danielk1977 | fab1127 | 2008-09-16 14:38:02 +0000 | [diff] [blame] | 975 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 976 | if( rc!=SQLITE_OK || res==0 ){ |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 977 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
drh | 18a3a48 | 2022-09-02 00:36:16 +0000 | [diff] [blame] | 978 | sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 979 | goto pragma_out; |
| 980 | } |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 981 | } |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 982 | if( SQLITE_TEMP_STORE==0 |
| 983 | || (SQLITE_TEMP_STORE==1 && db->temp_store<=1) |
| 984 | || (SQLITE_TEMP_STORE==2 && db->temp_store==1) |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 985 | ){ |
| 986 | invalidateTempStorage(pParse); |
| 987 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 988 | sqlite3_free(sqlite3_temp_directory); |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 989 | if( zRight[0] ){ |
drh | b975598 | 2010-07-24 16:34:37 +0000 | [diff] [blame] | 990 | sqlite3_temp_directory = sqlite3_mprintf("%s", zRight); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 991 | }else{ |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 992 | sqlite3_temp_directory = 0; |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 993 | } |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 994 | #endif /* SQLITE_OMIT_WSD */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 995 | } |
drh | 18a3a48 | 2022-09-02 00:36:16 +0000 | [diff] [blame] | 996 | sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 997 | break; |
| 998 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 999 | |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1000 | #if SQLITE_OS_WIN |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1001 | /* |
| 1002 | ** PRAGMA data_store_directory |
| 1003 | ** PRAGMA data_store_directory = ""|"directory_name" |
| 1004 | ** |
| 1005 | ** Return or set the local value of the data_store_directory flag. Changing |
| 1006 | ** the value sets a specific directory to be used for database files that |
| 1007 | ** were specified with a relative pathname. Setting to a null string reverts |
| 1008 | ** to the default database directory, which for database files specified with |
| 1009 | ** a relative path will probably be based on the current directory for the |
| 1010 | ** process. Database file specified with an absolute path are not impacted |
| 1011 | ** by this setting, regardless of its value. |
| 1012 | ** |
| 1013 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1014 | case PragTyp_DATA_STORE_DIRECTORY: { |
drh | 18a3a48 | 2022-09-02 00:36:16 +0000 | [diff] [blame] | 1015 | sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1016 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 1017 | returnSingleText(v, sqlite3_data_directory); |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1018 | }else{ |
| 1019 | #ifndef SQLITE_OMIT_WSD |
| 1020 | if( zRight[0] ){ |
| 1021 | int res; |
| 1022 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 1023 | if( rc!=SQLITE_OK || res==0 ){ |
| 1024 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
drh | 18a3a48 | 2022-09-02 00:36:16 +0000 | [diff] [blame] | 1025 | sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1026 | goto pragma_out; |
| 1027 | } |
| 1028 | } |
| 1029 | sqlite3_free(sqlite3_data_directory); |
| 1030 | if( zRight[0] ){ |
| 1031 | sqlite3_data_directory = sqlite3_mprintf("%s", zRight); |
| 1032 | }else{ |
| 1033 | sqlite3_data_directory = 0; |
| 1034 | } |
| 1035 | #endif /* SQLITE_OMIT_WSD */ |
| 1036 | } |
drh | 18a3a48 | 2022-09-02 00:36:16 +0000 | [diff] [blame] | 1037 | sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | } |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1040 | #endif |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1041 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1042 | #if SQLITE_ENABLE_LOCKING_STYLE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1043 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1044 | ** PRAGMA [schema.]lock_proxy_file |
| 1045 | ** PRAGMA [schema.]lock_proxy_file = ":auto:"|"lock_file_path" |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1046 | ** |
| 1047 | ** Return or set the value of the lock_proxy_file flag. Changing |
| 1048 | ** the value sets a specific file to be used for database access locks. |
| 1049 | ** |
| 1050 | */ |
| 1051 | case PragTyp_LOCK_PROXY_FILE: { |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1052 | if( !zRight ){ |
| 1053 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 1054 | char *proxy_file_path = NULL; |
| 1055 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
drh | c02372c | 2012-01-10 17:59:59 +0000 | [diff] [blame] | 1056 | sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1057 | &proxy_file_path); |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 1058 | returnSingleText(v, proxy_file_path); |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1059 | }else{ |
| 1060 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 1061 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
| 1062 | int res; |
| 1063 | if( zRight[0] ){ |
| 1064 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 1065 | zRight); |
| 1066 | } else { |
| 1067 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 1068 | NULL); |
| 1069 | } |
| 1070 | if( res!=SQLITE_OK ){ |
| 1071 | sqlite3ErrorMsg(pParse, "failed to set lock proxy file"); |
| 1072 | goto pragma_out; |
| 1073 | } |
| 1074 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1075 | break; |
| 1076 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1077 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1078 | |
| 1079 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1080 | ** PRAGMA [schema.]synchronous |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 1081 | ** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1082 | ** |
| 1083 | ** Return or set the local value of the synchronous flag. Changing |
| 1084 | ** the local value does not make changes to the disk file and the |
| 1085 | ** default value will be restored the next time the database is |
| 1086 | ** opened. |
| 1087 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1088 | case PragTyp_SYNCHRONOUS: { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1089 | if( !zRight ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 1090 | returnSingleInt(v, pDb->safety_level-1); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1091 | }else{ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1092 | if( !db->autoCommit ){ |
| 1093 | sqlite3ErrorMsg(pParse, |
| 1094 | "Safety level may not be changed inside a transaction"); |
drh | 7553c82 | 2017-03-15 14:04:03 +0000 | [diff] [blame] | 1095 | }else if( iDb!=1 ){ |
drh | d99d283 | 2015-04-17 15:58:33 +0000 | [diff] [blame] | 1096 | int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; |
| 1097 | if( iLevel==0 ) iLevel = 1; |
| 1098 | pDb->safety_level = iLevel; |
drh | 50a1a5a | 2016-03-08 14:40:11 +0000 | [diff] [blame] | 1099 | pDb->bSyncSet = 1; |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 1100 | setAllPagerFlags(db); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1101 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1102 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1103 | break; |
| 1104 | } |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1105 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1106 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 1107 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1108 | case PragTyp_FLAG: { |
| 1109 | if( zRight==0 ){ |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 1110 | setPragmaResultColumnNames(v, pPragma); |
| 1111 | returnSingleInt(v, (db->flags & pPragma->iArg)!=0 ); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1112 | }else{ |
drh | fd748c6 | 2018-10-30 16:25:35 +0000 | [diff] [blame] | 1113 | u64 mask = pPragma->iArg; /* Mask of bits to set or clear. */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1114 | if( db->autoCommit==0 ){ |
| 1115 | /* Foreign key support may not be enabled or disabled while not |
| 1116 | ** in auto-commit mode. */ |
| 1117 | mask &= ~(SQLITE_ForeignKeys); |
| 1118 | } |
drh | d453097 | 2014-09-09 14:47:53 +0000 | [diff] [blame] | 1119 | #if SQLITE_USER_AUTHENTICATION |
drh | b2445d5 | 2014-09-11 14:01:41 +0000 | [diff] [blame] | 1120 | if( db->auth.authLevel==UAUTH_User ){ |
drh | d453097 | 2014-09-09 14:47:53 +0000 | [diff] [blame] | 1121 | /* Do not allow non-admin users to modify the schema arbitrarily */ |
| 1122 | mask &= ~(SQLITE_WriteSchema); |
| 1123 | } |
| 1124 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1125 | |
| 1126 | if( sqlite3GetBoolean(zRight, 0) ){ |
drh | 2eeca20 | 2020-01-08 20:37:45 +0000 | [diff] [blame] | 1127 | db->flags |= mask; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1128 | }else{ |
| 1129 | db->flags &= ~mask; |
| 1130 | if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0; |
drh | 635e6a9 | 2021-10-08 16:39:33 +0000 | [diff] [blame] | 1131 | if( (mask & SQLITE_WriteSchema)!=0 |
| 1132 | && sqlite3_stricmp(zRight, "reset")==0 |
| 1133 | ){ |
drh | bc98f90 | 2021-10-14 17:30:32 +0000 | [diff] [blame] | 1134 | /* IMP: R-60817-01178 If the argument is "RESET" then schema |
| 1135 | ** writing is disabled (as with "PRAGMA writable_schema=OFF") and, |
| 1136 | ** in addition, the schema is reloaded. */ |
drh | 635e6a9 | 2021-10-08 16:39:33 +0000 | [diff] [blame] | 1137 | sqlite3ResetAllSchemasOfConnection(db); |
| 1138 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /* Many of the flag-pragmas modify the code generated by the SQL |
| 1142 | ** compiler (eg. count_changes). So add an opcode to expire all |
| 1143 | ** compiled SQL statements after modifying a pragma value. |
| 1144 | */ |
drh | 01c736d | 2016-05-20 15:15:07 +0000 | [diff] [blame] | 1145 | sqlite3VdbeAddOp0(v, OP_Expire); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1146 | setAllPagerFlags(db); |
| 1147 | } |
| 1148 | break; |
| 1149 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 1150 | #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1151 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1152 | #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1153 | /* |
| 1154 | ** PRAGMA table_info(<table>) |
| 1155 | ** |
| 1156 | ** Return a single row for each column of the named table. The columns of |
| 1157 | ** the returned data set are: |
| 1158 | ** |
| 1159 | ** cid: Column id (numbered from left to right, starting at 0) |
| 1160 | ** name: Column name |
| 1161 | ** type: Column declaration type. |
| 1162 | ** notnull: True if 'NOT NULL' is part of column declaration |
| 1163 | ** dflt_value: The default value for the column, if any. |
dan | 3e6ac16 | 2016-02-11 21:01:16 +0000 | [diff] [blame] | 1164 | ** pk: Non-zero for PK fields. |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1165 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1166 | case PragTyp_TABLE_INFO: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1167 | Table *pTab; |
drh | a78d2c0 | 2020-07-04 20:29:56 +0000 | [diff] [blame] | 1168 | sqlite3CodeVerifyNamedSchema(pParse, zDb); |
drh | 4d249e6 | 2016-06-10 22:49:01 +0000 | [diff] [blame] | 1169 | pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1170 | if( pTab ){ |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1171 | int i, k; |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 1172 | int nHidden = 0; |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 1173 | Column *pCol; |
drh | 4415628 | 2013-10-23 22:23:03 +0000 | [diff] [blame] | 1174 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
drh | d7dc0a3 | 2018-10-01 18:28:42 +0000 | [diff] [blame] | 1175 | pParse->nMem = 7; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1176 | sqlite3ViewGetColumnNames(pParse, pTab); |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 1177 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
drh | ab3c5f2 | 2019-10-17 13:15:40 +0000 | [diff] [blame] | 1178 | int isHidden = 0; |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 1179 | const Expr *pColExpr; |
drh | ab3c5f2 | 2019-10-17 13:15:40 +0000 | [diff] [blame] | 1180 | if( pCol->colFlags & COLFLAG_NOINSERT ){ |
drh | 676fa25 | 2019-10-17 14:21:07 +0000 | [diff] [blame] | 1181 | if( pPragma->iArg==0 ){ |
| 1182 | nHidden++; |
| 1183 | continue; |
| 1184 | } |
drh | ab3c5f2 | 2019-10-17 13:15:40 +0000 | [diff] [blame] | 1185 | if( pCol->colFlags & COLFLAG_VIRTUAL ){ |
| 1186 | isHidden = 2; /* GENERATED ALWAYS AS ... VIRTUAL */ |
drh | c143114 | 2019-10-17 17:54:05 +0000 | [diff] [blame] | 1187 | }else if( pCol->colFlags & COLFLAG_STORED ){ |
drh | ab3c5f2 | 2019-10-17 13:15:40 +0000 | [diff] [blame] | 1188 | isHidden = 3; /* GENERATED ALWAYS AS ... STORED */ |
drh | c143114 | 2019-10-17 17:54:05 +0000 | [diff] [blame] | 1189 | }else{ assert( pCol->colFlags & COLFLAG_HIDDEN ); |
drh | ab3c5f2 | 2019-10-17 13:15:40 +0000 | [diff] [blame] | 1190 | isHidden = 1; /* HIDDEN */ |
| 1191 | } |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 1192 | } |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1193 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 1194 | k = 0; |
| 1195 | }else if( pPk==0 ){ |
| 1196 | k = 1; |
| 1197 | }else{ |
drh | 1b67896 | 2015-04-15 07:19:27 +0000 | [diff] [blame] | 1198 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1199 | } |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 1200 | pColExpr = sqlite3ColumnExpr(pTab,pCol); |
| 1201 | assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 ); |
drh | 9d43db5 | 2021-10-07 14:19:32 +0000 | [diff] [blame] | 1202 | assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue) |
| 1203 | || isHidden>=2 ); |
drh | d7dc0a3 | 2018-10-01 18:28:42 +0000 | [diff] [blame] | 1204 | sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1205 | i-nHidden, |
drh | cf9d36d | 2021-08-02 18:03:43 +0000 | [diff] [blame] | 1206 | pCol->zCnName, |
drh | d756486 | 2016-03-22 20:05:09 +0000 | [diff] [blame] | 1207 | sqlite3ColumnType(pCol,""), |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1208 | pCol->notNull ? 1 : 0, |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 1209 | (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken, |
drh | d7dc0a3 | 2018-10-01 18:28:42 +0000 | [diff] [blame] | 1210 | k, |
| 1211 | isHidden); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1212 | } |
| 1213 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1214 | } |
| 1215 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1216 | |
drh | 2e50f67 | 2021-09-21 17:26:23 +0000 | [diff] [blame] | 1217 | /* |
| 1218 | ** PRAGMA table_list |
| 1219 | ** |
| 1220 | ** Return a single row for each table, virtual table, or view in the |
| 1221 | ** entire schema. |
| 1222 | ** |
| 1223 | ** schema: Name of attached database hold this table |
| 1224 | ** name: Name of the table itself |
| 1225 | ** type: "table", "view", "virtual", "shadow" |
| 1226 | ** ncol: Number of columns |
| 1227 | ** wr: True for a WITHOUT ROWID table |
| 1228 | ** strict: True for a STRICT table |
| 1229 | */ |
| 1230 | case PragTyp_TABLE_LIST: { |
| 1231 | int ii; |
| 1232 | pParse->nMem = 6; |
| 1233 | sqlite3CodeVerifyNamedSchema(pParse, zDb); |
| 1234 | for(ii=0; ii<db->nDb; ii++){ |
| 1235 | HashElem *k; |
| 1236 | Hash *pHash; |
drh | dc88b40 | 2021-10-21 19:48:14 +0000 | [diff] [blame] | 1237 | int initNCol; |
drh | 2e50f67 | 2021-09-21 17:26:23 +0000 | [diff] [blame] | 1238 | if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue; |
drh | dc88b40 | 2021-10-21 19:48:14 +0000 | [diff] [blame] | 1239 | |
| 1240 | /* Ensure that the Table.nCol field is initialized for all views |
| 1241 | ** and virtual tables. Each time we initialize a Table.nCol value |
| 1242 | ** for a table, that can potentially disrupt the hash table, so restart |
| 1243 | ** the initialization scan. |
| 1244 | */ |
drh | 2e50f67 | 2021-09-21 17:26:23 +0000 | [diff] [blame] | 1245 | pHash = &db->aDb[ii].pSchema->tblHash; |
drh | dc88b40 | 2021-10-21 19:48:14 +0000 | [diff] [blame] | 1246 | initNCol = sqliteHashCount(pHash); |
| 1247 | while( initNCol-- ){ |
| 1248 | for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){ |
| 1249 | Table *pTab; |
| 1250 | if( k==0 ){ initNCol = 0; break; } |
| 1251 | pTab = sqliteHashData(k); |
| 1252 | if( pTab->nCol==0 ){ |
| 1253 | char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName); |
| 1254 | if( zSql ){ |
| 1255 | sqlite3_stmt *pDummy = 0; |
| 1256 | (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0); |
| 1257 | (void)sqlite3_finalize(pDummy); |
| 1258 | sqlite3DbFree(db, zSql); |
| 1259 | } |
drh | 0c7d3d3 | 2022-01-24 16:47:12 +0000 | [diff] [blame] | 1260 | if( db->mallocFailed ){ |
| 1261 | sqlite3ErrorMsg(db->pParse, "out of memory"); |
| 1262 | db->pParse->rc = SQLITE_NOMEM_BKPT; |
| 1263 | } |
drh | dc88b40 | 2021-10-21 19:48:14 +0000 | [diff] [blame] | 1264 | pHash = &db->aDb[ii].pSchema->tblHash; |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
drh | 2e50f67 | 2021-09-21 17:26:23 +0000 | [diff] [blame] | 1270 | for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){ |
| 1271 | Table *pTab = sqliteHashData(k); |
| 1272 | const char *zType; |
| 1273 | if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue; |
| 1274 | if( IsView(pTab) ){ |
| 1275 | zType = "view"; |
| 1276 | }else if( IsVirtual(pTab) ){ |
| 1277 | zType = "virtual"; |
| 1278 | }else if( pTab->tabFlags & TF_Shadow ){ |
| 1279 | zType = "shadow"; |
| 1280 | }else{ |
| 1281 | zType = "table"; |
| 1282 | } |
| 1283 | sqlite3VdbeMultiLoad(v, 1, "sssiii", |
| 1284 | db->aDb[ii].zDbSName, |
drh | a4a871c | 2021-11-04 14:04:20 +0000 | [diff] [blame] | 1285 | sqlite3PreferredTableName(pTab->zName), |
drh | 2e50f67 | 2021-09-21 17:26:23 +0000 | [diff] [blame] | 1286 | zType, |
| 1287 | pTab->nCol, |
| 1288 | (pTab->tabFlags & TF_WithoutRowid)!=0, |
| 1289 | (pTab->tabFlags & TF_Strict)!=0 |
| 1290 | ); |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | break; |
| 1295 | |
drh | 33bec3f | 2017-02-17 13:38:15 +0000 | [diff] [blame] | 1296 | #ifdef SQLITE_DEBUG |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1297 | case PragTyp_STATS: { |
| 1298 | Index *pIdx; |
| 1299 | HashElem *i; |
drh | 33bec3f | 2017-02-17 13:38:15 +0000 | [diff] [blame] | 1300 | pParse->nMem = 5; |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1301 | sqlite3CodeVerifySchema(pParse, iDb); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1302 | for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 1303 | Table *pTab = sqliteHashData(i); |
drh | 33bec3f | 2017-02-17 13:38:15 +0000 | [diff] [blame] | 1304 | sqlite3VdbeMultiLoad(v, 1, "ssiii", |
drh | a4a871c | 2021-11-04 14:04:20 +0000 | [diff] [blame] | 1305 | sqlite3PreferredTableName(pTab->zName), |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1306 | 0, |
drh | d566c95 | 2016-02-25 21:19:03 +0000 | [diff] [blame] | 1307 | pTab->szTabRow, |
drh | 33bec3f | 2017-02-17 13:38:15 +0000 | [diff] [blame] | 1308 | pTab->nRowLogEst, |
| 1309 | pTab->tabFlags); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1310 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 40cf27c | 2017-07-07 16:00:53 +0000 | [diff] [blame] | 1311 | sqlite3VdbeMultiLoad(v, 2, "siiiX", |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1312 | pIdx->zName, |
drh | d566c95 | 2016-02-25 21:19:03 +0000 | [diff] [blame] | 1313 | pIdx->szIdxRow, |
drh | 33bec3f | 2017-02-17 13:38:15 +0000 | [diff] [blame] | 1314 | pIdx->aiRowLogEst[0], |
| 1315 | pIdx->hasStat1); |
| 1316 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | break; |
drh | 33bec3f | 2017-02-17 13:38:15 +0000 | [diff] [blame] | 1321 | #endif |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1322 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1323 | case PragTyp_INDEX_INFO: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1324 | Index *pIdx; |
| 1325 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1326 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
drh | 7b1904e | 2019-07-17 11:01:11 +0000 | [diff] [blame] | 1327 | if( pIdx==0 ){ |
| 1328 | /* If there is no index named zRight, check to see if there is a |
| 1329 | ** WITHOUT ROWID table named zRight, and if there is, show the |
| 1330 | ** structure of the PRIMARY KEY index for that table. */ |
| 1331 | pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb); |
| 1332 | if( pTab && !HasRowid(pTab) ){ |
| 1333 | pIdx = sqlite3PrimaryKeyIndex(pTab); |
| 1334 | } |
| 1335 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1336 | if( pIdx ){ |
dan | 3c42548 | 2018-11-20 18:09:59 +0000 | [diff] [blame] | 1337 | int iIdxDb = sqlite3SchemaToIndex(db, pIdx->pSchema); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1338 | int i; |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1339 | int mx; |
| 1340 | if( pPragma->iArg ){ |
| 1341 | /* PRAGMA index_xinfo (newer version with more rows and columns) */ |
| 1342 | mx = pIdx->nColumn; |
| 1343 | pParse->nMem = 6; |
| 1344 | }else{ |
| 1345 | /* PRAGMA index_info (legacy version) */ |
| 1346 | mx = pIdx->nKeyCol; |
| 1347 | pParse->nMem = 3; |
| 1348 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1349 | pTab = pIdx->pTable; |
dan | 3c42548 | 2018-11-20 18:09:59 +0000 | [diff] [blame] | 1350 | sqlite3CodeVerifySchema(pParse, iIdxDb); |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 1351 | assert( pParse->nMem<=pPragma->nPragCName ); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1352 | for(i=0; i<mx; i++){ |
drh | bbbdc83 | 2013-10-22 18:01:40 +0000 | [diff] [blame] | 1353 | i16 cnum = pIdx->aiColumn[i]; |
drh | 40cf27c | 2017-07-07 16:00:53 +0000 | [diff] [blame] | 1354 | sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum, |
drh | cf9d36d | 2021-08-02 18:03:43 +0000 | [diff] [blame] | 1355 | cnum<0 ? 0 : pTab->aCol[cnum].zCnName); |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1356 | if( pPragma->iArg ){ |
drh | 40cf27c | 2017-07-07 16:00:53 +0000 | [diff] [blame] | 1357 | sqlite3VdbeMultiLoad(v, 4, "isiX", |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1358 | pIdx->aSortOrder[i], |
| 1359 | pIdx->azColl[i], |
| 1360 | i<pIdx->nKeyCol); |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1361 | } |
| 1362 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1363 | } |
| 1364 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1365 | } |
| 1366 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1367 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1368 | case PragTyp_INDEX_LIST: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1369 | Index *pIdx; |
| 1370 | Table *pTab; |
drh | e13e9f5 | 2013-10-05 19:18:00 +0000 | [diff] [blame] | 1371 | int i; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1372 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1373 | if( pTab ){ |
dan | 3c42548 | 2018-11-20 18:09:59 +0000 | [diff] [blame] | 1374 | int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1375 | pParse->nMem = 5; |
dan | 3c42548 | 2018-11-20 18:09:59 +0000 | [diff] [blame] | 1376 | sqlite3CodeVerifySchema(pParse, iTabDb); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1377 | for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1378 | const char *azOrigin[] = { "c", "u", "pk" }; |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1379 | sqlite3VdbeMultiLoad(v, 1, "isisi", |
| 1380 | i, |
| 1381 | pIdx->zName, |
| 1382 | IsUniqueIndex(pIdx), |
| 1383 | azOrigin[pIdx->idxType], |
| 1384 | pIdx->pPartIdxWhere!=0); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1385 | } |
| 1386 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1387 | } |
| 1388 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1389 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1390 | case PragTyp_DATABASE_LIST: { |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1391 | int i; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1392 | pParse->nMem = 3; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1393 | for(i=0; i<db->nDb; i++){ |
| 1394 | if( db->aDb[i].pBt==0 ) continue; |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 1395 | assert( db->aDb[i].zDbSName!=0 ); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1396 | sqlite3VdbeMultiLoad(v, 1, "iss", |
| 1397 | i, |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 1398 | db->aDb[i].zDbSName, |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1399 | sqlite3BtreeGetFilename(db->aDb[i].pBt)); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1400 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1401 | } |
| 1402 | break; |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1403 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1404 | case PragTyp_COLLATION_LIST: { |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1405 | int i = 0; |
| 1406 | HashElem *p; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1407 | pParse->nMem = 2; |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1408 | for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){ |
| 1409 | CollSeq *pColl = (CollSeq *)sqliteHashData(p); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1410 | sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1411 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1412 | } |
| 1413 | break; |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1414 | |
drh | cc3f3d1 | 2019-08-17 15:27:58 +0000 | [diff] [blame] | 1415 | #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1416 | case PragTyp_FUNCTION_LIST: { |
| 1417 | int i; |
| 1418 | HashElem *j; |
| 1419 | FuncDef *p; |
drh | 337ca51 | 2020-01-04 19:58:28 +0000 | [diff] [blame] | 1420 | int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0; |
drh | 79d5bc8 | 2020-01-04 01:43:02 +0000 | [diff] [blame] | 1421 | pParse->nMem = 6; |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1422 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 1423 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){ |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 1424 | assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
drh | 337ca51 | 2020-01-04 19:58:28 +0000 | [diff] [blame] | 1425 | pragmaFunclistLine(v, p, 1, showInternFunc); |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){ |
| 1429 | p = (FuncDef*)sqliteHashData(j); |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 1430 | assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 ); |
drh | 337ca51 | 2020-01-04 19:58:28 +0000 | [diff] [blame] | 1431 | pragmaFunclistLine(v, p, 0, showInternFunc); |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | break; |
| 1435 | |
| 1436 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 1437 | case PragTyp_MODULE_LIST: { |
| 1438 | HashElem *j; |
| 1439 | pParse->nMem = 1; |
| 1440 | for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){ |
| 1441 | Module *pMod = (Module*)sqliteHashData(j); |
| 1442 | sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName); |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1443 | } |
| 1444 | } |
| 1445 | break; |
| 1446 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 1447 | |
drh | 8ae11aa | 2017-07-07 17:33:07 +0000 | [diff] [blame] | 1448 | case PragTyp_PRAGMA_LIST: { |
| 1449 | int i; |
| 1450 | for(i=0; i<ArraySize(aPragmaName); i++){ |
| 1451 | sqlite3VdbeMultiLoad(v, 1, "s", aPragmaName[i].zName); |
drh | 8ae11aa | 2017-07-07 17:33:07 +0000 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | break; |
| 1455 | #endif /* SQLITE_INTROSPECTION_PRAGMAS */ |
drh | ab53bb6 | 2017-07-07 15:43:22 +0000 | [diff] [blame] | 1456 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1457 | #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ |
| 1458 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1459 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1460 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1461 | FKey *pFK; |
| 1462 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1463 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | 78b2fa8 | 2021-10-07 12:11:20 +0000 | [diff] [blame] | 1464 | if( pTab && IsOrdinaryTable(pTab) ){ |
drh | f38524d | 2021-08-02 16:41:57 +0000 | [diff] [blame] | 1465 | pFK = pTab->u.tab.pFKey; |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1466 | if( pFK ){ |
dan | 3c42548 | 2018-11-20 18:09:59 +0000 | [diff] [blame] | 1467 | int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1468 | int i = 0; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1469 | pParse->nMem = 8; |
dan | 3c42548 | 2018-11-20 18:09:59 +0000 | [diff] [blame] | 1470 | sqlite3CodeVerifySchema(pParse, iTabDb); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1471 | while(pFK){ |
| 1472 | int j; |
| 1473 | for(j=0; j<pFK->nCol; j++){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1474 | sqlite3VdbeMultiLoad(v, 1, "iissssss", |
| 1475 | i, |
| 1476 | j, |
| 1477 | pFK->zTo, |
drh | cf9d36d | 2021-08-02 18:03:43 +0000 | [diff] [blame] | 1478 | pTab->aCol[pFK->aCol[j].iFrom].zCnName, |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1479 | pFK->aCol[j].zCol, |
| 1480 | actionName(pFK->aAction[1]), /* ON UPDATE */ |
| 1481 | actionName(pFK->aAction[0]), /* ON DELETE */ |
| 1482 | "NONE"); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1483 | } |
| 1484 | ++i; |
| 1485 | pFK = pFK->pNextFrom; |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1486 | } |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1489 | } |
| 1490 | break; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1491 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1492 | |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1493 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
dan | 09ff9e1 | 2013-03-11 11:49:03 +0000 | [diff] [blame] | 1494 | #ifndef SQLITE_OMIT_TRIGGER |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1495 | case PragTyp_FOREIGN_KEY_CHECK: { |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1496 | FKey *pFK; /* A foreign key constraint */ |
| 1497 | Table *pTab; /* Child table contain "REFERENCES" keyword */ |
| 1498 | Table *pParent; /* Parent table that child points to */ |
| 1499 | Index *pIdx; /* Index in the parent table */ |
| 1500 | int i; /* Loop counter: Foreign key number for pTab */ |
| 1501 | int j; /* Loop counter: Field of the foreign key */ |
| 1502 | HashElem *k; /* Loop counter: Next table in schema */ |
| 1503 | int x; /* result variable */ |
| 1504 | int regResult; /* 3 registers to hold a result row */ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1505 | int regRow; /* Registers to hold a row from pTab */ |
| 1506 | int addrTop; /* Top of a loop checking foreign keys */ |
| 1507 | int addrOk; /* Jump here if the key is OK */ |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1508 | int *aiCols; /* child to parent column mapping */ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1509 | |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1510 | regResult = pParse->nMem+1; |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1511 | pParse->nMem += 4; |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1512 | regRow = ++pParse->nMem; |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1513 | k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash); |
| 1514 | while( k ){ |
| 1515 | if( zRight ){ |
| 1516 | pTab = sqlite3LocateTable(pParse, 0, zRight, zDb); |
| 1517 | k = 0; |
| 1518 | }else{ |
| 1519 | pTab = (Table*)sqliteHashData(k); |
| 1520 | k = sqliteHashNext(k); |
| 1521 | } |
drh | 78b2fa8 | 2021-10-07 12:11:20 +0000 | [diff] [blame] | 1522 | if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue; |
drh | ec1650a | 2020-07-03 12:15:59 +0000 | [diff] [blame] | 1523 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 1524 | zDb = db->aDb[iDb].zDbSName; |
| 1525 | sqlite3CodeVerifySchema(pParse, iDb); |
| 1526 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1527 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
drh | ec1650a | 2020-07-03 12:15:59 +0000 | [diff] [blame] | 1528 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1529 | sqlite3VdbeLoadString(v, regResult, pTab->zName); |
drh | 78b2fa8 | 2021-10-07 12:11:20 +0000 | [diff] [blame] | 1530 | assert( IsOrdinaryTable(pTab) ); |
drh | f38524d | 2021-08-02 16:41:57 +0000 | [diff] [blame] | 1531 | for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1532 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 1533 | if( pParent==0 ) continue; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1534 | pIdx = 0; |
drh | ec1650a | 2020-07-03 12:15:59 +0000 | [diff] [blame] | 1535 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1536 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1537 | if( x==0 ){ |
| 1538 | if( pIdx==0 ){ |
drh | ec1650a | 2020-07-03 12:15:59 +0000 | [diff] [blame] | 1539 | sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1540 | }else{ |
drh | ec1650a | 2020-07-03 12:15:59 +0000 | [diff] [blame] | 1541 | sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb); |
drh | 2ec2fb2 | 2013-11-06 19:59:23 +0000 | [diff] [blame] | 1542 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1543 | } |
| 1544 | }else{ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1545 | k = 0; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1546 | break; |
| 1547 | } |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1548 | } |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1549 | assert( pParse->nErr>0 || pFK==0 ); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1550 | if( pFK ) break; |
| 1551 | if( pParse->nTab<i ) pParse->nTab = i; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1552 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
drh | 78b2fa8 | 2021-10-07 12:11:20 +0000 | [diff] [blame] | 1553 | assert( IsOrdinaryTable(pTab) ); |
drh | f38524d | 2021-08-02 16:41:57 +0000 | [diff] [blame] | 1554 | for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1555 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1556 | pIdx = 0; |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1557 | aiCols = 0; |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1558 | if( pParent ){ |
| 1559 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
drh | d96e382 | 2020-09-16 19:48:23 +0000 | [diff] [blame] | 1560 | assert( x==0 || db->mallocFailed ); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1561 | } |
drh | ec4ccdb | 2018-12-29 02:26:59 +0000 | [diff] [blame] | 1562 | addrOk = sqlite3VdbeMakeLabel(pParse); |
dan | 4bee559 | 2017-04-17 18:42:33 +0000 | [diff] [blame] | 1563 | |
| 1564 | /* Generate code to read the child key values into registers |
| 1565 | ** regRow..regRow+n. If any of the child key values are NULL, this |
| 1566 | ** row cannot cause an FK violation. Jump directly to addrOk in |
| 1567 | ** this case. */ |
drh | 4f16ff9 | 2021-07-07 16:48:24 +0000 | [diff] [blame] | 1568 | if( regRow+pFK->nCol>pParse->nMem ) pParse->nMem = regRow+pFK->nCol; |
dan | 4bee559 | 2017-04-17 18:42:33 +0000 | [diff] [blame] | 1569 | for(j=0; j<pFK->nCol; j++){ |
| 1570 | int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom; |
| 1571 | sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j); |
| 1572 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1573 | } |
dan | 4bee559 | 2017-04-17 18:42:33 +0000 | [diff] [blame] | 1574 | |
| 1575 | /* Generate code to query the parent index for a matching parent |
| 1576 | ** key. If a match is found, jump to addrOk. */ |
| 1577 | if( pIdx ){ |
drh | 36d2d09 | 2022-04-04 18:17:59 +0000 | [diff] [blame] | 1578 | sqlite3VdbeAddOp4(v, OP_Affinity, regRow, pFK->nCol, 0, |
dan | 4bee559 | 2017-04-17 18:42:33 +0000 | [diff] [blame] | 1579 | sqlite3IndexAffinityStr(db,pIdx), pFK->nCol); |
drh | 36d2d09 | 2022-04-04 18:17:59 +0000 | [diff] [blame] | 1580 | sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regRow, pFK->nCol); |
dan | 4bee559 | 2017-04-17 18:42:33 +0000 | [diff] [blame] | 1581 | VdbeCoverage(v); |
| 1582 | }else if( pParent ){ |
| 1583 | int jmp = sqlite3VdbeCurrentAddr(v)+2; |
| 1584 | sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v); |
| 1585 | sqlite3VdbeGoto(v, addrOk); |
drh | d96e382 | 2020-09-16 19:48:23 +0000 | [diff] [blame] | 1586 | assert( pFK->nCol==1 || db->mallocFailed ); |
dan | 4bee559 | 2017-04-17 18:42:33 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /* Generate code to report an FK violation to the caller. */ |
dan | 940464b | 2017-04-17 18:02:41 +0000 | [diff] [blame] | 1590 | if( HasRowid(pTab) ){ |
| 1591 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); |
| 1592 | }else{ |
| 1593 | sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1); |
| 1594 | } |
drh | 40cf27c | 2017-07-07 16:00:53 +0000 | [diff] [blame] | 1595 | sqlite3VdbeMultiLoad(v, regResult+2, "siX", pFK->zTo, i-1); |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1596 | sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1597 | sqlite3VdbeResolveLabel(v, addrOk); |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1598 | sqlite3DbFree(db, aiCols); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1599 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1600 | sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1601 | sqlite3VdbeJumpHere(v, addrTop); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1602 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1603 | } |
| 1604 | break; |
dan | 09ff9e1 | 2013-03-11 11:49:03 +0000 | [diff] [blame] | 1605 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1606 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 1607 | |
drh | 08652b5 | 2019-05-08 17:27:18 +0000 | [diff] [blame] | 1608 | #ifndef SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1609 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 1610 | ** used will be case sensitive or not depending on the RHS. |
| 1611 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1612 | case PragTyp_CASE_SENSITIVE_LIKE: { |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1613 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 1614 | sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0)); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1615 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1616 | } |
| 1617 | break; |
drh | 08652b5 | 2019-05-08 17:27:18 +0000 | [diff] [blame] | 1618 | #endif /* SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA */ |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1619 | |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1620 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 1621 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| 1622 | #endif |
| 1623 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1624 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 1625 | /* PRAGMA integrity_check |
| 1626 | ** PRAGMA integrity_check(N) |
| 1627 | ** PRAGMA quick_check |
| 1628 | ** PRAGMA quick_check(N) |
| 1629 | ** |
| 1630 | ** Verify the integrity of the database. |
| 1631 | ** |
| 1632 | ** The "quick_check" is reduced version of |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1633 | ** integrity_check designed to detect most database corruption |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 1634 | ** without the overhead of cross-checking indexes. Quick_check |
| 1635 | ** is linear time wherease integrity_check is O(NlogN). |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1636 | ** |
| 1637 | ** The maximum nubmer of errors is 100 by default. A different default |
| 1638 | ** can be specified using a numeric parameter N. |
| 1639 | ** |
| 1640 | ** Or, the parameter N can be the name of a table. In that case, only |
| 1641 | ** the one table named is verified. The freelist is only verified if |
| 1642 | ** the named table is "sqlite_schema" (or one of its aliases). |
| 1643 | ** |
| 1644 | ** All schemas are checked by default. To check just a single |
| 1645 | ** schema, use the form: |
| 1646 | ** |
| 1647 | ** PRAGMA schema.integrity_check; |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1648 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1649 | case PragTyp_INTEGRITY_CHECK: { |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1650 | int i, j, addr, mxErr; |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1651 | Table *pObjTab = 0; /* Check only this one table, if not NULL */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1652 | |
drh | c522731 | 2011-10-13 17:09:01 +0000 | [diff] [blame] | 1653 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1654 | |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1655 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 1656 | ** then iDb is set to the index of the database identified by <db>. |
| 1657 | ** In this case, the integrity of database iDb only is verified by |
| 1658 | ** the VDBE created below. |
| 1659 | ** |
| 1660 | ** Otherwise, if the command was simply "PRAGMA integrity_check" (or |
| 1661 | ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb |
| 1662 | ** to -1 here, to indicate that the VDBE should verify the integrity |
| 1663 | ** of all attached databases. */ |
| 1664 | assert( iDb>=0 ); |
| 1665 | assert( iDb==0 || pId2->z ); |
| 1666 | if( pId2->z==0 ) iDb = -1; |
| 1667 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1668 | /* Initialize the VDBE program */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1669 | pParse->nMem = 6; |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1670 | |
| 1671 | /* Set the maximum error count */ |
| 1672 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1673 | if( zRight ){ |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1674 | if( sqlite3GetInt32(zRight, &mxErr) ){ |
| 1675 | if( mxErr<=0 ){ |
| 1676 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1677 | } |
| 1678 | }else{ |
| 1679 | pObjTab = sqlite3LocateTable(pParse, 0, zRight, |
| 1680 | iDb>=0 ? db->aDb[iDb].zDbSName : 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1681 | } |
| 1682 | } |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 1683 | sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1684 | |
| 1685 | /* Do an integrity check on each database file */ |
| 1686 | for(i=0; i<db->nDb; i++){ |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 1687 | HashElem *x; /* For looping over tables in the schema */ |
| 1688 | Hash *pTbls; /* Set of all tables in the schema */ |
| 1689 | int *aRoot; /* Array of root page numbers of all btrees */ |
| 1690 | int cnt = 0; /* Number of entries in aRoot[] */ |
| 1691 | int mxIdx = 0; /* Maximum number of indexes for any table */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1692 | |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1693 | if( OMIT_TEMPDB && i==1 ) continue; |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1694 | if( iDb>=0 && i!=iDb ) continue; |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1695 | |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1696 | sqlite3CodeVerifySchema(pParse, i); |
| 1697 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1698 | /* Do an integrity check of the B-Tree |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1699 | ** |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1700 | ** Begin by finding the root pages numbers |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1701 | ** for all tables and indices in the database. |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1702 | */ |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1703 | assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1704 | pTbls = &db->aDb[i].pSchema->tblHash; |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1705 | for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 1706 | Table *pTab = sqliteHashData(x); /* Current table */ |
| 1707 | Index *pIdx; /* An index on pTab */ |
| 1708 | int nIdx; /* Number of indexes on pTab */ |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1709 | if( pObjTab && pObjTab!=pTab ) continue; |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1710 | if( HasRowid(pTab) ) cnt++; |
drh | bb9b5f2 | 2016-03-19 00:35:02 +0000 | [diff] [blame] | 1711 | for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; } |
| 1712 | if( nIdx>mxIdx ) mxIdx = nIdx; |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1713 | } |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1714 | if( cnt==0 ) continue; |
| 1715 | if( pObjTab ) cnt++; |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1716 | aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1)); |
| 1717 | if( aRoot==0 ) break; |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1718 | cnt = 0; |
| 1719 | if( pObjTab ) aRoot[++cnt] = 0; |
| 1720 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1721 | Table *pTab = sqliteHashData(x); |
| 1722 | Index *pIdx; |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1723 | if( pObjTab && pObjTab!=pTab ) continue; |
drh | b5c1063 | 2017-09-21 00:49:15 +0000 | [diff] [blame] | 1724 | if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum; |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1725 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | b5c1063 | 2017-09-21 00:49:15 +0000 | [diff] [blame] | 1726 | aRoot[++cnt] = pIdx->tnum; |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1727 | } |
| 1728 | } |
drh | b5c1063 | 2017-09-21 00:49:15 +0000 | [diff] [blame] | 1729 | aRoot[0] = cnt; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1730 | |
| 1731 | /* Make sure sufficient number of registers have been allocated */ |
drh | bb9b5f2 | 2016-03-19 00:35:02 +0000 | [diff] [blame] | 1732 | pParse->nMem = MAX( pParse->nMem, 8+mxIdx ); |
drh | 3963e58 | 2017-07-15 20:33:19 +0000 | [diff] [blame] | 1733 | sqlite3ClearTempRegCache(pParse); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1734 | |
| 1735 | /* Do the b-tree integrity checks */ |
drh | 98968b2 | 2016-03-15 22:00:39 +0000 | [diff] [blame] | 1736 | sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 1737 | sqlite3VdbeChangeP5(v, (u8)i); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1738 | addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1739 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 1740 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName), |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1741 | P4_DYNAMIC); |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 1742 | sqlite3VdbeAddOp3(v, OP_Concat, 2, 3, 3); |
| 1743 | integrityCheckResultRow(v); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1744 | sqlite3VdbeJumpHere(v, addr); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1745 | |
| 1746 | /* Make sure all the indices are constructed correctly. |
| 1747 | */ |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 1748 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1749 | Table *pTab = sqliteHashData(x); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1750 | Index *pIdx, *pPk; |
drh | 16b03c0 | 2022-08-17 18:07:52 +0000 | [diff] [blame] | 1751 | Index *pPrior = 0; /* Previous index */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1752 | int loopTop; |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1753 | int iDataCur, iIdxCur; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1754 | int r1 = -1; |
drh | db6940a | 2022-10-10 19:38:01 +0000 | [diff] [blame] | 1755 | int bStrict; /* True for a STRICT table */ |
drh | 16b03c0 | 2022-08-17 18:07:52 +0000 | [diff] [blame] | 1756 | int r2; /* Previous key for WITHOUT ROWID tables */ |
drh | db6940a | 2022-10-10 19:38:01 +0000 | [diff] [blame] | 1757 | int mxCol; /* Maximum non-virtual column number */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1758 | |
drh | 9966621 | 2021-10-11 15:21:42 +0000 | [diff] [blame] | 1759 | if( !IsOrdinaryTable(pTab) ) continue; |
drh | 17d2d59 | 2020-07-23 00:45:06 +0000 | [diff] [blame] | 1760 | if( pObjTab && pObjTab!=pTab ) continue; |
drh | 16b03c0 | 2022-08-17 18:07:52 +0000 | [diff] [blame] | 1761 | if( isQuick || HasRowid(pTab) ){ |
| 1762 | pPk = 0; |
| 1763 | r2 = 0; |
| 1764 | }else{ |
| 1765 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 1766 | r2 = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 1767 | sqlite3VdbeAddOp3(v, OP_Null, 1, r2, r2+pPk->nKeyCol-1); |
| 1768 | } |
dan | fd261ec | 2015-10-22 20:54:33 +0000 | [diff] [blame] | 1769 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
drh | 6a53499 | 2013-11-16 20:13:39 +0000 | [diff] [blame] | 1770 | 1, 0, &iDataCur, &iIdxCur); |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 1771 | /* reg[7] counts the number of entries in the table. |
| 1772 | ** reg[8+i] counts the number of entries in the i-th index |
| 1773 | */ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1774 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1775 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1776 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */ |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1777 | } |
drh | bb9b5f2 | 2016-03-19 00:35:02 +0000 | [diff] [blame] | 1778 | assert( pParse->nMem>=8+j ); |
| 1779 | assert( sqlite3NoTempsInRange(pParse,1,7+j) ); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1780 | sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1781 | loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); |
drh | db6940a | 2022-10-10 19:38:01 +0000 | [diff] [blame] | 1782 | |
| 1783 | /* Fetch the right-most column from the table. This will cause |
| 1784 | ** the entire record header to be parsed and sanity checked. It |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1785 | ** will also prepopulate the cursor column cache that is used |
| 1786 | ** by the OP_IsType code, so it is a required step. |
| 1787 | */ |
drh | db6940a | 2022-10-10 19:38:01 +0000 | [diff] [blame] | 1788 | mxCol = pTab->nCol-1; |
| 1789 | while( mxCol>=0 |
| 1790 | && ((pTab->aCol[mxCol].colFlags & COLFLAG_VIRTUAL)!=0 |
| 1791 | || pTab->iPKey==mxCol) ) mxCol--; |
| 1792 | if( mxCol>=0 ){ |
| 1793 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, mxCol, 3); |
drh | e995d2c | 2022-10-13 12:47:33 +0000 | [diff] [blame] | 1794 | sqlite3VdbeTypeofColumn(v, 3); |
drh | db6940a | 2022-10-10 19:38:01 +0000 | [diff] [blame] | 1795 | } |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1796 | |
drh | 4011c44 | 2018-06-06 19:48:19 +0000 | [diff] [blame] | 1797 | if( !isQuick ){ |
drh | 16b03c0 | 2022-08-17 18:07:52 +0000 | [diff] [blame] | 1798 | if( pPk ){ |
| 1799 | /* Verify WITHOUT ROWID keys are in ascending order */ |
| 1800 | int a1; |
| 1801 | char *zErr; |
| 1802 | a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol); |
| 1803 | VdbeCoverage(v); |
| 1804 | sqlite3VdbeAddOp1(v, OP_IsNull, r2); VdbeCoverage(v); |
| 1805 | zErr = sqlite3MPrintf(db, |
| 1806 | "row not in PRIMARY KEY order for %s", |
| 1807 | pTab->zName); |
| 1808 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 1809 | integrityCheckResultRow(v); |
| 1810 | sqlite3VdbeJumpHere(v, a1); |
| 1811 | sqlite3VdbeJumpHere(v, a1+1); |
| 1812 | for(j=0; j<pPk->nKeyCol; j++){ |
| 1813 | sqlite3ExprCodeLoadIndexColumn(pParse, pPk, iDataCur, j, r2+j); |
| 1814 | } |
| 1815 | } |
drh | 4011c44 | 2018-06-06 19:48:19 +0000 | [diff] [blame] | 1816 | } |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1817 | /* Verify datatypes for all columns: |
| 1818 | ** |
| 1819 | ** (1) NOT NULL columns may not contain a NULL |
| 1820 | ** (2) Datatype must be exact for non-ANY columns in STRICT tables |
| 1821 | ** (3) Datatype for TEXT columns in non-STRICT tables must be |
| 1822 | ** NULL, TEXT, or BLOB. |
| 1823 | ** (4) Datatype for numeric columns in non-STRICT tables must not |
| 1824 | ** be a TEXT value that can be losslessly converted to numeric. |
| 1825 | */ |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 1826 | bStrict = (pTab->tabFlags & TF_Strict)!=0; |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1827 | for(j=0; j<pTab->nCol; j++){ |
| 1828 | char *zErr; |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1829 | Column *pCol = pTab->aCol + j; /* The column to be checked */ |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1830 | int labelError; /* Jump here to report an error */ |
| 1831 | int labelOk; /* Jump here if all looks ok */ |
| 1832 | int p1, p3, p4; /* Operands to the OP_IsType opcode */ |
| 1833 | int doTypeCheck; /* Check datatypes (besides NOT NULL) */ |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1834 | |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1835 | if( j==pTab->iPKey ) continue; |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1836 | if( bStrict ){ |
| 1837 | doTypeCheck = pCol->eCType>COLTYPE_ANY; |
| 1838 | }else{ |
| 1839 | doTypeCheck = pCol->affinity>SQLITE_AFF_BLOB; |
drh | ebd70ee | 2019-12-09 15:52:07 +0000 | [diff] [blame] | 1840 | } |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1841 | if( pCol->notNull==0 && !doTypeCheck ) continue; |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1842 | |
| 1843 | /* Compute the operands that will be needed for OP_IsType */ |
drh | db6940a | 2022-10-10 19:38:01 +0000 | [diff] [blame] | 1844 | p4 = SQLITE_NULL; |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1845 | if( pCol->colFlags & COLFLAG_VIRTUAL ){ |
| 1846 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 1847 | p1 = -1; |
| 1848 | p3 = 3; |
| 1849 | }else{ |
| 1850 | if( pCol->iDflt ){ |
| 1851 | sqlite3_value *pDfltValue = 0; |
| 1852 | sqlite3ValueFromExpr(db, sqlite3ColumnExpr(pTab,pCol), ENC(db), |
| 1853 | pCol->affinity, &pDfltValue); |
| 1854 | if( pDfltValue ){ |
| 1855 | p4 = sqlite3_value_type(pDfltValue); |
| 1856 | sqlite3ValueFree(pDfltValue); |
| 1857 | } |
| 1858 | } |
| 1859 | p1 = iDataCur; |
| 1860 | if( !HasRowid(pTab) ){ |
| 1861 | testcase( j!=sqlite3TableColumnToStorage(pTab, j) ); |
| 1862 | p3 = sqlite3TableColumnToIndex(sqlite3PrimaryKeyIndex(pTab), j); |
| 1863 | }else{ |
| 1864 | p3 = sqlite3TableColumnToStorage(pTab,j); |
| 1865 | testcase( p3!=j); |
| 1866 | } |
| 1867 | } |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1868 | |
| 1869 | labelError = sqlite3VdbeMakeLabel(pParse); |
| 1870 | labelOk = sqlite3VdbeMakeLabel(pParse); |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 1871 | if( pCol->notNull ){ |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1872 | /* (1) NOT NULL columns may not contain a NULL */ |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1873 | int jmp2 = sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1874 | sqlite3VdbeChangeP5(v, 0x0f); |
| 1875 | VdbeCoverage(v); |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 1876 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 1877 | pCol->zCnName); |
| 1878 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1879 | if( doTypeCheck ){ |
| 1880 | sqlite3VdbeGoto(v, labelError); |
| 1881 | sqlite3VdbeJumpHere(v, jmp2); |
drh | 71c770f | 2021-08-19 16:29:33 +0000 | [diff] [blame] | 1882 | }else{ |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1883 | /* VDBE byte code will fall thru */ |
drh | 71c770f | 2021-08-19 16:29:33 +0000 | [diff] [blame] | 1884 | } |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 1885 | } |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1886 | if( bStrict && doTypeCheck ){ |
| 1887 | /* (2) Datatype must be exact for non-ANY columns in STRICT tables*/ |
| 1888 | static unsigned char aStdTypeMask[] = { |
| 1889 | 0x1f, /* ANY */ |
| 1890 | 0x18, /* BLOB */ |
| 1891 | 0x11, /* INT */ |
| 1892 | 0x11, /* INTEGER */ |
| 1893 | 0x13, /* REAL */ |
| 1894 | 0x14 /* TEXT */ |
| 1895 | }; |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1896 | sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1897 | assert( pCol->eCType>=1 && pCol->eCType<=sizeof(aStdTypeMask) ); |
| 1898 | sqlite3VdbeChangeP5(v, aStdTypeMask[pCol->eCType-1]); |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 1899 | VdbeCoverage(v); |
| 1900 | zErr = sqlite3MPrintf(db, "non-%s value in %s.%s", |
| 1901 | sqlite3StdType[pCol->eCType-1], |
| 1902 | pTab->zName, pTab->aCol[j].zCnName); |
| 1903 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1904 | }else if( !bStrict && pCol->affinity==SQLITE_AFF_TEXT ){ |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1905 | /* (3) Datatype for TEXT columns in non-STRICT tables must be |
| 1906 | ** NULL, TEXT, or BLOB. */ |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1907 | sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1908 | sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */ |
| 1909 | VdbeCoverage(v); |
| 1910 | zErr = sqlite3MPrintf(db, "NUMERIC value in %s.%s", |
| 1911 | pTab->zName, pTab->aCol[j].zCnName); |
| 1912 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1913 | }else if( !bStrict && pCol->affinity>=SQLITE_AFF_NUMERIC ){ |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1914 | /* (4) Datatype for numeric columns in non-STRICT tables must not |
| 1915 | ** be a TEXT value that can be converted to numeric. */ |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1916 | sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1917 | sqlite3VdbeChangeP5(v, 0x1b); /* NULL, INT, FLOAT, or BLOB */ |
| 1918 | VdbeCoverage(v); |
| 1919 | if( p1>=0 ){ |
| 1920 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 1921 | } |
| 1922 | sqlite3VdbeAddOp4(v, OP_Affinity, 3, 1, 0, "C", P4_STATIC); |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1923 | sqlite3VdbeAddOp4Int(v, OP_IsType, -1, labelOk, 3, p4); |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1924 | sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */ |
| 1925 | VdbeCoverage(v); |
| 1926 | zErr = sqlite3MPrintf(db, "TEXT value in %s.%s", |
| 1927 | pTab->zName, pTab->aCol[j].zCnName); |
| 1928 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
drh | 49d77ee | 2022-10-10 18:25:05 +0000 | [diff] [blame] | 1929 | } |
drh | c9ef12f | 2022-10-10 21:21:04 +0000 | [diff] [blame] | 1930 | sqlite3VdbeResolveLabel(v, labelError); |
| 1931 | integrityCheckResultRow(v); |
| 1932 | sqlite3VdbeResolveLabel(v, labelOk); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1933 | } |
drh | 8a284dc | 2017-02-22 14:15:37 +0000 | [diff] [blame] | 1934 | /* Verify CHECK constraints */ |
| 1935 | if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ |
dan | 75f9558 | 2017-04-04 19:58:54 +0000 | [diff] [blame] | 1936 | ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0); |
| 1937 | if( db->mallocFailed==0 ){ |
drh | ec4ccdb | 2018-12-29 02:26:59 +0000 | [diff] [blame] | 1938 | int addrCkFault = sqlite3VdbeMakeLabel(pParse); |
| 1939 | int addrCkOk = sqlite3VdbeMakeLabel(pParse); |
dan | 75f9558 | 2017-04-04 19:58:54 +0000 | [diff] [blame] | 1940 | char *zErr; |
| 1941 | int k; |
drh | 6e97f8e | 2017-07-20 13:17:08 +0000 | [diff] [blame] | 1942 | pParse->iSelfTab = iDataCur + 1; |
dan | 75f9558 | 2017-04-04 19:58:54 +0000 | [diff] [blame] | 1943 | for(k=pCheck->nExpr-1; k>0; k--){ |
| 1944 | sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0); |
| 1945 | } |
| 1946 | sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, |
| 1947 | SQLITE_JUMPIFNULL); |
| 1948 | sqlite3VdbeResolveLabel(v, addrCkFault); |
drh | 3e34eab | 2017-07-19 19:48:40 +0000 | [diff] [blame] | 1949 | pParse->iSelfTab = 0; |
dan | 75f9558 | 2017-04-04 19:58:54 +0000 | [diff] [blame] | 1950 | zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s", |
| 1951 | pTab->zName); |
| 1952 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 1953 | integrityCheckResultRow(v); |
dan | 75f9558 | 2017-04-04 19:58:54 +0000 | [diff] [blame] | 1954 | sqlite3VdbeResolveLabel(v, addrCkOk); |
drh | 8a284dc | 2017-02-22 14:15:37 +0000 | [diff] [blame] | 1955 | } |
dan | 75f9558 | 2017-04-04 19:58:54 +0000 | [diff] [blame] | 1956 | sqlite3ExprListDelete(db, pCheck); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1957 | } |
drh | 226cef4 | 2017-09-09 20:38:49 +0000 | [diff] [blame] | 1958 | if( !isQuick ){ /* Omit the remaining tests for quick_check */ |
drh | 226cef4 | 2017-09-09 20:38:49 +0000 | [diff] [blame] | 1959 | /* Validate index entries for the current row */ |
| 1960 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 1961 | int jmp2, jmp3, jmp4, jmp5; |
drh | ec4ccdb | 2018-12-29 02:26:59 +0000 | [diff] [blame] | 1962 | int ckUniq = sqlite3VdbeMakeLabel(pParse); |
drh | 226cef4 | 2017-09-09 20:38:49 +0000 | [diff] [blame] | 1963 | if( pPk==pIdx ) continue; |
| 1964 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 1965 | pPrior, r1); |
| 1966 | pPrior = pIdx; |
| 1967 | sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */ |
| 1968 | /* Verify that an index entry exists for the current table row */ |
| 1969 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1, |
| 1970 | pIdx->nColumn); VdbeCoverage(v); |
| 1971 | sqlite3VdbeLoadString(v, 3, "row "); |
| 1972 | sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 1973 | sqlite3VdbeLoadString(v, 4, " missing from index "); |
| 1974 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 1975 | jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 1976 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 1977 | jmp4 = integrityCheckResultRow(v); |
drh | 226cef4 | 2017-09-09 20:38:49 +0000 | [diff] [blame] | 1978 | sqlite3VdbeJumpHere(v, jmp2); |
| 1979 | /* For UNIQUE indexes, verify that only one entry exists with the |
| 1980 | ** current key. The entry is unique if (1) any column is NULL |
| 1981 | ** or (2) the next entry has a different key */ |
| 1982 | if( IsUniqueIndex(pIdx) ){ |
drh | ec4ccdb | 2018-12-29 02:26:59 +0000 | [diff] [blame] | 1983 | int uniqOk = sqlite3VdbeMakeLabel(pParse); |
drh | 226cef4 | 2017-09-09 20:38:49 +0000 | [diff] [blame] | 1984 | int jmp6; |
| 1985 | int kk; |
| 1986 | for(kk=0; kk<pIdx->nKeyCol; kk++){ |
| 1987 | int iCol = pIdx->aiColumn[kk]; |
| 1988 | assert( iCol!=XN_ROWID && iCol<pTab->nCol ); |
| 1989 | if( iCol>=0 && pTab->aCol[iCol].notNull ) continue; |
| 1990 | sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); |
| 1991 | VdbeCoverage(v); |
| 1992 | } |
| 1993 | jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v); |
| 1994 | sqlite3VdbeGoto(v, uniqOk); |
| 1995 | sqlite3VdbeJumpHere(v, jmp6); |
| 1996 | sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1, |
| 1997 | pIdx->nKeyCol); VdbeCoverage(v); |
| 1998 | sqlite3VdbeLoadString(v, 3, "non-unique entry in index "); |
| 1999 | sqlite3VdbeGoto(v, jmp5); |
| 2000 | sqlite3VdbeResolveLabel(v, uniqOk); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 2001 | } |
drh | 226cef4 | 2017-09-09 20:38:49 +0000 | [diff] [blame] | 2002 | sqlite3VdbeJumpHere(v, jmp4); |
| 2003 | sqlite3ResolvePartIdxLabel(pParse, jmp3); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 2004 | } |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 2005 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 2006 | sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 2007 | sqlite3VdbeJumpHere(v, loopTop-1); |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 2008 | if( !isQuick ){ |
| 2009 | sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); |
| 2010 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 2011 | if( pPk==pIdx ) continue; |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 2012 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 2013 | addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v); |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 2014 | sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
drh | 9ecd708 | 2017-09-10 01:06:05 +0000 | [diff] [blame] | 2015 | sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 2016 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3); |
| 2017 | integrityCheckResultRow(v); |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 2018 | sqlite3VdbeJumpHere(v, addr); |
drh | 8b174f2 | 2017-02-22 15:11:36 +0000 | [diff] [blame] | 2019 | } |
drh | 16b03c0 | 2022-08-17 18:07:52 +0000 | [diff] [blame] | 2020 | if( pPk ){ |
| 2021 | sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol); |
| 2022 | } |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | } |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2026 | { |
| 2027 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 2028 | static const VdbeOpList endCode[] = { |
| 2029 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 2030 | { OP_IfNotZero, 1, 4, 0}, /* 1 */ |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2031 | { OP_String8, 0, 3, 0}, /* 2 */ |
drh | 1b32554 | 2016-02-03 01:55:44 +0000 | [diff] [blame] | 2032 | { OP_ResultRow, 3, 1, 0}, /* 3 */ |
drh | 74588ce | 2017-09-13 00:13:05 +0000 | [diff] [blame] | 2033 | { OP_Halt, 0, 0, 0}, /* 4 */ |
| 2034 | { OP_String8, 0, 3, 0}, /* 5 */ |
| 2035 | { OP_Goto, 0, 3, 0}, /* 6 */ |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2036 | }; |
| 2037 | VdbeOp *aOp; |
| 2038 | |
| 2039 | aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 2040 | if( aOp ){ |
drh | 66accfc | 2017-02-22 18:04:42 +0000 | [diff] [blame] | 2041 | aOp[0].p2 = 1-mxErr; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2042 | aOp[2].p4type = P4_STATIC; |
| 2043 | aOp[2].p4.z = "ok"; |
drh | 74588ce | 2017-09-13 00:13:05 +0000 | [diff] [blame] | 2044 | aOp[5].p4type = P4_STATIC; |
| 2045 | aOp[5].p4.z = (char*)sqlite3ErrStr(SQLITE_CORRUPT); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2046 | } |
drh | 74588ce | 2017-09-13 00:13:05 +0000 | [diff] [blame] | 2047 | sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2048 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2049 | } |
| 2050 | break; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 2051 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 2052 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2053 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2054 | /* |
| 2055 | ** PRAGMA encoding |
| 2056 | ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" |
| 2057 | ** |
drh | 85b623f | 2007-12-13 21:54:09 +0000 | [diff] [blame] | 2058 | ** In its first form, this pragma returns the encoding of the main |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2059 | ** database. If the database is not initialized, it is initialized now. |
| 2060 | ** |
| 2061 | ** The second form of this pragma is a no-op if the main database file |
| 2062 | ** has not already been initialized. In this case it sets the default |
| 2063 | ** encoding that will be used for the main database file if a new file |
| 2064 | ** is created. If an existing main database file is opened, then the |
| 2065 | ** default text encoding for the existing database is used. |
| 2066 | ** |
| 2067 | ** In all cases new databases created using the ATTACH command are |
| 2068 | ** created to use the same default text encoding as the main database. If |
| 2069 | ** the main database has not been initialized and/or created when ATTACH |
| 2070 | ** is executed, this is done before the ATTACH operation. |
| 2071 | ** |
| 2072 | ** In the second form this pragma sets the text encoding to be used in |
| 2073 | ** new database files created using this database handle. It is only |
| 2074 | ** useful if invoked immediately after the main database i |
| 2075 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2076 | case PragTyp_ENCODING: { |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 2077 | static const struct EncName { |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2078 | char *zName; |
| 2079 | u8 enc; |
| 2080 | } encnames[] = { |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 2081 | { "UTF8", SQLITE_UTF8 }, |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 2082 | { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */ |
| 2083 | { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */ |
| 2084 | { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */ |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 2085 | { "UTF16le", SQLITE_UTF16LE }, |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 2086 | { "UTF16be", SQLITE_UTF16BE }, |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 2087 | { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */ |
| 2088 | { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2089 | { 0, 0 } |
| 2090 | }; |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 2091 | const struct EncName *pEnc; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 2092 | if( !zRight ){ /* "PRAGMA encoding" */ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 2093 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 2094 | assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 ); |
| 2095 | assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE ); |
| 2096 | assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE ); |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 2097 | returnSingleText(v, encnames[ENC(pParse->db)].zName); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2098 | }else{ /* "PRAGMA encoding = XXX" */ |
| 2099 | /* Only change the value of sqlite.enc if the database handle is not |
| 2100 | ** initialized. If the main database exists, the new sqlite.enc value |
| 2101 | ** will be overwritten when the schema is next loaded. If it does not |
| 2102 | ** already exists, it will be created to use the new encoding value. |
| 2103 | */ |
dan | 0ea2d42 | 2020-03-05 18:04:09 +0000 | [diff] [blame] | 2104 | if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2105 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 2106 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
drh | 42a630b | 2020-03-05 16:13:24 +0000 | [diff] [blame] | 2107 | u8 enc = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 2108 | SCHEMA_ENC(db) = enc; |
| 2109 | sqlite3SetTextEncoding(db, enc); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2110 | break; |
| 2111 | } |
| 2112 | } |
| 2113 | if( !pEnc->zName ){ |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 2114 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2118 | } |
| 2119 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2120 | #endif /* SQLITE_OMIT_UTF16 */ |
| 2121 | |
| 2122 | #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2123 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 2124 | ** PRAGMA [schema.]schema_version |
| 2125 | ** PRAGMA [schema.]schema_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2126 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 2127 | ** PRAGMA [schema.]user_version |
| 2128 | ** PRAGMA [schema.]user_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2129 | ** |
drh | e459bd4 | 2016-03-16 20:05:57 +0000 | [diff] [blame] | 2130 | ** PRAGMA [schema.]freelist_count |
| 2131 | ** |
| 2132 | ** PRAGMA [schema.]data_version |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 2133 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 2134 | ** PRAGMA [schema.]application_id |
| 2135 | ** PRAGMA [schema.]application_id = <integer> |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 2136 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2137 | ** The pragma's schema_version and user_version are used to set or get |
| 2138 | ** the value of the schema-version and user-version, respectively. Both |
| 2139 | ** the schema-version and the user-version are 32-bit signed integers |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2140 | ** stored in the database header. |
| 2141 | ** |
| 2142 | ** The schema-cookie is usually only manipulated internally by SQLite. It |
| 2143 | ** is incremented by SQLite whenever the database schema is modified (by |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2144 | ** creating or dropping a table or index). The schema version is used by |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2145 | ** SQLite each time a query is executed to ensure that the internal cache |
| 2146 | ** of the schema used when compiling the SQL query matches the schema of |
| 2147 | ** the database against which the compiled query is actually executed. |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2148 | ** Subverting this mechanism by using "PRAGMA schema_version" to modify |
| 2149 | ** the schema-version is potentially dangerous and may lead to program |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2150 | ** crashes or database corruption. Use with caution! |
| 2151 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2152 | ** The user-version is not used internally by SQLite. It may be used by |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2153 | ** applications for any purpose. |
| 2154 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2155 | case PragTyp_HEADER_VALUE: { |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 2156 | int iCookie = pPragma->iArg; /* Which cookie to read or write */ |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 2157 | sqlite3VdbeUsesBtree(v, iDb); |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 2158 | if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2159 | /* Write the specified cookie value */ |
| 2160 | static const VdbeOpList setCookie[] = { |
| 2161 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 2162 | { OP_SetCookie, 0, 0, 0}, /* 1 */ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2163 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2164 | VdbeOp *aOp; |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 2165 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2166 | aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 2167 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2168 | aOp[0].p1 = iDb; |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 2169 | aOp[1].p1 = iDb; |
| 2170 | aOp[1].p2 = iCookie; |
| 2171 | aOp[1].p3 = sqlite3Atoi(zRight); |
drh | e3863b5 | 2020-07-01 16:19:14 +0000 | [diff] [blame] | 2172 | aOp[1].p5 = 1; |
drh | 7e475e5 | 2022-11-12 17:17:01 +0000 | [diff] [blame] | 2173 | if( iCookie==BTREE_SCHEMA_VERSION && (db->flags & SQLITE_Defensive)!=0 ){ |
| 2174 | /* Do not allow the use of PRAGMA schema_version=VALUE in defensive |
| 2175 | ** mode. Change the OP_SetCookie opcode into a no-op. */ |
| 2176 | aOp[1].opcode = OP_Noop; |
| 2177 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2178 | }else{ |
| 2179 | /* Read the specified cookie value */ |
| 2180 | static const VdbeOpList readCookie[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 2181 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 2182 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2183 | { OP_ResultRow, 1, 1, 0} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2184 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2185 | VdbeOp *aOp; |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 2186 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(readCookie)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2187 | aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 2188 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 2189 | aOp[0].p1 = iDb; |
| 2190 | aOp[1].p1 = iDb; |
| 2191 | aOp[1].p3 = iCookie; |
drh | f71a366 | 2016-03-16 20:44:45 +0000 | [diff] [blame] | 2192 | sqlite3VdbeReusable(v); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2193 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2194 | } |
| 2195 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2196 | #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 2197 | |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2198 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 2199 | /* |
| 2200 | ** PRAGMA compile_options |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2201 | ** |
drh | 71caabf | 2010-02-26 15:39:24 +0000 | [diff] [blame] | 2202 | ** Return the names of all compile-time options used in this build, |
| 2203 | ** one option per row. |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2204 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2205 | case PragTyp_COMPILE_OPTIONS: { |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2206 | int i = 0; |
| 2207 | const char *zOpt; |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2208 | pParse->nMem = 1; |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2209 | while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 2210 | sqlite3VdbeLoadString(v, 1, zOpt); |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2211 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 2212 | } |
drh | f71a366 | 2016-03-16 20:44:45 +0000 | [diff] [blame] | 2213 | sqlite3VdbeReusable(v); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2214 | } |
| 2215 | break; |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2216 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 2217 | |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 2218 | #ifndef SQLITE_OMIT_WAL |
| 2219 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 2220 | ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 2221 | ** |
| 2222 | ** Checkpoint the database. |
| 2223 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2224 | case PragTyp_WAL_CHECKPOINT: { |
drh | 099b385 | 2021-03-10 16:35:37 +0000 | [diff] [blame] | 2225 | int iBt = (pId2->z?iDb:SQLITE_MAX_DB); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2226 | int eMode = SQLITE_CHECKPOINT_PASSIVE; |
| 2227 | if( zRight ){ |
| 2228 | if( sqlite3StrICmp(zRight, "full")==0 ){ |
| 2229 | eMode = SQLITE_CHECKPOINT_FULL; |
| 2230 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 2231 | eMode = SQLITE_CHECKPOINT_RESTART; |
dan | f26a154 | 2014-12-02 19:04:54 +0000 | [diff] [blame] | 2232 | }else if( sqlite3StrICmp(zRight, "truncate")==0 ){ |
| 2233 | eMode = SQLITE_CHECKPOINT_TRUNCATE; |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2234 | } |
| 2235 | } |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2236 | pParse->nMem = 3; |
drh | 30aa3b9 | 2011-02-07 23:56:01 +0000 | [diff] [blame] | 2237 | sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2238 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2239 | } |
| 2240 | break; |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 2241 | |
| 2242 | /* |
| 2243 | ** PRAGMA wal_autocheckpoint |
| 2244 | ** PRAGMA wal_autocheckpoint = N |
| 2245 | ** |
| 2246 | ** Configure a database connection to automatically checkpoint a database |
| 2247 | ** after accumulating N frames in the log. Or query for the current value |
| 2248 | ** of N. |
| 2249 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2250 | case PragTyp_WAL_AUTOCHECKPOINT: { |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 2251 | if( zRight ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 2252 | sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight)); |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 2253 | } |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 2254 | returnSingleInt(v, |
drh | b033d8b | 2010-05-03 13:37:30 +0000 | [diff] [blame] | 2255 | db->xWalCallback==sqlite3WalDefaultHook ? |
| 2256 | SQLITE_PTR_TO_INT(db->pWalArg) : 0); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2257 | } |
| 2258 | break; |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 2259 | #endif |
dan | 7c24610 | 2010-04-12 19:00:29 +0000 | [diff] [blame] | 2260 | |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2261 | /* |
| 2262 | ** PRAGMA shrink_memory |
| 2263 | ** |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 2264 | ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database |
| 2265 | ** connection on which it is invoked to free up as much memory as it |
| 2266 | ** can, by calling sqlite3_db_release_memory(). |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2267 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2268 | case PragTyp_SHRINK_MEMORY: { |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2269 | sqlite3_db_release_memory(db); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | } |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2272 | |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2273 | /* |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2274 | ** PRAGMA optimize |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2275 | ** PRAGMA optimize(MASK) |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2276 | ** PRAGMA schema.optimize |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2277 | ** PRAGMA schema.optimize(MASK) |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2278 | ** |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2279 | ** Attempt to optimize the database. All schemas are optimized in the first |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2280 | ** two forms, and only the specified schema is optimized in the latter two. |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2281 | ** |
drh | e1f1c08 | 2017-03-06 20:44:13 +0000 | [diff] [blame] | 2282 | ** The details of optimizations performed by this pragma are expected |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2283 | ** to change and improve over time. Applications should anticipate that |
| 2284 | ** this pragma will perform new optimizations in future releases. |
| 2285 | ** |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2286 | ** The optional argument is a bitmask of optimizations to perform: |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2287 | ** |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2288 | ** 0x0001 Debugging mode. Do not actually perform any optimizations |
| 2289 | ** but instead return one line of text for each optimization |
| 2290 | ** that would have been done. Off by default. |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2291 | ** |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2292 | ** 0x0002 Run ANALYZE on tables that might benefit. On by default. |
| 2293 | ** See below for additional information. |
| 2294 | ** |
| 2295 | ** 0x0004 (Not yet implemented) Record usage and performance |
| 2296 | ** information from the current session in the |
| 2297 | ** database file so that it will be available to "optimize" |
| 2298 | ** pragmas run by future database connections. |
| 2299 | ** |
| 2300 | ** 0x0008 (Not yet implemented) Create indexes that might have |
| 2301 | ** been helpful to recent queries |
| 2302 | ** |
drh | e7c6f97 | 2017-07-15 20:25:22 +0000 | [diff] [blame] | 2303 | ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all |
| 2304 | ** of the optimizations listed above except Debug Mode, including new |
drh | 59dbe3a | 2017-03-06 23:51:16 +0000 | [diff] [blame] | 2305 | ** optimizations that have not yet been invented. If new optimizations are |
| 2306 | ** ever added that should be off by default, those off-by-default |
| 2307 | ** optimizations will have bitmasks of 0x10000 or larger. |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2308 | ** |
| 2309 | ** DETERMINATION OF WHEN TO RUN ANALYZE |
| 2310 | ** |
| 2311 | ** In the current implementation, a table is analyzed if only if all of |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2312 | ** the following are true: |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2313 | ** |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2314 | ** (1) MASK bit 0x02 is set. |
| 2315 | ** |
| 2316 | ** (2) The query planner used sqlite_stat1-style statistics for one or |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2317 | ** more indexes of the table at some point during the lifetime of |
| 2318 | ** the current connection. |
| 2319 | ** |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2320 | ** (3) One or more indexes of the table are currently unanalyzed OR |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2321 | ** the number of rows in the table has increased by 25 times or more |
| 2322 | ** since the last time ANALYZE was run. |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2323 | ** |
| 2324 | ** The rules for when tables are analyzed are likely to change in |
| 2325 | ** future releases. |
drh | 72052a7 | 2017-02-17 16:26:34 +0000 | [diff] [blame] | 2326 | */ |
drh | 2ead47c | 2017-02-22 20:24:10 +0000 | [diff] [blame] | 2327 | case PragTyp_OPTIMIZE: { |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2328 | int iDbLast; /* Loop termination point for the schema loop */ |
| 2329 | int iTabCur; /* Cursor for a table whose size needs checking */ |
| 2330 | HashElem *k; /* Loop over tables of a schema */ |
| 2331 | Schema *pSchema; /* The current schema */ |
| 2332 | Table *pTab; /* A table in the schema */ |
| 2333 | Index *pIdx; /* An index of the table */ |
| 2334 | LogEst szThreshold; /* Size threshold above which reanalysis is needd */ |
| 2335 | char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2336 | u32 opMask; /* Mask of operations to perform */ |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2337 | |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2338 | if( zRight ){ |
| 2339 | opMask = (u32)sqlite3Atoi(zRight); |
| 2340 | if( (opMask & 0x02)==0 ) break; |
| 2341 | }else{ |
drh | 59dbe3a | 2017-03-06 23:51:16 +0000 | [diff] [blame] | 2342 | opMask = 0xfffe; |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2343 | } |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2344 | iTabCur = pParse->nTab++; |
| 2345 | for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){ |
| 2346 | if( iDb==1 ) continue; |
| 2347 | sqlite3CodeVerifySchema(pParse, iDb); |
| 2348 | pSchema = db->aDb[iDb].pSchema; |
| 2349 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 2350 | pTab = (Table*)sqliteHashData(k); |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2351 | |
| 2352 | /* If table pTab has not been used in a way that would benefit from |
| 2353 | ** having analysis statistics during the current session, then skip it. |
| 2354 | ** This also has the effect of skipping virtual tables and views */ |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2355 | if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue; |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2356 | |
| 2357 | /* Reanalyze if the table is 25 times larger than the last analysis */ |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2358 | szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 ); |
| 2359 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 2360 | if( !pIdx->hasStat1 ){ |
drh | 99d5b4c | 2017-02-18 22:52:40 +0000 | [diff] [blame] | 2361 | szThreshold = 0; /* Always analyze if any index lacks statistics */ |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | } |
| 2364 | } |
| 2365 | if( szThreshold ){ |
| 2366 | sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); |
| 2367 | sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur, |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2368 | sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold); |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2369 | VdbeCoverage(v); |
| 2370 | } |
| 2371 | zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"", |
| 2372 | db->aDb[iDb].zDbSName, pTab->zName); |
drh | 1cfaf8e | 2017-03-02 14:17:21 +0000 | [diff] [blame] | 2373 | if( opMask & 0x01 ){ |
| 2374 | int r1 = sqlite3GetTempReg(pParse); |
| 2375 | sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC); |
| 2376 | sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1); |
| 2377 | }else{ |
| 2378 | sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC); |
| 2379 | } |
drh | 4a54bb5 | 2017-02-18 15:58:52 +0000 | [diff] [blame] | 2380 | } |
| 2381 | } |
drh | bce0414 | 2017-02-23 00:58:36 +0000 | [diff] [blame] | 2382 | sqlite3VdbeAddOp0(v, OP_Expire); |
drh | 72052a7 | 2017-02-17 16:26:34 +0000 | [diff] [blame] | 2383 | break; |
| 2384 | } |
| 2385 | |
| 2386 | /* |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2387 | ** PRAGMA busy_timeout |
| 2388 | ** PRAGMA busy_timeout = N |
| 2389 | ** |
| 2390 | ** Call sqlite3_busy_timeout(db, N). Return the current timeout value |
drh | c0c7b5e | 2012-09-07 18:49:57 +0000 | [diff] [blame] | 2391 | ** if one is set. If no busy handler or a different busy handler is set |
| 2392 | ** then 0 is returned. Setting the busy_timeout to 0 or negative |
| 2393 | ** disables the timeout. |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2394 | */ |
drh | d49c358 | 2013-09-13 19:00:06 +0000 | [diff] [blame] | 2395 | /*case PragTyp_BUSY_TIMEOUT*/ default: { |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 2396 | assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT ); |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2397 | if( zRight ){ |
| 2398 | sqlite3_busy_timeout(db, sqlite3Atoi(zRight)); |
| 2399 | } |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 2400 | returnSingleInt(v, db->busyTimeout); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | } |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2403 | |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 2404 | /* |
| 2405 | ** PRAGMA soft_heap_limit |
| 2406 | ** PRAGMA soft_heap_limit = N |
| 2407 | ** |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 2408 | ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the |
| 2409 | ** sqlite3_soft_heap_limit64() interface with the argument N, if N is |
| 2410 | ** specified and is a non-negative integer. |
| 2411 | ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always |
| 2412 | ** returns the same integer that would be returned by the |
| 2413 | ** sqlite3_soft_heap_limit64(-1) C-language function. |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 2414 | */ |
| 2415 | case PragTyp_SOFT_HEAP_LIMIT: { |
| 2416 | sqlite3_int64 N; |
drh | 9296c18 | 2014-07-23 13:40:49 +0000 | [diff] [blame] | 2417 | if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){ |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 2418 | sqlite3_soft_heap_limit64(N); |
| 2419 | } |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 2420 | returnSingleInt(v, sqlite3_soft_heap_limit64(-1)); |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | } |
| 2423 | |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 2424 | /* |
drh | 10c0e71 | 2019-04-25 18:15:38 +0000 | [diff] [blame] | 2425 | ** PRAGMA hard_heap_limit |
| 2426 | ** PRAGMA hard_heap_limit = N |
| 2427 | ** |
| 2428 | ** Invoke sqlite3_hard_heap_limit64() to query or set the hard heap |
| 2429 | ** limit. The hard heap limit can be activated or lowered by this |
| 2430 | ** pragma, but not raised or deactivated. Only the |
| 2431 | ** sqlite3_hard_heap_limit64() C-language API can raise or deactivate |
| 2432 | ** the hard heap limit. This allows an application to set a heap limit |
| 2433 | ** constraint that cannot be relaxed by an untrusted SQL script. |
| 2434 | */ |
| 2435 | case PragTyp_HARD_HEAP_LIMIT: { |
| 2436 | sqlite3_int64 N; |
| 2437 | if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){ |
| 2438 | sqlite3_int64 iPrior = sqlite3_hard_heap_limit64(-1); |
| 2439 | if( N>0 && (iPrior==0 || iPrior>N) ) sqlite3_hard_heap_limit64(N); |
| 2440 | } |
drh | 31999c5 | 2019-11-14 17:46:32 +0000 | [diff] [blame] | 2441 | returnSingleInt(v, sqlite3_hard_heap_limit64(-1)); |
drh | 10c0e71 | 2019-04-25 18:15:38 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | /* |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 2446 | ** PRAGMA threads |
| 2447 | ** PRAGMA threads = N |
| 2448 | ** |
| 2449 | ** Configure the maximum number of worker threads. Return the new |
| 2450 | ** maximum, which might be less than requested. |
| 2451 | */ |
| 2452 | case PragTyp_THREADS: { |
| 2453 | sqlite3_int64 N; |
drh | 111544c | 2014-08-29 16:20:47 +0000 | [diff] [blame] | 2454 | if( zRight |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 2455 | && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK |
| 2456 | && N>=0 |
| 2457 | ){ |
drh | 111544c | 2014-08-29 16:20:47 +0000 | [diff] [blame] | 2458 | sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff)); |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 2459 | } |
drh | c232aca | 2016-12-15 16:01:17 +0000 | [diff] [blame] | 2460 | returnSingleInt(v, sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1)); |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 2461 | break; |
| 2462 | } |
| 2463 | |
drh | 49a76a8 | 2020-03-31 20:57:06 +0000 | [diff] [blame] | 2464 | /* |
| 2465 | ** PRAGMA analysis_limit |
| 2466 | ** PRAGMA analysis_limit = N |
| 2467 | ** |
| 2468 | ** Configure the maximum number of rows that ANALYZE will examine |
| 2469 | ** in each index that it looks at. Return the new limit. |
| 2470 | */ |
| 2471 | case PragTyp_ANALYSIS_LIMIT: { |
| 2472 | sqlite3_int64 N; |
| 2473 | if( zRight |
drh | bc98f90 | 2021-10-14 17:30:32 +0000 | [diff] [blame] | 2474 | && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */ |
drh | 49a76a8 | 2020-03-31 20:57:06 +0000 | [diff] [blame] | 2475 | && N>=0 |
| 2476 | ){ |
| 2477 | db->nAnalysisLimit = (int)(N&0x7fffffff); |
| 2478 | } |
drh | bc98f90 | 2021-10-14 17:30:32 +0000 | [diff] [blame] | 2479 | returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */ |
drh | 49a76a8 | 2020-03-31 20:57:06 +0000 | [diff] [blame] | 2480 | break; |
| 2481 | } |
| 2482 | |
dougcurrie | 81c95ef | 2004-06-18 23:21:47 +0000 | [diff] [blame] | 2483 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2484 | /* |
| 2485 | ** Report the current state of file logs for all databases |
| 2486 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2487 | case PragTyp_LOCK_STATUS: { |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 2488 | static const char *const azLockName[] = { |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2489 | "unlocked", "shared", "reserved", "pending", "exclusive" |
| 2490 | }; |
| 2491 | int i; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2492 | pParse->nMem = 2; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2493 | for(i=0; i<db->nDb; i++){ |
| 2494 | Btree *pBt; |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 2495 | const char *zState = "unknown"; |
| 2496 | int j; |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 2497 | if( db->aDb[i].zDbSName==0 ) continue; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2498 | pBt = db->aDb[i].pBt; |
drh | 5a05be1 | 2012-10-09 18:51:44 +0000 | [diff] [blame] | 2499 | if( pBt==0 || sqlite3BtreePager(pBt)==0 ){ |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 2500 | zState = "closed"; |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 2501 | }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0, |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 2502 | SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){ |
| 2503 | zState = azLockName[j]; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2504 | } |
drh | 69c3382 | 2016-08-18 14:33:11 +0000 | [diff] [blame] | 2505 | sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2506 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2507 | break; |
| 2508 | } |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2509 | #endif |
| 2510 | |
drh | b48c0d5 | 2020-02-07 01:12:53 +0000 | [diff] [blame] | 2511 | #if defined(SQLITE_ENABLE_CEROD) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2512 | case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2513 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2514 | sqlite3_activate_cerod(&zRight[6]); |
| 2515 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2516 | } |
| 2517 | break; |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2518 | #endif |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 2519 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2520 | } /* End of the PRAGMA switch */ |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 2521 | |
dan | 9e1ab1a | 2017-01-05 19:32:48 +0000 | [diff] [blame] | 2522 | /* The following block is a no-op unless SQLITE_DEBUG is defined. Its only |
| 2523 | ** purpose is to execute assert() statements to verify that if the |
| 2524 | ** PragFlg_NoColumns1 flag is set and the caller specified an argument |
| 2525 | ** to the PRAGMA, the implementation has not added any OP_ResultRow |
| 2526 | ** instructions to the VM. */ |
| 2527 | if( (pPragma->mPragFlg & PragFlg_NoColumns1) && zRight ){ |
| 2528 | sqlite3VdbeVerifyNoResultRow(v); |
| 2529 | } |
| 2530 | |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 2531 | pragma_out: |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 2532 | sqlite3DbFree(db, zLeft); |
| 2533 | sqlite3DbFree(db, zRight); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 2534 | } |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2535 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 2536 | /***************************************************************************** |
| 2537 | ** Implementation of an eponymous virtual table that runs a pragma. |
| 2538 | ** |
| 2539 | */ |
| 2540 | typedef struct PragmaVtab PragmaVtab; |
| 2541 | typedef struct PragmaVtabCursor PragmaVtabCursor; |
| 2542 | struct PragmaVtab { |
| 2543 | sqlite3_vtab base; /* Base class. Must be first */ |
| 2544 | sqlite3 *db; /* The database connection to which it belongs */ |
| 2545 | const PragmaName *pName; /* Name of the pragma */ |
| 2546 | u8 nHidden; /* Number of hidden columns */ |
| 2547 | u8 iHidden; /* Index of the first hidden column */ |
| 2548 | }; |
| 2549 | struct PragmaVtabCursor { |
| 2550 | sqlite3_vtab_cursor base; /* Base class. Must be first */ |
| 2551 | sqlite3_stmt *pPragma; /* The pragma statement to run */ |
| 2552 | sqlite_int64 iRowid; /* Current rowid */ |
| 2553 | char *azArg[2]; /* Value of the argument and schema */ |
| 2554 | }; |
| 2555 | |
| 2556 | /* |
| 2557 | ** Pragma virtual table module xConnect method. |
| 2558 | */ |
| 2559 | static int pragmaVtabConnect( |
| 2560 | sqlite3 *db, |
| 2561 | void *pAux, |
| 2562 | int argc, const char *const*argv, |
| 2563 | sqlite3_vtab **ppVtab, |
| 2564 | char **pzErr |
| 2565 | ){ |
| 2566 | const PragmaName *pPragma = (const PragmaName*)pAux; |
| 2567 | PragmaVtab *pTab = 0; |
| 2568 | int rc; |
| 2569 | int i, j; |
| 2570 | char cSep = '('; |
| 2571 | StrAccum acc; |
| 2572 | char zBuf[200]; |
| 2573 | |
drh | 344a1bf | 2016-12-22 14:53:25 +0000 | [diff] [blame] | 2574 | UNUSED_PARAMETER(argc); |
| 2575 | UNUSED_PARAMETER(argv); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2576 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2577 | sqlite3_str_appendall(&acc, "CREATE TABLE x"); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2578 | for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2579 | sqlite3_str_appendf(&acc, "%c\"%s\"", cSep, pragCName[j]); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2580 | cSep = ','; |
| 2581 | } |
drh | 9a63f09 | 2016-12-16 02:14:15 +0000 | [diff] [blame] | 2582 | if( i==0 ){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2583 | sqlite3_str_appendf(&acc, "(\"%s\"", pPragma->zName); |
drh | 9a63f09 | 2016-12-16 02:14:15 +0000 | [diff] [blame] | 2584 | i++; |
| 2585 | } |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2586 | j = 0; |
| 2587 | if( pPragma->mPragFlg & PragFlg_Result1 ){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2588 | sqlite3_str_appendall(&acc, ",arg HIDDEN"); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2589 | j++; |
| 2590 | } |
| 2591 | if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2592 | sqlite3_str_appendall(&acc, ",schema HIDDEN"); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2593 | j++; |
| 2594 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2595 | sqlite3_str_append(&acc, ")", 1); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2596 | sqlite3StrAccumFinish(&acc); |
| 2597 | assert( strlen(zBuf) < sizeof(zBuf)-1 ); |
| 2598 | rc = sqlite3_declare_vtab(db, zBuf); |
| 2599 | if( rc==SQLITE_OK ){ |
| 2600 | pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab)); |
| 2601 | if( pTab==0 ){ |
| 2602 | rc = SQLITE_NOMEM; |
| 2603 | }else{ |
| 2604 | memset(pTab, 0, sizeof(PragmaVtab)); |
| 2605 | pTab->pName = pPragma; |
| 2606 | pTab->db = db; |
| 2607 | pTab->iHidden = i; |
| 2608 | pTab->nHidden = j; |
| 2609 | } |
| 2610 | }else{ |
| 2611 | *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db)); |
| 2612 | } |
| 2613 | |
| 2614 | *ppVtab = (sqlite3_vtab*)pTab; |
| 2615 | return rc; |
| 2616 | } |
| 2617 | |
| 2618 | /* |
| 2619 | ** Pragma virtual table module xDisconnect method. |
| 2620 | */ |
| 2621 | static int pragmaVtabDisconnect(sqlite3_vtab *pVtab){ |
| 2622 | PragmaVtab *pTab = (PragmaVtab*)pVtab; |
| 2623 | sqlite3_free(pTab); |
| 2624 | return SQLITE_OK; |
| 2625 | } |
| 2626 | |
| 2627 | /* Figure out the best index to use to search a pragma virtual table. |
| 2628 | ** |
| 2629 | ** There are not really any index choices. But we want to encourage the |
| 2630 | ** query planner to give == constraints on as many hidden parameters as |
| 2631 | ** possible, and especially on the first hidden parameter. So return a |
| 2632 | ** high cost if hidden parameters are unconstrained. |
| 2633 | */ |
| 2634 | static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ |
| 2635 | PragmaVtab *pTab = (PragmaVtab*)tab; |
| 2636 | const struct sqlite3_index_constraint *pConstraint; |
| 2637 | int i, j; |
| 2638 | int seen[2]; |
| 2639 | |
drh | ae7045c | 2016-12-15 21:33:55 +0000 | [diff] [blame] | 2640 | pIdxInfo->estimatedCost = (double)1; |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2641 | if( pTab->nHidden==0 ){ return SQLITE_OK; } |
| 2642 | pConstraint = pIdxInfo->aConstraint; |
| 2643 | seen[0] = 0; |
| 2644 | seen[1] = 0; |
| 2645 | for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ |
| 2646 | if( pConstraint->usable==0 ) continue; |
| 2647 | if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; |
| 2648 | if( pConstraint->iColumn < pTab->iHidden ) continue; |
| 2649 | j = pConstraint->iColumn - pTab->iHidden; |
| 2650 | assert( j < 2 ); |
drh | d7175eb | 2016-12-15 21:11:15 +0000 | [diff] [blame] | 2651 | seen[j] = i+1; |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2652 | } |
| 2653 | if( seen[0]==0 ){ |
| 2654 | pIdxInfo->estimatedCost = (double)2147483647; |
| 2655 | pIdxInfo->estimatedRows = 2147483647; |
| 2656 | return SQLITE_OK; |
| 2657 | } |
drh | d7175eb | 2016-12-15 21:11:15 +0000 | [diff] [blame] | 2658 | j = seen[0]-1; |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2659 | pIdxInfo->aConstraintUsage[j].argvIndex = 1; |
| 2660 | pIdxInfo->aConstraintUsage[j].omit = 1; |
| 2661 | if( seen[1]==0 ) return SQLITE_OK; |
| 2662 | pIdxInfo->estimatedCost = (double)20; |
| 2663 | pIdxInfo->estimatedRows = 20; |
drh | d7175eb | 2016-12-15 21:11:15 +0000 | [diff] [blame] | 2664 | j = seen[1]-1; |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2665 | pIdxInfo->aConstraintUsage[j].argvIndex = 2; |
| 2666 | pIdxInfo->aConstraintUsage[j].omit = 1; |
| 2667 | return SQLITE_OK; |
| 2668 | } |
| 2669 | |
| 2670 | /* Create a new cursor for the pragma virtual table */ |
| 2671 | static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor){ |
| 2672 | PragmaVtabCursor *pCsr; |
| 2673 | pCsr = (PragmaVtabCursor*)sqlite3_malloc(sizeof(*pCsr)); |
| 2674 | if( pCsr==0 ) return SQLITE_NOMEM; |
| 2675 | memset(pCsr, 0, sizeof(PragmaVtabCursor)); |
| 2676 | pCsr->base.pVtab = pVtab; |
| 2677 | *ppCursor = &pCsr->base; |
| 2678 | return SQLITE_OK; |
| 2679 | } |
| 2680 | |
| 2681 | /* Clear all content from pragma virtual table cursor. */ |
| 2682 | static void pragmaVtabCursorClear(PragmaVtabCursor *pCsr){ |
| 2683 | int i; |
| 2684 | sqlite3_finalize(pCsr->pPragma); |
| 2685 | pCsr->pPragma = 0; |
| 2686 | for(i=0; i<ArraySize(pCsr->azArg); i++){ |
| 2687 | sqlite3_free(pCsr->azArg[i]); |
| 2688 | pCsr->azArg[i] = 0; |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | /* Close a pragma virtual table cursor */ |
| 2693 | static int pragmaVtabClose(sqlite3_vtab_cursor *cur){ |
| 2694 | PragmaVtabCursor *pCsr = (PragmaVtabCursor*)cur; |
| 2695 | pragmaVtabCursorClear(pCsr); |
drh | 9a63f09 | 2016-12-16 02:14:15 +0000 | [diff] [blame] | 2696 | sqlite3_free(pCsr); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2697 | return SQLITE_OK; |
| 2698 | } |
| 2699 | |
| 2700 | /* Advance the pragma virtual table cursor to the next row */ |
| 2701 | static int pragmaVtabNext(sqlite3_vtab_cursor *pVtabCursor){ |
| 2702 | PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor; |
| 2703 | int rc = SQLITE_OK; |
| 2704 | |
| 2705 | /* Increment the xRowid value */ |
| 2706 | pCsr->iRowid++; |
drh | 9a63f09 | 2016-12-16 02:14:15 +0000 | [diff] [blame] | 2707 | assert( pCsr->pPragma ); |
| 2708 | if( SQLITE_ROW!=sqlite3_step(pCsr->pPragma) ){ |
| 2709 | rc = sqlite3_finalize(pCsr->pPragma); |
| 2710 | pCsr->pPragma = 0; |
| 2711 | pragmaVtabCursorClear(pCsr); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2712 | } |
| 2713 | return rc; |
| 2714 | } |
| 2715 | |
| 2716 | /* |
| 2717 | ** Pragma virtual table module xFilter method. |
| 2718 | */ |
| 2719 | static int pragmaVtabFilter( |
| 2720 | sqlite3_vtab_cursor *pVtabCursor, |
| 2721 | int idxNum, const char *idxStr, |
| 2722 | int argc, sqlite3_value **argv |
| 2723 | ){ |
| 2724 | PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor; |
| 2725 | PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab); |
| 2726 | int rc; |
drh | d8b7200 | 2016-12-16 04:20:27 +0000 | [diff] [blame] | 2727 | int i, j; |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2728 | StrAccum acc; |
| 2729 | char *zSql; |
| 2730 | |
drh | 344a1bf | 2016-12-22 14:53:25 +0000 | [diff] [blame] | 2731 | UNUSED_PARAMETER(idxNum); |
| 2732 | UNUSED_PARAMETER(idxStr); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2733 | pragmaVtabCursorClear(pCsr); |
drh | d8b7200 | 2016-12-16 04:20:27 +0000 | [diff] [blame] | 2734 | j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1; |
| 2735 | for(i=0; i<argc; i++, j++){ |
dan | d8ecefa | 2017-07-15 20:48:30 +0000 | [diff] [blame] | 2736 | const char *zText = (const char*)sqlite3_value_text(argv[i]); |
drh | d8b7200 | 2016-12-16 04:20:27 +0000 | [diff] [blame] | 2737 | assert( j<ArraySize(pCsr->azArg) ); |
dan | d8ecefa | 2017-07-15 20:48:30 +0000 | [diff] [blame] | 2738 | assert( pCsr->azArg[j]==0 ); |
| 2739 | if( zText ){ |
| 2740 | pCsr->azArg[j] = sqlite3_mprintf("%s", zText); |
| 2741 | if( pCsr->azArg[j]==0 ){ |
| 2742 | return SQLITE_NOMEM; |
| 2743 | } |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2744 | } |
| 2745 | } |
drh | d7175eb | 2016-12-15 21:11:15 +0000 | [diff] [blame] | 2746 | sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]); |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2747 | sqlite3_str_appendall(&acc, "PRAGMA "); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2748 | if( pCsr->azArg[1] ){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2749 | sqlite3_str_appendf(&acc, "%Q.", pCsr->azArg[1]); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2750 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2751 | sqlite3_str_appendall(&acc, pTab->pName->zName); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2752 | if( pCsr->azArg[0] ){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 2753 | sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2754 | } |
| 2755 | zSql = sqlite3StrAccumFinish(&acc); |
| 2756 | if( zSql==0 ) return SQLITE_NOMEM; |
| 2757 | rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0); |
| 2758 | sqlite3_free(zSql); |
| 2759 | if( rc!=SQLITE_OK ){ |
| 2760 | pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db)); |
| 2761 | return rc; |
| 2762 | } |
| 2763 | return pragmaVtabNext(pVtabCursor); |
| 2764 | } |
| 2765 | |
| 2766 | /* |
| 2767 | ** Pragma virtual table module xEof method. |
| 2768 | */ |
| 2769 | static int pragmaVtabEof(sqlite3_vtab_cursor *pVtabCursor){ |
| 2770 | PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor; |
| 2771 | return (pCsr->pPragma==0); |
| 2772 | } |
| 2773 | |
| 2774 | /* The xColumn method simply returns the corresponding column from |
| 2775 | ** the PRAGMA. |
| 2776 | */ |
| 2777 | static int pragmaVtabColumn( |
| 2778 | sqlite3_vtab_cursor *pVtabCursor, |
| 2779 | sqlite3_context *ctx, |
| 2780 | int i |
| 2781 | ){ |
| 2782 | PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor; |
| 2783 | PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab); |
| 2784 | if( i<pTab->iHidden ){ |
| 2785 | sqlite3_result_value(ctx, sqlite3_column_value(pCsr->pPragma, i)); |
| 2786 | }else{ |
| 2787 | sqlite3_result_text(ctx, pCsr->azArg[i-pTab->iHidden],-1,SQLITE_TRANSIENT); |
| 2788 | } |
| 2789 | return SQLITE_OK; |
| 2790 | } |
| 2791 | |
| 2792 | /* |
| 2793 | ** Pragma virtual table module xRowid method. |
| 2794 | */ |
| 2795 | static int pragmaVtabRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *p){ |
| 2796 | PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor; |
| 2797 | *p = pCsr->iRowid; |
| 2798 | return SQLITE_OK; |
| 2799 | } |
| 2800 | |
| 2801 | /* The pragma virtual table object */ |
| 2802 | static const sqlite3_module pragmaVtabModule = { |
| 2803 | 0, /* iVersion */ |
| 2804 | 0, /* xCreate - create a table */ |
| 2805 | pragmaVtabConnect, /* xConnect - connect to an existing table */ |
| 2806 | pragmaVtabBestIndex, /* xBestIndex - Determine search strategy */ |
| 2807 | pragmaVtabDisconnect, /* xDisconnect - Disconnect from a table */ |
| 2808 | 0, /* xDestroy - Drop a table */ |
| 2809 | pragmaVtabOpen, /* xOpen - open a cursor */ |
| 2810 | pragmaVtabClose, /* xClose - close a cursor */ |
| 2811 | pragmaVtabFilter, /* xFilter - configure scan constraints */ |
| 2812 | pragmaVtabNext, /* xNext - advance a cursor */ |
| 2813 | pragmaVtabEof, /* xEof */ |
| 2814 | pragmaVtabColumn, /* xColumn - read data */ |
| 2815 | pragmaVtabRowid, /* xRowid - read data */ |
| 2816 | 0, /* xUpdate - write data */ |
| 2817 | 0, /* xBegin - begin transaction */ |
| 2818 | 0, /* xSync - sync transaction */ |
| 2819 | 0, /* xCommit - commit transaction */ |
| 2820 | 0, /* xRollback - rollback transaction */ |
| 2821 | 0, /* xFindFunction - function overloading */ |
| 2822 | 0, /* xRename - rename the table */ |
| 2823 | 0, /* xSavepoint */ |
| 2824 | 0, /* xRelease */ |
drh | 84c501b | 2018-11-05 23:01:45 +0000 | [diff] [blame] | 2825 | 0, /* xRollbackTo */ |
| 2826 | 0 /* xShadowName */ |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2827 | }; |
| 2828 | |
| 2829 | /* |
| 2830 | ** Check to see if zTabName is really the name of a pragma. If it is, |
| 2831 | ** then register an eponymous virtual table for that pragma and return |
| 2832 | ** a pointer to the Module object for the new virtual table. |
| 2833 | */ |
| 2834 | Module *sqlite3PragmaVtabRegister(sqlite3 *db, const char *zName){ |
| 2835 | const PragmaName *pName; |
| 2836 | assert( sqlite3_strnicmp(zName, "pragma_", 7)==0 ); |
| 2837 | pName = pragmaLocate(zName+7); |
| 2838 | if( pName==0 ) return 0; |
| 2839 | if( (pName->mPragFlg & (PragFlg_Result0|PragFlg_Result1))==0 ) return 0; |
| 2840 | assert( sqlite3HashFind(&db->aModule, zName)==0 ); |
drh | d7175eb | 2016-12-15 21:11:15 +0000 | [diff] [blame] | 2841 | return sqlite3VtabCreateModule(db, zName, &pragmaVtabModule, (void*)pName, 0); |
drh | 2fcc159 | 2016-12-15 20:59:03 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2845 | |
drh | 8bfdf72 | 2009-06-19 14:06:03 +0000 | [diff] [blame] | 2846 | #endif /* SQLITE_OMIT_PRAGMA */ |