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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16
/* Functions to map mysqld errno to sql_state */
18
#include <my_global.h>
19
#include <mysqld_error.h>
22
struct st_map_errno_to_sqlstate
25
const char *odbc_state;
26
const char *jdbc_state;
29
struct st_map_errno_to_sqlstate sqlstate_map[]=
31
#include <handler_state.h>
32
#include <sql_state.h>
35
const char *mysql_errno_to_sqlstate(uint mysql_errno)
37
uint first=0, end= array_elements(sqlstate_map)-1;
38
struct st_map_errno_to_sqlstate *map;
40
/* Do binary search in the sorted array */
43
uint mid= (first+end)/2;
44
map= sqlstate_map+mid;
45
if (map->mysql_errno < mysql_errno)
50
map= sqlstate_map+first;
51
if (map->mysql_errno == mysql_errno)
52
return map->odbc_state;
53
return "HY000"; /* General error */