mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
Recycle CreateDatabase-form after first usage / don't FreeAndNil' it. Avoids 3 SQL-queries for each calling time after the first one.
This commit is contained in:
@@ -22,7 +22,7 @@ uses
|
||||
ZSqlMonitor, EDBImage, ZDbcLogging,
|
||||
SynCompletionProposal, HeidiComp, SynEditMiscClasses, MysqlQuery,
|
||||
MysqlQueryThread, queryprogress, communication, MysqlConn, smdbgrid, Tabs,
|
||||
VirtualTrees;
|
||||
VirtualTrees, createdatabase;
|
||||
|
||||
|
||||
type
|
||||
@@ -533,6 +533,7 @@ type
|
||||
CachedTableLists : TStringList;
|
||||
QueryHelpersSelectedItems : Array[0..3] of Integer;
|
||||
ListTablesColumnNames : TStringList;
|
||||
CreateDatabaseForm : TCreateDatabaseForm;
|
||||
|
||||
function GetQueryRunning: Boolean;
|
||||
procedure SetQueryRunning(running: Boolean);
|
||||
@@ -618,7 +619,7 @@ uses
|
||||
Main, createtable, fieldeditor, tbl_properties, tblcomment,
|
||||
optimizetables, copytable, sqlhelp, printlist,
|
||||
column_selection, data_sorting, runsqlfile, mysql,
|
||||
Registry, createdatabase;
|
||||
Registry;
|
||||
|
||||
|
||||
{$I const.inc}
|
||||
@@ -3329,19 +3330,19 @@ end;
|
||||
|
||||
|
||||
procedure TMDIChild.CreateDatabase(Sender: TObject);
|
||||
var
|
||||
f : TCreateDatabaseForm;
|
||||
begin
|
||||
// Create database:
|
||||
// - create modal form
|
||||
// - rely on the modalresult being set correctly
|
||||
f := TCreateDatabaseForm.Create(Self);
|
||||
if f.ShowModal = mrOK then
|
||||
// Create modal form once on demand
|
||||
if CreateDatabaseForm = nil then
|
||||
CreateDatabaseForm := TCreateDatabaseForm.Create(Self);
|
||||
|
||||
// Rely on the modalresult being set correctly
|
||||
if CreateDatabaseForm.ShowModal = mrOK then
|
||||
begin
|
||||
// Add DB to OnlyDBs-regkey if this is not empty
|
||||
if OnlyDBs.Count > 0 then
|
||||
begin
|
||||
OnlyDBs.Add( f.editDBName.Text );
|
||||
OnlyDBs.Add( CreateDatabaseForm.editDBName.Text );
|
||||
with TRegistry.Create do
|
||||
begin
|
||||
if OpenKey(REGPATH + '\Servers\' + FConn.Description, false) then
|
||||
@@ -3353,9 +3354,8 @@ begin
|
||||
end;
|
||||
// Todo: Don't expand node of old database in dbtree, just reload and switch to new one
|
||||
ReadDatabasesAndTables(self);
|
||||
ActiveDatabase := f.editDBName.Text;
|
||||
ActiveDatabase := CreateDatabaseForm.editDBName.Text;
|
||||
end;
|
||||
FreeAndNil(f);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
@@ -20,10 +20,12 @@ type
|
||||
procedure comboCharsetChange(Sender: TObject);
|
||||
procedure editDBNameChange(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
listCharsets : TStringList;
|
||||
dsCollations : TDataSet;
|
||||
defaultCharset : String;
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
@@ -40,8 +42,6 @@ uses main, childwin, helpers;
|
||||
Fetch list with character sets and collations from the server
|
||||
}
|
||||
procedure TCreateDatabaseForm.FormCreate(Sender: TObject);
|
||||
var
|
||||
defaultCharset : String;
|
||||
begin
|
||||
try
|
||||
listCharsets := Mainform.Childwin.GetCol('SHOW CHARACTER SET');
|
||||
@@ -55,16 +55,29 @@ begin
|
||||
begin
|
||||
comboCharset.Enabled := True;
|
||||
comboCharset.Items := listCharsets;
|
||||
// Select servers default charset if possible
|
||||
// Detect servers default charset
|
||||
defaultCharset := Mainform.Childwin.GetVar( 'SHOW VARIABLES LIKE '+esc('character_set_database'), 1 );
|
||||
end;
|
||||
|
||||
comboCollation.Enabled := dsCollations <> nil;
|
||||
end;
|
||||
|
||||
|
||||
{**
|
||||
Form gets displayed: Set default values.
|
||||
}
|
||||
procedure TCreateDatabaseForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
editDBName.Text := '';
|
||||
if comboCharset.Items.Count > 0 then
|
||||
begin
|
||||
if comboCharset.Items.IndexOf(defaultCharset) > -1 then
|
||||
comboCharset.ItemIndex := comboCharset.Items.IndexOf(defaultCharset)
|
||||
else
|
||||
comboCharset.ItemIndex := 0;
|
||||
// Invoke selecting default collation
|
||||
comboCharsetChange( Sender );
|
||||
end;
|
||||
|
||||
comboCollation.Enabled := dsCollations <> nil;
|
||||
comboCharsetChange( Sender );
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user