ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/fbintf/client/FBStatement.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/FBStatement.pas (file contents):
Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 209 by tony, Wed Mar 14 12:48:51 2018 UTC

# Line 28 | Line 28
28   *
29   *)
30   unit FBStatement;
31 + {$IFDEF MSWINDOWS}
32 + {$DEFINE WINDOWS}
33 + {$ENDIF}
34  
35   {$IFDEF FPC}
36 < {$mode objfpc}{$H+}
36 > {$mode delphi}
37   {$codepage UTF8}
38   {$interfaces COM}
39   {$ENDIF}
# Line 42 | Line 45 | uses
45    FBTransaction;
46  
47   type
48 +  TPerfStatistics = array[psCurrentMemory..psFetches] of Int64;
49  
50    { TFBStatement }
51  
# Line 56 | Line 60 | type
60      FOpen: boolean;
61      FPrepared: boolean;
62      FPrepareSeqNo: integer; {used to check for out of date references from interfaces}
63 <    FSQL: string;
64 <    FProcessedSQL: string;
63 >    FSQL: AnsiString;
64 >    FProcessedSQL: AnsiString;
65      FHasParamNames: boolean;
66      FBOF: boolean;
67      FEOF: boolean;
68      FSingleResults: boolean;
69      FGenerateParamNames: boolean;
70      FChangeSeqNo: integer;
71 +    FCollectStatistics: boolean;
72 +    FStatisticsAvailable: boolean;
73 +    FBeforeStats: TPerfStatistics;
74 +    FAfterStats: TPerfStatistics;
75      procedure CheckHandle; virtual; abstract;
76      procedure CheckTransaction(aTransaction: ITransaction);
77      procedure GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults); overload; virtual; abstract;
# Line 72 | Line 80 | type
80      function InternalOpenCursor(aTransaction: ITransaction): IResultSet;   virtual; abstract;
81      procedure FreeHandle;  virtual; abstract;
82      procedure InternalClose(Force: boolean); virtual; abstract;
83 +    function TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64;
84    public
85      constructor Create(Attachment: IAttachment; Transaction: ITransaction;
86 <      sql: string; SQLDialect: integer);
86 >      sql: AnsiString; SQLDialect: integer);
87      constructor CreateWithParameterNames(Attachment: IAttachment; Transaction: ITransaction;
88 <      sql: string;  SQLDialect: integer; GenerateParamNames: boolean =false);
88 >      sql: AnsiString;  SQLDialect: integer; GenerateParamNames: boolean =false);
89      destructor Destroy; override;
90      procedure Close;
91      procedure TransactionEnding(aTransaction: ITransaction; Force: boolean);
# Line 88 | Line 97 | type
97      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount,
98        DeleteCount: integer): boolean;
99      function GetSQLStatementType: TIBSQLStatementTypes;
100 <    function GetSQLText: string;
100 >    function GetSQLText: AnsiString;
101      function GetSQLDialect: integer;
102  
103      {GetDSQLInfo only supports isc_info_sql_stmt_type, isc_info_sql_get_plan, isc_info_sql_records}
104      procedure Prepare(aTransaction: ITransaction=nil); virtual;
105      function Execute(aTransaction: ITransaction=nil): IResults;
106      function OpenCursor(aTransaction: ITransaction=nil): IResultSet;
107 <    function CreateBlob(paramName: string): IBlob; overload;
107 >    function CreateBlob(paramName: AnsiString): IBlob; overload;
108      function CreateBlob(index: integer): IBlob; overload;
109      function CreateBlob(column: TColumnMetaData): IBlob; overload; virtual; abstract;
110 <    function CreateArray(paramName: string): IArray; overload;
110 >    function CreateArray(paramName: AnsiString): IArray; overload;
111      function CreateArray(index: integer): IArray;  overload;
112      function CreateArray(column: TColumnMetaData): IArray; overload; virtual; abstract;
113      function GetAttachment: IAttachment;
114      function GetTransaction: ITransaction;
115      function GetDSQLInfo(Request: byte): ISQLInfoResults; overload;
116      procedure SetRetainInterfaces(aValue: boolean); virtual;
117 +    procedure EnableStatistics(aValue: boolean);
118 +    function GetPerfStatistics(var stats: TPerfCounters): boolean;
119      property ChangeSeqNo: integer read FChangeSeqNo;
120      property SQLParams: ISQLParams read GetSQLParams;
121      property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
# Line 125 | Line 136 | begin
136      IBError(ibxeNotInTransaction,[]);
137   end;
138  
139 + function TFBStatement.TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64;
140 + begin
141 +  Result := TimeStamp.Time + Int64(timestamp.date)*msecsperday;
142 + end;
143 +
144   constructor TFBStatement.Create(Attachment: IAttachment;
145 <  Transaction: ITransaction; sql: string; SQLDialect: integer);
145 >  Transaction: ITransaction; sql: AnsiString; SQLDialect: integer);
146   begin
147    inherited Create(Transaction as TFBTransaction,2);
148    FAttachmentIntf := Attachment;
# Line 136 | Line 152 | begin
152   end;
153  
154   constructor TFBStatement.CreateWithParameterNames(Attachment: IAttachment;
155 <  Transaction: ITransaction; sql: string; SQLDialect: integer;
155 >  Transaction: ITransaction; sql: AnsiString; SQLDialect: integer;
156    GenerateParamNames: boolean);
157   begin
158    FHasParamNames := true;
# Line 207 | Line 223 | begin
223    Result := FSQLStatementType;
224   end;
225  
226 < function TFBStatement.GetSQLText: string;
226 > function TFBStatement.GetSQLText: AnsiString;
227   begin
228    Result := FSQL;
229   end;
# Line 246 | Line 262 | begin
262      Result := InternalOpenCursor(aTransaction);
263   end;
264  
265 < function TFBStatement.CreateBlob(paramName: string): IBlob;
265 > function TFBStatement.CreateBlob(paramName: AnsiString): IBlob;
266   var column: TColumnMetaData;
267   begin
268    InternalPrepare;
# Line 262 | Line 278 | begin
278    Result := CreateBlob(SQLParams[index] as TSQLParam);
279   end;
280  
281 < function TFBStatement.CreateArray(paramName: string): IArray;
281 > function TFBStatement.CreateArray(paramName: AnsiString): IArray;
282   var column: TColumnMetaData;
283   begin
284    InternalPrepare;
# Line 299 | Line 315 | begin
315    RetainInterfaces := aValue;
316   end;
317  
318 + procedure TFBStatement.EnableStatistics(aValue: boolean);
319 + begin
320 +  if FCollectStatistics <> aValue then
321 +  begin
322 +    FCollectStatistics := aValue;
323 +    FStatisticsAvailable := false;
324 +  end;
325 + end;
326 +
327 + function TFBStatement.GetPerfStatistics(var stats: TPerfCounters): boolean;
328 + begin
329 +  Result := FStatisticsAvailable;
330 +  if Result then
331 +  begin
332 +    stats[psCurrentMemory] := FAfterStats[psCurrentMemory];
333 +    stats[psDeltaMemory] := FAfterStats[psCurrentMemory] - FBeforeStats[psCurrentMemory];
334 +    stats[psMaxMemory] := FAfterStats[psMaxMemory];
335 +    stats[psRealTime] :=  FAfterStats[psRealTime] - FBeforeStats[psRealTime];
336 +    stats[psUserTime] :=  FAfterStats[psUserTime] - FBeforeStats[psUserTime];
337 +    stats[psReads] := FAfterStats[psReads] - FBeforeStats[psReads];
338 +    stats[psWrites] := FAfterStats[psWrites] - FBeforeStats[psWrites];
339 +    stats[psFetches] := FAfterStats[psFetches] - FBeforeStats[psFetches];
340 +    stats[psBuffers] :=  FAfterStats[psBuffers];
341 +  end;
342 + end;
343 +
344   end.
345  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines