Skip to content

Cannot Bind Parameters in GenericExecuteSpec.filters #1630

@hciq-justin-michalczak

Description

@hciq-justin-michalczak

Here's the concept:

final Integer parameter = 5; // Or maybe null.
final String sql = (parameter == null) ? "SELECT 0" : "SELECT :param";
return databaseClient.sql(sql)
    .filter(statement -> {
        if (parameter == null) {
            return statement;
        } else {
            return statement.bind("param", parameter);
        }
    })
    .all();

(Obviously this simple example could be worked around via other means. The real code involves dynamic SQL over possibly-provided filter parameters.)

Expected

The query functions with the binding provided during the filter chain.

Actual

The statement fails before the filter chain is invoked, indicating that the param binding is not set.

org.springframework.dao.InvalidDataAccessApiUsageException: No parameter specified for [param] in query [SELECT :param]

I cannot find any documentation on how the DatabaseClient.GenericExecuteSpec filter chain is intended to work. So I'm unsure whether this would be an enhancement request or bug report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions