github.com/jdgcs/sqlite3@v1.12.1-0.20210908114423-bc5f96e4dd51/testdata/tcl/carray01.test (about)

     1  # 2020-11-17
     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  # This file implements tests for CARRAY extension
    13  #
    14  
    15  set testdir [file dirname $argv0]
    16  source $testdir/tester.tcl
    17  set testprefix carray01
    18  
    19  ifcapable !vtab {
    20    finish_test
    21    return
    22  }
    23  load_static_extension db carray
    24  
    25  # Parameter $stmt must be a prepared statement created using
    26  # the sqlite3_prepare_v2 command and with parameters fullly bound.
    27  # This routine simply runs the statement, gathers the result, and
    28  # returns a list containing the result.
    29  #
    30  # If the optional second argument is true, then the stmt is finalized
    31  # after it is run.
    32  #
    33  proc run_stmt {stmt {finalizeFlag 0}} {
    34    set r {}
    35    while {[sqlite3_step $stmt]=="SQLITE_ROW"} {
    36      for {set i 0} {$i<[sqlite3_data_count $stmt]} {incr i} {
    37        lappend r [sqlite3_column_text $stmt $i]
    38      }
    39    }
    40    if {$finalizeFlag} {
    41      sqlite3_finalize $stmt
    42    } else {
    43      sqlite3_reset $stmt
    44    }
    45    return $r
    46  }
    47  
    48  do_test 100 {
    49    set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1]
    50    sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7
    51    run_stmt $STMT 0
    52  } {1}
    53  do_test 101 {
    54    sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7
    55    run_stmt $STMT 0
    56  } {1}
    57  do_test 110 {
    58    sqlite3_carray_bind $STMT 3 1 2 3 4 6 7
    59    run_stmt $STMT 0
    60  } {0}
    61  do_test 120 {
    62    sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7
    63    run_stmt $STMT 0
    64  } {1}
    65  do_test 130 {
    66    sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7
    67    run_stmt $STMT 0
    68  } {0}
    69  do_test 131 {
    70    sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7
    71    run_stmt $STMT 0
    72  } {0}
    73  do_test 140 {
    74    sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7
    75    run_stmt $STMT 0
    76  } {1}
    77  do_test 150 {
    78    sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7
    79    run_stmt $STMT 0
    80  } {0}
    81  do_test 160 {
    82    sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7
    83    run_stmt $STMT 0
    84  } {1}
    85  do_test 170 {
    86    sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7
    87    run_stmt $STMT 0
    88  } {0}
    89  do_test 180 {
    90    sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7
    91    run_stmt $STMT 0
    92  } {0}
    93  do_test 190 {
    94    sqlite3_carray_bind $STMT 3
    95    run_stmt $STMT 0
    96  } {0}
    97  
    98  sqlite3_finalize $STMT
    99  
   100  finish_test