Commit b3bc02f9 authored by Monty's avatar Monty Committed by Sergei Golubchik

Added ErrConvString.lex_cstring() to simplify code

This allows us to use String::append() without using strlen().

The changes to the ErrConvString class where done by Alexander Barkov
parent 5c7d243b
......@@ -3816,7 +3816,7 @@ void Item_string::print(String *str, enum_query_type query_type)
changed.
*/
ErrConvString tmp(str_value.ptr(), str_value.length(), &my_charset_bin);
str->append(tmp.ptr());
str->append(tmp.lex_cstring());
}
else
{
......
......@@ -393,7 +393,7 @@ void field_unpack(String *to, Field *field, const uchar *rec, uint max_length,
if (max_length < field->pack_length())
tmp.length(MY_MIN(tmp.length(),max_length));
ErrConvString err(&tmp);
to->append(err.ptr());
to->append(err.lex_cstring());
}
else
to->append(STRING_WITH_LEN("???"));
......
......@@ -7558,10 +7558,10 @@ class ErrConvDQName: public ErrConv
ErrConvDQName(const Database_qualified_name *name)
:m_name(name)
{ }
const char *ptr() const
LEX_CSTRING lex_cstring() const override
{
m_name->make_qname(err_buffer, sizeof(err_buffer));
return err_buffer;
size_t length= m_name->make_qname(err_buffer, sizeof(err_buffer));
return {err_buffer, length};
}
};
......
......@@ -864,10 +864,10 @@ extern "C" int my_wc_mb_utf8_null_terminated(CHARSET_INFO *cs,
@param from_cs charset from convert
@retval
result string
result string length
*/
char *err_conv(char *buff, uint to_length, const char *from,
size_t err_conv(char *buff, uint to_length, const char *from,
uint from_length, CHARSET_INFO *from_cs)
{
char *to= buff;
......@@ -919,7 +919,7 @@ char *err_conv(char *buff, uint to_length, const char *from,
&errors);
to[res]= 0;
}
return buff;
return res;
}
......
......@@ -811,7 +811,7 @@ class Warning_info
};
extern char *err_conv(char *buff, uint to_length, const char *from,
extern size_t err_conv(char *buff, uint to_length, const char *from,
uint from_length, CHARSET_INFO *from_cs);
class ErrBuff
......@@ -824,31 +824,37 @@ class ErrBuff
err_buffer[0]= '\0';
}
const char *ptr() const { return err_buffer; }
const char *set_longlong(const Longlong_hybrid &nr) const
LEX_CSTRING set_longlong(const Longlong_hybrid &nr) const
{
return nr.is_unsigned() ? ullstr(nr.value(), err_buffer) :
llstr(nr.value(), err_buffer);
int radix= nr.is_unsigned() ? 10 : -10;
const char *end= longlong10_to_str(nr.value(), err_buffer, radix);
DBUG_ASSERT(end >= err_buffer);
return {err_buffer, (size_t) (end - err_buffer)};
}
const char *set_double(double nr) const
LEX_CSTRING set_double(double nr) const
{
my_gcvt(nr, MY_GCVT_ARG_DOUBLE, sizeof(err_buffer), err_buffer, 0);
return err_buffer;
size_t length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE,
sizeof(err_buffer), err_buffer, 0);
return {err_buffer, length};
}
const char *set_decimal(const decimal_t *d) const
LEX_CSTRING set_decimal(const decimal_t *d) const
{
int len= sizeof(err_buffer);
decimal2string(d, err_buffer, &len, 0, 0, ' ');
return err_buffer;
int length= sizeof(err_buffer);
decimal2string(d, err_buffer, &length, 0, 0, ' ');
DBUG_ASSERT(length >= 0);
return {err_buffer, (size_t) length};
}
const char *set_str(const char *str, size_t len, CHARSET_INFO *cs) const
LEX_CSTRING set_str(const char *str, size_t len, CHARSET_INFO *cs) const
{
DBUG_ASSERT(len < UINT_MAX32);
return err_conv(err_buffer, (uint) sizeof(err_buffer), str, (uint) len, cs);
len= err_conv(err_buffer, (uint) sizeof(err_buffer), str, (uint) len, cs);
return {err_buffer, len};
}
const char *set_mysql_time(const MYSQL_TIME *ltime) const
LEX_CSTRING set_mysql_time(const MYSQL_TIME *ltime) const
{
my_TIME_to_str(ltime, err_buffer, AUTO_SEC_PART_DIGITS);
return err_buffer;
int length= my_TIME_to_str(ltime, err_buffer, AUTO_SEC_PART_DIGITS);
DBUG_ASSERT(length >= 0);
return {err_buffer, (size_t) length};
}
};
......@@ -858,7 +864,11 @@ class ErrConv: public ErrBuff
public:
ErrConv() {}
virtual ~ErrConv() {}
virtual const char *ptr() const = 0;
virtual LEX_CSTRING lex_cstring() const= 0;
inline const char *ptr() const
{
return lex_cstring().str;
}
};
class ErrConvString : public ErrConv
......@@ -873,7 +883,7 @@ class ErrConvString : public ErrConv
: ErrConv(), str(str_arg), len(strlen(str_arg)), cs(cs_arg) {}
ErrConvString(const String *s)
: ErrConv(), str(s->ptr()), len(s->length()), cs(s->charset()) {}
const char *ptr() const
LEX_CSTRING lex_cstring() const override
{
return set_str(str, len, cs);
}
......@@ -884,7 +894,7 @@ class ErrConvInteger : public ErrConv, public Longlong_hybrid
public:
ErrConvInteger(const Longlong_hybrid &nr)
: ErrConv(), Longlong_hybrid(nr) { }
const char *ptr() const
LEX_CSTRING lex_cstring() const override
{
return set_longlong(static_cast<Longlong_hybrid>(*this));
}
......@@ -895,7 +905,7 @@ class ErrConvDouble: public ErrConv
double num;
public:
ErrConvDouble(double num_arg) : ErrConv(), num(num_arg) {}
const char *ptr() const
LEX_CSTRING lex_cstring() const override
{
return set_double(num);
}
......@@ -906,7 +916,7 @@ class ErrConvTime : public ErrConv
const MYSQL_TIME *ltime;
public:
ErrConvTime(const MYSQL_TIME *ltime_arg) : ErrConv(), ltime(ltime_arg) {}
const char *ptr() const
LEX_CSTRING lex_cstring() const override
{
return set_mysql_time(ltime);
}
......@@ -917,7 +927,7 @@ class ErrConvDecimal : public ErrConv
const decimal_t *d;
public:
ErrConvDecimal(const decimal_t *d_arg) : ErrConv(), d(d_arg) {}
const char *ptr() const
LEX_CSTRING lex_cstring() const override
{
return set_decimal(d);
}
......
......@@ -3480,11 +3480,11 @@ bool ha_connect::get_error_message(int error, String* buf)
if (trace(1))
htrc("GEM(%d): %s\n", error, g->Message);
buf->append(ErrConvString(g->Message, strlen(g->Message),
&my_charset_latin1).ptr());
buf->append(ErrConvString(g->Message,
strlen(g->Message),
&my_charset_latin1).lex_cstring());
} else
buf->append("Cannot retrieve error message");
buf->append(STRING_WITH_LEN("Cannot retrieve error message"));
DBUG_RETURN(false);
} // end of get_error_message
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment