[Zope-DB] DCOracle2.1.1 problems
DA Loeffler
David.Loeffler@bristol.ac.uk
Wed, 17 Jul 2002 13:18:09 +0100 (BST)
On Mon, 15 Jul 2002, Matthew T. Kromer wrote:
> DCO2 should (emphasis on Should) do number conversion to INT when
> precision is 9 digits or less and scale is zero. If both precision and
> scale are zero, the underlying C module converts to float.
>
> Here's the relevant code snippet from src/dco2.c:
>
> if (scale != 0 || (precision == 0 && scale == 0)) {
> sscanf((char *) data, "%lf", &d);
> result = PyFloat_FromDouble(d);
> } else if (precision < 10) {
> sscanf((char *) data, "%ld", &l);
> result = PyInt_FromLong(l);
> } else {
> result = PyLong_FromString((char *)data, NULL, 10);
> }
>
> The reason the precision ==0 and scale == 0 check is there is that my
> experience is that some Oracle connections return zero for both scale
> and precision for NUMBER columns; as such, it isn't known what the real
> scale and precision are. I just ran a simple test query, and this is
> the case... if you create a NUMBER column, the scale and precision are
> zero. If you create a column as INTEGER you'll get a precision of 38,
> scale of 0 -- which will turn the result into a python long.
>
All my Number columns have a precision specified, so I must be using one
of these brain-damaged setups.
Wouldn't it make sense, in the case where the precision and scale come
back as 0, to check the result to see if its fractional part is zero,
and if so return an integer? Since I am working under NT rather than
Unix I can't recompile the module easily, I'm afraid, so I haven't been
able to test this idea.
David