persistentstorage/sqlite3api/TEST/TclScript/manydb.test
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 # 2005 October 3
       
     2 #
       
     3 # The author disclaims copyright to this source code.  In place of
       
     4 # a legal notice, here is a blessing:
       
     5 #
       
     6 #    May you do good and not evil.
       
     7 #    May you find forgiveness for yourself and forgive others.
       
     8 #    May you share freely, never taking more than you give.
       
     9 #
       
    10 #***********************************************************************
       
    11 # This file implements regression tests for SQLite library.
       
    12 #
       
    13 # This file implements tests the ability of the library to open
       
    14 # many different databases at the same time without leaking memory.
       
    15 #
       
    16 # $Id: manydb.test,v 1.3 2006/01/11 01:08:34 drh Exp $
       
    17 
       
    18 set testdir [file dirname $argv0]
       
    19 source $testdir/tester.tcl
       
    20 
       
    21 set N 300
       
    22 
       
    23 # First test how many file descriptors are available for use. To open a
       
    24 # database for writing SQLite requires 3 file descriptors (the database, the
       
    25 # journal and the directory).
       
    26 set filehandles {}
       
    27 catch {
       
    28   for {set i 0} {$i<($N * 3)} {incr i} {
       
    29     lappend filehandles [open testfile.1 w]
       
    30   }
       
    31 }
       
    32 foreach fd $filehandles {
       
    33   close $fd
       
    34 }
       
    35 catch {
       
    36   file delete -force testfile.1
       
    37 }
       
    38 set N [expr $i / 3]
       
    39 
       
    40 # Create a bunch of random database names
       
    41 #
       
    42 unset -nocomplain dbname
       
    43 unset -nocomplain used
       
    44 for {set i 0} {$i<$N} {incr i} {
       
    45   while 1 {
       
    46     set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
       
    47     if {[info exists used($name)]} continue
       
    48     set dbname($i) $name
       
    49     set used($name) $i
       
    50     break
       
    51   }
       
    52 }
       
    53 
       
    54 # Create a bunch of databases
       
    55 #
       
    56 for {set i 0} {$i<$N} {incr i} {
       
    57   do_test manydb-1.$i {
       
    58     sqlite3 db$i $dbname($i)
       
    59     execsql {
       
    60        CREATE TABLE t1(a,b);
       
    61        BEGIN;
       
    62        INSERT INTO t1 VALUES(1,2);
       
    63     } db$i
       
    64   } {}
       
    65 }
       
    66 
       
    67 # Finish the transactions
       
    68 #
       
    69 for {set i 0} {$i<$N} {incr i} {
       
    70   do_test manydb-2.$i {
       
    71     execsql {
       
    72        COMMIT;
       
    73        SELECT * FROM t1;
       
    74     } db$i
       
    75   } {1 2}
       
    76 }
       
    77 
       
    78 
       
    79 # Close the databases and erase the files.
       
    80 #
       
    81 for {set i 0} {$i<$N} {incr i} {
       
    82   do_test manydb-3.$i {
       
    83     db$i close
       
    84     file delete -force $dbname($i)
       
    85   } {}
       
    86 }
       
    87 
       
    88 
       
    89 
       
    90 
       
    91 finish_test