Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a StrToHex API function?
Message
From
04/02/2002 07:48:24
 
 
To
04/02/2002 05:57:39
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00614674
Message ID:
00614706
Views:
54
Hi!

Thanks for this new approach, I will add this new approach to that article. A few notes:

First of all, I suspect that the conversion is done by ODBC driver on the way to SQL Server, not by VFP, so there are probably no built-in VFP functioality for that. Think - different databases might require different approaches for preparing binary data. So probably ODBC driver does this accordinly to the database system for which driver is used.

Second, manual conversion also takes the time and space. In addition, you then use string concatenation and pass binary data as a string in SELECT statement. This probably have a limitation for the size of the binary data (though I'm not sure in this), as well as might require some memory and as a result disk swapping when passing that string to ODBC. Really large files might work more quickly in such case when using ADO or just simpler approach desribed in FAQ aricle.

Third, you can use ADO with much better speed, and no need in conversion at all. In FAQ article, there is mentioning of ADO as well.


>I just found a solution. Albert Ballinger's great utility FoxCrypto.fll (see http://fox.wikis.com/wc.dll?Wiki~FoxCrypto~VFP) has a function called HexEncoder which does exactly this. This function is soooooo fast. My StrToHex() version written in VFP took 127 seconds to convert a 180KB file. Albert's function does it in 0.1 second!!!
>
>Vlad, you may want to update your FAQ to mention this as an alternative solution?
>
>>This is a follow-up on Vlad's FAQ#7995 regarding the difficulties to update SQL Server image fields with binary data when using SPT. So far I've been using the workaround suggested in the FAQ. The workaround is quite involved and requires an extra copy to disk. Last week I was looking into this problem again as I thought that there must be an easier way to do this.
>>
>>I used the SQL Profiler and found that binary data is actually sent in HEX format. For example, the string "Hello World" is sent as 0x48656C6C6F20576F726C64. I then created a simple program that converts a string into HEX format. This allows me to insert binary data into SQL Server with the following syntax:
>>
>>?SQLEXEC(nSql, "UPDATE MyTable SET ImageField = " + StrToHex(FILETOSTR(MyBinaryFile)) + " WHERE PkField=1")
>>
>>
>>This works well and the same approach could also be used to send binary data to a stored procedure. The problem is speed. My function StrToHex() loops through the file character by character. Needless to say that this is very slow. Does anyone know of an API/FLL function that converts a string into HEX? The funny thing is that VFP internally does exactly this when using SPT or a remote view.
>>
>>TIA
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform