Skip to content

Commit 03c68f4

Browse files
committed
ErrConvStringQ helper
like ErrConvString, but puts the string in 'single quotes'
1 parent 3c9ecf4 commit 03c68f4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sql/sql_error.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,14 @@ class ErrBuff
857857
len= err_conv(err_buffer, (uint) sizeof(err_buffer), str, (uint) len, cs);
858858
return {err_buffer, len};
859859
}
860+
LEX_CSTRING set_strq(const char *str, size_t len, CHARSET_INFO *cs) const
861+
{
862+
DBUG_ASSERT(len < UINT_MAX32);
863+
len= err_conv(err_buffer+1, (uint) sizeof(err_buffer)-2, str, (uint) len, cs);
864+
err_buffer[0]= err_buffer[len+1]= '\'';
865+
err_buffer[len+2]= 0;
866+
return {err_buffer, len+2};
867+
}
860868
LEX_CSTRING set_mysql_time(const MYSQL_TIME *ltime) const
861869
{
862870
int length= my_TIME_to_str(ltime, err_buffer, AUTO_SEC_PART_DIGITS);
@@ -880,6 +888,7 @@ class ErrConv: public ErrBuff
880888

881889
class ErrConvString : public ErrConv
882890
{
891+
protected:
883892
const char *str;
884893
size_t len;
885894
CHARSET_INFO *cs;
@@ -896,6 +905,16 @@ class ErrConvString : public ErrConv
896905
}
897906
};
898907

908+
class ErrConvStringQ : public ErrConvString
909+
{
910+
public:
911+
using ErrConvString::ErrConvString;
912+
LEX_CSTRING lex_cstring() const override
913+
{
914+
return set_strq(str, len, cs);
915+
}
916+
};
917+
899918
class ErrConvInteger : public ErrConv, public Longlong_hybrid
900919
{
901920
public:

0 commit comments

Comments
 (0)