diff options
author | kent@mysql.com <> | 2004-09-16 20:52:23 +0200 |
---|---|---|
committer | kent@mysql.com <> | 2004-09-16 20:52:23 +0200 |
commit | 604acced00bbebe5596d033b9b5062250c5e5e2a (patch) | |
tree | c4d86ca5f0559b51a673378dc3d5a2ffd2a0dbcf /client | |
parent | a660499cd9a216c2b915830c8dcb7c03aca2f3af (diff) | |
download | mariadb-git-604acced00bbebe5596d033b9b5062250c5e5e2a.tar.gz |
mysqltest.c:
Feature to solve Bug#4640, added "--character_set <charset>" test case option
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqltest.c | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 3287c9738d3..1e939d3a825 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -125,7 +125,8 @@ static int block_stack[BLOCK_STACK_DEPTH]; static int block_ok_stack[BLOCK_STACK_DEPTH]; static uint global_expected_errno[MAX_EXPECTED_ERRORS], global_expected_errors; -static CHARSET_INFO *charset_info= &my_charset_latin1; +static CHARSET_INFO *charset_info= &my_charset_latin1; /* Default charset */ +static char *charset_name = "latin1"; /* Default character set name */ static int embedded_server_arg_count=0; static char *embedded_server_args[MAX_SERVER_ARGS]; @@ -230,6 +231,7 @@ Q_ENABLE_METADATA, Q_DISABLE_METADATA, Q_EXEC, Q_DELIMITER, Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, +Q_CHARACTER_SET, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ @@ -308,6 +310,7 @@ const char *command_names[]= "horizontal_results", "query_vertical", "query_horizontal", + "character_set", 0 }; @@ -329,6 +332,7 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname); void reject_dump(const char *record_file, char *buf, int size); int close_connection(struct st_query* q); +static void set_charset(struct st_query*); VAR* var_get(const char *var_name, const char** var_name_end, my_bool raw, my_bool ignore_not_existing); int eval_expr(VAR* v, const char *p, const char** p_end); @@ -1224,6 +1228,23 @@ static void get_file_name(char *filename, struct st_query* q) p[0]=0; } +static void set_charset(struct st_query* q) +{ + char* charset_name= q->first_argument; + char* tmp; + + if (!charset_name || !*charset_name) + die("Missing charset name in 'character_set'\n"); + /* Remove end space */ + tmp= charset_name; + while (*tmp && !my_isspace(charset_info,*tmp)) + tmp++; + *tmp= 0; + + charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME)); + if (!charset_info) + abort_not_supported_test(); +} static uint get_ints(uint *to,struct st_query* q) { @@ -1568,7 +1589,7 @@ int do_connect(struct st_query* q) if (opt_compress) mysql_options(&next_con->mysql,MYSQL_OPT_COMPRESS,NullS); mysql_options(&next_con->mysql, MYSQL_OPT_LOCAL_INFILE, 0); - mysql_options(&next_con->mysql, MYSQL_SET_CHARSET_NAME, "latin1"); + mysql_options(&next_con->mysql, MYSQL_SET_CHARSET_NAME, charset_name); #ifdef HAVE_OPENSSL if (opt_use_ssl) @@ -1714,6 +1735,7 @@ int read_line(char* buf, int size) c= my_getc(*cur_file); if (feof(*cur_file)) { + found_eof: if ((*cur_file) != stdin) my_fclose(*cur_file, MYF(0)); cur_file--; @@ -1823,7 +1845,39 @@ int read_line(char* buf, int size) } if (!no_save) - *p++= c; + { + /* Could be a multibyte character */ + /* This code is based on the code in "sql_load.cc" */ +#ifdef USE_MB + int charlen = my_mbcharlen(charset_info, c); + /* Not 100% correct that buf_end tell us anything if this is */ + /* a multibyte char or not but we give up if it doesn't fit */ + if ((charlen > 1) && (p + charlen) <= buf_end) + { + int i; + char* mb_start = p; + + *p++ = c; + + for (i= 1; i < charlen; i++) + { + if (feof(*cur_file)) + goto found_eof; /* FIXME: could we just break here?! */ + c= my_getc(*cur_file); + *p++ = c; + } + if (! my_ismbchar(charset_info, mb_start, p)) + { + /* It was not a multiline char, push back the characters */ + /* We leave first 'c', i.e. pretend it was a normal char */ + while (p > mb_start) + my_ungetc(*--p); + } + } + else +#endif + *p++= c; + } } *p= 0; /* Always end with \0 */ DBUG_RETURN(feof(*cur_file)); @@ -2637,7 +2691,7 @@ int main(int argc, char **argv) if (opt_compress) mysql_options(&cur_con->mysql,MYSQL_OPT_COMPRESS,NullS); mysql_options(&cur_con->mysql, MYSQL_OPT_LOCAL_INFILE, 0); - mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_NAME, "latin1"); + mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_NAME, charset_name); #ifdef HAVE_OPENSSL if (opt_use_ssl) @@ -2810,6 +2864,9 @@ int main(int argc, char **argv) case Q_PING: (void) mysql_ping(&cur_con->mysql); break; + case Q_CHARACTER_SET: + set_charset(q); + break; case Q_EXEC: (void) do_exec(q); break; |