Skip to content
Permalink
Browse files

Fix ordinary loop bug with a value in MaxLen, used for the next loop. C…

…loses #918

* prevent meaningless length of "0" for date/time columns
* make detection of length more exact to the relevant data types
  • Loading branch information
ansgarbecker committed Feb 29, 2020
1 parent 3cb40f4 commit f1b72b75cd9d790ddb2b8bd6e5e08f6c9a4ab418
Showing with 25 additions and 11 deletions.
  1. +25 −11 source/dbconnection.pas
@@ -4656,18 +4656,32 @@ function TDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
Col.ParseDatatype(ColQuery.Col(dt));
// PG/MSSQL don't include length in data type
if Col.LengthSet.IsEmpty then begin
if not ColQuery.IsNull('CHARACTER_MAXIMUM_LENGTH') then begin
MaxLen := ColQuery.Col('CHARACTER_MAXIMUM_LENGTH');
if MaxLen = '-1' then
MaxLen := 'max';
end else if not ColQuery.IsNull('NUMERIC_PRECISION') then begin
MaxLen := ColQuery.Col('NUMERIC_PRECISION');
if (not ColQuery.IsNull('NUMERIC_SCALE'))
or (Col.DataType.Index in [dtDouble]) then begin
MaxLen := MaxLen + ',' + StrToIntDef(ColQuery.Col('NUMERIC_SCALE'), 0).ToString;
MaxLen := '';
case Col.DataType.Category of
dtcText, dtcBinary: begin
if not ColQuery.IsNull('CHARACTER_MAXIMUM_LENGTH') then begin
MaxLen := ColQuery.Col('CHARACTER_MAXIMUM_LENGTH');
if MaxLen = '-1' then
MaxLen := 'max';
end;
end;
dtcInteger, dtcReal: begin
if not ColQuery.IsNull('NUMERIC_PRECISION') then begin
MaxLen := ColQuery.Col('NUMERIC_PRECISION');
if (not ColQuery.IsNull('NUMERIC_SCALE'))
or (Col.DataType.Index in [dtDouble]) then begin
MaxLen := MaxLen + ',' + StrToIntDef(ColQuery.Col('NUMERIC_SCALE'), 0).ToString;
end;
end;
end;
dtcTemporal: begin
if not ColQuery.IsNull('DATETIME_PRECISION') then begin
MaxLen := ColQuery.Col('DATETIME_PRECISION');
// Remove meaningless length of "0"
if StrToIntDef(MaxLen, -1) < 1 then
MaxLen := '';
end;
end;
end else if not ColQuery.IsNull('DATETIME_PRECISION') then begin
MaxLen := ColQuery.Col('DATETIME_PRECISION');
end;
if not MaxLen.IsEmpty then
Col.LengthSet := MaxLen;

0 comments on commit f1b72b7

Please sign in to comment.
You can’t perform that action at this time.