diff options
author | serg@serg.mylan <> | 2005-05-14 19:28:29 +0200 |
---|---|---|
committer | serg@serg.mylan <> | 2005-05-14 19:28:29 +0200 |
commit | 40ce1e174d1e02b9e11a6092a332ca74280e040d (patch) | |
tree | ef2346baa5a2fe4cff6f083464efec28e5ea3c34 /client | |
parent | 0dab212f5c1dcf6d829751765ae9d5dcdb5346d5 (diff) | |
parent | 7cb3e5924c6064e31542332a48f81c9f87928ed8 (diff) | |
download | mariadb-git-40ce1e174d1e02b9e11a6092a332ca74280e040d.tar.gz |
merged
Diffstat (limited to 'client')
-rw-r--r-- | client/Makefile.am | 4 | ||||
-rw-r--r-- | client/client_priv.h | 7 | ||||
-rw-r--r-- | client/mysql.cc | 18 | ||||
-rw-r--r-- | client/mysqladmin.cc | 5 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 1 | ||||
-rw-r--r-- | client/mysqldump.c | 19 | ||||
-rw-r--r-- | client/mysqlshow.c | 65 |
7 files changed, 73 insertions, 46 deletions
diff --git a/client/Makefile.am b/client/Makefile.am index 58dcebfd852..791da2760a5 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -30,10 +30,10 @@ noinst_HEADERS = sql_string.h completion_hash.h my_readline.h \ mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc mysqladmin_SOURCES = mysqladmin.cc mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS) -mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS) mysqltest_SOURCES= mysqltest.c $(top_srcdir)/mysys/my_getsystime.c mysqltest_LDADD = $(top_builddir)/regex/libregex.a $(LDADD) -mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c +mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c $(top_srcdir)/mysys/my_new.cc +mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS) mysqltestmanagerc_SOURCES = mysqlmanagerc.c mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc diff --git a/client/client_priv.h b/client/client_priv.h index 892a9185ffa..d656e54a2b8 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -45,10 +45,9 @@ enum options_client OPT_COMPATIBLE, OPT_RECONNECT, OPT_DELIMITER, OPT_SECURE_AUTH, OPT_OPEN_FILES_LIMIT, OPT_SET_CHARSET, OPT_CREATE_OPTIONS, OPT_START_POSITION, OPT_STOP_POSITION, OPT_START_DATETIME, OPT_STOP_DATETIME, - OPT_SIGINT_IGNORE, OPT_HEXBLOB, OPT_ORDER_BY_PRIMARY + OPT_SIGINT_IGNORE, OPT_HEXBLOB, OPT_ORDER_BY_PRIMARY, OPT_COUNT, #ifdef HAVE_NDBCLUSTER_DB - ,OPT_NDBCLUSTER,OPT_NDB_CONNECTSTRING + OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING, #endif - ,OPT_IGNORE_TABLE - ,OPT_SHOW_WARNINGS + OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS }; diff --git a/client/mysql.cc b/client/mysql.cc index c3a5da430ac..15917e99a23 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -720,9 +720,15 @@ static void usage(int version) const char* readline= "readline"; #endif +#ifdef HAVE_READLINE printf("%s Ver %s Distrib %s, for %s (%s) using %s %s\n", my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE, readline, rl_library_version); +#else + printf("%s Ver %s Distrib %s, for %s (%s)", my_progname, VER, + MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); +#endif + if (version) return; printf("\ @@ -966,7 +972,8 @@ static int read_lines(bool execute_commands) } else { - char *prompt= (char*) (glob_buffer.is_empty() ? construct_prompt() : + char *prompt= (char*) (ml_comment ? " /*> " : + glob_buffer.is_empty() ? construct_prompt() : !in_string ? " -> " : in_string == '\'' ? " '> " : (in_string == '`' ? @@ -1103,6 +1110,7 @@ static bool add_line(String &buffer,char *line,char *in_string, uchar inchar; char buff[80], *pos, *out; COMMANDS *com; + bool need_space= 0; if (!line[0] && buffer.is_empty()) return 0; @@ -1211,6 +1219,7 @@ static bool add_line(String &buffer,char *line,char *in_string, { pos++; *ml_comment= 0; + need_space= 1; } else { // Add found char to buffer @@ -1220,7 +1229,14 @@ static bool add_line(String &buffer,char *line,char *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()) diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 24fe14b6675..32e0dfdb837 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -727,7 +727,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) void (*func) (MYSQL_RES*, MYSQL_ROW, uint); new_line = 1; - if (mysql_query(mysql, "show status") || + if (mysql_query(mysql, "show /*!50002 GLOBAL */ status") || !(res = mysql_store_result(mysql))) { my_printf_error(0, "unable to show status; error: '%s'", MYF(ME_BELL), @@ -1346,6 +1346,3 @@ static my_bool wait_pidfile(char *pidfile, time_t last_modified, } DBUG_RETURN(error); } -#ifdef __GNUC__ -FIX_GCC_LINKING_PROBLEM -#endif diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 59c90f59e8e..1a628bd08c7 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1458,4 +1458,3 @@ int main(int argc, char** argv) #include "log_event.cc" #endif -FIX_GCC_LINKING_PROBLEM diff --git a/client/mysqldump.c b/client/mysqldump.c index b07a36aa7ad..976a6642ea0 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -83,7 +83,7 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick= 1, extended_insert= 1, opt_autocommit=0,opt_disable_keys=1,opt_xml=0, opt_delete_master_logs=0, tty_password=0, opt_single_transaction=0, opt_comments= 0, opt_compact= 0, - opt_hex_blob=0, opt_order_by_primary=0; + opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0; static ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*sock=0; static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, @@ -257,6 +257,9 @@ static struct my_option my_long_options[] = "use the directive multiple times, once for each table. Each table must " "be specified with both database and table names, e.g. --ignore-table=database.table", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.", + (gptr*) &opt_ignore, (gptr*) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", (gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -1100,13 +1103,15 @@ static uint get_table_structure(char *table, char *db) my_bool init=0; uint numFields; char *strpos, *result_table, *opt_quoted_table; - const char *delayed; + const char *insert_option; char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3]; char table_buff2[NAME_LEN*2+3]; FILE *sql_file = md_result_file; DBUG_ENTER("get_table_structure"); - delayed= opt_delayed ? " DELAYED " : ""; + insert_option= (opt_delayed && opt_ignore) ? " DELAYED IGNORE " : + opt_delayed ? " DELAYED " : + opt_ignore ? " IGNORE " : ""; if (verbose) fprintf(stderr, "-- Retrieving table structure for table %s...\n", table); @@ -1190,11 +1195,11 @@ static uint get_table_structure(char *table, char *db) if (cFlag) my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s (", - delayed, opt_quoted_table); + insert_option, opt_quoted_table); else { my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s VALUES ", - delayed, opt_quoted_table); + insert_option, opt_quoted_table); if (!extended_insert) strcat(insert_pat,"("); } @@ -1258,11 +1263,11 @@ static uint get_table_structure(char *table, char *db) } if (cFlag) my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s (", - delayed, result_table); + insert_option, result_table); else { my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s VALUES ", - delayed, result_table); + insert_option, result_table); if (!extended_insert) strcat(insert_pat,"("); } diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 5631d296a54..85c8f123082 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -28,7 +28,7 @@ #include <sslopt-vars.h> static my_string host=0,opt_password=0,user=0; -static my_bool opt_show_keys= 0, opt_compress= 0, opt_status= 0, +static my_bool opt_show_keys= 0, opt_compress= 0, opt_count=0, opt_status= 0, tty_password= 0, opt_table_type= 0; static uint opt_verbose=0; static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; @@ -71,8 +71,7 @@ int main(int argc, char **argv) char *pos= argv[argc-1], *to; for (to= pos ; *pos ; pos++, to++) { - switch (*pos) - { + switch (*pos) { case '*': *pos= '%'; first_argument_uses_wildcards= 1; @@ -163,6 +162,10 @@ static struct my_option my_long_options[] = {"default-character-set", OPT_DEFAULT_CHARSET, "Set the default character set.", (gptr*) &default_charset, (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"count", OPT_COUNT, + "Show number of rows per table (may be slow for not MyISAM tables)", + (gptr*) &opt_count, (gptr*) &opt_count, 0, GET_BOOL, NO_ARG, 0, 0, 0, + 0, 0, 0}, {"compress", 'C', "Use compression in server/client protocol.", (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -308,6 +311,14 @@ get_options(int *argc,char ***argv) if (tty_password) opt_password=get_tty_password(NullS); + if (opt_count) + { + /* + We need to set verbose to 2 as we need to change the output to include + the number-of-rows column + */ + opt_verbose= 2; + } return; } @@ -322,7 +333,7 @@ list_dbs(MYSQL *mysql,const char *wild) char query[255]; MYSQL_FIELD *field; MYSQL_RES *result; - MYSQL_ROW row, trow, rrow; + MYSQL_ROW row, rrow; if (!(result=mysql_list_dbs(mysql,wild))) { @@ -352,11 +363,6 @@ list_dbs(MYSQL *mysql,const char *wild) if (opt_verbose) { - /* - * Original code by MG16373; Slightly modified by Monty. - * Print now the count of tables and rows for each database. - */ - if (!(mysql_select_db(mysql,row[0]))) { MYSQL_RES *tresult = mysql_list_tables(mysql,(char*)NULL); @@ -366,6 +372,8 @@ list_dbs(MYSQL *mysql,const char *wild) rowcount = 0; if (opt_verbose > 1) { + /* Print the count of tables and rows for each database */ + MYSQL_ROW trow; while ((trow = mysql_fetch_row(tresult))) { sprintf(query,"SELECT COUNT(*) FROM `%s`",trow[0]); @@ -487,10 +495,6 @@ list_tables(MYSQL *mysql,const char *db,const char *table) while ((row = mysql_fetch_row(result))) { - /* - * Modified by MG16373 - * Print now the count of rows for each table. - */ counter++; if (opt_verbose > 0) { @@ -510,6 +514,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table) if (opt_verbose > 1) { + /* Print the count of rows for each table */ sprintf(query,"SELECT COUNT(*) FROM `%s`",row[0]); if (!(mysql_query(mysql,query))) { @@ -574,7 +579,7 @@ list_table_status(MYSQL *mysql,const char *db,const char *wild) MYSQL_RES *result; MYSQL_ROW row; - end=strxmov(query,"show table status from ",db,NullS); + end=strxmov(query,"show table status from `",db,"`",NullS); if (wild && wild[0]) strxmov(end," like '",wild,"'",NullS); if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql))) @@ -600,8 +605,8 @@ list_table_status(MYSQL *mysql,const char *db,const char *wild) } /* -** list fields uses field interface as an example of how to parse -** a MYSQL FIELD + list fields uses field interface as an example of how to parse + a MYSQL FIELD */ static int @@ -612,6 +617,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table, MYSQL_RES *result; MYSQL_ROW row; ulong rows; + LINT_INIT(rows); if (mysql_select_db(mysql,db)) { @@ -619,16 +625,20 @@ list_fields(MYSQL *mysql,const char *db,const char *table, mysql_error(mysql)); return 1; } - sprintf(query,"select count(*) from `%s`", table); - if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql))) + + if (opt_count) { - fprintf(stderr,"%s: Cannot get record count for db: %s, table: %s: %s\n", - my_progname,db,table,mysql_error(mysql)); - return 1; + sprintf(query,"select count(*) from `%s`", table); + if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql))) + { + fprintf(stderr,"%s: Cannot get record count for db: %s, table: %s: %s\n", + my_progname,db,table,mysql_error(mysql)); + return 1; + } + row= mysql_fetch_row(result); + rows= (ulong) strtoull(row[0], (char**) 0, 10); + mysql_free_result(result); } - row = mysql_fetch_row(result); - rows = (ulong) strtoull(row[0], (char**) 0, 10); - mysql_free_result(result); end=strmov(strmov(strmov(query,"show /*!32332 FULL */ columns from `"),table),"`"); if (wild && wild[0]) @@ -640,8 +650,9 @@ list_fields(MYSQL *mysql,const char *db,const char *table, return 1; } - printf("Database: %s Table: %s Rows: %lu", db, table, rows); - + printf("Database: %s Table: %s", db, table); + if (opt_count) + printf(" Rows: %lu", rows); if (wild && wild[0]) printf(" Wildcard: %s",wild); putchar('\n'); @@ -675,7 +686,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table, /***************************************************************************** -** General functions to print a nice ascii-table from data + General functions to print a nice ascii-table from data *****************************************************************************/ static void |