| Index: third_party/sqlite_google/src/pragma.c |
| =================================================================== |
| --- third_party/sqlite_google/src/pragma.c (revision 1608) |
| +++ third_party/sqlite_google/src/pragma.c (working copy) |
| @@ -14,6 +14,7 @@ |
| ** $Id: pragma.c,v 1.139 2007/05/23 13:50:24 danielk1977 Exp $ |
| */ |
| #include "sqliteInt.h" |
| +#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
|
| #include "os.h" |
| #include <ctype.h> |
| @@ -1132,4 +1133,38 @@ |
| sqliteFree(zRight); |
| } |
| +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
|
| + // 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
|
| + 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
|
| + // 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
|
| + // 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, 6, (u32 *)user_version); |
| +} |
| + |
| +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
|
| + Btree *bt = sqlite->aDb[0].pBt; |
| + int rc; |
| + // have to enclose this in a write-transaction, if transaction isn't already |
| + // in progress |
| + int needs_transaction = bt->inTrans != TRANS_WRITE; |
| + 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
|
| + // begin write transaction, if not already started |
| + rc = sqlite3BtreeBeginTrans(bt, 1); |
| + 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
|
| + return rc; |
| + } |
| + } |
| + rc = sqlite3BtreeUpdateMeta(bt, 6, (u32)user_version); |
| + if (needs_transaction) { |
| + if (rc != SQLITE_OK) { |
| + sqlite3BtreeRollback(bt); |
| + return rc; |
| + } |
| + return sqlite3BtreeCommit(bt); |
| + } |
| + 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
|
| +} |
| + |
| #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ |