~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to sql/sql_state.c

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include <my_base.h>
 
21
 
 
22
struct st_map_errno_to_sqlstate
 
23
{
 
24
  uint mysql_errno;
 
25
  const char *odbc_state;
 
26
  const char *jdbc_state;
 
27
};
 
28
 
 
29
struct st_map_errno_to_sqlstate sqlstate_map[]=
 
30
{
 
31
#include <handler_state.h>
 
32
#include <sql_state.h>
 
33
};
 
34
 
 
35
const char *mysql_errno_to_sqlstate(uint mysql_errno)
 
36
{
 
37
  uint first=0, end= array_elements(sqlstate_map)-1;
 
38
  struct st_map_errno_to_sqlstate *map;
 
39
 
 
40
  /* Do binary search in the sorted array */
 
41
  while (first != end)
 
42
  {
 
43
    uint mid= (first+end)/2;
 
44
    map= sqlstate_map+mid;
 
45
    if (map->mysql_errno < mysql_errno)
 
46
      first= mid+1;
 
47
    else
 
48
      end= mid;
 
49
  }
 
50
  map= sqlstate_map+first;
 
51
  if (map->mysql_errno == mysql_errno)
 
52
    return map->odbc_state;
 
53
  return "HY000";                               /* General error */
 
54
}