SQLDB: Fix generation of incomplete SQL statements by component editor. Modified patch by Don Siders, issue #39975.

This commit is contained in:
wp_xyz 2022-11-20 16:08:51 +01:00
parent 0a3429053c
commit f40f8d5c28
2 changed files with 79 additions and 75 deletions

View File

@ -8,10 +8,10 @@ object GenerateSQLForm: TGenerateSQLForm
ClientHeight = 423 ClientHeight = 423
ClientWidth = 796 ClientWidth = 796
OnCreate = FormCreate OnCreate = FormCreate
LCLVersion = '2.1.0.0' LCLVersion = '2.3.0.0'
object PCSQL: TPageControl object PCSQL: TPageControl
Left = 0 Left = 0
Height = 372 Height = 377
Top = 0 Top = 0
Width = 796 Width = 796
ActivePage = TSFields ActivePage = TSFields
@ -25,17 +25,17 @@ object GenerateSQLForm: TGenerateSQLForm
ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.ControlsPerLine = 3 ChildSizing.ControlsPerLine = 3
ClientHeight = 341 ClientHeight = 349
ClientWidth = 786 ClientWidth = 788
OnResize = TSResize OnResize = TSResize
object POptions: TPanel object POptions: TPanel
Left = 0 Left = 0
Height = 341 Height = 349
Top = 0 Top = 0
Width = 254 Width = 254
Align = alLeft Align = alLeft
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 341 ClientHeight = 349
ClientWidth = 254 ClientWidth = 254
Constraints.MinWidth = 180 Constraints.MinWidth = 180
TabOrder = 0 TabOrder = 0
@ -47,6 +47,7 @@ object GenerateSQLForm: TGenerateSQLForm
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = False AutoSize = False
Caption = 'Ta&ble' Caption = 'Ta&ble'
Color = clDefault
FocusControl = CBTables FocusControl = CBTables
ParentColor = False ParentColor = False
end end
@ -59,6 +60,7 @@ object GenerateSQLForm: TGenerateSQLForm
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = False AutoSize = False
Caption = 'I&ndent' Caption = 'I&ndent'
Color = clDefault
Layout = tlCenter Layout = tlCenter
ParentColor = False ParentColor = False
end end
@ -71,16 +73,17 @@ object GenerateSQLForm: TGenerateSQLForm
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = False AutoSize = False
Caption = 'Line Length' Caption = 'Line Length'
Color = clDefault
Layout = tlCenter Layout = tlCenter
ParentColor = False ParentColor = False
end end
object CBTables: TComboBox object CBTables: TComboBox
Left = 8 Left = 8
Height = 31 Height = 23
Top = 32 Top = 32
Width = 238 Width = 238
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
ItemHeight = 0 ItemHeight = 15
OnChange = CBTablesChange OnChange = CBTablesChange
Sorted = True Sorted = True
Style = csDropDownList Style = csDropDownList
@ -89,7 +92,7 @@ object GenerateSQLForm: TGenerateSQLForm
object BGenerate: TButton object BGenerate: TButton
Left = 8 Left = 8
Height = 25 Height = 25
Top = 305 Top = 313
Width = 238 Width = 238
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
BorderSpacing.InnerBorder = 4 BorderSpacing.InnerBorder = 4
@ -99,7 +102,7 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object seIndent: TSpinEdit object seIndent: TSpinEdit
Left = 196 Left = 196
Height = 29 Height = 23
Top = 197 Top = 197
Width = 50 Width = 50
TabOrder = 2 TabOrder = 2
@ -107,7 +110,7 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object seLineLength: TSpinEdit object seLineLength: TSpinEdit
Left = 196 Left = 196
Height = 29 Height = 23
Top = 229 Top = 229
Width = 50 Width = 50
TabOrder = 3 TabOrder = 3
@ -115,48 +118,48 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object CBQuoteFields: TCheckBox object CBQuoteFields: TCheckBox
Left = 8 Left = 8
Height = 23 Height = 19
Top = 72 Top = 72
Width = 95 Width = 84
Caption = 'Quote Fields' Caption = 'Quote Fields'
TabOrder = 4 TabOrder = 4
end end
object CBSystemTables: TCheckBox object CBSystemTables: TCheckBox
Left = 88 Left = 88
Height = 23 Height = 19
Top = 3 Top = 3
Width = 136 Width = 121
Caption = 'Show system tables' Caption = 'Show system tables'
OnChange = CBSystemTablesChange OnChange = CBSystemTablesChange
TabOrder = 5 TabOrder = 5
end end
object CBOneFieldPerLine: TCheckBox object CBOneFieldPerLine: TCheckBox
Left = 8 Left = 8
Height = 23 Height = 19
Top = 104 Top = 104
Width = 121 Width = 108
Caption = 'One field per line' Caption = 'One field per line'
TabOrder = 6 TabOrder = 6
end end
object cbUpperCaseKeywords: TCheckBox object cbUpperCaseKeywords: TCheckBox
Left = 8 Left = 8
Height = 23 Height = 19
Top = 136 Top = 136
Width = 143 Width = 126
Caption = 'Uppercase keywords' Caption = 'Uppercase keywords'
TabOrder = 7 TabOrder = 7
end end
object cbFullyQualifiedFields: TCheckBox object cbFullyQualifiedFields: TCheckBox
Left = 8 Left = 8
Height = 23 Height = 19
Top = 168 Top = 168
Width = 135 Width = 123
Caption = 'Fully qualified fields' Caption = 'Fully qualified fields'
TabOrder = 8 TabOrder = 8
end end
object edtQuoteChar: TEdit object edtQuoteChar: TEdit
Left = 214 Left = 214
Height = 29 Height = 23
Top = 69 Top = 69
Width = 32 Width = 32
MaxLength = 1 MaxLength = 1
@ -165,11 +168,12 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object lblQuoteChar: TLabel object lblQuoteChar: TLabel
Left = 143 Left = 143
Height = 17 Height = 15
Top = 74 Top = 74
Width = 62 Width = 59
Alignment = taRightJustify Alignment = taRightJustify
Caption = 'Quote char' Caption = 'Quote char'
Color = clDefault
ParentColor = False ParentColor = False
end end
end end
@ -178,48 +182,48 @@ object GenerateSQLForm: TGenerateSQLForm
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = PSelectFields AnchorSideRight.Control = PSelectFields
Left = 254 Left = 254
Height = 341 Height = 349
Top = 0 Top = 0
Width = 244 Width = 246
Align = alClient Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 341 ClientHeight = 349
ClientWidth = 244 ClientWidth = 246
TabOrder = 1 TabOrder = 1
object LLBKeyFields: TLabel object LLBKeyFields: TLabel
Left = 0 Left = 0
Height = 26 Height = 26
Top = 0 Top = 0
Width = 244 Width = 246
Align = alTop Align = alTop
Alignment = taCenter Alignment = taCenter
AutoSize = False AutoSize = False
Caption = '&Key fields' Caption = '&Key fields'
Color = clDefault
Layout = tlCenter Layout = tlCenter
ParentColor = False ParentColor = False
end end
object LBKeyFields: TListBox object LBKeyFields: TListBox
Left = 2 Left = 2
Height = 296 Height = 304
Top = 34 Top = 34
Width = 238 Width = 240
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
ItemHeight = 0 ItemHeight = 0
MultiSelect = True MultiSelect = True
ScrollWidth = 236 ScrollWidth = 236
Sorted = True Sorted = True
TabOrder = 0 TabOrder = 0
TopIndex = -1
end end
end end
object PSelectFields: TPanel object PSelectFields: TPanel
Left = 498 Left = 500
Height = 341 Height = 349
Top = 0 Top = 0
Width = 288 Width = 288
Align = alRight Align = alRight
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 341 ClientHeight = 349
ClientWidth = 288 ClientWidth = 288
TabOrder = 2 TabOrder = 2
object Label2: TLabel object Label2: TLabel
@ -231,12 +235,13 @@ object GenerateSQLForm: TGenerateSQLForm
Alignment = taCenter Alignment = taCenter
AutoSize = False AutoSize = False
Caption = 'Select/Update/Insert fields' Caption = 'Select/Update/Insert fields'
Color = clDefault
Layout = tlCenter Layout = tlCenter
ParentColor = False ParentColor = False
end end
object LBFields: TListBox object LBFields: TListBox
Left = 12 Left = 12
Height = 296 Height = 304
Top = 34 Top = 34
Width = 266 Width = 266
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
@ -245,19 +250,18 @@ object GenerateSQLForm: TGenerateSQLForm
ScrollWidth = 264 ScrollWidth = 264
Sorted = True Sorted = True
TabOrder = 0 TabOrder = 0
TopIndex = -1
end end
end end
end end
object TSSelect: TTabSheet object TSSelect: TTabSheet
Caption = 'Select' Caption = 'Select'
ClientHeight = 341 ClientHeight = 349
ClientWidth = 786 ClientWidth = 788
inline MSelect: TSynEdit inline MSelect: TSynEdit
Left = 0 Left = 0
Height = 328 Height = 349
Top = 0 Top = 0
Width = 802 Width = 788
Align = alClient Align = alClient
Font.Height = 13 Font.Height = 13
Font.Name = 'DejaVu Sans Mono' Font.Name = 'DejaVu Sans Mono'
@ -266,7 +270,7 @@ object GenerateSQLForm: TGenerateSQLForm
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
TabOrder = 0 TabOrder = 0
Gutter.Width = 57 Gutter.Width = 55
Gutter.MouseActions = <> Gutter.MouseActions = <>
RightGutter.Width = 0 RightGutter.Width = 0
RightGutter.MouseActions = <> RightGutter.MouseActions = <>
@ -723,7 +727,7 @@ object GenerateSQLForm: TGenerateSQLForm
MouseActions = <> MouseActions = <>
end end
object SynGutterLineNumber1: TSynGutterLineNumber object SynGutterLineNumber1: TSynGutterLineNumber
Width = 17 Width = 15
MouseActions = <> MouseActions = <>
MarkupInfo.Background = clBtnFace MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone MarkupInfo.Foreground = clNone
@ -756,13 +760,13 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object TSInsert: TTabSheet object TSInsert: TTabSheet
Caption = '&Insert' Caption = '&Insert'
ClientHeight = 341 ClientHeight = 349
ClientWidth = 786 ClientWidth = 788
inline MInsert: TSynEdit inline MInsert: TSynEdit
Left = 0 Left = 0
Height = 328 Height = 349
Top = 0 Top = 0
Width = 802 Width = 788
Align = alClient Align = alClient
Font.Height = 13 Font.Height = 13
Font.Name = 'DejaVu Sans Mono' Font.Name = 'DejaVu Sans Mono'
@ -771,7 +775,7 @@ object GenerateSQLForm: TGenerateSQLForm
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
TabOrder = 0 TabOrder = 0
Gutter.Width = 57 Gutter.Width = 55
Gutter.MouseActions = <> Gutter.MouseActions = <>
RightGutter.Width = 0 RightGutter.Width = 0
RightGutter.MouseActions = <> RightGutter.MouseActions = <>
@ -1228,7 +1232,7 @@ object GenerateSQLForm: TGenerateSQLForm
MouseActions = <> MouseActions = <>
end end
object SynGutterLineNumber1: TSynGutterLineNumber object SynGutterLineNumber1: TSynGutterLineNumber
Width = 17 Width = 15
MouseActions = <> MouseActions = <>
MarkupInfo.Background = clBtnFace MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone MarkupInfo.Foreground = clNone
@ -1261,13 +1265,13 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object TSUpdate: TTabSheet object TSUpdate: TTabSheet
Caption = '&Update' Caption = '&Update'
ClientHeight = 341 ClientHeight = 349
ClientWidth = 786 ClientWidth = 788
inline MUpdate: TSynEdit inline MUpdate: TSynEdit
Left = 0 Left = 0
Height = 328 Height = 349
Top = 0 Top = 0
Width = 802 Width = 788
Align = alClient Align = alClient
Font.Height = 13 Font.Height = 13
Font.Name = 'DejaVu Sans Mono' Font.Name = 'DejaVu Sans Mono'
@ -1276,7 +1280,7 @@ object GenerateSQLForm: TGenerateSQLForm
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
TabOrder = 0 TabOrder = 0
Gutter.Width = 57 Gutter.Width = 55
Gutter.MouseActions = <> Gutter.MouseActions = <>
RightGutter.Width = 0 RightGutter.Width = 0
RightGutter.MouseActions = <> RightGutter.MouseActions = <>
@ -1733,7 +1737,7 @@ object GenerateSQLForm: TGenerateSQLForm
MouseActions = <> MouseActions = <>
end end
object SynGutterLineNumber1: TSynGutterLineNumber object SynGutterLineNumber1: TSynGutterLineNumber
Width = 17 Width = 15
MouseActions = <> MouseActions = <>
MarkupInfo.Background = clBtnFace MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone MarkupInfo.Foreground = clNone
@ -1766,13 +1770,13 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object TSDelete: TTabSheet object TSDelete: TTabSheet
Caption = '&Delete' Caption = '&Delete'
ClientHeight = 341 ClientHeight = 349
ClientWidth = 786 ClientWidth = 788
inline MDelete: TSynEdit inline MDelete: TSynEdit
Left = 0 Left = 0
Height = 328 Height = 349
Top = 0 Top = 0
Width = 802 Width = 788
Align = alClient Align = alClient
Font.Height = 13 Font.Height = 13
Font.Name = 'DejaVu Sans Mono' Font.Name = 'DejaVu Sans Mono'
@ -1781,7 +1785,7 @@ object GenerateSQLForm: TGenerateSQLForm
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
TabOrder = 0 TabOrder = 0
Gutter.Width = 57 Gutter.Width = 55
Gutter.MouseActions = <> Gutter.MouseActions = <>
RightGutter.Width = 0 RightGutter.Width = 0
RightGutter.MouseActions = <> RightGutter.MouseActions = <>
@ -2238,7 +2242,7 @@ object GenerateSQLForm: TGenerateSQLForm
MouseActions = <> MouseActions = <>
end end
object SynGutterLineNumber1: TSynGutterLineNumber object SynGutterLineNumber1: TSynGutterLineNumber
Width = 17 Width = 15
MouseActions = <> MouseActions = <>
MarkupInfo.Background = clBtnFace MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone MarkupInfo.Foreground = clNone
@ -2271,13 +2275,13 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object TSRefresh: TTabSheet object TSRefresh: TTabSheet
Caption = 'Refresh' Caption = 'Refresh'
ClientHeight = 341 ClientHeight = 349
ClientWidth = 786 ClientWidth = 788
inline MRefresh: TSynEdit inline MRefresh: TSynEdit
Left = 0 Left = 0
Height = 328 Height = 349
Top = 0 Top = 0
Width = 802 Width = 788
Align = alClient Align = alClient
Font.Height = 13 Font.Height = 13
Font.Name = 'DejaVu Sans Mono' Font.Name = 'DejaVu Sans Mono'
@ -2286,7 +2290,7 @@ object GenerateSQLForm: TGenerateSQLForm
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
TabOrder = 0 TabOrder = 0
Gutter.Width = 57 Gutter.Width = 55
Gutter.MouseActions = <> Gutter.MouseActions = <>
RightGutter.Width = 0 RightGutter.Width = 0
RightGutter.MouseActions = <> RightGutter.MouseActions = <>
@ -2743,7 +2747,7 @@ object GenerateSQLForm: TGenerateSQLForm
MouseActions = <> MouseActions = <>
end end
object SynGutterLineNumber1: TSynGutterLineNumber object SynGutterLineNumber1: TSynGutterLineNumber
Width = 17 Width = 15
MouseActions = <> MouseActions = <>
MarkupInfo.Background = clBtnFace MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone MarkupInfo.Foreground = clNone
@ -2777,8 +2781,8 @@ object GenerateSQLForm: TGenerateSQLForm
end end
object BPGenSQL: TButtonPanel object BPGenSQL: TButtonPanel
Left = 6 Left = 6
Height = 39 Height = 34
Top = 378 Top = 383
Width = 784 Width = 784
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True
@ -2795,7 +2799,7 @@ object GenerateSQLForm: TGenerateSQLForm
DefaultFilter = 'SQL Files (*.sql)|*.sql' DefaultFilter = 'SQL Files (*.sql)|*.sql'
Enabled = False Enabled = False
SQLDialect = sqlFirebird40 SQLDialect = sqlFirebird40
left = 392 Left = 392
top = 64 Top = 64
end end
end end

View File

@ -164,7 +164,7 @@ begin
L:=L+' '+Format('(%s = :%s%s)', [FieldName,ParamPrefix,KeyFields[I]]); L:=L+' '+Format('(%s = :%s%s)', [FieldName,ParamPrefix,KeyFields[I]]);
if I<KeyFields.Count - 1 then if I<KeyFields.Count - 1 then
L:=L+' '+SQLKeyWord(skAnd); L:=L+' '+SQLKeyWord(skAnd);
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then if CBOneFieldPerLine.Checked or (Length(L)>MaxLen) or (not IsNotLast) then
begin begin
SQL.Add(L); SQL.Add(L);
L:=IndentString; L:=IndentString;
@ -213,7 +213,7 @@ procedure TGenerateSQLForm.GenInsertSQL(const TableName: string; UpdateFields, S
L:=L+FN; L:=L+FN;
if IsNotLast then if IsNotLast then
L:=L+', '; L:=L+', ';
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then if CBOneFieldPerLine.Checked or (Length(L)>MaxLen) or (not IsNotLast) then
begin begin
SQL.Add(L); SQL.Add(L);
L:=IndentString; L:=IndentString;
@ -251,7 +251,7 @@ begin
L:=L+FN; L:=L+FN;
if IsNotLast then if IsNotLast then
L:=L+', '; L:=L+', ';
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then if CBOneFieldPerLine.Checked or (Length(L)>MaxLen) or (not IsNotLast) then
begin begin
SQL.Add(L); SQL.Add(L);
L:=IndentString; L:=IndentString;
@ -299,7 +299,7 @@ begin
L:=L+FN; L:=L+FN;
if IsNotLast then if IsNotLast then
L:=L+', '; L:=L+', ';
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then if CBOneFieldPerLine.Checked or (Length(L)>MaxLen) or (not IsNotLast) then
begin begin
SQL.Add(L); SQL.Add(L);
L:=IndentString; L:=IndentString;