⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bind.test

📁 最新的sqlite3.6.2源代码
💻 TEST
📖 第 1 页 / 共 2 页
字号:
# 2003 September 6## 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.##***********************************************************************# This file implements regression tests for SQLite library.  The# focus of this script testing the sqlite_bind API.## $Id: bind.test,v 1.44 2008/07/09 01:39:44 drh Exp $#set testdir [file dirname $argv0]source $testdir/tester.tclproc sqlite_step {stmt N VALS COLS} {  upvar VALS vals  upvar COLS cols  set vals [list]  set cols [list]  set rc [sqlite3_step $stmt]  for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {    lappend cols [sqlite3_column_name $stmt $i]  }  for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {    lappend vals [sqlite3_column_text $stmt $i]  }  return $rc}do_test bind-1.1 {  set DB [sqlite3_connection_pointer db]  execsql {CREATE TABLE t1(a,b,c);}  set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL]  set TAIL} {}do_test bind-1.1.1 {  sqlite3_bind_parameter_count $VM} 3do_test bind-1.1.2 {  sqlite3_bind_parameter_name $VM 1} {:1}do_test bind-1.1.3 {  sqlite3_bind_parameter_name $VM 2} {}do_test bind-1.1.4 {  sqlite3_bind_parameter_name $VM 3} {:abc}do_test bind-1.2 {  sqlite_step $VM N VALUES COLNAMES} {SQLITE_DONE}do_test bind-1.3 {  execsql {SELECT rowid, * FROM t1}} {1 {} {} {}}do_test bind-1.4 {  sqlite3_reset $VM  sqlite_bind $VM 1 {test value 1} normal  sqlite_step $VM N VALUES COLNAMES} SQLITE_DONEdo_test bind-1.5 {  execsql {SELECT rowid, * FROM t1}} {1 {} {} {} 2 {test value 1} {} {}}do_test bind-1.6 {  sqlite3_reset $VM  sqlite_bind $VM 3 {'test value 2'} normal  sqlite_step $VM N VALUES COLNAMES} SQLITE_DONEdo_test bind-1.7 {  execsql {SELECT rowid, * FROM t1}} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}do_test bind-1.8 {  sqlite3_reset $VM  set sqlite_static_bind_value 123  sqlite_bind $VM 1 {} static  sqlite_bind $VM 2 {abcdefg} normal  sqlite_bind $VM 3 {} null  execsql {DELETE FROM t1}  sqlite_step $VM N VALUES COLNAMES  execsql {SELECT rowid, * FROM t1}} {1 123 abcdefg {}}do_test bind-1.9 {  sqlite3_reset $VM  sqlite_bind $VM 1 {456} normal  sqlite_step $VM N VALUES COLNAMES  execsql {SELECT rowid, * FROM t1}} {1 123 abcdefg {} 2 456 abcdefg {}}do_test bind-1.10 {   set rc [catch {     sqlite3_prepare db {INSERT INTO t1 VALUES($abc:123,?,:abc)} -1 TAIL   } msg]   lappend rc $msg} {1 {(1) near ":123": syntax error}}do_test bind-1.11 {   set rc [catch {     sqlite3_prepare db {INSERT INTO t1 VALUES(@abc:xyz,?,:abc)} -1 TAIL   } msg]   lappend rc $msg} {1 {(1) near ":xyz": syntax error}}do_test bind-1.99 {  sqlite3_finalize $VM} SQLITE_OK# Prepare the statement in different ways depending on whether or not# the $var processing is compiled into the library.#ifcapable {tclvar} {  do_test bind-2.1 {    execsql {      DELETE FROM t1;    }    set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,$x(-z-))}\            -1 TX]    set TX  } {}  set v1 {$one}  set v2 {$::two}  set v3 {$x(-z-)}}ifcapable {!tclvar} {  do_test bind-2.1 {    execsql {      DELETE FROM t1;    }    set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:one,:two,:_)} -1 TX]    set TX  } {}  set v1 {:one}  set v2 {:two}  set v3 {:_}}do_test bind-2.1.1 {  sqlite3_bind_parameter_count $VM} 3do_test bind-2.1.2 {  sqlite3_bind_parameter_name $VM 1} $v1do_test bind-2.1.3 {  sqlite3_bind_parameter_name $VM 2} $v2do_test bind-2.1.4 {  sqlite3_bind_parameter_name $VM 3} $v3do_test bind-2.1.5 {  sqlite3_bind_parameter_index $VM $v1} 1do_test bind-2.1.6 {  sqlite3_bind_parameter_index $VM $v2} 2do_test bind-2.1.7 {  sqlite3_bind_parameter_index $VM $v3} 3do_test bind-2.1.8 {  sqlite3_bind_parameter_index $VM {:hi}} 0# 32 bit Integersdo_test bind-2.2 {  sqlite3_bind_int $VM 1 123  sqlite3_bind_int $VM 2 456  sqlite3_bind_int $VM 3 789  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  execsql {SELECT rowid, * FROM t1}} {1 123 456 789}do_test bind-2.3 {  sqlite3_bind_int $VM 2 -2000000000  sqlite3_bind_int $VM 3 2000000000  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  execsql {SELECT rowid, * FROM t1}} {1 123 456 789 2 123 -2000000000 2000000000}do_test bind-2.4 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {integer integer integer integer integer integer}do_test bind-2.5 {  execsql {    DELETE FROM t1;  }} {}# 64 bit Integersdo_test bind-3.1 {  sqlite3_bind_int64 $VM 1 32  sqlite3_bind_int64 $VM 2 -2000000000000  sqlite3_bind_int64 $VM 3 2000000000000  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  execsql {SELECT rowid, * FROM t1}} {1 32 -2000000000000 2000000000000}do_test bind-3.2 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {integer integer integer}do_test bind-3.3 {  execsql {    DELETE FROM t1;  }} {}# Doublesdo_test bind-4.1 {  sqlite3_bind_double $VM 1 1234.1234  sqlite3_bind_double $VM 2 0.00001  sqlite3_bind_double $VM 3 123456789  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  set x [execsql {SELECT rowid, * FROM t1}]  regsub {1e-005} $x {1e-05} y  set y} {1 1234.1234 1e-05 123456789.0}do_test bind-4.2 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {real real real}do_test bind-4.3 {  execsql {    DELETE FROM t1;  }} {}do_test bind-4.4 {  sqlite3_bind_double $VM 1 NaN  sqlite3_bind_double $VM 2 1e300  sqlite3_bind_double $VM 3 -1e-300  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  set x [execsql {SELECT rowid, * FROM t1}]  regsub {1e-005} $x {1e-05} y  set y} {1 {} 1e+300 -1e-300}do_test bind-4.5 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {null real real}do_test bind-4.6 {  execsql {    DELETE FROM t1;  }} {}# NULLdo_test bind-5.1 {  sqlite3_bind_null $VM 1  sqlite3_bind_null $VM 2  sqlite3_bind_null $VM 3   sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  execsql {SELECT rowid, * FROM t1}} {1 {} {} {}}do_test bind-5.2 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {null null null}do_test bind-5.3 {  execsql {    DELETE FROM t1;  }} {}# UTF-8 textdo_test bind-6.1 {  sqlite3_bind_text $VM 1 hellothere 5  sqlite3_bind_text $VM 2 ".." 1  sqlite3_bind_text $VM 3 world\000 -1  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  execsql {SELECT rowid, * FROM t1}} {1 hello . world}do_test bind-6.2 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {text text text}do_test bind-6.3 {  execsql {    DELETE FROM t1;  }} {}# Make sure zeros in a string work.#do_test bind-6.4 {  db eval {DELETE FROM t1}  sqlite3_bind_text $VM 1 hello\000there\000 12  sqlite3_bind_text $VM 2 hello\000there\000 11  sqlite3_bind_text $VM 3 hello\000there\000 -1  sqlite_step $VM N VALUES COLNAMES  sqlite3_reset $VM  execsql {SELECT * FROM t1}} {hello hello hello}set enc [db eval {PRAGMA encoding}]if {$enc=="UTF-8"} {  do_test bind-6.5 {    execsql {SELECT  hex(a), hex(b), hex(c) FROM t1}  } {68656C6C6F00746865726500 68656C6C6F007468657265 68656C6C6F}} elseif {$enc=="UTF-16le"} {  do_test bind-6.5 {    execsql {SELECT  hex(a), hex(b), hex(c) FROM t1}  } {680065006C006C006F000000740068006500720065000000 680065006C006C006F00000074006800650072006500 680065006C006C006F00}} elseif {$enc=="UTF-16be"} {  do_test bind-6.5 {    execsql {SELECT  hex(a), hex(b), hex(c) FROM t1}  } {00680065006C006C006F0000007400680065007200650000 00680065006C006C006F000000740068006500720065 00680065006C006C006F}} else {  do_test bind-6.5 {    set "Unknown database encoding: $::enc"  } {}}do_test bind-6.6 {  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}} {text text text}do_test bind-6.7 {  execsql {    DELETE FROM t1;  }} {}# UTF-16 textifcapable {utf16} {  do_test bind-7.1 {    sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10    sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0    sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10    sqlite_step $VM N VALUES COLNAMES    sqlite3_reset $VM    execsql {SELECT rowid, * FROM t1}  } {1 hello {} world}  do_test bind-7.2 {    execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -