os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/bindxfer.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2005 April 21
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.  The
sl@0
    12
# focus of this script testing the sqlite_transfer_bindings() API.
sl@0
    13
#
sl@0
    14
# $Id: bindxfer.test,v 1.5 2008/03/17 16:23:27 drh Exp $
sl@0
    15
#
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
proc sqlite_step {stmt VALS COLS} {
sl@0
    21
  upvar #0 $VALS vals
sl@0
    22
  upvar #0 $COLS cols
sl@0
    23
  set vals [list]
sl@0
    24
  set cols [list]
sl@0
    25
sl@0
    26
  set rc [sqlite3_step $stmt]
sl@0
    27
  for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {
sl@0
    28
    lappend cols [sqlite3_column_name $stmt $i]
sl@0
    29
  }
sl@0
    30
  for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
sl@0
    31
    lappend vals [sqlite3_column_text $stmt $i]
sl@0
    32
  }
sl@0
    33
sl@0
    34
  return $rc
sl@0
    35
}
sl@0
    36
sl@0
    37
do_test bindxfer-1.1 {
sl@0
    38
  set DB [sqlite3_connection_pointer db]
sl@0
    39
  execsql {CREATE TABLE t1(a,b,c);}
sl@0
    40
  set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
sl@0
    41
  set TAIL
sl@0
    42
} {}
sl@0
    43
do_test bindxfer-1.2 {
sl@0
    44
  sqlite3_bind_parameter_count $VM1
sl@0
    45
} 3
sl@0
    46
do_test bindxfer-1.3 {
sl@0
    47
  set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
sl@0
    48
  set TAIL
sl@0
    49
} {}
sl@0
    50
do_test bindxfer-1.4 {
sl@0
    51
  sqlite3_bind_parameter_count $VM2
sl@0
    52
} 3
sl@0
    53
do_test bindxfer-1.5 {
sl@0
    54
  sqlite_bind $VM1 1 one normal
sl@0
    55
  set sqlite_static_bind_value two
sl@0
    56
  sqlite_bind $VM1 2 {} static
sl@0
    57
  sqlite_bind $VM1 3 {} null
sl@0
    58
  sqlite3_transfer_bindings $VM1 $VM2
sl@0
    59
  sqlite_step $VM1 VALUES COLNAMES
sl@0
    60
} SQLITE_ROW
sl@0
    61
do_test bindxfer-1.6 {
sl@0
    62
  set VALUES
sl@0
    63
} {{} {} {}}
sl@0
    64
do_test bindxfer-1.7 {
sl@0
    65
  sqlite_step $VM2 VALUES COLNAMES
sl@0
    66
} SQLITE_ROW
sl@0
    67
do_test bindxfer-1.8 {
sl@0
    68
  set VALUES
sl@0
    69
} {one two {}}
sl@0
    70
do_test bindxfer-1.9-misuse {
sl@0
    71
  catch {sqlite3_finalize $VM1}
sl@0
    72
  catch {sqlite3_finalize $VM2}
sl@0
    73
  sqlite3_transfer_bindings $VM1 $VM2
sl@0
    74
} 21 ;# SQLITE_MISUSE
sl@0
    75
do_test bindxfer-1.10 {
sl@0
    76
  set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
sl@0
    77
  set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?, ?} -1 TAIL]
sl@0
    78
  sqlite3_transfer_bindings $VM1 $VM2
sl@0
    79
} 1  ;# SQLITE_ERROR
sl@0
    80
catch {sqlite3_finalize $VM1}
sl@0
    81
catch {sqlite3_finalize $VM2}
sl@0
    82
sl@0
    83
sl@0
    84
finish_test