ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/nongui/IBUpdate.pas
(Generate patch)

Comparing ibx/trunk/runtime/nongui/IBUpdate.pas (file contents):
Revision 291 by tony, Fri Apr 17 10:26:08 2020 UTC vs.
Revision 402 by tony, Mon Aug 1 10:07:24 2022 UTC

# Line 15 | Line 15
15   *
16   *  The Initial Developer of the Original Code is Tony Whyman.
17   *
18 < *  The Original Code is (C) 2015 Tony Whyman, MWA Software
18 > *  The Original Code is (C) 2015-2020 Tony Whyman, MWA Software
19   *  (http://www.mwasoftware.co.uk).
20   *
21   *  All Rights Reserved.
# Line 60 | Line 60 | type
60  
61   implementation
62  
63 < uses variants;
63 > uses variants, FmtBCD, DateUtils, FBNumeric;
64  
65   type
66  
# Line 72 | Line 72 | type
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;
# Line 86 | Line 89 | type
89      {ISQLParams}
90      function getCount: integer;
91      function getSQLParam(index: integer): ISQLParam;
92 +    function ParamExists(Idx: AnsiString): boolean;
93      function ByName(Idx: AnsiString): ISQLParam ;
94      function GetModified: Boolean;
95      function GetHasCaseSensitiveParams: Boolean;
96 +    function GetStatement: IStatement;
97 +    function GetTransaction: ITransaction;
98 +    function GetAttachment: IAttachment;
99 +    procedure Clear;
100    end;
101  
102    { TParamIntf }
# Line 97 | Line 105 | type
105    private
106      FIndex: integer;
107      FOwner: TParamListIntf;
108 +    function GetDataSet: TDataSet;
109    public
110      constructor Create(aOwner: TParamListIntf; aIndex: integer);
111 +    function getColMetadata: IParamMetaData;
112      function GetIndex: integer;
113      function GetSQLType: cardinal;
114      function GetSQLTypeName: AnsiString;
# Line 112 | Line 122 | type
122      function GetAsBoolean: boolean;
123      function GetAsCurrency: Currency;
124      function GetAsInt64: Int64;
125 <    function GetAsDateTime: TDateTime;
125 >    function GetAsDateTime: TDateTime; overload;
126 >    procedure GetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload;
127 >    procedure GetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload;
128 >    procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime); overload;
129 >    procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString; OnDate: TDateTime); overload;
130 >    procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload;
131 >    procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload;
132 >    function GetAsUTCDateTime: TDateTime;
133      function GetAsDouble: Double;
134      function GetAsFloat: Float;
135      function GetAsLong: Long;
# Line 124 | Line 141 | type
141      function GetAsVariant: Variant;
142      function GetAsBlob: IBlob;
143      function GetAsArray: IArray;
144 +    function GetAsBCD: tBCD;
145 +    function GetAsNumeric: IFBNumeric;
146 +    function GetStatement: IStatement;
147 +    function GetTransaction: ITransaction;
148 +    function GetAttachment: IAttachment;
149      procedure Clear;
150      function GetModified: boolean;
151      procedure SetAsBoolean(AValue: boolean);
# Line 131 | Line 153 | type
153      procedure SetAsInt64(aValue: Int64);
154      procedure SetAsDate(aValue: TDateTime);
155      procedure SetAsLong(aValue: Long);
156 <    procedure SetAsTime(aValue: TDateTime);
157 <    procedure SetAsDateTime(aValue: TDateTime);
156 >    procedure SetAsTime(aValue: TDateTime); overload;
157 >    procedure SetAsTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
158 >    procedure SetAsTime(aValue: TDateTime; aTimeZone: AnsiString); overload;
159 >    procedure SetAsTime(aValue: TDateTime; OnDate: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
160 >    procedure SetAsTime(aValue: TDateTime; OnDate: TDateTime; aTimeZone: AnsiString); overload;
161 >    procedure SetAsDateTime(aValue: TDateTime); overload;
162 >    procedure SetAsDateTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
163 >    procedure SetAsDateTime(aValue: TDateTime; aTimeZone: AnsiString); overload;
164 >    procedure SetAsUTCDateTime(aUTCTime: TDateTime);
165      procedure SetAsDouble(aValue: Double);
166      procedure SetAsFloat(aValue: Float);
167      procedure SetAsPointer(aValue: Pointer);
# Line 144 | Line 173 | type
173      procedure SetAsArray(anArray: IArray);
174      procedure SetAsQuad(aValue: TISC_QUAD);
175      procedure SetCharSetID(aValue: cardinal);
176 +    procedure SetAsBcd(aValue: tBCD);
177 +    procedure SetAsNumeric(Value: IFBNumeric);
178    end;
179  
180   { TParamIntf }
181  
182 + function TParamIntf.GetDataSet: TDataSet;
183 + begin
184 +  Result := FOwner.FParams[FIndex].DataSet;
185 + end;
186 +
187   constructor TParamIntf.Create(aOwner: TParamListIntf; aIndex: integer);
188   begin
189    FOwner := aOwner;
190    FIndex := aIndex;
191   end;
192  
193 + function TParamIntf.getColMetadata: IParamMetaData;
194 + begin
195 +  IBError(ibxeNotSupported,[]);
196 + end;
197 +
198   function TParamIntf.GetIndex: integer;
199   begin
200    Result := Findex;
# Line 226 | Line 267 | begin
267    Result := FOwner.FParams[FIndex].Value;
268   end;
269  
270 + procedure TParamIntf.GetAsDateTime(var aDateTime: TDateTime;
271 +  var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID);
272 + begin
273 +  with FOwner.FParams[FIndex] do
274 +  if VarIsArray(Value) then
275 +  begin
276 +    aDateTime := Value[0];
277 +    dstOffset := Value[1];
278 +    if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
279 +      aTimezoneID := Value[2]
280 +    else
281 +      aTimeZoneID := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneName2TimeZoneID(Value[2]);
282 +  end
283 +  else
284 +  begin
285 +    aDateTime := FOwner.FParams[FIndex].Value;
286 +    dstOffset := 0;
287 +    aTimeZoneID := TimeZoneID_GMT;
288 +  end;
289 + end;
290 +
291 + procedure TParamIntf.GetAsDateTime(var aDateTime: TDateTime;
292 +  var dstOffset: smallint; var aTimezone: AnsiString);
293 + begin
294 +  with FOwner.FParams[FIndex] do
295 +  if VarIsArray(Value) then
296 +  begin
297 +    aDateTime := Value[0];
298 +    dstOffset := Value[1];
299 +    if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
300 +      aTimeZone := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneID2TimeZoneName(Value[2])
301 +    else
302 +      aTimezone := Value[2];
303 +  end
304 +  else
305 +  begin
306 +    aDateTime := FOwner.FParams[FIndex].Value;
307 +    dstOffset := 0;
308 +    aTimeZone := 'GMT';
309 +  end;
310 + end;
311 +
312 + procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
313 +  var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime);
314 + var LocalTime: TDateTime;
315 + begin
316 +  with FOwner.FParams[FIndex] do
317 +  if VarIsArray(Value) then
318 +  begin
319 +    LocalTime := OnDate + TimeOf(Value[0]);
320 +    dstOffset := Value[1];
321 +    if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
322 +      aTimezoneID := Value[2]
323 +    else
324 +      aTimeZoneID := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneName2TimeZoneID(Value[2]);
325 +    aTime := TimeOf(FOwner.DataBase.attachment.GetTimeZoneServices.GMTToLocalTime(IncMinute(LocalTime,-dstOffset),aTimeZoneID))
326 +  end
327 +  else
328 +  begin
329 +    aTime := FOwner.FParams[FIndex].Value;
330 +    dstOffset := 0;
331 +    aTimeZoneID := TimeZoneID_GMT;
332 +  end;
333 + end;
334 +
335 + procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
336 +  var aTimezone: AnsiString; OnDate: TDateTime);
337 + var LocalTime: TDateTime;
338 + begin
339 +  with FOwner.FParams[FIndex] do
340 +  if VarIsArray(Value) then
341 +  begin
342 +    LocalTime := OnDate + TimeOf(Value[0]);
343 +    dstOffset := Value[1];
344 +    if VarType(Value[2]) in [varSmallint, varInteger, varByte, varWord, varShortInt] then
345 +      aTimeZone := FOwner.DataBase.attachment.GetTimeZoneServices.TimeZoneID2TimeZoneName(Value[2])
346 +    else
347 +      aTimezone := Value[2];
348 +    aTime := TimeOf(FOwner.DataBase.attachment.GetTimeZoneServices.GMTToLocalTime(IncMinute(LocalTime,-dstOffset),aTimeZone))
349 +  end
350 +  else
351 +  begin
352 +    aTime := FOwner.FParams[FIndex].Value;
353 +    dstOffset := 0;
354 +    aTimeZone := 'GMT';
355 +  end;
356 + end;
357 +
358 + procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
359 +  var aTimezoneID: TFBTimeZoneID);
360 + begin
361 +  GetAsTime(aTime,dstOffset,aTimeZoneID,(GetDataSet as TIBCustomDataSet).DefaultTZDate);
362 + end;
363 +
364 + procedure TParamIntf.GetAsTime(var aTime: TDateTime; var dstOffset: smallint;
365 +  var aTimezone: AnsiString);
366 + begin
367 +  GetAsTime(aTime,dstOffset,aTimeZone,(GetDataSet as TIBCustomDataSet).DefaultTZDate);
368 + end;
369 +
370 + function TParamIntf.GetAsUTCDateTime: TDateTime;
371 + begin
372 +  with FOwner.FParams[FIndex] do
373 +  if VarIsArray(Value) then
374 +    Result := IncMinute(Value[0],-Value[1])
375 +  else
376 +    Result := FOwner.FParams[FIndex].Value;
377 + end;
378 +
379   function TParamIntf.GetAsDouble: Double;
380   begin
381    Result := FOwner.FParams[FIndex].Value;
# Line 315 | Line 465 | begin
465    IBError(ibxeNotSupported,[]);
466   end;
467  
468 + function TParamIntf.GetAsBCD: tBCD;
469 + begin
470 +  Result := VarToBCD(FOwner.FParams[FIndex].Value);
471 + end;
472 +
473 + function TParamIntf.GetAsNumeric: IFBNumeric;
474 + begin
475 +  IBError(ibxeNotSupported,[]);
476 + end;
477 +
478 + function TParamIntf.GetStatement: IStatement;
479 + begin
480 +  IBError(ibxeNotSupported,[]);
481 + end;
482 +
483 + function TParamIntf.GetTransaction: ITransaction;
484 + begin
485 +  IBError(ibxeNotSupported,[]);
486 + end;
487 +
488 + function TParamIntf.GetAttachment: IAttachment;
489 + begin
490 +  IBError(ibxeNotSupported,[]);
491 + end;
492 +
493   procedure TParamIntf.Clear;
494   begin
495    FOwner.SetParam(FIndex,NULL);
# Line 355 | Line 530 | begin
530    FOwner.SetParam(FIndex,AValue);
531   end;
532  
533 + procedure TParamIntf.SetAsTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID);
534 + begin
535 +  SetAsTime(aValue,(GetDataSet as TIBCustomDataSet).DefaultTZDate,aTimeZoneID);
536 + end;
537 +
538 + procedure TParamIntf.SetAsTime(aValue: TDateTime; aTimeZone: AnsiString);
539 + begin
540 +  SetAsTime(aValue,(GetDataSet as TIBCustomDataSet).DefaultTZDate,aTimeZone);
541 + end;
542 +
543 + procedure TParamIntf.SetAsTime(aValue: TDateTime; OnDate: TDateTime;
544 +  aTimeZoneID: TFBTimeZoneID);
545 + var dstOffset: smallint;
546 + begin
547 +  aValue := TimeOf(aValue);
548 +  dstOffset := FOwner.Database.Attachment.GetTimeZoneServices.GetEffectiveOffsetMins(OnDate + aValue,aTimeZoneID);
549 +  FOwner.SetParam(FIndex,VarArrayOf([aValue,dstOffset,aTimeZoneID]));
550 + end;
551 +
552 + procedure TParamIntf.SetAsTime(aValue: TDateTime; OnDate: TDateTime;
553 +  aTimeZone: AnsiString);
554 + var dstOffset: smallint;
555 + begin
556 +  aValue := TimeOf(aValue);
557 +  dstOffset := FOwner.Database.Attachment.GetTimeZoneServices.GetEffectiveOffsetMins(OnDate + aValue,aTimeZone);
558 +  FOwner.SetParam(FIndex,VarArrayOf([aValue,dstOffset,aTimeZone]));
559 + end;
560 +
561   procedure TParamIntf.SetAsDateTime(aValue: TDateTime);
562   begin
563    FOwner.SetParam(FIndex,AValue);
564   end;
565  
566 + procedure TParamIntf.SetAsDateTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID
567 +  );
568 + var dstOffset: smallint;
569 + begin
570 +  with FOwner.DataBase.attachment.GetTimeZoneServices do
571 +  begin
572 +    dstOffset := GetEffectiveOffsetMins(aValue,aTimeZoneID);
573 +    FOwner.SetParam(FIndex,VarArrayOf([aValue,aTimeZoneID]));
574 +  end;
575 + end;
576 +
577 + procedure TParamIntf.SetAsDateTime(aValue: TDateTime; aTimeZone: AnsiString);
578 + var dstOffset: smallint;
579 + begin
580 +  with FOwner.DataBase.attachment.GetTimeZoneServices do
581 +  begin
582 +    dstOffset := GetEffectiveOffsetMins(aValue,aTimeZone);
583 +    FOwner.SetParam(FIndex,VarArrayOf([aValue,aTimeZone]));
584 +  end;
585 + end;
586 +
587 + procedure TParamIntf.SetAsUTCDateTime(aUTCTime: TDateTime);
588 + begin
589 +  IBError(ibxeNotSupported,[]);
590 + end;
591 +
592   procedure TParamIntf.SetAsDouble(aValue: Double);
593   begin
594    FOwner.SetParam(FIndex,AValue);
# Line 422 | Line 651 | begin
651      SetCodePage(s,codepage,codepage <> cp_none);
652   end;
653  
654 + procedure TParamIntf.SetAsBcd(aValue: tBCD);
655 + begin
656 +  FOwner.SetParam(FIndex,VarFmtBCDCreate(AValue));
657 + end;
658 +
659 + procedure TParamIntf.SetAsNumeric(Value: IFBNumeric);
660 + begin
661 +  IBError(ibxeNotSupported,[]);
662 + end;
663 +
664   { TParamListIntf }
665  
666   procedure TParamListIntf.SetParam(index: integer; aValue: variant);
667   begin
668    FParams[index].Value := aValue;
669    FParams[index].Modified := true;
670 +  FParams[index].TimeZoneID := TimeZoneID_GMT;
671    FModified := true;
672   end;
673  
674 + procedure TParamListIntf.SetTimeZoneID(index: integer; aValue: TFBTimeZoneID);
675 + begin
676 +  if FParams[index].Modified then
677 +    FParams[index].TimeZoneID := aValue;
678 + end;
679 +
680   constructor TParamListIntf.Create(aFields: TFields; aDatabase: TIBDatabase);
681   var i,j: integer;
682   begin
# Line 445 | Line 691 | begin
691      FParams[j].Name := aFields[i].FieldName;
692      FParams[j].Value := NULL;
693      FParams[j].Modified := false;
694 +    FParams[j].DataSet := aFields[i].DataSet;
695      Inc(j);
696      FParams[j].Name := 'OLD_' + aFields[i].FieldName;
697      FParams[j].Value := NULL;
698      FParams[j].Modified := false;
699 +    FParams[j].DataSet := aFields[i].DataSet;
700      Inc(j);
701    end;
702    SetLength(FParams,j);
# Line 472 | Line 720 | begin
720    Result := TParamIntf.Create(self,index);
721   end;
722  
723 + function TParamListIntf.ParamExists(Idx: AnsiString): boolean;
724 + begin
725 +  Result := ByName(Idx) <> nil;
726 + end;
727 +
728   function TParamListIntf.ByName(Idx: AnsiString): ISQLParam;
729   var i: integer;
730   begin
# Line 494 | Line 747 | begin
747    Result := false;
748   end;
749  
750 + function TParamListIntf.GetStatement: IStatement;
751 + begin
752 +  IBError(ibxeNotSupported,[]);
753 + end;
754 +
755 + function TParamListIntf.GetTransaction: ITransaction;
756 + begin
757 +  IBError(ibxeNotSupported,[]);
758 + end;
759 +
760 + function TParamListIntf.GetAttachment: IAttachment;
761 + begin
762 +  Result := Database.Attachment;
763 + end;
764 +
765 + procedure TParamListIntf.Clear;
766 + var i: integer;
767 + begin
768 +  for i := 0 to getCount - 1 do
769 +    getSQLParam(i).Clear;
770 + end;
771 +
772   { TIBUpdate }
773  
774   function TIBUpdate.GetSQL(UpdateKind: TUpdateKind): TStrings;

Comparing ibx/trunk/runtime/nongui/IBUpdate.pas (property svn:eol-style):
Revision 291 by tony, Fri Apr 17 10:26:08 2020 UTC vs.
Revision 402 by tony, Mon Aug 1 10:07:24 2022 UTC

# Line 0 | Line 1
1 + native

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines