ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/2.5/FB25Array.pas
Revision: 263
Committed: Thu Dec 6 15:55:01 2018 UTC (5 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 6436 byte(s)
Log Message:
Release 2.3.2 committed

File Contents

# Content
1 (*
2 * Firebird Interface (fbintf). The fbintf components provide a set of
3 * Pascal language bindings for the Firebird API.
4 *
5 * The contents of this file are subject to the Initial Developer's
6 * Public License Version 1.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain a copy
8 * of the License here:
9 *
10 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
11 *
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing rights
15 * and limitations under the License.
16 *
17 * The Initial Developer of the Original Code is Tony Whyman.
18 *
19 * The Original Code is (C) 2016 Tony Whyman, MWA Software
20 * (http://www.mwasoftware.co.uk).
21 *
22 * All Rights Reserved.
23 *
24 * Contributor(s): ______________________________________.
25 *
26 *)
27 unit FB25Array;
28 {$IFDEF MSWINDOWS}
29 {$DEFINE WINDOWS}
30 {$ENDIF}
31
32 {$IFDEF FPC}
33 {$mode delphi}
34 {$codepage UTF8}
35 {$interfaces COM}
36 {$ENDIF}
37
38 interface
39
40 uses
41 Classes, SysUtils, IB, FBArray, IBHeader, FB25Statement, FB25Attachment, FBClientAPI,
42 FB25Transaction, FB25ClientAPI;
43
44 type
45
46 { TFB25ArrayMetaData }
47
48 TFB25ArrayMetaData = class(TFBArrayMetaData,IArrayMetaData)
49 private
50 FCodePage: TSystemCodePage;
51 protected
52 procedure LoadMetaData(aAttachment: IAttachment; aTransaction: ITransaction;
53 relationName, columnName: AnsiString); override;
54 public
55 function GetCharSetID: cardinal; override;
56 function GetCodePage: TSystemCodePage; override;
57 end;
58
59 { TFB25Array }
60
61 TFB25Array = class(TFBArray,IArray)
62 private
63 FDBHandle: TISC_DB_HANDLE;
64 FTRHandle: TISC_TR_HANDLE;
65 FFirebird25ClientAPI: TFB25ClientAPI;
66 protected
67 procedure InternalGetSlice; override;
68 procedure InternalPutSlice(Force: boolean); override;
69 public
70 constructor Create(aAttachment: TFB25Attachment; aTransaction: TFB25Transaction; aField: IArrayMetaData); overload;
71 constructor Create(aAttachment: TFB25Attachment; aTransaction: TFB25Transaction; aField: IArrayMetaData; ArrayID: TISC_QUAD); overload;
72 end;
73
74 implementation
75
76 uses FBAttachment;
77
78 const
79 sGetArrayMetaData = 'Select F.RDB$CHARACTER_SET_ID '+
80 'From RDB$FIELDS F JOIN RDB$RELATION_FIELDS RF '+
81 'On F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE '+
82 'Where RF.RDB$RELATION_NAME = ? and RF.RDB$FIELD_NAME = ? '+
83 'UNION '+
84 'Select F.RDB$CHARACTER_SET_ID '+
85 'From RDB$FIELDS F JOIN RDB$PROCEDURE_PARAMETERS PP '+
86 'On F.RDB$FIELD_NAME = PP.RDB$FIELD_SOURCE '+
87 'Where PP.RDB$PROCEDURE_NAME = ? and PP.RDB$PARAMETER_NAME = ?';
88
89 { TFB25ArrayMetaData }
90
91 procedure TFB25ArrayMetaData.LoadMetaData(aAttachment: IAttachment;
92 aTransaction: ITransaction; relationName, columnName: AnsiString);
93 var
94 DBHandle: TISC_DB_HANDLE;
95 TRHandle: TISC_TR_HANDLE;
96 stmt: IStatement;
97 CharWidth: integer;
98 RelName: AnsiString;
99 ColName: AnsiString;
100 begin
101 DBHandle := (aAttachment as TFB25Attachment).Handle;
102 TRHandle := (aTransaction as TFB25Transaction).Handle;
103 RelName := AnsiUpperCase(relationName);
104 ColName := AnsiUpperCase(columnName);
105 with (aAttachment as TFB25Attachment).Firebird25ClientAPI do
106 if isc_array_lookup_bounds(StatusVector,@(DBHandle),@(TRHandle),
107 PAnsiChar(RelName),PAnsiChar(ColName),@FArrayDesc) > 0 then
108 IBDatabaseError;
109
110 if (GetSQLType = SQL_TEXT) or (GetSQLType = SQL_VARYING) then
111 begin
112 stmt := TFB25Statement.Create(aAttachment as TFB25Attachment,aTransaction,
113 sGetArrayMetaData ,aAttachment.GetSQLDialect);
114 with stmt do
115 begin
116 SQLParams[0].AsString := RelationName;
117 SQLParams[1].AsString := ColumnName;
118 SQLParams[2].AsString := RelationName;
119 SQLParams[3].AsString := ColumnName;
120 with OpenCursor do
121 if FetchNext then
122 begin
123 FCharSetID := Data[0].AsInteger;
124 with (aAttachment as TFB25Attachment) do
125 if (FCharSetID > 1) and HasDefaultCharSet then
126 begin
127 FCharSetID := CharSetID;
128 FCodePage := CodePage;
129 end
130 else
131 begin
132 FCodePage := CP_NONE;
133 FAttachment.CharSetID2CodePage(FCharSetID,FCodePage);
134 end;
135 end;
136 end;
137 end;
138 if (FArrayDesc.array_desc_dtype in [blr_text,blr_cstring, blr_varying]) and
139 (FCharSetID = 0) then {This really shouldn't be necessary - but it is :(}
140 with aAttachment as TFBAttachment do
141 begin
142 if HasDefaultCharSet and FAttachment.CharSetWidth(CharSetID,CharWidth) then
143 FArrayDesc.array_desc_length := FArrayDesc.array_desc_length * CharWidth;
144 end;
145 end;
146
147 function TFB25ArrayMetaData.GetCharSetID: cardinal;
148 begin
149 Result := FCharSetID;
150 end;
151
152 function TFB25ArrayMetaData.GetCodePage: TSystemCodePage;
153 begin
154 Result := FCodePage;
155 end;
156
157 { TFB25Array }
158
159 procedure TFB25Array.InternalGetSlice;
160 begin
161 with FFirebird25ClientAPI do
162 Call(isc_array_get_slice(StatusVector,@(FDBHandle),@(FTRHandle),
163 @FArrayID, GetArrayDesc,
164 Pointer(FBuffer), @FBufSize));
165 end;
166
167 procedure TFB25Array.InternalPutSlice(Force: boolean);
168 begin
169 with FFirebird25ClientAPI do
170 if (isc_array_put_slice(StatusVector, @(FDBHandle),@(FTRHandle),
171 @FArrayID, GetArrayDesc,
172 Pointer(FBuffer),@FBufSize) > 0) and not Force then
173 IBDatabaseError;
174 SignalActivity;
175 end;
176
177 constructor TFB25Array.Create(aAttachment: TFB25Attachment;
178 aTransaction: TFB25Transaction; aField: IArrayMetaData);
179 begin
180 inherited Create(aAttachment,aTransaction,aField);
181 FDBHandle := aAttachment.Handle;
182 FTRHandle := aTransaction.Handle;
183 FFirebird25ClientAPI := aAttachment.Firebird25ClientAPI;
184 OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError;
185 end;
186
187 constructor TFB25Array.Create(aAttachment: TFB25Attachment;
188 aTransaction: TFB25Transaction; aField: IArrayMetaData; ArrayID: TISC_QUAD);
189 begin
190 inherited Create(aAttachment,aTransaction,aField,ArrayID);
191 FDBHandle := aAttachment.Handle;
192 FTRHandle := aTransaction.Handle;
193 FFirebird25ClientAPI := aAttachment.Firebird25ClientAPI;
194 OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError;
195 end;
196
197 end.
198