Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add custom setting for number of days to keep queries in the query hi…
  • Loading branch information
ansgarbecker committed Mar 13, 2017
1 parent f6a405b commit 444a5bd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
5 changes: 4 additions & 1 deletion out/locale/en/LC_MESSAGES/default.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2017-03-07 21:07+0100\n"
"PO-Revision-Date: 2017-03-13 21:17+0100\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/"
"language/en/)\n"
Expand Down Expand Up @@ -2720,6 +2720,9 @@ msgstr "Debug messages"
msgid "Enable query history"
msgstr "Enable query history"

msgid "days to keep queries before removing them"
msgstr "days to keep queries before removing them"

#. optionsform..pagecontrolMain..tabSQL..lblFont..Caption
#: options.dfm:357
msgid "Editor font:"
Expand Down
4 changes: 3 additions & 1 deletion source/helpers.pas
Expand Up @@ -174,7 +174,8 @@ TQueryThread = class(TThread)
asFieldEditorSet, asFieldNullBackground, asRowBackgroundEven, asRowBackgroundOdd, asGroupTreeObjects, asDisplayObjectSizeColumn, asSQLfile,
asActionShortcut1, asActionShortcut2, asHighlighterForeground, asHighlighterBackground, asHighlighterStyle,
asListColWidths, asListColsVisible, asListColPositions, asListColSort, asSessionFolder,
asRecentFilter, asTimestampColumns, asDateTimeEditorCursorPos, asAppLanguage, asAutoExpand, asDoubleClickInsertsNodeText, asForeignDropDown, asQueryHistoryEnabled,
asRecentFilter, asTimestampColumns, asDateTimeEditorCursorPos, asAppLanguage, asAutoExpand, asDoubleClickInsertsNodeText, asForeignDropDown,
asQueryHistoryEnabled, asQueryHistoryKeepDays,
asColumnSelectorWidth, asColumnSelectorHeight, asDonatedEmail, asFavoriteObjects, asFavoriteObjectsOnly, asFullTableStatus, asLineBreakStyle,
asFileDialogEncoding,
asUnused);
Expand Down Expand Up @@ -3427,6 +3428,7 @@ constructor TAppSettings.Create;
InitSetting(asDoubleClickInsertsNodeText, 'DoubleClickInsertsNodeText', 0, True);
InitSetting(asForeignDropDown, 'ForeignDropDown', 0, True);
InitSetting(asQueryHistoryEnabled, 'QueryHistory', 0, True);
InitSetting(asQueryHistoryKeepDays, 'QueryHistoryKeeypDays', 30);
InitSetting(asColumnSelectorWidth, 'ColumnSelectorWidth', 200, False, '');
InitSetting(asColumnSelectorHeight, 'ColumnSelectorHeight', 270, False, '');
InitSetting(asDonatedEmail, 'DonatedEmail', 0, False, '');
Expand Down
5 changes: 3 additions & 2 deletions source/main.pas
Expand Up @@ -2754,7 +2754,7 @@ procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
History: TQueryHistory;
HistoryItem: TQueryHistoryItem;
Warnings: TDBQuery;
HistoryNum, MaxWarnings, RegItemsSize: Integer;
HistoryNum, MaxWarnings, RegItemsSize, KeepDays: Integer;
DoDelete, ValueFound: Boolean;
MinDate: TDateTime;

Expand Down Expand Up @@ -2877,6 +2877,7 @@ procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
and (Thread.Batch.Size <= SIZE_MB)
then begin
ShowStatusMsg(_('Updating query history ...'));
KeepDays := AppSettings.ReadInt(asQueryHistoryKeepDays);

// Load all items so we can clean up
History := TQueryHistory.Create(Thread.Connection.Parameters.SessionPath);
Expand All @@ -2901,7 +2902,7 @@ procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
// Delete old items
// Delete items which exceed a max datasize barrier
AppSettings.SessionPath := Thread.Connection.Parameters.SessionPath + '\' + REGKEY_QUERYHISTORY;
MinDate := IncDay(Now, -30);
MinDate := IncDay(Now, -KeepDays);
RegItemsSize := Thread.Batch.Size;
for HistoryItem in History do begin
Inc(RegItemsSize, Length(HistoryItem.SQL));
Expand Down
34 changes: 32 additions & 2 deletions source/options.dfm
Expand Up @@ -304,6 +304,13 @@ object optionsform: Toptionsform
Height = 13
Caption = 'Log events:'
end
object lblQueryHistoryKeepDays: TLabel
Left = 278
Top = 201
Width = 209
Height = 13
Caption = 'days to keep queries before removing them'
end
object editLogLines: TEdit
Left = 202
Top = 8
Expand Down Expand Up @@ -421,11 +428,11 @@ object optionsform: Toptionsform
object chkQueryHistory: TCheckBox
Left = 8
Top = 200
Width = 429
Width = 176
Height = 17
Caption = 'Enable query history'
TabOrder = 11
OnClick = Modified
OnClick = chkQueryHistoryClick
end
object chkHorizontalScrollbar: TCheckBox
Left = 8
Expand All @@ -436,6 +443,29 @@ object optionsform: Toptionsform
TabOrder = 12
OnClick = Modified
end
object editQueryHistoryKeepDays: TEdit
Left = 202
Top = 198
Width = 53
Height = 21
Enabled = False
TabOrder = 13
Text = '1'
OnChange = Modified
end
object updownQueryHistoryKeepDays: TUpDown
Left = 255
Top = 198
Width = 16
Height = 21
Associate = editQueryHistoryKeepDays
Enabled = False
Min = 1
Max = 365
Position = 1
TabOrder = 14
OnChanging = anyUpDownLimitChanging
end
end
object tabSQL: TTabSheet
Caption = 'SQL'
Expand Down
15 changes: 15 additions & 0 deletions source/options.pas
Expand Up @@ -136,6 +136,9 @@ Toptionsform = class(TForm)
updownGUIFontSize: TUpDown;
lblGUIFontSize: TLabel;
chkHorizontalScrollbar: TCheckBox;
editQueryHistoryKeepDays: TEdit;
updownQueryHistoryKeepDays: TUpDown;
lblQueryHistoryKeepDays: TLabel;
procedure FormShow(Sender: TObject);
procedure Modified(Sender: TObject);
procedure Apply(Sender: TObject);
Expand Down Expand Up @@ -174,6 +177,7 @@ Toptionsform = class(TForm)
procedure editGridRowCountExit(Sender: TObject);
procedure editCustomSnippetsDirectoryRightButtonClick(Sender: TObject);
procedure comboGUIFontChange(Sender: TObject);
procedure chkQueryHistoryClick(Sender: TObject);
private
{ Private declarations }
FWasModified: Boolean;
Expand Down Expand Up @@ -248,6 +252,7 @@ procedure Toptionsform.Apply(Sender: TObject);
AppSettings.WriteBool(asLogInfos, chkLogEventInfo.Checked);
AppSettings.WriteBool(asLogDebug, chkLogEventDebug.Checked);
AppSettings.WriteBool(asQueryHistoryEnabled, chkQueryHistory.Checked);
AppSettings.WriteInt(asQueryHistoryKeepDays, updownQueryHistoryKeepDays.Position);
AppSettings.WriteBool(asLogHorizontalScrollbar, chkHorizontalScrollbar.Checked);
for i:=0 to SynSQLSynSQLSample.AttrCount - 1 do begin
Attri := SynSQLSynSQLSample.Attribute[i];
Expand Down Expand Up @@ -488,6 +493,7 @@ procedure Toptionsform.FormShow(Sender: TObject);
chkLogEventInfo.Checked := AppSettings.ReadBool(asLogInfos);
chkLogEventDebug.Checked := AppSettings.ReadBool(asLogDebug);
chkQueryHistory.Checked := AppSettings.ReadBool(asQueryHistoryEnabled);
updownQueryHistoryKeepDays.Position := AppSettings.ReadInt(asQueryHistoryKeepDays);
chkHorizontalScrollbar.Checked := AppSettings.ReadBool(asLogHorizontalScrollbar);

// Default column width in grids:
Expand Down Expand Up @@ -672,6 +678,15 @@ procedure Toptionsform.chkLogToFileClick(Sender: TObject);
end;


procedure Toptionsform.chkQueryHistoryClick(Sender: TObject);
begin
editQueryHistoryKeepDays.Enabled := chkQueryHistory.Checked;
updownQueryHistoryKeepDays.Enabled := chkQueryHistory.Checked;
lblQueryHistoryKeepDays.Enabled := chkQueryHistory.Checked;
Modified(Sender);
end;


procedure Toptionsform.comboGridTextColorsSelect(Sender: TObject);
begin
// Data type category selected
Expand Down

0 comments on commit 444a5bd

Please sign in to comment.