Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/if.sql # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / if.sql` 858 lines ยท 13159 bytes Raw Blame History 1 #!sqlite3 2 # 3 # 2026-10-24 4 # 5 # The author disclaims copyright to this source code. In place of 6 # a legal notice, here is a blessing: 7 # 8 # May you do good and not evil. 9 # May you find forgiveness for yourself and forgive others. 10 # May you share freely, never taking more than you give. 11 # 12 #*********************************************************************** 13 # 14 # Test cases for the ".if", ".elseif", ".else", and ".endif" commands 15 # and the capable() SQL function of the CLI. 16 # 17 # ./sqlite3 test/if.sql 18 # 19 # Many tests use ".read <100) 178 .print 300-BUG 179 .endif 180 .if EXISTS(SELECT 1 FROM t1 WHERE a=2) 181 .print 300-c 182 .endif 183 .if -1 184 .print 300-d 185 .endif 186 .if 'abc' 187 .print 300-BUG 188 .endif 189 .if '5' 190 .print 300-e 191 .endif 192 .if 0.0 193 .print 300-BUG 194 .endif 195 .if 0.5 196 .print 300-f 197 .endif 198 .if `9223372036854775807` 199 .print 300-g 200 .endif 201 .check <3 227 .print 320-a 228 .else 229 .print 320-BUG 230 .endif 231 .if $x>10 232 .print 320-BUG 233 .endif 234 .parameter unset $x 235 .check 320-a 236 237 # An expression that has a syntax error or a run-time error is false. 238 # No error message is issued. 239 # 240 .testcase 330 241 .if 1 + 242 .print 330-BUG 243 .else 244 .print 330-else 245 .endif 246 .check 330-else 247 248 .testcase 331 249 .if 250 .print 331-BUG 251 .else 252 .print 331-else 253 .endif 254 .check 331-else 255 256 .testcase 332 257 .if (SELECT x FROM no_such_table) 258 .print 332-BUG 259 .else 260 .print 332-else 261 .endif 262 .check 332-else 263 264 .testcase 333 265 .if NOT (SELECT x FROM no_such_table) 266 .print 333-BUG 267 .endif 268 .print 333-end 269 .check 333-end 270 271 .testcase 340 272 .if abs(-`9223372036854775808`) 273 .print 340-BUG 274 .else 275 .print 340-else 276 .endif 277 .check 340-else 278 279 .testcase 341 280 .if 0 281 .print 341-BUG 282 .elseif abs(-`9223372036854775808`) 283 .print 341-BUG 284 .elseif no_such_function(1) 285 .print 341-BUG 286 .else 287 .print 341-else 288 .endif 289 .check 341-else 290 291 # A capable() test on a table that might not exist. This is the 292 # intended use for the error-is-false rule. 293 # 294 .testcase 350 295 .if (SELECT count(*) FROM pragma_module_list WHERE name='no_such_module') 296 .print 350-BUG 297 .elseif (SELECT count(*) FROM no_such_vtab)>=0 298 .print 350-BUG 299 .else 300 .print 350-else 301 .endif 302 .check 350-else 303 304 ############################################################################# 305 # .elseif 306 # 307 .testcase 400 308 .if 0 309 .print 400-BUG 310 .elseif 1 311 .print 400-a 312 .else 313 .print 400-BUG 314 .endif 315 .check 400-a 316 317 .testcase 410 318 .if 0 319 .print 410-BUG 320 .elseif 0 321 .print 410-BUG 322 .else 323 .print 410-a 324 .endif 325 .check 410-a 326 327 # At most one branch of an .if/.elseif/.else chain is run 328 # 329 .testcase 420 330 .if 1 331 .print 420-a 332 .elseif 1 333 .print 420-BUG 334 .endif 335 .check 420-a 336 337 .testcase 421 338 .if 1 339 .print 421-a 340 .elseif 0 341 .print 421-BUG 342 .else 343 .print 421-BUG 344 .endif 345 .check 421-a 346 347 .testcase 422 348 .if 0 349 .print 422-BUG 350 .elseif 0 351 .print 422-BUG 352 .elseif 1 353 .print 422-a 354 .elseif 1 355 .print 422-BUG 356 .else 357 .print 422-BUG 358 .endif 359 .check 422-a 360 361 .testcase 423 362 .if 0 363 .print 423-BUG 364 .elseif 1 365 .print 423-a 366 .elseif 0 367 .print 423-BUG 368 .else 369 .print 423-BUG 370 .endif 371 .check 423-a 372 373 # The chain state of one .if does not carry over to the next .if at 374 # the same level. 375 # 376 .testcase 424 377 .if 1 378 .endif 379 .if 0 380 .print 424-BUG 381 .elseif 1 382 .print 424-a 383 .endif 384 .if 1 385 .endif 386 .if 0 387 .print 424-BUG 388 .else 389 .print 424-b 390 .endif 391 .check <:2: unterminated .if" 607 .check --keep --nowhere 700-BUG 608 .check --glob "*700-inner*700-after-read*" 609 610 # Also with nested unterminated .ifs. The .else at nesting level 2 611 # must not be remembered after the .read finishes. 612 # 613 .testcase 701 614 .read <