os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/tkt2192.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 January 26
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 to verify that ticket #2192 has been
sl@0
    14
# fixed.  
sl@0
    15
#
sl@0
    16
#
sl@0
    17
# $Id: tkt2192.test,v 1.3 2008/08/04 03:51:24 danielk1977 Exp $
sl@0
    18
sl@0
    19
set testdir [file dirname $argv0]
sl@0
    20
source $testdir/tester.tcl
sl@0
    21
sl@0
    22
ifcapable !datetime||!compound {
sl@0
    23
  finish_test
sl@0
    24
  return
sl@0
    25
}
sl@0
    26
sl@0
    27
do_test tkt2192-1.1 {
sl@0
    28
  execsql {
sl@0
    29
    -- Raw data (RBS) --------
sl@0
    30
    
sl@0
    31
    create table records (
sl@0
    32
      date          real,
sl@0
    33
      type          text,
sl@0
    34
      description   text,
sl@0
    35
      value         integer,
sl@0
    36
      acc_name      text,
sl@0
    37
      acc_no        text
sl@0
    38
    );
sl@0
    39
    
sl@0
    40
    -- Direct Debits ----------------
sl@0
    41
    create view direct_debits as
sl@0
    42
      select * from records where type = 'D/D';
sl@0
    43
    
sl@0
    44
    create view monthly_direct_debits as
sl@0
    45
      select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
sl@0
    46
        from direct_debits
sl@0
    47
       group by strftime('%Y-%m', date);
sl@0
    48
    
sl@0
    49
    -- Expense Categories ---------------
sl@0
    50
    create view energy as
sl@0
    51
      select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
sl@0
    52
        from direct_debits
sl@0
    53
       where description like '%NPOWER%'
sl@0
    54
       group by strftime('%Y-%m', date);
sl@0
    55
    
sl@0
    56
    create view phone_internet as
sl@0
    57
      select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
sl@0
    58
        from direct_debits
sl@0
    59
       where description like '%BT DIRECT%'
sl@0
    60
          or description like '%SUPANET%'
sl@0
    61
          or description like '%ORANGE%'
sl@0
    62
       group by strftime('%Y-%m', date);
sl@0
    63
    
sl@0
    64
    create view credit_cards as
sl@0
    65
      select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
sl@0
    66
        from direct_debits where description like '%VISA%'
sl@0
    67
       group by strftime('%Y-%m', date);
sl@0
    68
    
sl@0
    69
    -- Overview ---------------------
sl@0
    70
    
sl@0
    71
    create view expense_overview as
sl@0
    72
      select 'Energy' as expense, date, value from energy
sl@0
    73
      union
sl@0
    74
      select 'Phone/Internet' as expense, date, value from phone_internet
sl@0
    75
      union
sl@0
    76
      select 'Credit Card' as expense, date, value from credit_cards;
sl@0
    77
    
sl@0
    78
    create view jan as
sl@0
    79
      select 'jan', expense, value from expense_overview
sl@0
    80
       where date like '%-01';
sl@0
    81
    
sl@0
    82
    create view nov as
sl@0
    83
      select 'nov', expense, value from expense_overview
sl@0
    84
       where date like '%-11';
sl@0
    85
    
sl@0
    86
    create view summary as
sl@0
    87
      select * from jan join nov on (jan.expense = nov.expense);
sl@0
    88
  }
sl@0
    89
} {}
sl@0
    90
do_test tkt2192-1.2 {
sl@0
    91
  # set ::sqlite_addop_trace 1
sl@0
    92
  execsql {
sl@0
    93
    select * from summary;
sl@0
    94
  }
sl@0
    95
} {}
sl@0
    96
do_test tkt2192-2.1 {
sl@0
    97
  execsql {
sl@0
    98
    CREATE TABLE t1(a,b);
sl@0
    99
    CREATE VIEW v1 AS
sl@0
   100
      SELECT * FROM t1 WHERE b%7=0 UNION SELECT * FROM t1 WHERE b%5=0;
sl@0
   101
    INSERT INTO t1 VALUES(1,7);
sl@0
   102
    INSERT INTO t1 VALUES(2,10);
sl@0
   103
    INSERT INTO t1 VALUES(3,14);
sl@0
   104
    INSERT INTO t1 VALUES(4,15);
sl@0
   105
    INSERT INTO t1 VALUES(1,16);
sl@0
   106
    INSERT INTO t1 VALUES(2,17);
sl@0
   107
    INSERT INTO t1 VALUES(3,20);
sl@0
   108
    INSERT INTO t1 VALUES(4,21);
sl@0
   109
    INSERT INTO t1 VALUES(1,22);
sl@0
   110
    INSERT INTO t1 VALUES(2,24);
sl@0
   111
    INSERT INTO t1 VALUES(3,25);
sl@0
   112
    INSERT INTO t1 VALUES(4,26);
sl@0
   113
    INSERT INTO t1 VALUES(1,27);
sl@0
   114
 
sl@0
   115
    SELECT b FROM v1 ORDER BY b;
sl@0
   116
  }
sl@0
   117
} {7 10 14 15 20 21 25}
sl@0
   118
do_test tkt2192-2.2 {
sl@0
   119
  execsql {
sl@0
   120
    SELECT * FROM v1 ORDER BY a, b;
sl@0
   121
  }
sl@0
   122
} {1 7 2 10 3 14 3 20 3 25 4 15 4 21}
sl@0
   123
do_test tkt2192-2.3 {
sl@0
   124
  execsql {
sl@0
   125
    SELECT x.a || '/' || x.b || '/' || y.b
sl@0
   126
      FROM v1 AS x JOIN v1 AS y ON x.a=y.a AND x.b<y.b
sl@0
   127
     ORDER BY x.a, x.b, y.b
sl@0
   128
  }
sl@0
   129
} {3/14/20 3/14/25 3/20/25 4/15/21}
sl@0
   130
do_test tkt2192-2.4 {
sl@0
   131
  execsql {
sl@0
   132
    CREATE VIEW v2 AS
sl@0
   133
    SELECT x.a || '/' || x.b || '/' || y.b AS z
sl@0
   134
      FROM v1 AS x JOIN v1 AS y ON x.a=y.a AND x.b<y.b
sl@0
   135
     ORDER BY x.a, x.b, y.b;
sl@0
   136
    SELECT * FROM v2;
sl@0
   137
  }
sl@0
   138
} {3/14/20 3/14/25 3/20/25 4/15/21}
sl@0
   139
sl@0
   140
finish_test