os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vacuum2.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2005 February 15
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.  The
sl@0
    12
# focus of this file is testing the VACUUM statement.
sl@0
    13
#
sl@0
    14
# $Id: vacuum2.test,v 1.8 2008/08/23 16:17:56 danielk1977 Exp $
sl@0
    15
sl@0
    16
set testdir [file dirname $argv0]
sl@0
    17
source $testdir/tester.tcl
sl@0
    18
sl@0
    19
# If the VACUUM statement is disabled in the current build, skip all
sl@0
    20
# the tests in this file.
sl@0
    21
#
sl@0
    22
ifcapable {!vacuum||!autoinc} {
sl@0
    23
  finish_test
sl@0
    24
  return
sl@0
    25
}
sl@0
    26
if $AUTOVACUUM {
sl@0
    27
  finish_test
sl@0
    28
  return
sl@0
    29
}
sl@0
    30
sl@0
    31
# Ticket #1121 - make sure vacuum works if all autoincrement tables
sl@0
    32
# have been deleted.
sl@0
    33
#
sl@0
    34
do_test vacuum2-1.1 {
sl@0
    35
  execsql {
sl@0
    36
    CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
sl@0
    37
    DROP TABLE t1;
sl@0
    38
    VACUUM;
sl@0
    39
  }
sl@0
    40
} {}
sl@0
    41
sl@0
    42
# Ticket #2518.  Make sure vacuum increments the change counter
sl@0
    43
# in the database header.
sl@0
    44
#
sl@0
    45
do_test vacuum2-2.1 {
sl@0
    46
  execsql {
sl@0
    47
    CREATE TABLE t1(x);
sl@0
    48
    CREATE TABLE t2(y);
sl@0
    49
    INSERT INTO t1 VALUES(1);
sl@0
    50
  }
sl@0
    51
  hexio_get_int [hexio_read test.db 24 4]
sl@0
    52
} [expr {[hexio_get_int [hexio_read test.db 24 4]]+3}]
sl@0
    53
do_test vacuum2-2.1 {
sl@0
    54
  execsql {
sl@0
    55
    VACUUM
sl@0
    56
  }
sl@0
    57
  hexio_get_int [hexio_read test.db 24 4]
sl@0
    58
} [expr {[hexio_get_int [hexio_read test.db 24 4]]+1}]
sl@0
    59
sl@0
    60
############################################################################
sl@0
    61
# Verify that we can use the auto_vacuum pragma to request a new
sl@0
    62
# autovacuum setting, do a VACUUM, and the new setting takes effect.
sl@0
    63
# Make sure this happens correctly even if there are multiple open
sl@0
    64
# connections to the same database file.
sl@0
    65
#
sl@0
    66
sqlite3 db2 test.db
sl@0
    67
set pageSize [db eval {pragma page_size}]
sl@0
    68
sl@0
    69
# We are currently not autovacuuming so the database should be 3 pages
sl@0
    70
# in size.  1 page for each of sqlite_master, t1, and t2.
sl@0
    71
#
sl@0
    72
do_test vacuum2-3.1 {
sl@0
    73
  execsql {
sl@0
    74
    INSERT INTO t1 VALUES('hello');
sl@0
    75
    INSERT INTO t2 VALUES('out there');
sl@0
    76
  }
sl@0
    77
  expr {[file size test.db]/$pageSize}
sl@0
    78
} {3}
sl@0
    79
set cksum [cksum]
sl@0
    80
do_test vacuum2-3.2 {
sl@0
    81
  cksum db2
sl@0
    82
} $cksum
sl@0
    83
sl@0
    84
# Convert the database to an autovacuumed database.
sl@0
    85
do_test vacuum2-3.3 {
sl@0
    86
  execsql {
sl@0
    87
    PRAGMA auto_vacuum=FULL;
sl@0
    88
    VACUUM;
sl@0
    89
  }
sl@0
    90
  expr {[file size test.db]/$pageSize}
sl@0
    91
} {4}
sl@0
    92
do_test vacuum2-3.4 {
sl@0
    93
  cksum db2
sl@0
    94
} $cksum
sl@0
    95
do_test vacuum2-3.5 {
sl@0
    96
  cksum
sl@0
    97
} $cksum
sl@0
    98
do_test vacuum2-3.6 {
sl@0
    99
  execsql {PRAGMA integrity_check} db2
sl@0
   100
} {ok}
sl@0
   101
do_test vacuum2-3.7 {
sl@0
   102
  execsql {PRAGMA integrity_check} db
sl@0
   103
} {ok}
sl@0
   104
sl@0
   105
# Convert the database back to a non-autovacuumed database.
sl@0
   106
do_test vacuum2-3.13 {
sl@0
   107
  execsql {
sl@0
   108
    PRAGMA auto_vacuum=NONE;
sl@0
   109
    VACUUM;
sl@0
   110
  }
sl@0
   111
  expr {[file size test.db]/$pageSize}
sl@0
   112
} {3}
sl@0
   113
do_test vacuum2-3.14 {
sl@0
   114
  cksum db2
sl@0
   115
} $cksum
sl@0
   116
do_test vacuum2-3.15 {
sl@0
   117
  cksum
sl@0
   118
} $cksum
sl@0
   119
do_test vacuum2-3.16 {
sl@0
   120
  execsql {PRAGMA integrity_check} db2
sl@0
   121
} {ok}
sl@0
   122
do_test vacuum2-3.17 {
sl@0
   123
  execsql {PRAGMA integrity_check} db
sl@0
   124
} {ok}
sl@0
   125
sl@0
   126
db2 close
sl@0
   127
sl@0
   128
ifcapable autovacuum {
sl@0
   129
  do_test vacuum2-4.1 {
sl@0
   130
    db close
sl@0
   131
    file delete -force test.db
sl@0
   132
    sqlite3 db test.db
sl@0
   133
    execsql {
sl@0
   134
      pragma auto_vacuum=1;
sl@0
   135
      create table t(a, b);
sl@0
   136
      insert into t values(1, 2);
sl@0
   137
      insert into t values(1, 2);
sl@0
   138
      pragma auto_vacuum=0;
sl@0
   139
      vacuum;
sl@0
   140
      pragma auto_vacuum;
sl@0
   141
    }
sl@0
   142
  } {0}
sl@0
   143
  do_test vacuum2-4.2 {
sl@0
   144
    execsql {
sl@0
   145
      pragma auto_vacuum=1;
sl@0
   146
      vacuum;
sl@0
   147
      pragma auto_vacuum;
sl@0
   148
    }
sl@0
   149
  } {1}
sl@0
   150
  do_test vacuum2-4.3 {
sl@0
   151
    execsql {
sl@0
   152
      pragma integrity_check
sl@0
   153
    }
sl@0
   154
  } {ok}
sl@0
   155
  do_test vacuum2-4.4 {
sl@0
   156
    execsql {
sl@0
   157
      pragma auto_vacuum;
sl@0
   158
    }
sl@0
   159
  } {1}
sl@0
   160
}
sl@0
   161
sl@0
   162
finish_test