bindxfer.test 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # 2005 April 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. The
  12. # focus of this script testing the sqlite_transfer_bindings() API.
  13. #
  14. # $Id: bindxfer.test,v 1.9 2009/04/17 11:56:28 drh Exp $
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. proc sqlite_step {stmt VALS COLS} {
  19. upvar #0 $VALS vals
  20. upvar #0 $COLS cols
  21. set vals [list]
  22. set cols [list]
  23. set rc [sqlite3_step $stmt]
  24. for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {
  25. lappend cols [sqlite3_column_name $stmt $i]
  26. }
  27. for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
  28. lappend vals [sqlite3_column_text $stmt $i]
  29. }
  30. return $rc
  31. }
  32. do_test bindxfer-1.1 {
  33. set DB [sqlite3_connection_pointer db]
  34. execsql {CREATE TABLE t1(a,b,c);}
  35. set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
  36. set TAIL
  37. } {}
  38. do_test bindxfer-1.2 {
  39. sqlite3_bind_parameter_count $VM1
  40. } 3
  41. do_test bindxfer-1.3 {
  42. set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
  43. set TAIL
  44. } {}
  45. do_test bindxfer-1.4 {
  46. sqlite3_bind_parameter_count $VM2
  47. } 3
  48. ifcapable deprecated {
  49. do_test bindxfer-1.5 {
  50. sqlite_bind $VM1 1 one normal
  51. set sqlite_static_bind_value two
  52. sqlite_bind $VM1 2 {} static
  53. sqlite_bind $VM1 3 {} null
  54. sqlite3_transfer_bindings $VM1 $VM2
  55. sqlite_step $VM1 VALUES COLNAMES
  56. } SQLITE_ROW
  57. do_test bindxfer-1.6 {
  58. set VALUES
  59. } {{} {} {}}
  60. do_test bindxfer-1.7 {
  61. sqlite_step $VM2 VALUES COLNAMES
  62. } SQLITE_ROW
  63. do_test bindxfer-1.8 {
  64. set VALUES
  65. } {one two {}}
  66. }
  67. catch {sqlite3_finalize $VM1}
  68. catch {sqlite3_finalize $VM2}
  69. finish_test