xref: /sqlite-3.40.0/test/vtabrhs1.test (revision 4734b3f9)
1# 2022-01-20
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
6#    May you do good and not evil.
7#    May you find forgiveness for yourself and forgive others.
8#    May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# This file implements tests for sqlite3_vtab_rhs_value() interface.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix vtabrhs1
18
19ifcapable !vtab {
20  finish_test
21  return
22}
23load_static_extension db qpvtab
24
25# EVIDENCE-OF: R-60223-49197 When the sqlite3_vtab_rhs_value(P,J,V)
26# interface is invoked from within the xBestIndex method of a virtual
27# table implementation, with P being a copy of the sqlite3_index_info
28# object pointer passed into xBestIndex and J being a 0-based index into
29# P->aConstraint[], then this routine attempts to set *V to the value
30# of the right-hand operand of that constraint if the right-hand operand
31# is known.
32#
33do_execsql_test 1.1 {
34  SELECT rhs FROM qpvtab
35   WHERE cn='a'
36     AND a=12345
37} {12345}
38do_execsql_test 1.2 {
39  SELECT rhs FROM qpvtab
40   WHERE cn='a'
41     AND a<>4.5
42} {4.5}
43do_execsql_test 1.3 {
44  SELECT rhs FROM qpvtab
45   WHERE cn='a'
46     AND 'quokka' < a
47} {'quokka'}
48do_execsql_test 1.4 {
49  SELECT rhs FROM qpvtab
50   WHERE cn='a'
51     AND a IS NULL
52} {{}}
53do_execsql_test 1.5 {
54  SELECT rhs FROM qpvtab
55   WHERE cn='a'
56     AND a GLOB x'0123'
57} {x'0123'}
58
59# EVIDENCE-OF: R-37799-62852 If the right-hand operand is not known,
60# then *V is set to a NULL pointer.
61#
62do_execsql_test 2.1 {
63  SELECT typeof(rhs) FROM qpvtab WHERE cn='a' AND a=format('abc');
64} {null}
65do_execsql_test 2.2 {
66  SELECT typeof(rhs) FROM qpvtab WHERE cn='a' AND a=?2
67} {null}
68
69# EVIDENCE-OF: R-14553-25174 When xBestIndex returns, the sqlite3_value
70# object returned by sqlite3_vtab_rhs_value() is automatically
71# deallocated.
72#
73# Where this not the case, the following "finish_test" statement would
74# report a memory leak.
75#
76finish_test
77