mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Make foreign values drop down optionally. See http://www.heidisql.com/forum.php?t=11816
This commit is contained in:
@ -172,7 +172,7 @@ type
|
|||||||
asFieldEditorSet, asFieldNullBackground, asGroupTreeObjects, asDisplayObjectSizeColumn, asSQLfile,
|
asFieldEditorSet, asFieldNullBackground, asGroupTreeObjects, asDisplayObjectSizeColumn, asSQLfile,
|
||||||
asActionShortcut1, asActionShortcut2, asHighlighterForeground, asHighlighterBackground, asHighlighterStyle,
|
asActionShortcut1, asActionShortcut2, asHighlighterForeground, asHighlighterBackground, asHighlighterStyle,
|
||||||
asListColWidths, asListColsVisible, asListColPositions, asListColSort, asSessionFolder,
|
asListColWidths, asListColsVisible, asListColPositions, asListColSort, asSessionFolder,
|
||||||
asRecentFilter, asDateTimeEditorCursorPos, asAppLanguage, asAutoExpand, asUnused);
|
asRecentFilter, asDateTimeEditorCursorPos, asAppLanguage, asAutoExpand, asForeignDropDown, asUnused);
|
||||||
TAppSetting = record
|
TAppSetting = record
|
||||||
Name: String;
|
Name: String;
|
||||||
Session: Boolean;
|
Session: Boolean;
|
||||||
@ -3209,6 +3209,7 @@ begin
|
|||||||
InitSetting(asDateTimeEditorCursorPos, 'DateTimeEditor_CursorPos_Type%s', 0);
|
InitSetting(asDateTimeEditorCursorPos, 'DateTimeEditor_CursorPos_Type%s', 0);
|
||||||
InitSetting(asAppLanguage, 'Language', 0, False, '');
|
InitSetting(asAppLanguage, 'Language', 0, False, '');
|
||||||
InitSetting(asAutoExpand, 'AutoExpand', 0, False);
|
InitSetting(asAutoExpand, 'AutoExpand', 0, False);
|
||||||
|
InitSetting(asForeignDropDown, 'ForeignDropDown', 0, True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -7896,45 +7896,47 @@ begin
|
|||||||
Conn := Results.Connection;
|
Conn := Results.Connection;
|
||||||
|
|
||||||
// Find foreign key values on InnoDB table cells
|
// Find foreign key values on InnoDB table cells
|
||||||
if Sender = DataGrid then for ForeignKey in SelectedTableForeignKeys do begin
|
if AppSettings.ReadBool(asForeignDropDown) and (Sender = DataGrid) then begin
|
||||||
idx := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Column].Text);
|
for ForeignKey in SelectedTableForeignKeys do begin
|
||||||
if idx > -1 then try
|
idx := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Column].Text);
|
||||||
// Find the first text column if available and use that for displaying in the pulldown instead of using meaningless id numbers
|
if idx > -1 then try
|
||||||
CreateTable := Conn.GetVar('SHOW CREATE TABLE '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.'), 1);
|
// Find the first text column if available and use that for displaying in the pulldown instead of using meaningless id numbers
|
||||||
Columns := TTableColumnList.Create;
|
CreateTable := Conn.GetVar('SHOW CREATE TABLE '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.'), 1);
|
||||||
Keys := nil;
|
Columns := TTableColumnList.Create;
|
||||||
ForeignKeys := nil;
|
Keys := nil;
|
||||||
Conn.ParseTableStructure(CreateTable, Columns, Keys, ForeignKeys);
|
ForeignKeys := nil;
|
||||||
TextCol := '';
|
Conn.ParseTableStructure(CreateTable, Columns, Keys, ForeignKeys);
|
||||||
for TblColumn in Columns do begin
|
TextCol := '';
|
||||||
if (TblColumn.DataType.Category = dtcText) and (TblColumn.Name <> ForeignKey.ForeignColumns[idx]) then begin
|
for TblColumn in Columns do begin
|
||||||
TextCol := TblColumn.Name;
|
if (TblColumn.DataType.Category = dtcText) and (TblColumn.Name <> ForeignKey.ForeignColumns[idx]) then begin
|
||||||
break;
|
TextCol := TblColumn.Name;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
KeyCol := Conn.QuoteIdent(ForeignKey.ForeignColumns[idx]);
|
KeyCol := Conn.QuoteIdent(ForeignKey.ForeignColumns[idx]);
|
||||||
SQL := 'SELECT '+KeyCol;
|
SQL := 'SELECT '+KeyCol;
|
||||||
if TextCol <> '' then SQL := SQL + ', LEFT(' + Conn.QuoteIdent(TextCol) + ', 256)';
|
if TextCol <> '' then SQL := SQL + ', LEFT(' + Conn.QuoteIdent(TextCol) + ', 256)';
|
||||||
SQL := SQL + ' FROM '+Conn.QuoteIdent(ForeignKey.ReferenceTable, True, '.')+' GROUP BY '+KeyCol+' ORDER BY ';
|
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;
|
if TextCol <> '' then SQL := SQL + Conn.QuoteIdent(TextCol) else SQL := SQL + KeyCol;
|
||||||
SQL := SQL + ' LIMIT 1000';
|
SQL := SQL + ' LIMIT 1000';
|
||||||
|
|
||||||
ForeignResults := Conn.GetResults(SQL);
|
ForeignResults := Conn.GetResults(SQL);
|
||||||
if ForeignResults.RecordCount < 1000 then begin
|
if ForeignResults.RecordCount < 1000 then begin
|
||||||
EnumEditor := TEnumEditorLink.Create(VT);
|
EnumEditor := TEnumEditorLink.Create(VT);
|
||||||
EditLink := EnumEditor;
|
EditLink := EnumEditor;
|
||||||
while not ForeignResults.Eof do begin
|
while not ForeignResults.Eof do begin
|
||||||
EnumEditor.ValueList.Add(ForeignResults.Col(0));
|
EnumEditor.ValueList.Add(ForeignResults.Col(0));
|
||||||
if TextCol <> '' then
|
if TextCol <> '' then
|
||||||
EnumEditor.DisplayList.Add(ForeignResults.Col(0)+': '+ForeignResults.Col(1));
|
EnumEditor.DisplayList.Add(ForeignResults.Col(0)+': '+ForeignResults.Col(1));
|
||||||
ForeignResults.Next;
|
ForeignResults.Next;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
ForeignResults.Free;
|
||||||
|
break;
|
||||||
|
except on E:EDatabaseError do
|
||||||
|
// Error gets logged, do nothing more here. All other exception types raise please.
|
||||||
end;
|
end;
|
||||||
ForeignResults.Free;
|
|
||||||
break;
|
|
||||||
except on E:EDatabaseError do
|
|
||||||
// Error gets logged, do nothing more here. All other exception types raise please.
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -835,6 +835,14 @@ object optionsform: Toptionsform
|
|||||||
Caption = 'Remember filters, sorting and column selection across sessions'
|
Caption = 'Remember filters, sorting and column selection across sessions'
|
||||||
TabOrder = 17
|
TabOrder = 17
|
||||||
end
|
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
|
end
|
||||||
object tabShortcuts: TTabSheet
|
object tabShortcuts: TTabSheet
|
||||||
Caption = 'Shortcuts'
|
Caption = 'Shortcuts'
|
||||||
|
@ -119,6 +119,7 @@ type
|
|||||||
chkRememberFilters: TCheckBox;
|
chkRememberFilters: TCheckBox;
|
||||||
lblLanguage: TLabel;
|
lblLanguage: TLabel;
|
||||||
comboAppLanguage: TComboBox;
|
comboAppLanguage: TComboBox;
|
||||||
|
chkForeignDropDown: TCheckBox;
|
||||||
procedure FormShow(Sender: TObject);
|
procedure FormShow(Sender: TObject);
|
||||||
procedure Modified(Sender: TObject);
|
procedure Modified(Sender: TObject);
|
||||||
procedure Apply(Sender: TObject);
|
procedure Apply(Sender: TObject);
|
||||||
@ -276,6 +277,7 @@ begin
|
|||||||
AppSettings.WriteBool(asFieldEditorEnum, chkEditorEnum.Checked);
|
AppSettings.WriteBool(asFieldEditorEnum, chkEditorEnum.Checked);
|
||||||
AppSettings.WriteBool(asFieldEditorSet, chkEditorSet.Checked);
|
AppSettings.WriteBool(asFieldEditorSet, chkEditorSet.Checked);
|
||||||
AppSettings.WriteBool(asRememberFilters, chkRememberFilters.Checked);
|
AppSettings.WriteBool(asRememberFilters, chkRememberFilters.Checked);
|
||||||
|
AppSettings.WriteBool(asForeignDropDown, chkForeignDropDown.Checked);
|
||||||
|
|
||||||
AppSettings.WriteBool(asCompletionProposal, chkCompletionProposal.Checked);
|
AppSettings.WriteBool(asCompletionProposal, chkCompletionProposal.Checked);
|
||||||
AppSettings.WriteBool(asTabsToSpaces, chkTabsToSpaces.Checked);
|
AppSettings.WriteBool(asTabsToSpaces, chkTabsToSpaces.Checked);
|
||||||
@ -478,6 +480,7 @@ begin
|
|||||||
chkEditorEnum.Checked := AppSettings.ReadBool(asFieldEditorEnum);
|
chkEditorEnum.Checked := AppSettings.ReadBool(asFieldEditorEnum);
|
||||||
chkEditorSet.Checked := AppSettings.ReadBool(asFieldEditorEnum);
|
chkEditorSet.Checked := AppSettings.ReadBool(asFieldEditorEnum);
|
||||||
chkRememberFilters.Checked := AppSettings.ReadBool(asRememberFilters);
|
chkRememberFilters.Checked := AppSettings.ReadBool(asRememberFilters);
|
||||||
|
chkForeignDropDown.Checked := AppSettings.ReadBool(asForeignDropDown);
|
||||||
|
|
||||||
// Shortcuts
|
// Shortcuts
|
||||||
TreeShortcutItems.ReinitChildren(nil, True);
|
TreeShortcutItems.ReinitChildren(nil, True);
|
||||||
|
Reference in New Issue
Block a user