Commit f434b329 authored by hf@deer.(none)'s avatar hf@deer.(none)

SCRUM

embedded&client library
some fixes: zero at the end of the data added
mysql_list_fields became 'virtual'
parent 4f347492
...@@ -414,8 +414,6 @@ const char * STDCALL mysql_get_host_info(MYSQL *mysql); ...@@ -414,8 +414,6 @@ const char * STDCALL mysql_get_host_info(MYSQL *mysql);
unsigned int STDCALL mysql_get_proto_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_dbs(MYSQL *mysql,const char *wild);
MYSQL_RES * STDCALL mysql_list_tables(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); MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
const char *arg); const char *arg);
...@@ -540,6 +538,7 @@ typedef struct st_mysql_stmt ...@@ -540,6 +538,7 @@ typedef struct st_mysql_stmt
#define mysql_read_query_result(mysql) (*(mysql)->methods->read_query_result)(mysql) #define mysql_read_query_result(mysql) (*(mysql)->methods->read_query_result)(mysql)
#define mysql_store_result(mysql) (*(mysql)->methods->store_result)(mysql) #define mysql_store_result(mysql) (*(mysql)->methods->store_result)(mysql)
#define mysql_use_result(mysql) (*(mysql)->methods->use_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 typedef struct st_mysql_methods
{ {
...@@ -549,10 +548,14 @@ typedef struct st_mysql_methods ...@@ -549,10 +548,14 @@ typedef struct st_mysql_methods
const char *header, const char *header,
unsigned long header_length, unsigned long header_length,
const char *arg, 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 *store_result)(MYSQL *mysql);
MYSQL_RES * (STDCALL *use_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_METHODS;
MYSQL_STMT * STDCALL mysql_prepare(MYSQL * mysql, const char *query, MYSQL_STMT * STDCALL mysql_prepare(MYSQL * mysql, const char *query,
......
...@@ -41,3 +41,5 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename); ...@@ -41,3 +41,5 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename);
#define reset_sigpipe(mysql) #define reset_sigpipe(mysql)
#endif #endif
MYSQL_RES * STDCALL cli_list_fields(MYSQL *mysql, const char *table, const char *wild);
...@@ -974,7 +974,7 @@ mysql_list_tables(MYSQL *mysql, const char *wild) ...@@ -974,7 +974,7 @@ mysql_list_tables(MYSQL *mysql, const char *wild)
**************************************************************************/ **************************************************************************/
MYSQL_RES * STDCALL 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_RES *result;
MYSQL_DATA *query; MYSQL_DATA *query;
......
...@@ -487,11 +487,12 @@ bool Protocol_simple::store_null() ...@@ -487,11 +487,12 @@ bool Protocol_simple::store_null()
bool Protocol::net_store_data(const char *from, uint length) bool Protocol::net_store_data(const char *from, uint length)
{ {
char *field_buf; char *field_buf;
if (!(field_buf=alloc_root(alloc, length + sizeof(uint)))) if (!(field_buf=alloc_root(alloc, length + sizeof(uint) + 1)))
return true; return true;
*(uint *)field_buf= length; *(uint *)field_buf= length;
*next_field= field_buf + sizeof(uint); *next_field= field_buf + sizeof(uint);
memcpy(*next_field, from, length); memcpy(*next_field, from, length);
(*next_field)[length]= 0;
if (next_mysql_field->max_length < length) if (next_mysql_field->max_length < length)
next_mysql_field->max_length=length; next_mysql_field->max_length=length;
++next_field; ++next_field;
......
...@@ -179,6 +179,39 @@ static void STDCALL emb_fetch_lengths(ulong *to, MYSQL_ROW column, uint field_co ...@@ -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; *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() ** Note that the mysql argument must be initialized with mysql_init()
...@@ -195,7 +228,8 @@ static MYSQL_METHODS embedded_methods= ...@@ -195,7 +228,8 @@ static MYSQL_METHODS embedded_methods=
emb_advanced_command, emb_advanced_command,
emb_mysql_store_result, emb_mysql_store_result,
emb_mysql_use_result, emb_mysql_use_result,
emb_fetch_lengths emb_fetch_lengths,
emb_list_fields
}; };
MYSQL * STDCALL MYSQL * STDCALL
......
...@@ -1406,7 +1406,8 @@ static MYSQL_METHODS client_methods= ...@@ -1406,7 +1406,8 @@ static MYSQL_METHODS client_methods=
cli_advanced_command, cli_advanced_command,
cli_mysql_store_result, cli_mysql_store_result,
cli_mysql_use_result, cli_mysql_use_result,
cli_fetch_lengths cli_fetch_lengths,
cli_list_fields
}; };
MYSQL * STDCALL MYSQL * STDCALL
...@@ -1432,6 +1433,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -1432,6 +1433,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
#ifdef HAVE_SYS_UN_H #ifdef HAVE_SYS_UN_H
struct sockaddr_un UNIXaddr; struct sockaddr_un UNIXaddr;
#endif #endif
init_sigpipe_variables init_sigpipe_variables
DBUG_ENTER("mysql_real_connect"); DBUG_ENTER("mysql_real_connect");
LINT_INIT(host_info); LINT_INIT(host_info);
......
...@@ -32,3 +32,5 @@ ...@@ -32,3 +32,5 @@
#undef HAVE_SMEM #undef HAVE_SMEM
#undef _CUSTOMCONFIG_ #undef _CUSTOMCONFIG_
#define cli_list_fields NULL
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