[英]Create and run stored procedure using Grails database migration plugin
我正在尝试进行一个稍微麻烦的数据库迁移,并且正在使用存储过程来更新应用程序表之一中的某些行。 如果使用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 path:'my_stored_procedure.sql', splitStatements: false
否则,数据库迁移插件将尝试变得更聪明,并拆分您的语句,这将破坏您的定义。
runOnChange ='true'配置强制插件检查更改集是否已更改,而不是仅检查更改集之前是否已运行过一次,因此可以跳过该更改集。
默认情况下,将文件中的sql语句拆分为;以避免这种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)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.