diff options
Diffstat (limited to 'sql-common')
-rw-r--r-- | sql-common/client.c | 19 | ||||
-rw-r--r-- | sql-common/client_plugin.c | 2 | ||||
-rw-r--r-- | sql-common/my_time.c | 440 | ||||
-rw-r--r-- | sql-common/my_user.c | 28 | ||||
-rw-r--r-- | sql-common/pack.c | 6 |
5 files changed, 211 insertions, 284 deletions
diff --git a/sql-common/client.c b/sql-common/client.c index 913dab75fda..eb51a7aae76 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -891,7 +891,10 @@ void free_old_query(MYSQL *mysql) DBUG_ENTER("free_old_query"); if (mysql->fields) free_root(&mysql->field_alloc,MYF(0)); - init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ + /* Assume rowlength < 8192 */ + init_alloc_root(&mysql->field_alloc, 8192, 0, + MYF(mysql->options.use_thread_specific_memory ? + MY_THREAD_SPECIFIC : 0)); mysql->fields= 0; mysql->field_count= 0; /* For API */ mysql->warning_count= 0; @@ -1171,7 +1174,7 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd) { options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY), MYF(MY_WME)); - init_dynamic_array(options->init_commands,sizeof(char*),5,5); + my_init_dynamic_array(options->init_commands,sizeof(char*),5, 5, MYF(0)); } if (!(tmp= my_strdup(cmd,MYF(MY_WME))) || @@ -1580,7 +1583,10 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(0); } - init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ + /* Assume rowlength < 8192 */ + init_alloc_root(&result->alloc, 8192, 0, + MYF(mysql->options.use_thread_specific_memory ? + MY_THREAD_SPECIFIC : 0)); result->alloc.min_malloc=sizeof(MYSQL_ROWS); prev_ptr= &result->data; result->rows=0; @@ -3211,7 +3217,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, */ DBUG_PRINT("info",("IPV6 getaddrinfo error %d", gai_errno)); set_mysql_extended_error(mysql, CR_UNKNOWN_HOST, unknown_sqlstate, - ER(CR_UNKNOWN_HOST), host, errno); + ER(CR_UNKNOWN_HOST), host, gai_errno); goto error; } @@ -3296,7 +3302,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, if (mysql->options.extension && mysql->options.extension->async_context) net->vio->async_context= mysql->options.extension->async_context; - if (my_net_init(net, net->vio)) + if (my_net_init(net, net->vio, MYF(0))) { vio_delete(net->vio); net->vio = 0; @@ -4213,6 +4219,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) case MYSQL_OPT_RECONNECT: mysql->reconnect= *(my_bool *) arg; break; + case MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY: + mysql->options.use_thread_specific_memory= *(my_bool *) arg; + break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: if (*(my_bool*) arg) mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT; diff --git a/sql-common/client_plugin.c b/sql-common/client_plugin.c index f31ddb22a6a..5b59c4e0e71 100644 --- a/sql-common/client_plugin.c +++ b/sql-common/client_plugin.c @@ -251,7 +251,7 @@ int mysql_client_plugin_init() bzero(&mysql, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ pthread_mutex_init(&LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW); - init_alloc_root(&mem_root, 128, 128); + init_alloc_root(&mem_root, 128, 128, MYF(0)); bzero(&plugin_list, sizeof(plugin_list)); diff --git a/sql-common/my_time.c b/sql-common/my_time.c index b91028cc1ea..297eec15b13 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -1,5 +1,6 @@ /* Copyright (c) 2004, 2012, Oracle and/or its affiliates. + Copyright (c) 2010, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,10 +25,10 @@ ulonglong log_10_int[20]= { 1, 10, 100, 1000, 10000UL, 100000UL, 1000000UL, 10000000UL, - ULL(100000000), ULL(1000000000), ULL(10000000000), ULL(100000000000), - ULL(1000000000000), ULL(10000000000000), ULL(100000000000000), - ULL(1000000000000000), ULL(10000000000000000), ULL(100000000000000000), - ULL(1000000000000000000), ULL(10000000000000000000) + 100000000ULL, 1000000000ULL, 10000000000ULL, 100000000000ULL, + 1000000000000ULL, 10000000000000ULL, 100000000000000ULL, + 1000000000000000ULL, 10000000000000000ULL, 100000000000000000ULL, + 1000000000000000000ULL, 10000000000000000000ULL }; @@ -104,6 +105,103 @@ my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, return FALSE; } +static int get_number(uint *val, uint *number_of_fields, const char **str, + const char *end) +{ + const char *s = *str; + + if (s >= end) + return 0; + + if (!my_isdigit(&my_charset_latin1, *s)) + return 1; + *val= *s++ - '0'; + + for (; s < end && my_isdigit(&my_charset_latin1, *s); s++) + *val= *val * 10 + *s - '0'; + *str = s; + (*number_of_fields)++; + return 0; +} + +static int get_digits(uint *val, uint *number_of_fields, const char **str, + const char *end, uint length) +{ + return get_number(val, number_of_fields, str, min(end, *str + length)); +} + +static int get_punct(const char **str, const char *end) +{ + if (*str >= end) + return 0; + if (my_ispunct(&my_charset_latin1, **str)) + { + (*str)++; + return 0; + } + return 1; +} + +static int get_date_time_separator(uint *number_of_fields, ulonglong flags, + const char **str, const char *end) +{ + const char *s= *str; + if (s >= end) + return 0; + + if (*s == 'T') + { + (*str)++; + return 0; + } + + /* + now, this is tricky, for backward compatibility reasons. + cast("11:11:11.12.12.12" as datetime) should give 2011-11-11 12:12:12 + but + cast("11:11:11.12.12.12" as time) should give 11:11:11.12 + that is, a punctuation character can be accepted as a date/time separator + only if TIME_DATETIME_ONLY (see str_to_time) is not set. + */ + if (my_ispunct(&my_charset_latin1, *s)) + { + if (flags & TIME_DATETIME_ONLY) + { + /* see above, returning 1 is not enough, we need hard abort here */ + *number_of_fields= 0; + return 1; + } + + (*str)++; + return 0; + } + + if (!my_isspace(&my_charset_latin1, *s)) + return 1; + + do + { + s++; + } while (my_isspace(&my_charset_latin1, *s)); + *str= s; + return 0; +} + +static int get_maybe_T(const char **str, const char *end) +{ + if (*str < end && **str == 'T') + (*str)++; + return 0; +} + +static uint skip_digits(const char **str, const char *end) +{ + const char *start= *str, *s= *str; + while (s < end && my_isdigit(&my_charset_latin1, *s)) + s++; + *str= s; + return s - start; +} /* Convert a timestamp string to a MYSQL_TIME value. @@ -132,24 +230,9 @@ my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, The second part may have an optional .###### fraction part. - NOTES - This function should work with a format position vector as long as the - following things holds: - - All date are kept together and all time parts are kept together - - Date and time parts must be separated by blank - - Second fractions must come after second part and be separated - by a '.'. (The second fractions are optional) - - AM/PM must come after second fractions (or after seconds if no fractions) - - Year must always been specified. - - If time is before date, then we will use datetime format only if - the argument consist of two parts, separated by space. - Otherwise we will assume the argument is a date. - - The hour part must be specified in hour-minute-second order. - RETURN VALUES MYSQL_TIMESTAMP_NONE String wasn't a timestamp, like [DD [HH:[MM:[SS]]]].fraction. - l_time is not changed. MYSQL_TIMESTAMP_DATE DATE string (YY MM and DD parts ok) MYSQL_TIMESTAMP_DATETIME Full timestamp MYSQL_TIMESTAMP_ERROR Timestamp with wrong values. @@ -162,18 +245,10 @@ enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ulonglong flags, int *was_cut) { - uint UNINIT_VAR(field_length), UNINIT_VAR(year_length), digits, i, number_of_fields; - uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS]; - uint add_hours= 0, start_loop; - ulong not_zero_date, allow_space; - my_bool is_internal_format; - const char *pos, *UNINIT_VAR(last_field_pos); - const char *end=str+length; - const uchar *format_position; - my_bool found_delimitier= 0, found_space= 0; - uint frac_pos, frac_len; + const char *end=str+length, *pos; + uint number_of_fields= 0, digits, year_length, not_zero_date; DBUG_ENTER("str_to_datetime"); - DBUG_PRINT("enter",("str: %.*s",length,str)); + bzero(l_time, sizeof(*l_time)); if (flags & TIME_TIME_ONLY) { @@ -181,7 +256,6 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ret= str_to_time(str, length, l_time, flags, was_cut); DBUG_RETURN(ret); } - *was_cut= 0; /* Skip space at start */ @@ -193,254 +267,93 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, DBUG_RETURN(MYSQL_TIMESTAMP_NONE); } - is_internal_format= 0; - /* This has to be changed if want to activate different timestamp formats */ - format_position= internal_format_positions; - /* Calculate number of digits in first part. If length= 8 or >= 14 then year is of format YYYY. (YYYY-MM-DD, YYYYMMDD, YYYYYMMDDHHMMSS) */ - for (pos=str; - pos != end && (my_isdigit(&my_charset_latin1,*pos) || *pos == 'T'); - pos++) - ; + pos= str; + digits= skip_digits(&pos, end); - digits= (uint) (pos-str); - start_loop= 0; /* Start of scan loop */ - date_len[format_position[0]]= 0; /* Length of year field */ - if (pos == end || *pos == '.') + if (pos < end && *pos == 'T') /* YYYYYMMDDHHMMSSThhmmss is supported too */ { - /* Found date in internal format (only numbers like YYYYMMDD) */ - year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; - field_length= year_length; - is_internal_format= 1; - format_position= internal_format_positions; + pos++; + digits+= skip_digits(&pos, end); } - else + if (pos < end && *pos == '.' && digits >= 12) /* YYYYYMMDDHHMMSShhmmss.uuuuuu is supported too */ { - if (format_position[0] >= 3) /* If year is after HHMMDD */ - { - /* - If year is not in first part then we have to determinate if we got - a date field or a datetime field. - We do this by checking if there is two numbers separated by - space in the input. - */ - while (pos < end && !my_isspace(&my_charset_latin1, *pos)) - pos++; - while (pos < end && !my_isdigit(&my_charset_latin1, *pos)) - pos++; - if (pos == end) - { - if (flags & TIME_DATETIME_ONLY) - { - *was_cut= 1; - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); /* Can't be a full datetime */ - } - /* Date field. Set hour, minutes and seconds to 0 */ - date[0]= date[1]= date[2]= date[3]= date[4]= 0; - start_loop= 5; /* Start with first date part */ - } - } - - field_length= format_position[0] == 0 ? 4 : 2; + pos++; + skip_digits(&pos, end); // ignore the return value } - /* - Only allow space in the first "part" of the datetime field and: - - after days, part seconds - - before and after AM/PM (handled by code later) - - 2003-03-03 20:00:20 AM - 20:00:20.000000 AM 03-03-2000 - */ - i= max((uint) format_position[0], (uint) format_position[1]); - set_if_bigger(i, (uint) format_position[2]); - allow_space= ((1 << i) | (1 << format_position[6])); - allow_space&= (1 | 2 | 4 | 8); - - not_zero_date= 0; - for (i = start_loop; - i < MAX_DATE_PARTS-1 && str != end && - my_isdigit(&my_charset_latin1,*str); - i++) + if (pos == end) { - const char *start= str; - ulong tmp_value= (uint) (uchar) (*str++ - '0'); - /* - Internal format means no delimiters; every field has a fixed - width. Otherwise, we scan until we find a delimiter and discard - leading zeroes -- except for the microsecond part, where leading - zeroes are significant, and where we never process more than six - digits. + Found date in internal format + (only numbers like [YY]YYMMDD[T][hhmmss[.uuuuuu]]) */ - my_bool scan_until_delim= !is_internal_format && - ((i != format_position[6])); - - while (str != end && my_isdigit(&my_charset_latin1,str[0]) && - (scan_until_delim || --field_length)) - { - tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0'); - str++; - } - date_len[i]= (uint) (str - start); - if (tmp_value > 999999) /* Impossible date part */ - { - *was_cut= 1; - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); - } - date[i]=tmp_value; - not_zero_date|= tmp_value; - - /* Length of next field */ - field_length= format_position[i+1] == 0 ? 4 : 2; - - if ((last_field_pos= str) == end) - { - i++; /* Register last found part */ - break; - } - /* Allow a 'T' after day to allow CCYYMMDDT type of fields */ - if (i == format_position[2] && *str == 'T') - { - str++; /* ISO8601: CCYYMMDDThhmmss */ - continue; - } - if (i == format_position[5]) /* Seconds */ - { - if (*str == '.') /* Followed by part seconds */ - { - str++; - field_length= 6; /* 6 digits */ - } - continue; - } - while (str != end && - (my_ispunct(&my_charset_latin1,*str) || - my_isspace(&my_charset_latin1,*str))) - { - if (my_isspace(&my_charset_latin1,*str)) - { - if (!(allow_space & (1 << i))) - { - *was_cut= 1; - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); - } - found_space= 1; - } - str++; - found_delimitier= 1; /* Should be a 'normal' date */ - } - /* Check if next position is AM/PM */ - if (i == format_position[6]) /* Seconds, time for AM/PM */ - { - i++; /* Skip AM/PM part */ - if (format_position[7] != 255) /* If using AM/PM */ - { - if (str+2 <= end && (str[1] == 'M' || str[1] == 'm')) - { - if (str[0] == 'p' || str[0] == 'P') - add_hours= 12; - else if (str[0] != 'a' && str[0] != 'A') - continue; /* Not AM/PM */ - str+= 2; /* Skip AM/PM */ - /* Skip space after AM/PM */ - while (str != end && my_isspace(&my_charset_latin1,*str)) - str++; - } - } - } - last_field_pos= str; + year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; + *was_cut= get_digits(&l_time->year, &number_of_fields, &str, end, year_length) + || get_digits(&l_time->month, &number_of_fields, &str, end, 2) + || get_digits(&l_time->day, &number_of_fields, &str, end, 2) + || get_maybe_T(&str, end) + || get_digits(&l_time->hour, &number_of_fields, &str, end, 2) + || get_digits(&l_time->minute, &number_of_fields, &str, end, 2) + || get_digits(&l_time->second, &number_of_fields, &str, end, 2); } - if (found_delimitier && !found_space && (flags & TIME_DATETIME_ONLY)) + else { - *was_cut= 1; - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); /* Can't be a datetime */ + const char *start= str; + *was_cut = get_number(&l_time->year, &number_of_fields, &str, end); + year_length= str - start; + + if (!*was_cut) + *was_cut= get_punct(&str, end) + || get_number(&l_time->month, &number_of_fields, &str, end) + || get_punct(&str, end) + || get_number(&l_time->day, &number_of_fields, &str, end) + || get_date_time_separator(&number_of_fields, flags, &str, end) + || get_number(&l_time->hour, &number_of_fields, &str, end) + || get_punct(&str, end) + || get_number(&l_time->minute, &number_of_fields, &str, end) + || get_punct(&str, end) + || get_number(&l_time->second, &number_of_fields, &str, end); } - str= last_field_pos; + if (number_of_fields < 3) + *was_cut= 1; - number_of_fields= i - start_loop; - while (i < MAX_DATE_PARTS) - { - date_len[i]= 0; - date[i++]= 0; - } + /* we're ok if date part is correct. even if the rest is truncated */ + if (*was_cut && number_of_fields < 3) + DBUG_RETURN(MYSQL_TIMESTAMP_NONE); - if (!is_internal_format) + if (!*was_cut && str < end && *str == '.') { - year_length= date_len[(uint) format_position[0]]; - if (!year_length) /* Year must be specified */ - { + uint second_part; + const char *start= ++str; + *was_cut= get_digits(&second_part, &number_of_fields, &str, end, 6); + if (str - start < 6) + second_part*= log_10_int[6 - (str - start)]; + l_time->second_part= second_part; + if (skip_digits(&str, end)) *was_cut= 1; - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); - } - - l_time->year= date[(uint) format_position[0]]; - l_time->month= date[(uint) format_position[1]]; - l_time->day= date[(uint) format_position[2]]; - l_time->hour= date[(uint) format_position[3]]; - l_time->minute= date[(uint) format_position[4]]; - l_time->second= date[(uint) format_position[5]]; - - frac_pos= (uint) format_position[6]; - frac_len= date_len[frac_pos]; - if (frac_len < 6) - date[frac_pos]*= (uint) log_10_int[6 - frac_len]; - l_time->second_part= date[frac_pos]; - - if (format_position[7] != (uchar) 255) - { - if (l_time->hour > 12) - { - *was_cut= 1; - goto err; - } - l_time->hour= l_time->hour%12 + add_hours; - } - } - else - { - l_time->year= date[0]; - l_time->month= date[1]; - l_time->day= date[2]; - l_time->hour= date[3]; - l_time->minute= date[4]; - l_time->second= date[5]; - if (date_len[6] < 6) - date[6]*= (uint) log_10_int[6 - date_len[6]]; - l_time->second_part=date[6]; } - l_time->neg= 0; + + not_zero_date = l_time->year || l_time->month || l_time->day || + l_time->hour || l_time->minute || l_time->second || + l_time->second_part; if (year_length == 2 && not_zero_date) l_time->year+= (l_time->year < YY_PART_YEAR ? 2000 : 1900); - if (number_of_fields < 3 || - l_time->year > 9999 || l_time->month > 12 || - l_time->day > 31 || l_time->hour > 23 || - l_time->minute > 59 || l_time->second > 59) + if (l_time->year > 9999 || l_time->month > 12 || l_time->day > 31 || + l_time->hour > 23 || l_time->minute > 59 || l_time->second > 59) { - /* Only give warning for a zero date if there is some garbage after */ - if (!not_zero_date) /* If zero date */ - { - for (; str != end ; str++) - { - if (!my_isspace(&my_charset_latin1, *str)) - { - not_zero_date= 1; /* Give warning */ - break; - } - } - } - *was_cut= test(not_zero_date); + *was_cut= 1; goto err; } - if (check_date(l_time, not_zero_date != 0, flags, was_cut)) + if (check_date(l_time, not_zero_date, flags, was_cut)) goto err; l_time->time_type= (number_of_fields <= 3 ? @@ -495,16 +408,15 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, ulong date[5]; ulonglong value; const char *end=str+length, *end_of_days; - my_bool found_days,found_hours; - uint state; + my_bool found_days,found_hours, neg= 0; + uint UNINIT_VAR(state); - l_time->neg=0; *warning= 0; for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++) length--; if (str != end && *str == '-') { - l_time->neg=1; + neg=1; str++; length--; } @@ -527,6 +439,7 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, } } + l_time->neg= neg; /* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */ for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++) value=value*10L + (long) (*str - '0'); @@ -536,7 +449,6 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, for (; str != end && my_isspace(&my_charset_latin1, str[0]) ; str++) ; - LINT_INIT(state); found_days=found_hours=0; if ((uint) (end-str) > 1 && str != end_of_days && my_isdigit(&my_charset_latin1, *str)) @@ -1254,19 +1166,19 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, time_res->time_type=MYSQL_TIMESTAMP_DATETIME; - if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959)) + if (nr <= (YY_PART_YEAR-1)*10000000000LL+1231235959LL) { - nr= nr+LL(20000000000000); /* YYMMDDHHMMSS, 2000-2069 */ + nr= nr+20000000000000LL; /* YYMMDDHHMMSS, 2000-2069 */ goto ok; } - if (nr < YY_PART_YEAR*LL(10000000000)+ LL(101000000)) + if (nr < YY_PART_YEAR*10000000000LL+ 101000000LL) goto err; - if (nr <= LL(991231235959)) - nr= nr+LL(19000000000000); /* YYMMDDHHMMSS, 1970-1999 */ + if (nr <= 991231235959LL) + nr= nr+19000000000000LL; /* YYMMDDHHMMSS, 1970-1999 */ ok: - part1=(long) (nr/LL(1000000)); - part2=(long) (nr - (longlong) part1*LL(1000000)); + part1=(long) (nr/1000000LL); + part2=(long) (nr - (longlong) part1*1000000LL); time_res->year= (int) (part1/10000L); part1%=10000L; time_res->month= (int) part1 / 100; time_res->day= (int) part1 % 100; @@ -1286,7 +1198,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, /* Don't want to have was_cut get set if NO_ZERO_DATE was violated. */ if (nr || !(flags & TIME_NO_ZERO_DATE)) *was_cut= 1; - return LL(-1); + return -1; err: { @@ -1296,7 +1208,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, time_res->time_type= save; /* Restore range */ *was_cut= 1; /* Found invalid date */ } - return LL(-1); + return -1; } /* @@ -1361,7 +1273,7 @@ ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *my_time) { return ((ulonglong) (my_time->year * 10000UL + my_time->month * 100UL + - my_time->day) * ULL(1000000) + + my_time->day) * 1000000ULL + (ulonglong) (my_time->hour * 10000UL + my_time->minute * 100UL + my_time->second)); @@ -1422,7 +1334,7 @@ ulonglong TIME_to_ulonglong(const MYSQL_TIME *my_time) return TIME_to_ulonglong_time(my_time); case MYSQL_TIMESTAMP_NONE: case MYSQL_TIMESTAMP_ERROR: - return ULL(0); + return 0; default: DBUG_ASSERT(0); } diff --git a/sql-common/my_user.c b/sql-common/my_user.c index 8d717ea7131..a486f77bc1e 100644 --- a/sql-common/my_user.c +++ b/sql-common/my_user.c @@ -30,34 +30,40 @@ host_name_str [OUT] Buffer to store host name part. Must be not less than HOSTNAME_LENGTH + 1. host_name_len [OUT] A place to store length of the host name part. + + RETURN + 0 - if only a user was set, no '@' was found + 1 - if both user and host were set */ -void parse_user(const char *user_id_str, size_t user_id_len, - char *user_name_str, size_t *user_name_len, - char *host_name_str, size_t *host_name_len) +int parse_user(const char *user_id_str, size_t user_id_len, + char *user_name_str, size_t *user_name_len, + char *host_name_str, size_t *host_name_len) { char *p= strrchr(user_id_str, '@'); if (!p) { - *user_name_len= 0; + *user_name_len= user_id_len; *host_name_len= 0; } else { *user_name_len= (uint) (p - user_id_str); *host_name_len= (uint) (user_id_len - *user_name_len - 1); + } - if (*user_name_len > USERNAME_LENGTH) - *user_name_len= USERNAME_LENGTH; + if (*user_name_len > USERNAME_LENGTH) + *user_name_len= USERNAME_LENGTH; - if (*host_name_len > HOSTNAME_LENGTH) - *host_name_len= HOSTNAME_LENGTH; + if (*host_name_len > HOSTNAME_LENGTH) + *host_name_len= HOSTNAME_LENGTH; - memcpy(user_name_str, user_id_str, *user_name_len); - memcpy(host_name_str, p + 1, *host_name_len); - } + memcpy(user_name_str, user_id_str, *user_name_len); + memcpy(host_name_str, p + 1, *host_name_len); user_name_str[*user_name_len]= 0; host_name_str[*host_name_len]= 0; + + return p != NULL; } diff --git a/sql-common/pack.c b/sql-common/pack.c index 02e91b5c3e3..5af5a9f1d33 100644 --- a/sql-common/pack.c +++ b/sql-common/pack.c @@ -97,19 +97,19 @@ my_ulonglong net_field_length_ll(uchar **packet) uchar *net_store_length(uchar *packet, ulonglong length) { - if (length < (ulonglong) LL(251)) + if (length < (ulonglong) 251LL) { *packet=(uchar) length; return packet+1; } /* 251 is reserved for NULL */ - if (length < (ulonglong) LL(65536)) + if (length < (ulonglong) 65536LL) { *packet++=252; int2store(packet,(uint) length); return packet+2; } - if (length < (ulonglong) LL(16777216)) + if (length < (ulonglong) 16777216LL) { *packet++=253; int3store(packet,(ulong) length); |