#
# 2001 September 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is collation sequences in concert with triggers.
#
# $Id: collate6.test,v 1.1 2004/06/11 10:51:41 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a case-insensitive collation type NOCASE for use in testing. 
# Normally, capital letters are less than their lower-case counterparts.
db collate NOCASE nocase_collate
proc nocase_collate {a b} {
  return [string compare -nocase $a $b]
}

#
# Tests are organized as follows:
# collate6-1.* - triggers.
#

do_test collate6-1.0 {
  execsql {
    CREATE TABLE collate6log(a, b);
    CREATE TABLE collate6tab(a COLLATE NOCASE, b COLLATE BINARY);
  }
} {}

# Test that the default collation sequence applies to new.* references 
# in WHEN clauses.
do_test collate6-1.1 {
  execsql {
    CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab 
      WHEN new.a = 'a' BEGIN
        INSERT INTO collate6log VALUES(new.a, new.b);
    END;
  }
} {}
do_test collate6-1.2 {
  execsql {
    INSERT INTO collate6tab VALUES('a', 'b');
    SELECT * FROM collate6log;
  }
} {a b}
do_test collate6-1.3 {
  execsql {
    INSERT INTO collate6tab VALUES('A', 'B');
    SELECT * FROM collate6log;
  }
} {a b A B}
do_test collate6-1.4 {
  execsql {
    DROP TRIGGER collate6trig;
    DELETE FROM collate6log;
  } 
} {}

# Test that the default collation sequence applies to new.* references 
# in the body of triggers.
do_test collate6-1.5 {
  execsql {
    CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab BEGIN
      INSERT INTO collate6log VALUES(new.a='a', new.b='b');
    END;
  }
} {}
do_test collate6-1.6 {
  execsql {
    INSERT INTO collate6tab VALUES('a', 'b');
    SELECT * FROM collate6log;
  }
} {1 1}
do_test collate6-1.7 {
  execsql {
    INSERT INTO collate6tab VALUES('A', 'B');
    SELECT * FROM collate6log;
  }
} {1 1 1 0}
do_test collate6-1.8 {
  execsql {
    DROP TRIGGER collate6trig;
    DELETE FROM collate6log;
  } 
} {}

do_test collate6-1.9 {
  execsql {
    DROP TABLE collate6tab;
  }
} {}


finish_test



