amachanic / sp_whoisactive

sp_whoisactive
GNU General Public License v3.0
1.13k stars 281 forks source link

@get_full_inner_text = 1 #101

Closed Sicos1977 closed 10 months ago

Sicos1977 commented 1 year ago

In my case most of my methods that are running against the database are comming from stored procedures. When the parameter @get_full_inner_text = 1 is set I can get the whole stored procedure but then I don't have the part that is running. Is it somehow possible to get both outer and inner parts.

The reason why I want this is because I want to show the whole stored procedure in a webpage and then highlight the part that is running with the this part is running tags.

I already tried @get_outer_command = 1 but that gives me only the name of the stored procedure that is called.

erikdarlingdata commented 1 year ago

I think the best you can do with the current implementation is to use ‘get_full_inner_text = 0’ with ‘get_outer_command = 1’ which will show you the module name and the current command in it. I realize it’s not precisely what you’re asking for.

Sicos1977 commented 1 year ago

I see that this parts decided to get the inner our outer parts. I tried to add a column myself that gives both parts that I need but I got lost in the stored procedure because it is so damn huge :-)

 s.sql_text =
                        (
                            SELECT
                                REPLACE
                                (
                                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                        N'--' + NCHAR(13) + NCHAR(10) +
                                        CASE
                                            WHEN @get_full_inner_text = 1 THEN est.text
                                            WHEN LEN(est.text) < (@statement_end_offset / 2) + 1 THEN est.text
                                            WHEN SUBSTRING(est.text, (@statement_start_offset/2), 2) LIKE N'[a-zA-Z0-9][a-zA-Z0-9]' THEN est.text
                                            ELSE
                                                CASE
                                                    WHEN @statement_start_offset > 0 THEN
                                                        SUBSTRING
                                                        (
                                                            est.text,
                                                            ((@statement_start_offset/2) + 1),
                                                            (
                                                                CASE
                                                                    WHEN @statement_end_offset = -1 THEN 2147483647
                                                                    ELSE ((@statement_end_offset - @statement_start_offset)/2) + 1
                                                                END
                                                            )
                                                        )
                                                    ELSE RTRIM(LTRIM(est.text))
                                                END
                                        END +
                                        NCHAR(13) + NCHAR(10) + N'--' COLLATE Latin1_General_Bin2,
                                        NCHAR(31),N'?'),NCHAR(30),N'?'),NCHAR(29),N'?'),NCHAR(28),N'?'),NCHAR(27),N'?'),NCHAR(26),N'?'),NCHAR(25),N'?'),NCHAR(24),N'?'),NCHAR(23),N'?'),NCHAR(22),N'?'),
                                        NCHAR(21),N'?'),NCHAR(20),N'?'),NCHAR(19),N'?'),NCHAR(18),N'?'),NCHAR(17),N'?'),NCHAR(16),N'?'),NCHAR(15),N'?'),NCHAR(14),N'?'),NCHAR(12),N'?'),
                                        NCHAR(11),N'?'),NCHAR(8),N'?'),NCHAR(7),N'?'),NCHAR(6),N'?'),NCHAR(5),N'?'),NCHAR(4),N'?'),NCHAR(3),N'?'),NCHAR(2),N'?'),NCHAR(1),N'?'),
                                    NCHAR(0),
                                    N''
                                ) AS [processing-instruction(query)]
                            FOR XML
                                PATH(''),
                                TYPE
                        ),
                        s.statement_start_offset =
                            CASE
                                WHEN LEN(est.text) < (@statement_end_offset / 2) + 1 THEN 0
                                WHEN SUBSTRING(CONVERT(VARCHAR(MAX), est.text), (@statement_start_offset/2), 2) LIKE '[a-zA-Z0-9][a-zA-Z0-9]' THEN 0
                                ELSE @statement_start_offset
                            END,
                        s.statement_end_offset =
                            CASE
                                WHEN LEN(est.text) < (@statement_end_offset / 2) + 1 THEN -1
                                WHEN SUBSTRING(CONVERT(VARCHAR(MAX), est.text), (@statement_start_offset/2), 2) LIKE '[a-zA-Z0-9][a-zA-Z0-9]' THEN -1
                                ELSE @statement_end_offset
                            END

Any tips where to look if I want to add an extra collumn, for example

sql_text--> sql_full_text(renamed) and then also add a column sql_running_textso that I only get the running part in there? And then for example add an extra level to get_outer_command = 2 so that this behaviour is shown instead of the default behaviour.

We can also just not rename sql_textand just add only the extra column sql_running_textwhen requested

erikdarlingdata commented 10 months ago

@Sicos1977 it's been a while since we've heard back from you on this, so I'm going to close the issue out for now. If you decide you want to work on it, just leave a comment here and I'll reopen the issue.