List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 14 2000 5:34pm
Subject:Re: Getting data as raw bytes
View as plain text  
At 11:22 AM -0700 01-14-2000, Sasha Pachev wrote:
>Cliff Addy wrote:
>>
>>  I'm using the C api to access a mysql database.  One particular field is
>>  defined as a bigint.  If I retrieve this field, I get the value formatted
>>  as a base-10 number in string format.  What I *need* is the 8 raw data
>>  bytes, is there any way I can set up the query to return this?  Failing
>>  this, is there a C function that will turn it back into raw bytes?
>>
>>  Cliff
>
>mysql will always return base 10 number -- no way around this unless you
>hack the client lib and the server and make a big mess of everything
>else :-)

You can return things in other bases.  BIN() for binary, OCT() for octal,
HEX() for hex.  (But they'll always arrive at the client as a string, because
all values are sent from the server to the client as strings.  So the client
still needs to do the conversion to raw bytes.)

>to conver the number to an int in C you can use atoi(), atol() or
>strtol() -- now if your libc is not smart enough to deal with a big here
>is a hack -- untested, but should work, if it does not , at least you
>get the idea:
>
>longlong atoll(char* str)
>  {
>    longlong res = 0;
>    while(isdigit(*str))
>     {
>       res = res * 10 + *str - '0';
>     }
>   return res;
>  }

Er, well you probably want to advance down the string at some point. :-)

       res = res * 10 + *str++ - '0';

-- 
Paul DuBois, paul@stripped
Thread
Getting data as raw bytesCliff Addy14 Jan
  • Re: Getting data as raw bytesSasha Pachev14 Jan
    • Re: Getting data as raw bytesPaul DuBois14 Jan
  • Re: Getting data as raw bytessinisa15 Jan
  • Re: Another Answer: Getting data as raw bytesRick Moore15 Jan