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

Prevent XML parsing error #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions sp_WhoIsActive.sql
Original file line number Diff line number Diff line change
Expand Up @@ -448,37 +448,37 @@ BEGIN;
RAISERROR('Input parameters cannot be NULL', 16, 1);
RETURN;
END;

IF @filter_type NOT IN ('session', 'program', 'database', 'login', 'host')
BEGIN;
RAISERROR('Valid filter types are: session, program, database, login, host', 16, 1);
RETURN;
END;

IF @filter_type = 'session' AND @filter LIKE '%[^0123456789]%'
BEGIN;
RAISERROR('Session filters must be valid integers', 16, 1);
RETURN;
END;

IF @not_filter_type NOT IN ('session', 'program', 'database', 'login', 'host')
BEGIN;
RAISERROR('Valid filter types are: session, program, database, login, host', 16, 1);
RETURN;
END;

IF @not_filter_type = 'session' AND @not_filter LIKE '%[^0123456789]%'
BEGIN;
RAISERROR('Session filters must be valid integers', 16, 1);
RETURN;
END;

IF @show_sleeping_spids NOT IN (0, 1, 2)
BEGIN;
RAISERROR('Valid values for @show_sleeping_spids are: 0, 1, or 2', 16, 1);
RETURN;
END;

IF @get_plans NOT IN (0, 1, 2)
BEGIN;
RAISERROR('Valid values for @get_plans are: 0, 1, or 2', 16, 1);
Expand All @@ -496,7 +496,7 @@ BEGIN;
RAISERROR('Valid values for @format_output are: 0, 1, or 2', 16, 1);
RETURN;
END;

IF @get_memory_info = 1 AND NOT EXISTS (SELECT * FROM sys.all_objects WHERE name = 'resource_governor_resource_pools')
BEGIN;
RAISERROR('@get_memory_info is not available for SQL Server 2005.', 16, 1);
Expand Down Expand Up @@ -716,7 +716,7 @@ BEGIN;
ORDER BY
param_group,
group_order;

WITH
a0 AS
(SELECT 1 AS n UNION ALL SELECT 1),
Expand Down Expand Up @@ -964,7 +964,7 @@ BEGIN;
UNION ALL
SELECT '[physical_io_delta]', 17
WHERE
@delta_interval > 0
@delta_interval > 0
AND @get_task_info = 2
UNION ALL
SELECT '[reads_delta]', 18
Expand Down Expand Up @@ -1100,13 +1100,13 @@ BEGIN;
1,
''
);

IF COALESCE(RTRIM(@output_column_list), '') = ''
BEGIN;
RAISERROR('No valid column matches found in @output_column_list or no columns remain due to selected options.', 16, 1);
RETURN;
END;

IF @destination_table <> ''
BEGIN;
SET @destination_table =
Expand All @@ -1116,7 +1116,7 @@ BEGIN;
COALESCE(QUOTENAME(PARSENAME(@destination_table, 2)) + '.', '') +
--table
COALESCE(QUOTENAME(PARSENAME(@destination_table, 1)), '');

IF COALESCE(RTRIM(@destination_table), '') = ''
BEGIN;
RAISERROR('Destination table not properly formatted.', 16, 1);
Expand Down Expand Up @@ -1370,7 +1370,7 @@ BEGIN;

--Used for the delta pull
REDO:;

IF
@get_locks = 1
AND @recursion = 1
Expand Down Expand Up @@ -1793,7 +1793,7 @@ BEGIN;
CREATE STATISTICS s_principal_name ON #locks (principal_name)
WITH SAMPLE 0 ROWS, NORECOMPUTE;
END;

DECLARE
@sql VARCHAR(MAX),
@sql_n NVARCHAR(MAX),
Expand Down Expand Up @@ -2830,15 +2830,15 @@ BEGIN;
(
SELECT TOP(@i)
(
SELECT TOP(@i)
SELECT TOP(@i)
x.request_time,
x.grant_time,
x.wait_time_ms,
x.requested_memory_kb,
x.requested_memory_kb,
x.mg_granted_memory_kb AS granted_memory_kb,
x.mg_used_memory_kb AS used_memory_kb,
x.max_used_memory_kb,
x.ideal_memory_kb,
x.ideal_memory_kb,
x.required_memory_kb,
x.queue_id,
x.wait_order,
Expand All @@ -2865,7 +2865,7 @@ BEGIN;
TYPE
),
(
SELECT TOP(@i)
SELECT TOP(@i)
x.wg_name AS name,
x.request_max_memory_grant_percent,
x.request_max_cpu_time_sec,
Expand All @@ -2876,7 +2876,7 @@ BEGIN;
TYPE
),
(
SELECT TOP(@i)
SELECT TOP(@i)
x.rp_name AS name,
x.min_memory_percent,
x.max_memory_percent,
Expand All @@ -2891,7 +2891,7 @@ BEGIN;
FOR XML
PATH(''memory_info''),
TYPE
)
)
'
ELSE
'NULL '
Expand Down Expand Up @@ -3773,7 +3773,7 @@ BEGIN;
open_tran_count,
sql_handle,
statement_start_offset,
statement_end_offset,
statement_end_offset,
sql_text,
plan_handle,
blocking_session_id,
Expand Down Expand Up @@ -3802,7 +3802,7 @@ BEGIN;
OR @output_column_list LIKE '%|[tran_log_writes|]%' ESCAPE '|'
OR @output_column_list LIKE '%|[implicit_tran|]%' ESCAPE '|'
)
BEGIN;
BEGIN;
DECLARE @i INT;
SET @i = 2147483647;

Expand Down Expand Up @@ -3955,9 +3955,9 @@ BEGIN;
WHERE
s1.transaction_id = s_tran.transaction_id
AND s1.recursion = 1

UNION ALL

SELECT TOP(1)
s2.session_id,
s2.request_id
Expand Down Expand Up @@ -3989,7 +3989,7 @@ BEGIN;
END;

--Variables for text and plan collection
DECLARE
DECLARE
@session_id SMALLINT,
@request_id INT,
@sql_handle VARBINARY(64),
Expand Down Expand Up @@ -4100,9 +4100,9 @@ BEGIN;
text,
0 AS row_num
FROM sys.dm_exec_sql_text(@sql_handle)

UNION ALL

SELECT
NULL,
1 AS row_num
Expand Down Expand Up @@ -4372,7 +4372,7 @@ BEGIN;
s.query_plan =
(
SELECT
CONVERT(xml, query_plan)
TRY_CAST(query_plan as xml)
FROM sys.dm_exec_text_query_plan
(
@plan_handle,
Expand Down Expand Up @@ -4589,7 +4589,7 @@ BEGIN;
WHERE
l.database_name = @database_name
OPTION (KEEPFIXED PLAN); ';

EXEC sp_executesql
@sql_n,
N'@database_name sysname',
Expand Down Expand Up @@ -4830,7 +4830,7 @@ BEGIN;
WITH SAMPLE 0 ROWS, NORECOMPUTE;
CREATE STATISTICS s_query_error ON #blocked_requests (query_error)
WITH SAMPLE 0 ROWS, NORECOMPUTE;

INSERT #blocked_requests
(
session_id,
Expand Down Expand Up @@ -4869,20 +4869,20 @@ BEGIN;
OR t.hobt_id IS NOT NULL
OR t.schema_node IS NOT NULL
);

DECLARE blocks_cursor
CURSOR LOCAL FAST_FORWARD
FOR
SELECT DISTINCT
database_name
FROM #blocked_requests;

OPEN blocks_cursor;

FETCH NEXT FROM blocks_cursor
INTO
@database_name;

WHILE @@FETCH_STATUS = 0
BEGIN;
BEGIN TRY;
Expand Down Expand Up @@ -4925,7 +4925,7 @@ BEGIN;
s.schema_id = COALESCE(o.schema_id, b.schema_id)
WHERE
b.database_name = @database_name; ';

EXEC sp_executesql
@sql_n,
N'@database_name sysname',
Expand Down Expand Up @@ -4959,10 +4959,10 @@ BEGIN;
INTO
@database_name;
END;

CLOSE blocks_cursor;
DEALLOCATE blocks_cursor;

UPDATE s
SET
additional_info.modify
Expand Down Expand Up @@ -5073,7 +5073,7 @@ BEGIN;
s.session_id = @session_id
AND s.recursion = 1
OPTION (KEEPFIXED PLAN);

UPDATE s
SET
additional_info.modify
Expand All @@ -5091,7 +5091,7 @@ BEGIN;
BEGIN CATCH;
DECLARE @msdb_error_message NVARCHAR(256);
SET @msdb_error_message = ERROR_MESSAGE();

UPDATE s
SET
additional_info.modify
Expand Down Expand Up @@ -5122,7 +5122,7 @@ BEGIN;
WHERE
s.recursion = 1
OPTION (KEEPFIXED PLAN);

OPEN agent_cursor;

FETCH NEXT FROM agent_cursor
Expand All @@ -5148,7 +5148,7 @@ BEGIN;
CLOSE agent_cursor;
DEALLOCATE agent_cursor;
END;

IF
@delta_interval > 0
AND @recursion <> 1
Expand Down
Loading