Fix the max_page_count pragma so that it will not set to a value smaller

than the current database size, as the documentation requires.  Also,
remove all occurances of atoi() from the core.

FossilOrigin-Name: 2031974b606ef713b5f34522b2221470d98687c5
This commit is contained in:
drh 2010-11-23 18:59:27 +00:00
parent 15eac4e48a
commit 60ac3f426c
8 changed files with 81 additions and 49 deletions

View File

@ -1,5 +1,8 @@
C Fix\sa\stypo\sin\sunixCurrentTimeInt64()\spreventing\scompilation\swith\sNO_GETTOD\sdefined.
D 2010-11-22T17:26:07
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Fix\sthe\smax_page_count\spragma\sso\sthat\sit\swill\snot\sset\sto\sa\svalue\ssmaller\nthan\sthe\scurrent\sdatabase\ssize,\sas\sthe\sdocumentation\srequires.\s\sAlso,\nremove\sall\soccurances\sof\satoi()\sfrom\sthe\score.
D 2010-11-23T18:59:28
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in e7a59672eaeb04408d1fa8501618d7501a3c5e39
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -168,8 +171,8 @@ F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
F src/pcache.c 09d38c44ab275db581f7a2f6ff8b9bc7f8c0faaa
F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
F src/pcache1.c e9578a3beac26f229ee558a4e16c863f2498185f
F src/pragma.c 8e87e9e3e8a6734995d22f60dcc8bb838db52436
F src/prepare.c c2b318037d626fed27905c9446730b560637217a
F src/pragma.c 8a6cd3c787f882fa44f6490d2411fc26839ce8f3
F src/prepare.c c8b877b80721d70b68053fd9ae30ec6d63eeeadc
F src/printf.c 8ae5082dd38a1b5456030c3755ec3a392cd51506
F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
@ -178,7 +181,7 @@ F src/select.c 550d67688f5e8bc8022faf6d014838afba1415af
F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056
F src/sqlite.h.in e6e87d10e6a3756b8c7e9a11703716b6a1575a40
F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754
F src/sqliteInt.h f5b5041bfebd5654212992f6ebaa3f575c4b9c17
F src/sqliteInt.h 7739098f7b8c9e83ed46f75744138921136ed4b8
F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44
F src/status.c 496913d4e8441195f6f2a75b1c95993a45b9b30b
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@ -226,9 +229,9 @@ F src/tokenize.c 604607d6813e9551cf5189d899e0a25c12681080
F src/trigger.c b8bedb9c0084ceb51a40f54fcca2ce048c8de852
F src/update.c 227e6cd512108b84f69421fc6c7aa1b83d60d6e0
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
F src/util.c cd78524566fe45671863eee78685969a4bfd4e4c
F src/util.c ab1c92426494f499f42b9e307537b03e923d75c1
F src/vacuum.c 924bd1bcee2dfb05376f79845bd3b4cec7b54b2f
F src/vdbe.c 63bb1e56a035bc65b20d6f9c7d7c876f19b4605f
F src/vdbe.c c7e4f78c4dd263241b24d164351b8d9cdb50e3c8
F src/vdbe.h 4de0efb4b0fdaaa900cf419b35c458933ef1c6d2
F src/vdbeInt.h 7f4cf1b2b69bef3a432b1f23dfebef57275436b4
F src/vdbeapi.c fb0036185b3c56e15916a5ee96309cd4acf6818f
@ -572,7 +575,7 @@ F test/notify3.test d60923e186e0900f4812a845fcdfd8eea096e33a
F test/notnull.test cc7c78340328e6112a13c3e311a9ab3127114347
F test/null.test a8b09b8ed87852742343b33441a9240022108993
F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec
F test/pager1.test 07b06b89d50bc38bb118a18b99c7bee645b315de
F test/pager1.test e066fb2e2dc1ac1cd9ef2b44a28ae3cc79a9150f
F test/pager2.test 0fbb6b6dc40ce1fecfe758c555a748ad2e9beaa3
F test/pager3.test 3856d9c80839be0668efee1b74811b1b7f7fc95f
F test/pagerfault.test 9de4d3e0c59970b4c6cb8dac511fa242f335d8a7
@ -889,7 +892,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P e38c81cc18d2ceaa1644aaba64530ba5d1fbf2cf
R d7dd6f7536f2f168157ffbcee03e168e
U dan
Z 238874a9476b4d03764b69cbc465de50
P 3df3e79b56821201b4f5ecd23f94d485745c48c3
R d6d12a53ba894b3f7fea4dc3bcc807a0
U drh
Z 1d6a40ca5db70d8ab4bdb6ba9632081d
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFM7A8UoxKgR168RlERAiLFAJwN4OTIE38FGud8XoxtDlxqTpHsigCfT9xh
qywgx7z1po++UXATymbWvhQ=
=FWyf
-----END PGP SIGNATURE-----

View File

@ -1 +1 @@
3df3e79b56821201b4f5ecd23f94d485745c48c3
2031974b606ef713b5f34522b2221470d98687c5

View File

@ -35,7 +35,7 @@ static u8 getSafetyLevel(const char *z){
static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
int i, n;
if( sqlite3Isdigit(*z) ){
return (u8)atoi(z);
return (u8)sqlite3Atoi(z);
}
n = sqlite3Strlen30(z);
for(i=0; i<ArraySize(iLength); i++){
@ -76,7 +76,7 @@ static int getAutoVacuum(const char *z){
if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
i = atoi(z);
i = sqlite3Atoi(z);
return (u8)((i>=0&&i<=2)?i:0);
}
#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
@ -384,7 +384,7 @@ void sqlite3Pragma(
sqlite3VdbeChangeP1(v, addr+1, iDb);
sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
}else{
int size = atoi(zRight);
int size = sqlite3Atoi(zRight);
if( size<0 ) size = -size;
sqlite3BeginWriteOperation(pParse, 0, iDb);
sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
@ -413,35 +413,13 @@ void sqlite3Pragma(
/* Malloc may fail when setting the page-size, as there is an internal
** buffer that the pager module resizes using sqlite3_realloc().
*/
db->nextPagesize = atoi(zRight);
db->nextPagesize = sqlite3Atoi(zRight);
if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
db->mallocFailed = 1;
}
}
}else
/*
** PRAGMA [database.]max_page_count
** PRAGMA [database.]max_page_count=N
**
** The first form reports the current setting for the
** maximum number of pages in the database file. The
** second form attempts to change this setting. Both
** forms return the current setting.
*/
if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
Btree *pBt = pDb->pBt;
int newMax = 0;
assert( pBt!=0 );
if( zRight ){
newMax = atoi(zRight);
}
if( ALWAYS(pBt) ){
newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
}
returnSingleInt(pParse, "max_page_count", newMax);
}else
/*
** PRAGMA [database.]secure_delete
** PRAGMA [database.]secure_delete=ON/OFF
@ -468,19 +446,33 @@ void sqlite3Pragma(
}else
/*
** PRAGMA [database.]max_page_count
** PRAGMA [database.]max_page_count=N
**
** The first form reports the current setting for the
** maximum number of pages in the database file. The
** second form attempts to change this setting. Both
** forms return the current setting.
**
** PRAGMA [database.]page_count
**
** Return the number of pages in the specified database.
*/
if( sqlite3StrICmp(zLeft,"page_count")==0 ){
if( sqlite3StrICmp(zLeft,"page_count")==0
|| sqlite3StrICmp(zLeft,"max_page_count")==0
){
int iReg;
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
sqlite3CodeVerifySchema(pParse, iDb);
iReg = ++pParse->nMem;
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
if( zLeft[0]=='p' ){
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
}else{
sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight));
}
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
}else
/*
@ -702,7 +694,7 @@ void sqlite3Pragma(
if( !zRight ){
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
}else{
int size = atoi(zRight);
int size = sqlite3Atoi(zRight);
if( size<0 ) size = -size;
pDb->pSchema->cache_size = size;
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
@ -1095,7 +1087,7 @@ void sqlite3Pragma(
/* Set the maximum error count */
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
if( zRight ){
mxErr = atoi(zRight);
sqlite3GetInt32(zRight, &mxErr);
if( mxErr<=0 ){
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
}
@ -1352,7 +1344,7 @@ void sqlite3Pragma(
};
int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
sqlite3VdbeChangeP1(v, addr, iDb);
sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
sqlite3VdbeChangeP1(v, addr+2, iDb);
sqlite3VdbeChangeP2(v, addr+2, iCookie);
}else{
@ -1413,8 +1405,7 @@ void sqlite3Pragma(
*/
if( sqlite3StrICmp(zLeft, "wal_autocheckpoint")==0 ){
if( zRight ){
int nAuto = atoi(zRight);
sqlite3_wal_autocheckpoint(db, nAuto);
sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
}
returnSingleInt(pParse, "wal_autocheckpoint",
db->xWalCallback==sqlite3WalDefaultHook ?

View File

@ -79,7 +79,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
assert( db->init.busy );
db->init.iDb = iDb;
db->init.newTnum = atoi(argv[1]);
db->init.newTnum = sqlite3Atoi(argv[1]);
db->init.orphanTrigger = 0;
TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
rc = db->errCode;

View File

@ -2840,6 +2840,7 @@ int sqlite3FixExprList(DbFixer*, ExprList*);
int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
int sqlite3AtoF(const char *z, double*, int, u8);
int sqlite3GetInt32(const char *, int*);
int sqlite3Atoi(const char*);
int sqlite3Utf16ByteLen(const void *pData, int nChar);
int sqlite3Utf8CharLen(const char *pData, int nByte);
int sqlite3Utf8Read(const u8*, const u8**);

View File

@ -541,6 +541,16 @@ int sqlite3GetInt32(const char *zNum, int *pValue){
return 1;
}
/*
** Return a 32-bit integer value extracted from a string. If the
** string is not an integer, just return 0.
*/
int sqlite3Atoi(const char *z){
int x = 0;
if( z ) sqlite3GetInt32(z, &x);
return x;
}
/*
** The variable-length integer encoding is as follows:
**

View File

@ -5788,6 +5788,26 @@ case OP_Pagecount: { /* out2-prerelease */
}
#endif
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/* Opcode: MaxPgcnt P1 P2 P3 * *
**
** Try to set the maximum page count for database P1 to the value in P3.
** Do not let the maximum page count fall below the current page count.
** Store the maximum page count after the change in register P2.
*/
case OP_MaxPgcnt: { /* out2-prerelease */
unsigned int pgcnt;
Btree *pBt;
pBt = db->aDb[pOp->p1].pBt;
pgcnt = sqlite3BtreeLastPage(pBt);
pOut->u.i = sqlite3BtreeMaxPageCount(pBt, pOp->p3<pgcnt ? pgcnt : pOp->p3);
break;
}
#endif
#ifndef SQLITE_OMIT_TRACE
/* Opcode: Trace * * * P4 *
**

View File

@ -1062,7 +1062,7 @@ do_execsql_test pager1-6.8 {
} {11}
do_execsql_test pager1-6.9 { COMMIT } {}
do_execsql_test pager1-6.10 { PRAGMA max_page_count = 10 } {10}
do_execsql_test pager1-6.10 { PRAGMA max_page_count = 10 } {11}
do_execsql_test pager1-6.11 { SELECT * FROM t11 } {1 2 3 4}
do_execsql_test pager1-6.12 { PRAGMA max_page_count } {11}