Skip to content

Error when using case when #62

Description

@cyberrspiritt

Trying to run this query including case when clause

 this.db.select("ar.id as resolution_id, ar.resolution_no, ar.resolution_heading, ar.resolution_text, ar.resolution_proposer, ar.resolution_seconder, " +
        "case when (art.proxy_vote_allowed=1 and ar.proxy_allowed_to_vote=1) then 1 " +
        "when (art.proxy_vote_allowed=1 and ar.`proxy_allowed_to_vote`=0) then 0 " +
        "when (art.proxy_vote_allowed=0 and ar.`proxy_allowed_to_vote`=0) then 0 " +
        "when (art.proxy_vote_allowed=0 and ar.`proxy_allowed_to_vote`=1) then 1 " +
        "end as proxy_vote_allowed, ard.decision_made_by, ard.decision, art.resolution_type, art.resolution_category, art.objection_feasibility, art.pending_dues_vote_allowed, art.decision_calculation_type, art.decision_at_agm, art.decision_threshold_percentage", false)
        .from('agm_resolutions as ar')
        .join('agm_resolution_decisions as ard', 'ar.id = ard.resolution_id and ard.is_active=1', 'left')
        .join('agm_resolution_types as art', 'art.id = ar.resolution_type_id and art.is_active=1')
        .where('ar.agm_id', agmId)
        .where('ar.is_active', 1);

    try {
        let result = await this.db.get();
        this.db.disconnect();
        return result;
    } catch (e) {
        console.log(this.db.last_query());
    }

but the last_query function prints out something different:

SELECT ar.id as resolution_id, ar.resolution_no, ar.resolution_heading, ar.resolution_text, ar.resolution_proposer, ar.resolution_seconder, case when (art.proxy_vote_allowed=1 and ar.proxy_allowed_to_vote=1) then 1 when (art.proxy_vote_allowed=1 and ar.`proxy_allowed_to_vote`=0) then 0 when (art.proxy_vote_allowed=0 and ar.`proxy_allowed_to_vote`=0) then 0 when (art.proxy_vote_allowed=0 and ar.`proxy_allowed_to_vote`=1) AS `then 1 endproxy_vote_allowed, ard`.`decision_made_by, ard`.`decision, art`.`resolution_type, art`.`resolution_category, art`.`objection_feasibility, art`.`pending_dues_vote_allowed, art`.`decision_calculation_type, art`.`decision_at_agm, art`.`decision_threshold_percentage` FROM `agm_resolutions` as `ar` LEFT JOIN `agm_resolution_decisions` as `ard` ON `ar`.`id` = `ard`.`resolution_id` and `ard`.`is_active` = 1 JOIN `agm_resolution_types` as `art` ON `art`.`id` = `ar`.`resolution_type_id` and `art`.`is_active` = 1 WHERE `ar`.`agm_id` = 1 AND `ar`.`is_active` = 1

It prints out parsing error, obviously because it messed up the case when condition when (art.proxy_vote_allowed=0 and ar.proxy_allowed_to_vote=1) AS `then 1 endproxy_vote_allowed, here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions