Skip to content

Commit 179a484

Browse files
committed
fix: prepend database name to the trigger name at the correct position, when newer MariaDB versions use IF NOT EXISTS
Refs #2528
1 parent 9cb9c93 commit 179a484

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

source/tabletools.pas

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,8 +2012,15 @@ procedure TfrmTableTools.DoExport(DBObj: TDBObject);
20122012
lntTrigger: begin
20132013
StrucResult := DBObj.Connection.GetResults('SHOW TRIGGERS FROM '+DBObj.QuotedDatabase+' WHERE `Trigger`='+DBObj.Connection.EscapeString(DBObj.Name));
20142014
Struc := DBObj.GetCreateCode(False, menuExportRemoveDefiner.Checked);
2015-
if ToDb then
2016-
Insert(Quoter.QuoteIdent(FinalDbName)+'.', Struc, Pos('TRIGGER', Struc) + 8 );
2015+
if ToDb then begin
2016+
// Prepend target database to trigger name
2017+
Struc := ReplaceRegExpr(
2018+
'TRIGGER(\s+IF\s+NOT\s+EXISTS)?\s+',
2019+
Struc,
2020+
'$0' + Quoter.QuoteIdent(FinalDbName)+'.',
2021+
[rroModifierI, rroUseSubstitution, rroModifierG] // Greedy is required to catch group 1
2022+
);
2023+
end;
20172024
if ToFile or ToClipboard or ToDir then begin
20182025
Struc := 'SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE=' + DBObj.Connection.EscapeString(StrucResult.Col('sql_mode')) + ';' + CRLF +
20192026
'DELIMITER ' + TempDelim + CRLF +

0 commit comments

Comments
 (0)