Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
2.5 KiB

  1. IF EXISTS (
  2. SELECT * FROM dbo.sysobjects
  3. WHERE (
  4. id = OBJECT_ID('dbo.event_data') AND
  5. OBJECTPROPERTY(id, 'IsUserTable') = 1
  6. )
  7. )
  8. DROP TABLE dbo.event_data
  9. IF EXISTS (
  10. SELECT * FROM dbo.sysobjects
  11. WHERE (
  12. id = OBJECT_ID('dbo.event_main') AND
  13. OBJECTPROPERTY(id, 'IsUserTable') = 1
  14. )
  15. )
  16. DROP TABLE dbo.event_main
  17. IF EXISTS (
  18. SELECT * FROM dbo.sysobjects
  19. WHERE (
  20. id = OBJECT_ID('dbo.event_data_type') AND
  21. OBJECTPROPERTY(id, 'IsUserTable') = 1
  22. )
  23. )
  24. DROP TABLE dbo.event_data_type
  25. IF EXISTS (
  26. SELECT * FROM dbo.sysobjects
  27. WHERE (
  28. id = OBJECT_ID('dbo.report_event') AND
  29. OBJECTPROPERTY(id, 'IsProcedure') = 1
  30. )
  31. )
  32. DROP PROCEDURE dbo.report_event
  33. GO
  34. CREATE TABLE dbo.event_main (
  35. event_id uniqueidentifier NOT NULL
  36. PRIMARY KEY CLUSTERED,
  37. record_timestamp datetime NOT NULL
  38. )
  39. GO
  40. CREATE TABLE dbo.event_data_type (
  41. attribute_data_type tinyint NOT NULL
  42. PRIMARY KEY CLUSTERED,
  43. attribute_data_type_name nvarchar (128) NOT NULL
  44. )
  45. GO
  46. CREATE TABLE dbo.event_data (
  47. event_id uniqueidentifier NOT NULL
  48. REFERENCES event_main (event_id)
  49. ON UPDATE CASCADE
  50. ON DELETE CASCADE,
  51. attribute_type nvarchar (64) NOT NULL,
  52. attribute_value nvarchar (1024) NULL,
  53. attribute_data_type tinyint NOT NULL
  54. FOREIGN KEY REFERENCES event_data_type (attribute_data_type)
  55. )
  56. GO
  57. INSERT INTO dbo.event_data_type
  58. VALUES (0, 'nonNegativeInteger')
  59. INSERT INTO dbo.event_data_type
  60. VALUES (1, 'string')
  61. INSERT INTO dbo.event_data_type
  62. VALUES (2, 'hexBinary')
  63. INSERT INTO dbo.event_data_type
  64. VALUES (3, 'ipv4Address')
  65. INSERT INTO dbo.event_data_type
  66. VALUES (4, 'sqlDateTime')
  67. GO
  68. CREATE PROCEDURE dbo.report_event
  69. @doc ntext
  70. AS
  71. SET NOCOUNT ON
  72. DECLARE @idoc int
  73. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
  74. DECLARE @event_id uniqueidentifier
  75. SET @event_id = NEWID()
  76. DECLARE @record_timestamp datetime
  77. SET @record_timestamp = GETUTCDATE()
  78. BEGIN TRANSACTION
  79. INSERT dbo.event_main VALUES (
  80. @event_id,
  81. @record_timestamp
  82. )
  83. INSERT dbo.event_data
  84. SELECT
  85. @event_id,
  86. attribute_type,
  87. attribute_value,
  88. attribute_data_type
  89. FROM OPENXML(@idoc, '/Event/*')
  90. WITH (
  91. attribute_type nvarchar(64) '@mp:localname',
  92. attribute_value nvarchar(1024) 'child::text()',
  93. attribute_data_type tinyint '@data_type'
  94. )
  95. COMMIT TRANSACTION
  96. EXEC sp_xml_removedocument @idoc
  97. GO