| OLD | NEW |
| 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" | |
| 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" |
| (...skipping 1098 matching lines...) Show 10 above Show 10 below |
| 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) { | |
| 1137 // grab actual (not temporary tables) database | |
| 1138 Btree *bt = sqlite->aDb[0].pBt; | |
| 1139 // 6 = user_version cookie | |
| 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) { | |
| 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) { | |
| 1153 // begin write transaction, if not already started | |
| 1154 rc = sqlite3BtreeBeginTrans(bt, 1); | |
| 1155 if (rc != SQLITE_OK) { | |
| 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; | |
| 1168 } | |
| 1169 | |
| 1170 #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ | 1135 #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ |
| OLD | NEW |