Discussion:
INSERT INTO and Hexadecimal Literals
Ben Atkinson
2009-07-01 20:32:16 UTC
Permalink
Sorry for the newbie SQL question. I'm trying to use the INSERT INTO
statement with a hexadecimal literal. I want to accomplish something
like this:

INSERT INTO TruckDefaultsTable VALUES ( 'AirPressureTime', 0, 0xB40000);

sqlite chokes on the 0xB40000 expression with:
unrecognized token: "0xB40000"

I could express the value in decimal as 11796480, but that's pretty awkward
since the actual value I'm putting into the table is a Linux timeval structure.
It just makes more sense as hex.

Does SQL have a hex literal sequence that serves the same role as "0x" in C?

Thanks for any help.

Ben
Clay Baenziger
2009-07-01 20:38:16 UTC
Permalink
Hi Ben,
I hit this a few months ago. Hex literals have to contain an even
number of hex digits. For that discussion, see:
http://www.nabble.com/Hexadecimal-Inequalities-Failing--td20216982.html

Thank you,
Clay
Post by Ben Atkinson
Sorry for the newbie SQL question. I'm trying to use the INSERT INTO
statement with a hexadecimal literal. I want to accomplish something
INSERT INTO TruckDefaultsTable VALUES ( 'AirPressureTime', 0, 0xB40000);
unrecognized token: "0xB40000"
I could express the value in decimal as 11796480, but that's pretty awkward
since the actual value I'm putting into the table is a Linux timeval structure.
It just makes more sense as hex.
Does SQL have a hex literal sequence that serves the same role as "0x" in C?
Thanks for any help.
Ben
_______________________________________________
sqlite-users mailing list
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Clay Baenziger
2009-07-01 20:43:36 UTC
Permalink
Erg, I can almost count. Sorry, the correct way to specify a hex literal
is in that thread too. If you use x'<value>' you can enter the bits.

Thank you,
Clay
Post by Clay Baenziger
Hi Ben,
I hit this a few months ago. Hex literals have to contain an even
http://www.nabble.com/Hexadecimal-Inequalities-Failing--td20216982.html
Thank you,
Clay
Post by Ben Atkinson
Sorry for the newbie SQL question. I'm trying to use the INSERT INTO
statement with a hexadecimal literal. I want to accomplish something
INSERT INTO TruckDefaultsTable VALUES ( 'AirPressureTime', 0, 0xB40000);
unrecognized token: "0xB40000"
I could express the value in decimal as 11796480, but that's pretty awkward
since the actual value I'm putting into the table is a Linux timeval structure.
It just makes more sense as hex.
Does SQL have a hex literal sequence that serves the same role as "0x" in C?
Thanks for any help.
Ben
_______________________________________________
sqlite-users mailing list
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Igor Tandetnik
2009-07-01 20:55:29 UTC
Permalink
Post by Ben Atkinson
Sorry for the newbie SQL question. I'm trying to use the INSERT INTO
statement with a hexadecimal literal. I want to accomplish something
INSERT INTO TruckDefaultsTable VALUES ( 'AirPressureTime', 0,
0xB40000);
Does SQL have a hex literal sequence that serves the same role as "0x" in C?
No, there's no syntax for integral hexadecimal literals. There is a blob
literal x'B40000', but it doesn't behave like a number (e.g. you can't
do arithmetic on blobs). Bottom line, the only option is to use plain
vanilla decimal numbers.
Post by Ben Atkinson
I could express the value in decimal as 11796480, but that's pretty
awkward since the actual value I'm putting into the table is a Linux
timeval structure. It just makes more sense as hex.
How come you need to type these timestamps in by hand? When you work
with SQLite programmatically, you just use int variables and such -
there's almost never a need to represent the number as string, whether
decimal or hex.

Igor Tandetnik
Ben Atkinson
2009-07-02 14:02:46 UTC
Permalink
Post by Igor Tandetnik
No, there's no syntax for integral hexadecimal literals. There is a blob
literal x'B40000', but it doesn't behave like a number (e.g. you can't
do arithmetic on blobs). Bottom line, the only option is to use plain
vanilla decimal numbers.
Thanks for the response, Igor. That tells me what I need.

Regards,

Ben
Post by Igor Tandetnik
Post by Ben Atkinson
Sorry for the newbie SQL question. I'm trying to use the INSERT INTO
statement with a hexadecimal literal. I want to accomplish something
INSERT INTO TruckDefaultsTable VALUES ( 'AirPressureTime', 0, 0xB40000);
Does SQL have a hex literal sequence that serves the same role as "0x" in C?
No, there's no syntax for integral hexadecimal literals. There is a blob
literal x'B40000', but it doesn't behave like a number (e.g. you can't
do arithmetic on blobs). Bottom line, the only option is to use plain
vanilla decimal numbers.
Post by Ben Atkinson
I could express the value in decimal as 11796480, but that's pretty
awkward since the actual value I'm putting into the table is a Linux
timeval structure. It just makes more sense as hex.
How come you need to type these timestamps in by hand? When you work
with SQLite programmatically, you just use int variables and such -
there's almost never a need to represent the number as string, whether
decimal or hex.
Igor Tandetnik
Continue reading on narkive:
Loading...