Skip to content

Commit 1e708b2

Browse files
Darling Datagflpcantor31
authored andcommitted
Automation: Format and Build SQL File
1 parent 851cf1a commit 1e708b2

1 file changed

Lines changed: 170 additions & 62 deletions

File tree

Install-All/DarlingData.sql

Lines changed: 170 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Compile Date: 12/28/2025 13:51:30 UTC
1+
-- Compile Date: 12/28/2025 14:31:00 UTC
22
SET ANSI_NULLS ON;
33
SET ANSI_PADDING ON;
44
SET ANSI_WARNINGS ON;
@@ -5919,6 +5919,12 @@ CREATE TABLE
59195919
human_events_xml xml
59205920
);
59215921

5922+
CREATE TABLE
5923+
#human_events_xml
5924+
(
5925+
human_events_xml xml
5926+
);
5927+
59225928
CREATE TABLE
59235929
#wait
59245930
(
@@ -7299,8 +7305,55 @@ WAITFOR DELAY @waitfor;
72997305

73007306

73017307
/* Dump whatever we got into a temp table */
7302-
IF @azure = 0
7308+
IF LOWER(@target_output) = N'ring_buffer'
7309+
BEGIN
7310+
IF @azure = 0
7311+
BEGIN
7312+
INSERT
7313+
#x WITH(TABLOCK)
7314+
(
7315+
x
7316+
)
7317+
SELECT
7318+
x =
7319+
CONVERT
7320+
(
7321+
xml,
7322+
t.target_data
7323+
)
7324+
FROM sys.dm_xe_session_targets AS t
7325+
JOIN sys.dm_xe_sessions AS s
7326+
ON s.address = t.event_session_address
7327+
WHERE s.name = @session_name
7328+
AND t.target_name = N'ring_buffer';
7329+
END;
7330+
ELSE
7331+
BEGIN
7332+
INSERT
7333+
#x WITH(TABLOCK)
7334+
(
7335+
x
7336+
)
7337+
SELECT
7338+
x =
7339+
CONVERT
7340+
(
7341+
xml,
7342+
t.target_data
7343+
)
7344+
FROM sys.dm_xe_database_session_targets AS t
7345+
JOIN sys.dm_xe_database_sessions AS s
7346+
ON s.address = t.event_session_address
7347+
WHERE s.name = @session_name
7348+
AND t.target_name = N'ring_buffer';
7349+
END;
7350+
END;
7351+
ELSE IF LOWER(@target_output) = N'event_file'
73037352
BEGIN
7353+
/*
7354+
Read from event file target
7355+
Azure SQL Database and Managed Instance are not supported for event_file
7356+
*/
73047357
INSERT
73057358
#x WITH(TABLOCK)
73067359
(
@@ -7311,41 +7364,46 @@ BEGIN
73117364
CONVERT
73127365
(
73137366
xml,
7314-
t.target_data
7367+
f.event_data
73157368
)
7316-
FROM sys.dm_xe_session_targets AS t
7317-
JOIN sys.dm_xe_sessions AS s
7318-
ON s.address = t.event_session_address
7319-
WHERE s.name = @session_name
7320-
AND t.target_name = N'ring_buffer';
7369+
FROM sys.fn_xe_file_target_read_file
7370+
(
7371+
@session_name + N'*.xel',
7372+
NULL,
7373+
NULL,
7374+
NULL
7375+
) AS f;
73217376
END;
7322-
ELSE
7377+
7378+
7379+
/*
7380+
Parse XML events based on target output type
7381+
ring_buffer wraps events in RingBufferTarget node, event_file does not
7382+
*/
7383+
IF LOWER(@target_output) = N'ring_buffer'
73237384
BEGIN
73247385
INSERT
7325-
#x WITH(TABLOCK)
7386+
#human_events_xml WITH(TABLOCK)
73267387
(
7327-
x
7388+
human_events_xml
73287389
)
73297390
SELECT
7330-
x =
7331-
CONVERT
7332-
(
7333-
xml,
7334-
t.target_data
7335-
)
7336-
FROM sys.dm_xe_database_session_targets AS t
7337-
JOIN sys.dm_xe_database_sessions AS s
7338-
ON s.address = t.event_session_address
7339-
WHERE s.name = @session_name
7340-
AND t.target_name = N'ring_buffer';
7391+
human_events_xml = e.x.query('.')
7392+
FROM #x AS x
7393+
CROSS APPLY x.x.nodes('/RingBufferTarget/event') AS e(x);
7394+
END;
7395+
ELSE IF LOWER(@target_output) = N'event_file'
7396+
BEGIN
7397+
INSERT
7398+
#human_events_xml WITH(TABLOCK)
7399+
(
7400+
human_events_xml
7401+
)
7402+
SELECT
7403+
human_events_xml = e.x.query('.')
7404+
FROM #x AS x
7405+
CROSS APPLY x.x.nodes('/event') AS e(x);
73417406
END;
7342-
7343-
7344-
SELECT
7345-
human_events_xml = e.x.query('.')
7346-
INTO #human_events_xml
7347-
FROM #x AS x
7348-
CROSS APPLY x.x.nodes('/RingBufferTarget/event') AS e(x);
73497407

73507408

73517409
IF @debug = 1
@@ -10068,8 +10126,55 @@ ORDER BY
1006810126
);
1006910127

1007010128
/* this table is only used for the inserts, hence the "internal" in the name */
10071-
IF @azure = 0
10129+
IF LOWER(@target_output) = N'ring_buffer'
10130+
BEGIN
10131+
IF @azure = 0
10132+
BEGIN
10133+
INSERT
10134+
#x WITH(TABLOCK)
10135+
(
10136+
x
10137+
)
10138+
SELECT
10139+
x =
10140+
CONVERT
10141+
(
10142+
xml,
10143+
t.target_data
10144+
)
10145+
FROM sys.dm_xe_session_targets AS t
10146+
JOIN sys.dm_xe_sessions AS s
10147+
ON s.address = t.event_session_address
10148+
WHERE s.name = @event_type_check
10149+
AND t.target_name = N'ring_buffer';
10150+
END;
10151+
ELSE
10152+
BEGIN
10153+
INSERT
10154+
#x WITH(TABLOCK)
10155+
(
10156+
x
10157+
)
10158+
SELECT
10159+
x =
10160+
CONVERT
10161+
(
10162+
xml,
10163+
t.target_data
10164+
)
10165+
FROM sys.dm_xe_database_session_targets AS t
10166+
JOIN sys.dm_xe_database_sessions AS s
10167+
ON s.address = t.event_session_address
10168+
WHERE s.name = @event_type_check
10169+
AND t.target_name = N'ring_buffer';
10170+
END;
10171+
END;
10172+
ELSE IF LOWER(@target_output) = N'event_file'
1007210173
BEGIN
10174+
/*
10175+
Read from event file target
10176+
Azure SQL Database and Managed Instance are not supported for event_file
10177+
*/
1007310178
INSERT
1007410179
#x WITH(TABLOCK)
1007510180
(
@@ -10080,46 +10185,49 @@ ORDER BY
1008010185
CONVERT
1008110186
(
1008210187
xml,
10083-
t.target_data
10188+
f.event_data
1008410189
)
10085-
FROM sys.dm_xe_session_targets AS t
10086-
JOIN sys.dm_xe_sessions AS s
10087-
ON s.address = t.event_session_address
10088-
WHERE s.name = @event_type_check
10089-
AND t.target_name = N'ring_buffer';
10190+
FROM sys.fn_xe_file_target_read_file
10191+
(
10192+
@event_type_check + N'*.xel',
10193+
NULL,
10194+
NULL,
10195+
NULL
10196+
) AS f;
1009010197
END;
10091-
ELSE
10198+
10199+
/*
10200+
Parse XML events based on target output type
10201+
ring_buffer wraps events in RingBufferTarget node, event_file does not
10202+
*/
10203+
IF LOWER(@target_output) = N'ring_buffer'
1009210204
BEGIN
1009310205
INSERT
10094-
#x WITH(TABLOCK)
10206+
#human_events_xml_internal WITH(TABLOCK)
1009510207
(
10096-
x
10208+
human_events_xml
1009710209
)
1009810210
SELECT
10099-
x =
10100-
CONVERT
10101-
(
10102-
xml,
10103-
t.target_data
10104-
)
10105-
FROM sys.dm_xe_database_session_targets AS t
10106-
JOIN sys.dm_xe_database_sessions AS s
10107-
ON s.address = t.event_session_address
10108-
WHERE s.name = @event_type_check
10109-
AND t.target_name = N'ring_buffer';
10211+
human_events_xml =
10212+
e.x.query('.')
10213+
FROM #x AS x
10214+
CROSS APPLY x.x.nodes('/RingBufferTarget/event') AS e(x)
10215+
WHERE e.x.exist('@timestamp[. > sql:variable("@date_filter")]') = 1;
10216+
END;
10217+
ELSE IF LOWER(@target_output) = N'event_file'
10218+
BEGIN
10219+
INSERT
10220+
#human_events_xml_internal WITH(TABLOCK)
10221+
(
10222+
human_events_xml
10223+
)
10224+
SELECT
10225+
human_events_xml =
10226+
e.x.query('.')
10227+
FROM #x AS x
10228+
CROSS APPLY x.x.nodes('/event') AS e(x)
10229+
WHERE e.x.exist('@timestamp[. > sql:variable("@date_filter")]') = 1;
1011010230
END;
10111-
10112-
INSERT
10113-
#human_events_xml_internal WITH(TABLOCK)
10114-
(
10115-
human_events_xml
10116-
)
10117-
SELECT
10118-
human_events_xml =
10119-
e.x.query('.')
10120-
FROM #x AS x
10121-
CROSS APPLY x.x.nodes('/RingBufferTarget/event') AS e(x)
10122-
WHERE e.x.exist('@timestamp[. > sql:variable("@date_filter")]') = 1;
1012310231

1012410232
IF @debug = 1
1012510233
BEGIN

0 commit comments

Comments
 (0)