File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sqlite3 / test / tkt2332.test
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:04:16 2012 UTC (12 years, 3 months ago) by misho
Branches: sqlite3, MAIN
CVS tags: v3_7_10, HEAD
sqlite3

# 2007 May 3
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# $Id: tkt2332.test,v 1.1.1.1 2012/02/21 17:04:16 misho Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !incrblob||!tclvar {
  finish_test
  return
}

do_test tkt2332.1 {
  execsql {
    CREATE TABLE blobs (k INTEGER PRIMARY KEY, v BLOB);
    PRAGMA cache_size = 100;
  }
} {}

set ::iKey 1
foreach Len [list 10000 100000 1000000] {
  do_test tkt2332.$Len.1 {
    set val "[expr rand()][expr rand()][expr rand()][expr rand()][expr rand()]"
    set ::blobstr [string range \
      [string repeat $val [expr ($Len/[string length $val])+1]] 0 [expr $Len-1]
    ]

    db eval { INSERT INTO blobs VALUES($::iKey, zeroblob($Len)) }
  } {}

  do_test tkt2332.$Len.2 {
    execsql {
      SELECT length(v) FROM blobs WHERE k = $::iKey;
    }
  } $Len

  do_test tkt2332.$Len.3 {
    set ::fd [db incrblob blobs v $::iKey]
    puts -nonewline $::fd $::blobstr
    close $::fd
  } {}

  do_test tkt2332.$Len.4 {
    execsql { SELECT length(v) FROM blobs WHERE k = $::iKey; }
  } $Len

  do_test tkt2332.$Len.5 {
    lindex [execsql {SELECT v FROM blobs WHERE k = $::iKey}] 0
  } $::blobstr

  incr ::iKey
}

# Free memory:
unset ::blobstr

finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>