#!sqlite3 # # 2026-10-24 # # 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 ".if", ".elseif", ".else", and ".endif" commands # and the capable() SQL function of the CLI. # # ./sqlite3 test/if.sql # # Many tests use ".read <100) .print 300-BUG .endif .if EXISTS(SELECT 1 FROM t1 WHERE a=2) .print 300-c .endif .if -1 .print 300-d .endif .if 'abc' .print 300-BUG .endif .if '5' .print 300-e .endif .if 0.0 .print 300-BUG .endif .if 0.5 .print 300-f .endif .if 9223372036854775807 .print 300-g .endif .check <3 .print 320-a .else .print 320-BUG .endif .if $x>10 .print 320-BUG .endif .parameter unset $x .check 320-a # An expression that has a syntax error or a run-time error is false. # No error message is issued. # .testcase 330 .if 1 + .print 330-BUG .else .print 330-else .endif .check 330-else .testcase 331 .if .print 331-BUG .else .print 331-else .endif .check 331-else .testcase 332 .if (SELECT x FROM no_such_table) .print 332-BUG .else .print 332-else .endif .check 332-else .testcase 333 .if NOT (SELECT x FROM no_such_table) .print 333-BUG .endif .print 333-end .check 333-end .testcase 340 .if abs(-9223372036854775808) .print 340-BUG .else .print 340-else .endif .check 340-else .testcase 341 .if 0 .print 341-BUG .elseif abs(-9223372036854775808) .print 341-BUG .elseif no_such_function(1) .print 341-BUG .else .print 341-else .endif .check 341-else # A capable() test on a table that might not exist. This is the # intended use for the error-is-false rule. # .testcase 350 .if (SELECT count(*) FROM pragma_module_list WHERE name='no_such_module') .print 350-BUG .elseif (SELECT count(*) FROM no_such_vtab)>=0 .print 350-BUG .else .print 350-else .endif .check 350-else ############################################################################# # .elseif # .testcase 400 .if 0 .print 400-BUG .elseif 1 .print 400-a .else .print 400-BUG .endif .check 400-a .testcase 410 .if 0 .print 410-BUG .elseif 0 .print 410-BUG .else .print 410-a .endif .check 410-a # At most one branch of an .if/.elseif/.else chain is run # .testcase 420 .if 1 .print 420-a .elseif 1 .print 420-BUG .endif .check 420-a .testcase 421 .if 1 .print 421-a .elseif 0 .print 421-BUG .else .print 421-BUG .endif .check 421-a .testcase 422 .if 0 .print 422-BUG .elseif 0 .print 422-BUG .elseif 1 .print 422-a .elseif 1 .print 422-BUG .else .print 422-BUG .endif .check 422-a .testcase 423 .if 0 .print 423-BUG .elseif 1 .print 423-a .elseif 0 .print 423-BUG .else .print 423-BUG .endif .check 423-a # The chain state of one .if does not carry over to the next .if at # the same level. # .testcase 424 .if 1 .endif .if 0 .print 424-BUG .elseif 1 .print 424-a .endif .if 1 .endif .if 0 .print 424-BUG .else .print 424-b .endif .check <:2: unterminated .if" .check --keep --notglob 700-BUG .check --glob "700-inner*700-after-read" # Also with nested unterminated .ifs. The .else at nesting level 2 # must not be remembered after the .read finishes. # .testcase 701 .read <