1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Add sqlite3_quota_ferror() and sqlite3_quota_file_available() interfaces to

test_quota.c.  Change sqlite3_quota_fwrite() to use a const input buffer.

FossilOrigin-Name: 61669c95859e187618fb2fb4249306a947ae8d26
This commit is contained in:
drh
2012-06-05 13:56:15 +00:00
parent ed46682719
commit 98c78ea63f
5 changed files with 129 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
C Avoid\scalling\sfchown()\sif\sthe\sprocess\sis\snot\srunning\sas\sroot. C Add\ssqlite3_quota_ferror()\sand\ssqlite3_quota_file_available()\sinterfaces\sto\ntest_quota.c.\s\sChange\ssqlite3_quota_fwrite()\sto\suse\sa\sconst\sinput\sbuffer.
D 2012-05-31T13:10:49.376 D 2012-06-05T13:56:15.352
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 4f37eb61be9d38643cdd839a74b8e3bad724cfcf F Makefile.in 4f37eb61be9d38643cdd839a74b8e3bad724cfcf
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -218,8 +218,8 @@ F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e
F src/test_onefile.c 0396f220561f3b4eedc450cef26d40c593c69a25 F src/test_onefile.c 0396f220561f3b4eedc450cef26d40c593c69a25
F src/test_osinst.c 90a845c8183013d80eccb1f29e8805608516edba F src/test_osinst.c 90a845c8183013d80eccb1f29e8805608516edba
F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00 F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00
F src/test_quota.c 47cb7b606160ce8f603a7d47143dd1f74de09058 F src/test_quota.c 0af3e1e9a1f22bc5f431dd3efcc32762f4109f58
F src/test_quota.h ee5da2ae7f84d1c8e0e0e2ab33f01d69f10259b5 F src/test_quota.h 8761e463b25e75ebc078bd67d70e39b9c817a0cb
F src/test_rtree.c aba603c949766c4193f1068b91c787f57274e0d9 F src/test_rtree.c aba603c949766c4193f1068b91c787f57274e0d9
F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0 F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
F src/test_server.c 2f99eb2837dfa06a4aacf24af24c6affdf66a84f F src/test_server.c 2f99eb2837dfa06a4aacf24af24c6affdf66a84f
@@ -651,7 +651,7 @@ F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quick.test 1681febc928d686362d50057c642f77a02c62e57
F test/quota-glob.test 32901e9eed6705d68ca3faee2a06b73b57cb3c26 F test/quota-glob.test 32901e9eed6705d68ca3faee2a06b73b57cb3c26
F test/quota.test c2f778dab4c7fb07bcfa962cc5c762f36d8061dc F test/quota.test c2f778dab4c7fb07bcfa962cc5c762f36d8061dc
F test/quota2.test bc9fdb2e46aace691c1a01a9cc8d097bd4d7c1ab F test/quota2.test 52175f1c94fb01711da38095a7d3988d0c7d6575
F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459
F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df
@@ -1004,7 +1004,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings-clang.sh a8a0a3babda96dfb1ff51adda3cbbf3dfb7266c2 F tool/warnings-clang.sh a8a0a3babda96dfb1ff51adda3cbbf3dfb7266c2
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
P 07935d10d341fe6265cfd3b09e2c4ef4005c4826 P 70c419a434be77b042a23174483d6a411899eb5d
R db0f48be730e02610af744a3fe432e51 R 6f34bdd03e1922ea3b6cb56fd9309a2c
U drh U drh
Z a3e118b76a7afa02078e1c319e3927b5 Z 1b017ff1370375c5086bff54a1d45078

View File

@@ -1 +1 @@
70c419a434be77b042a23174483d6a411899eb5d 61669c95859e187618fb2fb4249306a947ae8d26

View File

@@ -1042,7 +1042,7 @@ size_t sqlite3_quota_fread(
** the write if we exceed quota. ** the write if we exceed quota.
*/ */
size_t sqlite3_quota_fwrite( size_t sqlite3_quota_fwrite(
void *pBuf, /* Take content to write from here */ const void *pBuf, /* Take content to write from here */
size_t size, /* Size of each element */ size_t size, /* Size of each element */
size_t nmemb, /* Number of elements */ size_t nmemb, /* Number of elements */
quota_FILE *p /* Write to this quota_FILE objecct */ quota_FILE *p /* Write to this quota_FILE objecct */
@@ -1052,7 +1052,7 @@ size_t sqlite3_quota_fwrite(
sqlite3_int64 szNew; sqlite3_int64 szNew;
quotaFile *pFile; quotaFile *pFile;
size_t rc; size_t rc;
iOfst = ftell(p->f); iOfst = ftell(p->f);
iEnd = iOfst + size*nmemb; iEnd = iOfst + size*nmemb;
pFile = p->pFile; pFile = p->pFile;
@@ -1091,7 +1091,7 @@ size_t sqlite3_quota_fwrite(
pFile->iSize = iNewEnd; pFile->iSize = iNewEnd;
quotaLeave(); quotaLeave();
} }
return rc; return rc;
} }
/* /*
@@ -1160,6 +1160,13 @@ long sqlite3_quota_ftell(quota_FILE *p){
return ftell(p->f); return ftell(p->f);
} }
/*
** Test the error indicator for the given file.
*/
int sqlite3_quota_ferror(quota_FILE *p){
return ferror(p->f);
}
/* /*
** Truncate a file to szNew bytes. ** Truncate a file to szNew bytes.
*/ */
@@ -1236,6 +1243,25 @@ sqlite3_int64 sqlite3_quota_file_truesize(quota_FILE *p){
sqlite3_int64 sqlite3_quota_file_size(quota_FILE *p){ sqlite3_int64 sqlite3_quota_file_size(quota_FILE *p){
return p->pFile ? p->pFile->iSize : -1; return p->pFile ? p->pFile->iSize : -1;
} }
/*
** Determine the amount of data in bytes available for reading
** in the given file.
*/
long sqlite3_quota_file_available(quota_FILE *p){
FILE* f = p->f;
long pos1, pos2;
int rc;
pos1 = ftell(f);
if ( pos1 < 0 ) return -1;
rc = fseek(f, 0, SEEK_END);
if ( rc != 0 ) return -1;
pos2 = ftell(f);
if ( pos2 < 0 ) return -1;
rc = fseek(f, pos1, SEEK_SET);
if ( rc != 0 ) return -1;
return pos2 - pos1;
}
/* /*
** Remove a managed file. Update quotas accordingly. ** Remove a managed file. Update quotas accordingly.
@@ -1895,6 +1921,53 @@ static int test_quota_glob(
return TCL_OK; return TCL_OK;
} }
/*
** tclcmd: sqlite3_quota_file_available HANDLE
**
** Return the number of bytes from the current file point to the end of
** the file.
*/
static int test_quota_file_available(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
quota_FILE *p;
sqlite3_int64 x;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
return TCL_ERROR;
}
p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
x = sqlite3_quota_file_available(p);
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
return TCL_OK;
}
/*
** tclcmd: sqlite3_quota_ferror HANDLE
**
** Return true if the file handle is in the error state.
*/
static int test_quota_ferror(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
quota_FILE *p;
int x;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
return TCL_ERROR;
}
p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
x = sqlite3_quota_ferror(p);
Tcl_SetObjResult(interp, Tcl_NewIntObj(x));
return TCL_OK;
}
/* /*
** This routine registers the custom TCL commands defined in this ** This routine registers the custom TCL commands defined in this
** module. This should be the only procedure visible from outside ** module. This should be the only procedure visible from outside
@@ -1924,6 +1997,8 @@ int Sqlitequota_Init(Tcl_Interp *interp){
{ "sqlite3_quota_file_mtime", test_quota_file_mtime }, { "sqlite3_quota_file_mtime", test_quota_file_mtime },
{ "sqlite3_quota_remove", test_quota_remove }, { "sqlite3_quota_remove", test_quota_remove },
{ "sqlite3_quota_glob", test_quota_glob }, { "sqlite3_quota_glob", test_quota_glob },
{ "sqlite3_quota_file_available",test_quota_file_available },
{ "sqlite3_quota_ferror", test_quota_ferror },
}; };
int i; int i;

View File

@@ -162,7 +162,7 @@ quota_FILE *sqlite3_quota_fopen(const char *zFilename, const char *zMode);
** the sum of sizes of all files from going over quota. ** the sum of sizes of all files from going over quota.
*/ */
size_t sqlite3_quota_fread(void*, size_t, size_t, quota_FILE*); size_t sqlite3_quota_fread(void*, size_t, size_t, quota_FILE*);
size_t sqlite3_quota_fwrite(void*, size_t, size_t, quota_FILE*); size_t sqlite3_quota_fwrite(const void*, size_t, size_t, quota_FILE*);
/* /*
** Flush all written content held in memory buffers out to disk. ** Flush all written content held in memory buffers out to disk.
@@ -190,6 +190,13 @@ int sqlite3_quota_fseek(quota_FILE*, long, int);
void sqlite3_quota_rewind(quota_FILE*); void sqlite3_quota_rewind(quota_FILE*);
long sqlite3_quota_ftell(quota_FILE*); long sqlite3_quota_ftell(quota_FILE*);
/*
** Test the error indicator for the given file.
**
** Return non-zero if the error indicator is set.
*/
int sqlite3_quota_ferror(quota_FILE*);
/* /*
** Truncate a file previously opened by sqlite3_quota_fopen(). Return ** Truncate a file previously opened by sqlite3_quota_fopen(). Return
** zero on success and non-zero on any kind of failure. ** zero on success and non-zero on any kind of failure.
@@ -198,7 +205,7 @@ long sqlite3_quota_ftell(quota_FILE*);
** Any attempt to "truncate" a file to a larger size results in ** Any attempt to "truncate" a file to a larger size results in
** undefined behavior. ** undefined behavior.
*/ */
int sqlite3_quota_ftrunate(quota_FILE*, sqlite3_int64 newSize); int sqlite3_quota_ftruncate(quota_FILE*, sqlite3_int64 newSize);
/* /*
** Return the last modification time of the opened file, in seconds ** Return the last modification time of the opened file, in seconds
@@ -232,6 +239,14 @@ sqlite3_int64 sqlite3_quota_file_size(quota_FILE*);
*/ */
sqlite3_int64 sqlite3_quota_file_truesize(quota_FILE*); sqlite3_int64 sqlite3_quota_file_truesize(quota_FILE*);
/*
** Determine the amount of data in bytes available for reading
** in the given file.
**
** Return -1 if the amount cannot be determined for some reason.
*/
long sqlite3_quota_file_available(quota_FILE*);
/* /*
** Delete a file from the disk, if that file is under quota management. ** Delete a file from the disk, if that file is under quota management.
** Adjust quotas accordingly. ** Adjust quotas accordingly.

View File

@@ -164,11 +164,17 @@ do_test quota2-2.1 {
do_test quota2-2.2 { do_test quota2-2.2 {
set ::quota set ::quota
} {} } {}
do_test quota2-2.3 { do_test quota2-2.3.1 {
sqlite3_quota_rewind $::h1 sqlite3_quota_rewind $::h1
sqlite3_quota_file_available $::h1
} {7000}
do_test quota2-2.3.2 {
set ::x [sqlite3_quota_fread $::h1 1001 7] set ::x [sqlite3_quota_fread $::h1 1001 7]
string length $::x string length $::x
} {6006} } {6006}
do_test quota2-2.3.3 {
sqlite3_quota_file_available $::h1
} {0}
do_test quota2-2.4 { do_test quota2-2.4 {
string match $::x [string range $::bigtext 0 6005] string match $::x [string range $::bigtext 0 6005]
} {1} } {1}
@@ -180,22 +186,40 @@ do_test quota2-2.6 {
sqlite3_quota_fseek $::h1 -100 SEEK_END sqlite3_quota_fseek $::h1 -100 SEEK_END
sqlite3_quota_ftell $::h1 sqlite3_quota_ftell $::h1
} {6900} } {6900}
do_test quota2-2.6.1 {
sqlite3_quota_file_available $::h1
} {100}
do_test quota2-2.7 { do_test quota2-2.7 {
sqlite3_quota_fseek $::h1 -100 SEEK_CUR sqlite3_quota_fseek $::h1 -100 SEEK_CUR
sqlite3_quota_ftell $::h1 sqlite3_quota_ftell $::h1
} {6800} } {6800}
do_test quota2-2.7.1 {
sqlite3_quota_file_available $::h1
} {200}
do_test quota2-2.8 { do_test quota2-2.8 {
sqlite3_quota_fseek $::h1 50 SEEK_CUR sqlite3_quota_fseek $::h1 50 SEEK_CUR
sqlite3_quota_ftell $::h1 sqlite3_quota_ftell $::h1
} {6850} } {6850}
do_test quota2-2.8.1 {
sqlite3_quota_file_available $::h1
} {150}
do_test quota2-2.9 { do_test quota2-2.9 {
sqlite3_quota_fseek $::h1 50 SEEK_SET sqlite3_quota_fseek $::h1 50 SEEK_SET
sqlite3_quota_ftell $::h1 sqlite3_quota_ftell $::h1
} {50} } {50}
do_test quota2-2.9.1 {
sqlite3_quota_file_available $::h1
} {6950}
do_test quota2-2.10 { do_test quota2-2.10 {
sqlite3_quota_rewind $::h1 sqlite3_quota_rewind $::h1
sqlite3_quota_ftell $::h1 sqlite3_quota_ftell $::h1
} {0} } {0}
do_test quota2-2.10.1 {
sqlite3_quota_file_available $::h1
} {7000}
do_test quota2-2.10.2 {
sqlite3_quota_ferror $::h1
} {0}
do_test quota2-2.11 { do_test quota2-2.11 {
standard_path [sqlite3_quota_dump] standard_path [sqlite3_quota_dump]
} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}} } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}