mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Convert database tree from TTreeView to TVirtualStringTree.
- Fixes bug #271 "F5 shortcut in database tree not working" - Fullfills rfe #519 "Highlight selected item in tree view when focus is elsewhere" - Fixes inconsistent expansion state of nodes after refreshing - Fixes plus sign staying when a db node with 0 tables was selected - Slightly enhances painting speed within the dbtree - Removes temporary storage of a rightclicked node (DBRightClickSelectItem). VirtualTree handles its right clicked selection exactly like the left clicked one, which makes makes coding a bit cleaner as we can always use the selected item instead of hacking with the right and left clicked node. On the other side it removes a quite user friendly feature. Well, we can reimplement this feature later, though it's not user UNfriendly currently. - Reasonably rename the StringList "OnlyDBs" to "DatabasesWanted" and "OnlyDBs2" to "Databases"
This commit is contained in:
@ -46,7 +46,7 @@ object MDIChild: TMDIChild
|
||||
Cursor = crSizeWE
|
||||
ResizeStyle = rsUpdate
|
||||
end
|
||||
object DBtree: TTreeView
|
||||
object DBtree: TVirtualStringTree
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 169
|
||||
@ -54,19 +54,33 @@ object MDIChild: TMDIChild
|
||||
Align = alLeft
|
||||
Constraints.MinWidth = 40
|
||||
DragMode = dmAutomatic
|
||||
HotTrack = True
|
||||
DragType = dtVCL
|
||||
Header.AutoSizeIndex = 0
|
||||
Header.Font.Charset = DEFAULT_CHARSET
|
||||
Header.Font.Color = clWindowText
|
||||
Header.Font.Height = -11
|
||||
Header.Font.Name = 'Tahoma'
|
||||
Header.Font.Style = []
|
||||
Header.MainColumn = -1
|
||||
Header.Options = [hoColumnResize, hoDrag]
|
||||
HotCursor = crHandPoint
|
||||
Images = MainForm.PngImageListMain
|
||||
Indent = 19
|
||||
ReadOnly = True
|
||||
RightClickSelect = True
|
||||
RowSelect = True
|
||||
ShowRoot = False
|
||||
Indent = 16
|
||||
Margin = 2
|
||||
PopupMenu = popupTreeView
|
||||
TabOrder = 0
|
||||
TextMargin = 2
|
||||
TreeOptions.AutoOptions = [toAutoDropExpand, toAutoTristateTracking, toAutoDeleteMovedNodes]
|
||||
TreeOptions.PaintOptions = [toHotTrack, toShowButtons, toShowDropmark, toShowTreeLines, toThemeAware, toUseBlendedImages]
|
||||
TreeOptions.SelectionOptions = [toRightClickSelect]
|
||||
OnChange = DBtreeChange
|
||||
OnChanging = DBtreeChanging
|
||||
OnContextPopup = DBtreeContextPopup
|
||||
OnDblClick = DBtreeDblClick
|
||||
OnExpanding = DBtreeExpanding
|
||||
OnGetText = DBtreeGetText
|
||||
OnGetImageIndex = DBtreeGetImageIndex
|
||||
OnGetNodeDataSize = DBtreeGetNodeDataSize
|
||||
OnInitChildren = DBtreeInitChildren
|
||||
OnInitNode = DBtreeInitNode
|
||||
Columns = <>
|
||||
end
|
||||
object TableShow: TPanel
|
||||
Left = 173
|
||||
@ -562,6 +576,7 @@ object MDIChild: TMDIChild
|
||||
OnChange = ListTablesChange
|
||||
OnCompareNodes = vstCompareNodes
|
||||
OnDblClick = ListTablesDblClick
|
||||
OnEdited = ListTablesEdited
|
||||
OnFreeNode = vstFreeNode
|
||||
OnGetText = vstGetText
|
||||
OnGetImageIndex = vstGetImageIndex
|
||||
@ -1781,11 +1796,11 @@ object MDIChild: TMDIChild
|
||||
object N5: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object Drop1: TMenuItem
|
||||
object menuRefreshDBTree: TMenuItem
|
||||
Caption = 'Refresh'
|
||||
ImageIndex = 0
|
||||
ShortCut = 116
|
||||
OnClick = ReadDatabasesAndTables
|
||||
OnClick = menuRefreshDBTreeClick
|
||||
end
|
||||
end
|
||||
object popupDbGrid: TPopupMenu
|
||||
|
1046
source/childwin.pas
1046
source/childwin.pas
File diff suppressed because it is too large
Load Diff
@ -105,7 +105,6 @@ end;
|
||||
procedure TCopyTableForm.FormShow(Sender: TObject);
|
||||
var
|
||||
i : Integer;
|
||||
tn : TTreeNode;
|
||||
struc_data : Byte;
|
||||
ds: TDataSet;
|
||||
NodeData: PVTreeData;
|
||||
@ -118,25 +117,11 @@ begin
|
||||
|
||||
// Select TargetDatabase
|
||||
ComboSelectDatabase.Items.Clear;
|
||||
for i:=0 to Mainform.ChildWin.DBTree.Items.Count-1 do
|
||||
begin
|
||||
tn := Mainform.ChildWin.DBTree.Items[i];
|
||||
if tn.Level = 1 then
|
||||
comboSelectDatabase.Items.Add(tn.Text);
|
||||
end;
|
||||
|
||||
for i:=0 to comboSelectDatabase.Items.Count-1 do
|
||||
begin
|
||||
if (comboSelectDatabase.Items[i] = Mainform.ChildWin.ActiveDatabase) then
|
||||
begin
|
||||
comboSelectDatabase.ItemIndex := i;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
ComboSelectDatabase.Items.Assign(Mainform.ChildWin.Databases);
|
||||
ComboSelectDatabase.ItemIndex := ComboSelectDatabase.Items.IndexOf( Mainform.ChildWin.ActiveDatabase );
|
||||
if comboSelectDatabase.ItemIndex = -1 then
|
||||
comboSelectDatabase.ItemIndex := 0;
|
||||
|
||||
|
||||
// fill columns:
|
||||
CheckListBoxFields.Items.Clear;
|
||||
ds := Mainform.ChildWin.GetResults( 'SHOW FIELDS FROM ' + mainform.mask(oldTableName) );
|
||||
|
@ -221,12 +221,14 @@ end;
|
||||
procedure TCreateDatabaseForm.btnOKClick(Sender: TObject);
|
||||
var
|
||||
sql : String;
|
||||
cwin: TMDIChild;
|
||||
begin
|
||||
cwin := Mainform.Childwin;
|
||||
if modifyDB = '' then
|
||||
begin
|
||||
sql := GetCreateStatement;
|
||||
Try
|
||||
Mainform.Childwin.ExecUpdateQuery( sql );
|
||||
cwin.ExecUpdateQuery( sql );
|
||||
// Close form
|
||||
ModalResult := mrOK;
|
||||
except
|
||||
@ -236,7 +238,7 @@ begin
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
sql := 'ALTER DATABASE ' + Mainform.Childwin.mask( modifyDB );
|
||||
sql := 'ALTER DATABASE ' + cwin.mask( modifyDB );
|
||||
if comboCharset.Enabled and (comboCharset.Text <> '') then
|
||||
begin
|
||||
sql := sql + ' CHARACTER SET ' + comboCharset.Text;
|
||||
@ -244,12 +246,12 @@ begin
|
||||
sql := sql + ' COLLATE ' + comboCollation.Text;
|
||||
end;
|
||||
Try
|
||||
Mainform.Childwin.ExecUpdateQuery( sql );
|
||||
cwin.ExecUpdateQuery( sql );
|
||||
if modifyDB <> editDBName.Text then
|
||||
begin
|
||||
Mainform.Childwin.ExecUpdateQuery( 'RENAME DATABASE ' + Mainform.Childwin.mask( modifyDB )
|
||||
+ ' TO ' + Mainform.Childwin.mask( editDBName.Text ) );
|
||||
Mainform.Childwin.ReadDatabasesAndTables( Sender );
|
||||
cwin.ExecUpdateQuery( 'RENAME DATABASE ' + cwin.mask( modifyDB )
|
||||
+ ' TO ' + cwin.mask( editDBName.Text ) );
|
||||
cwin.DBtree.ResetNode(cwin.DBtree.GetFirst);
|
||||
end;
|
||||
// Close form
|
||||
ModalResult := mrOK;
|
||||
|
@ -89,7 +89,6 @@ type
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
SelectedDatabase : String;
|
||||
end;
|
||||
|
||||
{$I const.inc}
|
||||
@ -251,7 +250,6 @@ begin
|
||||
Mainform.ChildWin.ExecUpdateQuery( createQuery, False, True );
|
||||
Mainform.ChildWin.MenuRefreshClick(sender);
|
||||
Mainform.ChildWin.SelectedTable := EditTablename.Text;
|
||||
Mainform.ChildWin.ShowTable(EditTablename.Text);
|
||||
except on E: THandledSQLError do
|
||||
// Keep the form open so the user can fix his faulty input
|
||||
ModalResult := mrNone;
|
||||
@ -509,23 +507,16 @@ end;
|
||||
|
||||
procedure TCreateTableForm.FormShow(Sender: TObject);
|
||||
var
|
||||
i : Integer;
|
||||
tn : TTreeNode;
|
||||
i: Integer;
|
||||
begin
|
||||
// FormShow!
|
||||
|
||||
// read dbs and Tables from treeview
|
||||
DBComboBox.Items.Clear;
|
||||
for i:=0 to Mainform.ChildWin.DBTree.Items.Count-1 do
|
||||
begin
|
||||
tn := Mainform.ChildWin.DBTree.Items[i];
|
||||
if tn.Level = 1 then
|
||||
DBComboBox.Items.Add(tn.Text);
|
||||
end;
|
||||
DBComboBox.Items.Assign(Mainform.ChildWin.Databases);
|
||||
// Preselect relevant database in pulldown
|
||||
if SelectedDatabase <> '' then
|
||||
DBComboBox.ItemIndex := DBComboBox.Items.IndexOf( SelectedDatabase )
|
||||
else if DBComboBox.Items.Count > 0 then
|
||||
DBComboBox.ItemIndex := DBComboBox.Items.IndexOf( Mainform.ChildWin.ActiveDatabase );
|
||||
if (DBComboBox.ItemIndex = -1) and (DBComboBox.Items.Count > 0) then
|
||||
DBComboBox.ItemIndex := 0;
|
||||
|
||||
if Mainform.ChildWin.mysql_version >= 32300 then
|
||||
|
@ -173,50 +173,25 @@ end;
|
||||
|
||||
procedure TExportSQLForm.FormShow(Sender: TObject);
|
||||
var
|
||||
tn : TTreeNode;
|
||||
i, OutputTo : Integer;
|
||||
dbtree_db : String;
|
||||
list: TWindowDataArray;
|
||||
CWin: TMDIChild;
|
||||
begin
|
||||
CWin := Mainform.ChildWin;
|
||||
barProgress.Position := 0;
|
||||
lblProgress.Caption := '';
|
||||
PageControl1.ActivePageIndex := 0;
|
||||
SynMemoExampleSQL.Highlighter := Mainform.ChildWin.SynSQLSyn1;
|
||||
SynMemoExampleSQL.Font := Mainform.ChildWin.SynMemoQuery.Font;
|
||||
SynMemoExampleSQL.Highlighter := CWin.SynSQLSyn1;
|
||||
SynMemoExampleSQL.Font := CWin.SynMemoQuery.Font;
|
||||
|
||||
// read dbs and Tables from treeview
|
||||
comboSelectDatabase.Items.Clear;
|
||||
Caption := Mainform.ChildWin.MysqlConn.SessionName + ' - Export Tables...';
|
||||
for i:=0 to Mainform.ChildWin.DBTree.Items.Count-1 do
|
||||
begin
|
||||
tn := Mainform.ChildWin.DBTree.Items[i];
|
||||
if tn.Level = 1 then
|
||||
comboSelectDatabase.Items.Add(tn.Text);
|
||||
end;
|
||||
|
||||
if Mainform.ChildWin.DBRightClickSelectedItem <> nil then
|
||||
begin
|
||||
case Mainform.ChildWin.DBRightClickSelectedItem.Level of
|
||||
1 : dbtree_db := Mainform.ChildWin.DBRightClickSelectedItem.Text;
|
||||
2 : dbtree_db := Mainform.ChildWin.DBRightClickSelectedItem.Parent.Text;
|
||||
3 : dbtree_db := Mainform.ChildWin.DBRightClickSelectedItem.Parent.Parent.Text;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i:=0 to comboSelectDatabase.Items.Count-1 do
|
||||
begin
|
||||
if ((dbtree_db = '') and (comboSelectDatabase.Items[i] = Mainform.ChildWin.ActiveDatabase))
|
||||
or ((dbtree_db <> '') and (comboSelectDatabase.Items[i] = dbtree_db)) then
|
||||
begin
|
||||
comboSelectDatabase.ItemIndex := i;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
Caption := CWin.MysqlConn.SessionName + ' - Export Tables...';
|
||||
comboSelectDatabase.Items.Assign(CWin.Databases);
|
||||
comboSelectDatabase.ItemIndex := comboSelectDatabase.Items.IndexOf(CWin.ActiveDatabase);
|
||||
// Select first database if at least one is available.
|
||||
if (comboSelectDatabase.ItemIndex = -1) and (comboSelectDatabase.Items.Count>0) then
|
||||
comboSelectDatabase.ItemIndex := 0;
|
||||
|
||||
comboSelectDatabaseChange(self);
|
||||
|
||||
// Initialize and fill list with target versions
|
||||
@ -229,7 +204,7 @@ begin
|
||||
Add( '40100=MySQL 4.1' );
|
||||
Add( '50000=MySQL 5.0' );
|
||||
Add( '50100=MySQL 5.1' );
|
||||
Add( IntToStr( Mainform.ChildWin.mysql_version ) + '=Same as source server (MySQL '+Mainform.ChildWin.GetVar('SELECT VERSION()') +')' );
|
||||
Add( IntToStr( CWin.mysql_version ) + '=Same as source server (MySQL '+CWin.GetVar('SELECT VERSION()') +')' );
|
||||
end;
|
||||
|
||||
// Add all target versions to combobox and set default option
|
||||
@ -371,42 +346,33 @@ end;
|
||||
procedure TExportSQLForm.comboSelectDatabaseChange(Sender: TObject);
|
||||
var
|
||||
i : Integer;
|
||||
dbtree_table : String;
|
||||
Selected : TStringList;
|
||||
sql: string;
|
||||
CWin: TMDIChild;
|
||||
CheckThisItem: Boolean;
|
||||
begin
|
||||
CWin := Mainform.Childwin;
|
||||
// read tables from db
|
||||
checkListTables.Items.Clear;
|
||||
|
||||
// Fetch tables from DB
|
||||
sql := 'FROM ' + MainForm.mask(comboSelectDatabase.Text);
|
||||
if Mainform.ChildWin.mysql_version > 50002 then sql := 'SHOW FULL TABLES ' + sql + ' WHERE table_type=''BASE TABLE'''
|
||||
if CWin.mysql_version > 50002 then sql := 'SHOW FULL TABLES ' + sql + ' WHERE table_type=''BASE TABLE'''
|
||||
else sql := 'SHOW TABLES ' + sql;
|
||||
checkListTables.Items := Mainform.ChildWin.GetCol( sql );
|
||||
checkListTables.Items := CWin.GetCol( sql );
|
||||
|
||||
// Fetch selected tables in list
|
||||
Selected := GetVTCaptions( Mainform.ChildWin.ListTables, True );
|
||||
Selected := GetVTCaptions( CWin.ListTables, True );
|
||||
|
||||
// select all/some:
|
||||
for i:=0 to checkListTables.Items.Count-1 do
|
||||
begin
|
||||
if Mainform.ChildWin.DBRightClickSelectedItem <> nil then
|
||||
begin
|
||||
case Mainform.ChildWin.DBRightClickSelectedItem.Level of
|
||||
2 : dbtree_table := Mainform.ChildWin.DBRightClickSelectedItem.Text;
|
||||
3 : dbtree_table := Mainform.ChildWin.DBRightClickSelectedItem.Parent.Text;
|
||||
end;
|
||||
case Mainform.ChildWin.DBRightClickSelectedItem.Level of
|
||||
1 : checkListTables.checked[i] := true;
|
||||
2,3 : checkListTables.checked[i] := dbtree_table = checkListTables.Items[i];
|
||||
end;
|
||||
end
|
||||
else if Mainform.ChildWin.ActiveDatabase = comboSelectDatabase.Text then
|
||||
checkListTables.checked[i] := Selected.IndexOf( checkListTables.Items[i] ) > -1
|
||||
if CWin.ActiveDatabase = comboSelectDatabase.Text then
|
||||
CheckThisItem := Selected.IndexOf( checkListTables.Items[i] ) > -1
|
||||
else
|
||||
checkListTables.checked[i] := true;
|
||||
CheckThisItem := true;
|
||||
checkListTables.checked[i] := CheckThisItem;
|
||||
end;
|
||||
Mainform.ChildWin.DBRightClickSelectedItem := nil;
|
||||
|
||||
// write items for "Another Databases":
|
||||
fillcombo_anotherdb(self);
|
||||
|
@ -91,32 +91,13 @@ end;
|
||||
|
||||
{ FormShow }
|
||||
procedure TfrmInsertFiles.FormShow(Sender: TObject);
|
||||
var
|
||||
tn : TTreeNode;
|
||||
i : Integer;
|
||||
begin
|
||||
ComboBoxDBs.Items.Clear;
|
||||
Caption := Mainform.ChildWin.MysqlConn.SessionName + ' - Insert files into table ...';
|
||||
for i:=0 to Mainform.ChildWin.DBTree.Items.Count-1 do
|
||||
begin
|
||||
tn := Mainform.ChildWin.DBTree.Items[i];
|
||||
if tn.Level = 1 then
|
||||
ComboBoxDBs.Items.Add(tn.Text);
|
||||
end;
|
||||
|
||||
for i:=0 to ComboBoxDBs.Items.Count-1 do
|
||||
begin
|
||||
if ComboBoxDBs.Items[i] = Mainform.ChildWin.ActiveDatabase then
|
||||
begin
|
||||
ComboBoxDBs.ItemIndex := i;
|
||||
end;
|
||||
end;
|
||||
|
||||
ComboBoxDBs.Items.Clear;
|
||||
ComboBoxDBs.Items.Assign(Mainform.ChildWin.Databases);
|
||||
ComboBoxDBs.ItemIndex := ComboBoxDBs.Items.IndexOf( Mainform.ChildWin.ActiveDatabase );
|
||||
if ComboBoxDBs.ItemIndex = -1 then
|
||||
begin
|
||||
ComboBoxDBs.ItemIndex := 0;
|
||||
end;
|
||||
|
||||
ComboBoxDBsChange(self);
|
||||
end;
|
||||
|
||||
|
@ -104,27 +104,11 @@ begin
|
||||
end;
|
||||
|
||||
procedure Tloaddataform.FormShow(Sender: TObject);
|
||||
var
|
||||
tn : TTreeNode;
|
||||
i : Integer;
|
||||
begin
|
||||
// read dbs and Tables from treeview
|
||||
comboDatabase.Items.Clear;
|
||||
for i:=0 to Mainform.ChildWin.DBTree.Items.Count-1 do
|
||||
begin
|
||||
tn := Mainform.ChildWin.DBTree.Items[i];
|
||||
if tn.Level = 1 then
|
||||
comboDatabase.Items.Add(tn.Text);
|
||||
end;
|
||||
|
||||
for i:=0 to comboDatabase.Items.Count-1 do
|
||||
begin
|
||||
if comboDatabase.Items[i] = Mainform.ChildWin.ActiveDatabase then
|
||||
begin
|
||||
comboDatabase.ItemIndex := i;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
comboDatabase.Items.Assign(Mainform.ChildWin.Databases);
|
||||
comboDatabase.ItemIndex := comboDatabase.Items.IndexOf( Mainform.ChildWin.ActiveDatabase );
|
||||
if comboDatabase.ItemIndex = -1 then
|
||||
comboDatabase.ItemIndex := 0;
|
||||
|
||||
|
@ -203,7 +203,6 @@ type
|
||||
procedure HandleWMComplete(var msg: TMessage); message WM_COMPLETED;
|
||||
procedure HandleWMCopyData(var msg: TWMCopyData); message WM_COPYDATA;
|
||||
procedure HandleWMProcessLog(var msg: TMessage); message WM_PROCESSLOG;
|
||||
procedure HandleWMClearRightClickPointer(var msg: TMessage); message WM_CLEAR_RIGHTCLICK_POINTER;
|
||||
procedure menuUpdateCheckClick(Sender: TObject);
|
||||
private
|
||||
regMain : TRegistry;
|
||||
@ -298,12 +297,6 @@ begin
|
||||
ChildWin.ProcessSqlLog;
|
||||
end;
|
||||
|
||||
procedure TMainForm.HandleWMClearRightClickPointer(var msg: TMessage);
|
||||
begin
|
||||
debug('clearing stored right click item');
|
||||
ChildWin.DBRightClickSelectedItem := nil;
|
||||
end;
|
||||
|
||||
procedure TMainForm.EnsureConnected;
|
||||
begin
|
||||
if ActiveMDIChild = nil then raise Exception.Create('Not connected.');
|
||||
@ -590,6 +583,8 @@ end;
|
||||
procedure TMainForm.ButtonRefreshClick(Sender: TObject);
|
||||
begin
|
||||
// Refresh
|
||||
// Force data tab update when appropriate.
|
||||
Childwin.dataselected := false;
|
||||
if ChildWin.PageControlMain.ActivePage = ChildWin.tabHost then
|
||||
ChildWin.ShowVariablesAndProcesses(self)
|
||||
else if ChildWin.PageControlMain.ActivePage = ChildWin.tabDatabase then
|
||||
@ -598,7 +593,8 @@ begin
|
||||
ChildWin.ShowTableProperties(ChildWin.SelectedTable)
|
||||
else if ChildWin.PageControlMain.ActivePage = ChildWin.tabData then
|
||||
ChildWin.viewdata(self)
|
||||
else ChildWin.ReadDatabasesAndTables(self);
|
||||
else
|
||||
ChildWin.RefreshTree(True);
|
||||
end;
|
||||
|
||||
procedure TMainForm.ButtonCreateDatabaseClick(Sender: TObject);
|
||||
@ -750,30 +746,27 @@ end;
|
||||
procedure TMainForm.actCreateViewExecute(Sender: TObject);
|
||||
var
|
||||
NodeData: PVTreeData;
|
||||
ds: TDataset;
|
||||
begin
|
||||
if ViewForm = nil then
|
||||
ViewForm := TfrmView.Create(Self);
|
||||
ViewForm.EditViewName := '';
|
||||
ViewForm.DBNode := nil;
|
||||
if (Sender as TAction) = actEditView then begin
|
||||
// Edit mode
|
||||
if Assigned(Childwin.ListTables.FocusedNode) then begin
|
||||
// "Edit view" was clicked in ListTables' context menu
|
||||
NodeData := Childwin.ListTables.GetNodeData(Childwin.ListTables.FocusedNode);
|
||||
ViewForm.EditViewName := NodeData.Captions[0];
|
||||
end else if Assigned(Childwin.DBRightClickSelectedItem) then begin
|
||||
end else if Childwin.DBtree.GetFirstSelected <> nil then begin
|
||||
// "Edit view" was clicked in DBTree's context menu
|
||||
ViewForm.EditViewName := Childwin.DBRightClickSelectedItem.Text;
|
||||
ViewForm.DBNode := Childwin.DBRightClickSelectedItem.Parent;
|
||||
ds := Childwin.FetchDbTableList(Childwin.ActiveDatabase);
|
||||
ds.RecNo := Childwin.DBtree.GetFirstSelected.Index+1;
|
||||
ViewForm.EditViewName := ds.Fields[0].AsString;
|
||||
end else
|
||||
// If we're here, there's a menu item "Edit/Create view" in an unknown location
|
||||
raise Exception.Create('Internal error in actCreateViewExexute.');
|
||||
end else begin
|
||||
// Create mode
|
||||
if Assigned(Childwin.DBRightClickSelectedItem) then case Childwin.DBRightClickSelectedItem.Level of
|
||||
1: ViewForm.DBNode := Childwin.DBRightClickSelectedItem;
|
||||
2: ViewForm.DBNode := Childwin.DBRightClickSelectedItem.Parent;
|
||||
end;
|
||||
// Create mode. Nothing special here.
|
||||
end;
|
||||
ViewForm.ShowModal;
|
||||
end;
|
||||
@ -1096,48 +1089,25 @@ end;
|
||||
procedure TMainForm.DropTablesAndViewsExecute(Sender: TObject);
|
||||
var
|
||||
i : Integer;
|
||||
tndb : TTreeNode;
|
||||
Objects, Tables, Views : TStringList;
|
||||
db, msg, sql, activeDB : String;
|
||||
ds: TDataSet;
|
||||
Tables, Views : TStringList;
|
||||
msg, sql, activeDB : String;
|
||||
begin
|
||||
debug('drop table activated');
|
||||
// Set default database name to to ActiveDatabase.
|
||||
// Can be overwritten when someone selects a table in dbtree from different database
|
||||
activeDB := Childwin.ActiveDatabase;
|
||||
db := activeDB;
|
||||
tndb := nil;
|
||||
|
||||
// Fill "Objects" and leave "Tables" and "Views" empty to postpone detection
|
||||
// of views|tables to below this IF statement
|
||||
Objects := TStringlist.Create;
|
||||
Tables := TStringlist.Create;
|
||||
Views := TStringlist.Create;
|
||||
if (Sender as TBasicAction).ActionComponent = Childwin.PopupMenuDropTable then begin
|
||||
// Invoked by tree menu popup.
|
||||
tndb := Childwin.DBRightClickSelectedItem.Parent;
|
||||
db := tndb.Text;
|
||||
Objects.add( Childwin.DBRightClickSelectedItem.Text );
|
||||
end else if Childwin.PageControlMain.ActivePage = Childwin.tabDatabase then begin
|
||||
if Childwin.PageControlMain.ActivePage = Childwin.tabDatabase then begin
|
||||
// Invoked from one of the various buttons, SheetDatabase is the active page, drop highlighted table(s).
|
||||
Tables := GetVTCaptions(Childwin.ListTables, True, 0, NODETYPE_BASETABLE);
|
||||
Views := GetVTCaptions(Childwin.ListTables, True, 0, NODETYPE_VIEW);
|
||||
end else begin
|
||||
// Invoked from one of the various buttons, drop table selected in tree view.
|
||||
Objects.add( Childwin.SelectedTable );
|
||||
end;
|
||||
|
||||
// Split Objects into Tables + Views if not already done
|
||||
if (Tables.Count = 0) and (Views.Count = 0) and (Objects.Count > 0) then begin
|
||||
ds := Childwin.GetResults('SHOW TABLE STATUS FROM '+Childwin.mask(db));
|
||||
for i := 0 to Objects.Count - 1 do begin
|
||||
while not ds.Eof do begin
|
||||
case GetDBObjectType( ds.Fields ) of
|
||||
NODETYPE_BASETABLE: begin Tables.Add(Objects[i]); break; end;
|
||||
NODETYPE_VIEW: begin Views.Add(Objects[i]); break; end;
|
||||
end;
|
||||
ds.Next;
|
||||
end;
|
||||
case Childwin.GetSelectedNodeType of
|
||||
NODETYPE_BASETABLE: Tables.Add(Childwin.SelectedTable);
|
||||
NODETYPE_VIEW: Views.Add(Childwin.SelectedTable)
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1149,12 +1119,10 @@ begin
|
||||
Exit;
|
||||
|
||||
// Ask user for confirmation to drop selected objects
|
||||
Objects.Clear;
|
||||
Objects.AddStrings(Tables);
|
||||
Objects.AddStrings(Views);
|
||||
msg := 'Drop ' + IntToStr(Objects.Count) + ' table(s) and/or view(s) in database "'+db+'"?'
|
||||
+ CRLF + CRLF + ImplodeStr(', ', Objects);
|
||||
FreeAndNil(Objects);
|
||||
msg := 'Drop ' + IntToStr(Tables.Count+Views.Count) + ' table(s) and/or view(s) in database "'+activeDB+'"?'
|
||||
+ CRLF;
|
||||
if Tables.Count > 0 then msg := msg + CRLF + 'Tables: ' + ImplodeStr(', ', Tables);
|
||||
if Views.Count > 0 then msg := msg + CRLF + 'Views: ' + ImplodeStr(', ', Views);
|
||||
if MessageDlg(msg, mtConfirmation, [mbok,mbcancel], 0) <> mrok then
|
||||
Exit;
|
||||
|
||||
@ -1165,8 +1133,6 @@ begin
|
||||
begin
|
||||
if i > 0 then
|
||||
sql := sql + ', ';
|
||||
if db <> activeDB then
|
||||
sql := sql + Childwin.mask(db) + '.';
|
||||
sql := sql + Childwin.mask(Tables[i]);
|
||||
end;
|
||||
Childwin.ExecUpdateQuery( sql );
|
||||
@ -1180,8 +1146,6 @@ begin
|
||||
begin
|
||||
if i > 0 then
|
||||
sql := sql + ', ';
|
||||
if db <> activeDB then
|
||||
sql := sql + Childwin.mask(db) + '.';
|
||||
sql := sql + Childwin.mask(Views[i]);
|
||||
end;
|
||||
Childwin.ExecUpdateQuery( sql );
|
||||
@ -1189,10 +1153,7 @@ begin
|
||||
FreeAndNil(Views);
|
||||
|
||||
// Refresh ListTables + dbtree so the dropped tables are gone:
|
||||
if db = activeDB then
|
||||
Childwin.MenuRefreshClick(Sender)
|
||||
else
|
||||
Childwin.PopulateTreeTableList( tndb, True );
|
||||
Childwin.MenuRefreshClick(Sender)
|
||||
end;
|
||||
|
||||
|
||||
|
@ -95,24 +95,12 @@ end;
|
||||
}
|
||||
procedure Toptimize.FormShow(Sender: TObject);
|
||||
var
|
||||
i : Integer;
|
||||
tn : TTreeNode;
|
||||
Selected: TStringList;
|
||||
begin
|
||||
// read dbs and Tables from treeview
|
||||
DBComboBox.Items.Clear;
|
||||
for i:=0 to Mainform.ChildWin.DBTree.Items.Count-1 do
|
||||
begin
|
||||
tn := Mainform.ChildWin.DBTree.Items[i];
|
||||
if tn.Level = 1 then
|
||||
DBComboBox.Items.Add(tn.Text);
|
||||
end;
|
||||
DBComboBox.ItemIndex := 0;
|
||||
for i:=0 to DBComboBox.Items.Count-1 do
|
||||
begin
|
||||
if DBComboBox.Items[i] = Mainform.ChildWin.ActiveDatabase then
|
||||
DBComboBox.ItemIndex := i;
|
||||
end;
|
||||
DBComboBox.Items.Assign(Mainform.ChildWin.Databases);
|
||||
DBComboBox.ItemIndex := DBComboBox.Items.IndexOf( Mainform.ChildWin.ActiveDatabase );
|
||||
if DBComboBox.ItemIndex = -1 then
|
||||
DBComboBox.ItemIndex := 0;
|
||||
DBComboBox.OnChange(self);
|
||||
|
@ -39,7 +39,6 @@ type
|
||||
PVirtualNode; var InitialStates: TVirtualNodeInitStates);
|
||||
private
|
||||
{ Private declarations }
|
||||
FDatabases: TStringList;
|
||||
FColumns: Array of Array of TStringList;
|
||||
function GetSelectedObject: TStringList;
|
||||
public
|
||||
@ -111,19 +110,11 @@ begin
|
||||
end;
|
||||
|
||||
procedure TfrmSelectDBObject.FormShow(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
CWin := Mainform.Childwin;
|
||||
TreeDBO.Clear;
|
||||
FDatabases := TStringList.Create;
|
||||
for i := 0 to CWin.DBtree.Items.Count - 1 do begin
|
||||
if CWin.DBtree.Items[i].Level <> 1 then
|
||||
continue;
|
||||
FDatabases.Add(CWin.DBtree.Items[i].Text);
|
||||
end;
|
||||
TreeDBO.RootNodeCount := FDatabases.Count;
|
||||
SetLength(FColumns, FDatabases.Count);
|
||||
TreeDBO.RootNodeCount := CWin.Databases.Count;
|
||||
SetLength(FColumns, CWin.Databases.Count);
|
||||
// TreeDBO.OnFocusChanged(TreeDBO, TreeDBO.FocusedNode, 0);
|
||||
editDB.Clear;
|
||||
editTable.Clear;
|
||||
@ -186,7 +177,7 @@ begin
|
||||
case Sender.GetNodeLevel(Node) of
|
||||
0: ImageIndex := ICONINDEX_DB;
|
||||
1: begin
|
||||
ds := CWin.FetchDbTableList(FDatabases[Node.Parent.Index]);
|
||||
ds := CWin.FetchDbTableList(CWin.Databases[Node.Parent.Index]);
|
||||
ds.RecNo := Node.Index+1;
|
||||
case GetDBObjectType(ds.Fields) of
|
||||
NODETYPE_BASETABLE: ImageIndex := ICONINDEX_TABLE;
|
||||
@ -214,15 +205,15 @@ begin
|
||||
// Fetch sub nodes
|
||||
case Sender.GetNodeLevel(Node) of
|
||||
0: begin // DB expanding
|
||||
ds := CWin.FetchDbTableList(FDatabases[Node.Index]);
|
||||
ds := CWin.FetchDbTableList(CWin.Databases[Node.Index]);
|
||||
ChildCount := ds.RecordCount;
|
||||
SetLength(FColumns[Node.Index], ds.RecordCount);
|
||||
end;
|
||||
1: begin // Table expanding
|
||||
ds := CWin.FetchDbTableList(FDatabases[Node.Parent.Index]);
|
||||
ds := CWin.FetchDbTableList(CWin.Databases[Node.Parent.Index]);
|
||||
ds.RecNo := Node.Index+1;
|
||||
cols := CWin.GetCol('SHOW COLUMNS FROM '
|
||||
+ Mainform.mask(FDatabases[Node.Parent.Index])+'.'
|
||||
+ Mainform.mask(CWin.Databases[Node.Parent.Index])+'.'
|
||||
+ Mainform.Mask(ds.Fields[0].AsString));
|
||||
FColumns[Node.Parent.Index][Node.Index] := cols;
|
||||
ChildCount := cols.Count;
|
||||
@ -239,9 +230,9 @@ var
|
||||
ds: TDataset;
|
||||
begin
|
||||
case Sender.GetNodeLevel(Node) of
|
||||
0: CellText := FDatabases[Node.Index];
|
||||
0: CellText := CWin.Databases[Node.Index];
|
||||
1: begin
|
||||
ds := CWin.FetchDbTableList(FDatabases[Node.Parent.Index]);
|
||||
ds := CWin.FetchDbTableList(CWin.Databases[Node.Parent.Index]);
|
||||
ds.RecNo := Node.Index+1;
|
||||
CellText := ds.Fields[0].AsString;
|
||||
end;
|
||||
|
@ -52,7 +52,6 @@ type
|
||||
currentCollation,
|
||||
currentAutoincrement : String;
|
||||
public
|
||||
DatabaseName,
|
||||
TableName : String;
|
||||
end;
|
||||
|
||||
@ -128,8 +127,6 @@ var
|
||||
begin
|
||||
// Fetch table properties
|
||||
sql := 'SHOW TABLE STATUS ';
|
||||
if DatabaseName <> '' then
|
||||
sql := sql + ' FROM ' + Mainform.mask(DatabaseName)+' ';
|
||||
sql := sql + 'LIKE '+esc(TableName);
|
||||
ds := Mainform.Childwin.GetResults(sql);
|
||||
|
||||
@ -183,8 +180,6 @@ begin
|
||||
|
||||
// SQL preview
|
||||
sql := 'SHOW CREATE TABLE ';
|
||||
if DatabaseName <> '' then
|
||||
sql := sql + Mainform.mask(DatabaseName)+'.';
|
||||
sql := sql + Mainform.Childwin.mask(currentName);
|
||||
SynMemoCreate.Lines.Text := Mainform.Childwin.GetVar( sql, 1 );
|
||||
|
||||
@ -278,8 +273,6 @@ begin
|
||||
if currentName <> editName.Text then
|
||||
begin
|
||||
tmp := 'RENAME ';
|
||||
if DatabaseName <> '' then
|
||||
tmp := tmp + Mainform.mask(DatabaseName)+'.';
|
||||
tmp := tmp + Mainform.mask(editName.Text);
|
||||
AlterSpecs.Add( tmp );
|
||||
end;
|
||||
@ -306,16 +299,9 @@ begin
|
||||
|
||||
if AlterSpecs.Count > 0 then
|
||||
begin
|
||||
sql := 'ALTER TABLE ';
|
||||
if DatabaseName <> '' then
|
||||
sql := sql + Mainform.mask(DatabaseName)+'.';
|
||||
sql := sql + Mainform.Childwin.mask(currentName) + ' ' + ImplodeStr(', ', AlterSpecs);
|
||||
sql := 'ALTER TABLE ' + Mainform.Childwin.mask(currentName) + ' ' + ImplodeStr(', ', AlterSpecs);
|
||||
try
|
||||
Mainform.ChildWin.ExecUpdateQuery( sql );
|
||||
if DatabaseName = '' then
|
||||
Mainform.ChildWin.MenuRefreshClick( Sender )
|
||||
else
|
||||
Mainform.ChildWin.PopulateTreeTableList( Mainform.ChildWin.DBRightClickSelectedItem.Parent, True );
|
||||
except
|
||||
On E:Exception do
|
||||
begin
|
||||
@ -324,6 +310,7 @@ begin
|
||||
ModalResult := mrNone;
|
||||
end;
|
||||
end;
|
||||
Mainform.ChildWin.MenuRefreshClick( Sender )
|
||||
end;
|
||||
|
||||
end;
|
||||
|
@ -28,7 +28,6 @@ type
|
||||
public
|
||||
{ Public declarations }
|
||||
EditViewName: String;
|
||||
DBNode: TTreeNode;
|
||||
end;
|
||||
|
||||
|
||||
@ -83,10 +82,7 @@ begin
|
||||
// Edit mode
|
||||
Caption := 'Edit view ...';
|
||||
editName.Text := EditViewName;
|
||||
if not Assigned(DBNode) then
|
||||
db := Mainform.ChildWin.ActiveDatabase
|
||||
else
|
||||
db := DBNode.Text;
|
||||
db := Mainform.ChildWin.ActiveDatabase;
|
||||
ds := Mainform.ChildWin.GetResults('SELECT * FROM '+Mainform.mask(DBNAME_INFORMATION_SCHEMA)+'.VIEWS ' +
|
||||
'WHERE TABLE_SCHEMA = '+esc(db)+' AND TABLE_NAME = '+esc(EditViewName));
|
||||
if ds.RecordCount = 0 then
|
||||
@ -167,8 +163,6 @@ begin
|
||||
viewname := EditViewName;
|
||||
end;
|
||||
viewname := Mainform.mask(viewname);
|
||||
if Assigned(DBNode) then
|
||||
viewname := Mainform.mask(DBNode.Text) + '.' + viewname;
|
||||
if rgAlgorithm.Enabled and (rgAlgorithm.ItemIndex > -1) then
|
||||
sql := sql + 'ALGORITHM = '+Uppercase(rgAlgorithm.Items[rgAlgorithm.ItemIndex])+' ';
|
||||
sql := sql + 'VIEW ' + viewname+' AS '+SynMemoSelect.Text+' ';
|
||||
@ -181,15 +175,10 @@ begin
|
||||
// Probably rename view
|
||||
if (EditViewName <> '') and (EditViewName <> editName.Text) then begin
|
||||
renamed := Mainform.mask(editName.Text);
|
||||
if Assigned(DBNode) then
|
||||
renamed := Mainform.mask(DBNode.Text) + '.' + renamed;
|
||||
Mainform.Childwin.ExecUpdateQuery('ALTER TABLE '+viewname
|
||||
+ ' RENAME '+renamed);
|
||||
end;
|
||||
if (not Assigned(DBNode)) or (DBNode.Text = Mainform.Childwin.ActiveDatabase) then
|
||||
Mainform.ChildWin.MenuRefreshClick( Sender )
|
||||
else
|
||||
Mainform.ChildWin.PopulateTreeTableList( DBNode, True );
|
||||
Mainform.ChildWin.RefreshTreeDB(Mainform.ChildWin.ActiveDatabase);
|
||||
except
|
||||
on E: THandledSQLError do begin
|
||||
MessageDlg(E.Message, mtError, [mbOK], 0);
|
||||
|
Reference in New Issue
Block a user