Commit graph

11 commits

Author SHA1 Message Date
Sergei Golubchik
aa4bcdbbb8 main.func_sformat: fixes for fmt 10.2.1 2024-04-22 00:14:03 +02:00
Sergei Golubchik
f0f9dc8631 enable main.func_sformat in --view 2024-04-22 00:14:02 +02:00
Weijun Huang
f288d42cdb MDEV-29646: sformat('Num [{:20}]', 42) gives incorrect result in view
The problem is that sformat does not assign the enough space for the
result string. The result string is allocated with the max_length of
argument, but the correst max_length should be based on the format
string.

The patch fixes the problem by using MAX_BLOB_WIDTH to assign length
2023-05-04 14:37:41 +10:00
Lena Startseva
cee61e37b9 MDEV-27691: make working view-protocol
Update tests for version 10.7
2022-09-27 17:47:12 +07:00
Sergei Golubchik
57bf8c1f35 MDEV-26646 SFORMAT Does not allow @variable use
If charset aggregation decides to convert arguments to some specific
charset and some arguments are numbers, they'll be wrapped into a
Item_func_conv_charset(), that changes result_type() to STRING_RESULT.

Fix: don't convert numbers, sformat needs their numerical value only.
2021-10-12 13:28:10 +02:00
Sergei Golubchik
6a7c10de92 MDEV-26691 SFORMAT: Pass down FLOAT as FLOAT, without upcast to DOUBLE 2021-10-12 13:28:10 +02:00
Sergei Golubchik
62d4e7e2df remove auto-switch between char and string based on the string length
1. it is against sql way, auto-detection should use metadata, not data,
consider:

create table t1 (qwe varchar(10)) as values ('qwe'),('qw'),('q'),('werty');
select sformat('{:*>5s}', qwe) from t1;

this will auto-break on the third row.

2. using max_char_length() instead of length() fixes that, but
there's a second big issue, fmt < 8.0 doesn't natively support unicode,
so {:c} would only work for one-byte strings, for 'a', not for 'я'

because of all that let's always format strings as strings.
{:c} will only now work for numbers and still only in the ascii range.
2021-10-12 13:28:10 +02:00
Sergei Golubchik
513c8b4c25 cannot allocate a new String[] in the ::val_str() method
String inherits from Sql_alloc, so it's allocated on the thd's memroot,
this cannot be done per row.

Moved String[] allocation into the Item_func_sformat constructor
(not fix_fields(), because we want it on the same memroot where the item
is).
2021-10-12 13:28:10 +02:00
Sergei Golubchik
8150f52e47 support charsets with mbminlen > 1 2021-10-12 13:28:10 +02:00
Sergei Golubchik
519bb2e41c disallow {:p}
by printing a String as an std::string_view, not as a char*
2021-10-12 13:28:10 +02:00
Sergei Golubchik
a363ccd681 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
2021-10-12 13:28:10 +02:00
Renamed from mysql-test/main/sformat.test (Browse further)