diff --git a/source/dbconnection.pas b/source/dbconnection.pas index e427a782..3aee8d03 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -300,6 +300,7 @@ type FOnLog: TDBLogEvent; FOnConnected: TDBEvent; FOnDatabaseChanged: TDBEvent; + FOnObjectnamesChanged: TDBEvent; FRowsFound: Int64; FRowsAffected: Int64; FWarningCount: Cardinal; @@ -317,7 +318,6 @@ type FSessionVariables: TDBQuery; FInformationSchemaObjects: TStringList; FDatabaseCache: TDatabaseCache; - FObjectNamesInSelectedDB: TStrings; FResultCount: Integer; FStatementNum: Cardinal; FCurrentUserHostCombination: String; @@ -355,7 +355,6 @@ type function GetRowCount(Obj: TDBObject): Int64; virtual; abstract; procedure ClearCache(IncludeDBObjects: Boolean); procedure FetchDbObjects(db: String; var Cache: TDBObjectList); virtual; abstract; - procedure SetObjectNamesInSelectedDB; procedure SetLockedByThread(Value: TThread); virtual; procedure KeepAliveTimerEvent(Sender: TObject); procedure Drop(Obj: TDBObject); virtual; @@ -430,7 +429,6 @@ type property CharsetTable: TDBQuery read GetCharsetTable; property CharsetList: TStringList read GetCharsetList; property InformationSchemaObjects: TStringList read GetInformationSchemaObjects; - property ObjectNamesInSelectedDB: TStrings read FObjectNamesInSelectedDB write FObjectNamesInSelectedDB; property ResultCount: Integer read FResultCount; property CurrentUserHostCombination: String read GetCurrentUserHostCombination; property LockedByThread: TThread read FLockedByThread write SetLockedByThread; @@ -443,6 +441,7 @@ type property OnLog: TDBLogEvent read FOnLog write FOnLog; property OnConnected: TDBEvent read FOnConnected write FOnConnected; property OnDatabaseChanged: TDBEvent read FOnDatabaseChanged write FOnDatabaseChanged; + property OnObjectnamesChanged: TDBEvent read FOnObjectnamesChanged write FOnObjectnamesChanged; end; TDBConnectionList = TObjectList; @@ -3038,7 +3037,8 @@ begin s := QuoteIdent(Value); Query(Format(GetSQLSpecifity(spUSEQuery), [s]), False); end; - SetObjectNamesInSelectedDB; + if Assigned(FOnObjectnamesChanged) then + FOnObjectnamesChanged(Self, FDatabase); end; end; @@ -4300,7 +4300,8 @@ begin Cache.Sort; // Add list of objects in this database to cached list of all databases FDatabaseCache.Add(Cache); - SetObjectNamesInSelectedDB; + if Assigned(FOnObjectnamesChanged) then + FOnObjectnamesChanged(Self, FDatabase); end; Result := nil; @@ -4639,29 +4640,6 @@ begin end; -procedure TDBConnection.SetObjectNamesInSelectedDB; -var - i: Integer; - Objects: TDBObjectList; - ObjNames: String; -begin - // Add object names to additional stringlist - if Assigned(FObjectNamesInSelectedDB) then begin - ObjNames := ''; - if DbObjectsCached(FDatabase) then begin - Objects := GetDbObjects(FDatabase); - // Limit slow highlighter to 1000 table names. See http://www.heidisql.com/forum.php?t=16307 - if Objects.Count < 1000 then begin - for i:=0 to Objects.Count-1 do - ObjNames := ObjNames + Objects[i].Name + CRLF; - end; - end; - if FObjectNamesInSelectedDB.Text <> ObjNames then - FObjectNamesInSelectedDB.Text := ObjNames; - end; -end; - - function TDBConnection.GetKeyColumns(Columns: TTableColumnList; Keys: TTableKeyList): TStringList; var i: Integer; diff --git a/source/main.pas b/source/main.pas index ea18979c..b1d9cd8e 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1057,6 +1057,7 @@ type procedure UpdateFilterPanel(Sender: TObject); procedure ConnectionReady(Connection: TDBConnection; Database: String); procedure DatabaseChanged(Connection: TDBConnection; Database: String); + procedure ObjectnamesChanged(Connection: TDBConnection; Database: String); procedure UpdateLineCharPanel; procedure SetSnippetFilenames; function TreeClickHistoryPrevious(MayBeNil: Boolean=False): PVirtualNode; @@ -3547,7 +3548,7 @@ begin Connection.OnLog := LogSQL; Connection.OnConnected := ConnectionReady; Connection.OnDatabaseChanged := DatabaseChanged; - Connection.ObjectNamesInSelectedDB := SynSQLSyn1.TableNames; + Connection.OnObjectnamesChanged := ObjectnamesChanged; try Connection.Active := True; // We have a connection @@ -8041,6 +8042,45 @@ begin end; +procedure TMainForm.ObjectnamesChanged(Connection: TDBConnection; Database: String); +var + DBObjects: TDBObjectList; + Obj: TDBObject; + TableNames, ProcNames: TStringList; +begin + // Tell SQL highlighter about names of tables and procedures in selected database + SynSQLSyn1.TableNames.Clear; + SynSQLSyn1.ProcNames.Clear; + if Connection.DbObjectsCached(Database) then begin + DBObjects := Connection.GetDBObjects(Database); + TableNames := TStringList.Create; + TableNames.BeginUpdate; + ProcNames := TStringList.Create; + ProcNames.BeginUpdate; + for Obj in DBObjects do begin + case Obj.NodeType of + lntTable, lntView: begin + // Limit slow highlighter to 1000 table names. See http://www.heidisql.com/forum.php?t=16307 + // ... and here: https://github.com/SynEdit/SynEdit/issues/28 + if TableNames.Count < 1000 then + TableNames.Add(Obj.Name); + end; + lntProcedure, lntFunction: begin + if ProcNames.Count < 1000 then + ProcNames.Add(Obj.Name); + end; + end; + end; + TableNames.EndUpdate; + ProcNames.EndUpdate; + SynSQLSyn1.TableNames.Text := TableNames.Text; + SynSQLSyn1.ProcNames.Text := ProcNames.Text; + TableNames.Free; + ProcNames.Free; + end; +end; + + procedure TMainForm.DBtreeDblClick(Sender: TObject); var DBObj: PDBObject;