diff options
Diffstat (limited to 'sql-common')
-rw-r--r-- | sql-common/client.c | 314 | ||||
-rw-r--r-- | sql-common/client_plugin.c | 2 | ||||
-rw-r--r-- | sql-common/conf_to_src.c | 144 | ||||
-rw-r--r-- | sql-common/errmsg.c | 129 | ||||
-rw-r--r-- | sql-common/my_time.c | 21 | ||||
-rw-r--r-- | sql-common/mysql_async.c | 4 | ||||
-rw-r--r-- | sql-common/pack.c | 24 |
7 files changed, 349 insertions, 289 deletions
diff --git a/sql-common/client.c b/sql-common/client.c index 4f1cc6c564e..d621a16b63b 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -105,6 +105,7 @@ my_bool net_flush(NET *net); #endif #include "client_settings.h" +#include <ssl_compat.h> #include <sql_common.h> #include <mysql/client_plugin.h> #include <my_context.h> @@ -575,16 +576,22 @@ err: Error message is set. @retval */ - ulong cli_safe_read(MYSQL *mysql) { + ulong reallen = 0; + return cli_safe_read_reallen(mysql, &reallen); +} + +ulong +cli_safe_read_reallen(MYSQL *mysql, ulong* reallen) +{ NET *net= &mysql->net; ulong len=0; restart: if (net->vio != 0) - len= my_net_read_packet(net, 0); + len= my_net_read_packet_reallen(net, 0, reallen); if (len == packet_error || len == 0) { @@ -607,7 +614,7 @@ restart: uint last_errno=uint2korr(pos); if (last_errno == 65535 && - (mysql->server_capabilities & CLIENT_PROGRESS)) + (mysql->server_capabilities & CLIENT_PROGRESS_OBSOLETE)) { if (cli_report_progress(mysql, pos+2, (uint) (len-3))) { @@ -951,7 +958,7 @@ void STDCALL mysql_free_result(MYSQL_RES *result) { DBUG_ENTER("mysql_free_result"); - DBUG_PRINT("enter",("mysql_res: 0x%lx", (long) result)); + DBUG_PRINT("enter",("mysql_res: %p", result)); if (result) { MYSQL *mysql= result->handle; @@ -1011,11 +1018,6 @@ enum option_id { static TYPELIB option_types={array_elements(default_options)-1, "options",default_options, NULL}; -const char *sql_protocol_names_lib[] = -{ "TCP", "SOCKET", "PIPE", "MEMORY", NullS }; -TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"", - sql_protocol_names_lib, NULL}; - static int add_init_command(struct st_mysql_options *options, const char *cmd) { char *tmp; @@ -1354,7 +1356,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, { uchar *pos; /* fields count may be wrong */ - if (field - result >= (my_ptrdiff_t)fields) + if (field >= result + fields) goto err; cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7); @@ -1401,7 +1403,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, /* old protocol, for backward compatibility */ for (row=data->data; row ; row = row->next,field++) { - if (field - result >= (my_ptrdiff_t)fields) + if (field >= result + fields) goto err; cli_fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5); field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]); @@ -1439,7 +1441,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, } } #endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */ - if (field - result < (my_ptrdiff_t)fields) + if (field < result + fields) goto err; free_rows(data); /* Free old data */ DBUG_RETURN(result); @@ -1661,15 +1663,15 @@ mysql_init(MYSQL *mysql) How this change impacts existing apps: - existing apps which relyed on the default will see a behaviour change; they will have to set reconnect=1 after mysql_real_connect(). - - existing apps which explicitely asked for reconnection (the only way they + - existing apps which explicitly asked for reconnection (the only way they could do it was by setting mysql.reconnect to 1 after mysql_real_connect()) will not see a behaviour change. - - existing apps which explicitely asked for no reconnection + - existing apps which explicitly asked for no reconnection (mysql.reconnect=0) will not see a behaviour change. */ mysql->reconnect= 0; - DBUG_PRINT("mysql",("mysql: 0x%lx", (long) mysql)); + DBUG_PRINT("mysql",("mysql: %p", mysql)); return mysql; } @@ -1787,9 +1789,8 @@ mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused))) #if defined(HAVE_OPENSSL) -#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(HAVE_YASSL) +#ifdef HAVE_X509_check_host #include <openssl/x509v3.h> -#define HAVE_X509_check_host #endif static int ssl_verify_server_cert(Vio *vio, const char* server_hostname, const char **errptr) @@ -1864,7 +1865,7 @@ static int ssl_verify_server_cert(Vio *vio, const char* server_hostname, const c goto error; } - cn= (char *) ASN1_STRING_data(cn_asn1); + cn= (char *) ASN1_STRING_get0_data(cn_asn1); if ((size_t)ASN1_STRING_length(cn_asn1) != strlen(cn)) { @@ -1926,250 +1927,13 @@ static MYSQL_METHODS client_methods= }; - -typedef enum my_cs_match_type_enum -{ - /* MySQL and OS charsets are fully compatible */ - my_cs_exact, - /* MySQL charset is very close to OS charset */ - my_cs_approx, - /* - MySQL knows this charset, but it is not supported as client character set. - */ - my_cs_unsupp -} my_cs_match_type; - - -typedef struct str2str_st -{ - const char *os_name; - const char *my_name; - my_cs_match_type param; -} MY_CSET_OS_NAME; - -const MY_CSET_OS_NAME charsets[]= -{ -#ifdef __WIN__ - {"cp437", "cp850", my_cs_approx}, - {"cp850", "cp850", my_cs_exact}, - {"cp852", "cp852", my_cs_exact}, - {"cp858", "cp850", my_cs_approx}, - {"cp866", "cp866", my_cs_exact}, - {"cp874", "tis620", my_cs_approx}, - {"cp932", "cp932", my_cs_exact}, - {"cp936", "gbk", my_cs_approx}, - {"cp949", "euckr", my_cs_approx}, - {"cp950", "big5", my_cs_exact}, - {"cp1200", "utf16le", my_cs_unsupp}, - {"cp1201", "utf16", my_cs_unsupp}, - {"cp1250", "cp1250", my_cs_exact}, - {"cp1251", "cp1251", my_cs_exact}, - {"cp1252", "latin1", my_cs_exact}, - {"cp1253", "greek", my_cs_exact}, - {"cp1254", "latin5", my_cs_exact}, - {"cp1255", "hebrew", my_cs_approx}, - {"cp1256", "cp1256", my_cs_exact}, - {"cp1257", "cp1257", my_cs_exact}, - {"cp10000", "macroman", my_cs_exact}, - {"cp10001", "sjis", my_cs_approx}, - {"cp10002", "big5", my_cs_approx}, - {"cp10008", "gb2312", my_cs_approx}, - {"cp10021", "tis620", my_cs_approx}, - {"cp10029", "macce", my_cs_exact}, - {"cp12001", "utf32", my_cs_unsupp}, - {"cp20107", "swe7", my_cs_exact}, - {"cp20127", "latin1", my_cs_approx}, - {"cp20866", "koi8r", my_cs_exact}, - {"cp20932", "ujis", my_cs_exact}, - {"cp20936", "gb2312", my_cs_approx}, - {"cp20949", "euckr", my_cs_approx}, - {"cp21866", "koi8u", my_cs_exact}, - {"cp28591", "latin1", my_cs_approx}, - {"cp28592", "latin2", my_cs_exact}, - {"cp28597", "greek", my_cs_exact}, - {"cp28598", "hebrew", my_cs_exact}, - {"cp28599", "latin5", my_cs_exact}, - {"cp28603", "latin7", my_cs_exact}, -#ifdef UNCOMMENT_THIS_WHEN_WL_4579_IS_DONE - {"cp28605", "latin9", my_cs_exact}, -#endif - {"cp38598", "hebrew", my_cs_exact}, - {"cp51932", "ujis", my_cs_exact}, - {"cp51936", "gb2312", my_cs_exact}, - {"cp51949", "euckr", my_cs_exact}, - {"cp51950", "big5", my_cs_exact}, -#ifdef UNCOMMENT_THIS_WHEN_WL_WL_4024_IS_DONE - {"cp54936", "gb18030", my_cs_exact}, -#endif - {"cp65001", "utf8", my_cs_exact}, - -#else /* not Windows */ - - {"646", "latin1", my_cs_approx}, /* Default on Solaris */ - {"ANSI_X3.4-1968", "latin1", my_cs_approx}, - {"ansi1251", "cp1251", my_cs_exact}, - {"armscii8", "armscii8", my_cs_exact}, - {"armscii-8", "armscii8", my_cs_exact}, - {"ASCII", "latin1", my_cs_approx}, - {"Big5", "big5", my_cs_exact}, - {"cp1251", "cp1251", my_cs_exact}, - {"cp1255", "hebrew", my_cs_approx}, - {"CP866", "cp866", my_cs_exact}, - {"eucCN", "gb2312", my_cs_exact}, - {"euc-CN", "gb2312", my_cs_exact}, - {"eucJP", "ujis", my_cs_exact}, - {"euc-JP", "ujis", my_cs_exact}, - {"eucKR", "euckr", my_cs_exact}, - {"euc-KR", "euckr", my_cs_exact}, -#ifdef UNCOMMENT_THIS_WHEN_WL_WL_4024_IS_DONE - {"gb18030", "gb18030", my_cs_exact}, -#endif - {"gb2312", "gb2312", my_cs_exact}, - {"gbk", "gbk", my_cs_exact}, - {"georgianps", "geostd8", my_cs_exact}, - {"georgian-ps", "geostd8", my_cs_exact}, - {"IBM-1252", "cp1252", my_cs_exact}, - - {"iso88591", "latin1", my_cs_approx}, - {"ISO_8859-1", "latin1", my_cs_approx}, - {"ISO8859-1", "latin1", my_cs_approx}, - {"ISO-8859-1", "latin1", my_cs_approx}, - - {"iso885913", "latin7", my_cs_exact}, - {"ISO_8859-13", "latin7", my_cs_exact}, - {"ISO8859-13", "latin7", my_cs_exact}, - {"ISO-8859-13", "latin7", my_cs_exact}, - -#ifdef UNCOMMENT_THIS_WHEN_WL_4579_IS_DONE - {"iso885915", "latin9", my_cs_exact}, - {"ISO_8859-15", "latin9", my_cs_exact}, - {"ISO8859-15", "latin9", my_cs_exact}, - {"ISO-8859-15", "latin9", my_cs_exact}, -#endif - - {"iso88592", "latin2", my_cs_exact}, - {"ISO_8859-2", "latin2", my_cs_exact}, - {"ISO8859-2", "latin2", my_cs_exact}, - {"ISO-8859-2", "latin2", my_cs_exact}, - - {"iso88597", "greek", my_cs_exact}, - {"ISO_8859-7", "greek", my_cs_exact}, - {"ISO8859-7", "greek", my_cs_exact}, - {"ISO-8859-7", "greek", my_cs_exact}, - - {"iso88598", "hebrew", my_cs_exact}, - {"ISO_8859-8", "hebrew", my_cs_exact}, - {"ISO8859-8", "hebrew", my_cs_exact}, - {"ISO-8859-8", "hebrew", my_cs_exact}, - - {"iso88599", "latin5", my_cs_exact}, - {"ISO_8859-9", "latin5", my_cs_exact}, - {"ISO8859-9", "latin5", my_cs_exact}, - {"ISO-8859-9", "latin5", my_cs_exact}, - - {"koi8r", "koi8r", my_cs_exact}, - {"KOI8-R", "koi8r", my_cs_exact}, - {"koi8u", "koi8u", my_cs_exact}, - {"KOI8-U", "koi8u", my_cs_exact}, - - {"roman8", "hp8", my_cs_exact}, /* Default on HP UX */ - - {"Shift_JIS", "sjis", my_cs_exact}, - {"SJIS", "sjis", my_cs_exact}, - {"shiftjisx0213", "sjis", my_cs_exact}, - - {"tis620", "tis620", my_cs_exact}, - {"tis-620", "tis620", my_cs_exact}, - - {"ujis", "ujis", my_cs_exact}, - - {"US-ASCII", "latin1", my_cs_approx}, - - {"utf8", "utf8", my_cs_exact}, - {"utf-8", "utf8", my_cs_exact}, -#endif - {NULL, NULL, 0} -}; - - -static const char * -my_os_charset_to_mysql_charset(const char *csname) -{ - const MY_CSET_OS_NAME *csp; - for (csp= charsets; csp->os_name; csp++) - { - if (!my_strcasecmp(&my_charset_latin1, csp->os_name, csname)) - { - switch (csp->param) - { - case my_cs_exact: - return csp->my_name; - - case my_cs_approx: - /* - Maybe we should print a warning eventually: - character set correspondence is not exact. - */ - return csp->my_name; - - default: - my_printf_error(ER_UNKNOWN_ERROR, - "OS character set '%s'" - " is not supported by MySQL client", - MYF(0), csp->my_name); - goto def; - } - } - } - - my_printf_error(ER_UNKNOWN_ERROR, - "Unknown OS character set '%s'.", - MYF(0), csname); - -def: - csname= MYSQL_DEFAULT_CHARSET_NAME; - my_printf_error(ER_UNKNOWN_ERROR, - "Switching to the default character set '%s'.", - MYF(0), csname); - return csname; -} - - -#ifndef __WIN__ -#include <stdlib.h> /* for getenv() */ -#ifdef HAVE_LANGINFO_H -#include <langinfo.h> -#endif -#ifdef HAVE_LOCALE_H -#include <locale.h> -#endif -#endif /* __WIN__ */ - - +#include <my_sys.h> static int mysql_autodetect_character_set(MYSQL *mysql) { - const char *csname= MYSQL_DEFAULT_CHARSET_NAME; - -#ifdef __WIN__ - char cpbuf[64]; - { - UINT cp= GetConsoleCP(); - if (cp == 0) - cp= GetACP(); - my_snprintf(cpbuf, sizeof(cpbuf), "cp%d", (int)cp); - csname= my_os_charset_to_mysql_charset(cpbuf); - } -#elif defined(HAVE_SETLOCALE) && defined(HAVE_NL_LANGINFO) - { - if (setlocale(LC_CTYPE, "") && (csname= nl_langinfo(CODESET))) - csname= my_os_charset_to_mysql_charset(csname); - } -#endif - if (mysql->options.charset_name) my_free(mysql->options.charset_name); - if (!(mysql->options.charset_name= my_strdup(csname, MYF(MY_WME)))) + if (!(mysql->options.charset_name= my_strdup(my_default_csname(),MYF(MY_WME)))) return 1; return 0; } @@ -2210,16 +1974,13 @@ C_MODE_START int mysql_init_character_set(MYSQL *mysql) { /* Set character set */ - if (!mysql->options.charset_name) + if (!mysql->options.charset_name || + !strcmp(mysql->options.charset_name, + MYSQL_AUTODETECT_CHARSET_NAME)) { - if (!(mysql->options.charset_name= - my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME)))) + if (mysql_autodetect_character_set(mysql)) return 1; } - else if (!strcmp(mysql->options.charset_name, - MYSQL_AUTODETECT_CHARSET_NAME) && - mysql_autodetect_character_set(mysql)) - return 1; mysql_set_character_set_with_default_collation(mysql); @@ -2834,11 +2595,11 @@ void mpvio_info(Vio *vio, MYSQL_PLUGIN_VIO_INFO *info) switch (vio->type) { case VIO_TYPE_TCPIP: info->protocol= MYSQL_VIO_TCP; - info->socket= vio_fd(vio); + info->socket= (int)vio_fd(vio); return; case VIO_TYPE_SOCKET: info->protocol= MYSQL_VIO_SOCKET; - info->socket= vio_fd(vio); + info->socket= (int)vio_fd(vio); return; case VIO_TYPE_SSL: { @@ -2848,7 +2609,7 @@ void mpvio_info(Vio *vio, MYSQL_PLUGIN_VIO_INFO *info) return; info->protocol= addr.sa_family == AF_UNIX ? MYSQL_VIO_SOCKET : MYSQL_VIO_TCP; - info->socket= vio_fd(vio); + info->socket= (int)vio_fd(vio); return; } #ifdef _WIN32 @@ -3148,7 +2909,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, DBUG_RETURN(0); mysql->methods= &client_methods; - net->vio = 0; /* If something goes wrong */ mysql->client_flag=0; /* For handshake */ /* use default options */ @@ -3409,7 +3169,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, } DBUG_PRINT("info", ("End of connect attempts, sock: %d status: %d error: %d", - sock, status, saved_error)); + (int)sock, status, saved_error)); freeaddrinfo(res_lst); @@ -3595,7 +3355,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, } else { - scramble_data_len= pkt_end - scramble_data; + scramble_data_len= (int)(pkt_end - scramble_data); scramble_plugin= native_password_plugin_name; } } @@ -3666,7 +3426,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, } #endif - DBUG_PRINT("exit", ("Mysql handler: 0x%lx", (long) mysql)); + DBUG_PRINT("exit", ("Mysql handler: %p",mysql)); DBUG_RETURN(mysql); error: @@ -3988,7 +3748,7 @@ void STDCALL mysql_close_slow_part(MYSQL *mysql) void STDCALL mysql_close(MYSQL *mysql) { DBUG_ENTER("mysql_close"); - DBUG_PRINT("enter", ("mysql: 0x%lx", (long) mysql)); + DBUG_PRINT("enter", ("mysql: %p", mysql)); if (mysql) /* Some simple safety */ { @@ -4113,7 +3873,7 @@ int STDCALL mysql_real_query(MYSQL *mysql, const char *query, ulong length) { DBUG_ENTER("mysql_real_query"); - DBUG_PRINT("enter",("handle: 0x%lx", (long) mysql)); + DBUG_PRINT("enter",("handle: %p", mysql)); DBUG_PRINT("query",("Query = '%-.4096s'",query)); if (mysql_send_query(mysql,query,length)) @@ -4821,3 +4581,11 @@ mysql_get_socket(const MYSQL *mysql) return vio_fd(mysql->net.vio); return INVALID_SOCKET; } + + +int STDCALL mysql_cancel(MYSQL *mysql) +{ + if (mysql->net.vio) + return vio_shutdown(mysql->net.vio, SHUT_RDWR); + return -1; +} diff --git a/sql-common/client_plugin.c b/sql-common/client_plugin.c index 52e0ae03ee1..a4de02b9f41 100644 --- a/sql-common/client_plugin.c +++ b/sql-common/client_plugin.c @@ -28,10 +28,8 @@ There is no reference counting and no unloading either. */ -#if _MSC_VER /* Silence warnings about variable 'unused' being used. */ #define FORCE_INIT_OF_VARS 1 -#endif #include <my_global.h> #include "mysql.h" diff --git a/sql-common/conf_to_src.c b/sql-common/conf_to_src.c new file mode 100644 index 00000000000..57d3ee864ac --- /dev/null +++ b/sql-common/conf_to_src.c @@ -0,0 +1,144 @@ +/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. + + 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 + the Free Software Foundation. + + There are special exceptions to the terms and conditions of the GPL as it + is applied to this software. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* can't use -lmysys because this prog is used to create -lstrings */ + + +#include <my_global.h> +#include <ctype.h> +#include <string.h> +#include <unistd.h> + +#define CHARSETS_SUBDIR "sql/share/charsets" +#define CTYPE_TABLE_SIZE 257 +#define TO_LOWER_TABLE_SIZE 256 +#define TO_UPPER_TABLE_SIZE 256 +#define SORT_ORDER_TABLE_SIZE 256 +#define ROW_LEN 16 + +void print_arrays_for(char *set); + +char *prog; +char buf[1024], *p, *endptr; + +int +main(int argc, char **argv) +{ + prog = *argv; + + if (argc < 2) { + fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog); + exit(EXIT_FAILURE); + } + + --argc; ++argv; /* skip program name */ + + if (chdir(*argv) != 0) { + fprintf(stderr, "%s: can't cd to %s\n", prog, *argv); + exit(EXIT_FAILURE); + } + --argc; ++argv; + + if (chdir(CHARSETS_SUBDIR) != 0) { + fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR); + exit(EXIT_FAILURE); + } + + while (argc--) + print_arrays_for(*argv++); + + exit(EXIT_SUCCESS); +} + +void +print_array(FILE *f, const char *set, const char *name, int n) +{ + int i; + char val[100]; + + printf("uchar %s_%s[] = {\n", name, set); + + p = buf; + *buf = '\0'; + for (i = 0; i < n; ++i) + { + /* get a word from f */ + endptr = p; + for (;;) + { + while (isspace(*endptr)) + ++endptr; + if (*endptr && *endptr != '#') /* not comment */ + break; + if ((fgets(buf, sizeof(buf), f)) == NULL) + return; /* XXX: break silently */ + endptr = buf; + } + + p = val; + while (!isspace(*endptr)) + *p++ = *endptr++; + *p = '\0'; + p = endptr; + + /* write the value out */ + + if (i == 0 || i % ROW_LEN == n % ROW_LEN) + printf(" "); + + printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16)); + + if (i < n - 1) + printf(","); + + if ((i+1) % ROW_LEN == n % ROW_LEN) + printf("\n"); + } + + printf("};\n\n"); +} + +void +print_arrays_for(char *set) +{ + FILE *f; + + snprintf(buf, sizeof(buf), "%s.conf", set); + + if ((f = fopen(buf, "r")) == NULL) { + fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set); + exit(EXIT_FAILURE); + } + + printf("\ +/* The %s character set. Generated automatically by configure and\n\ + * the %s program\n\ + */\n\n", + set, prog); + + /* it would be nice if this used the code in mysys/charset.c, but... */ + print_array(f, set, "ctype", CTYPE_TABLE_SIZE); + print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE); + print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE); + print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE); + printf("\n"); + + fclose(f); + + return; +} diff --git a/sql-common/errmsg.c b/sql-common/errmsg.c new file mode 100644 index 00000000000..049fb51ec87 --- /dev/null +++ b/sql-common/errmsg.c @@ -0,0 +1,129 @@ +/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + + 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 + the Free Software Foundation. + + There are special exceptions to the terms and conditions of the GPL as it + is applied to this software. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* Error messages for MySQL clients */ +/* (Error messages for the daemon are in share/language/errmsg.sys) */ + +#include <my_global.h> +#include <my_sys.h> +#include "errmsg.h" + +const char *client_errors[]= +{ + "Unknown MySQL error", + "Can't create UNIX socket (%d)", + "Can't connect to local MySQL server through socket '%-.100s' (%M)", + "Can't connect to MySQL server on '%-.100s' (%M)", + "Can't create TCP/IP socket (%M)", + "Unknown MySQL server host '%-.100s' (%d)", + "MySQL server has gone away", + "Protocol mismatch; server version = %d, client version = %d", + "MySQL client ran out of memory", + "Wrong host info", + "Localhost via UNIX socket", + "%-.100s via TCP/IP", + "Error in server handshake", + "Lost connection to MySQL server during query", + "Commands out of sync; you can't run this command now", + "Named pipe: %-.32s", + "Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)", + "Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)", + "Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)", + "Can't initialize character set %-.32s (path: %-.100s)", + "Got packet bigger than 'max_allowed_packet' bytes", + "Embedded server", + "Error on SHOW SLAVE STATUS:", + "Error on SHOW SLAVE HOSTS:", + "Error connecting to slave:", + "Error connecting to master:", + "SSL connection error: %-.100s", + "Malformed packet", + "This client library is licensed only for use with MySQL servers having '%s' license", + "Invalid use of null pointer", + "Statement not prepared", + "No data supplied for parameters in prepared statement", + "Data truncated", + "No parameters exist in the statement", + "Invalid parameter number", + "Can't send long data for non-string/non-binary data types (parameter: %d)", + "Using unsupported buffer type: %d (parameter: %d)", + "Shared memory: %-.100s", + "Can't open shared memory; client could not create request event (%lu)", + "Can't open shared memory; no answer event received from server (%lu)", + "Can't open shared memory; server could not allocate file mapping (%lu)", + "Can't open shared memory; server could not get pointer to file mapping (%lu)", + "Can't open shared memory; client could not allocate file mapping (%lu)", + "Can't open shared memory; client could not get pointer to file mapping (%lu)", + "Can't open shared memory; client could not create %s event (%lu)", + "Can't open shared memory; no answer from server (%lu)", + "Can't open shared memory; cannot send request event to server (%lu)", + "Wrong or unknown protocol", + "Invalid connection handle", + "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)", + "Row retrieval was canceled by mysql_stmt_close() call", + "Attempt to read column without prior row fetch", + "Prepared statement contains no metadata", + "Attempt to read a row while there is no result set associated with the statement", + "This feature is not implemented yet", + "Lost connection to MySQL server at '%s', system error: %M", + "Statement closed indirectly because of a preceding %s() call", + "The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again", + "This handle is already connected. Use a separate handle for each connection.", + "Authentication plugin '%s' cannot be loaded: %s", + "There is an attribute with the same name already", + "Authentication plugin '%s' reported error: %s", + "" +}; + +const char** get_client_errmsgs(int nr __attribute__((unused))) +{ + return client_errors; +} + +/* + Register client error messages for use with my_error(). + + SYNOPSIS + init_client_errs() + + RETURN + void +*/ + +void init_client_errs(void) +{ + compile_time_assert(array_elements(client_errors) == + (CR_ERROR_LAST - CR_ERROR_FIRST + 2)); + (void) my_error_register(get_client_errmsgs, CR_ERROR_FIRST, CR_ERROR_LAST); +} + + +/* + Unregister client error messages. + + SYNOPSIS + finish_client_errs() + + RETURN + void +*/ + +void finish_client_errs(void) +{ + (void) my_error_unregister(CR_ERROR_FIRST, CR_ERROR_LAST); +} diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 5482b6dfa5c..90ce0b11c1e 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -1,6 +1,6 @@ /* Copyright (c) 2004, 2012, Oracle and/or its affiliates. - Copyright (c) 2010, 2013, Monty Program Ab. + Copyright (c) 2010, 2017, MariaDB Corporation. 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 @@ -20,7 +20,7 @@ #include <m_ctype.h> /* Windows version of localtime_r() is declared in my_ptrhead.h */ #include <my_pthread.h> -#include <mysqld_error.h> + ulonglong log_10_int[20]= { @@ -202,7 +202,7 @@ static uint skip_digits(const char **str, const char *end) while (s < end && my_isdigit(&my_charset_latin1, *s)) s++; *str= s; - return s - start; + return (uint)(s - start); } @@ -236,7 +236,7 @@ static void get_microseconds(ulong *val, MYSQL_TIME_STATUS *status, uint tmp= 0; /* For the case '10:10:10.' */ if (get_digits(&tmp, number_of_fields, str, end, 6)) status->warnings|= MYSQL_TIME_WARN_TRUNCATED; - if ((status->precision= (*str - start)) < 6) + if ((status->precision= (uint)(*str - start)) < 6) *val= (ulong) (tmp * log_10_int[6 - (*str - start)]); else *val= tmp; @@ -358,7 +358,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, const char *start= str; if (get_number(&l_time->year, &number_of_fields, &str, end)) status->warnings|= MYSQL_TIME_WARN_TRUNCATED; - year_length= str - start; + year_length= (uint)(str - start); if (!status->warnings && (get_punct(&str, end) @@ -777,7 +777,6 @@ long calc_daynr(uint year,uint month,uint day) DBUG_RETURN(delsum+(int) y/4-temp); } /* calc_daynr */ - /* Convert time in MYSQL_TIME representation in system time zone to its my_time_t form (number of seconds in UTC since begginning of Unix Epoch). @@ -1445,11 +1444,11 @@ MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time) if ((my_time->neg= packed < 0)) packed= -packed; get_one(my_time->second_part, 1000000ULL); - get_one(my_time->second, 60ULL); - get_one(my_time->minute, 60ULL); - get_one(my_time->hour, 24ULL); - get_one(my_time->day, 32ULL); - get_one(my_time->month, 13ULL); + get_one(my_time->second, 60U); + get_one(my_time->minute, 60U); + get_one(my_time->hour, 24U); + get_one(my_time->day, 32U); + get_one(my_time->month, 13U); my_time->year= (uint)packed; my_time->time_type= MYSQL_TIMESTAMP_DATETIME; return my_time; diff --git a/sql-common/mysql_async.c b/sql-common/mysql_async.c index decf48e0e69..1bac16edd1e 100644 --- a/sql-common/mysql_async.c +++ b/sql-common/mysql_async.c @@ -128,7 +128,7 @@ my_connect_async(struct mysql_async_context *b, my_socket fd, #endif ssize_t -my_recv_async(struct mysql_async_context *b, int fd, +my_recv_async(struct mysql_async_context *b, my_socket fd, unsigned char *buf, size_t size, int timeout) { ssize_t res; @@ -156,7 +156,7 @@ my_recv_async(struct mysql_async_context *b, int fd, ssize_t -my_send_async(struct mysql_async_context *b, int fd, +my_send_async(struct mysql_async_context *b, my_socket fd, const unsigned char *buf, size_t size, int timeout) { ssize_t res; diff --git a/sql-common/pack.c b/sql-common/pack.c index 57abeffab22..de821f08b35 100644 --- a/sql-common/pack.c +++ b/sql-common/pack.c @@ -19,7 +19,7 @@ #include <mysql.h> /* Get the length of next field. Change parameter to point at fieldstart */ -ulong STDCALL net_field_length(uchar **packet) +ulong net_field_length(uchar **packet) { reg1 uchar *pos= (uchar *)*packet; if (*pos < 251) @@ -186,3 +186,25 @@ uchar *safe_net_store_length(uchar *packet, size_t packet_len, ulonglong length) return packet+8; } + +/** + The length of space required to store the resulting length-encoded integer + for the given number. This function can be used at places where one needs to + dynamically allocate the buffer for a given number to be stored as length- + encoded integer. + + @param num [IN] the input number + + @return length of buffer needed to store this number [1, 3, 4, 9]. +*/ + +uint net_length_size(ulonglong num) +{ + if (num < (ulonglong) 251LL) + return 1; + if (num < (ulonglong) 65536LL) + return 3; + if (num < (ulonglong) 16777216LL) + return 4; + return 9; +} |