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 ){ |
danielk1977 | 983e230 | 2008-07-08 07:35:51 +0000 | [diff] [blame] | 134 | if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 135 | sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " |
| 136 | "from within a transaction"); |
| 137 | return SQLITE_ERROR; |
| 138 | } |
| 139 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 140 | db->aDb[1].pBt = 0; |
drh | 81028a4 | 2012-05-15 18:28:27 +0000 | [diff] [blame] | 141 | sqlite3ResetAllSchemasOfConnection(db); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 142 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 143 | return SQLITE_OK; |
| 144 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 145 | #endif /* SQLITE_PAGER_PRAGMAS */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 146 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 147 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 148 | /* |
| 149 | ** If the TEMP database is open, close it and mark the database schema |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 150 | ** as needing reloading. This must be done when using the SQLITE_TEMP_STORE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 151 | ** or DEFAULT_TEMP_STORE pragmas. |
| 152 | */ |
| 153 | static int changeTempStorage(Parse *pParse, const char *zStorageType){ |
| 154 | int ts = getTempStore(zStorageType); |
| 155 | sqlite3 *db = pParse->db; |
| 156 | if( db->temp_store==ts ) return SQLITE_OK; |
| 157 | if( invalidateTempStorage( pParse ) != SQLITE_OK ){ |
| 158 | return SQLITE_ERROR; |
| 159 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 160 | db->temp_store = (u8)ts; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 161 | return SQLITE_OK; |
| 162 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 163 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 164 | |
| 165 | /* |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 166 | ** Set the names of the first N columns to the values in azCol[] |
| 167 | */ |
| 168 | static void setAllColumnNames( |
| 169 | Vdbe *v, /* The query under construction */ |
| 170 | int N, /* Number of columns */ |
| 171 | const char **azCol /* Names of columns */ |
| 172 | ){ |
| 173 | int i; |
| 174 | sqlite3VdbeSetNumCols(v, N); |
| 175 | for(i=0; i<N; i++){ |
| 176 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC); |
| 177 | } |
| 178 | } |
| 179 | static void setOneColumnName(Vdbe *v, const char *z){ |
| 180 | setAllColumnNames(v, 1, &z); |
| 181 | } |
| 182 | |
| 183 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 184 | ** Generate code to return a single integer value. |
| 185 | */ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 186 | static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){ |
| 187 | sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64); |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 188 | setOneColumnName(v, zLabel); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 189 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | ** Generate code to return a single text value. |
| 194 | */ |
| 195 | static void returnSingleText( |
| 196 | Vdbe *v, /* Prepared statement under construction */ |
| 197 | const char *zLabel, /* Name of the result column */ |
| 198 | const char *zValue /* Value to be returned */ |
| 199 | ){ |
| 200 | if( zValue ){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 201 | sqlite3VdbeLoadString(v, 1, (const char*)zValue); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 202 | setOneColumnName(v, zLabel); |
| 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 | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 281 | ** Process a pragma statement. |
| 282 | ** |
| 283 | ** Pragmas are of this form: |
| 284 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 285 | ** PRAGMA [schema.]id [= value] |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 286 | ** |
| 287 | ** The identifier might also be a string. The value is a string, and |
| 288 | ** identifier, or a number. If minusFlag is true, then the value is |
| 289 | ** a number that was preceded by a minus sign. |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 290 | ** |
| 291 | ** If the left side is "database.id" then pId1 is the database name |
| 292 | ** and pId2 is the id. If the left side is just "id" then pId1 is the |
| 293 | ** id and pId2 is any empty string. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 294 | */ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 295 | void sqlite3Pragma( |
| 296 | Parse *pParse, |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 297 | Token *pId1, /* First part of [schema.]id field */ |
| 298 | Token *pId2, /* Second part of [schema.]id field, or NULL */ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 299 | Token *pValue, /* Token for <value>, or NULL */ |
| 300 | int minusFlag /* True if a '-' sign preceded <value> */ |
| 301 | ){ |
| 302 | char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ |
| 303 | char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
| 304 | const char *zDb = 0; /* The database name */ |
| 305 | Token *pId; /* Pointer to <id> token */ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 306 | char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 307 | int iDb; /* Database index for <database> */ |
mistachkin | 1a51ce7 | 2015-01-12 18:38:02 +0000 | [diff] [blame] | 308 | int lwr, upr, mid = 0; /* Binary search bounds */ |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 309 | int rc; /* return value form SQLITE_FCNTL_PRAGMA */ |
| 310 | sqlite3 *db = pParse->db; /* The database connection */ |
| 311 | Db *pDb; /* The specific database being pragmaed */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 312 | Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 313 | const struct sPragmaNames *pPragma; |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 314 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 315 | if( v==0 ) return; |
drh | 4611d92 | 2010-02-25 14:47:01 +0000 | [diff] [blame] | 316 | sqlite3VdbeRunOnlyOnce(v); |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 317 | pParse->nMem = 2; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 318 | |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 319 | /* Interpret the [schema.] part of the pragma statement. iDb is the |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 320 | ** index of the database this pragma is being applied to in db.aDb[]. */ |
| 321 | iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); |
| 322 | if( iDb<0 ) return; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 323 | pDb = &db->aDb[iDb]; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 324 | |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 325 | /* If the temp database has been explicitly named as part of the |
| 326 | ** pragma, make sure it is open. |
| 327 | */ |
| 328 | if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){ |
| 329 | return; |
| 330 | } |
| 331 | |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 332 | zLeft = sqlite3NameFromToken(db, pId); |
danielk1977 | 96fb0dd | 2004-06-30 09:49:22 +0000 | [diff] [blame] | 333 | if( !zLeft ) return; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 334 | if( minusFlag ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 335 | zRight = sqlite3MPrintf(db, "-%T", pValue); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 336 | }else{ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 337 | zRight = sqlite3NameFromToken(db, pValue); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 338 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 339 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 340 | assert( pId2 ); |
| 341 | zDb = pId2->n>0 ? pDb->zName : 0; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 342 | if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 343 | goto pragma_out; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 344 | } |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 345 | |
| 346 | /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS |
| 347 | ** connection. If it returns SQLITE_OK, then assume that the VFS |
| 348 | ** handled the pragma and generate a no-op prepared statement. |
drh | 8dd7a6a | 2015-03-06 04:37:26 +0000 | [diff] [blame] | 349 | ** |
| 350 | ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed, |
| 351 | ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file |
| 352 | ** object corresponding to the database file to which the pragma |
| 353 | ** statement refers. |
| 354 | ** |
| 355 | ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA |
| 356 | ** file control is an array of pointers to strings (char**) in which the |
| 357 | ** second element of the array is the name of the pragma and the third |
| 358 | ** element is the argument to the pragma or NULL if the pragma has no |
| 359 | ** argument. |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 360 | */ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 361 | aFcntl[0] = 0; |
| 362 | aFcntl[1] = zLeft; |
| 363 | aFcntl[2] = zRight; |
| 364 | aFcntl[3] = 0; |
dan | 80bb6f8 | 2012-10-01 18:44:33 +0000 | [diff] [blame] | 365 | db->busyHandler.nBusy = 0; |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 366 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 367 | if( rc==SQLITE_OK ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 368 | returnSingleText(v, "result", aFcntl[0]); |
| 369 | sqlite3_free(aFcntl[0]); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 370 | goto pragma_out; |
| 371 | } |
| 372 | if( rc!=SQLITE_NOTFOUND ){ |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 373 | if( aFcntl[0] ){ |
| 374 | sqlite3ErrorMsg(pParse, "%s", aFcntl[0]); |
| 375 | sqlite3_free(aFcntl[0]); |
| 376 | } |
| 377 | pParse->nErr++; |
| 378 | pParse->rc = rc; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 379 | goto pragma_out; |
| 380 | } |
| 381 | |
| 382 | /* Locate the pragma in the lookup table */ |
| 383 | lwr = 0; |
| 384 | upr = ArraySize(aPragmaNames)-1; |
| 385 | while( lwr<=upr ){ |
| 386 | mid = (lwr+upr)/2; |
| 387 | rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName); |
| 388 | if( rc==0 ) break; |
| 389 | if( rc<0 ){ |
| 390 | upr = mid - 1; |
| 391 | }else{ |
| 392 | lwr = mid + 1; |
| 393 | } |
| 394 | } |
| 395 | if( lwr>upr ) goto pragma_out; |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 396 | pPragma = &aPragmaNames[mid]; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 397 | |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 398 | /* Make sure the database schema is loaded if the pragma requires that */ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 399 | if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){ |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 400 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 401 | } |
| 402 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 403 | /* Jump to the appropriate pragma handler */ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 404 | switch( pPragma->ePragTyp ){ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 405 | |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 406 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 407 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 408 | ** PRAGMA [schema.]default_cache_size |
| 409 | ** PRAGMA [schema.]default_cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 410 | ** |
| 411 | ** The first form reports the current persistent setting for the |
| 412 | ** page cache size. The value returned is the maximum number of |
| 413 | ** pages in the page cache. The second form sets both the current |
| 414 | ** page cache size value and the persistent page cache size value |
| 415 | ** stored in the database file. |
| 416 | ** |
drh | 93791ea | 2010-04-26 17:36:35 +0000 | [diff] [blame] | 417 | ** Older versions of SQLite would set the default cache size to a |
| 418 | ** negative number to indicate synchronous=OFF. These days, synchronous |
| 419 | ** is always on by default regardless of the sign of the default cache |
| 420 | ** size. But continue to take the absolute value of the default cache |
| 421 | ** size of historical compatibility. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 422 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 423 | case PragTyp_DEFAULT_CACHE_SIZE: { |
drh | b06a4ec | 2014-03-10 18:03:09 +0000 | [diff] [blame] | 424 | static const int iLn = VDBE_OFFSET_LINENO(2); |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 425 | static const VdbeOpList getCacheSize[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 426 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 427 | { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 428 | { OP_IfPos, 1, 8, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 429 | { OP_Integer, 0, 2, 0}, |
| 430 | { OP_Subtract, 1, 2, 1}, |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 431 | { OP_IfPos, 1, 8, 0}, |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 432 | { OP_Integer, 0, 1, 0}, /* 6 */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 433 | { OP_Noop, 0, 0, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 434 | { OP_ResultRow, 1, 1, 0}, |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 435 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 436 | VdbeOp *aOp; |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 437 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 438 | if( !zRight ){ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 439 | setOneColumnName(v, "cache_size"); |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 440 | pParse->nMem += 2; |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 441 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 442 | aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 443 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 444 | aOp[0].p1 = iDb; |
| 445 | aOp[1].p1 = iDb; |
| 446 | aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 447 | }else{ |
drh | d50ffc4 | 2011-03-08 02:38:28 +0000 | [diff] [blame] | 448 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 449 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 450 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, size); |
drh | 2120608 | 2011-04-04 18:22:02 +0000 | [diff] [blame] | 451 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 452 | pDb->pSchema->cache_size = size; |
| 453 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 454 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 455 | break; |
| 456 | } |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 457 | #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 458 | |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 459 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 460 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 461 | ** PRAGMA [schema.]page_size |
| 462 | ** PRAGMA [schema.]page_size=N |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 463 | ** |
| 464 | ** The first form reports the current setting for the |
| 465 | ** database page size in bytes. The second form sets the |
| 466 | ** database page size value. The value can only be set if |
| 467 | ** the database has not yet been created. |
| 468 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 469 | case PragTyp_PAGE_SIZE: { |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 470 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 471 | assert( pBt!=0 ); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 472 | if( !zRight ){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 473 | int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0; |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 474 | returnSingleInt(v, "page_size", size); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 475 | }else{ |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 476 | /* Malloc may fail when setting the page-size, as there is an internal |
| 477 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 478 | */ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 479 | db->nextPagesize = sqlite3Atoi(zRight); |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 480 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){ |
drh | 4a642b6 | 2016-02-05 01:55:27 +0000 | [diff] [blame] | 481 | sqlite3OomFault(db); |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 482 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 483 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 484 | break; |
| 485 | } |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 486 | |
| 487 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 488 | ** PRAGMA [schema.]secure_delete |
| 489 | ** PRAGMA [schema.]secure_delete=ON/OFF |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 490 | ** |
| 491 | ** The first form reports the current setting for the |
| 492 | ** secure_delete flag. The second form changes the secure_delete |
| 493 | ** flag setting and reports thenew value. |
| 494 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 495 | case PragTyp_SECURE_DELETE: { |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 496 | Btree *pBt = pDb->pBt; |
| 497 | int b = -1; |
| 498 | assert( pBt!=0 ); |
| 499 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 500 | b = sqlite3GetBoolean(zRight, 0); |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 501 | } |
drh | af034ed | 2010-02-12 19:46:26 +0000 | [diff] [blame] | 502 | if( pId2->n==0 && b>=0 ){ |
| 503 | int ii; |
| 504 | for(ii=0; ii<db->nDb; ii++){ |
| 505 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| 506 | } |
| 507 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 508 | b = sqlite3BtreeSecureDelete(pBt, b); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 509 | returnSingleInt(v, "secure_delete", b); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 510 | break; |
| 511 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 512 | |
| 513 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 514 | ** PRAGMA [schema.]max_page_count |
| 515 | ** PRAGMA [schema.]max_page_count=N |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 516 | ** |
| 517 | ** The first form reports the current setting for the |
| 518 | ** maximum number of pages in the database file. The |
| 519 | ** second form attempts to change this setting. Both |
| 520 | ** forms return the current setting. |
| 521 | ** |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 522 | ** The absolute value of N is used. This is undocumented and might |
| 523 | ** change. The only purpose is to provide an easy way to test |
| 524 | ** the sqlite3AbsInt32() function. |
| 525 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 526 | ** PRAGMA [schema.]page_count |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 527 | ** |
| 528 | ** Return the number of pages in the specified database. |
| 529 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 530 | case PragTyp_PAGE_COUNT: { |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 531 | int iReg; |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 532 | sqlite3CodeVerifySchema(pParse, iDb); |
| 533 | iReg = ++pParse->nMem; |
drh | c522731 | 2011-10-13 17:09:01 +0000 | [diff] [blame] | 534 | if( sqlite3Tolower(zLeft[0])=='p' ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 535 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 536 | }else{ |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 537 | sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, |
| 538 | sqlite3AbsInt32(sqlite3Atoi(zRight))); |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 539 | } |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 540 | sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); |
| 541 | sqlite3VdbeSetNumCols(v, 1); |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 542 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 543 | break; |
| 544 | } |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 545 | |
| 546 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 547 | ** PRAGMA [schema.]locking_mode |
| 548 | ** PRAGMA [schema.]locking_mode = (normal|exclusive) |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 549 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 550 | case PragTyp_LOCKING_MODE: { |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 551 | const char *zRet = "normal"; |
| 552 | int eMode = getLockingMode(zRight); |
| 553 | |
| 554 | if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){ |
| 555 | /* Simple "PRAGMA locking_mode;" statement. This is a query for |
| 556 | ** the current default locking mode (which may be different to |
| 557 | ** the locking-mode of the main database). |
| 558 | */ |
| 559 | eMode = db->dfltLockMode; |
| 560 | }else{ |
| 561 | Pager *pPager; |
| 562 | if( pId2->n==0 ){ |
| 563 | /* This indicates that no database name was specified as part |
| 564 | ** of the PRAGMA command. In this case the locking-mode must be |
| 565 | ** set on all attached databases, as well as the main db file. |
| 566 | ** |
| 567 | ** Also, the sqlite3.dfltLockMode variable is set so that |
| 568 | ** any subsequently attached databases also use the specified |
| 569 | ** locking mode. |
| 570 | */ |
| 571 | int ii; |
| 572 | assert(pDb==&db->aDb[0]); |
| 573 | for(ii=2; ii<db->nDb; ii++){ |
| 574 | pPager = sqlite3BtreePager(db->aDb[ii].pBt); |
| 575 | sqlite3PagerLockingMode(pPager, eMode); |
| 576 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 577 | db->dfltLockMode = (u8)eMode; |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 578 | } |
| 579 | pPager = sqlite3BtreePager(pDb->pBt); |
| 580 | eMode = sqlite3PagerLockingMode(pPager, eMode); |
| 581 | } |
| 582 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 583 | assert( eMode==PAGER_LOCKINGMODE_NORMAL |
| 584 | || eMode==PAGER_LOCKINGMODE_EXCLUSIVE ); |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 585 | if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){ |
| 586 | zRet = "exclusive"; |
| 587 | } |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 588 | returnSingleText(v, "locking_mode", zRet); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 589 | break; |
| 590 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 591 | |
| 592 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 593 | ** PRAGMA [schema.]journal_mode |
| 594 | ** PRAGMA [schema.]journal_mode = |
drh | 3ebaee9 | 2010-05-06 21:37:22 +0000 | [diff] [blame] | 595 | ** (delete|persist|off|truncate|memory|wal|off) |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 596 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 597 | case PragTyp_JOURNAL_MODE: { |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 598 | int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ |
| 599 | int ii; /* Loop counter */ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 600 | |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 601 | setOneColumnName(v, "journal_mode"); |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 602 | if( zRight==0 ){ |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 603 | /* If there is no "=MODE" part of the pragma, do a query for the |
| 604 | ** current mode */ |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 605 | eMode = PAGER_JOURNALMODE_QUERY; |
| 606 | }else{ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 607 | const char *zMode; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 608 | int n = sqlite3Strlen30(zRight); |
drh | f77e2ac | 2010-07-07 14:33:09 +0000 | [diff] [blame] | 609 | for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 610 | if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break; |
| 611 | } |
| 612 | if( !zMode ){ |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 613 | /* If the "=MODE" part does not match any known journal mode, |
| 614 | ** then do a query */ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 615 | eMode = PAGER_JOURNALMODE_QUERY; |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 618 | if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){ |
| 619 | /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */ |
| 620 | iDb = 0; |
| 621 | pId2->n = 1; |
| 622 | } |
| 623 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 624 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
| 625 | sqlite3VdbeUsesBtree(v, ii); |
| 626 | sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode); |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 627 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 628 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 629 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 630 | break; |
| 631 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 632 | |
| 633 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 634 | ** PRAGMA [schema.]journal_size_limit |
| 635 | ** PRAGMA [schema.]journal_size_limit=N |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 636 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 637 | ** Get or set the size limit on rollback journal files. |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 638 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 639 | case PragTyp_JOURNAL_SIZE_LIMIT: { |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 640 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 641 | i64 iLimit = -2; |
| 642 | if( zRight ){ |
drh | 9296c18 | 2014-07-23 13:40:49 +0000 | [diff] [blame] | 643 | sqlite3DecOrHexToI64(zRight, &iLimit); |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 644 | if( iLimit<-1 ) iLimit = -1; |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 645 | } |
| 646 | iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 647 | returnSingleInt(v, "journal_size_limit", iLimit); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 648 | break; |
| 649 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 650 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 651 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 652 | |
| 653 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 654 | ** PRAGMA [schema.]auto_vacuum |
| 655 | ** PRAGMA [schema.]auto_vacuum=N |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 656 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 657 | ** Get or set the value of the database 'auto-vacuum' parameter. |
| 658 | ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 659 | */ |
| 660 | #ifndef SQLITE_OMIT_AUTOVACUUM |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 661 | case PragTyp_AUTO_VACUUM: { |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 662 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 663 | assert( pBt!=0 ); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 664 | if( !zRight ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 665 | returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt)); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 666 | }else{ |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 667 | int eAuto = getAutoVacuum(zRight); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 668 | assert( eAuto>=0 && eAuto<=2 ); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 669 | db->nextAutovac = (u8)eAuto; |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 670 | /* Call SetAutoVacuum() to set initialize the internal auto and |
| 671 | ** incr-vacuum flags. This is required in case this connection |
| 672 | ** creates the database file. It is important that it is created |
| 673 | ** as an auto-vacuum capable db. |
| 674 | */ |
| 675 | rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 676 | if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 677 | /* When setting the auto_vacuum mode to either "full" or |
| 678 | ** "incremental", write the value of meta[6] in the database |
| 679 | ** file. Before writing to meta[6], check that meta[3] indicates |
| 680 | ** that this really is an auto-vacuum capable database. |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 681 | */ |
drh | b06a4ec | 2014-03-10 18:03:09 +0000 | [diff] [blame] | 682 | static const int iLn = VDBE_OFFSET_LINENO(2); |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 683 | static const VdbeOpList setMeta6[] = { |
| 684 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 685 | { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 686 | { OP_If, 1, 0, 0}, /* 2 */ |
| 687 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 688 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */ |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 689 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 690 | VdbeOp *aOp; |
| 691 | int iAddr = sqlite3VdbeCurrentAddr(v); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 692 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setMeta6)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 693 | aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 694 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 695 | aOp[0].p1 = iDb; |
| 696 | aOp[1].p1 = iDb; |
| 697 | aOp[2].p2 = iAddr+4; |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 698 | aOp[4].p1 = iDb; |
| 699 | aOp[4].p3 = eAuto - 1; |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 700 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 701 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 702 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 703 | break; |
| 704 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 705 | #endif |
| 706 | |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 707 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 708 | ** PRAGMA [schema.]incremental_vacuum(N) |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 709 | ** |
| 710 | ** Do N steps of incremental vacuuming on a database. |
| 711 | */ |
| 712 | #ifndef SQLITE_OMIT_AUTOVACUUM |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 713 | case PragTyp_INCREMENTAL_VACUUM: { |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 714 | int iLimit, addr; |
| 715 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 716 | iLimit = 0x7fffffff; |
| 717 | } |
| 718 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 4c58312 | 2008-01-04 22:01:03 +0000 | [diff] [blame] | 719 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 720 | addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 721 | sqlite3VdbeAddOp1(v, OP_ResultRow, 1); |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 722 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 723 | sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v); |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 724 | sqlite3VdbeJumpHere(v, addr); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 725 | break; |
| 726 | } |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 727 | #endif |
| 728 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 729 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 730 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 731 | ** PRAGMA [schema.]cache_size |
| 732 | ** PRAGMA [schema.]cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 733 | ** |
| 734 | ** The first form reports the current local setting for the |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 735 | ** page cache size. The second form sets the local |
| 736 | ** page cache size value. If N is positive then that is the |
| 737 | ** number of pages in the cache. If N is negative, then the |
| 738 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 739 | ** of memory. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 740 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 741 | case PragTyp_CACHE_SIZE: { |
drh | 2120608 | 2011-04-04 18:22:02 +0000 | [diff] [blame] | 742 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 743 | if( !zRight ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 744 | returnSingleInt(v, "cache_size", pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 745 | }else{ |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 746 | int size = sqlite3Atoi(zRight); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 747 | pDb->pSchema->cache_size = size; |
| 748 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 749 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 750 | break; |
| 751 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 752 | |
| 753 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 754 | ** PRAGMA [schema.]cache_spill |
| 755 | ** PRAGMA cache_spill=BOOLEAN |
| 756 | ** PRAGMA [schema.]cache_spill=N |
| 757 | ** |
| 758 | ** The first form reports the current local setting for the |
| 759 | ** page cache spill size. The second form turns cache spill on |
| 760 | ** or off. When turnning cache spill on, the size is set to the |
| 761 | ** current cache_size. The third form sets a spill size that |
| 762 | ** may be different form the cache size. |
| 763 | ** If N is positive then that is the |
| 764 | ** number of pages in the cache. If N is negative, then the |
| 765 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 766 | ** of memory. |
| 767 | ** |
| 768 | ** If the number of cache_spill pages is less then the number of |
| 769 | ** cache_size pages, no spilling occurs until the page count exceeds |
| 770 | ** the number of cache_size pages. |
| 771 | ** |
| 772 | ** The cache_spill=BOOLEAN setting applies to all attached schemas, |
| 773 | ** not just the schema specified. |
| 774 | */ |
| 775 | case PragTyp_CACHE_SPILL: { |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 776 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 777 | if( !zRight ){ |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 778 | returnSingleInt(v, "cache_spill", |
| 779 | (db->flags & SQLITE_CacheSpill)==0 ? 0 : |
| 780 | sqlite3BtreeSetSpillSize(pDb->pBt,0)); |
| 781 | }else{ |
drh | 4f9c8ec | 2015-11-12 15:47:48 +0000 | [diff] [blame] | 782 | int size = 1; |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 783 | if( sqlite3GetInt32(zRight, &size) ){ |
| 784 | sqlite3BtreeSetSpillSize(pDb->pBt, size); |
| 785 | } |
drh | 4f9c8ec | 2015-11-12 15:47:48 +0000 | [diff] [blame] | 786 | if( sqlite3GetBoolean(zRight, size!=0) ){ |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 787 | db->flags |= SQLITE_CacheSpill; |
| 788 | }else{ |
| 789 | db->flags &= ~SQLITE_CacheSpill; |
| 790 | } |
drh | 4f9c8ec | 2015-11-12 15:47:48 +0000 | [diff] [blame] | 791 | setAllPagerFlags(db); |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 792 | } |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | /* |
| 797 | ** PRAGMA [schema.]mmap_size(N) |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 798 | ** |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 799 | ** Used to set mapping size limit. The mapping size limit is |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 800 | ** used to limit the aggregate size of all memory mapped regions of the |
| 801 | ** database file. If this parameter is set to zero, then memory mapping |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 802 | ** 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] | 803 | ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set. |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 804 | ** The parameter N is measured in bytes. |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 805 | ** |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 806 | ** This value is advisory. The underlying VFS is free to memory map |
| 807 | ** as little or as much as it wants. Except, if N is set to 0 then the |
| 808 | ** upper layers will never invoke the xFetch interfaces to the VFS. |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 809 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 810 | case PragTyp_MMAP_SIZE: { |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 811 | sqlite3_int64 sz; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 812 | #if SQLITE_MAX_MMAP_SIZE>0 |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 813 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 814 | if( zRight ){ |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 815 | int ii; |
drh | 9296c18 | 2014-07-23 13:40:49 +0000 | [diff] [blame] | 816 | sqlite3DecOrHexToI64(zRight, &sz); |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 817 | if( sz<0 ) sz = sqlite3GlobalConfig.szMmap; |
| 818 | if( pId2->n==0 ) db->szMmap = sz; |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 819 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 820 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 821 | sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz); |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 822 | } |
| 823 | } |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 824 | } |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 825 | sz = -1; |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 826 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz); |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 827 | #else |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 828 | sz = 0; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 829 | rc = SQLITE_OK; |
drh | 188d488 | 2013-04-08 20:47:49 +0000 | [diff] [blame] | 830 | #endif |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 831 | if( rc==SQLITE_OK ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 832 | returnSingleInt(v, "mmap_size", sz); |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 833 | }else if( rc!=SQLITE_NOTFOUND ){ |
| 834 | pParse->nErr++; |
| 835 | pParse->rc = rc; |
drh | 34f7490 | 2013-04-03 13:09:18 +0000 | [diff] [blame] | 836 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 837 | break; |
| 838 | } |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 839 | |
| 840 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 841 | ** PRAGMA temp_store |
| 842 | ** PRAGMA temp_store = "default"|"memory"|"file" |
| 843 | ** |
| 844 | ** Return or set the local value of the temp_store flag. Changing |
| 845 | ** the local value does not make changes to the disk file and the default |
| 846 | ** value will be restored the next time the database is opened. |
| 847 | ** |
| 848 | ** Note that it is possible for the library compile-time options to |
| 849 | ** override this setting |
| 850 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 851 | case PragTyp_TEMP_STORE: { |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 852 | if( !zRight ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 853 | returnSingleInt(v, "temp_store", db->temp_store); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 854 | }else{ |
| 855 | changeTempStorage(pParse, zRight); |
| 856 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 857 | break; |
| 858 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 859 | |
| 860 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 861 | ** PRAGMA temp_store_directory |
| 862 | ** PRAGMA temp_store_directory = ""|"directory_name" |
| 863 | ** |
| 864 | ** Return or set the local value of the temp_store_directory flag. Changing |
| 865 | ** the value sets a specific directory to be used for temporary files. |
| 866 | ** Setting to a null string reverts to the default temporary directory search. |
| 867 | ** If temporary directory is changed, then invalidateTempStorage. |
| 868 | ** |
| 869 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 870 | case PragTyp_TEMP_STORE_DIRECTORY: { |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 871 | if( !zRight ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 872 | returnSingleText(v, "temp_store_directory", sqlite3_temp_directory); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 873 | }else{ |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 874 | #ifndef SQLITE_OMIT_WSD |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 875 | if( zRight[0] ){ |
| 876 | int res; |
danielk1977 | fab1127 | 2008-09-16 14:38:02 +0000 | [diff] [blame] | 877 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 878 | if( rc!=SQLITE_OK || res==0 ){ |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 879 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
| 880 | goto pragma_out; |
| 881 | } |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 882 | } |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 883 | if( SQLITE_TEMP_STORE==0 |
| 884 | || (SQLITE_TEMP_STORE==1 && db->temp_store<=1) |
| 885 | || (SQLITE_TEMP_STORE==2 && db->temp_store==1) |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 886 | ){ |
| 887 | invalidateTempStorage(pParse); |
| 888 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 889 | sqlite3_free(sqlite3_temp_directory); |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 890 | if( zRight[0] ){ |
drh | b975598 | 2010-07-24 16:34:37 +0000 | [diff] [blame] | 891 | sqlite3_temp_directory = sqlite3_mprintf("%s", zRight); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 892 | }else{ |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 893 | sqlite3_temp_directory = 0; |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 894 | } |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 895 | #endif /* SQLITE_OMIT_WSD */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 896 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 897 | break; |
| 898 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 899 | |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 900 | #if SQLITE_OS_WIN |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 901 | /* |
| 902 | ** PRAGMA data_store_directory |
| 903 | ** PRAGMA data_store_directory = ""|"directory_name" |
| 904 | ** |
| 905 | ** Return or set the local value of the data_store_directory flag. Changing |
| 906 | ** the value sets a specific directory to be used for database files that |
| 907 | ** were specified with a relative pathname. Setting to a null string reverts |
| 908 | ** to the default database directory, which for database files specified with |
| 909 | ** a relative path will probably be based on the current directory for the |
| 910 | ** process. Database file specified with an absolute path are not impacted |
| 911 | ** by this setting, regardless of its value. |
| 912 | ** |
| 913 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 914 | case PragTyp_DATA_STORE_DIRECTORY: { |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 915 | if( !zRight ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 916 | returnSingleText(v, "data_store_directory", sqlite3_data_directory); |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 917 | }else{ |
| 918 | #ifndef SQLITE_OMIT_WSD |
| 919 | if( zRight[0] ){ |
| 920 | int res; |
| 921 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 922 | if( rc!=SQLITE_OK || res==0 ){ |
| 923 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
| 924 | goto pragma_out; |
| 925 | } |
| 926 | } |
| 927 | sqlite3_free(sqlite3_data_directory); |
| 928 | if( zRight[0] ){ |
| 929 | sqlite3_data_directory = sqlite3_mprintf("%s", zRight); |
| 930 | }else{ |
| 931 | sqlite3_data_directory = 0; |
| 932 | } |
| 933 | #endif /* SQLITE_OMIT_WSD */ |
| 934 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 935 | break; |
| 936 | } |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 937 | #endif |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 938 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 939 | #if SQLITE_ENABLE_LOCKING_STYLE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 940 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 941 | ** PRAGMA [schema.]lock_proxy_file |
| 942 | ** PRAGMA [schema.]lock_proxy_file = ":auto:"|"lock_file_path" |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 943 | ** |
| 944 | ** Return or set the value of the lock_proxy_file flag. Changing |
| 945 | ** the value sets a specific file to be used for database access locks. |
| 946 | ** |
| 947 | */ |
| 948 | case PragTyp_LOCK_PROXY_FILE: { |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 949 | if( !zRight ){ |
| 950 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 951 | char *proxy_file_path = NULL; |
| 952 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
drh | c02372c | 2012-01-10 17:59:59 +0000 | [diff] [blame] | 953 | sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 954 | &proxy_file_path); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 955 | returnSingleText(v, "lock_proxy_file", proxy_file_path); |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 956 | }else{ |
| 957 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 958 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
| 959 | int res; |
| 960 | if( zRight[0] ){ |
| 961 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 962 | zRight); |
| 963 | } else { |
| 964 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 965 | NULL); |
| 966 | } |
| 967 | if( res!=SQLITE_OK ){ |
| 968 | sqlite3ErrorMsg(pParse, "failed to set lock proxy file"); |
| 969 | goto pragma_out; |
| 970 | } |
| 971 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 972 | break; |
| 973 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 974 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 975 | |
| 976 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 977 | ** PRAGMA [schema.]synchronous |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 978 | ** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 979 | ** |
| 980 | ** Return or set the local value of the synchronous flag. Changing |
| 981 | ** the local value does not make changes to the disk file and the |
| 982 | ** default value will be restored the next time the database is |
| 983 | ** opened. |
| 984 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 985 | case PragTyp_SYNCHRONOUS: { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 986 | if( !zRight ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 987 | returnSingleInt(v, "synchronous", pDb->safety_level-1); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 988 | }else{ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 989 | if( !db->autoCommit ){ |
| 990 | sqlite3ErrorMsg(pParse, |
| 991 | "Safety level may not be changed inside a transaction"); |
| 992 | }else{ |
drh | d99d283 | 2015-04-17 15:58:33 +0000 | [diff] [blame] | 993 | int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; |
| 994 | if( iLevel==0 ) iLevel = 1; |
| 995 | pDb->safety_level = iLevel; |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 996 | setAllPagerFlags(db); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 997 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 998 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 999 | break; |
| 1000 | } |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1001 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1002 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 1003 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1004 | case PragTyp_FLAG: { |
| 1005 | if( zRight==0 ){ |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 1006 | returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 ); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1007 | }else{ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1008 | int mask = pPragma->iArg; /* Mask of bits to set or clear. */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1009 | if( db->autoCommit==0 ){ |
| 1010 | /* Foreign key support may not be enabled or disabled while not |
| 1011 | ** in auto-commit mode. */ |
| 1012 | mask &= ~(SQLITE_ForeignKeys); |
| 1013 | } |
drh | d453097 | 2014-09-09 14:47:53 +0000 | [diff] [blame] | 1014 | #if SQLITE_USER_AUTHENTICATION |
drh | b2445d5 | 2014-09-11 14:01:41 +0000 | [diff] [blame] | 1015 | if( db->auth.authLevel==UAUTH_User ){ |
drh | d453097 | 2014-09-09 14:47:53 +0000 | [diff] [blame] | 1016 | /* Do not allow non-admin users to modify the schema arbitrarily */ |
| 1017 | mask &= ~(SQLITE_WriteSchema); |
| 1018 | } |
| 1019 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1020 | |
| 1021 | if( sqlite3GetBoolean(zRight, 0) ){ |
| 1022 | db->flags |= mask; |
| 1023 | }else{ |
| 1024 | db->flags &= ~mask; |
| 1025 | if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0; |
| 1026 | } |
| 1027 | |
| 1028 | /* Many of the flag-pragmas modify the code generated by the SQL |
| 1029 | ** compiler (eg. count_changes). So add an opcode to expire all |
| 1030 | ** compiled SQL statements after modifying a pragma value. |
| 1031 | */ |
| 1032 | sqlite3VdbeAddOp2(v, OP_Expire, 0, 0); |
| 1033 | setAllPagerFlags(db); |
| 1034 | } |
| 1035 | break; |
| 1036 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 1037 | #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1038 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1039 | #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1040 | /* |
| 1041 | ** PRAGMA table_info(<table>) |
| 1042 | ** |
| 1043 | ** Return a single row for each column of the named table. The columns of |
| 1044 | ** the returned data set are: |
| 1045 | ** |
| 1046 | ** cid: Column id (numbered from left to right, starting at 0) |
| 1047 | ** name: Column name |
| 1048 | ** type: Column declaration type. |
| 1049 | ** notnull: True if 'NOT NULL' is part of column declaration |
| 1050 | ** dflt_value: The default value for the column, if any. |
| 1051 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1052 | case PragTyp_TABLE_INFO: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1053 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1054 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1055 | if( pTab ){ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1056 | static const char *azCol[] = { |
| 1057 | "cid", "name", "type", "notnull", "dflt_value", "pk" |
| 1058 | }; |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1059 | int i, k; |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 1060 | int nHidden = 0; |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 1061 | Column *pCol; |
drh | 4415628 | 2013-10-23 22:23:03 +0000 | [diff] [blame] | 1062 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1063 | pParse->nMem = 6; |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1064 | sqlite3CodeVerifySchema(pParse, iDb); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1065 | setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) ); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1066 | sqlite3ViewGetColumnNames(pParse, pTab); |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 1067 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 1068 | if( IsHiddenColumn(pCol) ){ |
| 1069 | nHidden++; |
| 1070 | continue; |
| 1071 | } |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1072 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 1073 | k = 0; |
| 1074 | }else if( pPk==0 ){ |
| 1075 | k = 1; |
| 1076 | }else{ |
drh | 1b67896 | 2015-04-15 07:19:27 +0000 | [diff] [blame] | 1077 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1078 | } |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1079 | sqlite3VdbeMultiLoad(v, 1, "issisi", |
| 1080 | i-nHidden, |
| 1081 | pCol->zName, |
| 1082 | pCol->zType ? pCol->zType : "", |
| 1083 | pCol->notNull ? 1 : 0, |
| 1084 | pCol->zDflt, |
| 1085 | k); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1086 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1087 | } |
| 1088 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1089 | } |
| 1090 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1091 | |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1092 | case PragTyp_STATS: { |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1093 | static const char *azCol[] = { "table", "index", "width", "height" }; |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1094 | Index *pIdx; |
| 1095 | HashElem *i; |
| 1096 | v = sqlite3GetVdbe(pParse); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1097 | pParse->nMem = 4; |
| 1098 | sqlite3CodeVerifySchema(pParse, iDb); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1099 | setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) ); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1100 | for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 1101 | Table *pTab = sqliteHashData(i); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1102 | sqlite3VdbeMultiLoad(v, 1, "ssii", |
| 1103 | pTab->zName, |
| 1104 | 0, |
| 1105 | (int)sqlite3LogEstToInt(pTab->szTabRow), |
| 1106 | (int)sqlite3LogEstToInt(pTab->nRowLogEst)); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1107 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 1108 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1109 | sqlite3VdbeMultiLoad(v, 2, "sii", |
| 1110 | pIdx->zName, |
| 1111 | (int)sqlite3LogEstToInt(pIdx->szIdxRow), |
| 1112 | (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0])); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1113 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | break; |
| 1118 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1119 | case PragTyp_INDEX_INFO: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1120 | Index *pIdx; |
| 1121 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1122 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1123 | if( pIdx ){ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1124 | static const char *azCol[] = { |
| 1125 | "seqno", "cid", "name", "desc", "coll", "key" |
| 1126 | }; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1127 | int i; |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1128 | int mx; |
| 1129 | if( pPragma->iArg ){ |
| 1130 | /* PRAGMA index_xinfo (newer version with more rows and columns) */ |
| 1131 | mx = pIdx->nColumn; |
| 1132 | pParse->nMem = 6; |
| 1133 | }else{ |
| 1134 | /* PRAGMA index_info (legacy version) */ |
| 1135 | mx = pIdx->nKeyCol; |
| 1136 | pParse->nMem = 3; |
| 1137 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1138 | pTab = pIdx->pTable; |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1139 | sqlite3CodeVerifySchema(pParse, iDb); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1140 | assert( pParse->nMem<=ArraySize(azCol) ); |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1141 | setAllColumnNames(v, pParse->nMem, azCol); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1142 | for(i=0; i<mx; i++){ |
drh | bbbdc83 | 2013-10-22 18:01:40 +0000 | [diff] [blame] | 1143 | i16 cnum = pIdx->aiColumn[i]; |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1144 | sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum, |
| 1145 | cnum<0 ? 0 : pTab->aCol[cnum].zName); |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1146 | if( pPragma->iArg ){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1147 | sqlite3VdbeMultiLoad(v, 4, "isi", |
| 1148 | pIdx->aSortOrder[i], |
| 1149 | pIdx->azColl[i], |
| 1150 | i<pIdx->nKeyCol); |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1151 | } |
| 1152 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1153 | } |
| 1154 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1155 | } |
| 1156 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1157 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1158 | case PragTyp_INDEX_LIST: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1159 | Index *pIdx; |
| 1160 | Table *pTab; |
drh | e13e9f5 | 2013-10-05 19:18:00 +0000 | [diff] [blame] | 1161 | int i; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1162 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1163 | if( pTab ){ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1164 | static const char *azCol[] = { |
| 1165 | "seq", "name", "unique", "origin", "partial" |
| 1166 | }; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1167 | v = sqlite3GetVdbe(pParse); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1168 | pParse->nMem = 5; |
drh | e13e9f5 | 2013-10-05 19:18:00 +0000 | [diff] [blame] | 1169 | sqlite3CodeVerifySchema(pParse, iDb); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1170 | setAllColumnNames(v, 5, azCol); assert( 5==ArraySize(azCol) ); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1171 | for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1172 | const char *azOrigin[] = { "c", "u", "pk" }; |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1173 | sqlite3VdbeMultiLoad(v, 1, "isisi", |
| 1174 | i, |
| 1175 | pIdx->zName, |
| 1176 | IsUniqueIndex(pIdx), |
| 1177 | azOrigin[pIdx->idxType], |
| 1178 | pIdx->pPartIdxWhere!=0); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1179 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1180 | } |
| 1181 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1182 | } |
| 1183 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1184 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1185 | case PragTyp_DATABASE_LIST: { |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1186 | static const char *azCol[] = { "seq", "name", "file" }; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1187 | int i; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1188 | pParse->nMem = 3; |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1189 | setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) ); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1190 | for(i=0; i<db->nDb; i++){ |
| 1191 | if( db->aDb[i].pBt==0 ) continue; |
| 1192 | assert( db->aDb[i].zName!=0 ); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1193 | sqlite3VdbeMultiLoad(v, 1, "iss", |
| 1194 | i, |
| 1195 | db->aDb[i].zName, |
| 1196 | sqlite3BtreeGetFilename(db->aDb[i].pBt)); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1197 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1198 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1199 | } |
| 1200 | break; |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1201 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1202 | case PragTyp_COLLATION_LIST: { |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1203 | static const char *azCol[] = { "seq", "name" }; |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1204 | int i = 0; |
| 1205 | HashElem *p; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1206 | pParse->nMem = 2; |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1207 | setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) ); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1208 | for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){ |
| 1209 | CollSeq *pColl = (CollSeq *)sqliteHashData(p); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1210 | sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1211 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1212 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1213 | } |
| 1214 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1215 | #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ |
| 1216 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1217 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1218 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1219 | FKey *pFK; |
| 1220 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1221 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1222 | if( pTab ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1223 | v = sqlite3GetVdbe(pParse); |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1224 | pFK = pTab->pFKey; |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1225 | if( pFK ){ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1226 | static const char *azCol[] = { |
| 1227 | "id", "seq", "table", "from", "to", "on_update", "on_delete", |
| 1228 | "match" |
| 1229 | }; |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1230 | int i = 0; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1231 | pParse->nMem = 8; |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1232 | sqlite3CodeVerifySchema(pParse, iDb); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1233 | setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) ); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1234 | while(pFK){ |
| 1235 | int j; |
| 1236 | for(j=0; j<pFK->nCol; j++){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1237 | sqlite3VdbeMultiLoad(v, 1, "iissssss", |
| 1238 | i, |
| 1239 | j, |
| 1240 | pFK->zTo, |
| 1241 | pTab->aCol[pFK->aCol[j].iFrom].zName, |
| 1242 | pFK->aCol[j].zCol, |
| 1243 | actionName(pFK->aAction[1]), /* ON UPDATE */ |
| 1244 | actionName(pFK->aAction[0]), /* ON DELETE */ |
| 1245 | "NONE"); |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1246 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1247 | } |
| 1248 | ++i; |
| 1249 | pFK = pFK->pNextFrom; |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1250 | } |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1251 | } |
| 1252 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1253 | } |
| 1254 | break; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1255 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1256 | |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1257 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
dan | 09ff9e1 | 2013-03-11 11:49:03 +0000 | [diff] [blame] | 1258 | #ifndef SQLITE_OMIT_TRIGGER |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1259 | case PragTyp_FOREIGN_KEY_CHECK: { |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1260 | FKey *pFK; /* A foreign key constraint */ |
| 1261 | Table *pTab; /* Child table contain "REFERENCES" keyword */ |
| 1262 | Table *pParent; /* Parent table that child points to */ |
| 1263 | Index *pIdx; /* Index in the parent table */ |
| 1264 | int i; /* Loop counter: Foreign key number for pTab */ |
| 1265 | int j; /* Loop counter: Field of the foreign key */ |
| 1266 | HashElem *k; /* Loop counter: Next table in schema */ |
| 1267 | int x; /* result variable */ |
| 1268 | int regResult; /* 3 registers to hold a result row */ |
| 1269 | int regKey; /* Register to hold key for checking the FK */ |
| 1270 | int regRow; /* Registers to hold a row from pTab */ |
| 1271 | int addrTop; /* Top of a loop checking foreign keys */ |
| 1272 | int addrOk; /* Jump here if the key is OK */ |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1273 | int *aiCols; /* child to parent column mapping */ |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1274 | static const char *azCol[] = { "table", "rowid", "parent", "fkid" }; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1275 | |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1276 | regResult = pParse->nMem+1; |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1277 | pParse->nMem += 4; |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1278 | regKey = ++pParse->nMem; |
| 1279 | regRow = ++pParse->nMem; |
| 1280 | v = sqlite3GetVdbe(pParse); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1281 | setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) ); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1282 | sqlite3CodeVerifySchema(pParse, iDb); |
| 1283 | k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash); |
| 1284 | while( k ){ |
| 1285 | if( zRight ){ |
| 1286 | pTab = sqlite3LocateTable(pParse, 0, zRight, zDb); |
| 1287 | k = 0; |
| 1288 | }else{ |
| 1289 | pTab = (Table*)sqliteHashData(k); |
| 1290 | k = sqliteHashNext(k); |
| 1291 | } |
drh | 9148def | 2012-12-17 20:40:39 +0000 | [diff] [blame] | 1292 | if( pTab==0 || pTab->pFKey==0 ) continue; |
| 1293 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1294 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1295 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1296 | sqlite3VdbeLoadString(v, regResult, pTab->zName); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1297 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1298 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 1299 | if( pParent==0 ) continue; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1300 | pIdx = 0; |
drh | 9148def | 2012-12-17 20:40:39 +0000 | [diff] [blame] | 1301 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1302 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1303 | if( x==0 ){ |
| 1304 | if( pIdx==0 ){ |
| 1305 | sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead); |
| 1306 | }else{ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1307 | sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb); |
drh | 2ec2fb2 | 2013-11-06 19:59:23 +0000 | [diff] [blame] | 1308 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1309 | } |
| 1310 | }else{ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1311 | k = 0; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1312 | break; |
| 1313 | } |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1314 | } |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1315 | assert( pParse->nErr>0 || pFK==0 ); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1316 | if( pFK ) break; |
| 1317 | if( pParse->nTab<i ) pParse->nTab = i; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1318 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1319 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1320 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1321 | pIdx = 0; |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1322 | aiCols = 0; |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1323 | if( pParent ){ |
| 1324 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
| 1325 | assert( x==0 ); |
| 1326 | } |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1327 | addrOk = sqlite3VdbeMakeLabel(v); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1328 | if( pParent && pIdx==0 ){ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1329 | int iKey = pFK->aCol[0].iFrom; |
drh | 83e0dba | 2012-12-20 00:32:49 +0000 | [diff] [blame] | 1330 | assert( iKey>=0 && iKey<pTab->nCol ); |
| 1331 | if( iKey!=pTab->iPKey ){ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1332 | sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); |
| 1333 | sqlite3ColumnDefault(v, pTab, iKey, regRow); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1334 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v); |
| 1335 | sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, |
| 1336 | sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1337 | }else{ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1338 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1339 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1340 | sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1341 | sqlite3VdbeGoto(v, addrOk); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1342 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 1343 | }else{ |
| 1344 | for(j=0; j<pFK->nCol; j++){ |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1345 | sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1346 | aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1347 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1348 | } |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1349 | if( pParent ){ |
drh | 57bf4a8 | 2014-02-17 14:59:22 +0000 | [diff] [blame] | 1350 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey, |
drh | e910769 | 2015-08-25 19:20:04 +0000 | [diff] [blame] | 1351 | sqlite3IndexAffinityStr(db,pIdx), pFK->nCol); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1352 | sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1353 | VdbeCoverage(v); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1354 | } |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1355 | } |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1356 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1357 | sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1); |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1358 | sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1359 | sqlite3VdbeResolveLabel(v, addrOk); |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1360 | sqlite3DbFree(db, aiCols); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1361 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1362 | sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1363 | sqlite3VdbeJumpHere(v, addrTop); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1364 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1365 | } |
| 1366 | break; |
dan | 09ff9e1 | 2013-03-11 11:49:03 +0000 | [diff] [blame] | 1367 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1368 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 1369 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1370 | #ifndef NDEBUG |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1371 | case PragTyp_PARSER_TRACE: { |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1372 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 1373 | if( sqlite3GetBoolean(zRight, 0) ){ |
drh | 97e58a2 | 2015-11-10 14:27:17 +0000 | [diff] [blame] | 1374 | sqlite3ParserTrace(stdout, "parser: "); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1375 | }else{ |
| 1376 | sqlite3ParserTrace(0, 0); |
| 1377 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1378 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1379 | } |
| 1380 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1381 | #endif |
| 1382 | |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1383 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 1384 | ** used will be case sensitive or not depending on the RHS. |
| 1385 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1386 | case PragTyp_CASE_SENSITIVE_LIKE: { |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1387 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 1388 | sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0)); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1389 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1390 | } |
| 1391 | break; |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1392 | |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1393 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 1394 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| 1395 | #endif |
| 1396 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1397 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
drh | f7b5496 | 2013-05-28 12:11:54 +0000 | [diff] [blame] | 1398 | /* Pragma "quick_check" is reduced version of |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1399 | ** integrity_check designed to detect most database corruption |
| 1400 | ** without most of the overhead of a full integrity-check. |
| 1401 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1402 | case PragTyp_INTEGRITY_CHECK: { |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1403 | int i, j, addr, mxErr; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1404 | |
drh | c522731 | 2011-10-13 17:09:01 +0000 | [diff] [blame] | 1405 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1406 | |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1407 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 1408 | ** then iDb is set to the index of the database identified by <db>. |
| 1409 | ** In this case, the integrity of database iDb only is verified by |
| 1410 | ** the VDBE created below. |
| 1411 | ** |
| 1412 | ** Otherwise, if the command was simply "PRAGMA integrity_check" (or |
| 1413 | ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb |
| 1414 | ** to -1 here, to indicate that the VDBE should verify the integrity |
| 1415 | ** of all attached databases. */ |
| 1416 | assert( iDb>=0 ); |
| 1417 | assert( iDb==0 || pId2->z ); |
| 1418 | if( pId2->z==0 ) iDb = -1; |
| 1419 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1420 | /* Initialize the VDBE program */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1421 | pParse->nMem = 6; |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1422 | setOneColumnName(v, "integrity_check"); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1423 | |
| 1424 | /* Set the maximum error count */ |
| 1425 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1426 | if( zRight ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 1427 | sqlite3GetInt32(zRight, &mxErr); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1428 | if( mxErr<=0 ){ |
| 1429 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1430 | } |
| 1431 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1432 | sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1433 | |
| 1434 | /* Do an integrity check on each database file */ |
| 1435 | for(i=0; i<db->nDb; i++){ |
| 1436 | HashElem *x; |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1437 | Hash *pTbls; |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1438 | int cnt = 0; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1439 | |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1440 | if( OMIT_TEMPDB && i==1 ) continue; |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1441 | if( iDb>=0 && i!=iDb ) continue; |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1442 | |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1443 | sqlite3CodeVerifySchema(pParse, i); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1444 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */ |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1445 | VdbeCoverage(v); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1446 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1447 | sqlite3VdbeJumpHere(v, addr); |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1448 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1449 | /* Do an integrity check of the B-Tree |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1450 | ** |
| 1451 | ** Begin by filling registers 2, 3, ... with the root pages numbers |
| 1452 | ** for all tables and indices in the database. |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1453 | */ |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1454 | assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1455 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 1456 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1457 | Table *pTab = sqliteHashData(x); |
| 1458 | Index *pIdx; |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1459 | if( HasRowid(pTab) ){ |
| 1460 | sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); |
drh | 5838340 | 2013-11-04 17:00:50 +0000 | [diff] [blame] | 1461 | VdbeComment((v, "%s", pTab->zName)); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1462 | cnt++; |
| 1463 | } |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1464 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1465 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt); |
drh | 5838340 | 2013-11-04 17:00:50 +0000 | [diff] [blame] | 1466 | VdbeComment((v, "%s", pIdx->zName)); |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1467 | cnt++; |
| 1468 | } |
| 1469 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1470 | |
| 1471 | /* Make sure sufficient number of registers have been allocated */ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1472 | pParse->nMem = MAX( pParse->nMem, cnt+8 ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1473 | |
| 1474 | /* Do the b-tree integrity checks */ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1475 | sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 1476 | sqlite3VdbeChangeP5(v, (u8)i); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1477 | addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1478 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 1479 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1480 | P4_DYNAMIC); |
drh | 079a307 | 2014-03-19 14:10:55 +0000 | [diff] [blame] | 1481 | sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1); |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1482 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1483 | sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1484 | sqlite3VdbeJumpHere(v, addr); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1485 | |
| 1486 | /* Make sure all the indices are constructed correctly. |
| 1487 | */ |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1488 | for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1489 | Table *pTab = sqliteHashData(x); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1490 | Index *pIdx, *pPk; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1491 | Index *pPrior = 0; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1492 | int loopTop; |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1493 | int iDataCur, iIdxCur; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1494 | int r1 = -1; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1495 | |
| 1496 | if( pTab->pIndex==0 ) continue; |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1497 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1498 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */ |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1499 | VdbeCoverage(v); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1500 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1501 | sqlite3VdbeJumpHere(v, addr); |
drh | 66518ca | 2013-08-01 15:09:57 +0000 | [diff] [blame] | 1502 | sqlite3ExprCacheClear(pParse); |
dan | fd261ec | 2015-10-22 20:54:33 +0000 | [diff] [blame] | 1503 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
drh | 6a53499 | 2013-11-16 20:13:39 +0000 | [diff] [blame] | 1504 | 1, 0, &iDataCur, &iIdxCur); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1505 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1506 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1507 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */ |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1508 | } |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1509 | pParse->nMem = MAX(pParse->nMem, 8+j); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1510 | sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1511 | loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1512 | /* Verify that all NOT NULL columns really are NOT NULL */ |
| 1513 | for(j=0; j<pTab->nCol; j++){ |
| 1514 | char *zErr; |
| 1515 | int jmp2, jmp3; |
| 1516 | if( j==pTab->iPKey ) continue; |
| 1517 | if( pTab->aCol[j].notNull==0 ) continue; |
| 1518 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 1519 | sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 1520 | jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 1521 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
| 1522 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 1523 | pTab->aCol[j].zName); |
| 1524 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 1525 | sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
| 1526 | jmp3 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); |
| 1527 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 1528 | sqlite3VdbeJumpHere(v, jmp2); |
| 1529 | sqlite3VdbeJumpHere(v, jmp3); |
| 1530 | } |
| 1531 | /* Validate index entries for the current row */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1532 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1533 | int jmp2, jmp3, jmp4, jmp5; |
| 1534 | int ckUniq = sqlite3VdbeMakeLabel(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1535 | if( pPk==pIdx ) continue; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1536 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 1537 | pPrior, r1); |
| 1538 | pPrior = pIdx; |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1539 | sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */ |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1540 | /* Verify that an index entry exists for the current table row */ |
| 1541 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1, |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1542 | pIdx->nColumn); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1543 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1544 | sqlite3VdbeLoadString(v, 3, "row "); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1545 | sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1546 | sqlite3VdbeLoadString(v, 4, " missing from index "); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1547 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1548 | jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1549 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 1550 | sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1551 | jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1552 | sqlite3VdbeAddOp0(v, OP_Halt); |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1553 | sqlite3VdbeJumpHere(v, jmp2); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1554 | /* For UNIQUE indexes, verify that only one entry exists with the |
| 1555 | ** current key. The entry is unique if (1) any column is NULL |
| 1556 | ** or (2) the next entry has a different key */ |
| 1557 | if( IsUniqueIndex(pIdx) ){ |
| 1558 | int uniqOk = sqlite3VdbeMakeLabel(v); |
| 1559 | int jmp6; |
| 1560 | int kk; |
| 1561 | for(kk=0; kk<pIdx->nKeyCol; kk++){ |
| 1562 | int iCol = pIdx->aiColumn[kk]; |
drh | 4b92f98 | 2015-09-29 17:20:14 +0000 | [diff] [blame] | 1563 | assert( iCol!=XN_ROWID && iCol<pTab->nCol ); |
drh | 68391ac | 2015-09-25 20:49:16 +0000 | [diff] [blame] | 1564 | if( iCol>=0 && pTab->aCol[iCol].notNull ) continue; |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1565 | sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); |
| 1566 | VdbeCoverage(v); |
| 1567 | } |
| 1568 | jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1569 | sqlite3VdbeGoto(v, uniqOk); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1570 | sqlite3VdbeJumpHere(v, jmp6); |
| 1571 | sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1, |
| 1572 | pIdx->nKeyCol); VdbeCoverage(v); |
| 1573 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1574 | sqlite3VdbeLoadString(v, 3, "non-unique entry in index "); |
| 1575 | sqlite3VdbeGoto(v, jmp5); |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 1576 | sqlite3VdbeResolveLabel(v, uniqOk); |
| 1577 | } |
| 1578 | sqlite3VdbeJumpHere(v, jmp4); |
drh | 8774451 | 2014-04-13 19:15:49 +0000 | [diff] [blame] | 1579 | sqlite3ResolvePartIdxLabel(pParse, jmp3); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1580 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1581 | sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1582 | sqlite3VdbeJumpHere(v, loopTop-1); |
| 1583 | #ifndef SQLITE_OMIT_BTREECOUNT |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1584 | sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1585 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1586 | if( pPk==pIdx ) continue; |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1587 | addr = sqlite3VdbeCurrentAddr(v); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1588 | sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1589 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1590 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1591 | sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v); |
drh | 5655c54 | 2014-02-19 19:14:34 +0000 | [diff] [blame] | 1592 | sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1593 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1594 | sqlite3VdbeLoadString(v, 3, pIdx->zName); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1595 | sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); |
| 1596 | sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1597 | } |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1598 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1599 | } |
| 1600 | } |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1601 | { |
| 1602 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 1603 | static const VdbeOpList endCode[] = { |
| 1604 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
drh | 1b32554 | 2016-02-03 01:55:44 +0000 | [diff] [blame] | 1605 | { OP_If, 1, 4, 0}, /* 1 */ |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1606 | { OP_String8, 0, 3, 0}, /* 2 */ |
drh | 1b32554 | 2016-02-03 01:55:44 +0000 | [diff] [blame] | 1607 | { OP_ResultRow, 3, 1, 0}, /* 3 */ |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1608 | }; |
| 1609 | VdbeOp *aOp; |
| 1610 | |
| 1611 | aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 1612 | if( aOp ){ |
| 1613 | aOp[0].p2 = -mxErr; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1614 | aOp[2].p4type = P4_STATIC; |
| 1615 | aOp[2].p4.z = "ok"; |
| 1616 | } |
| 1617 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1618 | } |
| 1619 | break; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1620 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 1621 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1622 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1623 | /* |
| 1624 | ** PRAGMA encoding |
| 1625 | ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" |
| 1626 | ** |
drh | 85b623f | 2007-12-13 21:54:09 +0000 | [diff] [blame] | 1627 | ** In its first form, this pragma returns the encoding of the main |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1628 | ** database. If the database is not initialized, it is initialized now. |
| 1629 | ** |
| 1630 | ** The second form of this pragma is a no-op if the main database file |
| 1631 | ** has not already been initialized. In this case it sets the default |
| 1632 | ** encoding that will be used for the main database file if a new file |
| 1633 | ** is created. If an existing main database file is opened, then the |
| 1634 | ** default text encoding for the existing database is used. |
| 1635 | ** |
| 1636 | ** In all cases new databases created using the ATTACH command are |
| 1637 | ** created to use the same default text encoding as the main database. If |
| 1638 | ** the main database has not been initialized and/or created when ATTACH |
| 1639 | ** is executed, this is done before the ATTACH operation. |
| 1640 | ** |
| 1641 | ** In the second form this pragma sets the text encoding to be used in |
| 1642 | ** new database files created using this database handle. It is only |
| 1643 | ** useful if invoked immediately after the main database i |
| 1644 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1645 | case PragTyp_ENCODING: { |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1646 | static const struct EncName { |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1647 | char *zName; |
| 1648 | u8 enc; |
| 1649 | } encnames[] = { |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1650 | { "UTF8", SQLITE_UTF8 }, |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1651 | { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */ |
| 1652 | { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */ |
| 1653 | { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */ |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1654 | { "UTF16le", SQLITE_UTF16LE }, |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1655 | { "UTF16be", SQLITE_UTF16BE }, |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1656 | { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */ |
| 1657 | { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1658 | { 0, 0 } |
| 1659 | }; |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1660 | const struct EncName *pEnc; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1661 | if( !zRight ){ /* "PRAGMA encoding" */ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 1662 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1663 | assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 ); |
| 1664 | assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE ); |
| 1665 | assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE ); |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 1666 | returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1667 | }else{ /* "PRAGMA encoding = XXX" */ |
| 1668 | /* Only change the value of sqlite.enc if the database handle is not |
| 1669 | ** initialized. If the main database exists, the new sqlite.enc value |
| 1670 | ** will be overwritten when the schema is next loaded. If it does not |
| 1671 | ** already exists, it will be created to use the new encoding value. |
| 1672 | */ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 1673 | if( |
| 1674 | !(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
| 1675 | DbHasProperty(db, 0, DB_Empty) |
| 1676 | ){ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1677 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 1678 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
drh | 9bd3cc4 | 2014-12-12 23:17:54 +0000 | [diff] [blame] | 1679 | SCHEMA_ENC(db) = ENC(db) = |
| 1680 | pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | } |
| 1683 | } |
| 1684 | if( !pEnc->zName ){ |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 1685 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1689 | } |
| 1690 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1691 | #endif /* SQLITE_OMIT_UTF16 */ |
| 1692 | |
| 1693 | #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1694 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1695 | ** PRAGMA [schema.]schema_version |
| 1696 | ** PRAGMA [schema.]schema_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1697 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1698 | ** PRAGMA [schema.]user_version |
| 1699 | ** PRAGMA [schema.]user_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1700 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1701 | ** PRAGMA [schema.]freelist_count = <integer> |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 1702 | ** |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1703 | ** PRAGMA [schema.]application_id |
| 1704 | ** PRAGMA [schema.]application_id = <integer> |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 1705 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1706 | ** The pragma's schema_version and user_version are used to set or get |
| 1707 | ** the value of the schema-version and user-version, respectively. Both |
| 1708 | ** the schema-version and the user-version are 32-bit signed integers |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1709 | ** stored in the database header. |
| 1710 | ** |
| 1711 | ** The schema-cookie is usually only manipulated internally by SQLite. It |
| 1712 | ** is incremented by SQLite whenever the database schema is modified (by |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1713 | ** creating or dropping a table or index). The schema version is used by |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1714 | ** SQLite each time a query is executed to ensure that the internal cache |
| 1715 | ** of the schema used when compiling the SQL query matches the schema of |
| 1716 | ** the database against which the compiled query is actually executed. |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1717 | ** Subverting this mechanism by using "PRAGMA schema_version" to modify |
| 1718 | ** the schema-version is potentially dangerous and may lead to program |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1719 | ** crashes or database corruption. Use with caution! |
| 1720 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1721 | ** 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] | 1722 | ** applications for any purpose. |
| 1723 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1724 | case PragTyp_HEADER_VALUE: { |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1725 | int iCookie = pPragma->iArg; /* Which cookie to read or write */ |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 1726 | sqlite3VdbeUsesBtree(v, iDb); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1727 | if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1728 | /* Write the specified cookie value */ |
| 1729 | static const VdbeOpList setCookie[] = { |
| 1730 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 1731 | { OP_SetCookie, 0, 0, 0}, /* 1 */ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1732 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1733 | VdbeOp *aOp; |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 1734 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1735 | aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 1736 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1737 | aOp[0].p1 = iDb; |
drh | 1861afc | 2016-02-01 21:48:34 +0000 | [diff] [blame] | 1738 | aOp[1].p1 = iDb; |
| 1739 | aOp[1].p2 = iCookie; |
| 1740 | aOp[1].p3 = sqlite3Atoi(zRight); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1741 | }else{ |
| 1742 | /* Read the specified cookie value */ |
| 1743 | static const VdbeOpList readCookie[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 1744 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 1745 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1746 | { OP_ResultRow, 1, 1, 0} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1747 | }; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1748 | VdbeOp *aOp; |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 1749 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(readCookie)); |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1750 | aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0); |
drh | dad300d | 2016-01-18 00:20:26 +0000 | [diff] [blame] | 1751 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
drh | 2ce1865 | 2016-01-16 20:50:21 +0000 | [diff] [blame] | 1752 | aOp[0].p1 = iDb; |
| 1753 | aOp[1].p1 = iDb; |
| 1754 | aOp[1].p3 = iCookie; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1755 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1756 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1757 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1758 | } |
| 1759 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1760 | #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1761 | |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1762 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 1763 | /* |
| 1764 | ** PRAGMA compile_options |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1765 | ** |
drh | 71caabf | 2010-02-26 15:39:24 +0000 | [diff] [blame] | 1766 | ** Return the names of all compile-time options used in this build, |
| 1767 | ** one option per row. |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1768 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1769 | case PragTyp_COMPILE_OPTIONS: { |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1770 | int i = 0; |
| 1771 | const char *zOpt; |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1772 | pParse->nMem = 1; |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1773 | setOneColumnName(v, "compile_option"); |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1774 | while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){ |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1775 | sqlite3VdbeLoadString(v, 1, zOpt); |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1776 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 1777 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1778 | } |
| 1779 | break; |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1780 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 1781 | |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 1782 | #ifndef SQLITE_OMIT_WAL |
| 1783 | /* |
drh | 9b0cf34 | 2015-11-12 14:57:19 +0000 | [diff] [blame] | 1784 | ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 1785 | ** |
| 1786 | ** Checkpoint the database. |
| 1787 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1788 | case PragTyp_WAL_CHECKPOINT: { |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1789 | static const char *azCol[] = { "busy", "log", "checkpointed" }; |
dan | a58f26f | 2010-11-16 18:56:51 +0000 | [diff] [blame] | 1790 | int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 1791 | int eMode = SQLITE_CHECKPOINT_PASSIVE; |
| 1792 | if( zRight ){ |
| 1793 | if( sqlite3StrICmp(zRight, "full")==0 ){ |
| 1794 | eMode = SQLITE_CHECKPOINT_FULL; |
| 1795 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 1796 | eMode = SQLITE_CHECKPOINT_RESTART; |
dan | f26a154 | 2014-12-02 19:04:54 +0000 | [diff] [blame] | 1797 | }else if( sqlite3StrICmp(zRight, "truncate")==0 ){ |
| 1798 | eMode = SQLITE_CHECKPOINT_TRUNCATE; |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 1799 | } |
| 1800 | } |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1801 | setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) ); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 1802 | pParse->nMem = 3; |
drh | 30aa3b9 | 2011-02-07 23:56:01 +0000 | [diff] [blame] | 1803 | sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 1804 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1805 | } |
| 1806 | break; |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1807 | |
| 1808 | /* |
| 1809 | ** PRAGMA wal_autocheckpoint |
| 1810 | ** PRAGMA wal_autocheckpoint = N |
| 1811 | ** |
| 1812 | ** Configure a database connection to automatically checkpoint a database |
| 1813 | ** after accumulating N frames in the log. Or query for the current value |
| 1814 | ** of N. |
| 1815 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1816 | case PragTyp_WAL_AUTOCHECKPOINT: { |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1817 | if( zRight ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 1818 | sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight)); |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1819 | } |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 1820 | returnSingleInt(v, "wal_autocheckpoint", |
drh | b033d8b | 2010-05-03 13:37:30 +0000 | [diff] [blame] | 1821 | db->xWalCallback==sqlite3WalDefaultHook ? |
| 1822 | SQLITE_PTR_TO_INT(db->pWalArg) : 0); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1823 | } |
| 1824 | break; |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 1825 | #endif |
dan | 7c24610 | 2010-04-12 19:00:29 +0000 | [diff] [blame] | 1826 | |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 1827 | /* |
| 1828 | ** PRAGMA shrink_memory |
| 1829 | ** |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1830 | ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database |
| 1831 | ** connection on which it is invoked to free up as much memory as it |
| 1832 | ** can, by calling sqlite3_db_release_memory(). |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 1833 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1834 | case PragTyp_SHRINK_MEMORY: { |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 1835 | sqlite3_db_release_memory(db); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1836 | break; |
| 1837 | } |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 1838 | |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 1839 | /* |
| 1840 | ** PRAGMA busy_timeout |
| 1841 | ** PRAGMA busy_timeout = N |
| 1842 | ** |
| 1843 | ** Call sqlite3_busy_timeout(db, N). Return the current timeout value |
drh | c0c7b5e | 2012-09-07 18:49:57 +0000 | [diff] [blame] | 1844 | ** if one is set. If no busy handler or a different busy handler is set |
| 1845 | ** then 0 is returned. Setting the busy_timeout to 0 or negative |
| 1846 | ** disables the timeout. |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 1847 | */ |
drh | d49c358 | 2013-09-13 19:00:06 +0000 | [diff] [blame] | 1848 | /*case PragTyp_BUSY_TIMEOUT*/ default: { |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1849 | assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT ); |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 1850 | if( zRight ){ |
| 1851 | sqlite3_busy_timeout(db, sqlite3Atoi(zRight)); |
| 1852 | } |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 1853 | returnSingleInt(v, "timeout", db->busyTimeout); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1854 | break; |
| 1855 | } |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 1856 | |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 1857 | /* |
| 1858 | ** PRAGMA soft_heap_limit |
| 1859 | ** PRAGMA soft_heap_limit = N |
| 1860 | ** |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1861 | ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the |
| 1862 | ** sqlite3_soft_heap_limit64() interface with the argument N, if N is |
| 1863 | ** specified and is a non-negative integer. |
| 1864 | ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always |
| 1865 | ** returns the same integer that would be returned by the |
| 1866 | ** sqlite3_soft_heap_limit64(-1) C-language function. |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 1867 | */ |
| 1868 | case PragTyp_SOFT_HEAP_LIMIT: { |
| 1869 | sqlite3_int64 N; |
drh | 9296c18 | 2014-07-23 13:40:49 +0000 | [diff] [blame] | 1870 | if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){ |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 1871 | sqlite3_soft_heap_limit64(N); |
| 1872 | } |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 1873 | returnSingleInt(v, "soft_heap_limit", sqlite3_soft_heap_limit64(-1)); |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 1874 | break; |
| 1875 | } |
| 1876 | |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 1877 | /* |
| 1878 | ** PRAGMA threads |
| 1879 | ** PRAGMA threads = N |
| 1880 | ** |
| 1881 | ** Configure the maximum number of worker threads. Return the new |
| 1882 | ** maximum, which might be less than requested. |
| 1883 | */ |
| 1884 | case PragTyp_THREADS: { |
| 1885 | sqlite3_int64 N; |
drh | 111544c | 2014-08-29 16:20:47 +0000 | [diff] [blame] | 1886 | if( zRight |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 1887 | && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK |
| 1888 | && N>=0 |
| 1889 | ){ |
drh | 111544c | 2014-08-29 16:20:47 +0000 | [diff] [blame] | 1890 | sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff)); |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 1891 | } |
drh | 7cc023c | 2015-09-03 04:28:25 +0000 | [diff] [blame] | 1892 | returnSingleInt(v, "threads", |
drh | 111544c | 2014-08-29 16:20:47 +0000 | [diff] [blame] | 1893 | sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1)); |
drh | 0345961 | 2014-08-25 15:13:22 +0000 | [diff] [blame] | 1894 | break; |
| 1895 | } |
| 1896 | |
dougcurrie | 81c95ef | 2004-06-18 23:21:47 +0000 | [diff] [blame] | 1897 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1898 | /* |
| 1899 | ** Report the current state of file logs for all databases |
| 1900 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1901 | case PragTyp_LOCK_STATUS: { |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 1902 | static const char *const azLockName[] = { |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1903 | "unlocked", "shared", "reserved", "pending", "exclusive" |
| 1904 | }; |
drh | b460e52 | 2015-09-03 03:29:51 +0000 | [diff] [blame] | 1905 | static const char *azCol[] = { "database", "status" }; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1906 | int i; |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1907 | setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1908 | pParse->nMem = 2; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1909 | for(i=0; i<db->nDb; i++){ |
| 1910 | Btree *pBt; |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 1911 | const char *zState = "unknown"; |
| 1912 | int j; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1913 | if( db->aDb[i].zName==0 ) continue; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1914 | pBt = db->aDb[i].pBt; |
drh | 5a05be1 | 2012-10-09 18:51:44 +0000 | [diff] [blame] | 1915 | if( pBt==0 || sqlite3BtreePager(pBt)==0 ){ |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 1916 | zState = "closed"; |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 1917 | }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 1918 | SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){ |
| 1919 | zState = azLockName[j]; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1920 | } |
drh | 076e85f | 2015-09-03 13:46:12 +0000 | [diff] [blame] | 1921 | sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1922 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1923 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | } |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1926 | #endif |
| 1927 | |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 1928 | #ifdef SQLITE_HAS_CODEC |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1929 | case PragTyp_KEY: { |
| 1930 | if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 1931 | break; |
| 1932 | } |
| 1933 | case PragTyp_REKEY: { |
| 1934 | if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 1935 | break; |
| 1936 | } |
| 1937 | case PragTyp_HEXKEY: { |
| 1938 | if( zRight ){ |
drh | 8ab8832 | 2013-10-07 00:36:01 +0000 | [diff] [blame] | 1939 | u8 iByte; |
| 1940 | int i; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1941 | char zKey[40]; |
drh | 8ab8832 | 2013-10-07 00:36:01 +0000 | [diff] [blame] | 1942 | for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){ |
| 1943 | iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); |
| 1944 | if( (i&1)!=0 ) zKey[i/2] = iByte; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1945 | } |
| 1946 | if( (zLeft[3] & 0xf)==0xb ){ |
| 1947 | sqlite3_key_v2(db, zDb, zKey, i/2); |
| 1948 | }else{ |
| 1949 | sqlite3_rekey_v2(db, zDb, zKey, i/2); |
| 1950 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1951 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | } |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 1954 | #endif |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 1955 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1956 | case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){ |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 1957 | #ifdef SQLITE_HAS_CODEC |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1958 | if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1959 | sqlite3_activate_see(&zRight[4]); |
| 1960 | } |
| 1961 | #endif |
| 1962 | #ifdef SQLITE_ENABLE_CEROD |
| 1963 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1964 | sqlite3_activate_cerod(&zRight[6]); |
| 1965 | } |
| 1966 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1967 | } |
| 1968 | break; |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1969 | #endif |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 1970 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1971 | } /* End of the PRAGMA switch */ |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 1972 | |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 1973 | pragma_out: |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 1974 | sqlite3DbFree(db, zLeft); |
| 1975 | sqlite3DbFree(db, zRight); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1976 | } |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1977 | |
drh | 8bfdf72 | 2009-06-19 14:06:03 +0000 | [diff] [blame] | 1978 | #endif /* SQLITE_OMIT_PRAGMA */ |