SHARE
TWEET

Untitled

a guest Mar 18th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. USE [SRO_VT_ACCOUNT]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[_WebPurchaseSilk] ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. /**
  10. version : 1
  11. author : Syloxx
  12. created date: 2017-19-03
  13. description : add silk to user after purchase.
  14. return value :
  15. 0 = No Errors
  16. 100 = Unknown Error
  17. **/
  18.  
  19. ALTER PROCEDURE [dbo].[_WebPurchaseSilk]
  20.       @UserJID INT
  21.     , @PurchasedSilk INT
  22. AS
  23. SET NOCOUNT ON
  24. SET XACT_ABORT ON
  25.  
  26. DECLARE   @ReturnValue INT
  27.     , @NewSilkQuantity INT
  28.  
  29. /**_# Rollback and return if inside an uncommittable transaction.*/
  30. IF XACT_STATE() = -1
  31. BEGIN
  32.     SET @ReturnValue = 1
  33.     GOTO ErrorHandler
  34. END
  35.  
  36. BEGIN TRY
  37.     BEGIN TRANSACTION
  38.  
  39.     IF NOT EXISTS (SELECT * FROM SK_Silk WHERE JID = @UserJID)
  40.     BEGIN
  41.         INSERT SK_Silk
  42.         VALUES (@UserJID, @PurchasedSilk, 0, 0)
  43.  
  44.         SET @NewSilkQuantity = @PurchasedSilk
  45.     END
  46.     ELSE
  47.     BEGIN
  48.         UPDATE SK_Silk
  49.         SET silk_own += @PurchasedSilk
  50.         WHERE JID = @UserJID
  51.  
  52.         SELECT @NewSilkQuantity = silk_own + @PurchasedSilk
  53.         FROM SK_Silk
  54.         WHERE JID = @UserJID
  55.     END
  56.  
  57.     INSERT SK_SilkChange_BY_Web
  58.     VALUES (@UserJID, @NewSilkQuantity, @PurchasedSilk, 0, 0)
  59.  
  60.     COMMIT TRANSACTION
  61. END TRY
  62. BEGIN CATCH
  63.     SET @ReturnValue = 100
  64.     GOTO ErrorHandler
  65. END CATCH
  66.  
  67. RETURN 0
  68.  
  69. ErrorHandler:
  70. IF XACT_STATE() <> 0
  71.     ROLLBACK TRANSACTION
  72.     RETURN @ReturnValue
RAW Paste Data
Top