"David Godsey" <[EMAIL PROTECTED]> wrote on 02/14/2006 03:28:41 PM:

> Well, just thought I'd try one more time because I didn't get an answer 
to
> my question last time.
> 
> So what I have is a random data stream that is sent in raw form, and 
based
> on some data definition, I can assemble with the correct data types and
> such.  One of my requirements is that I have to store the data in raw
> form, and when I pull the data out, it displays based on the 
configuration
> (with the correct data types and such).  So floats and doubles are IEEE
> standards so I don't have to worry about those, however with integer
> types, I may need to do some byte swapping (because this data can come
> from variouse systems that could be either big or little endian).  So I 
am
> singling out the data I need, but now I need to add the ability to byte
> swap the data.
> 
> Keep in mind that it would be best if I can do this in SQL so that it is
> portable.  I realize that it can easily be done in C, but that makes my
> code less portable (which is also a requirement, to have it portable 
that
> is).  So does anybody know of a MySQL function that is already 
implemented
> to do byte swapping? or know of a way to implement this in SQL?
> 
> If not, is my only other option to write a UDF?
> 
> Thanks for any help.
> 
> Accomplishing the impossible means only that the boss will add it to 
your
> regular duties.
> 
> David Godsey
> 

Native functions? No. Something you can cobble together? Yes.  There 
should be several ways you can deal with your data as a string of binary 
characters. Just re-sequence those and you should have your bytes swapped.

One idea is to use the substring functions directly on your BINARY string. 
Another is to use the substring functions in combination with 
HEX()/UNHEX() to work on an escaped version of your BINARY string.

Sorry or the lame ideas but usually things like this are not handled at 
the database layer but rather in the application layer. Depending on which 
version of MySQL you are using you may be able to define a FUNCTION (a 
different creature than a UDF) or a STORED PROCEDURE to do the swapping. 
Both will be pure SQL and should meet your compatibility needs. Neither 
will be as fast as creating and registering a UDF, though.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to