Contraint Error could be raised if S'First was not 1
[gnadelite.git] / src / db-tools.adb
blobc44762854f3795c06f8db4e3be52550597d7355c
1 ------------------------------------------------------------------------------
2 -- GnadeLite --
3 -- --
4 -- Copyright (C) 2006-2007 --
5 -- Pascal Obry - Olivier Ramonat --
6 -- --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
11 -- --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
16 -- --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
22 package body DB.Tools is
24 -------
25 -- F --
26 -------
28 function F (F : in Float) return String is
29 begin
30 return Float'Image (F);
31 end F;
33 -------
34 -- I --
35 -------
37 function I (Int : in Integer) return String is
38 begin
39 return Integer'Image (Int);
40 end I;
42 -------
43 -- Q --
44 -------
46 function Q (Str : in String) return String is
47 S : String (1 .. 2 + Str'Length * 2);
48 J : Positive := 1;
49 begin
50 if Str = "" then
51 return "NULL";
52 end if;
54 S (J) := ''';
56 for K in Str'Range loop
57 if Str (K) = ''' then
58 J := J + 1;
59 S (J) := ''';
60 end if;
61 J := J + 1;
62 S (J) := Str (K);
63 end loop;
65 J := J + 1;
66 S (J) := ''';
68 return S (1 .. J);
69 end Q;
71 function Q (Str : in Unbounded_String) return String is
72 begin
73 return Q (To_String (Str));
74 end Q;
76 function Q (Bool : in Boolean) return String is
77 begin
78 return Q (Boolean'Image (Bool));
79 end Q;
80 end DB.Tools;