Skip to content

Commit bcf9063

Browse files
almeida-cloves-bcgmkleehammer
authored andcommitted
truncate decimaldigits to 9
1 parent af1ae4b commit bcf9063

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/params.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,10 @@ static int PyToCType(Cursor *cur, unsigned char **outbuf, PyObject *cell, ParamI
403403
pts->second = PyDateTime_DATE_GET_SECOND(cell);
404404

405405
// Truncate the fraction according to precision
406-
long fast_pow10[] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000, 10000000000};
406+
size_t digits = min(9, pi->DecimalDigits);
407+
long fast_pow10[] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
407408
SQLUINTEGER milliseconds = PyDateTime_DATE_GET_MICROSECOND(cell) * 1000;
408-
pts->fraction = milliseconds - (milliseconds % fast_pow10[10 - pi->DecimalDigits]);
409+
pts->fraction = milliseconds - (milliseconds % fast_pow10[9 - digits]);
409410

410411
*outbuf += sizeof(SQL_TIMESTAMP_STRUCT);
411412
ind = sizeof(SQL_TIMESTAMP_STRUCT);

0 commit comments

Comments
 (0)