16 #include <my_global.h> 
   18 #include <mysqld_error.h> 
   19 #include <my_pthread.h> 
   21 #include <mysys_err.h> 
   29 #include <sql_common.h> 
   30 #include "embedded_priv.h" 
   31 #include "client_settings.h" 
   39 #ifdef HAVE_SYS_SELECT_H 
   40 #include <sys/select.h> 
   47 #define INADDR_NONE     -1 
   50 extern ulong net_buffer_length;
 
   51 extern ulong max_allowed_packet;
 
   54 #define ERRNO WSAGetLastError() 
   59 #define SOCKET_ERROR -1 
   60 #define closesocket(A) close(A) 
   64 struct passwd *getpwuid(uid_t);
 
   69 static my_bool is_NT(
void)
 
   71   char *os=getenv(
"OS");
 
   72   return (os && !strcmp(os, 
"Windows_NT")) ? 1 : 0;
 
   77 int mysql_init_character_set(
MYSQL *mysql);
 
   80 mysql_real_connect(
MYSQL *mysql,
const char *host, 
const char *user,
 
   81                    const char *passwd, 
const char *db,
 
   82                    uint port, 
const char *unix_socket,ulong client_flag)
 
   84   char name_buff[USERNAME_LENGTH + 1];
 
   86   DBUG_ENTER(
"mysql_real_connect");
 
   87   DBUG_PRINT(
"enter",(
"host: %s  db: %s  user: %s (libmysqld)",
 
   88                       host ? host : 
"(Null)",
 
   90                       user ? user : 
"(Null)"));
 
   93   if (mysql->server_version)
 
   95     set_mysql_error(mysql, CR_ALREADY_CONNECTED, unknown_sqlstate);
 
   99   if (!host || !host[0])
 
  100     host= mysql->options.host;
 
  102   if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION ||
 
  103       (mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION &&
 
  104        host && *host && strcmp(host,LOCAL_HOST)))
 
  105     DBUG_RETURN(cli_mysql_real_connect(mysql, host, user, 
 
  107                                        unix_socket, client_flag));
 
  109   mysql->methods= &embedded_methods;
 
  112   if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
 
  114     mysql_read_default_options(&mysql->options,
 
  115                                (mysql->options.my_cnf_file ?
 
  116                                 mysql->options.my_cnf_file : 
"my"),
 
  117                                mysql->options.my_cnf_group);
 
  118     my_free(mysql->options.my_cnf_file);
 
  119     my_free(mysql->options.my_cnf_group);
 
  120     mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
 
  124     db=mysql->options.db;
 
  126   if (!user || !user[0])
 
  127     user=mysql->options.user;
 
  129 #ifndef NO_EMBEDDED_ACCESS_CHECKS 
  132     passwd=mysql->options.password;
 
  133 #if !defined(DONT_USE_MYSQL_PWD) 
  135       passwd=getenv(
"MYSQL_PWD");               
 
  138   mysql->passwd= passwd ? my_strdup(passwd,MYF(0)) : NULL;
 
  140   if (!user || !user[0]) 
  142     read_user_name(name_buff);
 
  154   mysql->user= my_strdup(user, MYF(0));
 
  159   client_flag|=mysql->options.client_flag;
 
  161   client_flag|=CLIENT_CAPABILITIES;
 
  162   if (client_flag & CLIENT_MULTI_STATEMENTS)
 
  163     client_flag|= CLIENT_MULTI_RESULTS;
 
  168   client_flag&= ~(CLIENT_COMPRESS | CLIENT_PLUGIN_AUTH);
 
  170     client_flag|=CLIENT_CONNECT_WITH_DB;
 
  172   mysql->info_buffer= my_malloc(MYSQL_ERRMSG_SIZE, MYF(0));
 
  173   mysql->thd= create_embedded_thd(client_flag);
 
  175   init_embedded_mysql(mysql, client_flag);
 
  177   if (mysql_init_character_set(mysql))
 
  180   if (check_embedded_connection(mysql, db))
 
  183   mysql->server_status= SERVER_STATUS_AUTOCOMMIT;
 
  185   if (mysql->options.init_commands)
 
  188     char **ptr= (
char**)init_commands->buffer;
 
  189     char **end= ptr + init_commands->elements;
 
  191     for (; ptr<end; ptr++)
 
  194       if (mysql_query(mysql,*ptr))
 
  198         if (!(res= (*mysql->methods->use_result)(mysql)))
 
  200         mysql_free_result(res);
 
  205   DBUG_PRINT(
"exit",(
"Mysql handler: 0x%lx", (
long) mysql));
 
  209   DBUG_PRINT(
"error",(
"message: %u (%s)",
 
  210                       mysql->net.last_errno,
 
  214     my_bool free_me=mysql->free_me;
 
  215     free_old_query(mysql); 
 
  218     mysql->free_me=free_me;