Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Database Triggers Cause Exception #25

Closed
Azhkanizkael opened this issue Jan 31, 2018 · 4 comments · May be fixed by #31
Closed

[bug] Database Triggers Cause Exception #25

Azhkanizkael opened this issue Jan 31, 2018 · 4 comments · May be fixed by #31
Assignees

Comments

@Azhkanizkael
Copy link

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Exception calling "Stop" with "0" argument(s): "Unable to cast object of type 'System.DBNull' to type 'System.String'."

How to reproduce:
run sqlcover against a database without database level triggers, it will succeed. Add 1 database trigger to the database and sqlcover will fail.

I took your script from the encryption error issue and found that Database Level Triggers do not have object_names pulled from the query you provided.

SELECT object_id, '[' + object_schema_name(object_id) + '].[' + object_name(object_id) + ']' as object_name, definition, uses_quoted_identifier from sys.sql_modules where object_id not in (select object_id from sys.objects where type = 'IF')

This is when using the covering other stuff scripts.

$coverage = new-object SQLCover.CodeCoverage($connectionString, $database, $true, $false)
$coverage.Start() 
#do stuff here
$coverageResults = $coverage.Stop()
@Azhkanizkael Azhkanizkael changed the title [bug] Database Triggers cause Exception [bug] Database Triggers Cause Exception Jan 31, 2018
@Azhkanizkael
Copy link
Author

A fix to this is to alter the query used to populate this data to read inside of DatabaseSourceGateway.cs:

SELECT sm.object_id, ISNULL('[' + OBJECT_SCHEMA_NAME(sm.object_id)+ '].[' + OBJECT_NAME(sm.object_id) + ']','[' + st.name + ']')  object_name, sm.definition, sm.uses_quoted_identifier FROM sys.sql_modules sm LEFT JOIN sys.triggers st ON st.object_id = sm.object_id WHERE sm.object_id NOT IN (SELECT object_id FROM sys.objects WHERE type = 'IF');

I've made a fix for this in my fork of the project:
https://github.com/Azhkanizkael/SQLCover/blob/master/src/SQLCover/SQLCover/Source/DatabaseSourceGateway.cs

@Radamonas
Copy link

Do you know when we could expect the fix for this issue to be released?

@GoEddie
Copy link
Owner

GoEddie commented Dec 13, 2018

I am starting to put together the next release, I will include this fix in that release.

Thanks @Azhkanizkael for the fix :)

@GoEddie
Copy link
Owner

GoEddie commented Oct 15, 2019

This should be included in 0.5.0:

https://github.com/GoEddie/SQLCover/releases/tag/0.5.0

any problems please re-open and let me know

@GoEddie GoEddie closed this as completed Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants