0

Possible Duplicate:
How to convert Python decimal to SQLite numeric?

I am having an issue with sqlite not showing values that are not 2 decimal places but when I test it on MySQL (workbench) it works fine. I doesn't give an error or anything but just disappears quietly. I want to get to the bottom of this voodoo so it doesn't come back to bite me.

MY_CHOICE = (
   (Decimal('20.00'), '20'), /#doesnt work with sqlite
   (Decimal('20.00'), '20.00'), /#doesnt work with sqlite
   (Decimal('10.50'), '10.50'), /#doesnt work with sqlite
   (Decimal('5.05'), '5.05'),  /#works with sqlite
   (Decimal('4.75'), '4.75'),  /#works with sqlite
)

my_model = models.DecimalField(max_digits=6, decimal_places=2, choices=My_CHOICE, null=True, blank=True)

Any thoughts or ideas that might be helpful would be great. Thanks.

Community
  • 1
  • 1
Krazzzeee
  • 76
  • 4
  • sqlite does not support a decimal datatype, you'll have to use a workaround there are some similar questions on stack, e.g. http://stackoverflow.com/questions/6319409/how-to-convert-python-decimal-to-sqlite-numeric – Hedde van der Heide Oct 05 '12 at 14:41

1 Answers1

1

SQLite is very "democratic" and light-weight database. For example, you can declare VARCHAR(20) field and write 30-symbol string to it without any error or warning message.

From SQLite documentation:

A string might look like a floating-point literal with a decimal point and/or exponent notation but as long as the value can be expressed as an integer, the NUMERIC affinity will convert it into an integer. Hence, the string '3.0e+5' is stored in a column with NUMERIC affinity as the integer 300000, not as the floating point value 300000.0.

Marboni
  • 2,399
  • 3
  • 25
  • 42