Skip to content
Permalink
Browse files

Introduce function TDBConnection.ResultCount and use that instead of …

…syncing FResultCount variable in many places
  • Loading branch information
ansgarbecker committed Dec 27, 2019
1 parent 4c62279 commit ca0ee761568547b28c1e2f71cfcce27cfb47cc5a
Showing with 18 additions and 10 deletions.
  1. +18 −10 source/dbconnection.pas
@@ -340,7 +340,6 @@ TDBConnection = class(TComponent)
FSessionVariables: TDBQuery;
FInformationSchemaObjects: TStringList;
FDatabaseCache: TDatabaseCache;
FResultCount: Integer;
FStatementNum: Cardinal;
FCurrentUserHostCombination: String;
FAllUserHostCombinations: TStringList;
@@ -459,7 +458,7 @@ TDBConnection = class(TComponent)
property CharsetTable: TDBQuery read GetCharsetTable;
property CharsetList: TStringList read GetCharsetList;
property InformationSchemaObjects: TStringList read GetInformationSchemaObjects;
property ResultCount: Integer read FResultCount;
function ResultCount: Integer;
property CurrentUserHostCombination: String read GetCurrentUserHostCombination;
property AllUserHostCombinations: TStringList read GetAllUserHostCombinations;
property LockedByThread: TThread read FLockedByThread write SetLockedByThread;
@@ -2781,7 +2780,6 @@ procedure TMySQLConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogC
NativeSQL := AnsiString(SQL);
TimerStart := GetTickCount;
SetLength(FLastRawResults, 0);
FResultCount := 0;
FStatementNum := 1;
QueryStatus := FLib.mysql_real_query(FHandle, PAnsiChar(NativeSQL), Length(NativeSQL));
FLastQueryDuration := GetTickCount - TimerStart;
@@ -2842,7 +2840,6 @@ procedure TMySQLConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogC
raise EDbError.Create(GetLastErrorMsg);
end;
end;
FResultCount := Length(FLastRawResults);

end;
end;
@@ -2869,7 +2866,6 @@ procedure TAdoDBConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogC
FLastQuerySQL := SQL;
TimerStart := GetTickCount;
SetLength(FLastRawResults, 0);
FResultCount := 0;
FRowsFound := 0;
FRowsAffected := 0;
try
@@ -2894,7 +2890,6 @@ procedure TAdoDBConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogC
QueryResult := nil;
QueryResult := NextResult;
end;
FResultCount := Length(FLastRawResults);

DetectUSEQuery(SQL);
except
@@ -2932,7 +2927,6 @@ procedure TPGConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogCate
NativeSQL := AnsiString(SQL);
TimerStart := GetTickCount;
SetLength(FLastRawResults, 0);
FResultCount := 0;
FRowsFound := 0;
FRowsAffected := 0;
FWarningCount := 0;
@@ -2980,7 +2974,6 @@ procedure TPGConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogCate
Inc(FStatementNum);
QueryResult := FLib.PQgetResult(FHandle);
end;
FResultCount := Length(FLastRawResults);

end;

@@ -3016,7 +3009,6 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
NativeSQL := AnsiString(SQL);
TimerStart := GetTickCount;
SetLength(FLastRawResults, 0);
FResultCount := 0;
FRowsFound := 0;
FRowsAffected := 0;
FWarningCount := 0;
@@ -3051,7 +3043,6 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
SetLength(FLastRawResults, 1);
FLastRawResults[0] := Rows;
end;
FResultCount := Length(FLastRawResults);
DetectUSEQuery(SQL);
end;

@@ -4807,6 +4798,23 @@ function TAdoDBConnection.GetInformationSchemaObjects: TStringList;
end;


function TDBConnection.ResultCount;
begin
case Parameters.NetTypeGroup of
ngMySQL:
Result := Length(TMySQLConnection(Self).LastRawResults);
ngMSSQL:
Result := Length(TAdoDBConnection(Self).LastRawResults);
ngPgSQL:
Result := Length(TPGConnection(Self).LastRawResults);
ngSQLite:
Result := Length(TSQLiteConnection(Self).LastRawResults);
else
raise Exception.CreateFmt(_(MsgUnhandledNetType), [Integer(Parameters.NetType)]);
end;
end;


function TDBConnection.GetConnectionUptime: Integer;
begin
// Return seconds since last connect

0 comments on commit ca0ee76

Please sign in to comment.
You can’t perform that action at this time.