matreshka_league_21.0.0_0c8f4d47/source/sql/oci/matreshka-internals-sql_drivers-oracle-queries.ads

  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
------------------------------------------------------------------------------
--                                                                          --
--                            Matreshka Project                             --
--                                                                          --
--                           SQL Database Access                            --
--                                                                          --
--                        Runtime Library Component                         --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2011-2014, Vadim Godunko <vgodunko@gmail.com>                --
-- All rights reserved.                                                     --
--                                                                          --
-- Redistribution and use in source and binary forms, with or without       --
-- modification, are permitted provided that the following conditions       --
-- are met:                                                                 --
--                                                                          --
--  * Redistributions of source code must retain the above copyright        --
--    notice, this list of conditions and the following disclaimer.         --
--                                                                          --
--  * Redistributions in binary form must reproduce the above copyright     --
--    notice, this list of conditions and the following disclaimer in the   --
--    documentation and/or other materials provided with the distribution.  --
--                                                                          --
--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
--    contributors may be used to endorse or promote products derived from  --
--    this software without specific prior written permission.              --
--                                                                          --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 4982 $ $Date: 2014-11-04 13:25:16 +0300 (Вт, 04 ноя 2014) $
------------------------------------------------------------------------------
private with Ada.Containers.Hashed_Maps;
private with System.Storage_Elements;

private with League.Strings.Hash;
with Matreshka.Internals.SQL_Drivers.Oracle.Databases;
private with Matreshka.Internals.Strings;
limited with Matreshka.Internals.SQL_Drivers.Oracle.Plug_In;
with Matreshka.Internals.SQL_Drivers.Oracle.Utils;

package Matreshka.Internals.SQL_Drivers.Oracle.Queries is

   type OCI_Database_Access is access all Databases.OCI_Database;

   type OCI_Query (DB : not null access Databases.OCI_Database) is
     new Abstract_Query with private;

private

   type Plug_In_Access is access all
     Matreshka.Internals.SQL_Drivers.Oracle.Plug_In.Abstract_Plug_In'Class;

   type Bound_Value_Node (Length : System.Storage_Elements.Storage_Count)
   is limited record
      Value       : League.Holders.Holder;
      Bind        : aliased Oracle.Bind;
      Is_Null     : aliased Sb2;
      String_Size : aliased Ub4;
      String      : Matreshka.Internals.Strings.Shared_String_Access;
      Int         : aliased League.Holders.Universal_Integer;
      Float       : aliased League.Holders.Universal_Float;
      Date        : aliased Oracle.Utils.OCIDate;
      Timestamp   : aliased Date_Time;
      Direction   : SQL.Parameter_Directions;
      Plugin      : Plug_In_Access;
      Extra_Type  : Data_Type;
      Extra_Size  : System.Storage_Elements.Storage_Count;
      Extra       : System.Storage_Elements.Storage_Array (1 .. Length);
   end record;

   type Bound_Value_Access is access Bound_Value_Node;

   package Parameter_Maps is
     new Ada.Containers.Hashed_Maps
          (League.Strings.Universal_String,
           Bound_Value_Access,
           League.Strings.Hash,
           League.Strings."=");
   --  XXX Database independent parameter mapping must be extended and reused
   --  here.

   type Column_Types is
     (String_Column, Integer_Column, Float_Column, Date_Column, Time_Column);

   type Storage_Array_Access is
     access all System.Storage_Elements.Storage_Array;

   type Defined_Value is limited record
      Column_Type : Column_Types;
      Define      : aliased Oracle.Define;
      Is_Null     : aliased Sb2;
      Size        : Utf16.Utf16_String_Index;
      String      : Matreshka.Internals.Strings.Shared_String_Access;
      Int         : aliased League.Holders.Universal_Integer;
      Float       : aliased League.Holders.Universal_Float;
      Date        : aliased Oracle.Utils.OCIDate;
      Timestamp   : aliased Date_Time;
      Plugin      : Plug_In_Access;
      Extra_Type  : Data_Type;
      Extra_Size  : System.Storage_Elements.Storage_Count;
      Extra       : Storage_Array_Access;
   end record;

   type Defined_Value_Array is array (Positive range <>) of Defined_Value;

   type Defined_Value_Array_Access is access Defined_Value_Array;

   type Query_States is (Created, Prepared, Executed, Has_Row, No_More_Rows);

   subtype Active   is Query_States range Executed .. No_More_Rows;
   subtype Fetching is Query_States range Executed .. Has_Row;
   subtype Ready    is Query_States range Prepared .. No_More_Rows;

   type OCI_Query  (DB : not null access Databases.OCI_Database) is
     new Abstract_Query with
   record
      Handle       : aliased Statement_Handle;
      Column_Count : Natural      := 0;
      State        : Query_States := Created;
      Is_Described : Boolean      := False;
      Is_Select    : Boolean      := False;
      Parameters   : Parameter_Maps.Map;
      Columns      : Defined_Value_Array_Access;
   end record;

   overriding procedure Bind_Value
    (Self      : not null access OCI_Query;
     Name      : League.Strings.Universal_String;
     Value     : League.Holders.Holder;
     Direction : SQL.Parameter_Directions);

   overriding function Bound_Value
    (Self : not null access OCI_Query;
     Name : League.Strings.Universal_String)
       return League.Holders.Holder;

   overriding function Error_Message
    (Self : not null access OCI_Query) return League.Strings.Universal_String;

   overriding function Execute
    (Self : not null access OCI_Query) return Boolean;

   overriding procedure Finish (Self : not null access OCI_Query);

   overriding procedure Invalidate (Self : not null access OCI_Query);

   overriding function Is_Active
    (Self : not null access OCI_Query) return Boolean;

   overriding function Is_Valid
    (Self : not null access OCI_Query) return Boolean;

   overriding function Next (Self : not null access OCI_Query) return Boolean;

   overriding function Prepare
    (Self  : not null access OCI_Query;
     Query : League.Strings.Universal_String) return Boolean;

   overriding function Value
    (Self  : not null access OCI_Query;
     Index : Positive) return League.Holders.Holder;

end Matreshka.Internals.SQL_Drivers.Oracle.Queries;