session6.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # 2011 July 11
  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 sessions extension.
  12. # Specifically, it tests that sessions work when the database is modified
  13. # using incremental blob handles.
  14. #
  15. if {![info exists testdir]} {
  16. set testdir [file join [file dirname [info script]] .. .. test]
  17. }
  18. source [file join [file dirname [info script]] session_common.tcl]
  19. source $testdir/tester.tcl
  20. ifcapable !session {finish_test; return}
  21. ifcapable !incrblob {finish_test; return}
  22. set testprefix session6
  23. proc do_then_apply_tcl {tcl {dbname main}} {
  24. proc xConflict args { return "OMIT" }
  25. set rc [catch {
  26. sqlite3session S db $dbname
  27. db eval "SELECT name FROM $dbname.sqlite_master WHERE type = 'table'" {
  28. S attach $name
  29. }
  30. eval $tcl
  31. sqlite3changeset_apply db2 [S changeset] xConflict
  32. } msg]
  33. catch { S delete }
  34. if {$rc} {error $msg}
  35. }
  36. test_sqlite3_log x
  37. proc x {args} {puts $args}
  38. forcedelete test.db2
  39. sqlite3 db2 test.db2
  40. do_common_sql {
  41. CREATE TABLE t1(a PRIMARY KEY, b);
  42. CREATE TABLE t2(c PRIMARY KEY, d);
  43. }
  44. # Test a blob update.
  45. #
  46. do_test 1.1 {
  47. do_then_apply_tcl {
  48. db eval { INSERT INTO t1 VALUES(1, 'helloworld') }
  49. db eval { INSERT INTO t2 VALUES(2, 'onetwothree') }
  50. }
  51. compare_db db db2
  52. } {}
  53. do_test 1.2 {
  54. do_then_apply_tcl {
  55. set fd [db incrblob t1 b 1]
  56. puts -nonewline $fd 1234567890
  57. close $fd
  58. }
  59. compare_db db db2
  60. } {}
  61. # Test an attached database.
  62. #
  63. do_test 2.1 {
  64. forcedelete test.db3
  65. file copy test.db2 test.db3
  66. execsql { ATTACH 'test.db3' AS aux; }
  67. do_then_apply_tcl {
  68. set fd [db incrblob aux t2 d 1]
  69. puts -nonewline $fd fourfivesix
  70. close $fd
  71. } aux
  72. sqlite3 db3 test.db3
  73. compare_db db2 db3
  74. } {}
  75. db3 close
  76. db2 close
  77. finish_test