ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/nongui/IBUpdate.pas
Revision: 315
Committed: Thu Feb 25 11:56:36 2021 UTC (3 years, 9 months ago) by tony
Content type: text/x-pascal
File size: 19963 byte(s)
Log Message:
Updated for IBX 4 release

File Contents

# Content
1 (*
2 * IBX For Lazarus (Firebird Express)
3 *
4 * The contents of this file are subject to the Initial Developer's
5 * Public License Version 1.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy
7 * of the License here:
8 *
9 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 *
11 * Software distributed under the License is distributed on an "AS
12 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 * implied. See the License for the specific language governing rights
14 * and limitations under the License.
15 *
16 * The Initial Developer of the Original Code is Tony Whyman.
17 *
18 * The Original Code is (C) 2015-2020 Tony Whyman, MWA Software
19 * (http://www.mwasoftware.co.uk).
20 *
21 * All Rights Reserved.
22 *
23 * Contributor(s): ______________________________________.
24 *
25 *)
26
27 unit IBUpdate;
28
29 {$mode objfpc}{$H+}
30
31 interface
32
33 uses
34 Classes, SysUtils, IBCustomDataSet, DB, IB, IBDatabase, IBExternals, IBMessages;
35
36 type
37
38 TOnApplyUpdates = procedure(Sender: TObject; UpdateKind: TUpdateKind; Params: ISQLParams) of object;
39
40 { TIBUpdate}
41
42 TIBUpdate = class(TIBDataSetUpdateObject)
43 private
44 FDataSet: TIBCustomDataSet;
45 FDummySQL: TStrings;
46 FOnApplyUpdates: TOnApplyUpdates;
47 protected
48 function GetSQL(UpdateKind: TUpdateKind): TStrings; override;
49 function GetDataSet: TIBCustomDataSet; override;
50 procedure SetDataSet(ADataSet: TIBCustomDataSet); override;
51 procedure Apply(UpdateKind: TUpdateKind; buff: PChar); override;
52 public
53 constructor Create(AOwner: TComponent); override;
54 destructor Destroy; override;
55 property DataSet;
56 published
57 property OnApplyUpdates: TOnApplyUpdates read FOnApplyUpdates write FOnApplyUpdates;
58 end;
59
60
61 implementation
62
63 uses variants, FmtBCD, DateUtils;
64
65 type
66
67 { TParamListIntf }
68
69 TParamListIntf = class(TInterfacedObject,ISQLParams)
70 private
71 type TParamRec = record
72 Name: string;
73 Value: variant;
74 Modified: boolean;
75 TimeZoneID: TFBTimeZoneID;
76 DataSet: TDataSet;
77 end;
78 private
79 FDatabase: TIBDatabase;
80 FModified: boolean;
81 FParams: array of TParamRec;
82 procedure SetParam(index: integer; aValue: variant);
83 procedure SetTimeZoneID(index: integer; aValue: TFBTimeZoneID);
84 public
85 constructor Create(aFields: TFields; aDatabase: TIBDatabase);
86 destructor Destroy; override;
87 property Database: TIBDatabase read FDatabase;
88 public
89 {ISQLParams}
90 function getCount: integer;
91 function getSQLParam(index: integer): ISQLParam;
92 function ByName(Idx: AnsiString): ISQLParam ;
93 function GetModified: Boolean;
94 function GetHasCaseSensitiveParams: Boolean;
95 end;
96
97 { TParamIntf }
98
99 TParamIntf = class(TInterfacedObject,ISQLParam)
100 private
101 FIndex: integer;
102 FOwner: TParamListIntf;
103 function GetDataSet: TDataSet;
104 public
105 constructor Create(aOwner: TParamListIntf; aIndex: integer);
106 function GetIndex: integer;
107 function GetSQLType: cardinal;
108 function GetSQLTypeName: AnsiString;
109 function getSubtype: integer;
110 function getName: AnsiString;
111 function getScale: integer;
112 function getCharSetID: cardinal;
113 function getCodePage: TSystemCodePage;
114 function getIsNullable: boolean;
115 function GetSize: cardinal;
116 function GetAsBoolean: boolean;
117 function GetAsCurrency: Currency;
118 function GetAsInt64: Int64;
119 function GetAsDateTime: TDateTime; overload;
120 procedure GetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload;
121 procedure GetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload;
122 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime); overload;
123 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString; OnDate: TDateTime); overload;
124 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload;
125 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload;
126 function GetAsUTCDateTime: TDateTime;
127 function GetAsDouble: Double;
128 function GetAsFloat: Float;
129 function GetAsLong: Long;
130 function GetAsPointer: Pointer;
131 function GetAsQuad: TISC_QUAD;
132 function GetAsShort: short;
133 function GetAsString: AnsiString;
134 function GetIsNull: boolean;
135 function GetAsVariant: Variant;
136 function GetAsBlob: IBlob;
137 function GetAsArray: IArray;
138 function GetAsBCD: tBCD;
139 function GetStatement: IStatement;
140 function GetTransaction: ITransaction;
141 procedure Clear;
142 function GetModified: boolean;
143 procedure SetAsBoolean(AValue: boolean);
144 procedure SetAsCurrency(aValue: Currency);
145 procedure SetAsInt64(aValue: Int64);
146 procedure SetAsDate(aValue: TDateTime);
147 procedure SetAsLong(aValue: Long);
148 procedure SetAsTime(aValue: TDateTime); overload;
149 procedure SetAsTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
150 procedure SetAsTime(aValue: TDateTime; aTimeZone: AnsiString); overload;
151 procedure SetAsTime(aValue: TDateTime; OnDate: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
152 procedure SetAsTime(aValue: TDateTime; OnDate: TDateTime; aTimeZone: AnsiString); overload;
153 procedure SetAsDateTime(aValue: TDateTime); overload;
154 procedure SetAsDateTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
155 procedure SetAsDateTime(aValue: TDateTime; aTimeZone: AnsiString); overload;
156 procedure SetAsUTCDateTime(aUTCTime: TDateTime);
157 procedure SetAsDouble(aValue: Double);
158 procedure SetAsFloat(aValue: Float);
159 procedure SetAsPointer(aValue: Pointer);
160 procedure SetAsShort(aValue: Short);
161 procedure SetAsString(aValue: AnsiString);
162 procedure SetAsVariant(aValue: Variant);
163 procedure SetIsNull(aValue: Boolean);
164 procedure SetAsBlob(aValue: IBlob);
165 procedure SetAsArray(anArray: IArray);
166 procedure SetAsQuad(aValue: TISC_QUAD);
167 procedure SetCharSetID(aValue: cardinal);
168 procedure SetAsBcd(aValue: tBCD);
169 end;
170
171 { TParamIntf }
172
173 function TParamIntf.GetDataSet: TDataSet;
174 begin
175 Result := FOwner.FParams[FIndex].DataSet;
176 end;
177
178 constructor TParamIntf.Create(aOwner: TParamListIntf; aIndex: integer);
179 begin
180 FOwner := aOwner;
181 FIndex := aIndex;
182 end;
183
184 function TParamIntf.GetIndex: integer;
185 begin
186 Result := Findex;
187 end;
188
189 function TParamIntf.GetSQLType: cardinal;
190 begin
191 IBError(ibxeNotSupported,[]);
192 end;
193
194 function TParamIntf.GetSQLTypeName: AnsiString;
195 begin
196 IBError(ibxeNotSupported,[]);
197 end;
198
199 function TParamIntf.getSubtype: integer;
200 begin
201 IBError(ibxeNotSupported,[]);
202 end;
203
204 function TParamIntf.getName: AnsiString;
205 begin
206 Result := FOwner.FParams[FIndex].Name;
207 end;
208
209 function TParamIntf.getScale: integer;
210 begin
211 IBError(ibxeNotSupported,[]);
212 end;
213
214 function TParamIntf.getCharSetID: cardinal;
215 var id: integer;
216 begin
217 FOwner.Database.Attachment.CodePage2CharSetID(StringCodePage(FOwner.FParams[FIndex].Value),id);
218 Result := id;
219 end;
220
221 function TParamIntf.getCodePage: TSystemCodePage;
222 begin
223 Result := StringCodePage(FOwner.FParams[FIndex].Value);
224 end;
225
226 function TParamIntf.getIsNullable: boolean;
227 begin
228 Result := true;
229 end;
230
231 function TParamIntf.GetSize: cardinal;
232 begin
233 IBError(ibxeNotSupported,[]);
234 end;
235
236 function TParamIntf.GetAsBoolean: boolean;
237 begin
238 Result := FOwner.FParams[FIndex].Value;
239 end;
240
241 function TParamIntf.GetAsCurrency: Currency;
242 begin
243 Result := FOwner.FParams[FIndex].Value;
244 end;
245
246 function TParamIntf.GetAsInt64: Int64;
247 begin
248 Result := FOwner.FParams[FIndex].Value;
249 end;
250
251 function TParamIntf.GetAsDateTime: TDateTime;
252 begin
253 Result := FOwner.FParams[FIndex].Value;
254 end;
255
256 procedure TParamIntf.GetAsDateTime(var aDateTime: TDateTime;
257 var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID);
258 begin
259 with FOwner.FParams[FIndex] do
260 if VarIsArray(Value) then
261 begin
262 aDateTime := Value[0];
263 dstOffset := Value[1];
264 if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
265 aTimezoneID := Value[2]
266 else
267 aTimeZoneID := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneName2TimeZoneID(Value[2]);
268 end
269 else
270 begin
271 aDateTime := FOwner.FParams[FIndex].Value;
272 dstOffset := 0;
273 aTimeZoneID := TimeZoneID_GMT;
274 end;
275 end;
276
277 procedure TParamIntf.GetAsDateTime(var aDateTime: TDateTime;
278 var dstOffset: smallint; var aTimezone: AnsiString);
279 begin
280 with FOwner.FParams[FIndex] do
281 if VarIsArray(Value) then
282 begin
283 aDateTime := Value[0];
284 dstOffset := Value[1];
285 if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
286 aTimeZone := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneID2TimeZoneName(Value[2])
287 else
288 aTimezone := Value[2];
289 end
290 else
291 begin
292 aDateTime := FOwner.FParams[FIndex].Value;
293 dstOffset := 0;
294 aTimeZone := 'GMT';
295 end;
296 end;
297
298 procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
299 var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime);
300 var LocalTime: TDateTime;
301 begin
302 with FOwner.FParams[FIndex] do
303 if VarIsArray(Value) then
304 begin
305 LocalTime := OnDate + TimeOf(Value[0]);
306 dstOffset := Value[1];
307 if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
308 aTimezoneID := Value[2]
309 else
310 aTimeZoneID := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneName2TimeZoneID(Value[2]);
311 aTime := TimeOf(FOwner.DataBase.attachment.GetTimeZoneServices.GMTToLocalTime(IncMinute(LocalTime,-dstOffset),aTimeZoneID))
312 end
313 else
314 begin
315 aTime := FOwner.FParams[FIndex].Value;
316 dstOffset := 0;
317 aTimeZoneID := TimeZoneID_GMT;
318 end;
319 end;
320
321 procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
322 var aTimezone: AnsiString; OnDate: TDateTime);
323 var LocalTime: TDateTime;
324 begin
325 with FOwner.FParams[FIndex] do
326 if VarIsArray(Value) then
327 begin
328 LocalTime := OnDate + TimeOf(Value[0]);
329 dstOffset := Value[1];
330 if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
331 aTimeZone := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneID2TimeZoneName(Value[2])
332 else
333 aTimezone := Value[2];
334 aTime := TimeOf(FOwner.DataBase.attachment.GetTimeZoneServices.GMTToLocalTime(IncMinute(LocalTime,-dstOffset),aTimeZone))
335 end
336 else
337 begin
338 aTime := FOwner.FParams[FIndex].Value;
339 dstOffset := 0;
340 aTimeZone := 'GMT';
341 end;
342 end;
343
344 procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
345 var aTimezoneID: TFBTimeZoneID);
346 begin
347 GetAsTime(aTime,dstOffset,aTimeZoneID,(GetDataSet as TIBCustomDataSet).DefaultTZDate);
348 end;
349
350 procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
351 var aTimezone: AnsiString);
352 begin
353 GetAsTime(aTime,dstOffset,aTimeZone,(GetDataSet as TIBCustomDataSet).DefaultTZDate);
354 end;
355
356 function TParamIntf.GetAsUTCDateTime: TDateTime;
357 begin
358 with FOwner.FParams[FIndex] do
359 if VarIsArray(Value) then
360 Result := IncMinute(Value[0],-Value[1])
361 else
362 Result := FOwner.FParams[FIndex].Value;
363 end;
364
365 function TParamIntf.GetAsDouble: Double;
366 begin
367 Result := FOwner.FParams[FIndex].Value;
368 end;
369
370 function TParamIntf.GetAsFloat: Float;
371 begin
372 Result := FOwner.FParams[FIndex].Value;
373 end;
374
375 function TParamIntf.GetAsLong: Long;
376 begin
377 Result := FOwner.FParams[FIndex].Value;
378 end;
379
380 function TParamIntf.GetAsPointer: Pointer;
381 begin
382 IBError(ibxeNotSupported,[]);
383 end;
384
385 function TParamIntf.GetAsQuad: TISC_QUAD;
386 begin
387 IBError(ibxeNotSupported,[]);
388 end;
389
390 function TParamIntf.GetAsShort: short;
391 begin
392 Result := FOwner.FParams[FIndex].Value;
393 end;
394
395 function TParamIntf.GetAsString: AnsiString;
396 var v: variant;
397 begin
398 v := FOwner.FParams[FIndex].Value;
399 Case varType(v) of
400 varEmpty,
401 varNull:
402 Result := '';
403 varShortInt,
404 varSmallint,
405 varInteger,
406 varInt64,
407 varByte,
408 varWord,
409 varDecimal,
410 varLongWord,
411 varQWord,
412 varSingle:
413 Result := IntToStr(v);
414 varCurrency,
415 varDouble:
416 Result := FloatToStr(v);
417 varDate:
418 Result := DateTimeToStr(v);
419 varStrArg,
420 varString:
421 Result := v;
422 varBoolean:
423 if v then
424 Result := 'true'
425 else
426 Result := 'false';
427 varVariant:
428 Result := v;
429 else
430 Result := v;
431 end;
432 end;
433
434 function TParamIntf.GetIsNull: boolean;
435 begin
436 Result := VarIsNull(FOwner.FParams[FIndex].Value);
437 end;
438
439 function TParamIntf.GetAsVariant: Variant;
440 begin
441 Result := FOwner.FParams[FIndex].Value;
442 end;
443
444 function TParamIntf.GetAsBlob: IBlob;
445 begin
446 IBError(ibxeNotSupported,[]);
447 end;
448
449 function TParamIntf.GetAsArray: IArray;
450 begin
451 IBError(ibxeNotSupported,[]);
452 end;
453
454 function TParamIntf.GetAsBCD: tBCD;
455 begin
456 Result := VarToBCD(FOwner.FParams[FIndex].Value);
457 end;
458
459 function TParamIntf.GetStatement: IStatement;
460 begin
461 IBError(ibxeNotSupported,[]);
462 end;
463
464 function TParamIntf.GetTransaction: ITransaction;
465 begin
466 IBError(ibxeNotSupported,[]);
467 end;
468
469 procedure TParamIntf.Clear;
470 begin
471 FOwner.SetParam(FIndex,NULL);
472 end;
473
474 function TParamIntf.GetModified: boolean;
475 begin
476 Result := FOwner.FParams[FIndex].Modified;
477 end;
478
479 procedure TParamIntf.SetAsBoolean(AValue: boolean);
480 begin
481 FOwner.SetParam(FIndex,AValue);
482 end;
483
484 procedure TParamIntf.SetAsCurrency(aValue: Currency);
485 begin
486 FOwner.SetParam(FIndex,AValue);
487 end;
488
489 procedure TParamIntf.SetAsInt64(aValue: Int64);
490 begin
491 FOwner.SetParam(FIndex,AValue);
492 end;
493
494 procedure TParamIntf.SetAsDate(aValue: TDateTime);
495 begin
496 FOwner.SetParam(FIndex,AValue);
497 end;
498
499 procedure TParamIntf.SetAsLong(aValue: Long);
500 begin
501 FOwner.SetParam(FIndex,AValue);
502 end;
503
504 procedure TParamIntf.SetAsTime(aValue: TDateTime);
505 begin
506 FOwner.SetParam(FIndex,AValue);
507 end;
508
509 procedure TParamIntf.SetAsTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID);
510 begin
511 SetAsTime(aValue,(GetDataSet as TIBCustomDataSet).DefaultTZDate,aTimeZoneID);
512 end;
513
514 procedure TParamIntf.SetAsTime(aValue: TDateTime; aTimeZone: AnsiString);
515 begin
516 SetAsTime(aValue,(GetDataSet as TIBCustomDataSet).DefaultTZDate,aTimeZone);
517 end;
518
519 procedure TParamIntf.SetAsTime(aValue: TDateTime; OnDate: TDateTime;
520 aTimeZoneID: TFBTimeZoneID);
521 var dstOffset: smallint;
522 begin
523 aValue := TimeOf(aValue);
524 dstOffset := FOwner.Database.Attachment.GetTimeZoneServices.GetEffectiveOffsetMins(OnDate + aValue,aTimeZoneID);
525 FOwner.SetParam(FIndex,VarArrayOf([aValue,dstOffset,aTimeZoneID]));
526 end;
527
528 procedure TParamIntf.SetAsTime(aValue: TDateTime; OnDate: TDateTime;
529 aTimeZone: AnsiString);
530 var dstOffset: smallint;
531 begin
532 aValue := TimeOf(aValue);
533 dstOffset := FOwner.Database.Attachment.GetTimeZoneServices.GetEffectiveOffsetMins(OnDate + aValue,aTimeZone);
534 FOwner.SetParam(FIndex,VarArrayOf([aValue,dstOffset,aTimeZone]));
535 end;
536
537 procedure TParamIntf.SetAsDateTime(aValue: TDateTime);
538 begin
539 FOwner.SetParam(FIndex,AValue);
540 end;
541
542 procedure TParamIntf.SetAsDateTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID
543 );
544 var dstOffset: smallint;
545 begin
546 with FOwner.DataBase.attachment.GetTimeZoneServices do
547 begin
548 dstOffset := GetEffectiveOffsetMins(aValue,aTimeZoneID);
549 FOwner.SetParam(FIndex,VarArrayOf([aValue,aTimeZoneID]));
550 end;
551 end;
552
553 procedure TParamIntf.SetAsDateTime(aValue: TDateTime; aTimeZone: AnsiString);
554 var dstOffset: smallint;
555 begin
556 with FOwner.DataBase.attachment.GetTimeZoneServices do
557 begin
558 dstOffset := GetEffectiveOffsetMins(aValue,aTimeZone);
559 FOwner.SetParam(FIndex,VarArrayOf([aValue,aTimeZone]));
560 end;
561 end;
562
563 procedure TParamIntf.SetAsUTCDateTime(aUTCTime: TDateTime);
564 begin
565 IBError(ibxeNotSupported,[]);
566 end;
567
568 procedure TParamIntf.SetAsDouble(aValue: Double);
569 begin
570 FOwner.SetParam(FIndex,AValue);
571 end;
572
573 procedure TParamIntf.SetAsFloat(aValue: Float);
574 begin
575 FOwner.SetParam(FIndex,AValue);
576 end;
577
578 procedure TParamIntf.SetAsPointer(aValue: Pointer);
579 begin
580 IBError(ibxeNotSupported,[]);
581 end;
582
583 procedure TParamIntf.SetAsShort(aValue: Short);
584 begin
585 FOwner.SetParam(FIndex,AValue);
586 end;
587
588 procedure TParamIntf.SetAsString(aValue: AnsiString);
589 begin
590 FOwner.SetParam(FIndex,AValue);
591 end;
592
593 procedure TParamIntf.SetAsVariant(aValue: Variant);
594 begin
595 FOwner.SetParam(FIndex,AValue);
596 end;
597
598 procedure TParamIntf.SetIsNull(aValue: Boolean);
599 begin
600 if aValue then
601 FOwner.SetParam(FIndex,NULL)
602 end;
603
604 procedure TParamIntf.SetAsBlob(aValue: IBlob);
605 begin
606 IBError(ibxeNotSupported,[]);
607 end;
608
609 procedure TParamIntf.SetAsArray(anArray: IArray);
610 begin
611 IBError(ibxeNotSupported,[]);
612 end;
613
614 procedure TParamIntf.SetAsQuad(aValue: TISC_QUAD);
615 begin
616 IBError(ibxeNotSupported,[]);
617 end;
618
619 procedure TParamIntf.SetCharSetID(aValue: cardinal);
620 var s: RawByteString;
621 codepage: TSystemCodePage;
622 str: string;
623 begin
624 str := FOwner.FParams[FIndex].Value;
625 s := str;
626 if FOwner.Database.Attachment.CharSetID2CodePage(aValue,codepage) then
627 SetCodePage(s,codepage,codepage <> cp_none);
628 end;
629
630 procedure TParamIntf.SetAsBcd(aValue: tBCD);
631 begin
632 FOwner.SetParam(FIndex,VarFmtBCDCreate(AValue));
633 end;
634
635 { TParamListIntf }
636
637 procedure TParamListIntf.SetParam(index: integer; aValue: variant);
638 begin
639 FParams[index].Value := aValue;
640 FParams[index].Modified := true;
641 FParams[index].TimeZoneID := TimeZoneID_GMT;
642 FModified := true;
643 end;
644
645 procedure TParamListIntf.SetTimeZoneID(index: integer; aValue: TFBTimeZoneID);
646 begin
647 if FParams[index].Modified then
648 FParams[index].TimeZoneID := aValue;
649 end;
650
651 constructor TParamListIntf.Create(aFields: TFields; aDatabase: TIBDatabase);
652 var i,j: integer;
653 begin
654 inherited Create;
655 FDatabase := aDatabase;
656 SetLength(FParams,aFields.Count*2);
657 j := 0;
658 {set up both current and "OLD" parameters from Field Names}
659 for i := 0 to aFields.Count - 1 do
660 if aFields[i].FieldKind = fkData then
661 begin
662 FParams[j].Name := aFields[i].FieldName;
663 FParams[j].Value := NULL;
664 FParams[j].Modified := false;
665 FParams[j].DataSet := aFields[i].DataSet;
666 Inc(j);
667 FParams[j].Name := 'OLD_' + aFields[i].FieldName;
668 FParams[j].Value := NULL;
669 FParams[j].Modified := false;
670 FParams[j].DataSet := aFields[i].DataSet;
671 Inc(j);
672 end;
673 SetLength(FParams,j);
674 end;
675
676 destructor TParamListIntf.Destroy;
677 begin
678 SetLength(FParams,0);
679 inherited Destroy;
680 end;
681
682 function TParamListIntf.getCount: integer;
683 begin
684 Result := Length(FParams);
685 end;
686
687 function TParamListIntf.getSQLParam(index: integer): ISQLParam;
688 begin
689 if (index < 0) or (index >= getCount) then
690 IBError(ibxeInvalidColumnIndex,[nil]);
691 Result := TParamIntf.Create(self,index);
692 end;
693
694 function TParamListIntf.ByName(Idx: AnsiString): ISQLParam;
695 var i: integer;
696 begin
697 Result := nil;
698 for i := 0 to getCount - 1 do
699 if CompareText(FParams[i].Name,Idx) = 0 then
700 begin
701 Result := getSQLParam(i);
702 Exit;
703 end;
704 end;
705
706 function TParamListIntf.GetModified: Boolean;
707 begin
708 Result := FModified;
709 end;
710
711 function TParamListIntf.GetHasCaseSensitiveParams: Boolean;
712 begin
713 Result := false;
714 end;
715
716 { TIBUpdate }
717
718 function TIBUpdate.GetSQL(UpdateKind: TUpdateKind): TStrings;
719 begin
720 Result := FDummySQL; {non empty result}
721 end;
722
723 function TIBUpdate.GetDataSet: TIBCustomDataSet;
724 begin
725 Result := FDataSet;
726 end;
727
728 procedure TIBUpdate.SetDataSet(ADataSet: TIBCustomDataSet);
729 begin
730 FDataSet := ADataset;
731 end;
732
733 procedure TIBUpdate.Apply(UpdateKind: TUpdateKind; buff: PChar);
734 var Params: ISQLParams;
735 begin
736 Params := TParamListIntf.Create(Dataset.Fields,(DataSet.Database as TIBDatabase));
737 InternalSetParams(Params,buff);
738 if assigned(FOnApplyUpdates) then
739 OnApplyUpdates(self,UpdateKind,Params);
740 end;
741
742 constructor TIBUpdate.Create(AOwner: TComponent);
743 begin
744 inherited Create(AOwner);
745 FDummySQL := TStringList.Create;
746 FDummySQL.Text := '*';
747 end;
748
749 destructor TIBUpdate.Destroy;
750 begin
751 if assigned(FDummySQL) then FDummySQL.Free;
752 inherited Destroy;
753 end;
754
755 end.
756