~ubuntu-branches/ubuntu/wily/sqlite3/wily

« back to all changes in this revision

Viewing changes to test/hook.test

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2011-09-27 00:09:20 UTC
  • mfrom: (0.23.1) (1.6.1) (16.3.5 oneiric)
  • Revision ID: package-import@ubuntu.com-20110927000920-8d87xm2c8837llx3
Tags: 3.7.7-2ubuntu2
Make sure to build lemon when cross-compiling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
274
274
    set ::update_hook
275
275
  } [list]
276
276
}
 
277
 
 
278
do_test hook-4.4 {
 
279
  execsql {
 
280
    CREATE TABLE t4(a UNIQUE, b);
 
281
    INSERT INTO t4 VALUES(1, 'a');
 
282
    INSERT INTO t4 VALUES(2, 'b');
 
283
  }
 
284
  set ::update_hook [list]
 
285
  execsql {
 
286
    REPLACE INTO t4 VALUES(1, 'c');
 
287
  }
 
288
  set ::update_hook
 
289
} [list INSERT main t4 3 ]
 
290
do_execsql_test hook-4.4.1 {
 
291
  SELECT * FROM t4 ORDER BY a;
 
292
} {1 c 2 b}
 
293
do_test hook-4.4.2 {
 
294
  set ::update_hook [list]
 
295
  execsql {
 
296
    PRAGMA recursive_triggers = on;
 
297
    REPLACE INTO t4 VALUES(1, 'd');
 
298
  }
 
299
  set ::update_hook
 
300
} [list INSERT main t4 4 ]
 
301
do_execsql_test hook-4.4.3 {
 
302
  SELECT * FROM t4 ORDER BY a;
 
303
} {1 d 2 b}
 
304
 
277
305
db update_hook {}
278
306
#
279
307
#----------------------------------------------------------------------------
334
362
# End rollback-hook testing.
335
363
#----------------------------------------------------------------------------
336
364
 
 
365
#----------------------------------------------------------------------------
 
366
# Test that if a commit-hook returns non-zero (causing a rollback), the
 
367
# rollback-hook is invoked.
 
368
#
 
369
proc commit_hook {} {
 
370
  lappend ::hooks COMMIT
 
371
  return 1
 
372
}
 
373
proc rollback_hook {} {
 
374
  lappend ::hooks ROLLBACK
 
375
}
 
376
do_test hook-6.1 {
 
377
  set ::hooks [list]
 
378
  db commit_hook commit_hook
 
379
  db rollback_hook rollback_hook
 
380
  catchsql {
 
381
    BEGIN;
 
382
      INSERT INTO t1 VALUES('two', 'II');
 
383
    COMMIT;
 
384
  }
 
385
  execsql { SELECT * FROM t1 }
 
386
} {one I}
 
387
do_test hook-6.2 {
 
388
  set ::hooks
 
389
} {COMMIT ROLLBACK}
 
390
unset ::hooks
 
391
 
337
392
finish_test