Skip to content

Commit 844d9c3

Browse files
committed
feat: reverse foreign keys on "Foreign keys" tab in table editor, including an option to toggle the new listing
Refs #1825
1 parent d674291 commit 844d9c3

File tree

5 files changed

+169
-35
lines changed

5 files changed

+169
-35
lines changed

source/apphelpers.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ TWinControlHelper = class helper for TWinControl
235235
asThemePreviewWidth, asThemePreviewHeight, asThemePreviewTop, asThemePreviewLeft,
236236
asCreateDbCollation, asRealTrailingZeros,
237237
asSequalSuggestWindowWidth, asSequalSuggestWindowHeight, asSequalSuggestPrompt, asSequalSuggestRecentPrompts,
238-
asReformatter, asReformatterNoDialog, asAlwaysGenerateFilter,
238+
asReformatter, asReformatterNoDialog, asAlwaysGenerateFilter, asDisplayReverseForeignKeys,
239239
asGenerateDataNumRows, asGenerateDataNullAmount, asWebOnceAction, asDisplayLogPanel, asDisplayTreeFilters,
240240
asUnused);
241241
TAppSetting = record
@@ -4053,6 +4053,7 @@ constructor TAppSettings.Create;
40534053
InitSetting(asReformatter, 'Reformatter', 0);
40544054
InitSetting(asReformatterNoDialog, 'ReformatterNoDialog', 0);
40554055
InitSetting(asAlwaysGenerateFilter, 'AlwaysGenerateFilter', 0, False);
4056+
InitSetting(asDisplayReverseForeignKeys, 'DisplayReverseForeignKeys', 0, False);
40564057
InitSetting(asGenerateDataNumRows, 'GenerateDataNumRows', 1000);
40574058
InitSetting(asGenerateDataNullAmount, 'GenerateDataNullAmount', 10);
40584059

source/dbstructures.mysql.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,12 @@ function TMySqlProvider.GetSql(AId: TQueryId): string;
33343334
'SHOW TABLE STATUS LIKE :EscapedName',
33353335
''
33363336
);
3337+
qGetReverseForeignKeys: Result := 'SELECT DISTINCT'+
3338+
' k.TABLE_SCHEMA, k.TABLE_NAME'+
3339+
' FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k'+
3340+
' WHERE'+
3341+
' REFERENCED_TABLE_SCHEMA = :EscapedDatabase AND'+
3342+
' REFERENCED_TABLE_NAME = :EscapedName';
33373343
else Result := inherited;
33383344
end;
33393345
end;

source/dbstructures.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ interface
4747
qFuncLength, qFuncCeil, qFuncLeft, qFuncNow, qFuncLastAutoIncNumber,
4848
qLockedTables, qDisableForeignKeyChecks, qEnableForeignKeyChecks,
4949
qOrderAsc, qOrderDesc, qGetRowCountExact, qGetRowCountApprox,
50-
qForeignKeyDrop, qGetTableColumns, qGetCollations, qGetCollationsExtended, qGetCharsets);
50+
qForeignKeyDrop, qGetTableColumns, qGetCollations, qGetCollationsExtended, qGetCharsets,
51+
qGetReverseForeignKeys);
5152
TSqlProvider = class
5253
strict protected
5354
FNetType: TNetType;

source/table_editor.dfm

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object frmTableEditor: TfrmTableEditor
3737
ImageName = 'icons8-data-sheet-100'
3838
DesignSize = (
3939
686
40-
121)
40+
120)
4141
object lblName: TLabel
4242
Left = 4
4343
Top = 6
@@ -235,10 +235,10 @@ object frmTableEditor: TfrmTableEditor
235235
ImageName = 'icons8-lightning-bolt-100'
236236
object treeIndexes: TVirtualStringTree
237237
AlignWithMargins = True
238-
Left = 69
238+
Left = 73
239239
Top = 0
240-
Width = 614
241-
Height = 121
240+
Width = 610
241+
Height = 120
242242
Margins.Top = 0
243243
Margins.Bottom = 0
244244
Align = alClient
@@ -275,7 +275,7 @@ object frmTableEditor: TfrmTableEditor
275275
Options = [coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible, coAllowFocus]
276276
Position = 0
277277
Text = 'Name'
278-
Width = 214
278+
Width = 226
279279
end
280280
item
281281
Options = [coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible, coAllowFocus]
@@ -302,11 +302,11 @@ object frmTableEditor: TfrmTableEditor
302302
object tlbIndexes: TToolBar
303303
Left = 0
304304
Top = 0
305-
Width = 66
306-
Height = 121
305+
Width = 70
306+
Height = 120
307307
Align = alLeft
308308
AutoSize = True
309-
ButtonWidth = 66
309+
ButtonWidth = 70
310310
Caption = 'tlbIndexes'
311311
Images = MainForm.VirtualImageListMain
312312
List = True
@@ -367,14 +367,23 @@ object frmTableEditor: TfrmTableEditor
367367
Caption = 'Foreign keys'
368368
ImageIndex = 136
369369
ImageName = 'icons8-data-grid-relation'
370+
object spltForeignKeyListings: TSplitter
371+
Left = 573
372+
Top = 0
373+
Height = 120
374+
Align = alRight
375+
Visible = False
376+
ExplicitLeft = 494
377+
ExplicitTop = -3
378+
end
370379
object tlbForeignKeys: TToolBar
371380
Left = 0
372381
Top = 0
373-
Width = 66
374-
Height = 121
382+
Width = 70
383+
Height = 120
375384
Align = alLeft
376385
AutoSize = True
377-
ButtonWidth = 66
386+
ButtonWidth = 70
378387
Caption = 'tlbForeignKeys'
379388
Images = MainForm.VirtualImageListMain
380389
List = True
@@ -406,14 +415,24 @@ object frmTableEditor: TfrmTableEditor
406415
Enabled = False
407416
ImageIndex = 26
408417
ImageName = 'icons8-close-button'
418+
Wrap = True
409419
OnClick = btnClearForeignKeysClick
410420
end
421+
object btnShowReverseForeignKeys: TToolButton
422+
Left = 0
423+
Top = 66
424+
Hint = 'Show reverse foreign keys'
425+
Caption = 'Reverse'
426+
ImageIndex = 40
427+
Style = tbsCheck
428+
OnClick = btnShowReverseForeignKeysClick
429+
end
411430
end
412431
object listForeignKeys: TVirtualStringTree
413-
Left = 66
432+
Left = 70
414433
Top = 0
415-
Width = 620
416-
Height = 121
434+
Width = 503
435+
Height = 120
417436
Margins.Top = 0
418437
Margins.Bottom = 0
419438
Align = alClient
@@ -474,8 +493,31 @@ object frmTableEditor: TfrmTableEditor
474493
Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible, coAllowFocus]
475494
Position = 5
476495
Text = 'On DELETE'
477-
Width = 80
496+
Width = 10
497+
end>
498+
end
499+
object ListViewReverseForeignKeys: TListView
500+
Left = 576
501+
Top = 0
502+
Width = 110
503+
Height = 120
504+
Align = alRight
505+
Columns = <
506+
item
507+
AutoSize = True
508+
Caption = 'Database'
509+
end
510+
item
511+
AutoSize = True
512+
Caption = 'Table'
478513
end>
514+
ColumnClick = False
515+
ReadOnly = True
516+
RowSelect = True
517+
TabOrder = 2
518+
ViewStyle = vsReport
519+
Visible = False
520+
OnDblClick = ListViewReverseForeignKeysDblClick
479521
end
480522
end
481523
object tabCheckConstraints: TTabSheet
@@ -484,11 +526,11 @@ object frmTableEditor: TfrmTableEditor
484526
object tlbCheckConstraints: TToolBar
485527
Left = 0
486528
Top = 0
487-
Width = 66
488-
Height = 121
529+
Width = 70
530+
Height = 120
489531
Align = alLeft
490532
AutoSize = True
491-
ButtonWidth = 66
533+
ButtonWidth = 70
492534
Caption = 'tlbCheckConstraints'
493535
Images = MainForm.VirtualImageListMain
494536
List = True
@@ -521,10 +563,10 @@ object frmTableEditor: TfrmTableEditor
521563
end
522564
end
523565
object listCheckConstraints: TVirtualStringTree
524-
Left = 66
566+
Left = 70
525567
Top = 0
526-
Width = 620
527-
Height = 121
568+
Width = 616
569+
Height = 120
528570
Align = alClient
529571
DefaultNodeHeight = 19
530572
EditDelay = 0
@@ -558,7 +600,7 @@ object frmTableEditor: TfrmTableEditor
558600
Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible, coAllowFocus, coEditable, coStyleColor]
559601
Position = 1
560602
Text = 'Check clause'
561-
Width = 416
603+
Width = 412
562604
end>
563605
end
564606
end
@@ -569,8 +611,8 @@ object frmTableEditor: TfrmTableEditor
569611
object SynMemoPartitions: TSynMemo
570612
Left = 0
571613
Top = 0
572-
Width = 593
573-
Height = 121
614+
Width = 686
615+
Height = 120
574616
SingleLineMode = False
575617
Align = alClient
576618
Font.Charset = DEFAULT_CHARSET
@@ -611,8 +653,8 @@ object frmTableEditor: TfrmTableEditor
611653
object SynMemoCREATEcode: TSynMemo
612654
Left = 0
613655
Top = 0
614-
Width = 593
615-
Height = 121
656+
Width = 686
657+
Height = 120
616658
SingleLineMode = False
617659
Align = alClient
618660
Font.Charset = DEFAULT_CHARSET
@@ -653,8 +695,8 @@ object frmTableEditor: TfrmTableEditor
653695
object SynMemoALTERcode: TSynMemo
654696
Left = 0
655697
Top = 0
656-
Width = 593
657-
Height = 121
698+
Width = 686
699+
Height = 120
658700
SingleLineMode = False
659701
Align = alClient
660702
Font.Charset = DEFAULT_CHARSET
@@ -714,7 +756,7 @@ object frmTableEditor: TfrmTableEditor
714756
Margins.Bottom = 0
715757
Align = alClient
716758
AutoSize = True
717-
ButtonWidth = 66
759+
ButtonWidth = 70
718760
Caption = 'Columns:'
719761
Images = MainForm.VirtualImageListMain
720762
List = True
@@ -730,7 +772,7 @@ object frmTableEditor: TfrmTableEditor
730772
OnClick = btnAddColumnClick
731773
end
732774
object btnRemoveColumn: TToolButton
733-
Left = 66
775+
Left = 70
734776
Top = 0
735777
Hint = 'Remove column'
736778
Caption = 'Remove'
@@ -739,7 +781,7 @@ object frmTableEditor: TfrmTableEditor
739781
OnClick = btnRemoveColumnClick
740782
end
741783
object btnMoveUpColumn: TToolButton
742-
Left = 132
784+
Left = 140
743785
Top = 0
744786
Hint = 'Move up'
745787
Caption = 'Up'
@@ -748,7 +790,7 @@ object frmTableEditor: TfrmTableEditor
748790
OnClick = btnMoveUpColumnClick
749791
end
750792
object btnMoveDownColumn: TToolButton
751-
Left = 198
793+
Left = 210
752794
Top = 0
753795
Hint = 'Move down'
754796
Caption = 'Down'

0 commit comments

Comments
 (0)