cs_Favorite_Add
ALTER PROCEDURE dbo.cs_Favorite_Add
(
@SettingsID int,
@UserID int,
@ItemID int,
@FavoriteType int,
@ApplicationType int,
@FavoriteID int OUTPUT
)
AS
SET NOCOUNT ON
/**//*当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。
当 SET NOCOUNT 为 OFF 时,返回计数。即使当 SET NOCOUNT 为 ON 时,
也更新 @@ROWCOUNT 函数。*/
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
IF @FavoriteType = 1 -- Section (为1时表示关注的类型为版块)
BEGIN
-- Check if favorite already exists, return existing id
--检查是否存在此条关注的记录,返回存在的记录的ID
SELECT @FavoriteID = F.FavoriteID
FROM cs_FavoriteSections F
WHERE OwnerID = @UserID
AND SettingsID = @SettingsID
AND SectionID = @ItemID
AND ApplicationType = @ApplicationType
-- New favorite
--如果不存在,创建新的记录,即新的关注
IF @FavoriteID IS NULL
BEGIN
INSERT INTO cs_FavoriteSections
(OwnerID, SettingsID, SectionID, ApplicationType)
VALUES
(@UserID, @SettingsID, @ItemID, @ApplicationType)
SET @FavoriteID = SCOPE_IDENTITY()
/**//*返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。一个作用域就是一个
模块——存储过程、触发器、函数或批处理。因此,如果两个语句处于同一个存储过程、函
数或批处理中,则它们位于相同的作用域中。*/
END
END
ELSE IF @FavoriteType = 2 -- User (2表示用户,即好友)
BEGIN
-- Check if favorite already exists, return existing id
--检查是否存在,存在返回ID
SELECT @FavoriteID = F.FavoriteID
FROM cs_FavoriteUsers F
WHERE OwnerID = @UserID
AND SettingsID = @SettingsID
AND UserID = @ItemID
AND ApplicationType = @ApplicationType
-- New favorite
--不存在创建新的记录,即添加新的好友
IF @FavoriteID IS NULL
BEGIN
INSERT INTO cs_FavoriteUsers
(OwnerID, SettingsID, UserID, ApplicationType)
VALUES
(@UserID, @SettingsID, @ItemID, @ApplicationType)
SET @FavoriteID = SCOPE_IDENTITY()
END
END
ELSE IF @FavoriteType = 4 -- Post (4表示帖子)
BEGIN
-- Check if favorite already exists, return existing id
--检查是否存在,存在返回ID
SELECT @FavoriteID = F.FavoriteID
FROM cs_FavoritePosts F
WHERE OwnerID = @UserID
AND SettingsID = @SettingsID
AND PostID = @ItemID
AND ApplicationType = @ApplicationType
-- New favorite
-- 不存在则创建新的记录
IF @FavoriteID IS NULL
BEGIN
INSERT INTO cs_FavoritePosts
(OwnerID, SettingsID, PostID, ApplicationType)
VALUES
(@UserID, @SettingsID, @ItemID, @ApplicationType)
SET @FavoriteID = SCOPE_IDENTITY()
END
END
GO
ALTER PROCEDURE dbo.cs_Favorite_Add
(
@SettingsID int,
@UserID int,
@ItemID int,
@FavoriteType int,
@ApplicationType int,
@FavoriteID int OUTPUT
)
AS
SET NOCOUNT ON
/**//*当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。
当 SET NOCOUNT 为 OFF 时,返回计数。即使当 SET NOCOUNT 为 ON 时,
也更新 @@ROWCOUNT 函数。*/
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
IF @FavoriteType = 1 -- Section (为1时表示关注的类型为版块)
BEGIN
-- Check if favorite already exists, return existing id
--检查是否存在此条关注的记录,返回存在的记录的ID
SELECT @FavoriteID = F.FavoriteID
FROM cs_FavoriteSections F
WHERE OwnerID = @UserID
AND SettingsID = @SettingsID
AND SectionID = @ItemID
AND ApplicationType = @ApplicationType
-- New favorite
--如果不存在,创建新的记录,即新的关注
IF @FavoriteID IS NULL
BEGIN
INSERT INTO cs_FavoriteSections
(OwnerID, SettingsID, SectionID, ApplicationType)
VALUES
(@UserID, @SettingsID, @ItemID, @ApplicationType)
SET @FavoriteID = SCOPE_IDENTITY()
/**//*返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。一个作用域就是一个
模块——存储过程、触发器、函数或批处理。因此,如果两个语句处于同一个存储过程、函
数或批处理中,则它们位于相同的作用域中。*/
END
END
ELSE IF @FavoriteType = 2 -- User (2表示用户,即好友)
BEGIN
-- Check if favorite already exists, return existing id
--检查是否存在,存在返回ID
SELECT @FavoriteID = F.FavoriteID
FROM cs_FavoriteUsers F
WHERE OwnerID = @UserID
AND SettingsID = @SettingsID
AND UserID = @ItemID
AND ApplicationType = @ApplicationType
-- New favorite
--不存在创建新的记录,即添加新的好友
IF @FavoriteID IS NULL
BEGIN
INSERT INTO cs_FavoriteUsers
(OwnerID, SettingsID, UserID, ApplicationType)
VALUES
(@UserID, @SettingsID, @ItemID, @ApplicationType)
SET @FavoriteID = SCOPE_IDENTITY()
END
END
ELSE IF @FavoriteType = 4 -- Post (4表示帖子)
BEGIN
-- Check if favorite already exists, return existing id
--检查是否存在,存在返回ID
SELECT @FavoriteID = F.FavoriteID
FROM cs_FavoritePosts F
WHERE OwnerID = @UserID
AND SettingsID = @SettingsID
AND PostID = @ItemID
AND ApplicationType = @ApplicationType
-- New favorite
-- 不存在则创建新的记录
IF @FavoriteID IS NULL
BEGIN
INSERT INTO cs_FavoritePosts
(OwnerID, SettingsID, PostID, ApplicationType)
VALUES
(@UserID, @SettingsID, @ItemID, @ApplicationType)
SET @FavoriteID = SCOPE_IDENTITY()
END
END
GO
cs_Exceptions_Log
ALTER procedure [dbo].cs_Exceptions_Log
(
@SettingsID int,
@ExceptionHash varchar(128),
@Category int,
@Exception nvarchar(2000),
@ExceptionMessage nvarchar(500),
@UserAgent nvarchar(64),
@IPAddress varchar(15),
@HttpReferrer nvarchar (256),
@HttpVerb nvarchar(24),
@PathAndQuery nvarchar(512)
)
AS
BEGIN
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
IF EXISTS (SELECT ExceptionID FROM cs_Exceptions WHERE ExceptionHash = @ExceptionHash and SettingsID = @SettingsID)
/**//*如果存在此事件的ID,则更新此事件的发生频率,即+1,并更新最近发生时间*/
UPDATE
cs_Exceptions
SET
DateLastOccurred = GetDate(),
Frequency = Frequency + 1
WHERE
ExceptionHash = @ExceptionHash and SettingsID = @SettingsID
ELSE ---不存在则插入新的异常事件
INSERT INTO
cs_Exceptions
(
ExceptionHash,
SettingsID,
Category,
Exception,
ExceptionMessage,
UserAgent,
IPAddress,
HttpReferrer,
HttpVerb,
PathAndQuery,
DateCreated,
DateLastOccurred,
Frequency
)
VALUES
(
@ExceptionHash,
@SettingsID,
@Category,
@Exception,
@ExceptionMessage,
@UserAgent,
@IPAddress,
@HttpReferrer,
@HttpVerb,
@PathAndQuery,
GetDate(),
GetDate(),
1
)
END
ALTER procedure [dbo].cs_Exceptions_Log
(
@SettingsID int,
@ExceptionHash varchar(128),
@Category int,
@Exception nvarchar(2000),
@ExceptionMessage nvarchar(500),
@UserAgent nvarchar(64),
@IPAddress varchar(15),
@HttpReferrer nvarchar (256),
@HttpVerb nvarchar(24),
@PathAndQuery nvarchar(512)
)
AS
BEGIN
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
IF EXISTS (SELECT ExceptionID FROM cs_Exceptions WHERE ExceptionHash = @ExceptionHash and SettingsID = @SettingsID)
/**//*如果存在此事件的ID,则更新此事件的发生频率,即+1,并更新最近发生时间*/
UPDATE
cs_Exceptions
SET
DateLastOccurred = GetDate(),
Frequency = Frequency + 1
WHERE
ExceptionHash = @ExceptionHash and SettingsID = @SettingsID
ELSE ---不存在则插入新的异常事件
INSERT INTO
cs_Exceptions
(
ExceptionHash,
SettingsID,
Category,
Exception,
ExceptionMessage,
UserAgent,
IPAddress,
HttpReferrer,
HttpVerb,
PathAndQuery,
DateCreated,
DateLastOccurred,
Frequency
)
VALUES
(
@ExceptionHash,
@SettingsID,
@Category,
@Exception,
@ExceptionMessage,
@UserAgent,
@IPAddress,
@HttpReferrer,
@HttpVerb,
@PathAndQuery,
GetDate(),
GetDate(),
1
)
END