My app includes a simple SQLFORM for generating payment receipts. The payment amount is stored as type='decimal(10,2)' using a MySQL database.
All works fine if the user enters the payment amount using just numbers (eg '1000'). However, if they include a ',' for the thousands separator in the payment amount field (eg '1,000'), it throws the following error: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. Traceback (most recent call last): File "/home/andy/web2py/gluon/restricted.py", line 227, in restricted exec ccode in environment File "/home/andy/web2py/applications/nurserymgr/controllers/finance.py" <https://andy.pythonanywhere.com/admin/edit/nurserymgr/controllers/finance.py>, line 301, in <module> File "/home/andy/web2py/gluon/globals.py", line 393, in <lambda> self._caller = lambda f: f() File "/home/andy/web2py/gluon/tools.py", line 3440, in f return action(*a, **b) File "/home/andy/web2py/applications/nurserymgr/controllers/finance.py" <https://andy.pythonanywhere.com/admin/edit/nurserymgr/controllers/finance.py>, line 112, in create_receipt if form.process().accepted: File "/home/andy/web2py/gluon/html.py", line 2301, in process self.validate(**kwargs) File "/home/andy/web2py/gluon/html.py", line 2238, in validate if self.accepts(**kwargs): File "/home/andy/web2py/gluon/sqlhtml.py", line 1679, in accepts self.vars.id = self.table.insert(**fields) File "/home/andy/web2py/gluon/packages/dal/pydal/objects.py", line 745, in insert ret = self._db._adapter.insert(self, self._listify(fields)) File "/home/andy/web2py/gluon/packages/dal/pydal/adapters/base.py", line 727, in insert raise e OperationalError: (1136, "Column count doesn't match value count at row 1") Error snapshot [image: help] <https://andy.pythonanywhere.com/admin/default/ticket/nurserymgr/31.215.24.252.2015-04-21.20-45-50.1d0af159-af99-4f0a-a938-c8f96727e280#> <class '_mysql_exceptions.OperationalError'>((1136, "Column count doesn't match value count at row 1")) The code is: Model: db.define_table('receipt', Field('student', db.student, required=True, default=request.args(0), readable=False, writable=False), Field('receipt_number', type='string', length=10, required=True, label=T('Receipt #')), Field('payment_date', type='date', default= datetime.date.today(), label=T('Payment Date')), Field('payment_amount', type='decimal(10,2)', label=T('Payment Amount'))) Controller: def create_receipt(): db.receipt.student.default=s.id db.receipt.student.readable=False db.receipt.student.writable=False form = SQLFORM(db.receipt) if form.process().accepted: session.flash = T("New receipt created") redirect(URL('print_receipt', args=form.vars.id)) elif form.errors: response.flash = 'form has errors' return dict(form=form) Any suggestions on how to prevent this would be much appreciated. Regards, Andy -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.