annotate sqlite/pragma.c @ 1571:0b69bc0eb2d2 trunk

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