Commit ccf59c38 authored by unknown's avatar unknown

Cleanup after split of libmysql.c to client.c and libmysql.c. A 4.1...

Cleanup after split of libmysql.c to client.c and libmysql.c.  A 4.1 master/slave will now use the 4.1 protocol
Fixed wrong value for SQLSTATE_LENGTH
Added CLIENT_REMEMBER_OPTIONS to mysql_real_connect()
Changed mysql_port and mysql_unix_port to mysqld_xxxx


client/mysql.cc:
  Removed valgrind & compiler warnings
client/sql_string.h:
  Fix to remove valgrind warnings
include/mysql.h:
  Added read_timeout and write_timeout to mysql options struct.
  This is to be used for slave when connection to master.
  code cleanup
include/mysql_com.h:
  Fixed wrong value for SQLSTATE_LENGTH
  Added CLIENT_REMEMBER_OPTIONS
include/sql_common.h:
  Cleanup after split of libmysql.c to client.c and libmysql.c
include/sql_state.h:
  Removed default states
libmysql/client_settings.h:
  Cleanup after split of libmysql.c to client.c and libmysql.c
libmysql/libmysql.c:
  Cleanup after split of libmysql.c to client.c and libmysql.c
mysql-test/r/type_blob.result:
  Update results after someone updated error messages without running tests
mysys/charset.c:
  More debug information
mysys/errors.c:
  Fixed wrong error message
sql-common/client.c:
  Cleanup after split of libmysql.c to client.c and libmysql.c
sql/Makefile.am:
  Added sql_client.cc
sql/client_settings.h:
  Cleanup after split of libmysql.c to client.c and libmysql.c
sql/log.cc:
  Changed mysql_port and mysql_unix_port to mysqld_xxxx
sql/mysql_priv.h:
  Changed mysql_port and mysql_unix_port to mysqld_xxxx
sql/mysqld.cc:
  Changed mysql_port and mysql_unix_port to mysqld_xxxx
sql/protocol.cc:
  Fix for SQLSTATE_LENGTH
  Moved function to sql_client.c
sql/repl_failsafe.cc:
  Cleanup after split of libmysql.c to client.c and libmysql.c
sql/set_var.cc:
  Changed mysql_port and mysql_unix_port to mysqld_xxxx
sql/slave.cc:
  Cleanup after split of libmysql.c to client.c and libmysql.c
parent 0826127b
...@@ -1525,6 +1525,9 @@ static int com_server_help(String *buffer __attribute__((unused)), ...@@ -1525,6 +1525,9 @@ static int com_server_help(String *buffer __attribute__((unused)),
char last_char; char last_char;
int num_name, num_cat; int num_name, num_cat;
LINT_INIT(num_name);
LINT_INIT(num_cat);
if (num_fields == 2) if (num_fields == 2)
{ {
put_info("Many help items for your request exist", INFO_INFO); put_info("Many help items for your request exist", INFO_INFO);
...@@ -1841,7 +1844,7 @@ print_table_data(MYSQL_RES *result) ...@@ -1841,7 +1844,7 @@ print_table_data(MYSQL_RES *result)
separator.fill(separator.length()+length+2,'-'); separator.fill(separator.length()+length+2,'-');
separator.append('+'); separator.append('+');
} }
tee_puts(separator.c_ptr(), PAGER); tee_puts(separator.c_ptr_safe(), PAGER);
if (column_names) if (column_names)
{ {
mysql_field_seek(result,0); mysql_field_seek(result,0);
......
...@@ -92,6 +92,14 @@ public: ...@@ -92,6 +92,14 @@ public:
Ptr[str_length]=0; Ptr[str_length]=0;
return Ptr; return Ptr;
} }
inline char *c_ptr_safe()
{
if (Ptr && str_length < Alloced_length)
Ptr[str_length]=0;
else
(void) realloc(str_length);
return Ptr;
}
void set(String &str,uint32 offset,uint32 arg_length) void set(String &str,uint32 offset,uint32 arg_length)
{ {
......
...@@ -135,9 +135,9 @@ typedef struct st_mysql_data { ...@@ -135,9 +135,9 @@ typedef struct st_mysql_data {
} MYSQL_DATA; } MYSQL_DATA;
struct st_mysql_options { struct st_mysql_options {
unsigned int connect_timeout; unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int port, protocol;
unsigned long client_flag; unsigned long client_flag;
unsigned int port;
char *host,*user,*password,*unix_socket,*db; char *host,*user,*password,*unix_socket,*db;
struct st_dynamic_array *init_commands; struct st_dynamic_array *init_commands;
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
...@@ -146,6 +146,7 @@ struct st_mysql_options { ...@@ -146,6 +146,7 @@ struct st_mysql_options {
char *ssl_ca; /* PEM CA file */ char *ssl_ca; /* PEM CA file */
char *ssl_capath; /* PEM directory of CA-s? */ char *ssl_capath; /* PEM directory of CA-s? */
char *ssl_cipher; /* cipher to use */ char *ssl_cipher; /* cipher to use */
char *shared_memory_base_name;
unsigned long max_allowed_packet; unsigned long max_allowed_packet;
my_bool use_ssl; /* if to use SSL or not */ my_bool use_ssl; /* if to use SSL or not */
my_bool compress,named_pipe; my_bool compress,named_pipe;
...@@ -167,18 +168,15 @@ struct st_mysql_options { ...@@ -167,18 +168,15 @@ struct st_mysql_options {
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
my_bool separate_thread; my_bool separate_thread;
#endif #endif
char *shared_memory_base_name;
unsigned int protocol;
}; };
enum mysql_option enum mysql_option
{ {
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND, MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
MYSQL_OPT_LOCAL_INFILE, MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
#ifdef EMBEDDED_LIBRARY MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
, MYSQL_OPT_USE_RESULT MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT
#endif
}; };
enum mysql_status enum mysql_status
...@@ -188,8 +186,8 @@ enum mysql_status ...@@ -188,8 +186,8 @@ enum mysql_status
enum mysql_protocol_type enum mysql_protocol_type
{ {
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_MEMORY MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
}; };
/* /*
There are three types of queries - the ones that have to go to There are three types of queries - the ones that have to go to
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#define HOSTNAME_LENGTH 60 #define HOSTNAME_LENGTH 60
#define USERNAME_LENGTH 16 #define USERNAME_LENGTH 16
#define SERVER_VERSION_LENGTH 60 #define SERVER_VERSION_LENGTH 60
#define SQLSTATE_LENGTH 6 #define SQLSTATE_LENGTH 5
#define LOCAL_HOST "localhost" #define LOCAL_HOST "localhost"
#define LOCAL_HOST_NAMEDPIPE "." #define LOCAL_HOST_NAMEDPIPE "."
...@@ -110,6 +110,7 @@ enum enum_server_command ...@@ -110,6 +110,7 @@ enum enum_server_command
#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */ #define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
#define CLIENT_MULTI_QUERIES 65536 /* Enable/disable multiquery support */ #define CLIENT_MULTI_QUERIES 65536 /* Enable/disable multiquery support */
#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */ #define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */
#define CLIENT_REMEMBER_OPTIONS (1L << 31)
#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ #define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
......
...@@ -42,9 +42,5 @@ my_bool mysql_reconnect(MYSQL *mysql); ...@@ -42,9 +42,5 @@ my_bool mysql_reconnect(MYSQL *mysql);
} }
#endif #endif
#ifdef MYSQL_SERVER
#define protocol_41(A) FALSE
#else
#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41) #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
#endif
...@@ -86,7 +86,6 @@ ER_UNSUPPORTED_EXTENSION, "42000", "", ...@@ -86,7 +86,6 @@ ER_UNSUPPORTED_EXTENSION, "42000", "",
ER_TABLE_MUST_HAVE_COLUMNS, "42000", "", ER_TABLE_MUST_HAVE_COLUMNS, "42000", "",
ER_UNKNOWN_CHARACTER_SET, "42000", "", ER_UNKNOWN_CHARACTER_SET, "42000", "",
ER_TOO_BIG_ROWSIZE, "42000", "", ER_TOO_BIG_ROWSIZE, "42000", "",
ER_STACK_OVERRUN, "HY000", "",
ER_WRONG_OUTER_JOIN, "42000", "", ER_WRONG_OUTER_JOIN, "42000", "",
ER_NULL_COLUMN_IN_INDEX, "42000", "", ER_NULL_COLUMN_IN_INDEX, "42000", "",
ER_PASSWORD_ANONYMOUS_USER, "42000", "", ER_PASSWORD_ANONYMOUS_USER, "42000", "",
...@@ -128,8 +127,6 @@ ER_REQUIRES_PRIMARY_KEY, "42000", "", ...@@ -128,8 +127,6 @@ ER_REQUIRES_PRIMARY_KEY, "42000", "",
ER_CHECK_NO_SUCH_TABLE, "42000", "", ER_CHECK_NO_SUCH_TABLE, "42000", "",
ER_CHECK_NOT_IMPLEMENTED, "42000", "", ER_CHECK_NOT_IMPLEMENTED, "42000", "",
ER_CANT_DO_THIS_DURING_AN_TRANSACTION, "25000", "", ER_CANT_DO_THIS_DURING_AN_TRANSACTION, "25000", "",
ER_ERROR_DURING_COMMIT, "HY000", "",
ER_ERROR_DURING_ROLLBACK, "HY000", "",
ER_NEW_ABORTING_CONNECTION, "08S01", "", ER_NEW_ABORTING_CONNECTION, "08S01", "",
ER_MASTER_NET_READ, "08S01", "", ER_MASTER_NET_READ, "08S01", "",
ER_MASTER_NET_WRITE, "08S01", "", ER_MASTER_NET_WRITE, "08S01", "",
......
...@@ -15,27 +15,10 @@ ...@@ -15,27 +15,10 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
static my_bool mysql_client_init=0; #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \
extern uint mysql_port; CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS | \
extern my_string mysql_unix_port; CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
| CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \
| CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0
#endif
#ifdef HAVE_SMEM
char *shared_memory_base_name=0;
const char *def_shared_memory_base_name=default_shared_memory_base_name;
#endif
static my_bool org_my_init_done=0;
sig_handler pipe_sig_handler(int sig __attribute__((unused))); sig_handler pipe_sig_handler(int sig __attribute__((unused)));
my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list); my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
...@@ -48,7 +31,7 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename); ...@@ -48,7 +31,7 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename);
*/ */
#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD) #if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD)
#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0; #define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0
#define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler) #define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler)
#define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler); #define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler);
#else #else
......
...@@ -59,24 +59,11 @@ ...@@ -59,24 +59,11 @@
#include <sql_common.h> #include <sql_common.h>
uint mysql_port=0;
my_string mysql_unix_port=0;
ulong net_buffer_length=8192; ulong net_buffer_length=8192;
ulong max_allowed_packet= 1024L*1024L*1024L; ulong max_allowed_packet= 1024L*1024L*1024L;
ulong net_read_timeout= NET_READ_TIMEOUT; ulong net_read_timeout= NET_READ_TIMEOUT;
ulong net_write_timeout= NET_WRITE_TIMEOUT; ulong net_write_timeout= NET_WRITE_TIMEOUT;
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
| CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \
| CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0
#endif
#if defined(MSDOS) || defined(__WIN__) #if defined(MSDOS) || defined(__WIN__)
/* socket_errno is defined in my_global.h for all platforms */ /* socket_errno is defined in my_global.h for all platforms */
#define perror(A) #define perror(A)
...@@ -85,10 +72,6 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT; ...@@ -85,10 +72,6 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT;
#define SOCKET_ERROR -1 #define SOCKET_ERROR -1
#endif /* __WIN__ */ #endif /* __WIN__ */
const char *sql_protocol_names_lib[] =
{ "TCP", "SOCKET", "PIPE", "MEMORY", NullS };
TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
sql_protocol_names_lib};
/* /*
If allowed through some configuration, then this needs to If allowed through some configuration, then this needs to
be changed be changed
...@@ -101,7 +84,67 @@ sig_handler pipe_sig_handler(int sig); ...@@ -101,7 +84,67 @@ sig_handler pipe_sig_handler(int sig);
static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
const char *from, ulong length); const char *from, ulong length);
my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list); my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
static my_bool org_my_init_done=0;
/*
Initialize the MySQL library
SYNOPSIS
mysql_once_init()
NOTES
Can't be static on NetWare
This function is called by mysql_init() and indirectly called
by mysql_real_query(), so one should never have to call this from an
outside program.
*/
static my_bool mysql_client_init= 0;
static my_bool org_my_init_done= 0;
void mysql_once_init(void)
{
if (!mysql_client_init)
{
mysql_client_init=1;
org_my_init_done=my_init_done;
my_init(); /* Will init threads */
init_client_errs();
if (!mysql_port)
{
mysql_port = MYSQL_PORT;
#ifndef MSDOS
{
struct servent *serv_ptr;
char *env;
if ((serv_ptr = getservbyname("mysql", "tcp")))
mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
if ((env = getenv("MYSQL_TCP_PORT")))
mysql_port =(uint) atoi(env);
}
#endif
}
if (!mysql_unix_port)
{
char *env;
#ifdef __WIN__
mysql_unix_port = (char*) MYSQL_NAMEDPIPE;
#else
mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
#endif
if ((env = getenv("MYSQL_UNIX_PORT")))
mysql_unix_port = env;
}
mysql_debug(NullS);
#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__)
(void) signal(SIGPIPE,SIG_IGN);
#endif
}
#ifdef THREAD
else
my_thread_init(); /* Init if new thread */
#endif
}
int STDCALL mysql_server_init(int argc __attribute__((unused)), int STDCALL mysql_server_init(int argc __attribute__((unused)),
char **argv __attribute__((unused)), char **argv __attribute__((unused)),
...@@ -529,30 +572,6 @@ STDCALL mysql_rpl_query_type(const char* q, int len) ...@@ -529,30 +572,6 @@ STDCALL mysql_rpl_query_type(const char* q, int len)
return MYSQL_RPL_MASTER; /* By default, send to master */ return MYSQL_RPL_MASTER; /* By default, send to master */
} }
/*
Fill in SSL part of MYSQL structure and set 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
*/
#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)) ,
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)))
{
#ifdef HAVE_OPENSSL
mysql->options.ssl_key= strdup_if_not_null(key);
mysql->options.ssl_cert= strdup_if_not_null(cert);
mysql->options.ssl_ca= strdup_if_not_null(ca);
mysql->options.ssl_capath= strdup_if_not_null(capath);
mysql->options.ssl_cipher= strdup_if_not_null(cipher);
#endif /* HAVE_OPENSSL */
return 0;
}
/************************************************************************** /**************************************************************************
Connect to sql server Connect to sql server
...@@ -578,6 +597,7 @@ mysql_connect(MYSQL *mysql,const char *host, ...@@ -578,6 +597,7 @@ mysql_connect(MYSQL *mysql,const char *host,
} }
#endif #endif
/************************************************************************** /**************************************************************************
Change user and database Change user and database
**************************************************************************/ **************************************************************************/
...@@ -836,56 +856,6 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host, ...@@ -836,56 +856,6 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
return 0; return 0;
} }
/**************************************************************************
Alloc struct for use with unbuffered reads. Data is fetched by domand
when calling to mysql_fetch_row.
mysql_data_seek is a noop.
No other queries may be specified with the same MYSQL handle.
There shouldn't be much processing per row because mysql server shouldn't
have to wait for the client (and will not wait more than 30 sec/packet).
**************************************************************************/
MYSQL_RES * STDCALL
mysql_use_result(MYSQL *mysql)
{
MYSQL_RES *result;
DBUG_ENTER("mysql_use_result");
mysql = mysql->last_used_con;
if (!mysql->fields)
DBUG_RETURN(0);
if (mysql->status != MYSQL_STATUS_GET_RESULT)
{
strmov(mysql->net.sqlstate, unknown_sqlstate);
strmov(mysql->net.last_error,
ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
DBUG_RETURN(0);
}
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
sizeof(ulong)*mysql->field_count,
MYF(MY_WME | MY_ZEROFILL))))
DBUG_RETURN(0);
result->lengths=(ulong*) (result+1);
if (!(result->row=(MYSQL_ROW)
my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
{ /* Ptrs: to one row */
my_free((gptr) result,MYF(0));
DBUG_RETURN(0);
}
result->fields= mysql->fields;
result->field_alloc= mysql->field_alloc;
result->field_count= mysql->field_count;
result->current_field=0;
result->handle= mysql;
result->current_row= 0;
mysql->fields=0; /* fields is now in result */
mysql->status=MYSQL_STATUS_USE_RESULT;
DBUG_RETURN(result); /* Data is read to be fetched */
}
/************************************************************************** /**************************************************************************
Return next field of the query results Return next field of the query results
...@@ -899,6 +869,13 @@ mysql_fetch_field(MYSQL_RES *result) ...@@ -899,6 +869,13 @@ mysql_fetch_field(MYSQL_RES *result)
return &result->fields[result->current_field++]; return &result->fields[result->current_field++];
} }
/**************************************************************************
Get column lengths of the current row
If one uses mysql_use_result, res->lengths contains the length information,
else the lengths are calculated from the offset between pointers.
**************************************************************************/
ulong * STDCALL ulong * STDCALL
mysql_fetch_lengths(MYSQL_RES *res) mysql_fetch_lengths(MYSQL_RES *res)
{ {
...@@ -911,6 +888,23 @@ mysql_fetch_lengths(MYSQL_RES *res) ...@@ -911,6 +888,23 @@ mysql_fetch_lengths(MYSQL_RES *res)
return res->lengths; return res->lengths;
} }
/**************************************************************************
Move to a specific row and column
**************************************************************************/
void STDCALL
mysql_data_seek(MYSQL_RES *result, my_ulonglong row)
{
MYSQL_ROWS *tmp=0;
DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row));
if (result->data)
for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
result->current_row=0;
result->data_cursor = tmp;
}
/************************************************************************* /*************************************************************************
put the row or field cursor one a position one got from mysql_row_tell() put the row or field cursor one a position one got from mysql_row_tell()
This doesn't restore any data. The next mysql_fetch_row or This doesn't restore any data. The next mysql_fetch_row or
...@@ -935,6 +929,7 @@ mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset) ...@@ -935,6 +929,7 @@ mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset)
return return_value; return return_value;
} }
/***************************************************************************** /*****************************************************************************
List all databases List all databases
*****************************************************************************/ *****************************************************************************/
...@@ -2444,7 +2439,7 @@ static void send_data_long(MYSQL_BIND *param, longlong value) ...@@ -2444,7 +2439,7 @@ static void send_data_long(MYSQL_BIND *param, longlong value)
} }
default: default:
{ {
char tmp[12]; char tmp[22]; /* Enough for longlong */
uint length= (uint)(longlong10_to_str(value,(char *)tmp,10)-tmp); uint length= (uint)(longlong10_to_str(value,(char *)tmp,10)-tmp);
ulong copy_length= min((ulong)length-param->offset, param->buffer_length); ulong copy_length= min((ulong)length-param->offset, param->buffer_length);
memcpy(buffer, (char *)tmp+param->offset, copy_length); memcpy(buffer, (char *)tmp+param->offset, copy_length);
...@@ -2492,7 +2487,7 @@ static void send_data_double(MYSQL_BIND *param, double value) ...@@ -2492,7 +2487,7 @@ static void send_data_double(MYSQL_BIND *param, double value)
} }
default: default:
{ {
char tmp[12]; char tmp[128];
uint length= my_sprintf(tmp,(tmp,"%g",value)); uint length= my_sprintf(tmp,(tmp,"%g",value));
ulong copy_length= min((ulong)length-param->offset, param->buffer_length); ulong copy_length= min((ulong)length-param->offset, param->buffer_length);
memcpy(buffer, (char *)tmp+param->offset, copy_length); memcpy(buffer, (char *)tmp+param->offset, copy_length);
......
...@@ -29,7 +29,7 @@ drop table t1,t2,t3 ...@@ -29,7 +29,7 @@ drop table t1,t2,t3
CREATE TABLE t1 (a char(257) default "hello"); CREATE TABLE t1 (a char(257) default "hello");
ERROR 42000: Too big column length for column 'a' (max = 255). Use BLOB instead ERROR 42000: Too big column length for column 'a' (max = 255). Use BLOB instead
CREATE TABLE t2 (a blob default "hello"); CREATE TABLE t2 (a blob default "hello");
ERROR 42000: BLOB column 'a' can't have a default value ERROR 42000: BLOB/TEXT column 'a' can't have a default value
drop table if exists t1,t2; drop table if exists t1,t2;
create table t1 (nr int(5) not null auto_increment,b blob,str char(10), primary key (nr)); create table t1 (nr int(5) not null auto_increment,b blob,str char(10), primary key (nr));
insert into t1 values (null,"a","A"); insert into t1 values (null,"a","A");
......
...@@ -368,6 +368,7 @@ static my_bool my_read_charset_file(const char *filename, myf myflags) ...@@ -368,6 +368,7 @@ static my_bool my_read_charset_file(const char *filename, myf myflags)
char *get_charsets_dir(char *buf) char *get_charsets_dir(char *buf)
{ {
const char *sharedir= SHAREDIR; const char *sharedir= SHAREDIR;
char *res;
DBUG_ENTER("get_charsets_dir"); DBUG_ENTER("get_charsets_dir");
if (charsets_dir != NULL) if (charsets_dir != NULL)
...@@ -381,9 +382,9 @@ char *get_charsets_dir(char *buf) ...@@ -381,9 +382,9 @@ char *get_charsets_dir(char *buf)
strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR, strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR,
NullS); NullS);
} }
convert_dirname(buf,buf,NullS); res= convert_dirname(buf,buf,NullS);
DBUG_PRINT("info",("charsets dir: '%s'", buf)); DBUG_PRINT("info",("charsets dir: '%s'", buf));
DBUG_RETURN(strend(buf)); DBUG_RETURN(res);
} }
CHARSET_INFO *all_charsets[256]; CHARSET_INFO *all_charsets[256];
...@@ -613,6 +614,9 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name, ...@@ -613,6 +614,9 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name,
{ {
CHARSET_INFO *cs=NULL; CHARSET_INFO *cs=NULL;
CHARSET_INFO **css; CHARSET_INFO **css;
DBUG_ENTER("get_charset_by_csname");
DBUG_PRINT("enter",("name: '%s'", cs_name));
(void) init_available_charsets(MYF(0)); /* If it isn't initialized */ (void) init_available_charsets(MYF(0)); /* If it isn't initialized */
for (css= all_charsets; css < all_charsets+255; ++css) for (css= all_charsets; css < all_charsets+255; ++css)
...@@ -624,7 +628,7 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name, ...@@ -624,7 +628,7 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name,
cs= css[0]->number ? get_internal_charset(css[0]->number,flags) : NULL; cs= css[0]->number ? get_internal_charset(css[0]->number,flags) : NULL;
break; break;
} }
} }
if (!cs && (flags & MY_WME)) if (!cs && (flags & MY_WME))
{ {
...@@ -633,5 +637,5 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name, ...@@ -633,5 +637,5 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name,
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file); my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
} }
return cs; DBUG_RETURN(cs);
} }
...@@ -82,7 +82,7 @@ void init_glob_errs() ...@@ -82,7 +82,7 @@ void init_glob_errs()
EE(EE_OPEN_WARNING) = "%d files and %d streams is left open\n"; EE(EE_OPEN_WARNING) = "%d files and %d streams is left open\n";
EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space..."; EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space...";
EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)"; EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)";
EE(EE_UNKNOWN_CHARSET)= "Character set is not a compiled character set and is not specified in the %s file"; EE(EE_UNKNOWN_CHARSET)= "Character set '%s' is not a compiled character set and is not specified in the %s file";
EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)"; EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)";
EE(EE_CANT_READLINK)="Can't read value for symlink '%s' (Error %d)"; EE(EE_CANT_READLINK)="Can't read value for symlink '%s' (Error %d)";
EE(EE_CANT_SYMLINK)="Can't create symlink '%s' pointing at '%s' (Error %d)"; EE(EE_CANT_SYMLINK)="Can't create symlink '%s' pointing at '%s' (Error %d)";
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000-2003 MySQL AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -37,13 +37,11 @@ ...@@ -37,13 +37,11 @@
#include <my_global.h> #include <my_global.h>
#if defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT)
#include "mysql.h" #include "mysql.h"
#if !defined(MYSQL_SERVER) && defined(__WIN__) || defined(_WIN32) || defined(_WIN64) #if !defined(MYSQL_SERVER) && (defined(__WIN__) || defined(_WIN32) || defined(_WIN64))
#include <winsock.h> #include <winsock.h>
#include <odbcinst.h> #include <odbcinst.h>
#endif #endif /* !defined(MYSQL_SERVER) && (defined(__WIN__) ... */
#include <my_sys.h> #include <my_sys.h>
#include <mysys_err.h> #include <mysys_err.h>
#include <m_string.h> #include <m_string.h>
...@@ -55,21 +53,19 @@ ...@@ -55,21 +53,19 @@
#include <assert.h> #include <assert.h>
#if defined(THREAD) && !defined(__WIN__) #if defined(THREAD) && !defined(__WIN__)
#include <my_pthread.h> /* because of signal() */ #include <my_pthread.h> /* because of signal() */
#endif #endif /* defined(THREAD) && !defined(__WIN__) */
#if defined( OS2) && defined(MYSQL_SERVER) #if defined(OS2) && defined(MYSQL_SERVER)
#undef ER #undef ER
#define ER CER #define ER CER
#endif #endif /* defined( OS2) && defined(MYSQL_SERVER) */
#include <sys/stat.h> #include <sys/stat.h>
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
#include <pwd.h> #include <pwd.h>
#endif #endif
#if !defined(MSDOS) && !defined(__WIN__) #if !defined(MSDOS) && !defined(__WIN__)
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
...@@ -96,16 +92,27 @@ ...@@ -96,16 +92,27 @@
#define SOCKET_ERROR -1 #define SOCKET_ERROR -1
#endif #endif
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0
#endif
#include "client_settings.h" #include "client_settings.h"
#include <sql_common.h> #include <sql_common.h>
const char *unknown_sqlstate= "HY0000"; uint mysql_port=0;
char *mysql_unix_port= 0;
const char *unknown_sqlstate= "HY000";
const char *not_error_sqlstate= "00000"; const char *not_error_sqlstate= "00000";
#ifdef HAVE_SMEM
#ifdef MYSQL_CLIENT char *shared_memory_base_name= 0;
extern my_bool stmt_close(MYSQL_STMT *stmt,my_bool skip_list); const char def_shared_memory_base_name= default_shared_memory_base_name;
#endif #endif
static void mysql_close_free_options(MYSQL *mysql);
static void mysql_close_free(MYSQL *mysql);
/**************************************************************************** /****************************************************************************
A modified version of connect(). my_connect() allows you to specify A modified version of connect(). my_connect() allows you to specify
a timeout value, in seconds, that we should wait until we a timeout value, in seconds, that we should wait until we
...@@ -293,6 +300,7 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, ...@@ -293,6 +300,7 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host,
} }
#endif #endif
/* /*
Create new shared memory connection, return handler of connection Create new shared memory connection, return handler of connection
...@@ -310,7 +318,8 @@ HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout) ...@@ -310,7 +318,8 @@ HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout)
/* /*
event_connect_request is event object for start connection actions event_connect_request is event object for start connection actions
event_connect_answer is event object for confirm, that server put data event_connect_answer is event object for confirm, that server put data
handle_connect_file_map is file-mapping object, use for create shared memory handle_connect_file_map is file-mapping object, use for create shared
memory
handle_connect_map is pointer on shared memory handle_connect_map is pointer on shared memory
handle_map is pointer on shared memory for client handle_map is pointer on shared memory for client
event_server_wrote, event_server_wrote,
...@@ -594,8 +603,6 @@ advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -594,8 +603,6 @@ advanced_command(MYSQL *mysql, enum enum_server_command command,
mysql->info=0; mysql->info=0;
mysql->affected_rows= ~(my_ulonglong) 0; mysql->affected_rows= ~(my_ulonglong) 0;
net_clear(&mysql->net); /* Clear receive buffer */ net_clear(&mysql->net); /* Clear receive buffer */
if (!arg)
arg="";
if (net_write_command(net,(uchar) command, header, header_length, if (net_write_command(net,(uchar) command, header, header_length,
arg, arg_length)) arg, arg_length))
...@@ -640,8 +647,7 @@ void free_old_query(MYSQL *mysql) ...@@ -640,8 +647,7 @@ void free_old_query(MYSQL *mysql)
DBUG_ENTER("free_old_query"); DBUG_ENTER("free_old_query");
if (mysql->fields) if (mysql->fields)
free_root(&mysql->field_alloc,MYF(0)); free_root(&mysql->field_alloc,MYF(0));
else init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */
init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */
mysql->fields=0; mysql->fields=0;
mysql->field_count=0; /* For API */ mysql->field_count=0; /* For API */
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -676,6 +682,7 @@ void end_server(MYSQL *mysql) ...@@ -676,6 +682,7 @@ void end_server(MYSQL *mysql)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
void STDCALL void STDCALL
mysql_free_result(MYSQL_RES *result) mysql_free_result(MYSQL_RES *result)
{ {
...@@ -726,6 +733,11 @@ static const char *default_options[]= ...@@ -726,6 +733,11 @@ static const char *default_options[]=
static TYPELIB option_types={array_elements(default_options)-1, static TYPELIB option_types={array_elements(default_options)-1,
"options",default_options}; "options",default_options};
const char *sql_protocol_names_lib[] =
{ "TCP", "SOCKET", "PIPE", "MEMORY", NullS };
TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
sql_protocol_names_lib};
static int add_init_command(struct st_mysql_options *options, const char *cmd) static int add_init_command(struct st_mysql_options *options, const char *cmd)
{ {
char *tmp; char *tmp;
...@@ -832,8 +844,8 @@ static void mysql_read_default_options(struct st_mysql_options *options, ...@@ -832,8 +844,8 @@ static void mysql_read_default_options(struct st_mysql_options *options,
options->db=my_strdup(opt_arg,MYF(MY_WME)); options->db=my_strdup(opt_arg,MYF(MY_WME));
} }
break; break;
#ifdef MYSQL_CLIENT
case 11: /* debug */ case 11: /* debug */
#ifdef MYSQL_CLIENT
mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace");
break; break;
#endif #endif
...@@ -885,26 +897,30 @@ static void mysql_read_default_options(struct st_mysql_options *options, ...@@ -885,26 +897,30 @@ static void mysql_read_default_options(struct st_mysql_options *options,
options->client_flag&= CLIENT_LOCAL_FILES; options->client_flag&= CLIENT_LOCAL_FILES;
break; break;
case 23: /* replication probe */ case 23: /* replication probe */
#ifndef TO_BE_DELETED
options->rpl_probe= 1; options->rpl_probe= 1;
#endif
break; break;
case 24: /* enable-reads-from-master */ case 24: /* enable-reads-from-master */
options->no_master_reads= 0; options->no_master_reads= 0;
break; break;
case 25: /* repl-parse-query */ case 25: /* repl-parse-query */
#ifndef TO_BE_DELETED
options->rpl_parse= 1; options->rpl_parse= 1;
#endif
break; break;
case 27: case 27:
options->max_allowed_packet= atoi(opt_arg); options->max_allowed_packet= atoi(opt_arg);
break; break;
#ifdef MYSQL_CLIENT
case 28: /* protocol */ case 28: /* protocol */
if ((options->protocol = find_type(opt_arg, &sql_protocol_typelib,0)) == ~(ulong) 0) if ((options->protocol = find_type(opt_arg,
&sql_protocol_typelib,0))
== ~(ulong) 0)
{ {
fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg); fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg);
exit(1); exit(1);
} }
break; break;
#endif
case 29: /* shared_memory_base_name */ case 29: /* shared_memory_base_name */
#ifdef HAVE_SMEM #ifdef HAVE_SMEM
if (options->shared_memory_base_name != def_shared_memory_base_name) if (options->shared_memory_base_name != def_shared_memory_base_name)
...@@ -928,6 +944,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, ...@@ -928,6 +944,7 @@ static void mysql_read_default_options(struct st_mysql_options *options,
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/************************************************************************** /**************************************************************************
Get column lengths of the current row Get column lengths of the current row
If one uses mysql_use_result, res->lengths contains the length information, If one uses mysql_use_result, res->lengths contains the length information,
...@@ -956,51 +973,6 @@ void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count) ...@@ -956,51 +973,6 @@ void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count)
} }
static inline void
unpack_fields_40(MYSQL_ROWS *row, MYSQL_FIELD *field, MEM_ROOT *alloc,
ulong *lengths, uint n_lengths,
my_bool default_value, my_bool long_flag_protocol)
{
DBUG_ENTER("unpack_fields_40");
for (; row ; row = row->next,field++)
{
fetch_lengths(lengths, row->data, n_lengths);
field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]);
field->name= strdup_root(alloc,(char*) row->data[1]);
field->length= (uint) uint3korr(row->data[2]);
field->type= (enum enum_field_types) (uchar) row->data[3][0];
field->catalog=(char*) "";
field->db= (char*) "";
field->catalog_length= 0;
field->db_length= 0;
field->org_table_length= field->table_length= lengths[0];
field->name_length= lengths[1];
if (long_flag_protocol)
{
field->flags= uint2korr(row->data[4]);
field->decimals=(uint) (uchar) row->data[4][2];
}
else
{
field->flags= (uint) (uchar) row->data[4][0];
field->decimals=(uint) (uchar) row->data[4][1];
}
if (INTERNAL_NUM_FIELD(field))
field->flags|= NUM_FLAG;
if (default_value && row->data[5])
{
field->def=strdup_root(alloc,(char*) row->data[5]);
field->def_length= lengths[5];
}
else
field->def=0;
field->max_length= 0;
}
}
/*************************************************************************** /***************************************************************************
Change field rows to field structs Change field rows to field structs
***************************************************************************/ ***************************************************************************/
...@@ -1009,25 +981,19 @@ MYSQL_FIELD * ...@@ -1009,25 +981,19 @@ MYSQL_FIELD *
unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
my_bool default_value, uint server_capabilities) my_bool default_value, uint server_capabilities)
{ {
#ifdef MYSQL_CLIENT
MYSQL_ROWS *row; MYSQL_ROWS *row;
#endif
MYSQL_FIELD *field,*result; MYSQL_FIELD *field,*result;
ulong lengths[9]; /* Max of fields */ ulong lengths[9]; /* Max of fields */
DBUG_ENTER("unpack_fields"); DBUG_ENTER("unpack_fields");
field=result=(MYSQL_FIELD*) alloc_root(alloc, field= result= (MYSQL_FIELD*) alloc_root(alloc,
(uint) sizeof(MYSQL_FIELD)*fields); (uint) sizeof(*field)*fields);
if (!result) if (!result)
{ {
free_rows(data); /* Free old data */ free_rows(data); /* Free old data */
DBUG_RETURN(0); DBUG_RETURN(0);
} }
bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields); bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields);
#ifdef MYSQL_SERVER
unpack_fields_40(data->data, field, alloc, lengths, default_value ? 6 : 5,
default_value, (my_bool)(server_capabilities & CLIENT_LONG_FLAG));
#else
if (server_capabilities & CLIENT_PROTOCOL_41) if (server_capabilities & CLIENT_PROTOCOL_41)
{ {
/* server is 4.1, and returns the new field result format */ /* server is 4.1, and returns the new field result format */
...@@ -1071,10 +1037,46 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, ...@@ -1071,10 +1037,46 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
} }
#ifndef DELETE_SUPPORT_OF_4_0_PROTOCOL #ifndef DELETE_SUPPORT_OF_4_0_PROTOCOL
else else
unpack_fields_40(data->data, field, alloc, lengths, default_value ? 6 : 5, {
default_value, (my_bool)(server_capabilities & CLIENT_LONG_FLAG)); /* old protocol, for backward compatibility */
for (row=data->data; row ; row = row->next,field++)
{
fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5);
field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]);
field->name= strdup_root(alloc,(char*) row->data[1]);
field->length= (uint) uint3korr(row->data[2]);
field->type= (enum enum_field_types) (uchar) row->data[3][0];
field->catalog=(char*) "";
field->db= (char*) "";
field->catalog_length= 0;
field->db_length= 0;
field->org_table_length= field->table_length= lengths[0];
field->name_length= lengths[1];
if (server_capabilities & CLIENT_LONG_FLAG)
{
field->flags= uint2korr(row->data[4]);
field->decimals=(uint) (uchar) row->data[4][2];
}
else
{
field->flags= (uint) (uchar) row->data[4][0];
field->decimals=(uint) (uchar) row->data[4][1];
}
if (INTERNAL_NUM_FIELD(field))
field->flags|= NUM_FLAG;
if (default_value && row->data[5])
{
field->def=strdup_root(alloc,(char*) row->data[5]);
field->def_length= lengths[5];
}
else
field->def=0;
field->max_length= 0;
}
}
#endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */ #endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */
#endif /*MYSQL_SERVER*/
free_rows(data); /* Free old data */ free_rows(data); /* Free old data */
DBUG_RETURN(result); DBUG_RETURN(result);
} }
...@@ -1172,13 +1174,11 @@ MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, ...@@ -1172,13 +1174,11 @@ MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
} }
} }
*prev_ptr=0; /* last pointer is null */ *prev_ptr=0; /* last pointer is null */
#ifndef MYSQL_SERVER
if (pkt_len > 1) /* MySQL 4.1 protocol */ if (pkt_len > 1) /* MySQL 4.1 protocol */
{ {
mysql->warning_count= uint2korr(cp+1); mysql->warning_count= uint2korr(cp+1);
DBUG_PRINT("info",("warning_count: %ld", mysql->warning_count)); DBUG_PRINT("info",("warning_count: %ld", mysql->warning_count));
} }
#endif
DBUG_PRINT("exit",("Got %d rows",result->rows)); DBUG_PRINT("exit",("Got %d rows",result->rows));
DBUG_RETURN(result); DBUG_RETURN(result);
} }
...@@ -1201,10 +1201,8 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) ...@@ -1201,10 +1201,8 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
return -1; return -1;
if (pkt_len <= 8 && net->read_pos[0] == 254) if (pkt_len <= 8 && net->read_pos[0] == 254)
{ {
#ifndef MYSQL_SERVER
if (pkt_len > 1) /* MySQL 4.1 protocol */ if (pkt_len > 1) /* MySQL 4.1 protocol */
mysql->warning_count= uint2korr(net->read_pos+1); mysql->warning_count= uint2korr(net->read_pos+1);
#endif
return 1; /* End of data */ return 1; /* End of data */
} }
prev_pos= 0; /* allowed to write at packet[-1] */ prev_pos= 0; /* allowed to write at packet[-1] */
...@@ -1256,102 +1254,84 @@ mysql_init(MYSQL *mysql) ...@@ -1256,102 +1254,84 @@ mysql_init(MYSQL *mysql)
} }
else else
bzero((char*) (mysql),sizeof(*(mysql))); bzero((char*) (mysql),sizeof(*(mysql)));
#ifndef MYSQL_SERVER mysql->options.connect_timeout= CONNECT_TIMEOUT;
mysql->options.connect_timeout=CONNECT_TIMEOUT; mysql->last_used_con= mysql->next_slave= mysql->master = mysql;
mysql->last_used_con = mysql->next_slave = mysql->master = mysql;
/* /*
By default, we are a replication pivot. The caller must reset it By default, we are a replication pivot. The caller must reset it
after we return if this is not the case. after we return if this is not the case.
*/ */
#ifndef TO_BE_DELETED
mysql->rpl_pivot = 1; mysql->rpl_pivot = 1;
#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) #endif
#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) && !defined(MYSQL_SERVER)
if (!((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE)) if (!((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE))
(void) signal(SIGPIPE,pipe_sig_handler); (void) signal(SIGPIPE,pipe_sig_handler);
#endif #endif
/* /*
Only enable LOAD DATA INFILE by default if configured with Only enable LOAD DATA INFILE by default if configured with
--enable-local-infile --enable-local-infile
*/ */
#ifdef ENABLED_LOCAL_INFILE #if defined(ENABLED_LOCAL_INFILE) && !defined(MYSQL_SERVER)
mysql->options.client_flag|= CLIENT_LOCAL_FILES; mysql->options.client_flag|= CLIENT_LOCAL_FILES;
#endif #endif
#ifdef HAVE_SMEM #ifdef HAVE_SMEM
mysql->options.shared_memory_base_name=(char*)def_shared_memory_base_name; mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name;
#endif #endif
#else /*MYSQL_SERVER*/
#ifdef __WIN__
mysql->options.connect_timeout=20;
#endif
#endif /*MYSQL_SERVER*/
return mysql; return mysql;
} }
/* /*
Initialize the MySQL library Fill in SSL part of MYSQL structure and set 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
SYNOPSIS
mysql_once_init()
NOTES
Can't be static on NetWare
This function is called by mysql_init() and indirectly called
by mysql_query(), so one should never have to call this from an
outside program.
*/ */
void mysql_once_init(void) #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)) ,
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)))
{ {
#ifndef MYSQL_SERVER #ifdef HAVE_OPENSSL
mysql->options.ssl_key= strdup_if_not_null(key);
mysql->options.ssl_cert= strdup_if_not_null(cert);
mysql->options.ssl_ca= strdup_if_not_null(ca);
mysql->options.ssl_capath= strdup_if_not_null(capath);
mysql->options.ssl_cipher= strdup_if_not_null(cipher);
#endif /* HAVE_OPENSSL */
return 0;
}
if (!mysql_client_init)
{
mysql_client_init=1;
org_my_init_done=my_init_done;
my_init(); /* Will init threads */
init_client_errs();
if (!mysql_port)
{
mysql_port = MYSQL_PORT;
#ifndef MSDOS
{
struct servent *serv_ptr;
char *env;
if ((serv_ptr = getservbyname("mysql", "tcp")))
mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
if ((env = getenv("MYSQL_TCP_PORT")))
mysql_port =(uint) atoi(env);
}
#endif
}
if (!mysql_unix_port)
{
char *env;
#ifdef __WIN__
mysql_unix_port = (char*) MYSQL_NAMEDPIPE;
#else
mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
#endif
if ((env = getenv("MYSQL_UNIX_PORT")))
mysql_unix_port = env;
}
mysql_debug(NullS);
#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__)
(void) signal(SIGPIPE,SIG_IGN);
#endif
}
#ifdef THREAD
else
my_thread_init(); /* Init if new thread */
#endif
#else /*MYSQL_SERVER*/ /*
init_client_errs(); Free strings in the SSL structure and clear 'use_ssl' flag.
#endif /*MYSQL_SERVER*/ NB! Errors are not reported until you do mysql_real_connect.
*/
#ifdef HAVE_OPENSSL
static void
mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
{
my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR));
mysql->options.ssl_key = 0;
mysql->options.ssl_cert = 0;
mysql->options.ssl_ca = 0;
mysql->options.ssl_capath = 0;
mysql->options.ssl_cipher= 0;
mysql->options.use_ssl = FALSE;
mysql->connector_fd = 0;
} }
#endif /* HAVE_OPENSSL */
/* /*
...@@ -1423,6 +1403,7 @@ error: ...@@ -1423,6 +1403,7 @@ error:
return 1; return 1;
} }
/* /*
Note that the mysql argument must be initialized with mysql_init() Note that the mysql argument must be initialized with mysql_init()
before calling mysql_real_connect ! before calling mysql_real_connect !
...@@ -1433,12 +1414,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1433,12 +1414,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db, const char *passwd, const char *db,
uint port, const char *unix_socket,ulong client_flag) uint port, const char *unix_socket,ulong client_flag)
{ {
#ifdef MYSQL_CLIENT char buff[NAME_LEN+USERNAME_LENGTH+100],charset_name_buff[16];
char *charset_name; char *end,*host_info,*charset_name;
char charset_name_buff[16];
#endif
char buff[NAME_LEN+USERNAME_LENGTH+100];
char *end,*host_info;
my_socket sock; my_socket sock;
uint32 ip_addr; uint32 ip_addr;
struct sockaddr_in sock_addr; struct sockaddr_in sock_addr;
...@@ -1447,16 +1424,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1447,16 +1424,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
thr_alarm_t alarmed; thr_alarm_t alarmed;
ALARM alarm_buff; ALARM alarm_buff;
ulong max_allowed_packet;
#endif #endif
#ifdef __WIN__ #ifdef __WIN__
HANDLE hPipe=INVALID_HANDLE_VALUE; HANDLE hPipe=INVALID_HANDLE_VALUE;
#endif #endif
#ifdef HAVE_SYS_UN_H #ifdef HAVE_SYS_UN_H
struct sockaddr_un UNIXaddr; struct sockaddr_un UNIXaddr;
#endif #endif
init_sigpipe_variables init_sigpipe_variables;
DBUG_ENTER("mysql_real_connect"); DBUG_ENTER("mysql_real_connect");
LINT_INIT(host_info); LINT_INIT(host_info);
...@@ -1469,9 +1444,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1469,9 +1444,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
set_sigpipe(mysql); set_sigpipe(mysql);
net->vio = 0; /* If something goes wrong */ net->vio = 0; /* If something goes wrong */
mysql->client_flag=0; /* For handshake */ mysql->client_flag=0; /* For handshake */
#ifdef MYSQL_SERVER
mysql->charset=default_charset_info; /* Set character set */
#endif
/* use default options */ /* use default options */
if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
...@@ -1493,7 +1465,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1493,7 +1465,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (!passwd) if (!passwd)
{ {
passwd=mysql->options.password; passwd=mysql->options.password;
#ifndef DONT_USE_MYSQL_PWD #if !defined(DONT_USE_MYSQL_PWD) && !defined(MYSQL_SERVER)
if (!passwd) if (!passwd)
passwd=getenv("MYSQL_PWD"); /* get it from environment */ passwd=getenv("MYSQL_PWD"); /* get it from environment */
#endif #endif
...@@ -1511,7 +1483,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1511,7 +1483,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
/* /*
Grab a socket and connect it to the server Grab a socket and connect it to the server
*/ */
#ifdef HAVE_SMEM #if defined(HAVE_SMEM)
if ((!mysql->options.protocol || if ((!mysql->options.protocol ||
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) && mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
(!host || !strcmp(host,LOCAL_HOST))) (!host || !strcmp(host,LOCAL_HOST)))
...@@ -1537,86 +1509,76 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1537,86 +1509,76 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
host=mysql->options.shared_memory_base_name; host=mysql->options.shared_memory_base_name;
host_info=(char*) ER(CR_SHARED_MEMORY_CONNECTION); host_info=(char*) ER(CR_SHARED_MEMORY_CONNECTION);
} }
} else }
#endif /* HAVE_SMEM */ #endif /* HAVE_SMEM */
#if defined(HAVE_SYS_UN_H) #if defined(HAVE_SYS_UN_H)
if ((!mysql->options.protocol || if (!net->vio &&
mysql->options.protocol == MYSQL_PROTOCOL_SOCKET)&& (!mysql->options.protocol ||
(unix_socket || mysql_unix_port) && mysql->options.protocol == MYSQL_PROTOCOL_SOCKET) &&
(!host || !strcmp(host,LOCAL_HOST))) (unix_socket || mysql_unix_port) &&
(!host || !strcmp(host,LOCAL_HOST)))
{
host=LOCAL_HOST;
if (!unix_socket)
unix_socket=mysql_unix_port;
host_info=(char*) ER(CR_LOCALHOST_CONNECTION);
DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
{ {
host=LOCAL_HOST; net->last_errno=CR_SOCKET_CREATE_ERROR;
if (!unix_socket) strmov(net->sqlstate, unknown_sqlstate);
unix_socket=mysql_unix_port; sprintf(net->last_error,ER(net->last_errno),socket_errno);
host_info=(char*) ER(CR_LOCALHOST_CONNECTION); goto error;
DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); }
if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) net->vio = vio_new(sock, VIO_TYPE_SOCKET, TRUE);
{ bzero((char*) &UNIXaddr,sizeof(UNIXaddr));
net->last_errno=CR_SOCKET_CREATE_ERROR; UNIXaddr.sun_family = AF_UNIX;
strmov(net->sqlstate, unknown_sqlstate); strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1);
sprintf(net->last_error,ER(net->last_errno),socket_errno); if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr),
goto error; mysql->options.connect_timeout))
} {
net->vio = vio_new(sock, VIO_TYPE_SOCKET, TRUE); DBUG_PRINT("error",("Got error %d on connect to local server",
bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); socket_errno));
UNIXaddr.sun_family = AF_UNIX; net->last_errno=CR_CONNECTION_ERROR;
strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1); strmov(net->sqlstate, unknown_sqlstate);
if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr), sprintf(net->last_error,ER(net->last_errno),unix_socket,socket_errno);
mysql->options.connect_timeout)) goto error;
{ }
DBUG_PRINT("error",("Got error %d on connect to local server", mysql->options.protocol=MYSQL_PROTOCOL_SOCKET;
socket_errno)); }
net->last_errno=CR_CONNECTION_ERROR; #elif defined(__WIN__)
strmov(net->sqlstate, unknown_sqlstate); if (!net->vio &&
sprintf(net->last_error,ER(net->last_errno),unix_socket,socket_errno); (mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
(host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
(! have_tcpip && (unix_socket || !host && is_NT()))))
{
sock=0;
if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout,
(char**) &host, (char**) &unix_socket)) ==
INVALID_HANDLE_VALUE)
{
DBUG_PRINT("error",
("host: '%s' socket: '%s' have_tcpip: %d",
host ? host : "<null>",
unix_socket ? unix_socket : "<null>",
(int) have_tcpip));
if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
(host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
(unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE)))
goto error; goto error;
} /* Try also with TCP/IP */
#ifdef MYSQL_CLIENT
else
mysql->options.protocol=MYSQL_PROTOCOL_SOCKET;
#endif
} }
else else
#elif defined(__WIN__)
{ {
if ((!mysql->options.protocol || net->vio=vio_new_win32pipe(hPipe);
mysql->options.protocol == MYSQL_PROTOCOL_PIPE)&& sprintf(host_info=buff, ER(CR_NAMEDPIPE_CONNECTION), host,
((unix_socket || !host && is_NT() || unix_socket);
host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) ||! have_tcpip))&&
(!net->vio))
{
sock=0;
if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout,
(char**) &host, (char**) &unix_socket)) ==
INVALID_HANDLE_VALUE)
{
DBUG_PRINT("error",
("host: '%s' socket: '%s' have_tcpip: %d",
host ? host : "<null>",
unix_socket ? unix_socket : "<null>",
(int) have_tcpip));
if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
(host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
(unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE)))
goto error;
/* Try also with TCP/IP */
}
else
{
net->vio=vio_new_win32pipe(hPipe);
sprintf(host_info=buff, ER(CR_NAMEDPIPE_CONNECTION), host,
unix_socket);
}
}
} }
#ifdef MYSQL_SERVER }
if (hPipe == INVALID_HANDLE_VALUE)
#endif
#endif
#ifdef MYSQL_CLIENT
if ((!mysql->options.protocol ||
mysql->options.protocol == MYSQL_PROTOCOL_TCP)&&(!net->vio))
#endif #endif
if (!net->vio &&
(!mysql->options.protocol ||
mysql->options.protocol == MYSQL_PROTOCOL_TCP))
{ {
unix_socket=0; /* This is not used */ unix_socket=0; /* This is not used */
if (!port) if (!port)
...@@ -1629,11 +1591,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1629,11 +1591,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
thr_alarm_init(&alarmed); thr_alarm_init(&alarmed);
thr_alarm(&alarmed, mysql->options.connect_timeout, &alarm_buff); thr_alarm(&alarmed, mysql->options.connect_timeout, &alarm_buff);
#endif #endif
/* _WIN64 ; Assume that the (int) range is enough for socket() */
sock = (my_socket) socket(AF_INET,SOCK_STREAM,0); sock = (my_socket) socket(AF_INET,SOCK_STREAM,0);
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
thr_end_alarm(&alarmed); thr_end_alarm(&alarmed);
#endif #endif
/* _WIN64 ; Assume that the (int) range is enough for socket() */
if (sock == SOCKET_ERROR) if (sock == SOCKET_ERROR)
{ {
net->last_errno=CR_IPSOCK_ERROR; net->last_errno=CR_IPSOCK_ERROR;
...@@ -1683,17 +1645,16 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1683,17 +1645,16 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
goto error; goto error;
} }
} }
#ifdef MYSQL_CLIENT if (!net->vio)
else if (!net->vio)
{ {
DBUG_PRINT("error",("Unknow protocol %d ",mysql->options.protocol)); DBUG_PRINT("error",("Unknow protocol %d ",mysql->options.protocol));
net->last_errno= CR_CONN_UNKNOW_PROTOCOL;
strmov(net->sqlstate, unknown_sqlstate); strmov(net->sqlstate, unknown_sqlstate);
sprintf(net->last_error ,ER(CR_CONN_UNKNOW_PROTOCOL)); net->last_errno= CR_CONN_UNKNOW_PROTOCOL;
strmov(net->last_error, ER(CR_CONN_UNKNOW_PROTOCOL));
goto error; goto error;
} }
#endif /*MYSQL_CLIENT*/
if (!net->vio || my_net_init(net, net->vio)) if (my_net_init(net, net->vio))
{ {
vio_delete(net->vio); vio_delete(net->vio);
net->vio = 0; net->vio = 0;
...@@ -1703,9 +1664,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1703,9 +1664,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
goto error; goto error;
} }
vio_keepalive(net->vio,TRUE); vio_keepalive(net->vio,TRUE);
#ifdef MYSQL_SERVER /* Override local client variables */
net->read_timeout=slave_net_timeout; if (mysql->options.read_timeout)
#endif net->read_timeout= mysql->options.read_timeout;
if (mysql->options.write_timeout)
net->write_timeout= mysql->options.write_timeout;
if (mysql->options.max_allowed_packet)
net->max_packet_size= mysql->options.max_allowed_packet;
/* Get version info */ /* Get version info */
mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */
if (mysql->options.connect_timeout && if (mysql->options.connect_timeout &&
...@@ -1725,9 +1691,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1725,9 +1691,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
DBUG_DUMP("packet",(char*) net->read_pos,10); DBUG_DUMP("packet",(char*) net->read_pos,10);
DBUG_PRINT("info",("mysql protocol version %d, server=%d", DBUG_PRINT("info",("mysql protocol version %d, server=%d",
PROTOCOL_VERSION, mysql->protocol_version)); PROTOCOL_VERSION, mysql->protocol_version));
if (mysql->protocol_version != PROTOCOL_VERSION if (mysql->protocol_version != PROTOCOL_VERSION)
&& mysql->protocol_version != PROTOCOL_VERSION-1)
{ {
strmov(net->sqlstate, unknown_sqlstate);
net->last_errno= CR_VERSION_ERROR; net->last_errno= CR_VERSION_ERROR;
sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version, sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version,
PROTOCOL_VERSION); PROTOCOL_VERSION);
...@@ -1747,7 +1713,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1747,7 +1713,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
mysql->server_status=uint2korr(end+3); mysql->server_status=uint2korr(end+3);
} }
#ifdef MYSQL_CLIENT
/* Set character set */ /* Set character set */
if ((charset_name=mysql->options.charset_name)) if ((charset_name=mysql->options.charset_name))
{ {
...@@ -1755,14 +1720,15 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1755,14 +1720,15 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (mysql->options.charset_dir) if (mysql->options.charset_dir)
charsets_dir=mysql->options.charset_dir; charsets_dir=mysql->options.charset_dir;
mysql->charset=get_charset_by_csname(mysql->options.charset_name, mysql->charset=get_charset_by_csname(mysql->options.charset_name,
MY_CS_PRIMARY, MY_CS_PRIMARY,
MYF(MY_WME)); MYF(MY_WME));
charsets_dir=save; charsets_dir=save;
} }
else if (mysql->server_language) else if (mysql->server_language)
{ {
charset_name=charset_name_buff; charset_name=charset_name_buff;
sprintf(charset_name,"%d",mysql->server_language); /* In case of errors */ /* Save name in case of errors */
int10_to_str(mysql->server_language, charset_name, 10);
if (!(mysql->charset = if (!(mysql->charset =
get_charset((uint8) mysql->server_language, MYF(0)))) get_charset((uint8) mysql->server_language, MYF(0))))
mysql->charset = default_charset_info; /* shouldn't be fatal */ mysql->charset = default_charset_info; /* shouldn't be fatal */
...@@ -1775,20 +1741,21 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1775,20 +1741,21 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
net->last_errno=CR_CANT_READ_CHARSET; net->last_errno=CR_CANT_READ_CHARSET;
strmov(net->sqlstate, unknown_sqlstate); strmov(net->sqlstate, unknown_sqlstate);
if (mysql->options.charset_dir) if (mysql->options.charset_dir)
sprintf(net->last_error,ER(net->last_errno), my_snprintf(net->last_error, sizeof(net->last_error)-1,
charset_name ? charset_name : "unknown", ER(net->last_errno),
mysql->options.charset_dir); charset_name ? charset_name : "unknown",
mysql->options.charset_dir);
else else
{ {
char cs_dir_name[FN_REFLEN]; char cs_dir_name[FN_REFLEN];
get_charsets_dir(cs_dir_name); get_charsets_dir(cs_dir_name);
sprintf(net->last_error,ER(net->last_errno), my_snprintf(net->last_error, sizeof(net->last_error)-1,
charset_name ? charset_name : "unknown", ER(net->last_errno),
cs_dir_name); charset_name ? charset_name : "unknown",
cs_dir_name);
} }
goto error; goto error;
} }
#endif /*MYSQL_CLIENT*/
/* Save connection information */ /* Save connection information */
if (!user) user=""; if (!user) user="";
...@@ -1834,7 +1801,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1834,7 +1801,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (db) if (db)
client_flag|=CLIENT_CONNECT_WITH_DB; client_flag|=CLIENT_CONNECT_WITH_DB;
#ifdef MYSQL_CLIENT
/* Remove options that server doesn't support */ /* Remove options that server doesn't support */
client_flag= ((client_flag & client_flag= ((client_flag &
~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41)) | ~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41)) |
...@@ -1842,11 +1808,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1842,11 +1808,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
#ifndef HAVE_COMPRESS #ifndef HAVE_COMPRESS
client_flag&= ~CLIENT_COMPRESS; client_flag&= ~CLIENT_COMPRESS;
#endif #endif
if (client_flag & CLIENT_PROTOCOL_41) if (client_flag & CLIENT_PROTOCOL_41)
{ {
/* 4.1 server and 4.1 client has a 32 byte option flag */ /* 4.1 server and 4.1 client has a 32 byte option flag */
int4store(buff,client_flag); int4store(buff,client_flag);
int4store(buff+4,max_allowed_packet); int4store(buff+4, net->max_packet_size);
buff[8]= mysql->charset->number; buff[8]= mysql->charset->number;
bzero(buff+9, 32-9); bzero(buff+9, 32-9);
end= buff+32; end= buff+32;
...@@ -1854,46 +1821,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1854,46 +1821,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
else else
{ {
int2store(buff,client_flag); int2store(buff,client_flag);
int3store(buff+2,max_allowed_packet); int3store(buff+2,net->max_packet_size);
end= buff+5; end= buff+5;
} }
mysql->client_flag=client_flag; mysql->client_flag=client_flag;
#endif /*MYSQL_CLIENT*/
#ifdef MYSQL_SERVER
#ifdef HAVE_COMPRESS
if ((mysql->server_capabilities & CLIENT_COMPRESS) &&
(mysql->options.compress || (client_flag & CLIENT_COMPRESS)))
client_flag|=CLIENT_COMPRESS; /* We will use compression */
else
#endif
client_flag&= ~CLIENT_COMPRESS;
#endif /*MYSQL_SERVER*/
#ifdef MYSQL_SERVER
#ifdef HAVE_OPENSSL
if ((mysql->server_capabilities & CLIENT_SSL) &&
(mysql->options.use_ssl || (client_flag & CLIENT_SSL)))
{
DBUG_PRINT("info", ("Changing IO layer to SSL"));
client_flag |= CLIENT_SSL;
}
else
{
if (client_flag & CLIENT_SSL)
{
DBUG_PRINT("info", ("Leaving IO layer intact because server doesn't support SSL"));
}
client_flag &= ~CLIENT_SSL;
}
#endif /* HAVE_OPENSSL */
max_allowed_packet=mysql->net.max_packet_size;
int2store(buff,client_flag);
int3store(buff+2,max_allowed_packet);
end= buff+5;
mysql->client_flag=client_flag;
#endif /*MYSQL_SERVER*/
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
/* /*
...@@ -1902,9 +1833,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1902,9 +1833,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
*/ */
if (client_flag & CLIENT_SSL) if (client_flag & CLIENT_SSL)
{ {
#ifdef MYSQL_CLIENT
struct st_mysql_options *options= &mysql->options; struct st_mysql_options *options= &mysql->options;
#endif
if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net)) if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net))
{ {
strmov(net->sqlstate, unknown_sqlstate); strmov(net->sqlstate, unknown_sqlstate);
...@@ -1913,7 +1842,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1913,7 +1842,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
goto error; goto error;
} }
/* Do the SSL layering. */ /* Do the SSL layering. */
#ifdef MYSQL_CLIENT
if (!(mysql->connector_fd= if (!(mysql->connector_fd=
(gptr) new_VioSSLConnectorFd(options->ssl_key, (gptr) new_VioSSLConnectorFd(options->ssl_key,
options->ssl_cert, options->ssl_cert,
...@@ -1926,7 +1854,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1926,7 +1854,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
strmov(net->last_error,ER(net->last_errno)); strmov(net->last_error,ER(net->last_errno));
goto error; goto error;
} }
#endif /*MYSQL_CLIENT*/
DBUG_PRINT("info", ("IO layer change in progress...")); DBUG_PRINT("info", ("IO layer change in progress..."));
if (sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd), if (sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd),
mysql->net.vio, (long) (mysql->options.connect_timeout))) mysql->net.vio, (long) (mysql->options.connect_timeout)))
...@@ -1947,18 +1874,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1947,18 +1874,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (user && user[0]) if (user && user[0])
strmake(end,user,32); /* Max user name */ strmake(end,user,32); /* Max user name */
else else
#ifdef MYSQL_SERVER
{
user = getenv("USER");
if (!user) user = "mysql";
strmov((char*) end, user );
}
#else
read_user_name((char*) end); read_user_name((char*) end);
#endif /*MYSQL_SERVER*/
/* We have to handle different version of handshake here */ /* We have to handle different version of handshake here */
#if defined(_CUSTOMCONFIG_) && defined(MYSQL_CLIENT) #ifdef _CUSTOMCONFIG_
#include "_cust_libmysql.h"; #include "_cust_libmysql.h"
#endif #endif
DBUG_PRINT("info",("user: %s",end)); DBUG_PRINT("info",("user: %s",end));
/* /*
...@@ -2012,9 +1932,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -2012,9 +1932,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (client_flag & CLIENT_COMPRESS) /* We will use compression */ if (client_flag & CLIENT_COMPRESS) /* We will use compression */
net->compress=1; net->compress=1;
#ifdef MYSQL_CLIENT
if (mysql->options.max_allowed_packet)
net->max_packet_size= mysql->options.max_allowed_packet;
if (db && mysql_select_db(mysql,db)) if (db && mysql_select_db(mysql,db))
goto error; goto error;
...@@ -2030,7 +1947,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -2030,7 +1947,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
for (; ptr<end; ptr++) for (; ptr<end; ptr++)
{ {
MYSQL_RES *res; MYSQL_RES *res;
if (mysql_query(mysql,*ptr)) if (mysql_real_query(mysql,*ptr, strlen(*ptr)))
goto error; goto error;
if (mysql->fields) if (mysql->fields)
{ {
...@@ -2039,13 +1956,13 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -2039,13 +1956,13 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
mysql_free_result(res); mysql_free_result(res);
} }
} }
mysql->reconnect=reconnect; mysql->reconnect=reconnect;
} }
#ifndef TO_BE_DELETED
if (mysql->options.rpl_probe && mysql_rpl_probe(mysql)) if (mysql->options.rpl_probe && mysql_rpl_probe(mysql))
goto error; goto error;
#endif /*MYSQL_CLIENT*/ #endif
DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); DBUG_PRINT("exit",("Mysql handler: %lx",mysql));
reset_sigpipe(mysql); reset_sigpipe(mysql);
...@@ -2057,37 +1974,35 @@ error: ...@@ -2057,37 +1974,35 @@ error:
net->last_errno, net->sqlstate, net->last_error)); net->last_errno, net->sqlstate, net->last_error));
{ {
/* Free alloced memory */ /* Free alloced memory */
my_bool free_me=mysql->free_me;
end_server(mysql); end_server(mysql);
mysql->free_me=0; mysql_close_free(mysql);
mysql_close(mysql); if (!(client_flag & CLIENT_REMEMBER_OPTIONS))
mysql->free_me=free_me; mysql_close_free_options(mysql);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/* needed when we move MYSQL structure to a different address */ /* needed when we move MYSQL structure to a different address */
#ifndef TO_BE_DELETED
static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql) static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql)
{ {
MYSQL *tmp, *tmp_prev;
if (mysql->master == old_mysql) if (mysql->master == old_mysql)
mysql->master = mysql; mysql->master= mysql;
if (mysql->last_used_con == old_mysql) if (mysql->last_used_con == old_mysql)
mysql->last_used_con = mysql; mysql->last_used_con= mysql;
if (mysql->last_used_slave == old_mysql) if (mysql->last_used_slave == old_mysql)
mysql->last_used_slave = mysql; mysql->last_used_slave= mysql;
#ifdef MYSQL_CLIENT /*should work in MYSQL_SERVER also, but doesn't */ for (tmp_prev = mysql, tmp = mysql->next_slave;
tmp != old_mysql;tmp = tmp->next_slave)
{ {
MYSQL *tmp, *tmp_prev; tmp_prev= tmp;
for (tmp_prev = mysql, tmp = mysql->next_slave;
tmp != old_mysql;tmp = tmp->next_slave)
{
tmp_prev = tmp;
}
tmp_prev->next_slave = mysql;
} }
#endif /*MYSQL_CLIENT*/ tmp_prev->next_slave= mysql;
} }
#endif
my_bool mysql_reconnect(MYSQL *mysql) my_bool mysql_reconnect(MYSQL *mysql)
...@@ -2111,11 +2026,11 @@ my_bool mysql_reconnect(MYSQL *mysql) ...@@ -2111,11 +2026,11 @@ my_bool mysql_reconnect(MYSQL *mysql)
tmp_mysql.rpl_pivot = mysql->rpl_pivot; tmp_mysql.rpl_pivot = mysql->rpl_pivot;
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
mysql->db, mysql->port, mysql->unix_socket, mysql->db, mysql->port, mysql->unix_socket,
mysql->client_flag)) mysql->client_flag | CLIENT_REMEMBER_OPTIONS))
{ {
mysql->net.last_errno= tmp_mysql.net.last_errno; mysql->net.last_errno= tmp_mysql.net.last_errno;
strmov(mysql->net.last_error, tmp_mysql.net.last_error); strmov(mysql->net.last_error, tmp_mysql.net.last_error);
strmov(mysql->net.sqlstate, unknown_sqlstate); strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
tmp_mysql.free_me=mysql->free_me; tmp_mysql.free_me=mysql->free_me;
...@@ -2128,6 +2043,7 @@ my_bool mysql_reconnect(MYSQL *mysql) ...@@ -2128,6 +2043,7 @@ my_bool mysql_reconnect(MYSQL *mysql)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/************************************************************************** /**************************************************************************
Set current database Set current database
**************************************************************************/ **************************************************************************/
...@@ -2146,42 +2062,62 @@ mysql_select_db(MYSQL *mysql, const char *db) ...@@ -2146,42 +2062,62 @@ mysql_select_db(MYSQL *mysql, const char *db)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/*
Free strings in the SSL structure and clear 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
*/
#ifdef HAVE_OPENSSL
static void
mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
{
my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR));
mysql->options.ssl_key = 0;
mysql->options.ssl_cert = 0;
mysql->options.ssl_ca = 0;
mysql->options.ssl_capath = 0;
mysql->options.ssl_cipher= 0;
mysql->options.use_ssl = FALSE;
mysql->connector_fd = 0;
}
#endif /* HAVE_OPENSSL */
/************************************************************************* /*************************************************************************
Send a QUIT to the server and close the connection Send a QUIT to the server and close the connection
If handle is alloced by mysql connect free it. If handle is alloced by mysql connect free it.
*************************************************************************/ *************************************************************************/
static void mysql_close_free_options(MYSQL *mysql)
{
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));
my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
if (mysql->options.init_commands)
{
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
char **ptr= (char**)init_commands->buffer;
char **end= ptr + init_commands->elements;
for (; ptr<end; ptr++)
my_free(*ptr,MYF(MY_WME));
delete_dynamic(init_commands);
my_free((char*)init_commands,MYF(MY_WME));
}
#ifdef HAVE_OPENSSL
mysql_ssl_free(mysql);
#endif /* HAVE_OPENSSL */
#ifdef HAVE_SMEM
if (mysql->options.shared_memory_base_name != def_shared_memory_base_name)
my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
#endif /* HAVE_SMEM */
bzero((char*) &mysql->options,sizeof(mysql->options));
}
static void mysql_close_free(MYSQL *mysql)
{
/* Clear pointers for better safety */
my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;
}
void STDCALL void STDCALL
mysql_close(MYSQL *mysql) mysql_close(MYSQL *mysql)
{ {
DBUG_ENTER("mysql_close"); DBUG_ENTER("mysql_close");
if (mysql) /* Some simple safety */ if (mysql) /* Some simple safety */
{ {
/* If connection is still up, send a QUIT message */
if (mysql->net.vio != 0) if (mysql->net.vio != 0)
{ {
free_old_query(mysql); free_old_query(mysql);
...@@ -2190,34 +2126,22 @@ mysql_close(MYSQL *mysql) ...@@ -2190,34 +2126,22 @@ mysql_close(MYSQL *mysql)
simple_command(mysql,COM_QUIT,NullS,0,1); simple_command(mysql,COM_QUIT,NullS,0,1);
end_server(mysql); /* Sets mysql->net.vio= 0 */ end_server(mysql); /* Sets mysql->net.vio= 0 */
} }
my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); mysql_close_free_options(mysql);
my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); mysql_close_free(mysql);
my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); #ifdef MYSQL_CLIENT
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); if (mysql->stmts)
my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
if (mysql->options.init_commands)
{ {
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; /* Free any open prepared statements */
char **ptr= (char**)init_commands->buffer; LIST *element, *next_element;
char **end= ptr + init_commands->elements; for (element= mysql->stmts; element; element= next_element)
for (; ptr<end; ptr++) {
my_free(*ptr,MYF(MY_WME)); next_element= element->next;
delete_dynamic(init_commands); stmt_close((MYSQL_STMT *)element->data, 0);
my_free((char*)init_commands,MYF(MY_WME)); }
mysql->stmts= 0;
} }
#ifdef HAVE_SMEM #endif /*MYSQL_CLIENT*/
if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) #ifndef TO_BE_DELETED
my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
#endif /* HAVE_SMEM */
/* free/close slave list */ /* free/close slave list */
if (mysql->rpl_pivot) if (mysql->rpl_pivot)
{ {
...@@ -2231,34 +2155,16 @@ mysql_close(MYSQL *mysql) ...@@ -2231,34 +2155,16 @@ mysql_close(MYSQL *mysql)
} }
mysql->rpl_pivot=0; mysql->rpl_pivot=0;
} }
#ifdef MYSQL_CLIENT #endif
if (mysql->stmts)
{
/* Free any open prepared statements */
LIST *element, *next_element;
for (element= mysql->stmts; element; element= next_element)
{
next_element= element->next;
stmt_close((MYSQL_STMT *)element->data, 0);
}
}
if (mysql != mysql->master) if (mysql != mysql->master)
mysql_close(mysql->master); mysql_close(mysql->master);
#endif /*MYSQL_CLIENT*/
#ifdef HAVE_OPENSSL
mysql_ssl_free(mysql);
#endif /* HAVE_OPENSSL */
/* Clear pointers for better safety */
mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;
bzero((char*) &mysql->options,sizeof(mysql->options));
if (mysql->free_me) if (mysql->free_me)
my_free((gptr) mysql,MYF(0)); my_free((gptr) mysql,MYF(0));
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
my_bool STDCALL mysql_read_query_result(MYSQL *mysql) my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
{ {
uchar *pos; uchar *pos;
...@@ -2267,18 +2173,16 @@ my_bool STDCALL mysql_read_query_result(MYSQL *mysql) ...@@ -2267,18 +2173,16 @@ my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
ulong length; ulong length;
DBUG_ENTER("mysql_read_query_result"); DBUG_ENTER("mysql_read_query_result");
#ifdef MYSQL_CLIENT
/* /*
Read from the connection which we actually used, which Read from the connection which we actually used, which
could differ from the original connection if we have slaves could differ from the original connection if we have slaves
*/ */
mysql = mysql->last_used_con; mysql = mysql->last_used_con;
#endif
if ((length = net_safe_read(mysql)) == packet_error) if ((length = net_safe_read(mysql)) == packet_error)
DBUG_RETURN(1); DBUG_RETURN(1);
free_old_query(mysql); /* Free old result */ free_old_query(mysql); /* Free old result */
#ifdef MYSQL_CLIENT /*or else gcc will warn of unused labels*/ #ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
get_info: get_info:
#endif #endif
pos=(uchar*) mysql->net.read_pos; pos=(uchar*) mysql->net.read_pos;
...@@ -2341,7 +2245,7 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length) ...@@ -2341,7 +2245,7 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length)
DBUG_ENTER("mysql_send_query"); DBUG_ENTER("mysql_send_query");
DBUG_PRINT("enter",("rpl_parse: %d rpl_pivot: %d", DBUG_PRINT("enter",("rpl_parse: %d rpl_pivot: %d",
mysql->options.rpl_parse, mysql->rpl_pivot)); mysql->options.rpl_parse, mysql->rpl_pivot));
#ifdef MYSQL_CLIENT #ifndef TO_BE_DELETED
if (mysql->options.rpl_parse && mysql->rpl_pivot) if (mysql->options.rpl_parse && mysql->rpl_pivot)
{ {
switch (mysql_rpl_query_type(query, length)) { switch (mysql_rpl_query_type(query, length)) {
...@@ -2353,9 +2257,8 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length) ...@@ -2353,9 +2257,8 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length)
break; /* fall through */ break; /* fall through */
} }
} }
mysql->last_used_con = mysql; mysql->last_used_con = mysql;
#endif /*MYSQL_CLIENT*/ #endif
DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1)); DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1));
} }
...@@ -2373,6 +2276,7 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length) ...@@ -2373,6 +2276,7 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length)
DBUG_RETURN((int) mysql_read_query_result(mysql)); DBUG_RETURN((int) mysql_read_query_result(mysql));
} }
/************************************************************************** /**************************************************************************
Alloc result struct for buffered results. All rows are read to buffer. Alloc result struct for buffered results. All rows are read to buffer.
mysql_data_seek may be used. mysql_data_seek may be used.
...@@ -2383,11 +2287,8 @@ mysql_store_result(MYSQL *mysql) ...@@ -2383,11 +2287,8 @@ mysql_store_result(MYSQL *mysql)
{ {
MYSQL_RES *result; MYSQL_RES *result;
DBUG_ENTER("mysql_store_result"); DBUG_ENTER("mysql_store_result");
#ifdef MYSQL_CLIENT
/* read from the actually used connection */ /* read from the actually used connection */
mysql = mysql->last_used_con; mysql = mysql->last_used_con;
#endif
if (!mysql->fields) if (!mysql->fields)
DBUG_RETURN(0); DBUG_RETURN(0);
if (mysql->status != MYSQL_STATUS_GET_RESULT) if (mysql->status != MYSQL_STATUS_GET_RESULT)
...@@ -2426,8 +2327,59 @@ mysql_store_result(MYSQL *mysql) ...@@ -2426,8 +2327,59 @@ mysql_store_result(MYSQL *mysql)
DBUG_RETURN(result); /* Data fetched */ DBUG_RETURN(result); /* Data fetched */
} }
/**************************************************************************
Alloc struct for use with unbuffered reads. Data is fetched by domand
when calling to mysql_fetch_row.
mysql_data_seek is a noop.
No other queries may be specified with the same MYSQL handle.
There shouldn't be much processing per row because mysql server shouldn't
have to wait for the client (and will not wait more than 30 sec/packet).
**************************************************************************/
MYSQL_RES * STDCALL
mysql_use_result(MYSQL *mysql)
{
MYSQL_RES *result;
DBUG_ENTER("mysql_use_result");
mysql = mysql->last_used_con;
if (!mysql->fields)
DBUG_RETURN(0);
if (mysql->status != MYSQL_STATUS_GET_RESULT)
{
strmov(mysql->net.sqlstate, unknown_sqlstate);
strmov(mysql->net.last_error,
ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
DBUG_RETURN(0);
}
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
sizeof(ulong)*mysql->field_count,
MYF(MY_WME | MY_ZEROFILL))))
DBUG_RETURN(0);
result->lengths=(ulong*) (result+1);
if (!(result->row=(MYSQL_ROW)
my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
{ /* Ptrs: to one row */
my_free((gptr) result,MYF(0));
DBUG_RETURN(0);
}
result->fields= mysql->fields;
result->field_alloc= mysql->field_alloc;
result->field_count= mysql->field_count;
result->current_field=0;
result->handle= mysql;
result->current_row= 0;
mysql->fields=0; /* fields is now in result */
mysql->status=MYSQL_STATUS_USE_RESULT;
DBUG_RETURN(result); /* Data is read to be fetched */
}
/************************************************************************** /**************************************************************************
Return next row of the query results Return next row of the query results
**************************************************************************/ **************************************************************************/
MYSQL_ROW STDCALL MYSQL_ROW STDCALL
...@@ -2467,20 +2419,6 @@ mysql_fetch_row(MYSQL_RES *res) ...@@ -2467,20 +2419,6 @@ mysql_fetch_row(MYSQL_RES *res)
} }
} }
/**************************************************************************
Move to a specific row and column
**************************************************************************/
void STDCALL
mysql_data_seek(MYSQL_RES *result, my_ulonglong row)
{
MYSQL_ROWS *tmp=0;
DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row));
if (result->data)
for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
result->current_row=0;
result->data_cursor = tmp;
}
int STDCALL int STDCALL
mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
...@@ -2491,11 +2429,17 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) ...@@ -2491,11 +2429,17 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
case MYSQL_OPT_CONNECT_TIMEOUT: case MYSQL_OPT_CONNECT_TIMEOUT:
mysql->options.connect_timeout= *(uint*) arg; mysql->options.connect_timeout= *(uint*) arg;
break; break;
case MYSQL_OPT_READ_TIMEOUT:
mysql->options.read_timeout= *(uint*) arg;
break;
case MYSQL_OPT_WRITE_TIMEOUT:
mysql->options.write_timeout= *(uint*) arg;
break;
case MYSQL_OPT_COMPRESS: case MYSQL_OPT_COMPRESS:
mysql->options.compress= 1; /* Remember for connect */ mysql->options.compress= 1; /* Remember for connect */
mysql->options.client_flag|= CLIENT_COMPRESS; mysql->options.client_flag|= CLIENT_COMPRESS;
break; break;
case MYSQL_OPT_NAMED_PIPE: case MYSQL_OPT_NAMED_PIPE: /* This option is depricated */
mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */ mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */
break; break;
case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
...@@ -2504,11 +2448,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) ...@@ -2504,11 +2448,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
else else
mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; mysql->options.client_flag&= ~CLIENT_LOCAL_FILES;
break; break;
#ifdef MYSQL_CLIENT
case MYSQL_INIT_COMMAND: case MYSQL_INIT_COMMAND:
add_init_command(&mysql->options,arg); add_init_command(&mysql->options,arg);
break; break;
#endif
case MYSQL_READ_DEFAULT_FILE: case MYSQL_READ_DEFAULT_FILE:
my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
mysql->options.my_cnf_file=my_strdup(arg,MYF(MY_WME)); mysql->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
...@@ -2567,6 +2509,3 @@ const char * STDCALL mysql_error(MYSQL *mysql) ...@@ -2567,6 +2509,3 @@ const char * STDCALL mysql_error(MYSQL *mysql)
{ {
return mysql->net.last_error; return mysql->net.last_error;
} }
#endif /* defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT) */
...@@ -84,7 +84,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ ...@@ -84,7 +84,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \ sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \
sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \ sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \
slave.cc sql_repl.cc sql_union.cc sql_derived.cc \ slave.cc sql_repl.cc sql_union.cc sql_derived.cc \
client.c mini_client_errors.c pack.c\ client.c sql_client.cc mini_client_errors.c pack.c\
stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\ stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\
gstream.cc spatial.cc sql_help.cc protocol_cursor.cc gstream.cc spatial.cc sql_help.cc protocol_cursor.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc gen_lex_hash_SOURCES = gen_lex_hash.cc
......
...@@ -17,18 +17,15 @@ ...@@ -17,18 +17,15 @@
#include <thr_alarm.h> #include <thr_alarm.h>
extern char *mysql_unix_port; #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \
CLIENT_SECURE_CONNECTION | CLIENT_TRANSACTIONS | \
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \ CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
| CLIENT_LOCAL_FILES | CLIENT_SECURE_CONNECTION)
#define init_sigpipe_variables #define init_sigpipe_variables
#define set_sigpipe(mysql) #define set_sigpipe(mysql)
#define reset_sigpipe(mysql) #define reset_sigpipe(mysql)
#define read_user_name(A) {}
extern ulong slave_net_timeout; #define mysql_rpl_query_type(A,B) MYSQL_RPL_ADMIN
#define mysql_rpl_probe(mysql) 0
#ifdef HAVE_SMEM
#undef HAVE_SMEM #undef HAVE_SMEM
#endif #undef _CUSTOMCONFIG_
...@@ -209,9 +209,9 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, ...@@ -209,9 +209,9 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
sprintf(buff, "%s, Version: %s, embedded library\n", my_progname, server_version); sprintf(buff, "%s, Version: %s, embedded library\n", my_progname, server_version);
#elif __NT__ #elif __NT__
sprintf(buff, "%s, Version: %s, started with:\nTCP Port: %d, Named Pipe: %s\n", my_progname, server_version, mysql_port, mysql_unix_port); sprintf(buff, "%s, Version: %s, started with:\nTCP Port: %d, Named Pipe: %s\n", my_progname, server_version, mysqld_port, mysqld_unix_port);
#else #else
sprintf(buff, "%s, Version: %s, started with:\nTcp port: %d Unix socket: %s\n", my_progname,server_version,mysql_port,mysql_unix_port); sprintf(buff, "%s, Version: %s, started with:\nTcp port: %d Unix socket: %s\n", my_progname,server_version,mysqld_port,mysqld_unix_port);
#endif #endif
end=strmov(strend(buff),"Time Id Command Argument\n"); end=strmov(strend(buff),"Time Id Command Argument\n");
if (my_b_write(&log_file, (byte*) buff,(uint) (end-buff)) || if (my_b_write(&log_file, (byte*) buff,(uint) (end-buff)) ||
......
...@@ -732,7 +732,7 @@ extern ulong specialflag, current_pid; ...@@ -732,7 +732,7 @@ extern ulong specialflag, current_pid;
extern ulong expire_logs_days; extern ulong expire_logs_days;
extern my_bool relay_log_purge; extern my_bool relay_log_purge;
extern uint test_flags,select_errors,ha_open_options; extern uint test_flags,select_errors,ha_open_options;
extern uint protocol_version,dropping_tables; extern uint protocol_version, mysqld_port, dropping_tables;
extern uint delay_key_write_options; extern uint delay_key_write_options;
extern bool opt_endinfo, using_udf_functions, locked_in_memory; extern bool opt_endinfo, using_udf_functions, locked_in_memory;
extern bool opt_using_transactions, mysql_embedded; extern bool opt_using_transactions, mysql_embedded;
...@@ -747,7 +747,7 @@ extern my_bool opt_slave_compressed_protocol, use_temp_pool; ...@@ -747,7 +747,7 @@ extern my_bool opt_slave_compressed_protocol, use_temp_pool;
extern my_bool opt_readonly; extern my_bool opt_readonly;
extern my_bool opt_enable_named_pipe; extern my_bool opt_enable_named_pipe;
extern my_bool opt_old_passwords, use_old_passwords; extern my_bool opt_old_passwords, use_old_passwords;
extern char *shared_memory_base_name; extern char *shared_memory_base_name, *mysqld_unix_port;
extern bool opt_enable_shared_memory; extern bool opt_enable_shared_memory;
extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log; extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <nisam.h> #include <nisam.h>
#include <thr_alarm.h> #include <thr_alarm.h>
#include <ft_global.h> #include <ft_global.h>
#include <errmsg.h>
#define mysqld_charset &my_charset_latin1 #define mysqld_charset &my_charset_latin1
...@@ -254,7 +255,7 @@ my_bool opt_console= 0, opt_bdb, opt_innodb, opt_isam; ...@@ -254,7 +255,7 @@ my_bool opt_console= 0, opt_bdb, opt_innodb, opt_isam;
my_bool opt_readonly, use_temp_pool, relay_log_purge; my_bool opt_readonly, use_temp_pool, relay_log_purge;
volatile bool mqh_used = 0; volatile bool mqh_used = 0;
uint mysql_port, test_flags, select_errors, dropping_tables, ha_open_options; uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
uint delay_key_write_options, protocol_version; uint delay_key_write_options, protocol_version;
uint volatile thread_count, thread_running, kill_cached_threads, wake_thread; uint volatile thread_count, thread_running, kill_cached_threads, wake_thread;
...@@ -303,7 +304,7 @@ char mysql_real_data_home[FN_REFLEN], ...@@ -303,7 +304,7 @@ char mysql_real_data_home[FN_REFLEN],
char *language_ptr, *default_collation_name, *default_character_set_name; char *language_ptr, *default_collation_name, *default_character_set_name;
char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home; char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home;
char server_version[SERVER_VERSION_LENGTH]=MYSQL_SERVER_VERSION; char server_version[SERVER_VERSION_LENGTH]=MYSQL_SERVER_VERSION;
char *mysql_unix_port, *opt_mysql_tmpdir; char *mysqld_unix_port, *opt_mysql_tmpdir;
char *my_bind_addr_str; char *my_bind_addr_str;
const char **errmesg; /* Error messages */ const char **errmesg; /* Error messages */
const char *myisam_recover_options_str="OFF"; const char *myisam_recover_options_str="OFF";
...@@ -561,7 +562,7 @@ static void close_connections(void) ...@@ -561,7 +562,7 @@ static void close_connections(void)
{ {
(void) shutdown(unix_sock,2); (void) shutdown(unix_sock,2);
(void) closesocket(unix_sock); (void) closesocket(unix_sock);
(void) unlink(mysql_unix_port); (void) unlink(mysqld_unix_port);
unix_sock= INVALID_SOCKET; unix_sock= INVALID_SOCKET;
} }
#endif #endif
...@@ -670,7 +671,7 @@ static void close_server_sock() ...@@ -670,7 +671,7 @@ static void close_server_sock()
DBUG_PRINT("info",("calling closesocket on unix/IP socket")); DBUG_PRINT("info",("calling closesocket on unix/IP socket"));
VOID(closesocket(tmp_sock)); VOID(closesocket(tmp_sock));
#endif #endif
VOID(unlink(mysql_unix_port)); VOID(unlink(mysqld_unix_port));
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
#endif #endif
...@@ -961,24 +962,24 @@ static void clean_up_mutexes() ...@@ -961,24 +962,24 @@ static void clean_up_mutexes()
static void set_ports() static void set_ports()
{ {
char *env; char *env;
if (!mysql_port && !opt_disable_networking) if (!mysqld_port && !opt_disable_networking)
{ // Get port if not from commandline { // Get port if not from commandline
struct servent *serv_ptr; struct servent *serv_ptr;
mysql_port = MYSQL_PORT; mysqld_port= MYSQL_PORT;
if ((serv_ptr = getservbyname("mysql", "tcp"))) if ((serv_ptr= getservbyname("mysql", "tcp")))
mysql_port = ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */ mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
if ((env = getenv("MYSQL_TCP_PORT"))) if ((env = getenv("MYSQL_TCP_PORT")))
mysql_port = (uint) atoi(env); /* purecov: inspected */ mysqld_port= (uint) atoi(env); /* purecov: inspected */
} }
if (!mysql_unix_port) if (!mysqld_unix_port)
{ {
#ifdef __WIN__ #ifdef __WIN__
mysql_unix_port = (char*) MYSQL_NAMEDPIPE; mysqld_unix_port= (char*) MYSQL_NAMEDPIPE;
#else #else
mysql_unix_port = (char*) MYSQL_UNIX_ADDR; mysqld_unix_port= (char*) MYSQL_UNIX_ADDR;
#endif #endif
if ((env = getenv("MYSQL_UNIX_PORT"))) if ((env = getenv("MYSQL_UNIX_PORT")))
mysql_unix_port = env; /* purecov: inspected */ mysqld_unix_port= env; /* purecov: inspected */
} }
} }
...@@ -1088,9 +1089,9 @@ static void server_init(void) ...@@ -1088,9 +1089,9 @@ static void server_init(void)
set_ports(); set_ports();
if (mysql_port != 0 && !opt_disable_networking && !opt_bootstrap) if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
{ {
DBUG_PRINT("general",("IP Socket is %d",mysql_port)); DBUG_PRINT("general",("IP Socket is %d",mysqld_port));
ip_sock = socket(AF_INET, SOCK_STREAM, 0); ip_sock = socket(AF_INET, SOCK_STREAM, 0);
if (ip_sock == INVALID_SOCKET) if (ip_sock == INVALID_SOCKET)
{ {
...@@ -1101,14 +1102,14 @@ static void server_init(void) ...@@ -1101,14 +1102,14 @@ static void server_init(void)
bzero((char*) &IPaddr, sizeof(IPaddr)); bzero((char*) &IPaddr, sizeof(IPaddr));
IPaddr.sin_family = AF_INET; IPaddr.sin_family = AF_INET;
IPaddr.sin_addr.s_addr = my_bind_addr; IPaddr.sin_addr.s_addr = my_bind_addr;
IPaddr.sin_port = (unsigned short) htons((unsigned short) mysql_port); IPaddr.sin_port = (unsigned short) htons((unsigned short) mysqld_port);
(void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg)); (void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
if (bind(ip_sock, my_reinterpret_cast(struct sockaddr *) (&IPaddr), if (bind(ip_sock, my_reinterpret_cast(struct sockaddr *) (&IPaddr),
sizeof(IPaddr)) < 0) sizeof(IPaddr)) < 0)
{ {
DBUG_PRINT("error",("Got error: %d from bind",socket_errno)); DBUG_PRINT("error",("Got error: %d from bind",socket_errno));
sql_perror("Can't start server: Bind on TCP/IP port"); sql_perror("Can't start server: Bind on TCP/IP port");
sql_print_error("Do you already have another mysqld server running on port: %d ?",mysql_port); sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port);
unireg_abort(1); unireg_abort(1);
} }
if (listen(ip_sock,(int) back_log) < 0) if (listen(ip_sock,(int) back_log) < 0)
...@@ -1123,10 +1124,10 @@ static void server_init(void) ...@@ -1123,10 +1124,10 @@ static void server_init(void)
#ifdef __NT__ #ifdef __NT__
/* create named pipe */ /* create named pipe */
if (Service.IsNT() && mysql_unix_port[0] && !opt_bootstrap && if (Service.IsNT() && mysqld_unix_port[0] && !opt_bootstrap &&
opt_enable_named_pipe) opt_enable_named_pipe)
{ {
sprintf(szPipeName, "\\\\.\\pipe\\%s", mysql_unix_port ); sprintf(szPipeName, "\\\\.\\pipe\\%s", mysqld_unix_port );
ZeroMemory( &saPipeSecurity, sizeof(saPipeSecurity) ); ZeroMemory( &saPipeSecurity, sizeof(saPipeSecurity) );
ZeroMemory( &sdPipeDescriptor, sizeof(sdPipeDescriptor) ); ZeroMemory( &sdPipeDescriptor, sizeof(sdPipeDescriptor) );
if ( !InitializeSecurityDescriptor(&sdPipeDescriptor, if ( !InitializeSecurityDescriptor(&sdPipeDescriptor,
...@@ -1172,9 +1173,9 @@ static void server_init(void) ...@@ -1172,9 +1173,9 @@ static void server_init(void)
/* /*
** Create the UNIX socket ** Create the UNIX socket
*/ */
if (mysql_unix_port[0] && !opt_bootstrap) if (mysqld_unix_port[0] && !opt_bootstrap)
{ {
DBUG_PRINT("general",("UNIX Socket is %s",mysql_unix_port)); DBUG_PRINT("general",("UNIX Socket is %s",mysqld_unix_port));
if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0) if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{ {
...@@ -1183,8 +1184,8 @@ static void server_init(void) ...@@ -1183,8 +1184,8 @@ static void server_init(void)
} }
bzero((char*) &UNIXaddr, sizeof(UNIXaddr)); bzero((char*) &UNIXaddr, sizeof(UNIXaddr));
UNIXaddr.sun_family = AF_UNIX; UNIXaddr.sun_family = AF_UNIX;
strmov(UNIXaddr.sun_path, mysql_unix_port); strmov(UNIXaddr.sun_path, mysqld_unix_port);
(void) unlink(mysql_unix_port); (void) unlink(mysqld_unix_port);
(void) setsockopt(unix_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg, (void) setsockopt(unix_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,
sizeof(arg)); sizeof(arg));
umask(0); umask(0);
...@@ -1192,12 +1193,12 @@ static void server_init(void) ...@@ -1192,12 +1193,12 @@ static void server_init(void)
sizeof(UNIXaddr)) < 0) sizeof(UNIXaddr)) < 0)
{ {
sql_perror("Can't start server : Bind on unix socket"); /* purecov: tested */ sql_perror("Can't start server : Bind on unix socket"); /* purecov: tested */
sql_print_error("Do you already have another mysqld server running on socket: %s ?",mysql_unix_port); sql_print_error("Do you already have another mysqld server running on socket: %s ?",mysqld_unix_port);
unireg_abort(1); /* purecov: tested */ unireg_abort(1); /* purecov: tested */
} }
umask(((~my_umask) & 0666)); umask(((~my_umask) & 0666));
#if defined(S_IFSOCK) && defined(SECURE_SOCKETS) #if defined(S_IFSOCK) && defined(SECURE_SOCKETS)
(void) chmod(mysql_unix_port,S_IFSOCK); /* Fix solaris 2.6 bug */ (void) chmod(mysqld_unix_port,S_IFSOCK); /* Fix solaris 2.6 bug */
#endif #endif
if (listen(unix_sock,(int) back_log) < 0) if (listen(unix_sock,(int) back_log) < 0)
sql_print_error("Warning: listen() on Unix socket failed with error %d", sql_print_error("Warning: listen() on Unix socket failed with error %d",
...@@ -2024,6 +2025,7 @@ static int init_common_variables(const char *conf_file_name, int argc, ...@@ -2024,6 +2025,7 @@ static int init_common_variables(const char *conf_file_name, int argc,
#endif #endif
unireg_init(opt_specialflag); /* Set up extern variabels */ unireg_init(opt_specialflag); /* Set up extern variabels */
init_errmessage(); /* Read error messages from file */ init_errmessage(); /* Read error messages from file */
init_client_errs();
lex_init(); lex_init();
item_init(); item_init();
set_var_init(); set_var_init();
...@@ -2426,7 +2428,7 @@ The server will not act as a slave."); ...@@ -2426,7 +2428,7 @@ The server will not act as a slave.");
(void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
#endif #endif
if (unix_sock != INVALID_SOCKET) if (unix_sock != INVALID_SOCKET)
unlink(mysql_unix_port); unlink(mysqld_unix_port);
exit(1); exit(1);
} }
if (!opt_noacl) if (!opt_noacl)
...@@ -2458,8 +2460,8 @@ The server will not act as a slave."); ...@@ -2458,8 +2460,8 @@ The server will not act as a slave.");
create_maintenance_thread(); create_maintenance_thread();
printf(ER(ER_READY),my_progname,server_version, printf(ER(ER_READY),my_progname,server_version,
((unix_sock == INVALID_SOCKET) ? (char*) "" : mysql_unix_port), ((unix_sock == INVALID_SOCKET) ? (char*) "" : mysqld_unix_port),
mysql_port); mysqld_port);
fflush(stdout); fflush(stdout);
#if defined(__NT__) || defined(HAVE_SMEM) #if defined(__NT__) || defined(HAVE_SMEM)
...@@ -3775,8 +3777,8 @@ Does nothing yet.", ...@@ -3775,8 +3777,8 @@ Does nothing yet.",
{"log-error", OPT_ERROR_LOG_FILE, "Log error file", {"log-error", OPT_ERROR_LOG_FILE, "Log error file",
(gptr*) &log_error_file_ptr, (gptr*) &log_error_file_ptr, 0, GET_STR, (gptr*) &log_error_file_ptr, (gptr*) &log_error_file_ptr, 0, GET_STR,
OPT_ARG, 0, 0, 0, 0, 0, 0}, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection.", (gptr*) &mysql_port, {"port", 'P', "Port number to use for connection.", (gptr*) &mysqld_port,
(gptr*) &mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, (gptr*) &mysqld_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"reckless-slave", OPT_RECKLESS_SLAVE, "For debugging", 0, 0, 0, GET_NO_ARG, {"reckless-slave", OPT_RECKLESS_SLAVE, "For debugging", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"replicate-do-db", OPT_REPLICATE_DO_DB, {"replicate-do-db", OPT_REPLICATE_DO_DB,
...@@ -3914,7 +3916,7 @@ replicating a LOAD DATA INFILE command", ...@@ -3914,7 +3916,7 @@ replicating a LOAD DATA INFILE command",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"socket", OPT_SOCKET, "Socket file to use for connection", {"socket", OPT_SOCKET, "Socket file to use for connection",
(gptr*) &mysql_unix_port, (gptr*) &mysql_unix_port, 0, GET_STR, (gptr*) &mysqld_unix_port, (gptr*) &mysqld_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"sql-bin-update-same", OPT_SQL_BIN_UPDATE_SAME, {"sql-bin-update-same", OPT_SQL_BIN_UPDATE_SAME,
"If set, setting SQL_LOG_BIN to a value will automatically set SQL_LOG_UPDATE to the same value and vice versa.", "If set, setting SQL_LOG_BIN to a value will automatically set SQL_LOG_UPDATE to the same value and vice versa.",
...@@ -4630,7 +4632,7 @@ static void mysql_init_variables(void) ...@@ -4630,7 +4632,7 @@ static void mysql_init_variables(void)
max_sort_char= 0; max_sort_char= 0;
mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0; mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
errmesg= 0; errmesg= 0;
mysql_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS; mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS;
bzero((gptr) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list)); bzero((gptr) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list));
bzero((gptr) &com_stat, sizeof(com_stat)); bzero((gptr) &com_stat, sizeof(com_stat));
...@@ -5037,7 +5039,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -5037,7 +5039,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break; break;
case (int) OPT_SKIP_NETWORKING: case (int) OPT_SKIP_NETWORKING:
opt_disable_networking=1; opt_disable_networking=1;
mysql_port=0; mysqld_port=0;
break; break;
case (int) OPT_SKIP_SHOW_DB: case (int) OPT_SKIP_SHOW_DB:
opt_skip_show_db=1; opt_skip_show_db=1;
......
...@@ -103,8 +103,7 @@ void send_error(THD *thd, uint sql_errno, const char *err) ...@@ -103,8 +103,7 @@ void send_error(THD *thd, uint sql_errno, const char *err)
{ {
/* The first # is to make the protocol backward compatible */ /* The first # is to make the protocol backward compatible */
buff[2]= '#'; buff[2]= '#';
strmov(buff+3, mysql_errno_to_sqlstate(sql_errno)); pos= strmov(buff+3, mysql_errno_to_sqlstate(sql_errno));
pos= buff + 2 + SQLSTATE_LENGTH +1;
} }
length= (uint) (strmake(pos, err, MYSQL_ERRMSG_SIZE-1) - buff); length= (uint) (strmake(pos, err, MYSQL_ERRMSG_SIZE-1) - buff);
err=buff; err=buff;
...@@ -236,28 +235,6 @@ net_printf(THD *thd, uint errcode, ...) ...@@ -236,28 +235,6 @@ net_printf(THD *thd, uint errcode, ...)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/*
Function called by my_net_init() to set some check variables
*/
#ifndef EMBEDDED_LIBRARY
extern "C" {
void my_net_local_init(NET *net)
{
net->max_packet= (uint) global_system_variables.net_buffer_length;
net->read_timeout= (uint) global_system_variables.net_read_timeout;
net->write_timeout=(uint) global_system_variables.net_write_timeout;
net->retry_count= (uint) global_system_variables.net_retry_count;
net->max_packet_size= max(global_system_variables.net_buffer_length,
global_system_variables.max_allowed_packet);
}
}
#else /* EMBEDDED_LIBRARY */
void my_net_local_init(NET *net __attribute__(unused))
{
}
#endif /* EMBEDDED_LIBRARY */
/* /*
Return ok to the client. Return ok to the client.
......
...@@ -450,11 +450,11 @@ int show_new_master(THD* thd) ...@@ -450,11 +450,11 @@ int show_new_master(THD* thd)
/* /*
Asks the master for the list of its other connected slaves. Asks the master for the list of its other connected slaves.
This is for failsafe replication : This is for failsafe replication:
in order for failsafe replication to work, the servers involved in replication in order for failsafe replication to work, the servers involved in
must know of each other. We accomplish this by having each slave report to the replication must know of each other. We accomplish this by having each
master how to reach it, and on connection, each slave receives information slave report to the master how to reach it, and on connection, each
about where the other slaves are. slave receives information about where the other slaves are.
SYNOPSIS SYNOPSIS
update_slave_list() update_slave_list()
...@@ -466,8 +466,8 @@ int show_new_master(THD* thd) ...@@ -466,8 +466,8 @@ int show_new_master(THD* thd)
hostname/port of the master, the username used by the slave to connect to hostname/port of the master, the username used by the slave to connect to
the master. the master.
If the user used by the slave to connect to the master does not have the If the user used by the slave to connect to the master does not have the
REPLICATION SLAVE privilege, it will pop in this function because SHOW SLAVE REPLICATION SLAVE privilege, it will pop in this function because
HOSTS will fail on the master. SHOW SLAVE HOSTS will fail on the master.
RETURN VALUES RETURN VALUES
1 error 1 error
...@@ -483,7 +483,6 @@ int update_slave_list(MYSQL* mysql, MASTER_INFO* mi) ...@@ -483,7 +483,6 @@ int update_slave_list(MYSQL* mysql, MASTER_INFO* mi)
int port_ind; int port_ind;
DBUG_ENTER("update_slave_list"); DBUG_ENTER("update_slave_list");
if (mysql_real_query(mysql,"SHOW SLAVE HOSTS",16) || if (mysql_real_query(mysql,"SHOW SLAVE HOSTS",16) ||
!(res = mysql_store_result(mysql))) !(res = mysql_store_result(mysql)))
{ {
...@@ -668,8 +667,10 @@ int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi) ...@@ -668,8 +667,10 @@ int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi)
strmov(mysql->net.last_error, "Master is not configured"); strmov(mysql->net.last_error, "Master is not configured");
DBUG_RETURN(1); DBUG_RETURN(1);
} }
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&slave_net_timeout); mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (char *)default_charset_info); mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset_info->csname);
mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
if (!mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0, if (!mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
mi->port, 0, 0)) mi->port, 0, 0))
DBUG_RETURN(1); DBUG_RETURN(1);
......
...@@ -596,7 +596,7 @@ struct show_var_st init_vars[]= { ...@@ -596,7 +596,7 @@ struct show_var_st init_vars[]= {
{"open_files_limit", (char*) &open_files_limit, SHOW_LONG}, {"open_files_limit", (char*) &open_files_limit, SHOW_LONG},
{"pid_file", (char*) pidfile_name, SHOW_CHAR}, {"pid_file", (char*) pidfile_name, SHOW_CHAR},
{"log_error", (char*) log_error_file, SHOW_CHAR}, {"log_error", (char*) log_error_file, SHOW_CHAR},
{"port", (char*) &mysql_port, SHOW_INT}, {"port", (char*) &mysqld_port, SHOW_INT},
{"protocol_version", (char*) &protocol_version, SHOW_INT}, {"protocol_version", (char*) &protocol_version, SHOW_INT},
{sys_pseudo_thread_id.name, (char*) &sys_pseudo_thread_id, SHOW_SYS}, {sys_pseudo_thread_id.name, (char*) &sys_pseudo_thread_id, SHOW_SYS},
{sys_read_buff_size.name, (char*) &sys_read_buff_size, SHOW_SYS}, {sys_read_buff_size.name, (char*) &sys_read_buff_size, SHOW_SYS},
...@@ -627,7 +627,7 @@ struct show_var_st init_vars[]= { ...@@ -627,7 +627,7 @@ struct show_var_st init_vars[]= {
{"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL}, {"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL},
{sys_slow_launch_time.name, (char*) &sys_slow_launch_time, SHOW_SYS}, {sys_slow_launch_time.name, (char*) &sys_slow_launch_time, SHOW_SYS},
#ifdef HAVE_SYS_UN_H #ifdef HAVE_SYS_UN_H
{"socket", (char*) &mysql_unix_port, SHOW_CHAR_PTR}, {"socket", (char*) &mysqld_unix_port, SHOW_CHAR_PTR},
#endif #endif
{sys_sort_buffer.name, (char*) &sys_sort_buffer, SHOW_SYS}, {sys_sort_buffer.name, (char*) &sys_sort_buffer, SHOW_SYS},
{sys_sql_mode.name, (char*) &sys_sql_mode, SHOW_SYS}, {sys_sql_mode.name, (char*) &sys_sql_mode, SHOW_SYS},
......
...@@ -71,7 +71,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi, ...@@ -71,7 +71,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed, static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed,
void* thread_killed_arg); void* thread_killed_arg);
static int request_table_dump(MYSQL* mysql, const char* db, const char* table); static int request_table_dump(MYSQL* mysql, const char* db, const char* table);
static int create_table_from_dump(THD* thd, NET* net, const char* db, static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
const char* table_name); const char* table_name);
static int check_master_version(MYSQL* mysql, MASTER_INFO* mi); static int check_master_version(MYSQL* mysql, MASTER_INFO* mi);
char* rewrite_db(char* db); char* rewrite_db(char* db);
...@@ -1049,10 +1049,10 @@ static int check_master_version(MYSQL* mysql, MASTER_INFO* mi) ...@@ -1049,10 +1049,10 @@ static int check_master_version(MYSQL* mysql, MASTER_INFO* mi)
} }
static int create_table_from_dump(THD* thd, NET* net, const char* db, static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
const char* table_name) const char* table_name)
{ {
ulong packet_len = my_net_read(net); // read create table statement ulong packet_len;
char *query; char *query;
Vio* save_vio; Vio* save_vio;
HA_CHECK_OPT check_opt; HA_CHECK_OPT check_opt;
...@@ -1060,7 +1060,9 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db, ...@@ -1060,7 +1060,9 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
int error= 1; int error= 1;
handler *file; handler *file;
ulong save_options; ulong save_options;
NET *net= &mysql->net;
packet_len= my_net_read(net); // read create table statement
if (packet_len == packet_error) if (packet_len == packet_error)
{ {
send_error(thd, ER_MASTER_NET_READ); send_error(thd, ER_MASTER_NET_READ);
...@@ -1068,32 +1070,27 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db, ...@@ -1068,32 +1070,27 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
} }
if (net->read_pos[0] == 255) // error from master if (net->read_pos[0] == 255) // error from master
{ {
net->read_pos[packet_len] = 0; char *err_msg;
net_printf(thd, ER_MASTER, net->read_pos + 3); err_msg= (char*) net->read_pos + ((mysql->server_capabilities &
CLIENT_PROTOCOL_41) ?
3+SQLSTATE_LENGTH+1 : 3);
net_printf(thd, ER_MASTER, err_msg);
return 1; return 1;
} }
thd->command = COM_TABLE_DUMP; thd->command = COM_TABLE_DUMP;
thd->query_length= packet_len;
/* Note that we should not set thd->query until the area is initalized */ /* Note that we should not set thd->query until the area is initalized */
if (!(query = sql_alloc(packet_len + 1))) if (!(query = thd->strmake((char*) net->read_pos, packet_len)))
{ {
sql_print_error("create_table_from_dump: out of memory"); sql_print_error("create_table_from_dump: out of memory");
net_printf(thd, ER_GET_ERRNO, "Out of memory"); net_printf(thd, ER_GET_ERRNO, "Out of memory");
return 1; return 1;
} }
memcpy(query, net->read_pos, packet_len);
query[packet_len]= 0;
thd->query_length= packet_len;
/*
We make the following lock in an attempt to ensure that the compiler will
not rearrange the code so that thd->query is set too soon
*/
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query= query; thd->query= query;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
thd->current_tablenr = 0; thd->current_tablenr = 0;
thd->query_error = 0; thd->query_error = 0;
thd->net.no_send_ok = 1; thd->net.no_send_ok = 1;
/* we do not want to log create table statement */ /* we do not want to log create table statement */
save_options = thd->options; save_options = thd->options;
thd->options &= ~(ulong) (OPTION_BIN_LOG); thd->options &= ~(ulong) (OPTION_BIN_LOG);
...@@ -1185,8 +1182,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, ...@@ -1185,8 +1182,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name,
errmsg= "Failed on table dump request"; errmsg= "Failed on table dump request";
goto err; goto err;
} }
if (create_table_from_dump(thd, &mysql->net, db_name, if (create_table_from_dump(thd, mysql, db_name, table_name))
table_name))
goto err; // create_table_from_dump will have sent the error already goto err; // create_table_from_dump will have sent the error already
error = 0; error = 0;
...@@ -2963,17 +2959,20 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi, ...@@ -2963,17 +2959,20 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
#ifndef DBUG_OFF #ifndef DBUG_OFF
events_till_disconnect = disconnect_slave_event_count; events_till_disconnect = disconnect_slave_event_count;
#endif #endif
uint client_flag=0; ulong client_flag= CLIENT_REMEMBER_OPTIONS;
if (opt_slave_compressed_protocol) if (opt_slave_compressed_protocol)
client_flag=CLIENT_COMPRESS; /* We will use compression */ client_flag=CLIENT_COMPRESS; /* We will use compression */
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset_info->csname);
/* This one is not strictly needed but we have it here for completeness */
mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
while (!(slave_was_killed = io_slave_killed(thd,mi)) && while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
(reconnect ? mysql_reconnect(mysql) != 0: (reconnect ? mysql_reconnect(mysql) != 0 :
!(mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
(char *)&thd->variables.net_read_timeout), mi->port, 0, client_flag) == 0))
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (char *)default_charset_info),
mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
mi->port, 0, client_flag))))
{ {
/* Don't repeat last error */ /* Don't repeat last error */
if ((int)mysql_errno(mysql) != last_errno) if ((int)mysql_errno(mysql) != last_errno)
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
This files defines some MySQL C API functions that are server specific
*/
#include <mysql_priv.h>
/*
Function called by my_net_init() to set some check variables
*/
extern "C" {
void my_net_local_init(NET *net)
{
#ifndef EMBEDDED_LIBRARY
net->max_packet= (uint) global_system_variables.net_buffer_length;
net->read_timeout= (uint) global_system_variables.net_read_timeout;
net->write_timeout=(uint) global_system_variables.net_write_timeout;
net->retry_count= (uint) global_system_variables.net_retry_count;
net->max_packet_size= max(global_system_variables.net_buffer_length,
global_system_variables.max_allowed_packet);
#endif
}
}
extern "C" {
void mysql_once_init(void)
{
}
}
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