gerald_clark <[EMAIL PROTECTED]> wrote on 02/14/2006 
03:59:21 PM:

> [EMAIL PROTECTED] wrote:
> 
> >"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.
> > 
> >
> Would not the first zero value character terminate the substring, 
> rendering it invalid?
> 
> >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
> >

I don't know if it will or if it won't. The original poster (David Godsey) 
seems to have no trouble extracting specific subsections of raw data from 
his blob fields. I just assume that working with chunks of raw data that 
contained zeroes in them was no problem for him.

His need is to somehow binarily invert sections of each number (the 
INET_... functions could also help) in order to convert big-endian to 
little-endian and vice versa. I was just trying to help point him to some 
possible functions that may help him to do that. Hopefully he will post 
back with what works and what doesn't.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to