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

Comparing ibx/trunk/runtime/IBBatchMove.pas (file contents):
Revision 17 by tony, Sat Dec 28 19:22:24 2013 UTC vs.
Revision 143 by tony, Fri Feb 23 12:11:21 2018 UTC

# Line 1 | Line 1
1 < {************************************************************************}
2 < {                                                                        }
3 < {       Borland Delphi Visual Component Library                          }
4 < {       InterBase Express core components                                }
5 < {                                                                        }
6 < {       Copyright (c) 1998-2000 Inprise Corporation                      }
7 < {                                                                        }
8 < {    InterBase Express is based in part on the product                   }
9 < {    Free IB Components, written by Gregory H. Deatz for                 }
10 < {    Hoagland, Longo, Moran, Dunst & Doukas Company.                     }
11 < {    Free IB Components is used under license.                           }
12 < {                                                                        }
13 < {    The contents of this file are subject to the InterBase              }
14 < {    Public License Version 1.0 (the "License"); you may not             }
15 < {    use this file except in compliance with the License. You            }
16 < {    may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17 < {    Software distributed under the License is distributed on            }
18 < {    an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either              }
19 < {    express or implied. See the License for the specific language       }
20 < {    governing rights and limitations under the License.                 }
21 < {    The Original Code was created by InterBase Software Corporation     }
22 < {       and its successors.                                              }
23 < {    Portions created by Inprise Corporation are Copyright (C) Inprise   }
24 < {       Corporation. All Rights Reserved.                                }
25 < {    Contributor(s): Jeff Overcash                                       }
26 < {                                                                        }
27 < {    IBX For Lazarus (Firebird Express)                                  }
28 < {    Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
29 < {    Portions created by MWA Software are copyright McCallum Whyman      }
30 < {    Associates Ltd 2011                                                 }
31 < {                                                                        }
32 < {************************************************************************}
33 <
34 < unit IBBatchMove;
35 <
36 < {$Mode Delphi}
37 <
38 < interface
39 <
40 < uses
41 < {$IFDEF WINDOWS }
42 <  Windows,
43 < {$ELSE}
44 <  unix,
45 < {$ENDIF}
46 <  SysUtils, {Graphics,} Classes, Controls, Db,
47 <     IB, IBCustomDataSet, IBDatabase, IBTable;
48 <
49 < type
50 <  TBatchMode = (batAppend, batUpdate, batAppendUpdate, batDelete, batCopy);
51 <
52 < { TBatchMove }
53 <
54 <  TIBBatchMove = class(TComponent)
55 <  private
56 <    FIBLoaded: Boolean;
57 <    FDestination: TIBTable;
58 <    FSource: TIBCustomDataSet;
59 <    FMode: TBatchMode;
60 <    FAbortOnKeyViol: Boolean;
61 <    FAbortOnProblem: Boolean;
62 <    FTransliterate: Boolean;
63 <    FRecordCount: Longint;
64 <    FMovedCount: Longint;
65 <    FKeyViolCount: Longint;
66 <    FProblemCount: Longint;
67 <    FChangedCount: Longint;
68 <    FMappings: TStrings;
69 <    FKeyViolTableName: TFileName;
70 <    FProblemTableName: TFileName;
71 <    FChangedTableName: TFileName;
72 <    FCommitCount: Integer;
73 <    procedure SetMappings(Value: TStrings);
74 <    procedure SetSource(Value: TIBCustomDataSet);
75 <    procedure InternalExecute (BatchMode: TBatchMode; FieldCount: Word);
76 <  protected
77 <    procedure Notification(AComponent: TComponent;
78 <      Operation: TOperation); override;
79 <  public
80 <    constructor Create(AOwner: TComponent); override;
81 <    destructor Destroy; override;
82 <    procedure Execute;
83 <  public
84 <    property ChangedCount: Longint read FChangedCount;
85 <    property KeyViolCount: Longint read FKeyViolCount;
86 <    property MovedCount: Longint read FMovedCount;
87 <    property ProblemCount: Longint read FProblemCount;
88 <  published
89 <    property AbortOnKeyViol: Boolean read FAbortOnKeyViol write FAbortOnKeyViol
90 <                                                          default True;
91 <    property AbortOnProblem: Boolean read FAbortOnProblem write FAbortOnProblem
92 <                                                          default True;
93 <    property CommitCount: Integer read FCommitCount write FCommitCount default 0;
94 <    property ChangedTableName: TFileName read FChangedTableName write FChangedTableName;
95 <    property Destination: TIBTable read FDestination write FDestination;
96 <    property KeyViolTableName: TFileName read FKeyViolTableName write FKeyViolTableName;
97 <    property Mappings: TStrings read FMappings write SetMappings;
98 <    property Mode: TBatchMode read FMode write FMode default batAppend;
99 <    property ProblemTableName: TFileName read FProblemTableName write FProblemTableName;
100 <    property RecordCount: Longint read FRecordCount write FRecordCount default 0;
101 <    property Source: TIBCustomDataSet read FSource write SetSource;
102 <    property Transliterate: Boolean read FTransliterate write FTransliterate
103 <                                                        default True;
104 <  end;
105 <
106 < implementation
107 <
108 < uses IBIntf;
109 <
110 < { TIBBatchMove }
111 <
112 < constructor TIBBatchMove.Create(AOwner: TComponent);
113 < begin
114 <  inherited Create(AOwner);
115 <  FIBLoaded := False;
116 <  CheckIBLoaded;
117 <  FIBLoaded := True;
118 <  FAbortOnKeyViol := True;
119 <  FAbortOnProblem := True;
120 <  FTransliterate := True;
121 <  FMappings := TStringList.Create;
122 < end;
123 <
124 < destructor TIBBatchMove.Destroy;
125 < begin
126 <  if FIBLoaded then
127 <  FMappings.Free;
128 <  inherited Destroy;
129 < end;
130 <
131 < procedure TIBBatchMove.Execute;
132 < type
133 <  TFieldMap = array of Word;
134 < var
135 <  SourceActive, DestinationActive: Boolean;
136 <  BatchMode: TBatchMode;
137 <  I: Integer;
138 <  FieldCount: Word;
139 <  FieldMap: TFieldMap;
140 <  DestName, SourceName: string;
141 <
142 <  procedure GetMappingNames;
143 <  var
144 <    P: Integer;
145 <    Mapping: string;
146 <  begin
147 <    Mapping := FMappings[I];
148 <    P := Pos('=', Mapping); {MBCS OK}
149 <    if P > 0 then
150 <    begin
151 <      DestName := Copy(Mapping, 1, P - 1);
152 <      SourceName := Copy(Mapping, P + 1, 255);
153 <    end
154 <    else begin
155 <      DestName := Mapping;
156 <      SourceName := Mapping;
157 <    end;
158 <  end;
159 <
160 < begin
161 <  if (Destination = nil) or (Source = nil) or (Destination = Source) then
162 <    IBError(ibxeInvalidBatchMove, [nil]);
163 <  SourceActive := Source.Active;
164 <  DestinationActive := Destination.Active;
165 <  FieldCount := 0;
166 <  FieldMap := nil;
167 <  try
168 <    Source.DisableControls;
169 <    Destination.DisableControls;
170 <    Source.Open;
171 <    Source.CheckBrowseMode;
172 <    Source.UpdateCursorPos;
173 <    BatchMode := FMode;
174 <    if BatchMode = batCopy then
175 <    begin
176 <      Destination.Close;
177 <      if FMappings.Count = 0 then
178 <        Destination.FieldDefs := Source.FieldDefs
179 <      else
180 <      begin
181 <        Destination.FieldDefs.Clear;
182 <        for I := 0 to FMappings.Count - 1 do
183 <        begin
184 <          GetMappingNames;
185 <          with Source.FieldDefs.Find(SourceName) do
186 <            Destination.FieldDefs.Add(DestName, DataType, Size, Required);
187 <        end;
188 <      end;
189 <      Destination.IndexDefs.Clear;
190 <      Destination.CreateTable;
191 <      BatchMode := batAppend;
192 <    end;
193 <    Destination.Open;
194 <    Destination.CheckBrowseMode;
195 <    if FMappings.Count <> 0 then
196 <    begin
197 <      FieldCount := Destination.FieldDefs.Count;
198 <      SetLength(FieldMap, FieldCount);
199 <      for I := 0 to FMappings.Count - 1 do
200 <      begin
201 <        GetMappingNames;
202 <        FieldMap[Destination.FieldDefs.Find(DestName).FieldNo-1] :=
203 <          Source.FieldDefs.Find(SourceName).FieldNo;
204 <      end;
205 <    end;
206 <    if FRecordCount > 0 then
207 <    begin
208 <      Source.UpdateCursorPos;
209 <      FMovedCount := FRecordCount;
210 <    end else
211 <    begin
212 <      FMovedCount := MaxLongint;
213 <    end;
214 <    Source.CursorPosChanged;
215 <    try
216 <      InternalExecute (BatchMode, FieldCount);
217 <    finally
218 <      if DestinationActive then Destination.First;
219 <    end;
220 <  finally
221 <    if not DestinationActive then
222 <      Destination.Close;
223 <    if not SourceActive then
224 <      Source.Close;
225 <    Destination.EnableControls;
226 <    Source.EnableControls;
227 <  end;
228 < end;
229 <
230 < procedure TIBBatchMove.Notification(AComponent: TComponent;
231 <  Operation: TOperation);
232 < begin
233 <  inherited Notification(AComponent, Operation);
234 <  if Operation = opRemove then
235 <  begin
236 <    if Destination = AComponent then
237 <      Destination := nil;
238 <    if Source = AComponent then
239 <      Source := nil;
240 <  end;
241 < end;
242 <
243 < procedure TIBBatchMove.SetMappings(Value: TStrings);
244 < begin
245 <  FMappings.Assign(Value);
246 < end;
247 <
248 < procedure TIBBatchMove.SetSource(Value: TIBCustomDataSet);
249 < begin
250 <  FSource := Value;
251 <  if Value <> nil then
252 <    Value.FreeNotification(Self);
253 < end;
254 <
255 <
256 < procedure TIBBatchMove.InternalExecute (BatchMode: TBatchMode; FieldCount: Word);
257 < begin
258 <
259 < end;
260 <
261 < end.
1 > {************************************************************************}
2 > {                                                                        }
3 > {       Borland Delphi Visual Component Library                          }
4 > {       InterBase Express core components                                }
5 > {                                                                        }
6 > {       Copyright (c) 1998-2000 Inprise Corporation                      }
7 > {                                                                        }
8 > {    InterBase Express is based in part on the product                   }
9 > {    Free IB Components, written by Gregory H. Deatz for                 }
10 > {    Hoagland, Longo, Moran, Dunst & Doukas Company.                     }
11 > {    Free IB Components is used under license.                           }
12 > {                                                                        }
13 > {    The contents of this file are subject to the InterBase              }
14 > {    Public License Version 1.0 (the "License"); you may not             }
15 > {    use this file except in compliance with the License. You            }
16 > {    may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17 > {    Software distributed under the License is distributed on            }
18 > {    an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either              }
19 > {    express or implied. See the License for the specific language       }
20 > {    governing rights and limitations under the License.                 }
21 > {    The Original Code was created by InterBase Software Corporation     }
22 > {       and its successors.                                              }
23 > {    Portions created by Inprise Corporation are Copyright (C) Inprise   }
24 > {       Corporation. All Rights Reserved.                                }
25 > {    Contributor(s): Jeff Overcash                                       }
26 > {                                                                        }
27 > {    IBX For Lazarus (Firebird Express)                                  }
28 > {    Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
29 > {    Portions created by MWA Software are copyright McCallum Whyman      }
30 > {    Associates Ltd 2011 - 2018                                               }
31 > {                                                                        }
32 > {************************************************************************}
33 >
34 > unit IBBatchMove;
35 >
36 > {$Mode Delphi}
37 >
38 > interface
39 >
40 > uses
41 > {$IFDEF WINDOWS }
42 >  Windows,
43 > {$ELSE}
44 >  unix,
45 > {$ENDIF}
46 >  SysUtils, Classes,  Db,
47 >     IB, IBCustomDataSet, IBDatabase, IBTable;
48 >
49 > type
50 >  TBatchMode = (batAppend, batUpdate, batAppendUpdate, batDelete, batCopy);
51 >
52 > { TBatchMove }
53 >
54 >  TIBBatchMove = class(TComponent)
55 >  private
56 >    FDestination: TIBTable;
57 >    FSource: TIBCustomDataSet;
58 >    FMode: TBatchMode;
59 >    FAbortOnKeyViol: Boolean;
60 >    FAbortOnProblem: Boolean;
61 >    FTransliterate: Boolean;
62 >    FRecordCount: Longint;
63 >    FMovedCount: Longint;
64 >    FKeyViolCount: Longint;
65 >    FProblemCount: Longint;
66 >    FChangedCount: Longint;
67 >    FMappings: TStrings;
68 >    FKeyViolTableName: TFileName;
69 >    FProblemTableName: TFileName;
70 >    FChangedTableName: TFileName;
71 >    FCommitCount: Integer;
72 >    procedure SetMappings(Value: TStrings);
73 >    procedure SetSource(Value: TIBCustomDataSet);
74 >    procedure InternalExecute (BatchMode: TBatchMode; FieldCount: Word);
75 >  protected
76 >    procedure Notification(AComponent: TComponent;
77 >      Operation: TOperation); override;
78 >  public
79 >    constructor Create(AOwner: TComponent); override;
80 >    destructor Destroy; override;
81 >    procedure Execute;
82 >  public
83 >    property ChangedCount: Longint read FChangedCount;
84 >    property KeyViolCount: Longint read FKeyViolCount;
85 >    property MovedCount: Longint read FMovedCount;
86 >    property ProblemCount: Longint read FProblemCount;
87 >  published
88 >    property AbortOnKeyViol: Boolean read FAbortOnKeyViol write FAbortOnKeyViol
89 >                                                          default True;
90 >    property AbortOnProblem: Boolean read FAbortOnProblem write FAbortOnProblem
91 >                                                          default True;
92 >    property CommitCount: Integer read FCommitCount write FCommitCount default 0;
93 >    property ChangedTableName: TFileName read FChangedTableName write FChangedTableName;
94 >    property Destination: TIBTable read FDestination write FDestination;
95 >    property KeyViolTableName: TFileName read FKeyViolTableName write FKeyViolTableName;
96 >    property Mappings: TStrings read FMappings write SetMappings;
97 >    property Mode: TBatchMode read FMode write FMode default batAppend;
98 >    property ProblemTableName: TFileName read FProblemTableName write FProblemTableName;
99 >    property RecordCount: Longint read FRecordCount write FRecordCount default 0;
100 >    property Source: TIBCustomDataSet read FSource write SetSource;
101 >    property Transliterate: Boolean read FTransliterate write FTransliterate
102 >                                                        default True;
103 >  end;
104 >
105 > implementation
106 >
107 > uses FBMessages;
108 >
109 > { TIBBatchMove }
110 >
111 > constructor TIBBatchMove.Create(AOwner: TComponent);
112 > begin
113 >  inherited Create(AOwner);
114 >  FAbortOnKeyViol := True;
115 >  FAbortOnProblem := True;
116 >  FTransliterate := True;
117 >  FMappings := TStringList.Create;
118 > end;
119 >
120 > destructor TIBBatchMove.Destroy;
121 > begin
122 >  if FMappings <> nil then
123 >    FMappings.Free;
124 >  inherited Destroy;
125 > end;
126 >
127 > procedure TIBBatchMove.Execute;
128 > type
129 >  TFieldMap = array of Word;
130 > var
131 >  SourceActive, DestinationActive: Boolean;
132 >  BatchMode: TBatchMode;
133 >  I: Integer;
134 >  FieldCount: Word;
135 >  FieldMap: TFieldMap;
136 >  DestName, SourceName: string;
137 >
138 >  procedure GetMappingNames;
139 >  var
140 >    P: Integer;
141 >    Mapping: string;
142 >  begin
143 >    Mapping := FMappings[I];
144 >    P := Pos('=', Mapping); {MBCS OK}
145 >    if P > 0 then
146 >    begin
147 >      DestName := Copy(Mapping, 1, P - 1);
148 >      SourceName := Copy(Mapping, P + 1, 255);
149 >    end
150 >    else begin
151 >      DestName := Mapping;
152 >      SourceName := Mapping;
153 >    end;
154 >  end;
155 >
156 > begin
157 >  if (Destination = nil) or (Source = nil) or (Destination = Source) then
158 >    IBError(ibxeInvalidBatchMove, [nil]);
159 >  SourceActive := Source.Active;
160 >  DestinationActive := Destination.Active;
161 >  FieldCount := 0;
162 >  FieldMap := nil;
163 >  try
164 >    Source.DisableControls;
165 >    Destination.DisableControls;
166 >    Source.Open;
167 >    Source.CheckBrowseMode;
168 >    Source.UpdateCursorPos;
169 >    BatchMode := FMode;
170 >    if BatchMode = batCopy then
171 >    begin
172 >      Destination.Close;
173 >      if FMappings.Count = 0 then
174 >        Destination.FieldDefs := Source.FieldDefs
175 >      else
176 >      begin
177 >        Destination.FieldDefs.Clear;
178 >        for I := 0 to FMappings.Count - 1 do
179 >        begin
180 >          GetMappingNames;
181 >          with Source.FieldDefs.Find(SourceName) do
182 >            Destination.FieldDefs.Add(DestName, DataType, Size, Required);
183 >        end;
184 >      end;
185 >      Destination.IndexDefs.Clear;
186 >      Destination.CreateTable;
187 >      BatchMode := batAppend;
188 >    end;
189 >    Destination.Open;
190 >    Destination.CheckBrowseMode;
191 >    if FMappings.Count <> 0 then
192 >    begin
193 >      FieldCount := Destination.FieldDefs.Count;
194 >      SetLength(FieldMap, FieldCount);
195 >      for I := 0 to FMappings.Count - 1 do
196 >      begin
197 >        GetMappingNames;
198 >        FieldMap[Destination.FieldDefs.Find(DestName).FieldNo-1] :=
199 >          Source.FieldDefs.Find(SourceName).FieldNo;
200 >      end;
201 >    end;
202 >    if FRecordCount > 0 then
203 >    begin
204 >      Source.UpdateCursorPos;
205 >      FMovedCount := FRecordCount;
206 >    end else
207 >    begin
208 >      FMovedCount := MaxLongint;
209 >    end;
210 >    Source.CursorPosChanged;
211 >    try
212 >      InternalExecute (BatchMode, FieldCount);
213 >    finally
214 >      if DestinationActive then Destination.First;
215 >    end;
216 >  finally
217 >    if not DestinationActive then
218 >      Destination.Close;
219 >    if not SourceActive then
220 >      Source.Close;
221 >    Destination.EnableControls;
222 >    Source.EnableControls;
223 >  end;
224 > end;
225 >
226 > procedure TIBBatchMove.Notification(AComponent: TComponent;
227 >  Operation: TOperation);
228 > begin
229 >  inherited Notification(AComponent, Operation);
230 >  if Operation = opRemove then
231 >  begin
232 >    if Destination = AComponent then
233 >      Destination := nil;
234 >    if Source = AComponent then
235 >      Source := nil;
236 >  end;
237 > end;
238 >
239 > procedure TIBBatchMove.SetMappings(Value: TStrings);
240 > begin
241 >  FMappings.Assign(Value);
242 > end;
243 >
244 > procedure TIBBatchMove.SetSource(Value: TIBCustomDataSet);
245 > begin
246 >  FSource := Value;
247 >  if Value <> nil then
248 >    Value.FreeNotification(Self);
249 > end;
250 >
251 >
252 > procedure TIBBatchMove.InternalExecute (BatchMode: TBatchMode; FieldCount: Word);
253 > begin
254 >
255 > end;
256 >
257 > end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines