From 8f2e7618286a8d1f39b875f48177c2bc8d09d930 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 28 Apr 2023 14:44:54 +0200 Subject: [PATCH] Issue #1800: attempt to distinguish text values from function expressions in a column's default value, for MySQL 8.0.13+ which seems to allow just all functions as default value. --- source/dbconnection.pas | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 0dfd3cec..7818bd67 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -5589,11 +5589,21 @@ begin // Inexact fallback detection, wrong if MariaDB allows "0+1" as expression at some point Result := Result or Value.IsEmpty or IsInt(Value[1]); end else if FParameters.IsAnyMySQL then begin - // Only MySQL case with expression in default value is as follows: - if (Tp.Category = dtcTemporal) and Value.StartsWith('CURRENT_TIMESTAMP', True) then begin - Result := False; - end else begin - Result := True; + if ServerVersionInt <= 80013 then begin + // Only MySQL case with expression in default value is as follows: + if (Tp.Category = dtcTemporal) and Value.StartsWith('CURRENT_TIMESTAMP', True) then begin + Result := False; + end else begin + Result := True; + end; + end + else begin + // https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html#data-type-defaults-explicit + // MySQL 8.0.13+ expect expressions to be wrapped in (..) when you create a table. + // But checking if first char is an opening parenthesis does not work here, as we get the expression + // from IS.COLUMNS, not from SHOW CREATE TABLE. So here's a workaround for distinguishing text + // from an expression: + Result := not Value.Contains('('); end; end else begin // MS SQL, PG and SQLite: