296
298
SELECT random() is not null;
303
SELECT typeof(random());
308
SELECT randomblob(32) is not null;
313
SELECT typeof(randomblob(32));
318
SELECT length(randomblob(32)), length(randomblob(-5)),
319
length(randomblob(2000))
323
# The "hex()" function was added in order to be able to render blobs
324
# generated by randomblob(). So this seems like a good place to test
329
execsql {SELECT hex(x'00112233445566778899aAbBcCdDeEfF')}
330
} {00112233445566778899AABBCCDDEEFF}
332
set encoding [db one {PRAGMA encoding}]
333
if {$encoding=="UTF-16le"} {
334
do_test func-9.11-utf16le {
335
execsql {SELECT hex(replace('abcdefg','ef','12'))}
336
} {6100620063006400310032006700}
337
do_test func-9.12-utf16le {
338
execsql {SELECT hex(replace('abcdefg','','12'))}
340
do_test func-9.13-utf16le {
341
execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
342
} {610061006100610061006100620063006400650066006700}
343
} elseif {$encoding=="UTF-8"} {
344
do_test func-9.11-utf8 {
345
execsql {SELECT hex(replace('abcdefg','ef','12'))}
347
do_test func-9.12-utf8 {
348
execsql {SELECT hex(replace('abcdefg','','12'))}
350
do_test func-9.13-utf8 {
351
execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
352
} {616161616161626364656667}
300
355
# Use the "sqlite_register_test_function" TCL command which is part of
301
356
# the text fixture in order to verify correct operation of some of
302
357
# the user-defined SQL function APIs that are not used by the built-in
773
# Tests of the REPLACE function.
779
} {1 {wrong number of arguments to function replace()}}
782
SELECT replace(1,2,3,4);
784
} {1 {wrong number of arguments to function replace()}}
787
SELECT typeof(replace("This is the main test string", NULL, "ALT"));
792
SELECT typeof(replace(NULL, "main", "ALT"));
797
SELECT typeof(replace("This is the main test string", "main", NULL));
802
SELECT replace("This is the main test string", "main", "ALT");
804
} {{This is the ALT test string}}
807
SELECT replace("This is the main test string", "main", "larger-main");
809
} {{This is the larger-main test string}}
812
SELECT replace("aaaaaaa", "a", "0123456789");
814
} {0123456789012345678901234567890123456789012345678901234567890123456789}
818
# Attempt to exploit a buffer-overflow that at one time existed
819
# in the REPLACE function.
820
set ::str "[string repeat A 29998]CC[string repeat A 35537]"
821
set ::rep [string repeat B 65536]
823
SELECT LENGTH(REPLACE($::str, 'C', $::rep));
825
} [expr 29998 + 2*65536 + 35537]
828
# Tests for the TRIM, LTRIM and RTRIM functions.
831
catchsql {SELECT trim(1,2,3)}
832
} {1 {wrong number of arguments to function trim()}}
834
catchsql {SELECT ltrim(1,2,3)}
835
} {1 {wrong number of arguments to function ltrim()}}
837
catchsql {SELECT rtrim(1,2,3)}
838
} {1 {wrong number of arguments to function rtrim()}}
840
execsql {SELECT trim(' hi ');}
843
execsql {SELECT ltrim(' hi ');}
846
execsql {SELECT rtrim(' hi ');}
849
execsql {SELECT trim(' hi ','xyz');}
852
execsql {SELECT ltrim(' hi ','xyz');}
855
execsql {SELECT rtrim(' hi ','xyz');}
858
execsql {SELECT trim('xyxzy hi zzzy','xyz');}
861
execsql {SELECT ltrim('xyxzy hi zzzy','xyz');}
864
execsql {SELECT rtrim('xyxzy hi zzzy','xyz');}
867
execsql {SELECT trim(' hi ','');}
869
if {[db one {PRAGMA encoding}]=="UTF-8"} {
871
execsql {SELECT hex(trim(x'c280e1bfbff48fbfbf6869',x'6162e1bfbfc280'))}
874
execsql {SELECT hex(trim(x'6869c280e1bfbff48fbfbf61',
875
x'6162e1bfbfc280f48fbfbf'))}
878
execsql {SELECT hex(trim(x'ceb1ceb2ceb3',x'ceb1'));}
882
execsql {SELECT typeof(trim(NULL));}
885
execsql {SELECT typeof(trim(NULL,'xyz'));}
888
execsql {SELECT typeof(trim('hello',NULL));}
891
# This is to test the deprecated sqlite3_aggregate_count() API.
894
sqlite3_create_aggregate db
896
SELECT legacy_count() FROM t6;
900
# The group_concat() function.
904
SELECT group_concat(t1) FROM tbl1
906
} {this,program,is,free,software}
909
SELECT group_concat(t1,' ') FROM tbl1
911
} {{this program is free software}}
914
SELECT group_concat(t1,' ' || rowid || ' ') FROM tbl1
916
} {{this 2 program 3 is 4 free 5 software}}
919
SELECT group_concat(NULL,t1) FROM tbl1
924
SELECT group_concat(t1,NULL) FROM tbl1
926
} {thisprogramisfreesoftware}
929
SELECT 'BEGIN-'||group_concat(t1) FROM tbl1
931
} {BEGIN-this,program,is,free,software}
933
# Use the test_isolation function to make sure that type conversions
934
# on function arguments do not effect subsequent arguments.
937
execsql {SELECT test_isolation(t1,t1) FROM tbl1}
938
} {this program is free software}