mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 11:17:57 +08:00
Move detection of best table name to helpers unit, away from several methods where we make use of it. Fixes issue #1967.
This commit is contained in:
@ -90,10 +90,11 @@ type
|
|||||||
function encrypt(str: String): String;
|
function encrypt(str: String): String;
|
||||||
function decrypt(str: String): String;
|
function decrypt(str: String): String;
|
||||||
function htmlentities(str: String): String;
|
function htmlentities(str: String): String;
|
||||||
procedure GridToHtml(Grid: TVirtualStringTree; Title: String; S: TStream);
|
procedure GridToHtml(Grid: TVirtualStringTree; S: TStream);
|
||||||
procedure GridToCsv(Grid: TVirtualStringTree; Separator, Encloser, Terminator: String; S: TStream);
|
procedure GridToCsv(Grid: TVirtualStringTree; Separator, Encloser, Terminator: String; S: TStream);
|
||||||
procedure GridToXml(Grid: TVirtualStringTree; root: String; S: TStream);
|
procedure GridToXml(Grid: TVirtualStringTree; S: TStream);
|
||||||
procedure GridToSql(Grid: TVirtualStringTree; Tablename: String; S: TStream);
|
procedure GridToSql(Grid: TVirtualStringTree; S: TStream);
|
||||||
|
function BestTableName(Data: TMySQLQuery): String;
|
||||||
function esc2ascii(str: String): String;
|
function esc2ascii(str: String): String;
|
||||||
function urlencode(url: String): String;
|
function urlencode(url: String): String;
|
||||||
procedure StreamWrite(S: TStream; Text: String = '');
|
procedure StreamWrite(S: TStream; Text: String = '');
|
||||||
@ -557,10 +558,10 @@ end;
|
|||||||
@param Grid Object which holds data to export
|
@param Grid Object which holds data to export
|
||||||
@param string Text used in <title>
|
@param string Text used in <title>
|
||||||
}
|
}
|
||||||
procedure GridToHtml(Grid: TVirtualStringTree; Title: String; S: TStream);
|
procedure GridToHtml(Grid: TVirtualStringTree; S: TStream);
|
||||||
var
|
var
|
||||||
i, MaxSize: Integer;
|
i, MaxSize: Integer;
|
||||||
tmp, Data, Generator: String;
|
tmp, Data, Generator, Title: String;
|
||||||
Node: PVirtualNode;
|
Node: PVirtualNode;
|
||||||
GridData: TMySQLQuery;
|
GridData: TMySQLQuery;
|
||||||
SelectionOnly: Boolean;
|
SelectionOnly: Boolean;
|
||||||
@ -572,6 +573,7 @@ begin
|
|||||||
|
|
||||||
Mainform.DataGridEnsureFullRows(Grid, SelectionOnly);
|
Mainform.DataGridEnsureFullRows(Grid, SelectionOnly);
|
||||||
GridData := Mainform.GridResult(Grid);
|
GridData := Mainform.GridResult(Grid);
|
||||||
|
Title := BestTableName(GridData);
|
||||||
|
|
||||||
MaxSize := GetRegValue(REGNAME_COPYMAXSIZE, DEFAULT_COPYMAXSIZE) * SIZE_MB;
|
MaxSize := GetRegValue(REGNAME_COPYMAXSIZE, DEFAULT_COPYMAXSIZE) * SIZE_MB;
|
||||||
|
|
||||||
@ -779,10 +781,10 @@ end;
|
|||||||
@param Grid Object which holds data to export
|
@param Grid Object which holds data to export
|
||||||
@param string Text used as root-element
|
@param string Text used as root-element
|
||||||
}
|
}
|
||||||
procedure GridToXml(Grid: TVirtualStringTree; root: String; S: TStream);
|
procedure GridToXml(Grid: TVirtualStringTree; S: TStream);
|
||||||
var
|
var
|
||||||
i, MaxSize: Integer;
|
i, MaxSize: Integer;
|
||||||
tmp, Data: String;
|
tmp, Data, root: String;
|
||||||
Node: PVirtualNode;
|
Node: PVirtualNode;
|
||||||
GridData: TMySQLQuery;
|
GridData: TMySQLQuery;
|
||||||
SelectionOnly: Boolean;
|
SelectionOnly: Boolean;
|
||||||
@ -794,6 +796,7 @@ begin
|
|||||||
|
|
||||||
Mainform.DataGridEnsureFullRows(Grid, SelectionOnly);
|
Mainform.DataGridEnsureFullRows(Grid, SelectionOnly);
|
||||||
GridData := Mainform.GridResult(Grid);
|
GridData := Mainform.GridResult(Grid);
|
||||||
|
root := BestTableName(GridData);
|
||||||
|
|
||||||
MaxSize := GetRegValue(REGNAME_COPYMAXSIZE, DEFAULT_COPYMAXSIZE) * SIZE_MB;
|
MaxSize := GetRegValue(REGNAME_COPYMAXSIZE, DEFAULT_COPYMAXSIZE) * SIZE_MB;
|
||||||
|
|
||||||
@ -860,10 +863,10 @@ end;
|
|||||||
@param Grid Object which holds data to export
|
@param Grid Object which holds data to export
|
||||||
@param string Text used as tablename in INSERTs
|
@param string Text used as tablename in INSERTs
|
||||||
}
|
}
|
||||||
procedure GridToSql(Grid: TVirtualStringTree; Tablename: String; S: TStream);
|
procedure GridToSql(Grid: TVirtualStringTree; S: TStream);
|
||||||
var
|
var
|
||||||
i, MaxSize: Integer;
|
i, MaxSize: Integer;
|
||||||
tmp, Data: String;
|
tmp, Data, TableName: String;
|
||||||
Node: PVirtualNode;
|
Node: PVirtualNode;
|
||||||
GridData: TMySQLQuery;
|
GridData: TMySQLQuery;
|
||||||
SelectionOnly: Boolean;
|
SelectionOnly: Boolean;
|
||||||
@ -875,6 +878,7 @@ begin
|
|||||||
|
|
||||||
Mainform.DataGridEnsureFullRows(Grid, SelectionOnly);
|
Mainform.DataGridEnsureFullRows(Grid, SelectionOnly);
|
||||||
GridData := Mainform.GridResult(Grid);
|
GridData := Mainform.GridResult(Grid);
|
||||||
|
TableName := BestTableName(GridData);
|
||||||
|
|
||||||
MaxSize := GetRegValue(REGNAME_COPYMAXSIZE, DEFAULT_COPYMAXSIZE) * SIZE_MB;
|
MaxSize := GetRegValue(REGNAME_COPYMAXSIZE, DEFAULT_COPYMAXSIZE) * SIZE_MB;
|
||||||
|
|
||||||
@ -937,6 +941,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function BestTableName(Data: TMySQLQuery): String;
|
||||||
|
begin
|
||||||
|
// Get table name from result if possible. Used by GridToXYZ() functions.
|
||||||
|
try
|
||||||
|
Result := Data.TableName;
|
||||||
|
except
|
||||||
|
Result := 'UnknownTable';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{***
|
{***
|
||||||
Return ASCII-Values from MySQL-Escape-Sequences
|
Return ASCII-Values from MySQL-Escape-Sequences
|
||||||
|
@ -2223,15 +2223,12 @@ end;
|
|||||||
procedure TMainForm.actCopyAsHTMLExecute(Sender: TObject);
|
procedure TMainForm.actCopyAsHTMLExecute(Sender: TObject);
|
||||||
var
|
var
|
||||||
S: TMemoryStream;
|
S: TMemoryStream;
|
||||||
Title: String;
|
|
||||||
begin
|
begin
|
||||||
// Copy data in focused grid as HTML table
|
// Copy data in focused grid as HTML table
|
||||||
Screen.Cursor := crHourglass;
|
Screen.Cursor := crHourglass;
|
||||||
S := TMemoryStream.Create;
|
S := TMemoryStream.Create;
|
||||||
if ActiveGrid = DataGrid then Title := SelectedTable.Name
|
|
||||||
else Title := 'SQL query';
|
|
||||||
try
|
try
|
||||||
GridToHtml(ActiveGrid, Title, S);
|
GridToHtml(ActiveGrid, S);
|
||||||
StreamToClipboard(S, S, True);
|
StreamToClipboard(S, S, True);
|
||||||
finally
|
finally
|
||||||
ShowStatusMsg('Freeing data...');
|
ShowStatusMsg('Freeing data...');
|
||||||
@ -2245,15 +2242,12 @@ end;
|
|||||||
procedure TMainForm.actCopyAsXMLExecute(Sender: TObject);
|
procedure TMainForm.actCopyAsXMLExecute(Sender: TObject);
|
||||||
var
|
var
|
||||||
S: TMemoryStream;
|
S: TMemoryStream;
|
||||||
Root: String;
|
|
||||||
begin
|
begin
|
||||||
// Copy data in focused grid as XML
|
// Copy data in focused grid as XML
|
||||||
Screen.Cursor := crHourglass;
|
Screen.Cursor := crHourglass;
|
||||||
S := TMemoryStream.Create;
|
S := TMemoryStream.Create;
|
||||||
if ActiveGrid = DataGrid then Root := SelectedTable.Name
|
|
||||||
else Root := 'SQL query';
|
|
||||||
try
|
try
|
||||||
GridToXml(ActiveGrid, Root, S);
|
GridToXml(ActiveGrid, S);
|
||||||
StreamToClipboard(S, nil, False);
|
StreamToClipboard(S, nil, False);
|
||||||
finally
|
finally
|
||||||
ShowStatusMsg('Freeing data...');
|
ShowStatusMsg('Freeing data...');
|
||||||
@ -2267,16 +2261,13 @@ end;
|
|||||||
procedure TMainForm.actCopyAsSQLExecute(Sender: TObject);
|
procedure TMainForm.actCopyAsSQLExecute(Sender: TObject);
|
||||||
var
|
var
|
||||||
S, HTML: TMemoryStream;
|
S, HTML: TMemoryStream;
|
||||||
Tablename: String;
|
|
||||||
Content: AnsiString;
|
Content: AnsiString;
|
||||||
begin
|
begin
|
||||||
// Copy data in focused grid as SQL
|
// Copy data in focused grid as SQL
|
||||||
Screen.Cursor := crHourglass;
|
Screen.Cursor := crHourglass;
|
||||||
S := TMemoryStream.Create;
|
S := TMemoryStream.Create;
|
||||||
if ActiveGrid = DataGrid then Tablename := SelectedTable.Name
|
|
||||||
else Tablename := 'unknown';
|
|
||||||
try
|
try
|
||||||
GridToSql(ActiveGrid, Tablename, S);
|
GridToSql(ActiveGrid, S);
|
||||||
SetLength(Content, S.Size);
|
SetLength(Content, S.Size);
|
||||||
S.Position := 0;
|
S.Position := 0;
|
||||||
S.Read(PAnsiChar(Content)^, S.Size);
|
S.Read(PAnsiChar(Content)^, S.Size);
|
||||||
@ -2297,27 +2288,19 @@ procedure TMainForm.actExportDataExecute(Sender: TObject);
|
|||||||
var
|
var
|
||||||
Dialog: TSaveDialog;
|
Dialog: TSaveDialog;
|
||||||
FS: TFileStream;
|
FS: TFileStream;
|
||||||
Title: String;
|
|
||||||
begin
|
begin
|
||||||
// Save data in current dataset as CSV, HTML or XML
|
// Save data in current dataset as CSV, HTML or XML
|
||||||
Dialog := SaveDialogExportData;
|
Dialog := SaveDialogExportData;
|
||||||
|
Dialog.FileName := BestTableName(GridResult(ActiveGrid));
|
||||||
if ActiveGrid = DataGrid then
|
|
||||||
Title := SelectedTable.Name
|
|
||||||
else
|
|
||||||
Title := 'SQL query';
|
|
||||||
|
|
||||||
Dialog.FileName := Title;
|
|
||||||
Dialog.Title := 'Export result set from '+Dialog.Filename+'...';
|
Dialog.Title := 'Export result set from '+Dialog.Filename+'...';
|
||||||
|
|
||||||
if Dialog.Execute and (Dialog.FileName <> '') then try
|
if Dialog.Execute and (Dialog.FileName <> '') then try
|
||||||
Screen.Cursor := crHourGlass;
|
Screen.Cursor := crHourGlass;
|
||||||
FS := TFileStream.Create(Dialog.FileName, fmCreate or fmOpenWrite);
|
FS := TFileStream.Create(Dialog.FileName, fmCreate or fmOpenWrite);
|
||||||
case Dialog.FilterIndex of
|
case Dialog.FilterIndex of
|
||||||
1: GridToCsv(ActiveGrid, prefCSVSeparator, prefCSVEncloser, prefCSVTerminator, FS);
|
1: GridToCsv(ActiveGrid, prefCSVSeparator, prefCSVEncloser, prefCSVTerminator, FS);
|
||||||
2: GridToHtml(ActiveGrid, Title, FS);
|
2: GridToHtml(ActiveGrid, FS);
|
||||||
3: GridToXml(ActiveGrid, Title, FS);
|
3: GridToXml(ActiveGrid, FS);
|
||||||
4: GridToSql(ActiveGrid, Title, FS);
|
4: GridToSql(ActiveGrid, FS);
|
||||||
end;
|
end;
|
||||||
ShowStatusMsg('Freeing data...');
|
ShowStatusMsg('Freeing data...');
|
||||||
FS.Free;
|
FS.Free;
|
||||||
|
Reference in New Issue
Block a user