/ Check-in [2b7fe8e5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the sqlite3_quota_file() interface to test_quota.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2b7fe8e5b74c3504edd0e3ff78096e357ee1b47c
User & Date: drh 2011-08-25 01:42:12
Context
2011-08-25
01:58
Cherrypick the [d4f6437f8d] change so that SQLITE_FCNTL_SIZE_HINT is always honored and never undone by memory pressure on windows. check-in: 67ff8d27 user: drh tags: trunk
01:42
Add the sqlite3_quota_file() interface to test_quota.c. check-in: 2b7fe8e5 user: drh tags: trunk
00:14
Add the SQLITE_EXTRA_INIT macro. check-in: a3220f36 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/test_quota.c.

   790    790     }
   791    791     pGroup->pArg = pArg;
   792    792     pGroup->xDestroy = xDestroy;
   793    793     quotaGroupDeref(pGroup);
   794    794     quotaLeave();
   795    795     return SQLITE_OK;
   796    796   }
          797  +
          798  +/*
          799  +** Bring the named file under quota management.  Or if it is already under
          800  +** management, update its size.
          801  +*/
          802  +int sqlite3_quota_file(const char *zFilename){
          803  +  char *zFull;
          804  +  sqlite3_file *fd;
          805  +  int rc;
          806  +  int outFlags = 0;
          807  +  sqlite3_int64 iSize;
          808  +  fd = sqlite3_malloc(gQuota.sThisVfs.szOsFile + gQuota.sThisVfs.mxPathname+1);
          809  +  if( fd==0 ) return SQLITE_NOMEM;
          810  +  zFull = gQuota.sThisVfs.szOsFile + (char*)fd;
          811  +  rc = gQuota.pOrigVfs->xFullPathname(gQuota.pOrigVfs, zFilename,
          812  +                                      gQuota.sThisVfs.mxPathname+1, zFull);
          813  +  if( rc==SQLITE_OK ){
          814  +    rc = quotaOpen(&gQuota.sThisVfs, zFull, fd, 
          815  +                   SQLITE_OPEN_READONLY | SQLITE_OPEN_MAIN_DB, &outFlags);
          816  +  }
          817  +  if( rc==SQLITE_OK ){
          818  +    quotaFileSize(fd, &iSize);
          819  +    quotaClose(fd);
          820  +  }else if( rc==SQLITE_CANTOPEN ){
          821  +    quotaGroup *pGroup;
          822  +    quotaFile *pFile;
          823  +    quotaEnter();
          824  +    pGroup = quotaGroupFind(zFull);
          825  +    if( pGroup ){
          826  +      pFile = quotaFindFile(pGroup, zFull);
          827  +      if( pFile ) quotaRemoveFile(pFile);
          828  +    }
          829  +    quotaLeave();
          830  +  }
          831  +  sqlite3_free(fd);
          832  +  return rc;
          833  +}
   797    834   
   798    835     
   799    836   /***************************** Test Code ***********************************/
   800    837   #ifdef SQLITE_TEST
   801    838   #include <tcl.h>
   802    839   
   803    840   /*
................................................................................
   966   1003   
   967   1004     /* Invoke sqlite3_quota_set() */
   968   1005     rc = sqlite3_quota_set(zPattern, iLimit, xCallback, (void*)p, xDestroy);
   969   1006   
   970   1007     Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
   971   1008     return TCL_OK;
   972   1009   }
         1010  +
         1011  +/*
         1012  +** tclcmd: sqlite3_quota_file FILENAME
         1013  +*/
         1014  +static int test_quota_file(
         1015  +  void * clientData,
         1016  +  Tcl_Interp *interp,
         1017  +  int objc,
         1018  +  Tcl_Obj *CONST objv[]
         1019  +){
         1020  +  const char *zFilename;          /* File pattern to configure */
         1021  +  int rc;                         /* Value returned by quota_file() */
         1022  +
         1023  +  /* Process arguments */
         1024  +  if( objc!=2 ){
         1025  +    Tcl_WrongNumArgs(interp, 1, objv, "FILENAME");
         1026  +    return TCL_ERROR;
         1027  +  }
         1028  +  zFilename = Tcl_GetString(objv[1]);
         1029  +
         1030  +  /* Invoke sqlite3_quota_file() */
         1031  +  rc = sqlite3_quota_file(zFilename);
         1032  +
         1033  +  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1034  +  return TCL_OK;
         1035  +}
   973   1036   
   974   1037   /*
   975   1038   ** tclcmd:  sqlite3_quota_dump
   976   1039   */
   977   1040   static int test_quota_dump(
   978   1041     void * clientData,
   979   1042     Tcl_Interp *interp,
................................................................................
  1024   1087     static struct {
  1025   1088        char *zName;
  1026   1089        Tcl_ObjCmdProc *xProc;
  1027   1090     } aCmd[] = {
  1028   1091       { "sqlite3_quota_initialize", test_quota_initialize },
  1029   1092       { "sqlite3_quota_shutdown", test_quota_shutdown },
  1030   1093       { "sqlite3_quota_set", test_quota_set },
         1094  +    { "sqlite3_quota_file", test_quota_file },
  1031   1095       { "sqlite3_quota_dump", test_quota_dump },
  1032   1096     };
  1033   1097     int i;
  1034   1098   
  1035   1099     for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
  1036   1100       Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
  1037   1101     }
  1038   1102   
  1039   1103     return TCL_OK;
  1040   1104   }
  1041   1105   #endif

Changes to test/quota.test.

   231    231   proc quota_list {} {
   232    232     set allq {}
   233    233     foreach q [sqlite3_quota_dump] {
   234    234       lappend allq [lindex $q 0]
   235    235     }
   236    236     return [lsort $allq]
   237    237   }
          238  +proc quota_size {name} {
          239  +  set allq {}
          240  +  foreach q [sqlite3_quota_dump] {
          241  +    if {[lindex $q 0]==$name} {return [lindex $q 2]}
          242  +  }
          243  +  return 0
          244  +}
   238    245   
   239    246   do_test quota-4.1.1 {
   240    247     sqlite3_quota_set *test.db 0 {}
   241    248     quota_list
   242    249   } {}
   243    250   do_test quota-4.1.2 {
   244    251     sqlite3_quota_set *test.db 4096 {}
................................................................................
   351    358        INSERT INTO t1 VALUES(randomblob(5000));
   352    359     }
   353    360     quota_list
   354    361   } {*/quota-test-A?.db}
   355    362   do_test quota-4.4.4 {
   356    363     expr {$::quota!=""}
   357    364   } {1}
          365  +do_test quota-4.4.5 {
          366  +  db close
          367  +  sqlite3_quota_set */quota-test-A?.db 0 {}
          368  +  sqlite3_quota_dump
          369  +} {}
          370  +do_test quota-4.4.6 {
          371  +  sqlite3_quota_set */quota-test-A?.db 10000 quota_callback
          372  +  sqlite3 db quota-test-A1.db
          373  +  db eval {SELECT count(*) FROM sqlite_master}
          374  +  quota_size */quota-test-A?.db
          375  +} [file size quota-test-A1.db]
          376  +do_test quota-4.4.7 {
          377  +  sqlite3_quota_file quota-test-A2.db
          378  +  quota_size */quota-test-A?.db
          379  +} [expr {[file size quota-test-A1.db]+[file size quota-test-A2.db]}]
   358    380   
          381  +do_test quota-4.5.1 {
          382  +  foreach file [glob -nocomplain quota-test-B*] {
          383  +    forcedelete $file
          384  +  }
          385  +  sqlite3_quota_set */quota-test-B* 100000 quota_callback
          386  +  quota_size */quota-test-B*
          387  +} {0}
          388  +do_test quota-4.5.2 {
          389  +  sqlite3_quota_file quota-test-B1.txt
          390  +  quota_size */quota-test-B*
          391  +} {0}
          392  +proc add_to_file {name n} {
          393  +  set out [open $name a]
          394  +  fconfigure $out -translation binary
          395  +  puts -nonewline $out [string repeat x $n]
          396  +  close $out
          397  +}
          398  +do_test quota-4.5.3 {
          399  +  add_to_file quota-test-B1.txt 123
          400  +  sqlite3_quota_file quota-test-B1.txt
          401  +  quota_size */quota-test-B*
          402  +} {123}
          403  +do_test quota-4.5.4 {
          404  +  add_to_file quota-test-B2.txt 234
          405  +  sqlite3_quota_file quota-test-B2.txt
          406  +  quota_size */quota-test-B*
          407  +} {357}
          408  +do_test quota-4.5.5 {
          409  +  add_to_file quota-test-B1.txt 2000
          410  +  sqlite3_quota_file quota-test-B1.txt
          411  +  quota_size */quota-test-B*
          412  +} {2357}
          413  +do_test quota-4.5.6 {
          414  +  forcedelete quota-test-B1.txt
          415  +  sqlite3_quota_file quota-test-B1.txt
          416  +  quota_size */quota-test-B*
          417  +} {234}
          418  +do_test quota-4.5.7 {
          419  +  forcedelete quota-test-B2.txt
          420  +  sqlite3_quota_file quota-test-B2.txt
          421  +  quota_size */quota-test-B*
          422  +} {0}
          423  +do_test quota-4.5.8 {
          424  +  add_to_file quota-test-B3.txt 1234
          425  +  sqlite3_quota_file quota-test-B3.txt
          426  +  quota_size */quota-test-B*
          427  +} {1234}
          428  +do_test quota-4.5.9 {
          429  +  sqlite3_quota_set */quota-test-B* 0 {}
          430  +  quota_size */quota-test-B*
          431  +} {0}
   359    432   
   360    433   do_test quota-4.9.1 {
   361    434     db close
   362    435     sqlite3_quota_set A 1000 quota_callback
   363    436     sqlite3_quota_shutdown
   364    437   } {SQLITE_OK}
   365    438   do_test quota-4.9.2 {