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

ChangeSet@stripped, 2007-10-31 17:16:53+03:00, kostja@bodhi.(none) +4 -0
  Cleanup: use helper functions to set an error in MYSQL or MYSQL_STMT.
  No functionality added or changed.
  This is a pre-requisite for the fix for Bug#12713 Error in a stored 
  function called from a SELECT doesn't cause ROLLBACK of statem
  
  Address post-review comments.

  include/sql_common.h@stripped, 2007-10-31 17:16:51+03:00, kostja@bodhi.(none) +4 -2
    Declare auxiliary functions to manipulate mysql.net.last_er* and 
    mysql_stmt.last_er*

  libmysql/libmysql.c@stripped, 2007-10-31 17:16:51+03:00, kostja@bodhi.(none) +66 -86
    Use helper functions to set an error in MYSQL or MYSQL_STMT

  libmysqld/lib_sql.cc@stripped, 2007-10-31 17:16:51+03:00, kostja@bodhi.(none) +8 -14
    Use helper functions to set an error in MYSQL or MYSQL_STMT

  sql-common/client.c@stripped, 2007-10-31 17:16:51+03:00, kostja@bodhi.(none) +66 -82
    Use helper functions to set an error in MYSQL or MYSQL_STMT

diff -Nrup a/include/sql_common.h b/include/sql_common.h
--- a/include/sql_common.h	2007-05-10 13:59:24 +04:00
+++ b/include/sql_common.h	2007-10-31 17:16:51 +03:00
@@ -36,8 +36,10 @@ cli_advanced_command(MYSQL *mysql, enum 
 		     const unsigned char *arg, ulong arg_length,
                      my_bool skip_check, MYSQL_STMT *stmt);
 unsigned long cli_safe_read(MYSQL *mysql);
-void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode,
-		     const char *sqlstate);
+void net_clear_error(NET *net);
+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);
 #ifdef	__cplusplus
 }
diff -Nrup a/libmysql/libmysql.c b/libmysql/libmysql.c
--- a/libmysql/libmysql.c	2007-10-23 19:10:26 +04:00
+++ b/libmysql/libmysql.c	2007-10-31 17:16:51 +03:00
@@ -686,9 +686,7 @@ int cli_read_change_user_result(MYSQL *m
     if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) ||
         net_flush(net))
     {
-      net->last_errno= CR_SERVER_LOST;
-      strmov(net->sqlstate, unknown_sqlstate);
-      strmov(net->last_error,ER(net->last_errno));
+      set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
       return 1;
     }
     /* Read what server thinks about out new auth message report */
@@ -860,8 +858,7 @@ my_bool handle_local_infile(MYSQL *mysql
   /* copy filename into local memory and allocate read buffer */
   if (!(buf=my_malloc(packet_length, MYF(0))))
   {
-    strmov(net->sqlstate, unknown_sqlstate);
-    strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY));
+    set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
     DBUG_RETURN(1);
   }
 
@@ -887,9 +884,7 @@ my_bool handle_local_infile(MYSQL *mysql
     {
       DBUG_PRINT("error",
 		 ("Lost connection to MySQL server during LOAD DATA of local file"));
-      strmov(net->sqlstate, unknown_sqlstate);
-      net->last_errno=CR_SERVER_LOST;
-      strmov(net->last_error,ER(net->last_errno));
+      set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
       goto err;
     }
   }
@@ -897,9 +892,7 @@ my_bool handle_local_infile(MYSQL *mysql
   /* Send empty packet to mark end of file */
   if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
   {
-    strmov(net->sqlstate, unknown_sqlstate);
-    net->last_errno=CR_SERVER_LOST;
-    sprintf(net->last_error,ER(net->last_errno),errno);
+    set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
     goto err;
   }
 
@@ -1400,9 +1393,7 @@ const char *cli_read_statistics(MYSQL *m
   mysql->net.read_pos[mysql->packet_length]=0;	/* End of stat string */
   if (!mysql->net.read_pos[0])
   {
-    strmov(mysql->net.sqlstate, unknown_sqlstate);
-    mysql->net.last_errno=CR_WRONG_HOST_INFO;
-    strmov(mysql->net.last_error, ER(mysql->net.last_errno));
+    set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
     return mysql->net.last_error;
   }
   return (char*) mysql->net.read_pos;
@@ -1848,24 +1839,17 @@ static my_bool my_realloc_str(NET *net, 
   if (buf_length + length > net->max_packet)
   {
     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;
   }
   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)
 {
   if (stmt->last_errno)
@@ -1876,18 +1860,21 @@ static void stmt_clear_error(MYSQL_STMT 
   }
 }
 
-/*
+/**
   Set statement error code, sqlstate, and error message
   from given errcode and sqlstate.
 */
 
-static void set_stmt_error(MYSQL_STMT * stmt, int errcode,
-                           const char *sqlstate)
+void set_stmt_error(MYSQL_STMT * stmt, int errcode,
+                    const char *sqlstate, const char *err)
 {
   DBUG_ENTER("set_stmt_error");
   DBUG_PRINT("enter", ("error: %d '%s'", errcode, ER(errcode)));
   DBUG_ASSERT(stmt != 0);
 
+  if (err == 0)
+    err= ER(errcode);
+
   stmt->last_errno= errcode;
   strmov(stmt->last_error, ER(errcode));
   strmov(stmt->sqlstate, sqlstate);
@@ -1896,21 +1883,24 @@ static void set_stmt_error(MYSQL_STMT * 
 }
 
 
-/*
-  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,
-                     const char *sqlstate)
+void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
 {
   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);
 
-  stmt->last_errno= errcode;
-  if (err && err[0])
-    strmov(stmt->last_error, err);
-  strmov(stmt->sqlstate, sqlstate);
+  stmt->last_errno= net->last_errno;
+  if (net->last_error && net->last_error[0])
+    strmov(stmt->last_error, net->last_error);
+  strmov(stmt->sqlstate, net->sqlstate);
 
   DBUG_VOID_RETURN;
 }
@@ -2085,7 +2075,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, con
   if (!mysql)
   {
     /* 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);
   }
 
@@ -2123,23 +2113,20 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, con
     stmt->state= MYSQL_STMT_INIT_DONE;
     if (stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt))
     {
-      set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
-                      mysql->net.sqlstate);
+      set_stmt_errmsg(stmt, &mysql->net);
       DBUG_RETURN(1);
     }
   }
 
   if (stmt_command(mysql, COM_STMT_PREPARE, (const uchar*) query, length, stmt))
   {
-    set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
-                    mysql->net.sqlstate);
+    set_stmt_errmsg(stmt, &mysql->net);
     DBUG_RETURN(1);
   }
 
   if ((*mysql->methods->read_prepare_result)(mysql, stmt))
   {
-    set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
-                    mysql->net.sqlstate);
+    set_stmt_errmsg(stmt, &mysql->net);
     DBUG_RETURN(1);
   }
 
@@ -2154,7 +2141,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, con
                                                 (stmt->param_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);
   }
   stmt->bind= stmt->params + stmt->param_count;
@@ -2284,7 +2271,7 @@ mysql_stmt_result_metadata(MYSQL_STMT *s
   if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result),
                                       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);
   }
 
@@ -2517,7 +2504,7 @@ static my_bool store_param(MYSQL_STMT *s
     */
     if ((my_realloc_str(net, *param->length)))
     {
-      set_stmt_error(stmt, net->last_errno, unknown_sqlstate);
+      set_stmt_errmsg(stmt, net);
       DBUG_RETURN(1);
     }
     (*param->store_param_func)(net, param);
@@ -2554,7 +2541,7 @@ static my_bool execute(MYSQL_STMT *stmt,
   stmt->insert_id= mysql->insert_id;
   if (res)
   {
-    set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+    set_stmt_errmsg(stmt, net);
     DBUG_RETURN(1);
   }
   DBUG_RETURN(0);
@@ -2577,13 +2564,13 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
 
     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);
     }
     if (mysql->status != MYSQL_STATUS_READY ||
         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);
     }
 
@@ -2592,7 +2579,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
     null_count= (stmt->param_count+7) /8;
     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);
     }
     bzero((char*) net->write_pos, null_count);
@@ -2605,7 +2592,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
     {
       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);
       }
       /*
@@ -2628,7 +2615,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
     /* TODO: Look into avoding the following memdup */
     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);
     }
     result= execute(stmt, param_data, length);
@@ -2692,20 +2679,19 @@ static int stmt_read_row_unbuffered(MYSQ
   */
   if (!mysql)
   {
-    set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+    set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
     return 1;
   }
   if (mysql->status != MYSQL_STATUS_GET_RESULT)
   {
     set_stmt_error(stmt, stmt->unbuffered_fetch_cancelled ?
                    CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC,
-                   unknown_sqlstate);
+                   unknown_sqlstate, NULL);
     goto error;
   }
   if ((*mysql->methods->unbuffered_fetch)(mysql, (char**) row))
   {
-    set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
-                    mysql->net.sqlstate);
+    set_stmt_errmsg(stmt, &mysql->net);
     /*
       If there was an error, there are no more pending rows:
       reset statement status to not hang up in following
@@ -2766,7 +2752,7 @@ stmt_read_row_from_cursor(MYSQL_STMT *st
                                             buff, sizeof(buff), (uchar*) 0, 0,
                                             1, NULL))
     {
-      set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+      set_stmt_errmsg(stmt, net);
       return 1;
     }
     if ((*mysql->methods->read_rows_from_cursor)(stmt))
@@ -2797,7 +2783,7 @@ static int
 stmt_read_row_no_result_set(MYSQL_STMT *stmt  __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;
 }
 
@@ -2847,7 +2833,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQ
   }
   return FALSE;
 err_not_implemented:
-  set_stmt_error(stmt, CR_NOT_IMPLEMENTED, unknown_sqlstate);
+  set_stmt_error(stmt, CR_NOT_IMPLEMENTED, unknown_sqlstate, NULL);
   return TRUE;
 }
 
@@ -3232,7 +3218,7 @@ my_bool STDCALL mysql_stmt_bind_param(MY
   {
     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(0);
@@ -3397,7 +3383,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *st
   */
   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);
   }
 
@@ -3433,8 +3419,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *st
                                             buff, sizeof(buff), (uchar*) data,
                                             length, 1, NULL))
     {
-      set_stmt_errmsg(stmt, mysql->net.last_error,
-		      mysql->net.last_errno, mysql->net.sqlstate);
+      set_stmt_errmsg(stmt, &mysql->net);
       DBUG_RETURN(1);
     }
   }
@@ -3903,7 +3888,8 @@ static void fetch_float_with_conversion(
       if (field->flags & ZEROFILL_FLAG && length < field->length &&
           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');
         length= field->length;
       }
@@ -4502,7 +4488,7 @@ my_bool STDCALL mysql_stmt_bind_result(M
   {
     int errorcode= (int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE ?
                    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);
   }
 
@@ -4682,12 +4668,12 @@ int STDCALL mysql_stmt_fetch_column(MYSQ
 
   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;
   }
   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);
   }
 
@@ -4733,7 +4719,7 @@ int cli_read_binary_rows(MYSQL_STMT *stm
 
   if (!mysql)
   {
-    set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+    set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
     DBUG_RETURN(1);
   }
 
@@ -4748,7 +4734,7 @@ int cli_read_binary_rows(MYSQL_STMT *stm
       if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc,
                                           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;
       }
       cur->data= (MYSQL_ROW) (cur+1);
@@ -4769,7 +4755,7 @@ int cli_read_binary_rows(MYSQL_STMT *stm
       DBUG_RETURN(0);
     }
   }
-  set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+  set_stmt_errmsg(stmt, net);
 
 err:
   DBUG_RETURN(1);
@@ -4836,7 +4822,7 @@ int STDCALL mysql_stmt_store_result(MYSQ
 
   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);
   }
 
@@ -4856,13 +4842,13 @@ int STDCALL mysql_stmt_store_result(MYSQ
     if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff),
                              (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);
     }
   }
   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);
   }
 
@@ -5043,8 +5029,7 @@ static my_bool reset_stmt_handle(MYSQL_S
         if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET, buff,
                                                 sizeof(buff), 0, 0, 0, NULL))
         {
-          set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
-                          mysql->net.sqlstate);
+          set_stmt_errmsg(stmt, &mysql->net);
           stmt->state= MYSQL_STMT_INIT_DONE;
           return 1;
         }
@@ -5117,8 +5102,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_S
       int4store(buff, stmt->stmt_id);
       if ((rc= stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt)))
       {
-        set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
-                        mysql->net.sqlstate);
+        set_stmt_errmsg(stmt, &mysql->net);
       }
     }
   }
@@ -5139,7 +5123,7 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_S
   if (!stmt->mysql)
   {
     /* 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);
   }
   /* Reset the client and server sides of the prepared statement */
@@ -5243,15 +5227,11 @@ int STDCALL mysql_next_result(MYSQL *mys
 
   if (mysql->status != MYSQL_STATUS_READY)
   {
-    strmov(mysql->net.sqlstate, unknown_sqlstate);
-    strmov(mysql->net.last_error,
-	   ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
+    set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
     DBUG_RETURN(1);
   }
 
-  mysql->net.last_error[0]= 0;
-  mysql->net.last_errno= 0;
-  strmov(mysql->net.sqlstate, not_error_sqlstate);
+  net_clear_error(&mysql->net);
   mysql->affected_rows= ~(my_ulonglong) 0;
 
   if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
diff -Nrup a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
--- a/libmysqld/lib_sql.cc	2007-10-10 04:12:09 +04:00
+++ b/libmysqld/lib_sql.cc	2007-10-31 17:16:51 +03:00
@@ -81,8 +81,7 @@ emb_advanced_command(MYSQL *mysql, enum 
   /* Check that we are calling the client functions in right order */
   if (mysql->status != MYSQL_STATUS_READY)
   {
-    strmov(net->last_error,
-	   ER(net->last_errno=CR_COMMANDS_OUT_OF_SYNC));
+    set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
     return 1;
   }
 
@@ -90,7 +89,7 @@ emb_advanced_command(MYSQL *mysql, enum 
   thd->clear_error();
   mysql->affected_rows= ~(my_ulonglong) 0;
   mysql->field_count= 0;
-  net->last_errno= 0;
+  net_clear_error(net);
   thd->current_stmt= stmt;
 
   thd->store_globals();				// Fix if more than one connect
@@ -245,8 +244,7 @@ static my_bool emb_read_query_result(MYS
   mysql->fields= res->embedded_info->fields_list;
   mysql->affected_rows= res->embedded_info->affected_rows;
   mysql->insert_id= res->embedded_info->insert_id;
-  mysql->net.last_errno= 0;
-  mysql->net.last_error[0]= 0;
+  net_clear_error(&mysql->net);
   mysql->info= 0;
 
   if (res->embedded_info->info[0])
@@ -288,7 +286,7 @@ static int emb_stmt_execute(MYSQL_STMT *
   if (res)
   {
     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(0);
@@ -299,14 +297,12 @@ int emb_read_binary_rows(MYSQL_STMT *stm
   MYSQL_DATA *data;
   if (!(data= emb_read_rows(stmt->mysql, 0, 0)))
   {
-    set_stmt_errmsg(stmt, stmt->mysql->net.last_error,
-                    stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate);
+    set_stmt_errmsg(stmt, &stmt->mysql->net);
     return 1;
   }
   stmt->result= *data;
   my_free((char *) data, MYF(0));
-  set_stmt_errmsg(stmt, stmt->mysql->net.last_error,
-                  stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate);
+  set_stmt_errmsg(stmt, &stmt->mysql->net);
   return 0;
 }
 
@@ -320,16 +316,14 @@ int emb_read_rows_from_cursor(MYSQL_STMT
   if (res->embedded_info->last_errno)
   {
     embedded_get_error(mysql, res);
-    set_stmt_errmsg(stmt, mysql->net.last_error,
-                    mysql->net.last_errno, mysql->net.sqlstate);
+    set_stmt_errmsg(stmt, &mysql->net);
     return 1;
   }
 
   thd->cur_data= res;
   mysql->warning_count= res->embedded_info->warning_count;
   mysql->server_status= res->embedded_info->server_status;
-  mysql->net.last_errno= 0;
-  mysql->net.last_error[0]= 0;
+  net_clear_error(&mysql->net);
 
   return emb_read_binary_rows(stmt);
 }
diff -Nrup a/sql-common/client.c b/sql-common/client.c
--- a/sql-common/client.c	2007-08-13 17:11:14 +04:00
+++ b/sql-common/client.c	2007-10-31 17:16:51 +03:00
@@ -312,42 +312,34 @@ HANDLE create_named_pipe(NET *net, uint 
       break;
     if (GetLastError() != ERROR_PIPE_BUSY)
     {
-      net->last_errno=CR_NAMEDPIPEOPEN_ERROR;
-      strmov(net->sqlstate, unknown_sqlstate);
-      my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                  ER(net->last_errno), host, unix_socket,
-	          (ulong) GetLastError());
+      set_mysql_extended_error(mysql, CR_NAMEDPIPEOPEN_ERROR,
+                               unknown_sqlstate, ER(CR_NAMEDPIPEOPEN_ERROR),
+                               host, unix_socket, (ulong) GetLastError());
       return INVALID_HANDLE_VALUE;
     }
     /* wait for for an other instance */
     if (! WaitNamedPipe(pipe_name, connect_timeout*1000) )
     {
-      net->last_errno=CR_NAMEDPIPEWAIT_ERROR;
-      strmov(net->sqlstate, unknown_sqlstate);
-      my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                  ER(net->last_errno), host, unix_socket,
-	          (ulong) GetLastError());
+      set_mysql_extended_error(mysql, CR_NAMEDPIPEWAIT_ERROR, unknown_sqlstate,
+                               ER(CR_NAMEDPIPEWAIT_ERROR),
+                               host, unix_socket, (ulong) GetLastError());
       return INVALID_HANDLE_VALUE;
     }
   }
   if (hPipe == INVALID_HANDLE_VALUE)
   {
-    net->last_errno=CR_NAMEDPIPEOPEN_ERROR;
-    strmov(net->sqlstate, unknown_sqlstate);
-    my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                ER(net->last_errno), host, unix_socket,
-	        (ulong) GetLastError());
+    set_mysql_extended_error(mysql, CR_NAMEDPIPEOPEN_ERROR, unknown_sqlstate,
+                             ER(CR_NAMEDPIPEOPEN_ERROR), host, unix_socket,
+                             (ulong) GetLastError());
     return INVALID_HANDLE_VALUE;
   }
   dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
   if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) )
   {
     CloseHandle( hPipe );
-    net->last_errno=CR_NAMEDPIPESETSTATE_ERROR;
-    strmov(net->sqlstate, unknown_sqlstate);
-    my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                ER(net->last_errno),host, unix_socket,
-	        (ulong) GetLastError());
+    set_mysql_extended_error(mysql, CR_NAMEDPIPESETSTATE_ERROR,
+                             unknown_sqlstate, ER(CR_NAMEDPIPESETSTATE_ERROR),
+                             host, unix_socket, (ulong) GetLastError());
     return INVALID_HANDLE_VALUE;
   }
   *arg_host=host ; *arg_unix_socket=unix_socket;	/* connect arg */
@@ -566,14 +558,12 @@ err:
     CloseHandle(handle_connect_file_map);
   if (error_allow)
   {
-    net->last_errno=error_allow;
-    strmov(net->sqlstate, unknown_sqlstate);
     if (error_allow == CR_SHARED_MEMORY_EVENT_ERROR)
-      my_snprintf(net->last_error,sizeof(net->last_error)-1,
-                  ER(net->last_errno),suffix_pos,error_code);
+      set_mysql_extended_error(mysql, error_allow, unknown_sqlstate,
+                               ER(error_allow), suffix_pos, error_code);
     else
-      my_snprintf(net->last_error,sizeof(net->last_error)-1,
-                  ER(net->last_errno),error_code);
+      set_mysql_extended_error(mysql, error_allow, unknown_sqlstate,
+                               ER(error_allow), error_code);
     return(INVALID_HANDLE_VALUE);
   }
   return(handle_map);
@@ -683,10 +673,8 @@ cli_advanced_command(MYSQL *mysql, enum 
     DBUG_RETURN(1);
   }
 
-  net->last_error[0]=0;
-  net->last_errno= 0;
-  strmov(net->sqlstate, not_error_sqlstate);
-  mysql->net.report_error=0;
+  net_clear_error(net);
+  net->report_error=0;
   mysql->info=0;
   mysql->affected_rows= ~(my_ulonglong) 0;
   /*
@@ -703,8 +691,7 @@ cli_advanced_command(MYSQL *mysql, enum 
 			socket_errno));
     if (net->last_errno == ER_NET_PACKET_TOO_LARGE)
     {
-      net->last_errno=CR_NET_PACKET_TOO_LARGE;
-      strmov(net->last_error,ER(net->last_errno));
+      set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
       goto end;
     }
     end_server(mysql);
@@ -713,8 +700,7 @@ cli_advanced_command(MYSQL *mysql, enum 
     if (net_write_command(net,(uchar) command, header, header_length,
 			  arg, arg_length))
     {
-      net->last_errno=CR_SERVER_GONE_ERROR;
-      strmov(net->last_error,ER(net->last_errno));
+      set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
       goto end;
     }
   }
@@ -760,6 +746,19 @@ void set_mysql_error(MYSQL *mysql, int e
   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,
                                      const char *sqlstate,
@@ -846,9 +845,8 @@ static int check_license(MYSQL *mysql)
   {
     if (net->last_errno == ER_UNKNOWN_SYSTEM_VARIABLE)
     {
-      net->last_errno= CR_WRONG_LICENSE;
-      my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                  ER(net->last_errno), required_license);
+      set_mysql_extended_error(mysql, CR_WRONG_LICENSE, unknown_sqlstate,
+                               ER(CR_WRONG_LICENSE), required_license);
     }
     return 1;
   }
@@ -864,9 +862,8 @@ static int check_license(MYSQL *mysql)
       (!row || !row[0] ||
        strncmp(row[0], required_license, sizeof(required_license))))
   {
-    net->last_errno= CR_WRONG_LICENSE;
-    my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                ER(net->last_errno), required_license);
+    set_mysql_extended_error(mysql, CR_WRONG_LICENSE, unknown_sqlstate,
+                             ER(CR_WRONG_LICENSE), required_license);
   }
   mysql_free_result(res);
   return net->last_errno;
@@ -1761,24 +1758,22 @@ int mysql_init_character_set(MYSQL *mysq
     }
     charsets_dir= save;
   }
-  
+
   if (!mysql->charset)
   {
-    net->last_errno=CR_CANT_READ_CHARSET;
-    strmov(net->sqlstate, unknown_sqlstate);
     if (mysql->options.charset_dir)
-      my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                  ER(net->last_errno),
-                  mysql->options.charset_name,
-                  mysql->options.charset_dir);
+      set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
+                               ER(CR_CANT_READ_CHARSET),
+                               mysql->options.charset_name,
+                               mysql->options.charset_dir);
     else
     {
       char cs_dir_name[FN_REFLEN];
       get_charsets_dir(cs_dir_name);
-      my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                  ER(net->last_errno),
-                  mysql->options.charset_name,
-                  cs_dir_name);
+      set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
+                               ER(CR_CANT_READ_CHARSET),
+                               mysql->options.charset_name,
+                               cs_dir_name);
     }
     return 1;
   }
@@ -1910,10 +1905,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
     if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
     {
-      net->last_errno=CR_SOCKET_CREATE_ERROR;
-      strmov(net->sqlstate, unknown_sqlstate);
-      my_snprintf(net->last_error,sizeof(net->last_error)-1,
-                  ER(net->last_errno),socket_errno);
+      set_mysql_extended_error(mysql, CR_SOCKET_CREATE_ERROR,
+                               unknown_sqlstate,
+                               ER(CR_SOCKET_CREATE_ERROR),
+                               socket_errno);
       goto error;
     }
     net->vio= vio_new(sock, VIO_TYPE_SOCKET,
@@ -1926,10 +1921,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     {
       DBUG_PRINT("error",("Got error %d on connect to local server",
 			  socket_errno));
-      net->last_errno=CR_CONNECTION_ERROR;
-      strmov(net->sqlstate, unknown_sqlstate);
-      my_snprintf(net->last_error,sizeof(net->last_error)-1,
-                  ER(net->last_errno),unix_socket,socket_errno);
+      set_mysql_extended_error(mysql, CR_CONNECTION_ERROR,
+                               unknown_sqlstate,
+                               ER(CR_CONNECTION_ERROR),
+                               unix_socket, socket_errno);
       goto error;
     }
     mysql->options.protocol=MYSQL_PROTOCOL_SOCKET;
@@ -1986,10 +1981,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
 #endif
     if (sock == SOCKET_ERROR)
     {
-      net->last_errno=CR_IPSOCK_ERROR;
-      strmov(net->sqlstate, unknown_sqlstate);
-      my_snprintf(net->last_error,sizeof(net->last_error)-1,
-                  ER(net->last_errno),socket_errno);
+      set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
+                               ER(CR_IPSOCK_ERROR), socket_errno);
       goto error;
     }
     net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ);
@@ -2014,10 +2007,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       if (!hp)
       {
 	my_gethostbyname_r_free();
-	net->last_errno=CR_UNKNOWN_HOST;
-	strmov(net->sqlstate, unknown_sqlstate);
-	my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                    ER(CR_UNKNOWN_HOST), host, tmp_errno);
+        set_mysql_extended_error(mysql, CR_UNKNOWN_HOST, unknown_sqlstate,
+                                 ER(CR_UNKNOWN_HOST), host, tmp_errno);
 	goto error;
       }
       memcpy(&sock_addr.sin_addr, hp->h_addr,
@@ -2030,10 +2021,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     {
       DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno,
 			  host));
-      net->last_errno= CR_CONN_HOST_ERROR;
-      strmov(net->sqlstate, unknown_sqlstate);
-      my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                  ER(CR_CONN_HOST_ERROR), host, socket_errno);
+      set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
+                               ER(CR_CONN_HOST_ERROR), host, socket_errno);
       goto error;
     }
   }
@@ -2097,11 +2086,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
 		     PROTOCOL_VERSION, mysql->protocol_version));
   if (mysql->protocol_version != PROTOCOL_VERSION)
   {
-    strmov(net->sqlstate, unknown_sqlstate);
-    net->last_errno= CR_VERSION_ERROR;
-    my_snprintf(net->last_error, sizeof(net->last_error)-1,
-                ER(CR_VERSION_ERROR), mysql->protocol_version,
-	        PROTOCOL_VERSION);
+    set_mysql_extended_error(mysql, CR_VERSION_ERROR, unknown_sqlstate,
+                             ER(CR_VERSION_ERROR), mysql->protocol_version,
+                             PROTOCOL_VERSION);
     goto error;
   }
   end=strend((char*) net->read_pos+1);
@@ -2625,7 +2612,7 @@ void mysql_detach_stmt_list(LIST **stmt_
   for (; element; element= element->next)
   {
     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;
     /* No need to call list_delete for statement here */
   }
@@ -3142,11 +3129,8 @@ int STDCALL mysql_set_character_set(MYSQ
   {
     char cs_dir_name[FN_REFLEN];
     get_charsets_dir(cs_dir_name);
-    mysql->net.last_errno= CR_CANT_READ_CHARSET;
-    strmov(mysql->net.sqlstate, unknown_sqlstate);
-    my_snprintf(mysql->net.last_error, sizeof(mysql->net.last_error) - 1,
-		ER(mysql->net.last_errno), cs_name, cs_dir_name);
-
+    set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
+                             ER(CR_CANT_READ_CHARSET), cs_name, cs_dir_name);
   }
   charsets_dir= save_csdir;
   return mysql->net.last_errno;
Thread
bk commit into 5.1 tree (kostja:1.2598) BUG#12713konstantin31 Oct
  • Re: bk commit into 5.1 tree (kostja:1.2598) BUG#12713Alexander Nozdrin31 Oct