I'm in the process of writing my first UDF and would appreciate some help.

I am pulling data from a table like:

                        SELECT payload_time,
                        SUBSTR(BINARY(frame_data),
                        FLOOR(foffset/8)+1,
                        CEIL((flength + (foffset %8 ))/8))
                        FROM RawMajorFrames
                        WHERE raw_major_frame_id=rfid
                        INTO ptime,fdata;

frame_data is type BLOB.  It is raw data collected. The substr will get
the specific bytes I'm interested in.  What I need to do, is if the data
is <= 8bytes, convert it to a BIGINT, so I can do some masking on the
data.

So I am writing a UDF to do the job, but I am apparently unfamiliar with
the Mysql data types and how I can convert them.

In a procedure.
DECLARE fdata_bigint BIGINT UNSIGNED;
SELECT BlobToInt(binary(fdata)) INTO fdata_bigint;

my_bool BlobToInt_init( UDF_INIT* initid, UDF_ARGS* args, char* message )
{
  if (args->arg_count != 1)
  {
    strcpy(message,"Wrong arguments to BlobToInt;  should be
BlobToInt(blob)");
    return 1;
  }
  return 0;
}
longlong BlobToInt( UDF_INIT* initid, UDF_ARGS* args, char* is_null, char
*error )
{
        longlong tmplong =  *((longlong*)args->args[0]);
        return tmplong;
}

I guess I was just assuming I could just cast the data as the type I want,
but that doesn't seem to work.  The function returns a 0.

Any help would be appreciated.

Accomplishing the impossible means only that the boss will add it to your
regular duties.

David Godsey


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to