When I use django-mssql, all DecimalFields are being saved with 4 decimal places in the database, even through the fields have far greater precision: all of them are decimal(28, 13). Everything works fine with other databases (MySQL and Postgres).
This was driving me mad, and I began debugging the save code, digging as deep as I could. I've managed to trace it down to the conversion from Decimal to adDecimal, which happens in Cursor.execute() in dbapi.py.
If I pause the Aptana debugger in line 520
_configure_parameter(p, value) # line 519 self.cmd.Parameters.Append(p) # line 520
when it's handling a Decimal parameter, and run the following command in the Console window
print value, value.__class__, p, p.__class__
1643991.703308 <class 'decimal.Decimal'> 1643991,7033 win32com.client.CDispatch
which is obviously wrong. I don't know how to go further because it's crossing the C layer.
When I query the field above through SQL Server Management Studio, the result is 1643991.7033000000000. For the record, if I run a UPDATE query manually in Management Studio (
UPDATE portfolio_snapshot SET shares = 1643991.703308 WHERE id = 20), the field gets saved with the appropriate number of places.
Possibly useful information:
- Running django-mssql 1.4 with Django 1.5, Python 2.7
- Happens in both Windows 8 and Windows Server 2008 R2
- Using SQL Server 2008 R2
- Using 'sqlncli10' as the provider