Commit 16218fe5 authored by Konstantin Osipov's avatar Konstantin Osipov

Backport of:

------------------------------------------------------------
revno: 2476.981.1
committer: msvensson@pilot.mysql.com
timestamp: Mon 2007-11-26 19:03:23 +0100
message:
  Bug#31952 Remove undocumented mysql_rpl_* functions.
  - Functions removed + variables in st_mysql and st_mysql_options 
    renamed to "unused".
  - Code updated to work without those functions and variables
parent 93ab04da
......@@ -188,24 +188,10 @@ struct st_mysql_options {
unsigned long max_allowed_packet;
my_bool use_ssl; /* if to use SSL or not */
my_bool compress,named_pipe;
/*
On connect, find out the replication role of the server, and
establish connections to all the peers
*/
my_bool rpl_probe;
/*
Each call to mysql_real_query() will parse it to tell if it is a read
or a write, and direct it to the slave or the master
*/
my_bool rpl_parse;
/*
If set, never read from a master, only from slave, when doing
a read that is replication-aware
*/
my_bool no_master_reads;
#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)
my_bool separate_thread;
#endif
my_bool unused1;
my_bool unused2;
my_bool unused3;
my_bool unused4;
enum mysql_option methods_to_use;
char *client_ip;
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
......@@ -232,15 +218,6 @@ enum mysql_protocol_type
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
};
/*
There are three types of queries - the ones that have to go to
the master, the ones that go to a slave, and the adminstrative
type which must happen on the pivot connectioin
*/
enum mysql_rpl_type
{
MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
};
typedef struct character_set
{
......@@ -285,21 +262,8 @@ typedef struct st_mysql
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
/*
Set if this is the original connection, not a master or a slave we have
added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
*/
my_bool rpl_pivot;
/*
Pointers to the master, and the next slave connections, points to
itself if lone connection.
*/
struct st_mysql* master, *next_slave;
struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
/* needed for send/read/store/use result to work correctly with replication */
struct st_mysql* last_used_con;
my_bool unused1;
void *unused2, *unused3, *unused4, *unused5;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
......@@ -431,16 +395,6 @@ int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
/* perform query on master */
my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q,
unsigned long length);
my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q,
unsigned long length);
/* perform query on slave */
my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q,
unsigned long length);
my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q,
unsigned long length);
void STDCALL mysql_get_character_set_info(MYSQL *mysql,
MY_CHARSET_INFO *charset);
......@@ -462,37 +416,6 @@ mysql_set_local_infile_handler(MYSQL *mysql,
void
mysql_set_local_infile_default(MYSQL *mysql);
/*
enable/disable parsing of all queries to decide if they go on master or
slave
*/
void STDCALL mysql_enable_rpl_parse(MYSQL* mysql);
void STDCALL mysql_disable_rpl_parse(MYSQL* mysql);
/* get the value of the parse flag */
int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql);
/* enable/disable reads from master */
void STDCALL mysql_enable_reads_from_master(MYSQL* mysql);
void STDCALL mysql_disable_reads_from_master(MYSQL* mysql);
/* get the value of the master read flag */
my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql);
enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len);
/* discover the master and its slaves */
my_bool STDCALL mysql_rpl_probe(MYSQL* mysql);
/* set the master, close/free the old one, if it is not a pivot */
int STDCALL mysql_set_master(MYSQL* mysql, const char* host,
unsigned int port,
const char* user,
const char* passwd);
int STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
unsigned int port,
const char* user,
const char* passwd);
int STDCALL mysql_shutdown(MYSQL *mysql,
enum mysql_enum_shutdown_level
shutdown_level);
......@@ -807,7 +730,6 @@ MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
const char *user, const char *passwd);
int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
#endif
#define HAVE_MYSQL_REAL_CONNECT
......
......@@ -277,10 +277,10 @@ struct st_mysql_options {
unsigned long max_allowed_packet;
my_bool use_ssl;
my_bool compress,named_pipe;
my_bool rpl_probe;
my_bool rpl_parse;
my_bool no_master_reads;
my_bool separate_thread;
my_bool unused1;
my_bool unused2;
my_bool unused3;
my_bool unused4;
enum mysql_option methods_to_use;
char *client_ip;
my_bool secure_auth;
......@@ -301,10 +301,6 @@ enum mysql_protocol_type
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
};
enum mysql_rpl_type
{
MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
};
typedef struct character_set
{
unsigned int number;
......@@ -344,10 +340,8 @@ typedef struct st_mysql
my_bool free_me;
my_bool reconnect;
char scramble[20 +1];
my_bool rpl_pivot;
struct st_mysql* master, *next_slave;
struct st_mysql* last_used_slave;
struct st_mysql* last_used_con;
my_bool unused1;
void *unused2, *unused3, *unused4, *unused5;
LIST *stmts;
const struct st_mysql_methods *methods;
void *thd;
......@@ -371,20 +365,6 @@ typedef struct st_mysql_res {
my_bool unbuffered_fetch_cancelled;
void *extension;
} MYSQL_RES;
typedef struct st_mysql_manager
{
NET net;
char *host, *user, *passwd;
char *net_buf, *net_buf_pos, *net_data_end;
unsigned int port;
int cmd_status;
int last_errno;
int net_buf_size;
my_bool free_me;
my_bool eof;
char last_error[256];
void *extension;
} MYSQL_MANAGER;
typedef struct st_mysql_parameters
{
unsigned long *p_max_allowed_packet;
......@@ -437,14 +417,6 @@ int mysql_real_query(MYSQL *mysql, const char *q,
unsigned long length);
MYSQL_RES * mysql_store_result(MYSQL *mysql);
MYSQL_RES * mysql_use_result(MYSQL *mysql);
my_bool mysql_master_query(MYSQL *mysql, const char *q,
unsigned long length);
my_bool mysql_master_send_query(MYSQL *mysql, const char *q,
unsigned long length);
my_bool mysql_slave_query(MYSQL *mysql, const char *q,
unsigned long length);
my_bool mysql_slave_send_query(MYSQL *mysql, const char *q,
unsigned long length);
void mysql_get_character_set_info(MYSQL *mysql,
MY_CHARSET_INFO *charset);
void
......@@ -459,22 +431,6 @@ mysql_set_local_infile_handler(MYSQL *mysql,
void *);
void
mysql_set_local_infile_default(MYSQL *mysql);
void mysql_enable_rpl_parse(MYSQL* mysql);
void mysql_disable_rpl_parse(MYSQL* mysql);
int mysql_rpl_parse_enabled(MYSQL* mysql);
void mysql_enable_reads_from_master(MYSQL* mysql);
void mysql_disable_reads_from_master(MYSQL* mysql);
my_bool mysql_reads_from_master_enabled(MYSQL* mysql);
enum mysql_rpl_type mysql_rpl_query_type(const char* q, int len);
my_bool mysql_rpl_probe(MYSQL* mysql);
int mysql_set_master(MYSQL* mysql, const char* host,
unsigned int port,
const char* user,
const char* passwd);
int mysql_add_slave(MYSQL* mysql, const char* host,
unsigned int port,
const char* user,
const char* passwd);
int mysql_shutdown(MYSQL *mysql,
enum mysql_enum_shutdown_level
shutdown_level);
......@@ -521,18 +477,6 @@ void mysql_debug(const char *debug);
void myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int mysql_thread_safe(void);
my_bool mysql_embedded(void);
MYSQL_MANAGER* mysql_manager_init(MYSQL_MANAGER* con);
MYSQL_MANAGER* mysql_manager_connect(MYSQL_MANAGER* con,
const char* host,
const char* user,
const char* passwd,
unsigned int port);
void mysql_manager_close(MYSQL_MANAGER* con);
int mysql_manager_command(MYSQL_MANAGER* con,
const char* cmd, int cmd_len);
int mysql_manager_fetch_line(MYSQL_MANAGER* con,
char* res_buf,
int res_buf_size);
my_bool mysql_read_query_result(MYSQL *mysql);
enum enum_mysql_stmt_state
{
......
......@@ -249,16 +249,6 @@ void STDCALL mysql_thread_end()
#endif
}
/*
Let the user specify that we don't want SIGPIPE; This doesn't however work
with threaded applications as we can have multiple read in progress.
*/
static MYSQL* spawn_init(MYSQL* parent, const char* host,
unsigned int port,
const char* user,
const char* passwd);
/*
Expand wildcard to a sql string
......@@ -320,7 +310,7 @@ mysql_debug(const char *debug __attribute__((unused)))
/**************************************************************************
Close the server connection if we get a SIGPIPE
Ignore SIGPIPE handler
ARGSUSED
**************************************************************************/
......@@ -333,305 +323,6 @@ my_pipe_sig_handler(int sig __attribute__((unused)))
#endif
}
/* perform query on master */
my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q,
unsigned long length)
{
DBUG_ENTER("mysql_master_query");
if (mysql_master_send_query(mysql, q, length))
DBUG_RETURN(1);
DBUG_RETURN((*mysql->methods->read_query_result)(mysql));
}
my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q,
unsigned long length)
{
MYSQL *master = mysql->master;
DBUG_ENTER("mysql_master_send_query");
if (!master->net.vio && !mysql_real_connect(master,0,0,0,0,0,0,0))
DBUG_RETURN(1);
master->reconnect= 1;
mysql->last_used_con = master;
DBUG_RETURN(simple_command(master, COM_QUERY, (const uchar*) q, length, 1));
}
/* perform query on slave */
my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q,
unsigned long length)
{
DBUG_ENTER("mysql_slave_query");
if (mysql_slave_send_query(mysql, q, length))
DBUG_RETURN(1);
DBUG_RETURN((*mysql->methods->read_query_result)(mysql));
}
my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q,
unsigned long length)
{
MYSQL* last_used_slave, *slave_to_use = 0;
DBUG_ENTER("mysql_slave_send_query");
if ((last_used_slave = mysql->last_used_slave))
slave_to_use = last_used_slave->next_slave;
else
slave_to_use = mysql->next_slave;
/*
Next_slave is always safe to use - we have a circular list of slaves
if there are no slaves, mysql->next_slave == mysql
*/
mysql->last_used_con = mysql->last_used_slave = slave_to_use;
if (!slave_to_use->net.vio && !mysql_real_connect(slave_to_use, 0,0,0,
0,0,0,0))
DBUG_RETURN(1);
slave_to_use->reconnect= 1;
DBUG_RETURN(simple_command(slave_to_use, COM_QUERY, (const uchar*) q,
length, 1));
}
/* enable/disable parsing of all queries to decide
if they go on master or slave */
void STDCALL mysql_enable_rpl_parse(MYSQL* mysql)
{
mysql->options.rpl_parse = 1;
}
void STDCALL mysql_disable_rpl_parse(MYSQL* mysql)
{
mysql->options.rpl_parse = 0;
}
/* get the value of the parse flag */
int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql)
{
return mysql->options.rpl_parse;
}
/* enable/disable reads from master */
void STDCALL mysql_enable_reads_from_master(MYSQL* mysql)
{
mysql->options.no_master_reads = 0;
}
void STDCALL mysql_disable_reads_from_master(MYSQL* mysql)
{
mysql->options.no_master_reads = 1;
}
/* get the value of the master read flag */
my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql)
{
return !(mysql->options.no_master_reads);
}
/*
We may get an error while doing replication internals.
In this case, we add a special explanation to the original
error
*/
static void expand_error(MYSQL* mysql, int error)
{
char tmp[MYSQL_ERRMSG_SIZE];
char *p;
uint err_length;
strmake(tmp, mysql->net.last_error, MYSQL_ERRMSG_SIZE-1);
p = strmake(mysql->net.last_error, ER(error), MYSQL_ERRMSG_SIZE-1);
err_length= (uint) (p - mysql->net.last_error);
strmake(p, tmp, MYSQL_ERRMSG_SIZE-1 - err_length);
mysql->net.last_errno = error;
}
/*
This function assumes we have just called SHOW SLAVE STATUS and have
read the given result and row
*/
static my_bool get_master(MYSQL* mysql, MYSQL_RES* res, MYSQL_ROW row)
{
MYSQL* master;
DBUG_ENTER("get_master");
if (mysql_num_fields(res) < 3)
DBUG_RETURN(1); /* safety */
/* use the same username and password as the original connection */
if (!(master = spawn_init(mysql, row[0], atoi(row[2]), 0, 0)))
DBUG_RETURN(1);
mysql->master = master;
DBUG_RETURN(0);
}
/*
Assuming we already know that mysql points to a master connection,
retrieve all the slaves
*/
static my_bool get_slaves_from_master(MYSQL* mysql)
{
MYSQL_RES* res = 0;
MYSQL_ROW row;
my_bool error = 1;
int has_auth_info;
int port_ind;
DBUG_ENTER("get_slaves_from_master");
if (!mysql->net.vio && !mysql_real_connect(mysql,0,0,0,0,0,0,0))
{
expand_error(mysql, CR_PROBE_MASTER_CONNECT);
DBUG_RETURN(1);
}
mysql->reconnect= 1;
if (mysql_query(mysql, "SHOW SLAVE HOSTS") ||
!(res = mysql_store_result(mysql)))
{
expand_error(mysql, CR_PROBE_SLAVE_HOSTS);
DBUG_RETURN(1);
}
switch (mysql_num_fields(res)) {
case 5:
has_auth_info = 0;
port_ind=2;
break;
case 7:
has_auth_info = 1;
port_ind=4;
break;
default:
goto err;
}
while ((row = mysql_fetch_row(res)))
{
MYSQL* slave;
const char* tmp_user, *tmp_pass;
if (has_auth_info)
{
tmp_user = row[2];
tmp_pass = row[3];
}
else
{
tmp_user = mysql->user;
tmp_pass = mysql->passwd;
}
if (!(slave = spawn_init(mysql, row[1], atoi(row[port_ind]),
tmp_user, tmp_pass)))
goto err;
/* Now add slave into the circular linked list */
slave->next_slave = mysql->next_slave;
mysql->next_slave = slave;
}
error = 0;
err:
if (res)
mysql_free_result(res);
DBUG_RETURN(error);
}
my_bool STDCALL mysql_rpl_probe(MYSQL* mysql)
{
MYSQL_RES *res= 0;
MYSQL_ROW row;
my_bool error= 1;
DBUG_ENTER("mysql_rpl_probe");
/*
First determine the replication role of the server we connected to
the most reliable way to do this is to run SHOW SLAVE STATUS and see
if we have a non-empty master host. This is still not fool-proof -
it is not a sin to have a master that has a dormant slave thread with
a non-empty master host. However, it is more reliable to check
for empty master than whether the slave thread is actually running
*/
if (mysql_query(mysql, "SHOW SLAVE STATUS") ||
!(res = mysql_store_result(mysql)))
{
expand_error(mysql, CR_PROBE_SLAVE_STATUS);
DBUG_RETURN(1);
}
row= mysql_fetch_row(res);
/*
Check master host for emptiness/NULL
For MySQL 4.0 it's enough to check for row[0]
*/
if (row && row[0] && *(row[0]))
{
/* this is a slave, ask it for the master */
if (get_master(mysql, res, row) || get_slaves_from_master(mysql))
goto err;
}
else
{
mysql->master = mysql;
if (get_slaves_from_master(mysql))
goto err;
}
error = 0;
err:
if (res)
mysql_free_result(res);
DBUG_RETURN(error);
}
/*
Make a not so fool-proof decision on where the query should go, to
the master or the slave. Ideally the user should always make this
decision himself with mysql_master_query() or mysql_slave_query().
However, to be able to more easily port the old code, we support the
option of an educated guess - this should work for most applications,
however, it may make the wrong decision in some particular cases. If
that happens, the user would have to change the code to call
mysql_master_query() or mysql_slave_query() explicitly in the place
where we have made the wrong decision
*/
enum mysql_rpl_type
STDCALL mysql_rpl_query_type(const char* q, int len)
{
const char *q_end= q + len;
for (; q < q_end; ++q)
{
char c;
if (my_isalpha(&my_charset_latin1, (c= *q)))
{
switch (my_tolower(&my_charset_latin1,c)) {
case 'i': /* insert */
case 'u': /* update or unlock tables */
case 'l': /* lock tables or load data infile */
case 'd': /* drop or delete */
case 'a': /* alter */
return MYSQL_RPL_MASTER;
case 'c': /* create or check */
return my_tolower(&my_charset_latin1,q[1]) == 'h' ? MYSQL_RPL_ADMIN :
MYSQL_RPL_MASTER;
case 's': /* select or show */
return my_tolower(&my_charset_latin1,q[1]) == 'h' ? MYSQL_RPL_ADMIN :
MYSQL_RPL_SLAVE;
case 'f': /* flush */
case 'r': /* repair */
case 'g': /* grant */
return MYSQL_RPL_ADMIN;
default:
return MYSQL_RPL_SLAVE;
}
}
}
return MYSQL_RPL_MASTER; /* By default, send to master */
}
/**************************************************************************
Connect to sql server
......@@ -1093,68 +784,6 @@ mysql_query(MYSQL *mysql, const char *query)
}
static MYSQL* spawn_init(MYSQL* parent, const char* host,
unsigned int port, const char* user,
const char* passwd)
{
MYSQL* child;
DBUG_ENTER("spawn_init");
if (!(child= mysql_init(0)))
DBUG_RETURN(0);
child->options.user= my_strdup((user) ? user :
(parent->user ? parent->user :
parent->options.user), MYF(0));
child->options.password= my_strdup((passwd) ? passwd :
(parent->passwd ?
parent->passwd :
parent->options.password), MYF(0));
child->options.port= port;
child->options.host= my_strdup((host) ? host :
(parent->host ?
parent->host :
parent->options.host), MYF(0));
if (parent->db)
child->options.db= my_strdup(parent->db, MYF(0));
else if (parent->options.db)
child->options.db= my_strdup(parent->options.db, MYF(0));
/*
rpl_pivot is set to 1 in mysql_init(); Reset it as we are not doing
replication here
*/
child->rpl_pivot= 0;
DBUG_RETURN(child);
}
int
STDCALL mysql_set_master(MYSQL* mysql, const char* host,
unsigned int port, const char* user,
const char* passwd)
{
if (mysql->master != mysql && !mysql->master->rpl_pivot)
mysql_close(mysql->master);
if (!(mysql->master = spawn_init(mysql, host, port, user, passwd)))
return 1;
return 0;
}
int
STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
unsigned int port,
const char* user,
const char* passwd)
{
MYSQL* slave;
if (!(slave = spawn_init(mysql, host, port, user, passwd)))
return 1;
slave->next_slave = mysql->next_slave;
mysql->next_slave = slave;
return 0;
}
/**************************************************************************
Return next field of the query results
**************************************************************************/
......@@ -1483,17 +1112,17 @@ MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res)
unsigned int STDCALL mysql_field_count(MYSQL *mysql)
{
return mysql->last_used_con->field_count;
return mysql->field_count;
}
my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql)
{
return mysql->last_used_con->affected_rows;
return mysql->affected_rows;
}
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
{
return mysql->last_used_con->insert_id;
return mysql->insert_id;
}
const char *STDCALL mysql_sqlstate(MYSQL *mysql)
......@@ -1858,7 +1487,6 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
MYSQL_DATA *fields_data;
DBUG_ENTER("cli_read_prepare_result");
mysql= mysql->last_used_con;
if ((packet_length= cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(1);
mysql->warning_count= 0;
......@@ -2092,7 +1720,7 @@ static void alloc_stmt_fields(MYSQL_STMT *stmt)
{
MYSQL_FIELD *fields, *field, *end;
MEM_ROOT *alloc= &stmt->mem_root;
MYSQL *mysql= stmt->mysql->last_used_con;
MYSQL *mysql= stmt->mysql;
stmt->field_count= mysql->field_count;
......@@ -2479,7 +2107,6 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length)
DBUG_ENTER("execute");
DBUG_DUMP("packet", (uchar *) packet, length);
mysql->last_used_con= mysql;
int4store(buff, stmt->stmt_id); /* Send stmt id to server */
buff[4]= (char) stmt->flags;
int4store(buff+5, 1); /* iteration count */
......@@ -4689,7 +4316,6 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
}
net = &mysql->net;
mysql= mysql->last_used_con;
while ((pkt_len= cli_safe_read(mysql)) != packet_error)
{
......@@ -4787,8 +4413,6 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
DBUG_RETURN(1);
}
mysql= mysql->last_used_con;
if (!stmt->field_count)
DBUG_RETURN(0);
......@@ -5193,8 +4817,7 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql)
my_bool res;
DBUG_ENTER("mysql_more_results");
res= ((mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) ?
1: 0);
res= ((mysql->server_status & SERVER_MORE_RESULTS_EXISTS) ? 1: 0);
DBUG_PRINT("exit",("More results exists ? %d", res));
DBUG_RETURN(res);
}
......@@ -5216,7 +4839,7 @@ int STDCALL mysql_next_result(MYSQL *mysql)
net_clear_error(&mysql->net);
mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
if (mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
DBUG_RETURN((*mysql->methods->next_result)(mysql));
DBUG_RETURN(-1); /* No more results */
......
......@@ -1036,7 +1036,6 @@ static const char *default_options[]=
"ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath",
"character-sets-dir", "default-character-set", "interactive-timeout",
"connect-timeout", "local-infile", "disable-local-infile",
"replication-probe", "enable-reads-from-master", "repl-parse-query",
"ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name",
"multi-results", "multi-statements", "multi-queries", "secure-auth",
"report-data-truncation",
......@@ -1214,24 +1213,11 @@ void mysql_read_default_options(struct st_mysql_options *options,
case 22:
options->client_flag&= ~CLIENT_LOCAL_FILES;
break;
case 23: /* replication probe */
#ifndef TO_BE_DELETED
options->rpl_probe= 1;
#endif
break;
case 24: /* enable-reads-from-master */
options->no_master_reads= 0;
break;
case 25: /* repl-parse-query */
#ifndef TO_BE_DELETED
options->rpl_parse= 1;
#endif
break;
case 27:
case 24: /* max-allowed-packet */
if (opt_arg)
options->max_allowed_packet= atoi(opt_arg);
break;
case 28: /* protocol */
case 25: /* protocol */
if ((options->protocol= find_type(opt_arg,
&sql_protocol_typelib,0)) <= 0)
{
......@@ -1239,24 +1225,24 @@ void mysql_read_default_options(struct st_mysql_options *options,
exit(1);
}
break;
case 29: /* shared_memory_base_name */
case 26: /* shared_memory_base_name */
#ifdef HAVE_SMEM
if (options->shared_memory_base_name != def_shared_memory_base_name)
my_free(options->shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
options->shared_memory_base_name=my_strdup(opt_arg,MYF(MY_WME));
#endif
break;
case 30:
case 27: /* multi-results */
options->client_flag|= CLIENT_MULTI_RESULTS;
break;
case 31:
case 32:
case 28: /* multi-statements */
case 29: /* multi-queries */
options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS;
break;
case 33: /* secure-auth */
case 30: /* secure-auth */
options->secure_auth= TRUE;
break;
case 34: /* report-data-truncation */
case 31: /* report-data-truncation */
options->report_data_truncation= opt_arg ? test(atoi(opt_arg)) : 1;
break;
default:
......@@ -1583,16 +1569,8 @@ mysql_init(MYSQL *mysql)
else
bzero((char*) (mysql), sizeof(*(mysql)));
mysql->options.connect_timeout= CONNECT_TIMEOUT;
mysql->last_used_con= mysql->next_slave= mysql->master = mysql;
mysql->charset=default_client_charset_info;
strmov(mysql->net.sqlstate, not_error_sqlstate);
/*
By default, we are a replication pivot. The caller must reset it
after we return if this is not the case.
*/
#ifndef TO_BE_DELETED
mysql->rpl_pivot = 1;
#endif
/*
Only enable LOAD DATA INFILE by default if configured with
......@@ -2533,11 +2511,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
mysql->reconnect=reconnect;
}
#ifndef TO_BE_DELETED
if (mysql->options.rpl_probe && mysql_rpl_probe(mysql))
goto error;
#endif
DBUG_PRINT("exit", ("Mysql handler: 0x%lx", (long) mysql));
reset_sigpipe(mysql);
DBUG_RETURN(mysql);
......@@ -2559,28 +2532,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
}
/* needed when we move MYSQL structure to a different address */
#ifndef TO_BE_DELETED
static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql)
{
MYSQL *tmp, *tmp_prev;
if (mysql->master == old_mysql)
mysql->master= mysql;
if (mysql->last_used_con == old_mysql)
mysql->last_used_con= mysql;
if (mysql->last_used_slave == old_mysql)
mysql->last_used_slave= mysql;
for (tmp_prev = mysql, tmp = mysql->next_slave;
tmp != old_mysql;tmp = tmp->next_slave)
{
tmp_prev= tmp;
}
tmp_prev->next_slave= mysql;
}
#endif
my_bool mysql_reconnect(MYSQL *mysql)
{
MYSQL tmp_mysql;
......@@ -2599,8 +2550,7 @@ my_bool mysql_reconnect(MYSQL *mysql)
mysql_init(&tmp_mysql);
tmp_mysql.options= mysql->options;
tmp_mysql.options.my_cnf_file= tmp_mysql.options.my_cnf_group= 0;
tmp_mysql.rpl_pivot= mysql->rpl_pivot;
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
mysql->db, mysql->port, mysql->unix_socket,
mysql->client_flag | CLIENT_REMEMBER_OPTIONS))
......@@ -2634,7 +2584,6 @@ my_bool mysql_reconnect(MYSQL *mysql)
mysql->free_me=0;
mysql_close(mysql);
*mysql=tmp_mysql;
mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */
net_clear(&mysql->net, 1);
mysql->affected_rows= ~(my_ulonglong) 0;
DBUG_RETURN(0);
......@@ -2812,23 +2761,6 @@ void STDCALL mysql_close(MYSQL *mysql)
mysql_close_free_options(mysql);
mysql_close_free(mysql);
mysql_detach_stmt_list(&mysql->stmts, "mysql_close");
#ifndef TO_BE_DELETED
/* free/close slave list */
if (mysql->rpl_pivot)
{
MYSQL* tmp;
for (tmp = mysql->next_slave; tmp != mysql; )
{
/* trick to avoid following freed pointer */
MYSQL* tmp1 = tmp->next_slave;
mysql_close(tmp);
tmp = tmp1;
}
mysql->rpl_pivot=0;
}
#endif
if (mysql != mysql->master)
mysql_close(mysql->master);
#ifndef MYSQL_SERVER
if (mysql->thd)
(*mysql->methods->free_embedded_thd)(mysql);
......@@ -2848,12 +2780,6 @@ static my_bool cli_read_query_result(MYSQL *mysql)
ulong length;
DBUG_ENTER("cli_read_query_result");
/*
Read from the connection which we actually used, which
could differ from the original connection if we have slaves
*/
mysql = mysql->last_used_con;
if ((length = cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(1);
free_old_query(mysql); /* Free old result */
......@@ -2928,23 +2854,6 @@ int STDCALL
mysql_send_query(MYSQL* mysql, const char* query, ulong length)
{
DBUG_ENTER("mysql_send_query");
DBUG_PRINT("enter",("rpl_parse: %d rpl_pivot: %d",
mysql->options.rpl_parse, mysql->rpl_pivot));
#ifndef TO_BE_DELETED
if (mysql->options.rpl_parse && mysql->rpl_pivot)
{
switch (mysql_rpl_query_type(query, length)) {
case MYSQL_RPL_MASTER:
DBUG_RETURN(mysql_master_send_query(mysql, query, length));
case MYSQL_RPL_SLAVE:
DBUG_RETURN(mysql_slave_send_query(mysql, query, length));
case MYSQL_RPL_ADMIN:
break; /* fall through */
}
}
mysql->last_used_con = mysql;
#endif
DBUG_RETURN(simple_command(mysql, COM_QUERY, (uchar*) query, length, 1));
}
......@@ -2971,8 +2880,7 @@ MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
{
MYSQL_RES *result;
DBUG_ENTER("mysql_store_result");
/* read from the actually used connection */
mysql = mysql->last_used_con;
if (!mysql->fields)
DBUG_RETURN(0);
if (mysql->status != MYSQL_STATUS_GET_RESULT)
......@@ -3027,8 +2935,6 @@ static MYSQL_RES * cli_use_result(MYSQL *mysql)
MYSQL_RES *result;
DBUG_ENTER("cli_use_result");
mysql = mysql->last_used_con;
if (!mysql->fields)
DBUG_RETURN(0);
if (mysql->status != MYSQL_STATUS_GET_RESULT)
......
......@@ -2892,7 +2892,7 @@ int ha_federated::info(uint flag)
}
if (flag & HA_STATUS_AUTO)
stats.auto_increment_value= mysql->last_used_con->insert_id;
stats.auto_increment_value= mysql->insert_id;
mysql_free_result(result);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment