Make foreign values drop down optionally. See http://www.heidisql.com/forum.php?t=11816

This commit is contained in:
Ansgar Becker
2013-02-04 18:30:35 +00:00
parent 3b56ed5b6f
commit e1c4f14dbc
4 changed files with 49 additions and 35 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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'

View File

@ -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);