| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 ** 2003 April 6 | 2 ** 2003 April 6 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| 11 ************************************************************************* | 11 ************************************************************************* |
| 12 ** This file contains code used to implement the PRAGMA command. | 12 ** This file contains code used to implement the PRAGMA command. |
| 13 ** | 13 ** |
| 14 ** $Id: pragma.c,v 1.139 2007/05/23 13:50:24 danielk1977 Exp $ | 14 ** $Id: pragma.c,v 1.139 2007/05/23 13:50:24 danielk1977 Exp $ |
| 15 */ | 15 */ |
| 16 #include "sqliteInt.h" | 16 #include "sqliteInt.h" |
| 17 #include "btreeInt.h" | |
|
Scott.Hess
2008/05/20 18:37:04
Maybe the new code should just live in btree.c?
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> Maybe
| |
| 18 #include "os.h" | 17 #include "os.h" |
| 19 #include <ctype.h> | 18 #include <ctype.h> |
| 20 | 19 |
| 21 /* Ignore this whole file if pragmas are disabled | 20 /* Ignore this whole file if pragmas are disabled |
| 22 */ | 21 */ |
| 23 #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER) | 22 #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER) |
| 24 | 23 |
| 25 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) | 24 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 26 # include "pager.h" | 25 # include "pager.h" |
| 27 # include "btree.h" | 26 # include "btree.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 /* | 29 /* |
| 31 ** Interpret the given string as a safety level. Return 0 for OFF, | 30 ** Interpret the given string as a safety level. Return 0 for OFF, |
| 32 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or | 31 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or |
| 33 ** unrecognized string argument. | 32 ** unrecognized string argument. |
| 34 ** | 33 ** |
| 35 ** Note that the values returned are one less that the values that | 34 ** Note that the values returned are one less that the values that |
| 36 ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done | 35 ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done |
| 37 ** to support legacy SQL code. The safety level used to be boolean | 36 ** to support legacy SQL code. The safety level used to be boolean |
| 38 ** and older scripts may have used numbers 0 for OFF and 1 for ON. | 37 ** and older scripts may have used numbers 0 for OFF and 1 for ON. |
| 39 */ | 38 */ |
| 40 static int getSafetyLevel(const char *z){ | 39 static int getSafetyLevel(const char *z){ |
| 41 /* 123456789 123456789 */ | 40 /* 123456789 123456789 */ |
| 42 static const char zText[] = "onoffalseyestruefull"; | 41 static const char zText[] = "onoffalseyestruefull"; |
| 43 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; | 42 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; |
| 44 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; | 43 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; |
| 45 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; | 44 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; |
| 46 int i, n; | 45 int i, n; |
| 47 if( isdigit(*z) ){ | 46 if( isdigit(*z) ){ |
| 48 return atoi(z); | 47 return atoi(z); |
| 49 } | 48 } |
| 50 n = strlen(z); | 49 n = strlen(z); |
| 51 for(i=0; i<sizeof(iLength); i++){ | 50 for(i=0; i<sizeof(iLength); i++){ |
| 52 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){ | 51 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){ |
| 53 return iValue[i]; | 52 return iValue[i]; |
| 54 } | 53 } |
| 55 } | 54 } |
| 56 return 1; | 55 return 1; |
| 57 } | 56 } |
| 58 | 57 |
| 59 /* | 58 /* |
| 60 ** Interpret the given string as a boolean value. | 59 ** Interpret the given string as a boolean value. |
| 61 */ | 60 */ |
| 62 static int getBoolean(const char *z){ | 61 static int getBoolean(const char *z){ |
| 63 return getSafetyLevel(z)&1; | 62 return getSafetyLevel(z)&1; |
| 64 } | 63 } |
| 65 | 64 |
| 66 /* | 65 /* |
| 67 ** Interpret the given string as a locking mode value. | 66 ** Interpret the given string as a locking mode value. |
| (...skipping 1018 matching lines...) Show 10 above Show 10 below | |
| 1086 }else | 1085 }else |
| 1087 #endif | 1086 #endif |
| 1088 | 1087 |
| 1089 #if SQLITE_HAS_CODEC | 1088 #if SQLITE_HAS_CODEC |
| 1090 if( sqlite3StrICmp(zLeft, "key")==0 ){ | 1089 if( sqlite3StrICmp(zLeft, "key")==0 ){ |
| 1091 sqlite3_key(db, zRight, strlen(zRight)); | 1090 sqlite3_key(db, zRight, strlen(zRight)); |
| 1092 }else | 1091 }else |
| 1093 #endif | 1092 #endif |
| 1094 #if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD) | 1093 #if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD) |
| 1095 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){ | 1094 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){ |
| 1096 #if SQLITE_HAS_CODEC | 1095 #if SQLITE_HAS_CODEC |
| 1097 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ | 1096 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ |
| 1098 extern void sqlite3_activate_see(const char*); | 1097 extern void sqlite3_activate_see(const char*); |
| 1099 sqlite3_activate_see(&zRight[4]); | 1098 sqlite3_activate_see(&zRight[4]); |
| 1100 } | 1099 } |
| 1101 #endif | 1100 #endif |
| 1102 #ifdef SQLITE_ENABLE_CEROD | 1101 #ifdef SQLITE_ENABLE_CEROD |
| 1103 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ | 1102 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
| 1104 extern void sqlite3_activate_cerod(const char*); | 1103 extern void sqlite3_activate_cerod(const char*); |
| 1105 sqlite3_activate_cerod(&zRight[6]); | 1104 sqlite3_activate_cerod(&zRight[6]); |
| 1106 } | 1105 } |
| 1107 #endif | 1106 #endif |
| 1108 } | 1107 } |
| 1109 #endif | 1108 #endif |
| 1110 | 1109 |
| 1111 {} | 1110 {} |
| 1112 | 1111 |
| 1113 if( v ){ | 1112 if( v ){ |
| 1114 /* Code an OP_Expire at the end of each PRAGMA program to cause | 1113 /* Code an OP_Expire at the end of each PRAGMA program to cause |
| 1115 ** the VDBE implementing the pragma to expire. Most (all?) pragmas | 1114 ** the VDBE implementing the pragma to expire. Most (all?) pragmas |
| 1116 ** are only valid for a single execution. | 1115 ** are only valid for a single execution. |
| 1117 */ | 1116 */ |
| 1118 sqlite3VdbeAddOp(v, OP_Expire, 1, 0); | 1117 sqlite3VdbeAddOp(v, OP_Expire, 1, 0); |
| 1119 | 1118 |
| 1120 /* | 1119 /* |
| 1121 ** Reset the safety level, in case the fullfsync flag or synchronous | 1120 ** Reset the safety level, in case the fullfsync flag or synchronous |
| 1122 ** setting changed. | 1121 ** setting changed. |
| 1123 */ | 1122 */ |
| 1124 #ifndef SQLITE_OMIT_PAGER_PRAGMAS | 1123 #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 1125 if( db->autoCommit ){ | 1124 if( db->autoCommit ){ |
| 1126 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, | 1125 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, |
| 1127 (db->flags&SQLITE_FullFSync)!=0); | 1126 (db->flags&SQLITE_FullFSync)!=0); |
| 1128 } | 1127 } |
| 1129 #endif | 1128 #endif |
| 1130 } | 1129 } |
| 1131 pragma_out: | 1130 pragma_out: |
| 1132 sqliteFree(zLeft); | 1131 sqliteFree(zLeft); |
| 1133 sqliteFree(zRight); | 1132 sqliteFree(zRight); |
| 1134 } | 1133 } |
| 1135 | 1134 |
| 1136 int sqlite3_pragma_get_user_version(sqlite3 *sqlite, int *user_version) { | |
|
Scott.Hess
2008/05/20 18:37:04
Suggest not naming this with "pragma", since it's
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> Sugges
| |
| 1137 // grab actual (not temporary tables) database | |
|
Scott.Hess
2008/05/20 18:37:04
This ain't c++! /* ... */, baby!
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> This a
| |
| 1138 Btree *bt = sqlite->aDb[0].pBt; | |
|
Scott.Hess
2008/05/20 18:37:04
Suggest a NULL check for sqlite, mainly because th
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> Sugges
| |
| 1139 // 6 = user_version cookie | |
|
Scott.Hess
2008/05/20 18:37:04
Suggest kUserVersionCookie or somesuch, so that yo
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> Sugges
| |
| 1140 // because sqlite3BtreeGetMeta sets a table read lock, it is safe to use | |
| 1141 // without explicit read transaction. Besides, it is very unlikely we will | |
| 1142 // ever call this outside of a transaction. | |
| 1143 return sqlite3BtreeGetMeta(bt, 6, (u32 *)user_version); | |
| 1144 } | |
| 1145 | |
| 1146 int sqlite3_pragma_set_user_version(sqlite3 *sqlite, int user_version) { | |
|
Scott.Hess
2008/05/20 18:37:04
Same checks down here, of course.
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> Same c
| |
| 1147 Btree *bt = sqlite->aDb[0].pBt; | |
| 1148 int rc; | |
| 1149 // have to enclose this in a write-transaction, if transaction isn't already | |
| 1150 // in progress | |
| 1151 int needs_transaction = bt->inTrans != TRANS_WRITE; | |
| 1152 if (needs_transaction) { | |
|
Scott.Hess
2008/05/20 18:37:04
SQLite code does if( needs_transaction ){. Indeed
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> SQLite
| |
| 1153 // begin write transaction, if not already started | |
| 1154 rc = sqlite3BtreeBeginTrans(bt, 1); | |
| 1155 if (rc != SQLITE_OK) { | |
|
Scott.Hess
2008/05/20 18:37:04
SQLite convention would be if( rc!=SQLITE_OK ) ret
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> SQLite
| |
| 1156 return rc; | |
| 1157 } | |
| 1158 } | |
| 1159 rc = sqlite3BtreeUpdateMeta(bt, 6, (u32)user_version); | |
| 1160 if (needs_transaction) { | |
| 1161 if (rc != SQLITE_OK) { | |
| 1162 sqlite3BtreeRollback(bt); | |
| 1163 return rc; | |
| 1164 } | |
| 1165 return sqlite3BtreeCommit(bt); | |
| 1166 } | |
| 1167 return rc; | |
|
Scott.Hess
2008/05/20 18:37:04
Have you tried a version of this which looked like
Dimitri
2008/05/21 13:14:31
On 2008/05/20 18:37:04, Scott.Hess wrote:
> Have y
| |
| 1168 } | |
| 1169 | |
| 1170 #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ | 1135 #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ |
| LEFT | RIGHT |