Skip to content
Permalink
Browse files

Issue #62: distinct between TIMEZONE (without time zone) and TIMEZONE…

…TZ (with time zone). And modify GetDatatypeByName() so it deletes the longest detected datatype string PostgreSQLDatatypes.Names . This solves empty/undetected column comments in ParseTableStructure(). See https://www.heidisql.com/forum.php?t=23211#p34709
  • Loading branch information...
ansgarbecker committed Oct 5, 2019
1 parent 56c6a1e commit 64c43aebbf005eb2f3dc51d118f17ea128321a1d
Showing with 36 additions and 4 deletions.
  1. +9 −0 source/apphelpers.pas
  2. +10 −1 source/dbconnection.pas
  3. +17 −3 source/dbstructures.pas
@@ -330,6 +330,7 @@ TAppSettings = class(TObject)
function StringListCompareAnythingAsc(List: TStringList; Index1, Index2: Integer): Integer;
function StringListCompareAnythingDesc(List: TStringList; Index1, Index2: Integer): Integer;
function StringListCompareByValue(List: TStringList; Index1, Index2: Integer): Integer;
function StringListCompareByLength(List: TStringList; Index1, Index2: Integer): Integer;
function GetImageLinkTimeStamp(const FileName: string): TDateTime;
function IsEmpty(Str: String): Boolean;
function IsNotEmpty(Str: String): Boolean;
@@ -2199,6 +2200,13 @@ function StringListCompareByValue(List: TStringList; Index1, Index2: Integer): I
end;


function StringListCompareByLength(List: TStringList; Index1, Index2: Integer): Integer;
begin
// Sort TStringList items by their length
Result := CompareValue(List[Index2].Length, List[Index1].Length);
end;


{**
Return compile date/time from passed .exe name
Code taken and modified from Michael Puff
@@ -4225,6 +4233,7 @@ initialization

LibHandleUser32 := LoadLibrary('User32.dll');


end.


@@ -1571,19 +1571,28 @@ function TDBConnection.GetDatatypeByName(var DataType: String; DeleteFromSource:
Match: Boolean;
rx: TRegExpr;
Types, tmp: String;
TypesSorted: TStringList;
begin
rx := TRegExpr.Create;
rx.ModifierI := True;
MatchLen := 0;
for i:=0 to High(FDatatypes) do begin
Types := FDatatypes[i].Name;
if FDatatypes[i].Names <> '' then
if FDatatypes[i].Names <> '' then begin
Types := Types + '|' + FDatatypes[i].Names;
// Move more exact (longer) types to the beginning
TypesSorted := Explode('|', Types);
TypesSorted.CustomSort(StringListCompareByLength);
Types := ImplodeStr('|', TypesSorted);
TypesSorted.Free;
end;

rx.Expression := '^('+Types+')\b(\[\])?';
Match := rx.Exec(DataType);
// Prefer a later match which is longer than the one found before.
// See http://www.heidisql.com/forum.php?t=17061
if Match and (rx.MatchLen[1] > MatchLen) then begin
Log(lcDebug, 'GetDatatypeByName: "'+DataType+'" : '+rx.Match[1]);
if (FParameters.NetTypeGroup = ngPgSQL) and (rx.MatchLen[2] > 0) then begin
// TODO: detect array style datatypes, e.g. TEXT[]
end else begin
@@ -1505,7 +1505,7 @@ TPostgreSQLLib = class(TDbLib)
)
);

PostgreSQLDatatypes: Array[0..34] of TDBDatatype =
PostgreSQLDatatypes: Array[0..35] of TDBDatatype =
(
(
Index: dtUnknown;
@@ -1769,9 +1769,23 @@ TPostgreSQLLib = class(TDbLib)
),
(
Index: dtDatetime;
NativeTypes: '1082|1114|1184|702';
NativeTypes: '1082|1114|702';
Name: 'TIMESTAMP';
Names: 'timestamp|datetime|timestamptz|abstime';
Names: 'timestamp|datetime|abstime|timestamp without time zone';
Description: 'Date and time.';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: False;
LoadPart: False;
Format: 'yyyy-mm-dd hh:nn:ss';
Category: dtcTemporal;
),
(
Index: dtDatetime2;
NativeTypes: '1184';
Name: 'TIMESTAMPTZ';
Names: 'timestamptz|timestamp with timezone';
Description: 'Date and time.';
HasLength: False;
RequiresLength: False;

0 comments on commit 64c43ae

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