testing/sqlite3: Import function TCL tests

This commit is contained in:
Pekka Enberg 2025-07-07 15:05:37 +03:00
parent 53070d74a4
commit 989fdca6e3
9 changed files with 3739 additions and 0 deletions

1598
testing/sqlite3/func.test Normal file

File diff suppressed because it is too large Load diff

534
testing/sqlite3/func2.test Normal file
View file

@ -0,0 +1,534 @@
# 2009 November 11
#
# 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 file is testing built-in functions.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Test plan:
#
# func2-1.*: substr implementation (ascii)
# func2-2.*: substr implementation (utf8)
# func2-3.*: substr implementation (blob)
#
proc bin_to_hex {blob} {
set bytes {}
binary scan $blob \c* bytes
set bytes2 [list]
foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]}
join $bytes2 {}
}
#----------------------------------------------------------------------------
# Test cases func2-1.*: substr implementation (ascii)
#
do_test func2-1.1 {
execsql {SELECT 'Supercalifragilisticexpialidocious'}
} {Supercalifragilisticexpialidocious}
# substr(x,y), substr(x,y,z)
do_test func2-1.2.1 {
catchsql {SELECT SUBSTR()}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-1.2.2 {
catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious')}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-1.2.3 {
catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1,1,1)}
} {1 {wrong number of arguments to function SUBSTR()}}
# p1 is 1-indexed
do_test func2-1.3 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.4 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.5 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2)}
} {upercalifragilisticexpialidocious}
do_test func2-1.6 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30)}
} {cious}
do_test func2-1.7 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34)}
} {s}
do_test func2-1.8 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35)}
} {{}}
do_test func2-1.9 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36)}
} {{}}
# if p1<0, start from right
do_test func2-1.10 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.11 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1)}
} {s}
do_test func2-1.12 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2)}
} {us}
do_test func2-1.13 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30)}
} {rcalifragilisticexpialidocious}
do_test func2-1.14 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.15 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.16 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36)}
} {Supercalifragilisticexpialidocious}
# p1 is 1-indexed, p2 length to return
do_test func2-1.17.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 1)}
} {{}}
do_test func2-1.17.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 2)}
} {S}
do_test func2-1.18 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 1)}
} {S}
do_test func2-1.19.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)}
} {{}}
do_test func2-1.19.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 1)}
} {u}
do_test func2-1.19.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 2)}
} {up}
do_test func2-1.20 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, 1)}
} {c}
do_test func2-1.21 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, 1)}
} {s}
do_test func2-1.22 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, 1)}
} {{}}
do_test func2-1.23 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 1)}
} {{}}
# if p1<0, start from right, p2 length to return
do_test func2-1.24 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0, 1)}
} {{}}
do_test func2-1.25.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 0)}
} {{}}
do_test func2-1.25.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 1)}
} {s}
do_test func2-1.25.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 2)}
} {s}
do_test func2-1.26 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2, 1)}
} {u}
do_test func2-1.27 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30, 1)}
} {r}
do_test func2-1.28.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 0)}
} {{}}
do_test func2-1.28.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 1)}
} {S}
do_test func2-1.28.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 2)}
} {Su}
do_test func2-1.29.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 1)}
} {{}}
do_test func2-1.29.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 2)}
} {S}
do_test func2-1.30.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 0)}
} {{}}
do_test func2-1.30.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 1)}
} {{}}
do_test func2-1.30.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 2)}
} {{}}
do_test func2-1.30.3 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 3)}
} {S}
# p1 is 1-indexed, p2 length to return, p2<0 return p2 chars before p1
do_test func2-1.31.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 0)}
} {{}}
do_test func2-1.31.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -1)}
} {{}}
do_test func2-1.31.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -2)}
} {{}}
do_test func2-1.32.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 0)}
} {{}}
do_test func2-1.32.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, -1)}
} {{}}
do_test func2-1.33.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)}
} {{}}
do_test func2-1.33.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -1)}
} {S}
do_test func2-1.33.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -2)}
} {S}
do_test func2-1.34.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, 0)}
} {{}}
do_test func2-1.34.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -1)}
} {u}
do_test func2-1.34.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -2)}
} {Su}
do_test func2-1.35.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -1)}
} {o}
do_test func2-1.35.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -2)}
} {do}
do_test func2-1.36 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, -1)}
} {u}
do_test func2-1.37 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, -1)}
} {s}
do_test func2-1.38.0 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 0)}
} {{}}
do_test func2-1.38.1 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -1)}
} {{}}
do_test func2-1.38.2 {
execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -2)}
} {s}
#----------------------------------------------------------------------------
# Test cases func2-2.*: substr implementation (utf8)
#
# Only do the following tests if TCL has UTF-8 capabilities
#
if {"\u1234"!="u1234"} {
do_test func2-2.1.1 {
execsql "SELECT 'hi\u1234ho'"
} "hi\u1234ho"
# substr(x,y), substr(x,y,z)
do_test func2-2.1.2 {
catchsql "SELECT SUBSTR()"
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-2.1.3 {
catchsql "SELECT SUBSTR('hi\u1234ho')"
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-2.1.4 {
catchsql "SELECT SUBSTR('hi\u1234ho', 1,1,1)"
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-2.2.0 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 0)"
} {{}}
do_test func2-2.2.1 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 1)"
} {{}}
do_test func2-2.2.2 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 2)"
} "h"
do_test func2-2.2.3 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 3)"
} "hi"
do_test func2-2.2.4 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 4)"
} "hi\u1234"
do_test func2-2.2.5 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 5)"
} "hi\u1234h"
do_test func2-2.2.6 {
execsql "SELECT SUBSTR('hi\u1234ho', 0, 6)"
} "hi\u1234ho"
do_test func2-2.3.0 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 0)"
} {{}}
do_test func2-2.3.1 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 1)"
} "h"
do_test func2-2.3.2 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 2)"
} "hi"
do_test func2-2.3.3 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 3)"
} "hi\u1234"
do_test func2-2.3.4 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 4)"
} "hi\u1234h"
do_test func2-2.3.5 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 5)"
} "hi\u1234ho"
do_test func2-2.3.6 {
execsql "SELECT SUBSTR('hi\u1234ho', 1, 6)"
} "hi\u1234ho"
do_test func2-2.4.0 {
execsql "SELECT SUBSTR('hi\u1234ho', 3, 0)"
} {{}}
do_test func2-2.4.1 {
execsql "SELECT SUBSTR('hi\u1234ho', 3, 1)"
} "\u1234"
do_test func2-2.4.2 {
execsql "SELECT SUBSTR('hi\u1234ho', 3, 2)"
} "\u1234h"
do_test func2-2.5.0 {
execsql "SELECT SUBSTR('\u1234', 0, 0)"
} {{}}
do_test func2-2.5.1 {
execsql "SELECT SUBSTR('\u1234', 0, 1)"
} {{}}
do_test func2-2.5.2 {
execsql "SELECT SUBSTR('\u1234', 0, 2)"
} "\u1234"
do_test func2-2.5.3 {
execsql "SELECT SUBSTR('\u1234', 0, 3)"
} "\u1234"
do_test func2-2.6.0 {
execsql "SELECT SUBSTR('\u1234', 1, 0)"
} {{}}
do_test func2-2.6.1 {
execsql "SELECT SUBSTR('\u1234', 1, 1)"
} "\u1234"
do_test func2-2.6.2 {
execsql "SELECT SUBSTR('\u1234', 1, 2)"
} "\u1234"
do_test func2-2.6.3 {
execsql "SELECT SUBSTR('\u1234', 1, 3)"
} "\u1234"
do_test func2-2.7.0 {
execsql "SELECT SUBSTR('\u1234', 2, 0)"
} {{}}
do_test func2-2.7.1 {
execsql "SELECT SUBSTR('\u1234', 2, 1)"
} {{}}
do_test func2-2.7.2 {
execsql "SELECT SUBSTR('\u1234', 2, 2)"
} {{}}
do_test func2-2.8.0 {
execsql "SELECT SUBSTR('\u1234', -1, 0)"
} {{}}
do_test func2-2.8.1 {
execsql "SELECT SUBSTR('\u1234', -1, 1)"
} "\u1234"
do_test func2-2.8.2 {
execsql "SELECT SUBSTR('\u1234', -1, 2)"
} "\u1234"
do_test func2-2.8.3 {
execsql "SELECT SUBSTR('\u1234', -1, 3)"
} "\u1234"
} ;# End \u1234!=u1234
#----------------------------------------------------------------------------
# Test cases func2-3.*: substr implementation (blob)
#
ifcapable {!bloblit} {
finish_test
return
}
do_test func2-3.1.1 {
set blob [execsql "SELECT x'1234'"]
bin_to_hex [lindex $blob 0]
} "1234"
# substr(x,y), substr(x,y,z)
do_test func2-3.1.2 {
catchsql {SELECT SUBSTR()}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-3.1.3 {
catchsql {SELECT SUBSTR(x'1234')}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-3.1.4 {
catchsql {SELECT SUBSTR(x'1234', 1,1,1)}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-3.2.0 {
set blob [execsql "SELECT SUBSTR(x'1234', 0, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.2.1 {
set blob [execsql "SELECT SUBSTR(x'1234', 0, 1)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.2.2 {
set blob [execsql "SELECT SUBSTR(x'1234', 0, 2)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.2.3 {
set blob [execsql "SELECT SUBSTR(x'1234', 0, 3)"]
bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.3.0 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.3.1 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, 1)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.3.2 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, 2)"]
bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.3.3 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, 3)"]
bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.4.0 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.4.1 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, 1)"]
bin_to_hex [lindex $blob 0]
} "34"
do_test func2-3.4.2 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, 2)"]
bin_to_hex [lindex $blob 0]
} "34"
do_test func2-3.4.3 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, 3)"]
bin_to_hex [lindex $blob 0]
} "34"
do_test func2-3.5.0 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.5.1 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, 1)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.5.2 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, 2)"]
bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.5.3 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, 3)"]
bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.6.0 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.6.1 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, -1)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.6.2 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, -2)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.6.3 {
set blob [execsql "SELECT SUBSTR(x'1234', -1, -3)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.7.0 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.7.1 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, -1)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.7.2 {
set blob [execsql "SELECT SUBSTR(x'1234', -2, -2)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.8.0 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.8.1 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, -1)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.8.2 {
set blob [execsql "SELECT SUBSTR(x'1234', 1, -2)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.9.0 {
set blob [execsql "SELECT SUBSTR(x'1234', 2, 0)"]
bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.9.1 {
set blob [execsql "SELECT SUBSTR(x'1234', 2, -1)"]
bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.9.2 {
set blob [execsql "SELECT SUBSTR(x'1234', 2, -2)"]
bin_to_hex [lindex $blob 0]
} "12"
#-------------------------------------------------------------------------
# At one point this was extremely slow to compile.
#
do_test func2-3.10 {
set tm [time {
execsql {
SELECT '' IN (zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(1)
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
}
}]
set tm [lindex $tm 0]
expr $tm<2000000
} {1}
finish_test

211
testing/sqlite3/func3.test Normal file
View file

@ -0,0 +1,211 @@
# 2010 August 27
#
# 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 file is testing that destructor functions associated
# with functions created using sqlite3_create_function_v2() is
# correctly invoked.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable utf16 {
do_test func3-1.1 {
set destroyed 0
proc destroy {} { set ::destroyed 1 }
sqlite3_create_function_v2 db f2 -1 any -func f2 -destroy destroy
set destroyed
} 0
do_test func3-1.2 {
sqlite3_create_function_v2 db f2 -1 utf8 -func f2
set destroyed
} 0
do_test func3-1.3 {
sqlite3_create_function_v2 db f2 -1 utf16le -func f2
set destroyed
} 0
do_test func3-1.4 {
sqlite3_create_function_v2 db f2 -1 utf16be -func f2
set destroyed
} 1
}
do_test func3-2.1 {
set destroyed 0
proc destroy {} { set ::destroyed 1 }
sqlite3_create_function_v2 db f3 -1 utf8 -func f3 -destroy destroy
set destroyed
} 0
do_test func3-2.2 {
sqlite3_create_function_v2 db f3 -1 utf8 -func f3
set destroyed
} 1
do_test func3-3.1 {
set destroyed 0
proc destroy {} { set ::destroyed 1 }
sqlite3_create_function_v2 db f3 -1 any -func f3 -destroy destroy
set destroyed
} 0
do_test func3-3.2 {
db close
set destroyed
} 1
sqlite3 db test.db
do_test func3-4.1 {
set destroyed 0
set rc [catch {
sqlite3_create_function_v2 db f3 -1 any -func f3 -step f3 -destroy destroy
} msg]
list $rc $msg
} {1 SQLITE_MISUSE}
do_test func3-4.2 { set destroyed } 1
# EVIDENCE-OF: R-41921-05214 The likelihood(X,Y) function returns
# argument X unchanged.
#
do_execsql_test func3-5.1 {
SELECT likelihood(9223372036854775807, 0.5);
} {9223372036854775807}
do_execsql_test func3-5.2 {
SELECT likelihood(-9223372036854775808, 0.5);
} {-9223372036854775808}
do_execsql_test func3-5.3 {
SELECT likelihood(14.125, 0.5);
} {14.125}
do_execsql_test func3-5.4 {
SELECT likelihood(NULL, 0.5);
} {{}}
do_execsql_test func3-5.5 {
SELECT likelihood('test-string', 0.5);
} {test-string}
do_execsql_test func3-5.6 {
SELECT quote(likelihood(x'010203000405', 0.5));
} {X'010203000405'}
# EVIDENCE-OF: R-44133-61651 The value Y in likelihood(X,Y) must be a
# floating point constant between 0.0 and 1.0, inclusive.
#
do_execsql_test func3-5.7 {
SELECT likelihood(123, 1.0), likelihood(456, 0.0);
} {123 456}
do_test func3-5.8 {
catchsql {
SELECT likelihood(123, 1.000001);
}
} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
do_test func3-5.9 {
catchsql {
SELECT likelihood(123, -0.000001);
}
} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
do_test func3-5.10 {
catchsql {
SELECT likelihood(123, 0.5+0.3);
}
} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
# EVIDENCE-OF: R-28535-44631 The likelihood(X) function is a no-op that
# the code generator optimizes away so that it consumes no CPU cycles
# during run-time (that is, during calls to sqlite3_step()).
#
do_test func3-5.20 {
db eval {EXPLAIN SELECT likelihood(min(1.0+'2.0',4*11), 0.5)}
} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}]
# EVIDENCE-OF: R-11152-23456 The unlikely(X) function returns the
# argument X unchanged.
#
do_execsql_test func3-5.30 {
SELECT unlikely(9223372036854775807);
} {9223372036854775807}
do_execsql_test func3-5.31 {
SELECT unlikely(-9223372036854775808);
} {-9223372036854775808}
do_execsql_test func3-5.32 {
SELECT unlikely(14.125);
} {14.125}
do_execsql_test func3-5.33 {
SELECT unlikely(NULL);
} {{}}
do_execsql_test func3-5.34 {
SELECT unlikely('test-string');
} {test-string}
do_execsql_test func3-5.35 {
SELECT quote(unlikely(x'010203000405'));
} {X'010203000405'}
# EVIDENCE-OF: R-22887-63324 The unlikely(X) function is a no-op that
# the code generator optimizes away so that it consumes no CPU cycles at
# run-time (that is, during calls to sqlite3_step()).
#
do_test func3-5.39 {
db eval {EXPLAIN SELECT unlikely(min(1.0+'2.0',4*11))}
} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}]
# Unlikely() does not preserve the affinity of X.
# ticket https://sqlite.org/src/tktview/0c620df60b
#
do_execsql_test func3-5.40 {
SELECT likely(CAST(1 AS INT))=='1';
} 0
do_execsql_test func3-5.41 {
SELECT unlikely(CAST(1 AS INT))=='1';
} 0
do_execsql_test func3-5.41 {
SELECT likelihood(CAST(1 AS INT),0.5)=='1';
} 0
# EVIDENCE-OF: R-23735-03107 The likely(X) function returns the argument
# X unchanged.
#
do_execsql_test func3-5.50 {
SELECT likely(9223372036854775807);
} {9223372036854775807}
do_execsql_test func3-5.51 {
SELECT likely(-9223372036854775808);
} {-9223372036854775808}
do_execsql_test func3-5.52 {
SELECT likely(14.125);
} {14.125}
do_execsql_test func3-5.53 {
SELECT likely(NULL);
} {{}}
do_execsql_test func3-5.54 {
SELECT likely('test-string');
} {test-string}
do_execsql_test func3-5.55 {
SELECT quote(likely(x'010203000405'));
} {X'010203000405'}
# EVIDENCE-OF: R-43464-09689 The likely(X) function is a no-op that the
# code generator optimizes away so that it consumes no CPU cycles at
# run-time (that is, during calls to sqlite3_step()).
#
do_test func3-5.59 {
db eval {EXPLAIN SELECT likely(min(1.0+'2.0',4*11))}
} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}]
# Test the outcome of specifying NULL xStep and xFinal pointers (normally
# used to delete any existing function) and a non-NULL xDestroy when there
# is no existing function to destroy.
#
do_test func3-6.0 {
sqlite3_create_function_v2 db nofunc 1 utf8
} {}
finish_test

781
testing/sqlite3/func4.test Normal file
View file

@ -0,0 +1,781 @@
# 2023-03-10
#
# 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 file is testing the tointeger() and toreal() functions that are
# part of the "totype.c" extension. This file does not test the core
# SQLite library. Failures of tests in this file are related to the
# ext/misc/totype.c extension.
#
# Several of the toreal() tests are disabled on platforms where floating
# point precision is not high enough to represent their constant integer
# expression arguments as double precision floating point values.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set saved_tcl_precision $tcl_precision
set tcl_precision 0
load_static_extension db totype
set highPrecision(1) [expr \
{[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
set highPrecision(2) [expr \
{[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
# highPrecision(3) is only known to be false on i586 with gcc-13 and -O2.
# It is true on the exact same platform with -O0. Both results seem
# reasonable, so we'll just very the expectation accordingly.
#
set highPrecision(3) [expr \
{[db eval {SELECT toreal(9007199254740992 + 1);}] eq {{}}}]
if {!$highPrecision(1) || !$highPrecision(2) || !$highPrecision(3)} {
puts "NOTICE:\
highPrecision: $highPrecision(1) $highPrecision(2) $highPrecision(3)"
}
do_execsql_test func4-1.1 {
SELECT tointeger(NULL);
} {{}}
do_execsql_test func4-1.2 {
SELECT tointeger('');
} {{}}
do_execsql_test func4-1.3 {
SELECT tointeger(' ');
} {{}}
do_execsql_test func4-1.4 {
SELECT tointeger('1234');
} {1234}
do_execsql_test func4-1.5 {
SELECT tointeger(' 1234');
} {{}}
do_execsql_test func4-1.6 {
SELECT tointeger('bad');
} {{}}
do_execsql_test func4-1.7 {
SELECT tointeger('0xBAD');
} {{}}
do_execsql_test func4-1.8 {
SELECT tointeger('123BAD');
} {{}}
do_execsql_test func4-1.9 {
SELECT tointeger('0x123BAD');
} {{}}
do_execsql_test func4-1.10 {
SELECT tointeger('123NO');
} {{}}
do_execsql_test func4-1.11 {
SELECT tointeger('0x123NO');
} {{}}
do_execsql_test func4-1.12 {
SELECT tointeger('-0x1');
} {{}}
do_execsql_test func4-1.13 {
SELECT tointeger('-0x0');
} {{}}
do_execsql_test func4-1.14 {
SELECT tointeger('0x0');
} {{}}
do_execsql_test func4-1.15 {
SELECT tointeger('0x1');
} {{}}
do_execsql_test func4-1.16 {
SELECT tointeger(-1);
} {-1}
do_execsql_test func4-1.17 {
SELECT tointeger(-0);
} {0}
do_execsql_test func4-1.18 {
SELECT tointeger(0);
} {0}
do_execsql_test func4-1.19 {
SELECT tointeger(1);
} {1}
do_execsql_test func4-1.20 {
SELECT tointeger(-1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.21 {
SELECT tointeger(-1.79769313486232e308);
} {{}}
do_execsql_test func4-1.22 {
SELECT tointeger(-1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.23 {
SELECT tointeger(-9223372036854775808 - 1);
} {{}}
do_execsql_test func4-1.24 {
SELECT tointeger(-9223372036854775808);
} {-9223372036854775808}
do_execsql_test func4-1.25 {
SELECT tointeger(-9223372036854775808 + 1);
} {-9223372036854775807}
do_execsql_test func4-1.26 {
SELECT tointeger(-9223372036854775807 - 1);
} {-9223372036854775808}
do_execsql_test func4-1.27 {
SELECT tointeger(-9223372036854775807);
} {-9223372036854775807}
do_execsql_test func4-1.28 {
SELECT tointeger(-9223372036854775807 + 1);
} {-9223372036854775806}
do_execsql_test func4-1.29 {
SELECT tointeger(-2147483648 - 1);
} {-2147483649}
do_execsql_test func4-1.30 {
SELECT tointeger(-2147483648);
} {-2147483648}
do_execsql_test func4-1.31 {
SELECT tointeger(-2147483648 + 1);
} {-2147483647}
do_execsql_test func4-1.32 {
SELECT tointeger(2147483647 - 1);
} {2147483646}
do_execsql_test func4-1.33 {
SELECT tointeger(2147483647);
} {2147483647}
do_execsql_test func4-1.34 {
SELECT tointeger(2147483647 + 1);
} {2147483648}
do_execsql_test func4-1.35 {
SELECT tointeger(9223372036854775807 - 1);
} {9223372036854775806}
do_execsql_test func4-1.36 {
SELECT tointeger(9223372036854775807);
} {9223372036854775807}
if {$highPrecision(1)} {
do_execsql_test func4-1.37 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
}
do_execsql_test func4-1.38 {
SELECT tointeger(1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.39 {
SELECT tointeger(1.79769313486232e308);
} {{}}
do_execsql_test func4-1.40 {
SELECT tointeger(1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.41 {
SELECT tointeger(4503599627370496 - 1);
} {4503599627370495}
do_execsql_test func4-1.42 {
SELECT tointeger(4503599627370496);
} {4503599627370496}
do_execsql_test func4-1.43 {
SELECT tointeger(4503599627370496 + 1);
} {4503599627370497}
do_execsql_test func4-1.44 {
SELECT tointeger(9007199254740992 - 1);
} {9007199254740991}
do_execsql_test func4-1.45 {
SELECT tointeger(9007199254740992);
} {9007199254740992}
do_execsql_test func4-1.46 {
SELECT tointeger(9007199254740992 + 1);
} {9007199254740993}
do_execsql_test func4-1.47 {
SELECT tointeger(9223372036854775807 - 1);
} {9223372036854775806}
do_execsql_test func4-1.48 {
SELECT tointeger(9223372036854775807);
} {9223372036854775807}
if {$highPrecision(1)} {
do_execsql_test func4-1.49 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
do_execsql_test func4-1.50 {
SELECT tointeger(9223372036854775808 - 1);
} {{}}
do_execsql_test func4-1.51 {
SELECT tointeger(9223372036854775808);
} {{}}
do_execsql_test func4-1.52 {
SELECT tointeger(9223372036854775808 + 1);
} {{}}
}
do_execsql_test func4-1.53 {
SELECT tointeger(18446744073709551616 - 1);
} {{}}
do_execsql_test func4-1.54 {
SELECT tointeger(18446744073709551616);
} {{}}
do_execsql_test func4-1.55 {
SELECT tointeger(18446744073709551616 + 1);
} {{}}
ifcapable floatingpoint {
do_execsql_test func4-2.1 {
SELECT toreal(NULL);
} {{}}
do_execsql_test func4-2.2 {
SELECT toreal('');
} {{}}
do_execsql_test func4-2.3 {
SELECT toreal(' ');
} {{}}
do_execsql_test func4-2.4 {
SELECT toreal('1234');
} {1234.0}
do_execsql_test func4-2.5 {
SELECT toreal(' 1234');
} {{}}
do_execsql_test func4-2.6 {
SELECT toreal('bad');
} {{}}
do_execsql_test func4-2.7 {
SELECT toreal('0xBAD');
} {{}}
do_execsql_test func4-2.8 {
SELECT toreal('123BAD');
} {{}}
do_execsql_test func4-2.9 {
SELECT toreal('0x123BAD');
} {{}}
do_execsql_test func4-2.10 {
SELECT toreal('123NO');
} {{}}
do_execsql_test func4-2.11 {
SELECT toreal('0x123NO');
} {{}}
do_execsql_test func4-2.12 {
SELECT toreal('-0x1');
} {{}}
do_execsql_test func4-2.13 {
SELECT toreal('-0x0');
} {{}}
do_execsql_test func4-2.14 {
SELECT toreal('0x0');
} {{}}
do_execsql_test func4-2.15 {
SELECT toreal('0x1');
} {{}}
do_execsql_test func4-2.16 {
SELECT toreal(-1);
} {-1.0}
do_execsql_test func4-2.17 {
SELECT toreal(-0);
} {0.0}
do_execsql_test func4-2.18 {
SELECT toreal(0);
} {0.0}
do_execsql_test func4-2.19 {
SELECT toreal(1);
} {1.0}
do_execsql_test func4-2.20 {
SELECT toreal(-1.79769313486232e308 - 1);
} {-Inf}
do_execsql_test func4-2.21 {
SELECT toreal(-1.79769313486232e308);
} {-Inf}
do_execsql_test func4-2.22 {
SELECT toreal(-1.79769313486232e308 + 1);
} {-Inf}
do_execsql_test func4-2.23 {
SELECT toreal(-9223372036854775808 - 1);
} {-9.223372036854776e+18}
do_execsql_test func4-2.24 {
SELECT toreal(-9223372036854775808);
} {{}}
if {$highPrecision(2)} {
do_execsql_test func4-2.25 {
SELECT toreal(-9223372036854775808 + 1);
} {{}}
}
do_execsql_test func4-2.26 {
SELECT toreal(-9223372036854775807 - 1);
} {{}}
if {$highPrecision(2)} {
do_execsql_test func4-2.27 {
SELECT toreal(-9223372036854775807);
} {{}}
do_execsql_test func4-2.28 {
SELECT toreal(-9223372036854775807 + 1);
} {{}}
}
do_execsql_test func4-2.29 {
SELECT toreal(-2147483648 - 1);
} {-2147483649.0}
do_execsql_test func4-2.30 {
SELECT toreal(-2147483648);
} {-2147483648.0}
do_execsql_test func4-2.31 {
SELECT toreal(-2147483648 + 1);
} {-2147483647.0}
do_execsql_test func4-2.32 {
SELECT toreal(2147483647 - 1);
} {2147483646.0}
do_execsql_test func4-2.33 {
SELECT toreal(2147483647);
} {2147483647.0}
do_execsql_test func4-2.34 {
SELECT toreal(2147483647 + 1);
} {2147483648.0}
if {$highPrecision(2)} {
do_execsql_test func4-2.35 {
SELECT toreal(9223372036854775807 - 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-2.36 {
SELECT toreal(9223372036854775807);
} {{}}
}
}
do_execsql_test func4-2.37 {
SELECT toreal(9223372036854775807 + 1);
} {9.223372036854776e+18}
do_execsql_test func4-2.38 {
SELECT toreal(1.79769313486232e308 - 1);
} {Inf}
do_execsql_test func4-2.39 {
SELECT toreal(1.79769313486232e308);
} {Inf}
do_execsql_test func4-2.40 {
SELECT toreal(1.79769313486232e308 + 1);
} {Inf}
do_execsql_test func4-2.41 {
SELECT toreal(4503599627370496 - 1);
} {4503599627370495.0}
do_execsql_test func4-2.42 {
SELECT toreal(4503599627370496);
} {4503599627370496.0}
do_execsql_test func4-2.43 {
SELECT toreal(4503599627370496 + 1);
} {4503599627370497.0}
do_execsql_test func4-2.44 {
SELECT toreal(9007199254740992 - 1);
} {9007199254740991.0}
do_execsql_test func4-2.45 {
SELECT toreal(9007199254740992);
} {9007199254740992.0}
if {$highPrecision(3)} {
do_execsql_test func4-2.46 {
SELECT toreal(9007199254740992 + 1);
} {{}}
} else {
do_execsql_test func4-2.46 {
SELECT toreal(9007199254740992 + 1);
} {9007199254740992.0}
}
do_execsql_test func4-2.47 {
SELECT toreal(9007199254740992 + 2);
} {9007199254740994.0}
do_execsql_test func4-2.48 {
SELECT toreal(tointeger(9223372036854775808) - 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-2.49 {
SELECT toreal(tointeger(9223372036854775808));
} {{}}
do_execsql_test func4-2.50 {
SELECT toreal(tointeger(9223372036854775808) + 1);
} {{}}
}
do_execsql_test func4-2.51 {
SELECT toreal(tointeger(18446744073709551616) - 1);
} {{}}
do_execsql_test func4-2.52 {
SELECT toreal(tointeger(18446744073709551616));
} {{}}
do_execsql_test func4-2.53 {
SELECT toreal(tointeger(18446744073709551616) + 1);
} {{}}
}
ifcapable check {
do_execsql_test func4-3.1 {
CREATE TABLE t1(
x INTEGER CHECK(tointeger(x) IS NOT NULL)
);
} {}
do_test func4-3.2 {
catchsql {
INSERT INTO t1 (x) VALUES (NULL);
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.3 {
catchsql {
INSERT INTO t1 (x) VALUES (NULL);
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.4 {
catchsql {
INSERT INTO t1 (x) VALUES ('');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.5 {
catchsql {
INSERT INTO t1 (x) VALUES ('bad');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.6 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234bad');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.7 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234.56bad');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.8 {
catchsql {
INSERT INTO t1 (x) VALUES (1234);
}
} {0 {}}
do_test func4-3.9 {
catchsql {
INSERT INTO t1 (x) VALUES (1234.56);
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.10 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234');
}
} {0 {}}
do_test func4-3.11 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234.56');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.12 {
catchsql {
INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.13 {
catchsql {
INSERT INTO t1 (x) VALUES (X'');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.14 {
catchsql {
INSERT INTO t1 (x) VALUES (X'1234');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.15 {
catchsql {
INSERT INTO t1 (x) VALUES (X'12345678');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
do_test func4-3.16 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234.00');
}
} {0 {}}
do_test func4-3.17 {
catchsql {
INSERT INTO t1 (x) VALUES (1234.00);
}
} {0 {}}
do_test func4-3.18 {
catchsql {
INSERT INTO t1 (x) VALUES ('-9223372036854775809');
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
if {$highPrecision(1)} {
do_test func4-3.19 {
catchsql {
INSERT INTO t1 (x) VALUES (9223372036854775808);
}
} {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}}
}
do_execsql_test func4-3.20 {
SELECT x FROM t1 WHERE x>0 ORDER BY x;
} {1234 1234 1234 1234}
ifcapable floatingpoint {
do_execsql_test func4-4.1 {
CREATE TABLE t2(
x REAL CHECK(toreal(x) IS NOT NULL)
);
} {}
do_test func4-4.2 {
catchsql {
INSERT INTO t2 (x) VALUES (NULL);
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.3 {
catchsql {
INSERT INTO t2 (x) VALUES (NULL);
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.4 {
catchsql {
INSERT INTO t2 (x) VALUES ('');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.5 {
catchsql {
INSERT INTO t2 (x) VALUES ('bad');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.6 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234bad');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.7 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234.56bad');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.8 {
catchsql {
INSERT INTO t2 (x) VALUES (1234);
}
} {0 {}}
do_test func4-4.9 {
catchsql {
INSERT INTO t2 (x) VALUES (1234.56);
}
} {0 {}}
do_test func4-4.10 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234');
}
} {0 {}}
do_test func4-4.11 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234.56');
}
} {0 {}}
do_test func4-4.12 {
catchsql {
INSERT INTO t2 (x) VALUES (ZEROBLOB(4));
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.13 {
catchsql {
INSERT INTO t2 (x) VALUES (X'');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.14 {
catchsql {
INSERT INTO t2 (x) VALUES (X'1234');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_test func4-4.15 {
catchsql {
INSERT INTO t2 (x) VALUES (X'12345678');
}
} {1 {CHECK constraint failed: toreal(x) IS NOT NULL}}
do_execsql_test func4-4.16 {
SELECT x FROM t2 ORDER BY x;
} {1234.0 1234.0 1234.56 1234.56}
}
}
ifcapable floatingpoint {
do_execsql_test func4-5.1 {
SELECT tointeger(toreal('1234'));
} {1234}
do_execsql_test func4-5.2 {
SELECT tointeger(toreal(-1));
} {-1}
do_execsql_test func4-5.3 {
SELECT tointeger(toreal(-0));
} {0}
do_execsql_test func4-5.4 {
SELECT tointeger(toreal(0));
} {0}
do_execsql_test func4-5.5 {
SELECT tointeger(toreal(1));
} {1}
do_execsql_test func4-5.6 {
SELECT tointeger(toreal(-9223372036854775808 - 1));
} {{}}
do_execsql_test func4-5.7 {
SELECT tointeger(toreal(-9223372036854775808));
} {{}}
if {$highPrecision(2)} {
do_execsql_test func4-5.8 {
SELECT tointeger(toreal(-9223372036854775808 + 1));
} {{}}
}
do_execsql_test func4-5.9 {
SELECT tointeger(toreal(-2147483648 - 1));
} {-2147483649}
do_execsql_test func4-5.10 {
SELECT tointeger(toreal(-2147483648));
} {-2147483648}
do_execsql_test func4-5.11 {
SELECT tointeger(toreal(-2147483648 + 1));
} {-2147483647}
do_execsql_test func4-5.12 {
SELECT tointeger(toreal(2147483647 - 1));
} {2147483646}
do_execsql_test func4-5.13 {
SELECT tointeger(toreal(2147483647));
} {2147483647}
do_execsql_test func4-5.14 {
SELECT tointeger(toreal(2147483647 + 1));
} {2147483648}
do_execsql_test func4-5.15 {
SELECT tointeger(toreal(9223372036854775807 - 1));
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-5.16 {
SELECT tointeger(toreal(9223372036854775807));
} {{}}
do_execsql_test func4-5.17 {
SELECT tointeger(toreal(9223372036854775807 + 1));
} {{}}
}
do_execsql_test func4-5.18 {
SELECT tointeger(toreal(4503599627370496 - 1));
} {4503599627370495}
do_execsql_test func4-5.19 {
SELECT tointeger(toreal(4503599627370496));
} {4503599627370496}
do_execsql_test func4-5.20 {
SELECT tointeger(toreal(4503599627370496 + 1));
} {4503599627370497}
do_execsql_test func4-5.21 {
SELECT tointeger(toreal(9007199254740992 - 1));
} {9007199254740991}
do_execsql_test func4-5.22 {
SELECT tointeger(toreal(9007199254740992));
} {9007199254740992}
if {$highPrecision(3)} {
do_execsql_test func4-5.23 {
SELECT tointeger(toreal(9007199254740992 + 1));
} {{}}
} else {
do_execsql_test func4-5.23 {
SELECT tointeger(toreal(9007199254740992 + 1));
} {9007199254740992}
}
do_execsql_test func4-5.24 {
SELECT tointeger(toreal(9007199254740992 + 2));
} {9007199254740994}
if {$highPrecision(1)} {
do_execsql_test func4-5.25 {
SELECT tointeger(toreal(9223372036854775808 - 1));
} {{}}
do_execsql_test func4-5.26 {
SELECT tointeger(toreal(9223372036854775808));
} {{}}
do_execsql_test func4-5.27 {
SELECT tointeger(toreal(9223372036854775808 + 1));
} {{}}
}
do_execsql_test func4-5.28 {
SELECT tointeger(toreal(18446744073709551616 - 1));
} {{}}
do_execsql_test func4-5.29 {
SELECT tointeger(toreal(18446744073709551616));
} {{}}
do_execsql_test func4-5.30 {
SELECT tointeger(toreal(18446744073709551616 + 1));
} {{}}
}
for {set i 0} {$i < 10} {incr i} {
if {$i == 8} continue
do_execsql_test func4-6.1.$i.1 [subst {
SELECT tointeger(x'[string repeat 01 $i]');
}] {{}}
ifcapable floatingpoint {
do_execsql_test func4-6.1.$i.2 [subst {
SELECT toreal(x'[string repeat 01 $i]');
}] {{}}
}
}
do_execsql_test func4-6.2.1 {
SELECT tointeger(x'0102030405060708');
} {578437695752307201}
do_execsql_test func4-6.2.2 {
SELECT tointeger(x'0807060504030201');
} {72623859790382856}
ifcapable floatingpoint {
do_execsql_test func4-6.3.1 {
SELECT toreal(x'ffefffffffffffff');
} {-1.7976931348623157e+308}
do_execsql_test func4-6.3.2 {
SELECT toreal(x'8010000000000000');
} {-2.2250738585072014e-308}
do_execsql_test func4-6.3.3 {
SELECT toreal(x'c000000000000000');
} {-2.0}
do_execsql_test func4-6.3.4 {
SELECT toreal(x'bff0000000000000');
} {-1.0}
do_execsql_test func4-6.3.5 {
SELECT toreal(x'8000000000000000');
} {-0.0}
do_execsql_test func4-6.3.6 {
SELECT toreal(x'0000000000000000');
} {0.0}
do_execsql_test func4-6.3.7 {
SELECT toreal(x'3ff0000000000000');
} {1.0}
do_execsql_test func4-6.3.8 {
SELECT toreal(x'4000000000000000');
} {2.0}
do_execsql_test func4-6.3.9 {
SELECT toreal(x'0010000000000000');
} {2.2250738585072014e-308}
do_execsql_test func4-6.3.10 {
SELECT toreal(x'7fefffffffffffff');
} {1.7976931348623157e+308}
do_execsql_test func4-6.3.11 {
SELECT toreal(x'8000000000000001');
} {-5e-324}
do_execsql_test func4-6.3.12 {
SELECT toreal(x'800fffffffffffff');
} {-2.225073858507201e-308}
do_execsql_test func4-6.3.13 {
SELECT toreal(x'0000000000000001');
} {5e-324}
do_execsql_test func4-6.3.14 {
SELECT toreal(x'000fffffffffffff');
} {2.225073858507201e-308}
do_execsql_test func4-6.3.15 {
SELECT toreal(x'fff0000000000000');
} {-Inf}
do_execsql_test func4-6.3.16 {
SELECT toreal(x'7ff0000000000000');
} {Inf}
do_execsql_test func4-6.3.17 {
SELECT toreal(x'fff8000000000000');
} {{}}
do_execsql_test func4-6.3.18 {
SELECT toreal(x'fff0000000000001');
} {{}}
do_execsql_test func4-6.3.19 {
SELECT toreal(x'fff7ffffffffffff');
} {{}}
do_execsql_test func4-6.3.20 {
SELECT toreal(x'7ff0000000000001');
} {{}}
do_execsql_test func4-6.3.21 {
SELECT toreal(x'7ff7ffffffffffff');
} {{}}
do_execsql_test func4-6.3.22 {
SELECT toreal(x'fff8000000000001');
} {{}}
do_execsql_test func4-6.3.23 {
SELECT toreal(x'ffffffffffffffff');
} {{}}
do_execsql_test func4-6.3.24 {
SELECT toreal(x'7ff8000000000000');
} {{}}
do_execsql_test func4-6.3.25 {
SELECT toreal(x'7fffffffffffffff');
} {{}}
}
set tcl_precision $saved_tcl_precision
unset saved_tcl_precision
finish_test

View file

@ -0,0 +1,64 @@
# 2013-11-21
#
# 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.
#
#*************************************************************************
#
# Testing of function factoring and the SQLITE_DETERMINISTIC flag.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Verify that constant string expressions that get factored into initializing
# code are not reused between function parameters and other values in the
# VDBE program, as the function might have changed the encoding.
#
do_execsql_test func5-1.1 {
PRAGMA encoding=UTF16le;
CREATE TABLE t1(x,a,b,c);
INSERT INTO t1 VALUES(1,'ab','cd',1);
INSERT INTO t1 VALUES(2,'gh','ef',5);
INSERT INTO t1 VALUES(3,'pqr','fuzzy',99);
INSERT INTO t1 VALUES(4,'abcdefg','xy',22);
INSERT INTO t1 VALUES(5,'shoe','mayer',2953);
SELECT x FROM t1 WHERE c=instr('abcdefg',b) OR a='abcdefg' ORDER BY +x;
} {2 4}
do_execsql_test func5-1.2 {
SELECT x FROM t1 WHERE a='abcdefg' OR c=instr('abcdefg',b) ORDER BY +x;
} {2 4}
# Verify that SQLITE_DETERMINISTIC functions get factored out of the
# evaluation loop whereas non-deterministic functions do not. counter1()
# is marked as non-deterministic and so is not factored out of the loop,
# and it really is non-deterministic, returning a different result each
# time. But counter2() is marked as deterministic, so it does get factored
# out of the loop. counter2() has the same implementation as counter1(),
# returning a different result on each invocation, but because it is
# only invoked once outside of the loop, it appears to return the same
# result multiple times.
#
do_execsql_test func5-2.1 {
CREATE TABLE t2(x,y);
INSERT INTO t2 VALUES(1,2),(3,4),(5,6),(7,8);
SELECT x, y FROM t2 WHERE x+5=5+x ORDER BY +x;
} {1 2 3 4 5 6 7 8}
sqlite3_create_function db
do_execsql_test func5-2.2 {
SELECT x, y FROM t2
WHERE x+counter1('hello')=counter1('hello')+x
ORDER BY +x;
} {}
set cvalue [db one {SELECT counter2('hello')+1}]
do_execsql_test func5-2.3 {
SELECT x, y FROM t2
WHERE x+counter2('hello')=$cvalue+x
ORDER BY +x;
} {1 2 3 4 5 6 7 8}
finish_test

183
testing/sqlite3/func6.test Normal file
View file

@ -0,0 +1,183 @@
# 2017-12-16
#
# 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.
#
#*************************************************************************
#
# Test cases for the sqlite_offset() function.
#
# Some of the tests in this file depend on the exact placement of content
# within b-tree pages. Such placement is at the implementations discretion,
# and so it is possible for results to change from one release to the next.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !offset_sql_func {
finish_test
return
}
set bNullTrim 0
ifcapable null_trim {
set bNullTrim 1
}
do_execsql_test func6-100 {
PRAGMA page_size=4096;
PRAGMA auto_vacuum=NONE;
CREATE TABLE t1(a,b,c,d);
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
INSERT INTO t1(a,b,c,d) SELECT printf('abc%03x',x), x, 1000-x, NULL FROM c;
CREATE INDEX t1a ON t1(a);
CREATE INDEX t1bc ON t1(b,c);
CREATE TABLE t2(x TEXT PRIMARY KEY, y) WITHOUT ROWID;
INSERT INTO t2(x,y) SELECT a, b FROM t1;
}
# Load the contents of $file from disk and return it encoded as a hex
# string.
proc loadhex {file} {
set fd [open $file]
fconfigure $fd -translation binary
set data [read $fd]
close $fd
binary encode hex $data
}
# Each argument is either an integer between 0 and 65535, a text value, or
# an empty string representing an SQL NULL. This command builds an SQLite
# record containing the values passed as arguments and returns it encoded
# as a hex string.
proc hexrecord {args} {
set hdr ""
set body ""
if {$::bNullTrim} {
while {[llength $args] && [lindex $args end]=={}} {
set args [lrange $args 0 end-1]
}
}
foreach x $args {
if {$x==""} {
append hdr 00
} elseif {[string is integer $x]==0} {
set n [string length $x]
append hdr [format %02x [expr $n*2 + 13]]
append body [binary encode hex $x]
} elseif {$x == 0} {
append hdr 08
} elseif {$x == 1} {
append hdr 09
} elseif {$x <= 127} {
append hdr 01
append body [format %02x $x]
} else {
append hdr 02
append body [format %04x $x]
}
}
set res [format %02x [expr 1 + [string length $hdr]/2]]
append res $hdr
append res $body
}
# Argument $off is an offset into the database image encoded as a hex string
# in argument $hexdb. This command returns 0 if the offset contains the hex
# $hexrec, or throws an exception otherwise.
#
proc offset_contains_record {off hexdb hexrec} {
set n [string length $hexrec]
set off [expr $off*2]
if { [string compare $hexrec [string range $hexdb $off [expr $off+$n-1]]] } {
error "record not found!"
}
return 0
}
# This command is the implementation of SQL function "offrec()". The first
# argument to this is an offset value. The remaining values are used to
# formulate an SQLite record. If database file test.db does not contain
# an equivalent record at the specified offset, an exception is thrown.
# Otherwise, 0 is returned.
#
proc offrec {args} {
set offset [lindex $args 0]
set rec [hexrecord {*}[lrange $args 1 end]]
offset_contains_record $offset $::F $rec
}
set F [loadhex test.db]
db func offrec offrec
# Test the sanity of the tests.
if {$bNullTrim} {
set offset 8180
} else {
set offset 8179
}
do_execsql_test func6-105 {
SELECT sqlite_offset(d) FROM t1 ORDER BY rowid LIMIT 1;
} $offset
do_test func6-106 {
set r [hexrecord abc001 1 999 {}]
offset_contains_record $offset $F $r
} 0
set z100 [string trim [string repeat "0 " 100]]
# Test offsets within table b-tree t1.
do_execsql_test func6-110 {
SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY rowid
} $z100
do_execsql_test func6-120 {
SELECT a, typeof(sqlite_offset(+a)) FROM t1
ORDER BY rowid LIMIT 2;
} {abc001 null abc002 null}
# Test offsets within index b-tree t1a.
do_execsql_test func6-130 {
SELECT offrec(sqlite_offset(a), a, rowid) FROM t1 ORDER BY a
} $z100
# Test offsets within table b-tree t1 with a temp b-tree ORDER BY.
do_execsql_test func6-140 {
SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY a
} $z100
# Test offsets from both index t1a and table t1 in the same query.
do_execsql_test func6-150 {
SELECT offrec(sqlite_offset(a), a, rowid),
offrec(sqlite_offset(d), a, b, c, d)
FROM t1 ORDER BY a
} [concat $z100 $z100]
# Test offsets from both index t1bc and table t1 in the same query.
do_execsql_test func6-160 {
SELECT offrec(sqlite_offset(b), b, c, rowid),
offrec(sqlite_offset(c), b, c, rowid),
offrec(sqlite_offset(d), a, b, c, d)
FROM t1
ORDER BY b
} [concat $z100 $z100 $z100]
# Test offsets in WITHOUT ROWID table t2.
do_execsql_test func6-200 {
SELECT offrec( sqlite_offset(y), x, y ) FROM t2 ORDER BY x
} $z100
# 2022-03-14 dbsqlfuzz 474499f3977d95fdf2dbcd99c50be1d0082e4c92
reset_db
do_execsql_test func6-300 {
CREATE TABLE t2(a INT, b INT PRIMARY KEY) WITHOUT ROWID;
CREATE INDEX x3 ON t2(b);
CREATE TABLE t1(a INT PRIMARY KEY, b TEXT);
SELECT * FROM t1 WHERE a IN (SELECT sqlite_offset(b) FROM t2);
} {}
finish_test

251
testing/sqlite3/func7.test Normal file
View file

@ -0,0 +1,251 @@
# 2020-12-07
#
# 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.
#
#*************************************************************************
#
# Test cases for SQL functions based off the standard math library
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !mathlib {
finish_test
return
}
do_execsql_test func7-100 {
SELECT ceil(99.9), ceiling(-99.01), floor(17), floor(-17.99);
} {100.0 -99.0 17 -18.0}
do_execsql_test func7-110 {
SELECT quote(ceil(NULL)), ceil('-99.99');
} {NULL -99.0}
do_execsql_test func7-200 {
SELECT round(ln(5),2), log(100.0), log(100), log(2,'256');
} {1.61 2.0 2.0 8.0}
do_execsql_test func7-210 {
SELECT ln(-5), log(-5,100.0);
} {{} {}}
# Test cases derived from PostgreSQL documentation
#
do_execsql_test func7-pg-100 {
SELECT abs(-17.4)
} {17.4}
do_execsql_test func7-pg-110 {
SELECT ceil(42.2)
} {43.0}
do_execsql_test func7-pg-120 {
SELECT ceil(-42.2)
} {-42.0}
do_execsql_test func7-pg-130 {
SELECT round(exp(1.0),7)
} {2.7182818}
do_execsql_test func7-pg-140 {
SELECT floor(42.8)
} {42.0}
do_execsql_test func7-pg-150 {
SELECT floor(-42.8)
} {-43.0}
do_execsql_test func7-pg-160 {
SELECT round(ln(2.0),7)
} {0.6931472}
do_execsql_test func7-pg-170 {
SELECT log(100.0)
} {2.0}
do_execsql_test func7-pg-180 {
SELECT log10(1000.0)
} {3.0}
do_execsql_test func7-pg-181 {
SELECT format('%.30f', log10(100.0) );
} {2.000000000000000000000000000000}
do_execsql_test func7-pg-182 {
SELECT format('%.30f', ln(exp(2.0)) );
} {2.000000000000000000000000000000}
do_execsql_test func7-pg-190 {
SELECT log(2.0, 64.0)
} {6.0}
do_execsql_test func7-pg-200 {
SELECT mod(9,4);
} {1.0}
do_execsql_test func7-pg-210 {
SELECT round(pi(),7);
} {3.1415927}
do_execsql_test func7-pg-220 {
SELECT power(9,3);
} {729.0}
do_execsql_test func7-pg-230 {
SELECT round(radians(45.0),7);
} {0.7853982}
do_execsql_test func7-pg-240 {
SELECT round(42.4);
} {42.0}
do_execsql_test func7-pg-250 {
SELECT round(42.4382,2);
} {42.44}
do_execsql_test func7-pg-260 {
SELECT sign(-8.4);
} {-1}
do_execsql_test func7-pg-270 {
SELECT round( sqrt(2), 7);
} {1.4142136}
do_execsql_test func7-pg-280 {
SELECT trunc(42.8), trunc(-42.8);
} {42.0 -42.0}
do_execsql_test func7-pg-300 {
SELECT acos(1);
} {0.0}
do_execsql_test func7-pg-301 {
SELECT format('%f',degrees(acos(0.5)));
} {60.0}
do_execsql_test func7-pg-310 {
SELECT round( asin(1), 7);
} {1.5707963}
do_execsql_test func7-pg-311 {
SELECT format('%f',degrees( asin(0.5) ));
} {30.0}
do_execsql_test func7-pg-320 {
SELECT round( atan(1), 7);
} {0.7853982}
do_execsql_test func7-pg-321 {
SELECT degrees( atan(1) );
} {45.0}
do_execsql_test func7-pg-330 {
SELECT round( atan2(1,0), 7);
} {1.5707963}
do_execsql_test func7-pg-331 {
SELECT degrees( atan2(1,0) );
} {90.0}
do_execsql_test func7-pg-400 {
SELECT cos(0);
} {1.0}
do_execsql_test func7-pg-401 {
SELECT cos( radians(60.0) );
} {0.5}
do_execsql_test func7-pg-400 {
SELECT cos(0);
} {1.0}
do_execsql_test func7-pg-410 {
SELECT round( sin(1), 7);
} {0.841471}
do_execsql_test func7-pg-411 {
SELECT sin( radians(30) );
} {0.5}
do_execsql_test func7-pg-420 {
SELECT round( tan(1), 7);
} {1.5574077}
do_execsql_test func7-pg-421 {
SELECT round(tan( radians(45) ),10);
} {1.0}
do_execsql_test func7-pg-500 {
SELECT round( sinh(1), 7);
} {1.1752012}
do_execsql_test func7-pg-510 {
SELECT round( cosh(0), 7);
} {1.0}
do_execsql_test func7-pg-520 {
SELECT round( tanh(1), 7);
} {0.7615942}
do_execsql_test func7-pg-530 {
SELECT round( asinh(1), 7);
} {0.8813736}
do_execsql_test func7-pg-540 {
SELECT round( acosh(1), 7);
} {0.0}
do_execsql_test func7-pg-550 {
SELECT round( atanh(0.5), 7);
} {0.5493061}
# Test cases derived from MySQL documentation
#
do_execsql_test func7-mysql-100 {
SELECT acos(1);
} {0.0}
do_execsql_test func7-mysql-110 {
SELECT acos(1.0001);
} {{}}
do_execsql_test func7-mysql-120 {
SELECT round( acos(0.0), 7);
} {1.5707963}
do_execsql_test func7-mysql-130 {
SELECT round( asin(0.2), 7);
} {0.2013579}
do_execsql_test func7-mysql-140 {
SELECT asin('foo');
} {{}} ;# Note: MySQL returns 0 here, not NULL.
# SQLite deliberately returns NULL.
# SQLServer and Oracle throw an error.
do_execsql_test func7-mysql-150 {
SELECT round( atan(2), 7), round( atan(-2), 7);
} {1.1071487 -1.1071487}
do_execsql_test func7-mysql-160 {
SELECT round( atan2(-2,2), 7), round( atan2(pi(),0), 7);
} {-0.7853982 1.5707963}
do_execsql_test func7-mysql-170 {
SELECT ceiling(1.23), ceiling(-1.23);
} {2.0 -1.0}
do_execsql_test func7-mysql-180 {
SELECT cos(pi());
} {-1.0}
do_execsql_test func7-mysql-190 {
SELECT degrees(pi()), degrees(pi()/2);
} {180.0 90.0}
do_execsql_test func7-mysql-190 {
SELECT round( exp(2), 7), round( exp(-2), 7), exp(0);
} {7.3890561 0.1353353 1.0}
do_execsql_test func7-mysql-200 {
SELECT floor(1.23), floor(-1.23);
} {1.0 -2.0}
do_execsql_test func7-mysql-210 {
SELECT round(ln(2),7), quote(ln(-2));
} {0.6931472 NULL}
#do_execsql_test func7-mysql-220 {
# SELECT round(log(2),7), log(-2);
#} {0.6931472 NULL}
# log() means natural logarithm in MySQL
do_execsql_test func7-mysql-230 {
SELECT log(2,65536), log(10,100), quote(log(1,100)), quote(log(0,100));
} {16.0 2.0 NULL NULL}
do_execsql_test func7-mysql-240 {
SELECT log2(65536), quote(log2(-100)), quote(log2(0));
} {16.0 NULL NULL}
do_execsql_test func7-mysql-250 {
SELECT round(log10(2),7), log10(100), quote(log10(-100));
} {0.30103 2.0 NULL}
do_execsql_test func7-mysql-260 {
SELECT mod(234,10), 253%7, mod(29,9), 29%9;
} {4.0 1 2.0 2}
do_execsql_test func7-mysql-270 {
SELECT mod(34.5,3);
} {1.5}
do_execsql_test func7-mysql-280 {
SELECT pow(2,2), pow(2,-2);
} {4.0 0.25}
do_execsql_test func7-mysql-281 {
SELECT power(2,2), power(2,-2);
} {4.0 0.25}
do_execsql_test func7-mysql-290 {
SELECT round(radians(90),7);
} {1.5707963}
do_execsql_test func7-mysql-300 {
SELECT sign(-32), sign(0), sign(234);
} {-1 0 1}
do_execsql_test func7-mysql-310 {
SELECT sin(pi()) BETWEEN -1.0e-15 AND 1.0e-15;
} {1}
do_execsql_test func7-mysql-320 {
SELECT sqrt(4), round(sqrt(20),7), quote(sqrt(-16));
} {2.0 4.472136 NULL}
do_execsql_test func7-mysql-330 {
SELECT tan(pi()) BETWEEN -1.0e-15 AND 1.0e-15;
} {1}
do_execsql_test func7-mysql-331 {
SELECT round(tan(pi()+1),7);
} {1.5574077}
finish_test

View file

@ -0,0 +1,64 @@
# 2023-03-17
#
# 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.
#
#*************************************************************************
#
# Test cases for SQL functions with names that are the same as join
# keywords: CROSS FULL INNER LEFT NATURAL OUTER RIGHT
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
proc joinx {args} {return [join $args -]}
db func cross {joinx cross}
db func full {joinx full}
db func inner {joinx inner}
db func left {joinx left}
db func natural {joinx natural}
db func outer {joinx outer}
db func right {joinx right}
do_execsql_test func8-100 {
CREATE TABLE cross(cross,full,inner,left,natural,outer,right);
CREATE TABLE full(cross,full,inner,left,natural,outer,right);
CREATE TABLE inner(cross,full,inner,left,natural,outer,right);
CREATE TABLE left(cross,full,inner,left,natural,outer,right);
CREATE TABLE natural(cross,full,inner,left,natural,outer,right);
CREATE TABLE outer(cross,full,inner,left,natural,outer,right);
CREATE TABLE right(cross,full,inner,left,natural,outer,right);
INSERT INTO cross VALUES(1,2,3,4,5,6,7);
INSERT INTO full VALUES(1,2,3,4,5,6,7);
INSERT INTO inner VALUES(1,2,3,4,5,6,7);
INSERT INTO left VALUES(1,2,3,4,5,6,7);
INSERT INTO natural VALUES(1,2,3,4,5,6,7);
INSERT INTO outer VALUES(1,2,3,4,5,6,7);
INSERT INTO right VALUES(1,2,3,4,5,6,7);
}
do_execsql_test func8-110 {
SELECT cross(cross,full,inner,left,natural,outer,right) FROM cross;
} cross-1-2-3-4-5-6-7
do_execsql_test func8-120 {
SELECT full(cross,full,inner,left,natural,outer,right) FROM full;
} full-1-2-3-4-5-6-7
do_execsql_test func8-130 {
SELECT inner(cross,full,inner,left,natural,outer,right) FROM inner;
} inner-1-2-3-4-5-6-7
do_execsql_test func8-140 {
SELECT left(cross,full,inner,left,natural,outer,right) FROM left;
} left-1-2-3-4-5-6-7
do_execsql_test func8-150 {
SELECT natural(cross,full,inner,left,natural,outer,right) FROM natural;
} natural-1-2-3-4-5-6-7
do_execsql_test func8-160 {
SELECT outer(cross,full,inner,left,natural,outer,right) FROM outer;
} outer-1-2-3-4-5-6-7
do_execsql_test func8-170 {
SELECT right(cross,full,inner,left,natural,outer,right) FROM right;
} right-1-2-3-4-5-6-7
finish_test

View file

@ -0,0 +1,53 @@
# 2023-08-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.
#
#*************************************************************************
#
# Test cases for some newer SQL functions
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_execsql_test func9-100 {
SELECT concat('abc',123,null,'xyz');
} {abc123xyz}
do_execsql_test func9-110 {
SELECT typeof(concat(null));
} {text}
do_catchsql_test func9-120 {
SELECT concat();
} {1 {wrong number of arguments to function concat()}}
do_execsql_test func9-130 {
SELECT concat_ws(',',1,2,3,4,5,6,7,8,NULL,9,10,11,12);
} {1,2,3,4,5,6,7,8,9,10,11,12}
do_execsql_test func9-131 {
SELECT concat_ws(',',1,2,3,4,'',6,7,8,NULL,9,10,11,12);
} {1,2,3,4,,6,7,8,9,10,11,12}
do_execsql_test func9-140 {
SELECT concat_ws(NULL,1,2,3,4,5,6,7,8,NULL,9,10,11,12);
} {{}}
do_catchsql_test func9-150 {
SELECT concat_ws();
} {1 {wrong number of arguments to function concat_ws()}}
do_catchsql_test func9-160 {
SELECT concat_ws(',');
} {1 {wrong number of arguments to function concat_ws()}}
# https://sqlite.org/forum/forumpost/4c344ca61f (2025-03-02)
do_execsql_test func9-200 {
SELECT unistr('G\u00e4ste');
} {Gäste}
do_execsql_test func9-210 {
SELECT unistr_quote(unistr('G\u00e4ste'));
} {'Gäste'}
do_execsql_test func9-220 {
SELECT format('%#Q',unistr('G\u00e4ste'));
} {'Gäste'}
finish_test