Running embeded scripts

79 views
Skip to first unread message

Scott Zumwalt

unread,
Jun 27, 2017, 5:08:09 PM6/27/17
to FluentMigrator Google Group
I've just started the work to move all my old database scripts into FM. My product supports MySQL and SQL Server. All the tables are easy, but we have some stored procedures and triggers that are, of course, database specific. So I'm just running our previously working scripts as embedded scripts in FM, but they don't work. It seems like FM is trying to run each line as a separate transaction. There isn't a lot of error output, but here is what I got:

Input script (edited to protect company):

delimiter $$
CREATE
DEFINER=`root`@`%`
TRIGGER `on_insert_XXXXX`
AFTER INSERT ON `XXXXX`
FOR EACH ROW
begin
    set @count = (select count(*) from YYYYY where e= new.e);
    if (@count = 0) then
    insert into YYYYY (a,b,c,d,e)
             values(new.a, new.b, new.c, new.d, new.e);
    else
        update YYYYYY set a= new.a, b= new.b, c= new.c, d= new.d where e= new.e;
    end if;
end$$
delimiter ;

FM Error:
!!! Fatal error encountered during command execution.
!!! Parameter '@count' must be defined.
!!! Fatal error encountered during command execution.
!!! Parameter '@count' must be defined.

Does the script need to be formatted in a specific way for FM?

Dustin Venegas

unread,
Jun 27, 2017, 5:14:21 PM6/27/17
to FluentMigrator Google Group
@Scott,

It depends how you're executing it from FluentMigrator. How are you calling the script? Is it line-by-line, as an embedded resource, as a string constant, or something else?

Thanks,
-dev

--
You received this message because you are subscribed to the Google Groups "FluentMigrator Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fluentmigrator-goog...@googlegroups.com.
To post to this group, send email to fluentmigrato...@googlegroups.com.
Visit this group at https://groups.google.com/group/fluentmigrator-google-group.
For more options, visit https://groups.google.com/d/optout.

Scott Zumwalt

unread,
Jul 1, 2017, 8:33:24 PM7/1/17
to FluentMigrator Google Group
As I stated, it is an embedded script. But I did get it to work. Although, I had to do some kind of weird things. Firstly, I had to set Allow User variables=true in my connection string. Secondly, I had to make sure I had a declare statement for any variable I used. Thirdly, I had to remove the '@' from any variable I declared. Lastly, I had to remove the delimiter statements and put the final semicolon on a line by itself.

The confounding part is that the script as I had it works fine if I pipe it directly into mysql. So does that mean the migrator parses the script on its own or is it pushing the DML into the server in some other weird way?
To unsubscribe from this group and stop receiving emails from it, send an email to fluentmigrator-google-group+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages