Add new "Options" dropdown button on SQL export dialog, and two new true/false settings: "Add comments" and "Remove auto_increment clauses".

* see http://www.heidisql.com/forum.php?t=18727#p18729
* see http://www.heidisql.com/forum.php?t=20363#p20373
This commit is contained in:
Ansgar Becker
2016-01-13 19:22:41 +00:00
parent bdaddea7ea
commit c7ad2b7dc1
4 changed files with 113 additions and 47 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: 2015-12-20 12:02+0100\n"
"PO-Revision-Date: 2016-01-13 20:15+0100\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/"
"language/en/)\n"
@@ -6186,3 +6186,9 @@ msgstr "Lower Case Block"
msgid "Column data type %s requires a length/set"
msgstr "Column data type %s requires a length/set"
msgid "Add comments"
msgstr "Add comments"
msgid "Remove AUTO_INCREMENT clauses"
msgstr "Remove AUTO_INCREMENT clauses"

View File

@@ -144,7 +144,8 @@ type
asSSLCert, asSSLCA, asSSLCipher, asNetType, asCompressed, asLocalTimeZone, asQueryTimeout,
asStartupScriptFilename, asDatabases, asComment, asDatabaseFilter, asTableFilter, asExportSQLCreateDatabases,
asExportSQLCreateTables, asExportSQLDataHow, asExportSQLDataInsertSize, asExportSQLFilenames, asExportZIPFilenames, asExportSQLDirectories,
asExportSQLDatabase, asExportSQLServerDatabase, asExportSQLOutput, asGridExportOutputCopy, asGridExportOutputFile,
asExportSQLDatabase, asExportSQLServerDatabase, asExportSQLOutput, asExportSQLAddComments, asExportSQLRemoveAutoIncrement,
asGridExportOutputCopy, asGridExportOutputFile,
asGridExportFilename, asGridExportRecentFiles, asGridExportEncoding, asGridExportFormat, asGridExportSelection,
asGridExportColumnNames, asGridExportIncludeAutoInc, asGridExportIncludeQuery,
asGridExportSeparator, asGridExportEncloser, asGridExportTerminator, asGridExportNull, asCSVImportSeparator,
@@ -3231,6 +3232,8 @@ begin
InitSetting(asExportSQLDatabase, 'ExportSQL_Database', 0, False, '');
InitSetting(asExportSQLServerDatabase, 'ExportSQL_ServerDatabase', 0, False, '');
InitSetting(asExportSQLOutput, 'ExportSQL_Output', 0);
InitSetting(asExportSQLAddComments, 'ExportSQLAddComments', 0, True);
InitSetting(asExportSQLRemoveAutoIncrement, 'ExportSQLRemoveAutoIncrement', 0, False);
InitSetting(asGridExportOutputCopy, 'GridExportOutputCopy', 0, True);
InitSetting(asGridExportOutputFile, 'GridExportOutputFile', 0, False);
InitSetting(asGridExportFilename, 'GridExportFilename', 0, False, '');

View File

@@ -3,7 +3,7 @@ object frmTableTools: TfrmTableTools
Top = 126
Caption = 'Table tools'
ClientHeight = 383
ClientWidth = 544
ClientWidth = 764
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
@@ -17,7 +17,7 @@ object frmTableTools: TfrmTableTools
OnDestroy = FormDestroy
OnShow = FormShow
DesignSize = (
544
764
383)
PixelsPerInch = 96
TextHeight = 13
@@ -30,7 +30,7 @@ object frmTableTools: TfrmTableTools
Caption = 'lblCheckedSize'
end
object btnCloseOrCancel: TButton
Left = 441
Left = 661
Top = 350
Width = 95
Height = 25
@@ -45,7 +45,7 @@ object frmTableTools: TfrmTableTools
AlignWithMargins = True
Left = 8
Top = 8
Width = 528
Width = 748
Height = 336
Margins.Left = 8
Margins.Top = 8
@@ -109,7 +109,7 @@ object frmTableTools: TfrmTableTools
object pnlRight: TPanel
Left = 148
Top = 0
Width = 380
Width = 600
Height = 336
Align = alClient
BevelOuter = bvNone
@@ -117,7 +117,7 @@ object frmTableTools: TfrmTableTools
object ResultGrid: TVirtualStringTree
Left = 0
Top = 180
Width = 380
Width = 600
Height = 156
Align = alClient
Header.AutoSizeIndex = -1
@@ -142,7 +142,7 @@ object frmTableTools: TfrmTableTools
object tabsTools: TPageControl
Left = 0
Top = 0
Width = 380
Width = 600
Height = 180
ActivePage = tabSQLexport
Align = alTop
@@ -153,7 +153,7 @@ object frmTableTools: TfrmTableTools
Caption = 'Maintenance'
ImageIndex = 39
DesignSize = (
372
592
151)
object lblOperation: TLabel
Left = 3
@@ -172,7 +172,7 @@ object frmTableTools: TfrmTableTools
object comboOperation: TComboBox
Left = 80
Top = 11
Width = 288
Width = 508
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -234,7 +234,7 @@ object frmTableTools: TfrmTableTools
OnClick = ValidateControls
end
object btnHelpMaintenance: TButton
Left = 294
Left = 514
Top = 38
Width = 75
Height = 25
@@ -257,7 +257,7 @@ object frmTableTools: TfrmTableTools
Caption = 'Find text'
ImageIndex = 30
DesignSize = (
372
592
151)
object lblFindText: TLabel
Left = 3
@@ -277,7 +277,7 @@ object frmTableTools: TfrmTableTools
object memoFindText: TMemo
Left = 208
Top = 11
Width = 161
Width = 381
Height = 78
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssVertical
@@ -287,7 +287,7 @@ object frmTableTools: TfrmTableTools
object comboDataTypes: TComboBox
Left = 208
Top = 95
Width = 161
Width = 381
Height = 21
Style = csDropDownList
Anchors = [akLeft, akRight, akBottom]
@@ -296,7 +296,7 @@ object frmTableTools: TfrmTableTools
object chkCaseSensitive: TCheckBox
Left = 208
Top = 122
Width = 161
Width = 381
Height = 17
Anchors = [akLeft, akRight, akBottom]
Caption = 'Case sensitive'
@@ -307,7 +307,7 @@ object frmTableTools: TfrmTableTools
Caption = 'SQL export'
ImageIndex = 9
DesignSize = (
372
592
151)
object lblExportData: TLabel
Left = 3
@@ -359,7 +359,7 @@ object frmTableTools: TfrmTableTools
Caption = 'KB (0 = Single INSERTs)'
end
object btnExportOutputTargetSelect: TButton
Left = 346
Left = 566
Top = 127
Width = 23
Height = 21
@@ -409,7 +409,7 @@ object frmTableTools: TfrmTableTools
object comboExportData: TComboBox
Left = 100
Top = 47
Width = 269
Width = 489
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -419,7 +419,7 @@ object frmTableTools: TfrmTableTools
object comboExportOutputType: TComboBox
Left = 100
Top = 101
Width = 269
Width = 489
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -429,7 +429,7 @@ object frmTableTools: TfrmTableTools
object comboExportOutputTarget: TComboBox
Left = 100
Top = 127
Width = 243
Width = 463
Height = 21
Anchors = [akLeft, akTop, akRight]
ParentShowHint = False
@@ -457,7 +457,7 @@ object frmTableTools: TfrmTableTools
Wrap = True
end
object btnHelpSQLExport: TButton
Left = 294
Left = 514
Top = 3
Width = 75
Height = 25
@@ -465,13 +465,26 @@ object frmTableTools: TfrmTableTools
Caption = 'Help'
TabOrder = 10
OnClick = btnHelpSQLExportClick
ExplicitLeft = 294
end
object btnExportOptions: TButton
Left = 464
Top = 72
Width = 125
Height = 25
Anchors = [akTop, akRight]
Caption = 'Options'
DropDownMenu = popupExportOptions
Style = bsSplitButton
TabOrder = 11
OnClick = btnExportOptionsClick
end
end
object tabBulkTableEdit: TTabSheet
Caption = 'Bulk table editor'
ImageIndex = 19
DesignSize = (
372
592
151)
object chkBulkTableEditDatabase: TCheckBox
Left = 3
@@ -485,7 +498,7 @@ object frmTableTools: TfrmTableTools
object comboBulkTableEditDatabase: TComboBox
Left = 208
Top = 3
Width = 160
Width = 380
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -513,7 +526,7 @@ object frmTableTools: TfrmTableTools
object comboBulkTableEditCollation: TComboBox
Left = 208
Top = 49
Width = 160
Width = 380
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -532,7 +545,7 @@ object frmTableTools: TfrmTableTools
object comboBulkTableEditEngine: TComboBox
Left = 208
Top = 26
Width = 160
Width = 380
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -551,7 +564,7 @@ object frmTableTools: TfrmTableTools
object comboBulkTableEditCharset: TComboBox
Left = 208
Top = 72
Width = 160
Width = 380
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@@ -563,7 +576,7 @@ object frmTableTools: TfrmTableTools
end
end
object btnExecute: TButton
Left = 340
Left = 560
Top = 350
Width = 95
Height = 25
@@ -573,7 +586,7 @@ object frmTableTools: TfrmTableTools
OnClick = Execute
end
object btnSeeResults: TButton
Left = 216
Left = 436
Top = 350
Width = 118
Height = 25
@@ -600,4 +613,16 @@ object frmTableTools: TfrmTableTools
Caption = 'Check ...'
end
end
object popupExportOptions: TPopupMenu
Left = 176
Top = 352
object menuExportAddComments: TMenuItem
AutoCheck = True
Caption = 'Add comments'
end
object menuExportRemoveAutoIncrement: TMenuItem
AutoCheck = True
Caption = 'Remove AUTO_INCREMENT clauses'
end
end
end

View File

@@ -77,6 +77,10 @@ type
updownInsertSize: TUpDown;
lblInsertSizeUnit: TLabel;
btnHelpSQLExport: TButton;
btnExportOptions: TButton;
popupExportOptions: TPopupMenu;
menuExportAddComments: TMenuItem;
menuExportRemoveAutoIncrement: TMenuItem;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
@@ -122,6 +126,7 @@ type
procedure CheckAllClick(Sender: TObject);
procedure TreeObjectsExpanded(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure btnHelpSQLExportClick(Sender: TObject);
procedure btnExportOptionsClick(Sender: TObject);
private
{ Private declarations }
FResults: TObjectList<TStringList>;
@@ -224,6 +229,8 @@ begin
comboExportData.Items.Text := DATA_NO+CRLF +DATA_REPLACE+CRLF +DATA_INSERT+CRLF +DATA_INSERTNEW+CRLF +DATA_UPDATE;
comboExportData.ItemIndex := AppSettings.ReadInt(asExportSQLDataHow);
updownInsertSize.Position := AppSettings.ReadInt(asExportSQLDataInsertSize);
menuExportAddComments.Checked := AppSettings.ReadBool(asExportSQLAddComments);
menuExportRemoveAutoIncrement.Checked := AppSettings.ReadBool(asExportSQLRemoveAutoIncrement);
// Add hardcoded output options and session names from registry
comboExportOutputType.Items.Text :=
OUTPUT_FILE + CRLF +
@@ -366,6 +373,8 @@ begin
AppSettings.WriteInt(asExportSQLDataHow, comboExportData.ItemIndex);
if comboExportData.ItemIndex > 0 then
AppSettings.WriteInt(asExportSQLDataInsertSize, updownInsertSize.Position);
AppSettings.WriteBool(asExportSQLAddComments, menuExportAddComments.Checked);
AppSettings.WriteBool(asExportSQLRemoveAutoIncrement, menuExportRemoveAutoIncrement.Checked);
if not StartsStr(OUTPUT_SERVER, comboExportOutputType.Text) then
AppSettings.WriteInt(asExportSQLOutput, comboExportOutputType.ItemIndex);
@@ -1180,6 +1189,15 @@ begin
end;
procedure TfrmTableTools.btnExportOptionsClick(Sender: TObject);
var
btn: TButton;
begin
btn := Sender as TButton;
btn.DropDownMenu.Popup(btn.ClientOrigin.X, btn.ClientOrigin.Y+btn.Height);
end;
procedure TfrmTableTools.btnExportOutputTargetSelectClick(Sender: TObject);
var
SaveDialog: TSaveDialog;
@@ -1337,16 +1355,21 @@ begin
'/*!50503 SET NAMES '+DBObj.Connection.CharacterSet+' */;' + CRLF
else
SetCharsetCode := '/*!40101 SET NAMES '+DBObj.Connection.CharacterSet+' */;' + CRLF;
Header := '-- --------------------------------------------------------' + CRLF +
Format('-- %-30s%s', [_('Host')+':', DBObj.Connection.Parameters.HostName]) + CRLF +
Format('-- %-30s%s', [_('Server version')+':', DBObj.Connection.ServerVersionUntouched]) + CRLF +
Format('-- %-30s%s', [_('Server OS')+':', DBObj.Connection.ServerOS]) + CRLF +
Format('-- %-30s%s', [APPNAME + ' ' + _('Version')+':', Mainform.AppVersion]) + CRLF +
'-- --------------------------------------------------------' + CRLF + CRLF +
Header := '';
if menuExportAddComments.Checked then begin
Header := Header +
'-- --------------------------------------------------------' + CRLF +
Format('-- %-30s%s', [_('Host')+':', DBObj.Connection.Parameters.HostName]) + CRLF +
Format('-- %-30s%s', [_('Server version')+':', DBObj.Connection.ServerVersionUntouched]) + CRLF +
Format('-- %-30s%s', [_('Server OS')+':', DBObj.Connection.ServerOS]) + CRLF +
Format('-- %-30s%s', [APPNAME + ' ' + _('Version')+':', Mainform.AppVersion]) + CRLF +
'-- --------------------------------------------------------' + CRLF + CRLF;
end;
Header := Header +
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' + CRLF +
SetCharsetCode +
'/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;' + CRLF +
'/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=''NO_AUTO_VALUE_ON_ZERO'' */;';
'/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=''NO_AUTO_VALUE_ON_ZERO'' */;' + CRLF;
Output(Header, False, DBObj.Database<>ExportLastDatabase, True, False, False);
Output('/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */', True, False, False, True, True);
Output('/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=''NO_AUTO_VALUE_ON_ZERO'' */', True, False, False, True, True);
@@ -1359,7 +1382,8 @@ begin
FinalDbName := comboExportOutputTarget.Text;
NeedsDBStructure := FinalDbName <> ExportLastDatabase;
if chkExportDatabasesDrop.Checked or chkExportDatabasesCreate.Checked then begin
Output(CRLF+CRLF+'-- '+f_('Dumping database structure for %s', [DBObj.Database])+CRLF, False, NeedsDBStructure, False, False, False);
if menuExportAddComments.Checked then
Output(CRLF+'-- '+f_('Dumping database structure for %s', [DBObj.Database])+CRLF, False, NeedsDBStructure, False, False, False);
if chkExportDatabasesDrop.Checked and chkExportDatabasesDrop.Enabled then
Output('DROP DATABASE IF EXISTS '+Quoter.QuoteIdent(FinalDbName), True, NeedsDBStructure, False, False, NeedsDBStructure);
if chkExportDatabasesCreate.Checked and chkExportDatabasesCreate.Enabled then begin
@@ -1382,7 +1406,8 @@ begin
// Table structure
if chkExportTablesDrop.Checked or chkExportTablesCreate.Checked then begin
Output(CRLF+CRLF+'-- '+f_('Dumping structure for %s %s.%s', [_(LowerCase(DBObj.ObjType)), DBObj.Database, DBObj.Name])+CRLF, False, True, True, False, False);
if menuExportAddComments.Checked then
Output(CRLF+'-- '+f_('Dumping structure for %s %s.%s', [_(LowerCase(DBObj.ObjType)), DBObj.Database, DBObj.Name])+CRLF, False, True, True, False, False);
if chkExportTablesDrop.Checked then begin
Struc := 'DROP '+UpperCase(DBObj.ObjType)+' IF EXISTS ';
if ToDb then
@@ -1395,8 +1420,8 @@ begin
case DBObj.NodeType of
lntTable: begin
Struc := DBObj.CreateCode;
// Remove AUTO_INCREMENT clause if no data gets exported
if comboExportData.Text = DATA_NO then begin
// Remove AUTO_INCREMENT clause
if menuExportRemoveAutoIncrement.Checked then begin
rx := TRegExpr.Create;
rx.ModifierI := True;
rx.Expression := '\sAUTO_INCREMENT\s*\=\s*\d+\s';
@@ -1423,8 +1448,10 @@ begin
// Create temporary VIEW replacement
ColumnList := TTableColumnList.Create(True);
DBObj.Connection.ParseViewStructure(DBObj.CreateCode, DBObj, ColumnList, Dummy, Dummy, Dummy, Dummy, Dummy);
Struc := '-- '+_('Creating temporary table to overcome VIEW dependency errors')+CRLF+
'CREATE TABLE ';
Struc := '';
if menuExportAddComments.Checked then
Struc := Struc + '-- '+_('Creating temporary table to overcome VIEW dependency errors')+CRLF;
Struc := Struc + 'CREATE TABLE ';
if ToDb then
Struc := Struc + Quoter.QuoteIdent(FinalDbName) + '.';
Struc := Struc + Quoter.QuoteIdent(DBObj.Name)+' (';
@@ -1438,8 +1465,10 @@ begin
Struc := Struc + CRLF + ') ENGINE=MyISAM';
ColumnList.Free;
end else begin
Struc := '-- '+_('Removing temporary table and create final VIEW structure')+CRLF+
'DROP TABLE IF EXISTS ';
Struc := '';
if menuExportAddComments.Checked then
Struc := Struc + '-- '+_('Removing temporary table and create final VIEW structure')+CRLF;
Struc := Struc + 'DROP TABLE IF EXISTS ';
if ToDb then
Struc := Struc + Quoter.QuoteIdent(FinalDbName)+'.';
Struc := Struc + Quoter.QuoteIdent(DBObj.Name);
@@ -1501,14 +1530,17 @@ begin
if DBObj.NodeType = lntTable then begin
// Table data
if comboExportData.Text = DATA_NO then begin
Output(CRLF+'-- '+_('Data exporting was unselected.')+CRLF, False, True, True, False, False);
if menuExportAddComments.Checked then
Output(CRLF+'-- '+_('Data exporting was unselected.')+CRLF, False, True, True, False, False);
end else if DBObj.Engine = 'MRG_MYISAM' then begin
Output(CRLF+'-- '+f_('Table data not exported because this is %s table which holds its data in separate tables.', [DBObj.Engine])+CRLF, False, True, True, False, False);
if menuExportAddComments.Checked then
Output(CRLF+'-- '+f_('Table data not exported because this is %s table which holds its data in separate tables.', [DBObj.Engine])+CRLF, False, True, True, False, False);
end else begin
tmp := FormatNumber(DBObj.Rows)+' rows';
if LowerCase(DBObj.Engine) = 'innodb' then
tmp := '~'+tmp+' ('+_('approximately')+')';
Output(CRLF+'-- '+f_('Dumping data for table %s.%s: %s', [DBObj.Database, DBObj.Name, tmp])+CRLF, False, True, True, False, False);
if menuExportAddComments.Checked then
Output(CRLF+'-- '+f_('Dumping data for table %s.%s: %s', [DBObj.Database, DBObj.Name, tmp])+CRLF, False, True, True, False, False);
TargetDbAndObject := Quoter.QuoteIdent(DBObj.Name);
if ToDb then
TargetDbAndObject := Quoter.QuoteIdent(FinalDbName) + '.' + TargetDbAndObject;