ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/udr/testsuite/udrlib/udr_test03.pas
(Generate patch)

Comparing ibx/branches/udr/udr/testsuite/udrlib/udr_test03.pas (file contents):
Revision 372 by tony, Wed Jan 5 15:21:22 2022 UTC vs.
Revision 373 by tony, Thu Jan 6 14:14:57 2022 UTC

# Line 41 | Line 41 | unit udr_test03;
41   interface
42  
43   uses
44 <  Classes, SysUtils, IB, FBUDRController, FBUDRIntf;
44 >  Classes, SysUtils, IB, FBUDRController, FBUDRIntf{$IFDEF FPC}, Streamex{$ENDIF};
45  
46    {This unit provides the implementation of selected number of UDR Select
47     procedures used to test out various aspects of the TFBUDRSelectProcedure class.
# Line 70 | Line 70 | type
70      procedure close; override;
71    end;
72  
73 +  {TReadTextFile is a select procedure that reads lines from a text file and
74 +   returns each line as successive rows.
75 +
76 +   create or alter procedure MyReadText (
77 +        path varchar(200) not null /*relative to udr directory */
78 +        ) returns (
79 +       text varchar(100) not null
80 +   )
81 +   external name 'fbudrtests!read_txt'
82 +   engine udr;
83 + }
84 +
85 +  TReadTextFile  = class(TFBUDRSelectProcedure)
86 +    private
87 +      FTextFile: TStreamReader;
88 +    public
89 +      procedure open(context: IFBUDRExternalContext;
90 +                       ProcMetadata: IFBUDRProcMetadata;
91 +                       InputParams: IFBUDRInputParams);  override;
92 +      function fetch(OutputData: IFBUDROutputData): boolean;  override;
93 +      procedure close; override;
94 +    end;
95 +
96   implementation
97  
98   { TMySelectProcedure }
# Line 109 | Line 132 | begin
132    FResults := nil;
133   end;
134  
135 + procedure TReadTextFile.open(context: IFBUDRExternalContext;
136 +                 ProcMetadata: IFBUDRProcMetadata;
137 +                 InputParams: IFBUDRInputParams);
138 + var aFileName: AnsiString;
139 +    {$IFDEF FPC}F: TFileStream;{$ENDIF}
140 +
141 + begin
142 +  context.WriteToLog('Read Text called in directory '+ GetCurrentDir);
143 +  aFileName := InputParams.ByName('path').AsString;
144 +  if not FileExists(aFileName) then
145 +    raise Exception.CreateFmt('Unable to find file "%s"',[aFileName]);
146 +  context.WriteToLog('Reading from ' + aFileName);
147 +  {$IFDEF FPC}
148 +  F := TFileStream.Create(aFileName,fmOpenRead);
149 +  FTextFile := TStreamReader.Create(F,8192,true);
150 +  {$ELSE}
151 +  FTextFile := TStreamReader.Create(aFileName, TEncoding.ANSI);
152 +  {$ENDIF}
153 + end;
154 +
155 + function TReadTextFile.fetch(OutputData: IFBUDROutputData): boolean;
156 + begin
157 +  Result := not FTextFile.{$IFDEF FPC}EOF{$ELSE}EndOfStream{$ENDIF};
158 +  if Result then
159 +    OutputData.ByName('text').AsString := FTextFile.ReadLine;
160 + end;
161 +
162 + procedure TReadTextFile.close;
163 + begin
164 +  if FTextFile <> nil then
165 +    FTextFile.Free;
166 +  FTextFile := nil;
167 + end;
168 +
169   Initialization
170    FBRegisterUDRProcedure('select_proc',TMySelectProcedure);
171 <
171 >  FBRegisterUDRProcedure('read_txt',TReadTextFile);
172  
173   end.
174  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines