Are you performing computations with that number?  For example, will you
be performing addition, subtraction, or bitwise and/or?

If not, you could just leave it as a string (and likely change the
create to be "... text(32) default '0xFFFFFF'").

I'm not an expert on the topic, but sqlite uses "manifest typing"
meaning that it doesn't enforce the type of a given column.  This allows
you to put whatever you want, wherever you want.  SQLite will try to
"coerce" the data into the type you've specified.  So, when it sees
xFFFFFF, it decides that you really want a string and makes it so.  When
it sees 0xFFFFFF it likely coerces that into the integer type specified
in the create.

When storing the number as an integer, it's stored as binary.  The fact
that you see it in base 10 when you select it is an artifact of whatever
you are using to display the number.  The sqlite command line utility
displays integers in base 10 (for good reason, most of the time, you
expect this!).

I had a quick look at the sqlite built-in sql functions to see if there
is a function that could convert an integer to a hex string (like
TO_CHAR() in oracle, or STR() in MSSQL), but it looks like there is not.


SQLite is intentinonally sparse in the included functions, so you can
either write or find a custom sqlite function to do this.
Alternatively, simply use whatever number->string conversion routines
the language/platform you are using supplies (e.g. printf for c).

Pat



-----Original Message-----
From: Wilfried Mestdagh [mailto:[EMAIL PROTECTED] 
Sent: Sunday, July 02, 2006 11:16 PM
To: sqlite-users@sqlite.org
Subject: [sqlite] default value in hex


Hi,

How to specify a hexadecimal value in the default by create of a table ?
I
try thinks like:

create table Test ( [Name] char, [Color] integer default 0xFFFFFF );

But have syntax errors. When I leave out the 0 then the xFFFFFF seems to
be
stored as a string. it is just that 0xFFFFFF makes more sence that
16777215,
specially if it is a color.
-- 
View this message in context:
http://www.nabble.com/default-value-in-hex-tf1882855.html#a5147011
Sent from the SQLite forum at Nabble.com.

Reply via email to