This file is indexed.

/usr/share/ada/adainclude/gnadeodbc/gnu-db-sqlcli-diag.adb is in libgnadeodbc2-dev 1.6.2-9.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
pragma Source_Reference (1, "dbi/odbc/gnu-db-sqlcli-diag.gpb");
-------------------------------------------------------------------------------
--                                                                           --
--                      GNADE  : GNu Ada Database Environment                --
--                                                                           --
--  Author          : Juergen Pfeifer <juergen.pfeifer@gmx.net>
--
--  Copyright (C) 2000-2002 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.Unchecked_Deallocation;





package body GNU.DB.SQLCLI.Diag is



   procedure Register_String_Attributes;

   function SQLGetDiagRec (HandleType  : SQL_HANDLE_TYPE := SQL_HANDLE_STMT;
                           Handle      : SQLHANDLE;
                           RecNumber   : SQLSMALLINT := 1;
                           State       : access SQLSTATE;
                           NativeError : access SQLINTEGER)
                           return String is
      function GetDiagRec (HandleType   : SQL_HANDLE_TYPE;
                           Handle       : SQLHANDLE;
                           RecNumber    : SQLSMALLINT;
                           pSqlstate    : access C_SQLSTATE;
                           pNativeError : access SQLINTEGER;
                           pMessageText : PTR_SQLCHAR;
                           BufferLength : SQLSMALLINT;
                           pTextLength  : access SQLSMALLINT)
                           return SQLRETURN;
      pragma Import (C, GetDiagRec, "SQLGetDiagRec");
      Len : aliased SQLSMALLINT := SQLSMALLINT (SQL_MAX_MESSAGE_SIZE);

      pragma Warnings (Off);
      Str : String (1 .. Positive (SQL_MAX_MESSAGE_SIZE));
      pragma Warnings (On);

      C_State : aliased C_SQLSTATE;
      RC  : constant SQLRETURN := GetDiagRec (HandleType,
                                              Handle,
                                              RecNumber,
                                              C_State'Access,
                                              NativeError,
                                              To_PTR_SQLCHAR (Str'Address),
                                              Len,
                                              Len'Access);
   begin
      State.all := GNU.DB.SQLCLI.To_Ada (C_State);
      if Is_SQL_Ok (RC) then
         if Len > 0 then
            return Str (1 .. Positive (Len));
         else
            return "";
         end if;
      else
         if RC = SQL_ERROR then
            return "Invalid Record Number";
         elsif RC = SQL_INVALID_HANDLE then
            return "Invalid Handle";
         elsif RC = SQL_NO_DATA then
            return "No diagnostic data available";
         else
            return "Unknown error return from SQLGetDiagRec";
         end if;
      end if;
   end SQLGetDiagRec;

   function SQLGetDiagRec (HandleType  : SQL_HANDLE_TYPE := SQL_HANDLE_STMT;
                           Handle      : SQLHANDLE;
                           RecNumber   : SQLSMALLINT := 1;
                           State       : access WIDE_SQLSTATE;
                           NativeError : access SQLINTEGER)
                           return Wide_String is

      function GetDiagRec (HandleType   : SQL_HANDLE_TYPE;
                           Handle       : SQLHANDLE;
                           RecNumber    : SQLSMALLINT;
                           pSqlstate    : access C_WSQLSTATE;
                           pNativeError : access SQLINTEGER;
                           pMessageText : PTR_SQLTCHAR;
                           BufferLength : SQLSMALLINT;
                           pTextLength  : access SQLSMALLINT)
                           return SQLRETURN;
      pragma Import (C, GetDiagRec, "SQLGetDiagRecW");
      Len : aliased SQLSMALLINT := SQLSMALLINT (SQL_MAX_MESSAGE_SIZE);

      pragma Warnings (Off);
      Str : Wide_String (1 .. Positive (SQL_MAX_MESSAGE_SIZE));
      pragma Warnings (On);

      C_State : aliased C_WSQLSTATE;
      RC  : constant SQLRETURN := GetDiagRec (HandleType,
                                              Handle,
                                              RecNumber,
                                              C_State'Access,
                                              NativeError,
                                              To_PTR_SQLTCHAR (Str'Address),
                                              Len,
                                              Len'Access);

   begin

      State.all := C_State;
      if Is_SQL_Ok (RC) then
         if Len > 0 then
            return Str (1 .. Positive (Len));
         else
            return Wide_String'("");
         end if;
      else
         if RC = SQL_ERROR then
            return Wide_String'("Invalid Record Number");
         elsif RC = SQL_INVALID_HANDLE then
            return Wide_String'("Invalid Handle");
         elsif RC = SQL_NO_DATA then
            return Wide_String'("No diagnostic data available");
         else
            return Wide_String'("Unknown error return from SQLGetDiagRec");
         end if;
      end if;







   end SQLGetDiagRec;

   procedure Get_Diag_Field (Ctx       : Diagnostic_Context;
                             AttrType  : SQL_DIAGNOSTIC_IDENTIFIER;
                             Value     : SQLPOINTER;
                             Length    : in out SQLSMALLINT;
                             Data      : in SQLSMALLINT;
                             ErrorCode : access SQLRETURN)
   is
      pragma Unreferenced (Data);
      function GetDiagField (HandleType     : SQL_HANDLE_TYPE;
                             Handle         : SQLHANDLE;
                             RecNumber      : SQLSMALLINT;
                             DiagIdentifier : SQL_DIAGNOSTIC_IDENTIFIER;
                             DiagInfo       : SQLPOINTER;
                             BufferLength   : SQLSMALLINT;
                             pStringLength  : access SQLSMALLINT)
                             return SQLRETURN;
      pragma Import (C, GetDiagField, "SQLGetDiagField");

      function GetDiagFieldW (HandleType     : SQL_HANDLE_TYPE;
                              Handle         : SQLHANDLE;
                              RecNumber      : SQLSMALLINT;
                              DiagIdentifier : SQL_DIAGNOSTIC_IDENTIFIER;
                              DiagInfo       : SQLPOINTER;
                              BufferLength   : SQLSMALLINT;
                              pStringLength  : access SQLSMALLINT)
                              return SQLRETURN;
      pragma Import (C, GetDiagFieldW, "SQLGetDiagFieldW");

      pragma Assert (Ctx /= null);
      Name : constant String := "SQLGetDiagField";
      Len  : aliased SQLSMALLINT := Length;
      RC   : SQLRETURN;
   begin
      if Unicode_Attr_Flag then

         RC := GetDiagFieldW (Ctx.HandleType,
                              Ctx.Handle,
                              Ctx.RecordNumber,
                              AttrType,
                              Value,
                              Len,
                              Len'Access);




      else
         RC := GetDiagField (Ctx.HandleType,
                             Ctx.Handle,
                             Ctx.RecordNumber,
                             AttrType,
                             Value,
                             Len,
                             Len'Access);
      end if;
      ErrorCode.all := RC;
      if Is_SQL_Ok (RC) then
         Length := Len;
      else
         if RC = SQL_ERROR then
            Raise_SQL_Error (ProcedureName => Name,
                             ErrorMessage  => "Invalid Field request");
         elsif RC = SQL_INVALID_HANDLE then
            Raise_SQL_Error (ProcedureName => Name,
                             ErrorMessage  => "Invalid Handle");
         elsif RC = SQL_NO_DATA then
            Raise_SQL_Error (ProcedureName => Name,
                             ErrorMessage  => "No diagnostic data available");
         else
            Raise_SQL_Error (ProcedureName => Name,
                             ErrorMessage  => "Unknown error return");
         end if;
      end if;
   end Get_Diag_Field;

   procedure Set_Diag_Field (Ctx       : Diagnostic_Context;
                             AttrType  : SQL_DIAGNOSTIC_IDENTIFIER;
                             Value     : SQLPOINTER;
                             Length    : in SQLSMALLINT;
                             Data      : in SQLSMALLINT;
                             ErrorCode : out SQLRETURN) is
      pragma Unreferenced (Data);
      pragma Unreferenced (Length);
      pragma Unreferenced (Value);
      pragma Unreferenced (AttrType);
      pragma Unreferenced (Ctx);
   begin
      ErrorCode := -1;
      Raise_SQL_Error (ProcedureName => "Set_Diag_Field",
                       ErrorMessage  => "Set Value not allowed");
   end Set_Diag_Field;

   function Default_Context return Diagnostic_Context is
   begin
      return null;
   end Default_Context;

   function SQLGetDiagField (HandleType   : SQL_HANDLE_TYPE;
                             Handle       : SQLHANDLE;
                             RecordNumber : SQLSMALLINT;
                             Field        : SQL_DIAGNOSTIC_IDENTIFIER;
                             MaxLength    : SQLSMALLINT := 1024)
                             return Diagnostic_Field'Class is
      use type Dispatch.Attr_Get_Func;
      procedure Free is new
        Ada.Unchecked_Deallocation (Diagnostic_Context_Record,
                                    Diagnostic_Context);

      Ctx : Diagnostic_Context := new Diagnostic_Context_Record'
        (Handle       => Handle,
         HandleType   => HandleType,
         RecordNumber => RecordNumber);
      ErrorCode : aliased SQLRETURN;
      F : constant Dispatch.Attr_Get_Func := Dispatch.Get_Func (Field);
   begin
      if F = null then
         Free (Ctx);
         Raise_SQL_Error ("SQLGetDiagField",
                          SQL_DIAGNOSTIC_IDENTIFIER'Image (Field) &
                          Attr_Not_Supported_Msg);
      else
         declare
            Res : constant Diagnostic_Field'Class :=
              F.all (Ctx, Field, MaxLength, 0, ErrorCode'Access);
         begin
            Free (Ctx);
            return Res;
         end;
      end if;
   end SQLGetDiagField;

   procedure Register_String_Attributes is
   begin
      if Unicode_Attr_Flag then
         DF_WString.Register (SQL_DIAG_SUBCLASS_ORIGIN);
         DF_WString.Register (SQL_DIAG_SQLSTATE);
         DF_WString.Register (SQL_DIAG_SERVER_NAME);
         DF_WString.Register (SQL_DIAG_MESSAGE_TEXT);
         DF_WString.Register (SQL_DIAG_CONNECTION_NAME);
         DF_WString.Register (SQL_DIAG_CLASS_ORIGIN);
         DF_WString.Register (SQL_DIAG_DYNAMIC_FUNCTION);
      else
         DF_String.Register (SQL_DIAG_SUBCLASS_ORIGIN);
         DF_String.Register (SQL_DIAG_SQLSTATE);
         DF_String.Register (SQL_DIAG_SERVER_NAME);
         DF_String.Register (SQL_DIAG_MESSAGE_TEXT);
         DF_String.Register (SQL_DIAG_CONNECTION_NAME);
         DF_String.Register (SQL_DIAG_CLASS_ORIGIN);
         DF_String.Register (SQL_DIAG_DYNAMIC_FUNCTION);
      end if;
   end Register_String_Attributes;

begin
   DF_Integer.Register (SQL_DIAG_NATIVE);
   DF_Integer.Register (SQL_DIAG_ROW_NUMBER);
   DF_Integer.Register (SQL_DIAG_COLUMN_NUMBER);
   DF_Integer.Register (SQL_DIAG_ROW_COUNT);
   DF_Integer.Register (SQL_DIAG_NUMBER);
   DF_Integer.Register (SQL_DIAG_CURSOR_ROW_COUNT);

   DF_SmallInteger.Register (SQL_DIAG_RETURNCODE);

   Register_String_Attributes;
   Register_Initializer (Register_String_Attributes'Access);



end GNU.DB.SQLCLI.Diag;