Home » U++ Library support » U++ Core » Jsonize int64 surprise
Jsonize int64 surprise [message #38862] |
Thu, 24 January 2013 19:51 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
It looks like jsonizing big int64 numbers leads to "string" representation instead of direct one.
I consider this bad kind of surprise as one's completely unable to send ANY big (int64) numbers to browser. I.e. you need to send some JSON containing javascript timestamp (which is really big int64 number) with int64 member. But you'll be surprised that this javascript code wont't work:
var d = new Date(receivedJson.t);
because t is not 1274574567221 but is a string '1274574567221'.
Looking into U++ core code reveals following:
//Core/JSON.cpp @ 238
if(var >= INT_MIN && var <= INT_MAX)
io.Set(var);
else
io.Set(AsString(var));
I propose eliminating such a surprise party leaving int64 numbers as it is. Besides all known to me modern javascript implementations DO SUPPORT int64 integer numbers by default.
[Updated on: Thu, 24 January 2013 19:53] Report message to a moderator
|
|
|
|
Re: Jsonize int64 surprise [message #38867 is a reply to message #38865] |
Thu, 24 January 2013 20:21 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
I may be wrong. But my point is that JSON is used mostly in Web development. In our case this means: Quote: | server[U++] <-> client[javascript]
|
And javascript natively supports integers up to 64-bit length (actually 53-bit, see below). So should we in U++.
This article
http://cdivilly.wordpress.com/2012/04/11/json-javascript-lar ge-64-bit-integers/
corrects that Javascript actually support integers up to 2^53. So if we really want to be close to standards here, we should check not INT_MAX, but 2^53 for stringification.
But I'd suggest eliminating ANY surprises at all. We have number - we represent as number. But one may disagree with it.
[Updated on: Thu, 24 January 2013 20:26] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Jsonize int64 surprise [message #38954 is a reply to message #38952] |
Tue, 29 January 2013 10:37 |
|
Check pls Sql for int64 columns also.
(I've spent many many hours to discover problem, that int64 is String Value)
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
|
|
|
|
|
|
Re: Jsonize int64 surprise [message #38963 is a reply to message #38962] |
Wed, 30 January 2013 09:01 |
|
And may you patch Sqlite3 schema plugin to do not convert int64 to int Type?
Sqlite normally eat int64 declaration, but if I write universal SqlExp expression - Sqlite3 schemaparser convert int64 to int. It's sad!
uppsrc/plugin/sqlite3/Sqlite3Schema.h:
Now:#define INT64(x) COLUMN("integer", int64, x, 0, 0)
#define INT64_ARRAY(x, items) COLUMN_ARRAY("integer", int64, x, 0, 0, items)
#define INT64_(x) COLUMN_("integer", int64, x, 0, 0)
#define INT64_ARRAY_(x, items) COLUMN_ARRAY_("integer", int64, x, 0, 0, items)
Need and tested: #define INT64(x) COLUMN("bigint", int64, x, 0, 0)
#define INT64_ARRAY(x, items) COLUMN_ARRAY("bigint", int64, x, 0, 0, items)
#define INT64_(x) COLUMN_("bigint", int64, x, 0, 0)
#define INT64_ARRAY_(x, items) COLUMN_ARRAY_("bigint", int64, x, 0, 0, items)
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
[Updated on: Wed, 30 January 2013 09:09] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Mar 29 02:38:31 CET 2024
Total time taken to generate the page: 0.02077 seconds
|