Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add the "page_count" pragma. Returns a single integer - the number of pages in the specified database file. (CVS 5135) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
eb6985e69ce2a5e5e7361f6226d1cfc5 |
User & Date: | danielk1977 2008-05-15 17:48:20.000 |
Context
2008-05-15
| ||
19:43 | Add version tag comments to source files that lack them. Tickets #3118 and #3119. (CVS 5136) (check-in: cf1fb2d850 user: drh tags: trunk) | |
17:48 | Add the "page_count" pragma. Returns a single integer - the number of pages in the specified database file. (CVS 5135) (check-in: eb6985e69c user: danielk1977 tags: trunk) | |
11:08 | If a pager is already in the error-state when CommitPhaseOne() is called, exit early. (CVS 5134) (check-in: 443cf1056c user: danielk1977 tags: trunk) | |
Changes
Changes to src/pragma.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2003 April 6 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2003 April 6 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** ** $Id: pragma.c,v 1.177 2008/05/15 17:48:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* Ignore this whole file if pragmas are disabled */ #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER) |
︙ | ︙ | |||
374 375 376 377 378 379 380 381 382 383 384 385 386 387 | } if( pBt ){ newMax = sqlite3BtreeMaxPageCount(pBt, newMax); } returnSingleInt(pParse, "max_page_count", newMax); }else /* ** PRAGMA [database.]locking_mode ** PRAGMA [database.]locking_mode = (normal|exclusive) */ if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){ const char *zRet = "normal"; int eMode = getLockingMode(zRight); | > > > > > > > > > > > > > > > > > > | 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | } if( pBt ){ newMax = sqlite3BtreeMaxPageCount(pBt, newMax); } 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) */ if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){ const char *zRet = "normal"; int eMode = getLockingMode(zRight); |
︙ | ︙ |
Changes to src/vdbe.c.
︙ | ︙ | |||
39 40 41 42 43 44 45 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** 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.741 2008/05/15 17:48:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> #include "vdbeInt.h" /* ** The following global variable is incremented every time a cursor |
︙ | ︙ | |||
4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 | db->lastRowid = rowid; } p->nChange++; } break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ #ifndef SQLITE_OMIT_TRACE /* Opcode: Trace * * * P4 * ** ** If tracing is enabled (by the sqlite3_trace()) interface, then ** the UTF-8 string contained in P4 is emitted on the trace callback. */ | > > > > > > > > > > > > > > > > > > > > > | 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 | db->lastRowid = rowid; } p->nChange++; } break; } #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 * ** ** If tracing is enabled (by the sqlite3_trace()) interface, then ** the UTF-8 string contained in P4 is emitted on the trace callback. */ |
︙ | ︙ |
Changes to test/pragma.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. # # This file implements tests for the PRAGMA command. # | | > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. # # This file implements tests for the PRAGMA command. # # $Id: pragma.test,v 1.60 2008/05/15 17:48:20 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Test organization: # # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. # pragma-2.*: Test synchronous on attached db. # pragma-3.*: Test detection of table/index inconsistency by integrity_check. # pragma-4.*: Test cache_size and default_cache_size on attached db. # pragma-5.*: Test that pragma synchronous may not be used inside of a # transaction. # pragma-6.*: Test schema-query pragmas. # pragma-7.*: Miscellaneous tests. # pragma-8.*: Test user_version and schema_version pragmas. # 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 { finish_test return } |
︙ | ︙ | |||
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | PRAGMA vdbe_trace=off; PRAGMA vdbe_listing=off; PRAGMA sql_trace=off; } } {} } ;# ifcapable bloblit # Reset the sqlite3_temp_directory variable for the next run of tests: sqlite3 dbX :memory: dbX eval {PRAGMA temp_store_directory = ""} dbX close finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 | PRAGMA vdbe_trace=off; PRAGMA vdbe_listing=off; PRAGMA sql_trace=off; } } {} } ;# 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 = ""} dbX close finish_test |