diff --git a/include/mysql.h b/include/mysql.h index 2e23a1e2f98fe1c7761079c56e81928e66773129..ff00e75687df2b92790af2c6c3b8bcd7994224d2 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 43f341c7b1c0007e9f20ce8bc96f66d4abae59d5..9cafd7182d057f455337e2e81a05763871346462 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 0a9e1114fc55c0eeeb9811714dd720e152c3cd31..3058efb83cbdd2905d4ef1632af27171321fb3fa 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 e4631f3d319be32f062f10bcd9390c0b6ffb74f7..00658eaffdd6b214fab846ba6d7e3e127ed3c45e 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 7ac723f30506fb336e017ea35c214adc0f7783a1..f403400812fafd481b1c9e8dca22044fd66a7702 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 b4d875b8132c62b0319ea9079c8da370dc5caea4..6372adb85500a645fbff92ce065363a773d63df8 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 b357e52ec9dfa5b780cfcdbc205501e02e832532..e31a75bdddd27183129e875e1c2b269e33e425ca 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 + diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 80096e5d5e6c68acc9604b511d184301706950b1..2d82454ad6d46bf706798add953afc50ae4f1749 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])