From: danielk1977 Date: Thu, 15 May 2008 17:48:20 +0000 (+0000) Subject: Add the "page_count" pragma. Returns a single integer - the number of pages in the... X-Git-Tag: version-3.6.10~1042 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59a93791cedbc627d11148cf314603b21ad9ef0e;p=thirdparty%2Fsqlite.git Add the "page_count" pragma. Returns a single integer - the number of pages in the specified database file. (CVS 5135) FossilOrigin-Name: eb6985e69ce2a5e5e7361f6226d1cfc547fd441d --- diff --git a/manifest b/manifest index f7a9861c13..51bcf0d68e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\spager\sis\salready\sin\sthe\serror-state\swhen\sCommitPhaseOne()\sis\scalled,\sexit\searly.\s(CVS\s5134) -D 2008-05-15T11:08:08 +C Add\sthe\s"page_count"\spragma.\sReturns\sa\ssingle\sinteger\s-\sthe\snumber\sof\spages\sin\sthe\sspecified\sdatabase\sfile.\s(CVS\s5135) +D 2008-05-15T17:48:20 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in 79aeba12300a54903f1b1257c1e7c190234045dd F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -124,7 +124,7 @@ F src/os_win.c 3a60bddd07ea6f8adb2314dd5996ac97b988f403 F src/pager.c 43f5f67ff211ed0f40ccd9a96c079e811a9ac601 F src/pager.h 4f051fd856de6fd3c19aef5f82eace54122b9173 F src/parse.y fc4bd35c6088901f7c8daead26c6fb11c87d22e7 -F src/pragma.c 2e4bb2e76e48a32750529fdc4bfe86ac5f54e01b +F src/pragma.c a4919a29a0923e00c6170b0677a50058e352b58c F src/prepare.c adc7e1fc08dfbab63cd213d4c0aff8f3fa70d477 F src/printf.c 77c192ccc81117d68b21b449cd33396357aa266d F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a @@ -167,7 +167,7 @@ F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34 F src/utf.c 8c94fa10efc78c2568d08d436acc59df4df7191b F src/util.c 28fb90e03f83b95f6e8b1978fb60953e6cef9e3a F src/vacuum.c c3b2b70677f874102b8753bf494c232e777f3998 -F src/vdbe.c 81035a619a605412a782c1f01ffeb924e08759da +F src/vdbe.c 25a362a4fdd5ff2797db0e20a9cf4300e053891e F src/vdbe.h f4bb70962d9c13e0f65b215c90e8acea1ae6e8ee F src/vdbeInt.h 18aebaa7857de4507d92ced62d8fe0844671a681 F src/vdbeapi.c 95ed14a59c509f98c64afba30cd18c3c8cf649cd @@ -409,7 +409,7 @@ F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5 F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4 F test/pageropt.test 6df72c441db0a037b7ec6990d16311c24fbea77b F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e -F test/pragma.test aec802c9599db3ec887b5fd96f0b08958129303e +F test/pragma.test c3229f5f66a00807fa1d3cb8fd07d87c28c93e3e F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test c3405535b418d454e8a52196a0fc592ec9eec58d F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x @@ -635,7 +635,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 47652e7b169626e5f3d95f29e867a2e8f68c5025 -R d8f7609758174cb331cdc46a0cb952a9 +P 443cf1056c73ae89d0efcc7a462455c078b3a4a8 +R 96e9041aae6fa8722c29c429bd779ba8 U danielk1977 -Z 7ea980f7a54707b1517ab40c9892ab63 +Z 5b148c1b18a27ad32a8908d4eed930da diff --git a/manifest.uuid b/manifest.uuid index f01d8b857c..3bbf611740 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -443cf1056c73ae89d0efcc7a462455c078b3a4a8 \ No newline at end of file +eb6985e69ce2a5e5e7361f6226d1cfc547fd441d \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 661af7a101..9a28563e3f 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 @@ -378,6 +378,24 @@ void sqlite3Pragma( returnSingleInt(pParse, "max_page_count", newMax); }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 8215a703f4..56be3b6ab1 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 @@ -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 * ** diff --git a/test/pragma.test b/test/pragma.test index f577f015aa..330139c524 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -12,7 +12,7 @@ # # This file implements tests for the PRAGMA command. # -# $Id: pragma.test,v 1.59 2008/03/19 00:21:31 drh Exp $ +# $Id: pragma.test,v 1.60 2008/05/15 17:48:20 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -31,6 +31,7 @@ source $testdir/tester.tcl # pragma-9.*: Test temp_store and temp_store_directory. # pragma-10.*: Test the count_changes pragma in the presence of triggers. # pragma-11.*: Test the collation_list pragma. +# pragma-14.*: Test the page_count pragma. # ifcapable !pragma { @@ -1095,6 +1096,61 @@ do_test pragma-13.1 { } ;# ifcapable bloblit +ifcapable pager_pragmas { + db close + file delete -force test.db + sqlite3 db test.db + + do_test pragma-14.1 { + execsql { pragma auto_vacuum = 0 } + execsql { pragma page_count } + } {0} + + do_test pragma-14.2 { + execsql { + CREATE TABLE abc(a, b, c); + PRAGMA page_count; + } + } {2} + + do_test pragma-14.3 { + execsql { + BEGIN; + CREATE TABLE def(a, b, c); + PRAGMA page_count; + } + } {3} + + do_test pragma-14.4 { + set page_size [db one {pragma page_size}] + expr [file size test.db] / $page_size + } {2} + + do_test pragma-14.5 { + execsql { + ROLLBACK; + PRAGMA page_count; + } + } {2} + + do_test pragma-14.6 { + file delete -force test2.db + sqlite3 db2 test2.db + execsql { + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE TABLE t3(a, b, c); + CREATE TABLE t4(a, b, c); + } db2 + db2 close + execsql { + ATTACH 'test2.db' AS aux; + PRAGMA aux.page_count; + } + } {5} +} + # Reset the sqlite3_temp_directory variable for the next run of tests: sqlite3 dbX :memory: dbX eval {PRAGMA temp_store_directory = ""}