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