Skip to content

Commit 2fbb779

Browse files
committed
refactor: prefer qAutoInc in SQLProvider over dedicated AutoIncName method
1 parent c770406 commit 2fbb779

File tree

6 files changed

+11
-18
lines changed

6 files changed

+11
-18
lines changed

source/copytable.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ procedure TCopyTableForm.btnOKClick(Sender: TObject);
419419
for Column in SelectedColumns do begin
420420
AutoIncGetsKey := False;
421421
AutoIncRemoved := False;
422-
AutoIncName := Column.AutoIncName;
422+
AutoIncName := FConnection.SqlProvider.GetSql(qAutoInc);
423423
if Column.DefaultType = cdtAutoInc then begin
424424
for Key in SelectedKeys do begin
425425
// Don't check index type, MySQL allows auto-increment columns on nearly all indexes

source/dbconnection.pas

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ TTableColumn = class(TPersistent)
6464
function CastAsText: String;
6565
property Status: TEditingStatus read FStatus write SetStatus;
6666
property Connection: TDBConnection read FConnection;
67-
function AutoIncName: String;
6867
function FullDataType: String;
6968
end;
7069
PTableColumn = ^TTableColumn;
@@ -5738,7 +5737,7 @@ function TDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
57385737
else if ExecRegExpr('\bauto_increment\b', ExtraText.ToLowerInvariant) then begin
57395738
// MySQL auto increment
57405739
Col.DefaultType := cdtAutoInc;
5741-
Col.DefaultText := Col.AutoIncName;
5740+
Col.DefaultText := FSqlProvider.GetSql(qAutoInc);
57425741
end
57435742
else if DefText.ToLowerInvariant = 'null' then begin
57445743
Col.DefaultType := cdtNull;
@@ -5829,7 +5828,7 @@ function TMySQLConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
58295828
Col.OnUpdateType := cdtNothing;
58305829
if ExecRegExpr('^auto_increment$', ExtraText.ToLowerInvariant) then begin
58315830
Col.DefaultType := cdtAutoInc;
5832-
Col.DefaultText := Col.AutoIncName;
5831+
Col.DefaultText := FSqlProvider.GetSql(qAutoInc);
58335832
end else if ColQuery.IsNull('Default') then begin
58345833
Col.DefaultType := cdtNothing;
58355834
end else if IsTextDefault(DefText, Col.DataType) then begin
@@ -10721,7 +10720,7 @@ function TTableColumn.SQLCode(OverrideCollation: String=''; Parts: TColumnParts=
1072110720
cdtAutoInc: begin
1072210721
case FConnection.Parameters.NetTypeGroup of
1072310722
ngPgSQL:;
10724-
else Result := Result + AutoIncName;
10723+
else Result := Result + FConnection.SqlProvider.GetSql(qAutoInc);
1072510724
end;
1072610725
end;
1072710726
cdtExpression: begin
@@ -10843,15 +10842,6 @@ function TTableColumn.CastAsText: String;
1084310842
end;
1084410843

1084510844

10846-
function TTableColumn.AutoIncName: String;
10847-
begin
10848-
case FConnection.Parameters.NetTypeGroup of
10849-
ngPgSQL: Result := 'SERIAL';
10850-
else Result := 'AUTO_INCREMENT';
10851-
end;
10852-
end;
10853-
10854-
1085510845
function TTableColumn.FullDataType: String;
1085610846
begin
1085710847
Result := DataType.Name;

source/dbstructures.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ interface
4949
qGetReverseForeignKeys, qExplain, qSetTimezone,
5050
qShowFunctionStatus, qShowProcedureStatus, qShowTriggers, qShowEvents, qShowCreateTrigger,
5151
qHelpKeyword, qShowWarnings, qGetEnumTypes,
52-
qDropUser, qCreateRole, qDropRole, qReloadPrivileges, qGrantRole, qRevokeRole, qSetDefaultRole);
52+
qDropUser, qCreateRole, qDropRole, qReloadPrivileges, qGrantRole, qRevokeRole, qSetDefaultRole,
53+
qAutoInc);
5354
TSqlProvider = class
5455
strict protected
5556
FNetType: TNetType;
@@ -210,6 +211,7 @@ function TSqlProvider.GetSql(AId: TQueryId): string;
210211
qOrderAsc: Result := 'ASC';
211212
qOrderDesc: Result := 'DESC';
212213
qGetRowCountExact: Result := 'SELECT COUNT(*) FROM :QuotedDbAndTableName';
214+
qAutoInc: Result := 'AUTO_INCREMENT';
213215
else Result := '';
214216
end;
215217
end;

source/dbstructures.postgresql.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ function TPostgreSQLProvider.GetSql(AId: TQueryId): string;
744744
'ORDER BY UPPER(t.typname)',
745745
'' // ServerVersion < 9
746746
);
747+
qAutoInc: Result := 'SERIAL';
747748
else Result := inherited;
748749
end;
749750
end;

source/grideditlinks.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ constructor TColumnDefaultEditorLink.Create(Tree: TVirtualStringTree; AllowEdit:
14141414
FRadioAutoInc.Width := FRadioAutoInc.Parent.Width - 2 * FRadioAutoInc.Left;
14151415
FRadioAutoInc.OnClick := RadioClick;
14161416
FRadioAutoInc.OnKeyDown := DoKeyDown;
1417-
FRadioAutoInc.Caption := Col.AutoIncName;
1417+
FRadioAutoInc.Caption := FTableColumn.Connection.SqlProvider.GetSql(qAutoInc);
14181418

14191419
FBtnOk := TButton.Create(FPanel);
14201420
FBtnOk.Parent := FPanel;
@@ -1578,7 +1578,7 @@ function TColumnDefaultEditorLink.EndEdit: Boolean; stdcall;
15781578
cdtText: Col.DefaultText := FTextEdit.Text;
15791579
cdtNull: Col.DefaultText := 'NULL';
15801580
cdtExpression: Col.DefaultText := FExpressionEdit.Text;
1581-
cdtAutoInc: Col.DefaultText := Col.AutoIncName;
1581+
cdtAutoInc: Col.DefaultText := Col.Connection.SqlProvider.GetSql(qAutoInc);
15821582
end;
15831583

15841584
if FOnUpdateEdit.Text <> '' then

source/table_editor.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ procedure TfrmTableEditor.listColumnsGetText(Sender: TBaseVirtualTree;
15371537
cdtText: CellText := Col.Connection.EscapeString(Col.DefaultText);
15381538
cdtNull: CellText := 'NULL';
15391539
cdtExpression: CellText := Col.DefaultText;
1540-
cdtAutoInc: CellText := Col.AutoIncName;
1540+
cdtAutoInc: CellText := Col.Connection.SqlProvider.GetSql(qAutoInc);
15411541
end;
15421542
case Col.OnUpdateType of
15431543
// cdtNothing: leave clause away

0 commit comments

Comments
 (0)