⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysql.cc

📁 这是linux下运行的mysql软件包,可用于linux 下安装 php + mysql + apach 的网络配置
💻 CC
📖 第 1 页 / 共 5 页
字号:
    }          else    {						// Add found char to buffer      if (inchar == *in_string)	*in_string= 0;      else if (!*ml_comment && !*in_string &&	       (inchar == '\'' || inchar == '"' || inchar == '`'))	*in_string= (char) inchar;      if (!*ml_comment)      {        if (need_space && !my_isspace(charset_info, (char)inchar))        {          *out++= ' ';          need_space= 0;        }	*out++= (char) inchar;      }    }  }  if (out != line || !buffer.is_empty())  {    *out++='\n';    uint length=(uint) (out-line);    if (buffer.length() + length >= buffer.alloced_length())      buffer.realloc(buffer.length()+length+IO_SIZE);    if (!(*ml_comment) && buffer.append(line,length))      DBUG_RETURN(1);  }  DBUG_RETURN(0);}/*****************************************************************	    Interface to Readline Completion******************************************************************/#ifdef HAVE_READLINEstatic char *new_command_generator(const char *text, int);static char **new_mysql_completion (const char *text, int start, int end);/*  Tell the GNU Readline library how to complete.  We want to try to complete  on command names if this is the first word in the line, or on filenames  if not.*/#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE)char *no_completion(const char*,int)#elseint no_completion()#endif{  return 0;					/* No filename completion */}/*	glues pieces of history back together if in pieces   */static void fix_history(String *final_command) {  int total_lines = 1;  char *ptr = final_command->c_ptr();  String fixed_buffer; 	/* Converted buffer */  char str_char = '\0';  /* Character if we are in a string or not */    /* find out how many lines we have and remove newlines */  while (*ptr != '\0')   {    switch (*ptr) {      /* string character */    case '"':    case '\'':    case '`':      if (str_char == '\0')	/* open string */	str_char = *ptr;      else if (str_char == *ptr)   /* close string */	str_char = '\0';      fixed_buffer.append(ptr,1);      break;    case '\n':      /* 	 not in string, change to space	 if in string, leave it alone       */      fixed_buffer.append(str_char == '\0' ? " " : "\n");      total_lines++;      break;    case '\\':      fixed_buffer.append('\\');      /* need to see if the backslash is escaping anything */      if (str_char)       {	ptr++;	/* special characters that need escaping */	if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')	  fixed_buffer.append(ptr,1);	else	  ptr--;      }      break;          default:      fixed_buffer.append(ptr,1);    }    ptr++;  }  if (total_lines > 1)			    add_history(fixed_buffer.ptr());}/*	  returns 0 if line matches the previous history entry  returns 1 if the line doesn't match the previous history entry*/static int not_in_history(const char *line) {  HIST_ENTRY *oldhist = history_get(history_length);    if (oldhist == 0)    return 1;  if (strcmp(oldhist->line,line) == 0)    return 0;  return 1;}static void initialize_readline (char *name){  /* Allow conditional parsing of the ~/.inputrc file. */  rl_readline_name = name;  /* Tell the completer that we want a crack first. */#if defined(USE_NEW_READLINE_INTERFACE)  rl_attempted_completion_function= (rl_completion_func_t*)&new_mysql_completion;  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;#elif defined(USE_LIBEDIT_INTERFACE)#ifdef HAVE_LOCALE_H  setlocale(LC_ALL,""); /* so as libedit use isprint */#endif  rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;  rl_completion_entry_function= (Function*)&no_completion;#else  rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;  rl_completion_entry_function= (Function*)&no_completion;#endif}/*  Attempt to complete on the contents of TEXT.  START and END show the  region of TEXT that contains the word to complete.  We can use the  entire line in case we want to do some simple parsing.  Return the  array of matches, or NULL if there aren't any.*/static char **new_mysql_completion (const char *text,				    int start __attribute__((unused)),				    int end __attribute__((unused))){  if (!status.batch && !quick)#if defined(USE_NEW_READLINE_INTERFACE)    return rl_completion_matches(text, new_command_generator);#else    return completion_matches((char *)text, (CPFunction *)new_command_generator);#endif  else    return (char**) 0;}static char *new_command_generator(const char *text,int state){  static int textlen;  char *ptr;  static Bucket *b;  static entry *e;  static uint i;  if (!state)    textlen=(uint) strlen(text);  if (textlen>0)  {						/* lookup in the hash */    if (!state)    {      uint len;      b = find_all_matches(&ht,text,(uint) strlen(text),&len);      if (!b)	return NullS;      e = b->pData;    }    if (e)    {      ptr= strdup(e->str);      e = e->pNext;      return ptr;    }  }  else  { /* traverse the entire hash, ugly but works */    if (!state)    {      /* find the first used bucket */      for (i=0 ; i < ht.nTableSize ; i++)      {	if (ht.arBuckets[i])	{	  b = ht.arBuckets[i];	  e = b->pData;	  break;	}      }    }    ptr= NullS;    while (e && !ptr)    {					/* find valid entry in bucket */      if ((uint) strlen(e->str) == b->nKeyLength)	ptr = strdup(e->str);      /* find the next used entry */      e = e->pNext;      if (!e)      { /* find the next used bucket */	b = b->pNext;	if (!b)	{	  for (i++ ; i<ht.nTableSize; i++)	  {	    if (ht.arBuckets[i])	    {	      b = ht.arBuckets[i];	      e = b->pData;	      break;	    }	  }	}	else	  e = b->pData;      }    }    if (ptr)      return ptr;  }  return NullS;}/* Build up the completion hash */static void build_completion_hash(bool rehash, bool write_info){  COMMANDS *cmd=commands;  MYSQL_RES *databases=0,*tables=0;  MYSQL_RES *fields;  static char ***field_names= 0;  MYSQL_ROW database_row,table_row;  MYSQL_FIELD *sql_field;  char buf[NAME_LEN*2+2];		 // table name plus field name plus 2  int i,j,num_fields;  DBUG_ENTER("build_completion_hash");  if (status.batch || quick || !current_db)    DBUG_VOID_RETURN;			// We don't need completion in batches  /* hash SQL commands */  while (cmd->name) {    add_word(&ht,(char*) cmd->name);    cmd++;  }  if (!rehash)    DBUG_VOID_RETURN;  /* Free old used memory */  if (field_names)    field_names=0;  completion_hash_clean(&ht);  free_root(&hash_mem_root,MYF(0));  /* hash MySQL functions (to be implemented) */  /* hash all database names */  if (mysql_query(&mysql,"show databases") == 0)  {    if (!(databases = mysql_store_result(&mysql)))      put_info(mysql_error(&mysql),INFO_INFO);    else    {      while ((database_row=mysql_fetch_row(databases)))      {	char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);	if (str)	  add_word(&ht,(char*) str);      }      mysql_free_result(databases);    }  }  /* hash all table names */  if (mysql_query(&mysql,"show tables")==0)  {    if (!(tables = mysql_store_result(&mysql)))      put_info(mysql_error(&mysql),INFO_INFO);    else    {      if (mysql_num_rows(tables) > 0 && !opt_silent && write_info)      {	tee_fprintf(stdout, "\Reading table information for completion of table and column names\n\You can turn off this feature to get a quicker startup with -A\n\n");      }      while ((table_row=mysql_fetch_row(tables)))      {	char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);	if (str &&	    !completion_hash_exists(&ht,(char*) str, (uint) strlen(str)))	  add_word(&ht,str);      }    }  }  /* hash all field names, both with the table prefix and without it */  if (!tables)					/* no tables */  {    DBUG_VOID_RETURN;  }  mysql_data_seek(tables,0);  if (!(field_names= (char ***) alloc_root(&hash_mem_root,sizeof(char **) *					   (uint) (mysql_num_rows(tables)+1))))  {    mysql_free_result(tables);    DBUG_VOID_RETURN;  }  i=0;  while ((table_row=mysql_fetch_row(tables)))  {    if ((fields=mysql_list_fields(&mysql,(const char*) table_row[0],NullS)))    {      num_fields=mysql_num_fields(fields);      if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,						  sizeof(char *) *						  (num_fields*2+1))))      {        mysql_free_result(fields);        break;      }      field_names[i][num_fields*2]= '\0';      j=0;      while ((sql_field=mysql_fetch_field(fields)))      {	sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);	field_names[i][j] = strdup_root(&hash_mem_root,buf);	add_word(&ht,field_names[i][j]);	field_names[i][num_fields+j] = strdup_root(&hash_mem_root,						   sql_field->name);	if (!completion_hash_exists(&ht,field_names[i][num_fields+j],				    (uint) strlen(field_names[i][num_fields+j])))	  add_word(&ht,field_names[i][num_fields+j]);	j++;      }      mysql_free_result(fields);    }    else      field_names[i]= 0;    i++;  }  mysql_free_result(tables);  field_names[i]=0;				// End pointer  DBUG_VOID_RETURN;}	/* for gnu readline */#ifndef HAVE_INDEXextern "C" {extern char *index(const char *,int c),*rindex(const char *,int);char *index(const char *s,int c){  for (;;)  {     if (*s == (char) c) return (char*) s;     if (!*s++) return NullS;  }}char *rindex(const char *s,int c){  reg3 char *t;  t = NullS;  do if (*s == (char) c) t = (char*) s; while (*s++);  return (char*) t;}}#endif#endif /* HAVE_READLINE */static int reconnect(void){  if (opt_reconnect)  {    put_info("No connection. Trying to reconnect...",INFO_INFO);    (void) com_connect((String *) 0, 0);    if (rehash)      com_rehash(NULL, NULL);  }  if (!connected)    return put_info("Can't connect to the server\n",INFO_ERROR);  return 0;}static void get_current_db(){  MYSQL_RES *res;  my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));  current_db= NULL;  /* In case of error below current_db will be NULL */  if (!mysql_query(&mysql, "SELECT DATABASE()") &&      (res= mysql_use_result(&mysql)))  {    MYSQL_ROW row= mysql_fetch_row(res);    if (row[0])      current_db= my_strdup(row[0], MYF(MY_WME));    mysql_free_result(res);  }}/*************************************************************************** The different commands***************************************************************************/int mysql_real_query_for_lazy(const char *buf, int length){  for (uint retry=0;; retry++)  {    int error;    if (!mysql_real_query(&mysql,buf,length))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -