SQLite

Check-in [a9ec5ee472]
Login

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

Overview
Comment:Further coverage improvements for pager.c and another IO error bug fix. (CVS 3001)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a9ec5ee4724ab993e71ef8b387e2d92f3e74959c
User & Date: danielk1977 2006-01-23 15:25:48.000
Context
2006-01-23
15:39
Fix a bug in pager.c that was overwriting freed memory. Comment changes in util.c. (CVS 3002) (check-in: 8c7e18c3f2 user: drh tags: trunk)
15:25
Further coverage improvements for pager.c and another IO error bug fix. (CVS 3001) (check-in: a9ec5ee472 user: danielk1977 tags: trunk)
14:05
Fix os_common.h so that the code builds without -DSQLITE_MEMDEBUG. (CVS 3000) (check-in: 06d6540026 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pager.c.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.251 2006/01/23 13:47:47 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.252 2006/01/23 15:25:48 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
      if( rc!=SQLITE_OK ) goto end_stmt_playback;
    }
  }

  pPager->journalOff = szJ;
  
end_stmt_playback:
  if( rc!=SQLITE_OK ){
    rc = pager_error(pPager, SQLITE_CORRUPT);
  }else{
    pPager->journalOff = szJ;
    /* pager_reload_cache(pPager); */
  }
  return rc;
}

/*







|
<
<







1460
1461
1462
1463
1464
1465
1466
1467


1468
1469
1470
1471
1472
1473
1474
      if( rc!=SQLITE_OK ) goto end_stmt_playback;
    }
  }

  pPager->journalOff = szJ;
  
end_stmt_playback:
  if( rc==SQLITE_OK) {


    pPager->journalOff = szJ;
    /* pager_reload_cache(pPager); */
  }
  return rc;
}

/*
Changes to src/vdbeaux.c.
1290
1291
1292
1293
1294
1295
1296

1297


1298
1299
1300
1301
1302
1303
1304
      xFunc==sqlite3BtreeRollbackStmt
    );
    for(i=0; xFunc && i<db->nDb; i++){ 
      int rc;
      Btree *pBt = db->aDb[i].pBt;
      if( pBt ){
        rc = xFunc(pBt);

        if( p->rc==SQLITE_OK ) p->rc = rc;


      }
    }
  
    /* If this was an INSERT, UPDATE or DELETE and the statement was committed, 
    ** set the change counter. 
    */
    if( p->changeCntOn && p->pc>=0 ){







>
|
>
>







1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
      xFunc==sqlite3BtreeRollbackStmt
    );
    for(i=0; xFunc && i<db->nDb; i++){ 
      int rc;
      Btree *pBt = db->aDb[i].pBt;
      if( pBt ){
        rc = xFunc(pBt);
        if( rc && (p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT) ){
          p->rc = rc;
          sqlite3SetString(&p->zErrMsg, 0);
        }
      }
    }
  
    /* If this was an INSERT, UPDATE or DELETE and the statement was committed, 
    ** set the change counter. 
    */
    if( p->changeCntOn && p->pc>=0 ){
Changes to test/ioerr.test.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This file implements regression tests for SQLite library.  The
# focus of this file is testing for correct handling of I/O errors
# such as writes failing because the disk is full.
# 
# The tests in this file use special facilities that are only
# available in the SQLite test fixture.
#
# $Id: ioerr.test,v 1.22 2006/01/06 14:32:20 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl


# If SQLITE_DEFAULT_AUTOVACUUM is set to true, then a simulated IO error
# on the 8th IO operation in the SQL script below doesn't report an error.







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This file implements regression tests for SQLite library.  The
# focus of this file is testing for correct handling of I/O errors
# such as writes failing because the disk is full.
# 
# The tests in this file use special facilities that are only
# available in the SQLite test fixture.
#
# $Id: ioerr.test,v 1.23 2006/01/23 15:25:48 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl


# If SQLITE_DEFAULT_AUTOVACUUM is set to true, then a simulated IO error
# on the 8th IO operation in the SQL script below doesn't report an error.
197
198
199
200
201
202
203
204




















































205
    INSERT INTO t1 VALUES(randstr(200,200), randstr(1000,1000), 2);
  }
  db close
  sqlite3 db test.db
} -sqlbody {
  SELECT c FROM t1;
}





















































finish_test








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

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
    INSERT INTO t1 VALUES(randstr(200,200), randstr(1000,1000), 2);
  }
  db close
  sqlite3 db test.db
} -sqlbody {
  SELECT c FROM t1;
}

# For test coverage: Cause an IO error whilst reading the master-journal
# name from a journal file.
do_ioerr_test ioerr-9 -tclprep {
  execsql {
    CREATE TABLE t1(a,b,c);
    INSERT INTO t1 VALUES(randstr(200,200), randstr(1000,1000), 2);
    BEGIN;
    INSERT INTO t1 VALUES(randstr(200,200), randstr(1000,1000), 2);
  }
  copy_file test.db-journal test2.db-journal
  execsql {
    COMMIT;
  }
  copy_file test2.db-journal test.db-journal
  set f [open test.db-journal a]
  fconfigure $f -encoding binary
  puts -nonewline $f "hello"
  puts -nonewline $f "\x00\x00\x00\x05\x01\x02\x03\x04"
  puts -nonewline $f "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7"
  close $f
} -sqlbody {
  SELECT a FROM t1;
}

# For test coverage: Cause an IO error during statement playback (i.e. 
# a constraint).
do_ioerr_test ioerr-10 -tclprep {
  execsql {
    BEGIN;
    CREATE TABLE t1(a PRIMARY KEY, b);
  }
  for {set i 0} {$i < 500} {incr i} {
    execsql {INSERT INTO t1 VALUES($i, 'hello world');}
  }
  execsql {
    COMMIT;
  }
} -tclbody {

  catch {execsql {
    BEGIN;
    INSERT INTO t1 VALUES('abc', 123);
    INSERT INTO t1 VALUES('def', 123);
    INSERT INTO t1 VALUES('ghi', 123);
    INSERT INTO t1 SELECT (a+500)%900, 'good string' FROM t1;
  }} msg

  if {$msg != "column a is not unique"} {
    error $msg
  }
}

finish_test
Changes to test/pager.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is page cache subsystem.
#
# $Id: pager.test,v 1.24 2006/01/23 13:09:47 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

if {[info commands pager_open]!=""} {
db close













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is page cache subsystem.
#
# $Id: pager.test,v 1.25 2006/01/23 15:25:48 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

if {[info commands pager_open]!=""} {
db close
532
533
534
535
536
537
538




539


540








541








542
543
544
545
546
547
548
} {1 {database is locked}}
do_test pager-6.4.2 {
  file delete -force test.db-journal
  catchsql {
    SELECT sql FROM sqlite_master;
  } db3;
} {0 {{CREATE TABLE abc(a, b, c)}}}







do_test pager-6.5 {








  db2 close








  db3 close
} {}
}
finish_test










>
>
>
>
|
>
>

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






532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
} {1 {database is locked}}
do_test pager-6.4.2 {
  file delete -force test.db-journal
  catchsql {
    SELECT sql FROM sqlite_master;
  } db3;
} {0 {{CREATE TABLE abc(a, b, c)}}}
do_test pager-6.4.3 {
  db3 close
  execsql {
    COMMIT;
  }
} {}

do_test pager-6.5 {
  copy_file test2.db test.db
  copy_file test2.db-journal test.db-journal

  set f [open test.db-journal a]
  fconfigure $f -encoding binary
  puts -nonewline $f "hello"
  puts -nonewline $f "\x00\x00\x00\x05\x01\x02\x03\x04"
  puts -nonewline $f "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7"
  close $f

  sqlite3 db test.db
  execsql {
    SELECT sql FROM sqlite_master
  }
} {{CREATE TABLE abc(a, b, c)}}

do_test pager-6.5 {
  db2 close
} {}
}
finish_test