Stored Procedure for synchronous updating of four user information _ MySQL

Source: Internet
Author: User
It is not practical. the reason for writing is the requirement of the leader. I am also familiar with writing code. there is no harm in writing more code. after writing it, I found that the temporary table is quite easy to use, when the data volume is small, the temporary table speed cannot be displayed. the code is as follows: SETQUOTED_IDENTIFIERONGOSETANSI_NULLSONGO * Name: the four-person data in the game is not practical at the same time. the reason for writing is the requirement of the leader. Also, you are familiar with writing code. there is no harm in writing, it is also easy to use temporary tables after writing. when the data volume is small, it does not show that the temporary table speed is not good.

The code is as follows:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*
Name: The four-person data in the game is updated simultaneously.
Designed By: whbo
Designed At: 2005-10-12
Modified:
Modified:
Memo:
*/

Alter proc [PrMoney_UpdateCash2]
@ ChvModeName varchar (16 ),
@ ChvSourceName varchar (64 ),
@ ChvRemark varchar (128 ),
@ IntUserID1 int,
@ IntUserID2 int,
@ IntUserID3 int,
@ IntUserID4 int,
@ IntWantedAmount1 int,
@ IntWantedAmount2 int,
@ IntWantedAmount3 int,
@ IntWantedAmount4 int,
@ ChvIPAddress1 varchar (15 ),
@ ChvIPAddress2 varchar (15 ),
@ ChvIPAddress3 varchar (15 ),
@ ChvIPAddress4 varchar (15 ),
@ InyLog tinyint
As
Set nocount on
Set xact_abort on
Declare @ intCashAmount1 int, @ intCashAmount2 int, @ intCashAmount3 int, @ intCashAmount4 int
Declare @ FRate float, @ FTemp float
Declare @ bNeedReCalc bit -- 0: no re-calculation required; 1: re-calculation required
Set @ FRate = 1.0.
Set @ FTemp = 1.0
Set @ bNeedReCalc = 0
Declare @ FTemp1 float, @ FTemp2 float, @ FTemp3 float, @ FTemp4 float

-- Note that updating users' cash to retrieve data from the database is consistent with the game server.
-- Get users' cash
Select @ intCashAmount1 = [Amount] from [dbo]. [Money] where [UserID] = @ intUserID1
Select @ intCashAmount2 = [Amount] from [dbo]. [Money] where [UserID] = @ intUserID2
Select @ intCashAmount3 = [Amount] from [dbo]. [Money] where [UserID] = @ intUserID3
Select @ intCashAmount4 = [Amount] from [dbo]. [Money] where [UserID] = @ intUserID4

Create Table # Temp1 (TTemp float)

If @ intCashAmount1 @ intWantedAmount1 <0
Begin
Set @ FTemp =-@ intCashAmount1/@ intWantedAmount1
Insert into # temp1 values (@ FTemp)
End


If @ intCashAmount2 @ intWantedAmount2 <0
Begin
Set @ FTemp =-@ intCashAmount2/@ intWantedAmount2
Insert into # temp1 values (@ FTemp)
End

If @ intCashAmount3 @ intWantedAmount3 <0
Begin
Set @ FTemp =-@ intCashAmount3/@ intWantedAmount3
Insert into # temp1 values (@ FTemp)
End

If @ intCashAmount4 @ intWantedAmount4 <0
Begin
Set @ FTemp =-@ intCashAmount4/@ intWantedAmount4
Insert into # temp1 values (@ FTemp)
End

Set @ FTemp = (select min (@ FTemp) from # temp)
Drop table # temp1

If @ FTemp <@ FRate
Begin
Set @ FRate = @ FTemp
Set @ BNeedReCalc = 1
End

If @ BNeedReCalc = 1
Begin
Set @ intWantedAmount1 = @ intWantedAmount1 * @ FRate
Set @ intWantedAmount2 = @ intWantedAmount2 * @ FRate
Set @ intWantedAmount3 = @ intWantedAmount3 * @ FRate
Set @ intWantedAmount4 = @ intWantedAmount4 * @ FRate
End

Begin tran
Exec [prMoney_UpdateCash]
@ ChvModeName: the method used, such as 'web' and 'gameserver '.
@ ChvSourceName: source of the method, such as 'gold coin mahjong server' and 'virtual stocks '.
@ ChvRemark, -- comment on other information.
@ IntUserID1, -- user ID
0, -- related user ID
@ IntWantedAmount1, -- number of updates to be updated (> 0 gold, <0 gold)
0, -- tax (tax> 0, to be deducted from cash, the game server can be set to 0)
@ ChvIPAddress1, -- IP address
0, -- machine code
1 -- whether to perform Log. if it is greater than 0, Log is performed. otherwise, Log is not performed.

Exec [prMoney_UpdateCash]
@ ChvModeName: the method used, such as 'web' and 'gameserver '.
@ ChvSourceName: source of the method, such as 'gold coin mahjong server' and 'virtual stocks '.
@ ChvRemark, -- comment on other information.
@ IntUserID2, -- user ID
0, -- related user ID
@ IntWantedAmount2, -- number of updates to be updated (> 0 gold, <0 gold)
0, -- tax (tax> 0, to be deducted from cash, the game server can be set to 0)
@ ChvIPAddress2, -- IP address
0, -- machine code
1 -- whether to perform Log. if it is greater than 0, Log is performed. otherwise, Log is not performed.

Exec [prMoney_UpdateCash]
@ ChvModeName: the method used, such as 'web' and 'gameserver '.
@ ChvSourceName: source of the method, such as 'gold coin mahjong server' and 'virtual stocks '.
@ ChvRemark, -- comment on other information.
@ IntUserID3, -- user ID
0, -- related user ID
@ IntWantedAmount3, -- number of updates to be updated (> 0 plus gold, <0 deducted Gold)
0, -- tax (tax> 0, to be deducted from cash, the game server can be set to 0)
@ ChvIPAddress3, -- IP address
0, -- machine code
1 -- whether to perform Log. if it is greater than 0, Log is performed. otherwise, Log is not performed.
Exec [prMoney_UpdateCash]
@ ChvModeName: the method used, such as 'web' and 'gameserver '.
@ ChvSourceName: source of the method, such as 'gold coin mahjong server' and 'virtual stocks '.
@ ChvRemark, -- comment on other information.
@ IntUserID4, -- user ID
0, -- related user ID
@ IntWantedAmount4, -- number of updates to be updated (> 0 gold, <0 gold)
0, -- tax (tax> 0, to be deducted from cash, the game server can be set to 0)
@ ChvIPAddress4, -- IP address
0, -- machine code
1 -- whether to perform Log. if it is greater than 0, Log is performed. otherwise, Log is not performed.
Commit tran
Return 1


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.