gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/tkt-cbd054fa6b.test (about)

     1  # 2010 March 25
     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  #
    12  # This file implements tests to verify that ticket [cbd054fa6b] has been
    13  # fixed.  
    14  #
    15  
    16  set testdir [file dirname $argv0]
    17  source $testdir/tester.tcl
    18  
    19  ifcapable !stat4 {
    20    finish_test
    21    return
    22  }
    23  
    24  proc s {blob} {
    25    set ret ""
    26    binary scan $blob c* bytes
    27    foreach b $bytes {
    28      set t [binary format c $b]
    29      if {[string is print $t]} {
    30        append ret $t
    31      } else {
    32        append ret .
    33      }
    34    }
    35    return $ret
    36  }
    37  db function s s
    38  
    39  do_test tkt-cbd05-1.1 {
    40    db eval {
    41      CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT UNIQUE NOT NULL);
    42      CREATE INDEX t1_x ON t1(b);
    43      INSERT INTO t1 VALUES (NULL, '');
    44      INSERT INTO t1 VALUES (NULL, 'A');
    45      INSERT INTO t1 VALUES (NULL, 'B');
    46      INSERT INTO t1 VALUES (NULL, 'C');
    47      INSERT INTO t1 VALUES (NULL, 'D');
    48      INSERT INTO t1 VALUES (NULL, 'E');
    49      INSERT INTO t1 VALUES (NULL, 'F');
    50      INSERT INTO t1 VALUES (NULL, 'G');
    51      INSERT INTO t1 VALUES (NULL, 'H');
    52      INSERT INTO t1 VALUES (NULL, 'I');
    53      SELECT count(*) FROM t1;
    54    }
    55  } {10}
    56  do_test tkt-cbd05-1.2 {
    57    db eval { ANALYZE; }
    58    db eval {
    59      PRAGMA writable_schema = 1;
    60      CREATE VIEW vvv AS 
    61      SELECT tbl,idx,neq,nlt,ndlt,test_extract(sample,0) AS sample
    62      FROM sqlite_stat4;
    63      PRAGMA writable_schema = 0;
    64    }
    65  } {}
    66  do_test tkt-cbd05-1.3 {
    67    execsql { 
    68      SELECT tbl,idx,group_concat(s(sample),' ') 
    69      FROM vvv 
    70      WHERE idx = 't1_x' 
    71      GROUP BY tbl,idx
    72    }
    73  } {t1 t1_x { A B C D E F G H I}}
    74  
    75  do_test tkt-cbd05-2.1 {
    76    db eval {
    77      DROP TABLE t1;
    78      CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB UNIQUE NOT NULL);
    79      CREATE INDEX t1_x ON t1(b);
    80      INSERT INTO t1 VALUES(NULL, X'');
    81      INSERT INTO t1 VALUES(NULL, X'41');
    82      INSERT INTO t1 VALUES(NULL, X'42');
    83      INSERT INTO t1 VALUES(NULL, X'43');
    84      INSERT INTO t1 VALUES(NULL, X'44');
    85      INSERT INTO t1 VALUES(NULL, X'45');
    86      INSERT INTO t1 VALUES(NULL, X'46');
    87      INSERT INTO t1 VALUES(NULL, X'47');
    88      INSERT INTO t1 VALUES(NULL, X'48');
    89      INSERT INTO t1 VALUES(NULL, X'49');
    90      SELECT count(*) FROM t1;
    91    }
    92  } {10}
    93  do_test tkt-cbd05-2.2 {
    94    db eval {
    95      ANALYZE;
    96    }
    97  } {}
    98  do_test tkt-cbd05-2.3 {
    99    execsql { 
   100      SELECT tbl,idx,group_concat(s(sample),' ') 
   101      FROM vvv 
   102      WHERE idx = 't1_x' 
   103      GROUP BY tbl,idx
   104    }
   105  } {t1 t1_x { A B C D E F G H I}}
   106  
   107  finish_test