Skip to content

Commit 27a3a51

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 4fcff3b commit 27a3a51

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
@@ -1983,8 +1983,15 @@ procedure TfrmTableTools.DoExport(DBObj: TDBObject);
19831983
lntTrigger: begin
19841984
StrucResult := DBObj.Connection.GetResults('SHOW TRIGGERS FROM '+DBObj.QuotedDatabase+' WHERE `Trigger`='+DBObj.Connection.EscapeString(DBObj.Name));
19851985
Struc := DBObj.GetCreateCode(False, menuExportRemoveDefiner.Checked);
1986-
if ToDb then
1987-
Insert(Quoter.QuoteIdent(FinalDbName)+'.', Struc, Pos('TRIGGER', Struc) + 8 );
1986+
if ToDb then begin
1987+
// Prepend target database to trigger name
1988+
Struc := ReplaceRegExpr(
1989+
'TRIGGER(\s+IF\s+NOT\s+EXISTS)?\s+',
1990+
Struc,
1991+
'$0' + Quoter.QuoteIdent(FinalDbName)+'.',
1992+
[rroModifierI, rroUseSubstitution, rroModifierG] // Greedy is required to catch group 1
1993+
);
1994+
end;
19881995
if ToFile or ToClipboard or ToDir then begin
19891996
Struc := 'SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE=' + DBObj.Connection.EscapeString(StrucResult.Col('sql_mode')) + ';' + CRLF +
19901997
'DELIMITER ' + TempDelim + CRLF +

0 commit comments

Comments
 (0)