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 | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 16 | /* Ignore this whole file if pragmas are disabled |
| 17 | */ |
drh | 8bfdf72 | 2009-06-19 14:06:03 +0000 | [diff] [blame] | 18 | #if !defined(SQLITE_OMIT_PRAGMA) |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 19 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 20 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 21 | ** Interpret the given string as a safety level. Return 0 for OFF, |
jplyon | b1639ff | 2004-01-19 04:52:29 +0000 | [diff] [blame] | 22 | ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or |
| 23 | ** unrecognized string argument. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 24 | ** |
| 25 | ** Note that the values returned are one less that the values that |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 26 | ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 27 | ** to support legacy SQL code. The safety level used to be boolean |
| 28 | ** and older scripts may have used numbers 0 for OFF and 1 for ON. |
| 29 | */ |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 30 | static u8 getSafetyLevel(const char *z){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 31 | /* 123456789 123456789 */ |
| 32 | static const char zText[] = "onoffalseyestruefull"; |
| 33 | static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; |
| 34 | static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; |
| 35 | static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; |
| 36 | int i, n; |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 37 | if( sqlite3Isdigit(*z) ){ |
drh | 3abbd39 | 2008-12-10 23:04:13 +0000 | [diff] [blame] | 38 | return (u8)atoi(z); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 39 | } |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 40 | n = sqlite3Strlen30(z); |
danielk1977 | 00e1361 | 2008-11-17 19:18:54 +0000 | [diff] [blame] | 41 | for(i=0; i<ArraySize(iLength); i++){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 42 | if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){ |
| 43 | return iValue[i]; |
| 44 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 45 | } |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | /* |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 50 | ** Interpret the given string as a boolean value. |
| 51 | */ |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 52 | static u8 getBoolean(const char *z){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 53 | return getSafetyLevel(z)&1; |
| 54 | } |
| 55 | |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 56 | /* |
| 57 | ** Interpret the given string as a locking mode value. |
| 58 | */ |
| 59 | static int getLockingMode(const char *z){ |
| 60 | if( z ){ |
| 61 | if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE; |
| 62 | if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL; |
| 63 | } |
| 64 | return PAGER_LOCKINGMODE_QUERY; |
| 65 | } |
| 66 | |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 67 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 68 | /* |
| 69 | ** Interpret the given string as an auto-vacuum mode value. |
| 70 | ** |
| 71 | ** The following strings, "none", "full" and "incremental" are |
| 72 | ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively. |
| 73 | */ |
| 74 | static int getAutoVacuum(const char *z){ |
| 75 | int i; |
| 76 | if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE; |
| 77 | if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL; |
| 78 | if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR; |
| 79 | i = atoi(z); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 80 | return (u8)((i>=0&&i<=2)?i:0); |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 81 | } |
| 82 | #endif /* ifndef SQLITE_OMIT_AUTOVACUUM */ |
| 83 | |
danielk1977 | b84f96f | 2005-01-20 11:32:23 +0000 | [diff] [blame] | 84 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 85 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 86 | ** Interpret the given string as a temp db location. Return 1 for file |
| 87 | ** backed temporary databases, 2 for the Red-Black tree in memory database |
| 88 | ** and 0 to use the compile-time default. |
| 89 | */ |
| 90 | static int getTempStore(const char *z){ |
| 91 | if( z[0]>='0' && z[0]<='2' ){ |
| 92 | return z[0] - '0'; |
| 93 | }else if( sqlite3StrICmp(z, "file")==0 ){ |
| 94 | return 1; |
| 95 | }else if( sqlite3StrICmp(z, "memory")==0 ){ |
| 96 | return 2; |
| 97 | }else{ |
| 98 | return 0; |
| 99 | } |
| 100 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 101 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 102 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 103 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 104 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 105 | ** Invalidate temp storage, either when the temp storage is changed |
| 106 | ** from default, or when 'file' and the temp_store_directory has changed |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 107 | */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 108 | static int invalidateTempStorage(Parse *pParse){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 109 | sqlite3 *db = pParse->db; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 110 | if( db->aDb[1].pBt!=0 ){ |
danielk1977 | 983e230 | 2008-07-08 07:35:51 +0000 | [diff] [blame] | 111 | if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 112 | sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " |
| 113 | "from within a transaction"); |
| 114 | return SQLITE_ERROR; |
| 115 | } |
| 116 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 117 | db->aDb[1].pBt = 0; |
| 118 | sqlite3ResetInternalSchema(db, 0); |
| 119 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 120 | return SQLITE_OK; |
| 121 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 122 | #endif /* SQLITE_PAGER_PRAGMAS */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 123 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 124 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 125 | /* |
| 126 | ** If the TEMP database is open, close it and mark the database schema |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 127 | ** as needing reloading. This must be done when using the SQLITE_TEMP_STORE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 128 | ** or DEFAULT_TEMP_STORE pragmas. |
| 129 | */ |
| 130 | static int changeTempStorage(Parse *pParse, const char *zStorageType){ |
| 131 | int ts = getTempStore(zStorageType); |
| 132 | sqlite3 *db = pParse->db; |
| 133 | if( db->temp_store==ts ) return SQLITE_OK; |
| 134 | if( invalidateTempStorage( pParse ) != SQLITE_OK ){ |
| 135 | return SQLITE_ERROR; |
| 136 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 137 | db->temp_store = (u8)ts; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 138 | return SQLITE_OK; |
| 139 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 140 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | ** Generate code to return a single integer value. |
| 144 | */ |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 145 | static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 146 | Vdbe *v = sqlite3GetVdbe(pParse); |
drh | 0a07c10 | 2008-01-03 18:03:08 +0000 | [diff] [blame] | 147 | int mem = ++pParse->nMem; |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 148 | i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); |
| 149 | if( pI64 ){ |
| 150 | memcpy(pI64, &value, sizeof(value)); |
| 151 | } |
| 152 | sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); |
drh | 1086172 | 2009-04-07 00:49:16 +0000 | [diff] [blame] | 153 | sqlite3VdbeSetNumCols(v, 1); |
| 154 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 155 | sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 156 | } |
| 157 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 158 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 159 | /* |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 160 | ** Check to see if zRight and zLeft refer to a pragma that queries |
| 161 | ** or changes one of the flags in db->flags. Return 1 if so and 0 if not. |
| 162 | ** Also, implement the pragma. |
| 163 | */ |
| 164 | static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 165 | static const struct sPragmaType { |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 166 | const char *zName; /* Name of the pragma */ |
| 167 | int mask; /* Mask for the db->flags value */ |
| 168 | } aPragma[] = { |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 169 | { "full_column_names", SQLITE_FullColNames }, |
| 170 | { "short_column_names", SQLITE_ShortColNames }, |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 171 | { "count_changes", SQLITE_CountRows }, |
| 172 | { "empty_result_callbacks", SQLITE_NullCallback }, |
drh | e321c29 | 2006-01-12 01:56:43 +0000 | [diff] [blame] | 173 | { "legacy_file_format", SQLITE_LegacyFileFmt }, |
drh | ac530b1 | 2006-02-11 01:25:50 +0000 | [diff] [blame] | 174 | { "fullfsync", SQLITE_FullFSync }, |
drh | 699b3d4 | 2009-02-23 16:52:07 +0000 | [diff] [blame] | 175 | { "reverse_unordered_selects", SQLITE_ReverseOrder }, |
drh | c633908 | 2010-04-07 16:54:58 +0000 | [diff] [blame] | 176 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 177 | { "automatic_index", SQLITE_AutoIndex }, |
| 178 | #endif |
drh | cf1023c | 2007-05-08 20:59:49 +0000 | [diff] [blame] | 179 | #ifdef SQLITE_DEBUG |
| 180 | { "sql_trace", SQLITE_SqlTrace }, |
| 181 | { "vdbe_listing", SQLITE_VdbeListing }, |
| 182 | { "vdbe_trace", SQLITE_VdbeTrace }, |
| 183 | #endif |
drh | 0cd2d4c | 2005-11-03 02:15:02 +0000 | [diff] [blame] | 184 | #ifndef SQLITE_OMIT_CHECK |
| 185 | { "ignore_check_constraints", SQLITE_IgnoreChecks }, |
| 186 | #endif |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 187 | /* The following is VERY experimental */ |
danielk1977 | 34c68fb | 2007-03-14 15:37:04 +0000 | [diff] [blame] | 188 | { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
drh | 7bec505 | 2005-02-06 02:45:41 +0000 | [diff] [blame] | 189 | { "omit_readlock", SQLITE_NoReadlock }, |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 190 | |
| 191 | /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted |
| 192 | ** flag if there are any active statements. */ |
| 193 | { "read_uncommitted", SQLITE_ReadUncommitted }, |
dan | 5bde73c | 2009-09-01 17:11:07 +0000 | [diff] [blame] | 194 | { "recursive_triggers", SQLITE_RecTriggers }, |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 195 | |
dan | 75cbd98 | 2009-09-21 16:06:03 +0000 | [diff] [blame] | 196 | /* This flag may only be set if both foreign-key and trigger support |
| 197 | ** are present in the build. */ |
| 198 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 199 | { "foreign_keys", SQLITE_ForeignKeys }, |
dan | 75cbd98 | 2009-09-21 16:06:03 +0000 | [diff] [blame] | 200 | #endif |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 201 | }; |
| 202 | int i; |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 203 | const struct sPragmaType *p; |
danielk1977 | 00e1361 | 2008-11-17 19:18:54 +0000 | [diff] [blame] | 204 | for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 205 | if( sqlite3StrICmp(zLeft, p->zName)==0 ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 206 | sqlite3 *db = pParse->db; |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 207 | Vdbe *v; |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 208 | v = sqlite3GetVdbe(pParse); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 209 | assert( v!=0 ); /* Already allocated by sqlite3Pragma() */ |
| 210 | if( ALWAYS(v) ){ |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 211 | if( zRight==0 ){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 212 | returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 ); |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 213 | }else{ |
dan | 75cbd98 | 2009-09-21 16:06:03 +0000 | [diff] [blame] | 214 | int mask = p->mask; /* Mask of bits to set or clear. */ |
| 215 | if( db->autoCommit==0 ){ |
| 216 | /* Foreign key support may not be enabled or disabled while not |
| 217 | ** in auto-commit mode. */ |
| 218 | mask &= ~(SQLITE_ForeignKeys); |
| 219 | } |
| 220 | |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 221 | if( getBoolean(zRight) ){ |
dan | 75cbd98 | 2009-09-21 16:06:03 +0000 | [diff] [blame] | 222 | db->flags |= mask; |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 223 | }else{ |
dan | 75cbd98 | 2009-09-21 16:06:03 +0000 | [diff] [blame] | 224 | db->flags &= ~mask; |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 225 | } |
danielk1977 | 8e55652 | 2007-11-13 10:30:24 +0000 | [diff] [blame] | 226 | |
| 227 | /* Many of the flag-pragmas modify the code generated by the SQL |
| 228 | ** compiler (eg. count_changes). So add an opcode to expire all |
| 229 | ** compiled SQL statements after modifying a pragma value. |
| 230 | */ |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 231 | sqlite3VdbeAddOp2(v, OP_Expire, 0, 0); |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 232 | } |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 233 | } |
danielk1977 | 8e55652 | 2007-11-13 10:30:24 +0000 | [diff] [blame] | 234 | |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 235 | return 1; |
| 236 | } |
| 237 | } |
| 238 | return 0; |
| 239 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 240 | #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 241 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 242 | /* |
| 243 | ** Return a human-readable name for a constraint resolution action. |
| 244 | */ |
dan | ba9108b | 2009-09-22 07:13:42 +0000 | [diff] [blame] | 245 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 246 | static const char *actionName(u8 action){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 247 | const char *zName; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 248 | switch( action ){ |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 249 | case OE_SetNull: zName = "SET NULL"; break; |
| 250 | case OE_SetDflt: zName = "SET DEFAULT"; break; |
| 251 | case OE_Cascade: zName = "CASCADE"; break; |
| 252 | case OE_Restrict: zName = "RESTRICT"; break; |
| 253 | default: zName = "NO ACTION"; |
| 254 | assert( action==OE_None ); break; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 255 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 256 | return zName; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 257 | } |
dan | ba9108b | 2009-09-22 07:13:42 +0000 | [diff] [blame] | 258 | #endif |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 259 | |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | ** Parameter eMode must be one of the PAGER_JOURNALMODE_XXX constants |
| 263 | ** defined in pager.h. This function returns the associated lowercase |
| 264 | ** journal-mode name. |
| 265 | */ |
| 266 | const char *sqlite3JournalModename(int eMode){ |
| 267 | static char * const azModeName[] = { |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 268 | "delete", "persist", "off", "truncate", "memory" |
| 269 | #ifndef SQLITE_OMIT_WAL |
| 270 | , "wal" |
| 271 | #endif |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 272 | }; |
| 273 | assert( PAGER_JOURNALMODE_DELETE==0 ); |
| 274 | assert( PAGER_JOURNALMODE_PERSIST==1 ); |
| 275 | assert( PAGER_JOURNALMODE_OFF==2 ); |
| 276 | assert( PAGER_JOURNALMODE_TRUNCATE==3 ); |
| 277 | assert( PAGER_JOURNALMODE_MEMORY==4 ); |
| 278 | assert( PAGER_JOURNALMODE_WAL==5 ); |
| 279 | assert( eMode>=0 && eMode<=ArraySize(azModeName) ); |
| 280 | |
| 281 | if( eMode==ArraySize(azModeName) ) return 0; |
| 282 | return azModeName[eMode]; |
| 283 | } |
| 284 | |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 285 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 286 | ** Process a pragma statement. |
| 287 | ** |
| 288 | ** Pragmas are of this form: |
| 289 | ** |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 290 | ** PRAGMA [database.]id [= value] |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 291 | ** |
| 292 | ** The identifier might also be a string. The value is a string, and |
| 293 | ** identifier, or a number. If minusFlag is true, then the value is |
| 294 | ** a number that was preceded by a minus sign. |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 295 | ** |
| 296 | ** If the left side is "database.id" then pId1 is the database name |
| 297 | ** and pId2 is the id. If the left side is just "id" then pId1 is the |
| 298 | ** id and pId2 is any empty string. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 299 | */ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 300 | void sqlite3Pragma( |
| 301 | Parse *pParse, |
| 302 | Token *pId1, /* First part of [database.]id field */ |
| 303 | Token *pId2, /* Second part of [database.]id field, or NULL */ |
| 304 | Token *pValue, /* Token for <value>, or NULL */ |
| 305 | int minusFlag /* True if a '-' sign preceded <value> */ |
| 306 | ){ |
| 307 | char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ |
| 308 | char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
| 309 | const char *zDb = 0; /* The database name */ |
| 310 | Token *pId; /* Pointer to <id> token */ |
| 311 | int iDb; /* Database index for <database> */ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 312 | sqlite3 *db = pParse->db; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 313 | Db *pDb; |
drh | 949f9cd | 2008-01-12 21:35:57 +0000 | [diff] [blame] | 314 | Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db); |
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 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 319 | /* Interpret the [database.] part of the pragma statement. iDb is the |
| 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 | } |
| 345 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 346 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 347 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 348 | ** PRAGMA [database.]default_cache_size |
| 349 | ** PRAGMA [database.]default_cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 350 | ** |
| 351 | ** The first form reports the current persistent setting for the |
| 352 | ** page cache size. The value returned is the maximum number of |
| 353 | ** pages in the page cache. The second form sets both the current |
| 354 | ** page cache size value and the persistent page cache size value |
| 355 | ** stored in the database file. |
| 356 | ** |
drh | 93791ea | 2010-04-26 17:36:35 +0000 | [diff] [blame] | 357 | ** Older versions of SQLite would set the default cache size to a |
| 358 | ** negative number to indicate synchronous=OFF. These days, synchronous |
| 359 | ** is always on by default regardless of the sign of the default cache |
| 360 | ** size. But continue to take the absolute value of the default cache |
| 361 | ** size of historical compatibility. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 362 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 363 | if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 364 | static const VdbeOpList getCacheSize[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 365 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 366 | { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */ |
| 367 | { OP_IfPos, 1, 7, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 368 | { OP_Integer, 0, 2, 0}, |
| 369 | { OP_Subtract, 1, 2, 1}, |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 370 | { OP_IfPos, 1, 7, 0}, |
| 371 | { OP_Integer, 0, 1, 0}, /* 6 */ |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 372 | { OP_ResultRow, 1, 1, 0}, |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 373 | }; |
drh | 905793e | 2004-02-21 13:31:09 +0000 | [diff] [blame] | 374 | int addr; |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 375 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 376 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 377 | if( !zRight ){ |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 378 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 379 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC); |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 380 | pParse->nMem += 2; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 381 | addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 382 | sqlite3VdbeChangeP1(v, addr, iDb); |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 383 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 384 | sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 385 | }else{ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 386 | int size = atoi(zRight); |
| 387 | if( size<0 ) size = -size; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 388 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 389 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 390 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 391 | pDb->pSchema->cache_size = size; |
| 392 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 393 | } |
| 394 | }else |
| 395 | |
| 396 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 397 | ** PRAGMA [database.]page_size |
| 398 | ** PRAGMA [database.]page_size=N |
| 399 | ** |
| 400 | ** The first form reports the current setting for the |
| 401 | ** database page size in bytes. The second form sets the |
| 402 | ** database page size value. The value can only be set if |
| 403 | ** the database has not yet been created. |
| 404 | */ |
| 405 | if( sqlite3StrICmp(zLeft,"page_size")==0 ){ |
| 406 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 407 | assert( pBt!=0 ); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 408 | if( !zRight ){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 409 | int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0; |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 410 | returnSingleInt(pParse, "page_size", size); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 411 | }else{ |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 412 | /* Malloc may fail when setting the page-size, as there is an internal |
| 413 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 414 | */ |
danielk1977 | f653d78 | 2008-03-20 11:04:21 +0000 | [diff] [blame] | 415 | db->nextPagesize = atoi(zRight); |
drh | ce4869f | 2009-04-02 20:16:58 +0000 | [diff] [blame] | 416 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){ |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 417 | db->mallocFailed = 1; |
| 418 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 419 | } |
| 420 | }else |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 421 | |
| 422 | /* |
drh | f8e632b | 2007-05-08 14:51:36 +0000 | [diff] [blame] | 423 | ** PRAGMA [database.]max_page_count |
| 424 | ** PRAGMA [database.]max_page_count=N |
| 425 | ** |
| 426 | ** The first form reports the current setting for the |
| 427 | ** maximum number of pages in the database file. The |
| 428 | ** second form attempts to change this setting. Both |
| 429 | ** forms return the current setting. |
| 430 | */ |
| 431 | if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){ |
| 432 | Btree *pBt = pDb->pBt; |
| 433 | int newMax = 0; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 434 | assert( pBt!=0 ); |
drh | f8e632b | 2007-05-08 14:51:36 +0000 | [diff] [blame] | 435 | if( zRight ){ |
| 436 | newMax = atoi(zRight); |
| 437 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 438 | if( ALWAYS(pBt) ){ |
drh | f8e632b | 2007-05-08 14:51:36 +0000 | [diff] [blame] | 439 | newMax = sqlite3BtreeMaxPageCount(pBt, newMax); |
| 440 | } |
| 441 | returnSingleInt(pParse, "max_page_count", newMax); |
| 442 | }else |
| 443 | |
| 444 | /* |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 445 | ** PRAGMA [database.]secure_delete |
| 446 | ** PRAGMA [database.]secure_delete=ON/OFF |
| 447 | ** |
| 448 | ** The first form reports the current setting for the |
| 449 | ** secure_delete flag. The second form changes the secure_delete |
| 450 | ** flag setting and reports thenew value. |
| 451 | */ |
| 452 | if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){ |
| 453 | Btree *pBt = pDb->pBt; |
| 454 | int b = -1; |
| 455 | assert( pBt!=0 ); |
| 456 | if( zRight ){ |
| 457 | b = getBoolean(zRight); |
| 458 | } |
drh | af034ed | 2010-02-12 19:46:26 +0000 | [diff] [blame] | 459 | if( pId2->n==0 && b>=0 ){ |
| 460 | int ii; |
| 461 | for(ii=0; ii<db->nDb; ii++){ |
| 462 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| 463 | } |
| 464 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 465 | b = sqlite3BtreeSecureDelete(pBt, b); |
| 466 | returnSingleInt(pParse, "secure_delete", b); |
| 467 | }else |
| 468 | |
| 469 | /* |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 470 | ** PRAGMA [database.]page_count |
| 471 | ** |
| 472 | ** Return the number of pages in the specified database. |
| 473 | */ |
| 474 | if( sqlite3StrICmp(zLeft,"page_count")==0 ){ |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 475 | int iReg; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 476 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 477 | sqlite3CodeVerifySchema(pParse, iDb); |
| 478 | iReg = ++pParse->nMem; |
| 479 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 480 | sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); |
| 481 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 482 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC); |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 483 | }else |
| 484 | |
| 485 | /* |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 486 | ** PRAGMA [database.]locking_mode |
| 487 | ** PRAGMA [database.]locking_mode = (normal|exclusive) |
| 488 | */ |
| 489 | if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){ |
| 490 | const char *zRet = "normal"; |
| 491 | int eMode = getLockingMode(zRight); |
| 492 | |
| 493 | if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){ |
| 494 | /* Simple "PRAGMA locking_mode;" statement. This is a query for |
| 495 | ** the current default locking mode (which may be different to |
| 496 | ** the locking-mode of the main database). |
| 497 | */ |
| 498 | eMode = db->dfltLockMode; |
| 499 | }else{ |
| 500 | Pager *pPager; |
| 501 | if( pId2->n==0 ){ |
| 502 | /* This indicates that no database name was specified as part |
| 503 | ** of the PRAGMA command. In this case the locking-mode must be |
| 504 | ** set on all attached databases, as well as the main db file. |
| 505 | ** |
| 506 | ** Also, the sqlite3.dfltLockMode variable is set so that |
| 507 | ** any subsequently attached databases also use the specified |
| 508 | ** locking mode. |
| 509 | */ |
| 510 | int ii; |
| 511 | assert(pDb==&db->aDb[0]); |
| 512 | for(ii=2; ii<db->nDb; ii++){ |
| 513 | pPager = sqlite3BtreePager(db->aDb[ii].pBt); |
| 514 | sqlite3PagerLockingMode(pPager, eMode); |
| 515 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 516 | db->dfltLockMode = (u8)eMode; |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 517 | } |
| 518 | pPager = sqlite3BtreePager(pDb->pBt); |
| 519 | eMode = sqlite3PagerLockingMode(pPager, eMode); |
| 520 | } |
| 521 | |
| 522 | assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE); |
| 523 | if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){ |
| 524 | zRet = "exclusive"; |
| 525 | } |
| 526 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 527 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 528 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0); |
| 529 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 530 | }else |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 531 | |
| 532 | /* |
| 533 | ** PRAGMA [database.]journal_mode |
drh | 3ebaee9 | 2010-05-06 21:37:22 +0000 | [diff] [blame^] | 534 | ** PRAGMA [database.]journal_mode = |
| 535 | ** (delete|persist|off|truncate|memory|wal|off) |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 536 | */ |
| 537 | if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 538 | int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ |
| 539 | |
| 540 | sqlite3VdbeSetNumCols(v, 1); |
| 541 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC); |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 542 | |
| 543 | if( zRight==0 ){ |
| 544 | eMode = PAGER_JOURNALMODE_QUERY; |
| 545 | }else{ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 546 | const char *zMode; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 547 | int n = sqlite3Strlen30(zRight); |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 548 | for(eMode=0; (zMode = sqlite3JournalModename(eMode)); eMode++){ |
| 549 | if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break; |
| 550 | } |
| 551 | if( !zMode ){ |
| 552 | eMode = PAGER_JOURNALMODE_QUERY; |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){ |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 556 | /* Simple "PRAGMA journal_mode;" statement. This is a query for |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 557 | ** the current default journal mode (which may be different to |
| 558 | ** the journal-mode of the main database). |
| 559 | */ |
| 560 | eMode = db->dfltJournalMode; |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 561 | sqlite3VdbeAddOp2(v, OP_String8, 0, 1); |
| 562 | sqlite3VdbeChangeP4(v, -1, sqlite3JournalModename(eMode), P4_STATIC); |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 563 | }else{ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 564 | int ii; |
| 565 | |
drh | 3ebaee9 | 2010-05-06 21:37:22 +0000 | [diff] [blame^] | 566 | if( pId2->n==0 ){ |
| 567 | /* When there is no database name before the "journal_mode" keyword |
| 568 | ** in the PRAGMA, then the journal-mode will be set on |
| 569 | ** all attached databases, as well as the main db file. |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 570 | ** |
| 571 | ** Also, the sqlite3.dfltJournalMode variable is set so that |
| 572 | ** any subsequently attached databases also use the specified |
drh | 3ebaee9 | 2010-05-06 21:37:22 +0000 | [diff] [blame^] | 573 | ** journal mode. |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 574 | */ |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 575 | db->dfltJournalMode = (u8)eMode; |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 576 | } |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 577 | |
| 578 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 579 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
| 580 | sqlite3VdbeUsesBtree(v, ii); |
| 581 | sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode); |
| 582 | } |
| 583 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 584 | } |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 585 | |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 586 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 587 | }else |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 588 | |
| 589 | /* |
| 590 | ** PRAGMA [database.]journal_size_limit |
| 591 | ** PRAGMA [database.]journal_size_limit=N |
| 592 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 593 | ** Get or set the size limit on rollback journal files. |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 594 | */ |
| 595 | if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){ |
| 596 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 597 | i64 iLimit = -2; |
| 598 | if( zRight ){ |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 599 | sqlite3Atoi64(zRight, &iLimit); |
| 600 | if( iLimit<-1 ) iLimit = -1; |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 601 | } |
| 602 | iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 603 | returnSingleInt(pParse, "journal_size_limit", iLimit); |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 604 | }else |
| 605 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 606 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 607 | |
| 608 | /* |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 609 | ** PRAGMA [database.]auto_vacuum |
| 610 | ** PRAGMA [database.]auto_vacuum=N |
| 611 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 612 | ** Get or set the value of the database 'auto-vacuum' parameter. |
| 613 | ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 614 | */ |
| 615 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 616 | if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){ |
| 617 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 618 | assert( pBt!=0 ); |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 619 | if( sqlite3ReadSchema(pParse) ){ |
| 620 | goto pragma_out; |
| 621 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 622 | if( !zRight ){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 623 | int auto_vacuum; |
| 624 | if( ALWAYS(pBt) ){ |
| 625 | auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt); |
| 626 | }else{ |
| 627 | auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM; |
| 628 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 629 | returnSingleInt(pParse, "auto_vacuum", auto_vacuum); |
| 630 | }else{ |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 631 | int eAuto = getAutoVacuum(zRight); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 632 | assert( eAuto>=0 && eAuto<=2 ); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 633 | db->nextAutovac = (u8)eAuto; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 634 | if( ALWAYS(eAuto>=0) ){ |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 635 | /* Call SetAutoVacuum() to set initialize the internal auto and |
| 636 | ** incr-vacuum flags. This is required in case this connection |
| 637 | ** creates the database file. It is important that it is created |
| 638 | ** as an auto-vacuum capable db. |
| 639 | */ |
| 640 | int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 641 | if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 642 | /* When setting the auto_vacuum mode to either "full" or |
| 643 | ** "incremental", write the value of meta[6] in the database |
| 644 | ** file. Before writing to meta[6], check that meta[3] indicates |
| 645 | ** that this really is an auto-vacuum capable database. |
| 646 | */ |
| 647 | static const VdbeOpList setMeta6[] = { |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 648 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 649 | { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 650 | { OP_If, 1, 0, 0}, /* 2 */ |
| 651 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 652 | { OP_Integer, 0, 1, 0}, /* 4 */ |
| 653 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 654 | }; |
| 655 | int iAddr; |
| 656 | iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); |
| 657 | sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 658 | sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 659 | sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 660 | sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 661 | sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 662 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 663 | } |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 664 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 665 | } |
| 666 | }else |
| 667 | #endif |
| 668 | |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 669 | /* |
| 670 | ** PRAGMA [database.]incremental_vacuum(N) |
| 671 | ** |
| 672 | ** Do N steps of incremental vacuuming on a database. |
| 673 | */ |
| 674 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 675 | if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){ |
| 676 | int iLimit, addr; |
danielk1977 | 17a240a | 2007-05-23 13:50:23 +0000 | [diff] [blame] | 677 | if( sqlite3ReadSchema(pParse) ){ |
| 678 | goto pragma_out; |
| 679 | } |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 680 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 681 | iLimit = 0x7fffffff; |
| 682 | } |
| 683 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 4c58312 | 2008-01-04 22:01:03 +0000 | [diff] [blame] | 684 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 685 | addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 686 | sqlite3VdbeAddOp1(v, OP_ResultRow, 1); |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 687 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 688 | sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 689 | sqlite3VdbeJumpHere(v, addr); |
| 690 | }else |
| 691 | #endif |
| 692 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 693 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 694 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 695 | ** PRAGMA [database.]cache_size |
| 696 | ** PRAGMA [database.]cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 697 | ** |
| 698 | ** The first form reports the current local setting for the |
| 699 | ** page cache size. The local setting can be different from |
| 700 | ** the persistent cache size value that is stored in the database |
| 701 | ** file itself. The value returned is the maximum number of |
| 702 | ** pages in the page cache. The second form sets the local |
| 703 | ** page cache size value. It does not change the persistent |
| 704 | ** cache size stored on the disk so the cache size will revert |
| 705 | ** to its default value when the database is closed and reopened. |
| 706 | ** N should be a positive integer. |
| 707 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 708 | if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 709 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 710 | if( !zRight ){ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 711 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 712 | }else{ |
| 713 | int size = atoi(zRight); |
| 714 | if( size<0 ) size = -size; |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 715 | pDb->pSchema->cache_size = size; |
| 716 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 717 | } |
| 718 | }else |
| 719 | |
| 720 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 721 | ** PRAGMA temp_store |
| 722 | ** PRAGMA temp_store = "default"|"memory"|"file" |
| 723 | ** |
| 724 | ** Return or set the local value of the temp_store flag. Changing |
| 725 | ** the local value does not make changes to the disk file and the default |
| 726 | ** value will be restored the next time the database is opened. |
| 727 | ** |
| 728 | ** Note that it is possible for the library compile-time options to |
| 729 | ** override this setting |
| 730 | */ |
| 731 | if( sqlite3StrICmp(zLeft, "temp_store")==0 ){ |
| 732 | if( !zRight ){ |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 733 | returnSingleInt(pParse, "temp_store", db->temp_store); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 734 | }else{ |
| 735 | changeTempStorage(pParse, zRight); |
| 736 | } |
| 737 | }else |
| 738 | |
| 739 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 740 | ** PRAGMA temp_store_directory |
| 741 | ** PRAGMA temp_store_directory = ""|"directory_name" |
| 742 | ** |
| 743 | ** Return or set the local value of the temp_store_directory flag. Changing |
| 744 | ** the value sets a specific directory to be used for temporary files. |
| 745 | ** Setting to a null string reverts to the default temporary directory search. |
| 746 | ** If temporary directory is changed, then invalidateTempStorage. |
| 747 | ** |
| 748 | */ |
| 749 | if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){ |
| 750 | if( !zRight ){ |
| 751 | if( sqlite3_temp_directory ){ |
| 752 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 753 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 754 | "temp_store_directory", SQLITE_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 755 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0); |
| 756 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 757 | } |
| 758 | }else{ |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 759 | #ifndef SQLITE_OMIT_WSD |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 760 | if( zRight[0] ){ |
danielk1977 | fab1127 | 2008-09-16 14:38:02 +0000 | [diff] [blame] | 761 | int rc; |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 762 | int res; |
danielk1977 | fab1127 | 2008-09-16 14:38:02 +0000 | [diff] [blame] | 763 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 764 | if( rc!=SQLITE_OK || res==0 ){ |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 765 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
| 766 | goto pragma_out; |
| 767 | } |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 768 | } |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 769 | if( SQLITE_TEMP_STORE==0 |
| 770 | || (SQLITE_TEMP_STORE==1 && db->temp_store<=1) |
| 771 | || (SQLITE_TEMP_STORE==2 && db->temp_store==1) |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 772 | ){ |
| 773 | invalidateTempStorage(pParse); |
| 774 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 775 | sqlite3_free(sqlite3_temp_directory); |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 776 | if( zRight[0] ){ |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 777 | sqlite3_temp_directory = sqlite3DbStrDup(0, zRight); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 778 | }else{ |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 779 | sqlite3_temp_directory = 0; |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 780 | } |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 781 | #endif /* SQLITE_OMIT_WSD */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 782 | } |
| 783 | }else |
| 784 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 785 | #if !defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 786 | # if defined(__APPLE__) |
| 787 | # define SQLITE_ENABLE_LOCKING_STYLE 1 |
| 788 | # else |
| 789 | # define SQLITE_ENABLE_LOCKING_STYLE 0 |
| 790 | # endif |
| 791 | #endif |
| 792 | #if SQLITE_ENABLE_LOCKING_STYLE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 793 | /* |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 794 | ** PRAGMA [database.]lock_proxy_file |
| 795 | ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path" |
| 796 | ** |
| 797 | ** Return or set the value of the lock_proxy_file flag. Changing |
| 798 | ** the value sets a specific file to be used for database access locks. |
| 799 | ** |
| 800 | */ |
| 801 | if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){ |
| 802 | if( !zRight ){ |
| 803 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 804 | char *proxy_file_path = NULL; |
| 805 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
| 806 | sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE, |
| 807 | &proxy_file_path); |
| 808 | |
| 809 | if( proxy_file_path ){ |
| 810 | sqlite3VdbeSetNumCols(v, 1); |
| 811 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
| 812 | "lock_proxy_file", SQLITE_STATIC); |
| 813 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0); |
| 814 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 815 | } |
| 816 | }else{ |
| 817 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 818 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
| 819 | int res; |
| 820 | if( zRight[0] ){ |
| 821 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 822 | zRight); |
| 823 | } else { |
| 824 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 825 | NULL); |
| 826 | } |
| 827 | if( res!=SQLITE_OK ){ |
| 828 | sqlite3ErrorMsg(pParse, "failed to set lock proxy file"); |
| 829 | goto pragma_out; |
| 830 | } |
| 831 | } |
| 832 | }else |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 833 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 834 | |
| 835 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 836 | ** PRAGMA [database.]synchronous |
| 837 | ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 838 | ** |
| 839 | ** Return or set the local value of the synchronous flag. Changing |
| 840 | ** the local value does not make changes to the disk file and the |
| 841 | ** default value will be restored the next time the database is |
| 842 | ** opened. |
| 843 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 844 | if( sqlite3StrICmp(zLeft,"synchronous")==0 ){ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 845 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 846 | if( !zRight ){ |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 847 | returnSingleInt(pParse, "synchronous", pDb->safety_level-1); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 848 | }else{ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 849 | if( !db->autoCommit ){ |
| 850 | sqlite3ErrorMsg(pParse, |
| 851 | "Safety level may not be changed inside a transaction"); |
| 852 | }else{ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 853 | pDb->safety_level = getSafetyLevel(zRight)+1; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 854 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 855 | } |
| 856 | }else |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 857 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 858 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 859 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 860 | if( flagPragma(pParse, zLeft, zRight) ){ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 861 | /* The flagPragma() subroutine also generates any necessary code |
| 862 | ** there is nothing more to do here */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 863 | }else |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 864 | #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 865 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 866 | #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 867 | /* |
| 868 | ** PRAGMA table_info(<table>) |
| 869 | ** |
| 870 | ** Return a single row for each column of the named table. The columns of |
| 871 | ** the returned data set are: |
| 872 | ** |
| 873 | ** cid: Column id (numbered from left to right, starting at 0) |
| 874 | ** name: Column name |
| 875 | ** type: Column declaration type. |
| 876 | ** notnull: True if 'NOT NULL' is part of column declaration |
| 877 | ** dflt_value: The default value for the column, if any. |
| 878 | */ |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 879 | if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 880 | Table *pTab; |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 881 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 882 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 883 | if( pTab ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 884 | int i; |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 885 | int nHidden = 0; |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 886 | Column *pCol; |
drh | 9f6696a | 2006-02-09 16:52:23 +0000 | [diff] [blame] | 887 | sqlite3VdbeSetNumCols(v, 6); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 888 | pParse->nMem = 6; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 889 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC); |
| 890 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 891 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC); |
| 892 | sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC); |
| 893 | sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC); |
| 894 | sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 895 | sqlite3ViewGetColumnNames(pParse, pTab); |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 896 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 897 | if( IsHiddenColumn(pCol) ){ |
| 898 | nHidden++; |
| 899 | continue; |
| 900 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 901 | sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1); |
| 902 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0); |
| 903 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
drh | bfa8b10 | 2006-03-03 21:20:16 +0000 | [diff] [blame] | 904 | pCol->zType ? pCol->zType : "", 0); |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 905 | sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4); |
drh | b7916a7 | 2009-05-27 10:31:29 +0000 | [diff] [blame] | 906 | if( pCol->zDflt ){ |
| 907 | sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0); |
drh | 6f83598 | 2006-09-25 13:48:30 +0000 | [diff] [blame] | 908 | }else{ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 909 | sqlite3VdbeAddOp2(v, OP_Null, 0, 5); |
drh | 6f83598 | 2006-09-25 13:48:30 +0000 | [diff] [blame] | 910 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 911 | sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6); |
| 912 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | }else |
| 916 | |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 917 | if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 918 | Index *pIdx; |
| 919 | Table *pTab; |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 920 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 921 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 922 | if( pIdx ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 923 | int i; |
| 924 | pTab = pIdx->pTable; |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 925 | sqlite3VdbeSetNumCols(v, 3); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 926 | pParse->nMem = 3; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 927 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC); |
| 928 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC); |
| 929 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 930 | for(i=0; i<pIdx->nColumn; i++){ |
| 931 | int cnum = pIdx->aiColumn[i]; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 932 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 933 | sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 934 | assert( pTab->nCol>cnum ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 935 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0); |
| 936 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | }else |
| 940 | |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 941 | if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 942 | Index *pIdx; |
| 943 | Table *pTab; |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 944 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 945 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 946 | if( pTab ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 947 | v = sqlite3GetVdbe(pParse); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 948 | pIdx = pTab->pIndex; |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 949 | if( pIdx ){ |
| 950 | int i = 0; |
| 951 | sqlite3VdbeSetNumCols(v, 3); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 952 | pParse->nMem = 3; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 953 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 954 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 955 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 956 | while(pIdx){ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 957 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 958 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 959 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3); |
| 960 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 961 | ++i; |
| 962 | pIdx = pIdx->pNext; |
| 963 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | }else |
| 967 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 968 | if( sqlite3StrICmp(zLeft, "database_list")==0 ){ |
| 969 | int i; |
| 970 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 971 | sqlite3VdbeSetNumCols(v, 3); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 972 | pParse->nMem = 3; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 973 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 974 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 975 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 976 | for(i=0; i<db->nDb; i++){ |
| 977 | if( db->aDb[i].pBt==0 ) continue; |
| 978 | assert( db->aDb[i].zName!=0 ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 979 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 980 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0); |
| 981 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 982 | sqlite3BtreeGetFilename(db->aDb[i].pBt), 0); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 983 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 984 | } |
| 985 | }else |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 986 | |
| 987 | if( sqlite3StrICmp(zLeft, "collation_list")==0 ){ |
| 988 | int i = 0; |
| 989 | HashElem *p; |
| 990 | sqlite3VdbeSetNumCols(v, 2); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 991 | pParse->nMem = 2; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 992 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 993 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 994 | for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){ |
| 995 | CollSeq *pColl = (CollSeq *)sqliteHashData(p); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 996 | sqlite3VdbeAddOp2(v, OP_Integer, i++, 1); |
| 997 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0); |
| 998 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 999 | } |
| 1000 | }else |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1001 | #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ |
| 1002 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1003 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 1004 | if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1005 | FKey *pFK; |
| 1006 | Table *pTab; |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 1007 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1008 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1009 | if( pTab ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1010 | v = sqlite3GetVdbe(pParse); |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1011 | pFK = pTab->pFKey; |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1012 | if( pFK ){ |
| 1013 | int i = 0; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1014 | sqlite3VdbeSetNumCols(v, 8); |
| 1015 | pParse->nMem = 8; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1016 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC); |
| 1017 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 1018 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC); |
| 1019 | sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC); |
| 1020 | sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC); |
| 1021 | sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC); |
| 1022 | sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC); |
| 1023 | sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1024 | while(pFK){ |
| 1025 | int j; |
| 1026 | for(j=0; j<pFK->nCol; j++){ |
drh | 2f47149 | 2005-06-23 03:15:07 +0000 | [diff] [blame] | 1027 | char *zCol = pFK->aCol[j].zCol; |
dan | 8099ce6 | 2009-09-23 08:43:35 +0000 | [diff] [blame] | 1028 | char *zOnDelete = (char *)actionName(pFK->aAction[0]); |
| 1029 | char *zOnUpdate = (char *)actionName(pFK->aAction[1]); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1030 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 1031 | sqlite3VdbeAddOp2(v, OP_Integer, j, 2); |
| 1032 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0); |
| 1033 | sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1034 | pTab->aCol[pFK->aCol[j].iFrom].zName, 0); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1035 | sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0); |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1036 | sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0); |
| 1037 | sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0); |
| 1038 | sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0); |
| 1039 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1040 | } |
| 1041 | ++i; |
| 1042 | pFK = pFK->pNextFrom; |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1043 | } |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | }else |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1047 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1048 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1049 | #ifndef NDEBUG |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1050 | if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1051 | if( zRight ){ |
| 1052 | if( getBoolean(zRight) ){ |
| 1053 | sqlite3ParserTrace(stderr, "parser: "); |
| 1054 | }else{ |
| 1055 | sqlite3ParserTrace(0, 0); |
| 1056 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1057 | } |
| 1058 | }else |
| 1059 | #endif |
| 1060 | |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1061 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 1062 | ** used will be case sensitive or not depending on the RHS. |
| 1063 | */ |
| 1064 | if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ |
| 1065 | if( zRight ){ |
| 1066 | sqlite3RegisterLikeFunctions(db, getBoolean(zRight)); |
| 1067 | } |
| 1068 | }else |
| 1069 | |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1070 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 1071 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| 1072 | #endif |
| 1073 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1074 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1075 | /* Pragma "quick_check" is an experimental reduced version of |
| 1076 | ** integrity_check designed to detect most database corruption |
| 1077 | ** without most of the overhead of a full integrity-check. |
| 1078 | */ |
| 1079 | if( sqlite3StrICmp(zLeft, "integrity_check")==0 |
| 1080 | || sqlite3StrICmp(zLeft, "quick_check")==0 |
| 1081 | ){ |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1082 | int i, j, addr, mxErr; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1083 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1084 | /* Code that appears at the end of the integrity check. If no error |
| 1085 | ** messages have been generated, output OK. Otherwise output the |
| 1086 | ** error message |
| 1087 | */ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 1088 | static const VdbeOpList endCode[] = { |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1089 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 1090 | { OP_IfNeg, 1, 0, 0}, /* 1 */ |
| 1091 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 1092 | { OP_ResultRow, 3, 1, 0}, |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1093 | }; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1094 | |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1095 | int isQuick = (zLeft[0]=='q'); |
| 1096 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1097 | /* Initialize the VDBE program */ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 1098 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1099 | pParse->nMem = 6; |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 1100 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1101 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1102 | |
| 1103 | /* Set the maximum error count */ |
| 1104 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1105 | if( zRight ){ |
| 1106 | mxErr = atoi(zRight); |
| 1107 | if( mxErr<=0 ){ |
| 1108 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1109 | } |
| 1110 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1111 | sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1112 | |
| 1113 | /* Do an integrity check on each database file */ |
| 1114 | for(i=0; i<db->nDb; i++){ |
| 1115 | HashElem *x; |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1116 | Hash *pTbls; |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1117 | int cnt = 0; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1118 | |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1119 | if( OMIT_TEMPDB && i==1 ) continue; |
| 1120 | |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1121 | sqlite3CodeVerifySchema(pParse, i); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1122 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */ |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1123 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1124 | sqlite3VdbeJumpHere(v, addr); |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1125 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1126 | /* Do an integrity check of the B-Tree |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1127 | ** |
| 1128 | ** Begin by filling registers 2, 3, ... with the root pages numbers |
| 1129 | ** for all tables and indices in the database. |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1130 | */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1131 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 1132 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1133 | Table *pTab = sqliteHashData(x); |
| 1134 | Index *pIdx; |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1135 | sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1136 | cnt++; |
| 1137 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1138 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt); |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1139 | cnt++; |
| 1140 | } |
| 1141 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1142 | |
| 1143 | /* Make sure sufficient number of registers have been allocated */ |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1144 | if( pParse->nMem < cnt+4 ){ |
| 1145 | pParse->nMem = cnt+4; |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1146 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1147 | |
| 1148 | /* Do the b-tree integrity checks */ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1149 | sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 1150 | sqlite3VdbeChangeP5(v, (u8)i); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1151 | addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); |
| 1152 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 1153 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1154 | P4_DYNAMIC); |
drh | b21e7c7 | 2008-06-22 12:37:57 +0000 | [diff] [blame] | 1155 | sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1); |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1156 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1157 | sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1158 | sqlite3VdbeJumpHere(v, addr); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1159 | |
| 1160 | /* Make sure all the indices are constructed correctly. |
| 1161 | */ |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1162 | for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1163 | Table *pTab = sqliteHashData(x); |
| 1164 | Index *pIdx; |
| 1165 | int loopTop; |
| 1166 | |
| 1167 | if( pTab->pIndex==0 ) continue; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1168 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */ |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1169 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1170 | sqlite3VdbeJumpHere(v, addr); |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 1171 | sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1172 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 2); /* reg(2) will count entries */ |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1173 | loopTop = sqlite3VdbeAddOp2(v, OP_Rewind, 1, 0); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1174 | sqlite3VdbeAddOp2(v, OP_AddImm, 2, 1); /* increment entry count */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1175 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
danielk1977 | 13adf8a | 2004-06-03 16:08:41 +0000 | [diff] [blame] | 1176 | int jmp2; |
drh | 91fc4a0 | 2009-11-12 20:39:03 +0000 | [diff] [blame] | 1177 | int r1; |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 1178 | static const VdbeOpList idxErr[] = { |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 1179 | { OP_AddImm, 1, -1, 0}, |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1180 | { OP_String8, 0, 3, 0}, /* 1 */ |
| 1181 | { OP_Rowid, 1, 4, 0}, |
| 1182 | { OP_String8, 0, 5, 0}, /* 3 */ |
| 1183 | { OP_String8, 0, 6, 0}, /* 4 */ |
| 1184 | { OP_Concat, 4, 3, 3}, |
| 1185 | { OP_Concat, 5, 3, 3}, |
| 1186 | { OP_Concat, 6, 3, 3}, |
| 1187 | { OP_ResultRow, 3, 1, 0}, |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 1188 | { OP_IfPos, 1, 0, 0}, /* 9 */ |
| 1189 | { OP_Halt, 0, 0, 0}, |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1190 | }; |
drh | 91fc4a0 | 2009-11-12 20:39:03 +0000 | [diff] [blame] | 1191 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0); |
| 1192 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1193 | addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr); |
drh | 2400345 | 2008-01-03 01:28:59 +0000 | [diff] [blame] | 1194 | sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC); |
| 1195 | sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1196 | sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC); |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 1197 | sqlite3VdbeJumpHere(v, addr+9); |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1198 | sqlite3VdbeJumpHere(v, jmp2); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1199 | } |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1200 | sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1); |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1201 | sqlite3VdbeJumpHere(v, loopTop); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1202 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 1203 | static const VdbeOpList cntIdx[] = { |
drh | 4c58312 | 2008-01-04 22:01:03 +0000 | [diff] [blame] | 1204 | { OP_Integer, 0, 3, 0}, |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1205 | { OP_Rewind, 0, 0, 0}, /* 1 */ |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 1206 | { OP_AddImm, 3, 1, 0}, |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1207 | { OP_Next, 0, 0, 0}, /* 3 */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1208 | { OP_Eq, 2, 0, 3}, /* 4 */ |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 1209 | { OP_AddImm, 1, -1, 0}, |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1210 | { OP_String8, 0, 2, 0}, /* 6 */ |
| 1211 | { OP_String8, 0, 3, 0}, /* 7 */ |
| 1212 | { OP_Concat, 3, 2, 2}, |
| 1213 | { OP_ResultRow, 2, 1, 0}, |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1214 | }; |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 1215 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1216 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1217 | sqlite3VdbeJumpHere(v, addr); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1218 | addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx); |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1219 | sqlite3VdbeChangeP1(v, addr+1, j+2); |
| 1220 | sqlite3VdbeChangeP2(v, addr+1, addr+4); |
| 1221 | sqlite3VdbeChangeP1(v, addr+3, j+2); |
| 1222 | sqlite3VdbeChangeP2(v, addr+3, addr+2); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1223 | sqlite3VdbeJumpHere(v, addr+4); |
| 1224 | sqlite3VdbeChangeP4(v, addr+6, |
drh | 2400345 | 2008-01-03 01:28:59 +0000 | [diff] [blame] | 1225 | "wrong # of entries in index ", P4_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1226 | sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1230 | addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1231 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| 1232 | sqlite3VdbeJumpHere(v, addr+1); |
| 1233 | sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1234 | }else |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1235 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 1236 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1237 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1238 | /* |
| 1239 | ** PRAGMA encoding |
| 1240 | ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" |
| 1241 | ** |
drh | 85b623f | 2007-12-13 21:54:09 +0000 | [diff] [blame] | 1242 | ** In its first form, this pragma returns the encoding of the main |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1243 | ** database. If the database is not initialized, it is initialized now. |
| 1244 | ** |
| 1245 | ** The second form of this pragma is a no-op if the main database file |
| 1246 | ** has not already been initialized. In this case it sets the default |
| 1247 | ** encoding that will be used for the main database file if a new file |
| 1248 | ** is created. If an existing main database file is opened, then the |
| 1249 | ** default text encoding for the existing database is used. |
| 1250 | ** |
| 1251 | ** In all cases new databases created using the ATTACH command are |
| 1252 | ** created to use the same default text encoding as the main database. If |
| 1253 | ** the main database has not been initialized and/or created when ATTACH |
| 1254 | ** is executed, this is done before the ATTACH operation. |
| 1255 | ** |
| 1256 | ** In the second form this pragma sets the text encoding to be used in |
| 1257 | ** new database files created using this database handle. It is only |
| 1258 | ** useful if invoked immediately after the main database i |
| 1259 | */ |
| 1260 | if( sqlite3StrICmp(zLeft, "encoding")==0 ){ |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1261 | static const struct EncName { |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1262 | char *zName; |
| 1263 | u8 enc; |
| 1264 | } encnames[] = { |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1265 | { "UTF8", SQLITE_UTF8 }, |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1266 | { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */ |
| 1267 | { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */ |
| 1268 | { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */ |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1269 | { "UTF16le", SQLITE_UTF16LE }, |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1270 | { "UTF16be", SQLITE_UTF16BE }, |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1271 | { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */ |
| 1272 | { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1273 | { 0, 0 } |
| 1274 | }; |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1275 | const struct EncName *pEnc; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1276 | if( !zRight ){ /* "PRAGMA encoding" */ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 1277 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1278 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1279 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1280 | sqlite3VdbeAddOp2(v, OP_String8, 0, 1); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1281 | assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 ); |
| 1282 | assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE ); |
| 1283 | assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE ); |
| 1284 | sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1285 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1286 | }else{ /* "PRAGMA encoding = XXX" */ |
| 1287 | /* Only change the value of sqlite.enc if the database handle is not |
| 1288 | ** initialized. If the main database exists, the new sqlite.enc value |
| 1289 | ** will be overwritten when the schema is next loaded. If it does not |
| 1290 | ** already exists, it will be created to use the new encoding value. |
| 1291 | */ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 1292 | if( |
| 1293 | !(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
| 1294 | DbHasProperty(db, 0, DB_Empty) |
| 1295 | ){ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1296 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 1297 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1298 | ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1299 | break; |
| 1300 | } |
| 1301 | } |
| 1302 | if( !pEnc->zName ){ |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 1303 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | }else |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1308 | #endif /* SQLITE_OMIT_UTF16 */ |
| 1309 | |
| 1310 | #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1311 | /* |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1312 | ** PRAGMA [database.]schema_version |
| 1313 | ** PRAGMA [database.]schema_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1314 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1315 | ** PRAGMA [database.]user_version |
| 1316 | ** PRAGMA [database.]user_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1317 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1318 | ** The pragma's schema_version and user_version are used to set or get |
| 1319 | ** the value of the schema-version and user-version, respectively. Both |
| 1320 | ** the schema-version and the user-version are 32-bit signed integers |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1321 | ** stored in the database header. |
| 1322 | ** |
| 1323 | ** The schema-cookie is usually only manipulated internally by SQLite. It |
| 1324 | ** is incremented by SQLite whenever the database schema is modified (by |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1325 | ** creating or dropping a table or index). The schema version is used by |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1326 | ** SQLite each time a query is executed to ensure that the internal cache |
| 1327 | ** of the schema used when compiling the SQL query matches the schema of |
| 1328 | ** the database against which the compiled query is actually executed. |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1329 | ** Subverting this mechanism by using "PRAGMA schema_version" to modify |
| 1330 | ** the schema-version is potentially dangerous and may lead to program |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1331 | ** crashes or database corruption. Use with caution! |
| 1332 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1333 | ** 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] | 1334 | ** applications for any purpose. |
| 1335 | */ |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 1336 | if( sqlite3StrICmp(zLeft, "schema_version")==0 |
| 1337 | || sqlite3StrICmp(zLeft, "user_version")==0 |
| 1338 | || sqlite3StrICmp(zLeft, "freelist_count")==0 |
| 1339 | ){ |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 1340 | int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */ |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 1341 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 1342 | switch( zLeft[0] ){ |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 1343 | case 'f': case 'F': |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 1344 | iCookie = BTREE_FREE_PAGE_COUNT; |
| 1345 | break; |
| 1346 | case 's': case 'S': |
| 1347 | iCookie = BTREE_SCHEMA_VERSION; |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 1348 | break; |
| 1349 | default: |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 1350 | iCookie = BTREE_USER_VERSION; |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 1351 | break; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 1354 | if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1355 | /* Write the specified cookie value */ |
| 1356 | static const VdbeOpList setCookie[] = { |
| 1357 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 1358 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 1359 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1360 | }; |
| 1361 | int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie); |
| 1362 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 1363 | sqlite3VdbeChangeP1(v, addr+1, atoi(zRight)); |
| 1364 | sqlite3VdbeChangeP1(v, addr+2, iDb); |
| 1365 | sqlite3VdbeChangeP2(v, addr+2, iCookie); |
| 1366 | }else{ |
| 1367 | /* Read the specified cookie value */ |
| 1368 | static const VdbeOpList readCookie[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 1369 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 1370 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1371 | { OP_ResultRow, 1, 1, 0} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1372 | }; |
| 1373 | int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie); |
| 1374 | sqlite3VdbeChangeP1(v, addr, iDb); |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 1375 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 1376 | sqlite3VdbeChangeP3(v, addr+1, iCookie); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1377 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1378 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1379 | } |
drh | 6e34599 | 2007-03-30 11:12:08 +0000 | [diff] [blame] | 1380 | }else |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1381 | #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1382 | |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1383 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 1384 | /* |
| 1385 | ** PRAGMA compile_options |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1386 | ** |
drh | 71caabf | 2010-02-26 15:39:24 +0000 | [diff] [blame] | 1387 | ** Return the names of all compile-time options used in this build, |
| 1388 | ** one option per row. |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1389 | */ |
drh | 264a2d4 | 2010-02-25 15:28:41 +0000 | [diff] [blame] | 1390 | if( sqlite3StrICmp(zLeft, "compile_options")==0 ){ |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 1391 | int i = 0; |
| 1392 | const char *zOpt; |
| 1393 | sqlite3VdbeSetNumCols(v, 1); |
| 1394 | pParse->nMem = 1; |
| 1395 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC); |
| 1396 | while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){ |
| 1397 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0); |
| 1398 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 1399 | } |
| 1400 | }else |
| 1401 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 1402 | |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 1403 | #ifndef SQLITE_OMIT_WAL |
| 1404 | /* |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1405 | ** PRAGMA [database.]wal_checkpoint |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 1406 | ** |
| 1407 | ** Checkpoint the database. |
| 1408 | */ |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1409 | if( sqlite3StrICmp(zLeft, "wal_checkpoint")==0 ){ |
| 1410 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
dan | af0cfd3 | 2010-05-03 15:58:50 +0000 | [diff] [blame] | 1411 | sqlite3VdbeAddOp3(v, OP_Checkpoint, pId2->z?iDb:SQLITE_MAX_ATTACHED, 0, 0); |
dan | 7c24610 | 2010-04-12 19:00:29 +0000 | [diff] [blame] | 1412 | }else |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1413 | |
| 1414 | /* |
| 1415 | ** PRAGMA wal_autocheckpoint |
| 1416 | ** PRAGMA wal_autocheckpoint = N |
| 1417 | ** |
| 1418 | ** Configure a database connection to automatically checkpoint a database |
| 1419 | ** after accumulating N frames in the log. Or query for the current value |
| 1420 | ** of N. |
| 1421 | */ |
| 1422 | if( sqlite3StrICmp(zLeft, "wal_autocheckpoint")==0 ){ |
| 1423 | if( zRight ){ |
| 1424 | int nAuto = atoi(zRight); |
| 1425 | sqlite3_wal_autocheckpoint(db, nAuto); |
| 1426 | } |
drh | b033d8b | 2010-05-03 13:37:30 +0000 | [diff] [blame] | 1427 | returnSingleInt(pParse, "wal_autocheckpoint", |
| 1428 | db->xWalCallback==sqlite3WalDefaultHook ? |
| 1429 | SQLITE_PTR_TO_INT(db->pWalArg) : 0); |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 1430 | }else |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 1431 | #endif |
dan | 7c24610 | 2010-04-12 19:00:29 +0000 | [diff] [blame] | 1432 | |
dougcurrie | 81c95ef | 2004-06-18 23:21:47 +0000 | [diff] [blame] | 1433 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1434 | /* |
| 1435 | ** Report the current state of file logs for all databases |
| 1436 | */ |
| 1437 | if( sqlite3StrICmp(zLeft, "lock_status")==0 ){ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 1438 | static const char *const azLockName[] = { |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1439 | "unlocked", "shared", "reserved", "pending", "exclusive" |
| 1440 | }; |
| 1441 | int i; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1442 | sqlite3VdbeSetNumCols(v, 2); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1443 | pParse->nMem = 2; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1444 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC); |
| 1445 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1446 | for(i=0; i<db->nDb; i++){ |
| 1447 | Btree *pBt; |
| 1448 | Pager *pPager; |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 1449 | const char *zState = "unknown"; |
| 1450 | int j; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1451 | if( db->aDb[i].zName==0 ) continue; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1452 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1453 | pBt = db->aDb[i].pBt; |
| 1454 | if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 1455 | zState = "closed"; |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 1456 | }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 1457 | SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){ |
| 1458 | zState = azLockName[j]; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1459 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1460 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC); |
| 1461 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1462 | } |
danielk1977 | a4de453 | 2008-09-02 15:44:08 +0000 | [diff] [blame] | 1463 | |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 1464 | }else |
| 1465 | #endif |
| 1466 | |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 1467 | #ifdef SQLITE_HAS_CODEC |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1468 | if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){ |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 1469 | sqlite3_key(db, zRight, sqlite3Strlen30(zRight)); |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 1470 | }else |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1471 | if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){ |
| 1472 | sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight)); |
| 1473 | }else |
| 1474 | if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 || |
| 1475 | sqlite3StrICmp(zLeft, "hexrekey")==0) ){ |
| 1476 | int i, h1, h2; |
| 1477 | char zKey[40]; |
| 1478 | for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){ |
| 1479 | h1 += 9*(1&(h1>>6)); |
| 1480 | h2 += 9*(1&(h2>>6)); |
| 1481 | zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4); |
| 1482 | } |
| 1483 | if( (zLeft[3] & 0xf)==0xb ){ |
| 1484 | sqlite3_key(db, zKey, i/2); |
| 1485 | }else{ |
| 1486 | sqlite3_rekey(db, zKey, i/2); |
| 1487 | } |
| 1488 | }else |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 1489 | #endif |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 1490 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1491 | if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){ |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 1492 | #ifdef SQLITE_HAS_CODEC |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1493 | if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1494 | sqlite3_activate_see(&zRight[4]); |
| 1495 | } |
| 1496 | #endif |
| 1497 | #ifdef SQLITE_ENABLE_CEROD |
| 1498 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1499 | sqlite3_activate_cerod(&zRight[6]); |
| 1500 | } |
| 1501 | #endif |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1502 | }else |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 1503 | #endif |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 1504 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1505 | |
| 1506 | {/* Empty ELSE clause */} |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 1507 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1508 | /* |
| 1509 | ** Reset the safety level, in case the fullfsync flag or synchronous |
| 1510 | ** setting changed. |
| 1511 | */ |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 1512 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1513 | if( db->autoCommit ){ |
| 1514 | sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, |
| 1515 | (db->flags&SQLITE_FullFSync)!=0); |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 1516 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1517 | #endif |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 1518 | pragma_out: |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 1519 | sqlite3DbFree(db, zLeft); |
| 1520 | sqlite3DbFree(db, zRight); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1521 | } |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1522 | |
drh | 8bfdf72 | 2009-06-19 14:06:03 +0000 | [diff] [blame] | 1523 | #endif /* SQLITE_OMIT_PRAGMA */ |