diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pragma.c | 20 | ||||
-rw-r--r-- | src/vdbe.c | 23 |
2 files changed, 41 insertions, 2 deletions
diff --git a/src/pragma.c b/src/pragma.c index 661af7a10..9a28563e3 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.176 2008/04/17 20:59:38 drh Exp $ +** $Id: pragma.c,v 1.177 2008/05/15 17:48:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -379,6 +379,24 @@ void sqlite3Pragma( }else /* + ** PRAGMA [database.]page_count + ** + ** Return the number of pages in the specified database. + */ + if( sqlite3StrICmp(zLeft,"page_count")==0 ){ + Vdbe *v; + int iReg; + v = sqlite3GetVdbe(pParse); + if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out; + sqlite3CodeVerifySchema(pParse, iDb); + iReg = ++pParse->nMem; + sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); + sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); + sqlite3VdbeSetNumCols(v, 1); + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", P4_STATIC); + }else + + /* ** PRAGMA [database.]locking_mode ** PRAGMA [database.]locking_mode = (normal|exclusive) */ diff --git a/src/vdbe.c b/src/vdbe.c index 8215a703f..56be3b6ab 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.740 2008/05/13 13:27:34 drh Exp $ +** $Id: vdbe.c,v 1.741 2008/05/15 17:48:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -4808,6 +4808,27 @@ case OP_VUpdate: { } #endif /* SQLITE_OMIT_VIRTUALTABLE */ +#ifndef SQLITE_OMIT_PAGER_PRAGMAS +/* Opcode: Pagecount P1 P2 * * * +** +** Write the current number of pages in database P1 to memory cell P2. +*/ +case OP_Pagecount: { /* out2-prerelease */ + int p1 = pOp->p1; + int nPage; + Pager *pPager = sqlite3BtreePager(db->aDb[p1].pBt); + + nPage = sqlite3PagerPagecount(pPager); + if( nPage<0 ){ + rc = SQLITE_IOERR; + }else{ + pOut->flags = MEM_Int; + pOut->u.i = nPage; + } + break; +} +#endif + #ifndef SQLITE_OMIT_TRACE /* Opcode: Trace * * * P4 * ** |