diff --git a/source/helpers.pas b/source/helpers.pas index d808f48e..53d18087 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -172,7 +172,7 @@ type asFieldEditorSet, asFieldNullBackground, asGroupTreeObjects, asDisplayObjectSizeColumn, asSQLfile, asActionShortcut1, asActionShortcut2, asHighlighterForeground, asHighlighterBackground, asHighlighterStyle, asListColWidths, asListColsVisible, asListColPositions, asListColSort, asSessionFolder, - asRecentFilter, asDateTimeEditorCursorPos, asAppLanguage, asAutoExpand, asUnused); + asRecentFilter, asDateTimeEditorCursorPos, asAppLanguage, asAutoExpand, asForeignDropDown, asUnused); TAppSetting = record Name: String; Session: Boolean; @@ -3209,6 +3209,7 @@ begin InitSetting(asDateTimeEditorCursorPos, 'DateTimeEditor_CursorPos_Type%s', 0); InitSetting(asAppLanguage, 'Language', 0, False, ''); InitSetting(asAutoExpand, 'AutoExpand', 0, False); + InitSetting(asForeignDropDown, 'ForeignDropDown', 0, True); end; diff --git a/source/main.pas b/source/main.pas index e52d59ea..e686d8bf 100644 --- a/source/main.pas +++ b/source/main.pas @@ -7896,45 +7896,47 @@ begin Conn := Results.Connection; // Find foreign key values on InnoDB table cells - if Sender = DataGrid then for ForeignKey in SelectedTableForeignKeys do begin - idx := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Column].Text); - if idx > -1 then try - // Find the first text column if available and use that for displaying in the pulldown instead of using meaningless id numbers - CreateTable := Conn.GetVar('SHOW CREATE TABLE '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.'), 1); - Columns := TTableColumnList.Create; - Keys := nil; - ForeignKeys := nil; - Conn.ParseTableStructure(CreateTable, Columns, Keys, ForeignKeys); - TextCol := ''; - for TblColumn in Columns do begin - if (TblColumn.DataType.Category = dtcText) and (TblColumn.Name <> ForeignKey.ForeignColumns[idx]) then begin - TextCol := TblColumn.Name; - break; + if AppSettings.ReadBool(asForeignDropDown) and (Sender = DataGrid) then begin + for ForeignKey in SelectedTableForeignKeys do begin + idx := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Column].Text); + if idx > -1 then try + // Find the first text column if available and use that for displaying in the pulldown instead of using meaningless id numbers + CreateTable := Conn.GetVar('SHOW CREATE TABLE '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.'), 1); + Columns := TTableColumnList.Create; + Keys := nil; + ForeignKeys := nil; + Conn.ParseTableStructure(CreateTable, Columns, Keys, ForeignKeys); + TextCol := ''; + for TblColumn in Columns do begin + if (TblColumn.DataType.Category = dtcText) and (TblColumn.Name <> ForeignKey.ForeignColumns[idx]) then begin + TextCol := TblColumn.Name; + break; + end; end; - end; - KeyCol := Conn.QuoteIdent(ForeignKey.ForeignColumns[idx]); - SQL := 'SELECT '+KeyCol; - if TextCol <> '' then SQL := SQL + ', LEFT(' + Conn.QuoteIdent(TextCol) + ', 256)'; - SQL := SQL + ' FROM '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.')+' GROUP BY '+KeyCol+' ORDER BY '; - if TextCol <> '' then SQL := SQL + Conn.QuoteIdent(TextCol) else SQL := SQL + KeyCol; - SQL := SQL + ' LIMIT 1000'; + KeyCol := Conn.QuoteIdent(ForeignKey.ForeignColumns[idx]); + SQL := 'SELECT '+KeyCol; + if TextCol <> '' then SQL := SQL + ', LEFT(' + Conn.QuoteIdent(TextCol) + ', 256)'; + SQL := SQL + ' FROM '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.')+' GROUP BY '+KeyCol+' ORDER BY '; + if TextCol <> '' then SQL := SQL + Conn.QuoteIdent(TextCol) else SQL := SQL + KeyCol; + SQL := SQL + ' LIMIT 1000'; - ForeignResults := Conn.GetResults(SQL); - if ForeignResults.RecordCount < 1000 then begin - EnumEditor := TEnumEditorLink.Create(VT); - EditLink := EnumEditor; - while not ForeignResults.Eof do begin - EnumEditor.ValueList.Add(ForeignResults.Col(0)); - if TextCol <> '' then - EnumEditor.DisplayList.Add(ForeignResults.Col(0)+': '+ForeignResults.Col(1)); - ForeignResults.Next; + ForeignResults := Conn.GetResults(SQL); + if ForeignResults.RecordCount < 1000 then begin + EnumEditor := TEnumEditorLink.Create(VT); + EditLink := EnumEditor; + while not ForeignResults.Eof do begin + EnumEditor.ValueList.Add(ForeignResults.Col(0)); + if TextCol <> '' then + EnumEditor.DisplayList.Add(ForeignResults.Col(0)+': '+ForeignResults.Col(1)); + ForeignResults.Next; + end; end; + ForeignResults.Free; + break; + except on E:EDatabaseError do + // Error gets logged, do nothing more here. All other exception types raise please. end; - ForeignResults.Free; - break; - except on E:EDatabaseError do - // Error gets logged, do nothing more here. All other exception types raise please. end; end; diff --git a/source/options.dfm b/source/options.dfm index 863c344e..16fc9106 100644 --- a/source/options.dfm +++ b/source/options.dfm @@ -835,6 +835,14 @@ object optionsform: Toptionsform Caption = 'Remember filters, sorting and column selection across sessions' TabOrder = 17 end + object chkForeignDropDown: TCheckBox + Left = 8 + Top = 302 + Width = 433 + Height = 17 + Caption = 'Drop down values from foreign table in InnoDB rows' + TabOrder = 18 + end end object tabShortcuts: TTabSheet Caption = 'Shortcuts' diff --git a/source/options.pas b/source/options.pas index c37e103c..e3d3e1a8 100644 --- a/source/options.pas +++ b/source/options.pas @@ -119,6 +119,7 @@ type chkRememberFilters: TCheckBox; lblLanguage: TLabel; comboAppLanguage: TComboBox; + chkForeignDropDown: TCheckBox; procedure FormShow(Sender: TObject); procedure Modified(Sender: TObject); procedure Apply(Sender: TObject); @@ -276,6 +277,7 @@ begin AppSettings.WriteBool(asFieldEditorEnum, chkEditorEnum.Checked); AppSettings.WriteBool(asFieldEditorSet, chkEditorSet.Checked); AppSettings.WriteBool(asRememberFilters, chkRememberFilters.Checked); + AppSettings.WriteBool(asForeignDropDown, chkForeignDropDown.Checked); AppSettings.WriteBool(asCompletionProposal, chkCompletionProposal.Checked); AppSettings.WriteBool(asTabsToSpaces, chkTabsToSpaces.Checked); @@ -478,6 +480,7 @@ begin chkEditorEnum.Checked := AppSettings.ReadBool(asFieldEditorEnum); chkEditorSet.Checked := AppSettings.ReadBool(asFieldEditorEnum); chkRememberFilters.Checked := AppSettings.ReadBool(asRememberFilters); + chkForeignDropDown.Checked := AppSettings.ReadBool(asForeignDropDown); // Shortcuts TreeShortcutItems.ReinitChildren(nil, True);