37 |
|
|
38 |
|
{$codepage UTF8} |
39 |
|
|
40 |
+ |
(* Define IBXQUERYSTATS to write to stdout a summary of query execution |
41 |
+ |
statistics each time a query is executed |
42 |
+ |
|
43 |
+ |
Define IBXQUERYTIME to write to stdout The local execution time for each |
44 |
+ |
query |
45 |
+ |
*) |
46 |
+ |
|
47 |
+ |
{ $DEFINE IBXQUERYSTATS} |
48 |
+ |
{ $DEFINE IBXQUERYTIME} |
49 |
+ |
|
50 |
|
interface |
51 |
|
|
52 |
|
uses |
696 |
|
procedure TIBSQL.ExecQuery; |
697 |
|
var |
698 |
|
fetch_res: ISC_STATUS; |
699 |
+ |
{$IFDEF IBXQUERYSTATS} |
700 |
+ |
stats: TPerfCounters; |
701 |
+ |
{$ENDIF} |
702 |
+ |
{$IFDEF IBXQUERYTIME} |
703 |
+ |
tmsecs: comp; |
704 |
+ |
{$ENDIF} |
705 |
|
begin |
706 |
|
CheckClosed; |
707 |
|
if not Prepared then Prepare; |
708 |
|
CheckValidStatement; |
709 |
+ |
{$IFDEF IBXQUERYTIME} |
710 |
+ |
tmsecs := TimeStampToMSecs(DateTimeToTimeStamp(Now)); |
711 |
+ |
{$ENDIF} |
712 |
|
if SQLStatementType = SQLSelect then |
713 |
|
begin |
714 |
|
FResultSet := FStatement.OpenCursor; |
728 |
|
if not (csDesigning in ComponentState) then |
729 |
|
MonitorHook.SQLExecute(Self); |
730 |
|
end; |
731 |
+ |
{$IFDEF IBXQUERYTIME} |
732 |
+ |
writeln('Executing ',FStatement.GetSQLText, |
733 |
+ |
' Response time= ',Format('%f msecs',[TimeStampToMSecs(DateTimeToTimeStamp(Now)) - tmsecs])); |
734 |
+ |
{$ENDIF} |
735 |
+ |
{$IFDEF IBXQUERYSTATS} |
736 |
+ |
if FStatement.GetPerfStatistics(stats) then |
737 |
+ |
writeln('Executing ',FStatement.GetSQLText, |
738 |
+ |
' Elapsed time= ', FormatFloat('#0.000',stats[psRealTime]/1000),' sec'); |
739 |
+ |
{$ENDIF} |
740 |
|
FBase.DoAfterExecQuery(self); |
741 |
|
end; |
742 |
|
|
879 |
|
|
880 |
|
procedure TIBSQL.SetDatabase(Value: TIBDatabase); |
881 |
|
begin |
882 |
+ |
if Value = FBase.Database then Exit; |
883 |
|
FBase.Database := Value; |
884 |
+ |
FreeHandle; |
885 |
|
end; |
886 |
|
|
887 |
|
procedure TIBSQL.Prepare; |
905 |
|
Transaction.TransactionIntf, |
906 |
|
SQL.Text, |
907 |
|
GenerateParamNames); |
908 |
+ |
{$IFDEF IBXQUERYSTATS} |
909 |
+ |
FStatement.EnableStatistics(true); |
910 |
+ |
{$ENDIF} |
911 |
|
FMetaData := FStatement.GetMetaData; |
912 |
|
FSQLParams := FStatement.GetSQLParams; |
913 |
|
FStatement.SetRetainInterfaces(true); |