000001  # 2014 October 30
000002  #
000003  # The author disclaims copyright to this source code.  In place of
000004  # a legal notice, here is a blessing:
000005  #
000006  #    May you do good and not evil.
000007  #    May you find forgiveness for yourself and forgive others.
000008  #    May you share freely, never taking more than you give.
000009  #
000010  #***********************************************************************
000011  #
000012  
000013  set testdir [file dirname $argv0]
000014  source $testdir/tester.tcl
000015  set testprefix e_blobbytes
000016  
000017  do_execsql_test 1.0 {
000018    CREATE TABLE q1(r INTEGER PRIMARY KEY, s TEXT);
000019    WITH d(a, b) AS (
000020      SELECT 0, '' 
000021        UNION ALL
000022      SELECT a+1, b||'.' FROM d WHERE a<10000
000023    )
000024    INSERT INTO q1 SELECT * FROM d;
000025  }
000026  
000027  
000028  # EVIDENCE-OF: R-07796-55423 Returns the size in bytes of the BLOB
000029  # accessible via the successfully opened BLOB handle in its only
000030  # argument.
000031  #
000032  proc check_blob_size {tn rowid bytes} {
000033    uplevel [list do_test $tn [subst -nocommands {
000034      sqlite3_blob_open db main q1 s $rowid 0 B
000035      set res [sqlite3_blob_bytes [set B]]
000036      sqlite3_blob_close [set B]
000037      set res
000038    }] $bytes]
000039  }
000040  check_blob_size 1.1 43 43
000041  check_blob_size 1.2 391 391
000042  check_blob_size 1.3 6349 6349
000043  check_blob_size 1.4 2621 2621
000044  check_blob_size 1.5 7771 7771
000045  check_blob_size 1.6 7949 7949
000046  check_blob_size 1.7 4374 4374
000047  check_blob_size 1.8 2578 2578
000048  check_blob_size 1.9 7004 7004
000049  check_blob_size 1.10 2180 2180
000050  check_blob_size 1.11 3796 3796
000051  check_blob_size 1.12 7101 7101
000052  check_blob_size 1.13 7449 7449
000053  check_blob_size 1.14 7224 7224
000054  check_blob_size 1.15 3038 3038
000055  check_blob_size 1.16 1083 1083
000056  check_blob_size 1.17 5157 5157
000057  check_blob_size 1.18 6686 6686
000058  check_blob_size 1.19 6592 6592
000059  check_blob_size 1.20 0 0
000060  
000061  
000062  # EVIDENCE-OF: R-53088-19343 The incremental blob I/O routines can only
000063  # read or overwriting existing blob content; they cannot change the size
000064  # of a blob.
000065  #
000066  #   Also demonstrated in other e_blobXXX.test files.
000067  #
000068  do_test 2.1 {
000069    sqlite3_blob_open db main q1 s 86 1 B
000070    list [catch { sqlite3_blob_write $B 86 "1" 1 } msg] $msg
000071  } {1 SQLITE_ERROR}
000072  sqlite3_blob_close $B
000073  
000074  finish_test