Permalink
Browse files

Find out whether the previously selected database has some locked tab…

…les, and if so, don't select it at startup time. Closes #49
  • Loading branch information...
ansgarbecker committed Dec 21, 2017
1 parent 829e7e6 commit c2594e40c0b426b559a575248a07884913a35387
Showing with 31 additions and 2 deletions.
  1. +27 −1 source/dbconnection.pas
  2. +4 −1 source/main.pas
View
@@ -286,7 +286,8 @@ TConnectionParameters = class(TObject)
spSessionVariables, spGlobalVariables,
spISTableSchemaCol,
spUSEQuery, spKillQuery, spKillProcess,
spFuncLength, spFuncCeil);
spFuncLength, spFuncCeil,
spLockedTables);
TDBConnection = class(TComponent)
private
@@ -435,6 +436,7 @@ TDBConnection = class(TComponent)
property LockedByThread: TThread read FLockedByThread write SetLockedByThread;
property Datatypes: TDBDataTypeArray read FDatatypes;
property Favorites: TStringList read FFavorites;
function GetLockedTableCount(db: String): Integer;
published
property Active: Boolean read FActive write SetActive default False;
property Database: String read FDatabase write SetDatabase;
@@ -2034,6 +2036,7 @@ procedure TDBConnection.DoBeforeConnect;
FSQLSpecifities[spKillProcess] := 'KILL %d';
FSQLSpecifities[spFuncLength] := 'LENGTH';
FSQLSpecifities[spFuncCeil] := 'CEIL';
FSQLSpecifities[spLockedTables] := '';
end;
ngMSSQL: begin
FSQLSpecifities[spEmptyTable] := 'DELETE FROM ';
@@ -2050,6 +2053,7 @@ procedure TDBConnection.DoBeforeConnect;
FSQLSpecifities[spKillProcess] := 'KILL %d';
FSQLSpecifities[spFuncLength] := 'LEN';
FSQLSpecifities[spFuncCeil] := 'CEILING';
FSQLSpecifities[spLockedTables] := '';
end;
ngPgSQL: begin
FSQLSpecifities[spEmptyTable] := 'DELETE FROM ';
@@ -2066,6 +2070,7 @@ procedure TDBConnection.DoBeforeConnect;
FSQLSpecifities[spKillProcess] := 'SELECT pg_cancel_backend(%d)';
FSQLSpecifities[spFuncLength] := 'LENGTH';
FSQLSpecifities[spFuncCeil] := 'CEIL';
FSQLSpecifities[spLockedTables] := '';
end;
end;
@@ -2225,6 +2230,9 @@ procedure TMySQLConnection.DoAfterConnect;
if ServerVersionInt >= 50000 then
FSQLSpecifities[spKillQuery] := 'KILL QUERY %d';
if ServerVersionInt >= 50124 then
FSQLSpecifities[spLockedTables] := 'SHOW OPEN TABLES FROM %s WHERE in_use!=0';
end;
@@ -3997,6 +4005,24 @@ function TPGConnection.MaxAllowedPacket: Int64;
end;
function TDBConnection.GetLockedTableCount(db: String): Integer;
var
sql: String;
LockedTables: TStringList;
begin
// Find tables which are currently locked.
// Used to prevent waiting time in GetDBObjects.
sql := GetSQLSpecifity(spLockedTables);
if sql.IsEmpty then begin
Result := 0;
end else begin
LockedTables := GetCol(Format(sql, [QuoteIdent(db,False)]));
Result := LockedTables.Count;
LockedTables.Free;
end;
end;
function TMySQLConnection.GetRowCount(Obj: TDBObject): Int64;
var
Rows: String;
View
@@ -3693,7 +3693,10 @@ function TMainform.InitConnection(Params: TConnectionParameters; ActivateMe: Boo
RestoreLastActiveDatabase := AppSettings.ReadBool(asRestoreLastUsedDB);
AppSettings.SessionPath := Params.SessionPath;
LastActiveDatabase := AppSettings.ReadString(asLastUsedDB);
if RestoreLastActiveDatabase and (Connection.AllDatabases.IndexOf(LastActiveDatabase) >- 1) then begin
if RestoreLastActiveDatabase
and (Connection.AllDatabases.IndexOf(LastActiveDatabase) >- 1)
and (Connection.GetLockedTableCount(LastActiveDatabase) = 0)
then begin
SetActiveDatabase(LastActiveDatabase, Connection);
DBNode := FindDBNode(DBtree, Connection, LastActiveDatabase);
if Assigned(DBNode) then

0 comments on commit c2594e4

Please sign in to comment.