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.

100 lines
2.1 KiB

  1. --
  2. -- convert dec to hex string
  3. --
  4. CREATE PROCEDURE #Dec2hex
  5. @stHex nvarchar(8) OUTPUT,
  6. @iDec bigint
  7. AS
  8. DECLARE @iDigit int
  9. SET @stHex = ""
  10. IF @iDec < 0
  11. SET @iDec = 0xFFFFFFFF + @iDec + 1
  12. WHILE @iDec <> 0
  13. BEGIN
  14. SET @iDigit = @iDec % 16
  15. SET @iDec = @iDec / 16
  16. IF @iDigit < 10
  17. SET @stHex = @stHex + CAST(@iDigit AS nvarchar(1))
  18. ELSE
  19. SET @stHex = @stHex + CHAR(ASCII('A') + @iDigit - 10)
  20. END
  21. SET @stHex = REVERSE(@stHex)
  22. RETURN
  23. GO
  24. --
  25. -- convert error code to winerror
  26. --
  27. CREATE PROCEDURE #Dec2Error
  28. @iDec bigint,
  29. @stHex nvarchar(8) OUTPUT,
  30. @stError nvarchar (32) OUTPUT
  31. AS
  32. CREATE Table #CmdOutput
  33. (
  34. TEXT nvarchar(80)
  35. )
  36. EXEC #Dec2hex @stHex OUTPUT, @iDec
  37. DECLARE @stCmdLine nvarchar(80)
  38. SET @stCmdLine = "winerror"
  39. DECLARE @bStatus bit
  40. SET @bStatus = 0
  41. IF @iDec < 0 AND @iDec > -1073741824
  42. BEGIN
  43. SET @bStatus = 1
  44. SET @stCmdLine = @stCmdLine + " " + "-s"
  45. END
  46. SET @stCmdLine = @stCmdLine + " 0x" + @stHex
  47. INSERT INTO #CmdOutput EXEC master.dbo.xp_cmdshell @stCmdLine
  48. DECLARE @stText nvarchar (80)
  49. DECLARE WinerrorCursor CURSOR FOR
  50. SELECT TEXT FROM #CmdOutput
  51. OPEN WinerrorCursor
  52. FETCH NEXT FROM WinerrorCursor
  53. INTO @stText
  54. IF @@FETCH_STATUS = 0
  55. BEGIN
  56. SET @stText = LTRIM(@stText)
  57. -- skip decimal value
  58. DECLARE @iPos int, @iStart int
  59. SET @iPos = CHARINDEX(" ", @stText, 0)
  60. -- read in windows error text
  61. SET @iStart = @iPos + 1
  62. SET @iPos = CHARINDEX(" ", @stText, @iStart)
  63. IF @bStatus = 0
  64. SET @stError = SUBSTRING(@stText, @iStart, @iPos - @iStart)
  65. -- skip '<-->'
  66. SET @iStart = @iPos + 1
  67. SET @iPos = CHARINDEX(" ", @stText, @iStart)
  68. -- skip hex value
  69. SET @iStart = @iPos + 1
  70. SET @iPos = CHARINDEX(" ", @stText, @iStart)
  71. -- read in ntstatus
  72. SET @iStart = @iPos + 1
  73. SET @iPos = LEN(@stText)
  74. IF @bStatus = 1
  75. SET @stError = SUBSTRING(@stText, @iStart, @iPos - @iStart + 1)
  76. IF @stError = "No"
  77. SET @stError = @stHex
  78. END
  79. GO