xref: /illumos-gate/usr/src/lib/libsqlite/test/bind.test (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*1da57d55SToomas Soome#
2c5c4113dSnw141292# 2003 September 6
3c5c4113dSnw141292#
4c5c4113dSnw141292# The author disclaims copyright to this source code.  In place of
5c5c4113dSnw141292# a legal notice, here is a blessing:
6c5c4113dSnw141292#
7c5c4113dSnw141292#    May you do good and not evil.
8c5c4113dSnw141292#    May you find forgiveness for yourself and forgive others.
9c5c4113dSnw141292#    May you share freely, never taking more than you give.
10c5c4113dSnw141292#
11c5c4113dSnw141292#***********************************************************************
12c5c4113dSnw141292# This file implements regression tests for SQLite library.  The
13c5c4113dSnw141292# focus of this script testing the sqlite_bind API.
14c5c4113dSnw141292#
15c5c4113dSnw141292# $Id: bind.test,v 1.1 2003/09/06 22:45:21 drh Exp $
16c5c4113dSnw141292#
17c5c4113dSnw141292
18c5c4113dSnw141292set testdir [file dirname $argv0]
19c5c4113dSnw141292source $testdir/tester.tcl
20c5c4113dSnw141292
21c5c4113dSnw141292do_test bind-1.1 {
22c5c4113dSnw141292  db close
23c5c4113dSnw141292  set DB [sqlite db test.db]
24c5c4113dSnw141292  execsql {CREATE TABLE t1(a,b,c)}
25c5c4113dSnw141292  set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
26c5c4113dSnw141292  set TAIL
27c5c4113dSnw141292} {}
28c5c4113dSnw141292do_test bind-1.2 {
29c5c4113dSnw141292  sqlite_step $VM N VALUES COLNAMES
30c5c4113dSnw141292} {SQLITE_DONE}
31c5c4113dSnw141292do_test bind-1.3 {
32c5c4113dSnw141292  execsql {SELECT rowid, * FROM t1}
33c5c4113dSnw141292} {1 {} {} {}}
34c5c4113dSnw141292do_test bind-1.4 {
35c5c4113dSnw141292  sqlite_reset $VM
36c5c4113dSnw141292  sqlite_bind $VM 1 {test value 1} normal
37c5c4113dSnw141292  sqlite_step $VM N VALUES COLNAMES
38c5c4113dSnw141292} SQLITE_DONE
39c5c4113dSnw141292do_test bind-1.5 {
40c5c4113dSnw141292  execsql {SELECT rowid, * FROM t1}
41c5c4113dSnw141292} {1 {} {} {} 2 {test value 1} {} {}}
42c5c4113dSnw141292do_test bind-1.6 {
43c5c4113dSnw141292  sqlite_reset $VM
44c5c4113dSnw141292  sqlite_bind $VM 3 {'test value 2'} normal
45c5c4113dSnw141292  sqlite_step $VM N VALUES COLNAMES
46c5c4113dSnw141292} SQLITE_DONE
47c5c4113dSnw141292do_test bind-1.7 {
48c5c4113dSnw141292  execsql {SELECT rowid, * FROM t1}
49c5c4113dSnw141292} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
50c5c4113dSnw141292do_test bind-1.8 {
51c5c4113dSnw141292  sqlite_reset $VM
52c5c4113dSnw141292  set sqlite_static_bind_value 123
53c5c4113dSnw141292  sqlite_bind $VM 1 {} static
54c5c4113dSnw141292  sqlite_bind $VM 2 {abcdefg} normal
55c5c4113dSnw141292  sqlite_bind $VM 3 {} null
56c5c4113dSnw141292  execsql {DELETE FROM t1}
57c5c4113dSnw141292  sqlite_step $VM N VALUES COLNAMES
58c5c4113dSnw141292  execsql {SELECT rowid, * FROM t1}
59c5c4113dSnw141292} {1 123 abcdefg {}}
60c5c4113dSnw141292do_test bind-1.9 {
61c5c4113dSnw141292  sqlite_reset $VM
62c5c4113dSnw141292  sqlite_bind $VM 1 {456} normal
63c5c4113dSnw141292  sqlite_step $VM N VALUES COLNAMES
64c5c4113dSnw141292  execsql {SELECT rowid, * FROM t1}
65c5c4113dSnw141292} {1 123 abcdefg {} 2 456 abcdefg {}}
66c5c4113dSnw141292
67c5c4113dSnw141292
68c5c4113dSnw141292do_test bind-1.99 {
69c5c4113dSnw141292  sqlite_finalize $VM
70c5c4113dSnw141292} {}
71c5c4113dSnw141292
72c5c4113dSnw141292
73c5c4113dSnw141292finish_test
74