mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Add some more elements of the new API. (CVS 1416)
FossilOrigin-Name: 2821767b947ae1a70e98dd7f47d69e424c37947f
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the sqlite_bind API.
|
||||
#
|
||||
# $Id: bind.test,v 1.2 2004/05/20 01:12:35 danielk1977 Exp $
|
||||
# $Id: bind.test,v 1.3 2004/05/20 11:00:53 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -190,7 +190,32 @@ do_test bind-7.3 {
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test bind-8.99 {
|
||||
# Test that the 'out of range' error works.
|
||||
do_test bind-8.1 {
|
||||
catch { sqlite3_bind_null $VM 0 }
|
||||
} {1}
|
||||
do_test bind-8.2 {
|
||||
sqlite3_errmsg $DB
|
||||
} {bind index out of range}
|
||||
do_test bind-8.3 {
|
||||
encoding convertfrom unicode [sqlite3_errmsg16 $DB]
|
||||
} {bind index out of range}
|
||||
do_test bind-8.4 {
|
||||
sqlite3_bind_null $VM 1
|
||||
sqlite3_errmsg $DB
|
||||
} {not an error}
|
||||
do_test bind-8.5 {
|
||||
catch { sqlite3_bind_null $VM 4 }
|
||||
} {1}
|
||||
do_test bind-8.6 {
|
||||
sqlite3_errmsg $DB
|
||||
} {bind index out of range}
|
||||
do_test bind-8.7 {
|
||||
encoding convertfrom unicode [sqlite3_errmsg16 $DB]
|
||||
} {bind index out of range}
|
||||
|
||||
|
||||
do_test bind-9.99 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
|
||||
|
110
test/capi3.test
Normal file
110
test/capi3.test
Normal file
@ -0,0 +1,110 @@
|
||||
# 2003 January 29
|
||||
#
|
||||
# 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 callback-free C/C++ API.
|
||||
#
|
||||
# $Id: capi3.test,v 1.1 2004/05/20 11:00:53 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Return the UTF-16 representation of the supplied UTF-8 string $str.
|
||||
# If $nt is true, append two 0x00 bytes as a nul terminator.
|
||||
proc utf16 {str {nt 1}} {
|
||||
set r [encoding convertto unicode $str]
|
||||
if {$nt} {
|
||||
append r "\x00\x00"
|
||||
}
|
||||
return $r
|
||||
}
|
||||
|
||||
# Return the UTF-8 representation of the supplied UTF-16 string $str.
|
||||
proc utf8 {str} {
|
||||
# If $str ends in two 0x00 0x00 bytes, knock these off before
|
||||
# converting to UTF-8 using TCL.
|
||||
binary scan $str \c* vals
|
||||
if {[lindex $vals end]==0 && [lindex $vals end-1]==0} {
|
||||
set str [binary format \c* [lrange $vals 0 end-2]]
|
||||
}
|
||||
|
||||
set r [encoding convertfrom unicode $str]
|
||||
return $r
|
||||
}
|
||||
|
||||
# These tests complement those in capi2.test. They are organized
|
||||
# as follows:
|
||||
#
|
||||
# capi3-1.*: Test sqlite3_prepare
|
||||
# capi3-2.*: Test sqlite3_prepare16
|
||||
#
|
||||
|
||||
db close
|
||||
set DB [sqlite db test.db]
|
||||
|
||||
do_test capi3-1.1 {
|
||||
set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
|
||||
sqlite_finalize $STMT
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi3-1.2 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-1.3 {
|
||||
sqlite3_errmsg $DB
|
||||
} {not an error}
|
||||
do_test capi3-1.4 {
|
||||
set sql {SELECT name FROM sqlite_master;SELECT 10}
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
sqlite_finalize $STMT
|
||||
set TAIL
|
||||
} {SELECT 10}
|
||||
do_test capi3-1.5 {
|
||||
set sql {SELECT namex FROM sqlite_master}
|
||||
catch {
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-1.6 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-1.7 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
|
||||
do_test capi3-2.1 {
|
||||
set sql16 [utf16 {SELECT name FROM sqlite_master}]
|
||||
set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL]
|
||||
sqlite_finalize $STMT
|
||||
utf8 $::TAIL
|
||||
} {}
|
||||
do_test capi3-2.2 {
|
||||
set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}]
|
||||
set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
|
||||
sqlite_finalize $STMT
|
||||
utf8 $TAIL
|
||||
} {SELECT 10}
|
||||
do_test capi3-2.3 {
|
||||
set sql [utf16 {SELECT namex FROM sqlite_master}]
|
||||
catch {
|
||||
set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-2.4 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-2.5 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
|
||||
finish_test
|
||||
|
||||
|
Reference in New Issue
Block a user