11#
2+ # MDEV-25015 Custom formatting of strings in MariaDB queries
3+ #
4+ #
25# Normal Test Cases
36#
47select sformat('string test');
@@ -109,7 +112,7 @@ select sformat('R={ }', 42);
109112sformat('R={ }', 42)
110113NULL
111114Warnings:
112- Warning 4183Wrong format exception : invalid format string
115+ Warning 4183SFORMAT error : invalid format string
113116select sformat(NULL, 'Null', 'Test');
114117sformat(NULL, 'Null', 'Test')
115118NULL
@@ -123,17 +126,17 @@ select sformat('My { Test');
123126sformat('My { Test')
124127NULL
125128Warnings:
126- Warning 4183Wrong format exception : invalid format string
129+ Warning 4183SFORMAT error : invalid format string
127130select sformat('Test { {');
128131sformat('Test { {')
129132NULL
130133Warnings:
131- Warning 4183Wrong format exception : invalid format string
134+ Warning 4183SFORMAT error : invalid format string
132135select sformat('A{}C{}E{}', 'B', 'D');
133136sformat('A{}C{}E{}', 'B', 'D')
134137NULL
135138Warnings:
136- Warning 4183Wrong format exception : argument not found
139+ Warning 4183SFORMAT error : argument not found
137140select sformat();
138141ERROR 42000: Incorrect parameter count in the call to native function 'sformat'
139142#
@@ -149,7 +152,7 @@ string: xyz, number: 123
149152NULL
150153Test case Print -> -32
151154Warnings:
152- Warning 4183Wrong format exception : argument not found
155+ Warning 4183SFORMAT error : argument not found
153156drop table t1;
154157create table t2 (param1 FLOAT, param2 SMALLINT, param3 CHAR, param4 DATE);
155158insert into t2 values (0.0025, 25, 'A', DATE('2020-06-29')),
@@ -313,77 +316,77 @@ select sformat('Test {:c}', 'word');
313316sformat('Test {:c}', 'word')
314317NULL
315318Warnings:
316- Warning 4183Wrong format exception : invalid type specifier
319+ Warning 4183SFORMAT error : invalid type specifier
317320select sformat('Test {one} {two} {three}', 1, 2, 3);
318321sformat('Test {one} {two} {three}', 1, 2, 3)
319322NULL
320323Warnings:
321- Warning 4183Wrong format exception : argument not found
324+ Warning 4183SFORMAT error : argument not found
322325select sformat('Number {:{<}', 8);
323326sformat('Number {:{<}', 8)
324327NULL
325328Warnings:
326- Warning 4183Wrong format exception : invalid fill character '{'
329+ Warning 4183SFORMAT error : invalid fill character '{'
327330select sformat('Number {:10000000000}', 5);
328331sformat('Number {:10000000000}', 5)
329332NULL
330333Warnings:
331- Warning 4183Wrong format exception : number is too big
334+ Warning 4183SFORMAT error : number is too big
332335select sformat('1={1} 2={2} 0={0}', 0, 1);
333336sformat('1={1} 2={2} 0={0}', 0, 1)
334337NULL
335338Warnings:
336- Warning 4183Wrong format exception : argument not found
339+ Warning 4183SFORMAT error : argument not found
337340select sformat('Number {:.2d}', 42);
338341sformat('Number {:.2d}', 42)
339342NULL
340343Warnings:
341- Warning 4183Wrong format exception : precision not allowed for this argument type
344+ Warning 4183SFORMAT error : precision not allowed for this argument type
342345select sformat('You scored {:.0%}', 0.25);
343346sformat('You scored {:.0%}', 0.25)
344347NULL
345348Warnings:
346- Warning 4183Wrong format exception : invalid type specifier
349+ Warning 4183SFORMAT error : invalid type specifier
347350select sformat('You scored {:%}', 0.25);
348351sformat('You scored {:%}', 0.25)
349352NULL
350353Warnings:
351- Warning 4183Wrong format exception : invalid type specifier
354+ Warning 4183SFORMAT error : invalid type specifier
352355select sformat('The price is {:f} dollars.', 45);
353356sformat('The price is {:f} dollars.', 45)
354357NULL
355358Warnings:
356- Warning 4183Wrong format exception : invalid type specifier
359+ Warning 4183SFORMAT error : invalid type specifier
357360select sformat('The price is {:.2f} dollars.', 45);
358361sformat('The price is {:.2f} dollars.', 45)
359362NULL
360363Warnings:
361- Warning 4183Wrong format exception : precision not allowed for this argument type
364+ Warning 4183SFORMAT error : precision not allowed for this argument type
362365select sformat('We have {:E} chickens.', 5);
363366sformat('We have {:E} chickens.', 5)
364367NULL
365368Warnings:
366- Warning 4183Wrong format exception : invalid type specifier
369+ Warning 4183SFORMAT error : invalid type specifier
367370select sformat('We have {:e} chickens.', 5);
368371sformat('We have {:e} chickens.', 5)
369372NULL
370373Warnings:
371- Warning 4183Wrong format exception : invalid type specifier
374+ Warning 4183SFORMAT error : invalid type specifier
372375select sformat('The universe is {:,} years old.', 13800000000);
373376sformat('The universe is {:,} years old.', 13800000000)
374377NULL
375378Warnings:
376- Warning 4183Wrong format exception : invalid type specifier
379+ Warning 4183SFORMAT error : invalid type specifier
377380select sformat('The universe is {:_} years old.', 13800000000);
378381sformat('The universe is {:_} years old.', 13800000000)
379382NULL
380383Warnings:
381- Warning 4183Wrong format exception : invalid type specifier
384+ Warning 4183SFORMAT error : invalid type specifier
382385select sformat('String {:-}', 'hello');
383386sformat('String {:-}', 'hello')
384387NULL
385388Warnings:
386- Warning 4183Wrong format exception : format specifier requires numeric argument
389+ Warning 4183SFORMAT error : format specifier requires numeric argument
387390#
388391# Table Format Test Cases
389392#
@@ -406,71 +409,3 @@ select a, sformat('{:.15f}', a) from t2;
406409a sformat('{:.15f}', a)
4074103.141592653589793 3.141592653589793
408411drop table t2;
409- #
410- # Table Test Cases
411- #
412- create table t1 (param1 text, param2 text, param3 int);
413- insert into t1 values ('string: {}, number: {}', 'xyz', 123),
414- ('something {} went {} wrong {}', 'foo', 0),
415- ('Test case {} -> {}', 'Print', -32);
416- select sformat(param1, param2, param3) from t1;
417- sformat(param1, param2, param3)
418- string: xyz, number: 123
419- NULL
420- Test case Print -> -32
421- Warnings:
422- Warning 4183 Wrong format exception: argument not found
423- drop table t1;
424- create table t2 (param1 FLOAT, param2 SMALLINT, param3 CHAR, param4 DATE);
425- insert into t2 values (0.0025, 25, 'A', DATE('2020-06-29')),
426- (0.0005, 5, 'B', DATE('2020-6-29')),
427- (5.5555, -5, 'C', DATE('200629')),
428- (-9, -9, 'D', DATE('20*06*29'));
429- select sformat('p1 {:.4f} p2 {} p3 {} p4 {}', param1, param2, param3, param4) from t2;
430- sformat('p1 {:.4f} p2 {} p3 {} p4 {}', param1, param2, param3, param4)
431- p1 0.0025 p2 25 p3 A p4 2020-06-29
432- p1 0.0005 p2 5 p3 B p4 2020-06-29
433- p1 5.5555 p2 -5 p3 C p4 2020-06-29
434- p1 -9.0000 p2 -9 p3 D p4 2020-06-29
435- drop table t2;
436- set names utf8;
437- create table t3 (format_str text character set 'latin1',
438- first_param text character set 'utf8',
439- second_param text character set 'latin1');
440- insert into t3 values ('test 1 {} {}', UNHEX('C3A5'), UNHEX('E5'));
441- select sformat(format_str, first_param, second_param) from t3;
442- sformat(format_str, first_param, second_param)
443- test 1 å å
444- select HEX(sformat(format_str, first_param, second_param)) from t3;
445- HEX(sformat(format_str, first_param, second_param))
446- 74657374203120C3A520C3A5
447- drop table t3;
448- set names latin1;
449- create table t4 (p1 bit(8), p2 boolean, p3 DECIMAL, p4 TIMESTAMP);
450- insert into t4 values (42, TRUE, 42, '2021-08-18 16:50:07'),
451- (24, FALSE, 24, '0000-00-00 00:00:00');
452- select sformat('{}: {} {} {} {}', 'Data', p1, p2, p3, p4) from t4;
453- sformat('{}: {} {} {} {}', 'Data', p1, p2, p3, p4)
454- Data: 42 1 42 2021-08-18 16:50:07
455- Data: 24 0 24 0000-00-00 00:00:00
456- drop table t4;
457- set names utf8;
458- create table t5 (param text character SET utf8 COLLATE utf8_general_ci);
459- insert into t5 values (UNHEX('C3A5')),(UNHEX('C5BB')),(UNHEX('e0b1bb')),
460- (UNHEX('C38A')), (NULL);
461- select sformat('{}', param) from t5;
462- sformat('{}', param)
463- å
464- Ż
465- ౻
466- Ê
467- NULL
468- select HEX(sformat('{}', param)) from t5;
469- HEX(sformat('{}', param))
470- C3A5
471- C5BB
472- E0B1BB
473- C38A
474- NULL
475- drop table t5;
476- set names latin1;
0 commit comments