summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c80
-rw-r--r--sql-common/my_time.c36
-rw-r--r--sql-common/my_user.c6
-rw-r--r--sql-common/pack.c12
4 files changed, 68 insertions, 66 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index cb1d224ef2e..baf154dcc43 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -50,7 +50,7 @@
#define MYSQL_CLIENT
#endif
-#define CLI_MYSQL_REAL_CONNECT cli_mysql_real_connect
+#define CLI_MYSQL_REAL_CONNECT STDCALL cli_mysql_real_connect
#undef net_flush
my_bool net_flush(NET *net);
@@ -70,11 +70,6 @@ my_bool net_flush(NET *net);
#include <my_pthread.h> /* because of signal() */
#endif /* defined(THREAD) && !defined(__WIN__) */
-#if defined(OS2) && defined(MYSQL_SERVER)
-#undef ER
-#define ER CER
-#endif /* defined( OS2) && defined(MYSQL_SERVER) */
-
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
@@ -125,7 +120,7 @@ const char *def_shared_memory_base_name= default_shared_memory_base_name;
static void mysql_close_free_options(MYSQL *mysql);
static void mysql_close_free(MYSQL *mysql);
-#if !(defined(__WIN__) || defined(OS2) || defined(__NETWARE__))
+#if !(defined(__WIN__) || defined(__NETWARE__))
static int wait_for_data(my_socket fd, uint timeout);
#endif
@@ -144,7 +139,7 @@ CHARSET_INFO *default_client_charset_info = &my_charset_latin1;
int my_connect(my_socket fd, const struct sockaddr *name, uint namelen,
uint timeout)
{
-#if defined(__WIN__) || defined(OS2) || defined(__NETWARE__)
+#if defined(__WIN__) || defined(__NETWARE__)
return connect(fd, (struct sockaddr*) name, namelen);
#else
int flags, res, s_err;
@@ -184,7 +179,7 @@ int my_connect(my_socket fd, const struct sockaddr *name, uint namelen,
If not, we will use select()
*/
-#if !(defined(__WIN__) || defined(OS2) || defined(__NETWARE__))
+#if !(defined(__WIN__) || defined(__NETWARE__))
static int wait_for_data(my_socket fd, uint timeout)
{
@@ -237,7 +232,7 @@ static int wait_for_data(my_socket fd, uint timeout)
implementations of select that don't adjust tv upon
failure to reflect the time remaining
*/
- start_time = time(NULL);
+ start_time= my_time(0);
for (;;)
{
tv.tv_sec = (long) timeout;
@@ -251,7 +246,7 @@ static int wait_for_data(my_socket fd, uint timeout)
#endif
if (res == 0) /* timeout */
return -1;
- now_time=time(NULL);
+ now_time= my_time(0);
timeout-= (uint) (now_time - start_time);
if (errno != EINTR || (int) timeout <= 0)
return -1;
@@ -275,7 +270,7 @@ static int wait_for_data(my_socket fd, uint timeout)
return (0); /* ok */
#endif /* HAVE_POLL */
}
-#endif /* defined(__WIN__) || defined(OS2) || defined(__NETWARE__) */
+#endif /* defined(__WIN__) || defined(__NETWARE__) */
/*
@@ -657,14 +652,14 @@ void free_rows(MYSQL_DATA *cur)
if (cur)
{
free_root(&cur->alloc,MYF(0));
- my_free((gptr) cur,MYF(0));
+ my_free((uchar*) cur,MYF(0));
}
}
my_bool
cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
- const char *header, ulong header_length,
- const char *arg, ulong arg_length, my_bool skip_check,
+ const uchar *header, ulong header_length,
+ const uchar *arg, ulong arg_length, my_bool skip_check,
MYSQL_STMT *stmt __attribute__((unused)))
{
NET *net= &mysql->net;
@@ -694,7 +689,12 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
mysql->net.report_error=0;
mysql->info=0;
mysql->affected_rows= ~(my_ulonglong) 0;
- net_clear(&mysql->net); /* Clear receive buffer */
+ /*
+ We don't want to clear the protocol buffer on COM_QUIT, because if
+ the previous command was a shutdown command, we may have the
+ response for the COM_QUIT already in the communication buffer
+ */
+ net_clear(&mysql->net, (command != COM_QUIT));
if (net_write_command(net,(uchar) command, header, header_length,
arg, arg_length))
@@ -922,8 +922,8 @@ mysql_free_result(MYSQL_RES *result)
if (result->fields)
free_root(&result->field_alloc,MYF(0));
if (result->row)
- my_free((gptr) result->row,MYF(0));
- my_free((gptr) result,MYF(0));
+ my_free((uchar*) result->row,MYF(0));
+ my_free((uchar*) result,MYF(0));
}
DBUG_VOID_RETURN;
}
@@ -966,7 +966,7 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd)
}
if (!(tmp= my_strdup(cmd,MYF(MY_WME))) ||
- insert_dynamic(options->init_commands, (gptr)&tmp))
+ insert_dynamic(options->init_commands, (uchar*)&tmp))
{
my_free(tmp, MYF(MY_ALLOW_ZERO_PTR));
return 1;
@@ -1178,7 +1178,7 @@ static void cli_fetch_lengths(ulong *to, MYSQL_ROW column,
unsigned int field_count)
{
ulong *prev_length;
- byte *start=0;
+ char *start=0;
MYSQL_ROW end;
prev_length=0; /* Keep gcc happy */
@@ -1597,7 +1597,7 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
*/
const char * STDCALL
-mysql_get_ssl_cipher(MYSQL *mysql)
+mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused)))
{
DBUG_ENTER("mysql_get_ssl_cipher");
#ifdef HAVE_OPENSSL
@@ -2302,7 +2302,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
db= 0;
}
/* Write authentication package */
- if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net))
+ if (my_net_write(net, (uchar*) buff, (size_t) (end-buff)) || net_flush(net))
{
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
ER(CR_SERVER_LOST_EXTENDED),
@@ -2334,7 +2334,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
password in old format.
*/
scramble_323(buff, mysql->scramble, passwd);
- if (my_net_write(net, buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net))
+ if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) ||
+ net_flush(net))
{
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
ER(CR_SERVER_LOST_EXTENDED),
@@ -2514,7 +2515,7 @@ my_bool mysql_reconnect(MYSQL *mysql)
mysql_close(mysql);
*mysql=tmp_mysql;
mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */
- net_clear(&mysql->net);
+ net_clear(&mysql->net, 1);
mysql->affected_rows= ~(my_ulonglong) 0;
DBUG_RETURN(0);
}
@@ -2531,7 +2532,8 @@ mysql_select_db(MYSQL *mysql, const char *db)
DBUG_ENTER("mysql_select_db");
DBUG_PRINT("enter",("db: '%s'",db));
- if ((error=simple_command(mysql,COM_INIT_DB,db,(ulong) strlen(db),0)))
+ if ((error=simple_command(mysql,COM_INIT_DB, (const uchar*) db,
+ (ulong) strlen(db),0)))
DBUG_RETURN(error);
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
mysql->db=my_strdup(db,MYF(MY_WME));
@@ -2582,7 +2584,7 @@ static void mysql_close_free_options(MYSQL *mysql)
static void mysql_close_free(MYSQL *mysql)
{
- my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
+ my_free((uchar*) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
@@ -2603,24 +2605,32 @@ static void mysql_close_free(MYSQL *mysql)
SYNOPSYS
mysql_detach_stmt_list()
stmt_list pointer to mysql->stmts
+ func_name name of calling function
NOTE
There is similar code in mysql_reconnect(), so changes here
should also be reflected there.
*/
-void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)))
+void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)),
+ const char *func_name __attribute__((unused)))
{
#ifdef MYSQL_CLIENT
/* Reset connection handle in all prepared statements. */
LIST *element= *stmt_list;
+ char buff[MYSQL_ERRMSG_SIZE];
+ DBUG_ENTER("mysql_detach_stmt_list");
+
+ my_snprintf(buff, sizeof(buff)-1, ER(CR_STMT_CLOSED), func_name);
for (; element; element= element->next)
{
MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
+ set_stmt_errmsg(stmt, buff, CR_STMT_CLOSED, unknown_sqlstate);
stmt->mysql= 0;
/* No need to call list_delete for statement here */
}
*stmt_list= 0;
+ DBUG_VOID_RETURN;
#endif /* MYSQL_CLIENT */
}
@@ -2636,12 +2646,12 @@ void STDCALL mysql_close(MYSQL *mysql)
free_old_query(mysql);
mysql->status=MYSQL_STATUS_READY; /* Force command */
mysql->reconnect=0;
- simple_command(mysql,COM_QUIT,NullS,0,1);
+ simple_command(mysql,COM_QUIT,(uchar*) 0,0,1);
end_server(mysql); /* Sets mysql->net.vio= 0 */
}
mysql_close_free_options(mysql);
mysql_close_free(mysql);
- mysql_detach_stmt_list(&mysql->stmts);
+ mysql_detach_stmt_list(&mysql->stmts, "mysql_close");
#ifndef TO_BE_DELETED
/* free/close slave list */
if (mysql->rpl_pivot)
@@ -2664,7 +2674,7 @@ void STDCALL mysql_close(MYSQL *mysql)
(*mysql->methods->free_embedded_thd)(mysql);
#endif
if (mysql->free_me)
- my_free((gptr) mysql,MYF(0));
+ my_free((uchar*) mysql,MYF(0));
}
DBUG_VOID_RETURN;
}
@@ -2767,7 +2777,7 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length)
mysql->last_used_con = mysql;
#endif
- DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1));
+ DBUG_RETURN(simple_command(mysql, COM_QUERY, (uchar*) query, length, 1));
}
@@ -2817,7 +2827,7 @@ MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
if (!(result->data=
(*mysql->methods->read_rows)(mysql,mysql->fields,mysql->field_count)))
{
- my_free((gptr) result,MYF(0));
+ my_free((uchar*) result,MYF(0));
DBUG_RETURN(0);
}
mysql->affected_rows= result->row_count= result->data->rows;
@@ -2827,6 +2837,7 @@ MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
result->field_count= mysql->field_count;
/* The rest of result members is bzeroed in malloc */
mysql->fields=0; /* fields is now in result */
+ clear_alloc_root(&mysql->field_alloc);
/* just in case this was mistakenly called after mysql_stmt_execute() */
mysql->unbuffered_fetch_owner= 0;
DBUG_RETURN(result); /* Data fetched */
@@ -2866,7 +2877,7 @@ static MYSQL_RES * cli_use_result(MYSQL *mysql)
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));
+ my_free((uchar*) result,MYF(0));
DBUG_RETURN(0);
}
result->fields= mysql->fields;
@@ -2876,6 +2887,7 @@ static MYSQL_RES * cli_use_result(MYSQL *mysql)
result->handle= mysql;
result->current_row= 0;
mysql->fields=0; /* fields is now in result */
+ clear_alloc_root(&mysql->field_alloc);
mysql->status=MYSQL_STATUS_USE_RESULT;
mysql->unbuffered_fetch_owner= &result->unbuffered_fetch_cancelled;
DBUG_RETURN(result); /* Data is read to be fetched */
@@ -2955,7 +2967,7 @@ mysql_fetch_lengths(MYSQL_RES *res)
int STDCALL
-mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
+mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
{
DBUG_ENTER("mysql_option");
DBUG_PRINT("enter",("option: %d",(int) option));
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index a39cc754c88..a6d3a4246ad 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -301,9 +301,6 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
field_length= 6; /* 6 digits */
}
continue;
-
- /* No part seconds */
- date[++i]= 0;
}
while (str != end &&
(my_ispunct(&my_charset_latin1,*str) ||
@@ -453,7 +450,7 @@ err:
/*
- Convert a time string to a TIME struct.
+ Convert a time string to a MYSQL_TIME struct.
SYNOPSIS
str_to_time()
@@ -569,12 +566,12 @@ my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time,
/* Fix the date to assume that seconds was given */
if (!found_hours && !found_days)
{
- bmove_upp((char*) (date+4), (char*) (date+state),
+ bmove_upp((uchar*) (date+4), (uchar*) (date+state),
sizeof(long)*(state-1));
- bzero((char*) date, sizeof(long)*(4-state));
+ bzero((uchar*) date, sizeof(long)*(4-state));
}
else
- bzero((char*) (date+state), sizeof(long)*(4-state));
+ bzero((uchar*) (date+state), sizeof(long)*(4-state));
}
fractional:
@@ -639,11 +636,11 @@ fractional:
l_time->second_part= date[4];
l_time->time_type= MYSQL_TIMESTAMP_TIME;
- /* Check if the value is valid and fits into TIME range */
+ /* Check if the value is valid and fits into MYSQL_TIME range */
if (check_time_range(l_time, warning))
return 1;
- /* Check if there is garbage at end of the TIME specification */
+ /* Check if there is garbage at end of the MYSQL_TIME specification */
if (str != end)
{
do
@@ -660,11 +657,11 @@ fractional:
/*
- Check 'time' value to lie in the TIME range
+ Check 'time' value to lie in the MYSQL_TIME range
SYNOPSIS:
check_time_range()
- time pointer to TIME value
+ time pointer to MYSQL_TIME value
warning set MYSQL_TIME_WARN_OUT_OF_RANGE flag if the value is out of range
DESCRIPTION
@@ -769,11 +766,6 @@ long calc_daynr(uint year,uint month,uint day)
if (year == 0 && month == 0 && day == 0)
DBUG_RETURN(0); /* Skip errors */
- if (year < 200)
- {
- if ((year=year+1900) < 1900+YY_PART_YEAR)
- year+=100;
- }
delsum= (long) (365L * year+ 31*(month-1) +day);
if (month <= 2)
year--;
@@ -1010,7 +1002,7 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type)
/*
Functions to convert time/date/datetime value to a string,
using default format.
- This functions don't check that given TIME structure members are
+ This functions don't check that given MYSQL_TIME structure members are
in valid range. If they are not, return value won't reflect any
valid date either. Additionally, make_time doesn't take into
account time->day member: it's assumed that days have been converted
@@ -1096,7 +1088,7 @@ int my_TIME_to_str(const MYSQL_TIME *l_time, char *to)
DESCRIPTION
Convert a datetime value of formats YYMMDD, YYYYMMDD, YYMMDDHHMSS,
- YYYYMMDDHHMMSS to broken-down TIME representation. Return value in
+ YYYYMMDDHHMMSS to broken-down MYSQL_TIME representation. Return value in
YYYYMMDDHHMMSS format as side-effect.
This function also checks if datetime value fits in DATETIME range.
@@ -1196,7 +1188,7 @@ ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *my_time)
}
-/* Convert TIME value to integer in YYYYMMDD format */
+/* Convert MYSQL_TIME value to integer in YYYYMMDD format */
ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *my_time)
{
@@ -1206,7 +1198,7 @@ ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *my_time)
/*
- Convert TIME value to integer in HHMMSS format.
+ Convert MYSQL_TIME value to integer in HHMMSS format.
This function doesn't take into account time->day member:
it's assumed that days have been converted to hours already.
*/
@@ -1220,7 +1212,7 @@ ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *my_time)
/*
- Convert struct TIME (date and time split into year/month/day/hour/...
+ Convert struct MYSQL_TIME (date and time split into year/month/day/hour/...
to a number in format YYYYMMDDHHMMSS (DATETIME),
YYYYMMDD (DATE) or HHMMSS (TIME).
@@ -1234,7 +1226,7 @@ ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *my_time)
SELECT ?+1;
NOTE
- This function doesn't check that given TIME structure members are
+ This function doesn't check that given MYSQL_TIME structure members are
in valid range. If they are not, return value won't reflect any
valid date either.
*/
diff --git a/sql-common/my_user.c b/sql-common/my_user.c
index fa5b80413bf..16a544387ee 100644
--- a/sql-common/my_user.c
+++ b/sql-common/my_user.c
@@ -31,9 +31,9 @@
host_name_len [OUT] A place to store length of the host name part.
*/
-void parse_user(const char *user_id_str, uint user_id_len,
- char *user_name_str, uint *user_name_len,
- char *host_name_str, uint *host_name_len)
+void parse_user(const char *user_id_str, size_t user_id_len,
+ char *user_name_str, size_t *user_name_len,
+ char *host_name_str, size_t *host_name_len)
{
char *p= strrchr(user_id_str, '@');
diff --git a/sql-common/pack.c b/sql-common/pack.c
index 33c1103fb04..7ff89471b45 100644
--- a/sql-common/pack.c
+++ b/sql-common/pack.c
@@ -94,30 +94,28 @@ my_ulonglong net_field_length_ll(uchar **packet)
Position in 'pkg' after the packed length
*/
-char *
-net_store_length(char *pkg, ulonglong length)
+uchar *net_store_length(uchar *packet, ulonglong length)
{
- uchar *packet=(uchar*) pkg;
if (length < (ulonglong) LL(251))
{
*packet=(uchar) length;
- return (char*) packet+1;
+ return packet+1;
}
/* 251 is reserved for NULL */
if (length < (ulonglong) LL(65536))
{
*packet++=252;
int2store(packet,(uint) length);
- return (char*) packet+2;
+ return packet+2;
}
if (length < (ulonglong) LL(16777216))
{
*packet++=253;
int3store(packet,(ulong) length);
- return (char*) packet+3;
+ return packet+3;
}
*packet++=254;
int8store(packet,length);
- return (char*) packet+8;
+ return packet+8;
}