DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
357 stars 19 forks source link

Missing brackets from IN clause causes Error - code still works #50

Open oriches opened 12 months ago

oriches commented 12 months ago

SQL string looks something like "... WHERE [DividendId] IN @Ids ORDER BY [SecId];"

This caused error DAP206 Incorrect syntax near @Ids, but the code executes as expected without having the brackets around the IN parameter,

Should this be an Error or a Warning - if the code still works, it feels like a Warning, and the correction an advisory.

mgravell commented 12 months ago

Please indicate what version you're using. I think this is already fixed; this works without any warnings:

var ids = new List<int> { 1, 2, 3 };

_ = conn.Query<string>("""
    select A, B, C
    from SomeTable
    where Id in @ids
    order by [SecId]
    """, new { ids });
oriches commented 12 months ago

0.5.0-beta.102

mgravell commented 12 months ago

can you show a concrete example then? because I can't repro - it does the right thing; also, make sure you've shut down the IDE - changing analyzer versions when devenv is open: is hit and miss

oriches commented 12 months ago

This is strange - was still doing it after restart, but now it has stopped, but now seem to have found a bug in Dapper (which I can;t believe...):

I have parameters declared as follows (id's are integers)

var parameters - new
{
   ids = ids.OrderBy(id => id)
}

When I use a sql statement with the explicit '(' ')' characters around the @Ids parameter I get a sql exception, e.,g

'WHERE [A] IN (@Ids) ORDER BY [B];'

causes the following exception message - "Incorrect syntax near ','."

mgravell commented 11 months ago

That's not a bug - it is a usage error, i.e. "don't do that" (when the parameter is going to be expanded). But it is something we can detect and issue guidance about in the analyzer. Are you happy for me to repurpose this ticket to track that?

mgravell commented 11 months ago

Btw, the LINQ order-by on the arg items shouldn't matter, at least semantically

oriches commented 11 months ago

Happy to re-purpose

xPaw commented 9 months ago

Is list expansion currently unsupported for MySqlConnection? With Dapper.AOT I am getting the following runtime exception (using the sample code from first comment).

System.NotSupportedException: 'Parameter type List`1 is not supported; see https://fl.vu/mysql-param-type. Value: System.Collections.Generic.List`1[System.Int32]'

Using version 1.0.14.

swimmesberger commented 7 months ago

Is list expansion currently unsupported for MySqlConnection? With Dapper.AOT I am getting the following runtime exception (using the sample code from first comment).

System.NotSupportedException: 'Parameter type List`1 is not supported; see https://fl.vu/mysql-param-type. Value: System.Collections.Generic.List`1[System.Int32]'

Using version 1.0.14.

Having the same issue with MySqlConnector