【问题标题】:Updating old stored procedure after changing database structure更改数据库结构后更新旧存储过程
【发布时间】:2015-04-24 07:01:44
【问题描述】:

我正在更新一个存储过程,它获取 _POST 信息并将其保存到 MySQL 数据库。表的结构发生了变化;某些属性已从 TINYINT(0,1) 更改为 ENUM(Yes/No)。

但是,当我更改过程以反映这一点时,我得到一个解析错误。这意味着我的新声明写错了。我不知道我是怎么做错的。

代码在这里:

DROP PROCEDURE IF EXISTS DSSv3_SummaryInfo_insertPostInfo;
DELIMITER //
CREATE PROCEDURE DSSv3_SummaryInfo_insertPostInfo(
     IN InProjectID INT,
     IN InTimeframe VARCHAR(25),
     IN InDateSpent VARCHAR(3000),
     IN InDateSpentDesc VARCHAR(3000),
     IN InQaName INT,
     IN InWhyStoreDesc TEXT,
     IN InChannelTypeDesc TEXT,
     IN InOtherEntitiesDesc TEXT,
     IN InNetworkDiagramDesc TEXT,
     IN InScopingMethods TEXT,
     IN InScopingConfirmationMethods TEXT,
     IN InScopingMethodEvaluation TEXT,
     IN InScopingMethodDocumentation TEXT,
     IN InScopingMethodAccuracy TEXT,
     IN InScopingAssessorName INT,
     IN InEnvironmentPeople TEXT,
     IN InEnvironmentProcesses TEXT,
     IN InEnvironmentTechnologies TEXT,
     IN InEnvironmentLocations TEXT,
     IN InEnvironmentOther TEXT,
     IN InSegmentationUsed ENUM,
     IN InNoSegmentationAssessor INT,
     IN InSegmentationHow TEXT,
     IN InSegmentationTechnologies TEXT,
     IN InSegmentationValidate TEXT,
     IN InSegmentationFunction TEXT,
     IN InSegmentationIntegrity TEXT,
     IN InWithSegmentationAssessor INT,
     IN InCountriesEntityConductsBusiness TEXT,
     IN InWirelessVerify TEXT,
     IN InWirelessImpact TEXT,
     IN InSamplingNotUsedAssessor INT,
     IN InSamplingUsedAssessor INT,
     IN InSamplingRational TEXT,
     IN InSamplingStandardiseControl TEXT,
     IN InSamplingControlValidation TEXT,
     IN InThirdPartyAssessorPadss INT,
     IN InThirdPartyAssessorP2pe INT,
     IN InThirdPartyScopeReduction TEXT,
     IN InThirdPartyComments TEXT,
     IN InSpIsSp TINYINT,
     IN InSpIncludedRequirements VARCHAR(3000),
     IN InSpExcludedRequirements VARCHAR(3000),
     IN InSpAssessor INT,
     IN InSpIpAddr VARCHAR(1500),
     IN InSpCustomerIpAddr VARCHAR(1500),
     IN InQsInitial TINYINT,
     IN InQsAmount TINYINT,
     IN InQsPassAssessor INT,
     IN InQsDocumentAssessor TEXT,
     IN InQsCorrection TEXT,
     IN InQsAssessorComments TEXT,
     IN InQsAocAssessor TEXT
     )
BEGIN
    /*
    set all _POST data for executive summary
    InParam:
            All _POST data variables on executive summary form
            Excludes _FILES data

    */
    IF NOT EXISTS (SELECT 1 FROM SummaryInfo WHERE ProjectID = InProjectID) THEN
        INSERT INTO SummaryInfo(
             ProjectID,
             timeframe,
             date_spent,
             date_spent_desc,
             qa_name,
             why_store_desc,
             channel_type_desc,
             other_entities_desc,
             network_diagram_desc,

             scoping_methods,
             scoping_confirmation_methods,
             scoping_method_evaluation,
             scoping_method_documentation,
             scoping_method_accuracy,
             scoping_assessor_name,

             environment_people,
             environment_processes,
             environment_technologies,
             environment_locations,
             environment_other,

             segmentation_used,
             no_segmentation_assessor,
             segmentation_how,
             segmentation_technologies,
             segmentation_validate,
             segmentation_function,
             segmentation_integrity,
             with_segmentation_assessor,
             countries_entity_conducts_business,
             wireless_verify,
             wireless_impact,

             sampling_not_used_assessor,
             sampling_used_assessor,
             sampling_rational,
             sampling_standardise_control,
             sampling_control_validation,
             third_party_assessor_padss,
             third_party_assessor_p2pe,
             third_party_scope_reduction,
             third_party_comments,

             sp_is_sp,
             sp_included_requirements,
             sp_excluded_requirements,
             sp_assessor,
             sp_ip_addr,
             sp_customer_ip_addr,

             qs_initial,
             qs_amount,
             qs_pass_assessor,
             qs_document_assessor,
             qs_correction,
             qs_assessor_comments,
             qs_aoc_assessor
            ) 
        VALUES (
            InProjectID,
            InTimeframe,
            InDateSpent,
            InDateSpentDesc,
            InQaName,
            InWhyStoreDesc,
            InChannelTypeDesc,
            InOtherEntitiesDesc,
            InNetworkDiagramDesc,

            InScopingMethods,
            InScopingConfirmationMethods,
            InScopingMethodEvaluation,
            InScopingMethodDocumentation,
            InScopingMethodAccuracy,
            InScopingAssessorName,

            InEnvironmentPeople,
            InEnvironmentProcesses,
            InEnvironmentTechnologies,
            InEnvironmentLocations,
            InEnvironmentOther,

            InSegmentationUsed,
            InNoSegmentationAssessor,
            InSegmentationHow,
            InSegmentationTechnologies,
            InSegmentationValidate,
            InSegmentationFunction,
            InSegmentationIntegrity,
            InWithSegmentationAssessor,
            InCountriesEntityConductsBusiness,
            InWirelessVerify,
            InWirelessImpact,

            InSamplingNotUsedAssessor,
            InSamplingUsedAssessor,
            InSamplingRational,
            InSamplingStandardiseControl,
            InSamplingControlValidation,

            InThirdPartyAssessorPadss,
            InThirdPartyAssessorP2pe,
            InThirdPartyScopeReduction,
            InThirdPartyComments,

            InSpIsSp,
            InSpIncludedRequirements,
            InSpExcludedRequirements,
            InSpAssessor,
            InSpIpAddr,
            InSpCustomerIpAddr,

            InQsInitial,
            InQsAmount,
            InQsPassAssessor,
            InQsDocumentAssessor,
            InQsCorrection,
            InQsAssessorComments,
            InQsAocAssessor 
            );
    ELSE 
        UPDATE SummaryInfo SET
            timeframe = InTimeframe,
            date_spent = InDateSpent,
            date_spent_desc = InDateSpentDesc,
            qa_name = InQaName,
            why_store_desc = InWhyStoreDesc,
            channel_type_desc = InChannelTypeDesc,
            other_entities_desc = InOtherEntitiesDesc,
            network_diagram_desc = InNetworkDiagramDesc,

            scoping_methods = InScopingMethods,
            scoping_confirmation_methods = InScopingConfirmationMethods,
            scoping_method_evaluation = InScopingMethodEvaluation,
            scoping_method_documentation = InScopingMethodDocumentation,
            scoping_method_accuracy = InScopingMethodAccuracy,
            scoping_assessor_name = InScopingAssessorName,

            environment_people = InEnvironmentPeople,
            environment_processes = InEnvironmentProcesses,
            environment_technologies = InEnvironmentTechnologies,
            environment_locations = InEnvironmentLocations,
            environment_other = InEnvironmentOther,

            segmentation_used = InSegmentationUsed,
            no_segmentation_assessor = InNoSegmentationAssessor,
            segmentation_how = InSegmentationHow,
            segmentation_technologies = InSegmentationTechnologies,
            segmentation_validate = InSegmentationValidate,
            segmentation_function = InSegmentationFunction,
            segmentation_integrity = InSegmentationIntegrity,
            with_segmentation_assessor = InWithSegmentationAssessor,
            countries_entity_conducts_business = InCountriesEntityConductsBusiness,
            wireless_verify = InWirelessVerify,
            wireless_impact = InWirelessImpact,

            sampling_not_used_assessor = InSamplingNotUsedAssessor,
            sampling_used_assessor = InSamplingUsedAssessor,
            sampling_rational = InSamplingRational,
            sampling_standardise_control = InSamplingStandardiseControl,
            sampling_control_validation = InSamplingControlValidation,

            third_party_assessor_padss = InThirdPartyAssessorPadss,
            third_party_assessor_p2pe = InThirdPartyAssessorP2pe,
            third_party_scope_reduction = InThirdPartyScopeReduction,
            third_party_comments = InThirdPartyComments,

            sp_is_sp = InSpIsSp,
            sp_included_requirements = InSpIncludedRequirements,
            sp_excluded_requirements = InSpExcludedRequirements,
            sp_assessor = InSpAssessor,
            sp_ip_addr = InSpIpAddr,
            sp_customer_ip_addr = InSpCustomerIpAddr,

            qs_initial = InQsInitial,
            qs_amount = InQsAmount,
            qs_pass_assessor = InQsPassAssessor,
            qs_document_assessor = InQsDocumentAssessor,
            qs_correction = InQsCorrection,
            qs_assessor_comments = InQsAssessorComments,
            qs_aoc_assessor = InQsAocAssessor  

        WHERE
            ProjectID = InProjectID;
    END IF;
END//
DELIMITER ;

错误信息:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 22 行的“IN InNoSegmentationAssessor INT,IN InSegmentationH”附近使用正确的语法

当我将 ENUM 改回 INT 时,就像在结构更改之前一样,存储过程加载时不会出错。但是它当然不会起作用,因为它与数据库的结构不匹配。

我一直在寻找答案,但我很清楚在这个特定情况下我首先做错了什么。任何提示或建议都会很好。

是的,这是一个庞大的过程。它是遗留代码。是的,它是一个枚举。就是出一份报告。

【问题讨论】:

    标签: mysql stored-procedures enums int


    【解决方案1】:

    当您声明ENUM 时,您必须指定值。所以应该是:

    IN InSegmentationUsed ENUM('Yes', 'No'),
    

    【讨论】:

    • 所以我必须再次定义这些值?表结构不知道值吗? ('是','否')?
    • 过程参数不是表格的一部分。
    • 您可以做的是将过程参数声明为VARCHAR。当您使用它们插入表格时,字符串将被转换为ENUM
    • 谢谢大家,它正在工作。哪种方式“更好”?使用 VARCHAR(3) 或 ENUM。我认为 ENUM 会是更好的方法,因为没有类型转换?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多