From cbff55a59d141d3538a792f9bc072b1892ed8b8f Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Fri, 18 Jul 2003 16:26:35 +0500 Subject: [PATCH] SCRUM Including client code into embedded library fixes --- libmysql/libmysql.c | 2 +- libmysqld/lib_sql.cc | 3 +++ libmysqld/libmysqld.c | 12 +++++++++--- sql-common/client.c | 25 +++++-------------------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 4051ed15db5..a90fb2f1205 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3388,7 +3388,7 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) mysql= stmt->mysql->last_used_con; int4store(buff, stmt->stmt_id); /* Send stmt id to server */ - if (advanced_command(mysql, COM_RESET_STMT,buff,MYSQL_STMT_HEADER,0,0,1)) + if ((*mysql->methods->advanced_command)(mysql, COM_RESET_STMT,buff,MYSQL_STMT_HEADER,0,0,1)) { set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, mysql->net.sqlstate); diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 73d5ca72654..f7b69b51d46 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -38,6 +38,7 @@ static char inited, org_my_init_done; C_MODE_START #include #include "errmsg.h" +#include static int check_connections1(THD * thd); static int check_connections2(THD * thd); @@ -66,8 +67,10 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, /* Clear result variables */ thd->clear_error(); mysql->affected_rows= ~(my_ulonglong) 0; + mysql->field_count= 0; thd->store_globals(); // Fix if more than one connect + free_old_query(mysql); result= dispatch_command(command, thd, (char *) arg, arg_length + 1); if (!skip_check) diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index 0a096a88889..b6278ab3c0b 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -72,6 +72,8 @@ cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket,ulong client_flag); +void STDCALL cli_mysql_close(MYSQL *mysql); + #ifdef HAVE_GETPWUID struct passwd *getpwuid(uid_t); char* getlogin(void); @@ -166,14 +168,12 @@ static inline int mysql_init_charset(MYSQL *mysql) ** before calling mysql_real_connect ! */ -static void STDCALL emb_mysql_close(MYSQL *mysql); static my_bool STDCALL emb_mysql_read_query_result(MYSQL *mysql); static MYSQL_RES * STDCALL emb_mysql_store_result(MYSQL *mysql); static MYSQL_RES * STDCALL emb_mysql_use_result(MYSQL *mysql); static MYSQL_METHODS embedded_methods= { - emb_mysql_close, emb_mysql_read_query_result, emb_advanced_command, emb_mysql_store_result, @@ -276,9 +276,15 @@ error: ** If handle is alloced by mysql connect free it. *************************************************************************/ -static void STDCALL emb_mysql_close(MYSQL *mysql) +void STDCALL mysql_close(MYSQL *mysql) { DBUG_ENTER("mysql_close"); + if (mysql->methods != &embedded_methods) + { + cli_mysql_close(mysql); + DBUG_VOID_RETURN; + } + if (mysql) /* Some simple safety */ { my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR)); diff --git a/sql-common/client.c b/sql-common/client.c index ea0d079511f..7c0de2dba73 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -48,12 +48,14 @@ #endif #define CLI_MYSQL_REAL_CONNECT cli_mysql_real_connect +#define CLI_MYSQL_CLOSE cli_mysql_close #undef net_flush my_bool net_flush(NET *net); #else /*EMBEDDED_LIBRARY*/ #define CLI_MYSQL_REAL_CONNECT mysql_real_connect +#define CLI_MYSQL_CLOSE mysql_close #endif /*EMBEDDED_LIBRARY*/ #if !defined(MYSQL_SERVER) && (defined(__WIN__) || defined(_WIN32) || defined(_WIN64)) @@ -965,26 +967,11 @@ void mysql_read_default_options(struct st_mysql_options *options, void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count) { - ulong *prev_length; - byte *start=0; MYSQL_ROW end; - - prev_length=0; /* Keep gcc happy */ - for (end=column + field_count + 1 ; column != end ; column++, to++) - { - if (!*column) - { - *to= 0; /* Null */ - continue; - } - if (start) /* Found end of prev string */ - *prev_length= (ulong) (*column-start-1); - start= *column; - prev_length= to; - } + for (end=column + field_count; column != end ; column++, to++) + *to= *column ? strlen(*column) : 0; } - /*************************************************************************** Change field rows to field structs ***************************************************************************/ @@ -1422,14 +1409,12 @@ error: before calling mysql_real_connect ! */ -static void STDCALL cli_mysql_close(MYSQL *mysql); static my_bool STDCALL cli_mysql_read_query_result(MYSQL *mysql); static MYSQL_RES * STDCALL cli_mysql_store_result(MYSQL *mysql); static MYSQL_RES * STDCALL cli_mysql_use_result(MYSQL *mysql); static MYSQL_METHODS client_methods= { - cli_mysql_close, cli_mysql_read_query_result, cli_advanced_command, cli_mysql_store_result, @@ -2140,7 +2125,7 @@ static void mysql_close_free(MYSQL *mysql) } -static void STDCALL cli_mysql_close(MYSQL *mysql) +void STDCALL CLI_MYSQL_CLOSE(MYSQL *mysql) { DBUG_ENTER("mysql_close"); if (mysql) /* Some simple safety */