schema5.test 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # 2010 September 28
  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 checks corner cases in the CREATE TABLE syntax to make
  13. # sure that legacy syntax (syntax that is disallowed according to the
  14. # syntax diagrams) is still accepted, so that older databases that use
  15. # that syntax can still be read.
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # Table constraints should be separated by commas, but they do not have
  20. # to be.
  21. #
  22. do_test schema5-1.1 {
  23. db eval {
  24. CREATE TABLE t1(a,b,c, PRIMARY KEY(a) UNIQUE (a) CONSTRAINT one);
  25. INSERT INTO t1 VALUES(1,2,3);
  26. SELECT * FROM t1;
  27. }
  28. } {1 2 3}
  29. do_test schema5-1.2 {
  30. catchsql {INSERT INTO t1 VALUES(1,3,4);}
  31. } {1 {column a is not unique}}
  32. do_test schema5-1.3 {
  33. db eval {
  34. DROP TABLE t1;
  35. CREATE TABLE t1(a,b,c,
  36. CONSTRAINT one PRIMARY KEY(a) CONSTRAINT two CHECK(b<10) UNIQUE(b)
  37. CONSTRAINT three
  38. );
  39. INSERT INTO t1 VALUES(1,2,3);
  40. SELECT * FROM t1;
  41. }
  42. } {1 2 3}
  43. do_test schema5-1.4 {
  44. catchsql {INSERT INTO t1 VALUES(10,11,12);}
  45. } {1 {constraint two failed}}
  46. do_test schema5-1.5 {
  47. db eval {
  48. DROP TABLE t1;
  49. CREATE TABLE t1(a,b,c,
  50. UNIQUE(a) CONSTRAINT one,
  51. PRIMARY KEY(b,c) CONSTRAINT two
  52. );
  53. INSERT INTO t1 VALUES(1,2,3);
  54. }
  55. } {}
  56. do_test schema5-1.6 {
  57. catchsql {INSERT INTO t1 VALUES(1,3,4)}
  58. } {1 {column a is not unique}}
  59. do_test schema5-1.7 {
  60. catchsql {INSERT INTO t1 VALUES(10,2,3)}
  61. } {1 {columns b, c are not unique}}
  62. finish_test