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