Skip to content

upsert() throws 'more question marks in the SQL than params defined' if parameters are repeated in update #295

Description

@michaelborn

This query attempts to update the Name column using a passed-in value, but QB seemingly fails to append the binding to the queryExecute call:

getInstance( "QueryBuilder@qb" )
    .table( "myTable" )
    .upsert(
        target = [ "Vendor_Code", "Code" ],
        values = {
            "Vendor_Code"  : variables.vendor_code,
            "Code"         : row.Code,
            "Count"        : 1,
            "Name"         : row.Name
        },
        update = {
            "Count"        : newQueryBuilder().raw( "[qb_target].[Count] + 1" ),
            "Name"         : row.Name
        }
    );

This throws:

there are more question marks in the SQL than params defined

MERGE [myTable] AS [qb_target]
USING
    (VALUES (?, ?, ?, ?)) AS [qb_src] ([Code], [Count], [Name], [Vendor_Code])
    ON [qb_target].[Vendor_Code] = [qb_src].[Vendor_Code]
AND [qb_target].[Code] = [qb_src].[Code]
WHEN MATCHED THEN 
    UPDATE SET [Count] = [qb_target].[Count] + 1, [Name] = ?
WHEN NOT MATCHED BY TARGET THEN 
    INSERT ([Code], [Count], [Name], [Vendor_Code])
    VALUES ([Code], [Count], [Name], [Vendor_Code])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions