From f434b329f58a0ae60b40d0fe41a8cab68162cbaa Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Thu, 11 Sep 2003 09:46:31 +0500 Subject: [PATCH 1/2] SCRUM embedded&client library some fixes: zero at the end of the data added mysql_list_fields became 'virtual' --- include/mysql.h | 11 +++++++---- libmysql/client_settings.h | 2 ++ libmysql/libmysql.c | 2 +- libmysqld/lib_sql.cc | 3 ++- libmysqld/libmysqld.c | 36 +++++++++++++++++++++++++++++++++++- sql-common/client.c | 4 +++- sql/client_settings.h | 2 ++ 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index 2e23a1e2f98..ff00e75687d 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -414,8 +414,6 @@ const char * STDCALL mysql_get_host_info(MYSQL *mysql); unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); -MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, - const char *wild); MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg); @@ -540,6 +538,7 @@ typedef struct st_mysql_stmt #define mysql_read_query_result(mysql) (*(mysql)->methods->read_query_result)(mysql) #define mysql_store_result(mysql) (*(mysql)->methods->store_result)(mysql) #define mysql_use_result(mysql) (*(mysql)->methods->use_result)(mysql) +#define mysql_list_fields(mysql, table, wild) (*(mysql)->methods->list_fields)(mysql, table, wild) typedef struct st_mysql_methods { @@ -549,10 +548,14 @@ typedef struct st_mysql_methods const char *header, unsigned long header_length, const char *arg, - unsigned long arg_length, my_bool skip_check); + unsigned long arg_length, + my_bool skip_check); MYSQL_RES * (STDCALL *store_result)(MYSQL *mysql); MYSQL_RES * (STDCALL *use_result)(MYSQL *mysql); - void (STDCALL *fetch_lengths)(unsigned long *to, MYSQL_ROW column, uint field_count); + void (STDCALL *fetch_lengths)(unsigned long *to, + MYSQL_ROW column, uint field_count); + MYSQL_RES * (STDCALL *list_fields)(MYSQL *mysql, const char *table, + const char *wild); } MYSQL_METHODS; MYSQL_STMT * STDCALL mysql_prepare(MYSQL * mysql, const char *query, diff --git a/libmysql/client_settings.h b/libmysql/client_settings.h index 43f341c7b1c..9cafd7182d0 100644 --- a/libmysql/client_settings.h +++ b/libmysql/client_settings.h @@ -41,3 +41,5 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename); #define reset_sigpipe(mysql) #endif +MYSQL_RES * STDCALL cli_list_fields(MYSQL *mysql, const char *table, const char *wild); + diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 0a9e1114fc5..3058efb83cb 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -974,7 +974,7 @@ mysql_list_tables(MYSQL *mysql, const char *wild) **************************************************************************/ MYSQL_RES * STDCALL -mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) +cli_list_fields(MYSQL *mysql, const char *table, const char *wild) { MYSQL_RES *result; MYSQL_DATA *query; diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index e4631f3d319..00658eaffdd 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -487,11 +487,12 @@ bool Protocol_simple::store_null() bool Protocol::net_store_data(const char *from, uint length) { char *field_buf; - if (!(field_buf=alloc_root(alloc, length + sizeof(uint)))) + if (!(field_buf=alloc_root(alloc, length + sizeof(uint) + 1))) return true; *(uint *)field_buf= length; *next_field= field_buf + sizeof(uint); memcpy(*next_field, from, length); + (*next_field)[length]= 0; if (next_mysql_field->max_length < length) next_mysql_field->max_length=length; ++next_field; diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index 7ac723f3050..f403400812f 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -179,6 +179,39 @@ static void STDCALL emb_fetch_lengths(ulong *to, MYSQL_ROW column, uint field_co *to= *column ? *(uint *)((*column) - sizeof(uint)) : 0; } +/************************************************************************** + List all fields in a table + If wild is given then only the fields matching wild is returned + Instead of this use query: + show fields in 'table' like "wild" +**************************************************************************/ + +static MYSQL_RES * STDCALL +emb_list_fields(MYSQL *mysql, const char *table, const char *wild) +{ + MYSQL_RES *result; + MYSQL_DATA *query; + char buff[257],*end; + DBUG_ENTER("mysql_list_fields"); + DBUG_PRINT("enter",("table: '%s' wild: '%s'",table,wild ? wild : "")); + + LINT_INIT(query); + + end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128); + if (simple_command(mysql,COM_FIELD_LIST,buff,(ulong) (end-buff),1)) + DBUG_RETURN(NULL); + + result= mysql->result; + if (!result) + return 0; + + result->methods= mysql->methods; + result->eof=1; + + DBUG_RETURN(result); +} + + /* ** Note that the mysql argument must be initialized with mysql_init() @@ -195,7 +228,8 @@ static MYSQL_METHODS embedded_methods= emb_advanced_command, emb_mysql_store_result, emb_mysql_use_result, - emb_fetch_lengths + emb_fetch_lengths, + emb_list_fields }; MYSQL * STDCALL diff --git a/sql-common/client.c b/sql-common/client.c index b4d875b8132..6372adb8550 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1406,7 +1406,8 @@ static MYSQL_METHODS client_methods= cli_advanced_command, cli_mysql_store_result, cli_mysql_use_result, - cli_fetch_lengths + cli_fetch_lengths, + cli_list_fields }; MYSQL * STDCALL @@ -1432,6 +1433,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, #ifdef HAVE_SYS_UN_H struct sockaddr_un UNIXaddr; #endif + init_sigpipe_variables DBUG_ENTER("mysql_real_connect"); LINT_INIT(host_info); diff --git a/sql/client_settings.h b/sql/client_settings.h index b357e52ec9d..e31a75bdddd 100644 --- a/sql/client_settings.h +++ b/sql/client_settings.h @@ -32,3 +32,5 @@ #undef HAVE_SMEM #undef _CUSTOMCONFIG_ +#define cli_list_fields NULL + From 9de77cc983e9456fb2d2fec6a02b77fe3d7e4d14 Mon Sep 17 00:00:00 2001 From: "ram@mysql.r18.ru" <> Date: Thu, 11 Sep 2003 13:50:18 +0500 Subject: [PATCH 2/2] Fix for the bug #1200: Can't start MySQL if bind-address set to hostname that starts with a number. --- sql/mysqld.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 80096e5d5e6..2d82454ad6d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5163,11 +5163,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), my_use_symdir=0; break; case (int) OPT_BIND_ADDRESS: - if (argument && my_isdigit(mysqld_charset, argument[0])) - { - my_bind_addr = (ulong) inet_addr(argument); - } - else + if (!argument || (my_bind_addr= (ulong) inet_addr(argument)) == INADDR_NONE) { struct hostent *ent; if (argument || argument[0])