aggerror.test 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # 2006 January 20
  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 calling sqlite3_result_error()
  14. # from within an aggregate function implementation.
  15. #
  16. # $Id: aggerror.test,v 1.3 2006/05/03 23:34:06 drh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # Add the x_count aggregate function to the database handle.
  20. # x_count will error out if its input is 40 or 41 or if its
  21. # final results is 42. Make sure that such errors are handled
  22. # appropriately.
  23. #
  24. do_test aggerror-1.1 {
  25. set DB [sqlite3_connection_pointer db]
  26. sqlite3_create_aggregate $DB
  27. execsql {
  28. CREATE TABLE t1(a);
  29. INSERT INTO t1 VALUES(1);
  30. INSERT INTO t1 VALUES(2);
  31. INSERT INTO t1 SELECT a+2 FROM t1;
  32. INSERT INTO t1 SELECT a+4 FROM t1;
  33. INSERT INTO t1 SELECT a+8 FROM t1;
  34. INSERT INTO t1 SELECT a+16 FROM t1;
  35. INSERT INTO t1 SELECT a+32 FROM t1 ORDER BY a LIMIT 7;
  36. SELECT x_count(*) FROM t1;
  37. }
  38. } {39}
  39. do_test aggerror-1.2 {
  40. execsql {
  41. INSERT INTO t1 VALUES(40);
  42. SELECT x_count(*) FROM t1;
  43. }
  44. } {40}
  45. do_test aggerror-1.3 {
  46. catchsql {
  47. SELECT x_count(a) FROM t1;
  48. }
  49. } {1 {value of 40 handed to x_count}}
  50. ifcapable utf16 {
  51. do_test aggerror-1.4 {
  52. execsql {
  53. UPDATE t1 SET a=41 WHERE a=40
  54. }
  55. catchsql {
  56. SELECT x_count(a) FROM t1;
  57. }
  58. } {1 abc}
  59. }
  60. do_test aggerror-1.5 {
  61. execsql {
  62. SELECT x_count(*) FROM t1
  63. }
  64. } 40
  65. do_test aggerror-1.6 {
  66. execsql {
  67. INSERT INTO t1 VALUES(40);
  68. INSERT INTO t1 VALUES(42);
  69. }
  70. catchsql {
  71. SELECT x_count(*) FROM t1;
  72. }
  73. } {1 {x_count totals to 42}}
  74. finish_test