diff --git a/manifest b/manifest index db2f7d28ab..e61f988724 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_EXTRA_INIT\smacro. -D 2011-08-25T00:14:41.083 +C Add\sthe\ssqlite3_quota_file()\sinterface\sto\stest_quota.c. +D 2011-08-25T01:42:12.133 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 8c930e7b493d59099ea1304bd0f2aed152eb3315 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -219,7 +219,7 @@ F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec F src/test_osinst.c 62b0b8ef21ce754cc94e17bb42377ed8795dba32 F src/test_pcache.c 7bf828972ac0d2403f5cfa4cd14da41f8ebe73d8 -F src/test_quota.c e3a72c73bae28470ebece837b73d960f5a252878 +F src/test_quota.c 8cba4d8eb7db7118df3d735278e37b5b78b0e7b6 F src/test_rtree.c 30c981837445a4e187ee850a49c4760d9642f7c3 F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0 F src/test_server.c 2f99eb2837dfa06a4aacf24af24c6affdf66a84f @@ -626,7 +626,7 @@ F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 -F test/quota.test dd8f0e0eb77bc206c1ad1b1494f4fe2fe6985183 +F test/quota.test 482ba633252e88b7e3f492d0b5feddb4ec573e98 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6 F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test 1084050991e9ba22c1c10edd8d84673b501cc25a @@ -961,7 +961,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings.sh b7fdb2cc525f5ef4fa43c80e771636dd3690f9d2 -P 988998fe7b0a21ed113b67f812e51f357045bef4 -R 8b28b7c3eecedf6de29c77136a1a0b20 +P a3220f36c164dd2edf085c07ea08d617d8438812 +R 283add70a055d6da3480c6a93e10a2e4 U drh -Z 5b1b2064520e67fe87ded16d48f38359 +Z 490fe9cf524e1e32a7a5a2b19a5723e6 diff --git a/manifest.uuid b/manifest.uuid index 349ecfea99..8912a48708 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3220f36c164dd2edf085c07ea08d617d8438812 \ No newline at end of file +2b7fe8e5b74c3504edd0e3ff78096e357ee1b47c \ No newline at end of file diff --git a/src/test_quota.c b/src/test_quota.c index faf4095559..855f300c30 100644 --- a/src/test_quota.c +++ b/src/test_quota.c @@ -795,6 +795,43 @@ int sqlite3_quota_set( return SQLITE_OK; } +/* +** Bring the named file under quota management. Or if it is already under +** management, update its size. +*/ +int sqlite3_quota_file(const char *zFilename){ + char *zFull; + sqlite3_file *fd; + int rc; + int outFlags = 0; + sqlite3_int64 iSize; + fd = sqlite3_malloc(gQuota.sThisVfs.szOsFile + gQuota.sThisVfs.mxPathname+1); + if( fd==0 ) return SQLITE_NOMEM; + zFull = gQuota.sThisVfs.szOsFile + (char*)fd; + rc = gQuota.pOrigVfs->xFullPathname(gQuota.pOrigVfs, zFilename, + gQuota.sThisVfs.mxPathname+1, zFull); + if( rc==SQLITE_OK ){ + rc = quotaOpen(&gQuota.sThisVfs, zFull, fd, + SQLITE_OPEN_READONLY | SQLITE_OPEN_MAIN_DB, &outFlags); + } + if( rc==SQLITE_OK ){ + quotaFileSize(fd, &iSize); + quotaClose(fd); + }else if( rc==SQLITE_CANTOPEN ){ + quotaGroup *pGroup; + quotaFile *pFile; + quotaEnter(); + pGroup = quotaGroupFind(zFull); + if( pGroup ){ + pFile = quotaFindFile(pGroup, zFull); + if( pFile ) quotaRemoveFile(pFile); + } + quotaLeave(); + } + sqlite3_free(fd); + return rc; +} + /***************************** Test Code ***********************************/ #ifdef SQLITE_TEST @@ -971,6 +1008,32 @@ static int test_quota_set( return TCL_OK; } +/* +** tclcmd: sqlite3_quota_file FILENAME +*/ +static int test_quota_file( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + const char *zFilename; /* File pattern to configure */ + int rc; /* Value returned by quota_file() */ + + /* Process arguments */ + if( objc!=2 ){ + Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); + return TCL_ERROR; + } + zFilename = Tcl_GetString(objv[1]); + + /* Invoke sqlite3_quota_file() */ + rc = sqlite3_quota_file(zFilename); + + Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC); + return TCL_OK; +} + /* ** tclcmd: sqlite3_quota_dump */ @@ -1028,6 +1091,7 @@ int Sqlitequota_Init(Tcl_Interp *interp){ { "sqlite3_quota_initialize", test_quota_initialize }, { "sqlite3_quota_shutdown", test_quota_shutdown }, { "sqlite3_quota_set", test_quota_set }, + { "sqlite3_quota_file", test_quota_file }, { "sqlite3_quota_dump", test_quota_dump }, }; int i; diff --git a/test/quota.test b/test/quota.test index 469bc49016..23ccf89baf 100644 --- a/test/quota.test +++ b/test/quota.test @@ -235,6 +235,13 @@ proc quota_list {} { } return [lsort $allq] } +proc quota_size {name} { + set allq {} + foreach q [sqlite3_quota_dump] { + if {[lindex $q 0]==$name} {return [lindex $q 2]} + } + return 0 +} do_test quota-4.1.1 { sqlite3_quota_set *test.db 0 {} @@ -355,7 +362,73 @@ do_test quota-4.4.3 { do_test quota-4.4.4 { expr {$::quota!=""} } {1} +do_test quota-4.4.5 { + db close + sqlite3_quota_set */quota-test-A?.db 0 {} + sqlite3_quota_dump +} {} +do_test quota-4.4.6 { + sqlite3_quota_set */quota-test-A?.db 10000 quota_callback + sqlite3 db quota-test-A1.db + db eval {SELECT count(*) FROM sqlite_master} + quota_size */quota-test-A?.db +} [file size quota-test-A1.db] +do_test quota-4.4.7 { + sqlite3_quota_file quota-test-A2.db + quota_size */quota-test-A?.db +} [expr {[file size quota-test-A1.db]+[file size quota-test-A2.db]}] +do_test quota-4.5.1 { + foreach file [glob -nocomplain quota-test-B*] { + forcedelete $file + } + sqlite3_quota_set */quota-test-B* 100000 quota_callback + quota_size */quota-test-B* +} {0} +do_test quota-4.5.2 { + sqlite3_quota_file quota-test-B1.txt + quota_size */quota-test-B* +} {0} +proc add_to_file {name n} { + set out [open $name a] + fconfigure $out -translation binary + puts -nonewline $out [string repeat x $n] + close $out +} +do_test quota-4.5.3 { + add_to_file quota-test-B1.txt 123 + sqlite3_quota_file quota-test-B1.txt + quota_size */quota-test-B* +} {123} +do_test quota-4.5.4 { + add_to_file quota-test-B2.txt 234 + sqlite3_quota_file quota-test-B2.txt + quota_size */quota-test-B* +} {357} +do_test quota-4.5.5 { + add_to_file quota-test-B1.txt 2000 + sqlite3_quota_file quota-test-B1.txt + quota_size */quota-test-B* +} {2357} +do_test quota-4.5.6 { + forcedelete quota-test-B1.txt + sqlite3_quota_file quota-test-B1.txt + quota_size */quota-test-B* +} {234} +do_test quota-4.5.7 { + forcedelete quota-test-B2.txt + sqlite3_quota_file quota-test-B2.txt + quota_size */quota-test-B* +} {0} +do_test quota-4.5.8 { + add_to_file quota-test-B3.txt 1234 + sqlite3_quota_file quota-test-B3.txt + quota_size */quota-test-B* +} {1234} +do_test quota-4.5.9 { + sqlite3_quota_set */quota-test-B* 0 {} + quota_size */quota-test-B* +} {0} do_test quota-4.9.1 { db close