On Sunday, 13 March, 2016 13:36 -07:00, jungle Boogie <jungleboogie0 at 
gmail.com> wrote:
> On 12 March 2016 at 22:07, J Decker <d3ck0r at gmail.com> wrote:

> > maybe ?
> > https://www.sqlite.org/lang_corefunc.html

> > hex(X)The hex() function interprets its argument as a BLOB and returns
> > a string which is the upper-case hexadecimal rendering of the content
> > of that blob.

> That's what I first tried but not working as I expected.

> Here it is in decimal: (select code from sidemeters)
> "0"
> "1"
> "2"
> "5"
> "6"
> "7"
> "28"
> "29"
> "30"
> "31"

Assuming that your quotes mean that the value is TEXT, not a number.
You can check this by running:

     select code, typeof(code) from sidemeters;

You will note that the printf function wants to cast the "code" to an integer, 
then outputs the hex representation of the integer.
The hex() function treats the item as a "blob" and converts the actual bytes 
stored into hex.

They are two entirely different things.


> And in hex with my attempt of printf: (SELECT printf("%x",code)  FROM
> sidemeters)
> "0"
> "1"
> "2"
> "5"
> "6"
> "7"
> "1c"
> "1d"
> "1e"
> "1f"
> 
> Here is with hex(code): (SELECT hex(code) FROM sidemeters)
> "30"
> "31"
> "32"
> "35"
> "36"
> "37"
> "3238"
> "3239"
> "3330"
> "3331"
> 
> 
> Am I trying to use hex() incorrectly?
> 
> Thanks!

So really the question is, what is the declared column affinity of the "code" 
column in you table definition and what is the actual type of the data stored?

Based on the results you have obtained, I would suspect that the column 
affinity is "integer" and you are storing either text or integer (it is 
immaterial which in this particular case).

In order for hex() to generate output, it "converts" the integer into a blob 
(text) and outputs the hexified result.




Reply via email to