File: gnu-db-sqlcli-raise_sql_error.adb

package info (click to toggle)
gnade 1.6.2-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,220 kB
  • ctags: 847
  • sloc: ada: 40,154; sh: 4,124; sql: 3,590; makefile: 1,372; xml: 120; awk: 29
file content (227 lines) | stat: -rw-r--r-- 10,032 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
-------------------------------------------------------------------------------
--                                                                           --
--                      GNADE  : GNu Ada Database Environment                --
--                                                                           --
--  Author          : Juergen Pfeifer <juergen.pfeifer@gmx.net>
--
--  Copyright (C) 2000-2001 Juergen Pfeifer
--                                                                           --
--  GNADE is free software;  you can redistribute it  and/or modify it under --
--  terms of the  GNU General Public License as published  by the Free Soft- --
--  ware  Foundation;  either version 2,  or (at your option) any later ver- --
--  sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
--  OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--  for  more details.  You should have  received  a copy of the GNU General --
--  Public License  distributed with GNAT;  see file COPYING.  If not, write --
--  to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--  MA 02111-1307, USA.                                                      --
--                                                                           --
--  As a special exception,  if other files  instantiate  generics from this --
--  unit, or you link  this unit with other files  to produce an executable, --
--  this  unit  does not  by itself cause  the resulting  executable  to  be --
--  covered  by the  GNU  General  Public  License.  This exception does not --
--  however invalidate  any other reasons why  the executable file  might be --
--  covered by the  GNU Public License.                                      --
--                                                                           --
--  GNADE is implemented to work with GNAT, the GNU Ada compiler.            --
--                                                                           --
-------------------------------------------------------------------------------
with Ada.Exceptions;

separate (GNU.DB.SQLCLI)
procedure Raise_SQL_Error
  (ProcedureName : in String;
   ErrorMessage  : in String    := "";
   RC            : in SQLRETURN := SQL_ADA95_BINDING_ERROR;
   State         : in SQLSTATE  := EMPTY_SQLSTATE)
is
   use Ada;

   Group : constant String := State (1 .. 2);
   Code  : constant String := State (3 .. 5);

   function Msg return String;
   procedure Check_State;

   function Msg return String is
   begin
      return "[Proc=" & ProcedureName & "]" & ErrorMessage;
   end Msg;

   procedure Check_State is
   begin
      if Group /= "00" and then Group /= "01" and then Group /= "  " then
         if Group = "07" then
            if Code = "001" then
               Ada.Exceptions.Raise_Exception
                 (Wrong_Parameter_Count'Identity, Msg);
            elsif Code = "002" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Count_Field'Identity, Msg);
            elsif Code = "005" then
               Ada.Exceptions.Raise_Exception
                 (Prepared_Stmt_Not_Cursor'Identity, Msg);
            elsif Code = "006" then
               Ada.Exceptions.Raise_Exception
                 (Restricted_Type_Violation'Identity, Msg);
            elsif Code = "009" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Descriptor_Index'Identity, Msg);
            elsif Code = "S01" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Default_Parameter'Identity, Msg);
            end if;
         elsif Group = "08" then
            Ada.Exceptions.Raise_Exception (Connection_Error'Identity, Msg);
         elsif Group = "21" then
            Ada.Exceptions.Raise_Exception
              (Column_List_Mismatch'Identity, Msg);
         elsif Group = "22" then
            Ada.Exceptions.Raise_Exception (Format_Error'Identity, Msg);
         elsif Group = "23" then
            Ada.Exceptions.Raise_Exception (Integrity_Violation'Identity, Msg);
         elsif Group = "24" then
            Ada.Exceptions.Raise_Exception
              (Invalid_Cursor_State'Identity, Msg);
         elsif Group = "25" then
            Ada.Exceptions.Raise_Exception
              (Invalid_Transaction_State'Identity, Msg);
         elsif Group = "28" then
            Ada.Exceptions.Raise_Exception (Invalid_Auth_Spec'Identity, Msg);
         elsif Group = "34" then
            Ada.Exceptions.Raise_Exception (Invalid_Cursor_Name'Identity, Msg);
         elsif Group = "3C" then
            Ada.Exceptions.Raise_Exception
              (Duplicate_Cursor_Name'Identity, Msg);
         elsif Group = "3D" then
            Ada.Exceptions.Raise_Exception
              (Invalid_Catalog_Name'Identity, Msg);
         elsif Group = "3F" then
            Ada.Exceptions.Raise_Exception (Invalid_Schema_Name'Identity, Msg);
         elsif Group = "40" then
            if Code = "001" then
               Ada.Exceptions.Raise_Exception (Serialization_Failure'Identity,
                                               Msg);
            elsif Code = "002" then
               Ada.Exceptions.Raise_Exception (Integrity_Violation'Identity,
                                               Msg);
            elsif Code = "003" then
               Ada.Exceptions.Raise_Exception
                 (Unknown_Stmt_Completion'Identity, Msg);
            end if;
         elsif Group = "42" then
            if Code = "000" then
               if ProcedureName = "SQLConnect" then
                  Ada.Exceptions.Raise_Exception
                    (Connection_Error'Identity, Msg);
               else
                  Ada.Exceptions.Raise_Exception (Syntax_Error'Identity, Msg);
               end if;
            elsif Code = "S01" then
               Ada.Exceptions.Raise_Exception
                 (Table_Already_Exists'Identity, Msg);
            elsif Code = "S02" then
               Ada.Exceptions.Raise_Exception
                 (Table_Not_Found'Identity, Msg);
            elsif Code = "S11" then
               Ada.Exceptions.Raise_Exception
                 (Index_Already_Exists'Identity, Msg);
            elsif Code = "S12" then
               Ada.Exceptions.Raise_Exception
                 (Index_Not_Found'Identity, Msg);
            elsif Code = "S21" then
               Ada.Exceptions.Raise_Exception
                 (Column_Already_Exists'Identity, Msg);
            elsif Code = "S22" then
               Ada.Exceptions.Raise_Exception
                 (Column_Not_Found'Identity, Msg);
            end if;
         elsif Group = "44" then
            Ada.Exceptions.Raise_Exception
              (With_Check_Violation'Identity, Msg);
         elsif Group = "HY" then
            if Code = "001" then
               Ada.Exceptions.Raise_Exception
                 (Operation_Canceled'Identity, Msg);
            elsif Code = "003" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_App_Buffer'Identity, Msg);
            elsif Code = "004" then
               Ada.Exceptions.Raise_Exception
                 (Memory_Allocation_Error'Identity, Msg);
            elsif Code = "007" then
               Ada.Exceptions.Raise_Exception
                 (Statement_Not_Prepared'Identity, Msg);
            elsif Code = "008" then
               Ada.Exceptions.Raise_Exception
                 (Operation_Canceled'Identity, Msg);
            elsif Code = "009" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Null_Pointer'Identity, Msg);
            elsif Code = "010" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Function_Sequence'Identity, Msg);
            elsif Code = "090" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Buffer_Length'Identity, Msg);
            elsif Code = "095" then
               Ada.Exceptions.Raise_Exception
                 (Functiontype_Out_Of_Range'Identity, Msg);
            elsif Code = "096" then
               Ada.Exceptions.Raise_Exception
                 (Invalid_Information_Type'Identity, Msg);
            elsif Code = "C00" then
               Ada.Exceptions.Raise_Exception
                 (Not_Implemented'Identity, Msg);
            elsif Code = "T00" then
               Ada.Exceptions.Raise_Exception
                 (Timeout_Expired'Identity, Msg);
            end if;
         elsif Group = "IM" then
            if Code = "001" then
               Ada.Exceptions.Raise_Exception
                 (Not_Implemented'Identity, Msg);
            else
               Ada.Exceptions.Raise_Exception (Driver_Error'Identity, Msg);
            end if;
         end if;
      end if;
   end Check_State;

begin
   case RC is
      when SQL_STILL_EXECUTING =>
         Ada.Exceptions.Raise_Exception (Still_Executing'Identity, Msg);

      when SQL_NO_DATA =>
         raise No_Data;

      when SQL_NEED_DATA =>
         raise Need_Data;

      when SQL_INVALID_HANDLE =>
         Ada.Exceptions.Raise_Exception (Invalid_Handle'Identity, Msg);

      when SQL_ADA95_DATA_ERROR =>
         Ada.Exceptions.Raise_Exception (Data_Error'Identity, Msg);

      when SQL_ADA95_INVALID_ENUM =>
         Ada.Exceptions.Raise_Exception
           (Unhandled_Enum'Identity,
            "[Proc=" & ProcedureName & "] ODBC Call returned enumeration " &
            "value that is not handled by the Ada95 binding: " & ErrorMessage);

      when SQL_ADA95_TYPE_ERROR =>
         Ada.Exceptions.Raise_Exception (Type_Error'Identity, Msg);

      when SQL_ADA95_NO_UNICODE =>
         Ada.Exceptions.Raise_Exception (No_Unicode_Support'Identity, Msg);

      when others =>
         if Generate_Detailed_Exceptions then
            Check_State;
         end if;
         Ada.Exceptions.Raise_Exception (Database_Error'Identity, Msg);
   end case;
end Raise_SQL_Error;