You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB

  1. /* Copyright (C) 2000-2003 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  13. /* Functions to map mysqld errno to sql_state */
  14. #include <my_global.h>
  15. #include <mysqld_error.h>
  16. struct st_map_errno_to_sqlstate
  17. {
  18. uint mysql_errno;
  19. const char *odbc_state;
  20. const char *jdbc_state;
  21. };
  22. struct st_map_errno_to_sqlstate sqlstate_map[]=
  23. {
  24. #include <sql_state.h>
  25. };
  26. const char *mysql_errno_to_sqlstate(uint mysql_errno)
  27. {
  28. uint first=0, end= array_elements(sqlstate_map)-1;
  29. struct st_map_errno_to_sqlstate *map;
  30. /* Do binary search in the sorted array */
  31. while (first != end)
  32. {
  33. uint mid= (first+end)/2;
  34. map= sqlstate_map+mid;
  35. if (map->mysql_errno < mysql_errno)
  36. first= mid+1;
  37. else
  38. end= mid;
  39. }
  40. map= sqlstate_map+first;
  41. if (map->mysql_errno == mysql_errno)
  42. return map->odbc_state;
  43. return "HY000"; /* General error */
  44. }