~drizzle-trunk/drizzle/development

467 by Monty Taylor
Made sql_state and stacktrace compile as C++. drizzled/ is pure c++ now.
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
467 by Monty Taylor
Made sql_state and stacktrace compile as C++. drizzled/ is pure c++ now.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
1 by brian
clean slate
20
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
21
/* Functions to map drizzle errno to sql_state */
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
22
#include <config.h>
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
23
24
#include <algorithm>
25
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
26
#include <drizzled/error.h>
2137.1.2 by Brian Aker
Just shuffle over sql_state to be in the error system.
27
#include <drizzled/error/sql_state.h>
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
28
29
using namespace std;
30
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
31
namespace drizzled
32
{
33
2137.1.2 by Brian Aker
Just shuffle over sql_state to be in the error system.
34
namespace error
35
{
36
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
37
struct sql_state_t
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
38
{
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
39
  drizzled::error_t drizzle_errno;
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
40
  const char *odbc_state;
41
  const char *jdbc_state;
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
42
};
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
43
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
44
sql_state_t sqlstate_map[]=
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
45
{
46
  { ER_DUP_KEY                              ,"23000", "" },
47
  { ER_OUTOFMEMORY                          ,"HY001", "S1001" },
48
  { ER_OUT_OF_SORTMEMORY                    ,"HY001", "S1001" },
49
  { ER_CON_COUNT_ERROR                      ,"08004", "" },
50
  { ER_BAD_HOST_ERROR                       ,"08S01", "" },
51
  { ER_HANDSHAKE_ERROR                      ,"08S01", "" },
52
  { ER_DBACCESS_DENIED_ERROR                ,"42000", "" },
53
  { ER_ACCESS_DENIED_ERROR                  ,"28000", "" },
54
  { ER_NO_DB_ERROR                          ,"3D000", "" },
55
  { ER_UNKNOWN_COM_ERROR                    ,"08S01", "" },
56
  { ER_BAD_NULL_ERROR                       ,"23000", "" },
57
  { ER_BAD_DB_ERROR                         ,"42000", "" },
58
  { ER_TABLE_EXISTS_ERROR                   ,"42S01", "" },
59
  { ER_BAD_TABLE_ERROR                      ,"42S02", "" },
60
  { ER_NON_UNIQ_ERROR                       ,"23000", "" },
61
  { ER_SERVER_SHUTDOWN                      ,"08S01", "" },
62
  { ER_BAD_FIELD_ERROR                      ,"42S22", "S0022" },
63
  { ER_WRONG_FIELD_WITH_GROUP               ,"42000", "S1009" },
64
  { ER_WRONG_GROUP_FIELD                    ,"42000", "S1009" },
65
  { ER_WRONG_SUM_SELECT                     ,"42000", "S1009" },
66
  { ER_WRONG_VALUE_COUNT                    ,"21S01", "" },
67
  { ER_TOO_LONG_IDENT                       ,"42000", "S1009" },
68
  { ER_DUP_FIELDNAME                        ,"42S21", "S1009" },
69
  { ER_DUP_KEYNAME                          ,"42000", "S1009" },
70
  { ER_DUP_ENTRY                            ,"23000", "S1009" },
71
  { ER_WRONG_FIELD_SPEC                     ,"42000", "S1009" },
72
  { ER_PARSE_ERROR                          ,"42000", "s1009" },
73
  { ER_EMPTY_QUERY                          ,"42000", "" },
74
  { ER_NONUNIQ_TABLE                        ,"42000", "S1009" },
75
  { ER_INVALID_DEFAULT                      ,"42000", "S1009" },
76
  { ER_MULTIPLE_PRI_KEY                     ,"42000", "S1009" },
77
  { ER_TOO_MANY_KEYS                        ,"42000", "S1009" },
78
  { ER_TOO_MANY_KEY_PARTS                   ,"42000", "S1009" },
79
  { ER_TOO_LONG_KEY                         ,"42000", "S1009" },
80
  { ER_KEY_COLUMN_DOES_NOT_EXITS            ,"42000", "S1009" },
81
  { ER_BLOB_USED_AS_KEY                     ,"42000", "S1009" },
82
  { ER_TOO_BIG_FIELDLENGTH                  ,"42000", "S1009" },
83
  { ER_WRONG_AUTO_KEY                       ,"42000", "S1009" },
84
  { ER_FORCING_CLOSE                        ,"08S01", "" },
85
  { ER_IPSOCK_ERROR                         ,"08S01", "" },
86
  { ER_NO_SUCH_INDEX                        ,"42S12", "S1009" },
87
  { ER_WRONG_FIELD_TERMINATORS              ,"42000", "S1009" },
88
  { ER_BLOBS_AND_NO_TERMINATED              ,"42000", "S1009" },
89
  { ER_CANT_REMOVE_ALL_FIELDS               ,"42000", "" },
90
  { ER_CANT_DROP_FIELD_OR_KEY               ,"42000", "" },
91
  { ER_BLOB_CANT_HAVE_DEFAULT               ,"42000", "" },
92
  { ER_WRONG_DB_NAME                        ,"42000", "" },
93
  { ER_WRONG_TABLE_NAME                     ,"42000", "" },
94
  { ER_TOO_BIG_SELECT                       ,"42000", "" },
95
  { ER_UNKNOWN_PROCEDURE                    ,"42000", "" },
96
  { ER_WRONG_PARAMCOUNT_TO_PROCEDURE        ,"42000", "" },
97
  { ER_UNKNOWN_TABLE                        ,"42S02", "" },
98
  { ER_FIELD_SPECIFIED_TWICE                ,"42000", "" },
99
  { ER_UNSUPPORTED_EXTENSION                ,"42000", "" },
100
  { ER_TABLE_MUST_HAVE_COLUMNS              ,"42000", "" },
101
  { ER_TOO_BIG_ROWSIZE                      ,"42000", "" },
102
  { ER_WRONG_OUTER_JOIN                     ,"42000", "" },
103
  { ER_NULL_COLUMN_IN_INDEX                 ,"42000", "" },
104
  { ER_WRONG_VALUE_COUNT_ON_ROW             ,"21S01", "" },
105
  { ER_MIX_OF_GROUP_FUNC_AND_FIELDS         ,"42000", "" },
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
106
  { ER_TABLE_UNKNOWN                        ,"42S02", "" },
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
107
  { ER_SYNTAX_ERROR                         ,"42000", "" },
108
  { ER_NET_PACKET_TOO_LARGE                 ,"08S01", "" },
109
  { ER_NET_PACKETS_OUT_OF_ORDER             ,"08S01", "" },
110
  { ER_TABLE_CANT_HANDLE_BLOB               ,"42000", "" },
111
  { ER_TABLE_CANT_HANDLE_AUTO_INCREMENT     ,"42000", "" },
112
  { ER_WRONG_COLUMN_NAME                    ,"42000", "" },
113
  { ER_WRONG_KEY_COLUMN                     ,"42000", "" },
114
  { ER_DUP_UNIQUE                           ,"23000", "" },
115
  { ER_BLOB_KEY_WITHOUT_LENGTH              ,"42000", "" },
116
  { ER_PRIMARY_CANT_HAVE_NULL               ,"42000", "" },
117
  { ER_TOO_MANY_ROWS                        ,"42000", "" },
118
  { ER_REQUIRES_PRIMARY_KEY                 ,"42000", "" },
119
  { ER_KEY_DOES_NOT_EXITS                   ,"42000", "S1009" },
120
  { ER_CHECK_NO_SUCH_TABLE                  ,"42000", "" },
121
  { ER_CHECK_NOT_IMPLEMENTED                ,"42000", "" },
122
  { ER_NEW_ABORTING_CONNECTION              ,"08S01", "" },
123
  { ER_READ_ONLY_TRANSACTION                ,"25000", "" },
124
  { ER_LOCK_DEADLOCK                        ,"40001", "" },
125
  { ER_NO_REFERENCED_ROW                    ,"23000", "" },
126
  { ER_ROW_IS_REFERENCED                    ,"23000", "" },
127
  { ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT    ,"21000", "" },
128
  { ER_NO_DEFAULT                           ,"42000", "" },
129
  { ER_WRONG_VALUE_FOR_VAR                  ,"42000", "" },
130
  { ER_WRONG_TYPE_FOR_VAR                   ,"42000", "" },
131
  { ER_CANT_USE_OPTION_HERE                 ,"42000", "" },
132
  { ER_NOT_SUPPORTED_YET                    ,"42000", "" },
133
  { ER_WRONG_FK_DEF                         ,"42000", "" },
134
  { ER_OPERAND_COLUMNS                      ,"21000", "" },
135
  { ER_SUBQUERY_NO_1_ROW                    ,"21000", "" },
136
  { ER_ILLEGAL_REFERENCE                    ,"42S22", "" },
137
  { ER_DERIVED_MUST_HAVE_ALIAS              ,"42000", "" },
138
  { ER_SELECT_REDUCED                       ,"01000", "" },
139
  { ER_TABLENAME_NOT_ALLOWED_HERE           ,"42000", "" },
140
  { ER_SPATIAL_CANT_HAVE_NULL               ,"42000", "" },
141
  { ER_COLLATION_CHARSET_MISMATCH           ,"42000", "" },
142
  { ER_WARN_TOO_FEW_RECORDS                 ,"01000", "" },
143
  { ER_WARN_TOO_MANY_RECORDS                ,"01000", "" },
144
  { ER_WARN_NULL_TO_NOTNULL                 ,"22004", "" },
145
  { ER_WARN_DATA_OUT_OF_RANGE               ,"22003", "" },
146
  { ER_WARN_DATA_TRUNCATED                  ,"01000", "" },
147
  { ER_WRONG_NAME_FOR_INDEX                 ,"42000", "" },
148
  { ER_WRONG_NAME_FOR_CATALOG               ,"42000", "" },
149
  { ER_UNKNOWN_STORAGE_ENGINE               ,"42000", "" },
150
  { ER_TRUNCATED_WRONG_VALUE                ,"22007", "" },
151
  { ER_SP_DOES_NOT_EXIST                    ,"42000", "" },
152
  { ER_QUERY_INTERRUPTED                    ,"70100", "" },
153
  { ER_DIVISION_BY_ZERO                     ,"22012", "" },
154
  { ER_ILLEGAL_VALUE_FOR_TYPE               ,"22007", "" },
155
  { ER_XAER_RMFAIL                          ,"XAE07", "" },
156
  { ER_DATA_TOO_LONG                        ,"22001", "" },
157
  { ER_SP_NO_RETSET                         ,"0A000", "" },
158
  { ER_CANT_CREATE_GEOMETRY_OBJECT          ,"22003", "" },
159
  { ER_TOO_BIG_SCALE                        ,"42000", "S1009" },
160
  { ER_TOO_BIG_PRECISION                    ,"42000", "S1009" },
161
  { ER_M_BIGGER_THAN_D                      ,"42000", "S1009" },
162
  { ER_TOO_BIG_DISPLAYWIDTH                 ,"42000", "S1009" },
163
  { ER_DATETIME_FUNCTION_OVERFLOW           ,"22008", "" },
164
  { ER_ROW_IS_REFERENCED_2                  ,"23000", "" },
165
  { ER_NO_REFERENCED_ROW_2                  ,"23000", "" },
166
  { ER_NON_GROUPING_FIELD_USED              ,"42000", "" },
167
  { ER_FOREIGN_DUPLICATE_KEY                ,"23000", "S1009" },
168
  { ER_CANT_CHANGE_TX_ISOLATION             ,"25001", "" },
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
169
  { ER_WRONG_PARAMCOUNT_TO_FUNCTION         ,"42000", "" },
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
170
  { ER_WRONG_PARAMETERS_TO_NATIVE_FCT       ,"42000", "" },
171
  { ER_DUP_ENTRY_WITH_KEY_NAME              ,"23000", "S1009" },
172
};
173
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
174
static bool compare_errno_map(sql_state_t a,
175
                              sql_state_t b)
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
176
{
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
177
  return (a.drizzle_errno < b.drizzle_errno);
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
178
}
179
2137.1.2 by Brian Aker
Just shuffle over sql_state to be in the error system.
180
const char *convert_to_sqlstate(drizzled::error_t drizzle_errno)
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
181
{
182
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
183
  sql_state_t drizzle_err_state= {drizzle_errno, NULL, NULL};
184
  sql_state_t* result=
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
185
    lower_bound(&sqlstate_map[0],
186
                &sqlstate_map[sizeof(sqlstate_map)/sizeof(*sqlstate_map)],
187
                drizzle_err_state, compare_errno_map);
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
188
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
189
  if ((*result).drizzle_errno == drizzle_errno)
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
190
    return (*result).odbc_state;
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
191
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
192
  /* General error */
193
  return "HY000";
1 by brian
clean slate
194
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
195
2137.1.2 by Brian Aker
Just shuffle over sql_state to be in the error system.
196
} /* namespace error */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
197
} /* namespace drizzled */