fkey7.test 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # 2001 September 15
  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 for foreign keys.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. set testprefix fkey7
  18. ifcapable {!foreignkey} {
  19. finish_test
  20. return
  21. }
  22. do_execsql_test 1.1 {
  23. PRAGMA foreign_keys = 1;
  24. CREATE TABLE s1(a PRIMARY KEY, b);
  25. CREATE TABLE par(a, b REFERENCES s1, c UNIQUE, PRIMARY KEY(a));
  26. CREATE TABLE c1(a, b REFERENCES par);
  27. CREATE TABLE c2(a, b REFERENCES par);
  28. CREATE TABLE c3(a, b REFERENCES par(c));
  29. }
  30. proc auth {op tbl args} {
  31. if {$op == "SQLITE_READ"} { set ::tbls($tbl) 1 }
  32. return "SQLITE_OK"
  33. }
  34. db auth auth
  35. db cache size 0
  36. proc do_tblsread_test {tn sql tbllist} {
  37. array unset ::tbls
  38. uplevel [list execsql $sql]
  39. uplevel [list do_test $tn {lsort [array names ::tbls]} $tbllist]
  40. }
  41. do_tblsread_test 1.2 { UPDATE par SET b=? WHERE a=? } {par s1}
  42. do_tblsread_test 1.3 { UPDATE par SET a=? WHERE b=? } {c1 c2 par}
  43. do_tblsread_test 1.4 { UPDATE par SET c=? WHERE b=? } {c3 par}
  44. do_tblsread_test 1.5 { UPDATE par SET a=?,b=?,c=? WHERE b=? } {c1 c2 c3 par s1}
  45. finish_test