如何将语法从 Foxpro 转换为 SQL 服务器
How to convert syntax from Foxpro to SQL Server
LOCAL in_txt
in_txt='mohammad'
txt_len=LEN(in_txt)
rev_txt=''
FOR ii=1 TO txt_len
w_chr=SUBSTR(in_txt,ii,1)
w_asc=IIF(ASC(w_chr)=32,32,ASC(w_chr)+1)
* ?' #'+w_chr+'='+CHR(w_asc)+'*'+STR(ASC(w_chr))+'>'+STR(ASC(w_chr)+1)+'*'+CHR(ASC(w_chr))+'>'+CHR(ASC(w_chr)+1)
rev_txt=rev_txt+ CHR(w_asc)
ENDFOR
return rev_txt
我知道解决我的问题 * 角色在 foxpro 中使用注释。
这是等效的SQL
DECLARE @in_txt varchar(100)
DECLARE @txt_Len int
DECLARE @rev_txt varchar(100)=''
DECLARE @i int=0
DECLARE @w_chr char(1)
DECLARE @w_asc int
SET @in_txt='mohammad'
SET @txt_len=LEN(@in_txt)
WHILE @i < @txt_len
BEGIN
SET @i = @i + 1
SET @w_chr=SUBSTRING(@in_txt,@i,1)
SET @w_asc = ASCII(@w_chr)
IF @w_asc <> 32 SET @w_asc=@w_asc+1
PRINT '#'+@w_chr+'='+CHAR(@w_asc)+'*'+STR(ASCII(@w_chr))+'>'+STR(ASCII(@w_chr)+1)+'*'+CHAR(ASCII(@w_chr))+'>'+CHAR(ASCII(@w_chr)+1)
SET @rev_txt = @rev_txt + CHAR(@w_asc)
END
PRINT @rev_Txt
这似乎是一个非常简单的文本加密。循环中的 Print 语句(相当于 Foxpro 中的 ?)是调试器语句
这是一段写得很烂的VFP代码。 * 将该行标记为注释,基本上它将字符串中除 char 32 (SPACE) 之外的所有字符替换为 ASCII 图表中的下一个字符。不过,这不是您可以在 MS SQL 中轻松转换的内容,因为在 VFP 中,字符串中可以包含任何字符,包括 char(0)。假设你没有 char 0:
Declare @in_txt varbinary(MAX);
DECLARE @rev_txt varbinary(MAX);
set @in_txt = CAST('mohammad' AS VARBINARY(MAX));
declare @i int;
declare @w_char int;
set @i = 1;
SET @rev_txt = CAST('' AS VARBINARY(MAX));
WHILE @i <= Len(@in_txt)
Begin
set @w_char = ASCII(SUBSTRING(@in_txt,@i,1));
SET @rev_txt = @rev_txt +
CAST(@w_char + case when @w_char = 32 then 0 else 1 end AS BINARY(1));
SET @i = @i +1;
END
SELECT @rev_txt;
LOCAL in_txt
in_txt='mohammad'
txt_len=LEN(in_txt)
rev_txt=''
FOR ii=1 TO txt_len
w_chr=SUBSTR(in_txt,ii,1)
w_asc=IIF(ASC(w_chr)=32,32,ASC(w_chr)+1)
* ?' #'+w_chr+'='+CHR(w_asc)+'*'+STR(ASC(w_chr))+'>'+STR(ASC(w_chr)+1)+'*'+CHR(ASC(w_chr))+'>'+CHR(ASC(w_chr)+1)
rev_txt=rev_txt+ CHR(w_asc)
ENDFOR
return rev_txt
我知道解决我的问题 * 角色在 foxpro 中使用注释。
这是等效的SQL
DECLARE @in_txt varchar(100)
DECLARE @txt_Len int
DECLARE @rev_txt varchar(100)=''
DECLARE @i int=0
DECLARE @w_chr char(1)
DECLARE @w_asc int
SET @in_txt='mohammad'
SET @txt_len=LEN(@in_txt)
WHILE @i < @txt_len
BEGIN
SET @i = @i + 1
SET @w_chr=SUBSTRING(@in_txt,@i,1)
SET @w_asc = ASCII(@w_chr)
IF @w_asc <> 32 SET @w_asc=@w_asc+1
PRINT '#'+@w_chr+'='+CHAR(@w_asc)+'*'+STR(ASCII(@w_chr))+'>'+STR(ASCII(@w_chr)+1)+'*'+CHAR(ASCII(@w_chr))+'>'+CHAR(ASCII(@w_chr)+1)
SET @rev_txt = @rev_txt + CHAR(@w_asc)
END
PRINT @rev_Txt
这似乎是一个非常简单的文本加密。循环中的 Print 语句(相当于 Foxpro 中的 ?)是调试器语句
这是一段写得很烂的VFP代码。 * 将该行标记为注释,基本上它将字符串中除 char 32 (SPACE) 之外的所有字符替换为 ASCII 图表中的下一个字符。不过,这不是您可以在 MS SQL 中轻松转换的内容,因为在 VFP 中,字符串中可以包含任何字符,包括 char(0)。假设你没有 char 0:
Declare @in_txt varbinary(MAX);
DECLARE @rev_txt varbinary(MAX);
set @in_txt = CAST('mohammad' AS VARBINARY(MAX));
declare @i int;
declare @w_char int;
set @i = 1;
SET @rev_txt = CAST('' AS VARBINARY(MAX));
WHILE @i <= Len(@in_txt)
Begin
set @w_char = ASCII(SUBSTRING(@in_txt,@i,1));
SET @rev_txt = @rev_txt +
CAST(@w_char + case when @w_char = 32 then 0 else 1 end AS BINARY(1));
SET @i = @i +1;
END
SELECT @rev_txt;