#wip(sql): Building SQL Server service.
This commit is contained in:
parent
0ef7dc7350
commit
fadc810390
@ -547,59 +547,58 @@ create procedure dbo.get_range(
|
||||
@integer integer output,
|
||||
@from smallint,
|
||||
@bits smallint
|
||||
) begin set nocount on
|
||||
if @string is not null begin
|
||||
) as begin set nocount on
|
||||
|
||||
execute dbo.get_from_bits @string, @integer, @from output, @bits output
|
||||
|
||||
if bits = 0 set bits = dbo.get_bits(@string, @integer) - @from
|
||||
if bits > 0 begin
|
||||
if @string is not null begin
|
||||
|
||||
if @bits = 0 set @bits = dbo.get_bits(@string, @integer) - @from
|
||||
if @bits > 0 begin
|
||||
|
||||
declare @alphabet varchar(128)
|
||||
declare @base smallint
|
||||
declare @power tinyint
|
||||
declare @shift smallint
|
||||
|
||||
select top 1 @alphabet = alphabet, @base = base, @power = power from dbo.Sets where in_use = 1
|
||||
|
||||
if @from > 0 begin
|
||||
|
||||
declare shift smallint = @from % @power
|
||||
declare mask smallint = ~-@base
|
||||
declare @mask smallint = ~-@base
|
||||
|
||||
set @shift = @from % @power
|
||||
set @string = substring(@string, @from / @power + 1, datalength(@string))
|
||||
if @shift != 0 and datalength(@string) > 0 begin
|
||||
|
||||
declare l integer = datalength(@string)
|
||||
declare i integer = 1
|
||||
declare @l integer = datalength(@string)
|
||||
declare @i integer = 1
|
||||
|
||||
while i < l begin
|
||||
while @i < @l begin
|
||||
set @string = (
|
||||
left(@string, i - 1) +
|
||||
left(@string, @i - 1) +
|
||||
substring(@alphabet, ((
|
||||
dbo.shift(charindex(@alphabet, substring(@string, i, 1)), @shift) |
|
||||
dbo.shift(charindex(@alphabet, substring(@string, i + 1, 1)), @power - @shift)
|
||||
dbo.shift(charindex(substring(@string, @i, 1), @alphabet) - 1, @shift) |
|
||||
dbo.shift(charindex(substring(@string, @i + 1, 1), @alphabet) - 1, @power - @shift)
|
||||
) & @mask) + 1, 1) +
|
||||
right(@string, l - i)
|
||||
right(@string, @l - @i)
|
||||
)
|
||||
set i = i + 1
|
||||
set @i = @i + 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
if @bits > 0 begin
|
||||
|
||||
declare @shift smallint = @bits % @power
|
||||
|
||||
set @string = left(@string, ceiling((@from + @bits) / @power))
|
||||
if @shift != 0 and datalength(@string) > 0 begin
|
||||
set @shift = @bits % @power
|
||||
set @string = left(@string, ceiling((@from + @bits) / cast(@power as float)))
|
||||
if @shift != 0 and datalength(@string) > 0
|
||||
set @string = (
|
||||
substring(@string, 1, datalength(@string) - 1) +
|
||||
substring(@alphabet, (
|
||||
dbo.shift(charindex(@alphabet, right(@string, 1)), -@shift) & ~-power(2, @power - @shift)
|
||||
dbo.shift(charindex(right(@string, 1), @alphabet) - 1, -@shift) & ~-cast(power(2, @power - @shift) as integer)
|
||||
) + 1, 1)
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@ -607,15 +606,204 @@ create procedure dbo.get_range(
|
||||
execute dbo.clean @string output, @integer output
|
||||
|
||||
end else if @integer is not null begin
|
||||
|
||||
execute dbo.get_from_bits null, @integer, @from output, @bits output
|
||||
|
||||
if @from > 0 set @code = dbo.shift(@code, @from) & (dbo.shift(1, 31 - @from) - 1)
|
||||
if @bits > 0 || @from < 31 begin
|
||||
if @from > 0 set @integer = dbo.shift(@integer, @from) & (dbo.shift(1, 31 - @from) - 1)
|
||||
if @bits > 0 or @from < 31 begin
|
||||
if @from + @bits > 31 set @bits = 31 - @from
|
||||
set @integer = dbo.shift(@integer, -@from) & (dbo.shift(1, @bits) - 1)
|
||||
end
|
||||
end
|
||||
|
||||
execute dbo.clean @string output, @integer output
|
||||
|
||||
end
|
||||
go
|
||||
|
||||
if object_id(N'dbo.bitwise', N'P') is not null drop procedure dbo.bitwise
|
||||
go
|
||||
create procedure dbo.bitwise(
|
||||
@string varchar(512) output,
|
||||
@integer integer output,
|
||||
@bits smallint
|
||||
) as begin set nocount on
|
||||
|
||||
if @string is not null begin
|
||||
if len(@string) > 0 and @bits != 0 begin
|
||||
|
||||
declare @alphabet varchar(128)
|
||||
declare @base smallint
|
||||
declare @power tinyint
|
||||
declare @shift smallint
|
||||
declare @mask smallint
|
||||
declare @l integer
|
||||
declare @i integer
|
||||
|
||||
select top 1 @alphabet = alphabet, @base = base, @power = power from dbo.Sets where in_use = 1
|
||||
set @shift = abs(@bits) % @power
|
||||
set @mask = ~-@base
|
||||
|
||||
if @bits < 0 begin
|
||||
|
||||
set @string = right(@string, datalength(@string) - (-@bits / @power))
|
||||
|
||||
if @shift != 0 and datalength(@string) > 0 begin
|
||||
|
||||
set @l = datalength(@string) - 1
|
||||
set @i = 1
|
||||
|
||||
while @i <= @l begin
|
||||
set @string = left(@string, @i - 1) + substring(@alphabet, ((
|
||||
dbo.shift(charindex(substring(@string, @i, 1), @alphabet) - 1, -@shift) |
|
||||
dbo.shift(charindex(substring(@string, @i + 1, 1), @alphabet) - 1, @power - @shift)
|
||||
) & @mask) + 1, 1) + right(@string, @l + 1 - @i)
|
||||
set @i = @i + 1
|
||||
end
|
||||
set @string = left(@string, @l) + substring(@alphabet, dbo.shift(charindex(right(@string, 1), @alphabet) - 1, -@shift) + 1, 1)
|
||||
|
||||
end
|
||||
|
||||
end else begin
|
||||
|
||||
declare @length integer = ceiling(@bits / cast(@power as float)) + datalength(@string)
|
||||
declare @character_0 char(1) = substring(@alphabet, 1, 1)
|
||||
|
||||
if @shift != 0 begin
|
||||
|
||||
declare @last_hexa smallint = dbo.shift(charindex(right(@string, 1), @alphabet) - 1, @shift)
|
||||
|
||||
set @l = datalength(@string)
|
||||
set @i = @l
|
||||
|
||||
while @i > 1 begin
|
||||
set @string = left(@string, @i - 1) + substring(@alphabet, ((
|
||||
dbo.shift(charindex(substring(@string, @i, 1), @alphabet) - 1, @shift) |
|
||||
dbo.shift(charindex(substring(@string, @i - 1, 1), @alphabet) - 1, @shift - @power)
|
||||
) & @mask) + 1, 1) + right(@string, @l - @i)
|
||||
set @i = @i - 1
|
||||
end
|
||||
set @string = (
|
||||
substring(@alphabet, (dbo.shift(charindex(substring(@string, 1, 1), @alphabet) - 1, @shift) & @mask) + 1, 1) +
|
||||
right(@string, @l - 1)
|
||||
)
|
||||
|
||||
if @last_hexa >= @base
|
||||
set @string = @string + substring(@alphabet, dbo.shift(@last_hexa, -@power) + 1, 1)
|
||||
|
||||
end
|
||||
|
||||
while len(@string) < @length
|
||||
set @string = @character_0 + @string
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end else if @integer is not null
|
||||
set @integer = dbo.shift(@integer, @bits)
|
||||
|
||||
execute dbo.clean @string output, @integer output
|
||||
|
||||
end
|
||||
go
|
||||
|
||||
if object_id(N'dbo.reset', N'P') is not null drop procedure dbo.reset
|
||||
go
|
||||
create procedure dbo.reset(
|
||||
@string varchar(512) output,
|
||||
@integer integer output,
|
||||
@from smallint,
|
||||
@bits smallint = 0,
|
||||
@reversed bit = 0
|
||||
) as begin set nocount on
|
||||
|
||||
execute dbo.get_from_bits @string, @integer, @from output, @bits output
|
||||
|
||||
if @string is not null begin
|
||||
|
||||
declare @alphabet varchar(128)
|
||||
declare @base smallint
|
||||
declare @power tinyint
|
||||
declare @hexa_from integer
|
||||
declare @hexa_to integer
|
||||
declare @l integer
|
||||
declare @i integer
|
||||
declare @from_mask integer
|
||||
declare @to_mask integer
|
||||
declare @m integer = datalength(@string)
|
||||
declare @character_0 char(1) = substring(@alphabet, 1, 1)
|
||||
|
||||
select top 1 @alphabet = alphabet, @base = base, @power = power from dbo.Sets where in_use = 1
|
||||
set @hexa_from = @from / @power
|
||||
set @hexa_to = (@from + @bits) / @power
|
||||
|
||||
if @reversed = 1 begin
|
||||
|
||||
set @l = @from % @power
|
||||
set @from_mask = ~(dbo.shift(1, @l) - 1)
|
||||
set @to_mask = dbo.shift(1, (@from + @bits) % @power) - 1
|
||||
set @i = 1
|
||||
|
||||
while @i <= @m begin
|
||||
if @i < @hexa_from or @i < @hexa_to
|
||||
set @string = left(@string, @i - 1) + @character_0 + right(@string, @m - @i)
|
||||
set @i = @i + 1
|
||||
end
|
||||
|
||||
if @hexa_from = @hexa_to
|
||||
set @string = (
|
||||
left(@string, @hexa_from - 1) +
|
||||
substring(@alphabet, (@from_mask & @to_mask) + 1, 1) +
|
||||
right(@string, @m - @hexa_from)
|
||||
)
|
||||
else
|
||||
set @string = (
|
||||
left(@string, @hexa_from - 1) +
|
||||
substring(@alphabet, @from_mask + 1, 1) +
|
||||
right(@string, @m - @hexa_from)
|
||||
)
|
||||
if @hexa_to < @m
|
||||
set @string = (
|
||||
left(@string, @hexa_to - 1) +
|
||||
substring(@alphabet, @to_mask + 1, 1) +
|
||||
right(@string, @m - @hexa_to)
|
||||
)
|
||||
|
||||
end else begin
|
||||
|
||||
set @l = (@from + @bits) % @power
|
||||
set @from_mask = dbo.shift(1, @from % @power) - 1
|
||||
set @to_mask = dbo.shift(dbo.shift(1, @power - @l) - 1, @l)
|
||||
|
||||
if @hexa_from = @hexa_to
|
||||
set @string = (
|
||||
(case when @hexa_from > 0 then left(@string, @hexa_from - 1) else '' end) +
|
||||
substring(@alphabet, (@from_mask | @to_mask) + 1, 1) +
|
||||
(case when @m - @hexa_to > 0 then right(@string, @m - @hexa_to) else '' end)
|
||||
)
|
||||
else
|
||||
set @string = (
|
||||
iif(@hexa_from - 1 < 0, '', left(@string, @hexa_from - 1)) +
|
||||
substring(@alphabet, @from_mask + 1, 1) +
|
||||
iif(@m - @hexa_to < 0, '', right(@string, @m - @hexa_to))
|
||||
)
|
||||
set @i = @hexa_from + 1
|
||||
while @i < @hexa_to begin
|
||||
if @i >= @m
|
||||
break
|
||||
set @string = left(@string, @hexa_from + @i - 1) + @character_0 + right(@string, @m - (@hexa_from + @i))
|
||||
set @i = @i + 1
|
||||
end
|
||||
if @hexa_to < @m
|
||||
set @string = left(@string, @hexa_to - 1) + substring(@alphabet, @to_mask + 1, 1) + right(@string, @m - @hexa_to)
|
||||
|
||||
end
|
||||
|
||||
end else if @integer is not null begin
|
||||
if @from + @bits > 31 set @bits = 31 - @from
|
||||
set @integer = @integer & (case
|
||||
when @reversed = 1 then dbo.shift((dbo.shift(1, @bits) - 1), @shift)
|
||||
else dbo.shift(dbo.shift(1, dbo.get_bits(@integer)) - 1, @from + @bits) | (dbo.shift(1, @from) -1) end)
|
||||
end
|
||||
|
||||
execute dbo.clean @string output, @integer output
|
||||
|
||||
end
|
||||
go
|
||||
8
SQLServer/Tests.server.sql
Normal file
8
SQLServer/Tests.server.sql
Normal file
@ -0,0 +1,8 @@
|
||||
use ErrorsManager
|
||||
|
||||
if object_id('dbo.tests_errors', N'P') is not null drop procedure dbo.tests_errors
|
||||
go
|
||||
create procedure dbo.tests_errors as begin set nocount on
|
||||
|
||||
end
|
||||
go
|
||||
Loading…
Reference in New Issue
Block a user