000001 # 2022-01-20 000002 # 000003 # The author disclaims copyright to this source code. In place of 000004 # a legal notice, here is a blessing: 000005 # 000006 # May you do good and not evil. 000007 # May you find forgiveness for yourself and forgive others. 000008 # May you share freely, never taking more than you give. 000009 # 000010 #*********************************************************************** 000011 # 000012 # This file implements tests for sqlite3_vtab_rhs_value() interface. 000013 # 000014 000015 set testdir [file dirname $argv0] 000016 source $testdir/tester.tcl 000017 set testprefix vtabrhs1 000018 000019 ifcapable !vtab { 000020 finish_test 000021 return 000022 } 000023 load_static_extension db qpvtab 000024 000025 # EVIDENCE-OF: R-60223-49197 When the sqlite3_vtab_rhs_value(P,J,V) 000026 # interface is invoked from within the xBestIndex method of a virtual 000027 # table implementation, with P being a copy of the sqlite3_index_info 000028 # object pointer passed into xBestIndex and J being a 0-based index into 000029 # P->aConstraint[], then this routine attempts to set *V to the value 000030 # of the right-hand operand of that constraint if the right-hand operand 000031 # is known. 000032 # 000033 do_execsql_test 1.1 { 000034 SELECT rhs FROM qpvtab 000035 WHERE cn='a' 000036 AND a=12345 000037 } {12345} 000038 do_execsql_test 1.2 { 000039 SELECT rhs FROM qpvtab 000040 WHERE cn='a' 000041 AND a<>4.5 000042 } {4.5} 000043 do_execsql_test 1.3 { 000044 SELECT rhs FROM qpvtab 000045 WHERE cn='a' 000046 AND 'quokka' < a 000047 } {'quokka'} 000048 do_execsql_test 1.4 { 000049 SELECT rhs FROM qpvtab 000050 WHERE cn='a' 000051 AND a IS NULL 000052 } {{}} 000053 do_execsql_test 1.5 { 000054 SELECT rhs FROM qpvtab 000055 WHERE cn='a' 000056 AND a GLOB x'0123' 000057 } {x'0123'} 000058 000059 # EVIDENCE-OF: R-37799-62852 If the right-hand operand is not known, 000060 # then *V is set to a NULL pointer. 000061 # 000062 do_execsql_test 2.1 { 000063 SELECT typeof(rhs) FROM qpvtab WHERE cn='a' AND a=format('abc'); 000064 } {null} 000065 do_execsql_test 2.2 { 000066 SELECT typeof(rhs) FROM qpvtab WHERE cn='a' AND a=?2 000067 } {null} 000068 000069 # EVIDENCE-OF: R-14553-25174 When xBestIndex returns, the sqlite3_value 000070 # object returned by sqlite3_vtab_rhs_value() is automatically 000071 # deallocated. 000072 # 000073 # Where this not the case, the following "finish_test" statement would 000074 # report a memory leak. 000075 # 000076 finish_test