📄 cs_1.0_to_1.1_upgrade.sql
字号:
@ApplicationName NVARCHAR(256),
@UserName NVARCHAR(256),
@TimeZoneAdjustment INT
AS
BEGIN
DECLARE @UserId UNIQUEIDENTIFIER
SELECT @UserId = NULL
SELECT @UserId = u.UserId
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u, dbo.aspnet_Applications a
WHERE LoweredUserName = LOWER(@UserName) AND
u.ApplicationId = a.ApplicationId AND
LOWER(@ApplicationName) = a.LoweredApplicationName AND
u.UserId = m.UserId
IF (@UserId IS NULL)
BEGIN
RETURN
END
DECLARE @TranStarted BIT
SET @TranStarted = 0
IF( @@TRANCOUNT = 0 )
BEGIN
BEGIN TRANSACTION
SET @TranStarted = 1
END
ELSE
SET @TranStarted = 0
DECLARE @DateTimeNowUTC DATETIME
EXEC dbo.aspnet_GetUtcDate @TimeZoneAdjustment, @DateTimeNowUTC OUTPUT
UPDATE dbo.aspnet_Membership
SET LastLoginDate = @DateTimeNowUTC
WHERE UserId = @UserId
IF( @@ERROR <> 0 )
GOTO Cleanup
UPDATE dbo.aspnet_Users
SET LastActivityDate = @DateTimeNowUTC
WHERE @UserId = UserId
IF( @@ERROR <> 0 )
GOTO Cleanup
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
COMMIT TRANSACTION
END
RETURN
Cleanup:
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
ROLLBACK TRANSACTION
END
RETURN -1
END
GO
PRINT N'Altering [dbo].[aspnet_Profile_GetProfiles]'
GO
ALTER PROCEDURE dbo.aspnet_Profile_GetProfiles
@ApplicationName NVARCHAR(256),
@ProfileAuthOptions INT,
@PageIndex INT,
@PageSize INT,
@TimeZoneAdjustment INT,
@UserNameToMatch NVARCHAR(256) = NULL,
@InactiveSinceDate DATETIME = NULL
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN
IF ((NOT(@InactiveSinceDate IS NULL)) AND (@InactiveSinceDate > CONVERT(DATETIME, '17540101', 112)) AND (@InactiveSinceDate < CONVERT(DATETIME, '99980101', 112)))
SELECT @InactiveSinceDate = DATEADD(n, -@TimeZoneAdjustment, @InactiveSinceDate)
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
DECLARE @TotalRecords INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId UNIQUEIDENTIFIER
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT u.UserId
FROM dbo.aspnet_Users u, dbo.aspnet_Profile p
WHERE ApplicationId = @ApplicationId
AND u.UserId = p.UserId
AND (@InactiveSinceDate IS NULL OR LastActivityDate <= @InactiveSinceDate)
AND ( (@ProfileAuthOptions = 2)
OR (@ProfileAuthOptions = 0 AND IsAnonymous = 1)
OR (@ProfileAuthOptions = 1 AND IsAnonymous = 0)
)
AND (@UserNameToMatch IS NULL OR LoweredUserName LIKE LOWER(@UserNameToMatch))
ORDER BY UserName
SELECT u.UserName, u.IsAnonymous, u.LastActivityDate, p.LastUpdatedDate,
DATALENGTH(p.PropertyNames) + DATALENGTH(p.PropertyValuesString) + DATALENGTH(p.PropertyValuesBinary)
FROM dbo.aspnet_Users u, dbo.aspnet_Profile p, #PageIndexForUsers i
WHERE u.UserId = p.UserId AND p.UserId = i.UserId AND i.IndexId >= @PageLowerBound AND i.IndexId <= @PageUpperBound
SELECT COUNT(*)
FROM #PageIndexForUsers
DROP TABLE #PageIndexForUsers
END
GO
PRINT N'Altering [dbo].[aspnet_Membership_FindUsersByName]'
GO
ALTER PROCEDURE dbo.aspnet_Membership_FindUsersByName
@ApplicationName NVARCHAR(256),
@UserNameToMatch NVARCHAR(256),
@PageIndex INT,
@PageSize INT
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN 0
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
DECLARE @TotalRecords INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId UNIQUEIDENTIFIER
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT u.UserId
FROM dbo.aspnet_Users u, dbo.aspnet_Membership m
WHERE u.ApplicationId = @ApplicationId AND m.UserId = u.UserId AND u.LoweredUserName LIKE LOWER(@UserNameToMatch)
ORDER BY u.UserName
SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
m.CreateDate,
m.LastLoginDate,
u.LastActivityDate,
m.LastPasswordChangedDate,
u.UserId, m.IsLockedOut,
m.LastLockoutDate
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
WHERE u.UserId = p.UserId AND u.UserId = m.UserId AND
p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY u.UserName
SELECT @TotalRecords = COUNT(*)
FROM #PageIndexForUsers
RETURN @TotalRecords
END
GO
PRINT N'Altering [dbo].[aspnet_Membership_GetAllUsers]'
GO
ALTER PROCEDURE dbo.aspnet_Membership_GetAllUsers
@ApplicationName NVARCHAR(256),
@PageIndex INT,
@PageSize INT
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN 0
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
DECLARE @TotalRecords INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId UNIQUEIDENTIFIER
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT u.UserId
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u
WHERE u.ApplicationId = @ApplicationId AND u.UserId = m.UserId
ORDER BY u.UserName
SELECT @TotalRecords = @@ROWCOUNT
SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
m.CreateDate,
m.LastLoginDate,
u.LastActivityDate,
m.LastPasswordChangedDate,
u.UserId, m.IsLockedOut,
m.LastLockoutDate
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
WHERE u.UserId = p.UserId AND u.UserId = m.UserId AND
p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY u.UserName
RETURN @TotalRecords
END
GO
PRINT N'Altering [dbo].[vw_aspnet_MembershipUsers]'
GO
ALTER VIEW [dbo].[vw_aspnet_MembershipUsers]
AS SELECT [dbo].[aspnet_Membership].[UserId],
[dbo].[aspnet_Membership].[PasswordFormat],
[dbo].[aspnet_Membership].[MobilePIN],
[dbo].[aspnet_Membership].[Email],
[dbo].[aspnet_Membership].[LoweredEmail],
[dbo].[aspnet_Membership].[PasswordQuestion],
[dbo].[aspnet_Membership].[PasswordAnswer],
[dbo].[aspnet_Membership].[IsApproved],
[dbo].[aspnet_Membership].[IsLockedOut],
[dbo].[aspnet_Membership].[CreateDate],
[dbo].[aspnet_Membership].[LastLoginDate],
[dbo].[aspnet_Membership].[LastPasswordChangedDate],
[dbo].[aspnet_Membership].[LastLockoutDate],
[dbo].[aspnet_Membership].[FailedPasswordAttemptCount],
[dbo].[aspnet_Membership].[FailedPasswordAttemptWindowStart],
[dbo].[aspnet_Membership].[FailedPasswordAnswerAttemptCount],
[dbo].[aspnet_Membership].[FailedPasswordAnswerAttemptWindowStart],
[dbo].[aspnet_Membership].[Comment],
[dbo].[aspnet_Users].[ApplicationId],
[dbo].[aspnet_Users].[UserName],
[dbo].[aspnet_Users].[MobileAlias],
[dbo].[aspnet_Users].[IsAnonymous],
[dbo].[aspnet_Users].[LastActivityDate]
FROM [dbo].[aspnet_Membership] INNER JOIN [dbo].[aspnet_Users]
ON [dbo].[aspnet_Membership].[UserId] = [dbo].[aspnet_Users].[UserId]
GO
PRINT N'Altering [dbo].[aspnet_Membership_GetPassword]'
GO
ALTER PROCEDURE dbo.aspnet_Membership_GetPassword
@ApplicationName NVARCHAR(256),
@UserName NVARCHAR(256),
@MaxInvalidPasswordAttempts INT,
@PasswordAttemptWindow INT,
@TimeZoneAdjustment INT,
@PasswordAnswer NVARCHAR(128) = NULL
AS
BEGIN
DECLARE @UserId UNIQUEIDENTIFIER
DECLARE @PasswordFormat INT
DECLARE @Password NVARCHAR(128)
DECLARE @passAns NVARCHAR(128)
DECLARE @IsLockedOut BIT
DECLARE @LastLockoutDate DATETIME
DECLARE @FailedPasswordAttemptCount INT
DECLARE @FailedPasswordAttemptWindowStart DATETIME
DECLARE @FailedPasswordAnswerAttemptCount INT
DECLARE @FailedPasswordAnswerAttemptWindowStart DATETIME
DECLARE @ErrorCode INT
SET @ErrorCode = 0
DECLARE @TranStarted BIT
SET @TranStarted = 0
IF( @@TRANCOUNT = 0 )
BEGIN
BEGIN TRANSACTION
SET @TranStarted = 1
END
ELSE
SET @TranStarted = 0
DECLARE @DateTimeNowUTC DATETIME
EXEC dbo.aspnet_GetUtcDate @TimeZoneAdjustment, @DateTimeNowUTC OUTPUT
SELECT @UserId = u.UserId,
@Password = m.Password,
@passAns = m.PasswordAnswer,
@PasswordFormat = m.PasswordFormat,
@IsLockedOut = m.IsLockedOut,
@LastLockoutDate = m.LastLockoutDate,
@FailedPasswordAttemptCount = m.FailedPasswordAttemptCount,
@FailedPasswordAttemptWindowStart = m.FailedPasswordAttemptWindowStart,
@FailedPasswordAnswerAttemptCount = m.FailedPasswordAnswerAttemptCount,
@FailedPasswordAnswerAttemptWindowStart = m.FailedPasswordAnswerAttemptWindowStart
FROM dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m WITH ( UPDLOCK )
WHERE LOWER(@ApplicationName) = a.LoweredApplicationName AND
u.ApplicationId = a.ApplicationId AND
u.UserId = m.UserId AND
LOWER(@UserName) = u.LoweredUserName
IF ( @@rowcount = 0 )
BEGIN
SET @ErrorCode = 1
GOTO Cleanup
END
IF( @IsLockedOut = 1 )
BEGIN
SET @ErrorCode = 99
GOTO Cleanup
END
IF ( NOT( @PasswordAnswer IS NULL ) )
BEGIN
IF( ( @passAns IS NULL ) OR ( LOWER( @passAns ) <> LOWER( @PasswordAnswer ) ) )
BEGIN
IF( @DateTimeNowUTC > DATEADD( minute, @PasswordAttemptWindow, @FailedPasswordAnswerAttemptWindowStart ) )
BEGIN
SET @FailedPasswordAnswerAttemptWindowStart = @DateTimeNowUTC
SET @FailedPasswordAnswerAttemptCount = 1
END
ELSE
BEGIN
SET @FailedPasswordAnswerAttemptCount = @FailedPasswordAnswerAttemptCount + 1
SET @FailedPasswordAnswerAttemptWindowStart = @DateTimeNowUTC
END
BEGIN
IF( @FailedPasswordAnswerAttemptCount >= @MaxInvalidPasswordAttempts )
BEGIN
SET @IsLockedOut = 1
SET @LastLockoutDate = @DateTimeNowUTC
END
END
SET @ErrorCode = 3
END
ELSE
BEGIN
IF( @FailedPasswordAnswerAttemptCount > 0 )
BEGIN
SET @FailedPasswordAnswerAttemptCount = 0
SET @FailedPasswordAnswerAttemptWindowStart = CONVERT( DATETIME, '17540101', 112 )
END
END
UPDATE dbo.aspnet_Membership
SET IsLockedOut = @IsLockedOut, LastLockoutDate = @LastLockoutDate,
FailedPasswordAttemptCount = @FailedPasswordAttemptCount,
FailedPasswordAttemptWindowStart = @FailedPasswordAttemptWindowStart,
FailedPasswordAnswerAttemptCount = @FailedPasswordAnswerAttemptCount,
FailedPasswordAnswerAttemptWindowStart = @FailedPasswordAnswerAttemptWindowStart
WHERE @UserId = UserId
IF( @@ERROR <> 0 )
BEGIN
SET @ErrorCode = -1
GOTO Cleanup
END
END
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
COMMIT TRANSACTION
END
IF( @ErrorCode = 0 )
SELECT @Password, @PasswordFormat
RETURN @ErrorCode
Cleanup:
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -