Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Varbinary() Manipulations
Message
De
04/04/2001 07:31:54
 
 
À
03/04/2001 18:27:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00489403
Message ID:
00491756
Vues:
7
Hi Alexander,

Thanks for looking at it. That is essentially what I am doing. It took some trial and error but I do have it working using SUBSTR(), STUFF(), CONVERT(), ^, etc. producing results like the VB version. This has been an interesting and informative exercise.

Bill

>Hi Bill,
>
>What about SUBSTRING and STUFF functions and some kind of conversion?
>
... other declarations
>...
>DECLARE @counter INT
>DECLARE @curChar BINARY(1)
>DECLARE @curKey  BINARY(1)
>SET @counter = 1
>WHILE @counter <= LEN( @bytData)
>BEGIN
>    SET @curChar = SUBSTRING( @bytData, @counter, 1)
>    SET @curKey = SUBSTRING( @bytKey, @counter, 1)
>    IF @counter % 2 = 0
>        SET @curChar = @curChar | (@curKey + @KEY_OFFSET)
>    ELSE
>        SET @curChar = @curChar | (@curKey - @KEY_OFFSET)
>    SET @bytData = CONVERT( VARBINARY, STUFF( @bytData, @counter, 1, @curChar))
>    SET @counter = @counter + 1
>END
>...
>
>Maybe I missed something, but in common this should work.
>
>>A bit off-topic here but thought I'd get some info from some of the T-SQL/binary experts.
>>
>>I have a situation where I am trying to translate some VB code using some byte arrays into T-SQL code so I can run the functionality in a SQL stored procedure. I believe I have successfully converted most of the code but I'm stuck at the the point where there is some manipulation of the VB byte arrays and I don't quite see how I can do this in T-SQL ( or even if it's possible ). The relevant VB code is:
>>Dim KEY_OFFSET As Long
>>Dim bytKey() As Byte
>>Dim bytData() As Byte
>>Dim lNum As Long
>>
>>'...Set values for the various variables, then:
>>
>>For lNum = LBound(bytData) To UBound(bytData)
>>    If lNum Mod 2 Then
>>        bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) + KEY_OFFSET)
>>    Else
>>        bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) - KEY_OFFSET)
>>    End If
>>Next lNum
>>I can ( or at least I think I can ) get most of the entities translated, i.e. the arrays bounds, Mod, and Xor I can translate. I am using T-SQL varbinary() for the equivalent VB byte arrays and the specific problem I am wrestling with is how to "replace" bits ( bytes? ) in the varbinary() variable like is done with the
>>        bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) + KEY_OFFSET)
>>VB statement.
>>
>>Is this possible in T-SQL and if so, how?
>>
>>Thanks,
>>Bill
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform