attachmalloc.test 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # 2005 September 19
  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. The
  12. # focus of this script is testing the ATTACH statement and
  13. # specifically out-of-memory conditions within that command.
  14. #
  15. # $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. ifcapable !memdebug||!attach {
  20. finish_test
  21. return
  22. }
  23. source $testdir/malloc_common.tcl
  24. do_malloc_test attachmalloc-1 -tclprep {
  25. catch { db close }
  26. for {set i 2} {$i<=4} {incr i} {
  27. catch { db$i close }
  28. forcedelete test$i.db
  29. forcedelete test$i.db-journal
  30. }
  31. } -tclbody {
  32. if {[catch {sqlite3 db test.db}]} {
  33. error "out of memory"
  34. }
  35. sqlite3_db_config_lookaside db 0 0 0
  36. sqlite3_extended_result_codes db 1
  37. } -sqlbody {
  38. ATTACH 'test2.db' AS two;
  39. CREATE TABLE two.t1(x);
  40. ATTACH 'test3.db' AS three;
  41. CREATE TABLE three.t1(x);
  42. ATTACH 'test4.db' AS four;
  43. CREATE TABLE four.t1(x);
  44. }
  45. do_malloc_test attachmalloc-2 -tclprep {
  46. forcedelete test2.db
  47. forcedelete test2.db-journal
  48. sqlite3 db2 test2.db
  49. db2 eval {
  50. CREATE TABLE t1(a, b, c);
  51. CREATE INDEX i1 ON t1(a, b);
  52. }
  53. db2 close
  54. } -sqlbody {
  55. CREATE TABLE t1(d, e, f);
  56. ATTACH 'test2.db' AS db1;
  57. }
  58. set enable_shared_cache [sqlite3_enable_shared_cache 1]
  59. sqlite3 dbaux test3.db
  60. dbaux eval {SELECT * FROM sqlite_master}
  61. do_malloc_test attachmalloc-3 -sqlbody {
  62. SELECT * FROM sqlite_master;
  63. ATTACH 'test3.db' AS three;
  64. } -cleanup {
  65. db eval { DETACH three }
  66. }
  67. dbaux close
  68. sqlite3_enable_shared_cache $enable_shared_cache
  69. finish_test