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

Side by Side Diff: third_party/sqlite/sqlite-src-3080704/src/test_onefile.c

Issue 883353008: [sql] Import reference version of SQLite 3.8.7.4. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hold back encoding change which is messing up patch. Created 5 years, 10 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
OLDNEW
1 /* 1 /*
2 ** 2007 September 14 2 ** 2007 September 14
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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 ** Write data to a tmp-file. 281 ** Write data to a tmp-file.
282 */ 282 */
283 static int tmpWrite( 283 static int tmpWrite(
284 sqlite3_file *pFile, 284 sqlite3_file *pFile,
285 const void *zBuf, 285 const void *zBuf,
286 int iAmt, 286 int iAmt,
287 sqlite_int64 iOfst 287 sqlite_int64 iOfst
288 ){ 288 ){
289 tmp_file *pTmp = (tmp_file *)pFile; 289 tmp_file *pTmp = (tmp_file *)pFile;
290 if( (iAmt+iOfst)>pTmp->nAlloc ){ 290 if( (iAmt+iOfst)>pTmp->nAlloc ){
291 int nNew = 2*(iAmt+iOfst+pTmp->nAlloc); 291 int nNew = (int)(2*(iAmt+iOfst+pTmp->nAlloc));
292 char *zNew = sqlite3_realloc(pTmp->zAlloc, nNew); 292 char *zNew = sqlite3_realloc(pTmp->zAlloc, nNew);
293 if( !zNew ){ 293 if( !zNew ){
294 return SQLITE_NOMEM; 294 return SQLITE_NOMEM;
295 } 295 }
296 pTmp->zAlloc = zNew; 296 pTmp->zAlloc = zNew;
297 pTmp->nAlloc = nNew; 297 pTmp->nAlloc = nNew;
298 } 298 }
299 memcpy(&pTmp->zAlloc[iOfst], zBuf, iAmt); 299 memcpy(&pTmp->zAlloc[iOfst], zBuf, iAmt);
300 pTmp->nSize = MAX(pTmp->nSize, iOfst+iAmt); 300 pTmp->nSize = (int)MAX(pTmp->nSize, iOfst+iAmt);
301 return SQLITE_OK; 301 return SQLITE_OK;
302 } 302 }
303 303
304 /* 304 /*
305 ** Truncate a tmp-file. 305 ** Truncate a tmp-file.
306 */ 306 */
307 static int tmpTruncate(sqlite3_file *pFile, sqlite_int64 size){ 307 static int tmpTruncate(sqlite3_file *pFile, sqlite_int64 size){
308 tmp_file *pTmp = (tmp_file *)pFile; 308 tmp_file *pTmp = (tmp_file *)pFile;
309 pTmp->nSize = MIN(pTmp->nSize, size); 309 pTmp->nSize = (int)MIN(pTmp->nSize, size);
310 return SQLITE_OK; 310 return SQLITE_OK;
311 } 311 }
312 312
313 /* 313 /*
314 ** Sync a tmp-file. 314 ** Sync a tmp-file.
315 */ 315 */
316 static int tmpSync(sqlite3_file *pFile, int flags){ 316 static int tmpSync(sqlite3_file *pFile, int flags){
317 return SQLITE_OK; 317 return SQLITE_OK;
318 } 318 }
319 319
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if( (p->eType==DATABASE_FILE && (iAmt+iOfst)>pReal->nDatabase) 411 if( (p->eType==DATABASE_FILE && (iAmt+iOfst)>pReal->nDatabase)
412 || (p->eType==JOURNAL_FILE && (iAmt+iOfst)>pReal->nJournal) 412 || (p->eType==JOURNAL_FILE && (iAmt+iOfst)>pReal->nJournal)
413 ){ 413 ){
414 rc = SQLITE_IOERR_SHORT_READ; 414 rc = SQLITE_IOERR_SHORT_READ;
415 }else if( p->eType==DATABASE_FILE ){ 415 }else if( p->eType==DATABASE_FILE ){
416 rc = pF->pMethods->xRead(pF, zBuf, iAmt, iOfst+BLOCKSIZE); 416 rc = pF->pMethods->xRead(pF, zBuf, iAmt, iOfst+BLOCKSIZE);
417 }else{ 417 }else{
418 /* Journal file. */ 418 /* Journal file. */
419 int iRem = iAmt; 419 int iRem = iAmt;
420 int iBuf = 0; 420 int iBuf = 0;
421 int ii = iOfst; 421 int ii = (int)iOfst;
422 while( iRem>0 && rc==SQLITE_OK ){ 422 while( iRem>0 && rc==SQLITE_OK ){
423 int iRealOff = pReal->nBlob - BLOCKSIZE*((ii/BLOCKSIZE)+1) + ii%BLOCKSIZE; 423 int iRealOff = pReal->nBlob - BLOCKSIZE*((ii/BLOCKSIZE)+1) + ii%BLOCKSIZE;
424 int iRealAmt = MIN(iRem, BLOCKSIZE - (iRealOff%BLOCKSIZE)); 424 int iRealAmt = MIN(iRem, BLOCKSIZE - (iRealOff%BLOCKSIZE));
425 425
426 rc = pF->pMethods->xRead(pF, &((char *)zBuf)[iBuf], iRealAmt, iRealOff); 426 rc = pF->pMethods->xRead(pF, &((char *)zBuf)[iBuf], iRealAmt, iRealOff);
427 ii += iRealAmt; 427 ii += iRealAmt;
428 iBuf += iRealAmt; 428 iBuf += iRealAmt;
429 iRem -= iRealAmt; 429 iRem -= iRealAmt;
430 } 430 }
431 } 431 }
(...skipping 14 matching lines...) Expand all
446 fs_file *p = (fs_file *)pFile; 446 fs_file *p = (fs_file *)pFile;
447 fs_real_file *pReal = p->pReal; 447 fs_real_file *pReal = p->pReal;
448 sqlite3_file *pF = pReal->pFile; 448 sqlite3_file *pF = pReal->pFile;
449 449
450 if( p->eType==DATABASE_FILE ){ 450 if( p->eType==DATABASE_FILE ){
451 if( (iAmt+iOfst+BLOCKSIZE)>(pReal->nBlob-pReal->nJournal) ){ 451 if( (iAmt+iOfst+BLOCKSIZE)>(pReal->nBlob-pReal->nJournal) ){
452 rc = SQLITE_FULL; 452 rc = SQLITE_FULL;
453 }else{ 453 }else{
454 rc = pF->pMethods->xWrite(pF, zBuf, iAmt, iOfst+BLOCKSIZE); 454 rc = pF->pMethods->xWrite(pF, zBuf, iAmt, iOfst+BLOCKSIZE);
455 if( rc==SQLITE_OK ){ 455 if( rc==SQLITE_OK ){
456 pReal->nDatabase = MAX(pReal->nDatabase, iAmt+iOfst); 456 pReal->nDatabase = (int)MAX(pReal->nDatabase, iAmt+iOfst);
457 } 457 }
458 } 458 }
459 }else{ 459 }else{
460 /* Journal file. */ 460 /* Journal file. */
461 int iRem = iAmt; 461 int iRem = iAmt;
462 int iBuf = 0; 462 int iBuf = 0;
463 int ii = iOfst; 463 int ii = (int)iOfst;
464 while( iRem>0 && rc==SQLITE_OK ){ 464 while( iRem>0 && rc==SQLITE_OK ){
465 int iRealOff = pReal->nBlob - BLOCKSIZE*((ii/BLOCKSIZE)+1) + ii%BLOCKSIZE; 465 int iRealOff = pReal->nBlob - BLOCKSIZE*((ii/BLOCKSIZE)+1) + ii%BLOCKSIZE;
466 int iRealAmt = MIN(iRem, BLOCKSIZE - (iRealOff%BLOCKSIZE)); 466 int iRealAmt = MIN(iRem, BLOCKSIZE - (iRealOff%BLOCKSIZE));
467 467
468 if( iRealOff<(pReal->nDatabase+BLOCKSIZE) ){ 468 if( iRealOff<(pReal->nDatabase+BLOCKSIZE) ){
469 rc = SQLITE_FULL; 469 rc = SQLITE_FULL;
470 }else{ 470 }else{
471 rc = pF->pMethods->xWrite(pF, &((char *)zBuf)[iBuf], iRealAmt,iRealOff); 471 rc = pF->pMethods->xWrite(pF, &((char *)zBuf)[iBuf], iRealAmt,iRealOff);
472 ii += iRealAmt; 472 ii += iRealAmt;
473 iBuf += iRealAmt; 473 iBuf += iRealAmt;
474 iRem -= iRealAmt; 474 iRem -= iRealAmt;
475 } 475 }
476 } 476 }
477 if( rc==SQLITE_OK ){ 477 if( rc==SQLITE_OK ){
478 pReal->nJournal = MAX(pReal->nJournal, iAmt+iOfst); 478 pReal->nJournal = (int)MAX(pReal->nJournal, iAmt+iOfst);
479 } 479 }
480 } 480 }
481 481
482 return rc; 482 return rc;
483 } 483 }
484 484
485 /* 485 /*
486 ** Truncate an fs-file. 486 ** Truncate an fs-file.
487 */ 487 */
488 static int fsTruncate(sqlite3_file *pFile, sqlite_int64 size){ 488 static int fsTruncate(sqlite3_file *pFile, sqlite_int64 size){
489 fs_file *p = (fs_file *)pFile; 489 fs_file *p = (fs_file *)pFile;
490 fs_real_file *pReal = p->pReal; 490 fs_real_file *pReal = p->pReal;
491 if( p->eType==DATABASE_FILE ){ 491 if( p->eType==DATABASE_FILE ){
492 pReal->nDatabase = MIN(pReal->nDatabase, size); 492 pReal->nDatabase = (int)MIN(pReal->nDatabase, size);
493 }else{ 493 }else{
494 pReal->nJournal = MIN(pReal->nJournal, size); 494 pReal->nJournal = (int)MIN(pReal->nJournal, size);
495 } 495 }
496 return SQLITE_OK; 496 return SQLITE_OK;
497 } 497 }
498 498
499 /* 499 /*
500 ** Sync an fs-file. 500 ** Sync an fs-file.
501 */ 501 */
502 static int fsSync(sqlite3_file *pFile, int flags){ 502 static int fsSync(sqlite3_file *pFile, int flags){
503 fs_file *p = (fs_file *)pFile; 503 fs_file *p = (fs_file *)pFile;
504 fs_real_file *pReal = p->pReal; 504 fs_real_file *pReal = p->pReal;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 memset(p, 0, sizeof(*p)); 599 memset(p, 0, sizeof(*p));
600 p->base.pMethods = &tmp_io_methods; 600 p->base.pMethods = &tmp_io_methods;
601 return SQLITE_OK; 601 return SQLITE_OK;
602 } 602 }
603 603
604 eType = ((flags&(SQLITE_OPEN_MAIN_DB))?DATABASE_FILE:JOURNAL_FILE); 604 eType = ((flags&(SQLITE_OPEN_MAIN_DB))?DATABASE_FILE:JOURNAL_FILE);
605 p->base.pMethods = &fs_io_methods; 605 p->base.pMethods = &fs_io_methods;
606 p->eType = eType; 606 p->eType = eType;
607 607
608 assert(strlen("-journal")==8); 608 assert(strlen("-journal")==8);
609 nName = strlen(zName)-((eType==JOURNAL_FILE)?8:0); 609 nName = (int)strlen(zName)-((eType==JOURNAL_FILE)?8:0);
610 pReal=pFsVfs->pFileList; 610 pReal=pFsVfs->pFileList;
611 for(; pReal && strncmp(pReal->zName, zName, nName); pReal=pReal->pNext); 611 for(; pReal && strncmp(pReal->zName, zName, nName); pReal=pReal->pNext);
612 612
613 if( !pReal ){ 613 if( !pReal ){
614 int real_flags = (flags&~(SQLITE_OPEN_MAIN_DB))|SQLITE_OPEN_TEMP_DB; 614 int real_flags = (flags&~(SQLITE_OPEN_MAIN_DB))|SQLITE_OPEN_TEMP_DB;
615 sqlite3_int64 size; 615 sqlite3_int64 size;
616 sqlite3_file *pRealFile; 616 sqlite3_file *pRealFile;
617 sqlite3_vfs *pParent = pFsVfs->pParent; 617 sqlite3_vfs *pParent = pFsVfs->pParent;
618 assert(eType==DATABASE_FILE); 618 assert(eType==DATABASE_FILE);
619 619
(...skipping 14 matching lines...) Expand all
634 634
635 rc = pRealFile->pMethods->xFileSize(pRealFile, &size); 635 rc = pRealFile->pMethods->xFileSize(pRealFile, &size);
636 if( rc!=SQLITE_OK ){ 636 if( rc!=SQLITE_OK ){
637 goto open_out; 637 goto open_out;
638 } 638 }
639 if( size==0 ){ 639 if( size==0 ){
640 rc = pRealFile->pMethods->xWrite(pRealFile, "\0", 1, BLOBSIZE-1); 640 rc = pRealFile->pMethods->xWrite(pRealFile, "\0", 1, BLOBSIZE-1);
641 pReal->nBlob = BLOBSIZE; 641 pReal->nBlob = BLOBSIZE;
642 }else{ 642 }else{
643 unsigned char zS[4]; 643 unsigned char zS[4];
644 pReal->nBlob = size; 644 pReal->nBlob = (int)size;
645 rc = pRealFile->pMethods->xRead(pRealFile, zS, 4, 0); 645 rc = pRealFile->pMethods->xRead(pRealFile, zS, 4, 0);
646 pReal->nDatabase = (zS[0]<<24)+(zS[1]<<16)+(zS[2]<<8)+zS[3]; 646 pReal->nDatabase = (zS[0]<<24)+(zS[1]<<16)+(zS[2]<<8)+zS[3];
647 if( rc==SQLITE_OK ){ 647 if( rc==SQLITE_OK ){
648 rc = pRealFile->pMethods->xRead(pRealFile, zS, 4, pReal->nBlob-4); 648 rc = pRealFile->pMethods->xRead(pRealFile, zS, 4, pReal->nBlob-4);
649 if( zS[0] || zS[1] || zS[2] || zS[3] ){ 649 if( zS[0] || zS[1] || zS[2] || zS[3] ){
650 pReal->nJournal = pReal->nBlob; 650 pReal->nJournal = pReal->nBlob;
651 } 651 }
652 } 652 }
653 } 653 }
654 654
(...skipping 25 matching lines...) Expand all
680 /* 680 /*
681 ** Delete the file located at zPath. If the dirSync argument is true, 681 ** Delete the file located at zPath. If the dirSync argument is true,
682 ** ensure the file-system modifications are synced to disk before 682 ** ensure the file-system modifications are synced to disk before
683 ** returning. 683 ** returning.
684 */ 684 */
685 static int fsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ 685 static int fsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
686 int rc = SQLITE_OK; 686 int rc = SQLITE_OK;
687 fs_vfs_t *pFsVfs = (fs_vfs_t *)pVfs; 687 fs_vfs_t *pFsVfs = (fs_vfs_t *)pVfs;
688 fs_real_file *pReal; 688 fs_real_file *pReal;
689 sqlite3_file *pF; 689 sqlite3_file *pF;
690 int nName = strlen(zPath) - 8; 690 int nName = (int)strlen(zPath) - 8;
691 691
692 assert(strlen("-journal")==8); 692 assert(strlen("-journal")==8);
693 assert(strcmp("-journal", &zPath[nName])==0); 693 assert(strcmp("-journal", &zPath[nName])==0);
694 694
695 pReal = pFsVfs->pFileList; 695 pReal = pFsVfs->pFileList;
696 for(; pReal && strncmp(pReal->zName, zPath, nName); pReal=pReal->pNext); 696 for(; pReal && strncmp(pReal->zName, zPath, nName); pReal=pReal->pNext);
697 if( pReal ){ 697 if( pReal ){
698 pF = pReal->pFile; 698 pF = pReal->pFile;
699 rc = pF->pMethods->xWrite(pF, "\0\0\0\0", 4, pReal->nBlob-BLOCKSIZE); 699 rc = pF->pMethods->xWrite(pF, "\0\0\0\0", 4, pReal->nBlob-BLOCKSIZE);
700 if( rc==SQLITE_OK ){ 700 if( rc==SQLITE_OK ){
701 pReal->nJournal = 0; 701 pReal->nJournal = 0;
702 } 702 }
703 } 703 }
704 return rc; 704 return rc;
705 } 705 }
706 706
707 /* 707 /*
708 ** Test for access permissions. Return true if the requested permission 708 ** Test for access permissions. Return true if the requested permission
709 ** is available, or false otherwise. 709 ** is available, or false otherwise.
710 */ 710 */
711 static int fsAccess( 711 static int fsAccess(
712 sqlite3_vfs *pVfs, 712 sqlite3_vfs *pVfs,
713 const char *zPath, 713 const char *zPath,
714 int flags, 714 int flags,
715 int *pResOut 715 int *pResOut
716 ){ 716 ){
717 fs_vfs_t *pFsVfs = (fs_vfs_t *)pVfs; 717 fs_vfs_t *pFsVfs = (fs_vfs_t *)pVfs;
718 fs_real_file *pReal; 718 fs_real_file *pReal;
719 int isJournal = 0; 719 int isJournal = 0;
720 int nName = strlen(zPath); 720 int nName = (int)strlen(zPath);
721 721
722 if( flags!=SQLITE_ACCESS_EXISTS ){ 722 if( flags!=SQLITE_ACCESS_EXISTS ){
723 sqlite3_vfs *pParent = ((fs_vfs_t *)pVfs)->pParent; 723 sqlite3_vfs *pParent = ((fs_vfs_t *)pVfs)->pParent;
724 return pParent->xAccess(pParent, zPath, flags, pResOut); 724 return pParent->xAccess(pParent, zPath, flags, pResOut);
725 } 725 }
726 726
727 assert(strlen("-journal")==8); 727 assert(strlen("-journal")==8);
728 if( nName>8 && strcmp("-journal", &zPath[nName-8])==0 ){ 728 if( nName>8 && strcmp("-journal", &zPath[nName-8])==0 ){
729 nName -= 8; 729 nName -= 8;
730 isJournal = 1; 730 isJournal = 1;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if( fs_vfs.pParent ) return SQLITE_OK; 821 if( fs_vfs.pParent ) return SQLITE_OK;
822 fs_vfs.pParent = sqlite3_vfs_find(0); 822 fs_vfs.pParent = sqlite3_vfs_find(0);
823 fs_vfs.base.mxPathname = fs_vfs.pParent->mxPathname; 823 fs_vfs.base.mxPathname = fs_vfs.pParent->mxPathname;
824 fs_vfs.base.szOsFile = MAX(sizeof(tmp_file), sizeof(fs_file)); 824 fs_vfs.base.szOsFile = MAX(sizeof(tmp_file), sizeof(fs_file));
825 return sqlite3_vfs_register(&fs_vfs.base, 0); 825 return sqlite3_vfs_register(&fs_vfs.base, 0);
826 } 826 }
827 827
828 #ifdef SQLITE_TEST 828 #ifdef SQLITE_TEST
829 int SqlitetestOnefile_Init() {return fs_register();} 829 int SqlitetestOnefile_Init() {return fs_register();}
830 #endif 830 #endif
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3080704/src/test_mutex.c ('k') | third_party/sqlite/sqlite-src-3080704/src/test_osinst.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698