Android SQLite Updating Null Fields
This is more of a "am I doing this the right way" kinda question as opposed to a "its not working, please help." I am using an sqlite data开发者_运维知识库base in an android project and on a particular activity the user can enter information into multiple edittext boxes. When the user leaves the activity the database updates everything. Right now I am simply updating every single field in the database not knowing whether or not the user has actually written something into the box, but is this a messy/unclean way of doing this? Is it necessary to perform a check on each item and make sure it has something in it before adding it to the database? How would I perform such a check and have a different sql statement for every possible scenario? I guess I could use a string builder and append a new field each time an editbox comes up full, but is this necessary or can I simply just let it enter null data because it doesn't really seem to be causing any negative effects. Just curious...
Updating a database record is fairly trivial and you won't gain much (if any) performance by only updating the fields that were changed. If you don't care about overwriting old values with new ones (which might be blank), then there's no point in performing all the extra checks. You'll just make the code more messy/complicated and are more likely to introduce bugs.
精彩评论