📄 mysql.cc
字号:
return 0; error= put_error(&mysql); if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR || retry > 1 || !opt_reconnect) return error; if (reconnect()) return error; }}int mysql_store_result_for_lazy(MYSQL_RES **result){ if ((*result=mysql_store_result(&mysql))) return 0; if (mysql_error(&mysql)[0]) return put_error(&mysql); return 0;}static void print_help_item(MYSQL_ROW *cur, int num_name, int num_cat, char *last_char){ char ccat= (*cur)[num_cat][0]; if (*last_char != ccat) { put_info(ccat == 'Y' ? "categories:" : "topics:", INFO_INFO); *last_char= ccat; } tee_fprintf(PAGER, " %s\n", (*cur)[num_name]);}static int com_server_help(String *buffer __attribute__((unused)), char *line __attribute__((unused)), char *help_arg){ MYSQL_ROW cur; const char *server_cmd= buffer->ptr(); char cmd_buf[100]; MYSQL_RES *result; int error; if (help_arg[0] != '\'') { (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NullS); server_cmd= cmd_buf; } if (!status.batch) { old_buffer= *buffer; old_buffer.copy(); } if (!connected && reconnect()) return 1; if ((error= mysql_real_query_for_lazy(server_cmd,(int)strlen(server_cmd))) || (error= mysql_store_result_for_lazy(&result))) return error; if (result) { unsigned int num_fields= mysql_num_fields(result); my_ulonglong num_rows= mysql_num_rows(result); mysql_fetch_fields(result); if (num_fields==3 && num_rows==1) { if (!(cur= mysql_fetch_row(result))) { error= -1; goto err; } init_pager(); tee_fprintf(PAGER, "Name: \'%s\'\n", cur[0]); tee_fprintf(PAGER, "Description:\n%s", cur[1]); if (cur[2] && *((char*)cur[2])) tee_fprintf(PAGER, "Examples:\n%s", cur[2]); tee_fprintf(PAGER, "\n"); end_pager(); } else if (num_fields >= 2 && num_rows) { init_pager(); char last_char= 0; int num_name= 0, num_cat= 0; LINT_INIT(num_name); LINT_INIT(num_cat); if (num_fields == 2) { put_info("Many help items for your request exist.", INFO_INFO); put_info("To make a more specific request, please type 'help <item>',\nwhere <item> is one of the following", INFO_INFO); num_name= 0; num_cat= 1; } else if ((cur= mysql_fetch_row(result))) { tee_fprintf(PAGER, "You asked for help about help category: \"%s\"\n", cur[0]); put_info("For more information, type 'help <item>', where <item> is one of the following", INFO_INFO); num_name= 1; num_cat= 2; print_help_item(&cur,1,2,&last_char); } while ((cur= mysql_fetch_row(result))) print_help_item(&cur,num_name,num_cat,&last_char); tee_fprintf(PAGER, "\n"); end_pager(); } else { put_info("\nNothing found", INFO_INFO); put_info("Please try to run 'help contents' for a list of all accessible topics\n", INFO_INFO); } }err: mysql_free_result(result); return error;}static intcom_help(String *buffer __attribute__((unused)), char *line __attribute__((unused))){ reg1 int i, j; char * help_arg= strchr(line,' '), buff[32], *end; if (help_arg) return com_server_help(buffer,line,help_arg+1); put_info("\nFor information about MySQL products and services, visit:\n" " http://www.mysql.com/\n" "For developer information, including the MySQL Reference Manual, " "visit:\n" " http://dev.mysql.com/\n" "To buy MySQL Network Support, training, or other products, visit:\n" " https://shop.mysql.com/\n", INFO_INFO); put_info("List of all MySQL commands:", INFO_INFO); if (!named_cmds) put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO); for (i = 0; commands[i].name; i++) { end= strmov(buff, commands[i].name); for (j= (int)strlen(commands[i].name); j < 10; j++) end= strmov(end, " "); if (commands[i].func) tee_fprintf(stdout, "%s(\\%c) %s\n", buff, commands[i].cmd_char, commands[i].doc); } if (connected && mysql_get_server_version(&mysql) >= 40100) put_info("\nFor server side help, type 'help contents'\n", INFO_INFO); return 0;} /* ARGSUSED */static intcom_clear(String *buffer,char *line __attribute__((unused))){#ifdef HAVE_READLINE if (status.add_to_history) fix_history(buffer);#endif buffer->length(0); return 0;} /* ARGSUSED */static intcom_charset(String *buffer __attribute__((unused)), char *line){ char buff[256], *param; CHARSET_INFO * new_cs; strmake(buff, line, sizeof(buff) - 1); param= get_arg(buff, 0); if (!param || !*param) { return put_info("Usage: \\C char_setname | charset charset_name", INFO_ERROR, 0); } new_cs= get_charset_by_csname(param, MY_CS_PRIMARY, MYF(MY_WME)); if (new_cs) { charset_info= new_cs; put_info("Charset changed", INFO_INFO); } else put_info("Charset is not found", INFO_INFO); return 0;}/* Execute command Returns: 0 if ok -1 if not fatal error 1 if fatal error*/static intcom_go(String *buffer,char *line __attribute__((unused))){ char buff[200], time_buff[32], *pos; MYSQL_RES *result; ulong timer, warnings; uint error= 0; int err= 0; if (!status.batch) { old_buffer= *buffer; // Save for edit command old_buffer.copy(); } /* Remove garbage for nicer messages */ LINT_INIT(buff[0]); remove_cntrl(*buffer); if (buffer->is_empty()) { if (status.batch) // Ignore empty quries return 0; return put_info("No query specified\n",INFO_ERROR); } if (!connected && reconnect()) { buffer->length(0); // Remove query on error return opt_reconnect ? -1 : 1; // Fatal error } if (verbose) (void) com_print(buffer,0); if (skip_updates && (buffer->length() < 4 || my_strnncoll(charset_info, (const uchar*)buffer->ptr(),4, (const uchar*)"SET ",4))) { (void) put_info("Ignoring query to other database",INFO_INFO); return 0; } timer=start_timer(); error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length());#ifdef HAVE_READLINE if (status.add_to_history) { buffer->append(vertical ? "\\G" : delimiter); /* Append final command onto history */ fix_history(buffer); }#endif if (error) { buffer->length(0); // Remove query on error return error; } error=0; buffer->length(0); do { if (quick) { if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql)) return put_error(&mysql); } else { error= mysql_store_result_for_lazy(&result); if (error) return error; } if (verbose >= 3 || !opt_silent) mysql_end_timer(timer,time_buff); else time_buff[0]=0; if (result) { if (!mysql_num_rows(result) && ! quick && !info_flag) { strmov(buff, "Empty set"); } else { init_pager(); if (opt_html) print_table_data_html(result); else if (opt_xml) print_table_data_xml(result); else if (vertical) print_table_data_vertically(result); else if (opt_silent && verbose <= 2 && !output_tables) print_tab_data(result); else print_table_data(result); sprintf(buff,"%ld %s in set", (long) mysql_num_rows(result), (long) mysql_num_rows(result) == 1 ? "row" : "rows"); end_pager(); } } else if (mysql_affected_rows(&mysql) == ~(ulonglong) 0) strmov(buff,"Query OK"); else sprintf(buff,"Query OK, %ld %s affected", (long) mysql_affected_rows(&mysql), (long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows"); pos=strend(buff); if ((warnings= mysql_warning_count(&mysql))) { *pos++= ','; *pos++= ' '; pos=int10_to_str(warnings, pos, 10); pos=strmov(pos, " warning"); if (warnings != 1) *pos++= 's'; } strmov(pos, time_buff); put_info(buff,INFO_RESULT); if (mysql_info(&mysql)) put_info(mysql_info(&mysql),INFO_RESULT); put_info("",INFO_RESULT); // Empty row if (result && !mysql_eof(result)) /* Something wrong when using quick */ error= put_error(&mysql); else if (unbuffered) fflush(stdout); mysql_free_result(result); } while (!(err= mysql_next_result(&mysql))); if (err >= 1) error= put_error(&mysql); if (show_warnings == 1 && warnings >= 1) /* Show warnings if any */ { init_pager(); print_warnings(); end_pager(); } if (!error && !status.batch && (mysql.server_status & SERVER_STATUS_DB_DROPPED)) get_current_db(); return error; /* New command follows */}static void init_pager(){#ifdef USE_POPEN if (!opt_nopager) { if (!(PAGER= popen(pager, "w"))) { tee_fprintf(stdout, "popen() failed! defaulting PAGER to stdout!\n"); PAGER= stdout; } } else#endif PAGER= stdout;}static void end_pager(){#ifdef USE_POPEN if (!opt_nopager) pclose(PAGER);#endif}static void init_tee(const char *file_name){ FILE* new_outfile; if (opt_outfile) end_tee(); if (!(new_outfile= my_fopen(file_name, O_APPEND | O_WRONLY, MYF(MY_WME)))) { tee_fprintf(stdout, "Error logging to file '%s'\n", file_name); return; } OUTFILE = new_outfile; strmake(outfile, file_name, FN_REFLEN-1); tee_fprintf(stdout, "Logging to file '%s'\n", file_name); opt_outfile= 1; return;}static void end_tee(){ my_fclose(OUTFILE, MYF(0)); OUTFILE= 0; opt_outfile= 0; return;}static intcom_ego(String *buffer,char *line){ int result; bool oldvertical=vertical; vertical=1; result=com_go(buffer,line); vertical=oldvertical; return result;}static const char *fieldtype2str(enum enum_field_types type){ switch (type) { case FIELD_TYPE_BIT: return "BIT"; case FIELD_TYPE_BLOB: return "BLOB"; case FIELD_TYPE_DATE: return "DATE"; case FIELD_TYPE_DATETIME: return "DATETIME"; case FIELD_TYPE_NEWDECIMAL: return "NEWDECIMAL"; case FIELD_TYPE_DECIMAL: return "DECIMAL"; case FIELD_TYPE_DOUBLE: return "DOUBLE"; case FIELD_TYPE_ENUM: return "ENUM"; case FIELD_TYPE_FLOAT: return "FLOAT"; case FIELD_TYPE_GEOMETRY: return "GEOMETRY"; case FIELD_TYPE_INT24: return "INT24"; case FIELD_TYPE_LONG: return "LONG"; case FIELD_TYPE_LONGLONG: return "LONGLONG"; case
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -