Thanks, I think this is a good tip.

On Saturday, 6 September 2014 18:16:59 UTC+10, Joe Barnhart wrote:
>
> File this under "stupid but useful web2py tricks"....
>
> I have a database that I need to populate from an ASCII text file.  I've 
> been tearing my hair out parsing the file and doing all the formatting by 
> hand for every field, and then inserting the data into the table.  What a 
> joy to find "validate_and_insert" which runs the data through the Field 
> validators first before inserting the data.
>
> My date fields, for instance, are written in the text file in compressed 
> form, like "MMDDYYYY" with no delimiters.  I just set the validator on that 
> Field first to IS_DATE(format="%m%d%Y") and it takes care of the conversion 
> automatically.  This is a real timesaver!
>
> I did notice that I need to null out some of the fancier validators that 
> use more than one field on table updates that don't include all the needed 
> fields.  Caveat emptor.  I dunno if it is marginally faster or slower than 
> me doing it by hand, but I can tell you its a whole lot more maintainable, 
> and that is the real winner long term.
>
> -- Joe
>
>

-- 
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.

Reply via email to