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.

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