MySQL 8.0.39
Source Code Documentation
sql_string.cc File Reference
#include "sql_string.h"
#include "sql/sql_const.h"
#include <assert.h>
#include <algorithm>
#include <limits>
#include "my_macros.h"
#include "my_pointer_arithmetic.h"
#include "my_sys.h"
#include "mysql_com.h"

Functions

void qs_append (const char *str_in, size_t len, String *str)
 
void qs_append (double d, size_t len, String *str)
 
void qs_append (int i, String *str)
 
void qs_append (uint i, String *str)
 
int sortcmp (const String *s, const String *t, const CHARSET_INFO *cs)
 
int stringcmp (const String *s, const String *t)
 
Stringcopy_if_not_alloced (String *to, String *from, size_t from_length)
 Makes a copy of a String's buffer unless it's already heap-allocated. More...
 
size_t well_formed_copy_nchars (const CHARSET_INFO *to_cs, char *to, size_t to_length, const CHARSET_INFO *from_cs, const char *from, size_t from_length, size_t nchars, const char **well_formed_error_pos, const char **cannot_convert_error_pos, const char **from_end_pos)
 
size_t convert_to_printable (char *to, size_t to_len, const char *from, size_t from_len, const CHARSET_INFO *from_cs, size_t nbytes)
 Convert string to printable ASCII string. More...
 
size_t bin_to_hex_str (char *to, size_t to_len, const char *from, size_t from_len)
 Convert a buffer to printable HEX encoded string For eg: ABCDEF1234. More...
 
bool validate_string (const CHARSET_INFO *cs, const char *str, size_t length, size_t *valid_length, bool *length_error)
 Check if an input byte sequence is a valid character string of a given charset. More...
 
bool append_escaped (String *to_str, const String *from_str)
 Appends from_str to to_str, escaping certain characters. More...
 

Variables

PSI_memory_key key_memory_String_value
 

Function Documentation

◆ append_escaped()

bool append_escaped ( String to_str,
const String from_str 
)

Appends from_str to to_str, escaping certain characters.

Parameters
[in,out]to_strThe destination string.
[in]from_strThe source string.
Returns
false on success, true on error.

◆ bin_to_hex_str()

size_t bin_to_hex_str ( char *  to,
size_t  to_len,
const char *  from,
size_t  from_len 
)

Convert a buffer to printable HEX encoded string For eg: ABCDEF1234.

Parameters
tooutput buffer
to_lensize of the output buffer (from_len*2 + 1 or greater)
frominput buffer
from_lensize of the input buffer
Returns
number of bytes in the output string

◆ convert_to_printable()

size_t convert_to_printable ( char *  to,
size_t  to_len,
const char *  from,
size_t  from_len,
const CHARSET_INFO from_cs,
size_t  nbytes 
)

Convert string to printable ASCII string.

This function converts input string "from" replacing non-ASCII bytes with hexadecimal sequences ("\xXX") optionally appending "..." to the end of the resulting string. This function used in the ER_TRUNCATED_WRONG_VALUE_FOR_FIELD error messages, e.g. when a string cannot be converted to a result charset.

Parameters
tooutput buffer
to_lensize of the output buffer (8 bytes or greater)
frominput string
from_lensize of the input string
from_csinput charset
nbytesmaximal number of bytes to convert (from_len if 0)
Returns
number of bytes in the output string

◆ copy_if_not_alloced()

String * copy_if_not_alloced ( String to,
String from,
size_t  from_length 
)

Makes a copy of a String's buffer unless it's already heap-allocated.

If the buffer ('str') of 'from' is on the heap, this function returns 'from', possibly re-allocated to be at least from_length bytes long. It is also the case if from==to or to==NULL. Otherwise, this function makes and returns a copy of "from" into "to"; the buffer of "to" is heap-allocated; a pre-condition is that from->str and to->str must point to non-overlapping buffers. The logic behind this complex design, is that a caller, typically a val_str() function, sometimes has an input String ('from') which buffer it wants to modify; but this String's buffer may or not be heap-allocated; if it's not heap-allocated it is possibly in static storage or belongs to an outer context, and thus should not be modified; in that case the caller wants a heap-allocated copy which it can freely modify.

Parameters
todestination string
fromsource string
from_lengthdestination string will hold at least from_length bytes.

◆ qs_append() [1/4]

void qs_append ( const char *  str_in,
size_t  len,
String str 
)

◆ qs_append() [2/4]

void qs_append ( double  d,
size_t  len,
String str 
)

◆ qs_append() [3/4]

void qs_append ( int  i,
String str 
)

◆ qs_append() [4/4]

void qs_append ( uint  i,
String str 
)

◆ sortcmp()

int sortcmp ( const String s,
const String t,
const CHARSET_INFO cs 
)

◆ stringcmp()

int stringcmp ( const String s,
const String t 
)

◆ validate_string()

bool validate_string ( const CHARSET_INFO cs,
const char *  str,
size_t  length,
size_t *  valid_length,
bool *  length_error 
)

Check if an input byte sequence is a valid character string of a given charset.

Parameters
csThe input character set.
strThe input byte sequence to validate.
lengthA byte length of the str.
[out]valid_lengthA byte length of a valid prefix of the str.
[out]length_errorTrue in the case of a character length error: some byte[s] in the input is not a valid prefix for a character, i.e. the byte length of that invalid character is undefined.
Return values
trueif the whole input byte sequence is a valid character string. The length_error output parameter is undefined.
Returns
if the whole input byte sequence is a valid character string then return false else if the length of some character in the input is undefined (MY_CS_ILSEQ) or the last character is truncated (MY_CS_TOOSMALL) then length_error= true; // fatal error! else length_error= false; // non-fatal error: there is no wide character encoding for some input character return true

◆ well_formed_copy_nchars()

size_t well_formed_copy_nchars ( const CHARSET_INFO to_cs,
char *  to,
size_t  to_length,
const CHARSET_INFO from_cs,
const char *  from,
size_t  from_length,
size_t  nchars,
const char **  well_formed_error_pos,
const char **  cannot_convert_error_pos,
const char **  from_end_pos 
)

Variable Documentation

◆ key_memory_String_value

PSI_memory_key key_memory_String_value