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  ifcapable !incrblob {
000018    finish_test
000019    return
000020  }
000021  
000022  do_execsql_test 1.0 {
000023    CREATE TABLE q1(r INTEGER PRIMARY KEY, s TEXT);
000024    WITH d(a, b) AS (
000025      SELECT 0, '' 
000026        UNION ALL
000027      SELECT a+1, b||'.' FROM d WHERE a<10000
000028    )
000029    INSERT INTO q1 SELECT * FROM d;
000030  }
000031  
000032  
000033  # EVIDENCE-OF: R-07796-55423 Returns the size in bytes of the BLOB
000034  # accessible via the successfully opened BLOB handle in its only
000035  # argument.
000036  #
000037  proc check_blob_size {tn rowid bytes} {
000038    uplevel [list do_test $tn [subst -nocommands {
000039      sqlite3_blob_open db main q1 s $rowid 0 B
000040      set res [sqlite3_blob_bytes [set B]]
000041      sqlite3_blob_close [set B]
000042      set res
000043    }] $bytes]
000044  }
000045  check_blob_size 1.1 43 43
000046  check_blob_size 1.2 391 391
000047  check_blob_size 1.3 6349 6349
000048  check_blob_size 1.4 2621 2621
000049  check_blob_size 1.5 7771 7771
000050  check_blob_size 1.6 7949 7949
000051  check_blob_size 1.7 4374 4374
000052  check_blob_size 1.8 2578 2578
000053  check_blob_size 1.9 7004 7004
000054  check_blob_size 1.10 2180 2180
000055  check_blob_size 1.11 3796 3796
000056  check_blob_size 1.12 7101 7101
000057  check_blob_size 1.13 7449 7449
000058  check_blob_size 1.14 7224 7224
000059  check_blob_size 1.15 3038 3038
000060  check_blob_size 1.16 1083 1083
000061  check_blob_size 1.17 5157 5157
000062  check_blob_size 1.18 6686 6686
000063  check_blob_size 1.19 6592 6592
000064  check_blob_size 1.20 0 0
000065  
000066  
000067  # EVIDENCE-OF: R-53088-19343 The incremental blob I/O routines can only
000068  # read or overwriting existing blob content; they cannot change the size
000069  # of a blob.
000070  #
000071  #   Also demonstrated in other e_blobXXX.test files.
000072  #
000073  do_test 2.1 {
000074    sqlite3_blob_open db main q1 s 86 1 B
000075    list [catch { sqlite3_blob_write $B 86 "1" 1 } msg] $msg
000076  } {1 SQLITE_ERROR}
000077  sqlite3_blob_close $B
000078  
000079  finish_test