Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用Grails数据库迁移插件创建并运行存储过程_Mysql_Grails_Database Migration - Fatal编程技术网

Mysql 使用Grails数据库迁移插件创建并运行存储过程

Mysql 使用Grails数据库迁移插件创建并运行存储过程,mysql,grails,database-migration,Mysql,Grails,Database Migration,我正在尝试进行一次稍微笨拙的数据库迁移,并使用存储过程更新应用程序表中的一些行。如果使用mysql命令行工具或在Sequel Pro中执行存储过程,则该存储过程运行正常,但是如果尝试使用数据库迁移插件运行它,则该存储过程不会运行 看起来liquibase支持存储过程,但数据库迁移插件似乎崩溃了。有人知道这是否有效吗 错误(以及完整的存储过程)如下所示: 2014-03-08 09:05:21,693 [localhost-startStop-1] INFO liquibase - C

我正在尝试进行一次稍微笨拙的数据库迁移,并使用存储过程更新应用程序表中的一些行。如果使用mysql命令行工具或在Sequel Pro中执行存储过程,则该存储过程运行正常,但是如果尝试使用数据库迁移插件运行它,则该存储过程不会运行

看起来liquibase支持存储过程,但数据库迁移插件似乎崩溃了。有人知道这是否有效吗

错误(以及完整的存储过程)如下所示:

    2014-03-08 09:05:21,693 [localhost-startStop-1] INFO  liquibase  - ChangeSet changelog_fb_contactForm_2_add_new_enquiry_roles.groovy::1393960870500-1::rcgeorge23 ran successfully in 6671ms
    | Error 2014-03-08 09:05:21,704 [localhost-startStop-1] ERROR liquibase  - Change Set changelog_fb_contactForm_3_add_enquiry_flexible_model_definition_to_existing_organisations.groovy::1393960870500-1::rcgeorge23
     failed.  Error: Error executing SQL DELIMITER // 
                            CREATE PROCEDURE ABC() 
                            BEGIN 
                                    REPEAT 
                                            set @organisationConfigurationId = (select id from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null limit 1); 
                                            insert into flexible_model_definition (`version`, `name`) values ('0', 'enquiry.flexible.model'); 
                                            set @newlyInsertedEnquiryFlexibleModelDefinitionId = LAST_INSERT_ID(); 
                                            update organisation_configuration oc set oc.enquiry_flexible_model_definition_id = @newlyInsertedEnquiryFlexibleModelDefinitionId where oc.id = @organisationConfigurationId
    ; 
                                    UNTIL 0 = (select count(*) from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null) 
                            END REPEAT; 
                            END //: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER // 
                            CREATE PROCEDURE ABC() 
                            BEGIN 
                                    REPEAT 
                                            set @organis' at line 1
    Message: Error executing SQL DELIMITER // 
                            CREATE PROCEDURE ABC() 
                            BEGIN 
                                    REPEAT 
                                            set @organisationConfigurationId = (select id from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null limit 1); 
                                            insert into flexible_model_definition (`version`, `name`) values ('0', 'enquiry.flexible.model'); 
                                            set @newlyInsertedEnquiryFlexibleModelDefinitionId = LAST_INSERT_ID(); 
                                            update organisation_configuration oc set oc.enquiry_flexible_model_definition_id = @newlyInsertedEnquiryFlexibleModelDefinitionId where oc.id = @organisationConfigurationId
    ; 
                                    UNTIL 0 = (select count(*) from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null) 
                            END REPEAT; 
                            END //: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER // 
                            CREATE PROCEDURE ABC() 
                            BEGIN 
                                    REPEAT 
                                            set @organis' at line 1
        Line | Method
    ->>   62 | execute                        in liquibase.executor.jvm.JdbcExecutor
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    104 | execute                        in     ''
    |   1091 | execute . . . . . . . . . . .  in liquibase.database.AbstractDatabase
    |   1075 | executeStatements              in     ''
    |    317 | execute . . . . . . . . . . .  in liquibase.changelog.ChangeSet
    |     27 | visit                          in liquibase.changelog.visitor.UpdateVisitor
    |     58 | run . . . . . . . . . . . . .  in liquibase.changelog.ChangeLogIterator
    ....

定义存储过程时,请尝试使用
splitStatements
,例如:

sqlFile路径:'my\u storage\u procedure.sql',splitStatements:false


否则,数据库迁移插件将尝试智能化并拆分您的语句,这将破坏您的定义。

runOnChange='true'配置强制插件检查更改集是否已更改,而不是只检查更改集之前是否运行过一次,以便跳过它

默认情况下,文件中的sql语句在上拆分;'s为避免出现这种情况,splitStatements='false'配置用于确保将完整的创建过程脚本作为一个脚本读取,而不是将其拆分;'中每个单独的sql语句的

示例:

changeSet(author: "Rahul", id: "1435600003872-128", runOnChange: "true") {
    sql("DROP PROCEDURE IF EXISTS BestCustomers;")
    sqlFile(path: "../sql/BestCustomers.sql", splitStatements: false)
}
BestCustomers.sql的代码:

CREATE PROCEDURE `BestCustomers`(
     //Input params here
   )
BEGIN
    //Sql scripts here ;
END
可以找到一个分步指南


感谢Rahul Babu。

谢谢这一点-我最后没有使用存储过程,但如果将来需要,我会尝试一下。我没有投反对票,我只是在review pipes上查看了答案