PlotDirector/PlotLine/Sql/201_UserToolbarPreferences.sql

27 lines
976 B
Transact-SQL

SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
-- NULL follows current defaults. JSON array order is display order; absent keys are disabled.
-- Lives on the existing account so hard account deletion needs no extra cleanup.
IF COL_LENGTH(N'dbo.AppUser', N'ToolbarCommandKeysJson') IS NULL
ALTER TABLE dbo.AppUser ADD ToolbarCommandKeysJson nvarchar(max) NULL;
GO
CREATE OR ALTER PROCEDURE dbo.UserToolbar_Get @UserID int
AS
BEGIN
SET NOCOUNT ON;
SELECT ToolbarCommandKeysJson FROM dbo.AppUser WHERE UserID = @UserID;
END;
GO
CREATE OR ALTER PROCEDURE dbo.UserToolbar_Save @UserID int, @CommandKeysJson nvarchar(max) = NULL
AS
BEGIN
SET NOCOUNT ON;
IF @CommandKeysJson IS NOT NULL AND ISJSON(@CommandKeysJson, ARRAY) <> 1
THROW 50001, 'Toolbar preferences must be a JSON array.', 1;
UPDATE dbo.AppUser SET ToolbarCommandKeysJson = @CommandKeysJson WHERE UserID = @UserID;
IF @@ROWCOUNT <> 1 THROW 50002, 'Account not found.', 1;
END;
GO