diff options
Diffstat (limited to 'libmysqld/libmysqld.c')
-rw-r--r-- | libmysqld/libmysqld.c | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index 05e5ff59b55..56be78e3509 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -79,6 +79,8 @@ struct passwd *getpwuid(uid_t); char* getlogin(void); #endif +extern char server_inited; + #ifdef __WIN__ static my_bool is_NT(void) { @@ -174,11 +176,42 @@ static void STDCALL emb_fetch_lengths(ulong *to, MYSQL_ROW column, uint field_co MYSQL_ROW end; for (end=column + field_count; column != end ; column++,to++) - { - *to= *column ? strlen(*column) : 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() @@ -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 @@ -210,6 +244,15 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, db ? db : "(Null)", user ? user : "(Null)")); +#if defined(EMBEDDED_LIBRARY) || !defined(DBUG_OFF) + if (!server_inited) + { + mysql->net.last_errno=CR_MYSQL_SERVER_INIT_MISSED; + strmov(mysql->net.last_error,ER(mysql->net.last_errno)); + goto error; + } +#endif + if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION || (mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION && host && strcmp(host,LOCAL_HOST))) @@ -297,14 +340,14 @@ error: 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 */ { + if (mysql->methods != &embedded_methods) + { + cli_mysql_close(mysql); + DBUG_VOID_RETURN; + } + my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR)); |