Type-checking error messages built into the DAL insert() function

33 views
Skip to first unread message

David Ripplinger

unread,
Jul 25, 2013, 1:56:45 PM7/25/13
to web...@googlegroups.com
Currently, the DAL insert() function allows one to insert a record with a DATE field containing a string type using sqlite as the database. My guess is that there are other types that also go unchecked within the insert() function. I think it would be a good idea to raise an exception or something within insert() whenever the wrong type is passed into an argument so that there is one less way of accidentally corrupting the database.

Massimo Di Pierro

unread,
Jul 25, 2013, 3:46:51 PM7/25/13
to web...@googlegroups.com
This is done on purpose and it is should not be corrupting the database. 

About date/datetime. All database (as far as I know) take datetime in input as a iso string. In fact if you were to pass a datatime object it would be converted to a datetime object. sqlite is special because not only takes is as a string, it also always stores it as a string.

I am not aware of any problem with the current implementation. If you think there is a problem, please post an example. It is possible I may be missing something.

About other types. Validation is not done because validation is done at the level of forms already. If you need validation at the db level you can call db.table.validate_and_insert(....).

Massimo

David Ripplinger

unread,
Jul 25, 2013, 3:58:40 PM7/25/13
to web...@googlegroups.com
Hmm. I admit I made a few assumptions based on the incident I experienced and how I saw things done in a couple examples in the book. To be precise, I created a form using the FORM function, where one field was meant to be used as a date (had a requires=is_date() on it). I then passed the submitted info to put stuff into my database, passing in the date as a string into the insert() function. I'm pretty certain that when I did this, it was a valid date. However, this caused an exception to be raised any time a query was made to fetch this record (consequently, also when fetching all records from the table). It said something like "day is out of range for this month". So after I manually deleted the record, I changed my code to manually parse the date and create a datetime.date object to pass into the insert() function. After that, I haven't had any problems.

I'll see if some time in the near future I can duplicate the error to determine if it was something I did wrong or if there is something that could use some tweaking with web2py.
Reply all
Reply to author
Forward
0 new messages