os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/pragma2.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
# 2002 March 6
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.
sl@0
    12
#
sl@0
    13
# This file implements tests for the PRAGMA command.
sl@0
    14
#
sl@0
    15
# $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
# Test organization:
sl@0
    21
#
sl@0
    22
# pragma2-1.*: Test freelist_count pragma on the main database.
sl@0
    23
# pragma2-2.*: Test freelist_count pragma on an attached database.
sl@0
    24
# pragma2-3.*: Test trying to write to the freelist_count is a no-op.
sl@0
    25
#
sl@0
    26
sl@0
    27
ifcapable !pragma||!schema_pragmas {
sl@0
    28
  finish_test
sl@0
    29
  return
sl@0
    30
}
sl@0
    31
sl@0
    32
# Delete the preexisting database to avoid the special setup
sl@0
    33
# that the "all.test" script does.
sl@0
    34
#
sl@0
    35
db close
sl@0
    36
file delete test.db test.db-journal
sl@0
    37
file delete test3.db test3.db-journal
sl@0
    38
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
sl@0
    39
db eval {PRAGMA auto_vacuum=0}
sl@0
    40
sl@0
    41
do_test pragma2-1.1 {
sl@0
    42
  execsql {
sl@0
    43
    PRAGMA freelist_count;
sl@0
    44
  }
sl@0
    45
} {0}
sl@0
    46
do_test pragma2-1.2 {
sl@0
    47
  execsql {
sl@0
    48
    CREATE TABLE abc(a, b, c);
sl@0
    49
    PRAGMA freelist_count;
sl@0
    50
  }
sl@0
    51
} {0}
sl@0
    52
do_test pragma2-1.3 {
sl@0
    53
  execsql {
sl@0
    54
    DROP TABLE abc;
sl@0
    55
    PRAGMA freelist_count;
sl@0
    56
  }
sl@0
    57
} {1}
sl@0
    58
do_test pragma2-1.4 {
sl@0
    59
  execsql {
sl@0
    60
    PRAGMA main.freelist_count;
sl@0
    61
  }
sl@0
    62
} {1}
sl@0
    63
sl@0
    64
file delete -force test2.db
sl@0
    65
file delete -force test2.db-journal
sl@0
    66
sl@0
    67
ifcapable attach {
sl@0
    68
  do_test pragma2-2.1 {
sl@0
    69
    execsql {
sl@0
    70
      ATTACH 'test2.db' AS aux;
sl@0
    71
      PRAGMA aux.auto_vacuum=OFF;
sl@0
    72
      PRAGMA aux.freelist_count;
sl@0
    73
    }
sl@0
    74
  } {0}
sl@0
    75
  do_test pragma2-2.2 {
sl@0
    76
    execsql {
sl@0
    77
      CREATE TABLE aux.abc(a, b, c);
sl@0
    78
      PRAGMA aux.freelist_count;
sl@0
    79
    }
sl@0
    80
  } {0}
sl@0
    81
  do_test pragma2-2.3 {
sl@0
    82
    set ::val [string repeat 0123456789 1000]
sl@0
    83
    execsql {
sl@0
    84
      INSERT INTO aux.abc VALUES(1, 2, $::val);
sl@0
    85
      PRAGMA aux.freelist_count;
sl@0
    86
    }
sl@0
    87
  } {0}
sl@0
    88
  do_test pragma2-2.4 {
sl@0
    89
    expr {[file size test2.db] / 1024}
sl@0
    90
  } {11}
sl@0
    91
  do_test pragma2-2.5 {
sl@0
    92
    execsql {
sl@0
    93
      DELETE FROM aux.abc;
sl@0
    94
      PRAGMA aux.freelist_count;
sl@0
    95
    }
sl@0
    96
  } {9}
sl@0
    97
  
sl@0
    98
  do_test pragma2-3.1 {
sl@0
    99
    execsql {
sl@0
   100
      PRAGMA aux.freelist_count;
sl@0
   101
      PRAGMA main.freelist_count;
sl@0
   102
      PRAGMA freelist_count;
sl@0
   103
    }
sl@0
   104
  } {9 1 1}
sl@0
   105
  do_test pragma2-3.2 {
sl@0
   106
    execsql {
sl@0
   107
      PRAGMA freelist_count = 500;
sl@0
   108
      PRAGMA freelist_count;
sl@0
   109
    }
sl@0
   110
  } {1 1}
sl@0
   111
  do_test pragma2-3.3 {
sl@0
   112
    execsql {
sl@0
   113
      PRAGMA aux.freelist_count = 500;
sl@0
   114
      PRAGMA aux.freelist_count;
sl@0
   115
    }
sl@0
   116
  } {9 9}
sl@0
   117
}
sl@0
   118
sl@0
   119
finish_test