oracle / odpi

ODPI-C: Oracle Database Programming Interface for Drivers and Applications
https://oracle.github.io/odpi/
Other
264 stars 75 forks source link

`dpiJson_getValue()` returns same top node even after another value is set by `dpiJson_setValue()`. #154

Closed kubo closed 3 years ago

kubo commented 3 years ago

ODPI-C version: 4.1.0 Oracle client version: 21.1

    dpiJsonNode node, *topNode;
    dpiDataBuffer value;

    node.oracleTypeNum = DPI_ORACLE_TYPE_NUMBER;
    node.nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE;
    node.value = &value;
    node.value->asDouble = 1.0;

    dpiJson_setValue(json, &node);
    dpiJson_getValue(json, DPI_JSON_OPT_DEFAULT, &topNode);
    fprintf(stderr, "%f\n", topNode->value->asDouble);

    node.value->asDouble = 2.0;
    dpiJson_setValue(json, &node);
    dpiJson_getValue(json, DPI_JSON_OPT_DEFAULT, &topNode);
    fprintf(stderr, "%f\n", topNode->value->asDouble);

The above code should print:

1.000000
2.000000

However it printed:

1.000000
1.000000

I noticed that once non-null value is set to json->topNode, dpiJson_getValue() returns same top node even after another JSON value is set by dpiJson_setValue(). https://github.com/oracle/odpi/blob/v4.1.0/src/dpiJson.c#L733-L744


Yet another but related issue:

    dpiJsonNode node, *topNode;
    dpiDataBuffer value;

    node.oracleTypeNum = DPI_ORACLE_TYPE_NUMBER;
    node.nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE;
    node.value = &value;
    node.value->asDouble = 1.0;

    dpiJson_setValue(json, &node);

    // Get number as double
    dpiJson_getValue(json, DPI_JSON_OPT_DEFAULT, &topNode);
    fprintf(stderr, "native_type: %d\n", topNode->nativeTypeNum);

    // Get number as string
    dpiJson_getValue(json, DPI_JSON_OPT_NUMBER_AS_STRING, &topNode);
    fprintf(stderr, "native_type: %d\n", topNode->nativeTypeNum);

The above code should print:

native_type: 3003
native_type: 3004

However it printed:

native_type: 3003
native_type: 3003
anthony-tuininga commented 3 years ago

Thanks, @kubo. I've just pushed a patch that should correct that for you!

kubo commented 3 years ago

Thanks. It works fine for me.