os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/createtab.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
# 2007 May 02
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 that it is OK to create new tables
sl@0
    13
# and indices while creating existing tables and indices.
sl@0
    14
#
sl@0
    15
# $Id: createtab.test,v 1.3 2007/09/12 17:01:45 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
ifcapable autovacuum {
sl@0
    21
  set upperBound 2
sl@0
    22
} else {
sl@0
    23
  set upperBound 0
sl@0
    24
}
sl@0
    25
sl@0
    26
# Run these tests for all possible values of autovacuum.
sl@0
    27
#
sl@0
    28
for {set av 0} {$av<=$upperBound} {incr av} {
sl@0
    29
  db close
sl@0
    30
  file delete -force test.db test.db-journal
sl@0
    31
  sqlite3 db test.db
sl@0
    32
sl@0
    33
  # Create a table that spans multiple pages.  It is important
sl@0
    34
  # that part of the database be in pages beyond the root page.
sl@0
    35
  #
sl@0
    36
  do_test createtab-$av.1 {
sl@0
    37
    execsql "PRAGMA auto_vacuum=$av"
sl@0
    38
    execsql {
sl@0
    39
      PRAGMA page_size=1024;
sl@0
    40
      CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
sl@0
    41
      INSERT INTO t1 VALUES(1, hex(randomblob(200)));
sl@0
    42
      INSERT INTO t1 VALUES(2, hex(randomblob(200)));
sl@0
    43
      INSERT INTO t1 VALUES(3, hex(randomblob(200)));
sl@0
    44
      INSERT INTO t1 VALUES(4, hex(randomblob(200)));
sl@0
    45
      SELECT count(*) FROM t1;
sl@0
    46
    }
sl@0
    47
  } {4}
sl@0
    48
sl@0
    49
  set isUtf16 0
sl@0
    50
  ifcapable utf16 { 
sl@0
    51
    set isUtf16 [expr {[execsql {PRAGMA encoding}] != "UTF-8"}]
sl@0
    52
  }
sl@0
    53
sl@0
    54
  do_test createtab-$av.2 {
sl@0
    55
    file size test.db
sl@0
    56
  } [expr {1024*(4+($av!=0)+(${isUtf16}*2))}]
sl@0
    57
  
sl@0
    58
  # Start reading the table
sl@0
    59
  #
sl@0
    60
  do_test createtab-$av.3 {
sl@0
    61
    set STMT [sqlite3_prepare db {SELECT x FROM t1} -1 TAIL]
sl@0
    62
    sqlite3_step $STMT
sl@0
    63
  } {SQLITE_ROW}
sl@0
    64
  do_test createtab-$av.4 {
sl@0
    65
    sqlite3_column_int $STMT 0
sl@0
    66
  } {1}
sl@0
    67
  
sl@0
    68
  # While still reading the table, create a new table.
sl@0
    69
  #
sl@0
    70
  do_test createtab-$av.5 {
sl@0
    71
    execsql {
sl@0
    72
      CREATE TABLE t2(a,b);
sl@0
    73
      INSERT INTO t2 VALUES(1,2);
sl@0
    74
      SELECT * FROM t2;
sl@0
    75
    }
sl@0
    76
  } {1 2}
sl@0
    77
  
sl@0
    78
  # Continue reading the original table.
sl@0
    79
  #
sl@0
    80
  do_test createtab-$av.6 {
sl@0
    81
    sqlite3_column_int $STMT 0
sl@0
    82
  } {1}
sl@0
    83
  do_test createtab-$av.7 {
sl@0
    84
    sqlite3_step $STMT
sl@0
    85
  } {SQLITE_ROW}
sl@0
    86
  do_test createtab-$av.8 {
sl@0
    87
    sqlite3_column_int $STMT 0
sl@0
    88
  } {2}
sl@0
    89
  
sl@0
    90
  # Do another cycle of creating a new database table while contining
sl@0
    91
  # to read the original table.
sl@0
    92
  #
sl@0
    93
  do_test createtab-$av.11 {
sl@0
    94
    execsql {
sl@0
    95
      CREATE TABLE t3(a,b);
sl@0
    96
      INSERT INTO t3 VALUES(4,5);
sl@0
    97
      SELECT * FROM t3;
sl@0
    98
    }
sl@0
    99
  } {4 5}
sl@0
   100
  do_test createtab-$av.12 {
sl@0
   101
    sqlite3_column_int $STMT 0
sl@0
   102
  } {2}
sl@0
   103
  do_test createtab-$av.13 {
sl@0
   104
    sqlite3_step $STMT
sl@0
   105
  } {SQLITE_ROW}
sl@0
   106
  do_test createtab-$av.14 {
sl@0
   107
    sqlite3_column_int $STMT 0
sl@0
   108
  } {3}
sl@0
   109
  
sl@0
   110
  # One more cycle.
sl@0
   111
  #
sl@0
   112
  do_test createtab-$av.21 {
sl@0
   113
    execsql {
sl@0
   114
      CREATE TABLE t4(a,b);
sl@0
   115
      INSERT INTO t4 VALUES('abc','xyz');
sl@0
   116
      SELECT * FROM t4;
sl@0
   117
    }
sl@0
   118
  } {abc xyz}
sl@0
   119
  do_test createtab-$av.22 {
sl@0
   120
    sqlite3_column_int $STMT 0
sl@0
   121
  } {3}
sl@0
   122
  do_test createtab-$av.23 {
sl@0
   123
    sqlite3_step $STMT
sl@0
   124
  } {SQLITE_ROW}
sl@0
   125
  do_test createtab-$av.24 {
sl@0
   126
    sqlite3_column_int $STMT 0
sl@0
   127
  } {4}
sl@0
   128
  
sl@0
   129
  # Finish reading.  Do an integrity check on the database.
sl@0
   130
  #
sl@0
   131
  do_test createtab-$av.30 {
sl@0
   132
    sqlite3_step $STMT
sl@0
   133
  } {SQLITE_DONE}
sl@0
   134
  do_test createtab-$av.31 {
sl@0
   135
    sqlite3_finalize $STMT
sl@0
   136
  } {SQLITE_OK}
sl@0
   137
  do_test createtab-$av.32 {
sl@0
   138
    execsql {
sl@0
   139
      SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1
sl@0
   140
    }
sl@0
   141
  } {t1 t2 t3 t4}
sl@0
   142
  integrity_check createtab-$av.40
sl@0
   143
sl@0
   144
}
sl@0
   145
  
sl@0
   146
finish_test