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

     1  # 2014 October 30
     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  
    13  set testdir [file dirname $argv0]
    14  source $testdir/tester.tcl
    15  set testprefix e_blobbytes
    16  
    17  do_execsql_test 1.0 {
    18    CREATE TABLE q1(r INTEGER PRIMARY KEY, s TEXT);
    19    WITH d(a, b) AS (
    20      SELECT 0, '' 
    21        UNION ALL
    22      SELECT a+1, b||'.' FROM d WHERE a<10000
    23    )
    24    INSERT INTO q1 SELECT * FROM d;
    25  }
    26  
    27  
    28  # EVIDENCE-OF: R-07796-55423 Returns the size in bytes of the BLOB
    29  # accessible via the successfully opened BLOB handle in its only
    30  # argument.
    31  #
    32  proc check_blob_size {tn rowid bytes} {
    33    uplevel [list do_test $tn [subst -nocommands {
    34      sqlite3_blob_open db main q1 s $rowid 0 B
    35      set res [sqlite3_blob_bytes [set B]]
    36      sqlite3_blob_close [set B]
    37      set res
    38    }] $bytes]
    39  }
    40  check_blob_size 1.1 43 43
    41  check_blob_size 1.2 391 391
    42  check_blob_size 1.3 6349 6349
    43  check_blob_size 1.4 2621 2621
    44  check_blob_size 1.5 7771 7771
    45  check_blob_size 1.6 7949 7949
    46  check_blob_size 1.7 4374 4374
    47  check_blob_size 1.8 2578 2578
    48  check_blob_size 1.9 7004 7004
    49  check_blob_size 1.10 2180 2180
    50  check_blob_size 1.11 3796 3796
    51  check_blob_size 1.12 7101 7101
    52  check_blob_size 1.13 7449 7449
    53  check_blob_size 1.14 7224 7224
    54  check_blob_size 1.15 3038 3038
    55  check_blob_size 1.16 1083 1083
    56  check_blob_size 1.17 5157 5157
    57  check_blob_size 1.18 6686 6686
    58  check_blob_size 1.19 6592 6592
    59  check_blob_size 1.20 0 0
    60  
    61  
    62  # EVIDENCE-OF: R-53088-19343 The incremental blob I/O routines can only
    63  # read or overwriting existing blob content; they cannot change the size
    64  # of a blob.
    65  #
    66  #   Also demonstrated in other e_blobXXX.test files.
    67  #
    68  do_test 2.1 {
    69    sqlite3_blob_open db main q1 s 86 1 B
    70    list [catch { sqlite3_blob_write $B 86 "1" 1 } msg] $msg
    71  } {1 SQLITE_ERROR}
    72  sqlite3_blob_close $B
    73  
    74  finish_test