fts5lastrowid.test 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # 2017 Feb 27
  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. # Tests of the last_insert_rowid functionality with fts5.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5lastrowid
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. do_execsql_test 1.0 {
  22. CREATE VIRTUAL TABLE t1 USING fts5(str);
  23. }
  24. do_execsql_test 1.1 {
  25. INSERT INTO t1 VALUES('one string');
  26. INSERT INTO t1 VALUES('two string');
  27. INSERT INTO t1 VALUES('three string');
  28. SELECT last_insert_rowid();
  29. } {3}
  30. do_execsql_test 1.2 {
  31. BEGIN;
  32. INSERT INTO t1 VALUES('one string');
  33. INSERT INTO t1 VALUES('two string');
  34. INSERT INTO t1 VALUES('three string');
  35. COMMIT;
  36. SELECT last_insert_rowid();
  37. } {6}
  38. do_execsql_test 1.3 {
  39. INSERT INTO t1(rowid, str) VALUES(-22, 'some more text');
  40. SELECT last_insert_rowid();
  41. } {-22}
  42. do_execsql_test 1.4 {
  43. BEGIN;
  44. INSERT INTO t1(rowid, str) VALUES(45, 'some more text');
  45. INSERT INTO t1(rowid, str) VALUES(46, 'some more text');
  46. INSERT INTO t1(rowid, str) VALUES(222, 'some more text');
  47. SELECT last_insert_rowid();
  48. COMMIT;
  49. SELECT last_insert_rowid();
  50. } {222 222}
  51. do_execsql_test 1.5 {
  52. CREATE TABLE x1(x);
  53. INSERT INTO x1 VALUES('john'), ('paul'), ('george'), ('ringo');
  54. INSERT INTO t1 SELECT x FROM x1;
  55. SELECT last_insert_rowid();
  56. } {226}
  57. do_execsql_test 1.6 {
  58. INSERT INTO t1(rowid, str) SELECT rowid+10, x FROM x1;
  59. SELECT last_insert_rowid();
  60. } {14}
  61. finish_test