/
e_expr.test.lua
executable file
·3482 lines (3204 loc) · 86.5 KB
/
e_expr.test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env tarantool
local test = require("sqltester")
test:plan(10641)
--!./tcltestrunner.lua
-- 2010 July 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.
--
-------------------------------------------------------------------------
--
-- This file implements tests to verify that the "testable statements" in
-- the lang_expr.html document are correct.
--
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]
-- ["source",[["testdir"],"\/malloc_common.tcl"]]
local function do_expr_test(tn, expr, type, value)
test:do_execsql_test(
""..tn,
"SELECT typeof("..expr.."), "..expr,
{type, value })
end
local function do_qexpr_test(tn, expr, value)
test:do_execsql_test(
""..tn,
"SELECT quote("..expr..")",
{value })
end
local function matchfunc(a, b)
return (a == b)
end
local function regexfunc(a, b)
return (a == b)
end
box.internal.sql_create_function("MATCH", "INT", matchfunc)
box.internal.sql_create_function("REGEXP", "INT", regexfunc)
-- Set up three global variables:
--
-- ::opname An array mapping from SQL operator to an easy to parse
-- name. The names are used as part of test case names.
--
-- ::opprec An array mapping from SQL operator to a numeric
-- precedence value. Operators that group more tightly
-- have lower numeric precedences.
--
-- ::oplist A list of all SQL operators supported by sql.
--
local operations = {
{"||", "cat"},
{"*", "mul"},
{"/", "div"},
{"%", "mod"},
{"+", "add"},
{"-", "sub"},
{"<<", "lshift"},
{">>", "rshift"},
{"&", "bitand"},
{"|", "bitor"},
{"<", "less"},
{"<=", "lesseq"},
{">", "more"},
{">=", "moreeq"},
{"=", "eq1"},
{"==", "eq2"},
{"<>", "ne1"},
{"!=", "ne2"},
{"IS", "is"},
{"AND", "and"},
{"OR", "or"},
{"MATCH", "match"},
{"REGEXP", "regexp"},
{"IS NOT", "isnt"}
}
local opname = {}
for _, op in ipairs(operations) do
opname[op[1]] = op[2]
end
operations = {
{"||"},
{"*", "/", "%"},
{"+", "-"},
{"<<", ">>", "&", "|"},
{"<", "<=", ">", ">="},
-- NOTE: MATCH & REGEXP aren't supported in Tarantool &
-- are waiting for their hour.
{"=", "==", "!=", "<>"}, --"MATCH", "REGEXP"},
{"AND"},
{"OR"},
}
local oplist = { }
local opprec = { }
for prec, opl in ipairs(operations) do
for _, op in ipairs(opl) do
opprec[op] = prec
table.insert(oplist,op)
end
end
-- Hook in definitions of MATCH and REGEX. The following implementations
-- cause MATCH and REGEX to behave similarly to the == operator.
--
---------------------------------------------------------------------------
-- Test cases e_expr-1.* attempt to verify that all binary operators listed
-- in the documentation exist and that the relative precedences of the
-- operators are also as the documentation suggests.
--
-- EVIDENCE-OF: R-15514-65163 sql understands the following binary
-- operators, in order from highest to lowest precedence: || * / % + -
-- << >> & | < <= > >= = == != <> IS IS
-- NOT IN LIKE MATCH REGEXP AND OR
--
-- EVIDENCE-OF: R-38759-38789 Operators IS and IS NOT have the same
-- precedence as =.
--
local test_cases1 = {
{1, 22, 45, 66},
{2, 0, 0, 0},
{3, 0, 0, 1},
{4, 0, 1, 0},
{5, 0, 1, 1},
{6, 1, 0, 0},
{7, 1, 0, 1},
{8, 1, 1, 0},
{9, 1, 1, 1},
{10, 5, 6, 1},
{11, 1, 5, 6},
{12, 1, 5, 5},
{13, 5, 5, 1},
{14, 5, 2, 1},
{15, 1, 4, 1},
{16, -1, 0, 1},
{17, 0, 1, -1},
}
local untested = {}
for _, op1 in ipairs(oplist) do
for _, op2 in ipairs(oplist) do
untested[op1..","..op2] = 1
for tn, val in ipairs(test_cases1) do
local A = val[2]
local B = val[3]
local C = val[4]
local testname = string.format("e_expr-1.%s.%s.%s", opname[op1], opname[op2], tn)
-- If ?op2 groups more tightly than ?op1, then the result
-- of executing ?sql1 whould be the same as executing ?sql.
-- If ?op1 groups more tightly, or if ?op1 and ?op2 have
-- the same precedence, then executing ?sql1 should return
-- the same value as ?sql2.
--
local sql1 = string.format("SELECT %s %s %s %s %s", A, op1, B, op2, C)
local sql2 = string.format("SELECT (%s %s %s) %s %s", A, op1, B, op2, C)
local sql = string.format("SELECT %s %s (%s %s %s)", A, op1, B, op2, C)
-- Some cases may fail due to wrong type conversions.
-- For instance: SELECT 1 + (1 || -1)
-- After concatenation we'he got: 1 + '1-1'.
-- Since '1-1' can't be converted to number, this
-- expression results in error.
--
local is_ok1, a2 = pcall(test.execsql, test, sql2)
local is_ok2, a3 = pcall(test.execsql, test, sql)
if is_ok1 and is_ok2 then
test:do_execsql_test(
testname,
sql1, (opprec[op2] < opprec[op1]) and a3 or a2)
end
if (a2 ~= a3) then
untested[op1..","..op2] = nil
end
end
end
end
for _, op in ipairs({"op","*", "AND", "OR", "+", "||", "&", "|"}) do
untested[op..","..op] = nil
end
---- ["unset","untested(+,-)"]
---- Since (a+b)-c == a+(b-c)
---- ["unset","untested(*,<<)"]
---- Since (a*b)<<c == a*(b<<c)
test:do_test(
"e_expr-1.1",
function()
return untested
end, {
-- <e_expr-1.1>
-- </e_expr-1.1>
})
-- At one point, test 1.2.2 was failing. Instead of the correct result, it
-- was returning {1 1 0}. This would seem to indicate that LIKE has the
-- same precedence as '<'. Which is incorrect. It has lower precedence.
--
test:do_execsql_test(
"e_expr-1.2.1",
[[
SELECT 0 < 2 LIKE 1, (0 < 2) LIKE 1, 0 < (2 LIKE 1)
]], {
-- <e_expr-1.2.1>
1, 1, 0
-- </e_expr-1.2.1>
})
test:do_execsql_test(
"e_expr-1.2.2",
[[
SELECT 0 LIKE 0 < 2, (0 LIKE 0) < 2, 0 LIKE (0 < 2)
]], {
-- <e_expr-1.2.2>
0, 1, 0
-- </e_expr-1.2.2>
})
-- Showing that LIKE and == have the same precedence
--
test:do_execsql_test(
"e_expr-1.2.3",
[[
SELECT 2 LIKE 2 == 1, (2 LIKE 2) == 1, 2 LIKE (2 == 1)
]], {
-- <e_expr-1.2.3>
1, 1, 0
-- </e_expr-1.2.3>
})
test:do_execsql_test(
"e_expr-1.2.4",
[[
SELECT 2 == 2 LIKE 1, (2 == 2) LIKE 1, 2 == (2 LIKE 1)
]], {
-- <e_expr-1.2.4>
1, 1, 0
-- </e_expr-1.2.4>
})
-- Showing that < groups more tightly than == (< has higher precedence).
--
test:do_execsql_test(
"e_expr-1.2.5",
[[
SELECT 0 < 2 == 1, (0 < 2) == 1, 0 < (2 == 1)
]], {
-- <e_expr-1.2.5>
1, 1, 0
-- </e_expr-1.2.5>
})
test:do_execsql_test(
"e_expr-1.6",
[[
SELECT 0 == 0 < 2, (0 == 0) < 2, 0 == (0 < 2)
]], {
-- <e_expr-1.6>
0, 1, 0
-- </e_expr-1.6>
})
---------------------------------------------------------------------------
-- Check that the four unary prefix operators mentioned in the
-- documentation exist.
--
-- EVIDENCE-OF: R-13958-53419 Supported unary prefix operators are these:
-- - + ~ NOT
--
test:do_execsql_test(
"e_expr-2.1",
[[
SELECT - 10
]], {
-- <e_expr-2.1>
-10
-- </e_expr-2.1>
})
test:do_execsql_test(
"e_expr-2.2",
[[
SELECT + 10
]], {
-- <e_expr-2.2>
10
-- </e_expr-2.2>
})
test:do_execsql_test(
"e_expr-2.3",
[[
SELECT ~ 10
]], {
-- <e_expr-2.3>
-11
-- </e_expr-2.3>
})
test:do_execsql_test(
"e_expr-2.4",
[[
SELECT NOT 10
]], {
-- <e_expr-2.4>
0
-- </e_expr-2.4>
})
---------------------------------------------------------------------------
-- Tests for the two statements made regarding the unary + operator.
--
-- EVIDENCE-OF: R-53670-03373 The unary operator + is a no-op.
--
-- EVIDENCE-OF: R-19480-30968 It can be applied to strings, numbers,
-- blobs or NULL and it always returns a result with the same value as
-- the operand.
--
local literals = {
{1, "'helloworld'", "text"},
{2, 45, "integer"},
{3, "45.2", "real"},
{4, "45.0", "real"},
{5, "X'ABCDEF'", "blob"},
{6, "NULL", "null"},
}
for _, val in ipairs(literals) do
local tn = val[1]
local literal = val[2]
local type = val[3]
local sql = string.format(" SELECT quote( + %s ), typeof( + %s) ", literal, literal)
test:do_execsql_test(
"e_expr-3."..tn,
sql, {
literal, type
})
end
---------------------------------------------------------------------------
-- Check that both = and == are both acceptable as the "equals" operator.
-- Similarly, either != or <> work as the not-equals operator.
--
-- EVIDENCE-OF: R-03679-60639 Equals can be either = or ==.
--
-- EVIDENCE-OF: R-30082-38996 The non-equals operator can be either != or
-- <>.
--
literals = {
{1, "'helloworld'", '12345'},
{2, 22, 23},
{3, "'xyz'", "X'78797A'"},
{4, "X'78797A00'", "'xyz'"}
}
for _, val in ipairs(literals) do
local tn = val[1]
local literal = val[2]
local different = val[3]
test:do_execsql_test(
"e_expr-4."..tn,
string.format([[
SELECT %s = %s, %s == %s,
%s = %s, %s == %s,
%s = NULL, %s == NULL,
%s != %s, %s <> %s,
%s != %s, %s <> %s,
%s != NULL, %s != NULL
]], literal, literal, literal, literal, literal, different, literal, different, literal, literal, literal, literal, literal, literal, literal, different, literal, different, literal, literal), {
1, 1, 0, 0, "", "", 0, 0, 1, 1, "", ""
})
end
---------------------------------------------------------------------------
-- Test the || operator.
--
-- EVIDENCE-OF: R-44409-62641 The || operator is "concatenate" - it joins
-- together the two strings of its operands.
--
local test_cases5 = {
{1, "'helloworld'", "'12345'"},
{2, 22, 23}
}
for _, val in ipairs(test_cases5) do
local tn = val[1]
local a = val[2]
local b = val[3]
local as = test:execsql("SELECT "..a.."")[1]
local bs = test:execsql("SELECT "..b.."")[1]
test:do_execsql_test(
"e_expr-5."..tn,
string.format([[
SELECT %s || %s
]], a, b), {
string.format("%s%s", as, bs)
})
end
---------------------------------------------------------------------------
-- Test the % operator.
--
-- EVIDENCE-OF: R-08914-63790 The operator % outputs the value of its
-- left operand modulo its right operand.
--
test:do_execsql_test(
"e_expr-6.1",
[[
SELECT 72%5
]], {
-- <e_expr-6.1>
2
-- </e_expr-6.1>
})
test:do_execsql_test(
"e_expr-6.2",
[[
SELECT 72%-5
]], {
-- <e_expr-6.2>
2
-- </e_expr-6.2>
})
test:do_execsql_test(
"e_expr-6.3",
[[
SELECT -72%-5
]], {
-- <e_expr-6.3>
-2
-- </e_expr-6.3>
})
test:do_execsql_test(
"e_expr-6.4",
[[
SELECT -72%5
]], {
-- <e_expr-6.4>
-2
-- </e_expr-6.4>
})
---------------------------------------------------------------------------
-- Test that the results of all binary operators are either numeric or
-- NULL, except for the || operator, which may evaluate to either a text
-- value or NULL.
--
-- EVIDENCE-OF: R-20665-17792 The result of any binary operator is either
-- a numeric value or NULL, except for the || concatenation operator
-- which always evaluates to either NULL or a text value.
--
literals = {
"'abc'", "'hexadecimal'", "''", 123, -123, 0,
123.4, 0.0, -123.4, "X'ABCDEF'", "X''",
"X'0000'", "NULL"}
for _, op in ipairs(oplist) do
for n1, rhs in ipairs(literals) do
for n2, lhs in ipairs(literals) do
local is_ok, t = pcall(test.execsql, test,
string.format(" SELECT typeof(%s %s %s) ",
lhs, op, rhs))
if is_ok then
t = t[1]
test:do_test(
string.format("e_expr-7.%s.%s.%s", opname[op], n1, n2),
function()
return (((op == "||") and ((t == "text") or
(t == "null"))) or
((op ~= "||") and (((t == "integer") or
(t == "real")) or
(t == "null")))) and 1 or 0
end, 1)
end
end
end
end
---------------------------------------------------------------------------
-- Test the IS and IS NOT operators.
--
-- EVIDENCE-OF: R-24731-45773 The IS and IS NOT operators work like = and
-- != except when one or both of the operands are NULL.
--
-- EVIDENCE-OF: R-06325-15315 In this case, if both operands are NULL,
-- then the IS operator evaluates to 1 (true) and the IS NOT operator
-- evaluates to 0 (false).
--
-- EVIDENCE-OF: R-19812-36779 If one operand is NULL and the other is
-- not, then the IS operator evaluates to 0 (false) and the IS NOT
-- operator is 1 (true).
--
-- EVIDENCE-OF: R-61975-13410 It is not possible for an IS or IS NOT
-- expression to evaluate to NULL.
--
test:do_execsql_test(
"e_expr-8.1.1",
[[
SELECT NULL IS NULL
]], {
-- <e_expr-8.1.1>
1
-- </e_expr-8.1.1>
})
test:do_execsql_test(
"e_expr-8.1.2",
[[
SELECT 'ab' IS NULL
]], {
-- <e_expr-8.1.2>
0
-- </e_expr-8.1.2>
})
test:do_execsql_test(
"e_expr-8.1.3",
[[
SELECT NULL == NULL
]], {
-- <e_expr-8.1.5>
""
-- </e_expr-8.1.5>
})
test:do_execsql_test(
"e_expr-8.1.4",
[[
SELECT 'ab' == NULL
]], {
-- <e_expr-8.1.6>
""
-- </e_expr-8.1.6>
})
test:do_execsql_test(
"e_expr-8.1.5",
[[
SELECT NULL == 'ab'
]], {
-- <e_expr-8.1.7>
""
-- </e_expr-8.1.7>
})
test:do_execsql_test(
"e_expr-8.1.6",
[[
SELECT 'ab' == 'ab'
]], {
-- <e_expr-8.1.8>
1
-- </e_expr-8.1.8>
})
test:do_execsql_test(
"e_expr-8.1.7",
[[
SELECT NULL IS NOT NULL
]], {
-- <e_expr-8.1.9>
0
-- </e_expr-8.1.9>
})
test:do_execsql_test(
"e_expr-8.1.8",
[[
SELECT 'ab' IS NOT NULL
]], {
-- <e_expr-8.1.10>
1
-- </e_expr-8.1.10>
})
test:do_execsql_test(
"e_expr-8.1.9",
[[
SELECT NULL != NULL
]], {
-- <e_expr-8.1.13>
""
-- </e_expr-8.1.13>
})
test:do_execsql_test(
"e_expr-8.1.10",
[[
SELECT 'ab' != NULL
]], {
-- <e_expr-8.1.14>
""
-- </e_expr-8.1.14>
})
test:do_execsql_test(
"e_expr-8.1.11",
[[
SELECT NULL != 'ab'
]], {
-- <e_expr-8.1.15>
""
-- </e_expr-8.1.15>
})
test:do_execsql_test(
"e_expr-8.1.12",
[[
SELECT 'ab' != 'ab'
]], {
-- <e_expr-8.1.16>
0
-- </e_expr-8.1.16>
})
---------------------------------------------------------------------------
-- Run some tests on the COLLATE "unary postfix operator".
--
-- This collation sequence reverses both arguments before using
-- [string compare] to compare them. For example, when comparing the
-- strings 'one' and 'four', return the result of:
--
-- string compare eno ruof
--
local function reverse_str(zStr)
local out = ""
for i = 1, #zStr, 1 do
out = string.format("%s%s", string.sub(zStr, i, i), out)
end
return out
end
local function reverse_collate(zLeft, zRight)
return reverse_str(zLeft) > reverse_str(zRight)
end
box.internal.sql_create_function("REVERSE", "INT", reverse_collate)
--db("collate", "reverse", "reverse_collate")
-- EVIDENCE-OF: R-59577-33471 The COLLATE operator is a unary postfix
-- operator that assigns a collating sequence to an expression.
--
-- EVIDENCE-OF: R-36231-30731 The COLLATE operator has a higher
-- precedence (binds more tightly) than any binary operator and any unary
-- prefix operator except "~".
--
-- MUST_WORK_TEST waiting for collations?
if (0>0) then
test:do_execsql_test(
"e_expr-9.1",
[[
SELECT 'abcd' < 'bbbb' COLLATE reverse
]], {
-- <e_expr-9.1>
0
-- </e_expr-9.1>
})
test:do_execsql_test(
"e_expr-9.2",
[[
SELECT ('abcd' < 'bbbb') COLLATE reverse
]], {
-- <e_expr-9.2>
1
-- </e_expr-9.2>
})
test:do_execsql_test(
"e_expr-9.3",
[[
SELECT 'abcd' <= 'bbbb' COLLATE reverse
]], {
-- <e_expr-9.3>
0
-- </e_expr-9.3>
})
test:do_execsql_test(
"e_expr-9.4",
[[
SELECT ('abcd' <= 'bbbb') COLLATE reverse
]], {
-- <e_expr-9.4>
1
-- </e_expr-9.4>
})
test:do_execsql_test(
"e_expr-9.5",
[[
SELECT 'abcd' > 'bbbb' COLLATE reverse
]], {
-- <e_expr-9.5>
1
-- </e_expr-9.5>
})
test:do_execsql_test(
"e_expr-9.6",
[[
SELECT ('abcd' > 'bbbb') COLLATE reverse
]], {
-- <e_expr-9.6>
0
-- </e_expr-9.6>
})
test:do_execsql_test(
"e_expr-9.7",
[[
SELECT 'abcd' >= 'bbbb' COLLATE reverse
]], {
-- <e_expr-9.7>
1
-- </e_expr-9.7>
})
test:do_execsql_test(
"e_expr-9.8",
[[
SELECT ('abcd' >= 'bbbb') COLLATE reverse
]], {
-- <e_expr-9.8>
0
-- </e_expr-9.8>
})
end
test:do_execsql_test(
"e_expr-9.10",
[[
SELECT 'abcd' = 'ABCD' COLLATE "unicode_ci"
]], {
-- <e_expr-9.10>
1
-- </e_expr-9.10>
})
test:do_execsql_test(
"e_expr-9.11",
[[
SELECT ('abcd' = 'ABCD') COLLATE "unicode_ci"
]], {
-- <e_expr-9.11>
0
-- </e_expr-9.11>
})
test:do_execsql_test(
"e_expr-9.12",
[[
SELECT 'abcd' == 'ABCD' COLLATE "unicode_ci"
]], {
-- <e_expr-9.12>
1
-- </e_expr-9.12>
})
test:do_execsql_test(
"e_expr-9.13",
[[
SELECT ('abcd' == 'ABCD') COLLATE "unicode_ci"
]], {
-- <e_expr-9.13>
0
-- </e_expr-9.13>
})
test:do_execsql_test(
"e_expr-9.14",
[[
SELECT 'abcd' != 'ABCD' COLLATE "unicode_ci"
]], {
-- <e_expr-9.16>
0
-- </e_expr-9.16>
})
test:do_execsql_test(
"e_expr-9.15",
[[
SELECT ('abcd' != 'ABCD') COLLATE "unicode_ci"
]], {
-- <e_expr-9.17>
1
-- </e_expr-9.17>
})
test:do_execsql_test(
"e_expr-9.16",
[[
SELECT 'abcd' <> 'ABCD' COLLATE "unicode_ci"
]], {
-- <e_expr-9.18>
0
-- </e_expr-9.18>
})
test:do_execsql_test(
"e_expr-9.17",
[[
SELECT ('abcd' <> 'ABCD') COLLATE "unicode_ci"
]], {
-- <e_expr-9.19>
1
-- </e_expr-9.19>
})
test:do_execsql_test(
"e_expr-9.19",
[[
SELECT 'bbb' BETWEEN 'AAA' AND 'CCC' COLLATE "unicode_ci"
]], {
-- <e_expr-9.22>
1
-- </e_expr-9.22>
})
test:do_execsql_test(
"e_expr-9.20",
[[
SELECT ('bbb' BETWEEN 'AAA' AND 'CCC') COLLATE "unicode_ci"
]], {
-- <e_expr-9.23>
0
-- </e_expr-9.23>
})
-- # EVIDENCE-OF: R-58731-25439 The collating sequence set by the COLLATE
-- # operator overrides the collating sequence determined by the COLLATE
-- # clause in a table column definition.
-- #
-- do_execsql_test e_expr-9.24 {
-- CREATE TABLE t24(a TEXT COLLATE NOCASE, b INT);
-- INSERT INTO t24 VALUES('aaa', 1);
-- INSERT INTO t24 VALUES('bbb', 2);
-- INSERT INTO t24 VALUES('ccc', 3);
-- } {}
-- do_execsql_test e_expr-9.25 { SELECT 'BBB' = a FROM t24 } {0 1 0}
-- do_execsql_test e_expr-9.25 { SELECT a = 'BBB' FROM t24 } {0 1 0}
-- do_execsql_test e_expr-9.25 { SELECT 'BBB' = a COLLATE binary FROM t24 } {0 0 0}
-- do_execsql_test e_expr-9.25 { SELECT a COLLATE binary = 'BBB' FROM t24 } {0 0 0}
---------------------------------------------------------------------------
-- Test statements related to literal values.
--
-- EVIDENCE-OF: R-31536-32008 Literal values may be integers, floating
-- point numbers, strings, BLOBs, or NULLs.
--
test:do_execsql_test(
"e_expr-10.1.1",
[[
SELECT typeof(5)
]], {
-- <e_expr-10.1.1>
"integer"
-- </e_expr-10.1.1>
})
test:do_execsql_test(
"e_expr-10.1.2",
[[
SELECT typeof(5.1)
]], {
-- <e_expr-10.1.2>
"real"
-- </e_expr-10.1.2>
})
test:do_execsql_test(
"e_expr-10.1.3",
[[
SELECT typeof('5.1')
]], {
-- <e_expr-10.1.3>
"text"
-- </e_expr-10.1.3>
})
test:do_execsql_test(
"e_expr-10.1.4",
[[
SELECT typeof(X'ABCD')
]], {
-- <e_expr-10.1.4>
"blob"
-- </e_expr-10.1.4>
})
test:do_execsql_test(
"e_expr-10.1.5",
[[
SELECT typeof(NULL)
]], {
-- <e_expr-10.1.5>
"null"
-- </e_expr-10.1.5>
})
-- "Scientific notation is supported for point literal values."
--
test:do_execsql_test(
"e_expr-10.2.1",
[[
SELECT typeof(3.4e-02)
]], {
-- <e_expr-10.2.1>
"real"
-- </e_expr-10.2.1>
})
test:do_execsql_test(
"e_expr-10.2.2",
[[
SELECT typeof(3e+5)
]], {
-- <e_expr-10.2.2>
"real"
-- </e_expr-10.2.2>
})
test:do_execsql_test(
"e_expr-10.2.3",
[[
SELECT 3.4e-02
]], {
-- <e_expr-10.2.3>
0.034
-- </e_expr-10.2.3>
})
test:do_execsql_test(
"e_expr-10.2.4",
[[
SELECT 3e+4
]], {
-- <e_expr-10.2.4>
30000.0
-- </e_expr-10.2.4>
})
-- EVIDENCE-OF: R-35229-17830 A string constant is formed by enclosing
-- the string in single quotes (').
--
-- EVIDENCE-OF: R-07100-06606 A single quote within the string can be
-- encoded by putting two single quotes in a row - as in Pascal.
--
test:do_execsql_test(
"e_expr-10.3.1",
[[
SELECT 'is not'
]], {
-- <e_expr-10.3.1>
"is not"
-- </e_expr-10.3.1>
})
test:do_execsql_test(
"e_expr-10.3.2",
[[
SELECT typeof('is not')
]], {
-- <e_expr-10.3.2>
"text"
-- </e_expr-10.3.2>
})
test:do_execsql_test(
"e_expr-10.3.3",
[[
SELECT 'isn''t'
]], {
-- <e_expr-10.3.3>
"isn't"
-- </e_expr-10.3.3>
})
test:do_execsql_test(
"e_expr-10.3.4",
[[
SELECT typeof('isn''t')
]], {
-- <e_expr-10.3.4>
"text"
-- </e_expr-10.3.4>
})
-- EVIDENCE-OF: R-09593-03321 BLOB literals are string literals
-- containing hexadecimal data and preceded by a single "x" or "X"
-- character.
--
-- EVIDENCE-OF: R-19836-11244 Example: X'53514C697465'