Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Unified Diff: third_party/sqlite_google/src/btree.c

Issue 924: sqlite3 pragma get/set user_version implemented (Closed) SVN Base: http://google-gears.googlecode.com/svn/contrib/dimitri.glazkov/database2/gears/
Patch Set: moved code to btree.c, restructured Created 3 months, 2 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: third_party/sqlite_google/src/btree.c
===================================================================
--- third_party/sqlite_google/src/btree.c (revision 1639)
+++ third_party/sqlite_google/src/btree.c (working copy)
@@ -29,6 +29,12 @@
*/
static const char zPoisonHeader[] = "SQLite poison 3";
+/*
+** The user cookie position in the database meta information
+** (see prepare.c#215), incremented by one, because first position is actually
+** the number of free pages in Btree (see vdbe.c#2521)
+*/
+static const int kUserCookie = 6;
/*
** Set this global variable to 1 to enable tracing using the TRACE
@@ -6422,3 +6428,41 @@
}
#endif
+
+int sqlite3_get_user_version(sqlite3 *sqlite, int *user_version) {
+ Btree *bt;
+
+ if( sqlite == NULL ) return SQLITE_ERROR;
+ if( sqlite->nDb<1 ) return SQLITE_ERROR;
+
+ /* grab actual (not temporary tables) database */
Scott.Hess 2008/05/22 23:44:28 Comments should mostly be composed of sentences.
Dimitri 2008/06/04 03:02:16 On 2008/05/22 23:44:28, Scott.Hess wrote: > Commen
+ bt = sqlite->aDb[0].pBt;
+ /* because sqlite3BtreeGetMeta sets a table read lock, it is safe to use
+ ** without explicit read transaction. Besides, it is very unlikely we will
+ ** ever call this outside of a transaction.
+ */
+ return sqlite3BtreeGetMeta(bt, kUserCookie, (u32 *)user_version);
+}
+
+int sqlite3_set_user_version(sqlite3 *sqlite, int user_version) {
+ Btree *bt;
+ int rc;
+
+ if( sqlite == NULL ) return SQLITE_ERROR;
+ if( sqlite->nDb<1 ) return SQLITE_ERROR;
+
+ bt = sqlite->aDb[0].pBt;
+ if( bt->inTrans!= TRANS_WRITE ) {
Scott.Hess 2008/05/22 23:44:28 Shouldn't this be ==? No space after = sign in an
Dimitri 2008/06/04 03:02:16 On 2008/05/22 23:44:28, Scott.Hess wrote: > Should
+ return sqlite3BtreeUpdateMeta(bt, kUserCookie, (u32)user_version);
+ }else{
+ /* transacion isn't already in progress, have to enclose in
+ ** a write-transaction
+ */
Scott.Hess 2008/05/22 23:44:28 sp on first occurrence of transaction. Revise com
+ rc = sqlite3BtreeBeginTrans(bt, 1);
+ if( rc!=SQLITE_OK ) return rc;
+ rc = sqlite3BtreeUpdateMeta(bt, kUserCookie, (u32)user_version);
+ if( rc==SQLITE_OK ) return sqlite3BtreeCommit(bt);
+ sqlite3BtreeRollback(bt);
+ return rc;
Scott.Hess 2008/05/22 23:44:28 For Database2, is it even possible to get to this
Dimitri 2008/06/04 03:02:16 On 2008/05/22 23:44:28, Scott.Hess wrote: > For Da
+ }
+}
Scott.Hess 2008/05/22 23:44:28 Sorry to be a pain, I'm trying to recall why we're
Dimitri 2008/06/04 03:02:16 On 2008/05/22 23:44:28, Scott.Hess wrote: > Sorry

Powered by Google App Engine
This is Rietveld r305