Support filename and dirname patterns in export target combobox. Fixes issue #2622.

This commit is contained in:
Ansgar Becker
2012-12-13 20:37:01 +00:00
parent 5a4d7faa22
commit 4662ebf31e
3 changed files with 83 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2012-12-10 23:21+0100\n"
"PO-Revision-Date: 2012-12-13 21:33+0100\n"
"Last-Translator: Ansgar Becker <heidisql@anse.de>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/"
"language/en/)\n"
@@ -4018,8 +4018,8 @@ msgid "Unsupported type (%d) in %s."
msgstr "Unsupported type (%d) in %s."
#. editvar.pas
msgid "\"%s\" is a read only variable, not editable.
msgstr "\"%s\" is a read only variable, not editable.
msgid "\"%s\" is a read only variable, not editable"
msgstr "\"%s\" is a read only variable, not editable"
#: editvar.pas:90
msgid "Could not find %s variable in internal mapping."
@@ -5530,3 +5530,35 @@ msgstr "Yes to all"
#. Message dialogs
msgid "Find some help on this error"
msgstr "Find some help on this error"
#. Table tools
msgid "Allows the following replacement patterns:"
msgstr "Allows the following replacement patterns:"
#. Table tools
msgid "Date and time"
msgstr "Date and time"
#. Table tools
msgid "Day of month"
msgstr "Day of month"
#. Table tools
msgid "Month"
msgstr "Month"
#. Table tools
msgid "Year"
msgstr "Year"
#. Table tools
msgid "Hour"
msgstr "Hour"
#. Table tools
msgid "Minute"
msgstr "Minute"
#. Table tools
msgid "Second"
msgstr "Second"

View File

@@ -407,6 +407,8 @@ object frmTableTools: TfrmTableTools
Width = 263
Height = 21
Anchors = [akLeft, akTop, akRight]
ParentShowHint = False
ShowHint = True
TabOrder = 6
Text = 'comboExportOutputTarget'
OnChange = comboExportOutputTargetChange

View File

@@ -11,7 +11,7 @@ interface
uses
Windows, SysUtils, Classes, Controls, Forms, StdCtrls, ComCtrls, Buttons, Dialogs, StdActns,
VirtualTrees, ExtCtrls, Graphics, SynRegExpr, Math, Generics.Collections,
dbconnection, helpers, Menus, gnugettext;
dbconnection, helpers, Menus, gnugettext, DateUtils;
type
TToolMode = (tmMaintenance, tmFind, tmSQLExport, tmBulkTableEdit);
@@ -140,6 +140,7 @@ type
procedure DoFind(DBObj: TDBObject);
procedure DoExport(DBObj: TDBObject);
procedure DoBulkTableEdit(DBObj: TDBObject);
function GetOutputFilename(DBObj: TDBObject): String;
public
{ Public declarations }
PreSelectObjects: TDBObjectList;
@@ -920,16 +921,29 @@ end;
procedure TfrmTableTools.comboExportOutputTypeChange(Sender: TObject);
var
SessionNode, DBNode: PVirtualNode;
SessionName: String;
SessionName, FilenameHint: String;
Params: TConnectionParameters;
begin
// Target type (file, directory, ...) selected
comboExportOutputTarget.Enabled := True;
comboExportOutputTarget.Text := '';
comboExportOutputTarget.Hint := '';
FilenameHint := _('Allows the following replacement patterns:') + CRLF +
'%host: '+_('Hostname') + CRLF +
'%u: '+_('Username') + CRLF +
'%db: '+_('Database') + CRLF +
'%date: '+_('Date and time') + CRLF +
'%d: '+_('Day of month') + CRLF +
'%m: '+_('Month') + CRLF +
'%y: '+_('Year') + CRLF +
'%h: '+_('Hour') + CRLF +
'%i: '+_('Minute') + CRLF +
'%s: '+_('Second');
if Assigned(FTargetConnection) then
FreeAndNil(FTargetConnection);
if comboExportOutputType.Text = OUTPUT_FILE then begin
comboExportOutputTarget.Style := csDropDown;
comboExportOutputTarget.Hint := FilenameHint;
comboExportOutputTarget.Items.Text := AppSettings.ReadString(asExportSQLFilenames, '');
if comboExportOutputTarget.Items.Count > 0 then
comboExportOutputTarget.ItemIndex := 0;
@@ -938,6 +952,7 @@ begin
btnExportOutputTargetSelect.ImageIndex := 10;
end else if comboExportOutputType.Text = OUTPUT_DIR then begin
comboExportOutputTarget.Style := csDropDown;
comboExportOutputTarget.Hint := FilenameHint;
comboExportOutputTarget.Items.Text := AppSettings.ReadString(asExportSQLDirectories, '');
if comboExportOutputTarget.Items.Count > 0 then
comboExportOutputTarget.ItemIndex := 0;
@@ -1177,7 +1192,7 @@ begin
ExportStreamStartOfQueryPos := 0;
if ToDir then begin
FreeAndNil(ExportStream);
DbDir := IncludeTrailingPathDelimiter(comboExportOutputTarget.Text) + DBObj.Database + '\';
DbDir := IncludeTrailingPathDelimiter(GetOutputFilename(DBObj)) + DBObj.Database + '\';
if not DirectoryExists(DbDir) then
ForceDirectories(DbDir);
ExportStream := TFileStream.Create(DbDir + DBObj.Name+'.sql', fmCreate or fmOpenWrite);
@@ -1185,7 +1200,7 @@ begin
end;
if not Assigned(ExportStream) then begin
if ToFile then
ExportStream := TFileStream.Create(comboExportOutputTarget.Text, fmCreate or fmOpenWrite);
ExportStream := TFileStream.Create(GetOutputFilename(DBObj), fmCreate or fmOpenWrite);
// ToDir handled above
if ToClipboard then
ExportStream := TMemoryStream.Create;
@@ -1459,6 +1474,33 @@ begin
end;
function TfrmTableTools.GetOutputFilename(DBObj: TDBObject): String;
var
Arguments: TStringList;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
i: Integer;
Path, Filename: String;
begin
// Rich format output filename, replace certain markers. See issue #2622
Result := comboExportOutputTarget.Text;
Arguments := TStringList.Create;
Arguments.Values['host'] := goodfilename(DBObj.Connection.Parameters.Hostname);
Arguments.Values['u'] := goodfilename(DBObj.Connection.Parameters.Username);
Arguments.Values['db'] := goodfilename(DBObj.Database);
Arguments.Values['date'] := goodfilename(DateTimeToStr(Now));
DecodeDateTime(Now, Year, Month, Day, Hour, Min, Sec, MSec);
Arguments.Values['d'] := Format('%.2d', [Day]);
Arguments.Values['m'] := Format('%.2d', [Month]);
Arguments.Values['y'] := Format('%.4d', [Year]);
Arguments.Values['h'] := Format('%.2d', [Hour]);
Arguments.Values['i'] := Format('%.2d', [Min]);
Arguments.Values['s'] := Format('%.2d', [Sec]);
for i:=0 to Arguments.Count-1 do begin
Result := StringReplace(Result, '%'+Arguments.Names[i], Arguments.ValueFromIndex[i], [rfReplaceAll]);
end;
end;
procedure TfrmTableTools.chkBulkTableEditCheckComboClick(Sender: TObject);
var
chk: TCheckBox;