|
ds@1952
|
1 |
/* |
|
ds@1952
|
2 |
** 2003 April 6 |
|
ds@1952
|
3 |
** |
|
ds@1952
|
4 |
** The author disclaims copyright to this source code. In place of |
|
ds@1952
|
5 |
** a legal notice, here is a blessing: |
|
ds@1952
|
6 |
** |
|
ds@1952
|
7 |
** May you do good and not evil. |
|
ds@1952
|
8 |
** May you find forgiveness for yourself and forgive others. |
|
ds@1952
|
9 |
** May you share freely, never taking more than you give. |
|
ds@1952
|
10 |
** |
|
ds@1952
|
11 |
************************************************************************* |
|
ds@1952
|
12 |
** This file contains code used to implement the PRAGMA command. |
|
ds@1952
|
13 |
** |
|
ds@1952
|
14 |
** $Id$ |
|
ds@1952
|
15 |
*/ |
|
ds@1952
|
16 |
#include "sqliteInt.h" |
|
ds@1952
|
17 |
#include <ctype.h> |
|
ds@1952
|
18 |
|
|
ds@1952
|
19 |
/* Ignore this whole file if pragmas are disabled |
|
ds@1952
|
20 |
*/ |
|
ds@1952
|
21 |
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER) |
|
ds@1952
|
22 |
|
|
ds@1952
|
23 |
/* |
|
ds@1952
|
24 |
** Interpret the given string as a safety level. Return 0 for OFF, |
|
ds@1952
|
25 |
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or |
|
ds@1952
|
26 |
** unrecognized string argument. |
|
ds@1952
|
27 |
** |
|
ds@1952
|
28 |
** Note that the values returned are one less that the values that |
|
ds@1952
|
29 |
** should be passed into sqlite3BtreeSetSafetyLevel(). The is done |
|
ds@1952
|
30 |
** to support legacy SQL code. The safety level used to be boolean |
|
ds@1952
|
31 |
** and older scripts may have used numbers 0 for OFF and 1 for ON. |
|
ds@1952
|
32 |
*/ |
|
ds@1952
|
33 |
static int getSafetyLevel(const char *z){ |
|
ds@1952
|
34 |
/* 123456789 123456789 */ |
|
ds@1952
|
35 |
static const char zText[] = "onoffalseyestruefull"; |
|
ds@1952
|
36 |
static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; |
|
ds@1952
|
37 |
static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; |
|
ds@1952
|
38 |
static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; |
|
ds@1952
|
39 |
int i, n; |
|
ds@1952
|
40 |
if( isdigit(*z) ){ |
|
ds@1952
|
41 |
return atoi(z); |
|
ds@1952
|
42 |
} |
|
ds@1952
|
43 |
n = strlen(z); |
|
ds@1952
|
44 |
for(i=0; i<sizeof(iLength); i++){ |
|
ds@1952
|
45 |
if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){ |
|
ds@1952
|
46 |
return iValue[i]; |
|
ds@1952
|
47 |
} |
|
ds@1952
|
48 |
} |
|
ds@1952
|
49 |
return 1; |
|
ds@1952
|
50 |
} |
|
ds@1952
|
51 |
|
|
ds@1952
|
52 |
/* |
|
ds@1952
|
53 |
** Interpret the given string as a boolean value. |
|
ds@1952
|
54 |
*/ |
|
ds@1952
|
55 |
static int getBoolean(const char *z){ |
|
ds@1952
|
56 |
return getSafetyLevel(z)&1; |
|
ds@1952
|
57 |
} |
|
ds@1952
|
58 |
|
|
ds@1952
|
59 |
/* |
|
ds@1952
|
60 |
** Interpret the given string as a locking mode value. |
|
ds@1952
|
61 |
*/ |
|
ds@1952
|
62 |
static int getLockingMode(const char *z){ |
|
ds@1952
|
63 |
if( z ){ |
|
ds@1952
|
64 |
if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE; |
|
ds@1952
|
65 |
if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL; |
|
ds@1952
|
66 |
} |
|
ds@1952
|
67 |
return PAGER_LOCKINGMODE_QUERY; |
|
ds@1952
|
68 |
} |
|
ds@1952
|
69 |
|
|
ds@1952
|
70 |
#ifndef SQLITE_OMIT_AUTOVACUUM |
|
ds@1952
|
71 |
/* |
|
ds@1952
|
72 |
** Interpret the given string as an auto-vacuum mode value. |
|
ds@1952
|
73 |
** |
|
ds@1952
|
74 |
** The following strings, "none", "full" and "incremental" are |
|
ds@1952
|
75 |
** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively. |
|
ds@1952
|
76 |
*/ |
|
ds@1952
|
77 |
static int getAutoVacuum(const char *z){ |
|
ds@1952
|
78 |
int i; |
|
ds@1952
|
79 |
if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE; |
|
ds@1952
|
80 |
if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL; |
|
ds@1952
|
81 |
if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR; |
|
ds@1952
|
82 |
i = atoi(z); |
|
ds@1952
|
83 |
return ((i>=0&&i<=2)?i:0); |
|
ds@1952
|
84 |
} |
|
ds@1952
|
85 |
#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */ |
|
ds@1952
|
86 |
|
|
ds@1952
|
87 |
#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
|
ds@1952
|
88 |
/* |
|
ds@1952
|
89 |
** Interpret the given string as a temp db location. Return 1 for file |
|
ds@1952
|
90 |
** backed temporary databases, 2 for the Red-Black tree in memory database |
|
ds@1952
|
91 |
** and 0 to use the compile-time default. |
|
ds@1952
|
92 |
*/ |
|
ds@1952
|
93 |
static int getTempStore(const char *z){ |
|
ds@1952
|
94 |
if( z[0]>='0' && z[0]<='2' ){ |
|
ds@1952
|
95 |
return z[0] - '0'; |
|
ds@1952
|
96 |
}else if( sqlite3StrICmp(z, "file")==0 ){ |
|
ds@1952
|
97 |
return 1; |
|
ds@1952
|
98 |
}else if( sqlite3StrICmp(z, "memory")==0 ){ |
|
ds@1952
|
99 |
return 2; |
|
ds@1952
|
100 |
}else{ |
|
ds@1952
|
101 |
return 0; |
|
ds@1952
|
102 |
} |
|
ds@1952
|
103 |
} |
|
ds@1952
|
104 |
#endif /* SQLITE_PAGER_PRAGMAS */ |
|
ds@1952
|
105 |
|
|
ds@1952
|
106 |
#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
|
ds@1952
|
107 |
/* |
|
ds@1952
|
108 |
** Invalidate temp storage, either when the temp storage is changed |
|
ds@1952
|
109 |
** from default, or when 'file' and the temp_store_directory has changed |
|
ds@1952
|
110 |
*/ |
|
ds@1952
|
111 |
static int invalidateTempStorage(Parse *pParse){ |
|
ds@1952
|
112 |
sqlite3 *db = pParse->db; |
|
ds@1952
|
113 |
if( db->aDb[1].pBt!=0 ){ |
|
ds@1952
|
114 |
if( !db->autoCommit ){ |
|
ds@1952
|
115 |
sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " |
|
ds@1952
|
116 |
"from within a transaction"); |
|
ds@1952
|
117 |
return SQLITE_ERROR; |
|
ds@1952
|
118 |
} |
|
ds@1952
|
119 |
sqlite3BtreeClose(db->aDb[1].pBt); |
|
ds@1952
|
120 |
db->aDb[1].pBt = 0; |
|
ds@1952
|
121 |
sqlite3ResetInternalSchema(db, 0); |
|
ds@1952
|
122 |
} |
|
ds@1952
|
123 |
return SQLITE_OK; |
|
ds@1952
|
124 |
} |
|
ds@1952
|
125 |
#endif /* SQLITE_PAGER_PRAGMAS */ |
|
ds@1952
|
126 |
|
|
ds@1952
|
127 |
#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
|
ds@1952
|
128 |
/* |
|
ds@1952
|
129 |
** If the TEMP database is open, close it and mark the database schema |
|
ds@1952
|
130 |
** as needing reloading. This must be done when using the TEMP_STORE |
|
ds@1952
|
131 |
** or DEFAULT_TEMP_STORE pragmas. |
|
ds@1952
|
132 |
*/ |
|
ds@1952
|
133 |
static int changeTempStorage(Parse *pParse, const char *zStorageType){ |
|
ds@1952
|
134 |
int ts = getTempStore(zStorageType); |
|
ds@1952
|
135 |
sqlite3 *db = pParse->db; |
|
ds@1952
|
136 |
if( db->temp_store==ts ) return SQLITE_OK; |
|
ds@1952
|
137 |
if( invalidateTempStorage( pParse ) != SQLITE_OK ){ |
|
ds@1952
|
138 |
return SQLITE_ERROR; |
|
ds@1952
|
139 |
} |
|
ds@1952
|
140 |
db->temp_store = ts; |
|
ds@1952
|
141 |
return SQLITE_OK; |
|
ds@1952
|
142 |
} |
|
ds@1952
|
143 |
#endif /* SQLITE_PAGER_PRAGMAS */ |
|
ds@1952
|
144 |
|
|
ds@1952
|
145 |
/* |
|
ds@1952
|
146 |
** Generate code to return a single integer value. |
|
ds@1952
|
147 |
*/ |
|
ds@1952
|
148 |
static void returnSingleInt(Parse *pParse, const char *zLabel, int value){ |
|
ds@1952
|
149 |
Vdbe *v = sqlite3GetVdbe(pParse); |
|
ds@1952
|
150 |
sqlite3VdbeAddOp(v, OP_Integer, value, 0); |
|
ds@1952
|
151 |
if( pParse->explain==0 ){ |
|
ds@1952
|
152 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
153 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC); |
|
ds@1952
|
154 |
} |
|
ds@1952
|
155 |
sqlite3VdbeAddOp(v, OP_Callback, 1, 0); |
|
ds@1952
|
156 |
} |
|
ds@1952
|
157 |
|
|
ds@1952
|
158 |
#ifndef SQLITE_OMIT_FLAG_PRAGMAS |
|
ds@1952
|
159 |
/* |
|
ds@1952
|
160 |
** Check to see if zRight and zLeft refer to a pragma that queries |
|
ds@1952
|
161 |
** or changes one of the flags in db->flags. Return 1 if so and 0 if not. |
|
ds@1952
|
162 |
** Also, implement the pragma. |
|
ds@1952
|
163 |
*/ |
|
ds@1952
|
164 |
static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ |
|
ds@1952
|
165 |
static const struct sPragmaType { |
|
ds@1952
|
166 |
const char *zName; /* Name of the pragma */ |
|
ds@1952
|
167 |
int mask; /* Mask for the db->flags value */ |
|
ds@1952
|
168 |
} aPragma[] = { |
|
ds@1952
|
169 |
{ "full_column_names", SQLITE_FullColNames }, |
|
ds@1952
|
170 |
{ "short_column_names", SQLITE_ShortColNames }, |
|
ds@1952
|
171 |
{ "count_changes", SQLITE_CountRows }, |
|
ds@1952
|
172 |
{ "empty_result_callbacks", SQLITE_NullCallback }, |
|
ds@1952
|
173 |
{ "legacy_file_format", SQLITE_LegacyFileFmt }, |
|
ds@1952
|
174 |
{ "fullfsync", SQLITE_FullFSync }, |
|
ds@1952
|
175 |
#ifdef SQLITE_DEBUG |
|
ds@1952
|
176 |
{ "sql_trace", SQLITE_SqlTrace }, |
|
ds@1952
|
177 |
{ "vdbe_listing", SQLITE_VdbeListing }, |
|
ds@1952
|
178 |
{ "vdbe_trace", SQLITE_VdbeTrace }, |
|
ds@1952
|
179 |
#endif |
|
ds@1952
|
180 |
#ifndef SQLITE_OMIT_CHECK |
|
ds@1952
|
181 |
{ "ignore_check_constraints", SQLITE_IgnoreChecks }, |
|
ds@1952
|
182 |
#endif |
|
ds@1952
|
183 |
/* The following is VERY experimental */ |
|
ds@1952
|
184 |
{ "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
|
ds@1952
|
185 |
{ "omit_readlock", SQLITE_NoReadlock }, |
|
ds@1952
|
186 |
|
|
ds@1952
|
187 |
/* TODO: Maybe it shouldn't be possible to change the ReadUncommitted |
|
ds@1952
|
188 |
** flag if there are any active statements. */ |
|
ds@1952
|
189 |
{ "read_uncommitted", SQLITE_ReadUncommitted }, |
|
ds@1952
|
190 |
}; |
|
ds@1952
|
191 |
int i; |
|
ds@1952
|
192 |
const struct sPragmaType *p; |
|
ds@1952
|
193 |
for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){ |
|
ds@1952
|
194 |
if( sqlite3StrICmp(zLeft, p->zName)==0 ){ |
|
ds@1952
|
195 |
sqlite3 *db = pParse->db; |
|
ds@1952
|
196 |
Vdbe *v; |
|
ds@1952
|
197 |
v = sqlite3GetVdbe(pParse); |
|
ds@1952
|
198 |
if( v ){ |
|
ds@1952
|
199 |
if( zRight==0 ){ |
|
ds@1952
|
200 |
returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 ); |
|
ds@1952
|
201 |
}else{ |
|
ds@1952
|
202 |
if( getBoolean(zRight) ){ |
|
ds@1952
|
203 |
db->flags |= p->mask; |
|
ds@1952
|
204 |
}else{ |
|
ds@1952
|
205 |
db->flags &= ~p->mask; |
|
ds@1952
|
206 |
} |
|
ds@1952
|
207 |
} |
|
ds@1952
|
208 |
} |
|
ds@1952
|
209 |
return 1; |
|
ds@1952
|
210 |
} |
|
ds@1952
|
211 |
} |
|
ds@1952
|
212 |
return 0; |
|
ds@1952
|
213 |
} |
|
ds@1952
|
214 |
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
|
ds@1952
|
215 |
|
|
ds@1952
|
216 |
/* |
|
ds@1952
|
217 |
** Process a pragma statement. |
|
ds@1952
|
218 |
** |
|
ds@1952
|
219 |
** Pragmas are of this form: |
|
ds@1952
|
220 |
** |
|
ds@1952
|
221 |
** PRAGMA [database.]id [= value] |
|
ds@1952
|
222 |
** |
|
ds@1952
|
223 |
** The identifier might also be a string. The value is a string, and |
|
ds@1952
|
224 |
** identifier, or a number. If minusFlag is true, then the value is |
|
ds@1952
|
225 |
** a number that was preceded by a minus sign. |
|
ds@1952
|
226 |
** |
|
ds@1952
|
227 |
** If the left side is "database.id" then pId1 is the database name |
|
ds@1952
|
228 |
** and pId2 is the id. If the left side is just "id" then pId1 is the |
|
ds@1952
|
229 |
** id and pId2 is any empty string. |
|
ds@1952
|
230 |
*/ |
|
ds@1952
|
231 |
void sqlite3Pragma( |
|
ds@1952
|
232 |
Parse *pParse, |
|
ds@1952
|
233 |
Token *pId1, /* First part of [database.]id field */ |
|
ds@1952
|
234 |
Token *pId2, /* Second part of [database.]id field, or NULL */ |
|
ds@1952
|
235 |
Token *pValue, /* Token for <value>, or NULL */ |
|
ds@1952
|
236 |
int minusFlag /* True if a '-' sign preceded <value> */ |
|
ds@1952
|
237 |
){ |
|
ds@1952
|
238 |
char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ |
|
ds@1952
|
239 |
char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
|
ds@1952
|
240 |
const char *zDb = 0; /* The database name */ |
|
ds@1952
|
241 |
Token *pId; /* Pointer to <id> token */ |
|
ds@1952
|
242 |
int iDb; /* Database index for <database> */ |
|
ds@1952
|
243 |
sqlite3 *db = pParse->db; |
|
ds@1952
|
244 |
Db *pDb; |
|
ds@1952
|
245 |
Vdbe *v = sqlite3GetVdbe(pParse); |
|
ds@1952
|
246 |
if( v==0 ) return; |
|
ds@1952
|
247 |
|
|
ds@1952
|
248 |
/* Interpret the [database.] part of the pragma statement. iDb is the |
|
ds@1952
|
249 |
** index of the database this pragma is being applied to in db.aDb[]. */ |
|
ds@1952
|
250 |
iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); |
|
ds@1952
|
251 |
if( iDb<0 ) return; |
|
ds@1952
|
252 |
pDb = &db->aDb[iDb]; |
|
ds@1952
|
253 |
|
|
ds@1952
|
254 |
/* If the temp database has been explicitly named as part of the |
|
ds@1952
|
255 |
** pragma, make sure it is open. |
|
ds@1952
|
256 |
*/ |
|
ds@1952
|
257 |
if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){ |
|
ds@1952
|
258 |
return; |
|
ds@1952
|
259 |
} |
|
ds@1952
|
260 |
|
|
ds@1952
|
261 |
zLeft = sqlite3NameFromToken(db, pId); |
|
ds@1952
|
262 |
if( !zLeft ) return; |
|
ds@1952
|
263 |
if( minusFlag ){ |
|
ds@1952
|
264 |
zRight = sqlite3MPrintf(db, "-%T", pValue); |
|
ds@1952
|
265 |
}else{ |
|
ds@1952
|
266 |
zRight = sqlite3NameFromToken(db, pValue); |
|
ds@1952
|
267 |
} |
|
ds@1952
|
268 |
|
|
ds@1952
|
269 |
zDb = ((iDb>0)?pDb->zName:0); |
|
ds@1952
|
270 |
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ |
|
ds@1952
|
271 |
goto pragma_out; |
|
ds@1952
|
272 |
} |
|
ds@1952
|
273 |
|
|
ds@1952
|
274 |
#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
|
ds@1952
|
275 |
/* |
|
ds@1952
|
276 |
** PRAGMA [database.]default_cache_size |
|
ds@1952
|
277 |
** PRAGMA [database.]default_cache_size=N |
|
ds@1952
|
278 |
** |
|
ds@1952
|
279 |
** The first form reports the current persistent setting for the |
|
ds@1952
|
280 |
** page cache size. The value returned is the maximum number of |
|
ds@1952
|
281 |
** pages in the page cache. The second form sets both the current |
|
ds@1952
|
282 |
** page cache size value and the persistent page cache size value |
|
ds@1952
|
283 |
** stored in the database file. |
|
ds@1952
|
284 |
** |
|
ds@1952
|
285 |
** The default cache size is stored in meta-value 2 of page 1 of the |
|
ds@1952
|
286 |
** database file. The cache size is actually the absolute value of |
|
ds@1952
|
287 |
** this memory location. The sign of meta-value 2 determines the |
|
ds@1952
|
288 |
** synchronous setting. A negative value means synchronous is off |
|
ds@1952
|
289 |
** and a positive value means synchronous is on. |
|
ds@1952
|
290 |
*/ |
|
ds@1952
|
291 |
if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){ |
|
ds@1952
|
292 |
static const VdbeOpList getCacheSize[] = { |
|
ds@1952
|
293 |
{ OP_ReadCookie, 0, 2, 0}, /* 0 */ |
|
ds@1952
|
294 |
{ OP_AbsValue, 0, 0, 0}, |
|
ds@1952
|
295 |
{ OP_Dup, 0, 0, 0}, |
|
ds@1952
|
296 |
{ OP_Integer, 0, 0, 0}, |
|
ds@1952
|
297 |
{ OP_Ne, 0, 6, 0}, |
|
ds@1952
|
298 |
{ OP_Integer, 0, 0, 0}, /* 5 */ |
|
ds@1952
|
299 |
{ OP_Callback, 1, 0, 0}, |
|
ds@1952
|
300 |
}; |
|
ds@1952
|
301 |
int addr; |
|
ds@1952
|
302 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
303 |
sqlite3VdbeUsesBtree(v, iDb); |
|
ds@1952
|
304 |
if( !zRight ){ |
|
ds@1952
|
305 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
306 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC); |
|
ds@1952
|
307 |
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); |
|
ds@1952
|
308 |
sqlite3VdbeChangeP1(v, addr, iDb); |
|
ds@1952
|
309 |
sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE); |
|
ds@1952
|
310 |
}else{ |
|
ds@1952
|
311 |
int size = atoi(zRight); |
|
ds@1952
|
312 |
if( size<0 ) size = -size; |
|
ds@1952
|
313 |
sqlite3BeginWriteOperation(pParse, 0, iDb); |
|
ds@1952
|
314 |
sqlite3VdbeAddOp(v, OP_Integer, size, 0); |
|
ds@1952
|
315 |
sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 2); |
|
ds@1952
|
316 |
addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0); |
|
ds@1952
|
317 |
sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3); |
|
ds@1952
|
318 |
sqlite3VdbeAddOp(v, OP_Negative, 0, 0); |
|
ds@1952
|
319 |
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2); |
|
ds@1952
|
320 |
pDb->pSchema->cache_size = size; |
|
ds@1952
|
321 |
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
|
ds@1952
|
322 |
} |
|
ds@1952
|
323 |
}else |
|
ds@1952
|
324 |
|
|
ds@1952
|
325 |
/* |
|
ds@1952
|
326 |
** PRAGMA [database.]page_size |
|
ds@1952
|
327 |
** PRAGMA [database.]page_size=N |
|
ds@1952
|
328 |
** |
|
ds@1952
|
329 |
** The first form reports the current setting for the |
|
ds@1952
|
330 |
** database page size in bytes. The second form sets the |
|
ds@1952
|
331 |
** database page size value. The value can only be set if |
|
ds@1952
|
332 |
** the database has not yet been created. |
|
ds@1952
|
333 |
*/ |
|
ds@1952
|
334 |
if( sqlite3StrICmp(zLeft,"page_size")==0 ){ |
|
ds@1952
|
335 |
Btree *pBt = pDb->pBt; |
|
ds@1952
|
336 |
if( !zRight ){ |
|
ds@1952
|
337 |
int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0; |
|
ds@1952
|
338 |
returnSingleInt(pParse, "page_size", size); |
|
ds@1952
|
339 |
}else{ |
|
ds@1952
|
340 |
/* Malloc may fail when setting the page-size, as there is an internal |
|
ds@1952
|
341 |
** buffer that the pager module resizes using sqlite3_realloc(). |
|
ds@1952
|
342 |
*/ |
|
ds@1952
|
343 |
if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, atoi(zRight), -1) ){ |
|
ds@1952
|
344 |
db->mallocFailed = 1; |
|
ds@1952
|
345 |
} |
|
ds@1952
|
346 |
} |
|
ds@1952
|
347 |
}else |
|
ds@1952
|
348 |
|
|
ds@1952
|
349 |
/* |
|
ds@1952
|
350 |
** PRAGMA [database.]max_page_count |
|
ds@1952
|
351 |
** PRAGMA [database.]max_page_count=N |
|
ds@1952
|
352 |
** |
|
ds@1952
|
353 |
** The first form reports the current setting for the |
|
ds@1952
|
354 |
** maximum number of pages in the database file. The |
|
ds@1952
|
355 |
** second form attempts to change this setting. Both |
|
ds@1952
|
356 |
** forms return the current setting. |
|
ds@1952
|
357 |
*/ |
|
ds@1952
|
358 |
if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){ |
|
ds@1952
|
359 |
Btree *pBt = pDb->pBt; |
|
ds@1952
|
360 |
int newMax = 0; |
|
ds@1952
|
361 |
if( zRight ){ |
|
ds@1952
|
362 |
newMax = atoi(zRight); |
|
ds@1952
|
363 |
} |
|
ds@1952
|
364 |
if( pBt ){ |
|
ds@1952
|
365 |
newMax = sqlite3BtreeMaxPageCount(pBt, newMax); |
|
ds@1952
|
366 |
} |
|
ds@1952
|
367 |
returnSingleInt(pParse, "max_page_count", newMax); |
|
ds@1952
|
368 |
}else |
|
ds@1952
|
369 |
|
|
ds@1952
|
370 |
/* |
|
ds@1952
|
371 |
** PRAGMA [database.]locking_mode |
|
ds@1952
|
372 |
** PRAGMA [database.]locking_mode = (normal|exclusive) |
|
ds@1952
|
373 |
*/ |
|
ds@1952
|
374 |
if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){ |
|
ds@1952
|
375 |
const char *zRet = "normal"; |
|
ds@1952
|
376 |
int eMode = getLockingMode(zRight); |
|
ds@1952
|
377 |
|
|
ds@1952
|
378 |
if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){ |
|
ds@1952
|
379 |
/* Simple "PRAGMA locking_mode;" statement. This is a query for |
|
ds@1952
|
380 |
** the current default locking mode (which may be different to |
|
ds@1952
|
381 |
** the locking-mode of the main database). |
|
ds@1952
|
382 |
*/ |
|
ds@1952
|
383 |
eMode = db->dfltLockMode; |
|
ds@1952
|
384 |
}else{ |
|
ds@1952
|
385 |
Pager *pPager; |
|
ds@1952
|
386 |
if( pId2->n==0 ){ |
|
ds@1952
|
387 |
/* This indicates that no database name was specified as part |
|
ds@1952
|
388 |
** of the PRAGMA command. In this case the locking-mode must be |
|
ds@1952
|
389 |
** set on all attached databases, as well as the main db file. |
|
ds@1952
|
390 |
** |
|
ds@1952
|
391 |
** Also, the sqlite3.dfltLockMode variable is set so that |
|
ds@1952
|
392 |
** any subsequently attached databases also use the specified |
|
ds@1952
|
393 |
** locking mode. |
|
ds@1952
|
394 |
*/ |
|
ds@1952
|
395 |
int ii; |
|
ds@1952
|
396 |
assert(pDb==&db->aDb[0]); |
|
ds@1952
|
397 |
for(ii=2; ii<db->nDb; ii++){ |
|
ds@1952
|
398 |
pPager = sqlite3BtreePager(db->aDb[ii].pBt); |
|
ds@1952
|
399 |
sqlite3PagerLockingMode(pPager, eMode); |
|
ds@1952
|
400 |
} |
|
ds@1952
|
401 |
db->dfltLockMode = eMode; |
|
ds@1952
|
402 |
} |
|
ds@1952
|
403 |
pPager = sqlite3BtreePager(pDb->pBt); |
|
ds@1952
|
404 |
eMode = sqlite3PagerLockingMode(pPager, eMode); |
|
ds@1952
|
405 |
} |
|
ds@1952
|
406 |
|
|
ds@1952
|
407 |
assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE); |
|
ds@1952
|
408 |
if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){ |
|
ds@1952
|
409 |
zRet = "exclusive"; |
|
ds@1952
|
410 |
} |
|
ds@1952
|
411 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
412 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P3_STATIC); |
|
ds@1952
|
413 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, zRet, 0); |
|
ds@1952
|
414 |
sqlite3VdbeAddOp(v, OP_Callback, 1, 0); |
|
ds@1952
|
415 |
}else |
|
ds@1952
|
416 |
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
|
ds@1952
|
417 |
|
|
ds@1952
|
418 |
/* |
|
ds@1952
|
419 |
** PRAGMA [database.]auto_vacuum |
|
ds@1952
|
420 |
** PRAGMA [database.]auto_vacuum=N |
|
ds@1952
|
421 |
** |
|
ds@1952
|
422 |
** Get or set the (boolean) value of the database 'auto-vacuum' parameter. |
|
ds@1952
|
423 |
*/ |
|
ds@1952
|
424 |
#ifndef SQLITE_OMIT_AUTOVACUUM |
|
ds@1952
|
425 |
if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){ |
|
ds@1952
|
426 |
Btree *pBt = pDb->pBt; |
|
ds@1952
|
427 |
if( sqlite3ReadSchema(pParse) ){ |
|
ds@1952
|
428 |
goto pragma_out; |
|
ds@1952
|
429 |
} |
|
ds@1952
|
430 |
if( !zRight ){ |
|
ds@1952
|
431 |
int auto_vacuum = |
|
ds@1952
|
432 |
pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM; |
|
ds@1952
|
433 |
returnSingleInt(pParse, "auto_vacuum", auto_vacuum); |
|
ds@1952
|
434 |
}else{ |
|
ds@1952
|
435 |
int eAuto = getAutoVacuum(zRight); |
|
ds@1952
|
436 |
if( eAuto>=0 ){ |
|
ds@1952
|
437 |
/* Call SetAutoVacuum() to set initialize the internal auto and |
|
ds@1952
|
438 |
** incr-vacuum flags. This is required in case this connection |
|
ds@1952
|
439 |
** creates the database file. It is important that it is created |
|
ds@1952
|
440 |
** as an auto-vacuum capable db. |
|
ds@1952
|
441 |
*/ |
|
ds@1952
|
442 |
int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
|
ds@1952
|
443 |
if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
|
ds@1952
|
444 |
/* When setting the auto_vacuum mode to either "full" or |
|
ds@1952
|
445 |
** "incremental", write the value of meta[6] in the database |
|
ds@1952
|
446 |
** file. Before writing to meta[6], check that meta[3] indicates |
|
ds@1952
|
447 |
** that this really is an auto-vacuum capable database. |
|
ds@1952
|
448 |
*/ |
|
ds@1952
|
449 |
static const VdbeOpList setMeta6[] = { |
|
ds@1952
|
450 |
{ OP_Transaction, 0, 1, 0}, /* 0 */ |
|
ds@1952
|
451 |
{ OP_ReadCookie, 0, 3, 0}, /* 1 */ |
|
ds@1952
|
452 |
{ OP_If, 0, 0, 0}, /* 2 */ |
|
ds@1952
|
453 |
{ OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
|
ds@1952
|
454 |
{ OP_Integer, 0, 0, 0}, /* 4 */ |
|
ds@1952
|
455 |
{ OP_SetCookie, 0, 6, 0}, /* 5 */ |
|
ds@1952
|
456 |
}; |
|
ds@1952
|
457 |
int iAddr; |
|
ds@1952
|
458 |
iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); |
|
ds@1952
|
459 |
sqlite3VdbeChangeP1(v, iAddr, iDb); |
|
ds@1952
|
460 |
sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
|
ds@1952
|
461 |
sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
|
ds@1952
|
462 |
sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
|
ds@1952
|
463 |
sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
|
ds@1952
|
464 |
sqlite3VdbeUsesBtree(v, iDb); |
|
ds@1952
|
465 |
} |
|
ds@1952
|
466 |
} |
|
ds@1952
|
467 |
} |
|
ds@1952
|
468 |
}else |
|
ds@1952
|
469 |
#endif |
|
ds@1952
|
470 |
|
|
ds@1952
|
471 |
/* |
|
ds@1952
|
472 |
** PRAGMA [database.]incremental_vacuum(N) |
|
ds@1952
|
473 |
** |
|
ds@1952
|
474 |
** Do N steps of incremental vacuuming on a database. |
|
ds@1952
|
475 |
*/ |
|
ds@1952
|
476 |
#ifndef SQLITE_OMIT_AUTOVACUUM |
|
ds@1952
|
477 |
if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){ |
|
ds@1952
|
478 |
int iLimit, addr; |
|
ds@1952
|
479 |
if( sqlite3ReadSchema(pParse) ){ |
|
ds@1952
|
480 |
goto pragma_out; |
|
ds@1952
|
481 |
} |
|
ds@1952
|
482 |
if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
|
ds@1952
|
483 |
iLimit = 0x7fffffff; |
|
ds@1952
|
484 |
} |
|
ds@1952
|
485 |
sqlite3BeginWriteOperation(pParse, 0, iDb); |
|
ds@1952
|
486 |
sqlite3VdbeAddOp(v, OP_MemInt, iLimit, 0); |
|
ds@1952
|
487 |
addr = sqlite3VdbeAddOp(v, OP_IncrVacuum, iDb, 0); |
|
ds@1952
|
488 |
sqlite3VdbeAddOp(v, OP_Callback, 0, 0); |
|
ds@1952
|
489 |
sqlite3VdbeAddOp(v, OP_MemIncr, -1, 0); |
|
ds@1952
|
490 |
sqlite3VdbeAddOp(v, OP_IfMemPos, 0, addr); |
|
ds@1952
|
491 |
sqlite3VdbeJumpHere(v, addr); |
|
ds@1952
|
492 |
}else |
|
ds@1952
|
493 |
#endif |
|
ds@1952
|
494 |
|
|
ds@1952
|
495 |
#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
|
ds@1952
|
496 |
/* |
|
ds@1952
|
497 |
** PRAGMA [database.]cache_size |
|
ds@1952
|
498 |
** PRAGMA [database.]cache_size=N |
|
ds@1952
|
499 |
** |
|
ds@1952
|
500 |
** The first form reports the current local setting for the |
|
ds@1952
|
501 |
** page cache size. The local setting can be different from |
|
ds@1952
|
502 |
** the persistent cache size value that is stored in the database |
|
ds@1952
|
503 |
** file itself. The value returned is the maximum number of |
|
ds@1952
|
504 |
** pages in the page cache. The second form sets the local |
|
ds@1952
|
505 |
** page cache size value. It does not change the persistent |
|
ds@1952
|
506 |
** cache size stored on the disk so the cache size will revert |
|
ds@1952
|
507 |
** to its default value when the database is closed and reopened. |
|
ds@1952
|
508 |
** N should be a positive integer. |
|
ds@1952
|
509 |
*/ |
|
ds@1952
|
510 |
if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ |
|
ds@1952
|
511 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
512 |
if( !zRight ){ |
|
ds@1952
|
513 |
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
|
ds@1952
|
514 |
}else{ |
|
ds@1952
|
515 |
int size = atoi(zRight); |
|
ds@1952
|
516 |
if( size<0 ) size = -size; |
|
ds@1952
|
517 |
pDb->pSchema->cache_size = size; |
|
ds@1952
|
518 |
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
|
ds@1952
|
519 |
} |
|
ds@1952
|
520 |
}else |
|
ds@1952
|
521 |
|
|
ds@1952
|
522 |
/* |
|
ds@1952
|
523 |
** PRAGMA temp_store |
|
ds@1952
|
524 |
** PRAGMA temp_store = "default"|"memory"|"file" |
|
ds@1952
|
525 |
** |
|
ds@1952
|
526 |
** Return or set the local value of the temp_store flag. Changing |
|
ds@1952
|
527 |
** the local value does not make changes to the disk file and the default |
|
ds@1952
|
528 |
** value will be restored the next time the database is opened. |
|
ds@1952
|
529 |
** |
|
ds@1952
|
530 |
** Note that it is possible for the library compile-time options to |
|
ds@1952
|
531 |
** override this setting |
|
ds@1952
|
532 |
*/ |
|
ds@1952
|
533 |
if( sqlite3StrICmp(zLeft, "temp_store")==0 ){ |
|
ds@1952
|
534 |
if( !zRight ){ |
|
ds@1952
|
535 |
returnSingleInt(pParse, "temp_store", db->temp_store); |
|
ds@1952
|
536 |
}else{ |
|
ds@1952
|
537 |
changeTempStorage(pParse, zRight); |
|
ds@1952
|
538 |
} |
|
ds@1952
|
539 |
}else |
|
ds@1952
|
540 |
|
|
ds@1952
|
541 |
/* |
|
ds@1952
|
542 |
** PRAGMA temp_store_directory |
|
ds@1952
|
543 |
** PRAGMA temp_store_directory = ""|"directory_name" |
|
ds@1952
|
544 |
** |
|
ds@1952
|
545 |
** Return or set the local value of the temp_store_directory flag. Changing |
|
ds@1952
|
546 |
** the value sets a specific directory to be used for temporary files. |
|
ds@1952
|
547 |
** Setting to a null string reverts to the default temporary directory search. |
|
ds@1952
|
548 |
** If temporary directory is changed, then invalidateTempStorage. |
|
ds@1952
|
549 |
** |
|
ds@1952
|
550 |
*/ |
|
ds@1952
|
551 |
if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){ |
|
ds@1952
|
552 |
if( !zRight ){ |
|
ds@1952
|
553 |
if( sqlite3_temp_directory ){ |
|
ds@1952
|
554 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
555 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
|
ds@1952
|
556 |
"temp_store_directory", P3_STATIC); |
|
ds@1952
|
557 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0); |
|
ds@1952
|
558 |
sqlite3VdbeAddOp(v, OP_Callback, 1, 0); |
|
ds@1952
|
559 |
} |
|
ds@1952
|
560 |
}else{ |
|
ds@1952
|
561 |
if( zRight[0] |
|
ds@1952
|
562 |
&& !sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE) |
|
ds@1952
|
563 |
){ |
|
ds@1952
|
564 |
sqlite3ErrorMsg(pParse, "not a writable directory"); |
|
ds@1952
|
565 |
goto pragma_out; |
|
ds@1952
|
566 |
} |
|
ds@1952
|
567 |
if( TEMP_STORE==0 |
|
ds@1952
|
568 |
|| (TEMP_STORE==1 && db->temp_store<=1) |
|
ds@1952
|
569 |
|| (TEMP_STORE==2 && db->temp_store==1) |
|
ds@1952
|
570 |
){ |
|
ds@1952
|
571 |
invalidateTempStorage(pParse); |
|
ds@1952
|
572 |
} |
|
ds@1952
|
573 |
sqlite3_free(sqlite3_temp_directory); |
|
ds@1952
|
574 |
if( zRight[0] ){ |
|
ds@1952
|
575 |
sqlite3_temp_directory = zRight; |
|
ds@1952
|
576 |
zRight = 0; |
|
ds@1952
|
577 |
}else{ |
|
ds@1952
|
578 |
sqlite3_temp_directory = 0; |
|
ds@1952
|
579 |
} |
|
ds@1952
|
580 |
} |
|
ds@1952
|
581 |
}else |
|
ds@1952
|
582 |
|
|
ds@1952
|
583 |
/* |
|
ds@1952
|
584 |
** PRAGMA [database.]synchronous |
|
ds@1952
|
585 |
** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL |
|
ds@1952
|
586 |
** |
|
ds@1952
|
587 |
** Return or set the local value of the synchronous flag. Changing |
|
ds@1952
|
588 |
** the local value does not make changes to the disk file and the |
|
ds@1952
|
589 |
** default value will be restored the next time the database is |
|
ds@1952
|
590 |
** opened. |
|
ds@1952
|
591 |
*/ |
|
ds@1952
|
592 |
if( sqlite3StrICmp(zLeft,"synchronous")==0 ){ |
|
ds@1952
|
593 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
594 |
if( !zRight ){ |
|
ds@1952
|
595 |
returnSingleInt(pParse, "synchronous", pDb->safety_level-1); |
|
ds@1952
|
596 |
}else{ |
|
ds@1952
|
597 |
if( !db->autoCommit ){ |
|
ds@1952
|
598 |
sqlite3ErrorMsg(pParse, |
|
ds@1952
|
599 |
"Safety level may not be changed inside a transaction"); |
|
ds@1952
|
600 |
}else{ |
|
ds@1952
|
601 |
pDb->safety_level = getSafetyLevel(zRight)+1; |
|
ds@1952
|
602 |
} |
|
ds@1952
|
603 |
} |
|
ds@1952
|
604 |
}else |
|
ds@1952
|
605 |
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
|
ds@1952
|
606 |
|
|
ds@1952
|
607 |
#ifndef SQLITE_OMIT_FLAG_PRAGMAS |
|
ds@1952
|
608 |
if( flagPragma(pParse, zLeft, zRight) ){ |
|
ds@1952
|
609 |
/* The flagPragma() subroutine also generates any necessary code |
|
ds@1952
|
610 |
** there is nothing more to do here */ |
|
ds@1952
|
611 |
}else |
|
ds@1952
|
612 |
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
|
ds@1952
|
613 |
|
|
ds@1952
|
614 |
#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS |
|
ds@1952
|
615 |
/* |
|
ds@1952
|
616 |
** PRAGMA table_info(<table>) |
|
ds@1952
|
617 |
** |
|
ds@1952
|
618 |
** Return a single row for each column of the named table. The columns of |
|
ds@1952
|
619 |
** the returned data set are: |
|
ds@1952
|
620 |
** |
|
ds@1952
|
621 |
** cid: Column id (numbered from left to right, starting at 0) |
|
ds@1952
|
622 |
** name: Column name |
|
ds@1952
|
623 |
** type: Column declaration type. |
|
ds@1952
|
624 |
** notnull: True if 'NOT NULL' is part of column declaration |
|
ds@1952
|
625 |
** dflt_value: The default value for the column, if any. |
|
ds@1952
|
626 |
*/ |
|
ds@1952
|
627 |
if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){ |
|
ds@1952
|
628 |
Table *pTab; |
|
ds@1952
|
629 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
630 |
pTab = sqlite3FindTable(db, zRight, zDb); |
|
ds@1952
|
631 |
if( pTab ){ |
|
ds@1952
|
632 |
int i; |
|
ds@1952
|
633 |
int nHidden = 0; |
|
ds@1952
|
634 |
Column *pCol; |
|
ds@1952
|
635 |
sqlite3VdbeSetNumCols(v, 6); |
|
ds@1952
|
636 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC); |
|
ds@1952
|
637 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC); |
|
ds@1952
|
638 |
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC); |
|
ds@1952
|
639 |
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC); |
|
ds@1952
|
640 |
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC); |
|
ds@1952
|
641 |
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC); |
|
ds@1952
|
642 |
sqlite3ViewGetColumnNames(pParse, pTab); |
|
ds@1952
|
643 |
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
|
ds@1952
|
644 |
const Token *pDflt; |
|
ds@1952
|
645 |
if( IsHiddenColumn(pCol) ){ |
|
ds@1952
|
646 |
nHidden++; |
|
ds@1952
|
647 |
continue; |
|
ds@1952
|
648 |
} |
|
ds@1952
|
649 |
sqlite3VdbeAddOp(v, OP_Integer, i-nHidden, 0); |
|
ds@1952
|
650 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0); |
|
ds@1952
|
651 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, |
|
ds@1952
|
652 |
pCol->zType ? pCol->zType : "", 0); |
|
ds@1952
|
653 |
sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0); |
|
ds@1952
|
654 |
if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){ |
|
ds@1952
|
655 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n); |
|
ds@1952
|
656 |
}else{ |
|
ds@1952
|
657 |
sqlite3VdbeAddOp(v, OP_Null, 0, 0); |
|
ds@1952
|
658 |
} |
|
ds@1952
|
659 |
sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0); |
|
ds@1952
|
660 |
sqlite3VdbeAddOp(v, OP_Callback, 6, 0); |
|
ds@1952
|
661 |
} |
|
ds@1952
|
662 |
} |
|
ds@1952
|
663 |
}else |
|
ds@1952
|
664 |
|
|
ds@1952
|
665 |
if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){ |
|
ds@1952
|
666 |
Index *pIdx; |
|
ds@1952
|
667 |
Table *pTab; |
|
ds@1952
|
668 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
669 |
pIdx = sqlite3FindIndex(db, zRight, zDb); |
|
ds@1952
|
670 |
if( pIdx ){ |
|
ds@1952
|
671 |
int i; |
|
ds@1952
|
672 |
pTab = pIdx->pTable; |
|
ds@1952
|
673 |
sqlite3VdbeSetNumCols(v, 3); |
|
ds@1952
|
674 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC); |
|
ds@1952
|
675 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC); |
|
ds@1952
|
676 |
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC); |
|
ds@1952
|
677 |
for(i=0; i<pIdx->nColumn; i++){ |
|
ds@1952
|
678 |
int cnum = pIdx->aiColumn[i]; |
|
ds@1952
|
679 |
sqlite3VdbeAddOp(v, OP_Integer, i, 0); |
|
ds@1952
|
680 |
sqlite3VdbeAddOp(v, OP_Integer, cnum, 0); |
|
ds@1952
|
681 |
assert( pTab->nCol>cnum ); |
|
ds@1952
|
682 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0); |
|
ds@1952
|
683 |
sqlite3VdbeAddOp(v, OP_Callback, 3, 0); |
|
ds@1952
|
684 |
} |
|
ds@1952
|
685 |
} |
|
ds@1952
|
686 |
}else |
|
ds@1952
|
687 |
|
|
ds@1952
|
688 |
if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){ |
|
ds@1952
|
689 |
Index *pIdx; |
|
ds@1952
|
690 |
Table *pTab; |
|
ds@1952
|
691 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
692 |
pTab = sqlite3FindTable(db, zRight, zDb); |
|
ds@1952
|
693 |
if( pTab ){ |
|
ds@1952
|
694 |
v = sqlite3GetVdbe(pParse); |
|
ds@1952
|
695 |
pIdx = pTab->pIndex; |
|
ds@1952
|
696 |
if( pIdx ){ |
|
ds@1952
|
697 |
int i = 0; |
|
ds@1952
|
698 |
sqlite3VdbeSetNumCols(v, 3); |
|
ds@1952
|
699 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC); |
|
ds@1952
|
700 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC); |
|
ds@1952
|
701 |
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC); |
|
ds@1952
|
702 |
while(pIdx){ |
|
ds@1952
|
703 |
sqlite3VdbeAddOp(v, OP_Integer, i, 0); |
|
ds@1952
|
704 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0); |
|
ds@1952
|
705 |
sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0); |
|
ds@1952
|
706 |
sqlite3VdbeAddOp(v, OP_Callback, 3, 0); |
|
ds@1952
|
707 |
++i; |
|
ds@1952
|
708 |
pIdx = pIdx->pNext; |
|
ds@1952
|
709 |
} |
|
ds@1952
|
710 |
} |
|
ds@1952
|
711 |
} |
|
ds@1952
|
712 |
}else |
|
ds@1952
|
713 |
|
|
ds@1952
|
714 |
if( sqlite3StrICmp(zLeft, "database_list")==0 ){ |
|
ds@1952
|
715 |
int i; |
|
ds@1952
|
716 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
717 |
sqlite3VdbeSetNumCols(v, 3); |
|
ds@1952
|
718 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC); |
|
ds@1952
|
719 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC); |
|
ds@1952
|
720 |
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC); |
|
ds@1952
|
721 |
for(i=0; i<db->nDb; i++){ |
|
ds@1952
|
722 |
if( db->aDb[i].pBt==0 ) continue; |
|
ds@1952
|
723 |
assert( db->aDb[i].zName!=0 ); |
|
ds@1952
|
724 |
sqlite3VdbeAddOp(v, OP_Integer, i, 0); |
|
ds@1952
|
725 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0); |
|
ds@1952
|
726 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, |
|
ds@1952
|
727 |
sqlite3BtreeGetFilename(db->aDb[i].pBt), 0); |
|
ds@1952
|
728 |
sqlite3VdbeAddOp(v, OP_Callback, 3, 0); |
|
ds@1952
|
729 |
} |
|
ds@1952
|
730 |
}else |
|
ds@1952
|
731 |
|
|
ds@1952
|
732 |
if( sqlite3StrICmp(zLeft, "collation_list")==0 ){ |
|
ds@1952
|
733 |
int i = 0; |
|
ds@1952
|
734 |
HashElem *p; |
|
ds@1952
|
735 |
sqlite3VdbeSetNumCols(v, 2); |
|
ds@1952
|
736 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC); |
|
ds@1952
|
737 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC); |
|
ds@1952
|
738 |
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){ |
|
ds@1952
|
739 |
CollSeq *pColl = (CollSeq *)sqliteHashData(p); |
|
ds@1952
|
740 |
sqlite3VdbeAddOp(v, OP_Integer, i++, 0); |
|
ds@1952
|
741 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0); |
|
ds@1952
|
742 |
sqlite3VdbeAddOp(v, OP_Callback, 2, 0); |
|
ds@1952
|
743 |
} |
|
ds@1952
|
744 |
}else |
|
ds@1952
|
745 |
#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ |
|
ds@1952
|
746 |
|
|
ds@1952
|
747 |
#ifndef SQLITE_OMIT_FOREIGN_KEY |
|
ds@1952
|
748 |
if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){ |
|
ds@1952
|
749 |
FKey *pFK; |
|
ds@1952
|
750 |
Table *pTab; |
|
ds@1952
|
751 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
752 |
pTab = sqlite3FindTable(db, zRight, zDb); |
|
ds@1952
|
753 |
if( pTab ){ |
|
ds@1952
|
754 |
v = sqlite3GetVdbe(pParse); |
|
ds@1952
|
755 |
pFK = pTab->pFKey; |
|
ds@1952
|
756 |
if( pFK ){ |
|
ds@1952
|
757 |
int i = 0; |
|
ds@1952
|
758 |
sqlite3VdbeSetNumCols(v, 5); |
|
ds@1952
|
759 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC); |
|
ds@1952
|
760 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC); |
|
ds@1952
|
761 |
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC); |
|
ds@1952
|
762 |
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC); |
|
ds@1952
|
763 |
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC); |
|
ds@1952
|
764 |
while(pFK){ |
|
ds@1952
|
765 |
int j; |
|
ds@1952
|
766 |
for(j=0; j<pFK->nCol; j++){ |
|
ds@1952
|
767 |
char *zCol = pFK->aCol[j].zCol; |
|
ds@1952
|
768 |
sqlite3VdbeAddOp(v, OP_Integer, i, 0); |
|
ds@1952
|
769 |
sqlite3VdbeAddOp(v, OP_Integer, j, 0); |
|
ds@1952
|
770 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0); |
|
ds@1952
|
771 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, |
|
ds@1952
|
772 |
pTab->aCol[pFK->aCol[j].iFrom].zName, 0); |
|
ds@1952
|
773 |
sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0); |
|
ds@1952
|
774 |
sqlite3VdbeAddOp(v, OP_Callback, 5, 0); |
|
ds@1952
|
775 |
} |
|
ds@1952
|
776 |
++i; |
|
ds@1952
|
777 |
pFK = pFK->pNextFrom; |
|
ds@1952
|
778 |
} |
|
ds@1952
|
779 |
} |
|
ds@1952
|
780 |
} |
|
ds@1952
|
781 |
}else |
|
ds@1952
|
782 |
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
|
ds@1952
|
783 |
|
|
ds@1952
|
784 |
#ifndef NDEBUG |
|
ds@1952
|
785 |
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ |
|
ds@1952
|
786 |
if( zRight ){ |
|
ds@1952
|
787 |
if( getBoolean(zRight) ){ |
|
ds@1952
|
788 |
sqlite3ParserTrace(stderr, "parser: "); |
|
ds@1952
|
789 |
}else{ |
|
ds@1952
|
790 |
sqlite3ParserTrace(0, 0); |
|
ds@1952
|
791 |
} |
|
ds@1952
|
792 |
} |
|
ds@1952
|
793 |
}else |
|
ds@1952
|
794 |
#endif |
|
ds@1952
|
795 |
|
|
ds@1952
|
796 |
/* Reinstall the LIKE and GLOB functions. The variant of LIKE |
|
ds@1952
|
797 |
** used will be case sensitive or not depending on the RHS. |
|
ds@1952
|
798 |
*/ |
|
ds@1952
|
799 |
if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ |
|
ds@1952
|
800 |
if( zRight ){ |
|
ds@1952
|
801 |
sqlite3RegisterLikeFunctions(db, getBoolean(zRight)); |
|
ds@1952
|
802 |
} |
|
ds@1952
|
803 |
}else |
|
ds@1952
|
804 |
|
|
ds@1952
|
805 |
#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
|
ds@1952
|
806 |
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
|
ds@1952
|
807 |
#endif |
|
ds@1952
|
808 |
|
|
ds@1952
|
809 |
#ifndef SQLITE_OMIT_INTEGRITY_CHECK |
|
ds@1952
|
810 |
if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){ |
|
ds@1952
|
811 |
int i, j, addr, mxErr; |
|
ds@1952
|
812 |
|
|
ds@1952
|
813 |
/* Code that appears at the end of the integrity check. If no error |
|
ds@1952
|
814 |
** messages have been generated, output OK. Otherwise output the |
|
ds@1952
|
815 |
** error message |
|
ds@1952
|
816 |
*/ |
|
ds@1952
|
817 |
static const VdbeOpList endCode[] = { |
|
ds@1952
|
818 |
{ OP_MemLoad, 0, 0, 0}, |
|
ds@1952
|
819 |
{ OP_Integer, 0, 0, 0}, |
|
ds@1952
|
820 |
{ OP_Ne, 0, 0, 0}, /* 2 */ |
|
ds@1952
|
821 |
{ OP_String8, 0, 0, "ok"}, |
|
ds@1952
|
822 |
{ OP_Callback, 1, 0, 0}, |
|
ds@1952
|
823 |
}; |
|
ds@1952
|
824 |
|
|
ds@1952
|
825 |
/* Initialize the VDBE program */ |
|
ds@1952
|
826 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
827 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
828 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P3_STATIC); |
|
ds@1952
|
829 |
|
|
ds@1952
|
830 |
/* Set the maximum error count */ |
|
ds@1952
|
831 |
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
|
ds@1952
|
832 |
if( zRight ){ |
|
ds@1952
|
833 |
mxErr = atoi(zRight); |
|
ds@1952
|
834 |
if( mxErr<=0 ){ |
|
ds@1952
|
835 |
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
|
ds@1952
|
836 |
} |
|
ds@1952
|
837 |
} |
|
ds@1952
|
838 |
sqlite3VdbeAddOp(v, OP_MemInt, mxErr, 0); |
|
ds@1952
|
839 |
|
|
ds@1952
|
840 |
/* Do an integrity check on each database file */ |
|
ds@1952
|
841 |
for(i=0; i<db->nDb; i++){ |
|
ds@1952
|
842 |
HashElem *x; |
|
ds@1952
|
843 |
Hash *pTbls; |
|
ds@1952
|
844 |
int cnt = 0; |
|
ds@1952
|
845 |
|
|
ds@1952
|
846 |
if( OMIT_TEMPDB && i==1 ) continue; |
|
ds@1952
|
847 |
|
|
ds@1952
|
848 |
sqlite3CodeVerifySchema(pParse, i); |
|
ds@1952
|
849 |
addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0); |
|
ds@1952
|
850 |
sqlite3VdbeAddOp(v, OP_Halt, 0, 0); |
|
ds@1952
|
851 |
sqlite3VdbeJumpHere(v, addr); |
|
ds@1952
|
852 |
|
|
ds@1952
|
853 |
/* Do an integrity check of the B-Tree |
|
ds@1952
|
854 |
*/ |
|
ds@1952
|
855 |
pTbls = &db->aDb[i].pSchema->tblHash; |
|
ds@1952
|
856 |
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
|
ds@1952
|
857 |
Table *pTab = sqliteHashData(x); |
|
ds@1952
|
858 |
Index *pIdx; |
|
ds@1952
|
859 |
sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0); |
|
ds@1952
|
860 |
cnt++; |
|
ds@1952
|
861 |
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
|
ds@1952
|
862 |
sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0); |
|
ds@1952
|
863 |
cnt++; |
|
ds@1952
|
864 |
} |
|
ds@1952
|
865 |
} |
|
ds@1952
|
866 |
if( cnt==0 ) continue; |
|
ds@1952
|
867 |
sqlite3VdbeAddOp(v, OP_IntegrityCk, 0, i); |
|
ds@1952
|
868 |
addr = sqlite3VdbeAddOp(v, OP_IsNull, -1, 0); |
|
ds@1952
|
869 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, |
|
ds@1952
|
870 |
sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), |
|
ds@1952
|
871 |
P3_DYNAMIC); |
|
ds@1952
|
872 |
sqlite3VdbeAddOp(v, OP_Pull, 1, 0); |
|
ds@1952
|
873 |
sqlite3VdbeAddOp(v, OP_Concat, 0, 0); |
|
ds@1952
|
874 |
sqlite3VdbeAddOp(v, OP_Callback, 1, 0); |
|
ds@1952
|
875 |
sqlite3VdbeJumpHere(v, addr); |
|
ds@1952
|
876 |
|
|
ds@1952
|
877 |
/* Make sure all the indices are constructed correctly. |
|
ds@1952
|
878 |
*/ |
|
ds@1952
|
879 |
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
|
ds@1952
|
880 |
Table *pTab = sqliteHashData(x); |
|
ds@1952
|
881 |
Index *pIdx; |
|
ds@1952
|
882 |
int loopTop; |
|
ds@1952
|
883 |
|
|
ds@1952
|
884 |
if( pTab->pIndex==0 ) continue; |
|
ds@1952
|
885 |
addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0); |
|
ds@1952
|
886 |
sqlite3VdbeAddOp(v, OP_Halt, 0, 0); |
|
ds@1952
|
887 |
sqlite3VdbeJumpHere(v, addr); |
|
ds@1952
|
888 |
sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead); |
|
ds@1952
|
889 |
sqlite3VdbeAddOp(v, OP_MemInt, 0, 1); |
|
ds@1952
|
890 |
loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0); |
|
ds@1952
|
891 |
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1); |
|
ds@1952
|
892 |
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
|
ds@1952
|
893 |
int jmp2; |
|
ds@1952
|
894 |
static const VdbeOpList idxErr[] = { |
|
ds@1952
|
895 |
{ OP_MemIncr, -1, 0, 0}, |
|
ds@1952
|
896 |
{ OP_String8, 0, 0, "rowid "}, |
|
ds@1952
|
897 |
{ OP_Rowid, 1, 0, 0}, |
|
ds@1952
|
898 |
{ OP_String8, 0, 0, " missing from index "}, |
|
ds@1952
|
899 |
{ OP_String8, 0, 0, 0}, /* 4 */ |
|
ds@1952
|
900 |
{ OP_Concat, 2, 0, 0}, |
|
ds@1952
|
901 |
{ OP_Callback, 1, 0, 0}, |
|
ds@1952
|
902 |
}; |
|
ds@1952
|
903 |
sqlite3GenerateIndexKey(v, pIdx, 1); |
|
ds@1952
|
904 |
jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0); |
|
ds@1952
|
905 |
addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr); |
|
ds@1952
|
906 |
sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC); |
|
ds@1952
|
907 |
sqlite3VdbeJumpHere(v, jmp2); |
|
ds@1952
|
908 |
} |
|
ds@1952
|
909 |
sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1); |
|
ds@1952
|
910 |
sqlite3VdbeJumpHere(v, loopTop); |
|
ds@1952
|
911 |
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
|
ds@1952
|
912 |
static const VdbeOpList cntIdx[] = { |
|
ds@1952
|
913 |
{ OP_MemInt, 0, 2, 0}, |
|
ds@1952
|
914 |
{ OP_Rewind, 0, 0, 0}, /* 1 */ |
|
ds@1952
|
915 |
{ OP_MemIncr, 1, 2, 0}, |
|
ds@1952
|
916 |
{ OP_Next, 0, 0, 0}, /* 3 */ |
|
ds@1952
|
917 |
{ OP_MemLoad, 1, 0, 0}, |
|
ds@1952
|
918 |
{ OP_MemLoad, 2, 0, 0}, |
|
ds@1952
|
919 |
{ OP_Eq, 0, 0, 0}, /* 6 */ |
|
ds@1952
|
920 |
{ OP_MemIncr, -1, 0, 0}, |
|
ds@1952
|
921 |
{ OP_String8, 0, 0, "wrong # of entries in index "}, |
|
ds@1952
|
922 |
{ OP_String8, 0, 0, 0}, /* 9 */ |
|
ds@1952
|
923 |
{ OP_Concat, 0, 0, 0}, |
|
ds@1952
|
924 |
{ OP_Callback, 1, 0, 0}, |
|
ds@1952
|
925 |
}; |
|
ds@1952
|
926 |
if( pIdx->tnum==0 ) continue; |
|
ds@1952
|
927 |
addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0); |
|
ds@1952
|
928 |
sqlite3VdbeAddOp(v, OP_Halt, 0, 0); |
|
ds@1952
|
929 |
sqlite3VdbeJumpHere(v, addr); |
|
ds@1952
|
930 |
addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx); |
|
ds@1952
|
931 |
sqlite3VdbeChangeP1(v, addr+1, j+2); |
|
ds@1952
|
932 |
sqlite3VdbeChangeP2(v, addr+1, addr+4); |
|
ds@1952
|
933 |
sqlite3VdbeChangeP1(v, addr+3, j+2); |
|
ds@1952
|
934 |
sqlite3VdbeChangeP2(v, addr+3, addr+2); |
|
ds@1952
|
935 |
sqlite3VdbeJumpHere(v, addr+6); |
|
ds@1952
|
936 |
sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC); |
|
ds@1952
|
937 |
} |
|
ds@1952
|
938 |
} |
|
ds@1952
|
939 |
} |
|
ds@1952
|
940 |
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); |
|
ds@1952
|
941 |
sqlite3VdbeChangeP1(v, addr+1, mxErr); |
|
ds@1952
|
942 |
sqlite3VdbeJumpHere(v, addr+2); |
|
ds@1952
|
943 |
}else |
|
ds@1952
|
944 |
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
|
ds@1952
|
945 |
|
|
ds@1952
|
946 |
#ifndef SQLITE_OMIT_UTF16 |
|
ds@1952
|
947 |
/* |
|
ds@1952
|
948 |
** PRAGMA encoding |
|
ds@1952
|
949 |
** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" |
|
ds@1952
|
950 |
** |
|
ds@1952
|
951 |
** In it's first form, this pragma returns the encoding of the main |
|
ds@1952
|
952 |
** database. If the database is not initialized, it is initialized now. |
|
ds@1952
|
953 |
** |
|
ds@1952
|
954 |
** The second form of this pragma is a no-op if the main database file |
|
ds@1952
|
955 |
** has not already been initialized. In this case it sets the default |
|
ds@1952
|
956 |
** encoding that will be used for the main database file if a new file |
|
ds@1952
|
957 |
** is created. If an existing main database file is opened, then the |
|
ds@1952
|
958 |
** default text encoding for the existing database is used. |
|
ds@1952
|
959 |
** |
|
ds@1952
|
960 |
** In all cases new databases created using the ATTACH command are |
|
ds@1952
|
961 |
** created to use the same default text encoding as the main database. If |
|
ds@1952
|
962 |
** the main database has not been initialized and/or created when ATTACH |
|
ds@1952
|
963 |
** is executed, this is done before the ATTACH operation. |
|
ds@1952
|
964 |
** |
|
ds@1952
|
965 |
** In the second form this pragma sets the text encoding to be used in |
|
ds@1952
|
966 |
** new database files created using this database handle. It is only |
|
ds@1952
|
967 |
** useful if invoked immediately after the main database i |
|
ds@1952
|
968 |
*/ |
|
ds@1952
|
969 |
if( sqlite3StrICmp(zLeft, "encoding")==0 ){ |
|
ds@1952
|
970 |
static const struct EncName { |
|
ds@1952
|
971 |
char *zName; |
|
ds@1952
|
972 |
u8 enc; |
|
ds@1952
|
973 |
} encnames[] = { |
|
ds@1952
|
974 |
{ "UTF-8", SQLITE_UTF8 }, |
|
ds@1952
|
975 |
{ "UTF8", SQLITE_UTF8 }, |
|
ds@1952
|
976 |
{ "UTF-16le", SQLITE_UTF16LE }, |
|
ds@1952
|
977 |
{ "UTF16le", SQLITE_UTF16LE }, |
|
ds@1952
|
978 |
{ "UTF-16be", SQLITE_UTF16BE }, |
|
ds@1952
|
979 |
{ "UTF16be", SQLITE_UTF16BE }, |
|
ds@1952
|
980 |
{ "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */ |
|
ds@1952
|
981 |
{ "UTF16", 0 }, /* SQLITE_UTF16NATIVE */ |
|
ds@1952
|
982 |
{ 0, 0 } |
|
ds@1952
|
983 |
}; |
|
ds@1952
|
984 |
const struct EncName *pEnc; |
|
ds@1952
|
985 |
if( !zRight ){ /* "PRAGMA encoding" */ |
|
ds@1952
|
986 |
if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
|
ds@1952
|
987 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
988 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC); |
|
ds@1952
|
989 |
sqlite3VdbeAddOp(v, OP_String8, 0, 0); |
|
ds@1952
|
990 |
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
|
ds@1952
|
991 |
if( pEnc->enc==ENC(pParse->db) ){ |
|
ds@1952
|
992 |
sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC); |
|
ds@1952
|
993 |
break; |
|
ds@1952
|
994 |
} |
|
ds@1952
|
995 |
} |
|
ds@1952
|
996 |
sqlite3VdbeAddOp(v, OP_Callback, 1, 0); |
|
ds@1952
|
997 |
}else{ /* "PRAGMA encoding = XXX" */ |
|
ds@1952
|
998 |
/* Only change the value of sqlite.enc if the database handle is not |
|
ds@1952
|
999 |
** initialized. If the main database exists, the new sqlite.enc value |
|
ds@1952
|
1000 |
** will be overwritten when the schema is next loaded. If it does not |
|
ds@1952
|
1001 |
** already exists, it will be created to use the new encoding value. |
|
ds@1952
|
1002 |
*/ |
|
ds@1952
|
1003 |
if( |
|
ds@1952
|
1004 |
!(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
|
ds@1952
|
1005 |
DbHasProperty(db, 0, DB_Empty) |
|
ds@1952
|
1006 |
){ |
|
ds@1952
|
1007 |
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
|
ds@1952
|
1008 |
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
|
ds@1952
|
1009 |
ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
|
ds@1952
|
1010 |
break; |
|
ds@1952
|
1011 |
} |
|
ds@1952
|
1012 |
} |
|
ds@1952
|
1013 |
if( !pEnc->zName ){ |
|
ds@1952
|
1014 |
sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
|
ds@1952
|
1015 |
} |
|
ds@1952
|
1016 |
} |
|
ds@1952
|
1017 |
} |
|
ds@1952
|
1018 |
}else |
|
ds@1952
|
1019 |
#endif /* SQLITE_OMIT_UTF16 */ |
|
ds@1952
|
1020 |
|
|
ds@1952
|
1021 |
#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
|
ds@1952
|
1022 |
/* |
|
ds@1952
|
1023 |
** PRAGMA [database.]schema_version |
|
ds@1952
|
1024 |
** PRAGMA [database.]schema_version = <integer> |
|
ds@1952
|
1025 |
** |
|
ds@1952
|
1026 |
** PRAGMA [database.]user_version |
|
ds@1952
|
1027 |
** PRAGMA [database.]user_version = <integer> |
|
ds@1952
|
1028 |
** |
|
ds@1952
|
1029 |
** The pragma's schema_version and user_version are used to set or get |
|
ds@1952
|
1030 |
** the value of the schema-version and user-version, respectively. Both |
|
ds@1952
|
1031 |
** the schema-version and the user-version are 32-bit signed integers |
|
ds@1952
|
1032 |
** stored in the database header. |
|
ds@1952
|
1033 |
** |
|
ds@1952
|
1034 |
** The schema-cookie is usually only manipulated internally by SQLite. It |
|
ds@1952
|
1035 |
** is incremented by SQLite whenever the database schema is modified (by |
|
ds@1952
|
1036 |
** creating or dropping a table or index). The schema version is used by |
|
ds@1952
|
1037 |
** SQLite each time a query is executed to ensure that the internal cache |
|
ds@1952
|
1038 |
** of the schema used when compiling the SQL query matches the schema of |
|
ds@1952
|
1039 |
** the database against which the compiled query is actually executed. |
|
ds@1952
|
1040 |
** Subverting this mechanism by using "PRAGMA schema_version" to modify |
|
ds@1952
|
1041 |
** the schema-version is potentially dangerous and may lead to program |
|
ds@1952
|
1042 |
** crashes or database corruption. Use with caution! |
|
ds@1952
|
1043 |
** |
|
ds@1952
|
1044 |
** The user-version is not used internally by SQLite. It may be used by |
|
ds@1952
|
1045 |
** applications for any purpose. |
|
ds@1952
|
1046 |
*/ |
|
ds@1952
|
1047 |
if( sqlite3StrICmp(zLeft, "schema_version")==0 |
|
ds@1952
|
1048 |
|| sqlite3StrICmp(zLeft, "user_version")==0 |
|
ds@1952
|
1049 |
|| sqlite3StrICmp(zLeft, "freelist_count")==0 |
|
ds@1952
|
1050 |
){ |
|
ds@1952
|
1051 |
|
|
ds@1952
|
1052 |
int iCookie; /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */ |
|
ds@1952
|
1053 |
sqlite3VdbeUsesBtree(v, iDb); |
|
ds@1952
|
1054 |
switch( zLeft[0] ){ |
|
ds@1952
|
1055 |
case 's': case 'S': |
|
ds@1952
|
1056 |
iCookie = 0; |
|
ds@1952
|
1057 |
break; |
|
ds@1952
|
1058 |
case 'f': case 'F': |
|
ds@1952
|
1059 |
iCookie = 1; |
|
ds@1952
|
1060 |
iDb = (-1*(iDb+1)); |
|
ds@1952
|
1061 |
assert(iDb<=0); |
|
ds@1952
|
1062 |
break; |
|
ds@1952
|
1063 |
default: |
|
ds@1952
|
1064 |
iCookie = 5; |
|
ds@1952
|
1065 |
break; |
|
ds@1952
|
1066 |
} |
|
ds@1952
|
1067 |
|
|
ds@1952
|
1068 |
if( zRight && iDb>=0 ){ |
|
ds@1952
|
1069 |
/* Write the specified cookie value */ |
|
ds@1952
|
1070 |
static const VdbeOpList setCookie[] = { |
|
ds@1952
|
1071 |
{ OP_Transaction, 0, 1, 0}, /* 0 */ |
|
ds@1952
|
1072 |
{ OP_Integer, 0, 0, 0}, /* 1 */ |
|
ds@1952
|
1073 |
{ OP_SetCookie, 0, 0, 0}, /* 2 */ |
|
ds@1952
|
1074 |
}; |
|
ds@1952
|
1075 |
int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie); |
|
ds@1952
|
1076 |
sqlite3VdbeChangeP1(v, addr, iDb); |
|
ds@1952
|
1077 |
sqlite3VdbeChangeP1(v, addr+1, atoi(zRight)); |
|
ds@1952
|
1078 |
sqlite3VdbeChangeP1(v, addr+2, iDb); |
|
ds@1952
|
1079 |
sqlite3VdbeChangeP2(v, addr+2, iCookie); |
|
ds@1952
|
1080 |
}else{ |
|
ds@1952
|
1081 |
/* Read the specified cookie value */ |
|
ds@1952
|
1082 |
static const VdbeOpList readCookie[] = { |
|
ds@1952
|
1083 |
{ OP_ReadCookie, 0, 0, 0}, /* 0 */ |
|
ds@1952
|
1084 |
{ OP_Callback, 1, 0, 0} |
|
ds@1952
|
1085 |
}; |
|
ds@1952
|
1086 |
int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie); |
|
ds@1952
|
1087 |
sqlite3VdbeChangeP1(v, addr, iDb); |
|
ds@1952
|
1088 |
sqlite3VdbeChangeP2(v, addr, iCookie); |
|
ds@1952
|
1089 |
sqlite3VdbeSetNumCols(v, 1); |
|
ds@1952
|
1090 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P3_TRANSIENT); |
|
ds@1952
|
1091 |
} |
|
ds@1952
|
1092 |
}else |
|
ds@1952
|
1093 |
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */ |
|
ds@1952
|
1094 |
|
|
ds@1952
|
1095 |
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
|
ds@1952
|
1096 |
/* |
|
ds@1952
|
1097 |
** Report the current state of file logs for all databases |
|
ds@1952
|
1098 |
*/ |
|
ds@1952
|
1099 |
if( sqlite3StrICmp(zLeft, "lock_status")==0 ){ |
|
ds@1952
|
1100 |
static const char *const azLockName[] = { |
|
ds@1952
|
1101 |
"unlocked", "shared", "reserved", "pending", "exclusive" |
|
ds@1952
|
1102 |
}; |
|
ds@1952
|
1103 |
int i; |
|
ds@1952
|
1104 |
Vdbe *v = sqlite3GetVdbe(pParse); |
|
ds@1952
|
1105 |
sqlite3VdbeSetNumCols(v, 2); |
|
ds@1952
|
1106 |
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC); |
|
ds@1952
|
1107 |
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC); |
|
ds@1952
|
1108 |
for(i=0; i<db->nDb; i++){ |
|
ds@1952
|
1109 |
Btree *pBt; |
|
ds@1952
|
1110 |
Pager *pPager; |
|
ds@1952
|
1111 |
const char *zState = "unknown"; |
|
ds@1952
|
1112 |
int j; |
|
ds@1952
|
1113 |
if( db->aDb[i].zName==0 ) continue; |
|
ds@1952
|
1114 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC); |
|
ds@1952
|
1115 |
pBt = db->aDb[i].pBt; |
|
ds@1952
|
1116 |
if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ |
|
ds@1952
|
1117 |
zState = "closed"; |
|
ds@1952
|
1118 |
}else if( sqlite3_file_control(db, db->aDb[i].zName, |
|
ds@1952
|
1119 |
SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){ |
|
ds@1952
|
1120 |
zState = azLockName[j]; |
|
ds@1952
|
1121 |
} |
|
ds@1952
|
1122 |
sqlite3VdbeOp3(v, OP_String8, 0, 0, zState, P3_STATIC); |
|
ds@1952
|
1123 |
sqlite3VdbeAddOp(v, OP_Callback, 2, 0); |
|
ds@1952
|
1124 |
} |
|
ds@1952
|
1125 |
}else |
|
ds@1952
|
1126 |
#endif |
|
ds@1952
|
1127 |
|
|
ds@1952
|
1128 |
#ifdef SQLITE_SSE |
|
ds@1952
|
1129 |
/* |
|
ds@1952
|
1130 |
** Check to see if the sqlite_statements table exists. Create it |
|
ds@1952
|
1131 |
** if it does not. |
|
ds@1952
|
1132 |
*/ |
|
ds@1952
|
1133 |
if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){ |
|
ds@1952
|
1134 |
extern int sqlite3CreateStatementsTable(Parse*); |
|
ds@1952
|
1135 |
sqlite3CreateStatementsTable(pParse); |
|
ds@1952
|
1136 |
}else |
|
ds@1952
|
1137 |
#endif |
|
ds@1952
|
1138 |
|
|
ds@1952
|
1139 |
#if SQLITE_HAS_CODEC |
|
ds@1952
|
1140 |
if( sqlite3StrICmp(zLeft, "key")==0 ){ |
|
ds@1952
|
1141 |
sqlite3_key(db, zRight, strlen(zRight)); |
|
ds@1952
|
1142 |
}else |
|
ds@1952
|
1143 |
#endif |
|
ds@1952
|
1144 |
#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD) |
|
ds@1952
|
1145 |
if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){ |
|
ds@1952
|
1146 |
#if SQLITE_HAS_CODEC |
|
ds@1952
|
1147 |
if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ |
|
ds@1952
|
1148 |
extern void sqlite3_activate_see(const char*); |
|
ds@1952
|
1149 |
sqlite3_activate_see(&zRight[4]); |
|
ds@1952
|
1150 |
} |
|
ds@1952
|
1151 |
#endif |
|
ds@1952
|
1152 |
#ifdef SQLITE_ENABLE_CEROD |
|
ds@1952
|
1153 |
if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
|
ds@1952
|
1154 |
extern void sqlite3_activate_cerod(const char*); |
|
ds@1952
|
1155 |
sqlite3_activate_cerod(&zRight[6]); |
|
ds@1952
|
1156 |
} |
|
ds@1952
|
1157 |
#endif |
|
ds@1952
|
1158 |
} |
|
ds@1952
|
1159 |
#endif |
|
ds@1952
|
1160 |
|
|
ds@1952
|
1161 |
{} |
|
ds@1952
|
1162 |
|
|
ds@1952
|
1163 |
if( v ){ |
|
ds@1952
|
1164 |
/* Code an OP_Expire at the end of each PRAGMA program to cause |
|
ds@1952
|
1165 |
** the VDBE implementing the pragma to expire. Most (all?) pragmas |
|
ds@1952
|
1166 |
** are only valid for a single execution. |
|
ds@1952
|
1167 |
*/ |
|
ds@1952
|
1168 |
sqlite3VdbeAddOp(v, OP_Expire, 1, 0); |
|
ds@1952
|
1169 |
|
|
ds@1952
|
1170 |
/* |
|
ds@1952
|
1171 |
** Reset the safety level, in case the fullfsync flag or synchronous |
|
ds@1952
|
1172 |
** setting changed. |
|
ds@1952
|
1173 |
*/ |
|
ds@1952
|
1174 |
#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
|
ds@1952
|
1175 |
if( db->autoCommit ){ |
|
ds@1952
|
1176 |
sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, |
|
ds@1952
|
1177 |
(db->flags&SQLITE_FullFSync)!=0); |
|
ds@1952
|
1178 |
} |
|
ds@1952
|
1179 |
#endif |
|
ds@1952
|
1180 |
} |
|
ds@1952
|
1181 |
pragma_out: |
|
ds@1952
|
1182 |
sqlite3_free(zLeft); |
|
ds@1952
|
1183 |
sqlite3_free(zRight); |
|
ds@1952
|
1184 |
} |
|
ds@1952
|
1185 |
|
|
ds@1952
|
1186 |
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ |