Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/sqlite/src/src/test_quota.c

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/src/test_osinst.c ('k') | third_party/sqlite/src/src/test_rtree.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2010 September 31 2 ** 2010 September 31
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 char *zFilename; /* Name of this file */ 104 char *zFilename; /* Name of this file */
105 quotaGroup *pGroup; /* Quota group to which this file belongs */ 105 quotaGroup *pGroup; /* Quota group to which this file belongs */
106 sqlite3_int64 iSize; /* Current size of this file */ 106 sqlite3_int64 iSize; /* Current size of this file */
107 int nRef; /* Number of times this file is open */ 107 int nRef; /* Number of times this file is open */
108 int deleteOnClose; /* True to delete this file when it closes */ 108 int deleteOnClose; /* True to delete this file when it closes */
109 quotaFile *pNext, **ppPrev; /* Linked list of files in the same group */ 109 quotaFile *pNext, **ppPrev; /* Linked list of files in the same group */
110 }; 110 };
111 111
112 /* 112 /*
113 ** An instance of the following object represents each open connection 113 ** An instance of the following object represents each open connection
114 ** to a file that participates in quota tracking. This object is a 114 ** to a file that participates in quota tracking. This object is a
115 ** subclass of sqlite3_file. The sqlite3_file object for the underlying 115 ** subclass of sqlite3_file. The sqlite3_file object for the underlying
116 ** VFS is appended to this structure. 116 ** VFS is appended to this structure.
117 */ 117 */
118 struct quotaConn { 118 struct quotaConn {
119 sqlite3_file base; /* Base class - must be first */ 119 sqlite3_file base; /* Base class - must be first */
120 quotaFile *pFile; /* The underlying file */ 120 quotaFile *pFile; /* The underlying file */
121 /* The underlying VFS sqlite3_file is appended to this object */ 121 /* The underlying VFS sqlite3_file is appended to this object */
122 }; 122 };
123 123
124 /* 124 /*
(...skipping 22 matching lines...) Expand all
147 ** during operation. It is only modified at start-time and thus does not 147 ** during operation. It is only modified at start-time and thus does not
148 ** require a mutex. 148 ** require a mutex.
149 */ 149 */
150 sqlite3_vfs *pOrigVfs; 150 sqlite3_vfs *pOrigVfs;
151 151
152 /* The sThisVfs is the VFS structure used by this shim. It is initialized 152 /* The sThisVfs is the VFS structure used by this shim. It is initialized
153 ** at start-time and thus does not require a mutex 153 ** at start-time and thus does not require a mutex
154 */ 154 */
155 sqlite3_vfs sThisVfs; 155 sqlite3_vfs sThisVfs;
156 156
157 /* The sIoMethods defines the methods used by sqlite3_file objects 157 /* The sIoMethods defines the methods used by sqlite3_file objects
158 ** associated with this shim. It is initialized at start-time and does 158 ** associated with this shim. It is initialized at start-time and does
159 ** not require a mutex. 159 ** not require a mutex.
160 ** 160 **
161 ** When the underlying VFS is called to open a file, it might return 161 ** When the underlying VFS is called to open a file, it might return
162 ** either a version 1 or a version 2 sqlite3_file object. This shim 162 ** either a version 1 or a version 2 sqlite3_file object. This shim
163 ** has to create a wrapper sqlite3_file of the same version. Hence 163 ** has to create a wrapper sqlite3_file of the same version. Hence
164 ** there are two I/O method structures, one for version 1 and the other 164 ** there are two I/O method structures, one for version 1 and the other
165 ** for version 2. 165 ** for version 2.
166 */ 166 */
167 sqlite3_io_methods sIoMethodsV1; 167 sqlite3_io_methods sIoMethodsV1;
168 sqlite3_io_methods sIoMethodsV2; 168 sqlite3_io_methods sIoMethodsV2;
169 169
170 /* True when this shim as been initialized. 170 /* True when this shim as been initialized.
171 */ 171 */
(...skipping 11 matching lines...) Expand all
183 } gQuota; 183 } gQuota;
184 184
185 /************************* Utility Routines *********************************/ 185 /************************* Utility Routines *********************************/
186 /* 186 /*
187 ** Acquire and release the mutex used to serialize access to the 187 ** Acquire and release the mutex used to serialize access to the
188 ** list of quotaGroups. 188 ** list of quotaGroups.
189 */ 189 */
190 static void quotaEnter(void){ sqlite3_mutex_enter(gQuota.pMutex); } 190 static void quotaEnter(void){ sqlite3_mutex_enter(gQuota.pMutex); }
191 static void quotaLeave(void){ sqlite3_mutex_leave(gQuota.pMutex); } 191 static void quotaLeave(void){ sqlite3_mutex_leave(gQuota.pMutex); }
192 192
193 /* Count the number of open files in a quotaGroup 193 /* Count the number of open files in a quotaGroup
194 */ 194 */
195 static int quotaGroupOpenFileCount(quotaGroup *pGroup){ 195 static int quotaGroupOpenFileCount(quotaGroup *pGroup){
196 int N = 0; 196 int N = 0;
197 quotaFile *pFile = pGroup->pFiles; 197 quotaFile *pFile = pGroup->pFiles;
198 while( pFile ){ 198 while( pFile ){
199 if( pFile->nRef ) N++; 199 if( pFile->nRef ) N++;
200 pFile = pFile->pNext; 200 pFile = pFile->pNext;
201 } 201 }
202 return N; 202 return N;
203 } 203 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; 392 codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
393 nMbcs = WideCharToMultiByte(codepage, 0, zTmpWide, nWide, 0, 0, 0, 0); 393 nMbcs = WideCharToMultiByte(codepage, 0, zTmpWide, nWide, 0, 0, 0, 0);
394 zMbcs = nMbcs ? (char*)sqlite3_malloc( nMbcs+1 ) : 0; 394 zMbcs = nMbcs ? (char*)sqlite3_malloc( nMbcs+1 ) : 0;
395 if( zMbcs ){ 395 if( zMbcs ){
396 WideCharToMultiByte(codepage, 0, zTmpWide, nWide, zMbcs, nMbcs, 0, 0); 396 WideCharToMultiByte(codepage, 0, zTmpWide, nWide, zMbcs, nMbcs, 0, 0);
397 } 397 }
398 sqlite3_free(zTmpWide); 398 sqlite3_free(zTmpWide);
399 return zMbcs; 399 return zMbcs;
400 #else 400 #else
401 return (char*)zUtf8; /* No-op on unix */ 401 return (char*)zUtf8; /* No-op on unix */
402 #endif 402 #endif
403 } 403 }
404 404
405 /* 405 /*
406 ** Deallocate any memory allocated by quota_utf8_to_mbcs(). 406 ** Deallocate any memory allocated by quota_utf8_to_mbcs().
407 */ 407 */
408 static void quota_mbcs_free(char *zOld){ 408 static void quota_mbcs_free(char *zOld){
409 #if SQLITE_OS_WIN 409 #if SQLITE_OS_WIN
410 sqlite3_free(zOld); 410 sqlite3_free(zOld);
411 #else 411 #else
412 /* No-op on unix */ 412 /* No-op on unix */
413 #endif 413 #endif
414 } 414 }
415 415
416 /************************* VFS Method Wrappers *****************************/ 416 /************************* VFS Method Wrappers *****************************/
417 /* 417 /*
418 ** This is the xOpen method used for the "quota" VFS. 418 ** This is the xOpen method used for the "quota" VFS.
419 ** 419 **
420 ** Most of the work is done by the underlying original VFS. This method 420 ** Most of the work is done by the underlying original VFS. This method
421 ** simply links the new file into the appropriate quota group if it is a 421 ** simply links the new file into the appropriate quota group if it is a
422 ** file that needs to be tracked. 422 ** file that needs to be tracked.
423 */ 423 */
424 static int quotaOpen( 424 static int quotaOpen(
425 sqlite3_vfs *pVfs, /* The quota VFS */ 425 sqlite3_vfs *pVfs, /* The quota VFS */
426 const char *zName, /* Name of file to be opened */ 426 const char *zName, /* Name of file to be opened */
427 sqlite3_file *pConn, /* Fill in this file descriptor */ 427 sqlite3_file *pConn, /* Fill in this file descriptor */
428 int flags, /* Flags to control the opening */ 428 int flags, /* Flags to control the opening */
429 int *pOutFlags /* Flags showing results of opening */ 429 int *pOutFlags /* Flags showing results of opening */
430 ){ 430 ){
431 int rc; /* Result code */ 431 int rc; /* Result code */
432 quotaConn *pQuotaOpen; /* The new quota file descriptor */ 432 quotaConn *pQuotaOpen; /* The new quota file descriptor */
433 quotaFile *pFile; /* Corresponding quotaFile obj */ 433 quotaFile *pFile; /* Corresponding quotaFile obj */
434 quotaGroup *pGroup; /* The group file belongs to */ 434 quotaGroup *pGroup; /* The group file belongs to */
435 sqlite3_file *pSubOpen; /* Real file descriptor */ 435 sqlite3_file *pSubOpen; /* Real file descriptor */
436 sqlite3_vfs *pOrigVfs = gQuota.pOrigVfs; /* Real VFS */ 436 sqlite3_vfs *pOrigVfs = gQuota.pOrigVfs; /* Real VFS */
437 437
438 /* If the file is not a main database file or a WAL, then use the 438 /* If the file is not a main database file or a WAL, then use the
439 ** normal xOpen method. 439 ** normal xOpen method.
440 */ 440 */
441 if( (flags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_WAL))==0 ){ 441 if( (flags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_WAL))==0 ){
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 ** 481 **
482 ** If the file being deleted is part of the quota group, then reduce 482 ** If the file being deleted is part of the quota group, then reduce
483 ** the size of the quota group accordingly. And remove the file from 483 ** the size of the quota group accordingly. And remove the file from
484 ** the set of files in the quota group. 484 ** the set of files in the quota group.
485 */ 485 */
486 static int quotaDelete( 486 static int quotaDelete(
487 sqlite3_vfs *pVfs, /* The quota VFS */ 487 sqlite3_vfs *pVfs, /* The quota VFS */
488 const char *zName, /* Name of file to be deleted */ 488 const char *zName, /* Name of file to be deleted */
489 int syncDir /* Do a directory sync after deleting */ 489 int syncDir /* Do a directory sync after deleting */
490 ){ 490 ){
491 int rc; /* Result code */ 491 int rc; /* Result code */
492 quotaFile *pFile; /* Files in the quota */ 492 quotaFile *pFile; /* Files in the quota */
493 quotaGroup *pGroup; /* The group file belongs to */ 493 quotaGroup *pGroup; /* The group file belongs to */
494 sqlite3_vfs *pOrigVfs = gQuota.pOrigVfs; /* Real VFS */ 494 sqlite3_vfs *pOrigVfs = gQuota.pOrigVfs; /* Real VFS */
495 495
496 /* Do the actual file delete */ 496 /* Do the actual file delete */
497 rc = pOrigVfs->xDelete(pOrigVfs, zName, syncDir); 497 rc = pOrigVfs->xDelete(pOrigVfs, zName, syncDir);
498 498
499 /* If the file just deleted is a member of a quota group, then remove 499 /* If the file just deleted is a member of a quota group, then remove
500 ** it from that quota group. 500 ** it from that quota group.
501 */ 501 */
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 quotaGroup *pGroup; 574 quotaGroup *pGroup;
575 quotaFile *pFile = p->pFile; 575 quotaFile *pFile = p->pFile;
576 sqlite3_int64 szNew; 576 sqlite3_int64 szNew;
577 577
578 if( pFile->iSize<iEnd ){ 578 if( pFile->iSize<iEnd ){
579 pGroup = pFile->pGroup; 579 pGroup = pFile->pGroup;
580 quotaEnter(); 580 quotaEnter();
581 szNew = pGroup->iSize - pFile->iSize + iEnd; 581 szNew = pGroup->iSize - pFile->iSize + iEnd;
582 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){ 582 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){
583 if( pGroup->xCallback ){ 583 if( pGroup->xCallback ){
584 pGroup->xCallback(pFile->zFilename, &pGroup->iLimit, szNew, 584 pGroup->xCallback(pFile->zFilename, &pGroup->iLimit, szNew,
585 pGroup->pArg); 585 pGroup->pArg);
586 } 586 }
587 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){ 587 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){
588 quotaLeave(); 588 quotaLeave();
589 return SQLITE_FULL; 589 return SQLITE_FULL;
590 } 590 }
591 } 591 }
592 pGroup->iSize = szNew; 592 pGroup->iSize = szNew;
593 pFile->iSize = iEnd; 593 pFile->iSize = iEnd;
594 quotaLeave(); 594 quotaLeave();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 */ 731 */
732 static int quotaShmUnmap(sqlite3_file *pConn, int deleteFlag){ 732 static int quotaShmUnmap(sqlite3_file *pConn, int deleteFlag){
733 sqlite3_file *pSubOpen = quotaSubOpen(pConn); 733 sqlite3_file *pSubOpen = quotaSubOpen(pConn);
734 return pSubOpen->pMethods->xShmUnmap(pSubOpen, deleteFlag); 734 return pSubOpen->pMethods->xShmUnmap(pSubOpen, deleteFlag);
735 } 735 }
736 736
737 /************************** Public Interfaces *****************************/ 737 /************************** Public Interfaces *****************************/
738 /* 738 /*
739 ** Initialize the quota VFS shim. Use the VFS named zOrigVfsName 739 ** Initialize the quota VFS shim. Use the VFS named zOrigVfsName
740 ** as the VFS that does the actual work. Use the default if 740 ** as the VFS that does the actual work. Use the default if
741 ** zOrigVfsName==NULL. 741 ** zOrigVfsName==NULL.
742 ** 742 **
743 ** The quota VFS shim is named "quota". It will become the default 743 ** The quota VFS shim is named "quota". It will become the default
744 ** VFS if makeDefault is non-zero. 744 ** VFS if makeDefault is non-zero.
745 ** 745 **
746 ** THIS ROUTINE IS NOT THREADSAFE. Call this routine exactly once 746 ** THIS ROUTINE IS NOT THREADSAFE. Call this routine exactly once
747 ** during start-up. 747 ** during start-up.
748 */ 748 */
749 int sqlite3_quota_initialize(const char *zOrigVfsName, int makeDefault){ 749 int sqlite3_quota_initialize(const char *zOrigVfsName, int makeDefault){
750 sqlite3_vfs *pOrigVfs; 750 sqlite3_vfs *pOrigVfs;
751 if( gQuota.isInitialized ) return SQLITE_MISUSE; 751 if( gQuota.isInitialized ) return SQLITE_MISUSE;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if( fd==0 ){ 901 if( fd==0 ){
902 rc = SQLITE_NOMEM; 902 rc = SQLITE_NOMEM;
903 }else{ 903 }else{
904 zFull = &((char *)fd)[gQuota.sThisVfs.szOsFile]; 904 zFull = &((char *)fd)[gQuota.sThisVfs.szOsFile];
905 rc = gQuota.pOrigVfs->xFullPathname(gQuota.pOrigVfs, zFilename, 905 rc = gQuota.pOrigVfs->xFullPathname(gQuota.pOrigVfs, zFilename,
906 gQuota.sThisVfs.mxPathname+1, zFull); 906 gQuota.sThisVfs.mxPathname+1, zFull);
907 } 907 }
908 908
909 if( rc==SQLITE_OK ){ 909 if( rc==SQLITE_OK ){
910 zFull[strlen(zFull)+1] = '\0'; 910 zFull[strlen(zFull)+1] = '\0';
911 rc = quotaOpen(&gQuota.sThisVfs, zFull, fd, 911 rc = quotaOpen(&gQuota.sThisVfs, zFull, fd,
912 SQLITE_OPEN_READONLY | SQLITE_OPEN_MAIN_DB, &outFlags); 912 SQLITE_OPEN_READONLY | SQLITE_OPEN_MAIN_DB, &outFlags);
913 if( rc==SQLITE_OK ){ 913 if( rc==SQLITE_OK ){
914 fd->pMethods->xFileSize(fd, &iSize); 914 fd->pMethods->xFileSize(fd, &iSize);
915 fd->pMethods->xClose(fd); 915 fd->pMethods->xClose(fd);
916 }else if( rc==SQLITE_CANTOPEN ){ 916 }else if( rc==SQLITE_CANTOPEN ){
917 quotaGroup *pGroup; 917 quotaGroup *pGroup;
918 quotaFile *pFile; 918 quotaFile *pFile;
919 quotaEnter(); 919 quotaEnter();
920 pGroup = quotaGroupFind(zFull); 920 pGroup = quotaGroupFind(zFull);
921 if( pGroup ){ 921 if( pGroup ){
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 1009
1010 iOfst = ftell(p->f); 1010 iOfst = ftell(p->f);
1011 iEnd = iOfst + size*nmemb; 1011 iEnd = iOfst + size*nmemb;
1012 pFile = p->pFile; 1012 pFile = p->pFile;
1013 if( pFile && pFile->iSize<iEnd ){ 1013 if( pFile && pFile->iSize<iEnd ){
1014 quotaGroup *pGroup = pFile->pGroup; 1014 quotaGroup *pGroup = pFile->pGroup;
1015 quotaEnter(); 1015 quotaEnter();
1016 szNew = pGroup->iSize - pFile->iSize + iEnd; 1016 szNew = pGroup->iSize - pFile->iSize + iEnd;
1017 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){ 1017 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){
1018 if( pGroup->xCallback ){ 1018 if( pGroup->xCallback ){
1019 pGroup->xCallback(pFile->zFilename, &pGroup->iLimit, szNew, 1019 pGroup->xCallback(pFile->zFilename, &pGroup->iLimit, szNew,
1020 pGroup->pArg); 1020 pGroup->pArg);
1021 } 1021 }
1022 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){ 1022 if( szNew>pGroup->iLimit && pGroup->iLimit>0 ){
1023 iEnd = pGroup->iLimit - pGroup->iSize + pFile->iSize; 1023 iEnd = pGroup->iLimit - pGroup->iSize + pFile->iSize;
1024 nmemb = (size_t)((iEnd - iOfst)/size); 1024 nmemb = (size_t)((iEnd - iOfst)/size);
1025 iEnd = iOfst + size*nmemb; 1025 iEnd = iOfst + size*nmemb;
1026 szNew = pGroup->iSize - pFile->iSize + iEnd; 1026 szNew = pGroup->iSize - pFile->iSize + iEnd;
1027 } 1027 }
1028 } 1028 }
1029 pGroup->iSize = szNew; 1029 pGroup->iSize = szNew;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 #endif 1196 #endif
1197 return rc==0 ? buf.st_size : -1; 1197 return rc==0 ? buf.st_size : -1;
1198 } 1198 }
1199 1199
1200 /* 1200 /*
1201 ** Return the size of the file, as it is known to the quota subsystem. 1201 ** Return the size of the file, as it is known to the quota subsystem.
1202 */ 1202 */
1203 sqlite3_int64 sqlite3_quota_file_size(quota_FILE *p){ 1203 sqlite3_int64 sqlite3_quota_file_size(quota_FILE *p){
1204 return p->pFile ? p->pFile->iSize : -1; 1204 return p->pFile ? p->pFile->iSize : -1;
1205 } 1205 }
1206 1206
1207 /* 1207 /*
1208 ** Determine the amount of data in bytes available for reading 1208 ** Determine the amount of data in bytes available for reading
1209 ** in the given file. 1209 ** in the given file.
1210 */ 1210 */
1211 long sqlite3_quota_file_available(quota_FILE *p){ 1211 long sqlite3_quota_file_available(quota_FILE *p){
1212 FILE* f = p->f; 1212 FILE* f = p->f;
1213 long pos1, pos2; 1213 long pos1, pos2;
1214 int rc; 1214 int rc;
1215 pos1 = ftell(f); 1215 pos1 = ftell(f);
1216 if ( pos1 < 0 ) return -1; 1216 if ( pos1 < 0 ) return -1;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 quotaRemoveFile(pFile); 1268 quotaRemoveFile(pFile);
1269 quotaGroupDeref(pGroup); 1269 quotaGroupDeref(pGroup);
1270 } 1270 }
1271 } 1271 }
1272 } 1272 }
1273 } 1273 }
1274 quotaLeave(); 1274 quotaLeave();
1275 sqlite3_free(zFull); 1275 sqlite3_free(zFull);
1276 return rc; 1276 return rc;
1277 } 1277 }
1278 1278
1279 /***************************** Test Code ***********************************/ 1279 /***************************** Test Code ***********************************/
1280 #ifdef SQLITE_TEST 1280 #ifdef SQLITE_TEST
1281 #include <tcl.h> 1281 #if defined(INCLUDE_SQLITE_TCL_H)
1282 # include "sqlite_tcl.h"
1283 #else
1284 # include "tcl.h"
1285 # ifndef SQLITE_TCLAPI
1286 # define SQLITE_TCLAPI
1287 # endif
1288 #endif
1282 1289
1283 /* 1290 /*
1284 ** Argument passed to a TCL quota-over-limit callback. 1291 ** Argument passed to a TCL quota-over-limit callback.
1285 */ 1292 */
1286 typedef struct TclQuotaCallback TclQuotaCallback; 1293 typedef struct TclQuotaCallback TclQuotaCallback;
1287 struct TclQuotaCallback { 1294 struct TclQuotaCallback {
1288 Tcl_Interp *interp; /* Interpreter in which to run the script */ 1295 Tcl_Interp *interp; /* Interpreter in which to run the script */
1289 Tcl_Obj *pScript; /* Script to be run */ 1296 Tcl_Obj *pScript; /* Script to be run */
1290 }; 1297 };
1291 1298
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 TclQuotaCallback *p = (TclQuotaCallback*)pObj; 1350 TclQuotaCallback *p = (TclQuotaCallback*)pObj;
1344 if( p ){ 1351 if( p ){
1345 Tcl_DecrRefCount(p->pScript); 1352 Tcl_DecrRefCount(p->pScript);
1346 sqlite3_free((char *)p); 1353 sqlite3_free((char *)p);
1347 } 1354 }
1348 } 1355 }
1349 1356
1350 /* 1357 /*
1351 ** tclcmd: sqlite3_quota_initialize NAME MAKEDEFAULT 1358 ** tclcmd: sqlite3_quota_initialize NAME MAKEDEFAULT
1352 */ 1359 */
1353 static int test_quota_initialize( 1360 static int SQLITE_TCLAPI test_quota_initialize(
1354 void * clientData, 1361 void * clientData,
1355 Tcl_Interp *interp, 1362 Tcl_Interp *interp,
1356 int objc, 1363 int objc,
1357 Tcl_Obj *CONST objv[] 1364 Tcl_Obj *CONST objv[]
1358 ){ 1365 ){
1359 const char *zName; /* Name of new quota VFS */ 1366 const char *zName; /* Name of new quota VFS */
1360 int makeDefault; /* True to make the new VFS the default */ 1367 int makeDefault; /* True to make the new VFS the default */
1361 int rc; /* Value returned by quota_initialize() */ 1368 int rc; /* Value returned by quota_initialize() */
1362 1369
1363 /* Process arguments */ 1370 /* Process arguments */
1364 if( objc!=3 ){ 1371 if( objc!=3 ){
1365 Tcl_WrongNumArgs(interp, 1, objv, "NAME MAKEDEFAULT"); 1372 Tcl_WrongNumArgs(interp, 1, objv, "NAME MAKEDEFAULT");
1366 return TCL_ERROR; 1373 return TCL_ERROR;
1367 } 1374 }
1368 zName = Tcl_GetString(objv[1]); 1375 zName = Tcl_GetString(objv[1]);
1369 if( Tcl_GetBooleanFromObj(interp, objv[2], &makeDefault) ) return TCL_ERROR; 1376 if( Tcl_GetBooleanFromObj(interp, objv[2], &makeDefault) ) return TCL_ERROR;
1370 if( zName[0]=='\0' ) zName = 0; 1377 if( zName[0]=='\0' ) zName = 0;
1371 1378
1372 /* Call sqlite3_quota_initialize() */ 1379 /* Call sqlite3_quota_initialize() */
1373 rc = sqlite3_quota_initialize(zName, makeDefault); 1380 rc = sqlite3_quota_initialize(zName, makeDefault);
1374 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); 1381 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
1375 1382
1376 return TCL_OK; 1383 return TCL_OK;
1377 } 1384 }
1378 1385
1379 /* 1386 /*
1380 ** tclcmd: sqlite3_quota_shutdown 1387 ** tclcmd: sqlite3_quota_shutdown
1381 */ 1388 */
1382 static int test_quota_shutdown( 1389 static int SQLITE_TCLAPI test_quota_shutdown(
1383 void * clientData, 1390 void * clientData,
1384 Tcl_Interp *interp, 1391 Tcl_Interp *interp,
1385 int objc, 1392 int objc,
1386 Tcl_Obj *CONST objv[] 1393 Tcl_Obj *CONST objv[]
1387 ){ 1394 ){
1388 int rc; /* Value returned by quota_shutdown() */ 1395 int rc; /* Value returned by quota_shutdown() */
1389 1396
1390 if( objc!=1 ){ 1397 if( objc!=1 ){
1391 Tcl_WrongNumArgs(interp, 1, objv, ""); 1398 Tcl_WrongNumArgs(interp, 1, objv, "");
1392 return TCL_ERROR; 1399 return TCL_ERROR;
1393 } 1400 }
1394 1401
1395 /* Call sqlite3_quota_shutdown() */ 1402 /* Call sqlite3_quota_shutdown() */
1396 rc = sqlite3_quota_shutdown(); 1403 rc = sqlite3_quota_shutdown();
1397 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); 1404 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
1398 1405
1399 return TCL_OK; 1406 return TCL_OK;
1400 } 1407 }
1401 1408
1402 /* 1409 /*
1403 ** tclcmd: sqlite3_quota_set PATTERN LIMIT SCRIPT 1410 ** tclcmd: sqlite3_quota_set PATTERN LIMIT SCRIPT
1404 */ 1411 */
1405 static int test_quota_set( 1412 static int SQLITE_TCLAPI test_quota_set(
1406 void * clientData, 1413 void * clientData,
1407 Tcl_Interp *interp, 1414 Tcl_Interp *interp,
1408 int objc, 1415 int objc,
1409 Tcl_Obj *CONST objv[] 1416 Tcl_Obj *CONST objv[]
1410 ){ 1417 ){
1411 const char *zPattern; /* File pattern to configure */ 1418 const char *zPattern; /* File pattern to configure */
1412 Tcl_WideInt iLimit; /* Initial quota in bytes */ 1419 Tcl_WideInt iLimit; /* Initial quota in bytes */
1413 Tcl_Obj *pScript; /* Tcl script to invoke to increase quota */ 1420 Tcl_Obj *pScript; /* Tcl script to invoke to increase quota */
1414 int rc; /* Value returned by quota_set() */ 1421 int rc; /* Value returned by quota_set() */
1415 TclQuotaCallback *p; /* Callback object */ 1422 TclQuotaCallback *p; /* Callback object */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 /* Invoke sqlite3_quota_set() */ 1456 /* Invoke sqlite3_quota_set() */
1450 rc = sqlite3_quota_set(zPattern, iLimit, xCallback, (void*)p, xDestroy); 1457 rc = sqlite3_quota_set(zPattern, iLimit, xCallback, (void*)p, xDestroy);
1451 1458
1452 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); 1459 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
1453 return TCL_OK; 1460 return TCL_OK;
1454 } 1461 }
1455 1462
1456 /* 1463 /*
1457 ** tclcmd: sqlite3_quota_file FILENAME 1464 ** tclcmd: sqlite3_quota_file FILENAME
1458 */ 1465 */
1459 static int test_quota_file( 1466 static int SQLITE_TCLAPI test_quota_file(
1460 void * clientData, 1467 void * clientData,
1461 Tcl_Interp *interp, 1468 Tcl_Interp *interp,
1462 int objc, 1469 int objc,
1463 Tcl_Obj *CONST objv[] 1470 Tcl_Obj *CONST objv[]
1464 ){ 1471 ){
1465 const char *zFilename; /* File pattern to configure */ 1472 const char *zFilename; /* File pattern to configure */
1466 int rc; /* Value returned by quota_file() */ 1473 int rc; /* Value returned by quota_file() */
1467 1474
1468 /* Process arguments */ 1475 /* Process arguments */
1469 if( objc!=2 ){ 1476 if( objc!=2 ){
1470 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); 1477 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME");
1471 return TCL_ERROR; 1478 return TCL_ERROR;
1472 } 1479 }
1473 zFilename = Tcl_GetString(objv[1]); 1480 zFilename = Tcl_GetString(objv[1]);
1474 1481
1475 /* Invoke sqlite3_quota_file() */ 1482 /* Invoke sqlite3_quota_file() */
1476 rc = sqlite3_quota_file(zFilename); 1483 rc = sqlite3_quota_file(zFilename);
1477 1484
1478 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); 1485 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
1479 return TCL_OK; 1486 return TCL_OK;
1480 } 1487 }
1481 1488
1482 /* 1489 /*
1483 ** tclcmd: sqlite3_quota_dump 1490 ** tclcmd: sqlite3_quota_dump
1484 */ 1491 */
1485 static int test_quota_dump( 1492 static int SQLITE_TCLAPI test_quota_dump(
1486 void * clientData, 1493 void * clientData,
1487 Tcl_Interp *interp, 1494 Tcl_Interp *interp,
1488 int objc, 1495 int objc,
1489 Tcl_Obj *CONST objv[] 1496 Tcl_Obj *CONST objv[]
1490 ){ 1497 ){
1491 Tcl_Obj *pResult; 1498 Tcl_Obj *pResult;
1492 Tcl_Obj *pGroupTerm; 1499 Tcl_Obj *pGroupTerm;
1493 Tcl_Obj *pFileTerm; 1500 Tcl_Obj *pFileTerm;
1494 quotaGroup *pGroup; 1501 quotaGroup *pGroup;
1495 quotaFile *pFile; 1502 quotaFile *pFile;
(...skipping 27 matching lines...) Expand all
1523 Tcl_ListObjAppendElement(interp, pResult, pGroupTerm); 1530 Tcl_ListObjAppendElement(interp, pResult, pGroupTerm);
1524 } 1531 }
1525 quotaLeave(); 1532 quotaLeave();
1526 Tcl_SetObjResult(interp, pResult); 1533 Tcl_SetObjResult(interp, pResult);
1527 return TCL_OK; 1534 return TCL_OK;
1528 } 1535 }
1529 1536
1530 /* 1537 /*
1531 ** tclcmd: sqlite3_quota_fopen FILENAME MODE 1538 ** tclcmd: sqlite3_quota_fopen FILENAME MODE
1532 */ 1539 */
1533 static int test_quota_fopen( 1540 static int SQLITE_TCLAPI test_quota_fopen(
1534 void * clientData, 1541 void * clientData,
1535 Tcl_Interp *interp, 1542 Tcl_Interp *interp,
1536 int objc, 1543 int objc,
1537 Tcl_Obj *CONST objv[] 1544 Tcl_Obj *CONST objv[]
1538 ){ 1545 ){
1539 const char *zFilename; /* File pattern to configure */ 1546 const char *zFilename; /* File pattern to configure */
1540 const char *zMode; /* Mode string */ 1547 const char *zMode; /* Mode string */
1541 quota_FILE *p; /* Open string object */ 1548 quota_FILE *p; /* Open string object */
1542 char zReturn[50]; /* Name of pointer to return */ 1549 char zReturn[50]; /* Name of pointer to return */
1543 1550
1544 /* Process arguments */ 1551 /* Process arguments */
1545 if( objc!=3 ){ 1552 if( objc!=3 ){
1546 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME MODE"); 1553 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME MODE");
1547 return TCL_ERROR; 1554 return TCL_ERROR;
1548 } 1555 }
1549 zFilename = Tcl_GetString(objv[1]); 1556 zFilename = Tcl_GetString(objv[1]);
1550 zMode = Tcl_GetString(objv[2]); 1557 zMode = Tcl_GetString(objv[2]);
1551 p = sqlite3_quota_fopen(zFilename, zMode); 1558 p = sqlite3_quota_fopen(zFilename, zMode);
1552 sqlite3_snprintf(sizeof(zReturn), zReturn, "%p", p); 1559 sqlite3_snprintf(sizeof(zReturn), zReturn, "%p", p);
1553 Tcl_SetResult(interp, zReturn, TCL_VOLATILE); 1560 Tcl_SetResult(interp, zReturn, TCL_VOLATILE);
1554 return TCL_OK; 1561 return TCL_OK;
1555 } 1562 }
1556 1563
1557 /* Defined in test1.c */ 1564 /* Defined in test1.c */
1558 extern void *sqlite3TestTextToPtr(const char*); 1565 extern void *sqlite3TestTextToPtr(const char*);
1559 1566
1560 /* 1567 /*
1561 ** tclcmd: sqlite3_quota_fread HANDLE SIZE NELEM 1568 ** tclcmd: sqlite3_quota_fread HANDLE SIZE NELEM
1562 */ 1569 */
1563 static int test_quota_fread( 1570 static int SQLITE_TCLAPI test_quota_fread(
1564 void * clientData, 1571 void * clientData,
1565 Tcl_Interp *interp, 1572 Tcl_Interp *interp,
1566 int objc, 1573 int objc,
1567 Tcl_Obj *CONST objv[] 1574 Tcl_Obj *CONST objv[]
1568 ){ 1575 ){
1569 quota_FILE *p; 1576 quota_FILE *p;
1570 char *zBuf; 1577 char *zBuf;
1571 int sz; 1578 int sz;
1572 int nElem; 1579 int nElem;
1573 size_t got; 1580 size_t got;
(...skipping 13 matching lines...) Expand all
1587 got = sqlite3_quota_fread(zBuf, sz, nElem, p); 1594 got = sqlite3_quota_fread(zBuf, sz, nElem, p);
1588 zBuf[got*sz] = 0; 1595 zBuf[got*sz] = 0;
1589 Tcl_SetResult(interp, zBuf, TCL_VOLATILE); 1596 Tcl_SetResult(interp, zBuf, TCL_VOLATILE);
1590 sqlite3_free(zBuf); 1597 sqlite3_free(zBuf);
1591 return TCL_OK; 1598 return TCL_OK;
1592 } 1599 }
1593 1600
1594 /* 1601 /*
1595 ** tclcmd: sqlite3_quota_fwrite HANDLE SIZE NELEM CONTENT 1602 ** tclcmd: sqlite3_quota_fwrite HANDLE SIZE NELEM CONTENT
1596 */ 1603 */
1597 static int test_quota_fwrite( 1604 static int SQLITE_TCLAPI test_quota_fwrite(
1598 void * clientData, 1605 void * clientData,
1599 Tcl_Interp *interp, 1606 Tcl_Interp *interp,
1600 int objc, 1607 int objc,
1601 Tcl_Obj *CONST objv[] 1608 Tcl_Obj *CONST objv[]
1602 ){ 1609 ){
1603 quota_FILE *p; 1610 quota_FILE *p;
1604 char *zBuf; 1611 char *zBuf;
1605 int sz; 1612 int sz;
1606 int nElem; 1613 int nElem;
1607 size_t got; 1614 size_t got;
1608 1615
1609 if( objc!=5 ){ 1616 if( objc!=5 ){
1610 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE SIZE NELEM CONTENT"); 1617 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE SIZE NELEM CONTENT");
1611 return TCL_ERROR; 1618 return TCL_ERROR;
1612 } 1619 }
1613 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1620 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1614 if( Tcl_GetIntFromObj(interp, objv[2], &sz) ) return TCL_ERROR; 1621 if( Tcl_GetIntFromObj(interp, objv[2], &sz) ) return TCL_ERROR;
1615 if( Tcl_GetIntFromObj(interp, objv[3], &nElem) ) return TCL_ERROR; 1622 if( Tcl_GetIntFromObj(interp, objv[3], &nElem) ) return TCL_ERROR;
1616 zBuf = Tcl_GetString(objv[4]); 1623 zBuf = Tcl_GetString(objv[4]);
1617 got = sqlite3_quota_fwrite(zBuf, sz, nElem, p); 1624 got = sqlite3_quota_fwrite(zBuf, sz, nElem, p);
1618 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(got)); 1625 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(got));
1619 return TCL_OK; 1626 return TCL_OK;
1620 } 1627 }
1621 1628
1622 /* 1629 /*
1623 ** tclcmd: sqlite3_quota_fclose HANDLE 1630 ** tclcmd: sqlite3_quota_fclose HANDLE
1624 */ 1631 */
1625 static int test_quota_fclose( 1632 static int SQLITE_TCLAPI test_quota_fclose(
1626 void * clientData, 1633 void * clientData,
1627 Tcl_Interp *interp, 1634 Tcl_Interp *interp,
1628 int objc, 1635 int objc,
1629 Tcl_Obj *CONST objv[] 1636 Tcl_Obj *CONST objv[]
1630 ){ 1637 ){
1631 quota_FILE *p; 1638 quota_FILE *p;
1632 int rc; 1639 int rc;
1633 1640
1634 if( objc!=2 ){ 1641 if( objc!=2 ){
1635 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1642 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1636 return TCL_ERROR; 1643 return TCL_ERROR;
1637 } 1644 }
1638 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1645 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1639 rc = sqlite3_quota_fclose(p); 1646 rc = sqlite3_quota_fclose(p);
1640 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); 1647 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
1641 return TCL_OK; 1648 return TCL_OK;
1642 } 1649 }
1643 1650
1644 /* 1651 /*
1645 ** tclcmd: sqlite3_quota_fflush HANDLE ?HARDSYNC? 1652 ** tclcmd: sqlite3_quota_fflush HANDLE ?HARDSYNC?
1646 */ 1653 */
1647 static int test_quota_fflush( 1654 static int SQLITE_TCLAPI test_quota_fflush(
1648 void * clientData, 1655 void * clientData,
1649 Tcl_Interp *interp, 1656 Tcl_Interp *interp,
1650 int objc, 1657 int objc,
1651 Tcl_Obj *CONST objv[] 1658 Tcl_Obj *CONST objv[]
1652 ){ 1659 ){
1653 quota_FILE *p; 1660 quota_FILE *p;
1654 int rc; 1661 int rc;
1655 int doSync = 0; 1662 int doSync = 0;
1656 1663
1657 if( objc!=2 && objc!=3 ){ 1664 if( objc!=2 && objc!=3 ){
1658 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE ?HARDSYNC?"); 1665 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE ?HARDSYNC?");
1659 return TCL_ERROR; 1666 return TCL_ERROR;
1660 } 1667 }
1661 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1668 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1662 if( objc==3 ){ 1669 if( objc==3 ){
1663 if( Tcl_GetBooleanFromObj(interp, objv[2], &doSync) ) return TCL_ERROR; 1670 if( Tcl_GetBooleanFromObj(interp, objv[2], &doSync) ) return TCL_ERROR;
1664 } 1671 }
1665 rc = sqlite3_quota_fflush(p, doSync); 1672 rc = sqlite3_quota_fflush(p, doSync);
1666 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); 1673 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
1667 return TCL_OK; 1674 return TCL_OK;
1668 } 1675 }
1669 1676
1670 /* 1677 /*
1671 ** tclcmd: sqlite3_quota_fseek HANDLE OFFSET WHENCE 1678 ** tclcmd: sqlite3_quota_fseek HANDLE OFFSET WHENCE
1672 */ 1679 */
1673 static int test_quota_fseek( 1680 static int SQLITE_TCLAPI test_quota_fseek(
1674 void * clientData, 1681 void * clientData,
1675 Tcl_Interp *interp, 1682 Tcl_Interp *interp,
1676 int objc, 1683 int objc,
1677 Tcl_Obj *CONST objv[] 1684 Tcl_Obj *CONST objv[]
1678 ){ 1685 ){
1679 quota_FILE *p; 1686 quota_FILE *p;
1680 int ofst; 1687 int ofst;
1681 const char *zWhence; 1688 const char *zWhence;
1682 int whence; 1689 int whence;
1683 int rc; 1690 int rc;
(...skipping 17 matching lines...) Expand all
1701 return TCL_ERROR; 1708 return TCL_ERROR;
1702 } 1709 }
1703 rc = sqlite3_quota_fseek(p, ofst, whence); 1710 rc = sqlite3_quota_fseek(p, ofst, whence);
1704 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); 1711 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
1705 return TCL_OK; 1712 return TCL_OK;
1706 } 1713 }
1707 1714
1708 /* 1715 /*
1709 ** tclcmd: sqlite3_quota_rewind HANDLE 1716 ** tclcmd: sqlite3_quota_rewind HANDLE
1710 */ 1717 */
1711 static int test_quota_rewind( 1718 static int SQLITE_TCLAPI test_quota_rewind(
1712 void * clientData, 1719 void * clientData,
1713 Tcl_Interp *interp, 1720 Tcl_Interp *interp,
1714 int objc, 1721 int objc,
1715 Tcl_Obj *CONST objv[] 1722 Tcl_Obj *CONST objv[]
1716 ){ 1723 ){
1717 quota_FILE *p; 1724 quota_FILE *p;
1718 if( objc!=2 ){ 1725 if( objc!=2 ){
1719 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1726 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1720 return TCL_ERROR; 1727 return TCL_ERROR;
1721 } 1728 }
1722 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1729 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1723 sqlite3_quota_rewind(p); 1730 sqlite3_quota_rewind(p);
1724 return TCL_OK; 1731 return TCL_OK;
1725 } 1732 }
1726 1733
1727 /* 1734 /*
1728 ** tclcmd: sqlite3_quota_ftell HANDLE 1735 ** tclcmd: sqlite3_quota_ftell HANDLE
1729 */ 1736 */
1730 static int test_quota_ftell( 1737 static int SQLITE_TCLAPI test_quota_ftell(
1731 void * clientData, 1738 void * clientData,
1732 Tcl_Interp *interp, 1739 Tcl_Interp *interp,
1733 int objc, 1740 int objc,
1734 Tcl_Obj *CONST objv[] 1741 Tcl_Obj *CONST objv[]
1735 ){ 1742 ){
1736 quota_FILE *p; 1743 quota_FILE *p;
1737 sqlite3_int64 x; 1744 sqlite3_int64 x;
1738 if( objc!=2 ){ 1745 if( objc!=2 ){
1739 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1746 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1740 return TCL_ERROR; 1747 return TCL_ERROR;
1741 } 1748 }
1742 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1749 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1743 x = sqlite3_quota_ftell(p); 1750 x = sqlite3_quota_ftell(p);
1744 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x)); 1751 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
1745 return TCL_OK; 1752 return TCL_OK;
1746 } 1753 }
1747 1754
1748 /* 1755 /*
1749 ** tclcmd: sqlite3_quota_ftruncate HANDLE SIZE 1756 ** tclcmd: sqlite3_quota_ftruncate HANDLE SIZE
1750 */ 1757 */
1751 static int test_quota_ftruncate( 1758 static int SQLITE_TCLAPI test_quota_ftruncate(
1752 void * clientData, 1759 void * clientData,
1753 Tcl_Interp *interp, 1760 Tcl_Interp *interp,
1754 int objc, 1761 int objc,
1755 Tcl_Obj *CONST objv[] 1762 Tcl_Obj *CONST objv[]
1756 ){ 1763 ){
1757 quota_FILE *p; 1764 quota_FILE *p;
1758 sqlite3_int64 x; 1765 sqlite3_int64 x;
1759 Tcl_WideInt w; 1766 Tcl_WideInt w;
1760 int rc; 1767 int rc;
1761 if( objc!=3 ){ 1768 if( objc!=3 ){
1762 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE SIZE"); 1769 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE SIZE");
1763 return TCL_ERROR; 1770 return TCL_ERROR;
1764 } 1771 }
1765 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1772 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1766 if( Tcl_GetWideIntFromObj(interp, objv[2], &w) ) return TCL_ERROR; 1773 if( Tcl_GetWideIntFromObj(interp, objv[2], &w) ) return TCL_ERROR;
1767 x = (sqlite3_int64)w; 1774 x = (sqlite3_int64)w;
1768 rc = sqlite3_quota_ftruncate(p, x); 1775 rc = sqlite3_quota_ftruncate(p, x);
1769 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); 1776 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
1770 return TCL_OK; 1777 return TCL_OK;
1771 } 1778 }
1772 1779
1773 /* 1780 /*
1774 ** tclcmd: sqlite3_quota_file_size HANDLE 1781 ** tclcmd: sqlite3_quota_file_size HANDLE
1775 */ 1782 */
1776 static int test_quota_file_size( 1783 static int SQLITE_TCLAPI test_quota_file_size(
1777 void * clientData, 1784 void * clientData,
1778 Tcl_Interp *interp, 1785 Tcl_Interp *interp,
1779 int objc, 1786 int objc,
1780 Tcl_Obj *CONST objv[] 1787 Tcl_Obj *CONST objv[]
1781 ){ 1788 ){
1782 quota_FILE *p; 1789 quota_FILE *p;
1783 sqlite3_int64 x; 1790 sqlite3_int64 x;
1784 if( objc!=2 ){ 1791 if( objc!=2 ){
1785 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1792 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1786 return TCL_ERROR; 1793 return TCL_ERROR;
1787 } 1794 }
1788 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1795 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1789 x = sqlite3_quota_file_size(p); 1796 x = sqlite3_quota_file_size(p);
1790 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x)); 1797 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
1791 return TCL_OK; 1798 return TCL_OK;
1792 } 1799 }
1793 1800
1794 /* 1801 /*
1795 ** tclcmd: sqlite3_quota_file_truesize HANDLE 1802 ** tclcmd: sqlite3_quota_file_truesize HANDLE
1796 */ 1803 */
1797 static int test_quota_file_truesize( 1804 static int SQLITE_TCLAPI test_quota_file_truesize(
1798 void * clientData, 1805 void * clientData,
1799 Tcl_Interp *interp, 1806 Tcl_Interp *interp,
1800 int objc, 1807 int objc,
1801 Tcl_Obj *CONST objv[] 1808 Tcl_Obj *CONST objv[]
1802 ){ 1809 ){
1803 quota_FILE *p; 1810 quota_FILE *p;
1804 sqlite3_int64 x; 1811 sqlite3_int64 x;
1805 if( objc!=2 ){ 1812 if( objc!=2 ){
1806 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1813 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1807 return TCL_ERROR; 1814 return TCL_ERROR;
1808 } 1815 }
1809 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1816 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1810 x = sqlite3_quota_file_truesize(p); 1817 x = sqlite3_quota_file_truesize(p);
1811 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x)); 1818 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
1812 return TCL_OK; 1819 return TCL_OK;
1813 } 1820 }
1814 1821
1815 /* 1822 /*
1816 ** tclcmd: sqlite3_quota_file_mtime HANDLE 1823 ** tclcmd: sqlite3_quota_file_mtime HANDLE
1817 */ 1824 */
1818 static int test_quota_file_mtime( 1825 static int SQLITE_TCLAPI test_quota_file_mtime(
1819 void * clientData, 1826 void * clientData,
1820 Tcl_Interp *interp, 1827 Tcl_Interp *interp,
1821 int objc, 1828 int objc,
1822 Tcl_Obj *CONST objv[] 1829 Tcl_Obj *CONST objv[]
1823 ){ 1830 ){
1824 quota_FILE *p; 1831 quota_FILE *p;
1825 time_t t; 1832 time_t t;
1826 if( objc!=2 ){ 1833 if( objc!=2 ){
1827 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1834 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1828 return TCL_ERROR; 1835 return TCL_ERROR;
1829 } 1836 }
1830 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1837 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1831 t = 0; 1838 t = 0;
1832 sqlite3_quota_file_mtime(p, &t); 1839 sqlite3_quota_file_mtime(p, &t);
1833 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(t)); 1840 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(t));
1834 return TCL_OK; 1841 return TCL_OK;
1835 } 1842 }
1836 1843
1837 1844
1838 /* 1845 /*
1839 ** tclcmd: sqlite3_quota_remove FILENAME 1846 ** tclcmd: sqlite3_quota_remove FILENAME
1840 */ 1847 */
1841 static int test_quota_remove( 1848 static int SQLITE_TCLAPI test_quota_remove(
1842 void * clientData, 1849 void * clientData,
1843 Tcl_Interp *interp, 1850 Tcl_Interp *interp,
1844 int objc, 1851 int objc,
1845 Tcl_Obj *CONST objv[] 1852 Tcl_Obj *CONST objv[]
1846 ){ 1853 ){
1847 const char *zFilename; /* File pattern to configure */ 1854 const char *zFilename; /* File pattern to configure */
1848 int rc; 1855 int rc;
1849 if( objc!=2 ){ 1856 if( objc!=2 ){
1850 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); 1857 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME");
1851 return TCL_ERROR; 1858 return TCL_ERROR;
1852 } 1859 }
1853 zFilename = Tcl_GetString(objv[1]); 1860 zFilename = Tcl_GetString(objv[1]);
1854 rc = sqlite3_quota_remove(zFilename); 1861 rc = sqlite3_quota_remove(zFilename);
1855 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); 1862 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
1856 return TCL_OK; 1863 return TCL_OK;
1857 } 1864 }
1858 1865
1859 /* 1866 /*
1860 ** tclcmd: sqlite3_quota_glob PATTERN TEXT 1867 ** tclcmd: sqlite3_quota_glob PATTERN TEXT
1861 ** 1868 **
1862 ** Test the glob pattern matching. Return 1 if TEXT matches PATTERN 1869 ** Test the glob pattern matching. Return 1 if TEXT matches PATTERN
1863 ** and return 0 if it does not. 1870 ** and return 0 if it does not.
1864 */ 1871 */
1865 static int test_quota_glob( 1872 static int SQLITE_TCLAPI test_quota_glob(
1866 void * clientData, 1873 void * clientData,
1867 Tcl_Interp *interp, 1874 Tcl_Interp *interp,
1868 int objc, 1875 int objc,
1869 Tcl_Obj *CONST objv[] 1876 Tcl_Obj *CONST objv[]
1870 ){ 1877 ){
1871 const char *zPattern; /* The glob pattern */ 1878 const char *zPattern; /* The glob pattern */
1872 const char *zText; /* Text to compare agains the pattern */ 1879 const char *zText; /* Text to compare agains the pattern */
1873 int rc; 1880 int rc;
1874 if( objc!=3 ){ 1881 if( objc!=3 ){
1875 Tcl_WrongNumArgs(interp, 1, objv, "PATTERN TEXT"); 1882 Tcl_WrongNumArgs(interp, 1, objv, "PATTERN TEXT");
1876 return TCL_ERROR; 1883 return TCL_ERROR;
1877 } 1884 }
1878 zPattern = Tcl_GetString(objv[1]); 1885 zPattern = Tcl_GetString(objv[1]);
1879 zText = Tcl_GetString(objv[2]); 1886 zText = Tcl_GetString(objv[2]);
1880 rc = quotaStrglob(zPattern, zText); 1887 rc = quotaStrglob(zPattern, zText);
1881 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); 1888 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
1882 return TCL_OK; 1889 return TCL_OK;
1883 } 1890 }
1884 1891
1885 /* 1892 /*
1886 ** tclcmd: sqlite3_quota_file_available HANDLE 1893 ** tclcmd: sqlite3_quota_file_available HANDLE
1887 ** 1894 **
1888 ** Return the number of bytes from the current file point to the end of 1895 ** Return the number of bytes from the current file point to the end of
1889 ** the file. 1896 ** the file.
1890 */ 1897 */
1891 static int test_quota_file_available( 1898 static int SQLITE_TCLAPI test_quota_file_available(
1892 void * clientData, 1899 void * clientData,
1893 Tcl_Interp *interp, 1900 Tcl_Interp *interp,
1894 int objc, 1901 int objc,
1895 Tcl_Obj *CONST objv[] 1902 Tcl_Obj *CONST objv[]
1896 ){ 1903 ){
1897 quota_FILE *p; 1904 quota_FILE *p;
1898 sqlite3_int64 x; 1905 sqlite3_int64 x;
1899 if( objc!=2 ){ 1906 if( objc!=2 ){
1900 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1907 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1901 return TCL_ERROR; 1908 return TCL_ERROR;
1902 } 1909 }
1903 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 1910 p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
1904 x = sqlite3_quota_file_available(p); 1911 x = sqlite3_quota_file_available(p);
1905 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x)); 1912 Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
1906 return TCL_OK; 1913 return TCL_OK;
1907 } 1914 }
1908 1915
1909 /* 1916 /*
1910 ** tclcmd: sqlite3_quota_ferror HANDLE 1917 ** tclcmd: sqlite3_quota_ferror HANDLE
1911 ** 1918 **
1912 ** Return true if the file handle is in the error state. 1919 ** Return true if the file handle is in the error state.
1913 */ 1920 */
1914 static int test_quota_ferror( 1921 static int SQLITE_TCLAPI test_quota_ferror(
1915 void * clientData, 1922 void * clientData,
1916 Tcl_Interp *interp, 1923 Tcl_Interp *interp,
1917 int objc, 1924 int objc,
1918 Tcl_Obj *CONST objv[] 1925 Tcl_Obj *CONST objv[]
1919 ){ 1926 ){
1920 quota_FILE *p; 1927 quota_FILE *p;
1921 int x; 1928 int x;
1922 if( objc!=2 ){ 1929 if( objc!=2 ){
1923 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); 1930 Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
1924 return TCL_ERROR; 1931 return TCL_ERROR;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 }; 1970 };
1964 int i; 1971 int i;
1965 1972
1966 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ 1973 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
1967 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); 1974 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
1968 } 1975 }
1969 1976
1970 return TCL_OK; 1977 return TCL_OK;
1971 } 1978 }
1972 #endif 1979 #endif
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/test_osinst.c ('k') | third_party/sqlite/src/src/test_rtree.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698