incrblob4.test 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # 2012 March 23
  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. #
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. ifcapable {!incrblob} { finish_test ; return }
  16. set testprefix incrblob4
  17. proc create_t1 {} {
  18. execsql {
  19. PRAGMA page_size = 1024;
  20. CREATE TABLE t1(k INTEGER PRIMARY KEY, v);
  21. }
  22. }
  23. proc populate_t1 {} {
  24. set data [list a b c d e f g h i j k l m n o p q r s t u v w x y z]
  25. foreach d $data {
  26. set blob [string repeat $d 900]
  27. execsql { INSERT INTO t1(v) VALUES($blob) }
  28. }
  29. }
  30. do_test 1.1 {
  31. create_t1
  32. populate_t1
  33. } {}
  34. do_test 1.2 {
  35. set blob [db incrblob t1 v 5]
  36. read $blob 10
  37. } {eeeeeeeeee}
  38. do_test 1.3 {
  39. execsql { DELETE FROM t1 }
  40. populate_t1
  41. } {}
  42. do_test 2.1 {
  43. reset_db
  44. create_t1
  45. populate_t1
  46. } {}
  47. do_test 2.2 {
  48. set blob [db incrblob t1 v 10]
  49. read $blob 10
  50. } {jjjjjjjjjj}
  51. do_test 2.3 {
  52. set new [string repeat % 900]
  53. execsql { DELETE FROM t1 WHERE k=10 }
  54. execsql { DELETE FROM t1 WHERE k=9 }
  55. execsql { INSERT INTO t1(v) VALUES($new) }
  56. } {}
  57. do_test 3.1 {
  58. reset_db
  59. create_t1
  60. populate_t1
  61. } {}
  62. do_test 3.2 {
  63. set blob [db incrblob t1 v 20]
  64. read $blob 10
  65. } {tttttttttt}
  66. do_test 3.3 {
  67. set new [string repeat % 900]
  68. execsql { UPDATE t1 SET v = $new WHERE k = 20 }
  69. execsql { DELETE FROM t1 WHERE k=19 }
  70. execsql { INSERT INTO t1(v) VALUES($new) }
  71. } {}
  72. finish_test