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

support custom DeParser #2013

Merged
merged 1 commit into from
May 29, 2024
Merged

support custom DeParser #2013

merged 1 commit into from
May 29, 2024

Conversation

redkale
Copy link
Contributor

@redkale redkale commented May 27, 2024

My requirement scenario is :
sql template "SELECT * FROM user WHERE name = :param_name AND status = :param_status"
where param_name and param_status both is null, need generated sql: "SELECT * FROM user"
where param_name is not null, param_status is null, need generated sql: "SELECT * FROM user WHERE name = ? "
so deParse where expression maybe is empty

deparseDistinctClause、deparseSelectItemsClause、deparseOrderByElementsClause requires two parameters ,
Parameter plainSelect mainly used to determine the current selection. like:

  @Override
  protected void deparseDistinctClause(PlainSelect plainSelect, Distinct distinct) {
    if (this.countSelect != plainSelect) {
        super.deparseDistinctClause(plainSelect, distinct);
    } else {
        super.deparseDistinctClause(plainSelect, this.countDistinct);
    }
}

protected void deparseSelectItemsClause(PlainSelect plainSelect, List<SelectItem<?>> selectItems) {
    if (this.countSelect != plainSelect) {
        super.deparseSelectItemsClause(plainSelect, selectItems);
    } else {
        super.deparseSelectItemsClause(plainSelect, this.countRootSelectItems);
    }
}

protected void deparseOrderByElementsClause(PlainSelect plainSelect, List<OrderByElement> orderByElements) {
    if (this.countSelect != plainSelect) {
        super.deparseOrderByElementsClause(plainSelect, orderByElements);
    } else {
        super.deparseOrderByElementsClause(plainSelect, null);
    }
}

@redkale
Copy link
Contributor Author

redkale commented May 28, 2024

@manticore-projects thanks, I resubmitted a request.

@manticore-projects manticore-projects merged commit 7479342 into JSQLParser:master May 29, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants