(SQL Server) Validate a ULID
Checks to see if a ULID is valid.
Important: Chilkat's ULID functionality was introduced in v9.5.0.94.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @dt int
-- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- A ULID must be exactly 26 chars in length,
-- and is composed of the following chars: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
-- Note: The ULID alphabet excludes the letters I, L, O, and U
-- Here's a valid ULID
DECLARE @ulid nvarchar(4000)
SELECT @ulid = '01GRGCH4J88RECEN4D4VK4F629'
DECLARE @valid int
EXEC sp_OAMethod @dt, 'UlidValidate', @valid OUT, @ulid
PRINT 'valid: ' + @valid
-- Here's an invalid ULID
SELECT @ulid = '71GRGxx4Jr8RECEN4D4VK4F62!'
EXEC sp_OAMethod @dt, 'UlidValidate', @valid OUT, @ulid
PRINT 'valid: ' + @valid
EXEC @hr = sp_OADestroy @dt
END
GO
|