1
1
#
2
+ # MDEV-25015 Custom formatting of strings in MariaDB queries
3
+ #
4
+ #
2
5
# Normal Test Cases
3
6
#
4
7
select sformat('string test');
@@ -109,7 +112,7 @@ select sformat('R={ }', 42);
109
112
sformat('R={ }', 42)
110
113
NULL
111
114
Warnings:
112
- Warning 4183 Wrong format exception : invalid format string
115
+ Warning 4183 SFORMAT error : invalid format string
113
116
select sformat(NULL, 'Null', 'Test');
114
117
sformat(NULL, 'Null', 'Test')
115
118
NULL
@@ -123,17 +126,17 @@ select sformat('My { Test');
123
126
sformat('My { Test')
124
127
NULL
125
128
Warnings:
126
- Warning 4183 Wrong format exception : invalid format string
129
+ Warning 4183 SFORMAT error : invalid format string
127
130
select sformat('Test { {');
128
131
sformat('Test { {')
129
132
NULL
130
133
Warnings:
131
- Warning 4183 Wrong format exception : invalid format string
134
+ Warning 4183 SFORMAT error : invalid format string
132
135
select sformat('A{}C{}E{}', 'B', 'D');
133
136
sformat('A{}C{}E{}', 'B', 'D')
134
137
NULL
135
138
Warnings:
136
- Warning 4183 Wrong format exception : argument not found
139
+ Warning 4183 SFORMAT error : argument not found
137
140
select sformat();
138
141
ERROR 42000: Incorrect parameter count in the call to native function 'sformat'
139
142
#
@@ -149,7 +152,7 @@ string: xyz, number: 123
149
152
NULL
150
153
Test case Print -> -32
151
154
Warnings:
152
- Warning 4183 Wrong format exception : argument not found
155
+ Warning 4183 SFORMAT error : argument not found
153
156
drop table t1;
154
157
create table t2 (param1 FLOAT, param2 SMALLINT, param3 CHAR, param4 DATE);
155
158
insert into t2 values (0.0025, 25, 'A', DATE('2020-06-29')),
@@ -313,77 +316,77 @@ select sformat('Test {:c}', 'word');
313
316
sformat('Test {:c}', 'word')
314
317
NULL
315
318
Warnings:
316
- Warning 4183 Wrong format exception : invalid type specifier
319
+ Warning 4183 SFORMAT error : invalid type specifier
317
320
select sformat('Test {one} {two} {three}', 1, 2, 3);
318
321
sformat('Test {one} {two} {three}', 1, 2, 3)
319
322
NULL
320
323
Warnings:
321
- Warning 4183 Wrong format exception : argument not found
324
+ Warning 4183 SFORMAT error : argument not found
322
325
select sformat('Number {:{<}', 8);
323
326
sformat('Number {:{<}', 8)
324
327
NULL
325
328
Warnings:
326
- Warning 4183 Wrong format exception : invalid fill character '{'
329
+ Warning 4183 SFORMAT error : invalid fill character '{'
327
330
select sformat('Number {:10000000000}', 5);
328
331
sformat('Number {:10000000000}', 5)
329
332
NULL
330
333
Warnings:
331
- Warning 4183 Wrong format exception : number is too big
334
+ Warning 4183 SFORMAT error : number is too big
332
335
select sformat('1={1} 2={2} 0={0}', 0, 1);
333
336
sformat('1={1} 2={2} 0={0}', 0, 1)
334
337
NULL
335
338
Warnings:
336
- Warning 4183 Wrong format exception : argument not found
339
+ Warning 4183 SFORMAT error : argument not found
337
340
select sformat('Number {:.2d}', 42);
338
341
sformat('Number {:.2d}', 42)
339
342
NULL
340
343
Warnings:
341
- Warning 4183 Wrong format exception : precision not allowed for this argument type
344
+ Warning 4183 SFORMAT error : precision not allowed for this argument type
342
345
select sformat('You scored {:.0%}', 0.25);
343
346
sformat('You scored {:.0%}', 0.25)
344
347
NULL
345
348
Warnings:
346
- Warning 4183 Wrong format exception : invalid type specifier
349
+ Warning 4183 SFORMAT error : invalid type specifier
347
350
select sformat('You scored {:%}', 0.25);
348
351
sformat('You scored {:%}', 0.25)
349
352
NULL
350
353
Warnings:
351
- Warning 4183 Wrong format exception : invalid type specifier
354
+ Warning 4183 SFORMAT error : invalid type specifier
352
355
select sformat('The price is {:f} dollars.', 45);
353
356
sformat('The price is {:f} dollars.', 45)
354
357
NULL
355
358
Warnings:
356
- Warning 4183 Wrong format exception : invalid type specifier
359
+ Warning 4183 SFORMAT error : invalid type specifier
357
360
select sformat('The price is {:.2f} dollars.', 45);
358
361
sformat('The price is {:.2f} dollars.', 45)
359
362
NULL
360
363
Warnings:
361
- Warning 4183 Wrong format exception : precision not allowed for this argument type
364
+ Warning 4183 SFORMAT error : precision not allowed for this argument type
362
365
select sformat('We have {:E} chickens.', 5);
363
366
sformat('We have {:E} chickens.', 5)
364
367
NULL
365
368
Warnings:
366
- Warning 4183 Wrong format exception : invalid type specifier
369
+ Warning 4183 SFORMAT error : invalid type specifier
367
370
select sformat('We have {:e} chickens.', 5);
368
371
sformat('We have {:e} chickens.', 5)
369
372
NULL
370
373
Warnings:
371
- Warning 4183 Wrong format exception : invalid type specifier
374
+ Warning 4183 SFORMAT error : invalid type specifier
372
375
select sformat('The universe is {:,} years old.', 13800000000);
373
376
sformat('The universe is {:,} years old.', 13800000000)
374
377
NULL
375
378
Warnings:
376
- Warning 4183 Wrong format exception : invalid type specifier
379
+ Warning 4183 SFORMAT error : invalid type specifier
377
380
select sformat('The universe is {:_} years old.', 13800000000);
378
381
sformat('The universe is {:_} years old.', 13800000000)
379
382
NULL
380
383
Warnings:
381
- Warning 4183 Wrong format exception : invalid type specifier
384
+ Warning 4183 SFORMAT error : invalid type specifier
382
385
select sformat('String {:-}', 'hello');
383
386
sformat('String {:-}', 'hello')
384
387
NULL
385
388
Warnings:
386
- Warning 4183 Wrong format exception : format specifier requires numeric argument
389
+ Warning 4183 SFORMAT error : format specifier requires numeric argument
387
390
#
388
391
# Table Format Test Cases
389
392
#
@@ -406,71 +409,3 @@ select a, sformat('{:.15f}', a) from t2;
406
409
a sformat('{:.15f}', a)
407
410
3.141592653589793 3.141592653589793
408
411
drop 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