Skip to content

{inq: []} produces invalid SQL #19

@bitmage

Description

@bitmage

This query:

Project.find({
  fields: { id: true },
  where: { id: { inq: [] } } }
}, function(){})

Produces this SQL:

SELECT [id] FROM [dbo].[Project]
WHERE 0
ORDER BY [id]

Which is invalid, and fails with this error:

RequestError: An expression of non-boolean type specified in a context where a condition is expected, near 'ORDER'.

The query presented is generated by the changes method, which is part of the Loopback replication implementation. This particular query will be generated when there are no changes detected.

I think the changes method should ignore this case and not send a query. I will send a separate issue/pull request for that.

I bring up the issue here though, because I think that the MSSQL driver should probably also gracefully handle this situation by creating a no-op query. Something like this:

SELECT [id] FROM [dbo].[Project]
WHERE 0 = 1
ORDER BY [id]

or...

WHERE [id] IS NULL

or...

WHERE [id] IN (NULL)

I'm concerned about the latter two though, as they might incorrectly produce results in the case of a NULLABLE field. Is there a better way to form such a query? I'm happy to make a pull request if I can get some feedback on what the correct solution would be.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions