Closed kubo closed 1 year ago
See https://stackoverflow.com/a/17508660 for the reason.
So convert to float and print that.
So convert to float and print that.
Agree. However there is no way to know whether a double value should be converted to float or not.
Both DPI_JZNVAL_FLOAT
and DPI_JZNVAL_DOUBLE
are got as same type. The former should be converted to float to print it. The latter should not. However there is no way to distinguish them.
https://github.com/oracle/odpi/blob/515a426239cfbd37d9446def11d0c5f8f1bb808b/src/dpiJson.c#L263-L272
This could be addressed by having node->nativeTypeNum
returned as DPI_NATIVE_TYPE_FLOAT
instead. Would that address your concerns?
node->nativeTypeNum = DPI_NATIVE_TYPE_FLOAT
for DPI_JZNVAL_FLOAT
is a must to address this.
In addition when nativeTypeNum
is DPI_NATIVE_TYPE_FLOAT
, scalar.value.asFloat.value
should be set to node->value->asFloat
for consistency of nativeTypeNum
and node->value
member. It isn't a must though.
Changing nativeTypeNum
is incompatible change. So I proposed to add the option to change the behavior.
Adding the option makes sense. I'll look into that when I get back from holidays!
Thinking about this a bit more, I think I'd rather just change the value of nativeTypeNum
to be DPI_NATIVE_TYPE_FLOAT
when the value is DPI_JZNVAL_FLOAT
as that makes more sense. This does mean that existing drivers that assumed that values would always come back as DPI_NATIVE_TYPE_DOUBLE
will need to be changed. As such, I think I'll relabel current development to 5.0 and note the need for adjusting driver assumptions for processing JSON. Use of DPI_JSNVAL_FLOAT
is uncommon, too. Thoughts?
@kubo, I've pushed the change I suggested and also bumped the version to 5.0. Timing on the release of 5.0 is unknown at this point -- but if you're not concerned about an official release, this should get you going!
@anthony-tuininga Thanks. It works fine.
Could you add
#define DPI_JSON_OPT_FLOAT_AS_FLOAT 0x04
todpi.h
and change https://github.com/oracle/odpi/blob/515a426239cfbd37d9446def11d0c5f8f1bb808b/src/dpiJson.c#L263-L266 as follows?When a float value is set to json, I want to get it as float without conversion from float to double, though I suspect that nobody uses float in json.
In rust language, double and float literals
2.3
are printed as2.3
. But the double value converted from float 2.3 is printed as2.299999952316284
. I want to avoid this kind of type conversion byDPI_JSON_OPT_FLOAT_AS_FLOAT
.