1
0

trace2.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # 2011 Jan 21
  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.
  12. #
  13. # This file implements tests for the "sqlite3_trace()" API. Specifically,
  14. # it tests the special handling of nested SQL statements (those executed
  15. # by virtual table or user function callbacks). These statements are treated
  16. # differently in two respects:
  17. #
  18. # 1. Each line of the statement is prefixed with "-- " to turn it into
  19. # an SQL comment.
  20. #
  21. # 2. Parameter expansion is not performed.
  22. #
  23. set testdir [file dirname $argv0]
  24. source $testdir/tester.tcl
  25. ifcapable !trace { finish_test ; return }
  26. set ::testprefix trace2
  27. proc sql {zSql} { db one $zSql }
  28. proc trace {zSql} { lappend ::trace $zSql }
  29. db func sql sql
  30. db trace trace
  31. proc do_trace_test {tn sql expected} {
  32. # Test that the list of string passed to the trace callback when $sql
  33. # is executed is equivalent to the list of strings in $expected.
  34. #
  35. set ::trace [list]
  36. execsql $sql
  37. uplevel do_test $tn [list {set ::trace}] [list [list {*}$expected]]
  38. }
  39. proc do_trace_select_test {tn sql expected} {
  40. uplevel [list do_trace_test ${tn}.a $sql $expected]
  41. # Now execute each SQL statement passed to the trace callback in the
  42. # block above. Check that this causes the same set of strings to be
  43. # passed to the trace callback again. i.e. that executing the output
  44. # of the trace callback is equivalent to the SQL script in $sql.
  45. #
  46. set sqllist $::trace
  47. set ::trace [list]
  48. foreach item $sqllist { execsql $item }
  49. uplevel do_test $tn.b [list {set ::trace}] [list $sqllist]
  50. }
  51. do_trace_select_test 1.1 {
  52. SELECT 1, 2, 3;
  53. } {
  54. "SELECT 1, 2, 3;"
  55. }
  56. do_trace_select_test 1.2 {
  57. SELECT sql('SELECT 1, 2, 3');
  58. } {
  59. "SELECT sql('SELECT 1, 2, 3');"
  60. "-- SELECT 1, 2, 3"
  61. }
  62. do_trace_select_test 1.3 {
  63. SELECT sql('SELECT 1,
  64. 2,
  65. 3'
  66. );
  67. } {
  68. "SELECT sql('SELECT 1,
  69. 2,
  70. 3'
  71. );"
  72. "-- SELECT 1,
  73. -- 2,
  74. -- 3"
  75. }
  76. do_trace_select_test 1.4 {
  77. SELECT sql('SELECT 1,
  78. 3'
  79. );
  80. } {
  81. "SELECT sql('SELECT 1,
  82. 3'
  83. );"
  84. "-- SELECT 1,
  85. --
  86. --
  87. -- 3"
  88. }
  89. do_trace_select_test 1.5 {
  90. SELECT $var, sql('SELECT 1,
  91. $var,
  92. 3'
  93. );
  94. } {
  95. "SELECT NULL, sql('SELECT 1,
  96. $var,
  97. 3'
  98. );"
  99. "-- SELECT 1,
  100. -- $var,
  101. -- 3"
  102. }
  103. ifcapable fts3 {
  104. do_execsql_test 2.1 {
  105. CREATE VIRTUAL TABLE x1 USING fts4;
  106. INSERT INTO x1 VALUES('Cloudy, with a high near 16');
  107. INSERT INTO x1 VALUES('Wind chill values as low as -13');
  108. }
  109. do_trace_test 2.2 {
  110. INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');
  111. } {
  112. "INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');"
  113. "-- DELETE FROM 'main'.'x1_segdir' WHERE level = ?"
  114. "-- INSERT INTO 'main'.'x1_content' VALUES(?,(?))"
  115. "-- REPLACE INTO 'main'.'x1_docsize' VALUES(?,?)"
  116. "-- SELECT value FROM 'main'.'x1_stat' WHERE id=?"
  117. "-- REPLACE INTO 'main'.'x1_stat' VALUES(?,?)"
  118. "-- SELECT (SELECT max(idx) FROM 'main'.'x1_segdir' WHERE level = ?) + 1"
  119. "-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
  120. "-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
  121. }
  122. do_trace_test 2.3 {
  123. INSERT INTO x1(x1) VALUES('optimize');
  124. } {
  125. "INSERT INTO x1(x1) VALUES('optimize');"
  126. "-- SELECT DISTINCT level / (1024 * ?) FROM 'main'.'x1_segdir'"
  127. "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?ORDER BY level DESC, idx ASC"
  128. "-- SELECT max(level) FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
  129. "-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
  130. "-- DELETE FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
  131. "-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
  132. }
  133. }
  134. finish_test