Commit 6c763974 authored by unknown's avatar unknown

Merge bk-internal.mysql.com:/home/bk/mysql-5.1-runtime

into  bodhi.(none):/opt/local/work/mysql-5.1-runtime-inc


libmysql/libmysql.c:
  Auto merged
parents 44068505 70987ab9
...@@ -36,8 +36,10 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -36,8 +36,10 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
const unsigned char *arg, ulong arg_length, const unsigned char *arg, ulong arg_length,
my_bool skip_check, MYSQL_STMT *stmt); my_bool skip_check, MYSQL_STMT *stmt);
unsigned long cli_safe_read(MYSQL *mysql); unsigned long cli_safe_read(MYSQL *mysql);
void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode, void net_clear_error(NET *net);
const char *sqlstate); void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
const char *err);
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate); void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -686,9 +686,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd) ...@@ -686,9 +686,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) || if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) ||
net_flush(net)) net_flush(net))
{ {
net->last_errno= CR_SERVER_LOST; set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
strmov(net->sqlstate, unknown_sqlstate);
strmov(net->last_error,ER(net->last_errno));
return 1; return 1;
} }
/* Read what server thinks about out new auth message report */ /* Read what server thinks about out new auth message report */
...@@ -861,8 +859,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) ...@@ -861,8 +859,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
/* copy filename into local memory and allocate read buffer */ /* copy filename into local memory and allocate read buffer */
if (!(buf=my_malloc(packet_length, MYF(0)))) if (!(buf=my_malloc(packet_length, MYF(0))))
{ {
strmov(net->sqlstate, unknown_sqlstate); set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -888,9 +885,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) ...@@ -888,9 +885,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
{ {
DBUG_PRINT("error", DBUG_PRINT("error",
("Lost connection to MySQL server during LOAD DATA of local file")); ("Lost connection to MySQL server during LOAD DATA of local file"));
strmov(net->sqlstate, unknown_sqlstate); set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
net->last_errno=CR_SERVER_LOST;
strmov(net->last_error,ER(net->last_errno));
goto err; goto err;
} }
} }
...@@ -898,9 +893,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) ...@@ -898,9 +893,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
/* Send empty packet to mark end of file */ /* Send empty packet to mark end of file */
if (my_net_write(net, (const uchar*) "", 0) || net_flush(net)) if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
{ {
strmov(net->sqlstate, unknown_sqlstate); set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
net->last_errno=CR_SERVER_LOST;
sprintf(net->last_error,ER(net->last_errno),errno);
goto err; goto err;
} }
...@@ -1401,9 +1394,7 @@ const char *cli_read_statistics(MYSQL *mysql) ...@@ -1401,9 +1394,7 @@ const char *cli_read_statistics(MYSQL *mysql)
mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */
if (!mysql->net.read_pos[0]) if (!mysql->net.read_pos[0])
{ {
strmov(mysql->net.sqlstate, unknown_sqlstate); set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
mysql->net.last_errno=CR_WRONG_HOST_INFO;
strmov(mysql->net.last_error, ER(mysql->net.last_errno));
return mysql->net.last_error; return mysql->net.last_error;
} }
return (char*) mysql->net.read_pos; return (char*) mysql->net.read_pos;
...@@ -1849,24 +1840,17 @@ static my_bool my_realloc_str(NET *net, ulong length) ...@@ -1849,24 +1840,17 @@ static my_bool my_realloc_str(NET *net, ulong length)
if (buf_length + length > net->max_packet) if (buf_length + length > net->max_packet)
{ {
res= net_realloc(net, buf_length + length); res= net_realloc(net, buf_length + length);
if (res)
{
strmov(net->sqlstate, unknown_sqlstate);
strmov(net->last_error, ER(net->last_errno));
}
net->write_pos= net->buff+ buf_length; net->write_pos= net->buff+ buf_length;
} }
DBUG_RETURN(res); DBUG_RETURN(res);
} }
/* Clear possible error statee of struct NET */
static void net_clear_error(NET *net)
{
if (net->last_errno)
{
net->last_errno= 0;
net->last_error[0]= '\0';
strmov(net->sqlstate, not_error_sqlstate);
}
}
static void stmt_clear_error(MYSQL_STMT *stmt) static void stmt_clear_error(MYSQL_STMT *stmt)
{ {
if (stmt->last_errno) if (stmt->last_errno)
...@@ -1877,18 +1861,21 @@ static void stmt_clear_error(MYSQL_STMT *stmt) ...@@ -1877,18 +1861,21 @@ static void stmt_clear_error(MYSQL_STMT *stmt)
} }
} }
/* /**
Set statement error code, sqlstate, and error message Set statement error code, sqlstate, and error message
from given errcode and sqlstate. from given errcode and sqlstate.
*/ */
static void set_stmt_error(MYSQL_STMT * stmt, int errcode, void set_stmt_error(MYSQL_STMT * stmt, int errcode,
const char *sqlstate) const char *sqlstate, const char *err)
{ {
DBUG_ENTER("set_stmt_error"); DBUG_ENTER("set_stmt_error");
DBUG_PRINT("enter", ("error: %d '%s'", errcode, ER(errcode))); DBUG_PRINT("enter", ("error: %d '%s'", errcode, ER(errcode)));
DBUG_ASSERT(stmt != 0); DBUG_ASSERT(stmt != 0);
if (err == 0)
err= ER(errcode);
stmt->last_errno= errcode; stmt->last_errno= errcode;
strmov(stmt->last_error, ER(errcode)); strmov(stmt->last_error, ER(errcode));
strmov(stmt->sqlstate, sqlstate); strmov(stmt->sqlstate, sqlstate);
...@@ -1897,21 +1884,24 @@ static void set_stmt_error(MYSQL_STMT * stmt, int errcode, ...@@ -1897,21 +1884,24 @@ static void set_stmt_error(MYSQL_STMT * stmt, int errcode,
} }
/* /**
Set statement error code, sqlstate, and error message. Set statement error code, sqlstate, and error message from NET.
@param stmt a statement handle. Copy the error here.
@param net mysql->net. Source of the error.
*/ */
void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode, void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
const char *sqlstate)
{ {
DBUG_ENTER("set_stmt_errmsg"); DBUG_ENTER("set_stmt_errmsg");
DBUG_PRINT("enter", ("error: %d/%s '%s'", errcode, sqlstate, err)); DBUG_PRINT("enter", ("error: %d/%s '%s'", net->last_errno, net->sqlstate,
net->last_error));
DBUG_ASSERT(stmt != 0); DBUG_ASSERT(stmt != 0);
stmt->last_errno= errcode; stmt->last_errno= net->last_errno;
if (err && err[0]) if (net->last_error && net->last_error[0])
strmov(stmt->last_error, err); strmov(stmt->last_error, net->last_error);
strmov(stmt->sqlstate, sqlstate); strmov(stmt->sqlstate, net->sqlstate);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -2086,7 +2076,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length) ...@@ -2086,7 +2076,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
if (!mysql) if (!mysql)
{ {
/* mysql can be reset in mysql_close called from mysql_reconnect */ /* mysql can be reset in mysql_close called from mysql_reconnect */
set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate); set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -2124,23 +2114,20 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length) ...@@ -2124,23 +2114,20 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
stmt->state= MYSQL_STMT_INIT_DONE; stmt->state= MYSQL_STMT_INIT_DONE;
if (stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt)) if (stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.sqlstate);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
if (stmt_command(mysql, COM_STMT_PREPARE, (const uchar*) query, length, stmt)) if (stmt_command(mysql, COM_STMT_PREPARE, (const uchar*) query, length, stmt))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.sqlstate);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
if ((*mysql->methods->read_prepare_result)(mysql, stmt)) if ((*mysql->methods->read_prepare_result)(mysql, stmt))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.sqlstate);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -2155,7 +2142,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length) ...@@ -2155,7 +2142,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
(stmt->param_count + (stmt->param_count +
stmt->field_count)))) stmt->field_count))))
{ {
set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
stmt->bind= stmt->params + stmt->param_count; stmt->bind= stmt->params + stmt->param_count;
...@@ -2285,7 +2272,7 @@ mysql_stmt_result_metadata(MYSQL_STMT *stmt) ...@@ -2285,7 +2272,7 @@ mysql_stmt_result_metadata(MYSQL_STMT *stmt)
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result), if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result),
MYF(MY_WME | MY_ZEROFILL)))) MYF(MY_WME | MY_ZEROFILL))))
{ {
set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -2518,7 +2505,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param) ...@@ -2518,7 +2505,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
*/ */
if ((my_realloc_str(net, *param->length))) if ((my_realloc_str(net, *param->length)))
{ {
set_stmt_error(stmt, net->last_errno, unknown_sqlstate); set_stmt_errmsg(stmt, net);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
(*param->store_param_func)(net, param); (*param->store_param_func)(net, param);
...@@ -2555,7 +2542,7 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length) ...@@ -2555,7 +2542,7 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length)
stmt->insert_id= mysql->insert_id; stmt->insert_id= mysql->insert_id;
if (res) if (res)
{ {
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); set_stmt_errmsg(stmt, net);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -2578,13 +2565,13 @@ int cli_stmt_execute(MYSQL_STMT *stmt) ...@@ -2578,13 +2565,13 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
if (!stmt->bind_param_done) if (!stmt->bind_param_done)
{ {
set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate); set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
if (mysql->status != MYSQL_STATUS_READY || if (mysql->status != MYSQL_STATUS_READY ||
mysql->server_status & SERVER_MORE_RESULTS_EXISTS) mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
{ {
set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -2593,7 +2580,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt) ...@@ -2593,7 +2580,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
null_count= (stmt->param_count+7) /8; null_count= (stmt->param_count+7) /8;
if (my_realloc_str(net, null_count + 1)) if (my_realloc_str(net, null_count + 1))
{ {
set_stmt_error(stmt, net->last_errno, unknown_sqlstate); set_stmt_errmsg(stmt, net);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
bzero((char*) net->write_pos, null_count); bzero((char*) net->write_pos, null_count);
...@@ -2606,7 +2593,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt) ...@@ -2606,7 +2593,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
{ {
if (my_realloc_str(net, 2 * stmt->param_count)) if (my_realloc_str(net, 2 * stmt->param_count))
{ {
set_stmt_error(stmt, net->last_errno, unknown_sqlstate); set_stmt_errmsg(stmt, net);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
/* /*
...@@ -2629,7 +2616,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt) ...@@ -2629,7 +2616,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
/* TODO: Look into avoding the following memdup */ /* TODO: Look into avoding the following memdup */
if (!(param_data= my_memdup(net->buff, length, MYF(0)))) if (!(param_data= my_memdup(net->buff, length, MYF(0))))
{ {
set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
result= execute(stmt, param_data, length); result= execute(stmt, param_data, length);
...@@ -2693,20 +2680,19 @@ static int stmt_read_row_unbuffered(MYSQL_STMT *stmt, unsigned char **row) ...@@ -2693,20 +2680,19 @@ static int stmt_read_row_unbuffered(MYSQL_STMT *stmt, unsigned char **row)
*/ */
if (!mysql) if (!mysql)
{ {
set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate); set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
return 1; return 1;
} }
if (mysql->status != MYSQL_STATUS_GET_RESULT) if (mysql->status != MYSQL_STATUS_GET_RESULT)
{ {
set_stmt_error(stmt, stmt->unbuffered_fetch_cancelled ? set_stmt_error(stmt, stmt->unbuffered_fetch_cancelled ?
CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC, CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC,
unknown_sqlstate); unknown_sqlstate, NULL);
goto error; goto error;
} }
if ((*mysql->methods->unbuffered_fetch)(mysql, (char**) row)) if ((*mysql->methods->unbuffered_fetch)(mysql, (char**) row))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.sqlstate);
/* /*
If there was an error, there are no more pending rows: If there was an error, there are no more pending rows:
reset statement status to not hang up in following reset statement status to not hang up in following
...@@ -2767,7 +2753,7 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row) ...@@ -2767,7 +2753,7 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row)
buff, sizeof(buff), (uchar*) 0, 0, buff, sizeof(buff), (uchar*) 0, 0,
1, NULL)) 1, NULL))
{ {
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); set_stmt_errmsg(stmt, net);
return 1; return 1;
} }
if ((*mysql->methods->read_rows_from_cursor)(stmt)) if ((*mysql->methods->read_rows_from_cursor)(stmt))
...@@ -2798,7 +2784,7 @@ static int ...@@ -2798,7 +2784,7 @@ static int
stmt_read_row_no_result_set(MYSQL_STMT *stmt __attribute__((unused)), stmt_read_row_no_result_set(MYSQL_STMT *stmt __attribute__((unused)),
unsigned char **row __attribute__((unused))) unsigned char **row __attribute__((unused)))
{ {
set_stmt_error(stmt, CR_NO_RESULT_SET, unknown_sqlstate); set_stmt_error(stmt, CR_NO_RESULT_SET, unknown_sqlstate, NULL);
return 1; return 1;
} }
...@@ -2848,7 +2834,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, ...@@ -2848,7 +2834,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
} }
return FALSE; return FALSE;
err_not_implemented: err_not_implemented:
set_stmt_error(stmt, CR_NOT_IMPLEMENTED, unknown_sqlstate); set_stmt_error(stmt, CR_NOT_IMPLEMENTED, unknown_sqlstate, NULL);
return TRUE; return TRUE;
} }
...@@ -3233,7 +3219,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *my_bind) ...@@ -3233,7 +3219,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *my_bind)
{ {
if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE) if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE)
{ {
set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate); set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -3398,7 +3384,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, ...@@ -3398,7 +3384,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
*/ */
if (param_number >= stmt->param_count) if (param_number >= stmt->param_count)
{ {
set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate); set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -3434,8 +3420,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, ...@@ -3434,8 +3420,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
buff, sizeof(buff), (uchar*) data, buff, sizeof(buff), (uchar*) data,
length, 1, NULL)) length, 1, NULL))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.last_errno, mysql->net.sqlstate);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
...@@ -3904,7 +3889,8 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, ...@@ -3904,7 +3889,8 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
if (field->flags & ZEROFILL_FLAG && length < field->length && if (field->flags & ZEROFILL_FLAG && length < field->length &&
field->length < MAX_DOUBLE_STRING_REP_LENGTH - 1) field->length < MAX_DOUBLE_STRING_REP_LENGTH - 1)
{ {
bmove_upp((char*) buff + field->length, buff + length, length); bmove_upp((uchar*) buff + field->length, (uchar*) buff + length,
length);
bfill((char*) buff, field->length - length, '0'); bfill((char*) buff, field->length - length, '0');
length= field->length; length= field->length;
} }
...@@ -4503,7 +4489,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *my_bind) ...@@ -4503,7 +4489,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *my_bind)
{ {
int errorcode= (int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE ? int errorcode= (int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE ?
CR_NO_PREPARE_STMT : CR_NO_STMT_METADATA; CR_NO_PREPARE_STMT : CR_NO_STMT_METADATA;
set_stmt_error(stmt, errorcode, unknown_sqlstate); set_stmt_error(stmt, errorcode, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -4683,12 +4669,12 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *my_bind, ...@@ -4683,12 +4669,12 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *my_bind,
if ((int) stmt->state < (int) MYSQL_STMT_FETCH_DONE) if ((int) stmt->state < (int) MYSQL_STMT_FETCH_DONE)
{ {
set_stmt_error(stmt, CR_NO_DATA, unknown_sqlstate); set_stmt_error(stmt, CR_NO_DATA, unknown_sqlstate, NULL);
return 1; return 1;
} }
if (column >= stmt->field_count) if (column >= stmt->field_count)
{ {
set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate); set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -4734,7 +4720,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt) ...@@ -4734,7 +4720,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
if (!mysql) if (!mysql)
{ {
set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate); set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -4749,7 +4735,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt) ...@@ -4749,7 +4735,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc,
sizeof(MYSQL_ROWS) + pkt_len - 1))) sizeof(MYSQL_ROWS) + pkt_len - 1)))
{ {
set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
goto err; goto err;
} }
cur->data= (MYSQL_ROW) (cur+1); cur->data= (MYSQL_ROW) (cur+1);
...@@ -4770,7 +4756,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt) ...@@ -4770,7 +4756,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
} }
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); set_stmt_errmsg(stmt, net);
err: err:
DBUG_RETURN(1); DBUG_RETURN(1);
...@@ -4837,7 +4823,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) ...@@ -4837,7 +4823,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
if ((int) stmt->state < (int) MYSQL_STMT_EXECUTE_DONE) if ((int) stmt->state < (int) MYSQL_STMT_EXECUTE_DONE)
{ {
set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -4857,13 +4843,13 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) ...@@ -4857,13 +4843,13 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff), if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff),
(uchar*) 0, 0, 1, NULL)) (uchar*) 0, 0, 1, NULL))
{ {
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); set_stmt_errmsg(stmt, net);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
else if (mysql->status != MYSQL_STATUS_GET_RESULT) else if (mysql->status != MYSQL_STATUS_GET_RESULT)
{ {
set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -5044,8 +5030,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags) ...@@ -5044,8 +5030,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags)
if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET, buff, if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET, buff,
sizeof(buff), 0, 0, 0, NULL)) sizeof(buff), 0, 0, 0, NULL))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.sqlstate);
stmt->state= MYSQL_STMT_INIT_DONE; stmt->state= MYSQL_STMT_INIT_DONE;
return 1; return 1;
} }
...@@ -5118,8 +5103,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) ...@@ -5118,8 +5103,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
int4store(buff, stmt->stmt_id); int4store(buff, stmt->stmt_id);
if ((rc= stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt))) if ((rc= stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt)))
{ {
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.sqlstate);
} }
} }
} }
...@@ -5140,7 +5124,7 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) ...@@ -5140,7 +5124,7 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt)
if (!stmt->mysql) if (!stmt->mysql)
{ {
/* mysql can be reset in mysql_close called from mysql_reconnect */ /* mysql can be reset in mysql_close called from mysql_reconnect */
set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate); set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
/* Reset the client and server sides of the prepared statement */ /* Reset the client and server sides of the prepared statement */
...@@ -5244,15 +5228,11 @@ int STDCALL mysql_next_result(MYSQL *mysql) ...@@ -5244,15 +5228,11 @@ int STDCALL mysql_next_result(MYSQL *mysql)
if (mysql->status != MYSQL_STATUS_READY) if (mysql->status != MYSQL_STATUS_READY)
{ {
strmov(mysql->net.sqlstate, unknown_sqlstate); set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
strmov(mysql->net.last_error,
ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
mysql->net.last_error[0]= 0; net_clear_error(&mysql->net);
mysql->net.last_errno= 0;
strmov(mysql->net.sqlstate, not_error_sqlstate);
mysql->affected_rows= ~(my_ulonglong) 0; mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
......
...@@ -81,8 +81,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -81,8 +81,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
/* Check that we are calling the client functions in right order */ /* Check that we are calling the client functions in right order */
if (mysql->status != MYSQL_STATUS_READY) if (mysql->status != MYSQL_STATUS_READY)
{ {
strmov(net->last_error, set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
ER(net->last_errno=CR_COMMANDS_OUT_OF_SYNC));
return 1; return 1;
} }
...@@ -90,7 +89,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -90,7 +89,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
thd->clear_error(); thd->clear_error();
mysql->affected_rows= ~(my_ulonglong) 0; mysql->affected_rows= ~(my_ulonglong) 0;
mysql->field_count= 0; mysql->field_count= 0;
net->last_errno= 0; net_clear_error(net);
thd->current_stmt= stmt; thd->current_stmt= stmt;
thd->store_globals(); // Fix if more than one connect thd->store_globals(); // Fix if more than one connect
...@@ -245,8 +244,7 @@ static my_bool emb_read_query_result(MYSQL *mysql) ...@@ -245,8 +244,7 @@ static my_bool emb_read_query_result(MYSQL *mysql)
mysql->fields= res->embedded_info->fields_list; mysql->fields= res->embedded_info->fields_list;
mysql->affected_rows= res->embedded_info->affected_rows; mysql->affected_rows= res->embedded_info->affected_rows;
mysql->insert_id= res->embedded_info->insert_id; mysql->insert_id= res->embedded_info->insert_id;
mysql->net.last_errno= 0; net_clear_error(&mysql->net);
mysql->net.last_error[0]= 0;
mysql->info= 0; mysql->info= 0;
if (res->embedded_info->info[0]) if (res->embedded_info->info[0])
...@@ -288,7 +286,7 @@ static int emb_stmt_execute(MYSQL_STMT *stmt) ...@@ -288,7 +286,7 @@ static int emb_stmt_execute(MYSQL_STMT *stmt)
if (res) if (res)
{ {
NET *net= &stmt->mysql->net; NET *net= &stmt->mysql->net;
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); set_stmt_errmsg(stmt, net);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -299,14 +297,12 @@ int emb_read_binary_rows(MYSQL_STMT *stmt) ...@@ -299,14 +297,12 @@ int emb_read_binary_rows(MYSQL_STMT *stmt)
MYSQL_DATA *data; MYSQL_DATA *data;
if (!(data= emb_read_rows(stmt->mysql, 0, 0))) if (!(data= emb_read_rows(stmt->mysql, 0, 0)))
{ {
set_stmt_errmsg(stmt, stmt->mysql->net.last_error, set_stmt_errmsg(stmt, &stmt->mysql->net);
stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate);
return 1; return 1;
} }
stmt->result= *data; stmt->result= *data;
my_free((char *) data, MYF(0)); my_free((char *) data, MYF(0));
set_stmt_errmsg(stmt, stmt->mysql->net.last_error, set_stmt_errmsg(stmt, &stmt->mysql->net);
stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate);
return 0; return 0;
} }
...@@ -320,16 +316,14 @@ int emb_read_rows_from_cursor(MYSQL_STMT *stmt) ...@@ -320,16 +316,14 @@ int emb_read_rows_from_cursor(MYSQL_STMT *stmt)
if (res->embedded_info->last_errno) if (res->embedded_info->last_errno)
{ {
embedded_get_error(mysql, res); embedded_get_error(mysql, res);
set_stmt_errmsg(stmt, mysql->net.last_error, set_stmt_errmsg(stmt, &mysql->net);
mysql->net.last_errno, mysql->net.sqlstate);
return 1; return 1;
} }
thd->cur_data= res; thd->cur_data= res;
mysql->warning_count= res->embedded_info->warning_count; mysql->warning_count= res->embedded_info->warning_count;
mysql->server_status= res->embedded_info->server_status; mysql->server_status= res->embedded_info->server_status;
mysql->net.last_errno= 0; net_clear_error(&mysql->net);
mysql->net.last_error[0]= 0;
return emb_read_binary_rows(stmt); return emb_read_binary_rows(stmt);
} }
......
...@@ -312,42 +312,34 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, ...@@ -312,42 +312,34 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host,
break; break;
if (GetLastError() != ERROR_PIPE_BUSY) if (GetLastError() != ERROR_PIPE_BUSY)
{ {
net->last_errno=CR_NAMEDPIPEOPEN_ERROR; set_mysql_extended_error(mysql, CR_NAMEDPIPEOPEN_ERROR,
strmov(net->sqlstate, unknown_sqlstate); unknown_sqlstate, ER(CR_NAMEDPIPEOPEN_ERROR),
my_snprintf(net->last_error, sizeof(net->last_error)-1, host, unix_socket, (ulong) GetLastError());
ER(net->last_errno), host, unix_socket,
(ulong) GetLastError());
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
/* wait for for an other instance */ /* wait for for an other instance */
if (! WaitNamedPipe(pipe_name, connect_timeout*1000) ) if (! WaitNamedPipe(pipe_name, connect_timeout*1000) )
{ {
net->last_errno=CR_NAMEDPIPEWAIT_ERROR; set_mysql_extended_error(mysql, CR_NAMEDPIPEWAIT_ERROR, unknown_sqlstate,
strmov(net->sqlstate, unknown_sqlstate); ER(CR_NAMEDPIPEWAIT_ERROR),
my_snprintf(net->last_error, sizeof(net->last_error)-1, host, unix_socket, (ulong) GetLastError());
ER(net->last_errno), host, unix_socket,
(ulong) GetLastError());
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
} }
if (hPipe == INVALID_HANDLE_VALUE) if (hPipe == INVALID_HANDLE_VALUE)
{ {
net->last_errno=CR_NAMEDPIPEOPEN_ERROR; set_mysql_extended_error(mysql, CR_NAMEDPIPEOPEN_ERROR, unknown_sqlstate,
strmov(net->sqlstate, unknown_sqlstate); ER(CR_NAMEDPIPEOPEN_ERROR), host, unix_socket,
my_snprintf(net->last_error, sizeof(net->last_error)-1, (ulong) GetLastError());
ER(net->last_errno), host, unix_socket,
(ulong) GetLastError());
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
dwMode = PIPE_READMODE_BYTE | PIPE_WAIT; dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) ) if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) )
{ {
CloseHandle( hPipe ); CloseHandle( hPipe );
net->last_errno=CR_NAMEDPIPESETSTATE_ERROR; set_mysql_extended_error(mysql, CR_NAMEDPIPESETSTATE_ERROR,
strmov(net->sqlstate, unknown_sqlstate); unknown_sqlstate, ER(CR_NAMEDPIPESETSTATE_ERROR),
my_snprintf(net->last_error, sizeof(net->last_error)-1, host, unix_socket, (ulong) GetLastError());
ER(net->last_errno),host, unix_socket,
(ulong) GetLastError());
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
*arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */ *arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */
...@@ -566,14 +558,12 @@ err: ...@@ -566,14 +558,12 @@ err:
CloseHandle(handle_connect_file_map); CloseHandle(handle_connect_file_map);
if (error_allow) if (error_allow)
{ {
net->last_errno=error_allow;
strmov(net->sqlstate, unknown_sqlstate);
if (error_allow == CR_SHARED_MEMORY_EVENT_ERROR) if (error_allow == CR_SHARED_MEMORY_EVENT_ERROR)
my_snprintf(net->last_error,sizeof(net->last_error)-1, set_mysql_extended_error(mysql, error_allow, unknown_sqlstate,
ER(net->last_errno),suffix_pos,error_code); ER(error_allow), suffix_pos, error_code);
else else
my_snprintf(net->last_error,sizeof(net->last_error)-1, set_mysql_extended_error(mysql, error_allow, unknown_sqlstate,
ER(net->last_errno),error_code); ER(error_allow), error_code);
return(INVALID_HANDLE_VALUE); return(INVALID_HANDLE_VALUE);
} }
return(handle_map); return(handle_map);
...@@ -683,10 +673,8 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -683,10 +673,8 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
DBUG_RETURN(1); DBUG_RETURN(1);
} }
net->last_error[0]=0; net_clear_error(net);
net->last_errno= 0; net->report_error=0;
strmov(net->sqlstate, not_error_sqlstate);
mysql->net.report_error=0;
mysql->info=0; mysql->info=0;
mysql->affected_rows= ~(my_ulonglong) 0; mysql->affected_rows= ~(my_ulonglong) 0;
/* /*
...@@ -703,8 +691,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -703,8 +691,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
socket_errno)); socket_errno));
if (net->last_errno == ER_NET_PACKET_TOO_LARGE) if (net->last_errno == ER_NET_PACKET_TOO_LARGE)
{ {
net->last_errno=CR_NET_PACKET_TOO_LARGE; set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
strmov(net->last_error,ER(net->last_errno));
goto end; goto end;
} }
end_server(mysql); end_server(mysql);
...@@ -713,8 +700,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -713,8 +700,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
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))
{ {
net->last_errno=CR_SERVER_GONE_ERROR; set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
strmov(net->last_error,ER(net->last_errno));
goto end; goto end;
} }
} }
...@@ -760,6 +746,19 @@ void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate) ...@@ -760,6 +746,19 @@ void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/**
Clear possible error state of struct NET
@param net clear the state of the argument
*/
void net_clear_error(NET *net)
{
net->last_errno= 0;
net->last_error[0]= '\0';
strmov(net->sqlstate, not_error_sqlstate);
}
static void set_mysql_extended_error(MYSQL *mysql, int errcode, static void set_mysql_extended_error(MYSQL *mysql, int errcode,
const char *sqlstate, const char *sqlstate,
...@@ -846,9 +845,8 @@ static int check_license(MYSQL *mysql) ...@@ -846,9 +845,8 @@ static int check_license(MYSQL *mysql)
{ {
if (net->last_errno == ER_UNKNOWN_SYSTEM_VARIABLE) if (net->last_errno == ER_UNKNOWN_SYSTEM_VARIABLE)
{ {
net->last_errno= CR_WRONG_LICENSE; set_mysql_extended_error(mysql, CR_WRONG_LICENSE, unknown_sqlstate,
my_snprintf(net->last_error, sizeof(net->last_error)-1, ER(CR_WRONG_LICENSE), required_license);
ER(net->last_errno), required_license);
} }
return 1; return 1;
} }
...@@ -864,9 +862,8 @@ static int check_license(MYSQL *mysql) ...@@ -864,9 +862,8 @@ static int check_license(MYSQL *mysql)
(!row || !row[0] || (!row || !row[0] ||
strncmp(row[0], required_license, sizeof(required_license)))) strncmp(row[0], required_license, sizeof(required_license))))
{ {
net->last_errno= CR_WRONG_LICENSE; set_mysql_extended_error(mysql, CR_WRONG_LICENSE, unknown_sqlstate,
my_snprintf(net->last_error, sizeof(net->last_error)-1, ER(CR_WRONG_LICENSE), required_license);
ER(net->last_errno), required_license);
} }
mysql_free_result(res); mysql_free_result(res);
return net->last_errno; return net->last_errno;
...@@ -1761,24 +1758,22 @@ int mysql_init_character_set(MYSQL *mysql) ...@@ -1761,24 +1758,22 @@ int mysql_init_character_set(MYSQL *mysql)
} }
charsets_dir= save; charsets_dir= save;
} }
if (!mysql->charset) if (!mysql->charset)
{ {
net->last_errno=CR_CANT_READ_CHARSET;
strmov(net->sqlstate, unknown_sqlstate);
if (mysql->options.charset_dir) if (mysql->options.charset_dir)
my_snprintf(net->last_error, sizeof(net->last_error)-1, set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
ER(net->last_errno), ER(CR_CANT_READ_CHARSET),
mysql->options.charset_name, mysql->options.charset_name,
mysql->options.charset_dir); 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);
my_snprintf(net->last_error, sizeof(net->last_error)-1, set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
ER(net->last_errno), ER(CR_CANT_READ_CHARSET),
mysql->options.charset_name, mysql->options.charset_name,
cs_dir_name); cs_dir_name);
} }
return 1; return 1;
} }
...@@ -1910,10 +1905,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -1910,10 +1905,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
{ {
net->last_errno=CR_SOCKET_CREATE_ERROR; set_mysql_extended_error(mysql, CR_SOCKET_CREATE_ERROR,
strmov(net->sqlstate, unknown_sqlstate); unknown_sqlstate,
my_snprintf(net->last_error,sizeof(net->last_error)-1, ER(CR_SOCKET_CREATE_ERROR),
ER(net->last_errno),socket_errno); socket_errno);
goto error; goto error;
} }
net->vio= vio_new(sock, VIO_TYPE_SOCKET, net->vio= vio_new(sock, VIO_TYPE_SOCKET,
...@@ -1926,10 +1921,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -1926,10 +1921,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
{ {
DBUG_PRINT("error",("Got error %d on connect to local server", DBUG_PRINT("error",("Got error %d on connect to local server",
socket_errno)); socket_errno));
net->last_errno=CR_CONNECTION_ERROR; set_mysql_extended_error(mysql, CR_CONNECTION_ERROR,
strmov(net->sqlstate, unknown_sqlstate); unknown_sqlstate,
my_snprintf(net->last_error,sizeof(net->last_error)-1, ER(CR_CONNECTION_ERROR),
ER(net->last_errno),unix_socket,socket_errno); unix_socket, socket_errno);
goto error; goto error;
} }
mysql->options.protocol=MYSQL_PROTOCOL_SOCKET; mysql->options.protocol=MYSQL_PROTOCOL_SOCKET;
...@@ -1986,10 +1981,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -1986,10 +1981,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
#endif #endif
if (sock == SOCKET_ERROR) if (sock == SOCKET_ERROR)
{ {
net->last_errno=CR_IPSOCK_ERROR; set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
strmov(net->sqlstate, unknown_sqlstate); ER(CR_IPSOCK_ERROR), socket_errno);
my_snprintf(net->last_error,sizeof(net->last_error)-1,
ER(net->last_errno),socket_errno);
goto error; goto error;
} }
net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ); net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ);
...@@ -2014,10 +2007,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -2014,10 +2007,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
if (!hp) if (!hp)
{ {
my_gethostbyname_r_free(); my_gethostbyname_r_free();
net->last_errno=CR_UNKNOWN_HOST; set_mysql_extended_error(mysql, CR_UNKNOWN_HOST, unknown_sqlstate,
strmov(net->sqlstate, unknown_sqlstate); ER(CR_UNKNOWN_HOST), host, tmp_errno);
my_snprintf(net->last_error, sizeof(net->last_error)-1,
ER(CR_UNKNOWN_HOST), host, tmp_errno);
goto error; goto error;
} }
memcpy(&sock_addr.sin_addr, hp->h_addr, memcpy(&sock_addr.sin_addr, hp->h_addr,
...@@ -2030,10 +2021,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -2030,10 +2021,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
{ {
DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno, DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno,
host)); host));
net->last_errno= CR_CONN_HOST_ERROR; set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
strmov(net->sqlstate, unknown_sqlstate); ER(CR_CONN_HOST_ERROR), host, socket_errno);
my_snprintf(net->last_error, sizeof(net->last_error)-1,
ER(CR_CONN_HOST_ERROR), host, socket_errno);
goto error; goto error;
} }
} }
...@@ -2097,11 +2086,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -2097,11 +2086,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
PROTOCOL_VERSION, mysql->protocol_version)); PROTOCOL_VERSION, mysql->protocol_version));
if (mysql->protocol_version != PROTOCOL_VERSION) if (mysql->protocol_version != PROTOCOL_VERSION)
{ {
strmov(net->sqlstate, unknown_sqlstate); set_mysql_extended_error(mysql, CR_VERSION_ERROR, unknown_sqlstate,
net->last_errno= CR_VERSION_ERROR; ER(CR_VERSION_ERROR), mysql->protocol_version,
my_snprintf(net->last_error, sizeof(net->last_error)-1, PROTOCOL_VERSION);
ER(CR_VERSION_ERROR), mysql->protocol_version,
PROTOCOL_VERSION);
goto error; goto error;
} }
end=strend((char*) net->read_pos+1); end=strend((char*) net->read_pos+1);
...@@ -2625,7 +2612,7 @@ void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)), ...@@ -2625,7 +2612,7 @@ void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)),
for (; element; element= element->next) for (; element; element= element->next)
{ {
MYSQL_STMT *stmt= (MYSQL_STMT *) element->data; MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
set_stmt_errmsg(stmt, buff, CR_STMT_CLOSED, unknown_sqlstate); set_stmt_error(stmt, CR_STMT_CLOSED, unknown_sqlstate, buff);
stmt->mysql= 0; stmt->mysql= 0;
/* No need to call list_delete for statement here */ /* No need to call list_delete for statement here */
} }
...@@ -3142,11 +3129,8 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *cs_name) ...@@ -3142,11 +3129,8 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *cs_name)
{ {
char cs_dir_name[FN_REFLEN]; char cs_dir_name[FN_REFLEN];
get_charsets_dir(cs_dir_name); get_charsets_dir(cs_dir_name);
mysql->net.last_errno= CR_CANT_READ_CHARSET; set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
strmov(mysql->net.sqlstate, unknown_sqlstate); ER(CR_CANT_READ_CHARSET), cs_name, cs_dir_name);
my_snprintf(mysql->net.last_error, sizeof(mysql->net.last_error) - 1,
ER(mysql->net.last_errno), cs_name, cs_dir_name);
} }
charsets_dir= save_csdir; charsets_dir= save_csdir;
return mysql->net.last_errno; return mysql->net.last_errno;
......
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