~drizzle-trunk/drizzle/development

1 by brian
clean slate
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* Functions to map mysqld errno to sql_state */
17
212.5.39 by Monty Taylor
Phew. Moved my_base and my_global.
18
#include "global.h"
212.5.42 by Monty Taylor
Ding dong include is dead.
19
#include <drizzled/error.h>
212.5.25 by Monty Taylor
Moved drizzle.h to libdrizzle.
20
#include <libdrizzle/drizzle.h>
212.5.42 by Monty Taylor
Ding dong include is dead.
21
#include "sql_state.h"
1 by brian
clean slate
22
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
23
const char *drizzle_errno_to_sqlstate(uint mysql_errno)
1 by brian
clean slate
24
{
25
  uint first=0, end= array_elements(sqlstate_map)-1;
26
  struct st_map_errno_to_sqlstate *map;
27
28
  /* Do binary search in the sorted array */
29
  while (first != end)
30
  {
31
    uint mid= (first+end)/2;
32
    map= sqlstate_map+mid;
33
    if (map->mysql_errno < mysql_errno)
34
      first= mid+1;
35
    else
36
      end= mid;
37
  }
38
  map= sqlstate_map+first;
39
  if (map->mysql_errno == mysql_errno)
40
    return map->odbc_state;
41
  return "HY000";				/* General error */
42
}