diff options
author | Bjorn Munch <bjorn.munch@oracle.com> | 2011-08-22 13:58:49 +0200 |
---|---|---|
committer | Bjorn Munch <bjorn.munch@oracle.com> | 2011-08-22 13:58:49 +0200 |
commit | 4cb3072356553a003848c8e72f659361ba58c59b (patch) | |
tree | dd93e35420754ad3bcc8c1adbd754962adce3e66 /client | |
parent | fd70af80fa87cadfdfeccd55d082bb37a7d10561 (diff) | |
download | mariadb-git-4cb3072356553a003848c8e72f659361ba58c59b.tar.gz |
Bug #12793170 MYSQLTEST: PROVIDE ACCESS TO ERROR NAMES THROUGH NUMERIC CODES AND VICE VERSA
Added a second internal variable $mysql_errname
This is set the same way as $mysql_errno
Can be used like "if ($mysql_errname == ER_NO_SUCH_TABLE)...."
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqltest.cc | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index cc5dd1f377c..93d475cbf7e 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -494,6 +494,7 @@ void str_to_file(const char *fname, char *str, int size); void str_to_file2(const char *fname, char *str, int size, my_bool append); void fix_win_paths(const char *val, int len); +const char *get_errname_from_code (uint error_code); #ifdef __WIN__ void free_tmp_sh_file(); @@ -2263,6 +2264,7 @@ void var_set_int(const char* name, int value) void var_set_errno(int sql_errno) { var_set_int("$mysql_errno", sql_errno); + var_set_string("$mysql_errname", get_errname_from_code(sql_errno)); } @@ -4670,8 +4672,7 @@ void do_shutdown_server(struct st_command *command) } -#if MYSQL_VERSION_ID >= 50000 -/* List of error names to error codes, available from 5.0 */ +/* List of error names to error codes */ typedef struct { const char *name; @@ -4681,6 +4682,7 @@ typedef struct static st_error global_error_names[] = { + { "<No error>", -1, "" }, #include <mysqld_ername.h> { 0, 0, 0 } }; @@ -4711,16 +4713,28 @@ uint get_errcode_from_name(char *error_name, char *error_end) die("Unknown SQL error name '%s'", error_name); DBUG_RETURN(0); } -#else -uint get_errcode_from_name(char *error_name __attribute__((unused)), - char *error_end __attribute__((unused))) + +const char *get_errname_from_code (uint error_code) { - abort_not_in_this_version(); - return 0; /* Never reached */ -} -#endif + st_error *e= global_error_names; + DBUG_ENTER("get_errname_from_code"); + DBUG_PRINT("enter", ("error_code: %d", error_code)); + if (! error_code) + { + DBUG_RETURN(""); + } + for (; e->name; e++) + { + if (e->code == error_code) + { + DBUG_RETURN(e->name); + } + } + die("Unknown SQL error code '%d'", error_code); +} + void do_get_errcodes(struct st_command *command) { |