mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
SCRUM:
splittiln common client's parts include/sql_common.h: superfluous #ifdef-s removed libmysql/client_settings.h: superfluous #ifdef-s removed libmysql/libmysql.c: some litter removed libmysqld/lib_sql.cc: here we had wrong parameters mysys/default.c: this is not needed anymore - calling code fixed sql-common/client.c: code trimmed and simplified sql/client_settings.h: code trimmed sql/repl_failsafe.cc: option's initialization added sql/slave.cc: option's initialization added
This commit is contained in:
@ -15,9 +15,6 @@
|
|||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
#ifndef _sql_common_h
|
|
||||||
#define _sql_common_h
|
|
||||||
|
|
||||||
extern const char *unknown_sqlstate;
|
extern const char *unknown_sqlstate;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -50,4 +47,3 @@ my_bool mysql_reconnect(MYSQL *mysql);
|
|||||||
#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
|
#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _sql_common_h */
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
#ifndef _client_settings_h
|
|
||||||
#define _client_settings_h
|
|
||||||
static my_bool mysql_client_init=0;
|
static my_bool mysql_client_init=0;
|
||||||
extern uint mysql_port;
|
extern uint mysql_port;
|
||||||
extern my_string mysql_unix_port;
|
extern my_string mysql_unix_port;
|
||||||
@ -58,4 +56,3 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename);
|
|||||||
#define set_sigpipe(mysql)
|
#define set_sigpipe(mysql)
|
||||||
#define reset_sigpipe(mysql)
|
#define reset_sigpipe(mysql)
|
||||||
#endif
|
#endif
|
||||||
#endif /* _client_settings_h */
|
|
||||||
|
@ -99,7 +99,6 @@ TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
|
|||||||
be changed
|
be changed
|
||||||
*/
|
*/
|
||||||
#define MAX_LONG_DATA_LENGTH 8192
|
#define MAX_LONG_DATA_LENGTH 8192
|
||||||
/*#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)*/
|
|
||||||
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
|
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
|
||||||
|
|
||||||
static void append_wild(char *to,char *end,const char *wild);
|
static void append_wild(char *to,char *end,const char *wild);
|
||||||
@ -157,10 +156,6 @@ void STDCALL mysql_thread_end()
|
|||||||
#define reset_sigpipe(mysql)
|
#define reset_sigpipe(mysql)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TO DELETE
|
|
||||||
#define _libmysql_c
|
|
||||||
#include "../sql-common/client.c"
|
|
||||||
*/
|
|
||||||
static MYSQL* spawn_init(MYSQL* parent, const char* host,
|
static MYSQL* spawn_init(MYSQL* parent, const char* host,
|
||||||
unsigned int port,
|
unsigned int port,
|
||||||
const char* user,
|
const char* user,
|
||||||
@ -987,6 +982,7 @@ mysql_query(MYSQL *mysql, const char *query)
|
|||||||
return mysql_real_query(mysql,query, (uint) strlen(query));
|
return mysql_real_query(mysql,query, (uint) strlen(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static MYSQL* spawn_init(MYSQL* parent, const char* host,
|
static MYSQL* spawn_init(MYSQL* parent, const char* host,
|
||||||
unsigned int port, const char* user,
|
unsigned int port, const char* user,
|
||||||
const char* passwd)
|
const char* passwd)
|
||||||
|
@ -183,7 +183,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
|
|||||||
MY_INIT((char *)"mysql_embedded"); // init my_sys library & pthreads
|
MY_INIT((char *)"mysql_embedded"); // init my_sys library & pthreads
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_common_variables("my", argc, argv, (const char **)groups))
|
if (init_common_variables("my", *argcp, *argvp, (const char **)groups))
|
||||||
{
|
{
|
||||||
mysql_server_end();
|
mysql_server_end();
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -174,8 +174,6 @@ void load_defaults(const char *conf_file, const char **groups,
|
|||||||
res= (char**) (ptr+sizeof(alloc));
|
res= (char**) (ptr+sizeof(alloc));
|
||||||
|
|
||||||
/* copy name + found arguments + command line arguments to new array */
|
/* copy name + found arguments + command line arguments to new array */
|
||||||
res[0]=*argc ? argv[0][0] : (char *)"";
|
|
||||||
|
|
||||||
memcpy((gptr) (res+1), args.buffer, args.elements*sizeof(char*));
|
memcpy((gptr) (res+1), args.buffer, args.elements*sizeof(char*));
|
||||||
/* Skipp --defaults-file and --defaults-extra-file */
|
/* Skipp --defaults-file and --defaults-extra-file */
|
||||||
(*argc)-= args_used;
|
(*argc)-= args_used;
|
||||||
|
@ -14,6 +14,27 @@
|
|||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is included by both libmysql.c (the MySQL client C API)
|
||||||
|
and the mysqld server to connect to another MYSQL server.
|
||||||
|
|
||||||
|
The differences for the two cases are:
|
||||||
|
|
||||||
|
- Things that only works for the client:
|
||||||
|
- Trying to automaticly determinate user name if not supplied to
|
||||||
|
mysql_real_connect()
|
||||||
|
- Support for reading local file with LOAD DATA LOCAL
|
||||||
|
- SHARED memory handling
|
||||||
|
- Protection against sigpipe
|
||||||
|
- Prepared statements
|
||||||
|
|
||||||
|
- Things that only works for the server
|
||||||
|
- Alarm handling on connect
|
||||||
|
|
||||||
|
In all other cases, the code should be idential for the client and
|
||||||
|
server.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <my_global.h>
|
#include <my_global.h>
|
||||||
|
|
||||||
#if defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT)
|
#if defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT)
|
||||||
@ -207,10 +228,8 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host,
|
|||||||
my_bool testing_named_pipes=0;
|
my_bool testing_named_pipes=0;
|
||||||
char *host= *arg_host, *unix_socket= *arg_unix_socket;
|
char *host= *arg_host, *unix_socket= *arg_unix_socket;
|
||||||
|
|
||||||
#ifdef MYSQL_CLIENT
|
|
||||||
if ( ! unix_socket || (unix_socket)[0] == 0x00)
|
if ( ! unix_socket || (unix_socket)[0] == 0x00)
|
||||||
unix_socket = mysql_unix_port;
|
unix_socket = mysql_unix_port;
|
||||||
#endif
|
|
||||||
if (!host || !strcmp(host,LOCAL_HOST))
|
if (!host || !strcmp(host,LOCAL_HOST))
|
||||||
host=LOCAL_HOST_NAMEDPIPE;
|
host=LOCAL_HOST_NAMEDPIPE;
|
||||||
|
|
||||||
@ -1285,7 +1304,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
|
|||||||
/*
|
/*
|
||||||
Grab a socket and connect it to the server
|
Grab a socket and connect it to the server
|
||||||
*/
|
*/
|
||||||
#if defined(MYSQL_CLIENT) && defined(HAVE_SMEM)
|
#ifdef HAVE_SMEM
|
||||||
if ((!mysql->options.protocol ||
|
if ((!mysql->options.protocol ||
|
||||||
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
|
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
|
||||||
(!host || !strcmp(host,LOCAL_HOST)))
|
(!host || !strcmp(host,LOCAL_HOST)))
|
||||||
@ -1314,22 +1333,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
|
|||||||
} else
|
} else
|
||||||
#endif /* HAVE_SMEM */
|
#endif /* HAVE_SMEM */
|
||||||
#if defined(HAVE_SYS_UN_H)
|
#if defined(HAVE_SYS_UN_H)
|
||||||
if (
|
if ((!mysql->options.protocol ||
|
||||||
#ifdef MYSQL_CLIENT
|
|
||||||
(!mysql->options.protocol ||
|
|
||||||
mysql->options.protocol == MYSQL_PROTOCOL_SOCKET)&&
|
mysql->options.protocol == MYSQL_PROTOCOL_SOCKET)&&
|
||||||
(unix_socket || mysql_unix_port) &&
|
(unix_socket || mysql_unix_port) &&
|
||||||
#endif
|
|
||||||
#ifdef MYSQL_SERVER
|
|
||||||
unix_socket &&
|
|
||||||
#endif
|
|
||||||
(!host || !strcmp(host,LOCAL_HOST)))
|
(!host || !strcmp(host,LOCAL_HOST)))
|
||||||
{
|
{
|
||||||
host=LOCAL_HOST;
|
host=LOCAL_HOST;
|
||||||
#ifdef MYSQL_CLIENT
|
|
||||||
if (!unix_socket)
|
if (!unix_socket)
|
||||||
unix_socket=mysql_unix_port;
|
unix_socket=mysql_unix_port;
|
||||||
#endif
|
|
||||||
host_info=(char*) ER(CR_LOCALHOST_CONNECTION);
|
host_info=(char*) ER(CR_LOCALHOST_CONNECTION);
|
||||||
DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
|
DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
|
||||||
if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
|
if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
|
||||||
@ -1361,18 +1372,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
|
|||||||
else
|
else
|
||||||
#elif defined(__WIN__)
|
#elif defined(__WIN__)
|
||||||
{
|
{
|
||||||
#ifdef MYSQL_CLIENT
|
|
||||||
if ((!mysql->options.protocol ||
|
if ((!mysql->options.protocol ||
|
||||||
mysql->options.protocol == MYSQL_PROTOCOL_PIPE)&&
|
mysql->options.protocol == MYSQL_PROTOCOL_PIPE)&&
|
||||||
((unix_socket || !host && is_NT() ||
|
((unix_socket || !host && is_NT() ||
|
||||||
host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) ||! have_tcpip))&&
|
host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) ||! have_tcpip))&&
|
||||||
(!net->vio))
|
(!net->vio))
|
||||||
#elif MYSQL_SERVER
|
|
||||||
if ((unix_socket ||
|
|
||||||
!host && is_NT() ||
|
|
||||||
host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) ||
|
|
||||||
mysql->options.named_pipe || !have_tcpip))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
sock=0;
|
sock=0;
|
||||||
if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout,
|
if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout,
|
||||||
@ -1408,10 +1412,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
unix_socket=0; /* This is not used */
|
unix_socket=0; /* This is not used */
|
||||||
#ifdef MYSQL_CLIENT
|
|
||||||
if (!port)
|
if (!port)
|
||||||
port=mysql_port;
|
port=mysql_port;
|
||||||
#endif
|
|
||||||
if (!host)
|
if (!host)
|
||||||
host=LOCAL_HOST;
|
host=LOCAL_HOST;
|
||||||
sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host);
|
sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host);
|
||||||
@ -1859,24 +1861,26 @@ error:
|
|||||||
|
|
||||||
/* needed when we move MYSQL structure to a different address */
|
/* needed when we move MYSQL structure to a different address */
|
||||||
|
|
||||||
#ifdef MYSQL_CLIENT /*should work in MYSQL_SERVER also, but doesn't */
|
|
||||||
static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql)
|
static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql)
|
||||||
{
|
{
|
||||||
MYSQL *tmp, *tmp_prev;
|
|
||||||
if (mysql->master == old_mysql)
|
if (mysql->master == old_mysql)
|
||||||
mysql->master = mysql;
|
mysql->master = mysql;
|
||||||
if (mysql->last_used_con == old_mysql)
|
if (mysql->last_used_con == old_mysql)
|
||||||
mysql->last_used_con = mysql;
|
mysql->last_used_con = mysql;
|
||||||
if (mysql->last_used_slave == old_mysql)
|
if (mysql->last_used_slave == old_mysql)
|
||||||
mysql->last_used_slave = mysql;
|
mysql->last_used_slave = mysql;
|
||||||
for (tmp_prev = mysql, tmp = mysql->next_slave;
|
#ifdef MYSQL_CLIENT /*should work in MYSQL_SERVER also, but doesn't */
|
||||||
tmp != old_mysql;tmp = tmp->next_slave)
|
|
||||||
{
|
{
|
||||||
tmp_prev = tmp;
|
MYSQL *tmp, *tmp_prev;
|
||||||
|
for (tmp_prev = mysql, tmp = mysql->next_slave;
|
||||||
|
tmp != old_mysql;tmp = tmp->next_slave)
|
||||||
|
{
|
||||||
|
tmp_prev = tmp;
|
||||||
|
}
|
||||||
|
tmp_prev->next_slave = mysql;
|
||||||
}
|
}
|
||||||
tmp_prev->next_slave = mysql;
|
|
||||||
}
|
|
||||||
#endif /*MYSQL_CLIENT*/
|
#endif /*MYSQL_CLIENT*/
|
||||||
|
}
|
||||||
|
|
||||||
my_bool mysql_reconnect(MYSQL *mysql)
|
my_bool mysql_reconnect(MYSQL *mysql)
|
||||||
{
|
{
|
||||||
@ -1897,9 +1901,6 @@ my_bool mysql_reconnect(MYSQL *mysql)
|
|||||||
tmp_mysql.options=mysql->options;
|
tmp_mysql.options=mysql->options;
|
||||||
bzero((char*) &mysql->options,sizeof(mysql->options));
|
bzero((char*) &mysql->options,sizeof(mysql->options));
|
||||||
tmp_mysql.rpl_pivot = mysql->rpl_pivot;
|
tmp_mysql.rpl_pivot = mysql->rpl_pivot;
|
||||||
#ifdef MYSQL_SERVER
|
|
||||||
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&mysql->net.read_timeout);
|
|
||||||
#endif
|
|
||||||
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
|
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
|
||||||
mysql->db, mysql->port, mysql->unix_socket,
|
mysql->db, mysql->port, mysql->unix_socket,
|
||||||
mysql->client_flag))
|
mysql->client_flag))
|
||||||
@ -1913,9 +1914,7 @@ my_bool mysql_reconnect(MYSQL *mysql)
|
|||||||
mysql->free_me=0;
|
mysql->free_me=0;
|
||||||
mysql_close(mysql);
|
mysql_close(mysql);
|
||||||
*mysql=tmp_mysql;
|
*mysql=tmp_mysql;
|
||||||
#ifdef MYSQL_CLIENT /*rpl000010 fails if #ifdef-s were removed*/
|
|
||||||
mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */
|
mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */
|
||||||
#endif
|
|
||||||
net_clear(&mysql->net);
|
net_clear(&mysql->net);
|
||||||
mysql->affected_rows= ~(my_ulonglong) 0;
|
mysql->affected_rows= ~(my_ulonglong) 0;
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
|
@ -15,19 +15,19 @@
|
|||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
#ifndef _client_settings_h
|
|
||||||
#define _client_settings_h
|
|
||||||
#include <thr_alarm.h>
|
#include <thr_alarm.h>
|
||||||
#include <mysql_embed.h>
|
|
||||||
#include <mysql_com.h>
|
|
||||||
|
|
||||||
|
extern char *mysql_unix_port;
|
||||||
|
|
||||||
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \
|
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
|
||||||
CLIENT_LOCAL_FILES | CLIENT_SECURE_CONNECTION)
|
| CLIENT_LOCAL_FILES | CLIENT_SECURE_CONNECTION)
|
||||||
|
|
||||||
|
|
||||||
extern ulong slave_net_timeout;
|
extern ulong slave_net_timeout;
|
||||||
#define init_sigpipe_variables
|
#define init_sigpipe_variables
|
||||||
#define set_sigpipe(mysql)
|
#define set_sigpipe(mysql)
|
||||||
#define reset_sigpipe(mysql)
|
#define reset_sigpipe(mysql)
|
||||||
#endif /* _client_settings_h */
|
|
||||||
|
#ifdef HAVE_SMEM
|
||||||
|
#undef HAVE_SMEM
|
||||||
|
#endif
|
||||||
|
@ -669,6 +669,7 @@ int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi)
|
|||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&slave_net_timeout);
|
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&slave_net_timeout);
|
||||||
|
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (char *)default_charset_info);
|
||||||
if (!mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
|
if (!mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
|
||||||
mi->port, 0, 0))
|
mi->port, 0, 0))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
|
@ -2950,6 +2950,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
|
|||||||
(reconnect ? mysql_reconnect(mysql) != 0:
|
(reconnect ? mysql_reconnect(mysql) != 0:
|
||||||
!(mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT,
|
!(mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT,
|
||||||
(char *)&thd->variables.net_read_timeout),
|
(char *)&thd->variables.net_read_timeout),
|
||||||
|
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (char *)default_charset_info),
|
||||||
mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
|
mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
|
||||||
mi->port, 0, client_flag))))
|
mi->port, 0, client_flag))))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user