From 6c7f80ab62d30c53fcbcbc285ac9254339cec81c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 28 Apr 2023 19:00:52 +0200 Subject: [PATCH] Issue #1800: wrap column default expression in parentheses on MySQL v8.0.13+ when altering a table --- source/dbconnection.pas | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 7818bd67..adc26345 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -10524,14 +10524,24 @@ begin cdtText: Result := Result + 'DEFAULT '+FConnection.EscapeString(DefaultText); cdtNull: Result := Result + 'DEFAULT NULL'; cdtAutoInc: Result := Result + 'AUTO_INCREMENT'; - cdtExpression: Result := Result + 'DEFAULT '+DefaultText; + cdtExpression: begin + if FConnection.Parameters.IsMySQL(True) and (FConnection.ServerVersionInt >= 80013) then + Result := Result + 'DEFAULT ('+DefaultText+')' + else + Result := Result + 'DEFAULT '+DefaultText; + end; end; case OnUpdateType of // cdtNothing: leave out whole clause // cdtText: not supported, but may be valid in MariaDB? // cdtNull: not supported, but may be valid in MariaDB? // cdtAutoInc: not valid in ON UPDATE - cdtExpression: Result := Result + ' ON UPDATE '+OnUpdateText; + cdtExpression: begin + if FConnection.Parameters.IsMySQL(True) and (FConnection.ServerVersionInt >= 80013) then + Result := Result + ' ON UPDATE ('+OnUpdateText+')' + else + Result := Result + ' ON UPDATE '+OnUpdateText; + end; end; Result := Result + ' '; end;