mithrandyr / SimplySql

PowerShell module for querying various SQL databases
MIT License
197 stars 31 forks source link

Incorrect Invoke-SqlQuery warning #164

Closed Dave-Sexton-Luma closed 1 week ago

Dave-Sexton-Luma commented 3 weeks ago

I am getting the following warning when using Invoke-SqlQuery:

WARNING: Query returned no resultset. This occurs when the query has no select statement or invokes a stored procedure that does not return a resultset. Use 'Invoke-SqlUpdate' to avoid this warning.

However, below is an example of the type of query that I am using which has an OUTPUT clause (for SQL Server or RETURNING for PostgreSQL). In this case the warning is incorrect, if I changed to Invoke-SqlUpdate then the query would not return the results only the number of records changed.

UPDATE table1
SET
    column1 = @column1
OUTPUT
    deleted.column1
    ,deleted.column2
    ,inserted.column1
WHERE id = @id
mithrandyr commented 2 weeks ago

thanks @Dave-Sexton-Luma -- I'll take a look as soon as I can.

mithrandyr commented 1 week ago

@Dave-Sexton-Luma -- the only way I can reproduce the above issue is if no changes were made. I.e. in your example if the value of @id is say 4 and in the table table1 there are no rows where id = 4 -- so long as at least one row is affected, then the results are returned as expected. If no results are returned, then the warning will be displayed (but the warning will not prevent execution from continuing). If you don't want to see the warning, then use -WarningAction Ignore (i.e. Invoke-SqlQuery "some query here" -WarningAction Ignore).