Skip to content
Permalink
Browse files

Detect ON UPDATE clause's content with a two-step approach, so it doe…

…s not eat a potentially existing COMMENT clause after it. Closes #637. Broken in 9fc7150 for #74.
  • Loading branch information...
ansgarbecker committed May 5, 2019
1 parent fb02867 commit 54c6d9123fc4eae30419ffb5a839a6e67f917d96
Showing with 11 additions and 6 deletions.
  1. +11 −6 source/dbconnection.pas
@@ -5225,14 +5225,19 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
Col.DefaultType := cdtExpression;
end;
Delete(ColSpec, 1, rxCol.MatchLen[1]);
ColSpec := Trim(ColSpec);

// Do the same for a potentially existing ON UPDATE clause
rxCol.Expression := '^\s*ON UPDATE\s+(.*)($|\s+(COLUMN_FORMAT|COMMENT|INVISIBLE)\b)';
if rxCol.Exec(ColSpec) then begin
Col.OnUpdateText := Trim(rxCol.Match[1]);
Col.OnUpdateText := Col.OnUpdateText.TrimRight([',']);
Col.OnUpdateType := cdtExpression;
Delete(ColSpec, 1, rxCol.MatchLen[1]);
if ColSpec.ToUpper.StartsWith('ON UPDATE ', True) then begin
Delete(ColSpec, 1, 10);
ColSpec := Trim(ColSpec);
rxCol.Expression := '($|\s+(COLUMN_FORMAT|COMMENT|INVISIBLE)\b)';
if rxCol.Exec(ColSpec) then begin
Col.OnUpdateText := ColSpec.Substring(0, rxCol.MatchPos[1]).Trim;
Col.OnUpdateText := Col.OnUpdateText.TrimRight([',']);
Col.OnUpdateType := cdtExpression;
Delete(ColSpec, 1, rxCol.MatchPos[1]);
end;
end;

end;

0 comments on commit 54c6d91

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