List:Commits« Previous MessageNext Message »
From:konstantin Date:June 1 2007 9:42pm
Subject:bk commit into 5.1 tree (kostja:1.2540)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of kostja. When kostja does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-06-01 23:42:00+04:00, kostja@bodhi.(none) +7 -0
  WL#2872 "Make client library extensible" tech. preview.

  include/mysql.h@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +62 -99
    WL#2872 "Make client library extensible" tech. preview.

  include/sql_common.h@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +8 -6
    WL#2872 "Make client library extensible" tech. preview.

  libmysql/Makefile.shared@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +1 -1
    WL#2872 "Make client library extensible" tech. preview.

  libmysql/client_settings.h@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +13 -10
    WL#2872 "Make client library extensible" tech. preview.

  libmysql/libmysql.c@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +171 -498
    WL#2872 "Make client library extensible" tech. preview.

  sql-common/client.c@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +115 -154
    WL#2872 "Make client library extensible" tech. preview.

  sql/slave.cc@stripped, 2007-06-01 23:41:57+04:00, kostja@bodhi.(none) +1 -1
    WL#2872 "Make client library extensible" tech. preview.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	kostja
# Host:	bodhi.(none)
# Root:	/opt/local/work/mysql-5.1-libmysql

--- 1.180/include/mysql.h	2007-05-24 02:39:16 +04:00
+++ 1.181/include/mysql.h	2007-06-01 23:41:57 +04:00
@@ -248,7 +248,7 @@
 struct st_mysql_methods;
 struct st_mysql_stmt;
 
-typedef struct st_mysql
+struct st_mysql_impl
 {
   NET		net;			/* Communication parameters */
   unsigned char	*connector_fd;		/* ConnectorFd for SSL */
@@ -271,27 +271,12 @@
   unsigned int	warning_count;
   struct st_mysql_options options;
   enum mysql_status status;
-  my_bool	free_me;		/* If free in mysql_close */
+  my_bool	free_handle;		/* If free in mysql_close */
   my_bool	reconnect;		/* set to 1 if automatic reconnect */
 
   /* 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;
-
   LIST  *stmts;                     /* list of all statements */
   const struct st_mysql_methods *methods;
   void *thd;
@@ -300,19 +285,24 @@
     from mysql_stmt_close if close had to cancel result set of this object.
   */
   my_bool *unbuffered_fetch_owner;
-#if defined(EMBEDDED_LIBRARY) || defined(EMBEDDED_LIBRARY_COMPATIBLE) || MYSQL_VERSION_ID
>= 50100
   /* needed for embedded server - no net buffer to store the 'info' */
   char *info_buffer;
-#endif
+};
+
+
+typedef struct st_mysql
+{
+  struct st_mysql_impl *impl;
 } MYSQL;
 
+
 typedef struct st_mysql_res {
   my_ulonglong row_count;
   MYSQL_FIELD	*fields;
   MYSQL_DATA	*data;
   MYSQL_ROWS	*data_cursor;
   unsigned long *lengths;		/* column lengths of current row */
-  MYSQL		*handle;		/* for unbuffered reads */
+  struct st_mysql_impl *mysql;		/* for unbuffered reads */
   MEM_ROOT	field_alloc;
   unsigned int	field_count, current_field;
   MYSQL_ROW	row;			/* If unbuffered read */
@@ -342,7 +332,7 @@
   NET net;
   char *host,*user,*passwd;
   unsigned int port;
-  my_bool free_me;
+  my_bool free_handle;
   my_bool eof;
   int cmd_status;
   int last_errno;
@@ -459,7 +449,7 @@
 #define LOCAL_INFILE_ERROR_LEN 512
 
 void
-mysql_set_local_infile_handler(MYSQL *mysql,
+mysql_set_local_infile_handler(struct st_mysql_impl *mysql,
                                int (*local_infile_init)(void **, const char *,
                             void *),
                                int (*local_infile_read)(void *, char *,
@@ -470,61 +460,31 @@
                                void *);
 
 void
-mysql_set_local_infile_default(MYSQL *mysql);
+mysql_set_local_infile_default(struct st_mysql_impl *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,
+int		STDCALL mysql_shutdown(MYSQL *handle,
                                        enum mysql_enum_shutdown_level
                                        shutdown_level);
-int		STDCALL mysql_dump_debug_info(MYSQL *mysql);
-int		STDCALL mysql_refresh(MYSQL *mysql,
+int		STDCALL mysql_dump_debug_info(MYSQL *handle);
+int		STDCALL mysql_refresh(MYSQL *handle,
 				     unsigned int refresh_options);
-int		STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
-int		STDCALL mysql_set_server_option(MYSQL *mysql,
+int		STDCALL mysql_kill(MYSQL *handle,unsigned long pid);
+int		STDCALL mysql_set_server_option(MYSQL *handle,
 						enum enum_mysql_set_option
 						option);
-int		STDCALL mysql_ping(MYSQL *mysql);
-const char *	STDCALL mysql_stat(MYSQL *mysql);
-const char *	STDCALL mysql_get_server_info(MYSQL *mysql);
+int		STDCALL mysql_ping(MYSQL *handle);
+const char *	STDCALL mysql_stat(MYSQL *handle);
+const char *	STDCALL mysql_get_server_info(MYSQL *handle);
 const char *	STDCALL mysql_get_client_info(void);
 unsigned long	STDCALL mysql_get_client_version(void);
-const char *	STDCALL mysql_get_host_info(MYSQL *mysql);
-unsigned long	STDCALL mysql_get_server_version(MYSQL *mysql);
-unsigned int	STDCALL mysql_get_proto_info(MYSQL *mysql);
-MYSQL_RES *	STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
-MYSQL_RES *	STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
-MYSQL_RES *	STDCALL mysql_list_processes(MYSQL *mysql);
-int		STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
+const char *	STDCALL mysql_get_host_info(MYSQL *handle);
+unsigned long	STDCALL mysql_get_server_version(MYSQL *handle);
+unsigned int	STDCALL mysql_get_proto_info(MYSQL *handle);
+MYSQL_RES *	STDCALL mysql_list_dbs(MYSQL *handle,const char *wild);
+MYSQL_RES *	STDCALL mysql_list_tables(MYSQL *handle,const char *wild);
+MYSQL_RES *	STDCALL mysql_list_processes(MYSQL *handle);
+int		STDCALL mysql_options(MYSQL *handle,enum mysql_option option,
 				      const void *arg);
 void		STDCALL mysql_free_result(MYSQL_RES *result);
 void		STDCALL mysql_data_seek(MYSQL_RES *result,
@@ -536,17 +496,17 @@
 MYSQL_ROW	STDCALL mysql_fetch_row(MYSQL_RES *result);
 unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
 MYSQL_FIELD *	STDCALL mysql_fetch_field(MYSQL_RES *result);
-MYSQL_RES *     STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
+MYSQL_RES *     STDCALL mysql_list_fields(MYSQL *handle, const char *table,
 					  const char *wild);
 unsigned long	STDCALL mysql_escape_string(char *to,const char *from,
 					    unsigned long from_length);
 unsigned long	STDCALL mysql_hex_string(char *to,const char *from,
                                          unsigned long from_length);
-unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
+unsigned long STDCALL mysql_real_escape_string(MYSQL *handle,
 					       char *to,const char *from,
 					       unsigned long length);
 void		STDCALL mysql_debug(const char *debug);
-char *		STDCALL mysql_odbc_escape_string(MYSQL *mysql,
+char *		STDCALL mysql_odbc_escape_string(MYSQL *handle,
 						 char *to,
 						 unsigned long to_length,
 						 const char *from,
@@ -556,7 +516,7 @@
 						 (*extend_buffer)
 						 (void *, char *to,
 						  unsigned long *length));
-void 		STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
+void 		STDCALL myodbc_remove_escape(MYSQL *handle,char *name);
 unsigned int	STDCALL mysql_thread_safe(void);
 my_bool		STDCALL mysql_embedded(void);
 MYSQL_MANAGER*  STDCALL mysql_manager_init(MYSQL_MANAGER* con);  
@@ -571,7 +531,7 @@
 int             STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con,
 						  char* res_buf,
 						 int res_buf_size);
-my_bool         STDCALL mysql_read_query_result(MYSQL *mysql);
+my_bool         STDCALL mysql_read_query_result(MYSQL *handle);
 
 
 /*
@@ -682,7 +642,7 @@
 {
   MEM_ROOT       mem_root;             /* root allocations */
   LIST           list;                 /* list to keep track of all stmts */
-  MYSQL          *mysql;               /* connection handle */
+  struct st_mysql_impl *mysql;               /* connection handle */
   MYSQL_BIND     *params;              /* input parameters */
   MYSQL_BIND     *bind;                /* output parameters */
   MYSQL_FIELD    *fields;              /* result set metadata */
@@ -749,8 +709,8 @@
 
 typedef struct st_mysql_methods
 {
-  my_bool (*read_query_result)(MYSQL *mysql);
-  my_bool (*advanced_command)(MYSQL *mysql,
+  my_bool (*read_query_result)(struct st_mysql_impl *mysql);
+  my_bool (*advanced_command)(struct st_mysql_impl *mysql,
 			      enum enum_server_command command,
 			      const unsigned char *header,
 			      unsigned long header_length,
@@ -758,28 +718,31 @@
 			      unsigned long arg_length,
 			      my_bool skip_check,
                               MYSQL_STMT *stmt);
-  MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
+  MYSQL_DATA *(*read_rows)(struct st_mysql_impl *mysql,
+                           MYSQL_FIELD *mysql_fields,
 			   unsigned int fields);
-  MYSQL_RES * (*use_result)(MYSQL *mysql);
-  void (*fetch_lengths)(unsigned long *to, 
+  MYSQL_RES * (*use_result)(struct st_mysql_impl *mysql);
+  void (*fetch_lengths)(unsigned long *to,
 			MYSQL_ROW column, unsigned int field_count);
-  void (*flush_use_result)(MYSQL *mysql);
+  void (*flush_use_result)(struct st_mysql_impl *mysql);
 #if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
-  MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
-  my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
+  MYSQL_FIELD * (*list_fields)(struct st_mysql_impl *mysql);
+  my_bool (*read_prepare_result)(struct st_mysql_impl *mysql,
+                                 MYSQL_STMT *stmt);
   int (*stmt_execute)(MYSQL_STMT *stmt);
   int (*read_binary_rows)(MYSQL_STMT *stmt);
-  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
-  void (*free_embedded_thd)(MYSQL *mysql);
-  const char *(*read_statistics)(MYSQL *mysql);
-  my_bool (*next_result)(MYSQL *mysql);
-  int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
+  int (*unbuffered_fetch)(struct st_mysql_impl *mysql, char **row);
+  void (*free_embedded_thd)(struct st_mysql_impl *mysql);
+  const char *(*read_statistics)(struct st_mysql_impl *mysql);
+  my_bool (*next_result)(struct st_mysql_impl *mysql);
+  int (*read_change_user_result)(struct st_mysql_impl *mysql,
+                                 char *buff, const char *passwd);
   int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
 #endif
 } MYSQL_METHODS;
 
 
-MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
+MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *handle);
 int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
                                unsigned long length);
 int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
@@ -818,26 +781,26 @@
 my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
 unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
 
-my_bool STDCALL mysql_commit(MYSQL * mysql);
-my_bool STDCALL mysql_rollback(MYSQL * mysql);
-my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
-my_bool STDCALL mysql_more_results(MYSQL *mysql);
-int STDCALL mysql_next_result(MYSQL *mysql);
-void STDCALL mysql_close(MYSQL *sock);
+my_bool STDCALL mysql_commit(MYSQL *handle);
+my_bool STDCALL mysql_rollback(MYSQL *handle);
+my_bool STDCALL mysql_autocommit(MYSQL *handle, my_bool auto_mode);
+my_bool STDCALL mysql_more_results(MYSQL *handle);
+int STDCALL mysql_next_result(MYSQL *handle);
+void STDCALL mysql_close(MYSQL *handle);
 
 
 /* status return codes */
 #define MYSQL_NO_DATA        100
 #define MYSQL_DATA_TRUNCATED 101
 
-#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
+#define mysql_reload(handle) mysql_refresh((handle),REFRESH_GRANT)
 
 #ifdef USE_OLD_FUNCTIONS
-MYSQL *		STDCALL mysql_connect(MYSQL *mysql, const char *host,
+MYSQL *		STDCALL mysql_connect(MYSQL *handle, 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)
+int		STDCALL mysql_create_db(MYSQL *handle, const char *DB);
+int		STDCALL mysql_drop_db(MYSQL *handle, const char *DB);
+#define	 mysql_reload(handle) mysql_refresh((handle),REFRESH_GRANT)
 #endif
 #define HAVE_MYSQL_REAL_CONNECT
 

--- 1.276/libmysql/libmysql.c	2007-05-10 13:59:24 +04:00
+++ 1.277/libmysql/libmysql.c	2007-06-01 23:41:57 +04:00
@@ -309,305 +309,6 @@
 #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, 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, 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
   If host == 0 then use localhost
@@ -615,21 +316,28 @@
 
 #ifdef USE_OLD_FUNCTIONS
 MYSQL * STDCALL
-mysql_connect(MYSQL *mysql,const char *host,
+mysql_connect(MYSQL *handle,const char *host,
 	      const char *user, const char *passwd)
 {
-  MYSQL *res;
-  mysql=mysql_init(mysql);			/* Make it thread safe */
+  DBUG_ENTER("mysql_connect");
+
+  if (handle == NULL &&
+      (handle= mysql_init(0)) == NULL)
+    DBUG_RETURN(0);                             /* Out of memory */
+
+  if (mysql_real_connect(handle, host, user,
+                          passwd, NullS, 0, NullS, 0))
+  {
+    /* Connect succeeded. */
+    my_bool reconnect= TRUE;
+    mysql_options(handle, MYSQL_OPT_RECONNECT, &opt_reconnect);
+  }
+  else
   {
-    DBUG_ENTER("mysql_connect");
-    if (!(res=mysql_real_connect(mysql,host,user,passwd,NullS,0,NullS,0)))
-    {
-      if (mysql->free_me)
-	my_free((uchar*) mysql,MYF(0));
-    }
-    mysql->reconnect= 1;
-    DBUG_RETURN(res);
+    mysql_close(handle);
+    handle= 0;
   }
+  DBUG_RETURN(handle);
 }
 #endif
 
@@ -638,7 +346,8 @@
   Change user and database
 **************************************************************************/
 
-int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
+int cli_read_change_user_result(struct st_mysql_impl *mysql,
+                                char *buff, const char *passwd)
 {
   NET *net= &mysql->net;
   ulong pkt_length;
@@ -656,7 +365,8 @@
       password in old format. The reply contains scramble_323.
     */
     scramble_323(buff, mysql->scramble, passwd);
-    if (my_net_write(net, buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net))
+    if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) ||
+        net_flush(net))
     {
       net->last_errno= CR_SERVER_LOST;
       strmov(net->sqlstate, unknown_sqlstate);
@@ -671,11 +381,12 @@
 }
 
 
-my_bool	STDCALL mysql_change_user(MYSQL *mysql, const char *user,
+my_bool	STDCALL mysql_change_user(MYSQL *handle, const char *user,
 				  const char *passwd, const char *db)
 {
   char buff[512],*end=buff;
   int rc;
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_change_user");
 
   if (!user)
@@ -707,7 +418,7 @@
   end= strmov(end, db ? db : "") + 1;
 
   /* Write authentication package */
-  simple_command(mysql,COM_CHANGE_USER, buff,(ulong) (end-buff),1);
+  simple_command(mysql,COM_CHANGE_USER, (uchar*) buff,(ulong) (end-buff),1);
 
   rc= (*mysql->methods->read_change_user_result)(mysql, buff, passwd);
 
@@ -784,7 +495,7 @@
 
 #endif
 
-my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
+my_bool handle_local_infile(struct st_mysql_impl *mysql, const char *net_filename)
 {
   my_bool result= 1;
   uint packet_length=MY_ALIGN(mysql->net.max_packet-16,IO_SIZE);
@@ -817,7 +528,7 @@
   if ((*options->local_infile_init)(&li_ptr, net_filename,
     options->local_infile_userdata))
   {
-    VOID(my_net_write(net,"",0));               /* Server needs one packet */
+    VOID(my_net_write(net, (uchar*) "", 0));               /* Server needs one packet */
     net_flush(net);
     strmov(net->sqlstate, unknown_sqlstate);
     net->last_errno= (*options->local_infile_error)(li_ptr,
@@ -831,7 +542,7 @@
 	  (*options->local_infile_read)(li_ptr, buf,
 					packet_length)) > 0)
   {
-    if (my_net_write(net,buf,readcount))
+    if (my_net_write(net, (uchar*) buf, readcount))
     {
       DBUG_PRINT("error",
 		 ("Lost connection to MySQL server during LOAD DATA of local file"));
@@ -843,7 +554,7 @@
   }
 
   /* Send empty packet to mark end of file */
-  if (my_net_write(net,"",0) || net_flush(net))
+  if (my_net_write(net, (uchar*) "", 0) || net_flush(net))
   {
     strmov(net->sqlstate, unknown_sqlstate);
     net->last_errno=CR_SERVER_LOST;
@@ -1010,7 +721,7 @@
 
 
 void
-mysql_set_local_infile_handler(MYSQL *mysql,
+mysql_set_local_infile_handler(struct st_mysql_impl *mysql,
                                int (*local_infile_init)(void **, const char *,
                                void *),
                                int (*local_infile_read)(void *, char *, uint),
@@ -1026,7 +737,7 @@
 }
 
 
-void mysql_set_local_infile_default(MYSQL *mysql)
+void mysql_set_local_infile_default(struct st_mysql_impl *mysql)
 {
   mysql->options.local_infile_init=  default_local_infile_init;
   mysql->options.local_infile_read=  default_local_infile_read;
@@ -1041,74 +752,12 @@
 **************************************************************************/
 
 int STDCALL
-mysql_query(MYSQL *mysql, const char *query)
+mysql_query(MYSQL *handle, const char *query)
 {
-  return mysql_real_query(mysql,query, (uint) strlen(query));
+  return mysql_real_query(handle, query, (uint) strlen(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
 **************************************************************************/
@@ -1168,15 +817,15 @@
 *****************************************************************************/
 
 MYSQL_RES * STDCALL
-mysql_list_dbs(MYSQL *mysql, const char *wild)
+mysql_list_dbs(MYSQL *handle, const char *wild)
 {
   char buff[255];
   DBUG_ENTER("mysql_list_dbs");
 
   append_wild(strmov(buff,"show databases"),buff+sizeof(buff),wild);
-  if (mysql_query(mysql,buff))
+  if (mysql_query(handle, buff))
     DBUG_RETURN(0);
-  DBUG_RETURN (mysql_store_result(mysql));
+  DBUG_RETURN (mysql_store_result(handle));
 }
 
 
@@ -1186,19 +835,19 @@
 *****************************************************************************/
 
 MYSQL_RES * STDCALL
-mysql_list_tables(MYSQL *mysql, const char *wild)
+mysql_list_tables(MYSQL *handle, const char *wild)
 {
   char buff[255];
   DBUG_ENTER("mysql_list_tables");
 
   append_wild(strmov(buff,"show tables"),buff+sizeof(buff),wild);
-  if (mysql_query(mysql,buff))
+  if (mysql_query(handle, buff))
     DBUG_RETURN(0);
-  DBUG_RETURN (mysql_store_result(mysql));
+  DBUG_RETURN (mysql_store_result(handle));
 }
 
 
-MYSQL_FIELD *cli_list_fields(MYSQL *mysql)
+MYSQL_FIELD *cli_list_fields(struct st_mysql_impl *mysql)
 {
   MYSQL_DATA *query;
   if (!(query= cli_read_rows(mysql,(MYSQL_FIELD*) 0, 
@@ -1219,17 +868,19 @@
 **************************************************************************/
 
 MYSQL_RES * STDCALL
-mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
+mysql_list_fields(MYSQL *handle, const char *table, const char *wild)
 {
   MYSQL_RES   *result;
   MYSQL_FIELD *fields;
   char	     buff[257],*end;
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_list_fields");
   DBUG_PRINT("enter",("table: '%s'  wild: '%s'",table,wild ? wild : ""));
 
   end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128);
   free_old_query(mysql);
-  if (simple_command(mysql,COM_FIELD_LIST,buff,(ulong) (end-buff),1) ||
+  if (simple_command(mysql,COM_FIELD_LIST, (uchar*) buff, (ulong)
+                     (end-buff),1) ||
       !(fields= (*mysql->methods->list_fields)(mysql)))
     DBUG_RETURN(NULL);
 
@@ -1249,11 +900,12 @@
 /* List all running processes (threads) in server */
 
 MYSQL_RES * STDCALL
-mysql_list_processes(MYSQL *mysql)
+mysql_list_processes(MYSQL *handle)
 {
   MYSQL_DATA *fields;
   uint field_count;
   uchar *pos;
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_list_processes");
 
   LINT_INIT(fields);
@@ -1270,81 +922,88 @@
     DBUG_RETURN(0);
   mysql->status=MYSQL_STATUS_GET_RESULT;
   mysql->field_count=field_count;
-  DBUG_RETURN(mysql_store_result(mysql));
+  DBUG_RETURN(mysql_store_result(handle));
 }
 
 
 #ifdef USE_OLD_FUNCTIONS
 int  STDCALL
-mysql_create_db(MYSQL *mysql, const char *db)
+mysql_create_db(MYSQL *handle, const char *db)
 {
-  DBUG_ENTER("mysql_createdb");
+  DBUG_ENTER("mysql_create_db");
   DBUG_PRINT("enter",("db: %s",db));
-  DBUG_RETURN(simple_command(mysql,COM_CREATE_DB,db, (ulong) strlen(db),0));
+  DBUG_RETURN(simple_command(handle->impl, COM_CREATE_DB, db,
+                             (ulong) strlen(db), 0));
 }
 
 
 int  STDCALL
-mysql_drop_db(MYSQL *mysql, const char *db)
+mysql_drop_db(MYSQL *handle, const char *db)
 {
   DBUG_ENTER("mysql_drop_db");
   DBUG_PRINT("enter",("db: %s",db));
-  DBUG_RETURN(simple_command(mysql,COM_DROP_DB,db,(ulong) strlen(db),0));
+  DBUG_RETURN(simple_command(handle->impl, COM_DROP_DB, db,
+                             (ulong) strlen(db), 0));
 }
 #endif
 
 
 int STDCALL
-mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
+mysql_shutdown(MYSQL *handle, enum mysql_enum_shutdown_level shutdown_level)
 {
   uchar level[1];
   DBUG_ENTER("mysql_shutdown");
   level[0]= (uchar) shutdown_level;
-  DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, (char *)level, 1, 0));
+  DBUG_RETURN(simple_command(handle->impl, COM_SHUTDOWN,
+                             level, 1, 0));
 }
 
 
 int STDCALL
-mysql_refresh(MYSQL *mysql,uint options)
+mysql_refresh(MYSQL *handle, uint options)
 {
   uchar bits[1];
   DBUG_ENTER("mysql_refresh");
   bits[0]= (uchar) options;
-  DBUG_RETURN(simple_command(mysql,COM_REFRESH,(char*) bits,1,0));
+  DBUG_RETURN(simple_command(handle->impl, COM_REFRESH,
+                             bits, 1, 0));
 }
 
 
 int STDCALL
-mysql_kill(MYSQL *mysql,ulong pid)
+mysql_kill(MYSQL *handle, ulong pid)
 {
-  char buff[4];
+  uchar buff[4];
   DBUG_ENTER("mysql_kill");
   int4store(buff,pid);
-  DBUG_RETURN(simple_command(mysql,COM_PROCESS_KILL,buff,sizeof(buff),0));
+  DBUG_RETURN(simple_command(handle->impl, COM_PROCESS_KILL,
+                             buff, sizeof(buff), 0));
 }
 
 
 int STDCALL
-mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
+mysql_set_server_option(MYSQL *handle, enum enum_mysql_set_option option)
 {
-  char buff[2];
+  uchar buff[2];
   DBUG_ENTER("mysql_set_server_option");
   int2store(buff, (uint) option);
-  DBUG_RETURN(simple_command(mysql, COM_SET_OPTION, buff, sizeof(buff), 0));
+  DBUG_RETURN(simple_command(handle->impl, COM_SET_OPTION,
+                             buff, sizeof(buff), 0));
 }
 
 
 int STDCALL
-mysql_dump_debug_info(MYSQL *mysql)
+mysql_dump_debug_info(MYSQL *handle)
 {
   DBUG_ENTER("mysql_dump_debug_info");
-  DBUG_RETURN(simple_command(mysql,COM_DEBUG,0,0,0));
+  DBUG_RETURN(simple_command(handle->impl, COM_DEBUG,
+                             0, 0, 0));
 }
 
 
-const char *cli_read_statistics(MYSQL *mysql)
+const char *cli_read_statistics(struct st_mysql_impl *mysql)
 {
-  mysql->net.read_pos[mysql->packet_length]=0;	/* End of stat string */
+  mysql->net.read_pos[mysql->packet_length]= 0;	/* End of stat string */
   if (!mysql->net.read_pos[0])
   {
     strmov(mysql->net.sqlstate, unknown_sqlstate);
@@ -1357,8 +1016,9 @@
 
 
 const char * STDCALL
-mysql_stat(MYSQL *mysql)
+mysql_stat(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_stat");
   if (simple_command(mysql,COM_STATISTICS,0,0,0))
     DBUG_RETURN(mysql->net.last_error);
@@ -1367,9 +1027,10 @@
 
 
 int STDCALL
-mysql_ping(MYSQL *mysql)
+mysql_ping(MYSQL *handle)
 {
   int res;
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_ping");
   res= simple_command(mysql,COM_PING,0,0,0);
   if (res == CR_SERVER_LOST && mysql->reconnect)
@@ -1379,23 +1040,23 @@
 
 
 const char * STDCALL
-mysql_get_server_info(MYSQL *mysql)
+mysql_get_server_info(MYSQL *handle)
 {
-  return((char*) mysql->server_version);
+  return (char*) handle->impl->server_version;
 }
 
 
 const char * STDCALL
-mysql_get_host_info(MYSQL *mysql)
+mysql_get_host_info(MYSQL *handle)
 {
-  return(mysql->host_info);
+  return handle->impl->host_info;
 }
 
 
 uint STDCALL
-mysql_get_proto_info(MYSQL *mysql)
+mysql_get_proto_info(MYSQL *handle)
 {
-  return (mysql->protocol_version);
+  return handle->impl->protocol_version;
 }
 
 const char * STDCALL
@@ -1436,48 +1097,51 @@
 
 /* MYSQL */
 
-unsigned int STDCALL mysql_field_count(MYSQL *mysql)
+unsigned int STDCALL mysql_field_count(MYSQL *handle)
 {
-  return mysql->last_used_con->field_count;
+  return handle->impl->field_count;
 }
 
-my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql)
+my_ulonglong STDCALL mysql_affected_rows(MYSQL *handle)
 {
-  return mysql->last_used_con->affected_rows;
+  return handle->impl->affected_rows;
 }
 
-my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
+my_ulonglong STDCALL mysql_insert_id(MYSQL *handle)
 {
-  return mysql->last_used_con->insert_id;
+  return handle->impl->insert_id;
 }
 
-const char *STDCALL mysql_sqlstate(MYSQL *mysql)
+const char *STDCALL mysql_sqlstate(MYSQL *handle)
 {
-  return mysql->net.sqlstate;
+  return handle->impl->net.sqlstate;
 }
 
-uint STDCALL mysql_warning_count(MYSQL *mysql)
+uint STDCALL mysql_warning_count(MYSQL *handle)
 {
-  return mysql->warning_count;
+  return handle->impl->warning_count;
 }
 
-const char *STDCALL mysql_info(MYSQL *mysql)
+const char *STDCALL mysql_info(MYSQL *handle)
 {
-  return mysql->info;
+  return handle->impl->info;
 }
 
-ulong STDCALL mysql_thread_id(MYSQL *mysql)
+ulong STDCALL mysql_thread_id(MYSQL *handle)
 {
-  return (mysql)->thread_id;
+  return handle->impl->thread_id;
 }
 
-const char * STDCALL mysql_character_set_name(MYSQL *mysql)
+const char * STDCALL mysql_character_set_name(MYSQL *handle)
 {
-  return mysql->charset->csname;
+  return handle->impl->charset->csname;
 }
 
-void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *csinfo)
+void STDCALL
+mysql_get_character_set_info(MYSQL *handle,
+                             MY_CHARSET_INFO *csinfo)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   csinfo->number   = mysql->charset->number;
   csinfo->state    = mysql->charset->state;
   csinfo->csname   = mysql->charset->csname;
@@ -1576,9 +1240,10 @@
 }
 
 ulong STDCALL
-mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
+mysql_real_escape_string(MYSQL *handle, char *to,const char *from,
 			 ulong length)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
     return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
   return escape_string_for_mysql(mysql->charset, to, 0, from, length);
@@ -1586,7 +1251,7 @@
 
 
 char * STDCALL
-mysql_odbc_escape_string(MYSQL *mysql,
+mysql_odbc_escape_string(MYSQL *handle,
 			 char *to, ulong to_length,
 			 const char *from, ulong from_length,
 			 void *param,
@@ -1595,6 +1260,7 @@
 {
   char *to_end=to+to_length-5;
   const char *end;
+  struct st_mysql_impl *mysql= handle->impl;
 #ifdef USE_MB
   my_bool use_mb_flag=use_mb(mysql->charset);
 #endif
@@ -1657,9 +1323,10 @@
 }
 
 void STDCALL
-myodbc_remove_escape(MYSQL *mysql,char *name)
+myodbc_remove_escape(MYSQL *handle, char *name)
 {
   char *to;
+  struct st_mysql_impl *mysql= handle->impl;
 #ifdef USE_MB
   my_bool use_mb_flag=use_mb(mysql->charset);
   char *end;
@@ -1876,7 +1543,7 @@
     1	error
 */
 
-my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
+my_bool cli_read_prepare_result(struct st_mysql_impl *mysql, MYSQL_STMT *stmt)
 {
   uchar *pos;
   uint field_count, param_count;
@@ -1884,7 +1551,6 @@
   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;
@@ -1961,9 +1627,10 @@
 */
 
 MYSQL_STMT * STDCALL
-mysql_stmt_init(MYSQL *mysql)
+mysql_stmt_init(MYSQL *handle)
 {
   MYSQL_STMT *stmt;
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_stmt_init");
 
   if (!(stmt= (MYSQL_STMT *) my_malloc(sizeof(MYSQL_STMT),
@@ -2026,7 +1693,7 @@
 int STDCALL
 mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
 {
-  MYSQL *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   DBUG_ENTER("mysql_stmt_prepare");
 
   if (!mysql)
@@ -2046,7 +1713,7 @@
   if ((int) stmt->state > (int) MYSQL_STMT_INIT_DONE)
   {
     /* This is second prepare with another statement */
-    char buff[MYSQL_STMT_HEADER];               /* 4 bytes - stmt id */
+    uchar buff[MYSQL_STMT_HEADER];              /* 4 bytes - stmt id */
 
     if (reset_stmt_handle(stmt, RESET_LONG_DATA | RESET_STORE_RESULT))
       DBUG_RETURN(1);
@@ -2076,7 +1743,7 @@
     }
   }
 
-  if (stmt_command(mysql, COM_STMT_PREPARE, query, length, stmt))
+  if (stmt_command(mysql, COM_STMT_PREPARE, (uchar*) query, length, stmt))
   {
     set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
                     mysql->net.sqlstate);
@@ -2121,7 +1788,7 @@
 {
   MYSQL_FIELD *fields, *field, *end;
   MEM_ROOT *alloc= &stmt->mem_root;
-  MYSQL *mysql= stmt->mysql->last_used_con;
+  struct st_mysql_impl *mysql= stmt->mysql;
 
   stmt->field_count= mysql->field_count;
 
@@ -2412,7 +2079,7 @@
 {
   /* param->length is always set in mysql_stmt_bind_param */
   ulong length= *param->length;
-  char *to= (char *) net_store_length((char *) net->write_pos, length);
+  uchar *to= (uchar *) net_store_length((uchar *) net->write_pos, length);
   memcpy(to, param->buffer, length);
   net->write_pos= (uchar*) to+length;
 }
@@ -2480,22 +2147,23 @@
 
 static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length)
 {
-  MYSQL *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   NET	*net= &mysql->net;
   char buff[4 /* size of stmt id */ +
             5 /* execution flags */];
   my_bool res;
 
   DBUG_ENTER("execute");
-  DBUG_DUMP("packet", packet, length);
+  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 */
 
-  res= test(cli_advanced_command(mysql, COM_STMT_EXECUTE, buff, sizeof(buff),
-                                 packet, length, 1, NULL) ||
+  res= test(cli_advanced_command(mysql, COM_STMT_EXECUTE,
+                                 (uchar*) buff, sizeof(buff),
+                                 (uchar*) packet, length,
+                                 1, NULL) ||
             (*mysql->methods->read_query_result)(mysql));
   stmt->affected_rows= mysql->affected_rows;
   stmt->server_status= mysql->server_status;
@@ -2515,7 +2183,7 @@
 
   if (stmt->param_count)
   {
-    MYSQL *mysql= stmt->mysql;
+    struct st_mysql_impl *mysql= stmt->mysql;
     NET        *net= &mysql->net;
     MYSQL_BIND *param, *param_end;
     char       *param_data;
@@ -2633,7 +2301,7 @@
 static int stmt_read_row_unbuffered(MYSQL_STMT *stmt, unsigned char **row)
 {
   int rc= 1;
-  MYSQL *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   /*
     This function won't be called if stmt->field_count is zero
     or execution wasn't done: this is ensured by mysql_stmt_execute.
@@ -2698,11 +2366,11 @@
     stmt->server_status &= ~SERVER_STATUS_LAST_ROW_SENT;
   else
   {
-    MYSQL *mysql= stmt->mysql;
+    struct st_mysql_impl *mysql= stmt->mysql;
     NET *net= &mysql->net;
     MYSQL_DATA *result= &stmt->result;
-    char buff[4 /* statement id */ +
-              4 /* number of rows to fetch */];
+    uchar buff[4 /* statement id */ +
+               4 /* number of rows to fetch */];
 
     free_root(&result->alloc, MYF(MY_KEEP_PREALLOC));
     result->data= NULL;
@@ -2711,7 +2379,8 @@
     int4store(buff, stmt->stmt_id);
     int4store(buff + 4, stmt->prefetch_rows); /* number of rows to fetch */
     if ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH,
-                                            buff, sizeof(buff), NullS, 0,
+                                            buff, sizeof(buff),
+                                            (uchar*) NullS, 0,
                                             1, NULL))
     {
       set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
@@ -2867,7 +2536,7 @@
 
 int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
 {
-  MYSQL *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   DBUG_ENTER("mysql_stmt_execute");
 
   if (!mysql)
@@ -3365,9 +3034,9 @@
   */
   if (length || param->long_data_used == 0)
   {
-    MYSQL *mysql= stmt->mysql;
+    struct st_mysql_impl *mysql= stmt->mysql;
     /* Packet header: stmt id (4 bytes), param no (2 bytes) */
-    char buff[MYSQL_LONG_DATA_HEADER];
+    uchar buff[MYSQL_LONG_DATA_HEADER];
 
     int4store(buff, stmt->stmt_id);
     int2store(buff + 4, param_number);
@@ -3378,8 +3047,9 @@
       This is intentional to save bandwidth.
     */
     if ((*mysql->methods->advanced_command)(mysql, COM_STMT_SEND_LONG_DATA,
-                                            buff, sizeof(buff), data,
-                                            length, 1, NULL))
+                                            buff, sizeof(buff),
+                                            (uchar *) data, length, 1,
+                                            NULL))
     {
       set_stmt_errmsg(stmt, mysql->net.last_error,
 		      mysql->net.last_errno, mysql->net.sqlstate);
@@ -3701,19 +3371,20 @@
   }
   default:
   {
-    char buff[22];                              /* Enough for longlong */
-    char *end= longlong10_to_str(value, buff, is_unsigned ? 10: -10);
+    uchar buff[22];                              /* Enough for longlong */
+    uchar *end= (uchar*) longlong10_to_str(value, (char*) buff,
+                                           is_unsigned ? 10: -10);
     /* Resort to string conversion which supports all typecodes */
     uint length= (uint) (end-buff);
 
     if (field->flags & ZEROFILL_FLAG && length < field->length
&&
         field->length < 21)
     {
-      bmove_upp((char*) buff+field->length,buff+length, length);
-      bfill((char*) buff, field->length - length,'0');
+      bmove_upp(buff+field->length,buff+length, length);
+      bfill(buff, field->length - length,'0');
       length= field->length;
     }
-    fetch_string_with_conversion(param, buff, length);
+    fetch_string_with_conversion(param, (char*) buff, length);
     break;
   }
   }
@@ -4549,7 +4220,7 @@
 }
 
 
-int cli_unbuffered_fetch(MYSQL *mysql, char **row)
+int cli_unbuffered_fetch(struct st_mysql_impl *mysql, char **row)
 {
   if (packet_error == cli_safe_read(mysql))
     return 1;
@@ -4652,13 +4323,12 @@
 {
   ulong      pkt_len;
   uchar      *cp;
-  MYSQL      *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   MYSQL_DATA *result= &stmt->result;
   MYSQL_ROWS *cur, **prev_ptr= &result->data;
   NET        *net = &mysql->net;
   DBUG_ENTER("cli_read_binary_rows");
 
-  mysql= mysql->last_used_con;
 
   while ((pkt_len= cli_safe_read(mysql)) != packet_error)
   {
@@ -4745,12 +4415,10 @@
 
 int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
 {
-  MYSQL *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   MYSQL_DATA *result= &stmt->result;
   DBUG_ENTER("mysql_stmt_store_result");
 
-  mysql= mysql->last_used_con;
-
   if (!stmt->field_count)
     DBUG_RETURN(0);
 
@@ -4767,14 +4435,14 @@
       Server side cursor exist, tell server to start sending the rows
     */
     NET *net= &mysql->net;
-    char buff[4 /* statement id */ +
-              4 /* number of rows to fetch */];
+    uchar buff[4 /* statement id */ +
+               4 /* number of rows to fetch */];
 
     /* Send row request to the server */
     int4store(buff, stmt->stmt_id);
     int4store(buff + 4, (int)~0); /* number of rows to fetch */
     if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff),
-                             NullS, 0, 1, NULL))
+                             (uchar*) NullS, 0, 1, NULL))
     {
       set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
       DBUG_RETURN(1);
@@ -4914,7 +4582,7 @@
   /* If statement hasn't been prepared there is nothing to reset */
   if ((int) stmt->state > (int) MYSQL_STMT_INIT_DONE)
   {
-    MYSQL *mysql= stmt->mysql;
+    struct st_mysql_impl *mysql= stmt->mysql;
     MYSQL_DATA *result= &stmt->result;
 
     /*
@@ -4958,10 +4626,11 @@
           Reset the server side statement and close the server side
           cursor if it exists.
         */
-        char buff[MYSQL_STMT_HEADER]; /* packet header: 4 bytes for stmt id */
+        uchar buff[MYSQL_STMT_HEADER]; /* packet header: 4 bytes for stmt id */
         int4store(buff, stmt->stmt_id);
-        if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET, buff,
-                                                sizeof(buff), 0, 0, 0, NULL))
+        if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET,
+                                                buff, sizeof(buff),
+                                                0, 0, 0, NULL))
         {
           set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
                           mysql->net.sqlstate);
@@ -5002,7 +4671,7 @@
 
 my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
 {
-  MYSQL *mysql= stmt->mysql;
+  struct st_mysql_impl *mysql= stmt->mysql;
   int rc= 0;
   DBUG_ENTER("mysql_stmt_close");
 
@@ -5019,7 +4688,7 @@
     net_clear_error(&mysql->net);
     if ((int) stmt->state > (int) MYSQL_STMT_INIT_DONE)
     {
-      char buff[MYSQL_STMT_HEADER];             /* 4 bytes - stmt id */
+      uchar buff[MYSQL_STMT_HEADER];             /* 4 bytes - stmt id */
 
       if (mysql->unbuffered_fetch_owner == &stmt->unbuffered_fetch_cancelled)
         mysql->unbuffered_fetch_owner= 0;
@@ -5101,20 +4770,20 @@
   Commit the current transaction
 */
 
-my_bool STDCALL mysql_commit(MYSQL * mysql)
+my_bool STDCALL mysql_commit(MYSQL *handle)
 {
   DBUG_ENTER("mysql_commit");
-  DBUG_RETURN((my_bool) mysql_real_query(mysql, "commit", 6));
+  DBUG_RETURN((my_bool) mysql_real_query(handle, "commit", 6));
 }
 
 /*
   Rollback the current transaction
 */
 
-my_bool STDCALL mysql_rollback(MYSQL * mysql)
+my_bool STDCALL mysql_rollback(MYSQL *handle)
 {
   DBUG_ENTER("mysql_rollback");
-  DBUG_RETURN((my_bool) mysql_real_query(mysql, "rollback", 8));
+  DBUG_RETURN((my_bool) mysql_real_query(handle, "rollback", 8));
 }
 
 
@@ -5122,12 +4791,12 @@
   Set autocommit to either true or false
 */
 
-my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode)
+my_bool STDCALL mysql_autocommit(MYSQL *handle, my_bool auto_mode)
 {
   DBUG_ENTER("mysql_autocommit");
   DBUG_PRINT("enter", ("mode : %d", auto_mode));
 
-  DBUG_RETURN((my_bool) mysql_real_query(mysql, auto_mode ?
+  DBUG_RETURN((my_bool) mysql_real_query(handle, auto_mode ?
                                          "set autocommit=1":"set autocommit=0",
                                          16));
 }
@@ -5142,12 +4811,13 @@
   to be read using mysql_next_result()
 */
 
-my_bool STDCALL mysql_more_results(MYSQL *mysql)
+my_bool STDCALL mysql_more_results(MYSQL *handle)
 {
   my_bool res;
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_more_results");
 
-  res= ((mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) ?
+  res= ((mysql->server_status & SERVER_MORE_RESULTS_EXISTS) ?
 	1: 0);
   DBUG_PRINT("exit",("More results exists ? %d", res));
   DBUG_RETURN(res);
@@ -5157,8 +4827,9 @@
 /*
   Reads and returns the next query results
 */
-int STDCALL mysql_next_result(MYSQL *mysql)
+int STDCALL mysql_next_result(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_next_result");
 
   if (mysql->status != MYSQL_STATUS_READY)
@@ -5174,20 +4845,22 @@
   strmov(mysql->net.sqlstate, not_error_sqlstate);
   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 */
 }
 
 
-MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql)
+MYSQL_RES * STDCALL mysql_use_result(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   return (*mysql->methods->use_result)(mysql);
 }
 
-my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
+my_bool STDCALL mysql_read_query_result(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   return (*mysql->methods->read_query_result)(mysql);
 }
 

--- 1.309/sql/slave.cc	2007-05-31 18:45:16 +04:00
+++ 1.310/sql/slave.cc	2007-06-01 23:41:57 +04:00
@@ -3169,7 +3169,7 @@
   mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
 
   while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
-         (reconnect ? mysql_reconnect(mysql) != 0 :
+         (reconnect ? mysql_reconnect(mysql->impl) != 0 :
           mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
                              mi->port, 0, client_flag) == 0))
   {

--- 1.20/include/sql_common.h	2007-05-10 13:59:24 +04:00
+++ 1.21/include/sql_common.h	2007-06-01 23:41:57 +04:00
@@ -25,20 +25,22 @@
 MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
 			   my_bool default_value, uint server_capabilities);
 void free_rows(MYSQL_DATA *cur);
-void free_old_query(MYSQL *mysql);
-void end_server(MYSQL *mysql);
-my_bool mysql_reconnect(MYSQL *mysql);
+void free_old_query(struct st_mysql_impl *mysql);
+void end_server(struct st_mysql_impl *mysql);
+my_bool mysql_reconnect(struct st_mysql_impl *mysql);
 void mysql_read_default_options(struct st_mysql_options *options,
 				const char *filename,const char *group);
 my_bool
-cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
+cli_advanced_command(struct st_mysql_impl *mysql,
+                     enum enum_server_command command,
 		     const unsigned char *header, ulong header_length,
 		     const unsigned char *arg, ulong arg_length,
                      my_bool skip_check, MYSQL_STMT *stmt);
-unsigned long cli_safe_read(MYSQL *mysql);
+unsigned long cli_safe_read(struct st_mysql_impl *mysql);
 void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode,
 		     const char *sqlstate);
-void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
+void set_mysql_error(struct st_mysql_impl *mysql,
+                     int errcode, const char *sqlstate);
 #ifdef	__cplusplus
 }
 #endif

--- 1.37/libmysql/client_settings.h	2007-05-10 13:59:24 +04:00
+++ 1.38/libmysql/client_settings.h	2007-06-01 23:41:57 +04:00
@@ -22,7 +22,7 @@
 
 sig_handler my_pipe_sig_handler(int sig);
 void read_user_name(char *name);
-my_bool handle_local_infile(MYSQL *mysql, const char *net_filename);
+my_bool handle_local_infile(struct st_mysql_impl *mysql, const char *net_filename);
 
 /*
   Let the user specify that we don't want SIGPIPE;  This doesn't however work
@@ -43,21 +43,24 @@
 				const char *filename,const char *group);
 void mysql_detach_stmt_list(LIST **stmt_list, const char *func_name);
 MYSQL *
-cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
+cli_mysql_real_connect(MYSQL *handle, const char *host, const char *user,
 		       const char *passwd, const char *db,
 		       uint port, const char *unix_socket,ulong client_flag);
 
-void cli_mysql_close(MYSQL *mysql);
+void cli_mysql_close(struct st_mysql_impl *mysql);
 
-MYSQL_FIELD * cli_list_fields(MYSQL *mysql);
-my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt);
-MYSQL_DATA * cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
-				   uint fields);
+MYSQL_FIELD * cli_list_fields(struct st_mysql_impl *mysql);
+my_bool cli_read_prepare_result(struct st_mysql_impl *mysql,
+                                MYSQL_STMT *stmt);
+MYSQL_DATA *cli_read_rows(struct st_mysql_impl *mysql,
+                          MYSQL_FIELD *mysql_fields,
+                          uint fields);
 int cli_stmt_execute(MYSQL_STMT *stmt);
 int cli_read_binary_rows(MYSQL_STMT *stmt);
-int cli_unbuffered_fetch(MYSQL *mysql, char **row);
-const char * cli_read_statistics(MYSQL *mysql);
-int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd);
+int cli_unbuffered_fetch(struct st_mysql_impl *mysql, char **row);
+const char *cli_read_statistics(struct st_mysql_impl *mysql);
+int cli_read_change_user_result(struct st_mysql_impl *mysql,
+                                char *buff, const char *passwd);
 
 #ifdef EMBEDDED_LIBRARY
 int init_embedded_server(int argc, char **argv, char **groups);

--- 1.133/sql-common/client.c	2007-05-10 13:59:30 +04:00
+++ 1.134/sql-common/client.c	2007-06-01 23:41:57 +04:00
@@ -117,8 +117,8 @@
 const char 	*def_shared_memory_base_name= default_shared_memory_base_name;
 #endif
 
-static void mysql_close_free_options(MYSQL *mysql);
-static void mysql_close_free(MYSQL *mysql);
+static void mysql_close_free_options(struct st_mysql_impl *mysql);
+static void mysql_close_free(struct st_mysql_impl *mysql);
 
 #if !(defined(__WIN__) || defined(__NETWARE__))
 static int wait_for_data(my_socket fd, uint timeout);
@@ -367,7 +367,8 @@
 */
 
 #ifdef HAVE_SMEM
-HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout)
+HANDLE create_shared_memory(struct st_mysql_impl *mysql,
+                            NET *net, uint connect_timeout)
 {
   ulong smem_buffer_length = shared_memory_buffer_length + 4;
   /*
@@ -578,7 +579,7 @@
 *****************************************************************************/
 
 ulong
-cli_safe_read(MYSQL *mysql)
+cli_safe_read(struct st_mysql_impl *mysql)
 {
   NET *net= &mysql->net;
   ulong len=0;
@@ -649,7 +650,8 @@
 }
 
 my_bool
-cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
+cli_advanced_command(struct st_mysql_impl *mysql,
+                     enum enum_server_command command,
 		     const uchar *header, ulong header_length,
 		     const uchar *arg, ulong arg_length, my_bool skip_check,
                      MYSQL_STMT *stmt __attribute__((unused)))
@@ -720,7 +722,7 @@
   DBUG_RETURN(result);
 }
 
-void free_old_query(MYSQL *mysql)
+void free_old_query(struct st_mysql_impl *mysql)
 {
   DBUG_ENTER("free_old_query");
   if (mysql->fields)
@@ -737,7 +739,7 @@
   Set the internal error message to mysql handler
 */
 
-void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
+void set_mysql_error(struct st_mysql_impl *mysql, int errcode, const char *sqlstate)
 {
   NET *net;
   DBUG_ENTER("set_mysql_error");
@@ -753,7 +755,8 @@
 }
 
 
-static void set_mysql_extended_error(MYSQL *mysql, int errcode,
+static void set_mysql_extended_error(struct st_mysql_impl *mysql,
+                                     int errcode,
                                      const char *sqlstate,
                                      const char *format, ...)
 {
@@ -779,7 +782,7 @@
   Flush result set sent from server
 */
 
-static void cli_flush_use_result(MYSQL *mysql)
+static void cli_flush_use_result(struct st_mysql_impl *mysql)
 {
   /* Clear the current execution status */
   DBUG_ENTER("cli_flush_use_result");
@@ -830,7 +833,7 @@
 {
   MYSQL_ROW row;
   MYSQL_RES *res;
-  NET *net= &mysql->net;
+  NET *net= &mysql->impl->net;
   static const char query[]= "SELECT @@license";
   static const char required_license[]= STRINGIFY_ARG(LICENSE);
 
@@ -870,7 +873,7 @@
   Shut down connection
 **************************************************************************/
 
-void end_server(MYSQL *mysql)
+void end_server(struct st_mysql_impl *mysql)
 {
   int save_errno= errno;
   DBUG_ENTER("end_server");
@@ -897,7 +900,7 @@
   DBUG_PRINT("enter",("mysql_res: 0x%lx", (long) result));
   if (result)
   {
-    MYSQL *mysql= result->handle;
+    struct st_mysql_impl *mysql= result->mysql;
     if (mysql)
     {
       if (mysql->unbuffered_fetch_owner == &result->unbuffered_fetch_cancelled)
@@ -1300,7 +1303,8 @@
 
 /* Read all rows (fields or data) from server */
 
-MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
+MYSQL_DATA *cli_read_rows(struct st_mysql_impl *mysql,
+                          MYSQL_FIELD *mysql_fields,
 			  unsigned int fields)
 {
   uint	field;
@@ -1403,7 +1407,8 @@
 
 
 static int
-read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
+read_one_row(struct st_mysql_impl *mysql,
+             uint fields,MYSQL_ROW row, ulong *lengths)
 {
   uint field;
   ulong pkt_len,len;
@@ -1457,31 +1462,35 @@
 ****************************************************************************/
 
 MYSQL * STDCALL
-mysql_init(MYSQL *mysql)
+mysql_init(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql;
   if (mysql_server_init(0, NULL, NULL))
     return 0;
-  if (!mysql)
+
+  if (handle)
   {
-    if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL))))
+    mysql= my_malloc(sizeof(*mysql), MYF(MY_WME | MY_ZEROFILL));
+    if (mysql == 0)
       return 0;
-    mysql->free_me=1;
   }
   else
-    bzero((char*) (mysql), sizeof(*(mysql)));
+  {
+    if (! my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
+                          &mysql,
+                          sizeof(*mysql),
+                          &handle,
+                          sizeof(*handle),
+                          NullS))
+      return 0;
+    mysql->free_handle= TRUE;
+  }
+  handle->impl= 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
     --enable-local-infile
   */
@@ -1514,7 +1523,7 @@
   */
   mysql->reconnect= 0;
 
-  return mysql;
+  return handle;
 }
 
 
@@ -1526,13 +1535,14 @@
 #define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
 
 my_bool STDCALL
-mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
+mysql_ssl_set(MYSQL *handle __attribute__((unused)),
 	      const char *key __attribute__((unused)),
 	      const char *cert __attribute__((unused)),
 	      const char *ca __attribute__((unused)),
 	      const char *capath __attribute__((unused)),
 	      const char *cipher __attribute__((unused)))
 {
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_ssl_set");
 #ifdef HAVE_OPENSSL
   mysql->options.ssl_key=    strdup_if_not_null(key);
@@ -1553,7 +1563,7 @@
 #ifdef HAVE_OPENSSL
 
 static void
-mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
+mysql_ssl_free(struct st_mysql_impl *mysql __attribute__((unused)))
 {
   struct st_VioSSLFd *ssl_fd= (struct st_VioSSLFd*) mysql->connector_fd;
   DBUG_ENTER("mysql_ssl_free");
@@ -1589,8 +1599,9 @@
 */
 
 const char * STDCALL
-mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused)))
+mysql_get_ssl_cipher(MYSQL *handle __attribute__((unused)))
 {
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_get_ssl_cipher");
 #ifdef HAVE_OPENSSL
   if (mysql->net.vio && mysql->net.vio->ssl_arg)
@@ -1681,8 +1692,8 @@
   before calling mysql_real_connect !
 */
 
-static my_bool cli_read_query_result(MYSQL *mysql);
-static MYSQL_RES *cli_use_result(MYSQL *mysql);
+static my_bool cli_read_query_result(struct st_mysql_impl *mysql);
+static MYSQL_RES *cli_use_result(struct st_mysql_impl *mysql);
 
 static MYSQL_METHODS client_methods=
 {
@@ -1707,8 +1718,9 @@
 };
 
 C_MODE_START
-int mysql_init_character_set(MYSQL *mysql)
+int mysql_init_character_set(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   NET		*net= &mysql->net;
   const char *default_collation_name;
   
@@ -1780,7 +1792,8 @@
 
 
 MYSQL * STDCALL 
-CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
+CLI_MYSQL_REAL_CONNECT(MYSQL *handle,
+                       const char *host, const char *user,
 		       const char *passwd, const char *db,
 		       uint port, const char *unix_socket,ulong client_flag)
 {
@@ -1790,6 +1803,7 @@
   in_addr_t	ip_addr;
   struct	sockaddr_in sock_addr;
   ulong		pkt_length;
+  struct st_mysql_impl *mysql= handle->impl;
   NET		*net= &mysql->net;
 #ifdef MYSQL_SERVER
   thr_alarm_t   alarmed;
@@ -2086,7 +2100,7 @@
   /* Check if version of protocol matches current one */
 
   mysql->protocol_version= net->read_pos[0];
-  DBUG_DUMP("packet",(char*) net->read_pos,10);
+  DBUG_DUMP("packet",(uchar*) net->read_pos,10);
   DBUG_PRINT("info",("mysql protocol version %d, server=%d",
 		     PROTOCOL_VERSION, mysql->protocol_version));
   if (mysql->protocol_version != PROTOCOL_VERSION)
@@ -2131,7 +2145,7 @@
     goto error;
   }
 
-  if (mysql_init_character_set(mysql))
+  if (mysql_init_character_set(handle))
     goto error;
 
   /* Save connection information */
@@ -2214,7 +2228,7 @@
       Send client_flag, max_packet_size - unencrypted otherwise
       the server does not know we want to do SSL
     */
-    if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net))
+    if (my_net_write(net, (uchar*) buff,(uint) (end-buff)) || net_flush(net))
     {
       set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
                                ER(CR_SERVER_LOST_EXTENDED),
@@ -2296,7 +2310,8 @@
     db= 0;
   }
   /* Write authentication package */
-  if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net))
+  if (my_net_write(net, (uchar*) buff,
+                   (ulong) (end-buff)) || net_flush(net))
   {
     set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
                              ER(CR_SERVER_LOST_EXTENDED),
@@ -2328,7 +2343,7 @@
       password in old format.
     */
     scramble_323(buff, mysql->scramble, passwd);
-    if (my_net_write(net, buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net))
+    if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net))
     {
       set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
                                ER(CR_SERVER_LOST_EXTENDED),
@@ -2352,11 +2367,11 @@
     net->compress=1;
 
 #ifdef CHECK_LICENSE 
-  if (check_license(mysql))
+  if (check_license(handle))
     goto error;
 #endif
 
-  if (db && mysql_select_db(mysql, db))
+  if (db && mysql_select_db(handle, db))
   {
     if (mysql->net.last_errno == CR_SERVER_LOST)
         set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
@@ -2378,7 +2393,7 @@
     for (; ptr < end_command; ptr++)
     {
       MYSQL_RES *res;
-      if (mysql_real_query(mysql,*ptr, (ulong) strlen(*ptr)))
+      if (mysql_real_query(handle, *ptr, (ulong) strlen(*ptr)))
 	goto error;
       if (mysql->fields)
       {
@@ -2390,14 +2405,9 @@
     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);
+  DBUG_RETURN(handle);
 
 error:
   reset_sigpipe(mysql);
@@ -2414,32 +2424,12 @@
 }
 
 
-/* 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)
+my_bool mysql_reconnect(struct st_mysql_impl *mysql)
 {
-  MYSQL tmp_mysql;
   DBUG_ENTER("mysql_reconnect");
+#if 0
+  MYSQL tmp_handle;
+  struct st_mysql_impl tmp_mysql;
   DBUG_ASSERT(mysql);
   DBUG_PRINT("enter", ("mysql->reconnect: %d", mysql->reconnect));
 
@@ -2451,11 +2441,12 @@
     set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
     DBUG_RETURN(1);
   }
-  mysql_init(&tmp_mysql);
+  bzero(&tmp_mysql, sizeof(tmp_mysql));
+  tmp_handle.impl= &tmp_mysql;
   tmp_mysql.options= mysql->options;
-  tmp_mysql.rpl_pivot= mysql->rpl_pivot;
-  
-  if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
+
+  if (!mysql_real_connect(&tmp_handle, mysql->host,
+                          mysql->user, mysql->passwd,
 			  mysql->db, mysql->port, mysql->unix_socket,
 			  mysql->client_flag | CLIENT_REMEMBER_OPTIONS))
   {
@@ -2464,7 +2455,7 @@
     strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate);
     DBUG_RETURN(1);
   }
-  if (mysql_set_character_set(&tmp_mysql, mysql->charset->csname))
+  if (mysql_set_character_set(&tmp_handle, mysql->charset->csname))
   {
     DBUG_PRINT("error", ("mysql_set_character_set() failed"));
     bzero((char*) &tmp_mysql.options,sizeof(tmp_mysql.options));
@@ -2506,9 +2497,9 @@
   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;
+#endif
   DBUG_RETURN(0);
 }
 
@@ -2518,13 +2509,16 @@
 **************************************************************************/
 
 int STDCALL
-mysql_select_db(MYSQL *mysql, const char *db)
+mysql_select_db(MYSQL *handle, const char *db)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   int error;
+
   DBUG_ENTER("mysql_select_db");
   DBUG_PRINT("enter",("db: '%s'",db));
 
-  if ((error=simple_command(mysql,COM_INIT_DB,db,(ulong) strlen(db),0)))
+  if ((error=simple_command(mysql, COM_INIT_DB, (uchar*) db,
+                            (ulong) strlen(db), 0)))
     DBUG_RETURN(error);
   my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
   mysql->db=my_strdup(db,MYF(MY_WME));
@@ -2537,7 +2531,7 @@
   If handle is alloced by mysql connect free it.
 *************************************************************************/
 
-static void mysql_close_free_options(MYSQL *mysql)
+static void mysql_close_free_options(struct st_mysql_impl *mysql)
 {
   DBUG_ENTER("mysql_close_free_options");
 
@@ -2573,16 +2567,14 @@
 }
 
 
-static void mysql_close_free(MYSQL *mysql)
+static void mysql_close_free(struct st_mysql_impl *mysql)
 {
   my_free((uchar*) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
   my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR));
   my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR));
   my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
-#if defined(EMBEDDED_LIBRARY) || MYSQL_VERSION_ID >= 50100
   my_free(mysql->info_buffer,MYF(MY_ALLOW_ZERO_PTR));
   mysql->info_buffer= 0;
-#endif
   /* Clear pointers for better safety */
   mysql->host_info= mysql->user= mysql->passwd= mysql->db= 0;
 }
@@ -2626,52 +2618,41 @@
 }
 
 
-void STDCALL mysql_close(MYSQL *mysql)
+void STDCALL mysql_close(MYSQL *handle)
 {
   DBUG_ENTER("mysql_close");
-  if (mysql)					/* Some simple safety */
+  if (handle)					/* Some simple safety */
   {
+    struct st_mysql_impl *mysql= handle->impl;
     /* If connection is still up, send a QUIT message */
     if (mysql->net.vio != 0)
     {
       free_old_query(mysql);
       mysql->status=MYSQL_STATUS_READY; /* Force command */
       mysql->reconnect=0;
-      simple_command(mysql,COM_QUIT,NullS,0,1);
+      simple_command(mysql, COM_QUIT, (uchar*) NullS,0,1);
       end_server(mysql);			/* Sets mysql->net.vio= 0 */
     }
     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);
 #endif
-    if (mysql->free_me)
-      my_free((uchar*) mysql,MYF(0));
+    if (mysql->free_handle)
+      my_free((uchar*) handle, MYF(0));
+    else
+    {
+      my_free(mysql, MYF(0));
+      handle->impl= NULL;                       /* safety */
+    }
   }
   DBUG_VOID_RETURN;
 }
 
 
-static my_bool cli_read_query_result(MYSQL *mysql)
+static my_bool cli_read_query_result(struct st_mysql_impl *mysql)
 {
   uchar *pos;
   ulong field_count;
@@ -2679,12 +2660,6 @@
   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 */
@@ -2719,7 +2694,7 @@
 #ifdef MYSQL_CLIENT
   if (field_count == NULL_LENGTH)		/* LOAD DATA LOCAL INFILE */
   {
-    int error=handle_local_infile(mysql,(char*) pos);
+    int error= handle_local_infile(mysql, (char*) pos);
     if ((length= cli_safe_read(mysql)) == packet_error || error)
       DBUG_RETURN(1);
     goto get_info;				/* Get info packet */
@@ -2748,38 +2723,23 @@
 */
 
 int STDCALL
-mysql_send_query(MYSQL* mysql, const char* query, ulong length)
+mysql_send_query(MYSQL *handle, 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, query, length, 1));
+  DBUG_RETURN(simple_command(handle->impl, COM_QUERY, (uchar*) query, length, 1));
 }
 
 
 int STDCALL
-mysql_real_query(MYSQL *mysql, const char *query, ulong length)
+mysql_real_query(MYSQL *handle, const char *query, ulong length)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_real_query");
-  DBUG_PRINT("enter",("handle: 0x%lx", (long) mysql));
+  DBUG_PRINT("enter",("handle: 0x%lx", (long) handle));
   DBUG_PRINT("query",("Query = '%-.4096s'",query));
 
-  if (mysql_send_query(mysql,query,length))
+  if (mysql_send_query(handle, query, length))
     DBUG_RETURN(1);
   DBUG_RETURN((int) (*mysql->methods->read_query_result)(mysql));
 }
@@ -2790,12 +2750,12 @@
   mysql_data_seek may be used.
 **************************************************************************/
 
-MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
+MYSQL_RES * STDCALL mysql_store_result(MYSQL *handle)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   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)
@@ -2845,13 +2805,11 @@
   have to wait for the client (and will not wait more than 30 sec/packet).
 **************************************************************************/
 
-static MYSQL_RES * cli_use_result(MYSQL *mysql)
+static MYSQL_RES * cli_use_result(struct st_mysql_impl *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)
@@ -2875,7 +2833,7 @@
   result->field_alloc=	mysql->field_alloc;
   result->field_count=	mysql->field_count;
   result->current_field=0;
-  result->handle=	mysql;
+  result->mysql=	mysql;
   result->current_row=	0;
   mysql->fields=0;			/* fields is now in result */
   clear_alloc_root(&mysql->field_alloc);
@@ -2897,7 +2855,7 @@
   {						/* Unbufferred fetch */
     if (!res->eof)
     {
-      MYSQL *mysql= res->handle;
+      struct st_mysql_impl *mysql= res->mysql;
       if (mysql->status != MYSQL_STATUS_USE_RESULT)
       {
         set_mysql_error(mysql,
@@ -2920,7 +2878,7 @@
       if (mysql->unbuffered_fetch_owner == &res->unbuffered_fetch_cancelled)
         mysql->unbuffered_fetch_owner= 0;
       /* Don't clear handle in mysql_free_result */
-      res->handle=0;
+      res->mysql= NULL;
     }
     DBUG_RETURN((MYSQL_ROW) NULL);
   }
@@ -2958,8 +2916,9 @@
 
 
 int STDCALL
-mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
+mysql_options(MYSQL *handle, enum mysql_option option, const void *arg)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   DBUG_ENTER("mysql_option");
   DBUG_PRINT("enter",("option: %d",(int) option));
   switch (option) {
@@ -3060,15 +3019,15 @@
   return res->field_count;
 }
 
-uint STDCALL mysql_errno(MYSQL *mysql)
+uint STDCALL mysql_errno(MYSQL *handle)
 {
-  return mysql->net.last_errno;
+  return handle->impl->net.last_errno;
 }
 
 
-const char * STDCALL mysql_error(MYSQL *mysql)
+const char * STDCALL mysql_error(MYSQL *handle)
 {
-  return mysql->net.last_error;
+  return handle->impl->net.last_error;
 }
 
 
@@ -3090,9 +3049,10 @@
 */
 
 ulong STDCALL
-mysql_get_server_version(MYSQL *mysql)
+mysql_get_server_version(MYSQL *handle)
 {
   uint major, minor, version;
+  struct st_mysql_impl *mysql= handle->impl;
   char *pos= mysql->server_version, *end_pos;
   major=   (uint) strtoul(pos, &end_pos, 10);	pos=end_pos+1;
   minor=   (uint) strtoul(pos, &end_pos, 10);	pos=end_pos+1;
@@ -3107,8 +3067,9 @@
    and character_set_connection) and updates mysql->charset so other
    functions like mysql_real_escape will work correctly.
 */
-int STDCALL mysql_set_character_set(MYSQL *mysql, const char *cs_name)
+int STDCALL mysql_set_character_set(MYSQL *handle, const char *cs_name)
 {
+  struct st_mysql_impl *mysql= handle->impl;
   struct charset_info_st *cs;
   const char *save_csdir= charsets_dir;
 
@@ -3121,10 +3082,10 @@
     char buff[MY_CS_NAME_SIZE + 10];
     charsets_dir= save_csdir;
     /* Skip execution of "SET NAMES" for pre-4.1 servers */
-    if (mysql_get_server_version(mysql) < 40100)
+    if (mysql_get_server_version(handle) < 40100)
       return 0;
     sprintf(buff, "SET NAMES %s", cs_name);
-    if (!mysql_real_query(mysql, buff, strlen(buff)))
+    if (!mysql_real_query(handle, buff, strlen(buff)))
     {
       mysql->charset= cs;
     }

--- 1.71/libmysql/Makefile.shared	2007-03-28 01:56:45 +04:00
+++ 1.72/libmysql/Makefile.shared	2007-06-01 23:41:57 +04:00
@@ -31,7 +31,7 @@
 noinst_PROGRAMS = conf_to_src
 
 
-target_sources = 	libmysql.c password.c manager.c \
+target_sources = 	libmysql.c password.c \
 			get_password.c errmsg.c
 
 mystringsobjects =	strmov.lo strxmov.lo strxnmov.lo strnmov.lo \
Thread
bk commit into 5.1 tree (kostja:1.2540)konstantin1 Jun