summaryrefslogtreecommitdiff
path: root/mysql-test/main/func_sformat.result
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-09-04 23:11:54 +0200
committerSergei Golubchik <serg@mariadb.org>2021-10-12 13:28:10 +0200
commita363ccd6811458e0b8d0be113b08efc11b9b67cd (patch)
treea4e5a9c798f7eb0cd6cd2bddfd8dbf7ba8c2eb37 /mysql-test/main/func_sformat.result
parente214e60201216b2e6330f86a84fec8ae14aa2887 (diff)
downloadmariadb-git-a363ccd6811458e0b8d0be113b08efc11b9b67cd.tar.gz
misc cleanups
* comment - use the standard style * no need to reimplement for with while * TODO comments for not implemented types * rename the error not to refer to the underlying library, it's the implementation detail * use res->length(0) to set length to 0, but preserve the already allocated buffer * rename main.sformat -> main.func_sformat * removed a duplicated part of the test
Diffstat (limited to 'mysql-test/main/func_sformat.result')
-rw-r--r--mysql-test/main/func_sformat.result411
1 files changed, 411 insertions, 0 deletions
diff --git a/mysql-test/main/func_sformat.result b/mysql-test/main/func_sformat.result
new file mode 100644
index 00000000000..913a021f1b5
--- /dev/null
+++ b/mysql-test/main/func_sformat.result
@@ -0,0 +1,411 @@
+#
+# MDEV-25015 Custom formatting of strings in MariaDB queries
+#
+#
+# Normal Test Cases
+#
+select sformat('string test');
+sformat('string test')
+string test
+select sformat(0);
+sformat(0)
+0
+select sformat('C');
+sformat('C')
+C
+select sformat(-4.2);
+sformat(-4.2)
+-4.2
+select sformat(5, 5, 5);
+sformat(5, 5, 5)
+5
+select sformat('{} {}', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+sformat('{} {}', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+0 0
+select sformat('{{{}}}', 0);
+sformat('{{{}}}', 0)
+{0}
+select sformat('{{{}{{', 0);
+sformat('{{{}{{', 0)
+{0{
+select sformat('{{{{{}{{', 'param1');
+sformat('{{{{{}{{', 'param1')
+{{param1{
+select sformat(' {{ {{ {} {{ ', 'param1');
+sformat(' {{ {{ {} {{ ', 'param1')
+ { { param1 {
+select sformat(' {{ {} {}', 'param1', 'param2');
+sformat(' {{ {} {}', 'param1', 'param2')
+ { param1 param2
+select sformat('A{}C{}E{}', 'B', 'D', 'F');
+sformat('A{}C{}E{}', 'B', 'D', 'F')
+ABCDEF
+select sformat('{} {}', FALSE, TRUE);
+sformat('{} {}', FALSE, TRUE)
+0 1
+select sformat('Add € != {} != {}?', '$', '£');
+sformat('Add € != {} != {}?', '$', '£')
+Add € != $ != £?
+select sformat('Check {} != {} != {}?', '€', '$', '£');
+sformat('Check {} != {} != {}?', '€', '$', '£')
+Check € != $ != £?
+select sformat('{}{}{}', 1, 2, 3);
+sformat('{}{}{}', 1, 2, 3)
+123
+select sformat('Float {} Boolean {} Number {}', 3.14159, True, -50);
+sformat('Float {} Boolean {} Number {}', 3.14159, True, -50)
+Float 3.14159 Boolean 1 Number -50
+select sformat('SUM {} + {} = {}', 2, 3, 2+3);
+sformat('SUM {} + {} = {}', 2, 3, 2+3)
+SUM 2 + 3 = 5
+select sformat('Numbers {} {} {}', 1, 1.11, 1.111);
+sformat('Numbers {} {} {}', 1, 1.11, 1.111)
+Numbers 1 1.11 1.111
+select sformat('what {} is {}?', 'time', 'it');
+sformat('what {} is {}?', 'time', 'it')
+what time is it?
+select sformat('{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}', 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);
+sformat('{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+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
+select sformat('{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}', '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');
+sformat('{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+ {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
+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
+#
+# Error Test Cases
+#
+select sformat('R={ }', 42);
+sformat('R={ }', 42)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid format string
+select sformat(NULL, 'Null', 'Test');
+sformat(NULL, 'Null', 'Test')
+NULL
+select sformat('Null Test {} {} ', 0, NULL);
+sformat('Null Test {} {} ', 0, NULL)
+NULL
+select sformat(NULL);
+sformat(NULL)
+NULL
+select sformat('My { Test');
+sformat('My { Test')
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid format string
+select sformat('Test { {');
+sformat('Test { {')
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid format string
+select sformat('A{}C{}E{}', 'B', 'D');
+sformat('A{}C{}E{}', 'B', 'D')
+NULL
+Warnings:
+Warning 4183 SFORMAT error: argument not found
+select sformat();
+ERROR 42000: Incorrect parameter count in the call to native function 'sformat'
+#
+# Table Test Cases
+#
+create table t1 (param1 text, param2 text, param3 int);
+insert into t1 values ('string: {}, number: {}', 'xyz', 123),
+('something {} went {} wrong {}', 'foo', 0),
+('Test case {} -> {}', 'Print', -32);
+select sformat(param1, param2, param3) from t1;
+sformat(param1, param2, param3)
+string: xyz, number: 123
+NULL
+Test case Print -> -32
+Warnings:
+Warning 4183 SFORMAT error: argument not found
+drop table t1;
+create table t2 (param1 FLOAT, param2 SMALLINT, param3 CHAR, param4 DATE);
+insert into t2 values (0.0025, 25, 'A', DATE('2020-06-29')),
+(0.0005, 5, 'B', DATE('2020-6-29')),
+(5.5555, -5, 'C', DATE('200629')),
+(-9, -9, 'D', DATE('20*06*29'));
+select sformat('p1 {:.4f} p2 {} p3 {} p4 {}', param1, param2, param3, param4) from t2;
+sformat('p1 {:.4f} p2 {} p3 {} p4 {}', param1, param2, param3, param4)
+p1 0.0025 p2 25 p3 A p4 2020-06-29
+p1 0.0005 p2 5 p3 B p4 2020-06-29
+p1 5.5555 p2 -5 p3 C p4 2020-06-29
+p1 -9.0000 p2 -9 p3 D p4 2020-06-29
+drop table t2;
+set names utf8;
+create table t3 (format_str text character set 'latin1',
+first_param text character set 'utf8',
+second_param text character set 'latin1');
+insert into t3 values ('test 1 {} {}', UNHEX('C3A5'), UNHEX('E5'));
+select sformat(format_str, first_param, second_param) from t3;
+sformat(format_str, first_param, second_param)
+test 1 å å
+select HEX(sformat(format_str, first_param, second_param)) from t3;
+HEX(sformat(format_str, first_param, second_param))
+74657374203120C3A520C3A5
+drop table t3;
+set names latin1;
+create table t4 (p1 bit(8), p2 boolean, p3 DECIMAL, p4 TIMESTAMP);
+insert into t4 values (42, TRUE, 42, '2021-08-18 16:50:07'),
+(24, FALSE, 24, '0000-00-00 00:00:00');
+select sformat('{}: {} {} {} {}', 'Data', p1, p2, p3, p4) from t4;
+sformat('{}: {} {} {} {}', 'Data', p1, p2, p3, p4)
+Data: 42 1 42 2021-08-18 16:50:07
+Data: 24 0 24 0000-00-00 00:00:00
+drop table t4;
+set names utf8;
+create table t5 (param text character SET utf8 COLLATE utf8_general_ci);
+insert into t5 values (UNHEX('C3A5')),(UNHEX('C5BB')),(UNHEX('e0b1bb')),
+(UNHEX('C38A')), (NULL);
+select sformat('{}', param) from t5;
+sformat('{}', param)
+౻
+NULL
+select HEX(sformat('{}', param)) from t5;
+HEX(sformat('{}', param))
+C3A5
+C5BB
+E0B1BB
+C38A
+NULL
+drop table t5;
+set names latin1;
+#
+# Format Test Cases
+#
+select sformat('Num {:L}', 13800000000);
+sformat('Num {:L}', 13800000000)
+Num 13800000000
+select sformat('Num [{:20}]', 42);
+sformat('Num [{:20}]', 42)
+Num [ 42]
+select sformat('Number: {:*^{}}', 4, 5);
+sformat('Number: {:*^{}}', 4, 5)
+Number: **4**
+select sformat('{:02} - {:02} - {:02}', 1, 2, 3);
+sformat('{:02} - {:02} - {:02}', 1, 2, 3)
+01 - 02 - 03
+select sformat('Character {:c}', 'h');
+sformat('Character {:c}', 'h')
+Character h
+select sformat('String {:s}', 'hello');
+sformat('String {:s}', 'hello')
+String hello
+select sformat('Large {0:+010.4g}', 392.64);
+sformat('Large {0:+010.4g}', 392.64)
+Large +0000392.6
+select sformat('Large {:g}', 392.65);
+sformat('Large {:g}', 392.65)
+Large 392.65
+select sformat('Float {:.2f}', 42.0);
+sformat('Float {:.2f}', 42.0)
+Float 42.00
+select sformat('Float {:f}', 42.0);
+sformat('Float {:f}', 42.0)
+Float 42.000000
+select sformat('Number {:d}', 42);
+sformat('Number {:d}', 42)
+Number 42
+select sformat('Number {:{}}', 5, 5);
+sformat('Number {:{}}', 5, 5)
+Number 5
+select sformat('Number [{:10}]', 9999);
+sformat('Number [{:10}]', 9999)
+Number [ 9999]
+select sformat('Number {:.3}', 3.1416);
+sformat('Number {:.3}', 3.1416)
+Number 3.14
+select sformat('int: {0:d}; hex: {0:x}; oct: {0:o}', 42);
+sformat('int: {0:d}; hex: {0:x}; oct: {0:o}', 42)
+int: 42; hex: 2a; oct: 52
+select sformat('int: {0:d}; hex: {0:#x}; oct: {0:#o}', 42);
+sformat('int: {0:d}; hex: {0:#x}; oct: {0:#o}', 42)
+int: 42; hex: 0x2a; oct: 052
+select sformat('The Hexadecimal version of {0} is {0:X}', 255);
+sformat('The Hexadecimal version of {0} is {0:X}', 255)
+The Hexadecimal version of 255 is FF
+select sformat('The Hexadecimal version of {0} is {0:x}', 255);
+sformat('The Hexadecimal version of {0} is {0:x}', 255)
+The Hexadecimal version of 255 is ff
+select sformat('The octal version of {0} is {0:o}', 10);
+sformat('The octal version of {0} is {0:o}', 10)
+The octal version of 10 is 12
+select sformat('The binary version of {0} is {0:b}', 5);
+sformat('The binary version of {0} is {0:b}', 5)
+The binary version of 5 is 101
+select sformat('{:+f}; {:+f}', 3.14, -3.14);
+sformat('{:+f}; {:+f}', 3.14, -3.14)
++3.140000; -3.140000
+select sformat('{: f}; {: f}', 3.14, -3.14);
+sformat('{: f}; {: f}', 3.14, -3.14)
+ 3.140000; -3.140000
+select sformat('{:-f}; {:-f}', 3.14, -3.14);
+sformat('{:-f}; {:-f}', 3.14, -3.14)
+3.140000; -3.140000
+select sformat('The temperature is between {: } and {: } degrees celsius.', -3, 7);
+sformat('The temperature is between {: } and {: } degrees celsius.', -3, 7)
+The temperature is between -3 and 7 degrees celsius.
+select sformat('The temperature is between {:-} and {:-} degrees celsius.', -3, 7);
+sformat('The temperature is between {:-} and {:-} degrees celsius.', -3, 7)
+The temperature is between -3 and 7 degrees celsius.
+select sformat('The temperature is between {:+} and {:+} degrees celsius.', -3, 7);
+sformat('The temperature is between {:+} and {:+} degrees celsius.', -3, 7)
+The temperature is between -3 and +7 degrees celsius.
+select sformat('We have {:<8} chickens.', 49);
+sformat('We have {:<8} chickens.', 49)
+We have 49 chickens.
+select sformat('Center alimgn [{:*^10}]', 'data');
+sformat('Center alimgn [{:*^10}]', 'data')
+Center alimgn [***data***]
+select sformat('Center aling [{:^10}].', 'data');
+sformat('Center aling [{:^10}].', 'data')
+Center aling [ data ].
+select sformat('Right aling [{:>10}].', 'data');
+sformat('Right aling [{:>10}].', 'data')
+Right aling [ data].
+select sformat('Left align [{:<10}].', 'data');
+sformat('Left align [{:<10}].', 'data')
+Left align [data ].
+select sformat('{0}{1}{0}', 'abra', 'cad');
+sformat('{0}{1}{0}', 'abra', 'cad')
+abracadabra
+select sformat('Change Order {1} {0}', 'second', 'first');
+sformat('Change Order {1} {0}', 'second', 'first')
+Change Order first second
+#
+# Failed Format Test Cases
+#
+select sformat('Test {:c}', 'word');
+sformat('Test {:c}', 'word')
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('Test {one} {two} {three}', 1, 2, 3);
+sformat('Test {one} {two} {three}', 1, 2, 3)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: argument not found
+select sformat('Number {:{<}', 8);
+sformat('Number {:{<}', 8)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid fill character '{'
+select sformat('Number {:10000000000}', 5);
+sformat('Number {:10000000000}', 5)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: number is too big
+select sformat('1={1} 2={2} 0={0}', 0, 1);
+sformat('1={1} 2={2} 0={0}', 0, 1)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: argument not found
+select sformat('Number {:.2d}', 42);
+sformat('Number {:.2d}', 42)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: precision not allowed for this argument type
+select sformat('You scored {:.0%}', 0.25);
+sformat('You scored {:.0%}', 0.25)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('You scored {:%}', 0.25);
+sformat('You scored {:%}', 0.25)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('The price is {:f} dollars.', 45);
+sformat('The price is {:f} dollars.', 45)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('The price is {:.2f} dollars.', 45);
+sformat('The price is {:.2f} dollars.', 45)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: precision not allowed for this argument type
+select sformat('We have {:E} chickens.', 5);
+sformat('We have {:E} chickens.', 5)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('We have {:e} chickens.', 5);
+sformat('We have {:e} chickens.', 5)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('The universe is {:,} years old.', 13800000000);
+sformat('The universe is {:,} years old.', 13800000000)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('The universe is {:_} years old.', 13800000000);
+sformat('The universe is {:_} years old.', 13800000000)
+NULL
+Warnings:
+Warning 4183 SFORMAT error: invalid type specifier
+select sformat('String {:-}', 'hello');
+sformat('String {:-}', 'hello')
+NULL
+Warnings:
+Warning 4183 SFORMAT error: format specifier requires numeric argument
+#
+# Table Format Test Cases
+#
+create table t1 (pformat text, data1 FLOAT, data2 INT,
+data3 VARCHAR(30), data4 CHAR);
+insert into t1 values ('{:.2f} {: } |{:*^15}| {:c}', 1.11, 1, 'example I', 'A'),
+('{:.1f} {:-} |{:^15}| {:c}', -2.22, -2, 'example II', 'B'),
+('{:.2f} {:+} |{:<15}| {:c}', 3.33, 3, 'example III', 'C'),
+('{:.4f} {:d} |{:^15}| {:c}', -4.44, -4, 'example IV', 'D');
+select sformat(pformat, data1, data2, data3, data4) from t1;
+sformat(pformat, data1, data2, data3, data4)
+1.11 1 |***example I***| A
+-2.2 -2 | example II | B
+3.33 +3 |example III | C
+-4.4400 -4 | example IV | D
+drop table t1;
+create table t2 (a double);
+insert into t2 values (3.14159265358979323846);
+select a, sformat('{:.15f}', a) from t2;
+a sformat('{:.15f}', a)
+3.141592653589793 3.141592653589793
+drop table t2;