File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sqlite3 / test / trigger7.test
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:04:16 2012 UTC (12 years, 10 months ago) by misho
Branches: sqlite3, MAIN
CVS tags: v3_7_10, HEAD
sqlite3

    1: # 2005 August 18
    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 to increase coverage of trigger.c.
   14: #
   15: # $Id: trigger7.test,v 1.1.1.1 2012/02/21 17:04:16 misho Exp $
   16: 
   17: set testdir [file dirname $argv0]
   18: source $testdir/tester.tcl
   19: ifcapable {!trigger} {
   20:   finish_test
   21:   return
   22: }
   23: 
   24: 
   25: # Error messages resulting from qualified trigger names.
   26: #
   27: do_test trigger7-1.1 {
   28:   execsql {
   29:     CREATE TABLE t1(x, y);
   30:   }
   31:   catchsql {
   32:     CREATE TEMP TRIGGER main.r1 AFTER INSERT ON t1 BEGIN
   33:       SELECT 'no nothing';
   34:     END
   35:   }
   36: } {1 {temporary trigger may not have qualified name}}
   37: do_test trigger7-1.2 {
   38:   catchsql {
   39:     CREATE TRIGGER not_a_db.r1 AFTER INSERT ON t1 BEGIN
   40:       SELECT 'no nothing';
   41:     END
   42:   }
   43: } {1 {unknown database not_a_db}}
   44: 
   45: 
   46: # When the UPDATE OF syntax is used, no code is generated for triggers
   47: # that do not match the update columns.
   48: #
   49: ifcapable explain {
   50:   do_test trigger7-2.1 {
   51:     execsql {
   52:       CREATE TRIGGER r1 AFTER UPDATE OF x ON t1 BEGIN
   53:         SELECT '___update_t1.x___';
   54:       END;
   55:       CREATE TRIGGER r2 AFTER UPDATE OF y ON t1 BEGIN
   56:         SELECT '___update_t1.y___';
   57:       END;
   58:     }
   59:     set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
   60:     string match *___update_t1.x___* $txt
   61:   } 1
   62:   do_test trigger7-2.2 {
   63:     set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
   64:     string match *___update_t1.y___* $txt
   65:   } 0
   66:   do_test trigger7-2.3 {
   67:     set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
   68:     string match *___update_t1.x___* $txt
   69:   } 0
   70:   do_test trigger7-2.4 {
   71:     set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
   72:     string match *___update_t1.y___* $txt
   73:   } 1
   74:   do_test trigger7-2.5 {
   75:     set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
   76:     string match *___update_t1.x___* $txt
   77:   } 0
   78:   do_test trigger7-2.6 {
   79:     set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
   80:     string match *___update_t1.x___* $txt
   81:   } 0
   82: }
   83: 
   84: # Test the ability to create many triggers on the same table, then
   85: # selectively drop those triggers.
   86: #
   87: do_test trigger7-3.1 {
   88:   execsql {
   89:     CREATE TABLE t2(x,y,z);
   90:     CREATE TRIGGER t2r1 AFTER INSERT ON t2 BEGIN SELECT 1; END;
   91:     CREATE TRIGGER t2r2 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
   92:     CREATE TRIGGER t2r3 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
   93:     CREATE TRIGGER t2r4 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
   94:     CREATE TRIGGER t2r5 AFTER DELETE ON t2 BEGIN SELECT 1; END;
   95:     CREATE TRIGGER t2r6 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
   96:     CREATE TRIGGER t2r7 AFTER INSERT ON t2 BEGIN SELECT 1; END;
   97:     CREATE TRIGGER t2r8 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
   98:     CREATE TRIGGER t2r9 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
   99:     CREATE TRIGGER t2r10 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
  100:     CREATE TRIGGER t2r11 AFTER DELETE ON t2 BEGIN SELECT 1; END;
  101:     CREATE TRIGGER t2r12 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
  102:     DROP TRIGGER t2r6;
  103:   }
  104: } {}
  105: 
  106: # This test corrupts the database file so it must be the last test
  107: # in the series.
  108: #
  109: do_test trigger7-99.1 {
  110:   execsql {
  111:     PRAGMA writable_schema=on;
  112:     UPDATE sqlite_master SET sql='nonsense';
  113:   }
  114:   db close
  115:   catch { sqlite3 db test.db }
  116:   catchsql { DROP TRIGGER t2r5 }
  117: } {1 {malformed database schema (t2r12) - near "nonsense": syntax error}}
  118: 
  119: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>