Skip to content

Commit

Permalink
Support wildcard options in "Find text on server" dialog in a new dro…
Browse files Browse the repository at this point in the history
…p down box, to provide a possibility to find exact matches. See http://www.heidisql.com/forum.php?t=21388
  • Loading branch information
ansgarbecker committed May 25, 2016
1 parent 9754d5d commit 76e038c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
17 changes: 16 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: 2016-04-10 12:25+0200\n"
"PO-Revision-Date: 2016-05-25 20:50+0200\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 @@ -3383,6 +3383,21 @@ msgstr "Text to find:"
msgid "Search in column types:"
msgstr "Search in column types:"

msgid "Match type:"
msgstr "Match type:"

msgid "Left and right wildcard"
msgstr "Left and right wildcard"

msgid "Exact match"
msgstr "Exact match"

msgid "Left wildcard"
msgstr "Left wildcard"

msgid "Right wildcard"
msgstr "Right wildcard"

#. frmTableTools..pnlTop..pnlRight..tabsTools..tabSQLexport..Caption
#: tabletools.dfm:308
msgid "SQL export"
Expand Down
3 changes: 2 additions & 1 deletion source/helpers.pas
Expand Up @@ -153,7 +153,7 @@ TQueryThread = class(TThread)
asCSVImportFilename, asCSVImportFieldsEnclosedOptionally, asCSVImportIgnoreLines, asCSVImportLowPriority, asCSVImportLocalNumbers,
asCSVImportDuplicateHandling, asCSVImportParseMethod, asUpdatecheck, asUpdatecheckBuilds,
asUpdatecheckInterval, asUpdatecheckLastrun, asTableToolsWindowWidth, asTableToolsWindowHeight, asTableToolsTreeWidth,
asTableToolsFindText, asTableToolsDatatype, asTableToolsFindCaseSensitive, asFileImportWindowWidth, asFileImportWindowHeight,
asTableToolsFindText, asTableToolsDatatype, asTableToolsFindCaseSensitive, asTableToolsFindMatchType, asFileImportWindowWidth, asFileImportWindowHeight,
asEditVarWindowWidth, asEditVarWindowHeight, asUsermanagerWindowWidth, asUsermanagerWindowHeight, asUsermanagerListWidth,
asSelectDBOWindowWidth, asSelectDBOWindowHeight, asSessionManagerListWidth, asSessionManagerWindowWidth, asSessionManagerWindowHeight,
asCopyTableWindowHeight, asCopyTableWindowWidth, asCopyTableColumns, asCopyTableKeys, asCopyTableForeignKeys,
Expand Down Expand Up @@ -3290,6 +3290,7 @@ constructor TAppSettings.Create;
InitSetting(asTableToolsFindText, 'TableTools_FindText', 0, False, '');
InitSetting(asTableToolsDatatype, 'TableTools_Datatype', 0);
InitSetting(asTableToolsFindCaseSensitive, 'TableTools_FindCaseSensitive', 0, False);
InitSetting(asTableToolsFindMatchType, 'TableToolsFindMatchType', 0);
InitSetting(asFileImportWindowWidth, 'FileImport_WindowWidth', 530);
InitSetting(asFileImportWindowHeight, 'FileImport_WindowHeight', 530);
InitSetting(asEditVarWindowWidth, 'EditVar_WindowWidth', 300);
Expand Down
31 changes: 27 additions & 4 deletions source/tabletools.dfm
Expand Up @@ -268,25 +268,32 @@ object frmTableTools: TfrmTableTools
end
object lblDataTypes: TLabel
Left = 3
Top = 98
Top = 83
Width = 114
Height = 13
Anchors = [akLeft, akBottom]
Caption = 'Search in column types:'
end
object lblMatchType: TLabel
Left = 3
Top = 129
Width = 58
Height = 13
Caption = 'Match type:'
end
object memoFindText: TMemo
Left = 208
Top = 11
Width = 381
Height = 78
Height = 59
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssVertical
TabOrder = 0
OnChange = ValidateControls
end
object comboDataTypes: TComboBox
Left = 208
Top = 95
Top = 76
Width = 381
Height = 21
Style = csDropDownList
Expand All @@ -295,13 +302,29 @@ object frmTableTools: TfrmTableTools
end
object chkCaseSensitive: TCheckBox
Left = 208
Top = 122
Top = 103
Width = 381
Height = 17
Anchors = [akLeft, akRight, akBottom]
Caption = 'Case sensitive'
TabOrder = 2
end
object comboMatchType: TComboBox
Left = 208
Top = 126
Width = 381
Height = 21
Style = csDropDownList
Anchors = [akLeft, akRight, akBottom]
ItemIndex = 0
TabOrder = 3
Text = 'Left and right wildcard'
Items.Strings = (
'Left and right wildcard'
'Exact match'
'Left wildcard'
'Right wildcard')
end
end
object tabSQLexport: TTabSheet
Caption = 'SQL export'
Expand Down
19 changes: 15 additions & 4 deletions source/tabletools.pas
Expand Up @@ -81,6 +81,8 @@ TfrmTableTools = class(TFormWithSizeGrip)
popupExportOptions: TPopupMenu;
menuExportAddComments: TMenuItem;
menuExportRemoveAutoIncrement: TMenuItem;
comboMatchType: TComboBox;
lblMatchType: TLabel;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
Expand Down Expand Up @@ -223,6 +225,7 @@ procedure TfrmTableTools.FormCreate(Sender: TObject);
comboDatatypes.Items.Add(DatatypeCategories[dtc].Name);
comboDatatypes.ItemIndex := AppSettings.ReadInt(asTableToolsDatatype);
chkCaseSensitive.Checked := AppSettings.ReadBool(asTableToolsFindCaseSensitive);
comboMatchType.ItemIndex := AppSettings.ReadInt(asTableToolsFindMatchType);

// SQL export tab
chkExportDatabasesCreate.Checked := AppSettings.ReadBool(asExportSQLCreateDatabases);
Expand Down Expand Up @@ -366,6 +369,7 @@ procedure TfrmTableTools.SaveSettings(Sender: TObject);
AppSettings.WriteString(asTableToolsFindText, memoFindText.Text);
AppSettings.WriteInt(asTableToolsDatatype, comboDatatypes.ItemIndex);
AppSettings.WriteBool(asTableToolsFindCaseSensitive, chkCaseSensitive.Checked);
AppSettings.WriteInt(asTableToolsFindMatchType, comboMatchType.ItemIndex);
end;

tmSQLExport: begin
Expand Down Expand Up @@ -800,7 +804,13 @@ procedure TfrmTableTools.DoFind(DBObj: TDBObject);
FFindSeeResultSQL.Add('');

FindText := memoFindText.Text;
FindTextJokers := '%'+FindText+'%';
case comboMatchType.ItemIndex of
0: FindTextJokers := '%'+FindText+'%';
1: FindTextJokers := FindText;
2: FindTextJokers := '%'+FindText;
3: FindTextJokers := FindText+'%';
end;

RoutineDefinitionColumn := DBObj.Connection.QuoteIdent('routine_definition');
if not chkCaseSensitive.Checked then begin
FindText := LowerCase(FindText);
Expand All @@ -825,10 +835,10 @@ procedure TfrmTableTools.DoFind(DBObj: TDBObject);
SQL := '';
for Col in Columns do begin
Column := DBObj.Connection.QuoteIdent(Col.Name);
if not chkCaseSensitive.Checked then
Column := 'LOWER('+Column+')';
if (comboDatatypes.ItemIndex = 0) or (Integer(Col.DataType.Category) = comboDatatypes.ItemIndex-1) then begin
if chkCaseSensitive.Checked then begin
if (Col.DataType.Category in [dtcInteger, dtcReal]) and (comboMatchType.ItemIndex=1) then begin
SQL := SQL + Column + '=' + UnformatNumber(FindText) + ' OR ';
end else if chkCaseSensitive.Checked then begin
case DBObj.Connection.Parameters.NetTypeGroup of
ngMySQL:
SQL := SQL + Column + ' LIKE BINARY ' + esc(FindTextJokers) + ' OR ';
Expand All @@ -838,6 +848,7 @@ procedure TfrmTableTools.DoFind(DBObj: TDBObject);
SQL := SQL + 'CAST(' + Column + ' AS TEXT) LIKE ' + esc(FindTextJokers) + ' OR ';
end;
end else begin
Column := 'LOWER('+Column+')';
case DBObj.Connection.Parameters.NetTypeGroup of
ngMySQL:
SQL := SQL + 'CONVERT('+Column+' USING '+DBObj.Connection.CharacterSet+') LIKE ' + esc(FindTextJokers) + ' OR ';
Expand Down

0 comments on commit 76e038c

Please sign in to comment.