MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_state.c
1 /* Copyright (C) 2000-2003 MySQL AB
2 
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.
6 
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.
11 
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 */
15 
16 /* Functions to map mysqld errno to sql_state */
17 
18 #include <my_global.h>
19 #include <mysqld_error.h>
20 
22 {
23  uint mysql_errno;
24  const char *odbc_state;
25  const char *jdbc_state;
26 };
27 
28 struct st_map_errno_to_sqlstate sqlstate_map[]=
29 {
30 #include <sql_state.h>
31 };
32 
33 const char *mysql_errno_to_sqlstate(uint mysql_errno)
34 {
35  uint first=0, end= array_elements(sqlstate_map)-1;
36  struct st_map_errno_to_sqlstate *map;
37 
38  /* Do binary search in the sorted array */
39  while (first != end)
40  {
41  uint mid= (first+end)/2;
42  map= sqlstate_map+mid;
43  if (map->mysql_errno < mysql_errno)
44  first= mid+1;
45  else
46  end= mid;
47  }
48  map= sqlstate_map+first;
49  if (map->mysql_errno == mysql_errno)
50  return map->odbc_state;
51  return "HY000"; /* General error */
52 }