Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using case when #62

Open
cyberrspiritt opened this issue Jul 27, 2020 · 0 comments
Open

Error when using case when #62

cyberrspiritt opened this issue Jul 27, 2020 · 0 comments

Comments

@cyberrspiritt
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant