SQLite

Check-in [d4f6437f8d]
Login

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

Overview
Comment:Make sure that SQLITE_FCNTL_SIZE_HINT on Windows does not shrink the file.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | winNativeHeap
Files: files | file ages | folders
SHA1: d4f6437f8de82482dfaa4c084f4221e89e21eb00
User & Date: mistachkin 2011-08-25 01:16:42.999
References
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: 67ff8d27f6 user: drh tags: trunk)
Context
2011-08-25
02:02
In the MSVC makefile, support several levels of debugging, each one building on the previous. Also, add comment about the SQLITE_WIN32_MALLOC_VALIDATE macro. (check-in: 4257e9b7ca user: mistachkin tags: winNativeHeap)
01:16
Make sure that SQLITE_FCNTL_SIZE_HINT on Windows does not shrink the file. (check-in: d4f6437f8d user: mistachkin tags: winNativeHeap)
2011-08-24
17:42
Add error logging to native Win32 heap support. (check-in: 7fca5a284c user: mistachkin tags: winNativeHeap)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/os_win.c.
1576
1577
1578
1579
1580
1581
1582

1583




1584
1585
1586


1587
1588
1589
1590
1591
1592
1593
1594
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_CHUNK_SIZE: {
      pFile->szChunk = *(int *)pArg;
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_SIZE_HINT: {

      sqlite3_int64 sz = *(sqlite3_int64*)pArg;




      SimulateIOErrorBenign(1);
      winTruncate(id, sz);
      SimulateIOErrorBenign(0);


      return SQLITE_OK;
    }
    case SQLITE_FCNTL_PERSIST_WAL: {
      int bPersist = *(int*)pArg;
      if( bPersist<0 ){
        *(int*)pArg = pFile->bPersistWal;
      }else{
        pFile->bPersistWal = bPersist!=0;







>
|
>
>
>
>
|
|
|
>
>
|







1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_CHUNK_SIZE: {
      pFile->szChunk = *(int *)pArg;
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_SIZE_HINT: {
      winFile *pFile = (winFile*)id;
      sqlite3_int64 oldSz;
      int rc = winFileSize(id, &oldSz);
      if( rc==SQLITE_OK ){
        sqlite3_int64 newSz = *(sqlite3_int64*)pArg;
        if( newSz>oldSz ){
          SimulateIOErrorBenign(1);
          rc = winTruncate(id, newSz);
          SimulateIOErrorBenign(0);
        }
      }
      return rc;
    }
    case SQLITE_FCNTL_PERSIST_WAL: {
      int bPersist = *(int*)pArg;
      if( bPersist<0 ){
        *(int*)pArg = pFile->bPersistWal;
      }else{
        pFile->bPersistWal = bPersist!=0;
Changes to test/pager1.test.
2414
2415
2416
2417
2418
2419
2420





































2421
2422
  
  hexio_write test.db2-journal 24 00000000
  sqlite3 db2 test.db2
  execsql { PRAGMA integrity_check } db2
} {ok}
}







































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
  
  hexio_write test.db2-journal 24 00000000
  sqlite3 db2 test.db2
  execsql { PRAGMA integrity_check } db2
} {ok}
}

#-------------------------------------------------------------------------
# Test that a database file can be "pre-hinted" to a certain size and that
# subsequent spilling of the pager cache does not result in the database
# file being shrunk.
#
catch {db close}
forcedelete test.db

do_test pager1-32.1 {
  sqlite3 db test.db
  execsql {
    CREATE TABLE t1(x, y);
  }
  db close
  sqlite3 db test.db
  execsql {
    BEGIN;
    INSERT INTO t1 VALUES(1, randomblob(10000));
  }
  file_control_sizehint_test db main 20971520; # 20MB
  execsql {
    PRAGMA cache_size = 10;
    INSERT INTO t1 VALUES(1, randomblob(10000));
    INSERT INTO t1 VALUES(2, randomblob(10000));
    INSERT INTO t1 SELECT x+2, randomblob(10000) from t1;
    INSERT INTO t1 SELECT x+4, randomblob(10000) from t1;
    INSERT INTO t1 SELECT x+8, randomblob(10000) from t1;
    INSERT INTO t1 SELECT x+16, randomblob(10000) from t1;
    SELECT count(*) FROM t1;
    COMMIT;
  }
  db close
  file size test.db
} {20971520}

# Cleanup 20MB file left by the previous test.
forcedelete test.db

finish_test